@webpieces/ai-hook-rules 0.4.774 → 0.4.776

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -68,14 +68,16 @@ never its own release — governance was always the primary's. Both hooks are ab
68
68
  guarantee is structural, `cd` into a subdirectory is simply allowed, and version skew between trees is
69
69
  caught where it actually lives: the `trinary-version-skew` L1 row (`core/version-sync.ts`).
70
70
 
71
- ### Keeping the four in step
72
-
73
- The installed surface is four things — `.claude/webpieces/ai-hook.sh`, the `settings.json` entries
74
- registering the two hooks, the ANCHORING of the hook entries the CONSUMER registers beside them, and
75
- the `settings.json` `env` entry
76
- `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1` — and they only
77
- work as a set. The guards binary compares all four against the release it came from and fails closed
78
- on any mismatch, naming which one moved. **`pnpm exec wp-upgrade-shim`** repairs all four
71
+ ### Keeping the five in step
72
+
73
+ The installed surface is five things — `.claude/webpieces/ai-hook.sh`, the `settings.json` entries
74
+ registering the two hooks, the ANCHORING of the hook entries the CONSUMER registers beside them, the
75
+ `settings.json` `env` entry `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1`, and the generic PR-gate
76
+ reviewer agent `.claude/agents/webpieces-reviewer.md` (generated from `templates/webpieces-reviewer.md`;
77
+ point `commands.pr-gate.reviewerAgentName` at it) — and they only
78
+ work as a set. The guards binary compares all five against the release it came from and fails closed
79
+ on any mismatch — including a missing or hand-edited reviewer agent — naming which one moved.
80
+ **`pnpm exec wp-upgrade-shim`** repairs all five
79
81
  (rewriting an old relative registration to the absolute form rather than adding beside it, and removing
80
82
  a leftover `guarantee-root.sh` registration) and is
81
83
  allowed through while that block is up. Its NAME is older than its job — it has not been shim-only
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/ai-hook-rules",
3
- "version": "0.4.774",
3
+ "version": "0.4.776",
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.774",
28
+ "@webpieces/rules-config": "0.4.776",
29
29
  "inversify": "7.10.4",
30
30
  "reflect-metadata": "0.2.2"
31
31
  },
@@ -418,6 +418,7 @@ export declare const SHIM_SURFACE = ".claude/webpieces/ai-hook.sh";
418
418
  export declare const REGISTRATION_SURFACE: string;
419
419
  export declare const CODEX_REGISTRATION_SURFACE: string;
420
420
  export declare const ENV_SURFACE = ".claude/settings.json env.CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR";
