opencode-command-hooks 0.1.4 → 0.1.5
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/dist/config/agent.d.ts +0 -24
- package/dist/config/agent.d.ts.map +1 -1
- package/dist/config/agent.js +0 -34
- package/dist/config/agent.js.map +1 -1
- package/dist/config/global.d.ts.map +1 -1
- package/dist/config/global.js +1 -17
- package/dist/config/global.js.map +1 -1
- package/dist/config/markdown.d.ts +0 -14
- package/dist/config/markdown.d.ts.map +1 -1
- package/dist/config/markdown.js +9 -80
- package/dist/config/markdown.js.map +1 -1
- package/dist/execution/shell.d.ts.map +1 -1
- package/dist/execution/shell.js +1 -7
- package/dist/execution/shell.js.map +1 -1
- package/dist/execution/template.d.ts.map +1 -1
- package/dist/execution/template.js +1 -7
- package/dist/execution/template.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +9 -96
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -151
- package/dist/index.js.map +1 -1
- package/dist/logging.d.ts +8 -4
- package/dist/logging.d.ts.map +1 -1
- package/dist/logging.js +11 -19
- package/dist/logging.js.map +1 -1
- package/dist/schemas.d.ts +16 -12
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +17 -0
- package/dist/schemas.js.map +1 -1
- package/dist/types/hooks.d.ts +75 -487
- package/dist/types/hooks.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/types/hooks.d.ts
CHANGED
|
@@ -13,95 +13,28 @@
|
|
|
13
13
|
*
|
|
14
14
|
* This is the new, simplified schema for defining hooks in agent markdown files.
|
|
15
15
|
* It's much more concise than the full CommandHooksConfig format.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```yaml
|
|
19
|
-
* hooks:
|
|
20
|
-
* before:
|
|
21
|
-
* - run: "echo 'Starting...'"
|
|
22
|
-
* after:
|
|
23
|
-
* - run: ["npm run typecheck", "npm run lint"]
|
|
24
|
-
* inject: "Validation results:\n{stdout}"
|
|
25
|
-
* ```
|
|
26
16
|
*/
|
|
27
17
|
export interface AgentHooks {
|
|
28
|
-
/**
|
|
29
|
-
* Hooks that run before agent execution
|
|
30
|
-
* Optional; omit if no before hooks needed
|
|
31
|
-
*/
|
|
18
|
+
/** Hooks that run before agent execution */
|
|
32
19
|
before?: AgentHookEntry[];
|
|
33
|
-
/**
|
|
34
|
-
* Hooks that run after agent execution
|
|
35
|
-
* Optional; omit if no after hooks needed
|
|
36
|
-
*/
|
|
20
|
+
/** Hooks that run after agent execution */
|
|
37
21
|
after?: AgentHookEntry[];
|
|
38
22
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Single hook entry in the simplified agent hooks format
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```yaml
|
|
44
|
-
* - run: "npm run typecheck"
|
|
45
|
-
* inject: "Typecheck results:\n{stdout}"
|
|
46
|
-
* toast:
|
|
47
|
-
* message: "Typecheck {exitCode, select, 0 {passed} other {failed}}"
|
|
48
|
-
* variant: "success"
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
23
|
+
/** Single hook entry in the simplified agent hooks format */
|
|
51
24
|
export interface AgentHookEntry {
|
|
52
|
-
/**
|
|
53
|
-
* Shell command(s) to execute when this hook runs.
|
|
54
|
-
* - Single string: executed as-is
|
|
55
|
-
* - Array of strings: executed sequentially
|
|
56
|
-
*
|
|
57
|
-
* Required field - hook must have a run command.
|
|
58
|
-
*/
|
|
25
|
+
/** Command(s) to execute. Array runs sequentially. */
|
|
59
26
|
run: string | string[];
|
|
60
|
-
/**
|
|
61
|
-
* Optional template for injecting hook results into the session.
|
|
62
|
-
* Supports the same placeholder substitution as ToolHook.inject.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```yaml
|
|
66
|
-
* inject: "Results:\n{stdout}"
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
27
|
+
/** Optional template for injecting hook results into the session. Supports placeholder substitution. */
|
|
69
28
|
inject?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Optional toast notification to display after the hook runs.
|
|
72
|
-
* Supports template placeholder substitution.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```yaml
|
|
76
|
-
* toast:
|
|
77
|
-
* message: "Tests {exitCode, select, 0 {passed} other {failed}}"
|
|
78
|
-
* variant: "success"
|
|
79
|
-
* duration: 3000
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
29
|
+
/** Optional toast notification. Supports placeholder substitution. */
|
|
82
30
|
toast?: {
|
|
83
|
-
/**
|
|
84
|
-
* Optional title for the toast notification.
|
|
85
|
-
* Supports template placeholder substitution.
|
|
86
|
-
*/
|
|
31
|
+
/** Optional title. Supports placeholder substitution. */
|
|
87
32
|
title?: string;
|
|
88
|
-
/**
|
|
89
|
-
* Required message for the toast notification.
|
|
90
|
-
* Supports template placeholder substitution.
|
|
91
|
-
*/
|
|
33
|
+
/** Message text. Supports placeholder substitution. */
|
|
92
34
|
message: string;
|
|
93
|
-
/**
|
|
94
|
-
* Visual variant/style for the toast.
|
|
95
|
-
* - "info": informational message (default)
|
|
96
|
-
* - "success": success message
|
|
97
|
-
* - "warning": warning message
|
|
98
|
-
* - "error": error message
|
|
99
|
-
*/
|
|
35
|
+
/** Visual variant: "info" | "success" | "warning" | "error" */
|
|
100
36
|
variant?: "info" | "success" | "warning" | "error";
|
|
101
|
-
/**
|
|
102
|
-
* Duration in milliseconds for which the toast should be displayed.
|
|
103
|
-
* If omitted, uses the default duration.
|
|
104
|
-
*/
|
|
37
|
+
/** Duration in milliseconds. */
|
|
105
38
|
duration?: number;
|
|
106
39
|
};
|
|
107
40
|
}
|
|
@@ -111,153 +44,51 @@ export interface AgentHookEntry {
|
|
|
111
44
|
* Runs shell command(s) before or after a tool execution. Hooks can be filtered
|
|
112
45
|
* by tool name, calling agent, and slash command context. Results can optionally
|
|
113
46
|
* be injected into the session as messages.
|
|
114
|
-
|
|
115
|
-
* @example
|
|
116
|
-
* ```json
|
|
117
|
-
* {
|
|
118
|
-
* "id": "global-tests-after-task",
|
|
119
|
-
* "when": {
|
|
120
|
-
* "phase": "after",
|
|
121
|
-
* "tool": ["task"],
|
|
122
|
-
* "callingAgent": ["*"]
|
|
123
|
-
* },
|
|
124
|
-
* "run": ["pnpm test --runInBand"],
|
|
125
|
-
* "inject": {
|
|
126
|
-
* "template": "Tests after {tool}: exit {exitCode}\n```sh\n{stdout}\n```"
|
|
127
|
-
* }
|
|
128
|
-
* }
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
47
|
+
*/
|
|
131
48
|
export interface ToolHook {
|
|
132
|
-
/**
|
|
133
|
-
* Unique identifier for this hook within its scope (global or per-entity).
|
|
134
|
-
* Used for error reporting and logging.
|
|
135
|
-
* Must be unique within the same config source (global or markdown file).
|
|
136
|
-
*/
|
|
49
|
+
/** Unique hook identifier. Must be unique within config source. */
|
|
137
50
|
id: string;
|
|
138
|
-
/**
|
|
139
|
-
* Matching conditions that determine when this hook should run.
|
|
140
|
-
* All specified conditions must match for the hook to execute.
|
|
141
|
-
*/
|
|
51
|
+
/** Matching conditions that determine when this hook should run. */
|
|
142
52
|
when: ToolHookWhen;
|
|
143
|
-
/**
|
|
144
|
-
* Shell command(s) to execute when this hook matches.
|
|
145
|
-
* - Single string: executed as-is
|
|
146
|
-
* - Array of strings: executed sequentially, even if earlier commands fail
|
|
147
|
-
*
|
|
148
|
-
* Commands are executed via Bun's shell API ($) with proper error handling.
|
|
149
|
-
* Non-zero exit codes do not block subsequent commands or normal tool execution.
|
|
150
|
-
*/
|
|
53
|
+
/** Command(s) to execute. Array runs sequentially; failures don't block. */
|
|
151
54
|
run: string | string[];
|
|
152
55
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
* - {id}: hook ID
|
|
158
|
-
* - {agent}: agent name (if available)
|
|
159
|
-
* - {tool}: tool name (for tool hooks)
|
|
160
|
-
* - {cmd}: command string that was executed
|
|
161
|
-
* - {stdout}: captured standard output (truncated to limit)
|
|
162
|
-
* - {stderr}: captured standard error (truncated to limit)
|
|
163
|
-
* - {exitCode}: command exit code (integer)
|
|
164
|
-
*
|
|
165
|
-
* Placeholders for unavailable values are replaced with empty string.
|
|
166
|
-
*/
|
|
56
|
+
* Optional template for injecting hook results into the session.
|
|
57
|
+
* Supports placeholders: {id}, {agent}, {tool}, {cmd}, {stdout}, {stderr}, {exitCode}
|
|
58
|
+
* Unavailable values are replaced with empty string.
|
|
59
|
+
*/
|
|
167
60
|
inject?: string;
|
|
168
|
-
/**
|
|
169
|
-
* Optional toast notification to display to the user.
|
|
170
|
-
* Supports template placeholder substitution like the inject template.
|
|
171
|
-
* If omitted, no toast is displayed.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```json
|
|
175
|
-
* {
|
|
176
|
-
* "title": "Lint Complete",
|
|
177
|
-
* "message": "Exit code: {exitCode}",
|
|
178
|
-
* "variant": "success",
|
|
179
|
-
* "duration": 3000
|
|
180
|
-
* }
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
61
|
+
/** Optional toast notification. Supports placeholder substitution. */
|
|
183
62
|
toast?: {
|
|
184
|
-
/**
|
|
185
|
-
* Optional title for the toast notification.
|
|
186
|
-
* Supports template placeholder substitution.
|
|
187
|
-
*/
|
|
63
|
+
/** Optional title. Supports placeholder substitution. */
|
|
188
64
|
title?: string;
|
|
189
|
-
/**
|
|
190
|
-
* Required message for the toast notification.
|
|
191
|
-
* Supports template placeholder substitution.
|
|
192
|
-
*/
|
|
65
|
+
/** Message text. Supports placeholder substitution. */
|
|
193
66
|
message: string;
|
|
194
|
-
/**
|
|
195
|
-
* Visual variant/style for the toast.
|
|
196
|
-
* - "info": informational message (default)
|
|
197
|
-
* - "success": success message
|
|
198
|
-
* - "warning": warning message
|
|
199
|
-
* - "error": error message
|
|
200
|
-
*/
|
|
67
|
+
/** Visual variant: "info" | "success" | "warning" | "error" */
|
|
201
68
|
variant?: "info" | "success" | "warning" | "error";
|
|
202
|
-
/**
|
|
203
|
-
* Duration in milliseconds for which the toast should be displayed.
|
|
204
|
-
* If omitted, uses the default duration.
|
|
205
|
-
*/
|
|
69
|
+
/** Duration in milliseconds. */
|
|
206
70
|
duration?: number;
|
|
207
71
|
};
|
|
208
72
|
}
|
|
209
73
|
/**
|
|
210
74
|
* Matching conditions for tool hooks
|
|
211
75
|
*
|
|
212
|
-
*
|
|
76
|
+
* All specified conditions must match for the hook to execute.
|
|
213
77
|
* Omitted fields default to matching all values (wildcard behavior).
|
|
214
78
|
*/
|
|
215
79
|
export interface ToolHookWhen {
|
|
216
|
-
/**
|
|
217
|
-
* Execution phase: "before" or "after" tool execution.
|
|
218
|
-
* - "before": runs before the tool is invoked
|
|
219
|
-
* - "after": runs after the tool completes (regardless of success/failure)
|
|
220
|
-
*/
|
|
80
|
+
/** Execution phase: "before" or "after" tool execution. */
|
|
221
81
|
phase: "before" | "after";
|
|
222
|
-
/**
|
|
223
|
-
* Tool name(s) to match.
|
|
224
|
-
* - Omitted or "*": matches all tools
|
|
225
|
-
* - Array of strings: matches if tool name is in the array
|
|
226
|
-
* - Single string: matches if tool name equals the string
|
|
227
|
-
*
|
|
228
|
-
* Examples: "task", ["bash", "write"], "*"
|
|
229
|
-
*/
|
|
82
|
+
/** Tool name(s) to match. Omitted or "*" matches all tools. */
|
|
230
83
|
tool?: string | string[];
|
|
231
84
|
/**
|
|
232
85
|
* Calling agent name(s) to match.
|
|
233
|
-
*
|
|
234
|
-
* - "*": matches any agent
|
|
235
|
-
* - Array of strings: matches if agent name is in the array
|
|
236
|
-
* - Single string: matches if agent name equals the string
|
|
237
|
-
*
|
|
238
|
-
* When defined in agent markdown, omitting this field means the hook
|
|
239
|
-
* applies only to that agent (implicit scoping).
|
|
86
|
+
* Omitted: defaults to "*" in global config, "this agent" in markdown.
|
|
240
87
|
*/
|
|
241
88
|
callingAgent?: string | string[];
|
|
242
|
-
/**
|
|
243
|
-
* Slash command name(s) to match (optional).
|
|
244
|
-
* Only applies when the tool invocation is associated with a slash command.
|
|
245
|
-
* - Omitted: matches tool calls regardless of slash command context
|
|
246
|
-
* - "*": matches any slash command
|
|
247
|
-
* - Array of strings: matches if slash command name is in the array
|
|
248
|
-
* - Single string: matches if slash command name equals the string
|
|
249
|
-
*
|
|
250
|
-
* Note: Slash command detection may not be available for all tool types.
|
|
251
|
-
*/
|
|
89
|
+
/** Slash command name(s) to match. Omitted matches all contexts. */
|
|
252
90
|
slashCommand?: string | string[];
|
|
253
|
-
/**
|
|
254
|
-
* Tool argument filters (optional, only available in tool.execute.before).
|
|
255
|
-
* Match based on the tool's input arguments.
|
|
256
|
-
* Useful for filtering task tool calls by subagentType.
|
|
257
|
-
*
|
|
258
|
-
* Example: { "subagentType": "validator" } matches only task calls with subagentType="validator"
|
|
259
|
-
* Example: { "subagentType": ["validator", "reviewer"] } matches multiple values
|
|
260
|
-
*/
|
|
91
|
+
/** Tool argument filters (only in tool.execute.before). Match by input arguments. */
|
|
261
92
|
toolArgs?: Record<string, string | string[]>;
|
|
262
93
|
}
|
|
263
94
|
/**
|
|
@@ -266,178 +97,62 @@ export interface ToolHookWhen {
|
|
|
266
97
|
* Runs shell command(s) on session lifecycle events (start, idle, end).
|
|
267
98
|
* Can be filtered by agent name. Results can optionally be injected into
|
|
268
99
|
* the session as messages.
|
|
269
|
-
|
|
270
|
-
* @example
|
|
271
|
-
* ```json
|
|
272
|
-
* {
|
|
273
|
-
* "id": "global-bootstrap",
|
|
274
|
-
* "when": {
|
|
275
|
-
* "event": "session.start",
|
|
276
|
-
* "agent": ["build", "validator", "*"]
|
|
277
|
-
* },
|
|
278
|
-
* "run": ["git status --short"],
|
|
279
|
-
* "inject": {
|
|
280
|
-
* "template": "Repo status for {agent}:\n```sh\n{stdout}\n```"
|
|
281
|
-
* }
|
|
282
|
-
* }
|
|
283
|
-
* ```
|
|
284
|
-
*/
|
|
100
|
+
*/
|
|
285
101
|
export interface SessionHook {
|
|
286
|
-
/**
|
|
287
|
-
* Unique identifier for this hook within its scope (global or per-entity).
|
|
288
|
-
* Used for error reporting and logging.
|
|
289
|
-
* Must be unique within the same config source (global or markdown file).
|
|
290
|
-
*/
|
|
102
|
+
/** Unique hook identifier. Must be unique within config source. */
|
|
291
103
|
id: string;
|
|
292
|
-
/**
|
|
293
|
-
* Matching conditions that determine when this hook should run.
|
|
294
|
-
* All specified conditions must match for the hook to execute.
|
|
295
|
-
*/
|
|
104
|
+
/** Matching conditions that determine when this hook should run. */
|
|
296
105
|
when: SessionHookWhen;
|
|
297
|
-
/**
|
|
298
|
-
* Shell command(s) to execute when this hook matches.
|
|
299
|
-
* - Single string: executed as-is
|
|
300
|
-
* - Array of strings: executed sequentially, even if earlier commands fail
|
|
301
|
-
*
|
|
302
|
-
* Commands are executed via Bun's shell API ($) with proper error handling.
|
|
303
|
-
* Non-zero exit codes do not block subsequent commands or normal session flow.
|
|
304
|
-
*/
|
|
106
|
+
/** Command(s) to execute. Array runs sequentially; failures don't block. */
|
|
305
107
|
run: string | string[];
|
|
306
108
|
/**
|
|
307
|
-
* Optional template
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* Supports placeholder substitution with the following variables:
|
|
311
|
-
* - {id}: hook ID
|
|
312
|
-
* - {agent}: agent name (if available)
|
|
313
|
-
* - {cmd}: command string that was executed
|
|
314
|
-
* - {stdout}: captured standard output (truncated to limit)
|
|
315
|
-
* - {stderr}: captured standard error (truncated to limit)
|
|
316
|
-
* - {exitCode}: command exit code (integer)
|
|
317
|
-
*
|
|
318
|
-
* Placeholders for unavailable values are replaced with empty string.
|
|
109
|
+
* Optional template for injecting hook results into the session.
|
|
110
|
+
* Supports placeholders: {id}, {agent}, {cmd}, {stdout}, {stderr}, {exitCode}
|
|
111
|
+
* Unavailable values are replaced with empty string.
|
|
319
112
|
*/
|
|
320
113
|
inject?: string;
|
|
321
|
-
/**
|
|
322
|
-
* Optional toast notification to display to the user.
|
|
323
|
-
* Supports template placeholder substitution like the inject template.
|
|
324
|
-
* If omitted, no toast is displayed.
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* ```json
|
|
328
|
-
* {
|
|
329
|
-
* "title": "Session Started",
|
|
330
|
-
* "message": "Agent {agent} is ready",
|
|
331
|
-
* "variant": "info",
|
|
332
|
-
* "duration": 2000
|
|
333
|
-
* }
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
114
|
+
/** Optional toast notification. Supports placeholder substitution. */
|
|
336
115
|
toast?: {
|
|
337
|
-
/**
|
|
338
|
-
* Optional title for the toast notification.
|
|
339
|
-
* Supports template placeholder substitution.
|
|
340
|
-
*/
|
|
116
|
+
/** Optional title. Supports placeholder substitution. */
|
|
341
117
|
title?: string;
|
|
342
|
-
/**
|
|
343
|
-
* Required message for the toast notification.
|
|
344
|
-
* Supports template placeholder substitution.
|
|
345
|
-
*/
|
|
118
|
+
/** Message text. Supports placeholder substitution. */
|
|
346
119
|
message: string;
|
|
347
|
-
/**
|
|
348
|
-
* Visual variant/style for the toast.
|
|
349
|
-
* - "info": informational message (default)
|
|
350
|
-
* - "success": success message
|
|
351
|
-
* - "warning": warning message
|
|
352
|
-
* - "error": error message
|
|
353
|
-
*/
|
|
120
|
+
/** Visual variant: "info" | "success" | "warning" | "error" */
|
|
354
121
|
variant?: "info" | "success" | "warning" | "error";
|
|
355
|
-
/**
|
|
356
|
-
* Duration in milliseconds for which the toast should be displayed.
|
|
357
|
-
* If omitted, uses the default duration.
|
|
358
|
-
*/
|
|
122
|
+
/** Duration in milliseconds. */
|
|
359
123
|
duration?: number;
|
|
360
124
|
};
|
|
361
125
|
}
|
|
362
126
|
/**
|
|
363
127
|
* Matching conditions for session hooks
|
|
364
128
|
*
|
|
365
|
-
*
|
|
129
|
+
* All specified conditions must match for the hook to execute.
|
|
366
130
|
* Omitted fields default to matching all values (wildcard behavior).
|
|
367
131
|
*/
|
|
368
132
|
export interface SessionHookWhen {
|
|
369
133
|
/**
|
|
370
134
|
* Session lifecycle event type.
|
|
371
|
-
*
|
|
372
|
-
* - "session.idle": fires after agent turn completes (for after-turn hooks)
|
|
373
|
-
* - "session.end": fires when session ends
|
|
374
|
-
*
|
|
375
|
-
* Note: For user convenience, config files can use "session.start" which maps to "session.created"
|
|
135
|
+
* "session.start" (alias for "session.created"), "session.idle", "session.end"
|
|
376
136
|
*/
|
|
377
137
|
event: "session.created" | "session.idle" | "session.end" | "session.start";
|
|
378
138
|
/**
|
|
379
139
|
* Agent name(s) to match.
|
|
380
|
-
*
|
|
381
|
-
* - "*": matches any agent
|
|
382
|
-
* - Array of strings: matches if agent name is in the array
|
|
383
|
-
* - Single string: matches if agent name equals the string
|
|
384
|
-
*
|
|
385
|
-
* When defined in agent markdown, omitting this field means the hook
|
|
386
|
-
* applies only to that agent (implicit scoping).
|
|
140
|
+
* Omitted: defaults to "*" in global config, "this agent" in markdown.
|
|
387
141
|
*/
|
|
388
142
|
agent?: string | string[];
|
|
389
143
|
}
|
|
390
144
|
/**
|
|
391
145
|
* Top-level command hooks configuration
|
|
392
146
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* In opencode.json:
|
|
398
|
-
* ```json
|
|
399
|
-
* {
|
|
400
|
-
* "command_hooks": {
|
|
401
|
-
* "truncationLimit": 5000,
|
|
402
|
-
* "tool": [...],
|
|
403
|
-
* "session": [...]
|
|
404
|
-
* }
|
|
405
|
-
* }
|
|
406
|
-
* ```
|
|
407
|
-
*
|
|
408
|
-
* In agent markdown frontmatter:
|
|
409
|
-
* ```yaml
|
|
410
|
-
* ---
|
|
411
|
-
* command_hooks:
|
|
412
|
-
* truncationLimit: 5000
|
|
413
|
-
* tool: [...]
|
|
414
|
-
* session: [...]
|
|
415
|
-
* ---
|
|
416
|
-
* ```
|
|
147
|
+
* Root configuration object in opencode.json/.opencode.jsonc under "command_hooks" key,
|
|
148
|
+
* or in YAML frontmatter of agent/slash-command markdown.
|
|
417
149
|
*/
|
|
418
150
|
export interface CommandHooksConfig {
|
|
419
|
-
/**
|
|
420
|
-
* Optional truncation limit for command output in characters.
|
|
421
|
-
* If omitted, defaults to 30,000 characters (matching OpenCode's bash tool).
|
|
422
|
-
* Set to a custom value to limit output captured from hook commands.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* ```json
|
|
426
|
-
* { "truncationLimit": 5000 }
|
|
427
|
-
* ```
|
|
428
|
-
*/
|
|
151
|
+
/** Truncation limit for command output in characters. Defaults to 30,000. */
|
|
429
152
|
truncationLimit?: number;
|
|
430
|
-
/**
|
|
431
|
-
* Array of tool execution hooks.
|
|
432
|
-
* Hooks run before or after tool calls based on matching conditions.
|
|
433
|
-
* Optional; omit if no tool hooks are needed.
|
|
434
|
-
*/
|
|
153
|
+
/** Array of tool execution hooks. */
|
|
435
154
|
tool?: ToolHook[];
|
|
436
|
-
/**
|
|
437
|
-
* Array of session lifecycle hooks.
|
|
438
|
-
* Hooks run on session events (start, idle, end) based on matching conditions.
|
|
439
|
-
* Optional; omit if no session hooks are needed.
|
|
440
|
-
*/
|
|
155
|
+
/** Array of session lifecycle hooks. */
|
|
441
156
|
session?: SessionHook[];
|
|
442
157
|
}
|
|
443
158
|
/**
|
|
@@ -447,129 +162,44 @@ export interface CommandHooksConfig {
|
|
|
447
162
|
* output, exit code, and any errors that occurred.
|
|
448
163
|
*/
|
|
449
164
|
export interface HookExecutionResult {
|
|
450
|
-
/**
|
|
451
|
-
* ID of the hook that was executed
|
|
452
|
-
*/
|
|
165
|
+
/** ID of the hook that was executed */
|
|
453
166
|
hookId: string;
|
|
454
|
-
/**
|
|
455
|
-
* Whether the hook executed successfully (exit code 0)
|
|
456
|
-
*/
|
|
167
|
+
/** Whether the hook executed successfully (exit code 0) */
|
|
457
168
|
success: boolean;
|
|
458
|
-
/**
|
|
459
|
-
* Exit code from the last command in the hook's run array
|
|
460
|
-
* - 0: success
|
|
461
|
-
* - non-zero: command failed
|
|
462
|
-
* - undefined: command did not execute (e.g., binary not found)
|
|
463
|
-
*/
|
|
169
|
+
/** Exit code from the last command (0 = success, undefined = not executed) */
|
|
464
170
|
exitCode?: number;
|
|
465
|
-
/**
|
|
466
|
-
* Captured standard output from the command(s).
|
|
467
|
-
* Truncated to the configured limit (default 4096 chars).
|
|
468
|
-
* May be empty if command produced no output.
|
|
469
|
-
*/
|
|
171
|
+
/** Captured standard output (truncated to configured limit) */
|
|
470
172
|
stdout?: string;
|
|
471
|
-
/**
|
|
472
|
-
* Captured standard error from the command(s).
|
|
473
|
-
* Truncated to the configured limit (default 4096 chars).
|
|
474
|
-
* May be empty if command produced no error output.
|
|
475
|
-
*/
|
|
173
|
+
/** Captured standard error (truncated to configured limit) */
|
|
476
174
|
stderr?: string;
|
|
477
|
-
/**
|
|
478
|
-
* Error message if the hook failed to execute.
|
|
479
|
-
* Examples:
|
|
480
|
-
* - "Command not found: pnpm"
|
|
481
|
-
* - "Timeout executing hook"
|
|
482
|
-
* - "Failed to inject message into session"
|
|
483
|
-
*/
|
|
175
|
+
/** Error message if the hook failed to execute */
|
|
484
176
|
error?: string;
|
|
485
177
|
}
|
|
486
178
|
/**
|
|
487
179
|
* Context object for template placeholder substitution
|
|
488
180
|
*
|
|
489
181
|
* When injecting hook results into a session, the template string is processed
|
|
490
|
-
* with placeholder substitution using values from this context.
|
|
491
|
-
* optional as not all contexts have all values available.
|
|
492
|
-
*
|
|
493
|
-
* @example
|
|
494
|
-
* ```typescript
|
|
495
|
-
* const context: TemplateContext = {
|
|
496
|
-
* id: "tests-after-task",
|
|
497
|
-
* agent: "build",
|
|
498
|
-
* tool: "task",
|
|
499
|
-
* cmd: "pnpm test --runInBand",
|
|
500
|
-
* stdout: "✓ All tests passed",
|
|
501
|
-
* stderr: "",
|
|
502
|
-
* exitCode: 0
|
|
503
|
-
* }
|
|
504
|
-
*
|
|
505
|
-
* const template = "Hook {id} for {tool} completed: exit {exitCode}"
|
|
506
|
-
* // Result: "Hook tests-after-task for task completed: exit 0"
|
|
507
|
-
* ```
|
|
182
|
+
* with placeholder substitution using values from this context.
|
|
183
|
+
* All fields are optional as not all contexts have all values available.
|
|
508
184
|
*/
|
|
509
185
|
export interface TemplateContext {
|
|
510
|
-
/**
|
|
511
|
-
* Hook ID (always available)
|
|
512
|
-
*/
|
|
186
|
+
/** Hook ID (always available) */
|
|
513
187
|
id: string;
|
|
514
|
-
/**
|
|
515
|
-
* Agent name (available for tool hooks and session hooks)
|
|
516
|
-
* May be undefined if agent context is not available
|
|
517
|
-
*/
|
|
188
|
+
/** Agent name (available for tool and session hooks) */
|
|
518
189
|
agent?: string;
|
|
519
|
-
/**
|
|
520
|
-
* Tool name (available for tool hooks only)
|
|
521
|
-
* May be undefined for session hooks
|
|
522
|
-
*/
|
|
190
|
+
/** Tool name (available for tool hooks only) */
|
|
523
191
|
tool?: string;
|
|
524
|
-
/**
|
|
525
|
-
* Command string that was executed (available when hook runs)
|
|
526
|
-
* May be undefined if command execution failed before running
|
|
527
|
-
*/
|
|
192
|
+
/** Command string that was executed */
|
|
528
193
|
cmd?: string;
|
|
529
|
-
/**
|
|
530
|
-
* Captured standard output from command execution
|
|
531
|
-
* Truncated to configured limit (default 4096 chars)
|
|
532
|
-
* May be undefined or empty if command produced no output
|
|
533
|
-
*/
|
|
194
|
+
/** Captured standard output (truncated to configured limit) */
|
|
534
195
|
stdout?: string;
|
|
535
|
-
/**
|
|
536
|
-
* Captured standard error from command execution
|
|
537
|
-
* Truncated to configured limit (default 4096 chars)
|
|
538
|
-
* May be undefined or empty if command produced no error output
|
|
539
|
-
*/
|
|
196
|
+
/** Captured standard error (truncated to configured limit) */
|
|
540
197
|
stderr?: string;
|
|
541
|
-
/**
|
|
542
|
-
* Exit code from command execution
|
|
543
|
-
* - 0: success
|
|
544
|
-
* - non-zero: command failed
|
|
545
|
-
* May be undefined if command did not execute
|
|
546
|
-
*/
|
|
198
|
+
/** Exit code from command execution (0 = success) */
|
|
547
199
|
exitCode?: number;
|
|
548
|
-
/**
|
|
549
|
-
* Additional context fields for future expansion
|
|
550
|
-
* Examples: subagentSummary, taskResult, etc.
|
|
551
|
-
*/
|
|
200
|
+
/** Additional context fields for future expansion */
|
|
552
201
|
[key: string]: unknown;
|
|
553
202
|
}
|
|
554
|
-
/**
|
|
555
|
-
* Normalized representation of a hook's matching conditions
|
|
556
|
-
*
|
|
557
|
-
* Converts flexible input formats (string | string[]) into consistent
|
|
558
|
-
* array format for easier matching logic.
|
|
559
|
-
*/
|
|
560
|
-
export interface NormalizedToolHookWhen {
|
|
561
|
-
phase: "before" | "after";
|
|
562
|
-
tool: string[];
|
|
563
|
-
callingAgent: string[];
|
|
564
|
-
slashCommand: string[];
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Normalized representation of session hook matching conditions
|
|
568
|
-
*/
|
|
569
|
-
export interface NormalizedSessionHookWhen {
|
|
570
|
-
event: "session.created" | "session.idle" | "session.end";
|
|
571
|
-
agent: string[];
|
|
572
|
-
}
|
|
573
203
|
/**
|
|
574
204
|
* Hook validation error
|
|
575
205
|
*
|
|
@@ -577,74 +207,32 @@ export interface NormalizedSessionHookWhen {
|
|
|
577
207
|
* Used for reporting configuration issues without blocking execution.
|
|
578
208
|
*/
|
|
579
209
|
export interface HookValidationError {
|
|
580
|
-
/**
|
|
581
|
-
* Hook ID (if available; may be undefined if id field is missing)
|
|
582
|
-
*/
|
|
210
|
+
/** Hook ID (if available) */
|
|
583
211
|
hookId?: string;
|
|
584
|
-
/**
|
|
585
|
-
* Type of validation error
|
|
586
|
-
*/
|
|
212
|
+
/** Type of validation error */
|
|
587
213
|
type: "missing_id" | "missing_when" | "missing_run" | "invalid_phase" | "invalid_event" | "invalid_injection_target" | "invalid_injection_as" | "duplicate_id" | "unknown";
|
|
588
|
-
/**
|
|
589
|
-
* Human-readable error message
|
|
590
|
-
*/
|
|
214
|
+
/** Human-readable error message */
|
|
591
215
|
message: string;
|
|
592
|
-
/**
|
|
593
|
-
* Severity level
|
|
594
|
-
*/
|
|
216
|
+
/** Severity level */
|
|
595
217
|
severity: "error" | "warning";
|
|
596
218
|
}
|
|
597
|
-
/**
|
|
598
|
-
* Loaded and merged hooks for a specific context
|
|
599
|
-
*
|
|
600
|
-
* Represents the final set of hooks that apply to a given agent/session/tool call,
|
|
601
|
-
* after merging global and entity-specific hooks with proper precedence.
|
|
602
|
-
*/
|
|
603
|
-
export interface MergedHooksContext {
|
|
604
|
-
/**
|
|
605
|
-
* Tool hooks that apply to this context
|
|
606
|
-
*/
|
|
607
|
-
toolHooks: ToolHook[];
|
|
608
|
-
/**
|
|
609
|
-
* Session hooks that apply to this context
|
|
610
|
-
*/
|
|
611
|
-
sessionHooks: SessionHook[];
|
|
612
|
-
/**
|
|
613
|
-
* Validation errors found during loading/merging
|
|
614
|
-
* Hooks with errors are included but marked for error reporting
|
|
615
|
-
*/
|
|
616
|
-
validationErrors: HookValidationError[];
|
|
617
|
-
}
|
|
618
219
|
/**
|
|
619
220
|
* Hook execution context
|
|
620
221
|
*
|
|
621
222
|
* Information about the current execution context that hooks may need
|
|
622
223
|
*/
|
|
623
224
|
export interface HookExecutionContext {
|
|
624
|
-
/**
|
|
625
|
-
* Current session ID
|
|
626
|
-
*/
|
|
225
|
+
/** Current session ID */
|
|
627
226
|
sessionId: string;
|
|
628
|
-
/**
|
|
629
|
-
* Current agent name
|
|
630
|
-
*/
|
|
227
|
+
/** Current agent name */
|
|
631
228
|
agent: string;
|
|
632
|
-
/**
|
|
633
|
-
* Tool name (for tool hooks)
|
|
634
|
-
*/
|
|
229
|
+
/** Tool name (for tool hooks) */
|
|
635
230
|
tool?: string;
|
|
636
|
-
/**
|
|
637
|
-
* Slash command name (if applicable)
|
|
638
|
-
*/
|
|
231
|
+
/** Slash command name (if applicable) */
|
|
639
232
|
slashCommand?: string;
|
|
640
|
-
/**
|
|
641
|
-
* Tool call ID provided by OpenCode (if available)
|
|
642
|
-
*/
|
|
233
|
+
/** Tool call ID provided by OpenCode (if available) */
|
|
643
234
|
callId?: string;
|
|
644
|
-
/**
|
|
645
|
-
* Tool arguments (available for tool.execute.before hooks)
|
|
646
|
-
* For task tool, this includes: description, prompt, subagentType
|
|
647
|
-
*/
|
|
235
|
+
/** Tool arguments (available for tool.execute.before hooks) */
|
|
648
236
|
toolArgs?: Record<string, unknown>;
|
|
649
237
|
}
|
|
650
238
|
//# sourceMappingURL=hooks.d.ts.map
|