@webpieces/ai-hook-rules 0.4.802 → 0.4.803
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/package.json +2 -2
- package/src/core/l1-rows.js +1 -1
- package/src/core/l1-rows.js.map +1 -1
- package/src/core/version-sync.d.ts +14 -10
- package/src/core/version-sync.js +20 -15
- package/src/core/version-sync.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/ai-hook-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.803",
|
|
4
4
|
"description": "Pluggable write-time validation framework for AI coding agents (@webpieces/ai-hook-rules). Claude Code PreToolUse + openclaw before_tool_call adapters share one rule engine.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/tooling/ai-hook-rules"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@webpieces/rules-config": "0.4.
|
|
28
|
+
"@webpieces/rules-config": "0.4.803",
|
|
29
29
|
"inversify": "7.10.4",
|
|
30
30
|
"reflect-metadata": "0.2.2"
|
|
31
31
|
},
|
package/src/core/l1-rows.js
CHANGED
|
@@ -200,7 +200,7 @@ exports.L1_ROWS = [
|
|
|
200
200
|
// re-point every historical reference. Its replacement is row 8.
|
|
201
201
|
new L1Row(8, 'w', 'n', 'n', '-', '-', exports.ACT_BLOCK, 'this worktree pins a DIFFERENT @webpieces than the main tree that governs it', new L1Cure('align the pins (same git hash -> same tracked pin -> install in each tree), work in the main tree, or use a separate clone', '@webpieces version SKEW', false), 'trinary-version-skew', [
|
|
202
202
|
new L1UseCase(12, 'a worktree on an older branch pins `0.4.612` while the main tree runs `0.4.616`, and `cd <wt> && pnpm build` is blocked', '`w` / `n` / `n` — row 8', 'BLOCK_AI_CURE', 'Option 1 (preferred): the MAIN tree is AHEAD, so this is YOURS and it is a one-line edit — raise THIS tree\'s catalog pin in `pnpm-workspace.yaml` to what main already runs, then `pnpm install` here if this tree has a node_modules. That edit is on the L0 allowlist, so it is typable while the block is up, and nothing has to move in the main tree<br>Option 2: do the work in the main tree, which this guard never blocks<br>Option 3: if the tree genuinely needs a DIFFERENT version, use a separate CLONE — a clone gets its own governance. That is the answer to "I need a different version", never to "I need to install here": a worktree MAY have its own node_modules (nx, vitest and the eslint plugin all load from it), it just may not hold a different @webpieces version<br>Do NOT: lower the MAIN tree\'s pin to match — that downgrades every tree, including this session\'s own governor. And do NOT reach for `pnpm install` BEFORE the edit: this tree\'s pin is the stale side, so installing first materializes the OLD release', new L1Classification('w', true, false, false, false)),
|
|
203
|
-
new L1UseCase(16, 'a SUBAGENT hits the same block inside `.claude/worktrees/agent-XXXX`', '`w` / `n` / `n` — row 8; in-repo placement is still `w`', 'BLOCK_AI_CURE', 'READ THE DIRECTION FIRST — the deny prints it. If the MAIN tree is AHEAD (the common case) a subagent fixes this ITSELF, here, by raising this tree\'s pin to what main already runs; there is nothing to escalate and the deny prints no escalation. Only when main is BEHIND, or when this branch bumped the pin on purpose, is the subagent stuck — the main tree is outside its tree, and a worktree-isolated agent may not even still be in the tree it was launched in (measured: auto-reaped at a turn boundary, resumed on the primary). Then, and only then, forward the deny\'s verbatim ask to the coordinator and
|
|
203
|
+
new L1UseCase(16, 'a SUBAGENT hits the same block inside `.claude/worktrees/agent-XXXX`', '`w` / `n` / `n` — row 8; in-repo placement is still `w`', 'BLOCK_AI_CURE', 'READ THE DIRECTION FIRST — the deny prints it. If the MAIN tree is AHEAD (the common case) a subagent fixes this ITSELF, here, by raising this tree\'s pin to what main already runs; there is nothing to escalate and the deny prints no escalation. Only when main is BEHIND, or when this branch bumped the pin on purpose, is the subagent stuck — the main tree is outside its tree, and a worktree-isolated agent may not even still be in the tree it was launched in (measured: auto-reaped at a turn boundary, resumed on the primary). Then, and only then, forward the deny\'s verbatim ask to the coordinator, and do NOT retry the blocked call — it re-fires the identical deny and buries the ask<br>Do NOT: expect exemption because it sits under the repo — K is git\'s `--git-common-dir` answer, not a path test', new L1Classification('w', true, false, false, false)),
|
|
204
204
|
]),
|
|
205
205
|
new L1Row(4, 'pw', '-', '-', 'n', '-', exports.ACT_DOWN, 'force-to-root has no jurisdiction', null, null, [
|
|
206
206
|
new L1UseCase(5, '`ls` from `packages/http/` runs normally', '`pw` / `n` / - — row 4', 'ALLOW (handed to L2)', 'none — force-to-root has no jurisdiction over non-git commands', new L1Classification('p', false, true, false, false)),
|
package/src/core/l1-rows.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l1-rows.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/l1-rows.ts"],"names":[],"mappings":";;;AAqXA,sCAGC;AAUD,gDAIC;AAjVD;;;;;;;;;;;GAWG;AACU,QAAA,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;GAKG;AACH,MAAa,gBAAgB;IAGZ;IACA;IACA;IACA;IACA;IANb,kGAAkG;IAClG,YACa,IAAY,EACZ,cAAuB,EACvB,QAAiB,EACjB,GAAY,EACZ,MAAe;QAJf,SAAI,GAAJ,IAAI,CAAQ;QACZ,mBAAc,GAAd,cAAc,CAAS;QACvB,aAAQ,GAAR,QAAQ,CAAS;QACjB,QAAG,GAAH,GAAG,CAAS;QACZ,WAAM,GAAN,MAAM,CAAS;IACzB,CAAC;IAEJ;;;;;;;;;;OAUG;IACH,oGAAoG;IACpG,kMAAkM;IAClM,MAAM,CAAC,cAAc,CACjB,QAAkB,EAClB,cAAuB,EACvB,QAAiB,EACjB,GAAY,EACZ,MAAe;QAEf,MAAM,IAAI,GAAW,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG;YAC7C,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG;gBAC9B,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,GAA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C3G,+FAA+F,EAC/F,cAAc,EACd,oFAAoF,CAAC;IACzF,IAAI,SAAS,CAAC,EAAE,EACZ,oIAAoI,EACpI,8GAA8G,EAC9G,cAAc,EACd,4JAA4J,CAAC;IACjK,IAAI,SAAS,CAAC,EAAE,EACZ,iFAAiF,EACjF,2BAA2B,EAC3B,OAAO,EACP,mDAAmD,CAAC;CAC3D,CAAC;AAEF,4FAA4F;AAC5F,0HAA0H;AAC1H,SAAgB,aAAa;IACzB,MAAM,GAAG,GAAG,CAAC,GAAG,eAAO,CAAC,OAAO,CAAC,CAAC,GAAU,EAAwB,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,4BAAoB,CAAC,CAAC;IAC9G,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAY,EAAE,CAAY,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,qGAAqG;AACrG,SAAgB,kBAAkB,CAAC,CAAmB;IAClD,MAAM,GAAG,GAAG,eAAO,CAAC,IAAI,CAAC,CAAC,CAAQ,EAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAI,GAAG,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpG,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { TreeKind } from './effective-tree';\n\n// ---------------------------------------------------------------------------\n// L1 — the LOCATION layer, as data.\n//\n// L1 answers four questions: do we govern this call at all, does the directory still EXIST, is the\n// WRONG AGENT standing here, and is the agent stranded away from the root? Drawn as a decision matrix\n// that is SEVEN ordered rows over five dimensions (K/A/R/G/P), first match wins.\n//\n// This module holds those rows, and l1-doc.ts renders them into guards/L1-location.md — the doc a human\n// reads on GitHub. A unit test locks that file byte-identical to the renderer, and the guard itself\n// CONSULTS L1_ROWS to decide which structural block fires (see runner.l1LocationBlock). Doc and code\n// come from the SAME array, so they cannot drift.\n//\n// This module is deliberately import-free at runtime (only a type-only import above), so\n// `pnpm guards:generate` can load it without the package's transitive dependencies.\n// ---------------------------------------------------------------------------\n\n/**\n * The K dimension as a CLASSIFICATION carries — one concrete tree, never the `pw` union.\n *\n * `p` and `w` are the same PROJECT and every rule-scoped guard treats them alike; the doc writes the\n * pair as `pw` in the row's MATCHER (below), which is a different vocabulary on purpose.\n */\nexport type L1Kind = 'f' | 'm' | 'o' | 'p' | 'w';\n\n/** The K value a ROW matches on. `pw` matches both `p` and `w`; `-` is the wildcard. */\nexport type L1KindMatch = 'f' | 'm' | 'o' | 'w' | 'pw' | '-';\n\n/** R and G are yes/no, written `y`/`n` in the doc, with `-` for \"does not matter\". */\nexport type L1Flag = 'y' | 'n' | '-';\n\n/**\n * V is the same one boolean wearing the doc's own letters: `n` the webpieces versions do NOT agree\n * between this worktree and the main tree, `y` they do.\n *\n * This dimension used to be A (`c` coordinator / `s` subagent). It was replaced rather than removed\n * because agent identity was measured untrustworthy as a proxy for \"which tree am I in\" — a\n * worktree-isolated agent auto-reaped at a turn boundary silently resumes on the primary clone. A\n * version read off the PATH being acted on cannot lie in that way.\n */\nexport type L1VersionSync = 'y' | 'n' | '-';\n\n/** What L1 does with a row. The labels are the doc's own action codebook (see GUARD_MATRIX.md). */\nexport type L1ActionKind = 'exempt' | 'down' | 'block';\n\n/**\n * WHICH structural block a blocking row dispatches to. This is the field that makes the array\n * load-bearing rather than decorative: runner.l1LocationBlock looks the row up and switches on it,\n * so deleting a row from the array removes the block.\n */\nexport type L1BlockId = 'trinary-version-skew' | 'force-to-root' | 'missing-directory';\n\n/**\n * The row number for L1's PRE-STAGE — `misplacedCdBlock`, which decides from command TEXT before a\n * tree has been resolved, and therefore cannot be classified over the five dimensions rows 1-6 use\n * (asking L1_ROWS to classify it would need the very resolution its answer determines).\n *\n * ZERO rather than a seventh row, deliberately. It has to appear in the table — an L1 block the\n * generated doc did not describe is precisely the drift the table exists to prevent, and it was\n * carrying a `KNOWN GAP` comment saying so. But numbering it 7 would assert it sits in the same\n * first-match scan as the others, which is the one thing that is not true about it. Row 0 says\n * \"decided before the scan\" in the number itself. `renderL1Doc()` PRINTS this row above the six, so\n * `row=0` in the L1 log joins to a line the reader can actually find.\n */\nexport const L1_PRESTAGE_ROW = '0';\n\n/**\n * One point in the five-dimensional space L1 classifies over. Data-only → a class, per CLAUDE.md.\n *\n * The dimensions are exactly the doc's legend: K (tree kind of the resolved target), V (webpieces versions in sync or\n * subagent), R (provably read-only inspection), G (invokes git/gh), P (root or subdirectory).\n */\nexport class L1Classification {\n // eslint-disable-next-line @typescript-eslint/max-params -- five dimensions is the matrix's shape\n constructor(\n readonly kind: L1Kind,\n readonly versionsSkewed: boolean,\n readonly readOnly: boolean,\n readonly git: boolean,\n readonly atRoot: boolean,\n ) {}\n\n /**\n * The classification the RUNNER enforces on, built from the resolved tree and the caller.\n *\n * `'outside'` maps to `p`, and that is not a typo. TreeKind `'outside'` is produced by\n * effective-tree.ts (git has no answer for the directory) and consumed NOWHERE, so a command in no git repo is\n * judged against the governed repo exactly as if it stood in it. Row 2 (`o` → L2) describes what\n * SHOULD happen and is deliberately unreachable from here until the \"Not done\" fix in\n * guards/L1-location.md lands — exempting `o` alone opens a `cd /tmp &&` bypass of every L2 guard,\n * so the two ship together or neither does. Mapping it to `p` here is what preserves today's\n * behaviour (a `git` command from /tmp is still force-to-root blocked); it is not an endorsement.\n */\n // eslint-disable-next-line @typescript-eslint/max-params -- mirrors the constructor it delegates to\n // webpieces-disable no-function-outside-class -- a named constructor for this data class, not a service: it takes the runner's TreeKind and returns the same class, so there is nothing to inject\n static forEnforcement(\n treeKind: TreeKind,\n versionsSkewed: boolean,\n readOnly: boolean,\n git: boolean,\n atRoot: boolean,\n ): L1Classification {\n const kind: L1Kind = treeKind === 'foreign' ? 'f'\n : treeKind === 'missing' ? 'm'\n : treeKind === 'worktree' ? 'w' : 'p';\n return new L1Classification(kind, versionsSkewed, readOnly, git, atRoot);\n }\n}\n\n/** The `act` cell of a row: the doc's literal label, plus the machine-readable kind behind it. */\nexport class L1Action {\n constructor(readonly label: string, readonly kind: L1ActionKind) {}\n}\n\nexport const ACT_EXEMPT = new L1Action('2 exempt', 'exempt');\nexport const ACT_DOWN = new L1Action('→ L2', 'down');\nexport const ACT_BLOCK = new L1Action('4 block', 'block');\n\n/**\n * The CURE a blocking row prescribes.\n *\n * `runnable` is the axis that matters to the tests: a cure that is a command must, once applied,\n * actually stop the row from matching (cure reachability). Row 3's cure is an INSTRUCTION — \"spawn a\n * subagent bound to the worktree\" — which no allowlist can accept and no reclassification can model,\n * so it declares `runnable: false` and is asserted only on the deny text.\n */\nexport class L1Cure {\n constructor(\n /** How the doc's `why` column spells it. */\n readonly summary: string,\n /** A substring that MUST appear in the deny text the guard emits for this row. */\n readonly denyMention: string,\n readonly runnable: boolean,\n ) {}\n}\n\n/**\n * One row of the \"L1 use cases\" table: what you SEE, the state it puts you in, the verdict, the fix.\n *\n * The four text fields are rendered VERBATIM into the doc. `classification` is the same case expressed\n * in the matrix's own vocabulary so the tests can run it through the matcher — it is test/enforcement\n * data, never rendered, which is why a use case that exercises the FILTER or the L0 allowlist (neither\n * of which is a row) can carry `null` there.\n */\nexport class L1UseCase {\n // eslint-disable-next-line @typescript-eslint/max-params -- four verbatim doc cells plus the classification behind them\n constructor(\n readonly num: number,\n readonly symptom: string,\n readonly state: string,\n readonly verdict: string,\n readonly fix: string,\n readonly classification: L1Classification | null = null,\n ) {}\n}\n\n/** One row of L1's decision table. Data-only → a class, per CLAUDE.md. */\nexport class L1Row {\n // eslint-disable-next-line @typescript-eslint/max-params -- five dimension cells plus act/why/cure/blockId/useCases\n constructor(\n readonly num: number,\n readonly k: L1KindMatch,\n readonly a: L1VersionSync,\n readonly r: L1Flag,\n readonly g: L1Flag,\n readonly p: 'root' | 'sub' | '-',\n readonly action: L1Action,\n /** The `why` cell, verbatim. */\n readonly why: string,\n readonly cure: L1Cure | null,\n readonly blockId: L1BlockId | null,\n readonly useCases: readonly L1UseCase[],\n ) {}\n\n matches(c: L1Classification): boolean {\n if (!this.kindMatches(c.kind)) return false;\n if (this.a !== '-' && (this.a === 'n') !== c.versionsSkewed) return false;\n if (!flagMatches(this.r, c.readOnly)) return false;\n if (!flagMatches(this.g, c.git)) return false;\n return this.p === '-' || this.p === (c.atRoot ? 'root' : 'sub');\n }\n\n private kindMatches(kind: L1Kind): boolean {\n if (this.k === '-') return true;\n if (this.k === 'pw') return kind === 'p' || kind === 'w';\n return this.k === kind;\n }\n}\n\n// R and G are one boolean each behind a `y`/`n`/`-` cell, so one helper answers for both. (A is the\n// same shape but spelled `c`/`s`, and is matched inline above so the row literals read like the doc.)\n// webpieces-disable no-function-outside-class -- pure predicate for L1Row.matches above, in this data module\nfunction flagMatches(cell: L1Flag, value: boolean): boolean {\n if (cell === '-') return true;\n return (cell === 'y') === value;\n}\n\n/**\n * THE seven L1 rows, in first-match-wins order.\n *\n * Rows 3, 5 and 7 are the structural blocks and they run as ONE step (runner.l1LocationBlock) so they\n * can never be reordered by accident. Every other row is a hand-down or an exemption, i.e. \"L1 has no\n * objection\" — which is why only those three carry a blockId.\n *\n * Row 7 (`m`, the vanished directory) sits LAST only because row numbers are stable across releases —\n * they are printed in the doc and logged as `row=`, so renumbering rows 1-6 to slot it in front would\n * silently invalidate every existing reference. Position costs nothing here: `m` is matched by no other\n * row, so first-match reaches it wherever it sits.\n */\nexport const L1_ROWS: readonly L1Row[] = [\n new L1Row(1, 'f', '-', '-', '-', '-', ACT_EXEMPT, 'different git repo — hands off', null, null, [\n new L1UseCase(1,\n '`cd repositories/vendored && git commit` goes through untouched',\n '`f` / `y` / - — row 1',\n 'ALLOW_EXEMPT',\n 'none needed — jurisdiction is judged on the RESOLVED target, after the `cd`; a different git repo is hands-off',\n new L1Classification('f', false, false, true, false)),\n ]),\n new L1Row(2, 'o', '-', '-', '-', '-', ACT_DOWN, 'see \"Not done\" below', null, null, []),\n // ROW 3 IS RETIRED — it was coordinator-in-worktree, deleted with CoordinatorWorktreeGuard when the\n // guard hooks went ABSOLUTE (one governor, so the filesystem/governance split it policed became\n // unconstructible). The NUMBER is never reused: row numbers are identity here — they are printed in\n // denies, logged as `row=`, and cited in guards/L1-location.md — so renumbering would silently\n // re-point every historical reference. Its replacement is row 8.\n new L1Row(8, 'w', 'n', 'n', '-', '-', ACT_BLOCK,\n 'this worktree pins a DIFFERENT @webpieces than the main tree that governs it',\n new L1Cure('align the pins (same git hash -> same tracked pin -> install in each tree), work in the main tree, or use a separate clone',\n '@webpieces version SKEW', false),\n 'trinary-version-skew', [\n new L1UseCase(12,\n 'a worktree on an older branch pins `0.4.612` while the main tree runs `0.4.616`, and `cd <wt> && pnpm build` is blocked',\n '`w` / `n` / `n` — row 8',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): the MAIN tree is AHEAD, so this is YOURS and it is a one-line edit — raise THIS tree\\'s catalog pin in `pnpm-workspace.yaml` to what main already runs, then `pnpm install` here if this tree has a node_modules. That edit is on the L0 allowlist, so it is typable while the block is up, and nothing has to move in the main tree<br>Option 2: do the work in the main tree, which this guard never blocks<br>Option 3: if the tree genuinely needs a DIFFERENT version, use a separate CLONE — a clone gets its own governance. That is the answer to \"I need a different version\", never to \"I need to install here\": a worktree MAY have its own node_modules (nx, vitest and the eslint plugin all load from it), it just may not hold a different @webpieces version<br>Do NOT: lower the MAIN tree\\'s pin to match — that downgrades every tree, including this session\\'s own governor. And do NOT reach for `pnpm install` BEFORE the edit: this tree\\'s pin is the stale side, so installing first materializes the OLD release',\n new L1Classification('w', true, false, false, false)),\n new L1UseCase(16,\n 'a SUBAGENT hits the same block inside `.claude/worktrees/agent-XXXX`',\n '`w` / `n` / `n` — row 8; in-repo placement is still `w`',\n 'BLOCK_AI_CURE',\n 'READ THE DIRECTION FIRST — the deny prints it. If the MAIN tree is AHEAD (the common case) a subagent fixes this ITSELF, here, by raising this tree\\'s pin to what main already runs; there is nothing to escalate and the deny prints no escalation. Only when main is BEHIND, or when this branch bumped the pin on purpose, is the subagent stuck — the main tree is outside its tree, and a worktree-isolated agent may not even still be in the tree it was launched in (measured: auto-reaped at a turn boundary, resumed on the primary). Then, and only then, forward the deny\\'s verbatim ask to the coordinator and STOP<br>Do NOT: expect exemption because it sits under the repo — K is git\\'s `--git-common-dir` answer, not a path test',\n new L1Classification('w', true, false, false, false)),\n ]),\n new L1Row(4, 'pw', '-', '-', 'n', '-', ACT_DOWN, 'force-to-root has no jurisdiction', null, null, [\n new L1UseCase(5,\n '`ls` from `packages/http/` runs normally',\n '`pw` / `n` / - — row 4',\n 'ALLOW (handed to L2)',\n 'none — force-to-root has no jurisdiction over non-git commands',\n new L1Classification('p', false, true, false, false)),\n new L1UseCase(6,\n '`pnpm test` from `packages/http/` runs normally',\n '`pw` / `n` / - — row 4',\n 'ALLOW (handed to L2)',\n 'none — deliberately untouched, so package-local test runs stay natural',\n new L1Classification('p', false, false, false, false)),\n new L1UseCase(10,\n '`echo \"cd sub && git push\"` passes',\n '`pw` / `n` / `root` — row 4',\n 'ALLOW (handed to L2)',\n 'none — the `cd` is inside quotes, so `ShellSegmentScan` never treats it as a scope escape',\n new L1Classification('p', false, false, false, true)),\n new L1UseCase(13,\n 'the same command from a **subagent** runs normally',\n '`w` / `y` — row 8 does not match',\n 'ALLOW (handed to L2)',\n 'none — a subagent pinned to a worktree is the correct pattern',\n new L1Classification('w', false, false, false, false)),\n new L1UseCase(14,\n 'inspection inside a SKEWED worktree still runs — `cd <worktree> && ls`/`cat`/`grep`',\n '`w` / `n` / `y` — row 8 does not match',\n 'ALLOW (handed to L2)',\n 'none — inspection is always open; so are the `Read` tool, `git -C <dir INSIDE this tree> …` and `git show <branch>:<file>`, none of which move you. `git -C <ANOTHER tree>` is a different matter: the harness refuses cross-tree git to a subagent, so it is never the cure for a skew — tell the MAIN agent instead',\n new L1Classification('w', true, true, false, false)),\n ]),\n new L1Row(5, 'pw', '-', '-', 'y', 'sub', ACT_BLOCK, '`cd <root> && <original>`',\n new L1Cure('`cd <root> && <original>`', 'Run git/gh commands from the repo root', true),\n 'force-to-root', [\n new L1UseCase(7,\n '`git status` from `packages/http/` is blocked',\n '`pw` / `y` / `sub` — row 5',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git status`',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(8,\n '`cd packages/http && git status` **typed from the root** is blocked',\n '`pw` / `y` / `sub` — row 5',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git status`<br>Do NOT: assume it is allowed because you started at the root — the predicate is `effectiveCwd === root`, i.e. the DESTINATION',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(11,\n '`cd <subdir> && git push` blocked with the force-to-root message, NOT the gated-flow one',\n '`pw` / `y` / `sub` — row 5; force-to-root runs first',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git push`, which then gets the push guard\\'s real answer ← costs one extra turn by design; still blocked',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(17,\n 'the printed cure REPLACES your `cd`, it does not stack in front of it',\n '`pw` / `y` / `sub` — row 5, on the cure itself',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): run the printed line VERBATIM — `cd <root> && <the work>`, with your own leading `cd` dropped<br>Do NOT: paste `cd <root> && cd <subdir> && <work>`; `effectiveCwd` resolves the leading `cd`s left to right, so that lands in `<subdir>` again and re-fires this exact block',\n new L1Classification('p', false, false, true, false)),\n ]),\n new L1Row(6, 'pw', '-', '-', 'y', 'root', ACT_DOWN, '', null, null, [\n new L1UseCase(9,\n '`cd <root> && git status` passes from anywhere',\n '`pw` / `y` / `root` — row 6',\n 'ALLOW (handed to L2)',\n 'none — this IS the prescribed cure',\n new L1Classification('p', false, false, true, true)),\n ]),\n new L1Row(7, 'm', '-', '-', '-', '-', ACT_BLOCK, 'the directory is GONE — nothing can run there',\n new L1Cure('`cd <root> && <the work>`, never back through the dead path',\n 'no longer exists', true),\n 'missing-directory', [\n new L1UseCase(18,\n 'every command from a worktree another agent REAPED mid-session is blocked',\n '`m` — row 7',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): run the printed `cd <root> && <the work>` line — it does NOT route back through the dead path<br>Do NOT: re-`cd` into the worktree, or `git worktree add` it back expecting your uncommitted work; that work is gone',\n new L1Classification('m', false, false, true, false)),\n new L1UseCase(19,\n 'the same block for a NON-git command there — `m` does not care about G',\n '`m` — row 7; K alone decides it',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): the same printed line. A vanished cwd is not a git question — nothing at all can run in a directory that does not exist',\n new L1Classification('m', false, false, false, false)),\n ]),\n];\n\n/**\n * The use cases that exercise something that is NOT a row: the excludePaths FILTER (2, 3, 4, 20) and the\n * L0 allowlist that runs ahead of L1 (15).\n *\n * They are use cases of L1 all the same — \"exempt\" is what emerges when the filter empties the rule\n * list, and case 15 is the invariant that a cure stays reachable from every tree — so they stay in the\n * doc's one numbered table. They carry no classification because no row classifies them.\n */\nexport const L1_UNROWED_USE_CASES: readonly L1UseCase[] = [\n new L1UseCase(2,\n 'Edit `repositories/vendored/foo.ts` allowed even on stale main',\n 'filter — the path is in `excludePaths`',\n 'ALLOW_EXEMPT',\n 'none needed'),\n new L1UseCase(3,\n 'Edit `packages/http/foo.ts` blocked on stale main',\n 'filter keeps the rules → L2 fires',\n 'BLOCK (at L2)',\n 'that is L2\\'s write-on-main verdict, not L1\\'s — follow the L2 message'),\n new L1UseCase(4,\n 'Edit `packages/http/foo.ts` judged even though the shell is in `/tmp`',\n 'filter, on the TARGET path',\n '→ L2',\n 'none — for file tools the cwd is irrelevant; do NOT `cd` anywhere to \"fix\" it'),\n new L1UseCase(20,\n 'Write `.webpieces/worktrees/agent-*/pr-review/…/review-*.json` allowed on main, with `excludePaths` empty',\n 'filter — `.webpieces/` is HARD-CODED exempt (`isWebpiecesStateDir`), ahead of the config list',\n 'ALLOW_EXEMPT',\n 'none needed — the dir is gitignored, so no config can put it back under governance'),\n new L1UseCase(21,\n 'Write a reviewer verdict into a WORKTREE\\'s own state dir — the `.webpieces` under `.claude/worktrees/agent-*`, not the primary\\'s',\n 'filter — the state-dir skip is asked about the path relative to the tree that OWNS it, not the governed root',\n 'ALLOW_EXEMPT',\n 'none — it was NOT exempt before (governed-root-relative that path begins `.claude`), and `wp-review-upsert-pr` requires the file before a PR can be opened'),\n new L1UseCase(15,\n '`cd <worktree> && pnpm install` still runs while row 8 is live — it is the CURE',\n 'L0 allowlist, ahead of L1',\n 'ALLOW',\n 'none — a cure must stay reachable from every tree'),\n];\n\n/** Every use case, in the doc's numbering — the order the table is rendered and read in. */\n// webpieces-disable no-function-outside-class -- pure accessor over the two arrays above, beside them in this data module\nexport function allL1UseCases(): readonly L1UseCase[] {\n const all = [...L1_ROWS.flatMap((row: L1Row): readonly L1UseCase[] => row.useCases), ...L1_UNROWED_USE_CASES];\n return all.sort((a: L1UseCase, b: L1UseCase): number => a.num - b.num);\n}\n\n/**\n * FIRST MATCH WINS — the one lookup the guard and the tests share.\n *\n * Never null: rows 1, 2 and 4/5/6 between them cover every kind, and rows 4/5/6 partition G × P, so a\n * classification that matched nothing would be a hole in the matrix. The totality test asserts exactly\n * that, which is why this returns L1Row rather than L1Row | null.\n */\n// webpieces-disable no-function-outside-class -- the matcher over L1_ROWS, beside the array it reads\nexport function firstMatchingL1Row(c: L1Classification): L1Row {\n const row = L1_ROWS.find((r: L1Row): boolean => r.matches(c));\n if (row === undefined) throw new Error(`L1 matrix has a hole: no row matches ${JSON.stringify(c)}`);\n return row;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"l1-rows.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/l1-rows.ts"],"names":[],"mappings":";;;AAqXA,sCAGC;AAUD,gDAIC;AAjVD;;;;;;;;;;;GAWG;AACU,QAAA,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;GAKG;AACH,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AAqG;AACrG,SAAgB,kBAAkB,CAAC,CAAmB;IAClD,MAAM,GAAG,GAAG,eAAO,CAAC,IAAI,CAAC,CAAC,CAAQ,EAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAI,GAAG,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpG,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { TreeKind } from './effective-tree';\n\n// ---------------------------------------------------------------------------\n// L1 — the LOCATION layer, as data.\n//\n// L1 answers four questions: do we govern this call at all, does the directory still EXIST, is the\n// WRONG AGENT standing here, and is the agent stranded away from the root? Drawn as a decision matrix\n// that is SEVEN ordered rows over five dimensions (K/A/R/G/P), first match wins.\n//\n// This module holds those rows, and l1-doc.ts renders them into guards/L1-location.md — the doc a human\n// reads on GitHub. A unit test locks that file byte-identical to the renderer, and the guard itself\n// CONSULTS L1_ROWS to decide which structural block fires (see runner.l1LocationBlock). Doc and code\n// come from the SAME array, so they cannot drift.\n//\n// This module is deliberately import-free at runtime (only a type-only import above), so\n// `pnpm guards:generate` can load it without the package's transitive dependencies.\n// ---------------------------------------------------------------------------\n\n/**\n * The K dimension as a CLASSIFICATION carries — one concrete tree, never the `pw` union.\n *\n * `p` and `w` are the same PROJECT and every rule-scoped guard treats them alike; the doc writes the\n * pair as `pw` in the row's MATCHER (below), which is a different vocabulary on purpose.\n */\nexport type L1Kind = 'f' | 'm' | 'o' | 'p' | 'w';\n\n/** The K value a ROW matches on. `pw` matches both `p` and `w`; `-` is the wildcard. */\nexport type L1KindMatch = 'f' | 'm' | 'o' | 'w' | 'pw' | '-';\n\n/** R and G are yes/no, written `y`/`n` in the doc, with `-` for \"does not matter\". */\nexport type L1Flag = 'y' | 'n' | '-';\n\n/**\n * V is the same one boolean wearing the doc's own letters: `n` the webpieces versions do NOT agree\n * between this worktree and the main tree, `y` they do.\n *\n * This dimension used to be A (`c` coordinator / `s` subagent). It was replaced rather than removed\n * because agent identity was measured untrustworthy as a proxy for \"which tree am I in\" — a\n * worktree-isolated agent auto-reaped at a turn boundary silently resumes on the primary clone. A\n * version read off the PATH being acted on cannot lie in that way.\n */\nexport type L1VersionSync = 'y' | 'n' | '-';\n\n/** What L1 does with a row. The labels are the doc's own action codebook (see GUARD_MATRIX.md). */\nexport type L1ActionKind = 'exempt' | 'down' | 'block';\n\n/**\n * WHICH structural block a blocking row dispatches to. This is the field that makes the array\n * load-bearing rather than decorative: runner.l1LocationBlock looks the row up and switches on it,\n * so deleting a row from the array removes the block.\n */\nexport type L1BlockId = 'trinary-version-skew' | 'force-to-root' | 'missing-directory';\n\n/**\n * The row number for L1's PRE-STAGE — `misplacedCdBlock`, which decides from command TEXT before a\n * tree has been resolved, and therefore cannot be classified over the five dimensions rows 1-6 use\n * (asking L1_ROWS to classify it would need the very resolution its answer determines).\n *\n * ZERO rather than a seventh row, deliberately. It has to appear in the table — an L1 block the\n * generated doc did not describe is precisely the drift the table exists to prevent, and it was\n * carrying a `KNOWN GAP` comment saying so. But numbering it 7 would assert it sits in the same\n * first-match scan as the others, which is the one thing that is not true about it. Row 0 says\n * \"decided before the scan\" in the number itself. `renderL1Doc()` PRINTS this row above the six, so\n * `row=0` in the L1 log joins to a line the reader can actually find.\n */\nexport const L1_PRESTAGE_ROW = '0';\n\n/**\n * One point in the five-dimensional space L1 classifies over. Data-only → a class, per CLAUDE.md.\n *\n * The dimensions are exactly the doc's legend: K (tree kind of the resolved target), V (webpieces versions in sync or\n * subagent), R (provably read-only inspection), G (invokes git/gh), P (root or subdirectory).\n */\nexport class L1Classification {\n // eslint-disable-next-line @typescript-eslint/max-params -- five dimensions is the matrix's shape\n constructor(\n readonly kind: L1Kind,\n readonly versionsSkewed: boolean,\n readonly readOnly: boolean,\n readonly git: boolean,\n readonly atRoot: boolean,\n ) {}\n\n /**\n * The classification the RUNNER enforces on, built from the resolved tree and the caller.\n *\n * `'outside'` maps to `p`, and that is not a typo. TreeKind `'outside'` is produced by\n * effective-tree.ts (git has no answer for the directory) and consumed NOWHERE, so a command in no git repo is\n * judged against the governed repo exactly as if it stood in it. Row 2 (`o` → L2) describes what\n * SHOULD happen and is deliberately unreachable from here until the \"Not done\" fix in\n * guards/L1-location.md lands — exempting `o` alone opens a `cd /tmp &&` bypass of every L2 guard,\n * so the two ship together or neither does. Mapping it to `p` here is what preserves today's\n * behaviour (a `git` command from /tmp is still force-to-root blocked); it is not an endorsement.\n */\n // eslint-disable-next-line @typescript-eslint/max-params -- mirrors the constructor it delegates to\n // webpieces-disable no-function-outside-class -- a named constructor for this data class, not a service: it takes the runner's TreeKind and returns the same class, so there is nothing to inject\n static forEnforcement(\n treeKind: TreeKind,\n versionsSkewed: boolean,\n readOnly: boolean,\n git: boolean,\n atRoot: boolean,\n ): L1Classification {\n const kind: L1Kind = treeKind === 'foreign' ? 'f'\n : treeKind === 'missing' ? 'm'\n : treeKind === 'worktree' ? 'w' : 'p';\n return new L1Classification(kind, versionsSkewed, readOnly, git, atRoot);\n }\n}\n\n/** The `act` cell of a row: the doc's literal label, plus the machine-readable kind behind it. */\nexport class L1Action {\n constructor(readonly label: string, readonly kind: L1ActionKind) {}\n}\n\nexport const ACT_EXEMPT = new L1Action('2 exempt', 'exempt');\nexport const ACT_DOWN = new L1Action('→ L2', 'down');\nexport const ACT_BLOCK = new L1Action('4 block', 'block');\n\n/**\n * The CURE a blocking row prescribes.\n *\n * `runnable` is the axis that matters to the tests: a cure that is a command must, once applied,\n * actually stop the row from matching (cure reachability). Row 3's cure is an INSTRUCTION — \"spawn a\n * subagent bound to the worktree\" — which no allowlist can accept and no reclassification can model,\n * so it declares `runnable: false` and is asserted only on the deny text.\n */\nexport class L1Cure {\n constructor(\n /** How the doc's `why` column spells it. */\n readonly summary: string,\n /** A substring that MUST appear in the deny text the guard emits for this row. */\n readonly denyMention: string,\n readonly runnable: boolean,\n ) {}\n}\n\n/**\n * One row of the \"L1 use cases\" table: what you SEE, the state it puts you in, the verdict, the fix.\n *\n * The four text fields are rendered VERBATIM into the doc. `classification` is the same case expressed\n * in the matrix's own vocabulary so the tests can run it through the matcher — it is test/enforcement\n * data, never rendered, which is why a use case that exercises the FILTER or the L0 allowlist (neither\n * of which is a row) can carry `null` there.\n */\nexport class L1UseCase {\n // eslint-disable-next-line @typescript-eslint/max-params -- four verbatim doc cells plus the classification behind them\n constructor(\n readonly num: number,\n readonly symptom: string,\n readonly state: string,\n readonly verdict: string,\n readonly fix: string,\n readonly classification: L1Classification | null = null,\n ) {}\n}\n\n/** One row of L1's decision table. Data-only → a class, per CLAUDE.md. */\nexport class L1Row {\n // eslint-disable-next-line @typescript-eslint/max-params -- five dimension cells plus act/why/cure/blockId/useCases\n constructor(\n readonly num: number,\n readonly k: L1KindMatch,\n readonly a: L1VersionSync,\n readonly r: L1Flag,\n readonly g: L1Flag,\n readonly p: 'root' | 'sub' | '-',\n readonly action: L1Action,\n /** The `why` cell, verbatim. */\n readonly why: string,\n readonly cure: L1Cure | null,\n readonly blockId: L1BlockId | null,\n readonly useCases: readonly L1UseCase[],\n ) {}\n\n matches(c: L1Classification): boolean {\n if (!this.kindMatches(c.kind)) return false;\n if (this.a !== '-' && (this.a === 'n') !== c.versionsSkewed) return false;\n if (!flagMatches(this.r, c.readOnly)) return false;\n if (!flagMatches(this.g, c.git)) return false;\n return this.p === '-' || this.p === (c.atRoot ? 'root' : 'sub');\n }\n\n private kindMatches(kind: L1Kind): boolean {\n if (this.k === '-') return true;\n if (this.k === 'pw') return kind === 'p' || kind === 'w';\n return this.k === kind;\n }\n}\n\n// R and G are one boolean each behind a `y`/`n`/`-` cell, so one helper answers for both. (A is the\n// same shape but spelled `c`/`s`, and is matched inline above so the row literals read like the doc.)\n// webpieces-disable no-function-outside-class -- pure predicate for L1Row.matches above, in this data module\nfunction flagMatches(cell: L1Flag, value: boolean): boolean {\n if (cell === '-') return true;\n return (cell === 'y') === value;\n}\n\n/**\n * THE seven L1 rows, in first-match-wins order.\n *\n * Rows 3, 5 and 7 are the structural blocks and they run as ONE step (runner.l1LocationBlock) so they\n * can never be reordered by accident. Every other row is a hand-down or an exemption, i.e. \"L1 has no\n * objection\" — which is why only those three carry a blockId.\n *\n * Row 7 (`m`, the vanished directory) sits LAST only because row numbers are stable across releases —\n * they are printed in the doc and logged as `row=`, so renumbering rows 1-6 to slot it in front would\n * silently invalidate every existing reference. Position costs nothing here: `m` is matched by no other\n * row, so first-match reaches it wherever it sits.\n */\nexport const L1_ROWS: readonly L1Row[] = [\n new L1Row(1, 'f', '-', '-', '-', '-', ACT_EXEMPT, 'different git repo — hands off', null, null, [\n new L1UseCase(1,\n '`cd repositories/vendored && git commit` goes through untouched',\n '`f` / `y` / - — row 1',\n 'ALLOW_EXEMPT',\n 'none needed — jurisdiction is judged on the RESOLVED target, after the `cd`; a different git repo is hands-off',\n new L1Classification('f', false, false, true, false)),\n ]),\n new L1Row(2, 'o', '-', '-', '-', '-', ACT_DOWN, 'see \"Not done\" below', null, null, []),\n // ROW 3 IS RETIRED — it was coordinator-in-worktree, deleted with CoordinatorWorktreeGuard when the\n // guard hooks went ABSOLUTE (one governor, so the filesystem/governance split it policed became\n // unconstructible). The NUMBER is never reused: row numbers are identity here — they are printed in\n // denies, logged as `row=`, and cited in guards/L1-location.md — so renumbering would silently\n // re-point every historical reference. Its replacement is row 8.\n new L1Row(8, 'w', 'n', 'n', '-', '-', ACT_BLOCK,\n 'this worktree pins a DIFFERENT @webpieces than the main tree that governs it',\n new L1Cure('align the pins (same git hash -> same tracked pin -> install in each tree), work in the main tree, or use a separate clone',\n '@webpieces version SKEW', false),\n 'trinary-version-skew', [\n new L1UseCase(12,\n 'a worktree on an older branch pins `0.4.612` while the main tree runs `0.4.616`, and `cd <wt> && pnpm build` is blocked',\n '`w` / `n` / `n` — row 8',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): the MAIN tree is AHEAD, so this is YOURS and it is a one-line edit — raise THIS tree\\'s catalog pin in `pnpm-workspace.yaml` to what main already runs, then `pnpm install` here if this tree has a node_modules. That edit is on the L0 allowlist, so it is typable while the block is up, and nothing has to move in the main tree<br>Option 2: do the work in the main tree, which this guard never blocks<br>Option 3: if the tree genuinely needs a DIFFERENT version, use a separate CLONE — a clone gets its own governance. That is the answer to \"I need a different version\", never to \"I need to install here\": a worktree MAY have its own node_modules (nx, vitest and the eslint plugin all load from it), it just may not hold a different @webpieces version<br>Do NOT: lower the MAIN tree\\'s pin to match — that downgrades every tree, including this session\\'s own governor. And do NOT reach for `pnpm install` BEFORE the edit: this tree\\'s pin is the stale side, so installing first materializes the OLD release',\n new L1Classification('w', true, false, false, false)),\n new L1UseCase(16,\n 'a SUBAGENT hits the same block inside `.claude/worktrees/agent-XXXX`',\n '`w` / `n` / `n` — row 8; in-repo placement is still `w`',\n 'BLOCK_AI_CURE',\n 'READ THE DIRECTION FIRST — the deny prints it. If the MAIN tree is AHEAD (the common case) a subagent fixes this ITSELF, here, by raising this tree\\'s pin to what main already runs; there is nothing to escalate and the deny prints no escalation. Only when main is BEHIND, or when this branch bumped the pin on purpose, is the subagent stuck — the main tree is outside its tree, and a worktree-isolated agent may not even still be in the tree it was launched in (measured: auto-reaped at a turn boundary, resumed on the primary). Then, and only then, forward the deny\\'s verbatim ask to the coordinator, and do NOT retry the blocked call — it re-fires the identical deny and buries the ask<br>Do NOT: expect exemption because it sits under the repo — K is git\\'s `--git-common-dir` answer, not a path test',\n new L1Classification('w', true, false, false, false)),\n ]),\n new L1Row(4, 'pw', '-', '-', 'n', '-', ACT_DOWN, 'force-to-root has no jurisdiction', null, null, [\n new L1UseCase(5,\n '`ls` from `packages/http/` runs normally',\n '`pw` / `n` / - — row 4',\n 'ALLOW (handed to L2)',\n 'none — force-to-root has no jurisdiction over non-git commands',\n new L1Classification('p', false, true, false, false)),\n new L1UseCase(6,\n '`pnpm test` from `packages/http/` runs normally',\n '`pw` / `n` / - — row 4',\n 'ALLOW (handed to L2)',\n 'none — deliberately untouched, so package-local test runs stay natural',\n new L1Classification('p', false, false, false, false)),\n new L1UseCase(10,\n '`echo \"cd sub && git push\"` passes',\n '`pw` / `n` / `root` — row 4',\n 'ALLOW (handed to L2)',\n 'none — the `cd` is inside quotes, so `ShellSegmentScan` never treats it as a scope escape',\n new L1Classification('p', false, false, false, true)),\n new L1UseCase(13,\n 'the same command from a **subagent** runs normally',\n '`w` / `y` — row 8 does not match',\n 'ALLOW (handed to L2)',\n 'none — a subagent pinned to a worktree is the correct pattern',\n new L1Classification('w', false, false, false, false)),\n new L1UseCase(14,\n 'inspection inside a SKEWED worktree still runs — `cd <worktree> && ls`/`cat`/`grep`',\n '`w` / `n` / `y` — row 8 does not match',\n 'ALLOW (handed to L2)',\n 'none — inspection is always open; so are the `Read` tool, `git -C <dir INSIDE this tree> …` and `git show <branch>:<file>`, none of which move you. `git -C <ANOTHER tree>` is a different matter: the harness refuses cross-tree git to a subagent, so it is never the cure for a skew — tell the MAIN agent instead',\n new L1Classification('w', true, true, false, false)),\n ]),\n new L1Row(5, 'pw', '-', '-', 'y', 'sub', ACT_BLOCK, '`cd <root> && <original>`',\n new L1Cure('`cd <root> && <original>`', 'Run git/gh commands from the repo root', true),\n 'force-to-root', [\n new L1UseCase(7,\n '`git status` from `packages/http/` is blocked',\n '`pw` / `y` / `sub` — row 5',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git status`',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(8,\n '`cd packages/http && git status` **typed from the root** is blocked',\n '`pw` / `y` / `sub` — row 5',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git status`<br>Do NOT: assume it is allowed because you started at the root — the predicate is `effectiveCwd === root`, i.e. the DESTINATION',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(11,\n '`cd <subdir> && git push` blocked with the force-to-root message, NOT the gated-flow one',\n '`pw` / `y` / `sub` — row 5; force-to-root runs first',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): `cd <root> && git push`, which then gets the push guard\\'s real answer ← costs one extra turn by design; still blocked',\n new L1Classification('p', false, false, true, false)),\n new L1UseCase(17,\n 'the printed cure REPLACES your `cd`, it does not stack in front of it',\n '`pw` / `y` / `sub` — row 5, on the cure itself',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): run the printed line VERBATIM — `cd <root> && <the work>`, with your own leading `cd` dropped<br>Do NOT: paste `cd <root> && cd <subdir> && <work>`; `effectiveCwd` resolves the leading `cd`s left to right, so that lands in `<subdir>` again and re-fires this exact block',\n new L1Classification('p', false, false, true, false)),\n ]),\n new L1Row(6, 'pw', '-', '-', 'y', 'root', ACT_DOWN, '', null, null, [\n new L1UseCase(9,\n '`cd <root> && git status` passes from anywhere',\n '`pw` / `y` / `root` — row 6',\n 'ALLOW (handed to L2)',\n 'none — this IS the prescribed cure',\n new L1Classification('p', false, false, true, true)),\n ]),\n new L1Row(7, 'm', '-', '-', '-', '-', ACT_BLOCK, 'the directory is GONE — nothing can run there',\n new L1Cure('`cd <root> && <the work>`, never back through the dead path',\n 'no longer exists', true),\n 'missing-directory', [\n new L1UseCase(18,\n 'every command from a worktree another agent REAPED mid-session is blocked',\n '`m` — row 7',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): run the printed `cd <root> && <the work>` line — it does NOT route back through the dead path<br>Do NOT: re-`cd` into the worktree, or `git worktree add` it back expecting your uncommitted work; that work is gone',\n new L1Classification('m', false, false, true, false)),\n new L1UseCase(19,\n 'the same block for a NON-git command there — `m` does not care about G',\n '`m` — row 7; K alone decides it',\n 'BLOCK_AI_CURE',\n 'Option 1 (preferred): the same printed line. A vanished cwd is not a git question — nothing at all can run in a directory that does not exist',\n new L1Classification('m', false, false, false, false)),\n ]),\n];\n\n/**\n * The use cases that exercise something that is NOT a row: the excludePaths FILTER (2, 3, 4, 20) and the\n * L0 allowlist that runs ahead of L1 (15).\n *\n * They are use cases of L1 all the same — \"exempt\" is what emerges when the filter empties the rule\n * list, and case 15 is the invariant that a cure stays reachable from every tree — so they stay in the\n * doc's one numbered table. They carry no classification because no row classifies them.\n */\nexport const L1_UNROWED_USE_CASES: readonly L1UseCase[] = [\n new L1UseCase(2,\n 'Edit `repositories/vendored/foo.ts` allowed even on stale main',\n 'filter — the path is in `excludePaths`',\n 'ALLOW_EXEMPT',\n 'none needed'),\n new L1UseCase(3,\n 'Edit `packages/http/foo.ts` blocked on stale main',\n 'filter keeps the rules → L2 fires',\n 'BLOCK (at L2)',\n 'that is L2\\'s write-on-main verdict, not L1\\'s — follow the L2 message'),\n new L1UseCase(4,\n 'Edit `packages/http/foo.ts` judged even though the shell is in `/tmp`',\n 'filter, on the TARGET path',\n '→ L2',\n 'none — for file tools the cwd is irrelevant; do NOT `cd` anywhere to \"fix\" it'),\n new L1UseCase(20,\n 'Write `.webpieces/worktrees/agent-*/pr-review/…/review-*.json` allowed on main, with `excludePaths` empty',\n 'filter — `.webpieces/` is HARD-CODED exempt (`isWebpiecesStateDir`), ahead of the config list',\n 'ALLOW_EXEMPT',\n 'none needed — the dir is gitignored, so no config can put it back under governance'),\n new L1UseCase(21,\n 'Write a reviewer verdict into a WORKTREE\\'s own state dir — the `.webpieces` under `.claude/worktrees/agent-*`, not the primary\\'s',\n 'filter — the state-dir skip is asked about the path relative to the tree that OWNS it, not the governed root',\n 'ALLOW_EXEMPT',\n 'none — it was NOT exempt before (governed-root-relative that path begins `.claude`), and `wp-review-upsert-pr` requires the file before a PR can be opened'),\n new L1UseCase(15,\n '`cd <worktree> && pnpm install` still runs while row 8 is live — it is the CURE',\n 'L0 allowlist, ahead of L1',\n 'ALLOW',\n 'none — a cure must stay reachable from every tree'),\n];\n\n/** Every use case, in the doc's numbering — the order the table is rendered and read in. */\n// webpieces-disable no-function-outside-class -- pure accessor over the two arrays above, beside them in this data module\nexport function allL1UseCases(): readonly L1UseCase[] {\n const all = [...L1_ROWS.flatMap((row: L1Row): readonly L1UseCase[] => row.useCases), ...L1_UNROWED_USE_CASES];\n return all.sort((a: L1UseCase, b: L1UseCase): number => a.num - b.num);\n}\n\n/**\n * FIRST MATCH WINS — the one lookup the guard and the tests share.\n *\n * Never null: rows 1, 2 and 4/5/6 between them cover every kind, and rows 4/5/6 partition G × P, so a\n * classification that matched nothing would be a hole in the matrix. The totality test asserts exactly\n * that, which is why this returns L1Row rather than L1Row | null.\n */\n// webpieces-disable no-function-outside-class -- the matcher over L1_ROWS, beside the array it reads\nexport function firstMatchingL1Row(c: L1Classification): L1Row {\n const row = L1_ROWS.find((r: L1Row): boolean => r.matches(c));\n if (row === undefined) throw new Error(`L1 matrix has a hole: no row matches ${JSON.stringify(c)}`);\n return row;\n}\n"]}
|
|
@@ -90,9 +90,9 @@ export declare class VersionSyncGuard {
|
|
|
90
90
|
* still see it is not their own action. Do not factor it out.
|
|
91
91
|
*
|
|
92
92
|
* The FIX block still prints ABOVE the escalation block, on purpose. Moving it below would split the
|
|
93
|
-
* numbered steps from the versions they refer to, and the
|
|
94
|
-
*
|
|
95
|
-
*
|
|
93
|
+
* numbered steps from the versions they refer to, and the do-not-retry beat has to stay last and stay
|
|
94
|
+
* unique — a second shouted beat competing with it is exactly the wall-of-text regression the L0
|
|
95
|
+
* message diet exists to prevent.
|
|
96
96
|
* Labelling carries the "not yours to run" fact instead, which is what the caps header does.
|
|
97
97
|
*/
|
|
98
98
|
private fixLines;
|
|
@@ -162,15 +162,19 @@ export declare class VersionSyncGuard {
|
|
|
162
162
|
* text asks for exactly that — and asks to be TOLD WHEN IT IS DONE, because "the work happened" is
|
|
163
163
|
* the event that unblocks this subagent and it has no way to observe it otherwise.
|
|
164
164
|
*
|
|
165
|
-
* And it has to
|
|
165
|
+
* And it has to refuse the RETRY, because forwarding is only half of what the subagent must do. One
|
|
166
166
|
* measured subagent transcript re-fired this identical deny 13 TIMES (25 across the whole session,
|
|
167
167
|
* counting two sibling subagents and two parent sessions): the subagent read it, escalated exactly
|
|
168
|
-
* as asked — and then
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* the
|
|
168
|
+
* as asked — and then re-ran the blocked call. Every retry cost a round trip and pushed the one
|
|
169
|
+
* message that mattered further up the scrollback. The block is not transient and no command from
|
|
170
|
+
* this tree slips past it, so retrying is never a strategy; it is the bug.
|
|
171
|
+
*
|
|
172
|
+
* What it must NOT do is decide the agent's control flow. #679 first wrote this beat as "STOP WORKING
|
|
173
|
+
* NOW. Forwarding that message IS the end of your turn: make NO further tool calls" — a turn-level
|
|
174
|
+
* prescription, which `.claude/rules/never-tell-an-ai-to-end-its-turn.md` forbids (#902 deleted every
|
|
175
|
+
* other one; this one survived because no spec rendered it — issue #1000). Refusing one futile
|
|
176
|
+
* command is legitimate; ruling on when the turn ends is a judgement the agent is better placed to
|
|
177
|
+
* make. So the beat names the retry, says why it is futile, and stops talking.
|
|
174
178
|
*/
|
|
175
179
|
private escalationLines;
|
|
176
180
|
/**
|
package/src/core/version-sync.js
CHANGED
|
@@ -250,9 +250,9 @@ class VersionSyncGuard {
|
|
|
250
250
|
* still see it is not their own action. Do not factor it out.
|
|
251
251
|
*
|
|
252
252
|
* The FIX block still prints ABOVE the escalation block, on purpose. Moving it below would split the
|
|
253
|
-
* numbered steps from the versions they refer to, and the
|
|
254
|
-
*
|
|
255
|
-
*
|
|
253
|
+
* numbered steps from the versions they refer to, and the do-not-retry beat has to stay last and stay
|
|
254
|
+
* unique — a second shouted beat competing with it is exactly the wall-of-text regression the L0
|
|
255
|
+
* message diet exists to prevent.
|
|
256
256
|
* Labelling carries the "not yours to run" fact instead, which is what the caps header does.
|
|
257
257
|
*/
|
|
258
258
|
fixLines(tree, quartet, skew) {
|
|
@@ -409,15 +409,19 @@ class VersionSyncGuard {
|
|
|
409
409
|
* text asks for exactly that — and asks to be TOLD WHEN IT IS DONE, because "the work happened" is
|
|
410
410
|
* the event that unblocks this subagent and it has no way to observe it otherwise.
|
|
411
411
|
*
|
|
412
|
-
* And it has to
|
|
412
|
+
* And it has to refuse the RETRY, because forwarding is only half of what the subagent must do. One
|
|
413
413
|
* measured subagent transcript re-fired this identical deny 13 TIMES (25 across the whole session,
|
|
414
414
|
* counting two sibling subagents and two parent sessions): the subagent read it, escalated exactly
|
|
415
|
-
* as asked — and then
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* the
|
|
415
|
+
* as asked — and then re-ran the blocked call. Every retry cost a round trip and pushed the one
|
|
416
|
+
* message that mattered further up the scrollback. The block is not transient and no command from
|
|
417
|
+
* this tree slips past it, so retrying is never a strategy; it is the bug.
|
|
418
|
+
*
|
|
419
|
+
* What it must NOT do is decide the agent's control flow. #679 first wrote this beat as "STOP WORKING
|
|
420
|
+
* NOW. Forwarding that message IS the end of your turn: make NO further tool calls" — a turn-level
|
|
421
|
+
* prescription, which `.claude/rules/never-tell-an-ai-to-end-its-turn.md` forbids (#902 deleted every
|
|
422
|
+
* other one; this one survived because no spec rendered it — issue #1000). Refusing one futile
|
|
423
|
+
* command is legitimate; ruling on when the turn ends is a judgement the agent is better placed to
|
|
424
|
+
* make. So the beat names the retry, says why it is futile, and stops talking.
|
|
421
425
|
*/
|
|
422
426
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
423
427
|
escalationLines(tree, quartet, skew, aiType) {
|
|
@@ -427,9 +431,8 @@ class VersionSyncGuard {
|
|
|
427
431
|
` > the main tree ${tree.mainRoot} is on ${this.show(quartet.main.pinned).trim()}.`,
|
|
428
432
|
...this.askLines(tree, quartet, skew),
|
|
429
433
|
...this.afterwardLines(aiType),
|
|
430
|
-
`
|
|
431
|
-
`
|
|
432
|
-
` deny and buries the ask above; one subagent did it 13 times, 25 across that whole session.`,
|
|
434
|
+
` Do NOT retry this call — RETRYING IS THE BUG. It re-fires this identical deny and buries the`,
|
|
435
|
+
` ask above; one subagent did it 13 times, 25 across that whole session.`,
|
|
433
436
|
...this.waitLines(aiType),
|
|
434
437
|
];
|
|
435
438
|
}
|
|
@@ -456,9 +459,11 @@ class VersionSyncGuard {
|
|
|
456
459
|
}
|
|
457
460
|
waitLines(aiType) {
|
|
458
461
|
if (aiType === 'codex') {
|
|
462
|
+
// The three-move wait shape (never-tell-an-ai-to-end-its-turn.md): name the efficient option,
|
|
463
|
+
// name the wasteful one, and say nothing about when a turn ends.
|
|
459
464
|
return [
|
|
460
|
-
` Nothing you can do from this tree clears it.
|
|
461
|
-
`
|
|
465
|
+
` Nothing you can do from this tree clears it. Be efficient with tokens: wait on the main`,
|
|
466
|
+
` agent's confirmation instead of re-running blocked calls to see whether it has cleared.`,
|
|
462
467
|
];
|
|
463
468
|
}
|
|
464
469
|
return [` Nothing you can do from this tree clears it; the coordinator redoes it in a fresh worktree.`];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-sync.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/version-sync.ts"],"names":[],"mappings":";;;;AACA,iDAA0C;AAC1C,mDAA6B;AAE7B,sDAAyD;AAEzD,iEAAgE;AAChE,6DAA2F;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,8FAA8F;AAC9F,MAAM,YAAY;IAGD;IAEA;IAJb;IACI,gDAAgD;IACvC,IAAuB;IAChC,mFAAmF;IAC1E,GAAW;QAFX,SAAI,GAAJ,IAAI,CAAmB;QAEvB,QAAG,GAAH,GAAG,CAAQ;IACrB,CAAC;CACP;AAmBD,MAAa,gBAAgB;IACR,UAAU,GAAG,IAAI,6CAAsB,EAAE,CAAC;IAC1C,QAAQ,GAAG,IAAI,sCAAiB,EAAE,CAAC;IAEpD;;;;OAIG;IACH,MAAM,CAAC,IAAmB;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACzC,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AC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,QAAQ,iBAAiB,qCAAgB,EAAE;YAC5G,uDAAuD;YACvD,qBAAqB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,sBAAsB;SAC/F,CAAC;QACF,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,qBAAqB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,iBAAiB,qCAAgB,EAAE,CAAC,CAAC;YACzH,KAAK,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACtE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,MAAM,sEAAsE,CAAC,CAAC;YAC3G,KAAK,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;YAC7F,KAAK,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,IAAI,CAAC,OAAsB;QAC/B,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;CACJ;AAteD,4CAseC","sourcesContent":["import { AiType } from './agent-event';\nimport { spawnSync } from 'child_process';\nimport * as path from 'path';\n\nimport { WORKSPACE_MANIFEST } from '../bin/l0-allowlist';\nimport { EffectiveTree } from './effective-tree';\nimport { ReadOnlyInspectionScan } from './read-only-inspection';\nimport { UMBRELLA_PACKAGE, VersionQuartet, WebpiecesVersions } from './webpieces-versions';\n\n/**\n * L1 row 8 — a tree may not be worked in while its `@webpieces` version disagrees with the MAIN tree's.\n *\n * ─── WHY THIS EXISTS, and what it replaces ─────────────────────────────────────────────────────────\n * The guard hooks are registered ABSOLUTE (`$CLAUDE_PROJECT_DIR/...`), so the MAIN tree governs every\n * tree. That is not a new imposition — it is what was always happening, because a linked worktree has no\n * `node_modules` and ai-hook.sh's upward walk already executed the main tree's binary. The design now\n * says so out loud, which makes ONE case newly important: a worktree whose branch pins a DIFFERENT\n * release is being linted, validated and built by a release it never asked for.\n *\n * This guard makes that case LOUD instead of silent. It replaces `CoordinatorWorktreeGuard`, and the\n * replacement is strictly better on the axis that matters: the old guard keyed off WHO was asking\n * (coordinator vs subagent), and agent identity was measured untrustworthy — a worktree-isolated agent\n * whose tree is auto-reaped at a turn boundary silently resumes with its cwd on the primary clone\n * (reproduced twice, 2026-08-10). This guard keys off the PATH the command acts on, which cannot lie.\n *\n * ─── IT EXISTS TO STOP A LOOP, not to enforce tidiness ─────────────────────────────────────────────\n * A main/worktree manifest mismatch is exactly the shape that produced the founding incident: an agent\n * is shown a fault measured against one tree, runs the prescribed cure in another, the cure succeeds,\n * nothing the guard measures changes, and the guard re-denies. Five identical no-op `pnpm install`s and\n * a fabricated theory about the harness later, a human had to untangle it. Firing EARLY, with a message\n * that names all the versions and all their files, is the whole point. Any future proposal to soften\n * this to a warning must answer: what stops the five-install loop instead?\n *\n * ─── Never a deadlock ──────────────────────────────────────────────────────────────────────────────\n * Two structurally independent escapes, and neither depends on an allowlist regex staying in step:\n * 1. WORK IN THE MAIN TREE — a main-tree-targeted command cannot classify as `worktree`, so it never\n * reaches this guard at all. No allowlist entry can break it because none is involved.\n * 2. EDIT THE MANIFESTS — `pnpm-workspace.yaml` / `package.json` edits are carved out in the runner\n * (`runInternal`, beside the `webpieces.config.json` pass) and on the L0 allowlist\n * (`MANIFEST_FILENAMES` / `isAllowed`), so the cure is typable from inside the block.\n * Reads and read-only inspection are never blocked either, so an agent can always look before it fixes.\n *\n * THAT SECOND ESCAPE WAS FICTION UNTIL 2026-08-20, and this docblock asserted it anyway. Only\n * `CONFIG_FILENAME` was ever carved out, so the one cure the report told a blocked agent to perform —\n * raise this tree's pin — was itself blocked. It is real now, and the `main-ahead` branch of `fixLines`\n * is what spends it. A future edit that narrows either carve-out has to change this text too.\n *\n * ─── The MAIN tree is `tree.mainRoot`, never `tree.governedRoot` ───────────────────────────────────\n * The two differ for exactly the reader this guard is for. `governedRoot` is walked up from the payload\n * cwd to the nearest `webpieces.config.json`, and that file is TRACKED — a linked worktree has its own.\n * So for an agent resident in a worktree `governedRoot` IS the worktree, and comparing it against\n * `tree.root` compared the tree with ITSELF: trivially in sync, guard silent. `mainRoot` is git's\n * `<git-common-dir>/..`, i.e. the clone whose `node_modules` actually supplies the judging binary, and\n * it is the same answer from every checkout. Measured 2026-08-10: a worktree on 0.4.624 with its own\n * install, a main clone on 0.4.616, and not one word from this guard.\n */\n/** One version reduced to what an order compare needs. Data-only → a class, per CLAUDE.md. */\nclass VersionParts {\n constructor(\n /** The numeric core, most-significant first. */\n readonly core: readonly number[],\n /** The pre-release suffix INCLUDING its leading `-`, or '' for a plain release. */\n readonly pre: string,\n ) {}\n}\n\n/**\n * WHICH of the five states this skew is. The whole point of naming them is that they do NOT share a\n * cure, and printing the wrong one is what walked a real agent backwards through a downgrade:\n *\n * `main-inconsistent` — the MAIN tree disagrees with ITSELF (its pin ≠ its own node_modules). Nothing\n * about this worktree is wrong; only the main agent can fix it, with one install.\n * `bump` — this branch RAISED the pin on purpose. The deliverable is the pin, so every\n * ordinary cure would revert it. Main has to come up to meet it.\n * `main-ahead` — the governing tree already RUNS a newer release than this tree's pin asks for.\n * This is the common case, and it is the ONE case the worktree fixes ITSELF, by\n * raising its own pin. No escalation, nobody to ask, nothing to wait for.\n * `worktree-stale` — every PIN agrees and so does main's install; only this tree's OWN node_modules\n * lags. The one state where a bare `pnpm install` HERE is exactly right.\n * `main-behind` — main is genuinely older and must move forward. Only the main agent can pull it.\n */\ntype SkewCase = 'main-inconsistent' | 'bump' | 'main-ahead' | 'worktree-stale' | 'main-behind';\n\nexport class VersionSyncGuard {\n private readonly inspection = new ReadOnlyInspectionScan();\n private readonly versions = new WebpiecesVersions();\n\n /**\n * True when this tree is a linked worktree whose webpieces version disagrees with the main tree's.\n * This is the `V` dimension of the L1 matrix; the runner asks it for EVERY Bash call so the answer\n * lands in the audit log even when nothing blocks.\n */\n skewed(tree: EffectiveTree): boolean {\n if (!this.applies(tree)) return false;\n return !this.quartetFor(tree).inSync;\n }\n\n /** The deny report, or null to allow. */\n block(command: string, tree: EffectiveTree, aiType: AiType): string | null {\n if (!this.applies(tree)) return null;\n if (this.inspection.isReadOnlyInspection(command)) return null;\n if (this.isCureOrLook(command)) return null;\n const quartet = this.quartetFor(tree);\n if (quartet.inSync) return null;\n return this.report(tree, quartet, aiType);\n }\n\n /**\n * Commands that must pass EVEN WHILE THIS GUARD IS BLOCKING, because they are how you get unblocked\n * — or how you look at the tree first.\n *\n * `ReadOnlyInspectionScan` deliberately excludes git and gh OUTRIGHT (\"the guards exist to police\n * git, and read-only git is not a line worth drawing while flying blind\"), which is right for the\n * guards that police git but WRONG here: this guard's own prescribed cure is `git pull` in both\n * trees. Without this carve-out the guard would deny the exact command it tells the reader to run —\n * the single failure shape this repo has been burned by most often, and the reason the deny text is\n * allowed to promise \"STILL ALLOWED HERE: ... pnpm install, git pull/fetch\".\n *\n * Deliberately NARROW: fetching, pulling and installing cannot make a skew worse, and every one of\n * them moves the tree toward agreement. Anything that BUILDS, TESTS or COMMITS is still blocked,\n * because those are the operations that would be judged by the wrong release.\n */\n private isCureOrLook(command: string): boolean {\n const words = command.trim().split(/\\s+/);\n const head = words[0] ?? '';\n const sub = words[1] ?? '';\n if (head === 'git' || head === 'gh') {\n // `git -C <dir> <sub>` names its own directory; take the first non-flag word after it.\n const subcommand = sub === '-C' ? (words[3] ?? '') : sub;\n return ['pull', 'fetch', 'status', 'log', 'diff', 'show', 'branch', 'rev-parse', 'worktree'].includes(subcommand);\n }\n return (head === 'pnpm' || head === 'npm') && (sub === 'install' || sub === 'i');\n }\n\n /**\n * Is there a cross-tree comparison to make at all? TWO cheap conditions, no file read behind either:\n *\n * • K is `worktree` — git's `--git-dir ≠ --git-common-dir`, so a repo with no linked worktrees can\n * never reach the manifests. (In the primary clone this is also structural escape #1: \"do the\n * work in the main tree\" needs no allowlist entry to keep working.)\n * • the two roots are DIFFERENT directories — a tree compared with itself is not a skew, it is the\n * single-tree pin-vs-install question the L0 drift guard already owns.\n */\n private applies(tree: EffectiveTree): boolean {\n return tree.kind === 'worktree'\n && path.resolve(tree.mainRoot) !== path.resolve(tree.root);\n }\n\n /** Public so the runner can log all four versions on ALLOW as well as on BLOCK (audit, not just deny). */\n quartetFor(tree: EffectiveTree): VersionQuartet {\n return this.versions.quartet(tree.mainRoot, tree.root);\n }\n\n // Short on purpose — L0 ran a deliberate message diet and these blocks regress into a wall of text\n // if each one argues its case. State the skew, show every version WITH its file, give the git cure\n // first, then the two structural escapes, then what is still allowed.\n private report(tree: EffectiveTree, quartet: VersionQuartet, aiType: AiType): string {\n const skew = this.classify(tree, quartet);\n // The two SELF-SERVE cases print NO escalation, and that omission is the deliverable rather than\n // a saving: an escalation block on a cure the reader can perform HERE teaches it to stop and wait\n // for a main agent who has nothing to do. The other three genuinely need the main tree to move.\n const selfServe = skew === 'main-ahead' || skew === 'worktree-stale';\n const escalation = selfServe ? [] : ['', ...this.escalationLines(tree, quartet, skew, aiType)];\n return [\n `❌ @webpieces version SKEW — this worktree and the main tree disagree, so work here is blocked.`,\n '',\n ...this.versionLines(tree, quartet),\n '',\n ` Whichever tree's hooks are live, one of these two releases lints, validates and builds`,\n ` this worktree — and it may be the one this manifest does not ask for.`,\n '',\n ...this.fixLines(tree, quartet, skew),\n ...escalation,\n '',\n ` STILL ALLOWED HERE: every Read, read-only inspection, \\`pnpm install\\`, \\`git pull\\`/\\`fetch\\`,`,\n ` and edits to pnpm-workspace.yaml / package.json / webpieces.config.json.`,\n ` Do NOT lower the MAIN tree's pin to match — that downgrades every tree, including this`,\n ` session's own governor.`,\n ].join('\\n');\n }\n\n /**\n * WHICH of the five states this is — asked ONCE, so the FIX block and the escalation block can never\n * describe two different diagnoses of the same skew.\n *\n * Order is not arbitrary. `main-inconsistent` is asked FIRST because it is a fault in the governing\n * tree itself: comparing this worktree against a tree that disagrees with itself picks a direction\n * out of two numbers that are not yet one answer. `bump` next, because a deliberate raise is the one\n * shape where the direction is real but every ordinary cure is harmful.\n */\n private classify(tree: EffectiveTree, quartet: VersionQuartet): SkewCase {\n const mainPin = quartet.main.pinned;\n const mainInstalled = quartet.main.installed;\n if (mainPin !== null && mainInstalled !== null && mainPin !== mainInstalled) return 'main-inconsistent';\n if (this.isDeliberateBump(tree, quartet)) return 'bump';\n const wtPin = quartet.worktree.pinned;\n if (mainInstalled !== null && wtPin === mainInstalled && quartet.worktree.installed !== null) return 'worktree-stale';\n return this.compare(mainInstalled, wtPin) > 0 ? 'main-ahead' : 'main-behind';\n }\n\n /**\n * SEMVER ORDER of two versions: 1 when `a` is newer, -1 when older, 0 when equal OR undecidable.\n *\n * 0 is the FAIL-SAFE answer and every caller must read it as \"no opinion\": an unreadable leg, a\n * dist-tag, two different pre-releases, or build metadata (which carries no precedence) all land\n * there, and `classify` then falls to `main-behind`, the branch that ASKS rather than acts. Guessing\n * a direction is how a downgrade gets prescribed, and this repo has already paid for that once.\n *\n * The same rules the shim's awk compare uses, so L0 and L1 cannot order one pair two ways: build\n * metadata stripped, numeric cores compared component-wise, and a pre-release sorting BELOW its\n * release.\n */\n private compare(a: string | null, b: string | null): number {\n if (a === null || b === null || a === b) return 0;\n const aParts = this.parts(a);\n const bParts = this.parts(b);\n if (aParts === null || bParts === null) return 0;\n const width = Math.max(aParts.core.length, bParts.core.length);\n for (let i = 0; i < width; i++) {\n const av = aParts.core[i] ?? 0;\n const bv = bParts.core[i] ?? 0;\n if (av !== bv) return av < bv ? -1 : 1;\n }\n if (aParts.pre === bParts.pre) return 0;\n if (aParts.pre !== '' && bParts.pre === '') return -1;\n if (aParts.pre === '' && bParts.pre !== '') return 1;\n return 0;\n }\n\n /** One version split into its numeric core and its pre-release suffix, or null if it is not numeric. */\n private parts(version: string): VersionParts | null {\n const noBuild = version.replace(/\\+.*$/, '');\n const core = noBuild.replace(/-.*$/, '');\n if (!/^[0-9]+(\\.[0-9]+)*$/.test(core)) return null;\n return new VersionParts(\n core.split('.').map((n: string): number => Number(n)),\n noBuild.slice(core.length),\n );\n }\n\n /**\n * The cure list, which is NOT the same list in both directions — but which, in BOTH directions, is a\n * list of things the reader ASKS FOR rather than runs.\n *\n * The ordinary skew is two trees sitting on different commits of main. The pin is tracked, so putting\n * both trees on the same commit and installing genuinely converges them. That cure is WRONG, and worse\n * than useless, when the branch bumped the pin ON PURPOSE: pulling would revert the deliverable, and\n * an install cannot move a pin in either tree. Printing the git cure first in that case is what sent a\n * real upgrade agent round the loop below.\n *\n * WHAT THIS BLOCK IS NOT ALLOWED TO SAY, in either branch: `git -C <the main tree> pull`. Two defects\n * rode on that one line, and it was printed ABOVE the escalation block, so it was the first thing read.\n * (a) A worktree-isolated SUBAGENT — the overwhelmingly common reader of this deny — CANNOT run\n * cross-tree git at all; the harness refuses it (shim-deny-reason.ts records the same\n * measurement). The one printed cure was the one thing the reader could not perform.\n * (b) A bare `git pull` acts on whatever branch that tree currently has checked out, and the primary\n * clone is normally sitting on a feature branch. It pulls the feature branch, the manifest never\n * moves, the pin never converges, and this guard fires again. The cure has to NAME main:\n * `cd <main> && git checkout main && git pull`.\n * So every step is prefixed `Tell main agent:` — INDIVIDUALLY, not under one shared header. That\n * repetition is deliberate and is the deliverable: a reader who skims exactly one of these lines must\n * still see it is not their own action. Do not factor it out.\n *\n * The FIX block still prints ABOVE the escalation block, on purpose. Moving it below would split the\n * numbered steps from the versions they refer to, and the one place caps are spent on ENDING the turn\n * (STOP WORKING NOW / RETRYING IS THE BUG) has to stay last and stay unique — a second STOP beat\n * competing with it is exactly the wall-of-text regression the L0 message diet exists to prevent.\n * Labelling carries the \"not yours to run\" fact instead, which is what the caps header does.\n */\n private fixLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase): readonly string[] {\n if (skew === 'main-inconsistent') return this.mainInconsistentFix(tree, quartet);\n if (skew === 'main-ahead') return this.mainAheadFix(tree, quartet);\n if (skew === 'worktree-stale') {\n // Every PIN agrees, and so does main's install. The ONLY disagreeing leg is this tree's own\n // node_modules — so this is the one state where a bare `pnpm install` HERE is not a guess,\n // is not a downgrade, and needs nobody's permission. Saying so plainly matters because the\n // other cases all warn AGAINST reaching for it.\n return [\n ` FIX — THIS ONE IS YOURS, AND IT IS ONE COMMAND. Every pin already agrees; only this`,\n ` tree's own node_modules lags at ${this.show(quartet.worktree.installed).trim()}.`,\n ` 1. Run \\`pnpm install\\` HERE, in ${tree.root}.`,\n ` Nothing needs to move in the main tree and there is nobody to ask.`,\n ];\n }\n if (skew === 'bump') {\n return [\n ` THIS BRANCH BUMPED THE PIN ON PURPOSE (${this.show(quartet.main.pinned).trim()} → ${this.show(quartet.worktree.pinned).trim()}), so the usual cures do NOT apply:`,\n ` • \\`pnpm install\\` cannot help in EITHER tree — an install materializes a pin, never moves one.`,\n ` • \\`git pull\\` here would revert the bump, which is the whole deliverable.`,\n ` • Wiping this tree's node_modules does NOT help — the two PINS still disagree, and the`,\n ` L0 drift guard blocks in this guard's place.`,\n ` FIX — YOU CANNOT DO THIS FROM HERE. BOTH ways out need the MAIN tree, and cross-tree`,\n ` git is REFUSED to a subagent, so every step below is something you ASK FOR, not run:`,\n ` 1. Tell main agent: this task has to be redone in the MAIN tree ${tree.mainRoot}`,\n ` — a version bump cannot be done in a worktree at all.`,\n ` 2. Tell main agent: OR raise the MAIN tree's pin to ${this.show(quartet.worktree.pinned).trim()} in`,\n ` ${tree.mainRoot}/${WORKSPACE_MANIFEST} and run \\`pnpm install\\` there.`,\n ` 3. Tell main agent: to tell you when that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ];\n }\n return [\n ` FIX — YOU CANNOT DO THIS FROM HERE. Cross-tree git is REFUSED to a subagent, and a bare`,\n ` \\`git pull\\` moves whatever branch that tree is on — so the cure must NAME main, in main:`,\n ` 1. Tell main agent: \\`cd ${tree.mainRoot} && git checkout main && git pull\\``,\n ` 2. Tell main agent: then run \\`pnpm install\\` in ${tree.mainRoot}`,\n ` 3. Tell main agent: then report back what \\`ls ${tree.mainRoot}/node_modules/@webpieces\\``,\n ` shows, so we know whether the hook shim needs re-upgrading too.`,\n ` 4. Tell main agent: to tell you when ALL of that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ` The two structural escapes, if converging the trees is not what the coordinator wants:`,\n ` • Do the work in the MAIN tree instead — it is never blocked by this guard.`,\n ` • Or use a separate CLONE, not a worktree, if this tree genuinely needs a DIFFERENT`,\n ` version: a clone gets its own governance. A worktree MAY have its own node_modules, so`,\n ` installing here is fine; what it may not have is a DIFFERENT @webpieces version.`,\n ];\n }\n\n /**\n * CASE A — the MAIN tree disagrees with ITSELF: its `node_modules` is on one version while its own\n * `pnpm-workspace.yaml` pins another. Nothing in this worktree is wrong, and nothing this worktree\n * does can help.\n *\n * The cure is deliberately the SMALL one. The generic branch prints `git checkout main && git pull`\n * first, and that is over-prescribed here: both halves of the disagreement are already in that tree,\n * so an install materializes the pin it already has and the skew is gone. Printing the pull as well\n * invites a main agent to move main's commit for a fault that is not about main's commit at all.\n */\n private mainInconsistentFix(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n return [\n ` THE MAIN TREE IS INTERNALLY INCONSISTENT — its node_modules is on ${this.show(quartet.main.installed).trim()} but its own`,\n ` pin says ${this.show(quartet.main.pinned).trim()}. That is not this worktree's fault and not this worktree's to fix.`,\n ` FIX — YOU CANNOT DO THIS FROM HERE. Cross-tree git is REFUSED to a subagent:`,\n ` 1. Tell main agent: run \\`pnpm install\\` in ${tree.mainRoot} — no pull is needed, both`,\n ` halves are already in that tree.`,\n ` 2. Tell main agent: to tell you when that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ];\n }\n\n /**\n * CASE B — the MAIN tree already RUNS a newer release than this tree's pin asks for. This is the\n * common case, and it is the one the old message got exactly backwards.\n *\n * It is the ONLY case a worktree fixes ITSELF. Nothing needs to move in the main tree — the version\n * the guards will judge this tree by is already installed there — so the entire fix is to raise this\n * tree's own pin to match, which is a one-line edit to a TRACKED file this tree owns. Printing an\n * escalation here (as every earlier revision did) tells an agent to stop and wait for a main agent\n * who has nothing to do, which is how a five-minute edit became a stalled turn.\n *\n * The edit is typable from inside the block because pnpm-workspace.yaml is on the L0 allowlist and\n * carved out in the runner's edit path. That carve-out and this text ship together on purpose: a\n * message prescribing a blocked call is the failure shape this repo has been burned by most often.\n *\n * ON A DETACHED HEAD the edit has no branch to belong to, so it is not offered — an edit that\n * survives nothing is worse than no edit. Get onto a branch, then read this message again.\n */\n private mainAheadFix(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n const target = this.show(quartet.main.installed).trim();\n if (this.isDetachedHead(tree.root)) {\n return [\n ` FIX — GET ONTO A BRANCH FIRST. \\`git branch --show-current\\` is empty in ${tree.root}, so`,\n ` HEAD is DETACHED and the one-line pin edit below would belong to no branch at all.`,\n ` 1. Check out a branch here, then re-run this command.`,\n ` 2. The fix is then yours alone: set ${WORKSPACE_MANIFEST}'s catalog pin to ${target}.`,\n ` Nothing needs to move in the main tree — it already runs ${target}.`,\n ];\n }\n const install = quartet.worktree.installed !== null\n ? [` 2. Then run \\`pnpm install\\` HERE — this tree has its own node_modules, so it must be`,\n ` materialized at ${target} too.`]\n : [` 2. Nothing else. This tree has no node_modules of its own, so there is nothing to install.`];\n return [\n ` FIX — THIS ONE IS YOURS, AND YOU CAN DO IT RIGHT HERE. The main tree is AHEAD: it already`,\n ` runs ${target}, so nothing has to move there and there is nobody to ask.`,\n ` 1. Edit ${tree.root}/${WORKSPACE_MANIFEST} — the catalog line for`,\n ` ${UMBRELLA_PACKAGE} — and set it to ${target}. That edit is ALLOWED`,\n ` right now, from inside this block.`,\n ...install,\n ` Do NOT run a bare \\`pnpm install\\` first: this tree's pin is the STALE side, so installing`,\n ` before the edit materializes the OLD release and this guard fires again.`,\n ];\n }\n\n /**\n * Is HEAD DETACHED in this tree — i.e. is there no branch for a pin edit to belong to?\n *\n * `branch --show-current`, NOT `rev-parse --abbrev-ref HEAD`: it answers on an UNBORN branch (which\n * every freshly-created worktree is until its first commit, and where `rev-parse` fatals) and prints\n * EMPTY on a detached HEAD, which is exactly the distinction case B needs.\n *\n * A git FAILURE is NOT detached, and the difference is load-bearing: `--show-current` prints nothing\n * in both situations, so keying off the output alone would tell anyone whose tree git cannot read\n * (no repo, a broken index, git absent) that their HEAD is detached — a confident diagnosis of a\n * state nobody measured. Only an exit-0-with-empty-output is detached; anything else falls back to\n * the ordinary branch wording, whose worst case is prescribing an edit that turns out to be moot.\n */\n private isDetachedHead(root: string): boolean {\n const result = spawnSync('git', ['-C', root, 'branch', '--show-current'], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() === '';\n }\n\n /**\n * THE SUBAGENT CANNOT REACH THE MAIN TREE, so the message it is handed has to be the message it\n * FORWARDS. This used to be one sentence — \"report to your coordinator that one of you must move to\n * the other's version\" — with no command, no direction and nothing pasteable, and the result was a\n * subagent that correctly diagnosed the block, correctly escalated, and handed its coordinator a\n * request too vague to act on. Worse, the obvious guess (\"ask the coordinator to run `pnpm install`\n * in main\") is a NO-OP on a bump: it reinstalls main's own pin and nothing moves.\n *\n * So the escalation is rendered as literal text to forward, with the versions and the direction\n * already filled in. A human cannot sit with every agent; the deny has to carry the whole ask.\n *\n * The ask is ROUTED THROUGH THE MAIN AGENT rather than phrased as a command, and that distinction is\n * the whole point of this block. `git -C <mainRoot> pull` reads like something you run from wherever\n * you are standing — so a subagent reads it, tries it, and only then discovers that CROSS-TREE GIT IS\n * REFUSED to a worktree-isolated agent (same measurement shim-deny-reason.ts records: the harness\n * blocks `git -C <other tree>`, and it is git specifically). This skew needs a git pull in main, so\n * the one printed cure was the one thing this session cannot perform. Be precise about that and do\n * NOT overstate it into \"you cannot reach that tree at all\" — a local `cd <main> && pnpm install`\n * measurably DOES run, it simply cannot move main onto a different commit, which is what a skew\n * requires. The actor who can is the MAIN AGENT running in the MAIN git worktree, so the forwarded\n * text asks for exactly that — and asks to be TOLD WHEN IT IS DONE, because \"the work happened\" is\n * the event that unblocks this subagent and it has no way to observe it otherwise.\n *\n * And it has to say STOP, in caps, because forwarding is only half of what the subagent must do. One\n * measured subagent transcript re-fired this identical deny 13 TIMES (25 across the whole session,\n * counting two sibling subagents and two parent sessions): the subagent read it, escalated exactly\n * as asked — and then kept making tool calls, because nothing here said that forwarding ENDS the\n * turn. Every retry cost a round trip and pushed the one message that mattered further up the\n * scrollback. The block is not transient and no command from this tree slips past it, so retrying is\n * never a strategy; it is the bug. The caps are spent ONLY on that beat (STOP WORKING NOW / NO\n * further tool calls / RETRYING IS THE BUG / WAIT) — shouting the whole report would just restore\n * the wall of text the L0 message diet exists to prevent.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private escalationLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase, aiType: AiType): readonly string[] {\n return [\n ` SUBAGENT? You cannot fix the main tree from here. Forward this to your coordinator verbatim:`,\n ` > My worktree ${tree.root} is on @webpieces ${this.show(quartet.worktree.pinned).trim()};`,\n ` > the main tree ${tree.mainRoot} is on ${this.show(quartet.main.pinned).trim()}.`,\n ...this.askLines(tree, quartet, skew),\n ...this.afterwardLines(aiType),\n ` THEN STOP WORKING NOW. Forwarding that message IS the end of your turn: make NO further tool`,\n ` calls and do NOT retry this one — RETRYING IS THE BUG. Every retry re-fires this identical`,\n ` deny and buries the ask above; one subagent did it 13 times, 25 across that whole session.`,\n ...this.waitLines(aiType),\n ];\n }\n\n /**\n * What the coordinator does ONCE main is synced — and here the two harnesses need opposite answers.\n *\n * Codex runs every subagent in the coordinator's own checkout, so \"tell me when it is done so I can\n * continue\" is literally true: the same agent picks up where it stopped.\n *\n * Claude Code does NOT keep that tree for it. A worktree-isolated subagent that hands back with an\n * unchanged worktree has that worktree REAPED, and a subagent resumed afterwards (SendMessage) comes\n * back with its cwd on the PRIMARY clone — which happened to the first agent on issue #863 itself. So\n * asking to be resumed routes the work into the one tree it must never land in. The ask is therefore a\n * FRESH `isolation: \"worktree\"` subagent, and \"resume me\" / \"continue working\" must not appear.\n */\n private afterwardLines(aiType: AiType): readonly string[] {\n if (aiType === 'codex') {\n return [` > Tell me when that is complete so I can continue working.`];\n }\n return [\n ` > Once main is synced, spawn a FRESH isolation: \"worktree\" subagent to redo this task. Do NOT`,\n ` > message this agent again: my worktree is reaped on hand-back, and a re-messaged agent lands in the primary clone.`,\n ];\n }\n\n private waitLines(aiType: AiType): readonly string[] {\n if (aiType === 'codex') {\n return [\n ` Nothing you can do from this tree clears it. WAIT for the main agent to confirm it is done,`,\n ` then resume — nothing between.`,\n ];\n }\n return [` Nothing you can do from this tree clears it; the coordinator redoes it in a fresh worktree.`];\n }\n\n /**\n * The forwardable ASK, one per case that needs one. `main-ahead` never reaches here — it has nothing\n * to ask for — so the three shapes below cover every escalating case. What happens AFTER the ask is\n * harness-specific and lives in {@link afterwardLines}, so none of these says \"tell me when\".\n *\n * The bump ask carries the upgrade sentence VERBATIM as Dean wrote it, because it answers the one\n * question an upgrade agent gets wrong: \"webpieces cannot be upgraded from a worktree\" is not a\n * missing permission it can route around, it is a property of who governs whom.\n */\n private askLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase): readonly string[] {\n if (skew === 'bump') {\n return [\n ` > A \\`pnpm install\\` in main will NOT fix this — main's PIN has to move. Pick one:`,\n ` > (a) I redo this task in the MAIN tree (a version bump cannot be done in a worktree), or`,\n ` > (b) you TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to`,\n ` > raise main's catalog pin to ${this.show(quartet.worktree.pinned).trim()} and \\`pnpm install\\` there. I cannot reach that tree from here.`,\n ` If you are a subagent upgrading webpieces, STOP — only main agents in worktrees can do`,\n ` this. Otherwise your main agent must \\`git pull\\` main: main has an earlier version of`,\n ` webpieces pinned and must upgrade. You MUST tell the main agent to pull main and`,\n ` \\`pnpm install\\`.`,\n ];\n }\n if (skew === 'main-inconsistent') {\n return [\n ` > Please TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to run`,\n ` > \\`pnpm install\\` there — its node_modules is on ${this.show(quartet.main.installed).trim()} but its own pin says`,\n ` > ${this.show(quartet.main.pinned).trim()}, so no pull is needed. I cannot reach that tree from here.`,\n ];\n }\n return [\n ` > Please TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to run`,\n ` > \\`git checkout main && git pull && pnpm install\\` there — it must NAME main, since a bare`,\n ` > pull moves whatever branch that tree is on — so both trees are on the same release, and`,\n ` > to report what \\`ls node_modules/@webpieces\\` shows there. I cannot reach that tree from here.`,\n ];\n }\n\n /**\n * Did THIS BRANCH change the pin, as opposed to the two trees having drifted onto different commits?\n *\n * Only answerable now that both pin legs actually resolve — before the catalog reader followed YAML\n * anchors they both read null on the repos that pin via an anchor, so every skew looked alike and the\n * report could only ever print the one generic cure.\n *\n * Two git spawns worst case, on the BLOCK path only (this is never reached on an allow), and\n * best-effort: a git failure answers \"not a deliberate bump\", which falls back to the generic cure\n * that was the only text this report had before.\n */\n private isDeliberateBump(tree: EffectiveTree, quartet: VersionQuartet): boolean {\n if (quartet.main.pinned === null || quartet.worktree.pinned === null) return false;\n if (quartet.main.pinned === quartet.worktree.pinned) return false;\n return this.touchesWorkspaceFile(tree.root, ['status', '--porcelain', '--', WORKSPACE_MANIFEST])\n || this.touchesWorkspaceFile(tree.root, ['diff', '--name-only', 'origin/main...HEAD', '--', WORKSPACE_MANIFEST]);\n }\n\n private touchesWorkspaceFile(root: string, args: readonly string[]): boolean {\n const result = spawnSync('git', ['-C', root, ...args], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() !== '';\n }\n\n // Every version WITH the file it came from. An agent that is told \"they disagree\" without being told\n // WHICH FILE to edit re-derives it by grepping, which is exactly the turn-burning this guard exists\n // to prevent. Unreadable legs are printed as `-` rather than omitted, so the reader can tell\n // \"this one is absent\" from \"I forgot to look\".\n private versionLines(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n const lines = [\n ` main pin ${this.show(quartet.main.pinned)} ${tree.mainRoot}/pnpm-workspace.yaml`,\n ` main installed ${this.show(quartet.main.installed)} ${tree.mainRoot}/node_modules/${UMBRELLA_PACKAGE}`,\n ` ^ the binary judging this very call`,\n ` this worktree ${this.show(quartet.worktree.pinned)} ${tree.root}/pnpm-workspace.yaml`,\n ];\n if (quartet.worktree.installed !== null) {\n lines.push(` its installed ${this.show(quartet.worktree.installed)} ${tree.root}/node_modules/${UMBRELLA_PACKAGE}`);\n lines.push(' ^ what nx, vitest and eslint load IN this tree');\n }\n const others = this.versions.otherWorktrees(tree.mainRoot, tree.root);\n if (others.length > 0) {\n lines.push(` NOTE ${others.length} other worktree(s) exist and are governed the same way — if they are`);\n lines.push(' skewed too, their agents are already mis-governed. Consider clones, or');\n lines.push(' serializing the work in the main tree.');\n }\n return lines;\n }\n\n private show(version: string | null): string {\n return (version ?? '-').padEnd(10);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"version-sync.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/version-sync.ts"],"names":[],"mappings":";;;;AACA,iDAA0C;AAC1C,mDAA6B;AAE7B,sDAAyD;AAEzD,iEAAgE;AAChE,6DAA2F;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,8FAA8F;AAC9F,MAAM,YAAY;IAGD;IAEA;IAJb;IACI,gDAAgD;IACvC,IAAuB;IAChC,mFAAmF;IAC1E,GAAW;QAFX,SAAI,G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,CAAC,gDAAgD,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,IAAI,CAAC,OAAsB;QAC/B,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;CACJ;AA3eD,4CA2eC","sourcesContent":["import { AiType } from './agent-event';\nimport { spawnSync } from 'child_process';\nimport * as path from 'path';\n\nimport { WORKSPACE_MANIFEST } from '../bin/l0-allowlist';\nimport { EffectiveTree } from './effective-tree';\nimport { ReadOnlyInspectionScan } from './read-only-inspection';\nimport { UMBRELLA_PACKAGE, VersionQuartet, WebpiecesVersions } from './webpieces-versions';\n\n/**\n * L1 row 8 — a tree may not be worked in while its `@webpieces` version disagrees with the MAIN tree's.\n *\n * ─── WHY THIS EXISTS, and what it replaces ─────────────────────────────────────────────────────────\n * The guard hooks are registered ABSOLUTE (`$CLAUDE_PROJECT_DIR/...`), so the MAIN tree governs every\n * tree. That is not a new imposition — it is what was always happening, because a linked worktree has no\n * `node_modules` and ai-hook.sh's upward walk already executed the main tree's binary. The design now\n * says so out loud, which makes ONE case newly important: a worktree whose branch pins a DIFFERENT\n * release is being linted, validated and built by a release it never asked for.\n *\n * This guard makes that case LOUD instead of silent. It replaces `CoordinatorWorktreeGuard`, and the\n * replacement is strictly better on the axis that matters: the old guard keyed off WHO was asking\n * (coordinator vs subagent), and agent identity was measured untrustworthy — a worktree-isolated agent\n * whose tree is auto-reaped at a turn boundary silently resumes with its cwd on the primary clone\n * (reproduced twice, 2026-08-10). This guard keys off the PATH the command acts on, which cannot lie.\n *\n * ─── IT EXISTS TO STOP A LOOP, not to enforce tidiness ─────────────────────────────────────────────\n * A main/worktree manifest mismatch is exactly the shape that produced the founding incident: an agent\n * is shown a fault measured against one tree, runs the prescribed cure in another, the cure succeeds,\n * nothing the guard measures changes, and the guard re-denies. Five identical no-op `pnpm install`s and\n * a fabricated theory about the harness later, a human had to untangle it. Firing EARLY, with a message\n * that names all the versions and all their files, is the whole point. Any future proposal to soften\n * this to a warning must answer: what stops the five-install loop instead?\n *\n * ─── Never a deadlock ──────────────────────────────────────────────────────────────────────────────\n * Two structurally independent escapes, and neither depends on an allowlist regex staying in step:\n * 1. WORK IN THE MAIN TREE — a main-tree-targeted command cannot classify as `worktree`, so it never\n * reaches this guard at all. No allowlist entry can break it because none is involved.\n * 2. EDIT THE MANIFESTS — `pnpm-workspace.yaml` / `package.json` edits are carved out in the runner\n * (`runInternal`, beside the `webpieces.config.json` pass) and on the L0 allowlist\n * (`MANIFEST_FILENAMES` / `isAllowed`), so the cure is typable from inside the block.\n * Reads and read-only inspection are never blocked either, so an agent can always look before it fixes.\n *\n * THAT SECOND ESCAPE WAS FICTION UNTIL 2026-08-20, and this docblock asserted it anyway. Only\n * `CONFIG_FILENAME` was ever carved out, so the one cure the report told a blocked agent to perform —\n * raise this tree's pin — was itself blocked. It is real now, and the `main-ahead` branch of `fixLines`\n * is what spends it. A future edit that narrows either carve-out has to change this text too.\n *\n * ─── The MAIN tree is `tree.mainRoot`, never `tree.governedRoot` ───────────────────────────────────\n * The two differ for exactly the reader this guard is for. `governedRoot` is walked up from the payload\n * cwd to the nearest `webpieces.config.json`, and that file is TRACKED — a linked worktree has its own.\n * So for an agent resident in a worktree `governedRoot` IS the worktree, and comparing it against\n * `tree.root` compared the tree with ITSELF: trivially in sync, guard silent. `mainRoot` is git's\n * `<git-common-dir>/..`, i.e. the clone whose `node_modules` actually supplies the judging binary, and\n * it is the same answer from every checkout. Measured 2026-08-10: a worktree on 0.4.624 with its own\n * install, a main clone on 0.4.616, and not one word from this guard.\n */\n/** One version reduced to what an order compare needs. Data-only → a class, per CLAUDE.md. */\nclass VersionParts {\n constructor(\n /** The numeric core, most-significant first. */\n readonly core: readonly number[],\n /** The pre-release suffix INCLUDING its leading `-`, or '' for a plain release. */\n readonly pre: string,\n ) {}\n}\n\n/**\n * WHICH of the five states this skew is. The whole point of naming them is that they do NOT share a\n * cure, and printing the wrong one is what walked a real agent backwards through a downgrade:\n *\n * `main-inconsistent` — the MAIN tree disagrees with ITSELF (its pin ≠ its own node_modules). Nothing\n * about this worktree is wrong; only the main agent can fix it, with one install.\n * `bump` — this branch RAISED the pin on purpose. The deliverable is the pin, so every\n * ordinary cure would revert it. Main has to come up to meet it.\n * `main-ahead` — the governing tree already RUNS a newer release than this tree's pin asks for.\n * This is the common case, and it is the ONE case the worktree fixes ITSELF, by\n * raising its own pin. No escalation, nobody to ask, nothing to wait for.\n * `worktree-stale` — every PIN agrees and so does main's install; only this tree's OWN node_modules\n * lags. The one state where a bare `pnpm install` HERE is exactly right.\n * `main-behind` — main is genuinely older and must move forward. Only the main agent can pull it.\n */\ntype SkewCase = 'main-inconsistent' | 'bump' | 'main-ahead' | 'worktree-stale' | 'main-behind';\n\nexport class VersionSyncGuard {\n private readonly inspection = new ReadOnlyInspectionScan();\n private readonly versions = new WebpiecesVersions();\n\n /**\n * True when this tree is a linked worktree whose webpieces version disagrees with the main tree's.\n * This is the `V` dimension of the L1 matrix; the runner asks it for EVERY Bash call so the answer\n * lands in the audit log even when nothing blocks.\n */\n skewed(tree: EffectiveTree): boolean {\n if (!this.applies(tree)) return false;\n return !this.quartetFor(tree).inSync;\n }\n\n /** The deny report, or null to allow. */\n block(command: string, tree: EffectiveTree, aiType: AiType): string | null {\n if (!this.applies(tree)) return null;\n if (this.inspection.isReadOnlyInspection(command)) return null;\n if (this.isCureOrLook(command)) return null;\n const quartet = this.quartetFor(tree);\n if (quartet.inSync) return null;\n return this.report(tree, quartet, aiType);\n }\n\n /**\n * Commands that must pass EVEN WHILE THIS GUARD IS BLOCKING, because they are how you get unblocked\n * — or how you look at the tree first.\n *\n * `ReadOnlyInspectionScan` deliberately excludes git and gh OUTRIGHT (\"the guards exist to police\n * git, and read-only git is not a line worth drawing while flying blind\"), which is right for the\n * guards that police git but WRONG here: this guard's own prescribed cure is `git pull` in both\n * trees. Without this carve-out the guard would deny the exact command it tells the reader to run —\n * the single failure shape this repo has been burned by most often, and the reason the deny text is\n * allowed to promise \"STILL ALLOWED HERE: ... pnpm install, git pull/fetch\".\n *\n * Deliberately NARROW: fetching, pulling and installing cannot make a skew worse, and every one of\n * them moves the tree toward agreement. Anything that BUILDS, TESTS or COMMITS is still blocked,\n * because those are the operations that would be judged by the wrong release.\n */\n private isCureOrLook(command: string): boolean {\n const words = command.trim().split(/\\s+/);\n const head = words[0] ?? '';\n const sub = words[1] ?? '';\n if (head === 'git' || head === 'gh') {\n // `git -C <dir> <sub>` names its own directory; take the first non-flag word after it.\n const subcommand = sub === '-C' ? (words[3] ?? '') : sub;\n return ['pull', 'fetch', 'status', 'log', 'diff', 'show', 'branch', 'rev-parse', 'worktree'].includes(subcommand);\n }\n return (head === 'pnpm' || head === 'npm') && (sub === 'install' || sub === 'i');\n }\n\n /**\n * Is there a cross-tree comparison to make at all? TWO cheap conditions, no file read behind either:\n *\n * • K is `worktree` — git's `--git-dir ≠ --git-common-dir`, so a repo with no linked worktrees can\n * never reach the manifests. (In the primary clone this is also structural escape #1: \"do the\n * work in the main tree\" needs no allowlist entry to keep working.)\n * • the two roots are DIFFERENT directories — a tree compared with itself is not a skew, it is the\n * single-tree pin-vs-install question the L0 drift guard already owns.\n */\n private applies(tree: EffectiveTree): boolean {\n return tree.kind === 'worktree'\n && path.resolve(tree.mainRoot) !== path.resolve(tree.root);\n }\n\n /** Public so the runner can log all four versions on ALLOW as well as on BLOCK (audit, not just deny). */\n quartetFor(tree: EffectiveTree): VersionQuartet {\n return this.versions.quartet(tree.mainRoot, tree.root);\n }\n\n // Short on purpose — L0 ran a deliberate message diet and these blocks regress into a wall of text\n // if each one argues its case. State the skew, show every version WITH its file, give the git cure\n // first, then the two structural escapes, then what is still allowed.\n private report(tree: EffectiveTree, quartet: VersionQuartet, aiType: AiType): string {\n const skew = this.classify(tree, quartet);\n // The two SELF-SERVE cases print NO escalation, and that omission is the deliverable rather than\n // a saving: an escalation block on a cure the reader can perform HERE teaches it to stop and wait\n // for a main agent who has nothing to do. The other three genuinely need the main tree to move.\n const selfServe = skew === 'main-ahead' || skew === 'worktree-stale';\n const escalation = selfServe ? [] : ['', ...this.escalationLines(tree, quartet, skew, aiType)];\n return [\n `❌ @webpieces version SKEW — this worktree and the main tree disagree, so work here is blocked.`,\n '',\n ...this.versionLines(tree, quartet),\n '',\n ` Whichever tree's hooks are live, one of these two releases lints, validates and builds`,\n ` this worktree — and it may be the one this manifest does not ask for.`,\n '',\n ...this.fixLines(tree, quartet, skew),\n ...escalation,\n '',\n ` STILL ALLOWED HERE: every Read, read-only inspection, \\`pnpm install\\`, \\`git pull\\`/\\`fetch\\`,`,\n ` and edits to pnpm-workspace.yaml / package.json / webpieces.config.json.`,\n ` Do NOT lower the MAIN tree's pin to match — that downgrades every tree, including this`,\n ` session's own governor.`,\n ].join('\\n');\n }\n\n /**\n * WHICH of the five states this is — asked ONCE, so the FIX block and the escalation block can never\n * describe two different diagnoses of the same skew.\n *\n * Order is not arbitrary. `main-inconsistent` is asked FIRST because it is a fault in the governing\n * tree itself: comparing this worktree against a tree that disagrees with itself picks a direction\n * out of two numbers that are not yet one answer. `bump` next, because a deliberate raise is the one\n * shape where the direction is real but every ordinary cure is harmful.\n */\n private classify(tree: EffectiveTree, quartet: VersionQuartet): SkewCase {\n const mainPin = quartet.main.pinned;\n const mainInstalled = quartet.main.installed;\n if (mainPin !== null && mainInstalled !== null && mainPin !== mainInstalled) return 'main-inconsistent';\n if (this.isDeliberateBump(tree, quartet)) return 'bump';\n const wtPin = quartet.worktree.pinned;\n if (mainInstalled !== null && wtPin === mainInstalled && quartet.worktree.installed !== null) return 'worktree-stale';\n return this.compare(mainInstalled, wtPin) > 0 ? 'main-ahead' : 'main-behind';\n }\n\n /**\n * SEMVER ORDER of two versions: 1 when `a` is newer, -1 when older, 0 when equal OR undecidable.\n *\n * 0 is the FAIL-SAFE answer and every caller must read it as \"no opinion\": an unreadable leg, a\n * dist-tag, two different pre-releases, or build metadata (which carries no precedence) all land\n * there, and `classify` then falls to `main-behind`, the branch that ASKS rather than acts. Guessing\n * a direction is how a downgrade gets prescribed, and this repo has already paid for that once.\n *\n * The same rules the shim's awk compare uses, so L0 and L1 cannot order one pair two ways: build\n * metadata stripped, numeric cores compared component-wise, and a pre-release sorting BELOW its\n * release.\n */\n private compare(a: string | null, b: string | null): number {\n if (a === null || b === null || a === b) return 0;\n const aParts = this.parts(a);\n const bParts = this.parts(b);\n if (aParts === null || bParts === null) return 0;\n const width = Math.max(aParts.core.length, bParts.core.length);\n for (let i = 0; i < width; i++) {\n const av = aParts.core[i] ?? 0;\n const bv = bParts.core[i] ?? 0;\n if (av !== bv) return av < bv ? -1 : 1;\n }\n if (aParts.pre === bParts.pre) return 0;\n if (aParts.pre !== '' && bParts.pre === '') return -1;\n if (aParts.pre === '' && bParts.pre !== '') return 1;\n return 0;\n }\n\n /** One version split into its numeric core and its pre-release suffix, or null if it is not numeric. */\n private parts(version: string): VersionParts | null {\n const noBuild = version.replace(/\\+.*$/, '');\n const core = noBuild.replace(/-.*$/, '');\n if (!/^[0-9]+(\\.[0-9]+)*$/.test(core)) return null;\n return new VersionParts(\n core.split('.').map((n: string): number => Number(n)),\n noBuild.slice(core.length),\n );\n }\n\n /**\n * The cure list, which is NOT the same list in both directions — but which, in BOTH directions, is a\n * list of things the reader ASKS FOR rather than runs.\n *\n * The ordinary skew is two trees sitting on different commits of main. The pin is tracked, so putting\n * both trees on the same commit and installing genuinely converges them. That cure is WRONG, and worse\n * than useless, when the branch bumped the pin ON PURPOSE: pulling would revert the deliverable, and\n * an install cannot move a pin in either tree. Printing the git cure first in that case is what sent a\n * real upgrade agent round the loop below.\n *\n * WHAT THIS BLOCK IS NOT ALLOWED TO SAY, in either branch: `git -C <the main tree> pull`. Two defects\n * rode on that one line, and it was printed ABOVE the escalation block, so it was the first thing read.\n * (a) A worktree-isolated SUBAGENT — the overwhelmingly common reader of this deny — CANNOT run\n * cross-tree git at all; the harness refuses it (shim-deny-reason.ts records the same\n * measurement). The one printed cure was the one thing the reader could not perform.\n * (b) A bare `git pull` acts on whatever branch that tree currently has checked out, and the primary\n * clone is normally sitting on a feature branch. It pulls the feature branch, the manifest never\n * moves, the pin never converges, and this guard fires again. The cure has to NAME main:\n * `cd <main> && git checkout main && git pull`.\n * So every step is prefixed `Tell main agent:` — INDIVIDUALLY, not under one shared header. That\n * repetition is deliberate and is the deliverable: a reader who skims exactly one of these lines must\n * still see it is not their own action. Do not factor it out.\n *\n * The FIX block still prints ABOVE the escalation block, on purpose. Moving it below would split the\n * numbered steps from the versions they refer to, and the do-not-retry beat has to stay last and stay\n * unique — a second shouted beat competing with it is exactly the wall-of-text regression the L0\n * message diet exists to prevent.\n * Labelling carries the \"not yours to run\" fact instead, which is what the caps header does.\n */\n private fixLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase): readonly string[] {\n if (skew === 'main-inconsistent') return this.mainInconsistentFix(tree, quartet);\n if (skew === 'main-ahead') return this.mainAheadFix(tree, quartet);\n if (skew === 'worktree-stale') {\n // Every PIN agrees, and so does main's install. The ONLY disagreeing leg is this tree's own\n // node_modules — so this is the one state where a bare `pnpm install` HERE is not a guess,\n // is not a downgrade, and needs nobody's permission. Saying so plainly matters because the\n // other cases all warn AGAINST reaching for it.\n return [\n ` FIX — THIS ONE IS YOURS, AND IT IS ONE COMMAND. Every pin already agrees; only this`,\n ` tree's own node_modules lags at ${this.show(quartet.worktree.installed).trim()}.`,\n ` 1. Run \\`pnpm install\\` HERE, in ${tree.root}.`,\n ` Nothing needs to move in the main tree and there is nobody to ask.`,\n ];\n }\n if (skew === 'bump') {\n return [\n ` THIS BRANCH BUMPED THE PIN ON PURPOSE (${this.show(quartet.main.pinned).trim()} → ${this.show(quartet.worktree.pinned).trim()}), so the usual cures do NOT apply:`,\n ` • \\`pnpm install\\` cannot help in EITHER tree — an install materializes a pin, never moves one.`,\n ` • \\`git pull\\` here would revert the bump, which is the whole deliverable.`,\n ` • Wiping this tree's node_modules does NOT help — the two PINS still disagree, and the`,\n ` L0 drift guard blocks in this guard's place.`,\n ` FIX — YOU CANNOT DO THIS FROM HERE. BOTH ways out need the MAIN tree, and cross-tree`,\n ` git is REFUSED to a subagent, so every step below is something you ASK FOR, not run:`,\n ` 1. Tell main agent: this task has to be redone in the MAIN tree ${tree.mainRoot}`,\n ` — a version bump cannot be done in a worktree at all.`,\n ` 2. Tell main agent: OR raise the MAIN tree's pin to ${this.show(quartet.worktree.pinned).trim()} in`,\n ` ${tree.mainRoot}/${WORKSPACE_MANIFEST} and run \\`pnpm install\\` there.`,\n ` 3. Tell main agent: to tell you when that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ];\n }\n return [\n ` FIX — YOU CANNOT DO THIS FROM HERE. Cross-tree git is REFUSED to a subagent, and a bare`,\n ` \\`git pull\\` moves whatever branch that tree is on — so the cure must NAME main, in main:`,\n ` 1. Tell main agent: \\`cd ${tree.mainRoot} && git checkout main && git pull\\``,\n ` 2. Tell main agent: then run \\`pnpm install\\` in ${tree.mainRoot}`,\n ` 3. Tell main agent: then report back what \\`ls ${tree.mainRoot}/node_modules/@webpieces\\``,\n ` shows, so we know whether the hook shim needs re-upgrading too.`,\n ` 4. Tell main agent: to tell you when ALL of that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ` The two structural escapes, if converging the trees is not what the coordinator wants:`,\n ` • Do the work in the MAIN tree instead — it is never blocked by this guard.`,\n ` • Or use a separate CLONE, not a worktree, if this tree genuinely needs a DIFFERENT`,\n ` version: a clone gets its own governance. A worktree MAY have its own node_modules, so`,\n ` installing here is fine; what it may not have is a DIFFERENT @webpieces version.`,\n ];\n }\n\n /**\n * CASE A — the MAIN tree disagrees with ITSELF: its `node_modules` is on one version while its own\n * `pnpm-workspace.yaml` pins another. Nothing in this worktree is wrong, and nothing this worktree\n * does can help.\n *\n * The cure is deliberately the SMALL one. The generic branch prints `git checkout main && git pull`\n * first, and that is over-prescribed here: both halves of the disagreement are already in that tree,\n * so an install materializes the pin it already has and the skew is gone. Printing the pull as well\n * invites a main agent to move main's commit for a fault that is not about main's commit at all.\n */\n private mainInconsistentFix(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n return [\n ` THE MAIN TREE IS INTERNALLY INCONSISTENT — its node_modules is on ${this.show(quartet.main.installed).trim()} but its own`,\n ` pin says ${this.show(quartet.main.pinned).trim()}. That is not this worktree's fault and not this worktree's to fix.`,\n ` FIX — YOU CANNOT DO THIS FROM HERE. Cross-tree git is REFUSED to a subagent:`,\n ` 1. Tell main agent: run \\`pnpm install\\` in ${tree.mainRoot} — no pull is needed, both`,\n ` halves are already in that tree.`,\n ` 2. Tell main agent: to tell you when that is complete.`,\n ` THEN AND ONLY THEN will this worktree — and every other subagent — work again.`,\n ];\n }\n\n /**\n * CASE B — the MAIN tree already RUNS a newer release than this tree's pin asks for. This is the\n * common case, and it is the one the old message got exactly backwards.\n *\n * It is the ONLY case a worktree fixes ITSELF. Nothing needs to move in the main tree — the version\n * the guards will judge this tree by is already installed there — so the entire fix is to raise this\n * tree's own pin to match, which is a one-line edit to a TRACKED file this tree owns. Printing an\n * escalation here (as every earlier revision did) tells an agent to stop and wait for a main agent\n * who has nothing to do, which is how a five-minute edit became a stalled turn.\n *\n * The edit is typable from inside the block because pnpm-workspace.yaml is on the L0 allowlist and\n * carved out in the runner's edit path. That carve-out and this text ship together on purpose: a\n * message prescribing a blocked call is the failure shape this repo has been burned by most often.\n *\n * ON A DETACHED HEAD the edit has no branch to belong to, so it is not offered — an edit that\n * survives nothing is worse than no edit. Get onto a branch, then read this message again.\n */\n private mainAheadFix(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n const target = this.show(quartet.main.installed).trim();\n if (this.isDetachedHead(tree.root)) {\n return [\n ` FIX — GET ONTO A BRANCH FIRST. \\`git branch --show-current\\` is empty in ${tree.root}, so`,\n ` HEAD is DETACHED and the one-line pin edit below would belong to no branch at all.`,\n ` 1. Check out a branch here, then re-run this command.`,\n ` 2. The fix is then yours alone: set ${WORKSPACE_MANIFEST}'s catalog pin to ${target}.`,\n ` Nothing needs to move in the main tree — it already runs ${target}.`,\n ];\n }\n const install = quartet.worktree.installed !== null\n ? [` 2. Then run \\`pnpm install\\` HERE — this tree has its own node_modules, so it must be`,\n ` materialized at ${target} too.`]\n : [` 2. Nothing else. This tree has no node_modules of its own, so there is nothing to install.`];\n return [\n ` FIX — THIS ONE IS YOURS, AND YOU CAN DO IT RIGHT HERE. The main tree is AHEAD: it already`,\n ` runs ${target}, so nothing has to move there and there is nobody to ask.`,\n ` 1. Edit ${tree.root}/${WORKSPACE_MANIFEST} — the catalog line for`,\n ` ${UMBRELLA_PACKAGE} — and set it to ${target}. That edit is ALLOWED`,\n ` right now, from inside this block.`,\n ...install,\n ` Do NOT run a bare \\`pnpm install\\` first: this tree's pin is the STALE side, so installing`,\n ` before the edit materializes the OLD release and this guard fires again.`,\n ];\n }\n\n /**\n * Is HEAD DETACHED in this tree — i.e. is there no branch for a pin edit to belong to?\n *\n * `branch --show-current`, NOT `rev-parse --abbrev-ref HEAD`: it answers on an UNBORN branch (which\n * every freshly-created worktree is until its first commit, and where `rev-parse` fatals) and prints\n * EMPTY on a detached HEAD, which is exactly the distinction case B needs.\n *\n * A git FAILURE is NOT detached, and the difference is load-bearing: `--show-current` prints nothing\n * in both situations, so keying off the output alone would tell anyone whose tree git cannot read\n * (no repo, a broken index, git absent) that their HEAD is detached — a confident diagnosis of a\n * state nobody measured. Only an exit-0-with-empty-output is detached; anything else falls back to\n * the ordinary branch wording, whose worst case is prescribing an edit that turns out to be moot.\n */\n private isDetachedHead(root: string): boolean {\n const result = spawnSync('git', ['-C', root, 'branch', '--show-current'], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() === '';\n }\n\n /**\n * THE SUBAGENT CANNOT REACH THE MAIN TREE, so the message it is handed has to be the message it\n * FORWARDS. This used to be one sentence — \"report to your coordinator that one of you must move to\n * the other's version\" — with no command, no direction and nothing pasteable, and the result was a\n * subagent that correctly diagnosed the block, correctly escalated, and handed its coordinator a\n * request too vague to act on. Worse, the obvious guess (\"ask the coordinator to run `pnpm install`\n * in main\") is a NO-OP on a bump: it reinstalls main's own pin and nothing moves.\n *\n * So the escalation is rendered as literal text to forward, with the versions and the direction\n * already filled in. A human cannot sit with every agent; the deny has to carry the whole ask.\n *\n * The ask is ROUTED THROUGH THE MAIN AGENT rather than phrased as a command, and that distinction is\n * the whole point of this block. `git -C <mainRoot> pull` reads like something you run from wherever\n * you are standing — so a subagent reads it, tries it, and only then discovers that CROSS-TREE GIT IS\n * REFUSED to a worktree-isolated agent (same measurement shim-deny-reason.ts records: the harness\n * blocks `git -C <other tree>`, and it is git specifically). This skew needs a git pull in main, so\n * the one printed cure was the one thing this session cannot perform. Be precise about that and do\n * NOT overstate it into \"you cannot reach that tree at all\" — a local `cd <main> && pnpm install`\n * measurably DOES run, it simply cannot move main onto a different commit, which is what a skew\n * requires. The actor who can is the MAIN AGENT running in the MAIN git worktree, so the forwarded\n * text asks for exactly that — and asks to be TOLD WHEN IT IS DONE, because \"the work happened\" is\n * the event that unblocks this subagent and it has no way to observe it otherwise.\n *\n * And it has to refuse the RETRY, because forwarding is only half of what the subagent must do. One\n * measured subagent transcript re-fired this identical deny 13 TIMES (25 across the whole session,\n * counting two sibling subagents and two parent sessions): the subagent read it, escalated exactly\n * as asked — and then re-ran the blocked call. Every retry cost a round trip and pushed the one\n * message that mattered further up the scrollback. The block is not transient and no command from\n * this tree slips past it, so retrying is never a strategy; it is the bug.\n *\n * What it must NOT do is decide the agent's control flow. #679 first wrote this beat as \"STOP WORKING\n * NOW. Forwarding that message IS the end of your turn: make NO further tool calls\" — a turn-level\n * prescription, which `.claude/rules/never-tell-an-ai-to-end-its-turn.md` forbids (#902 deleted every\n * other one; this one survived because no spec rendered it — issue #1000). Refusing one futile\n * command is legitimate; ruling on when the turn ends is a judgement the agent is better placed to\n * make. So the beat names the retry, says why it is futile, and stops talking.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private escalationLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase, aiType: AiType): readonly string[] {\n return [\n ` SUBAGENT? You cannot fix the main tree from here. Forward this to your coordinator verbatim:`,\n ` > My worktree ${tree.root} is on @webpieces ${this.show(quartet.worktree.pinned).trim()};`,\n ` > the main tree ${tree.mainRoot} is on ${this.show(quartet.main.pinned).trim()}.`,\n ...this.askLines(tree, quartet, skew),\n ...this.afterwardLines(aiType),\n ` Do NOT retry this call — RETRYING IS THE BUG. It re-fires this identical deny and buries the`,\n ` ask above; one subagent did it 13 times, 25 across that whole session.`,\n ...this.waitLines(aiType),\n ];\n }\n\n /**\n * What the coordinator does ONCE main is synced — and here the two harnesses need opposite answers.\n *\n * Codex runs every subagent in the coordinator's own checkout, so \"tell me when it is done so I can\n * continue\" is literally true: the same agent picks up where it stopped.\n *\n * Claude Code does NOT keep that tree for it. A worktree-isolated subagent that hands back with an\n * unchanged worktree has that worktree REAPED, and a subagent resumed afterwards (SendMessage) comes\n * back with its cwd on the PRIMARY clone — which happened to the first agent on issue #863 itself. So\n * asking to be resumed routes the work into the one tree it must never land in. The ask is therefore a\n * FRESH `isolation: \"worktree\"` subagent, and \"resume me\" / \"continue working\" must not appear.\n */\n private afterwardLines(aiType: AiType): readonly string[] {\n if (aiType === 'codex') {\n return [` > Tell me when that is complete so I can continue working.`];\n }\n return [\n ` > Once main is synced, spawn a FRESH isolation: \"worktree\" subagent to redo this task. Do NOT`,\n ` > message this agent again: my worktree is reaped on hand-back, and a re-messaged agent lands in the primary clone.`,\n ];\n }\n\n private waitLines(aiType: AiType): readonly string[] {\n if (aiType === 'codex') {\n // The three-move wait shape (never-tell-an-ai-to-end-its-turn.md): name the efficient option,\n // name the wasteful one, and say nothing about when a turn ends.\n return [\n ` Nothing you can do from this tree clears it. Be efficient with tokens: wait on the main`,\n ` agent's confirmation instead of re-running blocked calls to see whether it has cleared.`,\n ];\n }\n return [` Nothing you can do from this tree clears it; the coordinator redoes it in a fresh worktree.`];\n }\n\n /**\n * The forwardable ASK, one per case that needs one. `main-ahead` never reaches here — it has nothing\n * to ask for — so the three shapes below cover every escalating case. What happens AFTER the ask is\n * harness-specific and lives in {@link afterwardLines}, so none of these says \"tell me when\".\n *\n * The bump ask carries the upgrade sentence VERBATIM as Dean wrote it, because it answers the one\n * question an upgrade agent gets wrong: \"webpieces cannot be upgraded from a worktree\" is not a\n * missing permission it can route around, it is a property of who governs whom.\n */\n private askLines(tree: EffectiveTree, quartet: VersionQuartet, skew: SkewCase): readonly string[] {\n if (skew === 'bump') {\n return [\n ` > A \\`pnpm install\\` in main will NOT fix this — main's PIN has to move. Pick one:`,\n ` > (a) I redo this task in the MAIN tree (a version bump cannot be done in a worktree), or`,\n ` > (b) you TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to`,\n ` > raise main's catalog pin to ${this.show(quartet.worktree.pinned).trim()} and \\`pnpm install\\` there. I cannot reach that tree from here.`,\n ` If you are a subagent upgrading webpieces, STOP — only main agents in worktrees can do`,\n ` this. Otherwise your main agent must \\`git pull\\` main: main has an earlier version of`,\n ` webpieces pinned and must upgrade. You MUST tell the main agent to pull main and`,\n ` \\`pnpm install\\`.`,\n ];\n }\n if (skew === 'main-inconsistent') {\n return [\n ` > Please TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to run`,\n ` > \\`pnpm install\\` there — its node_modules is on ${this.show(quartet.main.installed).trim()} but its own pin says`,\n ` > ${this.show(quartet.main.pinned).trim()}, so no pull is needed. I cannot reach that tree from here.`,\n ];\n }\n return [\n ` > Please TELL THE MAIN AGENT in the MAIN git worktree ${tree.mainRoot} to run`,\n ` > \\`git checkout main && git pull && pnpm install\\` there — it must NAME main, since a bare`,\n ` > pull moves whatever branch that tree is on — so both trees are on the same release, and`,\n ` > to report what \\`ls node_modules/@webpieces\\` shows there. I cannot reach that tree from here.`,\n ];\n }\n\n /**\n * Did THIS BRANCH change the pin, as opposed to the two trees having drifted onto different commits?\n *\n * Only answerable now that both pin legs actually resolve — before the catalog reader followed YAML\n * anchors they both read null on the repos that pin via an anchor, so every skew looked alike and the\n * report could only ever print the one generic cure.\n *\n * Two git spawns worst case, on the BLOCK path only (this is never reached on an allow), and\n * best-effort: a git failure answers \"not a deliberate bump\", which falls back to the generic cure\n * that was the only text this report had before.\n */\n private isDeliberateBump(tree: EffectiveTree, quartet: VersionQuartet): boolean {\n if (quartet.main.pinned === null || quartet.worktree.pinned === null) return false;\n if (quartet.main.pinned === quartet.worktree.pinned) return false;\n return this.touchesWorkspaceFile(tree.root, ['status', '--porcelain', '--', WORKSPACE_MANIFEST])\n || this.touchesWorkspaceFile(tree.root, ['diff', '--name-only', 'origin/main...HEAD', '--', WORKSPACE_MANIFEST]);\n }\n\n private touchesWorkspaceFile(root: string, args: readonly string[]): boolean {\n const result = spawnSync('git', ['-C', root, ...args], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() !== '';\n }\n\n // Every version WITH the file it came from. An agent that is told \"they disagree\" without being told\n // WHICH FILE to edit re-derives it by grepping, which is exactly the turn-burning this guard exists\n // to prevent. Unreadable legs are printed as `-` rather than omitted, so the reader can tell\n // \"this one is absent\" from \"I forgot to look\".\n private versionLines(tree: EffectiveTree, quartet: VersionQuartet): readonly string[] {\n const lines = [\n ` main pin ${this.show(quartet.main.pinned)} ${tree.mainRoot}/pnpm-workspace.yaml`,\n ` main installed ${this.show(quartet.main.installed)} ${tree.mainRoot}/node_modules/${UMBRELLA_PACKAGE}`,\n ` ^ the binary judging this very call`,\n ` this worktree ${this.show(quartet.worktree.pinned)} ${tree.root}/pnpm-workspace.yaml`,\n ];\n if (quartet.worktree.installed !== null) {\n lines.push(` its installed ${this.show(quartet.worktree.installed)} ${tree.root}/node_modules/${UMBRELLA_PACKAGE}`);\n lines.push(' ^ what nx, vitest and eslint load IN this tree');\n }\n const others = this.versions.otherWorktrees(tree.mainRoot, tree.root);\n if (others.length > 0) {\n lines.push(` NOTE ${others.length} other worktree(s) exist and are governed the same way — if they are`);\n lines.push(' skewed too, their agents are already mis-governed. Consider clones, or');\n lines.push(' serializing the work in the main tree.');\n }\n return lines;\n }\n\n private show(version: string | null): string {\n return (version ?? '-').padEnd(10);\n }\n}\n"]}
|