@s_s/agent-kit 1.0.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/README.md +317 -0
- package/build/create-kit.d.ts +16 -0
- package/build/create-kit.js +54 -0
- package/build/create-kit.js.map +1 -0
- package/build/detect.d.ts +13 -0
- package/build/detect.js +34 -0
- package/build/detect.js.map +1 -0
- package/build/hook-capabilities.d.ts +87 -0
- package/build/hook-capabilities.js +191 -0
- package/build/hook-capabilities.js.map +1 -0
- package/build/hook-registry.d.ts +158 -0
- package/build/hook-registry.js +223 -0
- package/build/hook-registry.js.map +1 -0
- package/build/hook-translators/claude-code.d.ts +26 -0
- package/build/hook-translators/claude-code.js +351 -0
- package/build/hook-translators/claude-code.js.map +1 -0
- package/build/hook-translators/index.d.ts +4 -0
- package/build/hook-translators/index.js +4 -0
- package/build/hook-translators/index.js.map +1 -0
- package/build/hook-translators/openclaw.d.ts +25 -0
- package/build/hook-translators/openclaw.js +272 -0
- package/build/hook-translators/openclaw.js.map +1 -0
- package/build/hook-translators/opencode.d.ts +23 -0
- package/build/hook-translators/opencode.js +254 -0
- package/build/hook-translators/opencode.js.map +1 -0
- package/build/hook-translators/types.d.ts +59 -0
- package/build/hook-translators/types.js +2 -0
- package/build/hook-translators/types.js.map +1 -0
- package/build/hook-types.d.ts +155 -0
- package/build/hook-types.js +2 -0
- package/build/hook-types.js.map +1 -0
- package/build/hooks.d.ts +30 -0
- package/build/hooks.js +333 -0
- package/build/hooks.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.js +11 -0
- package/build/index.js.map +1 -0
- package/build/platform.d.ts +17 -0
- package/build/platform.js +79 -0
- package/build/platform.js.map +1 -0
- package/build/prompt.d.ts +21 -0
- package/build/prompt.js +87 -0
- package/build/prompt.js.map +1 -0
- package/build/register.d.ts +18 -0
- package/build/register.js +34 -0
- package/build/register.js.map +1 -0
- package/build/types.d.ts +111 -0
- package/build/types.js +53 -0
- package/build/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
const S = { level: 'supported' };
|
|
2
|
+
const U = (note) => ({ level: 'unsupported', note });
|
|
3
|
+
const P = (note) => ({ level: 'partial', note });
|
|
4
|
+
/**
|
|
5
|
+
* The capability matrix: intent sub-capability × agent → support level.
|
|
6
|
+
*
|
|
7
|
+
* This is the single source of truth for what each agent can and cannot do
|
|
8
|
+
* with each intent type. Used by installHooks() to generate precise warnings.
|
|
9
|
+
*/
|
|
10
|
+
export const CAPABILITY_MATRIX = {
|
|
11
|
+
'claude-code': {
|
|
12
|
+
inject: {
|
|
13
|
+
perTurn: S,
|
|
14
|
+
sessionStart: S,
|
|
15
|
+
compaction: S,
|
|
16
|
+
sessionEnd: S,
|
|
17
|
+
},
|
|
18
|
+
beforeToolCall: {
|
|
19
|
+
intercept: S,
|
|
20
|
+
block: S,
|
|
21
|
+
modifyArgs: S,
|
|
22
|
+
matcher: S,
|
|
23
|
+
},
|
|
24
|
+
afterToolCall: {
|
|
25
|
+
observe: S,
|
|
26
|
+
matcher: S,
|
|
27
|
+
},
|
|
28
|
+
onSession: {
|
|
29
|
+
start: S,
|
|
30
|
+
end: S,
|
|
31
|
+
},
|
|
32
|
+
onPermission: {
|
|
33
|
+
decide: S,
|
|
34
|
+
matcher: S,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
codex: {
|
|
38
|
+
inject: {
|
|
39
|
+
perTurn: S,
|
|
40
|
+
sessionStart: S,
|
|
41
|
+
compaction: S,
|
|
42
|
+
sessionEnd: S,
|
|
43
|
+
},
|
|
44
|
+
beforeToolCall: {
|
|
45
|
+
intercept: S,
|
|
46
|
+
block: S,
|
|
47
|
+
modifyArgs: S,
|
|
48
|
+
matcher: S,
|
|
49
|
+
},
|
|
50
|
+
afterToolCall: {
|
|
51
|
+
observe: S,
|
|
52
|
+
matcher: S,
|
|
53
|
+
},
|
|
54
|
+
onSession: {
|
|
55
|
+
start: S,
|
|
56
|
+
end: S,
|
|
57
|
+
},
|
|
58
|
+
onPermission: {
|
|
59
|
+
decide: S,
|
|
60
|
+
matcher: S,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
opencode: {
|
|
64
|
+
inject: {
|
|
65
|
+
perTurn: S,
|
|
66
|
+
sessionStart: S,
|
|
67
|
+
compaction: P('Relies on experimental.session.compacting which is marked experimental and may change.'),
|
|
68
|
+
sessionEnd: U('OpenCode has no session end hook. The event hook does not emit session.end.'),
|
|
69
|
+
},
|
|
70
|
+
beforeToolCall: {
|
|
71
|
+
intercept: S,
|
|
72
|
+
block: P("OpenCode's tool.execute.before has no explicit block mechanism. " +
|
|
73
|
+
'Blocking is simulated by clearing tool arguments, which may produce inconsistent behavior.'),
|
|
74
|
+
modifyArgs: S,
|
|
75
|
+
matcher: U('OpenCode hooks do not support regex matchers. All tool calls are received; filtering is done in handler code.'),
|
|
76
|
+
},
|
|
77
|
+
afterToolCall: {
|
|
78
|
+
observe: S,
|
|
79
|
+
matcher: U('OpenCode hooks do not support regex matchers. All tool calls are received; filtering is done in handler code.'),
|
|
80
|
+
},
|
|
81
|
+
onSession: {
|
|
82
|
+
start: P('OpenCode session start is detected via event hook filtering, not a dedicated hook.'),
|
|
83
|
+
end: U('OpenCode has no session end hook.'),
|
|
84
|
+
},
|
|
85
|
+
onPermission: {
|
|
86
|
+
decide: S,
|
|
87
|
+
matcher: U('OpenCode permission.ask does not support regex matchers.'),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
openclaw: {
|
|
91
|
+
inject: {
|
|
92
|
+
perTurn: S,
|
|
93
|
+
sessionStart: S,
|
|
94
|
+
compaction: S,
|
|
95
|
+
sessionEnd: P('OpenClaw session_end is a void plugin hook; content injection may not reach the agent context.'),
|
|
96
|
+
},
|
|
97
|
+
beforeToolCall: {
|
|
98
|
+
intercept: S,
|
|
99
|
+
block: S,
|
|
100
|
+
modifyArgs: S,
|
|
101
|
+
matcher: U('OpenClaw before_tool_call does not support regex matchers. All tool calls are received.'),
|
|
102
|
+
},
|
|
103
|
+
afterToolCall: {
|
|
104
|
+
observe: S,
|
|
105
|
+
matcher: U('OpenClaw after_tool_call does not support regex matchers. All tool calls are received.'),
|
|
106
|
+
},
|
|
107
|
+
onSession: {
|
|
108
|
+
start: S,
|
|
109
|
+
end: S,
|
|
110
|
+
},
|
|
111
|
+
onPermission: {
|
|
112
|
+
decide: U('OpenClaw has no dedicated permission hook. Use hooks.raw() with before_tool_call as a workaround.'),
|
|
113
|
+
matcher: U('OpenClaw has no dedicated permission hook.'),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Check all sub-capabilities for a given intent type on a given agent.
|
|
119
|
+
* Returns warnings for any partial or unsupported sub-capabilities.
|
|
120
|
+
*
|
|
121
|
+
* Only checks sub-capabilities that the intent actually uses.
|
|
122
|
+
* For example, if an inject intent has no `compaction` field, the compaction
|
|
123
|
+
* capability is not checked.
|
|
124
|
+
*/
|
|
125
|
+
export function checkDegradation(agent, intentType, usedCapabilities) {
|
|
126
|
+
const caps = CAPABILITY_MATRIX[agent][intentType];
|
|
127
|
+
const warnings = [];
|
|
128
|
+
const entries = Object.entries(caps);
|
|
129
|
+
for (const [capName, entry] of entries) {
|
|
130
|
+
// If usedCapabilities is specified, only check those
|
|
131
|
+
if (usedCapabilities && !usedCapabilities.includes(capName))
|
|
132
|
+
continue;
|
|
133
|
+
if (entry.level !== 'supported') {
|
|
134
|
+
warnings.push({
|
|
135
|
+
agent,
|
|
136
|
+
intent: intentType,
|
|
137
|
+
capability: capName,
|
|
138
|
+
level: entry.level,
|
|
139
|
+
message: `[${agent}] ${intentType}.${capName}: ${entry.note ?? `${entry.level} — no details available.`}`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return warnings;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Check degradation for all registered intents on a specific agent.
|
|
147
|
+
* Analyzes which sub-capabilities each intent actually uses and only
|
|
148
|
+
* warns about those.
|
|
149
|
+
*/
|
|
150
|
+
export function checkAllDegradation(agent, intentTypes) {
|
|
151
|
+
const warnings = [];
|
|
152
|
+
const seen = new Set();
|
|
153
|
+
for (const intentType of intentTypes) {
|
|
154
|
+
const intentWarnings = checkDegradation(agent, intentType);
|
|
155
|
+
for (const w of intentWarnings) {
|
|
156
|
+
const key = `${w.agent}::${w.intent}::${w.capability}`;
|
|
157
|
+
if (!seen.has(key)) {
|
|
158
|
+
seen.add(key);
|
|
159
|
+
warnings.push(w);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return warnings;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if a specific intent type is fully unsupported on an agent.
|
|
167
|
+
* Returns true only if ALL sub-capabilities are unsupported.
|
|
168
|
+
*/
|
|
169
|
+
export function isIntentFullyUnsupported(agent, intentType) {
|
|
170
|
+
const caps = CAPABILITY_MATRIX[agent][intentType];
|
|
171
|
+
return Object.values(caps).every((entry) => entry.level === 'unsupported');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Detect conflicts between intent-generated hooks and raw hooks.
|
|
175
|
+
*
|
|
176
|
+
* @param agent - The target agent.
|
|
177
|
+
* @param intentNativeHooks - Set of native hook names generated by intents.
|
|
178
|
+
* @param rawNativeHooks - Set of native hook names registered via hooks.raw().
|
|
179
|
+
* @returns Warning messages for each conflict.
|
|
180
|
+
*/
|
|
181
|
+
export function detectConflicts(agent, intentNativeHooks, rawNativeHooks) {
|
|
182
|
+
const warnings = [];
|
|
183
|
+
for (const hookName of intentNativeHooks) {
|
|
184
|
+
if (rawNativeHooks.has(hookName)) {
|
|
185
|
+
warnings.push(`[${agent}] Conflict: raw hook for '${hookName}' overrides intent-generated hook. ` +
|
|
186
|
+
`The raw hook will be used; intent-generated logic for this hook is discarded.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return warnings;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=hook-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-capabilities.js","sourceRoot":"","sources":["../src/hook-capabilities.ts"],"names":[],"mappings":"AAqDA,MAAM,CAAC,GAAoB,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAClD,MAAM,CAAC,GAAG,CAAC,IAAY,EAAmB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9E,MAAM,CAAC,GAAG,CAAC,IAAY,EAAmB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA0C;IACpE,aAAa,EAAE;QACX,MAAM,EAAE;YACJ,OAAO,EAAE,CAAC;YACV,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;SAChB;QACD,cAAc,EAAE;YACZ,SAAS,EAAE,CAAC;YACZ,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;SACb;QACD,aAAa,EAAE;YACX,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;SACb;QACD,SAAS,EAAE;YACP,KAAK,EAAE,CAAC;YACR,GAAG,EAAE,CAAC;SACT;QACD,YAAY,EAAE;YACV,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,CAAC;SACb;KACJ;IAED,KAAK,EAAE;QACH,MAAM,EAAE;YACJ,OAAO,EAAE,CAAC;YACV,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;SAChB;QACD,cAAc,EAAE;YACZ,SAAS,EAAE,CAAC;YACZ,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;SACb;QACD,aAAa,EAAE;Y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Intent, OnSessionIntent, OnPermissionIntent, HookIntent, RawHookRegistration, ExtendHookRegistration } from './hook-types.js';
|
|
3
|
+
/** Get a snapshot of all registered intents. */
|
|
4
|
+
export declare function getIntents(): readonly HookIntent[];
|
|
5
|
+
/** Get intents filtered by type. */
|
|
6
|
+
export declare function getIntentsByType<T extends HookIntent['type']>(type: T): Extract<HookIntent, {
|
|
7
|
+
type: T;
|
|
8
|
+
}>[];
|
|
9
|
+
/** Get the raw hook map (read-only view). */
|
|
10
|
+
export declare function getRawHooks(): ReadonlyMap<string, RawHookRegistration>;
|
|
11
|
+
/** Get the extend hook map (read-only view). */
|
|
12
|
+
export declare function getExtendHooks(): ReadonlyMap<string, readonly ExtendHookRegistration[]>;
|
|
13
|
+
/** Check if a raw hook is registered for a specific agent + native hook name. */
|
|
14
|
+
export declare function hasRawHook(agent: AgentType, hookName: string): boolean;
|
|
15
|
+
/** Get a raw hook registration for a specific agent + native hook name. */
|
|
16
|
+
export declare function getRawHook(agent: AgentType, hookName: string): RawHookRegistration | undefined;
|
|
17
|
+
/** Get extend registrations for a specific agent + native hook name. */
|
|
18
|
+
export declare function getExtendHooksFor(agent: AgentType, hookName: string): readonly ExtendHookRegistration[];
|
|
19
|
+
/**
|
|
20
|
+
* Register a content injection intent.
|
|
21
|
+
*
|
|
22
|
+
* Injects text into agent context at various lifecycle points.
|
|
23
|
+
* At minimum, `perTurn` is required.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* hooks.inject({
|
|
28
|
+
* perTurn: 'Always remember: you are a helpful assistant.',
|
|
29
|
+
* sessionStart: 'Welcome! This session uses the Foo tool.',
|
|
30
|
+
* compaction: 'Preserve the Foo tool context.',
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function inject(config: Omit<InjectIntent, 'type'>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Register a pre-tool-call interception intent.
|
|
37
|
+
*
|
|
38
|
+
* Intercept tool calls before execution — can block or modify arguments.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* hooks.beforeToolCall({
|
|
43
|
+
* match: /^(Bash|Write)/,
|
|
44
|
+
* handler: (ctx) => {
|
|
45
|
+
* if (ctx.args.path?.includes('/etc/')) {
|
|
46
|
+
* return { block: true, reason: 'Cannot modify /etc/' };
|
|
47
|
+
* }
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function beforeToolCall(config: Omit<BeforeToolCallIntent, 'type'>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Register a post-tool-call observation intent.
|
|
55
|
+
*
|
|
56
|
+
* Observe tool call results — cannot modify, only react.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* hooks.afterToolCall({
|
|
61
|
+
* match: 'Bash',
|
|
62
|
+
* handler: (ctx) => {
|
|
63
|
+
* console.log(`Tool ${ctx.toolName} returned: ${ctx.result}`);
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function afterToolCall(config: Omit<AfterToolCallIntent, 'type'>): void;
|
|
69
|
+
/**
|
|
70
|
+
* Register a session lifecycle intent.
|
|
71
|
+
*
|
|
72
|
+
* React to session start and/or end.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* hooks.onSession({
|
|
77
|
+
* start: (ctx) => console.log('Session started:', ctx.sessionId),
|
|
78
|
+
* end: (ctx) => console.log('Session ended:', ctx.sessionId),
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function onSession(config: Omit<OnSessionIntent, 'type'>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Register a permission decision intent.
|
|
85
|
+
*
|
|
86
|
+
* Intercept permission requests and decide allow/deny/ask.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* hooks.onPermission({
|
|
91
|
+
* match: 'Bash',
|
|
92
|
+
* handler: (ctx) => {
|
|
93
|
+
* if (ctx.args.command?.startsWith('git ')) return 'allow';
|
|
94
|
+
* return 'ask';
|
|
95
|
+
* },
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function onPermission(config: Omit<OnPermissionIntent, 'type'>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Register a raw native hook for a specific agent.
|
|
102
|
+
*
|
|
103
|
+
* Raw hooks bypass the intent layer entirely and write handler code directly.
|
|
104
|
+
* When a raw hook targets the same native hook as an intent-generated hook,
|
|
105
|
+
* the raw hook wins and a warning is emitted during `installHooks()`.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* hooks.raw({
|
|
110
|
+
* agent: 'claude-code',
|
|
111
|
+
* hookName: 'Notification',
|
|
112
|
+
* handler: '#!/bin/bash\ncurl -X POST https://webhook.example.com',
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function raw<A extends AgentType>(registration: RawHookRegistration<A>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Register an extend hook for a specific agent.
|
|
119
|
+
*
|
|
120
|
+
* Extend hooks run after the intent-generated handler for the same native hook.
|
|
121
|
+
* They cannot replace, only augment. Multiple extends for the same hook
|
|
122
|
+
* are executed in registration order.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* hooks.extend({
|
|
127
|
+
* agent: 'opencode',
|
|
128
|
+
* hookName: 'tool.execute.after',
|
|
129
|
+
* handler: 'console.log("Tool execution completed");',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function extend<A extends AgentType>(registration: ExtendHookRegistration<A>): void;
|
|
134
|
+
/**
|
|
135
|
+
* Reset all registrations. For testing only.
|
|
136
|
+
*/
|
|
137
|
+
declare function _resetForTesting(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Hook declaration API.
|
|
140
|
+
*
|
|
141
|
+
* Use `hooks.inject()`, `hooks.beforeToolCall()`, etc. to declare intents.
|
|
142
|
+
* Use `hooks.raw()` to bypass the intent layer for a specific agent.
|
|
143
|
+
* Use `hooks.extend()` to augment intent-generated hooks for a specific agent.
|
|
144
|
+
*
|
|
145
|
+
* All registrations are stored in a module-level singleton and consumed by
|
|
146
|
+
* `installHooks()` when generating native hook files.
|
|
147
|
+
*/
|
|
148
|
+
export declare const hooks: {
|
|
149
|
+
readonly inject: typeof inject;
|
|
150
|
+
readonly beforeToolCall: typeof beforeToolCall;
|
|
151
|
+
readonly afterToolCall: typeof afterToolCall;
|
|
152
|
+
readonly onSession: typeof onSession;
|
|
153
|
+
readonly onPermission: typeof onPermission;
|
|
154
|
+
readonly raw: typeof raw;
|
|
155
|
+
readonly extend: typeof extend;
|
|
156
|
+
readonly _resetForTesting: typeof _resetForTesting;
|
|
157
|
+
};
|
|
158
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Internal state — module-level singleton
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/** All registered intents (ordered by registration time). */
|
|
5
|
+
let intents = [];
|
|
6
|
+
/** Raw hook registrations keyed by `${agent}::${hookName}`. */
|
|
7
|
+
let rawHooks = new Map();
|
|
8
|
+
/** Extend hook registrations keyed by `${agent}::${hookName}` (multiple per key). */
|
|
9
|
+
let extendHooks = new Map();
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Key helpers
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
function rawKey(agent, hookName) {
|
|
14
|
+
return `${agent}::${hookName}`;
|
|
15
|
+
}
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Read-only accessors (for translators and installHooks)
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/** Get a snapshot of all registered intents. */
|
|
20
|
+
export function getIntents() {
|
|
21
|
+
return intents;
|
|
22
|
+
}
|
|
23
|
+
/** Get intents filtered by type. */
|
|
24
|
+
export function getIntentsByType(type) {
|
|
25
|
+
return intents.filter((i) => i.type === type);
|
|
26
|
+
}
|
|
27
|
+
/** Get the raw hook map (read-only view). */
|
|
28
|
+
export function getRawHooks() {
|
|
29
|
+
return rawHooks;
|
|
30
|
+
}
|
|
31
|
+
/** Get the extend hook map (read-only view). */
|
|
32
|
+
export function getExtendHooks() {
|
|
33
|
+
return extendHooks;
|
|
34
|
+
}
|
|
35
|
+
/** Check if a raw hook is registered for a specific agent + native hook name. */
|
|
36
|
+
export function hasRawHook(agent, hookName) {
|
|
37
|
+
return rawHooks.has(rawKey(agent, hookName));
|
|
38
|
+
}
|
|
39
|
+
/** Get a raw hook registration for a specific agent + native hook name. */
|
|
40
|
+
export function getRawHook(agent, hookName) {
|
|
41
|
+
return rawHooks.get(rawKey(agent, hookName));
|
|
42
|
+
}
|
|
43
|
+
/** Get extend registrations for a specific agent + native hook name. */
|
|
44
|
+
export function getExtendHooksFor(agent, hookName) {
|
|
45
|
+
return extendHooks.get(rawKey(agent, hookName)) ?? [];
|
|
46
|
+
}
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Intent registration API
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Register a content injection intent.
|
|
52
|
+
*
|
|
53
|
+
* Injects text into agent context at various lifecycle points.
|
|
54
|
+
* At minimum, `perTurn` is required.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* hooks.inject({
|
|
59
|
+
* perTurn: 'Always remember: you are a helpful assistant.',
|
|
60
|
+
* sessionStart: 'Welcome! This session uses the Foo tool.',
|
|
61
|
+
* compaction: 'Preserve the Foo tool context.',
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function inject(config) {
|
|
66
|
+
intents.push({ type: 'inject', ...config });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Register a pre-tool-call interception intent.
|
|
70
|
+
*
|
|
71
|
+
* Intercept tool calls before execution — can block or modify arguments.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* hooks.beforeToolCall({
|
|
76
|
+
* match: /^(Bash|Write)/,
|
|
77
|
+
* handler: (ctx) => {
|
|
78
|
+
* if (ctx.args.path?.includes('/etc/')) {
|
|
79
|
+
* return { block: true, reason: 'Cannot modify /etc/' };
|
|
80
|
+
* }
|
|
81
|
+
* },
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function beforeToolCall(config) {
|
|
86
|
+
intents.push({ type: 'beforeToolCall', ...config });
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Register a post-tool-call observation intent.
|
|
90
|
+
*
|
|
91
|
+
* Observe tool call results — cannot modify, only react.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* hooks.afterToolCall({
|
|
96
|
+
* match: 'Bash',
|
|
97
|
+
* handler: (ctx) => {
|
|
98
|
+
* console.log(`Tool ${ctx.toolName} returned: ${ctx.result}`);
|
|
99
|
+
* },
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
function afterToolCall(config) {
|
|
104
|
+
intents.push({ type: 'afterToolCall', ...config });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Register a session lifecycle intent.
|
|
108
|
+
*
|
|
109
|
+
* React to session start and/or end.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* hooks.onSession({
|
|
114
|
+
* start: (ctx) => console.log('Session started:', ctx.sessionId),
|
|
115
|
+
* end: (ctx) => console.log('Session ended:', ctx.sessionId),
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function onSession(config) {
|
|
120
|
+
intents.push({ type: 'onSession', ...config });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Register a permission decision intent.
|
|
124
|
+
*
|
|
125
|
+
* Intercept permission requests and decide allow/deny/ask.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* hooks.onPermission({
|
|
130
|
+
* match: 'Bash',
|
|
131
|
+
* handler: (ctx) => {
|
|
132
|
+
* if (ctx.args.command?.startsWith('git ')) return 'allow';
|
|
133
|
+
* return 'ask';
|
|
134
|
+
* },
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
function onPermission(config) {
|
|
139
|
+
intents.push({ type: 'onPermission', ...config });
|
|
140
|
+
}
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// Raw hook registration — bypass intent layer
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
/**
|
|
145
|
+
* Register a raw native hook for a specific agent.
|
|
146
|
+
*
|
|
147
|
+
* Raw hooks bypass the intent layer entirely and write handler code directly.
|
|
148
|
+
* When a raw hook targets the same native hook as an intent-generated hook,
|
|
149
|
+
* the raw hook wins and a warning is emitted during `installHooks()`.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* hooks.raw({
|
|
154
|
+
* agent: 'claude-code',
|
|
155
|
+
* hookName: 'Notification',
|
|
156
|
+
* handler: '#!/bin/bash\ncurl -X POST https://webhook.example.com',
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
function raw(registration) {
|
|
161
|
+
const key = rawKey(registration.agent, registration.hookName);
|
|
162
|
+
rawHooks.set(key, registration);
|
|
163
|
+
}
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// Extend hook registration — augment intent-generated hooks
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
/**
|
|
168
|
+
* Register an extend hook for a specific agent.
|
|
169
|
+
*
|
|
170
|
+
* Extend hooks run after the intent-generated handler for the same native hook.
|
|
171
|
+
* They cannot replace, only augment. Multiple extends for the same hook
|
|
172
|
+
* are executed in registration order.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* hooks.extend({
|
|
177
|
+
* agent: 'opencode',
|
|
178
|
+
* hookName: 'tool.execute.after',
|
|
179
|
+
* handler: 'console.log("Tool execution completed");',
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function extend(registration) {
|
|
184
|
+
const key = rawKey(registration.agent, registration.hookName);
|
|
185
|
+
const existing = extendHooks.get(key) ?? [];
|
|
186
|
+
existing.push(registration);
|
|
187
|
+
extendHooks.set(key, existing);
|
|
188
|
+
}
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Testing utilities
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
/**
|
|
193
|
+
* Reset all registrations. For testing only.
|
|
194
|
+
*/
|
|
195
|
+
function _resetForTesting() {
|
|
196
|
+
intents = [];
|
|
197
|
+
rawHooks = new Map();
|
|
198
|
+
extendHooks = new Map();
|
|
199
|
+
}
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// Public namespace object
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
/**
|
|
204
|
+
* Hook declaration API.
|
|
205
|
+
*
|
|
206
|
+
* Use `hooks.inject()`, `hooks.beforeToolCall()`, etc. to declare intents.
|
|
207
|
+
* Use `hooks.raw()` to bypass the intent layer for a specific agent.
|
|
208
|
+
* Use `hooks.extend()` to augment intent-generated hooks for a specific agent.
|
|
209
|
+
*
|
|
210
|
+
* All registrations are stored in a module-level singleton and consumed by
|
|
211
|
+
* `installHooks()` when generating native hook files.
|
|
212
|
+
*/
|
|
213
|
+
export const hooks = {
|
|
214
|
+
inject,
|
|
215
|
+
beforeToolCall,
|
|
216
|
+
afterToolCall,
|
|
217
|
+
onSession,
|
|
218
|
+
onPermission,
|
|
219
|
+
raw,
|
|
220
|
+
extend,
|
|
221
|
+
_resetForTesting,
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=hook-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-registry.js","sourceRoot":"","sources":["../src/hook-registry.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,0CAA0C;AAC1C,8EAA8E;AAE9E,6DAA6D;AAC7D,IAAI,OAAO,GAAiB,EAAE,CAAC;AAE/B,+DAA+D;AAC/D,IAAI,QAAQ,GAAqC,IAAI,GAAG,EAAE,CAAC;AAE3D,qFAAqF;AACrF,IAAI,WAAW,GAA0C,IAAI,GAAG,EAAE,CAAC;AAEnE,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,SAAS,MAAM,CAAC,KAAgB,EAAE,QAAgB;IAC9C,OAAO,GAAG,KAAK,KAAK,QAAQ,EAAE,CAAC;AACnC,CAAC;AAED,8EAA8E;AAC9E,yDAAyD;AACzD,8EAA8E;AAE9E,gDAAgD;AAChD,MAAM,UAAU,UAAU;IACtB,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,gBAAgB,CAA+B,IAAO;IAClE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAuC,CAAC;AACxF,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,WAAW;IACvB,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,cAAc;IAC1B,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC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sHookEntry } from './types.js';
|
|
2
|
+
import type { HookIntent, RawHookRegistration, ExtendHookRegistration } from '../hook-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Translates intent-based hooks into Claude Code / Codex native format.
|
|
5
|
+
*
|
|
6
|
+
* Claude Code uses:
|
|
7
|
+
* - Shell scripts executed as external processes
|
|
8
|
+
* - JSON input via stdin, JSON output via stdout
|
|
9
|
+
* - Exit codes for control (0 = allow, 2 = block)
|
|
10
|
+
* - settings.json for hook registration (event → matcher → handler)
|
|
11
|
+
*/
|
|
12
|
+
export declare class ClaudeCodeTranslator implements AgentHookTranslator {
|
|
13
|
+
private readonly agent;
|
|
14
|
+
constructor(agent?: 'claude-code' | 'codex');
|
|
15
|
+
translate(intents: readonly HookIntent[], rawHooks: ReadonlyMap<string, RawHookRegistration>, extendHooks: ReadonlyMap<string, readonly ExtendHookRegistration[]>, toolName: string): TranslationResult;
|
|
16
|
+
getSettingsEntries(hookDir: string, toolName: string): SettingsHookEntry[];
|
|
17
|
+
private mergeInjectIntents;
|
|
18
|
+
private buildInjectScript;
|
|
19
|
+
private buildSessionStartInjectScript;
|
|
20
|
+
private buildCompactionScript;
|
|
21
|
+
private buildSessionEndInjectScript;
|
|
22
|
+
private buildBeforeToolCallScript;
|
|
23
|
+
private buildAfterToolCallScript;
|
|
24
|
+
private buildOnSessionScript;
|
|
25
|
+
private buildPermissionScript;
|
|
26
|
+
}
|