@webpieces/ai-hook-rules 0.4.834 → 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"hook-outcome.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/hook-outcome.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,MAAa,WAAW;IACX,MAAM,CAAS;IACf,QAAQ,CAAS;IAE1B,YAAY,MAAc,EAAE,QAAgB;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AARD,kCAQC;AAED;;;;;GAKG;AACH,MAAa,QAAQ;IACR,IAAI,CAAW;IAExB,YAAY,IAAc;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAND,4BAMC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,cAAe,SAAQ,KAAK;IAC5B,OAAO,CAAc;IAE9B,YAAY,OAAoB;QAC5B,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ;AAPD,wCAOC","sourcesContent":["import { HookMode } from '../core/types';\n\n/**\n * What ONE hook invocation decided, as a value instead of as two side effects.\n *\n * Data class per CLAUDE.md rule 1 — fields only. `stdout` is the EXACT bytes to write (a deny's JSON\n * plus its trailing newline, or '' for an allow, because a silent exit 0 IS the allow) and `exitCode`\n * is the last byte of the PreToolUse contract. Making the decision a value is what lets a test assert\n * the composed pipeline's output without a process to inspect.\n */\nexport class HookOutcome {\n readonly stdout: string;\n readonly exitCode: number;\n\n constructor(stdout: string, exitCode: number) {\n this.stdout = stdout;\n this.exitCode = exitCode;\n }\n}\n\n/**\n * The arguments one hook binary is invoked with. Today that is only WHICH category of rules to run —\n * `guards` for the git/PR/branch guards, `rules` for the code-style rules — but it is a class rather\n * than a bare string so a second argument is an added field and not a changed signature at every call\n * site. Data class per CLAUDE.md rule 1.\n */\nexport class HookArgs {\n readonly mode: HookMode;\n\n constructor(mode: HookMode) {\n this.mode = mode;\n }\n}\n\n/**\n * THE HOOK'S TERMINAL CONTROL FLOW, as a throw.\n *\n * `emitAllow()` / `emitDeny()` are reached from a dozen places nested several frames deep inside the\n * pipeline, and every one of them means \"this invocation is over, here is its answer\". They used to\n * say that by writing to stdout and terminating the process on the spot, which is precisely what\n * made the composed pipeline untestable — the answer never became a value anybody could look at.\n *\n * Throwing carries the same \"nothing after this line runs\" guarantee (both helpers are still typed\n * `never`) while turning the answer into a HookOutcome that `HookApp` writes and exits with. The\n * ORDER of observable effects is unchanged: the audit line is still flushed at the emit site, the\n * bytes are still written before the exit, and the exit still happens at the same point, through the\n * injected HookProcessExit port, in production.\n *\n * The ONE thing this shape requires: any `catch` between an emit site and HookApp must RETHROW it\n * rather than treat it as a crash. There is exactly one such catch (the fail-closed boundary in\n * hook-core's `runPipeline`), and it returns the carried outcome.\n */\nexport class HookTerminated extends Error {\n readonly outcome: HookOutcome;\n\n constructor(outcome: HookOutcome) {\n super('hook invocation terminated');\n this.outcome = outcome;\n }\n}\n"]}
@@ -1,57 +0,0 @@
1
- /**
2
- * THE THREE PROCESS COUPLINGS OF THE HOOK — as injectable seams.
3
- *
4
- * Why they exist at all: the hook's real contract is a PIPELINE — `stdin -> parse -> adapter -> runner
5
- * -> emit -> exit` — and until this file existed there was no way to drive that pipeline from a test.
6
- * `runMain` read `process.stdin` itself and the emit boundary called `process.stdout.write` /
7
- * `process.exit` directly, so the only testable units were the pure functions UNDERNEATH the pipeline.
8
- * Tests therefore sat too low: they moved every time the composition was refactored (the AgentHookEvent
9
- * refactor rewrote `agent-response.spec.ts`'s call sites wholesale) and they proved nothing about the
10
- * composed bytes.
11
- *
12
- * The boundary is cut JUST ABOVE THE INJECTION POINT: production is
13
- * `new Container({autobind:true}).get(HookApp).run(new HookArgs('guards'))`, and a test builds the same
14
- * container with these three classes rebound to doubles. That is the whole difference between the two.
15
- * NOT a spawned process (too high — slow, and nothing can be substituted), NOT the pure helpers
16
- * underneath (too low — they move under every refactor).
17
- *
18
- * THREE, and no more. The rule engine, the adapters, the filesystem and git are NEVER substituted —
19
- * substituting any of them would leave the golden tests asserting the shape of the test harness rather
20
- * than the shape of the pipeline, which is the failure mode this whole seam exists to escape.
21
- *
22
- * They also stay OFF the L0 recovery path. `src/bin/install-entry.ts` and `src/bin/shim.ts` import
23
- * nothing but `fs`/`path` on purpose, so a corrupt `node_modules` still yields a clean fault code
24
- * instead of a crash; an inversify import reachable from either would turn a diagnosable fault into an
25
- * opaque one. The container lives in the two hook entry points and HookApp, and nowhere else.
26
- *
27
- * CLASSES, not interfaces, and that is the DI convention winning over the "behavior is an interface"
28
- * rule: this repo injects BY TYPE and forbids `Symbol()` DI tokens (`no-symbol-di-tokens`), and an
29
- * interface is not a runtime value, so it cannot BE the token. A test double therefore `extends` the
30
- * port and overrides the one method. See CLAUDE.md section 5.
31
- */
32
- export declare class HookStdinSource {
33
- /**
34
- * The PreToolUse payload, byte for byte as the harness wrote it.
35
- *
36
- * Moved here verbatim from `hook-core.readStdin()` — same encoding, same three listeners, same
37
- * "resolve('') on error or on a TTY" behaviour, so an empty read still means "nothing to judge"
38
- * and never a hang.
39
- */
40
- read(): Promise<string>;
41
- }
42
- export declare class HookStdoutSink {
43
- /**
44
- * The PreToolUse decision bytes. A deny is JSON + '\n' on STDOUT; an allow writes NOTHING — the
45
- * protocol reads a silent exit 0 as "allow". See agent-response.ts for the wire shape itself.
46
- */
47
- write(bytes: string): void;
48
- }
49
- export declare class HookProcessExit {
50
- /**
51
- * The hook's exit code IS the Claude Code PreToolUse protocol: exit 0 + JSON on stdout is a deny,
52
- * silent exit 0 is an allow, and exit 2 would make Claude ignore stdout entirely. So the exit is
53
- * not incidental plumbing to be tidied away — it is the last byte of the contract, which is
54
- * exactly why it is a port and not a bare call.
55
- */
56
- exit(code: number): void;
57
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HookProcessExit = exports.HookStdoutSink = exports.HookStdinSource = void 0;
4
- const tslib_1 = require("tslib");
5
- const inversify_1 = require("inversify");
6
- /**
7
- * THE THREE PROCESS COUPLINGS OF THE HOOK — as injectable seams.
8
- *
9
- * Why they exist at all: the hook's real contract is a PIPELINE — `stdin -> parse -> adapter -> runner
10
- * -> emit -> exit` — and until this file existed there was no way to drive that pipeline from a test.
11
- * `runMain` read `process.stdin` itself and the emit boundary called `process.stdout.write` /
12
- * `process.exit` directly, so the only testable units were the pure functions UNDERNEATH the pipeline.
13
- * Tests therefore sat too low: they moved every time the composition was refactored (the AgentHookEvent
14
- * refactor rewrote `agent-response.spec.ts`'s call sites wholesale) and they proved nothing about the
15
- * composed bytes.
16
- *
17
- * The boundary is cut JUST ABOVE THE INJECTION POINT: production is
18
- * `new Container({autobind:true}).get(HookApp).run(new HookArgs('guards'))`, and a test builds the same
19
- * container with these three classes rebound to doubles. That is the whole difference between the two.
20
- * NOT a spawned process (too high — slow, and nothing can be substituted), NOT the pure helpers
21
- * underneath (too low — they move under every refactor).
22
- *
23
- * THREE, and no more. The rule engine, the adapters, the filesystem and git are NEVER substituted —
24
- * substituting any of them would leave the golden tests asserting the shape of the test harness rather
25
- * than the shape of the pipeline, which is the failure mode this whole seam exists to escape.
26
- *
27
- * They also stay OFF the L0 recovery path. `src/bin/install-entry.ts` and `src/bin/shim.ts` import
28
- * nothing but `fs`/`path` on purpose, so a corrupt `node_modules` still yields a clean fault code
29
- * instead of a crash; an inversify import reachable from either would turn a diagnosable fault into an
30
- * opaque one. The container lives in the two hook entry points and HookApp, and nowhere else.
31
- *
32
- * CLASSES, not interfaces, and that is the DI convention winning over the "behavior is an interface"
33
- * rule: this repo injects BY TYPE and forbids `Symbol()` DI tokens (`no-symbol-di-tokens`), and an
34
- * interface is not a runtime value, so it cannot BE the token. A test double therefore `extends` the
35
- * port and overrides the one method. See CLAUDE.md section 5.
36
- */
37
- let HookStdinSource = class HookStdinSource {
38
- /**
39
- * The PreToolUse payload, byte for byte as the harness wrote it.
40
- *
41
- * Moved here verbatim from `hook-core.readStdin()` — same encoding, same three listeners, same
42
- * "resolve('') on error or on a TTY" behaviour, so an empty read still means "nothing to judge"
43
- * and never a hang.
44
- */
45
- read() {
46
- return new Promise((resolve) => {
47
- let data = '';
48
- process.stdin.setEncoding('utf8');
49
- process.stdin.on('data', (chunk) => { data += chunk; });
50
- process.stdin.on('end', () => { resolve(data); });
51
- process.stdin.on('error', () => { resolve(''); });
52
- if (process.stdin.isTTY)
53
- resolve('');
54
- });
55
- }
56
- };
57
- exports.HookStdinSource = HookStdinSource;
58
- exports.HookStdinSource = HookStdinSource = tslib_1.__decorate([
59
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
60
- ], HookStdinSource);
61
- let HookStdoutSink = class HookStdoutSink {
62
- /**
63
- * The PreToolUse decision bytes. A deny is JSON + '\n' on STDOUT; an allow writes NOTHING — the
64
- * protocol reads a silent exit 0 as "allow". See agent-response.ts for the wire shape itself.
65
- */
66
- write(bytes) {
67
- process.stdout.write(bytes);
68
- }
69
- };
70
- exports.HookStdoutSink = HookStdoutSink;
71
- exports.HookStdoutSink = HookStdoutSink = tslib_1.__decorate([
72
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
73
- ], HookStdoutSink);
74
- let HookProcessExit = class HookProcessExit {
75
- /**
76
- * The hook's exit code IS the Claude Code PreToolUse protocol: exit 0 + JSON on stdout is a deny,
77
- * silent exit 0 is an allow, and exit 2 would make Claude ignore stdout entirely. So the exit is
78
- * not incidental plumbing to be tidied away — it is the last byte of the contract, which is
79
- * exactly why it is a port and not a bare call.
80
- */
81
- exit(code) {
82
- // webpieces-disable no-process-exit-outside-main -- hook exit-code IS the Claude Code PreToolUse protocol (exit 0 + JSON = the contract); this class is the designated terminal boundary, injected so a test can record the code instead of killing the worker.
83
- process.exit(code);
84
- }
85
- };
86
- exports.HookProcessExit = HookProcessExit;
87
- exports.HookProcessExit = HookProcessExit = tslib_1.__decorate([
88
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
89
- ], HookProcessExit);
90
- //# sourceMappingURL=hook-ports.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hook-ports.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/hook-ports.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB;;;;;;OAMG;IACH,IAAI;QACA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAgC,EAAE,EAAE;YACpD,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAChE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK;gBAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAlBY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,eAAe,CAkB3B;AAGM,IAAM,cAAc,GAApB,MAAM,cAAc;IACvB;;;OAGG;IACH,KAAK,CAAC,KAAa;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACJ,CAAA;AARY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,cAAc,CAQ1B;AAGM,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB;;;;;OAKG;IACH,IAAI,CAAC,IAAY;QACb,gQAAgQ;QAChQ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;CACJ,CAAA;AAXY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,eAAe,CAW3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * THE THREE PROCESS COUPLINGS OF THE HOOK — as injectable seams.\n *\n * Why they exist at all: the hook's real contract is a PIPELINE — `stdin -> parse -> adapter -> runner\n * -> emit -> exit` — and until this file existed there was no way to drive that pipeline from a test.\n * `runMain` read `process.stdin` itself and the emit boundary called `process.stdout.write` /\n * `process.exit` directly, so the only testable units were the pure functions UNDERNEATH the pipeline.\n * Tests therefore sat too low: they moved every time the composition was refactored (the AgentHookEvent\n * refactor rewrote `agent-response.spec.ts`'s call sites wholesale) and they proved nothing about the\n * composed bytes.\n *\n * The boundary is cut JUST ABOVE THE INJECTION POINT: production is\n * `new Container({autobind:true}).get(HookApp).run(new HookArgs('guards'))`, and a test builds the same\n * container with these three classes rebound to doubles. That is the whole difference between the two.\n * NOT a spawned process (too high — slow, and nothing can be substituted), NOT the pure helpers\n * underneath (too low — they move under every refactor).\n *\n * THREE, and no more. The rule engine, the adapters, the filesystem and git are NEVER substituted —\n * substituting any of them would leave the golden tests asserting the shape of the test harness rather\n * than the shape of the pipeline, which is the failure mode this whole seam exists to escape.\n *\n * They also stay OFF the L0 recovery path. `src/bin/install-entry.ts` and `src/bin/shim.ts` import\n * nothing but `fs`/`path` on purpose, so a corrupt `node_modules` still yields a clean fault code\n * instead of a crash; an inversify import reachable from either would turn a diagnosable fault into an\n * opaque one. The container lives in the two hook entry points and HookApp, and nowhere else.\n *\n * CLASSES, not interfaces, and that is the DI convention winning over the \"behavior is an interface\"\n * rule: this repo injects BY TYPE and forbids `Symbol()` DI tokens (`no-symbol-di-tokens`), and an\n * interface is not a runtime value, so it cannot BE the token. A test double therefore `extends` the\n * port and overrides the one method. See CLAUDE.md section 5.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HookStdinSource {\n /**\n * The PreToolUse payload, byte for byte as the harness wrote it.\n *\n * Moved here verbatim from `hook-core.readStdin()` — same encoding, same three listeners, same\n * \"resolve('') on error or on a TTY\" behaviour, so an empty read still means \"nothing to judge\"\n * and never a hang.\n */\n read(): Promise<string> {\n return new Promise((resolve: (value: string) => void) => {\n let data = '';\n process.stdin.setEncoding('utf8');\n process.stdin.on('data', (chunk: string) => { data += chunk; });\n process.stdin.on('end', () => { resolve(data); });\n process.stdin.on('error', () => { resolve(''); });\n if (process.stdin.isTTY) resolve('');\n });\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class HookStdoutSink {\n /**\n * The PreToolUse decision bytes. A deny is JSON + '\\n' on STDOUT; an allow writes NOTHING — the\n * protocol reads a silent exit 0 as \"allow\". See agent-response.ts for the wire shape itself.\n */\n write(bytes: string): void {\n process.stdout.write(bytes);\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class HookProcessExit {\n /**\n * The hook's exit code IS the Claude Code PreToolUse protocol: exit 0 + JSON on stdout is a deny,\n * silent exit 0 is an allow, and exit 2 would make Claude ignore stdout entirely. So the exit is\n * not incidental plumbing to be tidied away — it is the last byte of the contract, which is\n * exactly why it is a port and not a bare call.\n */\n exit(code: number): void {\n // webpieces-disable no-process-exit-outside-main -- hook exit-code IS the Claude Code PreToolUse protocol (exit 0 + JSON = the contract); this class is the designated terminal boundary, injected so a test can record the code instead of killing the worker.\n process.exit(code);\n }\n}\n"]}
@@ -1,81 +0,0 @@
1
- import { ToolKind, NormalizedToolInput, NormalizedBashInput } from './types';
2
- /**
3
- * WHICH coding agent produced this hook call. The ONE discriminator that decides it lives in
4
- * ../adapters/detect-ai.ts (`turn_id` present ⇒ codex) and nowhere else.
5
- *
6
- * Every codex-only surface — the apply_patch parser, shell read-parity, the shared-tree subagent
7
- * guard — is gated on this field, so a Claude Code call can never reach any of them. That is not a
8
- * nicety: Claude Code is the harness every developer uses today and its behaviour must not move.
9
- */
10
- export type AiType = 'claude-code' | 'codex';
11
- /**
12
- * The `AiType` union AS DATA, so the audit-log vocabulary is rendered from the type rather than retyped
13
- * beside it. Adding a harness means adding it here and getting the log field's documented value set for
14
- * free — the same reason `SHIM_LOG_FAULTS` is built from `L0_SH_FAULT_CODES` rather than retyped.
15
- */
16
- export declare const AI_TYPES: readonly AiType[];
17
- /**
18
- * What a log row shows when NOTHING established the harness: a row written by a release older than the
19
- * `ai=` field, or a writer reached before any payload was parsed (the openclaw plugin, a library
20
- * consumer, a spec).
21
- *
22
- * It is a REAL VALUE, not a compatibility shim and not an absence. `ai=unknown` is greppable and
23
- * countable; an omitted field is neither, and "no `ai=`" would be indistinguishable from "this reader is
24
- * looking at the wrong column".
25
- */
26
- export declare const AI_TYPE_UNKNOWN = "unknown";
27
- /**
28
- * How the hook ROUTES this call. It is deliberately NOT `ToolKind`.
29
- *
30
- * The plan sketched the field as `ToolKind | 'Bash' | 'Ignored'`, and that shape cannot express the
31
- * measured Codex reality: ONE `apply_patch` envelope carries MANY files with MIXED operations (an
32
- * Add, an Update and a Delete in a single call). A single event-level `ToolKind` would have to pick
33
- * one of them and lie about the rest. So the per-file kind moved down onto `FileOperation`, where
34
- * there is one per file, and the event keeps only the routing question:
35
- *
36
- * - 'File' → run the file/edit pipeline over `files` (one entry for Claude, N for Codex).
37
- * - 'Bash' → run the bash guards over `bash`. `reads` may ALSO be populated on a Codex call
38
- * whose command is read-shaped (see ../core/shell-read-parity.ts).
39
- * - 'Read' → the read fast path over `reads`.
40
- * - 'Ignored' → nothing to judge; allow immediately.
41
- */
42
- export type AgentEventKind = 'File' | 'Bash' | 'Read' | 'Ignored';
43
- /**
44
- * ONE file touched by ONE operation, with the kind that operation is.
45
- *
46
- * `toolKind` is per-FILE precisely because `apply_patch` mixes operations inside one call; see
47
- * AgentEventKind's header for why this is not carried on the event.
48
- */
49
- export declare class FileOperation {
50
- readonly toolKind: ToolKind;
51
- readonly input: NormalizedToolInput;
52
- constructor(toolKind: ToolKind, input: NormalizedToolInput);
53
- }
54
- /**
55
- * The ONE normalized shape every harness's PreToolUse payload is morphed into, so the hook body,
56
- * the guards and the audit log are written once rather than once per agent.
57
- *
58
- * A data class per CLAUDE.md rule 1: fields only, explicit constructor, no business logic. The
59
- * morphing lives in the adapters (../adapters/claude-code-adapter.ts, ../adapters/codex-adapter.ts).
60
- */
61
- export declare class AgentHookEvent {
62
- readonly aiType: AiType;
63
- readonly kind: AgentEventKind;
64
- /** The harness's own tool name — 'Edit', 'apply_patch', 'Bash'. Carried for logs, never switched on. */
65
- readonly rawToolName: string;
66
- readonly cwd: string;
67
- readonly sessionId: string;
68
- /**
69
- * MEASURED, and identical in both harnesses: empty ⇒ the coordinator, populated ⇒ a subagent.
70
- * Used to NAME a log writer, and by the Codex shared-tree guard to know it is talking to a
71
- * subagent. Never to decide WHICH TREE a call acts on — that is measured from the path.
72
- */
73
- readonly agentId: string;
74
- readonly agentType: string;
75
- /** Claude: exactly 0 or 1. Codex `apply_patch`: N, with mixed kinds. */
76
- readonly files: readonly FileOperation[];
77
- readonly bash: NormalizedBashInput | null;
78
- /** Read targets. Claude: the `Read` tool's file. Codex: read-parity synthesis, else empty. */
79
- readonly reads: readonly string[];
80
- constructor(aiType: AiType, kind: AgentEventKind, rawToolName: string, cwd: string, sessionId: string, agentId: string, agentType: string, files: readonly FileOperation[], bash: NormalizedBashInput | null, reads: readonly string[]);
81
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentHookEvent = exports.FileOperation = exports.AI_TYPE_UNKNOWN = exports.AI_TYPES = void 0;
4
- /**
5
- * The `AiType` union AS DATA, so the audit-log vocabulary is rendered from the type rather than retyped
6
- * beside it. Adding a harness means adding it here and getting the log field's documented value set for
7
- * free — the same reason `SHIM_LOG_FAULTS` is built from `L0_SH_FAULT_CODES` rather than retyped.
8
- */
9
- exports.AI_TYPES = ['claude-code', 'codex'];
10
- /**
11
- * What a log row shows when NOTHING established the harness: a row written by a release older than the
12
- * `ai=` field, or a writer reached before any payload was parsed (the openclaw plugin, a library
13
- * consumer, a spec).
14
- *
15
- * It is a REAL VALUE, not a compatibility shim and not an absence. `ai=unknown` is greppable and
16
- * countable; an omitted field is neither, and "no `ai=`" would be indistinguishable from "this reader is
17
- * looking at the wrong column".
18
- */
19
- exports.AI_TYPE_UNKNOWN = 'unknown';
20
- /**
21
- * ONE file touched by ONE operation, with the kind that operation is.
22
- *
23
- * `toolKind` is per-FILE precisely because `apply_patch` mixes operations inside one call; see
24
- * AgentEventKind's header for why this is not carried on the event.
25
- */
26
- class FileOperation {
27
- toolKind;
28
- input;
29
- constructor(toolKind, input) {
30
- this.toolKind = toolKind;
31
- this.input = input;
32
- }
33
- }
34
- exports.FileOperation = FileOperation;
35
- /**
36
- * The ONE normalized shape every harness's PreToolUse payload is morphed into, so the hook body,
37
- * the guards and the audit log are written once rather than once per agent.
38
- *
39
- * A data class per CLAUDE.md rule 1: fields only, explicit constructor, no business logic. The
40
- * morphing lives in the adapters (../adapters/claude-code-adapter.ts, ../adapters/codex-adapter.ts).
41
- */
42
- class AgentHookEvent {
43
- aiType;
44
- kind;
45
- /** The harness's own tool name — 'Edit', 'apply_patch', 'Bash'. Carried for logs, never switched on. */
46
- rawToolName;
47
- cwd;
48
- sessionId;
49
- /**
50
- * MEASURED, and identical in both harnesses: empty ⇒ the coordinator, populated ⇒ a subagent.
51
- * Used to NAME a log writer, and by the Codex shared-tree guard to know it is talking to a
52
- * subagent. Never to decide WHICH TREE a call acts on — that is measured from the path.
53
- */
54
- agentId;
55
- agentType;
56
- /** Claude: exactly 0 or 1. Codex `apply_patch`: N, with mixed kinds. */
57
- files;
58
- bash;
59
- /** Read targets. Claude: the `Read` tool's file. Codex: read-parity synthesis, else empty. */
60
- reads;
61
- constructor(aiType, kind, rawToolName, cwd, sessionId, agentId, agentType, files, bash, reads) {
62
- this.aiType = aiType;
63
- this.kind = kind;
64
- this.rawToolName = rawToolName;
65
- this.cwd = cwd;
66
- this.sessionId = sessionId;
67
- this.agentId = agentId;
68
- this.agentType = agentType;
69
- this.files = files;
70
- this.bash = bash;
71
- this.reads = reads;
72
- }
73
- }
74
- exports.AgentHookEvent = AgentHookEvent;
75
- //# sourceMappingURL=agent-event.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-event.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/agent-event.ts"],"names":[],"mappings":";;;AAYA;;;;GAIG;AACU,QAAA,QAAQ,GAAsB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAEpE;;;;;;;;GAQG;AACU,QAAA,eAAe,GAAG,SAAS,CAAC;AAmBzC;;;;;GAKG;AACH,MAAa,aAAa;IACb,QAAQ,CAAW;IACnB,KAAK,CAAsB;IAEpC,YAAY,QAAkB,EAAE,KAA0B;QACtD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AARD,sCAQC;AAED;;;;;;GAMG;AACH,MAAa,cAAc;IACd,MAAM,CAAS;IACf,IAAI,CAAiB;IAC9B,wGAAwG;IAC/F,WAAW,CAAS;IACpB,GAAG,CAAS;IACZ,SAAS,CAAS;IAC3B;;;;OAIG;IACM,OAAO,CAAS;IAChB,SAAS,CAAS;IAC3B,wEAAwE;IAC/D,KAAK,CAA2B;IAChC,IAAI,CAA6B;IAC1C,8FAA8F;IACrF,KAAK,CAAoB;IAElC,YACI,MAAc,EACd,IAAoB,EACpB,WAAmB,EACnB,GAAW,EACX,SAAiB,EACjB,OAAe,EACf,SAAiB,EACjB,KAA+B,EAC/B,IAAgC,EAChC,KAAwB;QAExB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AA3CD,wCA2CC","sourcesContent":["import { ToolKind, NormalizedToolInput, NormalizedBashInput } from './types';\n\n/**\n * WHICH coding agent produced this hook call. The ONE discriminator that decides it lives in\n * ../adapters/detect-ai.ts (`turn_id` present ⇒ codex) and nowhere else.\n *\n * Every codex-only surface — the apply_patch parser, shell read-parity, the shared-tree subagent\n * guard — is gated on this field, so a Claude Code call can never reach any of them. That is not a\n * nicety: Claude Code is the harness every developer uses today and its behaviour must not move.\n */\nexport type AiType = 'claude-code' | 'codex';\n\n/**\n * The `AiType` union AS DATA, so the audit-log vocabulary is rendered from the type rather than retyped\n * beside it. Adding a harness means adding it here and getting the log field's documented value set for\n * free — the same reason `SHIM_LOG_FAULTS` is built from `L0_SH_FAULT_CODES` rather than retyped.\n */\nexport const AI_TYPES: readonly AiType[] = ['claude-code', 'codex'];\n\n/**\n * What a log row shows when NOTHING established the harness: a row written by a release older than the\n * `ai=` field, or a writer reached before any payload was parsed (the openclaw plugin, a library\n * consumer, a spec).\n *\n * It is a REAL VALUE, not a compatibility shim and not an absence. `ai=unknown` is greppable and\n * countable; an omitted field is neither, and \"no `ai=`\" would be indistinguishable from \"this reader is\n * looking at the wrong column\".\n */\nexport const AI_TYPE_UNKNOWN = 'unknown';\n\n/**\n * How the hook ROUTES this call. It is deliberately NOT `ToolKind`.\n *\n * The plan sketched the field as `ToolKind | 'Bash' | 'Ignored'`, and that shape cannot express the\n * measured Codex reality: ONE `apply_patch` envelope carries MANY files with MIXED operations (an\n * Add, an Update and a Delete in a single call). A single event-level `ToolKind` would have to pick\n * one of them and lie about the rest. So the per-file kind moved down onto `FileOperation`, where\n * there is one per file, and the event keeps only the routing question:\n *\n * - 'File' → run the file/edit pipeline over `files` (one entry for Claude, N for Codex).\n * - 'Bash' → run the bash guards over `bash`. `reads` may ALSO be populated on a Codex call\n * whose command is read-shaped (see ../core/shell-read-parity.ts).\n * - 'Read' → the read fast path over `reads`.\n * - 'Ignored' → nothing to judge; allow immediately.\n */\nexport type AgentEventKind = 'File' | 'Bash' | 'Read' | 'Ignored';\n\n/**\n * ONE file touched by ONE operation, with the kind that operation is.\n *\n * `toolKind` is per-FILE precisely because `apply_patch` mixes operations inside one call; see\n * AgentEventKind's header for why this is not carried on the event.\n */\nexport class FileOperation {\n readonly toolKind: ToolKind;\n readonly input: NormalizedToolInput;\n\n constructor(toolKind: ToolKind, input: NormalizedToolInput) {\n this.toolKind = toolKind;\n this.input = input;\n }\n}\n\n/**\n * The ONE normalized shape every harness's PreToolUse payload is morphed into, so the hook body,\n * the guards and the audit log are written once rather than once per agent.\n *\n * A data class per CLAUDE.md rule 1: fields only, explicit constructor, no business logic. The\n * morphing lives in the adapters (../adapters/claude-code-adapter.ts, ../adapters/codex-adapter.ts).\n */\nexport class AgentHookEvent {\n readonly aiType: AiType;\n readonly kind: AgentEventKind;\n /** The harness's own tool name — 'Edit', 'apply_patch', 'Bash'. Carried for logs, never switched on. */\n readonly rawToolName: string;\n readonly cwd: string;\n readonly sessionId: string;\n /**\n * MEASURED, and identical in both harnesses: empty ⇒ the coordinator, populated ⇒ a subagent.\n * Used to NAME a log writer, and by the Codex shared-tree guard to know it is talking to a\n * subagent. Never to decide WHICH TREE a call acts on — that is measured from the path.\n */\n readonly agentId: string;\n readonly agentType: string;\n /** Claude: exactly 0 or 1. Codex `apply_patch`: N, with mixed kinds. */\n readonly files: readonly FileOperation[];\n readonly bash: NormalizedBashInput | null;\n /** Read targets. Claude: the `Read` tool's file. Codex: read-parity synthesis, else empty. */\n readonly reads: readonly string[];\n\n constructor(\n aiType: AiType,\n kind: AgentEventKind,\n rawToolName: string,\n cwd: string,\n sessionId: string,\n agentId: string,\n agentType: string,\n files: readonly FileOperation[],\n bash: NormalizedBashInput | null,\n reads: readonly string[],\n ) {\n this.aiType = aiType;\n this.kind = kind;\n this.rawToolName = rawToolName;\n this.cwd = cwd;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.files = files;\n this.bash = bash;\n this.reads = reads;\n }\n}\n"]}