@goodfoot/agent-hooks 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 +137 -0
- package/dist/agents/antigravity/events.js +42 -0
- package/dist/agents/antigravity/hooks.js +59 -0
- package/dist/agents/antigravity/index.js +28 -0
- package/dist/agents/antigravity/outputs.js +81 -0
- package/dist/agents/antigravity/transport.js +84 -0
- package/dist/agents/antigravity/types.js +11 -0
- package/dist/agents/claude-code/env.js +27 -0
- package/dist/agents/claude-code/events.js +87 -0
- package/dist/agents/claude-code/hooks.js +1000 -0
- package/dist/agents/claude-code/index.js +57 -0
- package/dist/agents/claude-code/outputs.js +579 -0
- package/dist/agents/claude-code/tool-helpers.js +840 -0
- package/dist/agents/claude-code/transport.js +254 -0
- package/dist/agents/claude-code/types.js +11 -0
- package/dist/agents/codex/cli-support.js +318 -0
- package/dist/agents/codex/constants.js +29 -0
- package/dist/agents/codex/events.js +68 -0
- package/dist/agents/codex/hooks.js +93 -0
- package/dist/agents/codex/index.js +21 -0
- package/dist/agents/codex/outputs.js +189 -0
- package/dist/agents/codex/scaffold.js +273 -0
- package/dist/agents/codex/transport.js +139 -0
- package/dist/agents/codex/types.js +1 -0
- package/dist/cli.js +1357 -0
- package/dist/constants.js +39 -0
- package/dist/core/define-hook.js +61 -0
- package/dist/core/env.js +186 -0
- package/dist/core/logger.js +508 -0
- package/dist/core/stdin.js +38 -0
- package/dist/core/transport.js +231 -0
- package/dist/core/types.js +10 -0
- package/dist/index.js +17 -0
- package/dist/scaffold.js +512 -0
- package/package.json +61 -0
- package/types/agents/antigravity/events.d.ts +50 -0
- package/types/agents/antigravity/hooks.d.ts +76 -0
- package/types/agents/antigravity/index.d.ts +27 -0
- package/types/agents/antigravity/outputs.d.ts +107 -0
- package/types/agents/antigravity/transport.d.ts +47 -0
- package/types/agents/antigravity/types.d.ts +58 -0
- package/types/agents/claude-code/env.d.ts +27 -0
- package/types/agents/claude-code/events.d.ts +69 -0
- package/types/agents/claude-code/hooks.d.ts +1182 -0
- package/types/agents/claude-code/index.d.ts +23 -0
- package/types/agents/claude-code/outputs.d.ts +1160 -0
- package/types/agents/claude-code/tool-helpers.d.ts +807 -0
- package/types/agents/claude-code/transport.d.ts +119 -0
- package/types/agents/claude-code/types.d.ts +557 -0
- package/types/agents/codex/cli-support.d.ts +105 -0
- package/types/agents/codex/constants.d.ts +10 -0
- package/types/agents/codex/events.d.ts +63 -0
- package/types/agents/codex/hooks.d.ts +135 -0
- package/types/agents/codex/index.d.ts +19 -0
- package/types/agents/codex/outputs.d.ts +190 -0
- package/types/agents/codex/scaffold.d.ts +14 -0
- package/types/agents/codex/transport.d.ts +74 -0
- package/types/agents/codex/types.d.ts +131 -0
- package/types/cli.d.ts +315 -0
- package/types/constants.d.ts +9 -0
- package/types/core/define-hook.d.ts +39 -0
- package/types/core/env.d.ts +150 -0
- package/types/core/logger.d.ts +476 -0
- package/types/core/stdin.d.ts +21 -0
- package/types/core/transport.d.ts +131 -0
- package/types/core/types.d.ts +137 -0
- package/types/index.d.ts +18 -0
- package/types/scaffold.d.ts +46 -0
|
@@ -0,0 +1,1160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output types and builders for Claude Code hooks.
|
|
3
|
+
*
|
|
4
|
+
* Provides type-safe output builder functions for all 30 hook types. Each builder
|
|
5
|
+
* accepts options that match the wire format expected by Claude Code, with types
|
|
6
|
+
* derived from the Claude Agent SDK's `SyncHookJSONOutput` type.
|
|
7
|
+
* @see https://code.claude.com/docs/en/hooks
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { CwdChangedHookSpecificOutput as SDKCwdChangedHookSpecificOutput, ElicitationHookSpecificOutput as SDKElicitationHookSpecificOutput, ElicitationResultHookSpecificOutput as SDKElicitationResultHookSpecificOutput, FileChangedHookSpecificOutput as SDKFileChangedHookSpecificOutput, MessageDisplayHookSpecificOutput as SDKMessageDisplayHookSpecificOutput, NotificationHookSpecificOutput as SDKNotificationHookSpecificOutput, PermissionDeniedHookSpecificOutput as SDKPermissionDeniedHookSpecificOutput, PermissionRequestHookSpecificOutput as SDKPermissionRequestHookSpecificOutput, PostToolBatchHookSpecificOutput as SDKPostToolBatchHookSpecificOutput, PostToolUseFailureHookSpecificOutput as SDKPostToolUseFailureHookSpecificOutput, PostToolUseHookSpecificOutput as SDKPostToolUseHookSpecificOutput, PreToolUseHookSpecificOutput as SDKPreToolUseHookSpecificOutput, SessionStartHookSpecificOutput as SDKSessionStartHookSpecificOutput, SetupHookSpecificOutput as SDKSetupHookSpecificOutput, SubagentStartHookSpecificOutput as SDKSubagentStartHookSpecificOutput, SyncHookJSONOutput as SDKSyncHookJSONOutput, UserPromptExpansionHookSpecificOutput as SDKUserPromptExpansionHookSpecificOutput, UserPromptSubmitHookSpecificOutput as SDKUserPromptSubmitHookSpecificOutput, WorktreeCreateHookSpecificOutput as SDKWorktreeCreateHookSpecificOutput } from "@anthropic-ai/claude-agent-sdk";
|
|
11
|
+
/**
|
|
12
|
+
* Exit codes used by Claude Code hooks.
|
|
13
|
+
*
|
|
14
|
+
* | Exit Code | Name | When Used | Claude Code Behavior |
|
|
15
|
+
* |-----------|------|-----------|---------------------|
|
|
16
|
+
* | 0 | Success | Handler returns normally | Continue, parse stdout as JSON |
|
|
17
|
+
* | 1 | Error | Invalid input, non-blocking error | Non-blocking, stderr to user only |
|
|
18
|
+
* | 2 | Block | Handler throws OR `stopReason` set | Blocking, stderr shown to Claude |
|
|
19
|
+
*/
|
|
20
|
+
export declare const EXIT_CODES: {
|
|
21
|
+
/** Handler completed successfully. Claude Code parses stdout as JSON. */
|
|
22
|
+
readonly SUCCESS: 0;
|
|
23
|
+
/** Non-blocking error occurred (e.g., invalid input). stderr shown to user only. */
|
|
24
|
+
readonly ERROR: 1;
|
|
25
|
+
/** Handler threw exception OR blocking action requested. stderr shown to Claude. */
|
|
26
|
+
readonly BLOCK: 2;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Exit code type.
|
|
30
|
+
*/
|
|
31
|
+
export type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];
|
|
32
|
+
/**
|
|
33
|
+
* Re-export the SDK's SyncHookJSONOutput type.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Re-export SDK hook-specific output types (includes hookEventName discriminator).
|
|
37
|
+
*/
|
|
38
|
+
export type { SDKCwdChangedHookSpecificOutput, SDKElicitationHookSpecificOutput, SDKElicitationResultHookSpecificOutput, SDKFileChangedHookSpecificOutput, SDKMessageDisplayHookSpecificOutput, SDKNotificationHookSpecificOutput, SDKPermissionDeniedHookSpecificOutput, SDKPermissionRequestHookSpecificOutput, SDKPostToolUseFailureHookSpecificOutput, SDKPostToolUseHookSpecificOutput, SDKPreToolUseHookSpecificOutput, SDKSessionStartHookSpecificOutput, SDKSetupHookSpecificOutput, SDKSubagentStartHookSpecificOutput, SDKSyncHookJSONOutput, SDKUserPromptSubmitHookSpecificOutput, };
|
|
39
|
+
/**
|
|
40
|
+
* PreToolUse hook-specific output fields.
|
|
41
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
42
|
+
*/
|
|
43
|
+
export type PreToolUseHookSpecificOutput = Omit<SDKPreToolUseHookSpecificOutput, "hookEventName">;
|
|
44
|
+
/**
|
|
45
|
+
* PostToolUse hook-specific output fields.
|
|
46
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
47
|
+
*/
|
|
48
|
+
export type PostToolUseHookSpecificOutput = Omit<SDKPostToolUseHookSpecificOutput, "hookEventName">;
|
|
49
|
+
/**
|
|
50
|
+
* PostToolUseFailure hook-specific output fields.
|
|
51
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
52
|
+
*/
|
|
53
|
+
export type PostToolUseFailureHookSpecificOutput = Omit<SDKPostToolUseFailureHookSpecificOutput, "hookEventName">;
|
|
54
|
+
/**
|
|
55
|
+
* PostToolBatch hook-specific output fields.
|
|
56
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
57
|
+
*/
|
|
58
|
+
export type PostToolBatchHookSpecificOutput = Omit<SDKPostToolBatchHookSpecificOutput, "hookEventName">;
|
|
59
|
+
/**
|
|
60
|
+
* UserPromptExpansion hook-specific output fields.
|
|
61
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
62
|
+
*/
|
|
63
|
+
export type UserPromptExpansionHookSpecificOutput = Omit<SDKUserPromptExpansionHookSpecificOutput, "hookEventName">;
|
|
64
|
+
/**
|
|
65
|
+
* UserPromptSubmit hook-specific output fields.
|
|
66
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
67
|
+
*/
|
|
68
|
+
export type UserPromptSubmitHookSpecificOutput = Omit<SDKUserPromptSubmitHookSpecificOutput, "hookEventName">;
|
|
69
|
+
/**
|
|
70
|
+
* SessionStart hook-specific output fields.
|
|
71
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
72
|
+
*/
|
|
73
|
+
export type SessionStartHookSpecificOutput = Omit<SDKSessionStartHookSpecificOutput, "hookEventName">;
|
|
74
|
+
/**
|
|
75
|
+
* SubagentStart hook-specific output fields.
|
|
76
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
77
|
+
*/
|
|
78
|
+
export type SubagentStartHookSpecificOutput = Omit<SDKSubagentStartHookSpecificOutput, "hookEventName">;
|
|
79
|
+
/**
|
|
80
|
+
* PermissionRequest hook-specific output fields.
|
|
81
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
82
|
+
*/
|
|
83
|
+
export type PermissionRequestHookSpecificOutput = Omit<SDKPermissionRequestHookSpecificOutput, "hookEventName">;
|
|
84
|
+
/**
|
|
85
|
+
* Setup hook-specific output fields.
|
|
86
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
87
|
+
*/
|
|
88
|
+
export type SetupHookSpecificOutput = Omit<SDKSetupHookSpecificOutput, "hookEventName">;
|
|
89
|
+
/**
|
|
90
|
+
* Elicitation hook-specific output fields.
|
|
91
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
92
|
+
*/
|
|
93
|
+
export type ElicitationHookSpecificOutput = Omit<SDKElicitationHookSpecificOutput, "hookEventName">;
|
|
94
|
+
/**
|
|
95
|
+
* ElicitationResult hook-specific output fields.
|
|
96
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
97
|
+
*/
|
|
98
|
+
export type ElicitationResultHookSpecificOutput = Omit<SDKElicitationResultHookSpecificOutput, "hookEventName">;
|
|
99
|
+
/**
|
|
100
|
+
* PermissionDenied hook-specific output fields.
|
|
101
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
102
|
+
*/
|
|
103
|
+
export type PermissionDeniedHookSpecificOutput = Omit<SDKPermissionDeniedHookSpecificOutput, "hookEventName">;
|
|
104
|
+
/**
|
|
105
|
+
* Allow decision for permission requests.
|
|
106
|
+
* Derived from SDK's PermissionRequestHookSpecificOutput.
|
|
107
|
+
*/
|
|
108
|
+
export type PermissionRequestAllowDecision = Extract<SDKPermissionRequestHookSpecificOutput["decision"], {
|
|
109
|
+
behavior: "allow";
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Deny decision for permission requests.
|
|
113
|
+
* Derived from SDK's PermissionRequestHookSpecificOutput.
|
|
114
|
+
*/
|
|
115
|
+
export type PermissionRequestDenyDecision = Extract<SDKPermissionRequestHookSpecificOutput["decision"], {
|
|
116
|
+
behavior: "deny";
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Permission request decision - either allow or deny.
|
|
120
|
+
* Derived from SDK's PermissionRequestHookSpecificOutput.
|
|
121
|
+
*/
|
|
122
|
+
export type PermissionRequestDecision = SDKPermissionRequestHookSpecificOutput["decision"];
|
|
123
|
+
/**
|
|
124
|
+
* Notification hook-specific output fields.
|
|
125
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
126
|
+
*/
|
|
127
|
+
export type NotificationHookSpecificOutput = Omit<SDKNotificationHookSpecificOutput, "hookEventName">;
|
|
128
|
+
/**
|
|
129
|
+
* CwdChanged hook-specific output fields.
|
|
130
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
131
|
+
*/
|
|
132
|
+
export type CwdChangedHookSpecificOutput = Omit<SDKCwdChangedHookSpecificOutput, "hookEventName">;
|
|
133
|
+
/**
|
|
134
|
+
* FileChanged hook-specific output fields.
|
|
135
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
136
|
+
*/
|
|
137
|
+
export type FileChangedHookSpecificOutput = Omit<SDKFileChangedHookSpecificOutput, "hookEventName">;
|
|
138
|
+
/**
|
|
139
|
+
* MessageDisplay hook-specific output fields.
|
|
140
|
+
* Omits `hookEventName` which is added automatically by the builder.
|
|
141
|
+
*/
|
|
142
|
+
export type MessageDisplayHookSpecificOutput = Omit<SDKMessageDisplayHookSpecificOutput, "hookEventName">;
|
|
143
|
+
/**
|
|
144
|
+
* Full hook-specific output with hookEventName discriminator.
|
|
145
|
+
*/
|
|
146
|
+
export type HookSpecificOutput = SDKPreToolUseHookSpecificOutput | SDKPostToolUseHookSpecificOutput | SDKPostToolUseFailureHookSpecificOutput | SDKPostToolBatchHookSpecificOutput | SDKUserPromptExpansionHookSpecificOutput | SDKUserPromptSubmitHookSpecificOutput | SDKSessionStartHookSpecificOutput | SDKSetupHookSpecificOutput | SDKSubagentStartHookSpecificOutput | SDKPermissionRequestHookSpecificOutput | SDKPermissionDeniedHookSpecificOutput | SDKNotificationHookSpecificOutput | SDKElicitationHookSpecificOutput | SDKElicitationResultHookSpecificOutput | SDKCwdChangedHookSpecificOutput | SDKFileChangedHookSpecificOutput | SDKMessageDisplayHookSpecificOutput;
|
|
147
|
+
/**
|
|
148
|
+
* The JSON output format expected by Claude Code (sync hooks only).
|
|
149
|
+
* Extends SDK's SyncHookJSONOutput to include Notification hook support.
|
|
150
|
+
*/
|
|
151
|
+
export interface SyncHookJSONOutput {
|
|
152
|
+
/** If true, continue processing even after errors. */
|
|
153
|
+
continue?: boolean;
|
|
154
|
+
/** If true, suppress the hook's output from being displayed. */
|
|
155
|
+
suppressOutput?: boolean;
|
|
156
|
+
/** Reason for stopping the session (when blocking). */
|
|
157
|
+
stopReason?: string;
|
|
158
|
+
/** Decision for Stop/SubagentStop hooks: 'approve' allows stop, 'block' prevents it. */
|
|
159
|
+
decision?: "approve" | "block";
|
|
160
|
+
/** System message to inject into Claude's context. */
|
|
161
|
+
systemMessage?: string;
|
|
162
|
+
/** Reason shown to Claude when blocking. */
|
|
163
|
+
reason?: string;
|
|
164
|
+
/** Hook-specific output based on the hook type. */
|
|
165
|
+
hookSpecificOutput?: HookSpecificOutput;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The result of a hook handler, ready for the runtime to process.
|
|
169
|
+
* Exit code is always SUCCESS (0) - blocking behavior is communicated via stdout fields.
|
|
170
|
+
*/
|
|
171
|
+
export interface HookOutput {
|
|
172
|
+
/** JSON-serializable output to write to stdout. */
|
|
173
|
+
stdout: SyncHookJSONOutput;
|
|
174
|
+
/** Optional message to write to stderr. When present, the runtime exits with code 2 (BLOCK). */
|
|
175
|
+
stderr?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Plain-text payload written verbatim to stdout instead of `JSON.stringify(stdout)`.
|
|
178
|
+
* When present, the runtime emits this string and ignores `stdout`. See
|
|
179
|
+
* {@link BaseSpecificOutput.rawStdout}.
|
|
180
|
+
*/
|
|
181
|
+
rawStdout?: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Common options available to all output builders.
|
|
185
|
+
* These map directly to the wire format fields.
|
|
186
|
+
*/
|
|
187
|
+
export interface CommonOptions {
|
|
188
|
+
/** If true, continue processing even after errors. */
|
|
189
|
+
continue?: boolean;
|
|
190
|
+
/** If true, suppress the hook's output from being displayed. */
|
|
191
|
+
suppressOutput?: boolean;
|
|
192
|
+
/** System message to inject into Claude's context. */
|
|
193
|
+
systemMessage?: string;
|
|
194
|
+
/** Reason for stopping/blocking (sets exit code to BLOCK). */
|
|
195
|
+
stopReason?: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Options for exit-code-based hooks (TeammateIdle, TaskCompleted).
|
|
199
|
+
*
|
|
200
|
+
* These hooks use exit codes only, not JSON decision control.
|
|
201
|
+
* When `stderr` is provided, the runtime writes it to stderr and exits with code 2 (BLOCK).
|
|
202
|
+
* No stdout is written on this path: Claude Code's hook-result parser treats any stdout
|
|
203
|
+
* that parses as valid JSON as a success outcome regardless of exit code, so blocking
|
|
204
|
+
* only takes effect when stdout carries no JSON at all.
|
|
205
|
+
* When absent, the hook exits with code 0 (SUCCESS).
|
|
206
|
+
*/
|
|
207
|
+
export interface ExitCodeOptions {
|
|
208
|
+
/** Message to write to stderr. When present, exits with code 2 (BLOCK). */
|
|
209
|
+
stderr?: string;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Base structure for all specific outputs.
|
|
213
|
+
*/
|
|
214
|
+
interface BaseSpecificOutput<T extends string> {
|
|
215
|
+
readonly _type: T;
|
|
216
|
+
stdout: SyncHookJSONOutput;
|
|
217
|
+
stderr?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Plain-text payload written verbatim to stdout instead of `JSON.stringify(stdout)`.
|
|
220
|
+
*
|
|
221
|
+
* Used by command hooks whose wire protocol is a bare string rather than JSON —
|
|
222
|
+
* notably `WorktreeCreate`/`WorktreeRemove`, where Claude Code reads stdout as the
|
|
223
|
+
* worktree path and `chdir`s into it. When present, the runtime emits this string
|
|
224
|
+
* and ignores `stdout`.
|
|
225
|
+
*/
|
|
226
|
+
rawStdout?: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
*
|
|
230
|
+
*/
|
|
231
|
+
export type PreToolUseOutput = BaseSpecificOutput<"PreToolUse">;
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
*/
|
|
235
|
+
export type PostToolUseOutput = BaseSpecificOutput<"PostToolUse">;
|
|
236
|
+
/**
|
|
237
|
+
*
|
|
238
|
+
*/
|
|
239
|
+
export type PostToolUseFailureOutput = BaseSpecificOutput<"PostToolUseFailure">;
|
|
240
|
+
/**
|
|
241
|
+
*
|
|
242
|
+
*/
|
|
243
|
+
export type PostToolBatchOutput = BaseSpecificOutput<"PostToolBatch">;
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
*/
|
|
247
|
+
export type NotificationOutput = BaseSpecificOutput<"Notification">;
|
|
248
|
+
/**
|
|
249
|
+
*
|
|
250
|
+
*/
|
|
251
|
+
export type UserPromptExpansionOutput = BaseSpecificOutput<"UserPromptExpansion">;
|
|
252
|
+
/**
|
|
253
|
+
*
|
|
254
|
+
*/
|
|
255
|
+
export type UserPromptSubmitOutput = BaseSpecificOutput<"UserPromptSubmit">;
|
|
256
|
+
/**
|
|
257
|
+
*
|
|
258
|
+
*/
|
|
259
|
+
export type SessionStartOutput = BaseSpecificOutput<"SessionStart">;
|
|
260
|
+
/**
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
export type SessionEndOutput = BaseSpecificOutput<"SessionEnd">;
|
|
264
|
+
/**
|
|
265
|
+
*
|
|
266
|
+
*/
|
|
267
|
+
export type StopOutput = BaseSpecificOutput<"Stop">;
|
|
268
|
+
/**
|
|
269
|
+
*
|
|
270
|
+
*/
|
|
271
|
+
export type StopFailureOutput = BaseSpecificOutput<"StopFailure">;
|
|
272
|
+
/**
|
|
273
|
+
*
|
|
274
|
+
*/
|
|
275
|
+
export type SubagentStartOutput = BaseSpecificOutput<"SubagentStart">;
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
*/
|
|
279
|
+
export type SubagentStopOutput = BaseSpecificOutput<"SubagentStop">;
|
|
280
|
+
/**
|
|
281
|
+
*
|
|
282
|
+
*/
|
|
283
|
+
export type PreCompactOutput = BaseSpecificOutput<"PreCompact">;
|
|
284
|
+
/**
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
287
|
+
export type PostCompactOutput = BaseSpecificOutput<"PostCompact">;
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
*/
|
|
291
|
+
export type PermissionRequestOutput = BaseSpecificOutput<"PermissionRequest">;
|
|
292
|
+
/**
|
|
293
|
+
*
|
|
294
|
+
*/
|
|
295
|
+
export type PermissionDeniedOutput = BaseSpecificOutput<"PermissionDenied">;
|
|
296
|
+
/**
|
|
297
|
+
*
|
|
298
|
+
*/
|
|
299
|
+
export type SetupOutput = BaseSpecificOutput<"Setup">;
|
|
300
|
+
/**
|
|
301
|
+
*
|
|
302
|
+
*/
|
|
303
|
+
export type TeammateIdleOutput = BaseSpecificOutput<"TeammateIdle">;
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
*/
|
|
307
|
+
export type TaskCreatedOutput = BaseSpecificOutput<"TaskCreated">;
|
|
308
|
+
/**
|
|
309
|
+
*
|
|
310
|
+
*/
|
|
311
|
+
export type TaskCompletedOutput = BaseSpecificOutput<"TaskCompleted">;
|
|
312
|
+
/**
|
|
313
|
+
*
|
|
314
|
+
*/
|
|
315
|
+
export type ElicitationOutput = BaseSpecificOutput<"Elicitation">;
|
|
316
|
+
/**
|
|
317
|
+
*
|
|
318
|
+
*/
|
|
319
|
+
export type ElicitationResultOutput = BaseSpecificOutput<"ElicitationResult">;
|
|
320
|
+
/**
|
|
321
|
+
*
|
|
322
|
+
*/
|
|
323
|
+
export type ConfigChangeOutput = BaseSpecificOutput<"ConfigChange">;
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
*/
|
|
327
|
+
export type InstructionsLoadedOutput = BaseSpecificOutput<"InstructionsLoaded">;
|
|
328
|
+
/**
|
|
329
|
+
*
|
|
330
|
+
*/
|
|
331
|
+
export type WorktreeCreateOutput = BaseSpecificOutput<"WorktreeCreate">;
|
|
332
|
+
/**
|
|
333
|
+
*
|
|
334
|
+
*/
|
|
335
|
+
export type WorktreeRemoveOutput = BaseSpecificOutput<"WorktreeRemove">;
|
|
336
|
+
/**
|
|
337
|
+
*
|
|
338
|
+
*/
|
|
339
|
+
export type CwdChangedOutput = BaseSpecificOutput<"CwdChanged">;
|
|
340
|
+
/**
|
|
341
|
+
*
|
|
342
|
+
*/
|
|
343
|
+
export type FileChangedOutput = BaseSpecificOutput<"FileChanged">;
|
|
344
|
+
/**
|
|
345
|
+
*
|
|
346
|
+
*/
|
|
347
|
+
export type MessageDisplayOutput = BaseSpecificOutput<"MessageDisplay">;
|
|
348
|
+
/**
|
|
349
|
+
* Union of all specific output types.
|
|
350
|
+
*/
|
|
351
|
+
export type SpecificHookOutput = PreToolUseOutput | PostToolUseOutput | PostToolUseFailureOutput | PostToolBatchOutput | NotificationOutput | UserPromptExpansionOutput | UserPromptSubmitOutput | SessionStartOutput | SessionEndOutput | StopOutput | StopFailureOutput | SubagentStartOutput | SubagentStopOutput | PreCompactOutput | PostCompactOutput | PermissionRequestOutput | PermissionDeniedOutput | SetupOutput | TeammateIdleOutput | TaskCreatedOutput | TaskCompletedOutput | ElicitationOutput | ElicitationResultOutput | ConfigChangeOutput | InstructionsLoadedOutput | WorktreeCreateOutput | WorktreeRemoveOutput | CwdChangedOutput | FileChangedOutput | MessageDisplayOutput;
|
|
352
|
+
/**
|
|
353
|
+
* Options for decision-based hooks (Stop, SubagentStop).
|
|
354
|
+
*/
|
|
355
|
+
interface DecisionOptions extends CommonOptions {
|
|
356
|
+
/** Decision: 'approve' allows the action, 'block' prevents it. */
|
|
357
|
+
decision?: "approve" | "block";
|
|
358
|
+
/** Reason for the decision (shown to Claude when blocking). */
|
|
359
|
+
reason?: string;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Options for the PreToolUse output builder.
|
|
363
|
+
* Uses wire format: hookSpecificOutput with permissionDecision.
|
|
364
|
+
*/
|
|
365
|
+
export type PreToolUseOptions = CommonOptions & {
|
|
366
|
+
/** Hook-specific output matching the wire format. */
|
|
367
|
+
hookSpecificOutput?: PreToolUseHookSpecificOutput;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Creates an output for PreToolUse hooks.
|
|
371
|
+
* @param options - Configuration options for the hook output
|
|
372
|
+
* @returns A PreToolUseOutput object ready for the runtime
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* // Allow tool execution
|
|
376
|
+
* preToolUseOutput({
|
|
377
|
+
* hookSpecificOutput: { permissionDecision: 'allow' }
|
|
378
|
+
* });
|
|
379
|
+
*
|
|
380
|
+
* // Deny with reason
|
|
381
|
+
* preToolUseOutput({
|
|
382
|
+
* hookSpecificOutput: {
|
|
383
|
+
* permissionDecision: 'deny',
|
|
384
|
+
* permissionDecisionReason: 'Dangerous command detected'
|
|
385
|
+
* }
|
|
386
|
+
* });
|
|
387
|
+
*
|
|
388
|
+
* // Allow with modified input
|
|
389
|
+
* preToolUseOutput({
|
|
390
|
+
* hookSpecificOutput: {
|
|
391
|
+
* permissionDecision: 'allow',
|
|
392
|
+
* updatedInput: { command: 'ls -la' }
|
|
393
|
+
* }
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export declare const preToolUseOutput: (options?: CommonOptions & {
|
|
398
|
+
hookSpecificOutput?: PreToolUseHookSpecificOutput | undefined;
|
|
399
|
+
}) => {
|
|
400
|
+
readonly _type: "PreToolUse";
|
|
401
|
+
stdout: SyncHookJSONOutput;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Options for the PostToolUse output builder.
|
|
405
|
+
*/
|
|
406
|
+
export type PostToolUseOptions = CommonOptions & {
|
|
407
|
+
/** Hook-specific output matching the wire format. */
|
|
408
|
+
hookSpecificOutput?: PostToolUseHookSpecificOutput;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Creates an output for PostToolUse hooks.
|
|
412
|
+
* @param options - Configuration options for the hook output
|
|
413
|
+
* @returns A PostToolUseOutput object ready for the runtime
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // Add context after a file read
|
|
417
|
+
* postToolUseOutput({
|
|
418
|
+
* hookSpecificOutput: {
|
|
419
|
+
* additionalContext: 'File contains sensitive data'
|
|
420
|
+
* }
|
|
421
|
+
* });
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
export declare const postToolUseOutput: (options?: CommonOptions & {
|
|
425
|
+
hookSpecificOutput?: PostToolUseHookSpecificOutput | undefined;
|
|
426
|
+
}) => {
|
|
427
|
+
readonly _type: "PostToolUse";
|
|
428
|
+
stdout: SyncHookJSONOutput;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Options for the PostToolUseFailure output builder.
|
|
432
|
+
*/
|
|
433
|
+
export type PostToolUseFailureOptions = CommonOptions & {
|
|
434
|
+
/** Hook-specific output matching the wire format. */
|
|
435
|
+
hookSpecificOutput?: PostToolUseFailureHookSpecificOutput;
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* Creates an output for PostToolUseFailure hooks.
|
|
439
|
+
* @param options - Configuration options for the hook output
|
|
440
|
+
* @returns A PostToolUseFailureOutput object ready for the runtime
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* postToolUseFailureOutput({
|
|
444
|
+
* hookSpecificOutput: {
|
|
445
|
+
* additionalContext: 'Try using a different approach'
|
|
446
|
+
* }
|
|
447
|
+
* });
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
export declare const postToolUseFailureOutput: (options?: CommonOptions & {
|
|
451
|
+
hookSpecificOutput?: PostToolUseFailureHookSpecificOutput | undefined;
|
|
452
|
+
}) => {
|
|
453
|
+
readonly _type: "PostToolUseFailure";
|
|
454
|
+
stdout: SyncHookJSONOutput;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Options for the PostToolBatch output builder.
|
|
458
|
+
*/
|
|
459
|
+
export type PostToolBatchOptions = CommonOptions & {
|
|
460
|
+
/** Hook-specific output matching the wire format. */
|
|
461
|
+
hookSpecificOutput?: PostToolBatchHookSpecificOutput;
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Creates an output for PostToolBatch hooks.
|
|
465
|
+
* @param options - Configuration options for the hook output
|
|
466
|
+
* @returns A PostToolBatchOutput object ready for the runtime
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* postToolBatchOutput({
|
|
470
|
+
* hookSpecificOutput: {
|
|
471
|
+
* additionalContext: 'All edits in the batch were applied successfully'
|
|
472
|
+
* }
|
|
473
|
+
* });
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
export declare const postToolBatchOutput: (options?: CommonOptions & {
|
|
477
|
+
hookSpecificOutput?: PostToolBatchHookSpecificOutput | undefined;
|
|
478
|
+
}) => {
|
|
479
|
+
readonly _type: "PostToolBatch";
|
|
480
|
+
stdout: SyncHookJSONOutput;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Options for the UserPromptExpansion output builder.
|
|
484
|
+
*/
|
|
485
|
+
export type UserPromptExpansionOptions = CommonOptions & {
|
|
486
|
+
/** Hook-specific output matching the wire format. */
|
|
487
|
+
hookSpecificOutput?: UserPromptExpansionHookSpecificOutput;
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Creates an output for UserPromptExpansion hooks.
|
|
491
|
+
* @param options - Configuration options for the hook output
|
|
492
|
+
* @returns A UserPromptExpansionOutput object ready for the runtime
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* userPromptExpansionOutput({
|
|
496
|
+
* hookSpecificOutput: {
|
|
497
|
+
* additionalContext: 'Slash command expanded with additional context'
|
|
498
|
+
* }
|
|
499
|
+
* });
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
export declare const userPromptExpansionOutput: (options?: CommonOptions & {
|
|
503
|
+
hookSpecificOutput?: UserPromptExpansionHookSpecificOutput | undefined;
|
|
504
|
+
}) => {
|
|
505
|
+
readonly _type: "UserPromptExpansion";
|
|
506
|
+
stdout: SyncHookJSONOutput;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Options for the UserPromptSubmit output builder.
|
|
510
|
+
*/
|
|
511
|
+
export type UserPromptSubmitOptions = CommonOptions & {
|
|
512
|
+
/** Hook-specific output matching the wire format. */
|
|
513
|
+
hookSpecificOutput?: UserPromptSubmitHookSpecificOutput;
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Creates an output for UserPromptSubmit hooks.
|
|
517
|
+
* @param options - Configuration options for the hook output
|
|
518
|
+
* @returns A UserPromptSubmitOutput object ready for the runtime
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* userPromptSubmitOutput({
|
|
522
|
+
* hookSpecificOutput: {
|
|
523
|
+
* additionalContext: 'This project uses TypeScript strict mode'
|
|
524
|
+
* }
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
export declare const userPromptSubmitOutput: (options?: CommonOptions & {
|
|
529
|
+
hookSpecificOutput?: UserPromptSubmitHookSpecificOutput | undefined;
|
|
530
|
+
}) => {
|
|
531
|
+
readonly _type: "UserPromptSubmit";
|
|
532
|
+
stdout: SyncHookJSONOutput;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Options for the SessionStart output builder.
|
|
536
|
+
*/
|
|
537
|
+
export type SessionStartOptions = CommonOptions & {
|
|
538
|
+
/** Hook-specific output matching the wire format. */
|
|
539
|
+
hookSpecificOutput?: SessionStartHookSpecificOutput;
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* Creates an output for SessionStart hooks.
|
|
543
|
+
* @param options - Configuration options for the hook output
|
|
544
|
+
* @returns A SessionStartOutput object ready for the runtime
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* sessionStartOutput({
|
|
548
|
+
* hookSpecificOutput: {
|
|
549
|
+
* additionalContext: JSON.stringify({ project: 'my-project' })
|
|
550
|
+
* }
|
|
551
|
+
* });
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
export declare const sessionStartOutput: (options?: CommonOptions & {
|
|
555
|
+
hookSpecificOutput?: SessionStartHookSpecificOutput | undefined;
|
|
556
|
+
}) => {
|
|
557
|
+
readonly _type: "SessionStart";
|
|
558
|
+
stdout: SyncHookJSONOutput;
|
|
559
|
+
};
|
|
560
|
+
/**
|
|
561
|
+
* Options for the SessionEnd output builder.
|
|
562
|
+
* SessionEnd hooks only support common options.
|
|
563
|
+
*/
|
|
564
|
+
export type SessionEndOptions = CommonOptions;
|
|
565
|
+
/**
|
|
566
|
+
* Creates an output for SessionEnd hooks.
|
|
567
|
+
* @param options - Configuration options for the hook output
|
|
568
|
+
* @returns A SessionEndOutput object ready for the runtime
|
|
569
|
+
* @example
|
|
570
|
+
* ```typescript
|
|
571
|
+
* sessionEndOutput({});
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
export declare const sessionEndOutput: (options?: CommonOptions) => {
|
|
575
|
+
readonly _type: "SessionEnd";
|
|
576
|
+
stdout: SyncHookJSONOutput;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Options for the Stop output builder.
|
|
580
|
+
*/
|
|
581
|
+
export interface StopOptions extends CommonOptions {
|
|
582
|
+
/** Decision: 'approve' allows stop, 'block' prevents it. */
|
|
583
|
+
decision?: "approve" | "block";
|
|
584
|
+
/** Reason for the decision (shown to Claude when blocking). */
|
|
585
|
+
reason?: string;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Creates an output for Stop hooks.
|
|
589
|
+
* @param options - Configuration options for the hook output
|
|
590
|
+
* @returns A StopOutput object ready for the runtime
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* // Allow the stop
|
|
594
|
+
* stopOutput({ decision: 'approve' });
|
|
595
|
+
*
|
|
596
|
+
* // Block with reason
|
|
597
|
+
* stopOutput({
|
|
598
|
+
* decision: 'block',
|
|
599
|
+
* reason: 'There are uncommitted changes'
|
|
600
|
+
* });
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
export declare const stopOutput: (options?: DecisionOptions) => {
|
|
604
|
+
readonly _type: "Stop";
|
|
605
|
+
stdout: SyncHookJSONOutput;
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
* Options for the StopFailure output builder.
|
|
609
|
+
* StopFailure hooks only support common options.
|
|
610
|
+
*/
|
|
611
|
+
export type StopFailureOptions = CommonOptions;
|
|
612
|
+
/**
|
|
613
|
+
* Creates an output for StopFailure hooks.
|
|
614
|
+
* @param options - Configuration options for the hook output
|
|
615
|
+
* @returns A StopFailureOutput object ready for the runtime
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* stopFailureOutput({});
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
export declare const stopFailureOutput: (options?: CommonOptions) => {
|
|
622
|
+
readonly _type: "StopFailure";
|
|
623
|
+
stdout: SyncHookJSONOutput;
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Options for the SubagentStart output builder.
|
|
627
|
+
*/
|
|
628
|
+
export type SubagentStartOptions = CommonOptions & {
|
|
629
|
+
/** Hook-specific output matching the wire format. */
|
|
630
|
+
hookSpecificOutput?: SubagentStartHookSpecificOutput;
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Creates an output for SubagentStart hooks.
|
|
634
|
+
* @param options - Configuration options for the hook output
|
|
635
|
+
* @returns A SubagentStartOutput object ready for the runtime
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* subagentStartOutput({
|
|
639
|
+
* hookSpecificOutput: {
|
|
640
|
+
* additionalContext: 'Focus on finding patterns'
|
|
641
|
+
* }
|
|
642
|
+
* });
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
export declare const subagentStartOutput: (options?: CommonOptions & {
|
|
646
|
+
hookSpecificOutput?: SubagentStartHookSpecificOutput | undefined;
|
|
647
|
+
}) => {
|
|
648
|
+
readonly _type: "SubagentStart";
|
|
649
|
+
stdout: SyncHookJSONOutput;
|
|
650
|
+
};
|
|
651
|
+
/**
|
|
652
|
+
* Options for the SubagentStop output builder.
|
|
653
|
+
*/
|
|
654
|
+
export interface SubagentStopOptions extends CommonOptions {
|
|
655
|
+
/** Decision: 'approve' allows stop, 'block' prevents it. */
|
|
656
|
+
decision?: "approve" | "block";
|
|
657
|
+
/** Reason for the decision (shown to subagent when blocking). */
|
|
658
|
+
reason?: string;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Creates an output for SubagentStop hooks.
|
|
662
|
+
* @param options - Configuration options for the hook output
|
|
663
|
+
* @returns A SubagentStopOutput object ready for the runtime
|
|
664
|
+
* @example
|
|
665
|
+
* ```typescript
|
|
666
|
+
* // Block with reason
|
|
667
|
+
* subagentStopOutput({
|
|
668
|
+
* decision: 'block',
|
|
669
|
+
* reason: 'Task not complete'
|
|
670
|
+
* });
|
|
671
|
+
* ```
|
|
672
|
+
*/
|
|
673
|
+
export declare const subagentStopOutput: (options?: DecisionOptions) => {
|
|
674
|
+
readonly _type: "SubagentStop";
|
|
675
|
+
stdout: SyncHookJSONOutput;
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* Options for the Notification output builder.
|
|
679
|
+
*/
|
|
680
|
+
export type NotificationOptions = CommonOptions & {
|
|
681
|
+
/** Hook-specific output matching the wire format. */
|
|
682
|
+
hookSpecificOutput?: NotificationHookSpecificOutput;
|
|
683
|
+
};
|
|
684
|
+
/**
|
|
685
|
+
* Creates an output for Notification hooks.
|
|
686
|
+
* @param options - Configuration options for the hook output
|
|
687
|
+
* @returns A NotificationOutput object ready for the runtime
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* // Add context about the notification
|
|
691
|
+
* notificationOutput({
|
|
692
|
+
* hookSpecificOutput: {
|
|
693
|
+
* additionalContext: 'Notification forwarded to Slack #alerts channel'
|
|
694
|
+
* }
|
|
695
|
+
* });
|
|
696
|
+
*
|
|
697
|
+
* // Suppress the notification
|
|
698
|
+
* notificationOutput({ suppressOutput: true });
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
export declare const notificationOutput: (options?: CommonOptions & {
|
|
702
|
+
hookSpecificOutput?: NotificationHookSpecificOutput | undefined;
|
|
703
|
+
}) => {
|
|
704
|
+
readonly _type: "Notification";
|
|
705
|
+
stdout: SyncHookJSONOutput;
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* Options for the PreCompact output builder.
|
|
709
|
+
* PreCompact hooks only support common options.
|
|
710
|
+
*/
|
|
711
|
+
export type PreCompactOptions = CommonOptions;
|
|
712
|
+
/**
|
|
713
|
+
* Creates an output for PreCompact hooks.
|
|
714
|
+
* @param options - Configuration options for the hook output
|
|
715
|
+
* @returns A PreCompactOutput object ready for the runtime
|
|
716
|
+
* @example
|
|
717
|
+
* ```typescript
|
|
718
|
+
* preCompactOutput({
|
|
719
|
+
* systemMessage: 'Remember: strict mode is enabled'
|
|
720
|
+
* });
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
export declare const preCompactOutput: (options?: CommonOptions) => {
|
|
724
|
+
readonly _type: "PreCompact";
|
|
725
|
+
stdout: SyncHookJSONOutput;
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Options for the PostCompact output builder.
|
|
729
|
+
* PostCompact hooks only support common options.
|
|
730
|
+
*/
|
|
731
|
+
export type PostCompactOptions = CommonOptions;
|
|
732
|
+
/**
|
|
733
|
+
* Creates an output for PostCompact hooks.
|
|
734
|
+
* @param options - Configuration options for the hook output
|
|
735
|
+
* @returns A PostCompactOutput object ready for the runtime
|
|
736
|
+
* @example
|
|
737
|
+
* ```typescript
|
|
738
|
+
* postCompactOutput({});
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
export declare const postCompactOutput: (options?: CommonOptions) => {
|
|
742
|
+
readonly _type: "PostCompact";
|
|
743
|
+
stdout: SyncHookJSONOutput;
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Options for the PermissionRequest output builder.
|
|
747
|
+
*/
|
|
748
|
+
export type PermissionRequestOptions = CommonOptions & {
|
|
749
|
+
/** Hook-specific output matching the wire format. */
|
|
750
|
+
hookSpecificOutput?: PermissionRequestHookSpecificOutput;
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Creates an output for PermissionRequest hooks.
|
|
754
|
+
* @param options - Configuration options for the hook output
|
|
755
|
+
* @returns A PermissionRequestOutput object ready for the runtime
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* // Auto-approve
|
|
759
|
+
* permissionRequestOutput({
|
|
760
|
+
* hookSpecificOutput: {
|
|
761
|
+
* decision: { behavior: 'allow' }
|
|
762
|
+
* }
|
|
763
|
+
* });
|
|
764
|
+
*
|
|
765
|
+
* // Auto-approve with modified input
|
|
766
|
+
* permissionRequestOutput({
|
|
767
|
+
* hookSpecificOutput: {
|
|
768
|
+
* decision: {
|
|
769
|
+
* behavior: 'allow',
|
|
770
|
+
* updatedInput: { file_path: '/safe/path' }
|
|
771
|
+
* }
|
|
772
|
+
* }
|
|
773
|
+
* });
|
|
774
|
+
*
|
|
775
|
+
* // Auto-deny
|
|
776
|
+
* permissionRequestOutput({
|
|
777
|
+
* hookSpecificOutput: {
|
|
778
|
+
* decision: {
|
|
779
|
+
* behavior: 'deny',
|
|
780
|
+
* message: 'Not allowed',
|
|
781
|
+
* interrupt: true
|
|
782
|
+
* }
|
|
783
|
+
* }
|
|
784
|
+
* });
|
|
785
|
+
*
|
|
786
|
+
* // Fall through to normal prompt
|
|
787
|
+
* permissionRequestOutput({});
|
|
788
|
+
* ```
|
|
789
|
+
*/
|
|
790
|
+
export declare const permissionRequestOutput: (options?: CommonOptions & {
|
|
791
|
+
hookSpecificOutput?: PermissionRequestHookSpecificOutput | undefined;
|
|
792
|
+
}) => {
|
|
793
|
+
readonly _type: "PermissionRequest";
|
|
794
|
+
stdout: SyncHookJSONOutput;
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* Options for the PermissionDenied output builder.
|
|
798
|
+
*/
|
|
799
|
+
export type PermissionDeniedOptions = CommonOptions & {
|
|
800
|
+
/** Hook-specific output matching the wire format. */
|
|
801
|
+
hookSpecificOutput?: PermissionDeniedHookSpecificOutput;
|
|
802
|
+
};
|
|
803
|
+
/**
|
|
804
|
+
* Creates an output for PermissionDenied hooks.
|
|
805
|
+
* @param options - Configuration options for the hook output
|
|
806
|
+
* @returns A PermissionDeniedOutput object ready for the runtime
|
|
807
|
+
* @example
|
|
808
|
+
* ```typescript
|
|
809
|
+
* // Log and allow retry
|
|
810
|
+
* permissionDeniedOutput({
|
|
811
|
+
* hookSpecificOutput: { retry: true }
|
|
812
|
+
* });
|
|
813
|
+
*
|
|
814
|
+
* // Log without retry
|
|
815
|
+
* permissionDeniedOutput({});
|
|
816
|
+
* ```
|
|
817
|
+
*/
|
|
818
|
+
export declare const permissionDeniedOutput: (options?: CommonOptions & {
|
|
819
|
+
hookSpecificOutput?: PermissionDeniedHookSpecificOutput | undefined;
|
|
820
|
+
}) => {
|
|
821
|
+
readonly _type: "PermissionDenied";
|
|
822
|
+
stdout: SyncHookJSONOutput;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Options for the Setup output builder.
|
|
826
|
+
*/
|
|
827
|
+
export type SetupOptions = CommonOptions & {
|
|
828
|
+
/** Hook-specific output matching the wire format. */
|
|
829
|
+
hookSpecificOutput?: SetupHookSpecificOutput;
|
|
830
|
+
};
|
|
831
|
+
/**
|
|
832
|
+
* Creates an output for Setup hooks.
|
|
833
|
+
* @param options - Configuration options for the hook output
|
|
834
|
+
* @returns A SetupOutput object ready for the runtime
|
|
835
|
+
* @example
|
|
836
|
+
* ```typescript
|
|
837
|
+
* // Add context during setup
|
|
838
|
+
* setupOutput({
|
|
839
|
+
* hookSpecificOutput: {
|
|
840
|
+
* additionalContext: 'Project initialized with custom settings'
|
|
841
|
+
* }
|
|
842
|
+
* });
|
|
843
|
+
*
|
|
844
|
+
* // Simple passthrough
|
|
845
|
+
* setupOutput({});
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
export declare const setupOutput: (options?: CommonOptions & {
|
|
849
|
+
hookSpecificOutput?: SetupHookSpecificOutput | undefined;
|
|
850
|
+
}) => {
|
|
851
|
+
readonly _type: "Setup";
|
|
852
|
+
stdout: SyncHookJSONOutput;
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* Options for the TeammateIdle output builder.
|
|
856
|
+
* TeammateIdle hooks use exit codes only, not JSON decision control.
|
|
857
|
+
*/
|
|
858
|
+
export type TeammateIdleOptions = ExitCodeOptions;
|
|
859
|
+
/**
|
|
860
|
+
* Creates an output for TeammateIdle hooks.
|
|
861
|
+
* @param options - Configuration options for the hook output
|
|
862
|
+
* @returns A TeammateIdleOutput object ready for the runtime
|
|
863
|
+
* @example
|
|
864
|
+
* ```typescript
|
|
865
|
+
* // Allow teammate to go idle
|
|
866
|
+
* teammateIdleOutput({});
|
|
867
|
+
*
|
|
868
|
+
* // Block with feedback
|
|
869
|
+
* teammateIdleOutput({ stderr: 'Continue working: unfinished tasks remain.' });
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
export declare const teammateIdleOutput: ({ stderr }?: ExitCodeOptions) => {
|
|
873
|
+
readonly _type: "TeammateIdle";
|
|
874
|
+
stdout: SyncHookJSONOutput;
|
|
875
|
+
stderr?: string;
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* Options for the TaskCreated output builder.
|
|
879
|
+
* TaskCreated hooks use exit codes only, not JSON decision control.
|
|
880
|
+
*/
|
|
881
|
+
export type TaskCreatedOptions = ExitCodeOptions;
|
|
882
|
+
/**
|
|
883
|
+
* Creates an output for TaskCreated hooks.
|
|
884
|
+
* @param options - Configuration options for the hook output
|
|
885
|
+
* @returns A TaskCreatedOutput object ready for the runtime
|
|
886
|
+
* @example
|
|
887
|
+
* ```typescript
|
|
888
|
+
* // Allow task creation
|
|
889
|
+
* taskCreatedOutput({});
|
|
890
|
+
*
|
|
891
|
+
* // Block with feedback
|
|
892
|
+
* taskCreatedOutput({ stderr: 'Cannot create task: missing required fields.' });
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
895
|
+
export declare const taskCreatedOutput: ({ stderr }?: ExitCodeOptions) => {
|
|
896
|
+
readonly _type: "TaskCreated";
|
|
897
|
+
stdout: SyncHookJSONOutput;
|
|
898
|
+
stderr?: string;
|
|
899
|
+
};
|
|
900
|
+
/**
|
|
901
|
+
* Options for the TaskCompleted output builder.
|
|
902
|
+
* TaskCompleted hooks use exit codes only, not JSON decision control.
|
|
903
|
+
*/
|
|
904
|
+
export type TaskCompletedOptions = ExitCodeOptions;
|
|
905
|
+
/**
|
|
906
|
+
* Creates an output for TaskCompleted hooks.
|
|
907
|
+
* @param options - Configuration options for the hook output
|
|
908
|
+
* @returns A TaskCompletedOutput object ready for the runtime
|
|
909
|
+
* @example
|
|
910
|
+
* ```typescript
|
|
911
|
+
* // Allow task completion
|
|
912
|
+
* taskCompletedOutput({});
|
|
913
|
+
*
|
|
914
|
+
* // Block with feedback
|
|
915
|
+
* taskCompletedOutput({ stderr: 'Cannot complete: tests are failing.' });
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
export declare const taskCompletedOutput: ({ stderr }?: ExitCodeOptions) => {
|
|
919
|
+
readonly _type: "TaskCompleted";
|
|
920
|
+
stdout: SyncHookJSONOutput;
|
|
921
|
+
stderr?: string;
|
|
922
|
+
};
|
|
923
|
+
/**
|
|
924
|
+
* Options for the Elicitation output builder.
|
|
925
|
+
*/
|
|
926
|
+
export type ElicitationOptions = CommonOptions & {
|
|
927
|
+
/** Hook-specific output matching the wire format. */
|
|
928
|
+
hookSpecificOutput?: ElicitationHookSpecificOutput;
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* Creates an output for Elicitation hooks.
|
|
932
|
+
* @param options - Configuration options for the hook output
|
|
933
|
+
* @returns An ElicitationOutput object ready for the runtime
|
|
934
|
+
* @example
|
|
935
|
+
* ```typescript
|
|
936
|
+
* // Accept the elicitation
|
|
937
|
+
* elicitationOutput({
|
|
938
|
+
* hookSpecificOutput: { action: 'accept', content: { username: 'alice' } }
|
|
939
|
+
* });
|
|
940
|
+
*
|
|
941
|
+
* // Decline the elicitation
|
|
942
|
+
* elicitationOutput({
|
|
943
|
+
* hookSpecificOutput: { action: 'decline' }
|
|
944
|
+
* });
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
export declare const elicitationOutput: (options?: CommonOptions & {
|
|
948
|
+
hookSpecificOutput?: ElicitationHookSpecificOutput | undefined;
|
|
949
|
+
}) => {
|
|
950
|
+
readonly _type: "Elicitation";
|
|
951
|
+
stdout: SyncHookJSONOutput;
|
|
952
|
+
};
|
|
953
|
+
/**
|
|
954
|
+
* Options for the ElicitationResult output builder.
|
|
955
|
+
*/
|
|
956
|
+
export type ElicitationResultOptions = CommonOptions & {
|
|
957
|
+
/** Hook-specific output matching the wire format. */
|
|
958
|
+
hookSpecificOutput?: ElicitationResultHookSpecificOutput;
|
|
959
|
+
};
|
|
960
|
+
/**
|
|
961
|
+
* Creates an output for ElicitationResult hooks.
|
|
962
|
+
* @param options - Configuration options for the hook output
|
|
963
|
+
* @returns An ElicitationResultOutput object ready for the runtime
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* elicitationResultOutput({});
|
|
967
|
+
* ```
|
|
968
|
+
*/
|
|
969
|
+
export declare const elicitationResultOutput: (options?: CommonOptions & {
|
|
970
|
+
hookSpecificOutput?: ElicitationResultHookSpecificOutput | undefined;
|
|
971
|
+
}) => {
|
|
972
|
+
readonly _type: "ElicitationResult";
|
|
973
|
+
stdout: SyncHookJSONOutput;
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* Options for the ConfigChange output builder.
|
|
977
|
+
* ConfigChange hooks only support common options.
|
|
978
|
+
*/
|
|
979
|
+
export type ConfigChangeOptions = CommonOptions;
|
|
980
|
+
/**
|
|
981
|
+
* Creates an output for ConfigChange hooks.
|
|
982
|
+
* @param options - Configuration options for the hook output
|
|
983
|
+
* @returns A ConfigChangeOutput object ready for the runtime
|
|
984
|
+
* @example
|
|
985
|
+
* ```typescript
|
|
986
|
+
* configChangeOutput({});
|
|
987
|
+
* ```
|
|
988
|
+
*/
|
|
989
|
+
export declare const configChangeOutput: (options?: CommonOptions) => {
|
|
990
|
+
readonly _type: "ConfigChange";
|
|
991
|
+
stdout: SyncHookJSONOutput;
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* Options for the InstructionsLoaded output builder.
|
|
995
|
+
* InstructionsLoaded hooks only support common options.
|
|
996
|
+
*/
|
|
997
|
+
export type InstructionsLoadedOptions = CommonOptions;
|
|
998
|
+
/**
|
|
999
|
+
* Creates an output for InstructionsLoaded hooks.
|
|
1000
|
+
* @param options - Configuration options for the hook output
|
|
1001
|
+
* @returns An InstructionsLoadedOutput object ready for the runtime
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* instructionsLoadedOutput({});
|
|
1005
|
+
* ```
|
|
1006
|
+
*/
|
|
1007
|
+
export declare const instructionsLoadedOutput: (options?: CommonOptions) => {
|
|
1008
|
+
readonly _type: "InstructionsLoaded";
|
|
1009
|
+
stdout: SyncHookJSONOutput;
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* Options for the WorktreeCreate output builder.
|
|
1013
|
+
*
|
|
1014
|
+
* `worktreePath` is required: WorktreeCreate is a command hook whose protocol is the
|
|
1015
|
+
* **bare absolute path on stdout**. The path type is derived from the SDK's
|
|
1016
|
+
* `WorktreeCreateHookSpecificOutput`.
|
|
1017
|
+
*/
|
|
1018
|
+
export type WorktreeCreateOptions = CommonOptions & Pick<SDKWorktreeCreateHookSpecificOutput, "worktreePath">;
|
|
1019
|
+
/**
|
|
1020
|
+
* Creates an output for WorktreeCreate hooks.
|
|
1021
|
+
*
|
|
1022
|
+
* The runtime writes `worktreePath` to stdout as plain text (not JSON) so Claude Code
|
|
1023
|
+
* can `chdir` into the created worktree.
|
|
1024
|
+
* @param options - Configuration options for the hook output
|
|
1025
|
+
* @returns A WorktreeCreateOutput object ready for the runtime
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```typescript
|
|
1028
|
+
* worktreeCreateOutput({ worktreePath: '/abs/path/to/worktree' });
|
|
1029
|
+
* ```
|
|
1030
|
+
*/
|
|
1031
|
+
export declare const worktreeCreateOutput: (options: CommonOptions & {
|
|
1032
|
+
worktreePath: string;
|
|
1033
|
+
}) => {
|
|
1034
|
+
readonly _type: "WorktreeCreate";
|
|
1035
|
+
stdout: SyncHookJSONOutput;
|
|
1036
|
+
rawStdout: string;
|
|
1037
|
+
};
|
|
1038
|
+
/**
|
|
1039
|
+
* Options for the WorktreeRemove output builder.
|
|
1040
|
+
*
|
|
1041
|
+
* `worktreePath` is optional: when provided it is written to stdout as plain text
|
|
1042
|
+
* (matching the WorktreeCreate command-hook protocol); when omitted the builder falls
|
|
1043
|
+
* back to the JSON passthrough.
|
|
1044
|
+
*/
|
|
1045
|
+
export type WorktreeRemoveOptions = CommonOptions & {
|
|
1046
|
+
worktreePath?: string;
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* Creates an output for WorktreeRemove hooks.
|
|
1050
|
+
*
|
|
1051
|
+
* When `worktreePath` is supplied, the runtime writes it to stdout as plain text (not
|
|
1052
|
+
* JSON), matching the worktree command-hook protocol.
|
|
1053
|
+
* @param options - Configuration options for the hook output
|
|
1054
|
+
* @returns A WorktreeRemoveOutput object ready for the runtime
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```typescript
|
|
1057
|
+
* // Plain-text path protocol
|
|
1058
|
+
* worktreeRemoveOutput({ worktreePath: '/abs/path/to/worktree' });
|
|
1059
|
+
*
|
|
1060
|
+
* // No path payload
|
|
1061
|
+
* worktreeRemoveOutput({});
|
|
1062
|
+
* ```
|
|
1063
|
+
*/
|
|
1064
|
+
export declare const worktreeRemoveOutput: (options?: WorktreeRemoveOptions) => {
|
|
1065
|
+
readonly _type: "WorktreeRemove";
|
|
1066
|
+
stdout: SyncHookJSONOutput;
|
|
1067
|
+
rawStdout?: string;
|
|
1068
|
+
};
|
|
1069
|
+
/**
|
|
1070
|
+
* Options for the CwdChanged output builder.
|
|
1071
|
+
*/
|
|
1072
|
+
export type CwdChangedOptions = CommonOptions & {
|
|
1073
|
+
/** Hook-specific output matching the wire format. */
|
|
1074
|
+
hookSpecificOutput?: CwdChangedHookSpecificOutput;
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Creates an output for CwdChanged hooks.
|
|
1078
|
+
* @param options - Configuration options for the hook output
|
|
1079
|
+
* @returns A CwdChangedOutput object ready for the runtime
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```typescript
|
|
1082
|
+
* // Return additional paths to watch after the cwd change
|
|
1083
|
+
* cwdChangedOutput({
|
|
1084
|
+
* hookSpecificOutput: {
|
|
1085
|
+
* watchPaths: ['/new/path/to/watch']
|
|
1086
|
+
* }
|
|
1087
|
+
* });
|
|
1088
|
+
*
|
|
1089
|
+
* // Simple passthrough
|
|
1090
|
+
* cwdChangedOutput({});
|
|
1091
|
+
* ```
|
|
1092
|
+
*/
|
|
1093
|
+
export declare const cwdChangedOutput: (options?: CommonOptions & {
|
|
1094
|
+
hookSpecificOutput?: CwdChangedHookSpecificOutput | undefined;
|
|
1095
|
+
}) => {
|
|
1096
|
+
readonly _type: "CwdChanged";
|
|
1097
|
+
stdout: SyncHookJSONOutput;
|
|
1098
|
+
};
|
|
1099
|
+
/**
|
|
1100
|
+
* Options for the FileChanged output builder.
|
|
1101
|
+
*/
|
|
1102
|
+
export type FileChangedOptions = CommonOptions & {
|
|
1103
|
+
/** Hook-specific output matching the wire format. */
|
|
1104
|
+
hookSpecificOutput?: FileChangedHookSpecificOutput;
|
|
1105
|
+
};
|
|
1106
|
+
/**
|
|
1107
|
+
* Creates an output for FileChanged hooks.
|
|
1108
|
+
* @param options - Configuration options for the hook output
|
|
1109
|
+
* @returns A FileChangedOutput object ready for the runtime
|
|
1110
|
+
* @example
|
|
1111
|
+
* ```typescript
|
|
1112
|
+
* // Update the set of watched paths
|
|
1113
|
+
* fileChangedOutput({
|
|
1114
|
+
* hookSpecificOutput: {
|
|
1115
|
+
* watchPaths: ['/path/to/watch', '/another/path']
|
|
1116
|
+
* }
|
|
1117
|
+
* });
|
|
1118
|
+
*
|
|
1119
|
+
* // Simple passthrough
|
|
1120
|
+
* fileChangedOutput({});
|
|
1121
|
+
* ```
|
|
1122
|
+
*/
|
|
1123
|
+
export declare const fileChangedOutput: (options?: CommonOptions & {
|
|
1124
|
+
hookSpecificOutput?: FileChangedHookSpecificOutput | undefined;
|
|
1125
|
+
}) => {
|
|
1126
|
+
readonly _type: "FileChanged";
|
|
1127
|
+
stdout: SyncHookJSONOutput;
|
|
1128
|
+
};
|
|
1129
|
+
/**
|
|
1130
|
+
* Options for the MessageDisplay output builder.
|
|
1131
|
+
*/
|
|
1132
|
+
export type MessageDisplayOptions = CommonOptions & {
|
|
1133
|
+
/** Hook-specific output matching the wire format. */
|
|
1134
|
+
hookSpecificOutput?: MessageDisplayHookSpecificOutput;
|
|
1135
|
+
};
|
|
1136
|
+
/**
|
|
1137
|
+
* Creates an output for MessageDisplay hooks.
|
|
1138
|
+
*
|
|
1139
|
+
* MessageDisplay is display-only: the `displayContent` field replaces the delta on
|
|
1140
|
+
* screen without changing the stored message or what the model sees. Omit
|
|
1141
|
+
* `displayContent` (or set it to the original delta) to leave the display unchanged.
|
|
1142
|
+
* @param options - Configuration options for the hook output
|
|
1143
|
+
* @returns A MessageDisplayOutput object ready for the runtime
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```typescript
|
|
1146
|
+
* // Replace the delta shown on screen
|
|
1147
|
+
* messageDisplayOutput({
|
|
1148
|
+
* hookSpecificOutput: { displayContent: "[redacted]" }
|
|
1149
|
+
* });
|
|
1150
|
+
*
|
|
1151
|
+
* // Passthrough (no display modification)
|
|
1152
|
+
* messageDisplayOutput({});
|
|
1153
|
+
* ```
|
|
1154
|
+
*/
|
|
1155
|
+
export declare const messageDisplayOutput: (options?: CommonOptions & {
|
|
1156
|
+
hookSpecificOutput?: MessageDisplayHookSpecificOutput | undefined;
|
|
1157
|
+
}) => {
|
|
1158
|
+
readonly _type: "MessageDisplay";
|
|
1159
|
+
stdout: SyncHookJSONOutput;
|
|
1160
|
+
};
|