421
+ export declare const REVIEWER_AGENT_SURFACE = ".claude/agents/webpieces-reviewer.md";
421
422
  /**
422
423
  * WHICH of the managed surfaces disagree with this release — the input to fault S.
423
424
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENV_SURFACE = exports.CODEX_REGISTRATION_SURFACE = exports.REGISTRATION_SURFACE = exports.SHIM_SURFACE = exports.SettingsRepair = exports.HARNESS_REGISTRATIONS = exports.CODEX_REGISTRATION = exports.CLAUDE_REGISTRATION = exports.HarnessRegistration = exports.GUARDS_BIN = exports.RULES_BIN = exports.HookRegistrationEntry = exports.LEGACY_MARKER_REMOVE_AFTER = exports.LEGACY_GUARANTEE_ROOT_MARKER = void 0;
3
+ exports.REVIEWER_AGENT_SURFACE = exports.ENV_SURFACE = exports.CODEX_REGISTRATION_SURFACE = exports.REGISTRATION_SURFACE = exports.SHIM_SURFACE = exports.SettingsRepair = exports.HARNESS_REGISTRATIONS = exports.CODEX_REGISTRATION = exports.CLAUDE_REGISTRATION = exports.HarnessRegistration = exports.GUARDS_BIN = exports.RULES_BIN = exports.HookRegistrationEntry = exports.LEGACY_MARKER_REMOVE_AFTER = exports.LEGACY_GUARANTEE_ROOT_MARKER = void 0;
4
4
  exports.isManagedCommand = isManagedCommand;
5
5
  exports.managedEntries = managedEntries;
6
6
  exports.registeredBins = registeredBins;
@@ -23,6 +23,7 @@ const fs = tslib_1.__importStar(require("fs"));
23
23
  const path = tslib_1.__importStar(require("path"));
24
24
  const to_error_1 = require("../core/to-error");
25
25
  const shim_1 = require("./shim");
26
+ const reviewer_agent_1 = require("./reviewer-agent");
26
27
  const neighbour_hooks_1 = require("./neighbour-hooks");
27
28
  const managed_env_1 = require("./managed-env");
28
29
  /**
@@ -625,6 +626,9 @@ exports.SHIM_SURFACE = shim_1.SHIM_MARKER;
625
626
  exports.REGISTRATION_SURFACE = exports.CLAUDE_REGISTRATION.registrationSurface;
626
627
  exports.CODEX_REGISTRATION_SURFACE = exports.CODEX_REGISTRATION.registrationSurface;
627
628
  exports.ENV_SURFACE = `.claude/settings.json env.${managed_env_1.BASH_CWD_ENV_KEY}`;
629
+ // The generic PR-gate reviewer agent (issue #938): committed, generated, byte-stable — the same contract as
630
+ // the shim, so the same check and the same cure.
631
+ exports.REVIEWER_AGENT_SURFACE = reviewer_agent_1.REVIEWER_AGENT_MARKER;
628
632
  /**
629
633
  * WHICH of the managed surfaces disagree with this release — the input to fault S.
630
634
  *
@@ -650,6 +654,8 @@ function managedSurfaceDrift(root) {
650
654
  }
651
655
  if (envStaleAt(root))
652
656
  drifted.push(exports.ENV_SURFACE);
657
+ if ((0, reviewer_agent_1.reviewerAgentStale)(root))
658
+ drifted.push(exports.REVIEWER_AGENT_SURFACE);
653
659
  return drifted;
654
660
  }
655
661
  //# sourceMappingURL=hook-registration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook-registration.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/hook-registration.ts"],"names":[],"mappings":";;;AAqRA,4CAEC;AASD,wCAQC;AAQD,wCAGC;AAUD,0CAEC;AAUD,8CAOC;AAID,gDAYC;AAID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BAAmB,CAAC,OAAO,EAAE,IAAI,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAClF,iGAAiG;QACjG,gGAAgG;QAChG,6FAA6F;QAC7F,iFAAiF;QACjF,uFAAuF;QACvF,IAAI,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACrF,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,mBAAW,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { toError } from '../core/to-error';\nimport { AiType } from '../core/agent-event';\nimport { SHIM_MARKER, committedShimStale } from './shim';\nimport { NEIGHBOUR_SURFACE_SUFFIX, anchorNeighbourHooks, neighbourHooksStale } from './neighbour-hooks';\nimport type { ClaudeSettings, HookCommand, HookEntry } from './settings-shape';\nimport { BASH_CWD_ENV_KEY, BASH_CWD_ENV_VALUE } from './managed-env';\n\n/**\n * THE INSTALLED HOOK SURFACE — two hooks per harness, all ABSOLUTE, and the ONE place their spelling is\n * defined. See `HarnessRegistration` below, which is what makes \"per harness\" data rather than four\n * module constants that were only ever true of Claude Code.\n *\n * ─── ONE GOVERNOR: the MAIN tree judges every tree ─────────────────────────────────────────────────\n *\n * Claude Code — .claude/settings.json\n * H1 sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-guards-hook Write|…|Bash|Read\n * H2 sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-rules-hook Write|Edit|MultiEdit\n * Codex — .codex/hooks.json (the SAME `hooks.PreToolUse` JSON shape, measured)\n * H1 sh \"$PWD/.claude/webpieces/ai-hook.sh\" wp-ai-guards-hook Bash|apply_patch\n * H2 sh \"$PWD/.claude/webpieces/ai-hook.sh\" wp-ai-rules-hook apply_patch\n *\n * ONE shim file serves all four: `.claude/` there is a path, not a claim about who is calling.\n *\n * This REPLACES a three-hook form in which these two were RELATIVE (`sh \".claude/webpieces/ai-hook.sh\"`)\n * and a third hook, L-1 `guarantee-root.sh`, existed solely to guarantee that relative path resolved.\n *\n * ─── Why the relative experiment was reversed ──────────────────────────────────────────────────────\n * Relative registration was adopted so each git tree would be governed by \"its own release, binary and\n * pin\". MEASURED 2026-08-10: it never delivered that. A linked worktree has NO `node_modules`, so\n * ai-hook.sh's upward walk executes the PRIMARY's binary — `readlink -f` resolved a worktree agent's bin\n * to `<primary>/node_modules/@webpieces/ai-hook-rules`. A worktree ran its own SCRIPT and its own\n * CONFIG; it never ran its own release. Governance was already the primary's, in every tree, the whole\n * time.\n *\n * The price of that fiction was an entire guard layer. A relative path only resolves at a tree root, and\n * a hook that cannot resolve exits 127 — per the hooks reference a NON-BLOCKING error, i.e. a SILENT\n * UNGUARDED ALLOW. So L-1 had to deny every `cd` into a project subdirectory. That denial produced the\n * force-to-root bug class, the reaped-worktree `cd` prescription, and a measured hard deadlock: L-1 told\n * a worktree-isolated agent to `cd` to the primary clone, which the harness refuses for an isolated\n * agent, leaving it unable to stay or to follow the cure.\n *\n * An absolute path resolves from ANY cwd. So the launch guarantee is structural, L-1 has no job left and\n * is deleted, and `cd` into a subdirectory is simply allowed. What used to be true only by policing the\n * shell is now true by construction.\n *\n * ─── What replaces the property that was lost ──────────────────────────────────────────────────────\n * Nothing is lost that was ever delivered — but the case relative registration WANTED to handle (a tree\n * that genuinely needs a different @webpieces) is now DETECTED instead of silently mis-governed:\n * `VersionSyncGuard` (L1 row 8) blocks when a worktree's pin disagrees with the main tree's, and\n * prescribes either aligning the pins (same git hash → same tracked pin → install in each tree that has\n * a node_modules) or using a separate CLONE, which — unlike a worktree — gets its own GOVERNANCE. Note\n * what that does NOT say: a worktree may perfectly well have its own node_modules, and usually does the\n * moment anything installs in it. What it may not have is a DIFFERENT @webpieces version.\n *\n * ─── Why the registration is a DRIFT SURFACE, not just an install step ─────────────────────────────\n * Nothing used to validate `.claude/settings.json` at all, so a settings file left on a superseded form\n * silently changed who governs. The installed surface is FOUR things (ai-hook.sh, the registration, the\n * managed `env` entry — see managed-env.ts — and the ANCHORING of the NEIGHBOUR hook commands the\n * consumer registers beside ours, see neighbour-hooks.ts), all four are compared against this release,\n * and `wp-upgrade-shim` repairs all four. A cure that fixes three of four is worse than no cure, because\n * it reports success.\n */\n\n/**\n * The RETIRED L-1 hook's committed path. Named here, in the one module that must still recognise it, and\n * matched ONLY by isManagedCommand() so repairRegistration() can delete the stale entry. There is no\n * guarantee-root.ts any more — this literal is all that remains of it, deliberately.\n *\n * It is a one-way RECOGNISER, not a shim: nothing emits it, `expectedEntries()` never returns it, and a\n * settings file carrying it is reported STALE. Its only job is to make the retired entry findable so it\n * can be REMOVED.\n */\nexport const LEGACY_GUARANTEE_ROOT_MARKER = '.claude/webpieces/guarantee-root.sh';\n\n/**\n * When this recogniser may be deleted, as a value rather than a comment nobody re-reads.\n *\n * A removal-only migration is still dead weight once no consumer can be carrying the old shape. The\n * hazard of deleting it EARLY is severe and silent — repair would stop stripping the retired entry, and\n * a hook registered against a deleted file exits 127, which the Claude Code hooks reference defines as a\n * NON-BLOCKING error, i.e. every `cd` unjudged while the cure reports success. So it gets a stated date\n * and a test that fails once the date passes, instead of an intention.\n *\n * `legacy-marker-expiry.spec.ts` reads this and fails after it, which is the reminder.\n */\nexport const LEGACY_MARKER_REMOVE_AFTER = '2026-12-01';\n\n/** One PreToolUse hook entry as webpieces registers it. Data-only → a class, per CLAUDE.md. */\nexport class HookRegistrationEntry {\n constructor(\n readonly matcher: string,\n readonly command: string,\n ) {}\n\n sameAs(other: HookRegistrationEntry): boolean {\n return this.matcher === other.matcher && this.command === other.command;\n }\n}\n\n/**\n * THE SETTINGS-FILE SHAPE lives in `./settings-shape`, a LEAF module, and is imported from THERE by\n * everything that needs it — this module included. It is deliberately NOT re-exported here: a second\n * import path for one type is the \"two spellings of one thing\" shim the compatibility policy rejects,\n * and it would keep advertising `hook-registration` as a source of the shape, which is precisely the\n * edge that has to stay broken (`neighbour-hooks.ts` needs the shape, this module imports the repairs\n * FROM it, and `validate-no-file-import-cycles` counts even a type-only edge back as a cycle).\n */\n\nexport const RULES_BIN = 'wp-ai-rules-hook';\nexport const GUARDS_BIN = 'wp-ai-guards-hook';\n\n/**\n * ONE HARNESS'S registration surface — where its hooks live, what they match, and how they name the\n * shim. Data-only → a class, per CLAUDE.md.\n *\n * ─── Why this exists ──────────────────────────────────────────────────────────────────────────────\n * The matchers and the shim command used to be four module constants written for Claude Code alone.\n * Applied to Codex they are wrong in both halves, and the way they are wrong is SILENT:\n *\n * - MATCHER. Codex's file-editing tool is `apply_patch` (MEASURED, codex-cli 0.151.0). A matcher of\n * `Write|Edit|MultiEdit` matches it never, so every file rule is unreachable while the settings file\n * looks perfectly installed. Its shell tool IS called `Bash` — Codex reuses Claude's name — which is\n * the trap: half the matcher works, so the hooks appear to be running.\n * - ANCHOR. `$CLAUDE_PROJECT_DIR` does not exist in a Codex hook's environment (measured: 46 vars, no\n * such key), so the command expands to `sh \"/.claude/webpieces/ai-hook.sh\"`, which dies — and per the\n * hooks protocol a non-2 non-zero exit is a NON-BLOCKING error, i.e. a silent unguarded allow.\n *\n * Both halves of that were live in real repos, written by a Codex Desktop sync that transliterated the\n * Claude setup. Making the registration per-harness DATA is what stops a future harness inheriting a\n * matcher that was never true for it.\n *\n * ─── ONE SHIM, both harnesses ─────────────────────────────────────────────────────────────────────\n * `SHIM_MARKER` is shared deliberately: `.claude/webpieces/ai-hook.sh` is the single fail-closed entry\n * point, and moving or duplicating it would double the L0 allowlist regexes, the drift surfaces and the\n * cures. The `.claude/` prefix is a path, not a claim about which agent is calling.\n */\nexport class HarnessRegistration {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly aiType: AiType,\n /** How the installer and the drift report name this harness to a human. */\n readonly label: string,\n /** Which tool names the RULES hook (code-style, file-scoped) must see. */\n readonly rulesMatcher: string,\n /**\n * Which tool names the GUARDS hook must see. Wider than the rules matcher by the shell tool and,\n * for Claude Code, by `Read` — Read carries no guard, but the guards hook owns the\n * per-invocation audit log, so matching it records every file the AI opens (log-and-allow fast\n * path in hook-core.ts; a Read is never blocked). Codex has no Read tool at all: a read arrives\n * as `Bash` running a pager, which the shell matcher already covers and read-parity synthesizes.\n */\n readonly guardsMatcher: string,\n /** The settings files this harness's hooks can be installed into, relative to the repo root. */\n readonly settingsFiles: readonly string[],\n /**\n * THE PREFIX THE SHIM PATH IS ANCHORED ON, and the reason each harness needs its own.\n *\n * **BYTE-STABILITY IS A HARD CONSTRAINT ON THE CODEX VALUE.** Codex trusts a hook entry\n * TOFU — `~/.codex/config.toml` records a `trusted_hash` per entry — so ANY change to these bytes\n * invalidates that trust and re-prompts the human, whose third option is `Continue without\n * trusting (hooks won't run)`: one keystroke to a silently unguarded session. Changing this\n * string is therefore never a cosmetic edit. The hash is NOT reproducible from outside Codex\n * (16 encodings tried against a file we authored), so the installer can never repair trust for\n * itself — see ./codex-trust.ts, which REPORTS and never writes.\n */\n readonly shimAnchor: string,\n /**\n * True when this harness's settings file also carries the managed `env` block. Claude Code's\n * settings `env` is inherited by every subagent, which is what makes it the right home for the\n * Bash-cwd pin (see managed-env.ts). Codex has no equivalent surface — and needs none: its cwd\n * is MEASURED not to drift at all (`cd x && pwd` prints x, the next call is back at the repo\n * root, for the coordinator and for subagents alike).\n */\n readonly managesEnv: boolean,\n /** What `managedSurfaceDrift()` calls this harness's registration when it has moved. */\n readonly registrationSurface: string,\n ) {}\n\n /** Which matcher one guard bin registers under. */\n matcherFor(bin: string): string {\n return bin === RULES_BIN ? this.rulesMatcher : this.guardsMatcher;\n }\n\n /**\n * The guard-hook command — `sh \"<anchor>/.claude/webpieces/ai-hook.sh\" <bin>`.\n *\n * ABSOLUTE, in both harnesses. Claude's anchor replaced a RELATIVE spelling and that reversal is\n * documented at length in this file's header: relative resolves only at a tree root, a hook that\n * cannot resolve exits 127, and per the hooks reference that is a NON-BLOCKING error — a silent\n * unguarded allow. It also cost an entire guard layer (L-1) whose only job was to police the `cd`\n * that made the relative path resolvable.\n *\n * Invoked via `sh <file>` rather than executed directly so a missing executable bit on the\n * checked-in shim (fresh clone, a filesystem that drops the bit, git core.fileMode quirks) can never\n * break the hook with a raw `Permission denied` on every tool call. Quoted to survive spaces.\n */\n shimCommand(bin: string): string {\n return `sh \"${this.shimAnchor}/${SHIM_MARKER}\" ${bin}`;\n }\n\n /** The registration entry for one guard bin under this harness. */\n entryFor(bin: string): HookRegistrationEntry {\n return new HookRegistrationEntry(this.matcherFor(bin), this.shimCommand(bin));\n }\n\n /** This harness's settings files under one repo root, absolute. */\n settingsPaths(projectRoot: string): readonly string[] {\n return this.settingsFiles.map((file: string): string => path.join(projectRoot, ...file.split('/')));\n }\n\n /**\n * What `managedSurfaceDrift()` calls this harness's NEIGHBOUR hook commands — the entries a CONSUMER\n * repo registers in the same file — when one of them still carries a repo-RELATIVE entry path.\n *\n * DERIVED rather than a constructor field, unlike `registrationSurface` beside it, because there is\n * nothing here a harness could sensibly disagree about: it is the same file, said a second way. A\n * constructor param would be a second place to keep in step for no decision.\n */\n get neighbourSurface(): string {\n return `${this.settingsFiles[0]} ${NEIGHBOUR_SURFACE_SUFFIX}`;\n }\n}\n\nexport const CLAUDE_REGISTRATION = new HarnessRegistration(\n 'claude-code', 'Claude Code',\n 'Write|Edit|MultiEdit',\n 'Write|Edit|MultiEdit|Bash|Read',\n ['.claude/settings.json', '.claude/settings.local.json'],\n '$CLAUDE_PROJECT_DIR',\n true,\n '.claude/settings.json hook registration',\n);\n\n/**\n * Codex's registration, every value of it MEASURED against codex-cli 0.151.0 rather than assumed.\n *\n * `$PWD` is the anchor because there is no project-dir variable to use and none is needed: the payload\n * `cwd` and the hook process's own `PWD` are both the repo root on EVERY call — for the coordinator and\n * for subagents — and a `cd` inside one command never survives into the next. That was measured, not\n * hoped for, and it is the same effect Claude Code gets from the managed\n * `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR` env entry. See `shimAnchor` for why these exact bytes are\n * not free to change.\n */\nexport const CODEX_REGISTRATION = new HarnessRegistration(\n 'codex', 'Codex',\n 'apply_patch',\n 'Bash|apply_patch',\n ['.codex/hooks.json'],\n '$PWD',\n false,\n '.codex/hooks.json hook registration',\n);\n\n/**\n * Every harness webpieces arms, in installer order.\n *\n * The drift check, the repair and the installer all iterate THIS, so a harness cannot be armed by the\n * installer and then left unvalidated — which is exactly the state `.codex/hooks.json` was in before it\n * was a managed surface: written by something else, silently wrong, and invisible to every check.\n */\nexport const HARNESS_REGISTRATIONS: readonly HarnessRegistration[] = [CLAUDE_REGISTRATION, CODEX_REGISTRATION];\n\n/**\n * True when this PreToolUse command is one webpieces owns — in ANY spelling it has ever shipped.\n *\n * THE SINGLE MOST IMPORTANT LINE IN THIS RELEASE. `LEGACY_GUARANTEE_ROOT_MARKER` is matched here and\n * NOWHERE else: it is how `repairRegistration()` finds and REMOVES the retired H1 entry from a settings\n * file written by an older release. Drop it and the repair silently leaves a live L-1 hook registered\n * against a file this release deletes — exit 127, which the Claude Code hooks reference defines as a\n * NON-BLOCKING error, so every `cd` goes unjudged while `wp-upgrade-shim` reports success and no drift\n * check can name it. Removal-only, never emitted: it appears in no `expectedEntries()` result, so it is\n * a one-way migration and not a second accepted spelling.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function isManagedCommand(command: string): boolean {\n return command.includes(SHIM_MARKER) || command.includes(LEGACY_GUARANTEE_ROOT_MARKER);\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nfunction preToolUse(settings: ClaudeSettings): readonly HookEntry[] {\n return settings.hooks?.PreToolUse ?? [];\n}\n\n/** Every webpieces-managed entry of one settings file, flattened to matcher + command pairs. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function managedEntries(settings: ClaudeSettings): readonly HookRegistrationEntry[] {\n const found: HookRegistrationEntry[] = [];\n for (const entry of preToolUse(settings)) {\n for (const hook of entry.hooks) {\n if (isManagedCommand(hook.command)) found.push(new HookRegistrationEntry(entry.matcher, hook.command));\n }\n }\n return found;\n}\n\n/**\n * Which guard bins this settings file registers, in installer order. A file registering NEITHER is not\n * a project (relative) install and is therefore never judged — a global/absolute install names the bin\n * path directly and carries no shim marker at all.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function registeredBins(settings: ClaudeSettings): readonly string[] {\n const commands = managedEntries(settings).map((e: HookRegistrationEntry): string => e.command);\n return [GUARDS_BIN, RULES_BIN].filter((bin: string): boolean => commands.some((c: string): boolean => c.includes(bin)));\n}\n\n/**\n * The exact set of entries THIS RELEASE expects in a settings file that registers `bins`.\n *\n * ONE entry per registered bin, and nothing else. There used to be a third, `guarantee-root.sh`, added\n * whenever the GUARDS bin was present; it is retired, and a settings file still carrying it is STALE —\n * `repairRegistration()` removes it via isManagedCommand()'s legacy marker.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function expectedEntries(harness: HarnessRegistration, bins: readonly string[]): readonly HookRegistrationEntry[] {\n return bins.map((bin: string): HookRegistrationEntry => harness.entryFor(bin));\n}\n\n/**\n * True when a settings file registers webpieces hooks in a shape this release does not expect: a\n * RELATIVE shim command, a leftover guarantee-root entry, a stray duplicate, or a wrong matcher.\n *\n * Compared as a SET, not a sequence: Claude Code runs all matching hooks in parallel, so array order\n * carries no meaning and reordering must not read as drift.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function registrationStale(harness: HarnessRegistration, settings: ClaudeSettings): boolean {\n const bins = registeredBins(settings);\n if (bins.length === 0) return false;\n const have = managedEntries(settings);\n const want = expectedEntries(harness, bins);\n if (have.length !== want.length) return true;\n return want.some((w: HookRegistrationEntry): boolean => !have.some((h: HookRegistrationEntry): boolean => h.sameAs(w)));\n}\n\n/** Drop every webpieces-managed PreToolUse command; returns true if anything was removed. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function dropManagedEntries(settings: ClaudeSettings): boolean {\n const entries = settings.hooks?.PreToolUse;\n if (!entries) return false;\n let changed = false;\n const kept: HookEntry[] = [];\n for (const entry of entries) {\n const hooks = entry.hooks.filter((h: HookCommand): boolean => !isManagedCommand(h.command));\n if (hooks.length !== entry.hooks.length) changed = true;\n if (hooks.length > 0) kept.push({ matcher: entry.matcher, hooks });\n }\n if (changed) settings.hooks!.PreToolUse = kept;\n return changed;\n}\n\n/** Append one PreToolUse entry. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function addHookEntry(settings: ClaudeSettings, entry: HookRegistrationEntry): void {\n if (!settings.hooks) settings.hooks = {};\n if (!Array.isArray(settings.hooks.PreToolUse)) settings.hooks.PreToolUse = [];\n settings.hooks.PreToolUse.push({ matcher: entry.matcher, hooks: [{ type: 'command', command: entry.command }] });\n}\n\n/** The settings `env` block, or null when the file carries none (or carries junk in its place). */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nfunction settingsEnv(settings: ClaudeSettings): Record<string, string> | null {\n // webpieces-disable no-any-unknown -- settings.json is opaque consumer JSON; `env` is only typed after this check\n const env: unknown = settings.env;\n if (typeof env !== 'object' || env === null || Array.isArray(env)) return null;\n return env as Record<string, string>;\n}\n\n/**\n * True when a settings file that registers webpieces hooks is missing the managed `env` entry, or\n * carries any value other than the one required one.\n *\n * Gated on `registeredBins()` for the SAME reason `registrationStale()` is: a settings file that\n * registers no webpieces hooks is not a project install and is never judged — a global install names\n * the bin path directly and carries no shim marker at all, so there is nothing here to keep in step.\n *\n * NOTE what this entry is for NOW. It was originally justified by keeping the then-RELATIVE hook path\n * resolvable; that job is retired, because both hooks are absolute and resolve from any cwd. It is kept\n * for VERDICT STABILITY — a guard's answer must depend on the command, not on where an earlier `cd` left\n * the shell — and because settings `env` is inherited, every subagent shares that cwd and therefore that\n * verdict. See managed-env.ts, which states this at length.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function envStale(settings: ClaudeSettings): boolean {\n if (registeredBins(settings).length === 0) return false;\n const env = settingsEnv(settings);\n return env === null || env[BASH_CWD_ENV_KEY] !== BASH_CWD_ENV_VALUE;\n}\n\n/**\n * Set the managed `env` entry IN PLACE, whatever was there before. Returns true when it changed.\n *\n * A user-set `\"0\"` is BROUGHT TO `\"1\"`, not honoured: this is a managed surface, and \"webpieces sets it\n * unless you disagreed\" would be a second, invisible spelling of the decision. Turning it off means\n * uninstalling the hooks, exactly as it does for every other managed thing.\n *\n * UNGATED on purpose — the installer calls it for the file it is writing hooks into, and the gate lives\n * at the caller (repairRegistration / applyHook), so a file with no webpieces hooks is never touched.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function applyManagedEnv(settings: ClaudeSettings): boolean {\n const existing = settingsEnv(settings);\n if (existing !== null && existing[BASH_CWD_ENV_KEY] === BASH_CWD_ENV_VALUE) return false;\n const env = existing ?? {};\n env[BASH_CWD_ENV_KEY] = BASH_CWD_ENV_VALUE;\n settings.env = env;\n return true;\n}\n\n/**\n * Bring one settings object to the two-hook ABSOLUTE form AND the managed `env` entry IN PLACE. Returns\n * true when it changed anything.\n *\n * REMOVE-then-ADD for the hooks, never add-beside: two spellings of one registration is exactly the\n * compatibility shim the backwards-compat reviewer rejects, and leaving a RELATIVE entry beside the\n * absolute one would run two shims per call — the\n * straddle this whole change exists to delete.\n *\n * THE TWO REPAIRS ARE EVALUATED INDEPENDENTLY, and that is load-bearing rather than tidy: this used to\n * early-return on `!registrationStale(settings)`, so a repo whose hooks are already current but whose\n * `env` entry is missing — the state EVERY existing consumer is in the moment this release lands — would\n * have been reported as drifted by fault S and then left unrepaired by its own prescribed cure. A cure\n * that skips half the surface is the failure mode `upgrade-shim.ts`'s header exists to prevent.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function repairRegistration(harness: HarnessRegistration, settings: ClaudeSettings): boolean {\n const bins = registeredBins(settings);\n if (bins.length === 0) return false;\n let changed = false;\n if (registrationStale(harness, settings)) {\n dropManagedEntries(settings);\n for (const entry of expectedEntries(harness, bins)) addHookEntry(settings, entry);\n changed = true;\n }\n // Only where the harness HAS that surface. Codex's hooks.json has no `env` block to manage, and\n // inventing one there would write a key Codex does not read — a managed surface nothing consumes is\n // a surface that can drift with no consequence and no way to notice.\n if (harness.managesEnv && applyManagedEnv(settings)) changed = true;\n return changed;\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function readSettings(settingsPath: string): ClaudeSettings {\n if (!fs.existsSync(settingsPath)) return {};\n const raw = fs.readFileSync(settingsPath, 'utf8');\n if (raw.trim() === '') return {};\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return JSON.parse(raw) as ClaudeSettings;\n } catch (err: unknown) {\n const error = toError(err);\n throw new Error(`${settingsPath} has invalid JSON — fix it, then retry: ${error.message}`, { cause: error });\n }\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function writeSettings(settingsPath: string, settings: ClaudeSettings): void {\n fs.mkdirSync(path.dirname(settingsPath), { recursive: true });\n fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4) + '\\n');\n}\n\n/**\n * True when any settings file ONE HARNESS owns under `root` carries a NEIGHBOUR hook — one the consumer\n * repo wrote — whose entry path is repo-RELATIVE and would therefore fail to resolve from any cwd but\n * the root. See neighbour-hooks.ts for the measured failure and why webpieces owns the repair.\n *\n * Judged ONLY where the file registers webpieces hooks, exactly like `registrationStaleAt` below: a\n * settings file with no webpieces hooks in it is not a webpieces install, and webpieces rewriting\n * somebody's unrelated hook lines there would be editing a file it was never given.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function neighbourHooksStaleAt(harness: HarnessRegistration, root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return harness.settingsPaths(root).some((p: string): boolean => {\n const settings = readSettings(p);\n return registeredBins(settings).length > 0 && neighbourHooksStale(harness.shimAnchor, settings, root);\n });\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * True when any settings file ONE HARNESS owns under `root` carries a stale registration.\n *\n * Per harness, not per repo, so the drift report can NAME which one moved — `.claude/settings.json` and\n * `.codex/hooks.json` have different cures, and a fault that says only \"the registration is stale\" sends\n * the reader to the wrong file half the time.\n *\n * A file that does not exist, or exists and registers no webpieces hooks, is never judged (see\n * `registrationStale`). That is what keeps a repo which has never armed Codex from suddenly faulting on\n * a `.codex/hooks.json` it does not have.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function registrationStaleAt(harness: HarnessRegistration, root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return harness.settingsPaths(root).some((p: string): boolean => registrationStale(harness, readSettings(p)));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * True when either Claude project settings file under `root` is missing the managed `env` entry.\n *\n * CLAUDE-ONLY by construction, and stated as such rather than looped over the harnesses: `env` is a\n * Claude Code settings surface, Codex has no equivalent, and Codex's cwd is measured not to drift, which\n * is the whole thing the entry is for. See HarnessRegistration.managesEnv.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function envStaleAt(root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return CLAUDE_REGISTRATION.settingsPaths(root).some((p: string): boolean => envStale(readSettings(p)));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * WHAT was rewritten in ONE settings file. Data-only → a class, per CLAUDE.md.\n *\n * Two independent flags rather than one path, because the cure has to be able to SAY which repair it\n * made: \"rewrote the hook registration\" printed for a file whose registration was already current and\n * whose `env` entry was the only thing missing is a cure lying about its own work.\n */\nexport class SettingsRepair {\n constructor(\n readonly settingsPath: string,\n readonly registration: boolean,\n readonly env: boolean,\n /**\n * The NEW spelling of every NEIGHBOUR hook command this repair anchored — the consumer's own\n * entries, which webpieces rewrites but does not author.\n *\n * The commands themselves rather than a count or a flag, because this is the one repair that\n * edits lines webpieces did not write: the cure has to be able to show the consumer exactly what\n * it changed in their file, or it is a silent edit to somebody else's hooks.\n */\n readonly anchoredNeighbours: readonly string[],\n ) {}\n}\n\n/**\n * Rewrite every stale settings file under `root`, for EVERY harness; returns what changed, per file.\n *\n * Existing files only — this never CREATES a registration. Arming a harness is the installer's decision\n * (`wp-install-ai-hooks`); this is the cure for one that has already been armed and has drifted, so a\n * repo that has never armed Codex is left exactly as it was.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function repairRegistrationAt(root: string): readonly SettingsRepair[] {\n const repairs: SettingsRepair[] = [];\n for (const harness of HARNESS_REGISTRATIONS) {\n for (const settingsPath of harness.settingsPaths(root)) {\n if (!fs.existsSync(settingsPath)) continue;\n const settings = readSettings(settingsPath);\n const neededRegistration = registrationStale(harness, settings);\n const neededEnv = harness.managesEnv && envStale(settings);\n const changedManaged = repairRegistration(harness, settings);\n // AFTER the managed repair, never before: repairRegistration() removes the retired\n // guarantee-root entry and rewrites the two managed commands, so by the time the neighbour\n // pass runs there is nothing webpieces-owned left for it to look at. Gated on\n // registeredBins() for the same reason every other judgement here is — a settings file that\n // registers no webpieces hooks is not a webpieces install, and rewriting somebody's\n // unrelated hook lines in it would be webpieces editing a file it was never given.\n const anchored = registeredBins(settings).length === 0 ? [] : anchorNeighbourHooks(harness.shimAnchor, settings, root);\n if (!changedManaged && anchored.length === 0) continue;\n writeSettings(settingsPath, settings);\n repairs.push(new SettingsRepair(settingsPath, neededRegistration, neededEnv, anchored));\n }\n }\n return repairs;\n}\n\n/**\n * The names the drift check reports, so a deny can say WHICH surface moved.\n *\n * There were four, then three, and there are now FOUR again — but the fourth is not the one that was\n * deleted. `GUARANTEE_ROOT_SURFACE` went with L-1 itself: an absolutely-registered shim resolves from\n * any cwd, so there is no launch guarantee left to police and no second .sh file to keep byte-locked. A\n * settings file still carrying the retired H1 entry is not its own surface — it is ordinary REGISTRATION\n * drift, which `registrationStaleAt()` reports and `repairRegistration()` fixes by removing it.\n *\n * The new fourth is `.codex/hooks.json`, and it is here because of what happened while it was NOT a\n * managed surface: something else wrote it, with a matcher that matched no Codex file tool and a shim\n * path anchored on a variable Codex does not set, and no check in this package could see it. A file the\n * guards depend on and nothing validates is the exact shape of that incident.\n *\n * Each harness's registration surface is its own name, from HarnessRegistration.registrationSurface, so\n * the deny sends the reader to the file that actually moved.\n */\nexport const SHIM_SURFACE = SHIM_MARKER;\nexport const REGISTRATION_SURFACE = CLAUDE_REGISTRATION.registrationSurface;\nexport const CODEX_REGISTRATION_SURFACE = CODEX_REGISTRATION.registrationSurface;\nexport const ENV_SURFACE = `.claude/settings.json env.${BASH_CWD_ENV_KEY}`;\n\n/**\n * WHICH of the managed surfaces disagree with this release — the input to fault S.\n *\n * All of them are checked against the SAME root, resolved from the RUNNING MODULE (governingShimRoot),\n * never from cwd and never from `$CLAUDE_PROJECT_DIR`: the files we compare and the renderers we\n * compare them TO must come from one install, or the check straddles two trees and can never converge.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function managedSurfaceDrift(root: string | null): readonly string[] {\n const drifted: string[] = [];\n if (committedShimStale(root)) drifted.push(SHIM_SURFACE);\n for (const harness of HARNESS_REGISTRATIONS) {\n if (registrationStaleAt(harness, root)) drifted.push(harness.registrationSurface);\n // A neighbour hook registered with a RELATIVE entry path dies from any cwd but the root, and per\n // the hooks reference that non-zero exit is a NON-BLOCKING error — a SILENT UNGUARDED ALLOW. It\n // is a drift surface for exactly the reason the managed registration is one: nothing else in\n // this repo can see it, and the way it fails looks like a guard that PASSED. See\n // neighbour-hooks.ts, and issue #852 where it silently disarmed three security guards.\n if (neighbourHooksStaleAt(harness, root)) drifted.push(harness.neighbourSurface);\n }\n if (envStaleAt(root)) drifted.push(ENV_SURFACE);\n return drifted;\n}\n"]}
1
+ {"version":3,"file":"hook-registration.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/hook-registration.ts"],"names":[],"mappings":";;;AAsRA,4CAEC;AASD,wCAQC;AAQD,wCAGC;AAUD,0CAEC;AAUD,8CAOC;AAID,gDAYC;AAID,oCAIC;AA0BD,4BAIC;AAaD,0CAOC;AAkBD,gDAcC;AAGD,oCAWC;AAGD,sCAGC;AAYD,sDAaC;AAcD,kDAUC;AAUD,gCAUC;AAkCD,oDAsBC;AAmCD,kDAeC;;AA9nBD,+CAAyB;AACzB,mDAA6B;AAE7B,+CAA2C;AAE3C,iCAAyD;AACzD,qDAA6E;AAC7E,uDAAwG;AAExG,+CAAqE;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH;;;;;;;;GAQG;AACU,QAAA,4BAA4B,GAAG,qCAAqC,CAAC;AAElF;;;;;;;;;;GAUG;AACU,QAAA,0BAA0B,GAAG,YAAY,CAAC;AAEvD,+FAA+F;AAC/F,MAAa,qBAAqB;IAEjB;IACA;IAFb,YACa,OAAe,EACf,OAAe;QADf,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAQ;IACzB,CAAC;IAEJ,MAAM,CAAC,KAA4B;QAC/B,OAAO,IAAI,CAA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} from '../core/to-error';\nimport { AiType } from '../core/agent-event';\nimport { SHIM_MARKER, committedShimStale } from './shim';\nimport { REVIEWER_AGENT_MARKER, reviewerAgentStale } from './reviewer-agent';\nimport { NEIGHBOUR_SURFACE_SUFFIX, anchorNeighbourHooks, neighbourHooksStale } from './neighbour-hooks';\nimport type { ClaudeSettings, HookCommand, HookEntry } from './settings-shape';\nimport { BASH_CWD_ENV_KEY, BASH_CWD_ENV_VALUE } from './managed-env';\n\n/**\n * THE INSTALLED HOOK SURFACE — two hooks per harness, all ABSOLUTE, and the ONE place their spelling is\n * defined. See `HarnessRegistration` below, which is what makes \"per harness\" data rather than four\n * module constants that were only ever true of Claude Code.\n *\n * ─── ONE GOVERNOR: the MAIN tree judges every tree ─────────────────────────────────────────────────\n *\n * Claude Code — .claude/settings.json\n * H1 sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-guards-hook Write|…|Bash|Read\n * H2 sh \"$CLAUDE_PROJECT_DIR/.claude/webpieces/ai-hook.sh\" wp-ai-rules-hook Write|Edit|MultiEdit\n * Codex — .codex/hooks.json (the SAME `hooks.PreToolUse` JSON shape, measured)\n * H1 sh \"$PWD/.claude/webpieces/ai-hook.sh\" wp-ai-guards-hook Bash|apply_patch\n * H2 sh \"$PWD/.claude/webpieces/ai-hook.sh\" wp-ai-rules-hook apply_patch\n *\n * ONE shim file serves all four: `.claude/` there is a path, not a claim about who is calling.\n *\n * This REPLACES a three-hook form in which these two were RELATIVE (`sh \".claude/webpieces/ai-hook.sh\"`)\n * and a third hook, L-1 `guarantee-root.sh`, existed solely to guarantee that relative path resolved.\n *\n * ─── Why the relative experiment was reversed ──────────────────────────────────────────────────────\n * Relative registration was adopted so each git tree would be governed by \"its own release, binary and\n * pin\". MEASURED 2026-08-10: it never delivered that. A linked worktree has NO `node_modules`, so\n * ai-hook.sh's upward walk executes the PRIMARY's binary — `readlink -f` resolved a worktree agent's bin\n * to `<primary>/node_modules/@webpieces/ai-hook-rules`. A worktree ran its own SCRIPT and its own\n * CONFIG; it never ran its own release. Governance was already the primary's, in every tree, the whole\n * time.\n *\n * The price of that fiction was an entire guard layer. A relative path only resolves at a tree root, and\n * a hook that cannot resolve exits 127 — per the hooks reference a NON-BLOCKING error, i.e. a SILENT\n * UNGUARDED ALLOW. So L-1 had to deny every `cd` into a project subdirectory. That denial produced the\n * force-to-root bug class, the reaped-worktree `cd` prescription, and a measured hard deadlock: L-1 told\n * a worktree-isolated agent to `cd` to the primary clone, which the harness refuses for an isolated\n * agent, leaving it unable to stay or to follow the cure.\n *\n * An absolute path resolves from ANY cwd. So the launch guarantee is structural, L-1 has no job left and\n * is deleted, and `cd` into a subdirectory is simply allowed. What used to be true only by policing the\n * shell is now true by construction.\n *\n * ─── What replaces the property that was lost ──────────────────────────────────────────────────────\n * Nothing is lost that was ever delivered — but the case relative registration WANTED to handle (a tree\n * that genuinely needs a different @webpieces) is now DETECTED instead of silently mis-governed:\n * `VersionSyncGuard` (L1 row 8) blocks when a worktree's pin disagrees with the main tree's, and\n * prescribes either aligning the pins (same git hash → same tracked pin → install in each tree that has\n * a node_modules) or using a separate CLONE, which — unlike a worktree — gets its own GOVERNANCE. Note\n * what that does NOT say: a worktree may perfectly well have its own node_modules, and usually does the\n * moment anything installs in it. What it may not have is a DIFFERENT @webpieces version.\n *\n * ─── Why the registration is a DRIFT SURFACE, not just an install step ─────────────────────────────\n * Nothing used to validate `.claude/settings.json` at all, so a settings file left on a superseded form\n * silently changed who governs. The installed surface is FOUR things (ai-hook.sh, the registration, the\n * managed `env` entry — see managed-env.ts — and the ANCHORING of the NEIGHBOUR hook commands the\n * consumer registers beside ours, see neighbour-hooks.ts), all four are compared against this release,\n * and `wp-upgrade-shim` repairs all four. A cure that fixes three of four is worse than no cure, because\n * it reports success.\n */\n\n/**\n * The RETIRED L-1 hook's committed path. Named here, in the one module that must still recognise it, and\n * matched ONLY by isManagedCommand() so repairRegistration() can delete the stale entry. There is no\n * guarantee-root.ts any more — this literal is all that remains of it, deliberately.\n *\n * It is a one-way RECOGNISER, not a shim: nothing emits it, `expectedEntries()` never returns it, and a\n * settings file carrying it is reported STALE. Its only job is to make the retired entry findable so it\n * can be REMOVED.\n */\nexport const LEGACY_GUARANTEE_ROOT_MARKER = '.claude/webpieces/guarantee-root.sh';\n\n/**\n * When this recogniser may be deleted, as a value rather than a comment nobody re-reads.\n *\n * A removal-only migration is still dead weight once no consumer can be carrying the old shape. The\n * hazard of deleting it EARLY is severe and silent — repair would stop stripping the retired entry, and\n * a hook registered against a deleted file exits 127, which the Claude Code hooks reference defines as a\n * NON-BLOCKING error, i.e. every `cd` unjudged while the cure reports success. So it gets a stated date\n * and a test that fails once the date passes, instead of an intention.\n *\n * `legacy-marker-expiry.spec.ts` reads this and fails after it, which is the reminder.\n */\nexport const LEGACY_MARKER_REMOVE_AFTER = '2026-12-01';\n\n/** One PreToolUse hook entry as webpieces registers it. Data-only → a class, per CLAUDE.md. */\nexport class HookRegistrationEntry {\n constructor(\n readonly matcher: string,\n readonly command: string,\n ) {}\n\n sameAs(other: HookRegistrationEntry): boolean {\n return this.matcher === other.matcher && this.command === other.command;\n }\n}\n\n/**\n * THE SETTINGS-FILE SHAPE lives in `./settings-shape`, a LEAF module, and is imported from THERE by\n * everything that needs it — this module included. It is deliberately NOT re-exported here: a second\n * import path for one type is the \"two spellings of one thing\" shim the compatibility policy rejects,\n * and it would keep advertising `hook-registration` as a source of the shape, which is precisely the\n * edge that has to stay broken (`neighbour-hooks.ts` needs the shape, this module imports the repairs\n * FROM it, and `validate-no-file-import-cycles` counts even a type-only edge back as a cycle).\n */\n\nexport const RULES_BIN = 'wp-ai-rules-hook';\nexport const GUARDS_BIN = 'wp-ai-guards-hook';\n\n/**\n * ONE HARNESS'S registration surface — where its hooks live, what they match, and how they name the\n * shim. Data-only → a class, per CLAUDE.md.\n *\n * ─── Why this exists ──────────────────────────────────────────────────────────────────────────────\n * The matchers and the shim command used to be four module constants written for Claude Code alone.\n * Applied to Codex they are wrong in both halves, and the way they are wrong is SILENT:\n *\n * - MATCHER. Codex's file-editing tool is `apply_patch` (MEASURED, codex-cli 0.151.0). A matcher of\n * `Write|Edit|MultiEdit` matches it never, so every file rule is unreachable while the settings file\n * looks perfectly installed. Its shell tool IS called `Bash` — Codex reuses Claude's name — which is\n * the trap: half the matcher works, so the hooks appear to be running.\n * - ANCHOR. `$CLAUDE_PROJECT_DIR` does not exist in a Codex hook's environment (measured: 46 vars, no\n * such key), so the command expands to `sh \"/.claude/webpieces/ai-hook.sh\"`, which dies — and per the\n * hooks protocol a non-2 non-zero exit is a NON-BLOCKING error, i.e. a silent unguarded allow.\n *\n * Both halves of that were live in real repos, written by a Codex Desktop sync that transliterated the\n * Claude setup. Making the registration per-harness DATA is what stops a future harness inheriting a\n * matcher that was never true for it.\n *\n * ─── ONE SHIM, both harnesses ─────────────────────────────────────────────────────────────────────\n * `SHIM_MARKER` is shared deliberately: `.claude/webpieces/ai-hook.sh` is the single fail-closed entry\n * point, and moving or duplicating it would double the L0 allowlist regexes, the drift surfaces and the\n * cures. The `.claude/` prefix is a path, not a claim about which agent is calling.\n */\nexport class HarnessRegistration {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly aiType: AiType,\n /** How the installer and the drift report name this harness to a human. */\n readonly label: string,\n /** Which tool names the RULES hook (code-style, file-scoped) must see. */\n readonly rulesMatcher: string,\n /**\n * Which tool names the GUARDS hook must see. Wider than the rules matcher by the shell tool and,\n * for Claude Code, by `Read` — Read carries no guard, but the guards hook owns the\n * per-invocation audit log, so matching it records every file the AI opens (log-and-allow fast\n * path in hook-core.ts; a Read is never blocked). Codex has no Read tool at all: a read arrives\n * as `Bash` running a pager, which the shell matcher already covers and read-parity synthesizes.\n */\n readonly guardsMatcher: string,\n /** The settings files this harness's hooks can be installed into, relative to the repo root. */\n readonly settingsFiles: readonly string[],\n /**\n * THE PREFIX THE SHIM PATH IS ANCHORED ON, and the reason each harness needs its own.\n *\n * **BYTE-STABILITY IS A HARD CONSTRAINT ON THE CODEX VALUE.** Codex trusts a hook entry\n * TOFU — `~/.codex/config.toml` records a `trusted_hash` per entry — so ANY change to these bytes\n * invalidates that trust and re-prompts the human, whose third option is `Continue without\n * trusting (hooks won't run)`: one keystroke to a silently unguarded session. Changing this\n * string is therefore never a cosmetic edit. The hash is NOT reproducible from outside Codex\n * (16 encodings tried against a file we authored), so the installer can never repair trust for\n * itself — see ./codex-trust.ts, which REPORTS and never writes.\n */\n readonly shimAnchor: string,\n /**\n * True when this harness's settings file also carries the managed `env` block. Claude Code's\n * settings `env` is inherited by every subagent, which is what makes it the right home for the\n * Bash-cwd pin (see managed-env.ts). Codex has no equivalent surface — and needs none: its cwd\n * is MEASURED not to drift at all (`cd x && pwd` prints x, the next call is back at the repo\n * root, for the coordinator and for subagents alike).\n */\n readonly managesEnv: boolean,\n /** What `managedSurfaceDrift()` calls this harness's registration when it has moved. */\n readonly registrationSurface: string,\n ) {}\n\n /** Which matcher one guard bin registers under. */\n matcherFor(bin: string): string {\n return bin === RULES_BIN ? this.rulesMatcher : this.guardsMatcher;\n }\n\n /**\n * The guard-hook command — `sh \"<anchor>/.claude/webpieces/ai-hook.sh\" <bin>`.\n *\n * ABSOLUTE, in both harnesses. Claude's anchor replaced a RELATIVE spelling and that reversal is\n * documented at length in this file's header: relative resolves only at a tree root, a hook that\n * cannot resolve exits 127, and per the hooks reference that is a NON-BLOCKING error — a silent\n * unguarded allow. It also cost an entire guard layer (L-1) whose only job was to police the `cd`\n * that made the relative path resolvable.\n *\n * Invoked via `sh <file>` rather than executed directly so a missing executable bit on the\n * checked-in shim (fresh clone, a filesystem that drops the bit, git core.fileMode quirks) can never\n * break the hook with a raw `Permission denied` on every tool call. Quoted to survive spaces.\n */\n shimCommand(bin: string): string {\n return `sh \"${this.shimAnchor}/${SHIM_MARKER}\" ${bin}`;\n }\n\n /** The registration entry for one guard bin under this harness. */\n entryFor(bin: string): HookRegistrationEntry {\n return new HookRegistrationEntry(this.matcherFor(bin), this.shimCommand(bin));\n }\n\n /** This harness's settings files under one repo root, absolute. */\n settingsPaths(projectRoot: string): readonly string[] {\n return this.settingsFiles.map((file: string): string => path.join(projectRoot, ...file.split('/')));\n }\n\n /**\n * What `managedSurfaceDrift()` calls this harness's NEIGHBOUR hook commands — the entries a CONSUMER\n * repo registers in the same file — when one of them still carries a repo-RELATIVE entry path.\n *\n * DERIVED rather than a constructor field, unlike `registrationSurface` beside it, because there is\n * nothing here a harness could sensibly disagree about: it is the same file, said a second way. A\n * constructor param would be a second place to keep in step for no decision.\n */\n get neighbourSurface(): string {\n return `${this.settingsFiles[0]} ${NEIGHBOUR_SURFACE_SUFFIX}`;\n }\n}\n\nexport const CLAUDE_REGISTRATION = new HarnessRegistration(\n 'claude-code', 'Claude Code',\n 'Write|Edit|MultiEdit',\n 'Write|Edit|MultiEdit|Bash|Read',\n ['.claude/settings.json', '.claude/settings.local.json'],\n '$CLAUDE_PROJECT_DIR',\n true,\n '.claude/settings.json hook registration',\n);\n\n/**\n * Codex's registration, every value of it MEASURED against codex-cli 0.151.0 rather than assumed.\n *\n * `$PWD` is the anchor because there is no project-dir variable to use and none is needed: the payload\n * `cwd` and the hook process's own `PWD` are both the repo root on EVERY call — for the coordinator and\n * for subagents — and a `cd` inside one command never survives into the next. That was measured, not\n * hoped for, and it is the same effect Claude Code gets from the managed\n * `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR` env entry. See `shimAnchor` for why these exact bytes are\n * not free to change.\n */\nexport const CODEX_REGISTRATION = new HarnessRegistration(\n 'codex', 'Codex',\n 'apply_patch',\n 'Bash|apply_patch',\n ['.codex/hooks.json'],\n '$PWD',\n false,\n '.codex/hooks.json hook registration',\n);\n\n/**\n * Every harness webpieces arms, in installer order.\n *\n * The drift check, the repair and the installer all iterate THIS, so a harness cannot be armed by the\n * installer and then left unvalidated — which is exactly the state `.codex/hooks.json` was in before it\n * was a managed surface: written by something else, silently wrong, and invisible to every check.\n */\nexport const HARNESS_REGISTRATIONS: readonly HarnessRegistration[] = [CLAUDE_REGISTRATION, CODEX_REGISTRATION];\n\n/**\n * True when this PreToolUse command is one webpieces owns — in ANY spelling it has ever shipped.\n *\n * THE SINGLE MOST IMPORTANT LINE IN THIS RELEASE. `LEGACY_GUARANTEE_ROOT_MARKER` is matched here and\n * NOWHERE else: it is how `repairRegistration()` finds and REMOVES the retired H1 entry from a settings\n * file written by an older release. Drop it and the repair silently leaves a live L-1 hook registered\n * against a file this release deletes — exit 127, which the Claude Code hooks reference defines as a\n * NON-BLOCKING error, so every `cd` goes unjudged while `wp-upgrade-shim` reports success and no drift\n * check can name it. Removal-only, never emitted: it appears in no `expectedEntries()` result, so it is\n * a one-way migration and not a second accepted spelling.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function isManagedCommand(command: string): boolean {\n return command.includes(SHIM_MARKER) || command.includes(LEGACY_GUARANTEE_ROOT_MARKER);\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nfunction preToolUse(settings: ClaudeSettings): readonly HookEntry[] {\n return settings.hooks?.PreToolUse ?? [];\n}\n\n/** Every webpieces-managed entry of one settings file, flattened to matcher + command pairs. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function managedEntries(settings: ClaudeSettings): readonly HookRegistrationEntry[] {\n const found: HookRegistrationEntry[] = [];\n for (const entry of preToolUse(settings)) {\n for (const hook of entry.hooks) {\n if (isManagedCommand(hook.command)) found.push(new HookRegistrationEntry(entry.matcher, hook.command));\n }\n }\n return found;\n}\n\n/**\n * Which guard bins this settings file registers, in installer order. A file registering NEITHER is not\n * a project (relative) install and is therefore never judged — a global/absolute install names the bin\n * path directly and carries no shim marker at all.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function registeredBins(settings: ClaudeSettings): readonly string[] {\n const commands = managedEntries(settings).map((e: HookRegistrationEntry): string => e.command);\n return [GUARDS_BIN, RULES_BIN].filter((bin: string): boolean => commands.some((c: string): boolean => c.includes(bin)));\n}\n\n/**\n * The exact set of entries THIS RELEASE expects in a settings file that registers `bins`.\n *\n * ONE entry per registered bin, and nothing else. There used to be a third, `guarantee-root.sh`, added\n * whenever the GUARDS bin was present; it is retired, and a settings file still carrying it is STALE —\n * `repairRegistration()` removes it via isManagedCommand()'s legacy marker.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function expectedEntries(harness: HarnessRegistration, bins: readonly string[]): readonly HookRegistrationEntry[] {\n return bins.map((bin: string): HookRegistrationEntry => harness.entryFor(bin));\n}\n\n/**\n * True when a settings file registers webpieces hooks in a shape this release does not expect: a\n * RELATIVE shim command, a leftover guarantee-root entry, a stray duplicate, or a wrong matcher.\n *\n * Compared as a SET, not a sequence: Claude Code runs all matching hooks in parallel, so array order\n * carries no meaning and reordering must not read as drift.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function registrationStale(harness: HarnessRegistration, settings: ClaudeSettings): boolean {\n const bins = registeredBins(settings);\n if (bins.length === 0) return false;\n const have = managedEntries(settings);\n const want = expectedEntries(harness, bins);\n if (have.length !== want.length) return true;\n return want.some((w: HookRegistrationEntry): boolean => !have.some((h: HookRegistrationEntry): boolean => h.sameAs(w)));\n}\n\n/** Drop every webpieces-managed PreToolUse command; returns true if anything was removed. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function dropManagedEntries(settings: ClaudeSettings): boolean {\n const entries = settings.hooks?.PreToolUse;\n if (!entries) return false;\n let changed = false;\n const kept: HookEntry[] = [];\n for (const entry of entries) {\n const hooks = entry.hooks.filter((h: HookCommand): boolean => !isManagedCommand(h.command));\n if (hooks.length !== entry.hooks.length) changed = true;\n if (hooks.length > 0) kept.push({ matcher: entry.matcher, hooks });\n }\n if (changed) settings.hooks!.PreToolUse = kept;\n return changed;\n}\n\n/** Append one PreToolUse entry. */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function addHookEntry(settings: ClaudeSettings, entry: HookRegistrationEntry): void {\n if (!settings.hooks) settings.hooks = {};\n if (!Array.isArray(settings.hooks.PreToolUse)) settings.hooks.PreToolUse = [];\n settings.hooks.PreToolUse.push({ matcher: entry.matcher, hooks: [{ type: 'command', command: entry.command }] });\n}\n\n/** The settings `env` block, or null when the file carries none (or carries junk in its place). */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nfunction settingsEnv(settings: ClaudeSettings): Record<string, string> | null {\n // webpieces-disable no-any-unknown -- settings.json is opaque consumer JSON; `env` is only typed after this check\n const env: unknown = settings.env;\n if (typeof env !== 'object' || env === null || Array.isArray(env)) return null;\n return env as Record<string, string>;\n}\n\n/**\n * True when a settings file that registers webpieces hooks is missing the managed `env` entry, or\n * carries any value other than the one required one.\n *\n * Gated on `registeredBins()` for the SAME reason `registrationStale()` is: a settings file that\n * registers no webpieces hooks is not a project install and is never judged — a global install names\n * the bin path directly and carries no shim marker at all, so there is nothing here to keep in step.\n *\n * NOTE what this entry is for NOW. It was originally justified by keeping the then-RELATIVE hook path\n * resolvable; that job is retired, because both hooks are absolute and resolve from any cwd. It is kept\n * for VERDICT STABILITY — a guard's answer must depend on the command, not on where an earlier `cd` left\n * the shell — and because settings `env` is inherited, every subagent shares that cwd and therefore that\n * verdict. See managed-env.ts, which states this at length.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function envStale(settings: ClaudeSettings): boolean {\n if (registeredBins(settings).length === 0) return false;\n const env = settingsEnv(settings);\n return env === null || env[BASH_CWD_ENV_KEY] !== BASH_CWD_ENV_VALUE;\n}\n\n/**\n * Set the managed `env` entry IN PLACE, whatever was there before. Returns true when it changed.\n *\n * A user-set `\"0\"` is BROUGHT TO `\"1\"`, not honoured: this is a managed surface, and \"webpieces sets it\n * unless you disagreed\" would be a second, invisible spelling of the decision. Turning it off means\n * uninstalling the hooks, exactly as it does for every other managed thing.\n *\n * UNGATED on purpose — the installer calls it for the file it is writing hooks into, and the gate lives\n * at the caller (repairRegistration / applyHook), so a file with no webpieces hooks is never touched.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function applyManagedEnv(settings: ClaudeSettings): boolean {\n const existing = settingsEnv(settings);\n if (existing !== null && existing[BASH_CWD_ENV_KEY] === BASH_CWD_ENV_VALUE) return false;\n const env = existing ?? {};\n env[BASH_CWD_ENV_KEY] = BASH_CWD_ENV_VALUE;\n settings.env = env;\n return true;\n}\n\n/**\n * Bring one settings object to the two-hook ABSOLUTE form AND the managed `env` entry IN PLACE. Returns\n * true when it changed anything.\n *\n * REMOVE-then-ADD for the hooks, never add-beside: two spellings of one registration is exactly the\n * compatibility shim the backwards-compat reviewer rejects, and leaving a RELATIVE entry beside the\n * absolute one would run two shims per call — the\n * straddle this whole change exists to delete.\n *\n * THE TWO REPAIRS ARE EVALUATED INDEPENDENTLY, and that is load-bearing rather than tidy: this used to\n * early-return on `!registrationStale(settings)`, so a repo whose hooks are already current but whose\n * `env` entry is missing — the state EVERY existing consumer is in the moment this release lands — would\n * have been reported as drifted by fault S and then left unrepaired by its own prescribed cure. A cure\n * that skips half the surface is the failure mode `upgrade-shim.ts`'s header exists to prevent.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function repairRegistration(harness: HarnessRegistration, settings: ClaudeSettings): boolean {\n const bins = registeredBins(settings);\n if (bins.length === 0) return false;\n let changed = false;\n if (registrationStale(harness, settings)) {\n dropManagedEntries(settings);\n for (const entry of expectedEntries(harness, bins)) addHookEntry(settings, entry);\n changed = true;\n }\n // Only where the harness HAS that surface. Codex's hooks.json has no `env` block to manage, and\n // inventing one there would write a key Codex does not read — a managed surface nothing consumes is\n // a surface that can drift with no consequence and no way to notice.\n if (harness.managesEnv && applyManagedEnv(settings)) changed = true;\n return changed;\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function readSettings(settingsPath: string): ClaudeSettings {\n if (!fs.existsSync(settingsPath)) return {};\n const raw = fs.readFileSync(settingsPath, 'utf8');\n if (raw.trim() === '') return {};\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return JSON.parse(raw) as ClaudeSettings;\n } catch (err: unknown) {\n const error = toError(err);\n throw new Error(`${settingsPath} has invalid JSON — fix it, then retry: ${error.message}`, { cause: error });\n }\n}\n\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as shimCommand above\nexport function writeSettings(settingsPath: string, settings: ClaudeSettings): void {\n fs.mkdirSync(path.dirname(settingsPath), { recursive: true });\n fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4) + '\\n');\n}\n\n/**\n * True when any settings file ONE HARNESS owns under `root` carries a NEIGHBOUR hook — one the consumer\n * repo wrote — whose entry path is repo-RELATIVE and would therefore fail to resolve from any cwd but\n * the root. See neighbour-hooks.ts for the measured failure and why webpieces owns the repair.\n *\n * Judged ONLY where the file registers webpieces hooks, exactly like `registrationStaleAt` below: a\n * settings file with no webpieces hooks in it is not a webpieces install, and webpieces rewriting\n * somebody's unrelated hook lines there would be editing a file it was never given.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function neighbourHooksStaleAt(harness: HarnessRegistration, root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return harness.settingsPaths(root).some((p: string): boolean => {\n const settings = readSettings(p);\n return registeredBins(settings).length > 0 && neighbourHooksStale(harness.shimAnchor, settings, root);\n });\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * True when any settings file ONE HARNESS owns under `root` carries a stale registration.\n *\n * Per harness, not per repo, so the drift report can NAME which one moved — `.claude/settings.json` and\n * `.codex/hooks.json` have different cures, and a fault that says only \"the registration is stale\" sends\n * the reader to the wrong file half the time.\n *\n * A file that does not exist, or exists and registers no webpieces hooks, is never judged (see\n * `registrationStale`). That is what keeps a repo which has never armed Codex from suddenly faulting on\n * a `.codex/hooks.json` it does not have.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function registrationStaleAt(harness: HarnessRegistration, root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return harness.settingsPaths(root).some((p: string): boolean => registrationStale(harness, readSettings(p)));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * True when either Claude project settings file under `root` is missing the managed `env` entry.\n *\n * CLAUDE-ONLY by construction, and stated as such rather than looped over the harnesses: `env` is a\n * Claude Code settings surface, Codex has no equivalent, and Codex's cwd is measured not to drift, which\n * is the whole thing the entry is for. See HarnessRegistration.managesEnv.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function envStaleAt(root: string | null): boolean {\n if (root === null) return false;\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return CLAUDE_REGISTRATION.settingsPaths(root).some((p: string): boolean => envStale(readSettings(p)));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // best-effort: unreadable/invalid settings counts as \"not stale\" so it never wedges a call\n return false;\n }\n}\n\n/**\n * WHAT was rewritten in ONE settings file. Data-only → a class, per CLAUDE.md.\n *\n * Two independent flags rather than one path, because the cure has to be able to SAY which repair it\n * made: \"rewrote the hook registration\" printed for a file whose registration was already current and\n * whose `env` entry was the only thing missing is a cure lying about its own work.\n */\nexport class SettingsRepair {\n constructor(\n readonly settingsPath: string,\n readonly registration: boolean,\n readonly env: boolean,\n /**\n * The NEW spelling of every NEIGHBOUR hook command this repair anchored — the consumer's own\n * entries, which webpieces rewrites but does not author.\n *\n * The commands themselves rather than a count or a flag, because this is the one repair that\n * edits lines webpieces did not write: the cure has to be able to show the consumer exactly what\n * it changed in their file, or it is a silent edit to somebody else's hooks.\n */\n readonly anchoredNeighbours: readonly string[],\n ) {}\n}\n\n/**\n * Rewrite every stale settings file under `root`, for EVERY harness; returns what changed, per file.\n *\n * Existing files only — this never CREATES a registration. Arming a harness is the installer's decision\n * (`wp-install-ai-hooks`); this is the cure for one that has already been armed and has drifted, so a\n * repo that has never armed Codex is left exactly as it was.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function repairRegistrationAt(root: string): readonly SettingsRepair[] {\n const repairs: SettingsRepair[] = [];\n for (const harness of HARNESS_REGISTRATIONS) {\n for (const settingsPath of harness.settingsPaths(root)) {\n if (!fs.existsSync(settingsPath)) continue;\n const settings = readSettings(settingsPath);\n const neededRegistration = registrationStale(harness, settings);\n const neededEnv = harness.managesEnv && envStale(settings);\n const changedManaged = repairRegistration(harness, settings);\n // AFTER the managed repair, never before: repairRegistration() removes the retired\n // guarantee-root entry and rewrites the two managed commands, so by the time the neighbour\n // pass runs there is nothing webpieces-owned left for it to look at. Gated on\n // registeredBins() for the same reason every other judgement here is — a settings file that\n // registers no webpieces hooks is not a webpieces install, and rewriting somebody's\n // unrelated hook lines in it would be webpieces editing a file it was never given.\n const anchored = registeredBins(settings).length === 0 ? [] : anchorNeighbourHooks(harness.shimAnchor, settings, root);\n if (!changedManaged && anchored.length === 0) continue;\n writeSettings(settingsPath, settings);\n repairs.push(new SettingsRepair(settingsPath, neededRegistration, neededEnv, anchored));\n }\n }\n return repairs;\n}\n\n/**\n * The names the drift check reports, so a deny can say WHICH surface moved.\n *\n * There were four, then three, and there are now FOUR again — but the fourth is not the one that was\n * deleted. `GUARANTEE_ROOT_SURFACE` went with L-1 itself: an absolutely-registered shim resolves from\n * any cwd, so there is no launch guarantee left to police and no second .sh file to keep byte-locked. A\n * settings file still carrying the retired H1 entry is not its own surface — it is ordinary REGISTRATION\n * drift, which `registrationStaleAt()` reports and `repairRegistration()` fixes by removing it.\n *\n * The new fourth is `.codex/hooks.json`, and it is here because of what happened while it was NOT a\n * managed surface: something else wrote it, with a matcher that matched no Codex file tool and a shim\n * path anchored on a variable Codex does not set, and no check in this package could see it. A file the\n * guards depend on and nothing validates is the exact shape of that incident.\n *\n * Each harness's registration surface is its own name, from HarnessRegistration.registrationSurface, so\n * the deny sends the reader to the file that actually moved.\n */\nexport const SHIM_SURFACE = SHIM_MARKER;\nexport const REGISTRATION_SURFACE = CLAUDE_REGISTRATION.registrationSurface;\nexport const CODEX_REGISTRATION_SURFACE = CODEX_REGISTRATION.registrationSurface;\nexport const ENV_SURFACE = `.claude/settings.json env.${BASH_CWD_ENV_KEY}`;\n// The generic PR-gate reviewer agent (issue #938): committed, generated, byte-stable — the same contract as\n// the shim, so the same check and the same cure.\nexport const REVIEWER_AGENT_SURFACE = REVIEWER_AGENT_MARKER;\n\n/**\n * WHICH of the managed surfaces disagree with this release — the input to fault S.\n *\n * All of them are checked against the SAME root, resolved from the RUNNING MODULE (governingShimRoot),\n * never from cwd and never from `$CLAUDE_PROJECT_DIR`: the files we compare and the renderers we\n * compare them TO must come from one install, or the check straddles two trees and can never converge.\n */\n// webpieces-disable no-function-outside-class -- module-scope for the same dependency-free reason as HarnessRegistration's siblings\nexport function managedSurfaceDrift(root: string | null): readonly string[] {\n const drifted: string[] = [];\n if (committedShimStale(root)) drifted.push(SHIM_SURFACE);\n for (const harness of HARNESS_REGISTRATIONS) {\n if (registrationStaleAt(harness, root)) drifted.push(harness.registrationSurface);\n // A neighbour hook registered with a RELATIVE entry path dies from any cwd but the root, and per\n // the hooks reference that non-zero exit is a NON-BLOCKING error — a SILENT UNGUARDED ALLOW. It\n // is a drift surface for exactly the reason the managed registration is one: nothing else in\n // this repo can see it, and the way it fails looks like a guard that PASSED. See\n // neighbour-hooks.ts, and issue #852 where it silently disarmed three security guards.\n if (neighbourHooksStaleAt(harness, root)) drifted.push(harness.neighbourSurface);\n }\n if (envStaleAt(root)) drifted.push(ENV_SURFACE);\n if (reviewerAgentStale(root)) drifted.push(REVIEWER_AGENT_SURFACE);\n return drifted;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /** The agent type this file registers, and the value `commands.pr-gate.reviewerAgentName` names. */
2
+ export declare const REVIEWER_AGENT_NAME = "webpieces-reviewer";
3
+ /** The committed file, repo-relative — also the name the drift check reports it under. */
4
+ export declare const REVIEWER_AGENT_MARKER = ".claude/agents/webpieces-reviewer.md";
5
+ /** The copy that ships in the package, byte-identical to renderReviewerAgent() (locked by a unit test). */
6
+ export declare const REVIEWER_AGENT_TEMPLATE = "webpieces-reviewer.md";
7
+ export declare function reviewerAgentPath(projectRoot: string): string;
8
+ export declare function renderReviewerAgent(): string;
9
+ /**
10
+ * True when this tree is webpieces-hooked (its committed shim exists) and the reviewer agent is MISSING or
11
+ * differs from renderReviewerAgent(). Gated on the shim for the same reason `committedShimStale` is gated
12
+ * on its own file: a tree webpieces never installed into has no managed surface to police.
13
+ */
14
+ export declare function reviewerAgentStale(root: string | null): boolean;
15
+ /**
16
+ * Write the reviewer agent under `root`, returning true when the file changed. Creates `.claude/agents/`
17
+ * when it is absent — that directory is what a Claude Code session scans for agent types.
18
+ */
19
+ export declare function writeReviewerAgent(root: string): boolean;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REVIEWER_AGENT_TEMPLATE = exports.REVIEWER_AGENT_MARKER = exports.REVIEWER_AGENT_NAME = void 0;
4
+ exports.reviewerAgentPath = reviewerAgentPath;
5
+ exports.renderReviewerAgent = renderReviewerAgent;
6
+ exports.reviewerAgentStale = reviewerAgentStale;
7
+ exports.writeReviewerAgent = writeReviewerAgent;
8
+ const tslib_1 = require("tslib");
9
+ const fs = tslib_1.__importStar(require("fs"));
10
+ const path = tslib_1.__importStar(require("path"));
11
+ const shim_1 = require("./shim");
12
+ // ---------------------------------------------------------------------------
13
+ // THE GENERIC REVIEWER AGENT — `.claude/agents/webpieces-reviewer.md`, a webpieces-owned, committed file
14
+ // (issue #938).
15
+ //
16
+ // Every PR-gate checklist used to name its OWN agent type, one `.claude/agents/<name>-reviewer.md` each.
17
+ // Those files added almost nothing over the checklist doc — a tool restriction and a paragraph saying
18
+ // "read your instructions file" — were annoying to author per checklist, and drifted (#863: Codex never
19
+ // read them at all). They also forced one subagent per checklist. So a repo now names ONE agent type in
20
+ // `commands.pr-gate.reviewerAgentName`, and this is the one webpieces ships: checklist-agnostic, because
21
+ // everything checklist-specific is in the per-run instructions files `wp-review-upsert-pr` generates.
22
+ //
23
+ // It is a MANAGED SURFACE, exactly like `.claude/webpieces/ai-hook.sh`: GENERATED from
24
+ // renderReviewerAgent(), byte-STABLE across releases (no version stamp, so it changes only when its own
25
+ // words do), written by `wp-install-ai-hooks` and `wp-upgrade-shim`, and checked by managedSurfaceDrift()
26
+ // so a missing, stale or hand-edited copy is flagged with `pnpm wp-upgrade-shim` as the cure. A repo
27
+ // that wants different words points `reviewerAgentName` at an agent of its own instead of editing this.
28
+ //
29
+ // fs + path + ./shim only, like the rest of this directory: the cure must run on a tree too broken to
30
+ // load the rule engine.
31
+ // ---------------------------------------------------------------------------
32
+ /** The agent type this file registers, and the value `commands.pr-gate.reviewerAgentName` names. */
33
+ exports.REVIEWER_AGENT_NAME = 'webpieces-reviewer';
34
+ /** The committed file, repo-relative — also the name the drift check reports it under. */
35
+ exports.REVIEWER_AGENT_MARKER = `.claude/agents/${exports.REVIEWER_AGENT_NAME}.md`;
36
+ /** The copy that ships in the package, byte-identical to renderReviewerAgent() (locked by a unit test). */
37
+ exports.REVIEWER_AGENT_TEMPLATE = `${exports.REVIEWER_AGENT_NAME}.md`;
38
+ // webpieces-disable no-function-outside-class -- pure fs+path helper beside shimPath, in the dependency-free bin module
39
+ function reviewerAgentPath(projectRoot) {
40
+ return path.join(projectRoot, ...exports.REVIEWER_AGENT_MARKER.split('/'));
41
+ }
42
+ // webpieces-disable no-function-outside-class -- pure renderer beside renderShim, in the dependency-free bin module
43
+ function renderReviewerAgent() {
44
+ return `---
45
+ name: ${exports.REVIEWER_AGENT_NAME}
46
+ description: Generic PR-gate reviewer. Reviews a diff against one or more checklist docs, each over its own in-scope files, and writes exactly one verdict file per checklist. Spawned by \`pnpm wp-review-upsert-pr\`, which names the instructions files to read. Never edits code.
47
+ tools: Read, Grep, Glob, Bash, Write
48
+ ---
49
+
50
+ <!-- Generated by webpieces (@webpieces/ai-hook-rules) — do not edit; regenerate with pnpm wp-upgrade-shim.
51
+ To change how reviews are done, point commands.pr-gate.reviewerAgentName at an agent of your own. -->
52
+
53
+ You are a PR-gate reviewer. You did not write this change, and your job is to judge it against the
54
+ checklist(s) you are handed — nothing else.
55
+
56
+ ## What you are given
57
+
58
+ Your caller names ONE OR MORE instructions files by absolute path, one per checklist
59
+ (\`<checklist-id>.instructions.md\`). Read every one of them FIRST. Each is regenerated on every run and
60
+ holds, for its checklist:
61
+
62
+ - the checklist doc to review against — the substance of that review;
63
+ - the files in scope, each with its extracted diff and the absolute path of the full source;
64
+ - the diff manifest, the diff basis, and any pre-resolved context for this repo;
65
+ - the exact verdict file to write, and its exact format.
66
+
67
+ Work only from those files. Nothing about any checklist is restated here, so nothing here can drift.
68
+
69
+ ## How to review
70
+
71
+ 1. Handle each checklist SEPARATELY. Read its doc, then its in-scope diffs, then the full source of every
72
+ in-scope file — a hunk shows what changed, only the whole file shows what it changed into.
73
+ 2. Judge each checklist ONLY against its own in-scope files. A finding that belongs to another checklist
74
+ is not a finding for this one; a matched file that turns out to be irrelevant gets one sentence.
75
+ 3. Read other files for context when a judgement needs it, but do not go hunting: no searches through
76
+ \`node_modules\`, no re-deriving the dependency graph. If something you need is missing, say so in
77
+ \`output\` and judge what you could see.
78
+
79
+ ## What you write
80
+
81
+ Exactly ONE verdict file per checklist you were handed, at the path and in the format its instructions
82
+ file gives — and nothing for a checklist you were not handed.
83
+
84
+ You NEVER edit code, config, docs, or any file other than those verdict files. You never write
85
+ \`review.json\` or an \`override-<id>.json\`. If a finding needs a human's decision, say so in \`output\`;
86
+ the coordinating agent is the one with the human.
87
+ `;
88
+ }
89
+ /**
90
+ * True when this tree is webpieces-hooked (its committed shim exists) and the reviewer agent is MISSING or
91
+ * differs from renderReviewerAgent(). Gated on the shim for the same reason `committedShimStale` is gated
92
+ * on its own file: a tree webpieces never installed into has no managed surface to police.
93
+ */
94
+ // webpieces-disable no-function-outside-class -- pure fs+path helper beside committedShimStale, in the dependency-free bin module
95
+ function reviewerAgentStale(root) {
96
+ if (root === null || !fs.existsSync((0, shim_1.shimPath)(root)))
97
+ return false;
98
+ const target = reviewerAgentPath(root);
99
+ if (!fs.existsSync(target))
100
+ return true;
101
+ return fs.readFileSync(target, 'utf8') !== renderReviewerAgent();
102
+ }
103
+ /**
104
+ * Write the reviewer agent under `root`, returning true when the file changed. Creates `.claude/agents/`
105
+ * when it is absent — that directory is what a Claude Code session scans for agent types.
106
+ */
107
+ // webpieces-disable no-function-outside-class -- pure fs+path writer beside writeShim, in the dependency-free bin module
108
+ function writeReviewerAgent(root) {
109
+ const target = reviewerAgentPath(root);
110
+ const desired = renderReviewerAgent();
111
+ if (fs.existsSync(target) && fs.readFileSync(target, 'utf8') === desired)
112
+ return false;
113
+ fs.mkdirSync(path.dirname(target), { recursive: true });
114
+ fs.writeFileSync(target, desired);
115
+ return true;
116
+ }
117
+ //# sourceMappingURL=reviewer-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewer-agent.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/reviewer-agent.ts"],"names":[],"mappings":";;;AAoCA,8CAEC;AAGD,kDA6CC;AAQD,gDAKC;AAOD,gDAOC;;AAjHD,+CAAyB;AACzB,mDAA6B;AAE7B,iCAAkC;AAElC,8EAA8E;AAC9E,yGAAyG;AACzG,gBAAgB;AAChB,EAAE;AACF,yGAAyG;AACzG,sG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CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,mBAAmB,EAAE,CAAC;IACtC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACvF,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { shimPath } from './shim';\n\n// ---------------------------------------------------------------------------\n// THE GENERIC REVIEWER AGENT — `.claude/agents/webpieces-reviewer.md`, a webpieces-owned, committed file\n// (issue #938).\n//\n// Every PR-gate checklist used to name its OWN agent type, one `.claude/agents/<name>-reviewer.md` each.\n// Those files added almost nothing over the checklist doc — a tool restriction and a paragraph saying\n// \"read your instructions file\" — were annoying to author per checklist, and drifted (#863: Codex never\n// read them at all). They also forced one subagent per checklist. So a repo now names ONE agent type in\n// `commands.pr-gate.reviewerAgentName`, and this is the one webpieces ships: checklist-agnostic, because\n// everything checklist-specific is in the per-run instructions files `wp-review-upsert-pr` generates.\n//\n// It is a MANAGED SURFACE, exactly like `.claude/webpieces/ai-hook.sh`: GENERATED from\n// renderReviewerAgent(), byte-STABLE across releases (no version stamp, so it changes only when its own\n// words do), written by `wp-install-ai-hooks` and `wp-upgrade-shim`, and checked by managedSurfaceDrift()\n// so a missing, stale or hand-edited copy is flagged with `pnpm wp-upgrade-shim` as the cure. A repo\n// that wants different words points `reviewerAgentName` at an agent of its own instead of editing this.\n//\n// fs + path + ./shim only, like the rest of this directory: the cure must run on a tree too broken to\n// load the rule engine.\n// ---------------------------------------------------------------------------\n\n/** The agent type this file registers, and the value `commands.pr-gate.reviewerAgentName` names. */\nexport const REVIEWER_AGENT_NAME = 'webpieces-reviewer';\n\n/** The committed file, repo-relative — also the name the drift check reports it under. */\nexport const REVIEWER_AGENT_MARKER = `.claude/agents/${REVIEWER_AGENT_NAME}.md`;\n\n/** The copy that ships in the package, byte-identical to renderReviewerAgent() (locked by a unit test). */\nexport const REVIEWER_AGENT_TEMPLATE = `${REVIEWER_AGENT_NAME}.md`;\n\n// webpieces-disable no-function-outside-class -- pure fs+path helper beside shimPath, in the dependency-free bin module\nexport function reviewerAgentPath(projectRoot: string): string {\n return path.join(projectRoot, ...REVIEWER_AGENT_MARKER.split('/'));\n}\n\n// webpieces-disable no-function-outside-class -- pure renderer beside renderShim, in the dependency-free bin module\nexport function renderReviewerAgent(): string {\n return `---\nname: ${REVIEWER_AGENT_NAME}\ndescription: Generic PR-gate reviewer. Reviews a diff against one or more checklist docs, each over its own in-scope files, and writes exactly one verdict file per checklist. Spawned by \\`pnpm wp-review-upsert-pr\\`, which names the instructions files to read. Never edits code.\ntools: Read, Grep, Glob, Bash, Write\n---\n\n<!-- Generated by webpieces (@webpieces/ai-hook-rules) — do not edit; regenerate with pnpm wp-upgrade-shim.\n To change how reviews are done, point commands.pr-gate.reviewerAgentName at an agent of your own. -->\n\nYou are a PR-gate reviewer. You did not write this change, and your job is to judge it against the\nchecklist(s) you are handed — nothing else.\n\n## What you are given\n\nYour caller names ONE OR MORE instructions files by absolute path, one per checklist\n(\\`<checklist-id>.instructions.md\\`). Read every one of them FIRST. Each is regenerated on every run and\nholds, for its checklist:\n\n- the checklist doc to review against — the substance of that review;\n- the files in scope, each with its extracted diff and the absolute path of the full source;\n- the diff manifest, the diff basis, and any pre-resolved context for this repo;\n- the exact verdict file to write, and its exact format.\n\nWork only from those files. Nothing about any checklist is restated here, so nothing here can drift.\n\n## How to review\n\n1. Handle each checklist SEPARATELY. Read its doc, then its in-scope diffs, then the full source of every\n in-scope file — a hunk shows what changed, only the whole file shows what it changed into.\n2. Judge each checklist ONLY against its own in-scope files. A finding that belongs to another checklist\n is not a finding for this one; a matched file that turns out to be irrelevant gets one sentence.\n3. Read other files for context when a judgement needs it, but do not go hunting: no searches through\n \\`node_modules\\`, no re-deriving the dependency graph. If something you need is missing, say so in\n \\`output\\` and judge what you could see.\n\n## What you write\n\nExactly ONE verdict file per checklist you were handed, at the path and in the format its instructions\nfile gives — and nothing for a checklist you were not handed.\n\nYou NEVER edit code, config, docs, or any file other than those verdict files. You never write\n\\`review.json\\` or an \\`override-<id>.json\\`. If a finding needs a human's decision, say so in \\`output\\`;\nthe coordinating agent is the one with the human.\n`;\n}\n\n/**\n * True when this tree is webpieces-hooked (its committed shim exists) and the reviewer agent is MISSING or\n * differs from renderReviewerAgent(). Gated on the shim for the same reason `committedShimStale` is gated\n * on its own file: a tree webpieces never installed into has no managed surface to police.\n */\n// webpieces-disable no-function-outside-class -- pure fs+path helper beside committedShimStale, in the dependency-free bin module\nexport function reviewerAgentStale(root: string | null): boolean {\n if (root === null || !fs.existsSync(shimPath(root))) return false;\n const target = reviewerAgentPath(root);\n if (!fs.existsSync(target)) return true;\n return fs.readFileSync(target, 'utf8') !== renderReviewerAgent();\n}\n\n/**\n * Write the reviewer agent under `root`, returning true when the file changed. Creates `.claude/agents/`\n * when it is absent — that directory is what a Claude Code session scans for agent types.\n */\n// webpieces-disable no-function-outside-class -- pure fs+path writer beside writeShim, in the dependency-free bin module\nexport function writeReviewerAgent(root: string): boolean {\n const target = reviewerAgentPath(root);\n const desired = renderReviewerAgent();\n if (fs.existsSync(target) && fs.readFileSync(target, 'utf8') === desired) return false;\n fs.mkdirSync(path.dirname(target), { recursive: true });\n fs.writeFileSync(target, desired);\n return true;\n}\n"]}
package/src/bin/setup.js CHANGED
@@ -15,6 +15,7 @@ const os_1 = require("os");
15
15
  const readline_1 = require("readline");
16
16
  const rules_config_1 = require("@webpieces/rules-config");
17
17
  const shim_1 = require("./shim");
18
+ const reviewer_agent_1 = require("./reviewer-agent");
18
19
  const hook_registration_1 = require("./hook-registration");
19
20
  const managed_env_1 = require("./managed-env");
20
21
  const codex_trust_1 = require("./codex-trust");
@@ -228,6 +229,11 @@ function applyHook(hook, chosen, targets, projectRoot) {
228
229
  // otherwise clean it up once neither hook references it anymore.
229
230
  if (chosen !== null && !chosen.absolute) {
230
231
  writeShim(projectRoot);
232
+ // The generic PR-gate reviewer agent is part of the same committed, managed set as the shim — the
233
+ // drift check reports it beside the shim, so the installer writes it beside the shim.
234
+ if ((0, reviewer_agent_1.writeReviewerAgent)(projectRoot)) {
235
+ console.log(` ✅ ${reviewer_agent_1.REVIEWER_AGENT_MARKER} (the generic PR-gate reviewer; generated — commit it, do not edit it)`);
236
+ }
231
237
  }
232
238
  else if (!markerReferenced(targets, shim_1.SHIM_MARKER)) {
233
239
  removeShim(projectRoot);