@webpieces/ai-hook-rules 0.4.835 → 0.4.836

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.
Files changed (64) hide show
  1. package/package.json +3 -2
  2. package/src/adapters/agent-adapters.d.ts +1 -1
  3. package/src/adapters/agent-adapters.js.map +1 -1
  4. package/src/adapters/agent-response.d.ts +2 -3
  5. package/src/adapters/agent-response.js +8 -54
  6. package/src/adapters/agent-response.js.map +1 -1
  7. package/src/adapters/claude-code-adapter.d.ts +1 -1
  8. package/src/adapters/claude-code-adapter.js +6 -6
  9. package/src/adapters/claude-code-adapter.js.map +1 -1
  10. package/src/adapters/codex-adapter.d.ts +1 -1
  11. package/src/adapters/codex-adapter.js +3 -3
  12. package/src/adapters/codex-adapter.js.map +1 -1
  13. package/src/adapters/codex-subagent-guard.d.ts +1 -1
  14. package/src/adapters/codex-subagent-guard.js.map +1 -1
  15. package/src/adapters/detect-ai.d.ts +1 -1
  16. package/src/adapters/detect-ai.js.map +1 -1
  17. package/src/adapters/guards-hook.js +6 -5
  18. package/src/adapters/guards-hook.js.map +1 -1
  19. package/src/adapters/hook-core.d.ts +2 -2
  20. package/src/adapters/hook-core.js +2 -2
  21. package/src/adapters/hook-core.js.map +1 -1
  22. package/src/adapters/hook-pipeline-evaluator.d.ts +5 -0
  23. package/src/adapters/hook-pipeline-evaluator.js +18 -0
  24. package/src/adapters/hook-pipeline-evaluator.js.map +1 -0
  25. package/src/adapters/review-identity-stamper.d.ts +1 -1
  26. package/src/adapters/review-identity-stamper.js.map +1 -1
  27. package/src/adapters/rules-hook.js +6 -5
  28. package/src/adapters/rules-hook.js.map +1 -1
  29. package/src/bin/hook-registration.d.ts +1 -1
  30. package/src/bin/hook-registration.js.map +1 -1
  31. package/src/bin/l0-decide.d.ts +1 -1
  32. package/src/bin/l0-decide.js.map +1 -1
  33. package/src/bin/l0-entry.d.ts +1 -1
  34. package/src/bin/l0-entry.js.map +1 -1
  35. package/src/bin/shim-audit-log.js +2 -2
  36. package/src/bin/shim-audit-log.js.map +1 -1
  37. package/src/core/ai-type-context.d.ts +1 -1
  38. package/src/core/ai-type-context.js +2 -2
  39. package/src/core/ai-type-context.js.map +1 -1
  40. package/src/core/apply-patch-parse.d.ts +1 -1
  41. package/src/core/apply-patch-parse.js +4 -4
  42. package/src/core/apply-patch-parse.js.map +1 -1
  43. package/src/core/runner.d.ts +1 -1
  44. package/src/core/runner.js.map +1 -1
  45. package/src/core/types.d.ts +2 -16
  46. package/src/core/types.js +5 -26
  47. package/src/core/types.js.map +1 -1
  48. package/src/core/version-sync.d.ts +1 -1
  49. package/src/core/version-sync.js.map +1 -1
  50. package/src/index.d.ts +1 -2
  51. package/src/index.js +1 -12
  52. package/src/index.js.map +1 -1
  53. package/src/adapters/hook-app.d.ts +0 -61
  54. package/src/adapters/hook-app.js +0 -110
  55. package/src/adapters/hook-app.js.map +0 -1
  56. package/src/adapters/hook-outcome.d.ts +0 -46
  57. package/src/adapters/hook-outcome.js +0 -60
  58. package/src/adapters/hook-outcome.js.map +0 -1
  59. package/src/adapters/hook-ports.d.ts +0 -57
  60. package/src/adapters/hook-ports.js +0 -90
  61. package/src/adapters/hook-ports.js.map +0 -1
  62. package/src/core/agent-event.d.ts +0 -81
  63. package/src/core/agent-event.js +0 -75
  64. package/src/core/agent-event.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/ai-hook-rules",
3
- "version": "0.4.835",
3
+ "version": "0.4.836",
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,8 @@
25
25
  "directory": "packages/tooling/ai-hook-rules"
26
26
  },
27
27
  "dependencies": {
28
- "@webpieces/rules-config": "0.4.835",
28
+ "@webpieces/hook-runtime": "0.4.836",
29
+ "@webpieces/rules-config": "0.4.836",
29
30
  "inversify": "7.10.4",
30
31
  "reflect-metadata": "0.2.2"
31
32
  },
@@ -1,5 +1,5 @@
1
1
  import { AgentPayload } from './agent-payload';
