chore(layering): document R12/R18/R19, retire R8, make R9 shrink mandatory (#1781 A6)
Follow-through on the #1781 A6 review of check:layering. The verdict was KEEP in full — 15/15 planted violations fired, no other enforcer exists for import direction (tsconfig has no project references, oxlint restricts one module in one directory), and every numeric baseline movement in 65 commits of history is a lowering except one raise (#1590). Four small actions came out of it; three are code, one is a sentence in an ADR.
Gate-level four lines (after this change)
- Catches: import-direction and ownership claims no compiler, bundler, or package manager can see — value/type cycles, spine back-edges, static-vs-dynamic platform loading, per-file mutable-state ownership, relative tunnelling around an
exportsmap, and "the retired route is really gone" absence claims for 16 command cutovers. - Evidence: 15/15 planted violations fired during the review. Two more planted probes for this PR: raising the R9 baseline back to 47 fails with
dropped to 46 files (baseline 47), and ascripts/file importing../packages/kernel/src/errors.tsnow fails R11 where the retired R8 exception used to admit it. - Cost: 9.9 s wall (6.7 s checker + 3.2 s unit suite), 10,024 LOC of which 5,173 are tests — now ~9,750 with
zero-dep-jobs.tsgone. The cost is concentrated: theruntime-command-cutoverfamily is ~3,264 LOC (33%) serving one in-flight migration, which is why item 4 gives it an expiry. - Kill-criterion: retire the gate only if TypeScript project references (or an equivalent physical split) are adopted for the
src/zone spine and every zone becomes its own package, at which point R2/R3/R5/R11 become resolution errors. Retire individual cutover rows when ADR 0019 declares that command's migration closed.
Per-rule verdict (condensed)
| Rule | Verdict |
|---|---|
| R2 commands-floor | KEEP — planted commands/ import from core/ fired; no tsconfig/lint equivalent |
| R3 platforms-seam | KEEP — kind-sensitivity (static vs type-only vs dynamic) is unrepresentable in TS |
| R4 value-import-cycles | KEEP — TS permits value cycles; no import/no-cycle in the oxlint config |
| R5 back-edges | KEEP — planted spine back-edge fired |
| R6 type-spine-inversions | KEEP — type-only edges are invisible to every runtime tool |
| R7 session-state-ownership | KEEP — the store hands out a live mutable record; TS cannot scope writes by file |
| R8 zero-dep-job-closure | RETIRED here — zero jobs set install-deps: false; invariant has no subjects |
| R9 type-cycle-size | KEEP — shrink now mandatory (was growth-only with a suggestion) |
| R10 daemon-modularity | KEEP — per-zone ceilings + equality-pinned R7 counts |
| R11 package-boundaries | KEEP — Node blocks an undeclared specifier, not a relative tunnel |
| R12 bin-alias-fast-path | KEEP — now documented; the decoy-call case is exactly what types cannot see |
| R13 platform-package-policy | KEEP — oxlint's child_process ban covers src/**, not packages/** |
| R14–R17, R20–R31 cutover | KEEP — repo-wide absence claims; expiry condition now stated in ADR 0019 §6 |
| R16 record-runtime-registry-join | KEEP — planted deletion of the assertion fired |
| R18 contracts-implementation-authority | KEEP — now documented; fs/timers/timer calls have no other owner |
| R19 selector-pipeline-ownership | KEEP — now documented; exports publishes the subpath to every consumer |
| rule-id registry (test-only) | KEEP — empty KNOWN_RULE_ID_COLLISIONS, stale allowances fail closed |
What changed
1. Documented R12, R18, R19. Three live rules had no ADR/CONTEXT anchor — only a comment in their own policy module, which does not survive the person who wrote it. Each now has a bullet in CONTEXT.md's layering list, in the same place and voice as R7/R9/R10/R13, stating the invariant and the rule id.
2. Retired R8 zero-dep-job-closure. grep 'install-deps: false' .github/workflows returns nothing, and ci.yml (~L114) explicitly says to keep install-deps enabled on the layering guard and the Maestro conformance job. A rule with no subjects is not quiet, it is unemployed — and "the invariant is gone" is the one legitimate retirement reason under the A6 rule. Removed: scripts/layering/zero-dep-jobs.ts (278 LOC), its test block in model.test.ts, the LAYERING_RULE_IDS entry, and the doc mentions. R1 was retired the same way at #1490, and this follows that convention: the retirement is recorded in check.ts's header comment next to R1's, saying both numbers are spent so a new rule takes the next free id rather than reusing them.
R11's relative-into-packages/ exception was coupled to R8 — it required membership in an actual zero-dep closure, on the reasoning that no node_modules means specifier and relative loads cannot coexist and dual-instantiate. With no zero-dep job the closure is always empty, so the exception was already dead code; it retires with R8 and checkRootSites loses the parameter. Its test is replaced by one proving a scripts/ file gets no relative route either.
3. R9 shrink is now mandatory. daemon-modularity.ts reported the largest type cycle at 46 against a 47 baseline and only suggested lowering it in the success line. That is a ceiling accumulating quiet headroom the next change spends without a reviewer seeing a number move. R9 is now an equality pin, like TYPE_INVERSION_BASELINE (R6) and the R10 writer/owner counts already are: a baseline above the measured value fails with a message naming the constant and the delta. The committed baseline drops to the measured 46 (daemon-server ceiling 17 → 16, the one zone under its ceiling) so the gate is green in the same PR.
4. Cutover family expiry. ADR 0019 §6, where the runtime-command-cutover gate is specified, now states that each row is deleted in the change where the ADR declares that command's migration closed, and that the table must never outlive the migration. No code change — these 16 rows are ~33% of the gate's LOC and needed a stated end, not a deletion today.
Test plan
pnpm check:layering— 174 tests pass, checker green; success line now reportsthe largest type-level cycle is 46 files (R9)with no R8 clause.- Planted probe (reverted):
'daemon-server': 16→17⇒[R9 type-cycle-size] the largest type-level import cycle dropped to 46 files (baseline 47). Lower LARGEST_TYPE_CYCLE_ZONE_CEILINGS by the same 1 …. - Planted probe (reverted):
scripts/a6-probe-tunnel.tsimporting../packages/kernel/src/errors.ts⇒[R11 package-boundaries] bypasses the package boundary. Under the old R8 exception an exports-named target from a zero-dep closure was admitted; there is no closure left to be in. - New unit test
R9 rejects a baseline left above the measured cyclepins the stale-high failure; the existing zone-ceiling test now trades members between zones so it probes the per-zone claim alone rather than the total. pnpm format:check,pnpm lint,pnpm typecheck,pnpm depgraph:test,pnpm check:gate-manifest:test,pnpm check:gate-manifestall green.pnpm check:production-exportsreports the same 17 pre-existing unused exports asmain(none inscripts/).
Note on the rule name
R9 was named type-cycle-growth. Now that it fails in both directions, a CI annotation reading Layering drift (R9 type-cycle-growth):: … dropped to 46 files contradicts itself, so the rule is renamed to R9 type-cycle-size (two call sites plus the CONTEXT.md heading). The id is unchanged, and rule-ids.test.ts still sees one name per number.