harness-reflex 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +266 -2
- package/USER_GUIDE.md +639 -0
- package/dist/adapters/agy.d.ts +8 -0
- package/dist/adapters/agy.js +80 -0
- package/dist/adapters/agy.js.map +1 -0
- package/dist/adapters/claude.d.ts +13 -0
- package/dist/adapters/claude.js +46 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +139 -0
- package/dist/adapters/codex.js +368 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/backend/defaults.d.ts +31 -0
- package/dist/backend/defaults.js +32 -0
- package/dist/backend/defaults.js.map +1 -0
- package/dist/backend/factory.d.ts +11 -0
- package/dist/backend/factory.js +40 -0
- package/dist/backend/factory.js.map +1 -0
- package/dist/backend/jev.d.ts +524 -0
- package/dist/backend/jev.js +1486 -0
- package/dist/backend/jev.js.map +1 -0
- package/dist/backend/mock.d.ts +26 -0
- package/dist/backend/mock.js +320 -0
- package/dist/backend/mock.js.map +1 -0
- package/dist/backend/route-prompt.d.ts +37 -0
- package/dist/backend/route-prompt.js +42 -0
- package/dist/backend/route-prompt.js.map +1 -0
- package/dist/backend/simple-jev.d.ts +35 -0
- package/dist/backend/simple-jev.js +273 -0
- package/dist/backend/simple-jev.js.map +1 -0
- package/dist/backend/types.d.ts +270 -0
- package/dist/backend/types.js +5 -0
- package/dist/backend/types.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +278 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/calibrate.d.ts +56 -0
- package/dist/core/calibrate.js +144 -0
- package/dist/core/calibrate.js.map +1 -0
- package/dist/core/closing.d.ts +90 -0
- package/dist/core/closing.js +111 -0
- package/dist/core/closing.js.map +1 -0
- package/dist/core/evidence.d.ts +119 -0
- package/dist/core/evidence.js +209 -0
- package/dist/core/evidence.js.map +1 -0
- package/dist/core/gate.d.ts +25 -0
- package/dist/core/gate.js +114 -0
- package/dist/core/gate.js.map +1 -0
- package/dist/core/judge.d.ts +221 -0
- package/dist/core/judge.js +251 -0
- package/dist/core/judge.js.map +1 -0
- package/dist/core/ledger.d.ts +67 -0
- package/dist/core/ledger.js +173 -0
- package/dist/core/ledger.js.map +1 -0
- package/dist/core/orchestrate-closing.d.ts +237 -0
- package/dist/core/orchestrate-closing.js +250 -0
- package/dist/core/orchestrate-closing.js.map +1 -0
- package/dist/core/orchestrate-correction.d.ts +209 -0
- package/dist/core/orchestrate-correction.js +141 -0
- package/dist/core/orchestrate-correction.js.map +1 -0
- package/dist/core/orchestrate-host.d.ts +225 -0
- package/dist/core/orchestrate-host.js +80 -0
- package/dist/core/orchestrate-host.js.map +1 -0
- package/dist/core/orchestrate-stagnation.d.ts +259 -0
- package/dist/core/orchestrate-stagnation.js +270 -0
- package/dist/core/orchestrate-stagnation.js.map +1 -0
- package/dist/core/orchestrate.d.ts +357 -0
- package/dist/core/orchestrate.js +418 -0
- package/dist/core/orchestrate.js.map +1 -0
- package/dist/core/policy.d.ts +122 -0
- package/dist/core/policy.js +102 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/prune-plan.d.ts +141 -0
- package/dist/core/prune-plan.js +390 -0
- package/dist/core/prune-plan.js.map +1 -0
- package/dist/core/prune.d.ts +30 -0
- package/dist/core/prune.js +73 -0
- package/dist/core/prune.js.map +1 -0
- package/dist/core/route.d.ts +35 -0
- package/dist/core/route.js +39 -0
- package/dist/core/route.js.map +1 -0
- package/dist/core/score.d.ts +40 -0
- package/dist/core/score.js +49 -0
- package/dist/core/score.js.map +1 -0
- package/dist/core/screen.d.ts +22 -0
- package/dist/core/screen.js +117 -0
- package/dist/core/screen.js.map +1 -0
- package/dist/core/stagnation.d.ts +23 -0
- package/dist/core/stagnation.js +93 -0
- package/dist/core/stagnation.js.map +1 -0
- package/dist/core/text.d.ts +36 -0
- package/dist/core/text.js +66 -0
- package/dist/core/text.js.map +1 -0
- package/dist/hook/cli.d.ts +9 -0
- package/dist/hook/cli.js +52 -0
- package/dist/hook/cli.js.map +1 -0
- package/dist/hook/contract.d.ts +125 -0
- package/dist/hook/contract.js +159 -0
- package/dist/hook/contract.js.map +1 -0
- package/dist/hook/decision.d.ts +97 -0
- package/dist/hook/decision.js +955 -0
- package/dist/hook/decision.js.map +1 -0
- package/dist/hook/memory-store.d.ts +81 -0
- package/dist/hook/memory-store.js +157 -0
- package/dist/hook/memory-store.js.map +1 -0
- package/dist/hook/payload.d.ts +55 -0
- package/dist/hook/payload.js +129 -0
- package/dist/hook/payload.js.map +1 -0
- package/dist/hook/run.d.ts +48 -0
- package/dist/hook/run.js +218 -0
- package/dist/hook/run.js.map +1 -0
- package/dist/hook/store-port.d.ts +72 -0
- package/dist/hook/store-port.js +2 -0
- package/dist/hook/store-port.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +12 -0
- package/dist/mcp/server.js +368 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/ports/audit.d.ts +18 -0
- package/dist/ports/audit.js +11 -0
- package/dist/ports/audit.js.map +1 -0
- package/dist/ports/clock.d.ts +14 -0
- package/dist/ports/clock.js +11 -0
- package/dist/ports/clock.js.map +1 -0
- package/dist/ports/decision.d.ts +75 -0
- package/dist/ports/decision.js +2 -0
- package/dist/ports/decision.js.map +1 -0
- package/dist/ports/index.d.ts +14 -0
- package/dist/ports/index.js +2 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/log.d.ts +22 -0
- package/dist/ports/log.js +12 -0
- package/dist/ports/log.js.map +1 -0
- package/dist/ports/state.d.ts +46 -0
- package/dist/ports/state.js +13 -0
- package/dist/ports/state.js.map +1 -0
- package/dist/state/clock.d.ts +40 -0
- package/dist/state/clock.js +43 -0
- package/dist/state/clock.js.map +1 -0
- package/dist/state/file-store.d.ts +340 -0
- package/dist/state/file-store.js +849 -0
- package/dist/state/file-store.js.map +1 -0
- package/dist/state/paths.d.ts +41 -0
- package/dist/state/paths.js +73 -0
- package/dist/state/paths.js.map +1 -0
- package/docs/USER_GUIDE.en.md +721 -0
- package/docs/claude-code.md +281 -0
- package/docs/design/v0.2.0-harness-plugins.md +381 -0
- package/docs/design/v0.3.0-orchestration-unification.md +580 -0
- package/docs/dsh-plugin.md +578 -0
- package/docs/reflex-ui-regression-2026-10-20.md +34 -0
- package/docs/release-checklist-v0.1.0.md +315 -0
- package/docs/release-handbook-porting-notes.md +106 -0
- package/docs/release-handbook.md +393 -0
- package/docs/release-notes-v0.1.0.md +63 -0
- package/docs/release-notes-v0.3.0.md +152 -0
- package/docs/research/claude-code-harness.md +607 -0
- package/docs/research/pi-harness.md +621 -0
- package/experiments/data/calibration_sample.json +14 -0
- package/experiments/index.ts +29 -0
- package/experiments/runner.ts +156 -0
- package/package.json +82 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { DecisionLedger } from './ledger.js';
|
|
2
|
+
/** Cap on the steps one verdict may look at. */
|
|
3
|
+
const MAX_HISTORY = 30;
|
|
4
|
+
/**
|
|
5
|
+
* Merge caller-supplied steps in front of the steps this detector recorded.
|
|
6
|
+
*
|
|
7
|
+
* The result is chronological, capped to the last {@link MAX_HISTORY} entries,
|
|
8
|
+
* and copy-safe: the detector never retains the caller's array or objects.
|
|
9
|
+
*
|
|
10
|
+
* @param external - steps the caller observed, oldest first, when supplied.
|
|
11
|
+
* @param own - steps this detector recorded in this activation.
|
|
12
|
+
* @returns the merged, capped history.
|
|
13
|
+
*/
|
|
14
|
+
function mergeHistory(external, own) {
|
|
15
|
+
if (external === undefined || external.length === 0)
|
|
16
|
+
return [...own];
|
|
17
|
+
const merged = [...external.map((step) => ({ ...step })), ...own];
|
|
18
|
+
return merged.length > MAX_HISTORY ? merged.slice(merged.length - MAX_HISTORY) : merged;
|
|
19
|
+
}
|
|
20
|
+
export class StagnationDetector {
|
|
21
|
+
backend;
|
|
22
|
+
ledger;
|
|
23
|
+
history = [];
|
|
24
|
+
consecutiveAlerts = 0;
|
|
25
|
+
constructor(backend, ledger) {
|
|
26
|
+
this.backend = backend;
|
|
27
|
+
this.ledger = ledger || DecisionLedger.getInstance();
|
|
28
|
+
}
|
|
29
|
+
recordAction(step) {
|
|
30
|
+
this.history.push({
|
|
31
|
+
...step,
|
|
32
|
+
timestamp: step.timestamp || Date.now()
|
|
33
|
+
});
|
|
34
|
+
// Keep max 30 recent steps
|
|
35
|
+
if (this.history.length > MAX_HISTORY) {
|
|
36
|
+
this.history.shift();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Judge the merged action history for a stagnation pattern.
|
|
41
|
+
*
|
|
42
|
+
* @param goal - current overall goal, when the caller knows it.
|
|
43
|
+
* @param history - steps the caller observed that this detector never
|
|
44
|
+
* recorded itself (a resumed session, a foreign agent, a run this
|
|
45
|
+
* activation did not live through). They are treated as *earlier* than the
|
|
46
|
+
* steps recorded here, so the merged tail is what the window sees.
|
|
47
|
+
* @returns the stagnation verdict and corrective suggestion.
|
|
48
|
+
*/
|
|
49
|
+
async check(goal, history) {
|
|
50
|
+
const merged = mergeHistory(history, this.history);
|
|
51
|
+
if (merged.length < 3) {
|
|
52
|
+
return {
|
|
53
|
+
isStuck: false,
|
|
54
|
+
confidence: 1.0,
|
|
55
|
+
diagnosis: 'Action count below stagnation threshold (< 3).',
|
|
56
|
+
latencyMs: 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const req = {
|
|
60
|
+
history: merged,
|
|
61
|
+
goal,
|
|
62
|
+
windowSize: 6
|
|
63
|
+
};
|
|
64
|
+
const res = await this.backend.checkStagnation(req);
|
|
65
|
+
if (res.isStuck) {
|
|
66
|
+
this.consecutiveAlerts++;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.consecutiveAlerts = 0;
|
|
70
|
+
}
|
|
71
|
+
this.ledger.record({
|
|
72
|
+
type: 'stagnation',
|
|
73
|
+
backend: this.backend.name,
|
|
74
|
+
latencyMs: res.latencyMs,
|
|
75
|
+
isStuck: res.isStuck,
|
|
76
|
+
details: {
|
|
77
|
+
patternType: res.patternType,
|
|
78
|
+
historyLength: this.history.length,
|
|
79
|
+
consecutiveAlerts: this.consecutiveAlerts,
|
|
80
|
+
diagnosis: res.diagnosis
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
getHistory() {
|
|
86
|
+
return [...this.history];
|
|
87
|
+
}
|
|
88
|
+
clear() {
|
|
89
|
+
this.history = [];
|
|
90
|
+
this.consecutiveAlerts = 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=stagnation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stagnation.js","sourceRoot":"","sources":["../../src/core/stagnation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,gDAAgD;AAChD,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;;;;;;;GASG;AACH,SAAS,YAAY,CAAC,QAA2C,EAAE,GAA0B;IAC3F,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1F,CAAC;AAED,MAAM,OAAO,kBAAkB;IACrB,O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AC,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACjB,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YAC1B,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,OAAO,EAAE;gBACP,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;gBAClC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gBACzC,SAAS,EAAE,GAAG,CAAC,SAAS;aACzB;SACF,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {\n DecisionBackend,\n ActionStep,\n StagnationCheckRequest,\n StagnationCheckResponse\n} from '../backend/types.js';\nimport { DecisionLedger } from './ledger.js';\n\n/** Cap on the steps one verdict may look at. */\nconst MAX_HISTORY = 30;\n\n/**\n * Merge caller-supplied steps in front of the steps this detector recorded.\n *\n * The result is chronological, capped to the last {@link MAX_HISTORY} entries,\n * and copy-safe: the detector never retains the caller's array or objects.\n *\n * @param external - steps the caller observed, oldest first, when supplied.\n * @param own - steps this detector recorded in this activation.\n * @returns the merged, capped history.\n */\nfunction mergeHistory(external: readonly ActionStep[] | undefined, own: readonly ActionStep[]): ActionStep[] {\n if (external === undefined || external.length === 0) return [...own];\n const merged = [...external.map((step) => ({ ...step })), ...own];\n return merged.length > MAX_HISTORY ? merged.slice(merged.length - MAX_HISTORY) : merged;\n}\n\nexport class StagnationDetector {\n private backend: DecisionBackend;\n private ledger: DecisionLedger;\n private history: ActionStep[] = [];\n private consecutiveAlerts = 0;\n\n constructor(backend: DecisionBackend, ledger?: DecisionLedger) {\n this.backend = backend;\n this.ledger = ledger || DecisionLedger.getInstance();\n }\n\n recordAction(step: ActionStep): void {\n this.history.push({\n ...step,\n timestamp: step.timestamp || Date.now()\n });\n // Keep max 30 recent steps\n if (this.history.length > MAX_HISTORY) {\n this.history.shift();\n }\n }\n\n /**\n * Judge the merged action history for a stagnation pattern.\n *\n * @param goal - current overall goal, when the caller knows it.\n * @param history - steps the caller observed that this detector never\n * recorded itself (a resumed session, a foreign agent, a run this\n * activation did not live through). They are treated as *earlier* than the\n * steps recorded here, so the merged tail is what the window sees.\n * @returns the stagnation verdict and corrective suggestion.\n */\n async check(goal?: string, history?: readonly ActionStep[]): Promise<StagnationCheckResponse> {\n const merged = mergeHistory(history, this.history);\n if (merged.length < 3) {\n return {\n isStuck: false,\n confidence: 1.0,\n diagnosis: 'Action count below stagnation threshold (< 3).',\n latencyMs: 0\n };\n }\n\n const req: StagnationCheckRequest = {\n history: merged,\n goal,\n windowSize: 6\n };\n\n const res = await this.backend.checkStagnation(req);\n\n if (res.isStuck) {\n this.consecutiveAlerts++;\n } else {\n this.consecutiveAlerts = 0;\n }\n\n this.ledger.record({\n type: 'stagnation',\n backend: this.backend.name,\n latencyMs: res.latencyMs,\n isStuck: res.isStuck,\n details: {\n patternType: res.patternType,\n historyLength: this.history.length,\n consecutiveAlerts: this.consecutiveAlerts,\n diagnosis: res.diagnosis\n }\n });\n\n return res;\n }\n\n getHistory(): ActionStep[] {\n return [...this.history];\n }\n\n clear(): void {\n this.history = [];\n this.consecutiveAlerts = 0;\n }\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** One content block as the decision surface sees it: a tag and optional text. */
|
|
2
|
+
export interface TextBlockLike {
|
|
3
|
+
readonly type?: string;
|
|
4
|
+
readonly text?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Bound one text to a character budget, marking the cut.
|
|
8
|
+
* @param text - any text.
|
|
9
|
+
* @param max - maximum characters to keep.
|
|
10
|
+
* @returns the bounded text.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clip(text: string, max: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Tokens one text costs, at the ledger's shared four-characters-per-token rate.
|
|
15
|
+
* @param text - any text.
|
|
16
|
+
* @returns the estimated token count.
|
|
17
|
+
*/
|
|
18
|
+
export declare function estimateTokens(text: string): number;
|
|
19
|
+
/**
|
|
20
|
+
* Stable short digest of one value, used as a payload or call identity.
|
|
21
|
+
* @param value - the text to digest.
|
|
22
|
+
* @returns sixteen hexadecimal characters.
|
|
23
|
+
*/
|
|
24
|
+
export declare function digestOf(value: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Concatenate the text blocks of one content list.
|
|
27
|
+
* @param content - message or result content.
|
|
28
|
+
* @returns the text, in block order.
|
|
29
|
+
*/
|
|
30
|
+
export declare function textOfContent(content: readonly TextBlockLike[] | undefined): string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether one content list carries at least one text block.
|
|
33
|
+
* @param content - message or result content.
|
|
34
|
+
* @returns whether there is text to rewrite.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasTextBlock(content: readonly TextBlockLike[] | undefined): boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text helpers shared by the intervention decision core.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is host-agnostic: the unit of work is a string, an estimated
|
|
5
|
+
* token count, or a structural content block. No host message type, no session,
|
|
6
|
+
* no tool-execution type is imported or assumed.
|
|
7
|
+
*
|
|
8
|
+
* @module core/text
|
|
9
|
+
*/
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
/**
|
|
12
|
+
* Bound one text to a character budget, marking the cut.
|
|
13
|
+
* @param text - any text.
|
|
14
|
+
* @param max - maximum characters to keep.
|
|
15
|
+
* @returns the bounded text.
|
|
16
|
+
*/
|
|
17
|
+
export function clip(text, max) {
|
|
18
|
+
return text.length <= max ? text : `${text.slice(0, max)}…`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Tokens one text costs, at the ledger's shared four-characters-per-token rate.
|
|
22
|
+
* @param text - any text.
|
|
23
|
+
* @returns the estimated token count.
|
|
24
|
+
*/
|
|
25
|
+
export function estimateTokens(text) {
|
|
26
|
+
return text.length === 0 ? 0 : Math.ceil(text.length / 4);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Stable short digest of one value, used as a payload or call identity.
|
|
30
|
+
* @param value - the text to digest.
|
|
31
|
+
* @returns sixteen hexadecimal characters.
|
|
32
|
+
*/
|
|
33
|
+
export function digestOf(value) {
|
|
34
|
+
return createHash('sha256').update(value).digest('hex').slice(0, 16);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Concatenate the text blocks of one content list.
|
|
38
|
+
* @param content - message or result content.
|
|
39
|
+
* @returns the text, in block order.
|
|
40
|
+
*/
|
|
41
|
+
export function textOfContent(content) {
|
|
42
|
+
if (!content)
|
|
43
|
+
return '';
|
|
44
|
+
const parts = [];
|
|
45
|
+
for (const block of content) {
|
|
46
|
+
if (block && typeof block === 'object' && block.type === 'text') {
|
|
47
|
+
parts.push(block.text ?? '');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return parts.join('\n');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether one content list carries at least one text block.
|
|
54
|
+
* @param content - message or result content.
|
|
55
|
+
* @returns whether there is text to rewrite.
|
|
56
|
+
*/
|
|
57
|
+
export function hasTextBlock(content) {
|
|
58
|
+
if (!content)
|
|
59
|
+
return false;
|
|
60
|
+
for (const block of content) {
|
|
61
|
+
if (block && typeof block === 'object' && block.type === 'text')
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AIG;AACH,MAAM,UAAU,YAAY,CAAC,OAA6C;IACxE,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;IAC/E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Text helpers shared by the intervention decision core.\n *\n * Everything here is host-agnostic: the unit of work is a string, an estimated\n * token count, or a structural content block. No host message type, no session,\n * no tool-execution type is imported or assumed.\n *\n * @module core/text\n */\nimport { createHash } from 'node:crypto';\n\n/** One content block as the decision surface sees it: a tag and optional text. */\nexport interface TextBlockLike {\n readonly type?: string;\n readonly text?: string;\n}\n\n/**\n * Bound one text to a character budget, marking the cut.\n * @param text - any text.\n * @param max - maximum characters to keep.\n * @returns the bounded text.\n */\nexport function clip(text: string, max: number): string {\n return text.length <= max ? text : `${text.slice(0, max)}…`;\n}\n\n/**\n * Tokens one text costs, at the ledger's shared four-characters-per-token rate.\n * @param text - any text.\n * @returns the estimated token count.\n */\nexport function estimateTokens(text: string): number {\n return text.length === 0 ? 0 : Math.ceil(text.length / 4);\n}\n\n/**\n * Stable short digest of one value, used as a payload or call identity.\n * @param value - the text to digest.\n * @returns sixteen hexadecimal characters.\n */\nexport function digestOf(value: string): string {\n return createHash('sha256').update(value).digest('hex').slice(0, 16);\n}\n\n/**\n * Concatenate the text blocks of one content list.\n * @param content - message or result content.\n * @returns the text, in block order.\n */\nexport function textOfContent(content: readonly TextBlockLike[] | undefined): string {\n if (!content) return '';\n const parts: string[] = [];\n for (const block of content) {\n if (block && typeof block === 'object' && block.type === 'text') {\n parts.push(block.text ?? '');\n }\n }\n return parts.join('\\n');\n}\n\n/**\n * Whether one content list carries at least one text block.\n * @param content - message or result content.\n * @returns whether there is text to rewrite.\n */\nexport function hasTextBlock(content: readonly TextBlockLike[] | undefined): boolean {\n if (!content) return false;\n for (const block of content) {\n if (block && typeof block === 'object' && block.type === 'text') return true;\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the `hook` subcommand and exit.
|
|
3
|
+
*
|
|
4
|
+
* `stdout` receives exactly one JSON object (or nothing when the platform is
|
|
5
|
+
* refused). A termination signal writes `{}` and exits 0 so an interrupted hook
|
|
6
|
+
* is indistinguishable from an allow, never from a veto.
|
|
7
|
+
* @param argv - arguments after `hook`; the first is the event name.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runHookCli(argv: string[]): Promise<void>;
|
package/dist/hook/cli.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The process-shaped wrapper around {@link runHook}.
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists because the command is spawned per event: install the
|
|
5
|
+
* signal path that fails open, write exactly one JSON object to stdout, and
|
|
6
|
+
* flush it before exiting. The decision itself lives in `run.ts` and stays
|
|
7
|
+
* unit-testable without a process.
|
|
8
|
+
*
|
|
9
|
+
* @module hook/cli
|
|
10
|
+
*/
|
|
11
|
+
import { runHook } from './run.js';
|
|
12
|
+
/**
|
|
13
|
+
* Run the `hook` subcommand and exit.
|
|
14
|
+
*
|
|
15
|
+
* `stdout` receives exactly one JSON object (or nothing when the platform is
|
|
16
|
+
* refused). A termination signal writes `{}` and exits 0 so an interrupted hook
|
|
17
|
+
* is indistinguishable from an allow, never from a veto.
|
|
18
|
+
* @param argv - arguments after `hook`; the first is the event name.
|
|
19
|
+
*/
|
|
20
|
+
export async function runHookCli(argv) {
|
|
21
|
+
let finished = false;
|
|
22
|
+
const finish = (payload, code) => {
|
|
23
|
+
if (finished)
|
|
24
|
+
return;
|
|
25
|
+
finished = true;
|
|
26
|
+
if (payload.length === 0) {
|
|
27
|
+
process.exit(code);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
process.stdout.write(payload, () => process.exit(code));
|
|
31
|
+
};
|
|
32
|
+
const onSignal = () => finish('{}\n', 0);
|
|
33
|
+
process.once('SIGTERM', onSignal);
|
|
34
|
+
process.once('SIGINT', onSignal);
|
|
35
|
+
try {
|
|
36
|
+
const result = await runHook(argv[0]);
|
|
37
|
+
if (result.output === null)
|
|
38
|
+
finish('', result.code);
|
|
39
|
+
else
|
|
40
|
+
finish(`${JSON.stringify(result.output)}\n`, result.code);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
// runHook itself never throws, but a broken stdout must still fail open.
|
|
44
|
+
process.stderr.write(`harness-reflex hook: ${error.message}\n`);
|
|
45
|
+
finish('{}\n', 0);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
process.removeListener('SIGTERM', onSignal);
|
|
49
|
+
process.removeListener('SIGINT', onSignal);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/hook/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAc;IAC7C,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,IAAY,EAAQ,EAAE;QACrD,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAChB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,OAAO;QACT,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC;IACF,MAAM,QAAQ,GAAG,GAAS,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;YAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;;YAC/C,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yEAAyE;QACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAyB,KAAe,CAAC,OAAO,IAAI,CAAC,CAAC;QAC3E,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC5C,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC","sourcesContent":["/**\n * The process-shaped wrapper around {@link runHook}.\n *\n * Everything here exists because the command is spawned per event: install the\n * signal path that fails open, write exactly one JSON object to stdout, and\n * flush it before exiting. The decision itself lives in `run.ts` and stays\n * unit-testable without a process.\n *\n * @module hook/cli\n */\nimport { runHook } from './run.js';\n\n/**\n * Run the `hook` subcommand and exit.\n *\n * `stdout` receives exactly one JSON object (or nothing when the platform is\n * refused). A termination signal writes `{}` and exits 0 so an interrupted hook\n * is indistinguishable from an allow, never from a veto.\n * @param argv - arguments after `hook`; the first is the event name.\n */\nexport async function runHookCli(argv: string[]): Promise<void> {\n let finished = false;\n const finish = (payload: string, code: number): void => {\n if (finished) return;\n finished = true;\n if (payload.length === 0) {\n process.exit(code);\n return;\n }\n process.stdout.write(payload, () => process.exit(code));\n };\n const onSignal = (): void => finish('{}\\n', 0);\n process.once('SIGTERM', onSignal);\n process.once('SIGINT', onSignal);\n try {\n const result = await runHook(argv[0]);\n if (result.output === null) finish('', result.code);\n else finish(`${JSON.stringify(result.output)}\\n`, result.code);\n } catch (error) {\n // runHook itself never throws, but a broken stdout must still fail open.\n process.stderr.write(`harness-reflex hook: ${(error as Error).message}\\n`);\n finish('{}\\n', 0);\n } finally {\n process.removeListener('SIGTERM', onSignal);\n process.removeListener('SIGINT', onSignal);\n }\n}\n"]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `harness-reflex hook <event>` wire contract.
|
|
3
|
+
*
|
|
4
|
+
* One table, one source of truth: the event aliases a harness may invoke, the
|
|
5
|
+
* stdin shape this implementation reads, the stdout shape it may emit, and the
|
|
6
|
+
* per-event decision budget. The command only ever writes the JSON shape named
|
|
7
|
+
* here, because the host splices stdout into model-visible text and treats any
|
|
8
|
+
* non-JSON byte as a reason.
|
|
9
|
+
*
|
|
10
|
+
* @module hook/contract
|
|
11
|
+
*/
|
|
12
|
+
/** The events the hook accepts (design §2.5). */
|
|
13
|
+
export declare const HOOK_EVENTS: readonly ["pretooluse", "posttooluse", "postfailure", "stop", "substop", "sessionstart", "sessionend"];
|
|
14
|
+
/** One accepted hook event. */
|
|
15
|
+
export type HookEvent = (typeof HOOK_EVENTS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Events a host emits that this runtime has no capability for.
|
|
18
|
+
*
|
|
19
|
+
* Codex 0.163.0 fires twelve hook events (`hooks/src/engine/command_runner.rs`).
|
|
20
|
+
* Five of them describe something the decision runtime deliberately does not
|
|
21
|
+
* decide — the prompt is already submitted, the permission is already being
|
|
22
|
+
* asked, the compaction is already happening. They are still *recognized* so a
|
|
23
|
+
* wiring mistake is a silent `{}` instead of a stderr warning on every turn, but
|
|
24
|
+
* they can never produce a decision: `HookDecision.handle` never sees them.
|
|
25
|
+
*
|
|
26
|
+
* This is a separate type from {@link HookEvent} on purpose. Widening `HookEvent`
|
|
27
|
+
* would force every existing `switch` over it to grow a branch, which is exactly
|
|
28
|
+
* the kind of behavior change this adapter is not allowed to make.
|
|
29
|
+
*/
|
|
30
|
+
export declare const CODEX_ONLY_HOOK_EVENTS: readonly ["userpromptsubmit", "permissionrequest", "precompact", "postcompact", "subagentstart", "interrupt"];
|
|
31
|
+
/** One host event that is recognized but carries no reflex capability. */
|
|
32
|
+
export type CodexOnlyHookEvent = (typeof CODEX_ONLY_HOOK_EVENTS)[number];
|
|
33
|
+
/** What one raw event argument resolved to. */
|
|
34
|
+
export type ParsedHookEventName = {
|
|
35
|
+
kind: 'canonical';
|
|
36
|
+
event: HookEvent;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'codex-only';
|
|
39
|
+
event: CodexOnlyHookEvent;
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'unknown';
|
|
42
|
+
};
|
|
43
|
+
/** The three-state mode every capability shares. */
|
|
44
|
+
export type HookMode = 'off' | 'observe' | 'active';
|
|
45
|
+
/** Per-event decision budget and the host-side timeout it must stay inside. */
|
|
46
|
+
export interface EventBudget {
|
|
47
|
+
/** Internal decision budget; on expiry the hook fails open. */
|
|
48
|
+
budgetMs: number;
|
|
49
|
+
/** The host's own timeout, kept for documentation and the hard deadline. */
|
|
50
|
+
hookTimeoutMs: number;
|
|
51
|
+
}
|
|
52
|
+
/** Budgets from design §2.5, in the same order as {@link HOOK_EVENTS}. */
|
|
53
|
+
export declare const EVENT_BUDGETS: Record<HookEvent, EventBudget>;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve an event argument to its canonical name.
|
|
56
|
+
*
|
|
57
|
+
* The documented subcommand names are lowercase; the host's event names are
|
|
58
|
+
* PascalCase, kebab-case, or snake_case depending on the harness. All spellings
|
|
59
|
+
* are accepted so a wiring mistake is a no-op rather than a crash, and an
|
|
60
|
+
* unknown name is reported to stderr while stdout stays `{}`.
|
|
61
|
+
*
|
|
62
|
+
* Kebab-case is handled structurally: `pre-tool-use` loses its separators and
|
|
63
|
+
* becomes `pretooluse`, so the same table serves Claude Code's PascalCase and
|
|
64
|
+
* Codex's `pre-tool-use` without a second list.
|
|
65
|
+
*
|
|
66
|
+
* Events that are recognized but have no capability resolve to `undefined` here;
|
|
67
|
+
* use {@link parseHookEventName} when the difference matters.
|
|
68
|
+
* @param raw - the first argument after `hook`.
|
|
69
|
+
* @returns the canonical event, or `undefined` when unknown or capability-less.
|
|
70
|
+
*/
|
|
71
|
+
export declare function parseHookEvent(raw: string | undefined): HookEvent | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Resolve an event argument, distinguishing "no capability" from "unknown".
|
|
74
|
+
*
|
|
75
|
+
* The hook process uses this so that a Codex event the runtime has nothing to
|
|
76
|
+
* say about exits 0 with `{}` and no warning, while a genuine typo still gets one.
|
|
77
|
+
* @param raw - the first argument after `hook`.
|
|
78
|
+
* @returns the discriminated parse result.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseHookEventName(raw: string | undefined): ParsedHookEventName;
|
|
81
|
+
/** A JSON object, as every stdout shape and stdin payload is. */
|
|
82
|
+
export type JsonObject = Record<string, unknown>;
|
|
83
|
+
/** The `hookSpecificOutput` envelope of the Claude Code hook contract. */
|
|
84
|
+
export interface HookSpecificOutput {
|
|
85
|
+
hookEventName: string;
|
|
86
|
+
permissionDecision?: 'deny' | 'allow' | 'ask';
|
|
87
|
+
permissionDecisionReason?: string;
|
|
88
|
+
updatedToolOutput?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Codex's name for a replaced tool result. It is a *different field* from
|
|
91
|
+
* `updatedToolOutput`, not an alias, and Codex only honors it for MCP tool
|
|
92
|
+
* output — a shell tool result cannot be rewritten at all. Both names are
|
|
93
|
+
* modelled so a host mismatch is a typed mistake instead of a silently
|
|
94
|
+
* ignored field.
|
|
95
|
+
*/
|
|
96
|
+
updatedMCPToolOutput?: string;
|
|
97
|
+
additionalContext?: string;
|
|
98
|
+
}
|
|
99
|
+
/** The stdout object of a hook invocation. `{}` means "no instruction". */
|
|
100
|
+
export interface HookOutput extends JsonObject {
|
|
101
|
+
hookSpecificOutput?: HookSpecificOutput;
|
|
102
|
+
decision?: 'block';
|
|
103
|
+
reason?: string;
|
|
104
|
+
}
|
|
105
|
+
/** The empty output that always means "allow, no instruction". */
|
|
106
|
+
export declare function emptyHookOutput(): HookOutput;
|
|
107
|
+
/** The output of one PreToolUse denial. */
|
|
108
|
+
export declare function preToolUseDeny(reason: string): HookOutput;
|
|
109
|
+
/** The output of one PostToolUse replacement. */
|
|
110
|
+
export declare function postToolUseReplace(text: string): HookOutput;
|
|
111
|
+
/**
|
|
112
|
+
* The output of one Codex PostToolUse replacement.
|
|
113
|
+
*
|
|
114
|
+
* Codex reads `updatedMCPToolOutput` and only for MCP tools; emitting Claude's
|
|
115
|
+
* `updatedToolOutput` there is silently ignored. Kept as a separate function so
|
|
116
|
+
* the adapter cannot pick the wrong name by accident.
|
|
117
|
+
* @param text - the replacement text for the MCP tool result.
|
|
118
|
+
*/
|
|
119
|
+
export declare function postToolUseMcpReplace(text: string): HookOutput;
|
|
120
|
+
/** The output of one PostToolUseFailure correction. */
|
|
121
|
+
export declare function postToolUseFailureContext(text: string): HookOutput;
|
|
122
|
+
/** The output of one Stop objection. */
|
|
123
|
+
export declare function stopBlock(reason: string): HookOutput;
|
|
124
|
+
/** The output of one SessionStart notice. */
|
|
125
|
+
export declare function sessionStartContext(text: string): HookOutput;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `harness-reflex hook <event>` wire contract.
|
|
3
|
+
*
|
|
4
|
+
* One table, one source of truth: the event aliases a harness may invoke, the
|
|
5
|
+
* stdin shape this implementation reads, the stdout shape it may emit, and the
|
|
6
|
+
* per-event decision budget. The command only ever writes the JSON shape named
|
|
7
|
+
* here, because the host splices stdout into model-visible text and treats any
|
|
8
|
+
* non-JSON byte as a reason.
|
|
9
|
+
*
|
|
10
|
+
* @module hook/contract
|
|
11
|
+
*/
|
|
12
|
+
/** The events the hook accepts (design §2.5). */
|
|
13
|
+
export const HOOK_EVENTS = [
|
|
14
|
+
'pretooluse',
|
|
15
|
+
'posttooluse',
|
|
16
|
+
'postfailure',
|
|
17
|
+
'stop',
|
|
18
|
+
'substop',
|
|
19
|
+
'sessionstart',
|
|
20
|
+
'sessionend'
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Events a host emits that this runtime has no capability for.
|
|
24
|
+
*
|
|
25
|
+
* Codex 0.163.0 fires twelve hook events (`hooks/src/engine/command_runner.rs`).
|
|
26
|
+
* Five of them describe something the decision runtime deliberately does not
|
|
27
|
+
* decide — the prompt is already submitted, the permission is already being
|
|
28
|
+
* asked, the compaction is already happening. They are still *recognized* so a
|
|
29
|
+
* wiring mistake is a silent `{}` instead of a stderr warning on every turn, but
|
|
30
|
+
* they can never produce a decision: `HookDecision.handle` never sees them.
|
|
31
|
+
*
|
|
32
|
+
* This is a separate type from {@link HookEvent} on purpose. Widening `HookEvent`
|
|
33
|
+
* would force every existing `switch` over it to grow a branch, which is exactly
|
|
34
|
+
* the kind of behavior change this adapter is not allowed to make.
|
|
35
|
+
*/
|
|
36
|
+
export const CODEX_ONLY_HOOK_EVENTS = [
|
|
37
|
+
'userpromptsubmit',
|
|
38
|
+
'permissionrequest',
|
|
39
|
+
'precompact',
|
|
40
|
+
'postcompact',
|
|
41
|
+
'subagentstart',
|
|
42
|
+
'interrupt'
|
|
43
|
+
];
|
|
44
|
+
/** Strip the dashes, underscores and case a host may spell an event with. */
|
|
45
|
+
function normalizeEventName(raw) {
|
|
46
|
+
return raw.trim().toLowerCase().replace(/[-_\s]/g, '');
|
|
47
|
+
}
|
|
48
|
+
/** Budgets from design §2.5, in the same order as {@link HOOK_EVENTS}. */
|
|
49
|
+
export const EVENT_BUDGETS = {
|
|
50
|
+
pretooluse: { budgetMs: 300, hookTimeoutMs: 1000 },
|
|
51
|
+
posttooluse: { budgetMs: 800, hookTimeoutMs: 2000 },
|
|
52
|
+
postfailure: { budgetMs: 300, hookTimeoutMs: 1000 },
|
|
53
|
+
stop: { budgetMs: 1000, hookTimeoutMs: 2000 },
|
|
54
|
+
substop: { budgetMs: 1000, hookTimeoutMs: 2000 },
|
|
55
|
+
sessionstart: { budgetMs: 1200, hookTimeoutMs: 2000 },
|
|
56
|
+
sessionend: { budgetMs: 1200, hookTimeoutMs: 1500 }
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Resolve an event argument to its canonical name.
|
|
60
|
+
*
|
|
61
|
+
* The documented subcommand names are lowercase; the host's event names are
|
|
62
|
+
* PascalCase, kebab-case, or snake_case depending on the harness. All spellings
|
|
63
|
+
* are accepted so a wiring mistake is a no-op rather than a crash, and an
|
|
64
|
+
* unknown name is reported to stderr while stdout stays `{}`.
|
|
65
|
+
*
|
|
66
|
+
* Kebab-case is handled structurally: `pre-tool-use` loses its separators and
|
|
67
|
+
* becomes `pretooluse`, so the same table serves Claude Code's PascalCase and
|
|
68
|
+
* Codex's `pre-tool-use` without a second list.
|
|
69
|
+
*
|
|
70
|
+
* Events that are recognized but have no capability resolve to `undefined` here;
|
|
71
|
+
* use {@link parseHookEventName} when the difference matters.
|
|
72
|
+
* @param raw - the first argument after `hook`.
|
|
73
|
+
* @returns the canonical event, or `undefined` when unknown or capability-less.
|
|
74
|
+
*/
|
|
75
|
+
export function parseHookEvent(raw) {
|
|
76
|
+
if (!raw)
|
|
77
|
+
return undefined;
|
|
78
|
+
const name = normalizeEventName(raw);
|
|
79
|
+
// `post-tool` / `pre-tool` are what a few bundlers spell the Claude Code
|
|
80
|
+
// events as, so the alias table normalizes them instead of silently no-oping.
|
|
81
|
+
if (name === 'pretooluse' || name === 'pretool')
|
|
82
|
+
return 'pretooluse';
|
|
83
|
+
if (name === 'posttooluse' || name === 'posttool')
|
|
84
|
+
return 'posttooluse';
|
|
85
|
+
if (name === 'posttoolusefailure' || name === 'postfailure')
|
|
86
|
+
return 'postfailure';
|
|
87
|
+
if (name === 'stop')
|
|
88
|
+
return 'stop';
|
|
89
|
+
if (name === 'subagentstop' || name === 'substop')
|
|
90
|
+
return 'substop';
|
|
91
|
+
if (name === 'sessionstart')
|
|
92
|
+
return 'sessionstart';
|
|
93
|
+
if (name === 'sessionend')
|
|
94
|
+
return 'sessionend';
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Resolve an event argument, distinguishing "no capability" from "unknown".
|
|
99
|
+
*
|
|
100
|
+
* The hook process uses this so that a Codex event the runtime has nothing to
|
|
101
|
+
* say about exits 0 with `{}` and no warning, while a genuine typo still gets one.
|
|
102
|
+
* @param raw - the first argument after `hook`.
|
|
103
|
+
* @returns the discriminated parse result.
|
|
104
|
+
*/
|
|
105
|
+
export function parseHookEventName(raw) {
|
|
106
|
+
const canonical = parseHookEvent(raw);
|
|
107
|
+
if (canonical)
|
|
108
|
+
return { kind: 'canonical', event: canonical };
|
|
109
|
+
if (!raw)
|
|
110
|
+
return { kind: 'unknown' };
|
|
111
|
+
const name = normalizeEventName(raw);
|
|
112
|
+
for (const event of CODEX_ONLY_HOOK_EVENTS) {
|
|
113
|
+
if (name === event)
|
|
114
|
+
return { kind: 'codex-only', event };
|
|
115
|
+
}
|
|
116
|
+
return { kind: 'unknown' };
|
|
117
|
+
}
|
|
118
|
+
/** The empty output that always means "allow, no instruction". */
|
|
119
|
+
export function emptyHookOutput() {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
/** The output of one PreToolUse denial. */
|
|
123
|
+
export function preToolUseDeny(reason) {
|
|
124
|
+
return {
|
|
125
|
+
hookSpecificOutput: {
|
|
126
|
+
hookEventName: 'PreToolUse',
|
|
127
|
+
permissionDecision: 'deny',
|
|
128
|
+
permissionDecisionReason: reason
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** The output of one PostToolUse replacement. */
|
|
133
|
+
export function postToolUseReplace(text) {
|
|
134
|
+
return { hookSpecificOutput: { hookEventName: 'PostToolUse', updatedToolOutput: text } };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The output of one Codex PostToolUse replacement.
|
|
138
|
+
*
|
|
139
|
+
* Codex reads `updatedMCPToolOutput` and only for MCP tools; emitting Claude's
|
|
140
|
+
* `updatedToolOutput` there is silently ignored. Kept as a separate function so
|
|
141
|
+
* the adapter cannot pick the wrong name by accident.
|
|
142
|
+
* @param text - the replacement text for the MCP tool result.
|
|
143
|
+
*/
|
|
144
|
+
export function postToolUseMcpReplace(text) {
|
|
145
|
+
return { hookSpecificOutput: { hookEventName: 'PostToolUse', updatedMCPToolOutput: text } };
|
|
146
|
+
}
|
|
147
|
+
/** The output of one PostToolUseFailure correction. */
|
|
148
|
+
export function postToolUseFailureContext(text) {
|
|
149
|
+
return { hookSpecificOutput: { hookEventName: 'PostToolUseFailure', additionalContext: text } };
|
|
150
|
+
}
|
|
151
|
+
/** The output of one Stop objection. */
|
|
152
|
+
export function stopBlock(reason) {
|
|
153
|
+
return { decision: 'block', reason };
|
|
154
|
+
}
|
|
155
|
+
/** The output of one SessionStart notice. */
|
|
156
|
+
export function sessionStartContext(text) {
|
|
157
|
+
return { hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: text } };
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/hook/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,YAAY;IACZ,aAAa;IACb,aAAa;IACb,MAAM;IACN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C;AAED,iDAAiD;AACjD,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,EAAE,kBAAkB,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,CAAC;AAC3F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,EAAE,kBAAkB,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,CAAC;AAC9F,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,EAAE,kBAAkB,EAAE,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,CAAC;AAClG,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,EAAE,kBAAkB,EAAE,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,CAAC;AAC5F,CAAC","sourcesContent":["/**\n * The `harness-reflex hook <event>` wire contract.\n *\n * One table, one source of truth: the event aliases a harness may invoke, the\n * stdin shape this implementation reads, the stdout shape it may emit, and the\n * per-event decision budget. The command only ever writes the JSON shape named\n * here, because the host splices stdout into model-visible text and treats any\n * non-JSON byte as a reason.\n *\n * @module hook/contract\n */\n\n/** The events the hook accepts (design §2.5). */\nexport const HOOK_EVENTS = [\n 'pretooluse',\n 'posttooluse',\n 'postfailure',\n 'stop',\n 'substop',\n 'sessionstart',\n 'sessionend'\n] as const;\n\n/** One accepted hook event. */\nexport type HookEvent = (typeof HOOK_EVENTS)[number];\n\n/**\n * Events a host emits that this runtime has no capability for.\n *\n * Codex 0.163.0 fires twelve hook events (`hooks/src/engine/command_runner.rs`).\n * Five of them describe something the decision runtime deliberately does not\n * decide — the prompt is already submitted, the permission is already being\n * asked, the compaction is already happening. They are still *recognized* so a\n * wiring mistake is a silent `{}` instead of a stderr warning on every turn, but\n * they can never produce a decision: `HookDecision.handle` never sees them.\n *\n * This is a separate type from {@link HookEvent} on purpose. Widening `HookEvent`\n * would force every existing `switch` over it to grow a branch, which is exactly\n * the kind of behavior change this adapter is not allowed to make.\n */\nexport const CODEX_ONLY_HOOK_EVENTS = [\n 'userpromptsubmit',\n 'permissionrequest',\n 'precompact',\n 'postcompact',\n 'subagentstart',\n 'interrupt'\n] as const;\n\n/** One host event that is recognized but carries no reflex capability. */\nexport type CodexOnlyHookEvent = (typeof CODEX_ONLY_HOOK_EVENTS)[number];\n\n/** What one raw event argument resolved to. */\nexport type ParsedHookEventName =\n | { kind: 'canonical'; event: HookEvent }\n | { kind: 'codex-only'; event: CodexOnlyHookEvent }\n | { kind: 'unknown' };\n\n/** Strip the dashes, underscores and case a host may spell an event with. */\nfunction normalizeEventName(raw: string): string {\n return raw.trim().toLowerCase().replace(/[-_\\s]/g, '');\n}\n\n/** The three-state mode every capability shares. */\nexport type HookMode = 'off' | 'observe' | 'active';\n\n/** Per-event decision budget and the host-side timeout it must stay inside. */\nexport interface EventBudget {\n /** Internal decision budget; on expiry the hook fails open. */\n budgetMs: number;\n /** The host's own timeout, kept for documentation and the hard deadline. */\n hookTimeoutMs: number;\n}\n\n/** Budgets from design §2.5, in the same order as {@link HOOK_EVENTS}. */\nexport const EVENT_BUDGETS: Record<HookEvent, EventBudget> = {\n pretooluse: { budgetMs: 300, hookTimeoutMs: 1000 },\n posttooluse: { budgetMs: 800, hookTimeoutMs: 2000 },\n postfailure: { budgetMs: 300, hookTimeoutMs: 1000 },\n stop: { budgetMs: 1000, hookTimeoutMs: 2000 },\n substop: { budgetMs: 1000, hookTimeoutMs: 2000 },\n sessionstart: { budgetMs: 1200, hookTimeoutMs: 2000 },\n sessionend: { budgetMs: 1200, hookTimeoutMs: 1500 }\n};\n\n/**\n * Resolve an event argument to its canonical name.\n *\n * The documented subcommand names are lowercase; the host's event names are\n * PascalCase, kebab-case, or snake_case depending on the harness. All spellings\n * are accepted so a wiring mistake is a no-op rather than a crash, and an\n * unknown name is reported to stderr while stdout stays `{}`.\n *\n * Kebab-case is handled structurally: `pre-tool-use` loses its separators and\n * becomes `pretooluse`, so the same table serves Claude Code's PascalCase and\n * Codex's `pre-tool-use` without a second list.\n *\n * Events that are recognized but have no capability resolve to `undefined` here;\n * use {@link parseHookEventName} when the difference matters.\n * @param raw - the first argument after `hook`.\n * @returns the canonical event, or `undefined` when unknown or capability-less.\n */\nexport function parseHookEvent(raw: string | undefined): HookEvent | undefined {\n if (!raw) return undefined;\n const name = normalizeEventName(raw);\n // `post-tool` / `pre-tool` are what a few bundlers spell the Claude Code\n // events as, so the alias table normalizes them instead of silently no-oping.\n if (name === 'pretooluse' || name === 'pretool') return 'pretooluse';\n if (name === 'posttooluse' || name === 'posttool') return 'posttooluse';\n if (name === 'posttoolusefailure' || name === 'postfailure') return 'postfailure';\n if (name === 'stop') return 'stop';\n if (name === 'subagentstop' || name === 'substop') return 'substop';\n if (name === 'sessionstart') return 'sessionstart';\n if (name === 'sessionend') return 'sessionend';\n return undefined;\n}\n\n/**\n * Resolve an event argument, distinguishing \"no capability\" from \"unknown\".\n *\n * The hook process uses this so that a Codex event the runtime has nothing to\n * say about exits 0 with `{}` and no warning, while a genuine typo still gets one.\n * @param raw - the first argument after `hook`.\n * @returns the discriminated parse result.\n */\nexport function parseHookEventName(raw: string | undefined): ParsedHookEventName {\n const canonical = parseHookEvent(raw);\n if (canonical) return { kind: 'canonical', event: canonical };\n if (!raw) return { kind: 'unknown' };\n const name = normalizeEventName(raw);\n for (const event of CODEX_ONLY_HOOK_EVENTS) {\n if (name === event) return { kind: 'codex-only', event };\n }\n return { kind: 'unknown' };\n}\n\n/** A JSON object, as every stdout shape and stdin payload is. */\nexport type JsonObject = Record<string, unknown>;\n\n/** The `hookSpecificOutput` envelope of the Claude Code hook contract. */\nexport interface HookSpecificOutput {\n hookEventName: string;\n permissionDecision?: 'deny' | 'allow' | 'ask';\n permissionDecisionReason?: string;\n updatedToolOutput?: string;\n /**\n * Codex's name for a replaced tool result. It is a *different field* from\n * `updatedToolOutput`, not an alias, and Codex only honors it for MCP tool\n * output — a shell tool result cannot be rewritten at all. Both names are\n * modelled so a host mismatch is a typed mistake instead of a silently\n * ignored field.\n */\n updatedMCPToolOutput?: string;\n additionalContext?: string;\n}\n\n/** The stdout object of a hook invocation. `{}` means \"no instruction\". */\nexport interface HookOutput extends JsonObject {\n hookSpecificOutput?: HookSpecificOutput;\n decision?: 'block';\n reason?: string;\n}\n\n/** The empty output that always means \"allow, no instruction\". */\nexport function emptyHookOutput(): HookOutput {\n return {};\n}\n\n/** The output of one PreToolUse denial. */\nexport function preToolUseDeny(reason: string): HookOutput {\n return {\n hookSpecificOutput: {\n hookEventName: 'PreToolUse',\n permissionDecision: 'deny',\n permissionDecisionReason: reason\n }\n };\n}\n\n/** The output of one PostToolUse replacement. */\nexport function postToolUseReplace(text: string): HookOutput {\n return { hookSpecificOutput: { hookEventName: 'PostToolUse', updatedToolOutput: text } };\n}\n\n/**\n * The output of one Codex PostToolUse replacement.\n *\n * Codex reads `updatedMCPToolOutput` and only for MCP tools; emitting Claude's\n * `updatedToolOutput` there is silently ignored. Kept as a separate function so\n * the adapter cannot pick the wrong name by accident.\n * @param text - the replacement text for the MCP tool result.\n */\nexport function postToolUseMcpReplace(text: string): HookOutput {\n return { hookSpecificOutput: { hookEventName: 'PostToolUse', updatedMCPToolOutput: text } };\n}\n\n/** The output of one PostToolUseFailure correction. */\nexport function postToolUseFailureContext(text: string): HookOutput {\n return { hookSpecificOutput: { hookEventName: 'PostToolUseFailure', additionalContext: text } };\n}\n\n/** The output of one Stop objection. */\nexport function stopBlock(reason: string): HookOutput {\n return { decision: 'block', reason };\n}\n\n/** The output of one SessionStart notice. */\nexport function sessionStartContext(text: string): HookOutput {\n return { hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: text } };\n}\n"]}
|