@vwala/tooling-config 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,10 @@ Each tool gets a folder under `src/`:
6
6
 
7
7
  ```text
8
8
  src/
9
+ ├── _scripts/ Convention-check runner + git helpers
10
+ │ └── check-conventions.mjs
11
+ ├── agent-files/ Agent skill + brief layout policy (consumed via npm)
12
+ │ └── _scripts/
9
13
  ├── biome/ Biome config + custom GritQL rules (consumed via npm)
10
14
  │ ├── biome.config.json
11
15
  │ └── plugins/
@@ -13,6 +17,13 @@ src/
13
17
  │ ├── action.yml
14
18
  │ ├── commitlint.config.js
15
19
  │ └── hooks/
20
+ ├── context/ Module domain-language policy (consumed via npm)
21
+ │ └── _scripts/
22
+ ├── monorepo/ Package-manifest conventions (consumed via npm)
23
+ │ └── _scripts/
24
+ │ └── check-exports.mjs
25
+ ├── syncpack/ pnpm catalog policy (consumed via npm)
26
+ │ └── syncpack.config.json
16
27
  ├── typescript/ tsconfig presets (consumed via npm)
17
28
  │ ├── base.json
18
29
  │ ├── bundler.json
@@ -52,30 +63,205 @@ Anything you add alongside `extends` overrides the shared config for that key.
52
63
 
53
64
  ### Rules
54
65
 
55
- On top of Biome's `recommended` preset, four GritQL plugins enforce Vwala conventions:
66
+ Biome's own rules carry the [naming](#naming) and [export](#exports) conventions. On top of its `recommended` preset, six GritQL plugins cover what no built-in rule expresses:
56
67
 
57
68
  | Plugin | Enforces |
58
69
  | --- | --- |
59
70
  | `no-uuid-type-assertion` | No `as Uuid` / `as unknown as Uuid` — parse with `uuid()`, `newUuid()` or `zUuid` instead of manufacturing the brand. Production code only. |
60
71
  | `no-vwala-class-prefix` | No `vwala:` Tailwind prefix in apps — it only resolves inside the design system's precompiled stylesheet. Apps only. |
72
+ | `use-alias-imports` | No relative import crossing two or more parent directories (`../../`) — reach it through the project's configured alias. A single `../` to a sibling folder stays fine. Warns only. |
61
73
  | `use-given-when-then-test-names` | Every `test(...)` title reads GIVEN … WHEN … THEN … |
74
+ | `use-pnpm-scripts` | No `npm run` / `npx` / `yarn` in a script — use `pnpm run`, `pnpm dlx`. `package.json` only. |
62
75
  | `use-tests-folder-location` | Test files live in a `__tests__/` folder, never colocated with the implementation. |
63
76
 
64
77
  Each plugin file carries a header comment explaining the rule and linking to the governing reference in the [`vwala-conventions`](https://github.com/vwala-be/skills) skill. The plugins have tests in `src/biome/plugins/__tests__/` that drive the real Biome binary over fixture workspaces, so a rule that silently stops matching fails CI.
65
78
 
79
+ ### Naming
80
+
81
+ Two of Biome's own rules carry the naming convention, both at `warn`:
82
+
83
+ | Rule | Enforces |
84
+ | --- | --- |
85
+ | `useFilenamingConvention` | Filenames are kebab-case. Every dot-separated part counts, so `payment.service.ts`, `complete-invoice.command-handler.ts`, `invoice.types.ts` and `invoice.test.ts` all pass while `paymentService.ts` does not. |
86
+ | `useNamingConvention` | `camelCase` variables and functions, `PascalCase` types, classes, interfaces and components, `CONSTANT_CASE` for module-level constants. |
87
+
88
+ They are warnings because the convention applies to new code and asks that existing files be renamed only when meaningfully touched — a repository does not have to rename its way in. `useNamingConvention` deliberately does not check object literal or type properties: those keys are usually dictated by an external payload rather than chosen. `strictCase` is off, so `HTTPServer` is accepted alongside `HttpServer`.
89
+
90
+ `check-naming` (see [Convention checks](#convention-checks)) supplies the two halves the rules cannot express — folder names, which Biome never sees, and an error for files **added since the base ref**, which no static severity can express. Existing offenders are printed as warnings and leave the exit code at 0; a new file or a new folder that breaks the convention exits 1. The base ref defaults to `origin/main` — set `NAMING_BASE_REF` for a differently named default branch, and note that a shallow CI clone that cannot resolve it degrades the check to warnings only, so fetch enough history for `git merge-base` to work.
91
+
92
+ `__tests__`, `__mocks__`, `_scripts`, hidden folders, and the `[slug]` / `(group)` / `@slot` segments Next.js and Expo give meaning to are exempt from the folder check.
93
+
94
+ ### Exports
95
+
96
+ Entry points are declared in a package's `package.json` `exports`, not assembled by a barrel that re-exports the world. A feature's own `index.ts` is a different thing — an internal boundary, and one [`vwala-engineering-principles`](https://github.com/vwala-be/skills) requires — so nothing here touches it. Three of Biome's own rules carry the syntax half:
97
+
98
+ | Rule | Level | Enforces |
99
+ | --- | --- | --- |
100
+ | `noReExportAll` | error | No `export * from` — it hides name collisions, defeats tree-shaking, and re-exports whatever the target adds next. Name what you re-export. |
101
+ | `useExportType` | error | Type-only exports use `export type`, so a compiler can drop them without resolving them. |
102
+ | `noPrivateImports` | error | The `@package` and `@private` JSDoc tags are boundaries, not documentation. |
103
+
104
+ All three are errors, which is a departure from the [naming](#naming) rules and deliberate. `useExportType` has a safe autofix, so `biome check --write` clears every existing occurrence and there is no migration to protect against. `noPrivateImports` cannot flag pre-existing code at all: visibility defaults to public, so a diagnostic only exists once someone writes a tag — and a tag you are allowed to ignore is a comment. `noReExportAll` is the one with real remediation cost, but the fix is local to the barrel and changes no importer, which is what separates it from a rename.
105
+
106
+ **`noBarrelFile` is deliberately not enabled.** It flags *named* re-exports too, not just `export *`, which would put it in direct conflict with the feature-first rule that every feature exposes an `index.ts` as its public boundary. The turborepo advice it comes from is about the *package* level — don't make consumers import one giant barrel — and that is enforced by [package exports](#package-exports) instead, where it belongs.
107
+
108
+ **`test-support.ts` may re-export everything.** A package that publishes a `"./test-support"` subpath needs one file to point at, so that filename is exempt from `noReExportAll` — the same exception `check-test-layout` makes when it lets that file import test code.
109
+
110
+ **`noPrivateImports` turns on Biome's project scanner**, which indexes your project *and* its dependencies, including paths `files.includes` excludes. If lint time grows, force-ignore your build output the way this config already force-ignores `.agents`: `"!!**/dist"`, `"!!**/.next"`. Note there is no exemption for test files: `@package` visibility already reaches a `__tests__/` subfolder, and a test reaching for a `@private` symbol is the thing the rule is meant to catch.
111
+
66
112
  ### Test layout boundaries
67
113
 
68
- `use-tests-folder-location` can only check syntax — a GritQL plugin cannot see its own file path. The path-level halves of that convention (no `tests/` folder, no non-test files in `__tests__/`, no production code importing test code) live in a script you run yourself:
114
+ `use-tests-folder-location` can only check syntax — a GritQL plugin cannot see its own file path. The path-level halves of that convention — no `tests/` folder, no non-test files in `__tests__/`, no production code importing test code — are the second of the [convention checks](#convention-checks).
115
+
116
+ ---
117
+
118
+ ## Convention checks
119
+
120
+ Some conventions are about paths and manifests rather than syntax, and Biome reasons about syntax. Those live in scripts, behind one entry point:
121
+
122
+ ```jsonc
123
+ {
124
+ "scripts": {
125
+ "check-conventions": "node node_modules/@vwala/tooling-config/src/_scripts/check-conventions.mjs"
126
+ }
127
+ }
128
+ ```
129
+
130
+ | Check | Enforces |
131
+ | --- | --- |
132
+ | `naming` | Folders are kebab-case, and a file added since the base ref is named kebab-case — the error half of the [naming](#naming) rules. |
133
+ | `test layout` | The path-level halves of [test layout boundaries](#test-layout-boundaries). |
134
+ | `pnpm` | The halves of the [package manager](#package-manager) convention Biome cannot see — lockfiles, `packageManager`, and the invocations in hooks, workflows and Dockerfiles. |
135
+ | `package exports` | Every `packages/**` manifest declares an `exports` map of explicit subpaths, with no legacy `main`/`module`/`types` and no dangling targets — see [package exports](#package-exports). |
136
+ | `agent skills` | [`.agents/skills/` is the only copy](#agent-skills); other agent directories mirror it with symlinks. |
137
+ | `agent docs` | [`CLAUDE.md` is a symlink to `AGENTS.md`](#agent-briefs), never a second copy. |
138
+ | `module context` | [Every module under `packages/modules/` declares its domain language](#module-glossaries) in `CONTEXT.md`. |
139
+
140
+ Wire that single script into your own preflight and new checks arrive with an upgrade, rather than as another `&&` you have to add by hand. It runs every check even after one fails — a bad filename and a misplaced test are independent problems, and seeing both in one run beats fixing one to discover the other. Each check is still a standalone script under `src/**/_scripts/` if you want to run one on its own.
141
+
142
+ Every check reads the repository through `git`, so run this from the repository root — and in CI, from a checkout deep enough for `git merge-base` to reach the default branch. With `actions/checkout` that means `fetch-depth: 0`; on a shallow clone the naming check cannot tell a new file from an old one and silently reports everything as a warning.
143
+
144
+ The three checks below read the index rather than the working tree — `git ls-files --stage` reports mode `120000` for a symlink on every platform, while `fs.lstat` reports a regular file for every symlink in a repository cloned on Windows without developer mode.
145
+
146
+ > Upgrading into `agent skills` or `agent docs` will fail a repository that currently keeps a copied `.claude/skills/` tree or a second `CLAUDE.md`. That failure is the point, but it arrives with the upgrade rather than with an edit — fix it by replacing the copies with symlinks before wiring the new version in.
147
+
148
+ ### Package exports
149
+
150
+ A shared package's entry points are its `exports` map — one explicit subpath per entry point, so an importer reaches `@vwala/platform-ui/button` and pulls in one file rather than a barrel that drags the whole package along.
151
+
152
+ Scope is two rules, because "must have an exports map" and "the map must be well formed" are different questions:
153
+
154
+ - Only `packages/**` has to **have** an `exports` map and a scoped `@org/name`. An app under `apps/` is bundled by Next or Expo and imported by nobody, so an entry-point map would be ceremony; the workspace root is not a package at all. Neither is ever reported for a missing one.
155
+ - **Any** manifest that declares `exports` has its shape checked, wherever it lives — no `main`/`module`/`types` beside it (Node and TypeScript both resolve through `exports` and ignore them, so they can only go stale), keys that are real subpaths rather than conditions, no `./*` wildcard, and every target resolving to a file. That is also what makes this package check its own root manifest.
156
+
157
+ Detection is by path rather than by `private`, because `private` does not separate the two — an app and an internal package are both routinely private. It is a prefix rather than `packages/*/`, because the layout [`vwala-conventions`](https://github.com/vwala-be/skills) mandates nests a category: `packages/<tooling|modules|platform>/<name>/`.
158
+
159
+ A target is skipped when git ignores it, which is how `"./dist/button.js"` in a compiled package passes before `turbo build` has ever run. The flip side: a build output that nothing in `.gitignore` covers reads as a broken path.
160
+
161
+ Severity follows age, like [naming](#naming): an `exports` map is a published contract, and migrating one means updating every importer, so it cannot be a drive-by. A manifest **added or modified** since the base ref is an error, everything else a warning. The "or modified" is the difference from the naming check — a filename can only be wrong the day it is created, while a manifest field can be wrong at any edit, and the commonest real breakage is a typo in a subpath added to a manifest that already existed. Set `EXPORTS_BASE_REF` when the default branch is not `origin/main`.
162
+
163
+ Three things it deliberately leaves alone. A `"."` root export is fine — a feature's `index.ts` is its documented public boundary, so a package exporting only `"."` is following a convention rather than breaking one, and whether a given package should have one entry point or five is a review judgement, not a pattern. `"./package.json"` and `"./test-support"` are ordinary subpaths; the latter is the export [test layout boundaries](#test-layout-boundaries) explicitly sanctions. And the `@vwala/platform-*` / `module-*` / `tooling-*` prefix is a separate convention — only the `@org/` scope is checked here.
164
+
165
+ ### Agent skills
166
+
167
+ `.agents/skills/` is the only place a skill is stored. Every other agent directory — `.claude/skills/`, `.cursor/skills/`, and the rest — holds symlinks into it.
168
+
169
+ The failure this prevents is silent. `npx skills update` rewrites `.agents/skills/`; a materialised copy under `.claude/skills/` is untouched and stays the version the agent actually loads. Nothing errors, no diff looks wrong, and the agent quietly follows guidance that was replaced months ago. A symlink cannot drift, which is why the convention is a symlink rather than a sync step.
170
+
171
+ ```bash
172
+ ln -s ../../.agents/skills/vwala-conventions .claude/skills/vwala-conventions
173
+ ```
174
+
175
+ A symlink must resolve to exactly `.agents/skills/<its own name>`. Requiring the exact path rather than a prefix rejects a link into another mirror, a link reaching inside a skill, and a link whose name disagrees with the skill it points at. Symlinks are also banned *inside* `.agents/skills/` — if the source of truth is itself a link, every mirror points at nothing.
176
+
177
+ Scope is only the `skills/` subtree of each agent directory. `.claude/settings.json`, `.claude/commands/` and `.claude/agents/` are genuinely Claude's own and have no `.agents/` counterpart, so they are never flagged. Dot-prefixed entries such as `.gitkeep` are skipped too.
178
+
179
+ Mirror completeness is deliberately **not** checked. Agent directories are opt-in per tool, and a repository that only uses Claude should not be made to create a `.cursor/` it will never read.
180
+
181
+ ### Agent briefs
182
+
183
+ `AGENTS.md` is the brief; `CLAUDE.md` is a symlink to it.
184
+
185
+ Two real files means two briefs. They start identical, one gets edited, and from then on the instructions a reader reviews are not the instructions the agent loaded — with no error and no diff to notice, because both files are individually valid.
186
+
187
+ Both files are optional. A repository with neither passes, and so does one with only `AGENTS.md`; the rule only has something to say once a `CLAUDE.md` exists, and then it says the two must be the same file. The pairing is checked per directory, because a monorepo puts a brief next to each app or package. Vendored briefs under `.agents/` and `.claude/` are out of scope — they belong to the upstream skill.
188
+
189
+ ### Module glossaries
190
+
191
+ Every package under `packages/modules/` owns a bounded area of the business, so every one of them declares its domain language in `CONTEXT.md`.
192
+
193
+ Without it each module invents its own words for the same thing — one calls it an order, the next a purchase, the third a transaction — and the cost only shows up later, when the three have to talk to each other and nobody can say whether they mean the same thing. `packages/platform/` and `packages/tooling/` are excluded on purpose: they hold code with no domain knowledge, so they have no domain language to declare.
194
+
195
+ A module is identified by its `package.json`, at any depth. Modules nest (`packages/modules/act/enrich/`) and may be scoped (`packages/modules/@acme/invoicing/`), so every manifest counts — including one at a grouping level that has modules beneath it, because a directory carrying a manifest is a package and a package here is a module. Manifests below `node_modules/`, `src/`, `dist/`, `build/`, `__tests__/`, `test-support/` or `fixtures/` are skipped; a workspace package never has one of those as an ancestor, so excluding by folder rather than by depth is what keeps a fixture's manifest from registering as a module of its own.
196
+
197
+ Existence and non-emptiness are all that is checked. The convention asks for a glossary written as terms crystallise, and a checker that demanded headings and a minimum term count would only teach people to satisfy it with a heading and a fake term.
198
+
199
+ ---
200
+
201
+ ## Package manager
202
+
203
+ Vwala repositories install with pnpm. `use-pnpm-scripts` covers the `package.json` scripts and the `pnpm` convention check covers everything Biome cannot parse — a `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock` or `bun.lock` tracked beside `pnpm-lock.yaml`, a missing `pnpm-lock.yaml`, a root `package.json` that does not pin `"packageManager": "pnpm@<version>"`, and `npm`/`npx`/`yarn` invocations inside git hooks, workflows, shell scripts and Dockerfiles. Markdown is out of scope: documentation quotes a third party's install line as a citation, and a stale README is a review problem rather than a build-breaking one.
204
+
205
+ Two exemptions are deliberate, and both are load-bearing rather than courtesies:
206
+
207
+ - **`npm publish`, `npm view`, `npm pkg`, `npm --version`.** npm is matched on its install and run verbs, not on the bare word, because OIDC trusted publishing needs the npm CLI — this package's own release workflow runs all four.
208
+ - **`npx --no -- <bin>`.** It resolves the *locally installed* binary and refuses to fetch one, which is both the behaviour you want in a hook and what keeps zizmor's `adhoc-packages` rule quiet. Bare `npx` is still flagged, because it silently pulls from the registry.
209
+
210
+ > **A repository that deliberately uses another package manager** keeps it — switching is a dedicated change, not a drive-by. The check honours that on its own: it is a no-op unless the repository opts in by naming pnpm in `packageManager` or tracking a `pnpm-lock.yaml`. Biome cannot see a lockfile, though, so the plugin has no such escape hatch — drop its entry from your own `plugins` array.
211
+
212
+ ---
213
+
214
+ ## pnpm catalog
215
+
216
+ Every external dependency in a pnpm workspace must be declared once in the `pnpm-workspace.yaml` catalog and referenced everywhere as `catalog:`.
217
+
218
+ The rule exists because of a specific failure. `next-intl` was declared as `^4.13.2` in three apps; an install re-resolved it to `4.13.4`, which brought `use-intl@4.13.4` with it, while `platform-i18n` and `app-mobile` still pinned `use-intl@4.13.2`. Two copies of `use-intl` in the tree, and type errors that pointed everywhere except the actual cause. Nothing looked inconsistent beforehand — every declaration read `^4.13.2`. The drift arrived with a resolution, not with an edit, which is why the rule is unconditional: **a dependency used by only one package is still cataloged**, because the second use is exactly what nobody notices adding.
219
+
220
+ ```bash
221
+ pnpm add -Dw syncpack
222
+ ```
69
223
 
70
224
  ```jsonc