2
- import { AgentHookEvent } from '../core/agent-event';
2
+ import { AgentHookEvent } from '@webpieces/hook-runtime';
3
3
  /**
4
4
  * The ONE place a payload is routed to its harness's adapter. Every other module takes an
5
5
  * `AgentHookEvent` and never asks which agent produced it — except the two codex-only surfaces
@@ -1 +1 @@
1
- {"version":3,"file":"agent-adapters.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/agent-adapters.ts"],"names":[],"mappings":";;;AAEA,2CAA2C;AAC3C,+DAA0D;AAC1D,mDAA+C;AAE/C;;;;GAIG;AACH,MAAa,aAAa;IACL,MAAM,GAAG,IAAI,uCAAiB,EAAE,CAAC;IACjC,KAAK,GAAG,IAAI,4BAAY,EAAE,CAAC;IAE5C,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAA,wBAAY,EAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5G,CAAC;IAED,OAAO,CAAC,OAAqB,EAAE,GAAW;QACtC,OAAO,IAAA,wBAAY,EAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACpH,CAAC;CACJ;AAXD,sCAWC","sourcesContent":["import { AgentPayload } from './agent-payload';\nimport { AgentHookEvent } from '../core/agent-event';\nimport { detectAiType } from './detect-ai';\nimport { ClaudeCodeAdapter } from './claude-code-adapter';\nimport { CodexAdapter } from './codex-adapter';\n\n/**\n * The ONE place a payload is routed to its harness's adapter. Every other module takes an\n * `AgentHookEvent` and never asks which agent produced it — except the two codex-only surfaces\n * (read parity, the shared-tree subagent guard), which check `aiType` explicitly and say so.\n */\nexport class AgentAdapters {\n private readonly claude = new ClaudeCodeAdapter();\n private readonly codex = new CodexAdapter();\n\n envelope(payload: AgentPayload): AgentHookEvent {\n return detectAiType(payload) === 'codex' ? this.codex.envelope(payload) : this.claude.envelope(payload);\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n return detectAiType(payload) === 'codex' ? this.codex.toEvent(payload, cwd) : this.claude.toEvent(payload, cwd);\n }\n}\n"]}
1
+ {"version":3,"file":"agent-adapters.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/agent-adapters.ts"],"names":[],"mappings":";;;AAEA,2CAA2C;AAC3C,+DAA0D;AAC1D,mDAA+C;AAE/C;;;;GAIG;AACH,MAAa,aAAa;IACL,MAAM,GAAG,IAAI,uCAAiB,EAAE,CAAC;IACjC,KAAK,GAAG,IAAI,4BAAY,EAAE,CAAC;IAE5C,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAA,wBAAY,EAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5G,CAAC;IAED,OAAO,CAAC,OAAqB,EAAE,GAAW;QACtC,OAAO,IAAA,wBAAY,EAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACpH,CAAC;CACJ;AAXD,sCAWC","sourcesContent":["import { AgentPayload } from './agent-payload';\nimport { AgentHookEvent } from '@webpieces/hook-runtime';\nimport { detectAiType } from './detect-ai';\nimport { ClaudeCodeAdapter } from './claude-code-adapter';\nimport { CodexAdapter } from './codex-adapter';\n\n/**\n * The ONE place a payload is routed to its harness's adapter. Every other module takes an\n * `AgentHookEvent` and never asks which agent produced it — except the two codex-only surfaces\n * (read parity, the shared-tree subagent guard), which check `aiType` explicitly and say so.\n */\nexport class AgentAdapters {\n private readonly claude = new ClaudeCodeAdapter();\n private readonly codex = new CodexAdapter();\n\n envelope(payload: AgentPayload): AgentHookEvent {\n return detectAiType(payload) === 'codex' ? this.codex.envelope(payload) : this.claude.envelope(payload);\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n return detectAiType(payload) === 'codex' ? this.codex.toEvent(payload, cwd) : this.claude.toEvent(payload, cwd);\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
- import { AgentHookEvent } from '../core/agent-event';
2
- import { HookOutcome } from './hook-outcome';
3
- export declare function denyJson(event: AgentHookEvent | null, reason: string): string;
1
+ import { AgentHookEvent, HookOutcome } from '@webpieces/hook-runtime';
2
+ export { denyJson } from '@webpieces/hook-runtime';
4
3
  export declare function denyOutcome(event: AgentHookEvent | null, reason: string, rule?: string, fault?: string): HookOutcome;
5
4
  export declare function emitDeny(event: AgentHookEvent | null, reason: string, rule?: string, fault?: string): never;
6
5
  export declare function emitAllow(): never;
@@ -27,61 +27,15 @@
27
27
  // stderr invisible to the user on Bash).
28
28
  // Refs: Claude Code GitHub issues #31592, #40380, #17356 (asymmetry "closed / not planned").
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.denyJson = denyJson;
30
+ exports.denyJson = void 0;
31
31
  exports.denyOutcome = denyOutcome;
32
32
  exports.emitDeny = emitDeny;
33
33
  exports.emitAllow = emitAllow;
34
34
  const decision_log_1 = require("../core/decision-log");
35
35
  const l0_fault_codes_1 = require("../core/l0-fault-codes");
36
- const hook_outcome_1 = require("./hook-outcome");
37
- // ANSI escape (0x1b) built at runtime so no raw ESC byte sits in source. ANSI red is a *bonus* — the
38
- // 🛑 prefix + reason stay meaningful if a future/CI renderer strips the color. One place = one escape.
39
- const ESC = String.fromCharCode(0x1b);
40
- /**
41
- * ONLY THE HEADLINE IS RED. The body is left plain, and that is a legibility decision, not an oversight.
42
- *
43
- * Every deny that reaches here is MULTI-LINE — formatReport()'s `[rule] (N violations)` / `→ why` /
44
- * `Fix Option N:` skeleton for L1 and L2, and now the same skeleton for L0. A whole page rendered in
45
- * bold red is harder to read than the paragraph it replaced: the indentation that carries the structure
46
- * stops registering when every line shouts. Red the first line so the block is unmissable in a scroll of
47
- * terminal output, then let the structure do the rest of the work.
48
- *
49
- * The reset (`[0m`) still closes the sequence on the same line it opened, so nothing leaks into the
50
- * body or into whatever the terminal prints next.
51
- */
52
- // webpieces-disable no-function-outside-class -- private helper of the PreToolUse protocol boundary below; this module must stay callable from a tree too broken to build a DI container
53
- function redSystemMessage(reason) {
54
- const nl = reason.indexOf('\n');
55
- if (nl < 0)
56
- return `${ESC}[31;1m🛑 ${reason}${ESC}[0m`;
57
- return `${ESC}[31;1m🛑 ${reason.slice(0, nl)}${ESC}[0m${reason.slice(nl)}`;
58
- }
59
- // Takes the EVENT rather than a tool-name string, because the one thing this decision needs is the
60
- // event's routing kind, and the harnesses spell their tool names differently (`Bash` vs `apply_patch`)
61
- // while agreeing on the kind. The emitted bytes are identical for both harnesses — Codex accepts the
62
- // same `permissionDecision: "deny"` + `permissionDecisionReason` + `systemMessage` fields, and rejects
63
- // nothing we emit. It does hard-reject an EMPTY `permissionDecisionReason` where Claude tolerates one,
64
- // which is why emitDeny below refuses to send one.
65
- // webpieces-disable no-function-outside-class -- the PreToolUse wire shape itself, module-scope beside emitDeny/emitAllow by design, and it must stay callable from a tree too broken to build a DI container
66
- function denyJson(event, reason) {
67
- // NEVER an empty reason, and the check lives HERE because this function owns the wire shape. Codex
68
- // hard-rejects a deny whose permissionDecisionReason is empty (Claude tolerates it and shows the
69
- // human nothing), so an empty one is not a cosmetic defect — it is a block that silently fails to
70
- // block. Every call site passes prose; this is the backstop that keeps a future one from turning a
71
- // deny into a protocol error.
72
- const safe = reason.trim() === '' ? '[ai-hooks] blocked, but the guard produced no reason — failing closed.' : reason;
73
- const hookSpecificOutput = {
74
- hookEventName: 'PreToolUse',
75
- permissionDecision: 'deny',
76
- permissionDecisionReason: safe,
77
- };
78
- // Bash only: permissionDecisionReason is NOT user-visible, so add the red systemMessage.
79
- if (event !== null && event.kind === 'Bash') {
80
- return JSON.stringify({ systemMessage: redSystemMessage(safe), hookSpecificOutput });
81
- }
82
- // Write/Edit/MultiEdit (and anything else): reason renders red natively; no systemMessage.
83
- return JSON.stringify({ hookSpecificOutput });
84
- }
36
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
37
+ var hook_runtime_2 = require("@webpieces/hook-runtime");
38
+ Object.defineProperty(exports, "denyJson", { enumerable: true, get: function () { return hook_runtime_2.denyJson; } });
85
39
  // THE DENY, AS A VALUE. `reason` is surfaced to both the user (terminal UI) and the model; the event's
86
40
  // kind selects whether the red `systemMessage` is added (Bash) or omitted (file tools) — see denyJson.
87
41
  //
@@ -104,7 +58,7 @@ function denyOutcome(event, reason, rule = '-', fault = l0_fault_codes_1.L0_FAUL
104
58
  // HUMAN would have to say so at its own site; none does today, and inventing one here would be
105
59
  // guessing at the boundary rather than at the decision.
106
60
  decision_log_1.invocationLog.finish('BLOCK_AI_CURE', rule, fault);
107
- return new hook_outcome_1.HookOutcome(denyJson(event, reason) + '\n', 0);
61
+ return new hook_runtime_1.HookOutcome((0, hook_runtime_1.denyJson)(event, reason) + '\n', 0);
108
62
  }
109
63
  // The ALLOW, as a value. No JSON — a silent exit 0 is "allow" in the PreToolUse protocol.
110
64
  //
@@ -115,18 +69,18 @@ function denyOutcome(event, reason, rule = '-', fault = l0_fault_codes_1.L0_FAUL
115
69
  // webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/denyOutcome by design, and it must stay callable from a tree too broken to build a DI container
116
70
  function allowOutcome() {
117
71
  decision_log_1.invocationLog.finish('ALLOW', '-');
118
- return new hook_outcome_1.HookOutcome('', 0);
72
+ return new hook_runtime_1.HookOutcome('', 0);
119
73
  }
120
74
  // Block the tool call and END the invocation from wherever in the pipeline we are — see HookTerminated
121
75
  // for why the terminal control flow is a throw now rather than a `process.exit` at the call site. Still
122
76
  // typed `never`: nothing after a call to this runs.
123
77
  // webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/emitAllow by design, and it must stay callable from a tree too broken to build a DI container.
124
78
  function emitDeny(event, reason, rule = '-', fault = l0_fault_codes_1.L0_FAULT_NONE) {
125
- throw new hook_outcome_1.HookTerminated(denyOutcome(event, reason, rule, fault));
79
+ throw new hook_runtime_1.HookTerminated(denyOutcome(event, reason, rule, fault));
126
80
  }
127
81
  // Allow the tool call and END the invocation. See emitDeny.
128
82
  // webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/emitDeny by design, and it must stay callable from a tree too broken to build a DI container
129
83
  function emitAllow() {
130
- throw new hook_outcome_1.HookTerminated(allowOutcome());
84
+ throw new hook_runtime_1.HookTerminated(allowOutcome());
131
85
  }
132
86
  //# sourceMappingURL=agent-response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-response.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/agent-response.ts"],"names":[],"mappings":";AAAA,qGAAqG;AACrG,2CAA2C;AAC3C,yGAAyG;AACzG,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,uGAAuG;AACvG,oDAAoD;AACpD,EAAE;AACF,oGAAoG;AACpG,oDAAoD;AACpD,EAAE;AACF,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,8GAA8G;AAC9G,EAAE;AACF,mGAAmG;AACnG,qFAAqF;AACrF,qGAAqG;AACrG,mGAAmG;AACnG,mGAAmG;A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tE,CAAC;AAED,4DAA4D;AAC5D,6MAA6M;AAC7M,SAAgB,SAAS;IACrB,MAAM,IAAI,6BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["// The single place that knows the PreToolUse decision protocol, so every deny is emitted identically\n// — and identically to the checked-in shim\n// (.claude/webpieces/ai-hook.sh, rendered by renderShim() in ../bin/shim.ts), which emits the same JSON.\n//\n// A block is signalled by `permissionDecision: \"deny\"` JSON on STDOUT with exit 0 — NOT exit 2.\n// Claude Code only parses the JSON on exit 0; exit 2 would ignore stdout and the reason would not\n// surface in the terminal UI. \"deny\" still blocks the tool, so this remains fail-closed: it is not the\n// silent-allow a bare exit 0 with no JSON would be.\n//\n// WHY the tool-conditional `systemMessage` (verified by live tests against Claude Code v2.1.x — the\n// docs are wrong here; do NOT re-derive from them):\n//\n// | deny field | Bash tool | Write/Edit/MultiEdit tool |\n// |-----------------------------------|-----------------------------------|-------------------------------|\n// | permissionDecisionReason (plain) | model sees it; USER SEES NOTHING | model + RED \"Error:\" block ok |\n// | systemMessage | ONLY user-visible field; grey | grey extra line (redundant) |\n// | systemMessage wrapped in ANSI red | RED + visible to the user (fix) | redundant 2nd red line |\n//\n// So: on a **Bash** deny we ALSO emit a top-level `systemMessage` wrapped in ANSI red (ESC[31;1m …\n// ESC[0m) — it is the only field a Bash deny shows the human, and it honors ANSI. On\n// Write/Edit/MultiEdit we add NO `systemMessage` (the reason already renders red natively — a second\n// line is just noise). `permissionDecisionReason` is always plain text (never ANSI): it's what the\n// model reads and what Write/Edit renders red. JSON.stringify serializes the ESC char as the valid\n// \\u escape, so the payload stays valid JSON — we build the ESC via String.fromCharCode(0x1b) so no\n// raw ESC (0x1b) byte ever lives in this source file. Do NOT use exit 2 (stdout JSON ignored;\n// stderr invisible to the user on Bash).\n// Refs: Claude Code GitHub issues #31592, #40380, #17356 (asymmetry \"closed / not planned\").\n\nimport { invocationLog } from '../core/decision-log';\nimport { L0_FAULT_NONE } from '../core/l0-fault-codes';\nimport { AgentHookEvent } from '../core/agent-event';\nimport { HookOutcome, HookTerminated } from './hook-outcome';\n\n// ANSI escape (0x1b) built at runtime so no raw ESC byte sits in source. ANSI red is a *bonus* — the\n// 🛑 prefix + reason stay meaningful if a future/CI renderer strips the color. One place = one escape.\nconst ESC = String.fromCharCode(0x1b);\n\n/**\n * ONLY THE HEADLINE IS RED. The body is left plain, and that is a legibility decision, not an oversight.\n *\n * Every deny that reaches here is MULTI-LINE — formatReport()'s `[rule] (N violations)` / `→ why` /\n * `Fix Option N:` skeleton for L1 and L2, and now the same skeleton for L0. A whole page rendered in\n * bold red is harder to read than the paragraph it replaced: the indentation that carries the structure\n * stops registering when every line shouts. Red the first line so the block is unmissable in a scroll of\n * terminal output, then let the structure do the rest of the work.\n *\n * The reset (`[0m`) still closes the sequence on the same line it opened, so nothing leaks into the\n * body or into whatever the terminal prints next.\n */\n// webpieces-disable no-function-outside-class -- private helper of the PreToolUse protocol boundary below; this module must stay callable from a tree too broken to build a DI container\nfunction redSystemMessage(reason: string): string {\n const nl = reason.indexOf('\\n');\n if (nl < 0) return `${ESC}[31;1m🛑 ${reason}${ESC}[0m`;\n return `${ESC}[31;1m🛑 ${reason.slice(0, nl)}${ESC}[0m${reason.slice(nl)}`;\n}\n\n// Takes the EVENT rather than a tool-name string, because the one thing this decision needs is the\n// event's routing kind, and the harnesses spell their tool names differently (`Bash` vs `apply_patch`)\n// while agreeing on the kind. The emitted bytes are identical for both harnesses — Codex accepts the\n// same `permissionDecision: \"deny\"` + `permissionDecisionReason` + `systemMessage` fields, and rejects\n// nothing we emit. It does hard-reject an EMPTY `permissionDecisionReason` where Claude tolerates one,\n// which is why emitDeny below refuses to send one.\n// webpieces-disable no-function-outside-class -- the PreToolUse wire shape itself, module-scope beside emitDeny/emitAllow by design, and it must stay callable from a tree too broken to build a DI container\nexport function denyJson(event: AgentHookEvent | null, reason: string): string {\n // NEVER an empty reason, and the check lives HERE because this function owns the wire shape. Codex\n // hard-rejects a deny whose permissionDecisionReason is empty (Claude tolerates it and shows the\n // human nothing), so an empty one is not a cosmetic defect — it is a block that silently fails to\n // block. Every call site passes prose; this is the backstop that keeps a future one from turning a\n // deny into a protocol error.\n const safe = reason.trim() === '' ? '[ai-hooks] blocked, but the guard produced no reason — failing closed.' : reason;\n const hookSpecificOutput = {\n hookEventName: 'PreToolUse',\n permissionDecision: 'deny',\n permissionDecisionReason: safe,\n };\n // Bash only: permissionDecisionReason is NOT user-visible, so add the red systemMessage.\n if (event !== null && event.kind === 'Bash') {\n return JSON.stringify({ systemMessage: redSystemMessage(safe), hookSpecificOutput });\n }\n // Write/Edit/MultiEdit (and anything else): reason renders red natively; no systemMessage.\n return JSON.stringify({ hookSpecificOutput });\n}\n\n// THE DENY, AS A VALUE. `reason` is surfaced to both the user (terminal UI) and the model; the event's\n// kind selects whether the red `systemMessage` is added (Bash) or omitted (file tools) — see denyJson.\n//\n// This is the ONE boundary every blocking path passes through, which is why the per-invocation audit\n// line is flushed HERE: the `calls/` stream carries the outcome of its own call, and the outcome is not\n// known until this point. `rule` names what blocked (or '-'), for the line's `rule=` field.\n//\n// `fault` is the L0 fault code when the block IS an L0 fault (S/C/Y — the three decided here in JS,\n// where the sh shim's own `fault=` stamp can never reach), else '-'. Stamping it at this ONE boundary is\n// what makes `grep 'fault=S'` span the whole audit trail rather than only its sh half.\n//\n// It RETURNS the outcome instead of writing it. The write and the exit belong to HookApp, which owns\n// the injected stdout/exit ports — that separation is what lets a golden test read the exact bytes a\n// composed run produces. `denyForCrash` (hook-core) needs the value rather than the throw, because it\n// is already INSIDE the catch that would swallow one.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/allowOutcome by design, and it must stay callable from a tree too broken to build a DI container.\nexport function denyOutcome(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): HookOutcome {\n // BLOCK_AI_CURE: every deny that reaches this boundary prints a cure the agent can act on — the\n // L0 faults name a command on the allowlist, and the L1/L2 guards print theirs. A deny needing a\n // HUMAN would have to say so at its own site; none does today, and inventing one here would be\n // guessing at the boundary rather than at the decision.\n invocationLog.finish('BLOCK_AI_CURE', rule, fault);\n return new HookOutcome(denyJson(event, reason) + '\\n', 0);\n}\n\n// The ALLOW, as a value. No JSON — a silent exit 0 is \"allow\" in the PreToolUse protocol.\n//\n// NOT exported, deliberately, where denyOutcome is: `denyForCrash` genuinely needs the deny in value\n// form because it is already inside the catch a throw would land in, and nothing needs the allow that\n// way. An exported one would be a second, externally-pickable spelling of \"allow\" sitting three lines\n// from `emitAllow` — precisely the shape an agent picks by accident.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/denyOutcome by design, and it must stay callable from a tree too broken to build a DI container\nfunction allowOutcome(): HookOutcome {\n invocationLog.finish('ALLOW', '-');\n return new HookOutcome('', 0);\n}\n\n// Block the tool call and END the invocation from wherever in the pipeline we are — see HookTerminated\n// for why the terminal control flow is a throw now rather than a `process.exit` at the call site. Still\n// typed `never`: nothing after a call to this runs.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/emitAllow by design, and it must stay callable from a tree too broken to build a DI container.\nexport function emitDeny(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): never {\n throw new HookTerminated(denyOutcome(event, reason, rule, fault));\n}\n\n// Allow the tool call and END the invocation. See emitDeny.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/emitDeny by design, and it must stay callable from a tree too broken to build a DI container\nexport function emitAllow(): never {\n throw new HookTerminated(allowOutcome());\n}\n"]}
1
+ {"version":3,"file":"agent-response.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/agent-response.ts"],"names":[],"mappings":";AAAA,qGAAqG;AACrG,2CAA2C;AAC3C,yGAAyG;AACzG,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,uGAAuG;AACvG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GAAuG;AACvG,wGAAwG;AACxG,oDAAoD;AACpD,2NAA2N;AAC3N,SAAgB,QAAQ,CAAC,KAA4B,EAAE,MAAc,EAAE,OAAe,GAAG,EAAE,QAAgB,8BAAa;IACpH,MAAM,IAAI,6BAAc,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,4DAA4D;AAC5D,6MAA6M;AAC7M,SAAgB,SAAS;IACrB,MAAM,IAAI,6BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["// The single place that knows the PreToolUse decision protocol, so every deny is emitted identically\n// — and identically to the checked-in shim\n// (.claude/webpieces/ai-hook.sh, rendered by renderShim() in ../bin/shim.ts), which emits the same JSON.\n//\n// A block is signalled by `permissionDecision: \"deny\"` JSON on STDOUT with exit 0 — NOT exit 2.\n// Claude Code only parses the JSON on exit 0; exit 2 would ignore stdout and the reason would not\n// surface in the terminal UI. \"deny\" still blocks the tool, so this remains fail-closed: it is not the\n// silent-allow a bare exit 0 with no JSON would be.\n//\n// WHY the tool-conditional `systemMessage` (verified by live tests against Claude Code v2.1.x — the\n// docs are wrong here; do NOT re-derive from them):\n//\n// | deny field | Bash tool | Write/Edit/MultiEdit tool |\n// |-----------------------------------|-----------------------------------|-------------------------------|\n// | permissionDecisionReason (plain) | model sees it; USER SEES NOTHING | model + RED \"Error:\" block ok |\n// | systemMessage | ONLY user-visible field; grey | grey extra line (redundant) |\n// | systemMessage wrapped in ANSI red | RED + visible to the user (fix) | redundant 2nd red line |\n//\n// So: on a **Bash** deny we ALSO emit a top-level `systemMessage` wrapped in ANSI red (ESC[31;1m …\n// ESC[0m) — it is the only field a Bash deny shows the human, and it honors ANSI. On\n// Write/Edit/MultiEdit we add NO `systemMessage` (the reason already renders red natively — a second\n// line is just noise). `permissionDecisionReason` is always plain text (never ANSI): it's what the\n// model reads and what Write/Edit renders red. JSON.stringify serializes the ESC char as the valid\n// \\u escape, so the payload stays valid JSON — we build the ESC via String.fromCharCode(0x1b) so no\n// raw ESC (0x1b) byte ever lives in this source file. Do NOT use exit 2 (stdout JSON ignored;\n// stderr invisible to the user on Bash).\n// Refs: Claude Code GitHub issues #31592, #40380, #17356 (asymmetry \"closed / not planned\").\n\nimport { invocationLog } from '../core/decision-log';\nimport { L0_FAULT_NONE } from '../core/l0-fault-codes';\nimport { AgentHookEvent, HookOutcome, HookTerminated, denyJson } from '@webpieces/hook-runtime';\nexport { denyJson } from '@webpieces/hook-runtime';\n\n// THE DENY, AS A VALUE. `reason` is surfaced to both the user (terminal UI) and the model; the event's\n// kind selects whether the red `systemMessage` is added (Bash) or omitted (file tools) — see denyJson.\n//\n// This is the ONE boundary every blocking path passes through, which is why the per-invocation audit\n// line is flushed HERE: the `calls/` stream carries the outcome of its own call, and the outcome is not\n// known until this point. `rule` names what blocked (or '-'), for the line's `rule=` field.\n//\n// `fault` is the L0 fault code when the block IS an L0 fault (S/C/Y — the three decided here in JS,\n// where the sh shim's own `fault=` stamp can never reach), else '-'. Stamping it at this ONE boundary is\n// what makes `grep 'fault=S'` span the whole audit trail rather than only its sh half.\n//\n// It RETURNS the outcome instead of writing it. The write and the exit belong to HookApp, which owns\n// the injected stdout/exit ports — that separation is what lets a golden test read the exact bytes a\n// composed run produces. `denyForCrash` (hook-core) needs the value rather than the throw, because it\n// is already INSIDE the catch that would swallow one.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/allowOutcome by design, and it must stay callable from a tree too broken to build a DI container.\nexport function denyOutcome(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): HookOutcome {\n // BLOCK_AI_CURE: every deny that reaches this boundary prints a cure the agent can act on — the\n // L0 faults name a command on the allowlist, and the L1/L2 guards print theirs. A deny needing a\n // HUMAN would have to say so at its own site; none does today, and inventing one here would be\n // guessing at the boundary rather than at the decision.\n invocationLog.finish('BLOCK_AI_CURE', rule, fault);\n return new HookOutcome(denyJson(event, reason) + '\\n', 0);\n}\n\n// The ALLOW, as a value. No JSON — a silent exit 0 is \"allow\" in the PreToolUse protocol.\n//\n// NOT exported, deliberately, where denyOutcome is: `denyForCrash` genuinely needs the deny in value\n// form because it is already inside the catch a throw would land in, and nothing needs the allow that\n// way. An exported one would be a second, externally-pickable spelling of \"allow\" sitting three lines\n// from `emitAllow` — precisely the shape an agent picks by accident.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/denyOutcome by design, and it must stay callable from a tree too broken to build a DI container\nfunction allowOutcome(): HookOutcome {\n invocationLog.finish('ALLOW', '-');\n return new HookOutcome('', 0);\n}\n\n// Block the tool call and END the invocation from wherever in the pipeline we are — see HookTerminated\n// for why the terminal control flow is a throw now rather than a `process.exit` at the call site. Still\n// typed `never`: nothing after a call to this runs.\n// webpieces-disable no-function-outside-class -- the Claude Code PreToolUse protocol boundary; module-scope beside denyJson/emitAllow by design, and it must stay callable from a tree too broken to build a DI container.\nexport function emitDeny(event: AgentHookEvent | null, reason: string, rule: string = '-', fault: string = L0_FAULT_NONE): never {\n throw new HookTerminated(denyOutcome(event, reason, rule, fault));\n}\n\n// Allow the tool call and END the invocation. See emitDeny.\n// webpieces-disable no-function-outside-class -- the PreToolUse protocol boundary, module-scope beside denyJson/emitDeny by design, and it must stay callable from a tree too broken to build a DI container\nexport function emitAllow(): never {\n throw new HookTerminated(allowOutcome());\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { AgentPayload } from './agent-payload';
2
- import { AgentHookEvent } from '../core/agent-event';
2
+ import { AgentHookEvent } from '@webpieces/hook-runtime';
3
3
  /**
4
4
  * Morphs a Claude Code PreToolUse payload into the one normalized `AgentHookEvent`.
5
5
  *
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClaudeCodeAdapter = void 0;
4
- const agent_event_1 = require("../core/agent-event");
4
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
5
5
  const types_1 = require("../core/types");
6
6
  /**
7
7
  * The Claude Code tools that enter the file/edit rule pipeline. `Read` is deliberately NOT here — it
@@ -28,7 +28,7 @@ class ClaudeCodeAdapter {
28
28
  * (which does not). This is the shape that answers that, and it cannot fail.
29
29
  */
30
30
  envelope(payload) {
31
- return new agent_event_1.AgentHookEvent('claude-code', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
31
+ return new hook_runtime_1.AgentHookEvent('claude-code', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
32
32
  }
33
33
  toEvent(payload, cwd) {
34
34
  const kind = this.kindOf(payload.tool_name);
@@ -39,7 +39,7 @@ class ClaudeCodeAdapter {
39
39
  // A file tool that named no file has nothing to judge; fall back to Ignored so the hook allows
40
40
  // it, exactly as the old `if (!input) emitAllow()` did.
41
41
  const effective = kind === 'File' && files.length === 0 ? 'Ignored' : kind;
42
- return new agent_event_1.AgentHookEvent('claude-code', effective, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
42
+ return new hook_runtime_1.AgentHookEvent('claude-code', effective, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
43
43
  }
44
44
  kindOf(toolName) {
45
45
  if (toolName === 'Bash')
@@ -55,14 +55,14 @@ class ClaudeCodeAdapter {
55
55
  if (!filePath)
56
56
  return [];
57
57
  if (toolKind === 'Write') {
58
- return [new agent_event_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit('', toolInput.content || '')]))];
58
+ return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit('', toolInput.content || '')]))];
59
59
  }
60
60
  if (toolKind === 'Edit') {
61
- return [new agent_event_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];
61
+ return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, [new types_1.NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];
62
62
  }
63
63
  const raw = Array.isArray(toolInput.edits) ? toolInput.edits : [];
64
64
  const edits = raw.map((e) => new types_1.NormalizedEdit(e.old_string || '', e.new_string || ''));
65
- return [new agent_event_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, edits))];
65
+ return [new hook_runtime_1.FileOperation(toolKind, new types_1.NormalizedToolInput(filePath, edits))];
66
66
  }
