A reusable TypeScript code-quality workflow covering Biome linting and formatting, automatic fixes on save and commit, Lefthook staged-file enforcement, and optional Tailwind CSS v4 canonical-class rewriting in the editor via the standalone CLI.

Set up a Biome/Ultracite/Lefthook quality workflow for this repository, including standalone Tailwind v4 canonical-class rewriting.

First inspect the repository’s existing package manager, formatting/linting configuration, commit hooks, Tailwind setup, editor configuration, and contributor instructions. Preserve unrelated configuration and existing user changes.

Use current official documentation before configuring any tool. Prefer the project’s existing package manager.

Requirements:

1. Configure or retain Biome through Ultracite.
   - Install the required development dependencies if absent:
     - `@biomejs/biome`
     - `ultracite`
     - `lefthook`
   - Do not add Prettier or ESLint merely for Tailwind canonicalisation.
   - Do not create a second formatter pass after Biome.

2. Add standalone Tailwind canonicalisation.
   - Install this development dependency:
     - `@laststance/tailwind-suggest-canonical-classes`
   - Detect the project’s real Tailwind v4 entry stylesheet: the CSS file containing `@import "tailwindcss"` and any project theme, plugin, or custom-variant declarations.
   - Use that stylesheet explicitly with `--css <path>`. Do not assume the filename is `global.css`.
   - If no Tailwind v4 entry stylesheet exists, stop and explain what is missing rather than guessing.

3. Configure Lefthook’s `pre-commit` hook in this exact order:
   - First: run Ultracite/Biome fixes on staged supported files.
   - Second: run `tailwind-suggest-canonical-classes` only on staged `js`, `jsx`, `ts`, `tsx`, and `mdx` files, passing the detected stylesheet via `--css`.
   - Third: re-stage changes made by each fixer.
   - Retain unrelated existing hook commands and preserve their intended ordering.
   - Add a brief explanatory comment to any changed tooling configuration.

4. Provide manual project commands:
   - `canonical-check`: run the standalone CLI with `--check` against the project’s relevant source globs.
   - `canonical-fix`: rewrite those files in place.
   - Integrate these with existing task tooling such as `package.json` scripts or a Justfile; do not replace an existing task system unnecessarily.

5. Add optional editor save-time integration without a filesystem watcher.
   - First detect whether this repository already contains editor configuration and which editor it targets. Preserve existing editor choices.
   - Do not claim that one editor’s configuration works in another editor.
   - Create a small adapter using standard Node APIs. It must read the open buffer from stdin, write it to a uniquely created temporary file with the same extension, invoke the local `tailwind-suggest-canonical-classes` binary against that temporary file using the detected Tailwind stylesheet, print the transformed text to stdout, and always remove the temporary directory.
   - The adapter must not edit the real source file directly.
   - Configure save-time formatting only where the target editor supports chaining formatters through stdin/stdout:
     1. Biome first.
     2. The Tailwind adapter second.
   - For Zed, add project-local `.zed/settings.json` entries for JavaScript, JSX, TypeScript, TSX, and MDX. Enable `format_on_save`; chain the Biome language server before the external adapter.
   - For another editor, use that editor’s documented equivalent only if it supports this pipeline safely. Otherwise, omit save-time integration and retain the Lefthook enforcement and manual canonical commands.

6. Remove obsolete Prettier configuration and dependencies only if this repository used them solely for Tailwind canonicalisation. Do not remove Prettier if another established workflow still needs it.

7. Update repository documentation or code standards to explain that:
   - Biome handles formatting.
   - The standalone Tailwind CLI handles canonical class rewrites after Biome.
   - Lefthook enforces the same sequence on staged files.

8. Verify the implementation:
   - Confirm a representative class such as `mt-[16px]` becomes `mt-4` through the adapter.
   - Run the project’s relevant lint, canonical-check, and type-check commands.
   - Report any pre-existing or environment-only failures separately.
   - Do not commit changes unless explicitly asked.

At the end, summarise the files changed, the detected Tailwind stylesheet path, the final save-time order, and the final pre-commit order.