@webpieces/ai-hook-rules 0.4.826 → 0.4.827

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/ai-hook-rules",
3
- "version": "0.4.826",
3
+ "version": "0.4.827",
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.826",
28
+ "@webpieces/rules-config": "0.4.827",
29
29
  "inversify": "7.10.4",
30
30
  "reflect-metadata": "0.2.2"
31
31
  },
@@ -68,7 +68,7 @@ class CodexSubagentSharedTreeGuard {
68
68
  verdictWriteError(targets) {
69
69
  return new rules_config_1.RuleFailError(exports.CODEX_SUBAGENT_RULE, `A Codex subagent is writing review state directly: ${targets}\n\n` +
70
70
  `A reviewer verdict is never written as a file. Submit it through ${rules_config_1.WRITE_REVIEW_BIN}, which ` +
71
- `validates it and records who wrote it — a review-<id>.json written any other way is rejected ` +
71
+ `validates it and records who wrote it — a review-round<N>-<id>.json written any other way is rejected ` +
72
72
  `by pnpm wp-finish-upsert-pr.`, undefined, undefined, [
73
73
  new rules_config_1.Option(`Submit the verdict JSON on stdin: pnpm ${rules_config_1.WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF (or --file <a path OUTSIDE this tree>)`, true),
74
74
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"codex-subagent-guard.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-subagent-guard.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAyI;AAGzI,yCAA8C;AAEjC,QAAA,mBAAmB,GAAG,wCA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SAAS,EACT;YACI,IAAI,qBAAM,CAAC,wGAAwG,QAAQ,cAAc,EAAE,IAAI,CAAC;YAChJ,IAAI,qBAAM,CAAC,wGAAwG,CAAC;SACvH,CACJ,CAAC;QACF,OAAO,IAAI,qBAAa,CAAC,IAAA,kCAAmB,EAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,OAAe;QACrC,OAAO,IAAI,4BAAa,CACpB,2BAAmB,EACnB,sDAAsD,OAAO,MAAM;YACnE,oEAAoE,+BAAgB,UAAU;YAC9F,+FAA+F;YAC/F,8BAA8B,EAC9B,SAAS,EACT,SAAS,EACT;YACI,IAAI,qBAAM,CAAC,0CAA0C,+BAAgB,wEAAwE,EAAE,IAAI,CAAC;SACvJ,CACJ,CAAC;IACN,CAAC;IAEO,aAAa,CAAC,QAAgB,EAAE,IAAY;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,gCAAiB,EAAE,4BAAa,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QAC/E,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;IAEO,QAAQ,CAAC,QAAgB,EAAE,IAAY;QAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;CACJ;AA7DD,oEA6DC","sourcesContent":["import * as path from 'path';\n\nimport { Option, PR_REVIEW_DIR, RuleFailError, WEBPIECES_TMP_DIR, WRITE_REVIEW_BIN, renderRuleFailForAi } from '@webpieces/rules-config';\n\nimport { AgentHookEvent, FileOperation } from '../core/agent-event';\nimport { BlockedResult } from '../core/types';\n\nexport const CODEX_SUBAGENT_RULE = 'codex-subagent-no-write-in-shared-tree';\n\n/**\n * A Codex SUBAGENT may not write into the tree it shares with its coordinator.\n *\n * This exists because of a MEASURED structural gap, not a style preference. Claude Code can hand a\n * subagent its own git worktree (`isolation: \"worktree\"`), so two agents editing at once are editing\n * two different checkouts. Codex cannot: `spawn_agent`'s schema is\n * `{fork_turns?, message, model?, reasoning_effort?, task_name}` — there is no cwd, workdir or\n * worktree parameter — and cwd resets to the repo root before every command, so a subagent cannot even\n * put itself somewhere else. Every Codex subagent therefore writes into the coordinator's checkout,\n * and concurrent subagents write into each other's.\n *\n * Reviewers WRITE too, and that is not a side detail: one verdict per checklist is a reviewer's whole\n * output. An earlier comment here said \"reviewers are unaffected: they only read\", and it was false —\n * this guard blocked a Codex reviewer's `review-<id>.json`, the coordinator then took this guard's own\n * \"hand the edit back to the coordinator\" option and wrote all five verdicts itself, and the gate\n * accepted them (issue #863). So a verdict is never a patch: every reviewer SUBMITS it through\n * `pnpm wp-write-review`, a Bash call this guard does not see, and a blocked write under\n * `.webpieces/pr-review/` names that bin — and NEVER offers the coordinator hand-back, because a\n * coordinator writing a reviewer's verdict is precisely the forgery the gate refuses.\n *\n * NOT a configurable rule yet, and that is deliberate. A rule registered with the engine must have an\n * entry in webpieces.config.json, and the validator that would accept a new key is a RELEASE behind\n * the source that defines it — adding both at once rejects the key as unknown and blocks every tool\n * call in the repo. So the guard ships here, gated on `aiType === 'codex'`, and becomes a config-keyed\n * rule in the follow-up PR that lands after the publish.\n */\nexport class CodexSubagentSharedTreeGuard {\n /**\n * Returns a block when a Codex SUBAGENT's patch targets a file inside `root`, else null.\n * Claude Code events return null unconditionally — the harness has real isolation.\n */\n check(event: AgentHookEvent, root: string): BlockedResult | null {\n if (event.aiType !== 'codex') return null;\n if (event.agentId === '') return null;\n const inside = event.files.filter((f: FileOperation): boolean => this.isInside(f.input.filePath, root));\n if (inside.length === 0) return null;\n const targets = inside.map((f: FileOperation): string => path.relative(root, f.input.filePath)).join(', ');\n if (inside.some((f: FileOperation): boolean => this.isReviewState(f.input.filePath, root))) {\n return new BlockedResult(renderRuleFailForAi(this.verdictWriteError(targets)));\n }\n const worktree = path.join(path.dirname(root), 'wt-<task-name>');\n const error = new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing into the tree it shares with its coordinator: ${targets}\\n\\n` +\n `Codex cannot spawn a subagent into its own checkout — spawn_agent takes no cwd or worktree, ` +\n `and cwd resets to the repo root before every command — so this edit lands in the same files ` +\n `the coordinator and every sibling subagent are editing.`,\n undefined,\n undefined,\n [\n new Option(`Give this agent its own checkout and address every file by ABSOLUTE path inside it: git worktree add ${worktree} -b <branch>`, true),\n new Option('Hand the edit back to the coordinator and have this agent report what to change instead of changing it'),\n ],\n );\n return new BlockedResult(renderRuleFailForAi(error));\n }\n\n /**\n * A write under `.webpieces/pr-review/` — a verdict, or anything beside one. There is exactly one\n * route for it, and it is not a patch. No \"hand it to the coordinator\" option: the coordinator may\n * never write a reviewer's verdict, and `wp-finish-upsert-pr` rejects one that did not come through\n * the bin.\n */\n private verdictWriteError(targets: string): RuleFailError {\n return new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing review state directly: ${targets}\\n\\n` +\n `A reviewer verdict is never written as a file. Submit it through ${WRITE_REVIEW_BIN}, which ` +\n `validates it and records who wrote it — a review-<id>.json written any other way is rejected ` +\n `by pnpm wp-finish-upsert-pr.`,\n undefined,\n undefined,\n [\n new Option(`Submit the verdict JSON on stdin: pnpm ${WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF (or --file <a path OUTSIDE this tree>)`, true),\n ],\n );\n }\n\n private isReviewState(filePath: string, root: string): boolean {\n const reviewDir = path.join(root, WEBPIECES_TMP_DIR, PR_REVIEW_DIR) + path.sep;\n return path.resolve(filePath).startsWith(reviewDir);\n }\n\n private isInside(filePath: string, root: string): boolean {\n const rootWithSep = root.endsWith(path.sep) ? root : root + path.sep;\n return path.resolve(filePath).startsWith(rootWithSep);\n }\n}\n"]}
1
+ {"version":3,"file":"codex-subagent-guard.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-subagent-guard.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,0DAAyI;AAGzI,yCAA8C;AAEjC,QAAA,mBAAmB,GAAG,wCAAwC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,4BAA4B;IACrC;;;OAGG;IACH,KAAK,CAAC,KAAqB,EAAE,IAAY;QACrC,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;QAC1C,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAgB,EAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;QACxG,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3G,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAgB,EAAW,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YACzF,OAAO,IAAI,qBAAa,CAAC,IAAA,kCAAmB,EAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnF,CAA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CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;CACJ;AA7DD,oEA6DC","sourcesContent":["import * as path from 'path';\n\nimport { Option, PR_REVIEW_DIR, RuleFailError, WEBPIECES_TMP_DIR, WRITE_REVIEW_BIN, renderRuleFailForAi } from '@webpieces/rules-config';\n\nimport { AgentHookEvent, FileOperation } from '../core/agent-event';\nimport { BlockedResult } from '../core/types';\n\nexport const CODEX_SUBAGENT_RULE = 'codex-subagent-no-write-in-shared-tree';\n\n/**\n * A Codex SUBAGENT may not write into the tree it shares with its coordinator.\n *\n * This exists because of a MEASURED structural gap, not a style preference. Claude Code can hand a\n * subagent its own git worktree (`isolation: \"worktree\"`), so two agents editing at once are editing\n * two different checkouts. Codex cannot: `spawn_agent`'s schema is\n * `{fork_turns?, message, model?, reasoning_effort?, task_name}` — there is no cwd, workdir or\n * worktree parameter — and cwd resets to the repo root before every command, so a subagent cannot even\n * put itself somewhere else. Every Codex subagent therefore writes into the coordinator's checkout,\n * and concurrent subagents write into each other's.\n *\n * Reviewers WRITE too, and that is not a side detail: one verdict per checklist is a reviewer's whole\n * output. An earlier comment here said \"reviewers are unaffected: they only read\", and it was false —\n * this guard blocked a Codex reviewer's `review-<id>.json`, the coordinator then took this guard's own\n * \"hand the edit back to the coordinator\" option and wrote all five verdicts itself, and the gate\n * accepted them (issue #863). So a verdict is never a patch: every reviewer SUBMITS it through\n * `pnpm wp-write-review`, a Bash call this guard does not see, and a blocked write under\n * `.webpieces/pr-review/` names that bin — and NEVER offers the coordinator hand-back, because a\n * coordinator writing a reviewer's verdict is precisely the forgery the gate refuses.\n *\n * NOT a configurable rule yet, and that is deliberate. A rule registered with the engine must have an\n * entry in webpieces.config.json, and the validator that would accept a new key is a RELEASE behind\n * the source that defines it — adding both at once rejects the key as unknown and blocks every tool\n * call in the repo. So the guard ships here, gated on `aiType === 'codex'`, and becomes a config-keyed\n * rule in the follow-up PR that lands after the publish.\n */\nexport class CodexSubagentSharedTreeGuard {\n /**\n * Returns a block when a Codex SUBAGENT's patch targets a file inside `root`, else null.\n * Claude Code events return null unconditionally — the harness has real isolation.\n */\n check(event: AgentHookEvent, root: string): BlockedResult | null {\n if (event.aiType !== 'codex') return null;\n if (event.agentId === '') return null;\n const inside = event.files.filter((f: FileOperation): boolean => this.isInside(f.input.filePath, root));\n if (inside.length === 0) return null;\n const targets = inside.map((f: FileOperation): string => path.relative(root, f.input.filePath)).join(', ');\n if (inside.some((f: FileOperation): boolean => this.isReviewState(f.input.filePath, root))) {\n return new BlockedResult(renderRuleFailForAi(this.verdictWriteError(targets)));\n }\n const worktree = path.join(path.dirname(root), 'wt-<task-name>');\n const error = new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing into the tree it shares with its coordinator: ${targets}\\n\\n` +\n `Codex cannot spawn a subagent into its own checkout — spawn_agent takes no cwd or worktree, ` +\n `and cwd resets to the repo root before every command — so this edit lands in the same files ` +\n `the coordinator and every sibling subagent are editing.`,\n undefined,\n undefined,\n [\n new Option(`Give this agent its own checkout and address every file by ABSOLUTE path inside it: git worktree add ${worktree} -b <branch>`, true),\n new Option('Hand the edit back to the coordinator and have this agent report what to change instead of changing it'),\n ],\n );\n return new BlockedResult(renderRuleFailForAi(error));\n }\n\n /**\n * A write under `.webpieces/pr-review/` — a verdict, or anything beside one. There is exactly one\n * route for it, and it is not a patch. No \"hand it to the coordinator\" option: the coordinator may\n * never write a reviewer's verdict, and `wp-finish-upsert-pr` rejects one that did not come through\n * the bin.\n */\n private verdictWriteError(targets: string): RuleFailError {\n return new RuleFailError(\n CODEX_SUBAGENT_RULE,\n `A Codex subagent is writing review state directly: ${targets}\\n\\n` +\n `A reviewer verdict is never written as a file. Submit it through ${WRITE_REVIEW_BIN}, which ` +\n `validates it and records who wrote it — a review-round<N>-<id>.json written any other way is rejected ` +\n `by pnpm wp-finish-upsert-pr.`,\n undefined,\n undefined,\n [\n new Option(`Submit the verdict JSON on stdin: pnpm ${WRITE_REVIEW_BIN} --checklist <id> <<'EOF' … EOF (or --file <a path OUTSIDE this tree>)`, true),\n ],\n );\n }\n\n private isReviewState(filePath: string, root: string): boolean {\n const reviewDir = path.join(root, WEBPIECES_TMP_DIR, PR_REVIEW_DIR) + path.sep;\n return path.resolve(filePath).startsWith(reviewDir);\n }\n\n private isInside(filePath: string, root: string): boolean {\n const rootWithSep = root.endsWith(path.sep) ? root : root + path.sep;\n return path.resolve(filePath).startsWith(rootWithSep);\n }\n}\n"]}
@@ -69,11 +69,17 @@ Work only from those files. Nothing about any checklist is restated here, so not
69
69
 
70
70
  ## Before you review: the round budget
71
71
 
72
- For EACH checklist you were handed, run \`pnpm wp-write-review --checklist <id> --check\` first. It counts
73
- how many times that checklist has already been reviewed on this branch against the repository's
74
- \`maxReviewerRounds\`. When it REFUSES, do not review that checklist and submit nothing for it: report its
75
- refusal verbatim to your caller ("I am not allowed to review <id>: …"). \`wp-write-review\` refuses an
76
- over-budget verdict anyway, so a review past the budget is wasted work that cannot be recorded.
72
+ For EACH checklist you were handed, run \`pnpm wp-write-review --checklist <id> --check\` first. It confirms
73
+ the round is within the repository's \`maxReviewerRounds\` and that the checklist has no verdict yet in this
74
+ round, and it says when this is the FINAL round. When it REFUSES, do not review that checklist and submit
75
+ nothing for it: report its refusal verbatim to your caller ("I am not allowed to review <id>: …").
76
+ \`wp-write-review\` refuses an over-budget verdict anyway, so a review past the budget is wasted work that
77
+ cannot be recorded.
78
+
79
+ On the FINAL round there is no re-review, so there is no red: mark anything that must be fixed ORANGE, with
80
+ a concrete, actionable fix — the author applies it best effort and ships without another review, so put
81
+ every finding in now. Before the final round, a must-fix is RED and the author's fix is reviewed again.
82
+ Your instructions file says which round this is.
77
83
 
78
84
  ## How to review
79
85
 
@@ -1 +1 @@
1
- {"version":3,"file":"reviewer-agent.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/reviewer-agent.ts"],"names":[],"mappings":";;;AAqCA,8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IACxC,OAAO,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,mBAAmB,EAAE,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,yHAAyH;AACzH,SAAgB,kBAAkB,CAAC,IAAY;IAC3C,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,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` (`webpieces-reviewer` unless `overrideReviewerAgent` is true), 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 sets `\"overrideReviewerAgent\": true` and `reviewerAgentName` to an agent of its\n// 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 — the reviewer every repo gets unless it sets `overrideReviewerAgent`. */\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 submits exactly one verdict per checklist through pnpm wp-write-review. 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, set commands.pr-gate \"overrideReviewerAgent\": true and \"reviewerAgentName\" to 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 format, and the exact command that submits it.\n\nWork only from those files. Nothing about any checklist is restated here, so nothing here can drift.\n\n## Before you review: the round budget\n\nFor EACH checklist you were handed, run \\`pnpm wp-write-review --checklist <id> --check\\` first. It counts\nhow many times that checklist has already been reviewed on this branch against the repository's\n\\`maxReviewerRounds\\`. When it REFUSES, do not review that checklist and submit nothing for it: report its\nrefusal verbatim to your caller (\"I am not allowed to review <id>: …\"). \\`wp-write-review\\` refuses an\nover-budget verdict anyway, so a review past the budget is wasted work that cannot be recorded.\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 submit\n\nExactly ONE verdict per checklist you were handed — and nothing for a checklist you were not handed —\nin the format its instructions file gives, submitted through \\`pnpm wp-write-review --checklist <id>\\`\nwith the verdict JSON on stdin (a heredoc is simplest), or \\`--file <path>\\` naming a scratch file. It validates\nit, writes the verdict file, and records that YOU wrote it. A verdict file written any other way —\nby you, or by the coordinating agent on your behalf — is rejected by the gate, so there is no other route.\n\nYou NEVER edit code, config, docs, or any other file in the repo. You never write \\`summary.json\\` or an\n\\`override-<id>.json\\`. If a finding needs a human's decision, say so in \\`output\\`; the coordinating\nagent 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"]}
1
+ {"version":3,"file":"reviewer-agent.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/bin/reviewer-agent.ts"],"names":[],"mappings":";;;AAqCA,8CAEC;AAGD,kDA8DC;AAQD,gDAKC;AAOD,gDAOC;;AAnID,+CAAyB;AACzB,mDAA6B;AAE7B,iCAAkC;AAElC,8EAA8E;AAC9E,yGAAyG;AACzG,gBAAgB;AAChB,EAAE;AACF,yGAAyG;AACzG,sGAAsG;AACtG,wGAAwG;AACxG,wGAAwG;AACxG,qJAAqJ;AACrJ,sGAAsG;AACtG,EAAE;AACF,uFAAuF;AACvF,wGAAwG;AACxG,0GAA0G;AAC1G,qGAAqG;AACrG,6GAA6G;AAC7G,+BAA+B;AAC/B,EAAE;AACF,sGAAsG;AACtG,wBAAwB;AACxB,8EAA8E;AAE9E,gHAAgH;AACnG,QAAA,mBAAmB,GAAG,oBAAoB,CAAC;AAExD,0FAA0F;AAC7E,QAAA,qBAAqB,GAAG,kBAAkB,2BAAmB,KAAK,CAAC;AAEhF,2GAA2G;AAC9F,QAAA,uBAAuB,GAAG,GAAG,2BAAmB,KAAK,CAAC;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O,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` (`webpieces-reviewer` unless `overrideReviewerAgent` is true), 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 sets `\"overrideReviewerAgent\": true` and `reviewerAgentName` to an agent of its\n// 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 — the reviewer every repo gets unless it sets `overrideReviewerAgent`. */\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 submits exactly one verdict per checklist through pnpm wp-write-review. 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, set commands.pr-gate \"overrideReviewerAgent\": true and \"reviewerAgentName\" to 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 format, and the exact command that submits it.\n\nWork only from those files. Nothing about any checklist is restated here, so nothing here can drift.\n\n## Before you review: the round budget\n\nFor EACH checklist you were handed, run \\`pnpm wp-write-review --checklist <id> --check\\` first. It confirms\nthe round is within the repository's \\`maxReviewerRounds\\` and that the checklist has no verdict yet in this\nround, and it says when this is the FINAL round. When it REFUSES, do not review that checklist and submit\nnothing for it: report its refusal verbatim to your caller (\"I am not allowed to review <id>: …\").\n\\`wp-write-review\\` refuses an over-budget verdict anyway, so a review past the budget is wasted work that\ncannot be recorded.\n\nOn the FINAL round there is no re-review, so there is no red: mark anything that must be fixed ORANGE, with\na concrete, actionable fix — the author applies it best effort and ships without another review, so put\nevery finding in now. Before the final round, a must-fix is RED and the author's fix is reviewed again.\nYour instructions file says which round this is.\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 submit\n\nExactly ONE verdict per checklist you were handed — and nothing for a checklist you were not handed —\nin the format its instructions file gives, submitted through \\`pnpm wp-write-review --checklist <id>\\`\nwith the verdict JSON on stdin (a heredoc is simplest), or \\`--file <path>\\` naming a scratch file. It validates\nit, writes the verdict file, and records that YOU wrote it. A verdict file written any other way —\nby you, or by the coordinating agent on your behalf — is rejected by the gate, so there is no other route.\n\nYou NEVER edit code, config, docs, or any other file in the repo. You never write \\`summary.json\\` or an\n\\`override-<id>.json\\`. If a finding needs a human's decision, say so in \\`output\\`; the coordinating\nagent 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"]}
@@ -25,11 +25,17 @@ Work only from those files. Nothing about any checklist is restated here, so not
25
25
 
26
26
  ## Before you review: the round budget
27
27
 
28
- For EACH checklist you were handed, run `pnpm wp-write-review --checklist <id> --check` first. It counts
29
- how many times that checklist has already been reviewed on this branch against the repository's
30
- `maxReviewerRounds`. When it REFUSES, do not review that checklist and submit nothing for it: report its
31
- refusal verbatim to your caller ("I am not allowed to review <id>: …"). `wp-write-review` refuses an
32
- over-budget verdict anyway, so a review past the budget is wasted work that cannot be recorded.
28
+ For EACH checklist you were handed, run `pnpm wp-write-review --checklist <id> --check` first. It confirms
29
+ the round is within the repository's `maxReviewerRounds` and that the checklist has no verdict yet in this
30
+ round, and it says when this is the FINAL round. When it REFUSES, do not review that checklist and submit
31
+ nothing for it: report its refusal verbatim to your caller ("I am not allowed to review <id>: …").
32
+ `wp-write-review` refuses an over-budget verdict anyway, so a review past the budget is wasted work that
33
+ cannot be recorded.
34
+
35
+ On the FINAL round there is no re-review, so there is no red: mark anything that must be fixed ORANGE, with
36
+ a concrete, actionable fix — the author applies it best effort and ships without another review, so put
37
+ every finding in now. Before the final round, a must-fix is RED and the author's fix is reviewed again.
38
+ Your instructions file says which round this is.
33
39
 
34
40
  ## How to review
35
41