67
67
  }
68
68
  exports.ClaudeCodeAdapter = ClaudeCodeAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"claude-code-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/claude-code-adapter.ts"],"names":[],"mappings":";;;AACA,qDAAoF;AACpF,yCAAmG;AAEnG;;;GAGG;AACH,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAExF;;;;;;;;GAQG;AACH,MAAa,iBAAiB;IAC1B;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAI,4BAAc,CACrB,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,EAChE,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAC7F,EAAE,EAAE,IAAI,EAAE,EAAE,CACf,CAAC;IACN,CAAC;IAED,OAAO,CAAC,OAAqB,EAAE,GAAW;QACtC,MAAM,IAAI,GAA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EAAE,SAAyB;QAChE,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC;QACrC,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,CAAC;QACzB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,2BAAa,CAAC,QAAQ,EAAE,IAAI,2BAAmB,CAAC,QAAQ,EAAE,CAAC,IAAI,sBAAc,CAAC,EAAE,EAAE,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/H,CAAC;QACD,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,2BAAa,CAAC,QAAQ,EAAE,IAAI,2BAAmB,CAAC,QAAQ,EAAE,CAAC,IAAI,sBAAc,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,EAAE,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1J,CAAC;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAiB,EAAkB,EAAE,CAAC,IAAI,sBAAc,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;QACzH,OAAO,CAAC,IAAI,2BAAa,CAAC,QAAQ,EAAE,IAAI,2BAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;CACJ;AAtDD,8CAsDC","sourcesContent":["import { AgentPayload, AgentToolInput, AgentEditEntry } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind, FileOperation } from '../core/agent-event';\nimport { NormalizedBashInput, NormalizedEdit, NormalizedToolInput, ToolKind } from '../core/types';\n\n/**\n * The Claude Code tools that enter the file/edit rule pipeline. `Read` is deliberately NOT here — it\n * has its own fast path and only one guard may see it.\n */\nconst HANDLED_FILE_TOOLS: ReadonlySet<string> = new Set(['Write', 'Edit', 'MultiEdit']);\n\n/**\n * Morphs a Claude Code PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * This is the SAME `normalizeToolKind` / `normalizeToolInput` logic that used to live inline in\n * hook-core.ts, moved out unchanged so hook-core is written once for every harness. Claude Code is the\n * harness every developer uses today, so nothing about the mapping is allowed to move: `Write` still\n * becomes one edit of `content` against '', `Edit` one edit of `old_string`→`new_string`, `MultiEdit`\n * one per entry, and a file tool with no `file_path` still ends up allowed (kind `Ignored`).\n */\nexport class ClaudeCodeAdapter {\n /**\n * What is known from the ENVELOPE ALONE, touching nothing but `tool_name` and the identity fields.\n *\n * Not a second spelling of `toEvent` — a different question, asked at a moment when the answer to\n * the other one may not exist. `toEvent` reads `tool_input`, and a payload whose `tool_input` is\n * missing makes it throw; the crash then still has to be DENIED, and the deny still has to know\n * whether it is decorating a Bash block (which needs the red `systemMessage`) or a file block\n * (which does not). This is the shape that answers that, and it cannot fail.\n */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'claude-code', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const toolInput = payload.tool_input;\n const bash = kind === 'Bash' ? new NormalizedBashInput(toolInput.command ?? '') : null;\n const reads = kind === 'Read' ? [toolInput.file_path ?? ''] : [];\n const files = kind === 'File' ? this.fileOperations(payload.tool_name as ToolKind, toolInput) : [];\n // A file tool that named no file has nothing to judge; fall back to Ignored so the hook allows\n // it, exactly as the old `if (!input) emitAllow()` did.\n const effective: AgentEventKind = kind === 'File' && files.length === 0 ? 'Ignored' : kind;\n return new AgentHookEvent(\n 'claude-code', effective, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === 'Bash') return 'Bash';\n if (toolName === 'Read') return 'Read';\n if (HANDLED_FILE_TOOLS.has(toolName)) return 'File';\n return 'Ignored';\n }\n\n private fileOperations(toolKind: ToolKind, toolInput: AgentToolInput): readonly FileOperation[] {\n const filePath = toolInput.file_path;\n if (!filePath) return [];\n if (toolKind === 'Write') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit('', toolInput.content || '')]))];\n }\n if (toolKind === 'Edit') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];\n }\n const raw = Array.isArray(toolInput.edits) ? toolInput.edits : [];\n const edits = raw.map((e: AgentEditEntry): NormalizedEdit => new NormalizedEdit(e.old_string || '', e.new_string || ''));\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, edits))];\n }\n}\n"]}