71
225
  {
72
226
  "scripts": {
73
- "check-test-boundaries": "node node_modules/@vwala/tooling-config/src/biome/plugins/_scripts/check-test-layout.mjs"
227
+ "check-catalog": "syncpack lint --config ./node_modules/@vwala/tooling-config/src/syncpack/syncpack.config.json"
74
228
  }
75
229
  }
76
230
  ```
77
231
 
78
- It reads tracked files from `git ls-files`, so run it from the repository root.
232
+ Run it from the repository root, and add it to the repo's `isEverythingOk`.
233
+
234
+ Syncpack has no `extends`, so this cannot be wired the way `biome.json` is — unknown top-level keys are a hard error, not a warning. If a repo needs to override something, spread the config from a `.syncpackrc.mjs` instead:
235
+
236
+ ```js
237
+ import base from "@vwala/tooling-config/syncpack" with { type: "json" };
238
+
239
+ export default { ...base };
240
+ ```
241
+
242
+ That spread is shallow: replacing `versionGroups` replaces all of them, including the exemptions the config depends on. Read the comments in `syncpack.config.json` before overriding it.
243
+
244
+ ### What is in scope
245
+
246
+ `dependencies`, `devDependencies` and `optionalDependencies`, in every workspace package **and in the root manifest** — root dependencies install a real copy too, so a root `typescript@^5.7` alongside a package's `typescript@^5.9` is the same bug in the tooling layer.
247
+
248
+ `peerDependencies` are deliberately excluded. A peer range is a compatibility statement, intentionally wide; collapsing `>=18` to `catalog:` would pin a published package to one version of its own peer. The devDependency that actually installs the copy is in scope, so nothing is lost.
249
+
250
+ `workspace:`, `link:` and `file:` specifiers are exempt — all three resolve relative to the declaring package, so there is nothing for a central catalog to hold.
251
+
252
+ ### Migrating
253
+
254
+ `syncpack fix` rewrites specifiers to `catalog:` and writes the entries into `pnpm-workspace.yaml`, preserving comments and key order.
255
+
256
+ > **It picks the winner for you.** Where two packages disagree, `fix` takes the highest range and says so only in passing. That is usually right and occasionally an unannounced major bump, so resolve the genuine disagreements by hand first, then let `fix` do the mechanical rest. Re-run `pnpm install` and typecheck afterwards.
257
+
258
+ When two packages genuinely need different versions, use a [named catalog](https://pnpm.io/catalogs) (`catalog:react18`) rather than a literal range. Note that once more than one catalog exists, every dependency must live in exactly one of them — syncpack reports anything ambiguous as an unfixable error.
259
+
260
+ ### Stopping drift at the source
261
+
262
+ Set `catalogMode: strict` in `pnpm-workspace.yaml` (pnpm >= 10.12) so `pnpm add` writes catalog entries instead of literal ranges.
263
+
264
+ > **That is not a substitute for the CI check.** `catalogMode` applies only when `pnpm add` runs. It does not re-validate existing manifests on install, so a hand-edited `package.json` or a bad merge passes straight through. The two are complementary: `catalogMode` prevents most drift, `syncpack lint` catches the rest.
79
265
 
80
266
  ---
81
267
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vwala/tooling-config",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Shared tooling configuration for Vwala repositories",
6
6
  "license": "UNLICENSED",
@@ -19,6 +19,7 @@
19
19
  "exports": {
20
20
  "./biome": "./src/biome/biome.config.json",
21
21
  "./commitlint": "./src/commitlint/commitlint.config.js",
22
+ "./syncpack": "./src/syncpack/syncpack.config.json",
22
23
  "./typescript/base": "./src/typescript/base.json",
23
24
  "./typescript/bundler": "./src/typescript/bundler.json",
24
25
  "./typescript/node": "./src/typescript/node.json",
@@ -34,9 +35,10 @@
34
35
  "format": "biome check --write .",
35
36
  "typecheck": "tsc --noEmit",
36
37
  "test": "vitest run",
38
+ "check-conventions": "node src/_scripts/check-conventions.mjs",
37
39
  "commit": "cz",
38
40
  "prepare": "husky && node src/commitlint/_scripts/install-hooks.mjs",
39
- "isEverythingOk": "biome ci . && tsc --noEmit && vitest run"
41
+ "isEverythingOk": "biome ci . && tsc --noEmit && vitest run && node src/_scripts/check-conventions.mjs"
40
42
  },
41
43
  "config": {
42
44
  "commitizen": {
@@ -58,12 +60,14 @@
58
60
  "cz-emoji-conventional": "^1.2.1",
59
61
  "husky": "^9.1.7",
60
62
  "lint-staged": "^17.0.8",
63
+ "syncpack": "^15.3.2",
61
64
  "typescript": "^7.0.2",
62
65
  "vitest": "^4.1.10"
63
66
  },
64
67
  "peerDependencies": {
65
68
  "@biomejs/biome": ">=2.5.0",
66
69
  "@commitlint/cli": ">=19",
70
+ "syncpack": ">=15.0.0",
67
71
  "typescript": ">=5.7.0"
68
72
  },
69
73
  "peerDependenciesMeta": {
@@ -73,6 +77,9 @@
73
77
  "@commitlint/cli": {
74
78
  "optional": true
75
79
  },
80
+ "syncpack": {
81
+ "optional": true
82
+ },
76
83
  "typescript": {
77
84
  "optional": true
78
85
  }
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * One entry point for every convention check that is a script rather than a
4
+ * Biome rule — so a repository wires up `check-conventions` once and keeps
5
+ * getting new checks as they ship, instead of growing another `&&` in
6
+ * `isEverythingOk` each time one is added.
7
+ *
8
+ * Unlike the `&&` chain it replaces, this runs every check even after one
9
+ * fails. A failing name and a misplaced test are independent problems, and
10
+ * seeing both in one run beats fixing one to discover the other.
11
+ *
12
+ * Each check stays runnable on its own — they are separate scripts with their
13
+ * own tests, and this only sequences them.
14
+ */
15
+ import { spawnSync } from "node:child_process";
16
+ import path from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ // `src/` — the checks are addressed from there rather than relative to this
20
+ // file, so moving a check does not mean counting `..` hops.
21
+ const sourceRoot = path.resolve(
22
+ path.dirname(fileURLToPath(import.meta.url)),
23
+ "..",
24
+ );
25
+
26
+ const CHECKS = [
27
+ { name: "naming", script: "biome/_scripts/check-naming.mjs" },
28
+ {
29
+ name: "test layout",
30
+ script: "biome/plugins/_scripts/check-test-layout.mjs",
31
+ },
32
+ { name: "pnpm", script: "biome/plugins/_scripts/check-pnpm.mjs" },
33
+ { name: "package exports", script: "monorepo/_scripts/check-exports.mjs" },
34
+ {
35
+ name: "agent skills",
36
+ script: "agent-files/_scripts/check-agent-skills.mjs",
37
+ },
38
+ { name: "agent docs", script: "agent-files/_scripts/check-agent-docs.mjs" },
39
+ {
40
+ name: "module context",
41
+ script: "context/_scripts/check-module-context.mjs",
42
+ },
43
+ ];
44
+
45
+ const failed = [];
46
+
47
+ for (const check of CHECKS) {
48
+ console.log(`\n▸ ${check.name}`);
49
+ // The checks read the repository through git, so they inherit this process's
50
+ // working directory — which is why every one of them has to be run from the
51
+ // repository root.
52
+ const { status } = spawnSync(
53
+ process.execPath,
54
+ [path.join(sourceRoot, check.script)],
55
+ { stdio: "inherit" },
56
+ );
57
+ if (status !== 0) {
58
+ failed.push(check.name);
59
+ }
60
+ }
61
+
62
+ if (failed.length > 0) {
63
+ console.error(
64
+ `\n ✖ ${failed.length} of ${CHECKS.length} convention checks failed: ${failed.join(", ")}\n`,
65
+ );
66
+ process.exit(1);
67
+ }
68
+
69
+ console.log(`\n ✔ ${CHECKS.length} convention checks passed\n`);
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Reads the git index, because the agent-file conventions are about symlinks
3
+ * and `fs.lstat` cannot be trusted to see them.
4
+ *
5
+ * On a checkout with `core.symlinks=false` — the default on Windows without
6
+ * developer mode — git materialises every symlink as a regular file whose
7
+ * contents are the target path. `lstat` reports a regular file, so a check
8
+ * built on it would fail every repository cloned on Windows while passing the
9
+ * one case it exists to catch. The index records the mode git actually tracks:
10
+ * `120000` for a symlink, `100644` or `100755` for a regular file, on every
11
+ * platform.
12
+ *
13
+ * A symlink's target is the blob's contents, so `git cat-file blob <sha>`
14
+ * reads it without touching the working tree either.
15
+ */
16
+ import { execFileSync } from "node:child_process";
17
+ import path from "node:path";
18
+
19
+ const MAX_BUFFER = 1024 * 1024 * 64;
20
+ const WINDOWS_ABSOLUTE = /^[A-Za-z]:[\\/]/;
21
+
22
+ export const SYMLINK_MODE = "120000";
23
+
24
+ /**
25
+ * Every tracked path with the mode git records for it.
26
+ *
27
+ * `-z` because `core.quotePath` is on by default, so without it a path holding
28
+ * a space or a non-ASCII character comes back C-quoted and a check that splits
29
+ * it naively reports a violation nobody can locate.
30
+ *
31
+ * Entries at a stage other than 0 are the three sides of an unresolved merge
32
+ * conflict. They repeat the same path with different modes, which would report
33
+ * one file as several violations, so mid-conflict the working copy is what
34
+ * matters and those are skipped.
35
+ */
36
+ export function readIndexEntries() {
37
+ const output = execFileSync("git", ["ls-files", "--stage", "-z"], {
38
+ encoding: "utf8",
39
+ maxBuffer: MAX_BUFFER,
40
+ });
41
+
42
+ return output
43
+ .split("\0")
44
+ .filter(Boolean)
45
+ .map((record) => {
46
+ // `<mode> <sha> <stage>\t<path>`
47
+ const separator = record.indexOf("\t");
48
+ const [mode, sha, stage] = record.slice(0, separator).split(" ");
49
+ return { mode, sha, stage, path: record.slice(separator + 1) };
50
+ })
51
+ .filter((entry) => entry.stage === "0");
52
+ }
53
+
54
+ /**
55
+ * The blob's contents verbatim. Git stores a symlink target with no trailing
56
+ * newline, so this is not trimmed — a target that needs trimming is itself the
57
+ * bug, and the caller rejects it rather than papering over it.
58
+ */
59
+ export function readBlob({ sha }) {
60
+ return execFileSync("git", ["cat-file", "blob", sha], {
61
+ encoding: "utf8",
62
+ maxBuffer: MAX_BUFFER,
63
+ });
64
+ }
65
+
66
+ /**
67
+ * Where a symlink points, as a repository-relative path, or `null` when the
68
+ * target is not a usable path inside the repository.
69
+ *
70
+ * Targets are relative to the symlink's own directory rather than to the
71
+ * repository root, so `.claude/skills/foo -> ../../.agents/skills/foo` only
72
+ * resolves once joined with `.claude/skills`. Git paths always use forward
73
+ * slashes, so `path.posix` is right even on Windows.
74
+ *
75
+ * The order of the guards matters. `path.posix.join` does not reset on a
76
+ * leading slash — joining `.claude/skills` with `/etc/passwd` yields
77
+ * `.claude/skills/etc/passwd`, which would sail through every later check — so
78
+ * absolute targets have to be rejected before anything is joined.
79
+ */
80
+ export function resolveSymlinkTarget({ linkPath, target }) {
81
+ if (target === "" || target !== target.trim()) {
82
+ return null;
83
+ }
84
+
85
+ if (
86
+ path.posix.isAbsolute(target) ||
87
+ WINDOWS_ABSOLUTE.test(target) ||
88
+ target.includes("\\")
89
+ ) {
90
+ return null;
91
+ }
92
+
93
+ const resolved = path.posix.normalize(
94
+ path.posix.join(path.posix.dirname(linkPath), target),
95
+ );
96
+
97
+ if (resolved === ".." || resolved.startsWith("../")) {
98
+ return null;
99
+ }
100
+
101
+ // `normalize` preserves a trailing slash, and `.agents/skills/foo/` would
102
+ // not compare equal to the path git tracks.
103
+ return resolved.endsWith("/") ? resolved.slice(0, -1) : resolved;
104
+ }
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `AGENTS.md` is the brief; `CLAUDE.md` is a symlink to it.
4
+ *
5
+ * Two real files means two briefs. They start identical, one gets edited, and
6
+ * from then on the instructions a reader reviews are not the instructions the
7
+ * agent loaded — with no error and no diff to notice, because both files are
8
+ * individually valid. A symlink makes the second copy impossible.
9
+ *
10
+ * Both files are optional. A repository with neither passes, and so does one
11
+ * with only `AGENTS.md` — the rule only has something to say once a `CLAUDE.md`
12
+ * exists, and then it says the two must be the same file.
13
+ *
14
+ * This is checked per directory rather than at the root, because a monorepo
15
+ * puts a brief next to each app or package and the pairing has to hold for all
16
+ * of them.
17
+ *
18
+ * Biome cannot express this. Whether a path is a symlink, and what it points
19
+ * at, are properties of the index rather than of any file's syntax.
20
+ */
21
+ import {
22
+ readBlob,
23
+ readIndexEntries,
24
+ resolveSymlinkTarget,
25
+ SYMLINK_MODE,
26
+ } from "../../_scripts/git-index.mjs";
27
+
28
+ // Vendored skills ship their own `AGENTS.md` and `CLAUDE.md`. They belong to
29
+ // the upstream skill, are read-only here, and are not this repository's brief.
30
+ const IGNORED_PREFIXES = [".agents/", ".claude/"];
31
+ const AUTHORITATIVE = "AGENTS.md";
32
+ const ALIAS = "CLAUDE.md";
33
+
34
+ const entries = readIndexEntries();
35
+ const byPath = new Map(entries.map((entry) => [entry.path, entry]));
36
+ const violations = [];
37
+
38
+ const aliases = entries.filter(
39
+ (entry) =>
40
+ (entry.path === ALIAS || entry.path.endsWith(`/${ALIAS}`)) &&
41
+ !IGNORED_PREFIXES.some((prefix) => entry.path.startsWith(prefix)),
42
+ );
43
+
44
+ for (const alias of aliases) {
45
+ const directory = alias.path.slice(0, -ALIAS.length);
46
+ const authoritativePath = `${directory}${AUTHORITATIVE}`;
47
+
48
+ if (alias.mode !== SYMLINK_MODE) {
49
+ violations.push(
50
+ `${alias.path}\n Regular file. ${ALIAS} must be a symlink to ${authoritativePath}.`,
51
+ );
52
+ continue;
53
+ }
54
+
55
+ const target = readBlob({ sha: alias.sha });
56
+ const resolved = resolveSymlinkTarget({ linkPath: alias.path, target });
57
+
58
+ if (resolved === null) {
59
+ violations.push(
60
+ `${alias.path}\n Symlink target ${JSON.stringify(target)} is not a usable path inside the repository.`,
61
+ );
62
+ continue;
63
+ }
64
+
65
+ if (resolved !== authoritativePath) {
66
+ violations.push(
67
+ `${alias.path}\n Symlink resolves to "${resolved}" but must resolve to "${authoritativePath}".`,
68
+ );
69
+ continue;
70
+ }
71
+
72
+ const authoritative = byPath.get(authoritativePath);
73
+
74
+ if (authoritative === undefined) {
75
+ violations.push(
76
+ `${alias.path}\n Symlink target "${authoritativePath}" is not tracked. The brief it points at does not exist.`,
77
+ );
78
+ continue;
79
+ }
80
+
81
+ // A chain of symlinks has the same problem as a copy: the file you edit is
82
+ // not obviously the file that gets loaded.
83
+ if (authoritative.mode === SYMLINK_MODE) {
84
+ violations.push(
85
+ `${authoritativePath}\n Symlink. ${AUTHORITATIVE} is the authoritative file and must be a real file.`,
86
+ );
87
+ }
88
+ }
89
+
90
+ if (violations.length > 0) {
91
+ console.error(`\n ✖ ${violations.length} agent-docs violation(s):\n`);
92
+ for (const violation of violations) {
93
+ console.error(` ${violation}\n`);
94
+ }
95
+ process.exit(1);
96
+ }
97
+
98
+ console.log(" ✔ agent docs clean");