1
+ {"version":3,"file":"claude-code-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/claude-code-adapter.ts"],"names":[],"mappings":";;;AACA,0DAAwF;AACxF,yCAAmG;AAEnG;;;GAGG;AACH,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAExF;;;;;;;;GAQG;AACH,MAAa,iBAAiB;IAC1B;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAI,6BAAc,CACrB,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,EAChE,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO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CAAC;IACnF,CAAC;CACJ;AAtDD,8CAsDC","sourcesContent":["import { AgentPayload, AgentToolInput, AgentEditEntry } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind, FileOperation } from '@webpieces/hook-runtime';\nimport { NormalizedBashInput, NormalizedEdit, NormalizedToolInput, ToolKind } from '../core/types';\n\n/**\n * The Claude Code tools that enter the file/edit rule pipeline. `Read` is deliberately NOT here — it\n * has its own fast path and only one guard may see it.\n */\nconst HANDLED_FILE_TOOLS: ReadonlySet<string> = new Set(['Write', 'Edit', 'MultiEdit']);\n\n/**\n * Morphs a Claude Code PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * This is the SAME `normalizeToolKind` / `normalizeToolInput` logic that used to live inline in\n * hook-core.ts, moved out unchanged so hook-core is written once for every harness. Claude Code is the\n * harness every developer uses today, so nothing about the mapping is allowed to move: `Write` still\n * becomes one edit of `content` against '', `Edit` one edit of `old_string`→`new_string`, `MultiEdit`\n * one per entry, and a file tool with no `file_path` still ends up allowed (kind `Ignored`).\n */\nexport class ClaudeCodeAdapter {\n /**\n * What is known from the ENVELOPE ALONE, touching nothing but `tool_name` and the identity fields.\n *\n * Not a second spelling of `toEvent` — a different question, asked at a moment when the answer to\n * the other one may not exist. `toEvent` reads `tool_input`, and a payload whose `tool_input` is\n * missing makes it throw; the crash then still has to be DENIED, and the deny still has to know\n * whether it is decorating a Bash block (which needs the red `systemMessage`) or a file block\n * (which does not). This is the shape that answers that, and it cannot fail.\n */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'claude-code', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const toolInput = payload.tool_input;\n const bash = kind === 'Bash' ? new NormalizedBashInput(toolInput.command ?? '') : null;\n const reads = kind === 'Read' ? [toolInput.file_path ?? ''] : [];\n const files = kind === 'File' ? this.fileOperations(payload.tool_name as ToolKind, toolInput) : [];\n // A file tool that named no file has nothing to judge; fall back to Ignored so the hook allows\n // it, exactly as the old `if (!input) emitAllow()` did.\n const effective: AgentEventKind = kind === 'File' && files.length === 0 ? 'Ignored' : kind;\n return new AgentHookEvent(\n 'claude-code', effective, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === 'Bash') return 'Bash';\n if (toolName === 'Read') return 'Read';\n if (HANDLED_FILE_TOOLS.has(toolName)) return 'File';\n return 'Ignored';\n }\n\n private fileOperations(toolKind: ToolKind, toolInput: AgentToolInput): readonly FileOperation[] {\n const filePath = toolInput.file_path;\n if (!filePath) return [];\n if (toolKind === 'Write') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit('', toolInput.content || '')]))];\n }\n if (toolKind === 'Edit') {\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, [new NormalizedEdit(toolInput.old_string || '', toolInput.new_string || '')]))];\n }\n const raw = Array.isArray(toolInput.edits) ? toolInput.edits : [];\n const edits = raw.map((e: AgentEditEntry): NormalizedEdit => new NormalizedEdit(e.old_string || '', e.new_string || ''));\n return [new FileOperation(toolKind, new NormalizedToolInput(filePath, edits))];\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { AgentPayload } from './agent-payload';
2
- import { AgentHookEvent } from '../core/agent-event';
2
+ import { AgentHookEvent } from '@webpieces/hook-runtime';
3
3
  /**
4
4
  * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.
5
5
  *
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CodexAdapter = void 0;
4
4
  const rules_config_1 = require("@webpieces/rules-config");
5
- const agent_event_1 = require("../core/agent-event");
5
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
6
6
  const types_1 = require("../core/types");
7
7
  const apply_patch_parse_1 = require("../core/apply-patch-parse");
8
8
  const shell_read_parity_1 = require("../core/shell-read-parity");
@@ -24,7 +24,7 @@ class CodexAdapter {
24
24
  readParity = new shell_read_parity_1.ShellReadParity();
25
25
  /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */
26
26
  envelope(payload) {
27
- return new agent_event_1.AgentHookEvent('codex', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
27
+ return new hook_runtime_1.AgentHookEvent('codex', this.kindOf(payload.tool_name), payload.tool_name, payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', [], null, []);
28
28
  }
29
29
  toEvent(payload, cwd) {
30
30
  const kind = this.kindOf(payload.tool_name);
@@ -34,7 +34,7 @@ class CodexAdapter {
34
34
  // reads run the read guard IN ADDITION to the bash guards — see ../core/shell-read-parity.ts.
35
35
  const reads = kind === 'Bash' ? this.readParity.readTargets(command, cwd, new rules_config_1.RepoRootFinder().resolveRepoRoot(cwd)) : [];
36
36
  const files = kind === 'File' ? this.patchParser.parse(command, cwd) : [];
37
- return new agent_event_1.AgentHookEvent('codex', kind, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
37
+ return new hook_runtime_1.AgentHookEvent('codex', kind, payload.tool_name, cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '', files, bash, reads);
38
38
  }
39
39
  kindOf(toolName) {
40
40
  if (toolName === CODEX_BASH)
@@ -1 +1 @@
1
- {"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-adapter.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AAGzD,qDAAqE;AACrE,yCAAoD;AACpD,iEAA6D;AAC7D,iEAA4D;AAE5D,yFAAyF;AACz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GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,IAAI,4BAAc,CACrB,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,EAChC,GAAG,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAC/E,KAAK,EAAE,IAAI,EAAE,KAAK,CACrB,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,QAAgB;QAC3B,IAAI,QAAQ,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC;QAC3C,IAAI,QAAQ,KAAK,iBAAiB;YAAE,OAAO,MAAM,CAAC;QAClD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAjCD,oCAiCC","sourcesContent":["import { RepoRootFinder } from '@webpieces/rules-config';\n\nimport { AgentPayload } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind } from '../core/agent-event';\nimport { NormalizedBashInput } from '../core/types';\nimport { ApplyPatchParser } from '../core/apply-patch-parse';\nimport { ShellReadParity } from '../core/shell-read-parity';\n\n/** Codex's shell tool. MEASURED: it reuses Claude's name — it is `Bash`, NOT `shell`. */\nconst CODEX_BASH = 'Bash';\n/** Codex's ONLY file-editing tool. One envelope, many files, mixed operations. */\nconst CODEX_APPLY_PATCH = 'apply_patch';\n\n/**\n * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * Codex exposes exactly two tools this hook has anything to say about. Everything else measured in a\n * live session — `webrun`, `collaborationspawn_agent`, `collaborationwait_agent`, `view_image`,\n * `update_plan` — and every tool not yet seen maps to `Ignored` and is allowed immediately. That\n * default is chosen on purpose: an unknown tool is one we cannot judge, and inventing a mapping for it\n * would apply file rules to bytes that are not a file edit.\n */\nexport class CodexAdapter {\n private readonly patchParser = new ApplyPatchParser();\n private readonly readParity = new ShellReadParity();\n\n /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'codex', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const command = payload.tool_input.command ?? '';\n const bash = kind === 'Bash' ? new NormalizedBashInput(command) : null;\n // Read parity: Codex has no Read tool, so a read arrives as `Bash` running a pager. Synthesized\n // reads run the read guard IN ADDITION to the bash guards — see ../core/shell-read-parity.ts.\n const reads = kind === 'Bash' ? this.readParity.readTargets(command, cwd, new RepoRootFinder().resolveRepoRoot(cwd)) : [];\n const files = kind === 'File' ? this.patchParser.parse(command, cwd) : [];\n return new AgentHookEvent(\n 'codex', kind, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === CODEX_BASH) return 'Bash';\n if (toolName === CODEX_APPLY_PATCH) return 'File';\n return 'Ignored';\n }\n}\n"]}
1
+ {"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/codex-adapter.ts"],"names":[],"mappings":";;;AAAA,0DAAyD;AAGzD,0DAAyE;AACzE,yCAAoD;AACpD,iEAA6D;AAC7D,iEAA4D;AAE5D,yFAAyF;AACzF,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,kFAAkF;AAClF,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAa,YAAY;IACJ,WAAW,GAAG,IAAI,oCAAgB,EAAE,CAAC;IACrC,UAAU,GAAG,IAAI,mCAAe,EAAE,CAAC;IAEpD,yFAAyF;IACzF,QAAQ,CAAC,OAAqB;QAC1B,OAAO,IAAI,6BAAc,CACrB,OAAO,EAAE,IAAI,CAAC,MAAM,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QAAgB;QAC3B,IAAI,QAAQ,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC;QAC3C,IAAI,QAAQ,KAAK,iBAAiB;YAAE,OAAO,MAAM,CAAC;QAClD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAjCD,oCAiCC","sourcesContent":["import { RepoRootFinder } from '@webpieces/rules-config';\n\nimport { AgentPayload } from './agent-payload';\nimport { AgentHookEvent, AgentEventKind } from '@webpieces/hook-runtime';\nimport { NormalizedBashInput } from '../core/types';\nimport { ApplyPatchParser } from '../core/apply-patch-parse';\nimport { ShellReadParity } from '../core/shell-read-parity';\n\n/** Codex's shell tool. MEASURED: it reuses Claude's name — it is `Bash`, NOT `shell`. */\nconst CODEX_BASH = 'Bash';\n/** Codex's ONLY file-editing tool. One envelope, many files, mixed operations. */\nconst CODEX_APPLY_PATCH = 'apply_patch';\n\n/**\n * Morphs a Codex PreToolUse payload into the one normalized `AgentHookEvent`.\n *\n * Codex exposes exactly two tools this hook has anything to say about. Everything else measured in a\n * live session — `webrun`, `collaborationspawn_agent`, `collaborationwait_agent`, `view_image`,\n * `update_plan` — and every tool not yet seen maps to `Ignored` and is allowed immediately. That\n * default is chosen on purpose: an unknown tool is one we cannot judge, and inventing a mapping for it\n * would apply file rules to bytes that are not a file edit.\n */\nexport class CodexAdapter {\n private readonly patchParser = new ApplyPatchParser();\n private readonly readParity = new ShellReadParity();\n\n /** See ClaudeCodeAdapter.envelope — the pre-normalization shape the crash deny needs. */\n envelope(payload: AgentPayload): AgentHookEvent {\n return new AgentHookEvent(\n 'codex', this.kindOf(payload.tool_name), payload.tool_name,\n payload.cwd ?? '', payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n [], null, [],\n );\n }\n\n toEvent(payload: AgentPayload, cwd: string): AgentHookEvent {\n const kind = this.kindOf(payload.tool_name);\n const command = payload.tool_input.command ?? '';\n const bash = kind === 'Bash' ? new NormalizedBashInput(command) : null;\n // Read parity: Codex has no Read tool, so a read arrives as `Bash` running a pager. Synthesized\n // reads run the read guard IN ADDITION to the bash guards — see ../core/shell-read-parity.ts.\n const reads = kind === 'Bash' ? this.readParity.readTargets(command, cwd, new RepoRootFinder().resolveRepoRoot(cwd)) : [];\n const files = kind === 'File' ? this.patchParser.parse(command, cwd) : [];\n return new AgentHookEvent(\n 'codex', kind, payload.tool_name,\n cwd, payload.session_id ?? '', payload.agent_id ?? '', payload.agent_type ?? '',\n files, bash, reads,\n );\n }\n\n private kindOf(toolName: string): AgentEventKind {\n if (toolName === CODEX_BASH) return 'Bash';\n if (toolName === CODEX_APPLY_PATCH) return 'File';\n return 'Ignored';\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { AgentHookEvent } from '../core/agent-event';
1
+ import { AgentHookEvent } from '@webpieces/hook-runtime';
2
2
  import { BlockedResult } from '../core/types';
3
3
  export declare const CODEX_SUBAGENT_RULE = "codex-subagent-no-write-in-shared-tree";
4
4
  /**
@@ -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,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,I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A0C,+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-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"]}
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,IAA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C,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,wGAAwG;YACxG,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 '@webpieces/hook-runtime';\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"]}
@@ -1,4 +1,4 @@
1
- import { AiType } from '../core/agent-event';
1
+ import { AiType } from '@webpieces/hook-runtime';
2
2
  /**
3
3
  * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;
4
4
  * Claude Code's has no such key. Everything else in the two envelopes is the same key names
@@ -1 +1 @@
1
- {"version":3,"file":"detect-ai.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/detect-ai.ts"],"names":[],"mappings":";;;AA2EA,oCAIC;AA7ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACU,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACU,QAAA,UAAU,GAAG;6BACG,wBAAgB,2CAA2C,CAAC;AAEzF;;;GAGG;AACH,6NAA6N;AAC7N,2MAA2M;AAC3M,SAAgB,YAAY,CAAC,OAAgB;IACzC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC;IAC1E,kIAAkI;IAClI,OAAO,SAAS,IAAK,OAAmC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;AACvF,CAAC","sourcesContent":["import { AiType } from '../core/agent-event';\n\n/**\n * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;\n * Claude Code's has no such key. Everything else in the two envelopes is the same key names\n * (`hook_event_name`, `tool_name`, `tool_input`, `cwd`, `session_id`, `transcript_path`), which is\n * exactly why one positive key is the whole test rather than a shape heuristic.\n *\n * Exported as a TWIN — an sh fragment and a JS predicate — because L0 has two halves that must\n * answer the identical question: the rendered POSIX-sh shim (which has no JSON parser and scrapes\n * text) and this binary (which has the parsed object). That is the same pattern\n * ../bin/l0-allowlist.ts already uses for `L0_ALLOW_ERE_SH` / `L0_ALLOW_JS`, and detect-ai.spec.ts\n * asserts the two agree over a corpus the same way.\n *\n * ─── THE SH HALF IS AN APPROXIMATION, AND SINCE L0 BRANCHES ON IT, HERE IS EXACTLY HOW FAR OFF ──────\n *\n * The JS half asks the precise question (`turn_id` is a key of the TOP-LEVEL envelope). The sh half has\n * no JSON parser, so it asks a structural approximation of it: after deleting all whitespace, does the\n * payload contain `{` or `,` immediately followed by `\"turn_id\":`? That is strictly narrower than the\n * bare substring test it replaced, and the tightening is not cosmetic — `bin/l0-allowlist.ts` now gates\n * an allowlist entry on this answer, so a wrong answer is a grant.\n *\n * WHAT IT CAN AND CANNOT DISTINGUISH:\n *\n * - A Claude payload MENTIONING the key in a command — `grep '\"turn_id\":' x.json` — is answered\n * `claude-code`, and not by luck: JSON escapes every `\"` inside a string value, so the bytes on the\n * wire are `\\\"turn_id\\\":`, which contains no `\"turn_id\":` at all. There is no spelling of a shell\n * command that puts the RAW token into the payload.\n * - A NESTED `turn_id` key — an MCP tool_input that happens to carry one — IS misread as `codex`.\n * This is the residual gap and sh cannot close it. Do not write a JSON parser in sh to try.\n *\n * WHY THE RESIDUAL GAP IS NOT A PRIVILEGE ESCALATION, stated as the property to preserve rather than\n * as a reassurance: the ONLY thing the harness answer gates at L0 is `L0_CODEX_ALLOW_ERE` (built from\n * `CODEX_READ_BODY_ERE` in ../bin/l0-codex-read.ts), which\n * admits nothing but a single, unredirected, unchained READ (`cat`/`head`/`tail`/`less`/`more`/`bat`,\n * or `sed -n '<range>p'`). Allowlist entry 1 — \"any Read\", with no path restriction — already grants\n * Claude Code the identical capability under every L0 fault. So a misclassification hands a Claude\n * session another SPELLING of a read it could already do, and never a capability it lacked. Anything\n * added to the aiType-gated set later must be checked against that property, because it is what makes\n * the approximation tolerable. `codex-l0-read.spec.ts` pins both halves of this.\n *\n * WHENEVER THE JS HALF IS RUNNING IT IS AUTHORITATIVE: the binary calls `detectAiType()` on the parsed\n * envelope (see `enforceCommittedShim`), so the approximation decides only faults D/X/U/K, where the\n * binary never runs at all.\n *\n * WIRED INTO THE RENDERED SHIM (`PARSE_PAYLOAD_SH` in ../bin/shim.ts), which is what makes the L0 audit\n * line's `ai=` field possible. Note the release ordering that governs the ARTIFACT rather than this\n * constant: `committedShimStale()` compares the committed `.claude/webpieces/ai-hook.sh` against\n * `renderShim()` of the INSTALLED release, so the committed shim is NOT regenerated in the same PR that\n * changes the renderer — it is regenerated after that release publishes, or by `wp-upgrade-shim`.\n */\nexport const AI_TYPE_TOKEN_SH = '\"turn_id\":';\n\n/**\n * Sets `AI` to the literal `AiType` value — `codex` or `claude-code` — from `$PAYLOAD`. The values\n * are the SAME strings the TypeScript union carries, so the twin test can compare them byte for byte\n * instead of translating between two vocabularies (translation is where twins drift).\n *\n * Two steps, and both are load-bearing:\n * 1. `tr -d` deletes every whitespace byte into `WP_AI_ENV`, so the structural test below does not\n * have to spell \"optional whitespace\" — which a POSIX `case` glob cannot express — and a\n * pretty-printed envelope is read exactly like a compact one. The stripped copy is used for THIS\n * test only; `$PAYLOAD` itself is untouched and stays the input every `sed` scrape reads.\n * 2. the glob requires `{` or `,` IMMEDIATELY before the quoted key, i.e. the structural context a\n * real JSON key has and a mention inside a value does not.\n */\nexport const AI_TYPE_SH = `WP_AI_ENV=\"$(printf '%s' \"$PAYLOAD\" | tr -d ' \\\\t\\\\n\\\\r')\"\ncase \"$WP_AI_ENV\" in *[{,]'${AI_TYPE_TOKEN_SH}'*) AI=codex ;; *) AI=claude-code ;; esac`;\n\n/**\n * JS twin of AI_TYPE_SH. Asks the precise question the sh half approximates: is `turn_id` a key of\n * the top-level envelope?\n */\n// webpieces-disable no-any-unknown -- the argument IS unparsed JSON from another process's stdout; naming a type here would assert a shape we have not yet established, which is the question this function exists to answer\n// webpieces-disable no-function-outside-class -- twin of an sh fragment in the dependency-free adapter layer; it must stay callable on a tree too broken to build a DI container, exactly like isAllowed()\nexport function detectAiType(payload: unknown): AiType {\n if (payload === null || typeof payload !== 'object') return 'claude-code';\n // webpieces-disable no-any-unknown -- narrowing the same unparsed JSON; the index signature is the widest true statement about it\n return 'turn_id' in (payload as Record<string, unknown>) ? 'codex' : 'claude-code';\n}\n"]}
1
+ {"version":3,"file":"detect-ai.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/detect-ai.ts"],"names":[],"mappings":";;;AA2EA,oCAIC;AA7ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACU,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACU,QAAA,UAAU,GAAG;6BACG,wBAAgB,2CAA2C,CAAC;AAEzF;;;GAGG;AACH,6NAA6N;AAC7N,2MAA2M;AAC3M,SAAgB,YAAY,CAAC,OAAgB;IACzC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC;IAC1E,kIAAkI;IAClI,OAAO,SAAS,IAAK,OAAmC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;AACvF,CAAC","sourcesContent":["import { AiType } from '@webpieces/hook-runtime';\n\n/**\n * THE discriminator, and the only one. Codex's PreToolUse envelope carries a REQUIRED `turn_id`;\n * Claude Code's has no such key. Everything else in the two envelopes is the same key names\n * (`hook_event_name`, `tool_name`, `tool_input`, `cwd`, `session_id`, `transcript_path`), which is\n * exactly why one positive key is the whole test rather than a shape heuristic.\n *\n * Exported as a TWIN — an sh fragment and a JS predicate — because L0 has two halves that must\n * answer the identical question: the rendered POSIX-sh shim (which has no JSON parser and scrapes\n * text) and this binary (which has the parsed object). That is the same pattern\n * ../bin/l0-allowlist.ts already uses for `L0_ALLOW_ERE_SH` / `L0_ALLOW_JS`, and detect-ai.spec.ts\n * asserts the two agree over a corpus the same way.\n *\n * ─── THE SH HALF IS AN APPROXIMATION, AND SINCE L0 BRANCHES ON IT, HERE IS EXACTLY HOW FAR OFF ──────\n *\n * The JS half asks the precise question (`turn_id` is a key of the TOP-LEVEL envelope). The sh half has\n * no JSON parser, so it asks a structural approximation of it: after deleting all whitespace, does the\n * payload contain `{` or `,` immediately followed by `\"turn_id\":`? That is strictly narrower than the\n * bare substring test it replaced, and the tightening is not cosmetic — `bin/l0-allowlist.ts` now gates\n * an allowlist entry on this answer, so a wrong answer is a grant.\n *\n * WHAT IT CAN AND CANNOT DISTINGUISH:\n *\n * - A Claude payload MENTIONING the key in a command — `grep '\"turn_id\":' x.json` — is answered\n * `claude-code`, and not by luck: JSON escapes every `\"` inside a string value, so the bytes on the\n * wire are `\\\"turn_id\\\":`, which contains no `\"turn_id\":` at all. There is no spelling of a shell\n * command that puts the RAW token into the payload.\n * - A NESTED `turn_id` key — an MCP tool_input that happens to carry one — IS misread as `codex`.\n * This is the residual gap and sh cannot close it. Do not write a JSON parser in sh to try.\n *\n * WHY THE RESIDUAL GAP IS NOT A PRIVILEGE ESCALATION, stated as the property to preserve rather than\n * as a reassurance: the ONLY thing the harness answer gates at L0 is `L0_CODEX_ALLOW_ERE` (built from\n * `CODEX_READ_BODY_ERE` in ../bin/l0-codex-read.ts), which\n * admits nothing but a single, unredirected, unchained READ (`cat`/`head`/`tail`/`less`/`more`/`bat`,\n * or `sed -n '<range>p'`). Allowlist entry 1 — \"any Read\", with no path restriction — already grants\n * Claude Code the identical capability under every L0 fault. So a misclassification hands a Claude\n * session another SPELLING of a read it could already do, and never a capability it lacked. Anything\n * added to the aiType-gated set later must be checked against that property, because it is what makes\n * the approximation tolerable. `codex-l0-read.spec.ts` pins both halves of this.\n *\n * WHENEVER THE JS HALF IS RUNNING IT IS AUTHORITATIVE: the binary calls `detectAiType()` on the parsed\n * envelope (see `enforceCommittedShim`), so the approximation decides only faults D/X/U/K, where the\n * binary never runs at all.\n *\n * WIRED INTO THE RENDERED SHIM (`PARSE_PAYLOAD_SH` in ../bin/shim.ts), which is what makes the L0 audit\n * line's `ai=` field possible. Note the release ordering that governs the ARTIFACT rather than this\n * constant: `committedShimStale()` compares the committed `.claude/webpieces/ai-hook.sh` against\n * `renderShim()` of the INSTALLED release, so the committed shim is NOT regenerated in the same PR that\n * changes the renderer — it is regenerated after that release publishes, or by `wp-upgrade-shim`.\n */\nexport const AI_TYPE_TOKEN_SH = '\"turn_id\":';\n\n/**\n * Sets `AI` to the literal `AiType` value — `codex` or `claude-code` — from `$PAYLOAD`. The values\n * are the SAME strings the TypeScript union carries, so the twin test can compare them byte for byte\n * instead of translating between two vocabularies (translation is where twins drift).\n *\n * Two steps, and both are load-bearing:\n * 1. `tr -d` deletes every whitespace byte into `WP_AI_ENV`, so the structural test below does not\n * have to spell \"optional whitespace\" — which a POSIX `case` glob cannot express — and a\n * pretty-printed envelope is read exactly like a compact one. The stripped copy is used for THIS\n * test only; `$PAYLOAD` itself is untouched and stays the input every `sed` scrape reads.\n * 2. the glob requires `{` or `,` IMMEDIATELY before the quoted key, i.e. the structural context a\n * real JSON key has and a mention inside a value does not.\n */\nexport const AI_TYPE_SH = `WP_AI_ENV=\"$(printf '%s' \"$PAYLOAD\" | tr -d ' \\\\t\\\\n\\\\r')\"\ncase \"$WP_AI_ENV\" in *[{,]'${AI_TYPE_TOKEN_SH}'*) AI=codex ;; *) AI=claude-code ;; esac`;\n\n/**\n * JS twin of AI_TYPE_SH. Asks the precise question the sh half approximates: is `turn_id` a key of\n * the top-level envelope?\n */\n// webpieces-disable no-any-unknown -- the argument IS unparsed JSON from another process's stdout; naming a type here would assert a shape we have not yet established, which is the question this function exists to answer\n// webpieces-disable no-function-outside-class -- twin of an sh fragment in the dependency-free adapter layer; it must stay callable on a tree too broken to build a DI container, exactly like isAllowed()\nexport function detectAiType(payload: unknown): AiType {\n if (payload === null || typeof payload !== 'object') return 'claude-code';\n // webpieces-disable no-any-unknown -- narrowing the same unparsed JSON; the index signature is the widest true statement about it\n return 'turn_id' in (payload as Record<string, unknown>) ? 'codex' : 'claude-code';\n}\n"]}
@@ -10,13 +10,14 @@ exports.main = main;
10
10
  // rules-hook.ts is the one HookArgs it constructs.
11
11
  require("reflect-metadata");
12
12
  const inversify_1 = require("inversify");
13
- const hook_app_1 = require("./hook-app");
14
- const hook_outcome_1 = require("./hook-outcome");
13
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
14
+ const hook_pipeline_evaluator_1 = require("./hook-pipeline-evaluator");
15
15
  // webpieces-disable no-function-outside-class -- this IS the bin's process entry point, named in package.json `exports` as ./claude-code-guards / ./claude-code-rules; a class here would be a namespace around one call and could not be the module's callable entry.
16
16
  async function main() {
17
17
  const container = new inversify_1.Container({ autobind: true });
18
- const app = container.get(hook_app_1.HookApp);
19
- await app.run(new hook_outcome_1.HookArgs('guards'));
18
+ container.bind(hook_runtime_1.HookEvaluator).to(hook_pipeline_evaluator_1.HookPipelineEvaluator);
19
+ const app = container.get(hook_runtime_1.HookApp);
20
+ await app.run(new hook_runtime_1.HookArgs('guards'));
20
21
  }
21
22
  // `.catch` and not a bare `void main()`: a container that cannot be built throws BEFORE any HookApp
22
23
  // exists, and an unhandled rejection exits non-zero — which PreToolUse reads as a non-blocking error
@@ -24,6 +25,6 @@ async function main() {
24
25
  // arrives here as a rejection too.
25
26
  if (require.main === module) {
26
27
  // webpieces-disable no-any-unknown -- a rejection value is `unknown` by construction; HookBootFailure narrows it through toError(), which is the one place that job belongs
27
- void main().catch((err) => { new hook_app_1.HookBootFailure().report(err); });
28
+ void main().catch((err) => { new hook_runtime_1.HookBootFailure().report(err); });
28
29
  }
29
30
  //# sourceMappingURL=guards-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/guards-hook.ts"],"names":[],"mappings":";;;AAcA,oBAIC;AAjBD,qGAAqG;AACrG,qEAAqE;AACrE,EAAE;AACF,mGAAmG;AACnG,6FAA6F;AAC7F,mDAAmD;AACnD,4BAA0B;AAC1B,yCAAsC;AAEtC,yCAAsD;AACtD,iDAA0C;AAE1C,uQAAuQ;AAChQ,KAAK,UAAU,IAAI;IACtB,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAO,CAAC,CAAC;IACnC,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,uBAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,oGAAoG;AACpG,qGAAqG;AACrG,wGAAwG;AACxG,mCAAmC;AACnC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,4KAA4K;IAC5K,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAQ,EAAE,GAAG,IAAI,0BAAe,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC","sourcesContent":["#!/usr/bin/env node\n// Claude Code / Codex PreToolUse adapter for the GIT/PR/BRANCH GUARDS hook (matcher Bash|Write|Edit|\n// MultiEdit|Read). Code-style validation is the separate rules hook.\n//\n// COMPOSITION ROOT, and deliberately nothing else: build the container, get the app, run it. Every\n// decision this binary makes lives behind HookApp; the only thing that distinguishes it from\n// rules-hook.ts is the one HookArgs it constructs.\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\n\nimport { HookApp, HookBootFailure } from './hook-app';\nimport { HookArgs } from './hook-outcome';\n\n// webpieces-disable no-function-outside-class -- this IS the bin's process entry point, named in package.json `exports` as ./claude-code-guards / ./claude-code-rules; a class here would be a namespace around one call and could not be the module's callable entry.\nexport async function main(): Promise<void> {\n const container = new Container({ autobind: true });\n const app = container.get(HookApp);\n await app.run(new HookArgs('guards'));\n}\n\n// `.catch` and not a bare `void main()`: a container that cannot be built throws BEFORE any HookApp\n// exists, and an unhandled rejection exits non-zero — which PreToolUse reads as a non-blocking error\n// and lets the tool call through. See HookBootFailure. `main` is async so a synchronous throw inside it\n// arrives here as a rejection too.\nif (require.main === module) {\n // webpieces-disable no-any-unknown -- a rejection value is `unknown` by construction; HookBootFailure narrows it through toError(), which is the one place that job belongs\n void main().catch((err: unknown): void => { new HookBootFailure().report(err); });\n}\n"]}
1
+ {"version":3,"file":"guards-hook.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/guards-hook.ts"],"names":[],"mappings":";;;AAcA,oBAKC;AAlBD,qGAAqG;AACrG,qEAAqE;AACrE,EAAE;AACF,mGAAmG;AACnG,6FAA6F;AAC7F,mDAAmD;AACnD,4BAA0B;AAC1B,yCAAsC;AACtC,0DAA4F;AAE5F,uEAAkE;AAElE,uQAAuQ;AAChQ,KAAK,UAAU,IAAI;IACtB,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,SAAS,CAAC,IAAI,CAAC,4BAAa,CAAC,CAAC,EAAE,CAAC,+CAAqB,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,sBAAO,CAAC,CAAC;IACnC,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,uBAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,oGAAoG;AACpG,qGAAqG;AACrG,wGAAwG;AACxG,mCAAmC;AACnC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC1B,4KAA4K;IAC5K,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAQ,EAAE,GAAG,IAAI,8BAAe,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC","sourcesContent":["#!/usr/bin/env node\n// Claude Code / Codex PreToolUse adapter for the GIT/PR/BRANCH GUARDS hook (matcher Bash|Write|Edit|\n// MultiEdit|Read). Code-style validation is the separate rules hook.\n//\n// COMPOSITION ROOT, and deliberately nothing else: build the container, get the app, run it. Every\n// decision this binary makes lives behind HookApp; the only thing that distinguishes it from\n// rules-hook.ts is the one HookArgs it constructs.\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { HookApp, HookArgs, HookBootFailure, HookEvaluator } from '@webpieces/hook-runtime';\n\nimport { HookPipelineEvaluator } from './hook-pipeline-evaluator';\n\n// webpieces-disable no-function-outside-class -- this IS the bin's process entry point, named in package.json `exports` as ./claude-code-guards / ./claude-code-rules; a class here would be a namespace around one call and could not be the module's callable entry.\nexport async function main(): Promise<void> {\n const container = new Container({ autobind: true });\n container.bind(HookEvaluator).to(HookPipelineEvaluator);\n const app = container.get(HookApp);\n await app.run(new HookArgs('guards'));\n}\n\n// `.catch` and not a bare `void main()`: a container that cannot be built throws BEFORE any HookApp\n// exists, and an unhandled rejection exits non-zero — which PreToolUse reads as a non-blocking error\n// and lets the tool call through. See HookBootFailure. `main` is async so a synchronous throw inside it\n// arrives here as a rejection too.\nif (require.main === module) {\n // webpieces-disable no-any-unknown -- a rejection value is `unknown` by construction; HookBootFailure narrows it through toError(), which is the one place that job belongs\n void main().catch((err: unknown): void => { new HookBootFailure().report(err); });\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { HookMode } from '../core/types';
2
- import { AiType } from '../core/agent-event';
3
- import { HookOutcome } from './hook-outcome';
2
+ import { AiType } from '@webpieces/hook-runtime';
3
+ import { HookOutcome } from '@webpieces/hook-runtime';
4
4
  export type { HookMode };
5
5
  export type ShimStaleDecision = 'allow-cure' | 'pass' | 'deny';
6
6
  export declare function shimStaleRecoveryDecision(toolName: string, command: string, filePath: string, aiType: AiType): ShimStaleDecision;
@@ -14,7 +14,7 @@ const rules_config_1 = require("@webpieces/rules-config");
14
14
  const types_1 = require("../core/types");
15
15
  const to_error_1 = require("../core/to-error");
16
16
  const agent_response_1 = require("./agent-response");
17
- const hook_outcome_1 = require("./hook-outcome");
17
+ const hook_runtime_1 = require("@webpieces/hook-runtime");
18
18
  const agent_payload_1 = require("./agent-payload");
19
19
  const agent_adapters_1 = require("./agent-adapters");
20
20
  const detect_ai_1 = require("./detect-ai");
@@ -320,7 +320,7 @@ function runPipeline(raw, mode) {
320
320
  // The pipeline's own terminal control flow, not a failure: emitAllow/emitDeny threw the answer
321
321
  // out to here from wherever they were called. Treating it as a crash would turn every allow
322
322
  // into a deny, so this branch comes FIRST and returns the carried outcome verbatim.
323
- if (error instanceof hook_outcome_1.HookTerminated)
323
+ if (error instanceof hook_runtime_1.HookTerminated)
324
324
  return error.outcome;
325
325
  return denyForCrash(error, event);
326
326
  }