|
1 | 1 | /** |
2 | | - * Stub: Generated SDK core types. |
| 2 | + * Stub:自动生成的 SDK Core 类型。 |
3 | 3 | * |
4 | | - * In the full build, this is auto-generated from coreSchemas.ts Zod schemas. |
5 | | - * Here we provide typed stubs for all the types referenced throughout the codebase. |
| 4 | + * 在完整构建中,这些类型会基于 coreSchemas.ts 中的 Zod schema 自动生成。 |
| 5 | + * 这里提供的是类型化的 stub,用于覆盖代码库中引用到的所有相关类型。 |
6 | 6 | */ |
7 | 7 |
|
8 | 8 | import type { UUID } from 'crypto' |
@@ -65,11 +65,259 @@ export type RewindFilesResult = { |
65 | 65 | // Account |
66 | 66 | export type AccountInfo = Record<string, unknown> |
67 | 67 |
|
68 | | -// Hook input types |
69 | | -export type HookInput = { hook_event_name: string; [key: string]: unknown } |
70 | | -export type HookJSONOutput = Record<string, unknown> |
71 | | -export type AsyncHookJSONOutput = Record<string, unknown> |
72 | | -export type SyncHookJSONOutput = Record<string, unknown> |
| 68 | +// 钩子输入类型 |
| 69 | +export type HookInputBase = { |
| 70 | + session_id: string // 会话 ID |
| 71 | + transcript_path: string // 转录文件路径 |
| 72 | + cwd: string // 当前工作目录 |
| 73 | + permission_mode?: string // 权限模式(可选) |
| 74 | + /** 仅在从子代理触发的钩子中存在 */ |
| 75 | + agent_id?: string |
| 76 | + /** 在子代理钩子中存在,或在使用 --agent 启动的主线程会话中存在 */ |
| 77 | + agent_type?: string |
| 78 | +} |
| 79 | + |
| 80 | +export type HookInput = |
| 81 | + | (HookInputBase & { |
| 82 | + hook_event_name: 'PreToolUse' |
| 83 | + tool_name: string |
| 84 | + tool_input: unknown |
| 85 | + tool_use_id: string |
| 86 | + }) |
| 87 | + | (HookInputBase & { |
| 88 | + hook_event_name: 'PermissionRequest' |
| 89 | + tool_name: string |
| 90 | + tool_input: unknown |
| 91 | + permission_suggestions?: PermissionUpdate[] |
| 92 | + }) |
| 93 | + | (HookInputBase & { |
| 94 | + hook_event_name: 'PostToolUse' |
| 95 | + tool_name: string |
| 96 | + tool_input: unknown |
| 97 | + tool_response: unknown |
| 98 | + tool_use_id: string |
| 99 | + }) |
| 100 | + | (HookInputBase & { |
| 101 | + hook_event_name: 'PostToolUseFailure' |
| 102 | + tool_name: string |
| 103 | + tool_input: unknown |
| 104 | + tool_use_id: string |
| 105 | + error: string |
| 106 | + is_interrupt?: boolean |
| 107 | + }) |
| 108 | + | (HookInputBase & { |
| 109 | + hook_event_name: 'PermissionDenied' |
| 110 | + tool_name: string |
| 111 | + tool_input: unknown |
| 112 | + tool_use_id: string |
| 113 | + reason: string |
| 114 | + }) |
| 115 | + | (HookInputBase & { |
| 116 | + hook_event_name: 'Notification' |
| 117 | + message: string |
| 118 | + title?: string |
| 119 | + notification_type: string |
| 120 | + }) |
| 121 | + | (HookInputBase & { hook_event_name: 'UserPromptSubmit'; prompt: string }) |
| 122 | + | (HookInputBase & { |
| 123 | + hook_event_name: 'SessionStart' |
| 124 | + source: 'startup' | 'resume' | 'clear' | 'compact' |
| 125 | + agent_type?: string |
| 126 | + model?: string |
| 127 | + }) |
| 128 | + | (HookInputBase & { |
| 129 | + hook_event_name: 'SessionEnd' |
| 130 | + reason: |
| 131 | + | 'clear' |
| 132 | + | 'resume' |
| 133 | + | 'logout' |
| 134 | + | 'prompt_input_exit' |
| 135 | + | 'other' |
| 136 | + | 'bypass_permissions_disabled' |
| 137 | + }) |
| 138 | + | (HookInputBase & { |
| 139 | + hook_event_name: 'Setup' |
| 140 | + trigger: 'init' | 'maintenance' |
| 141 | + }) |
| 142 | + | (HookInputBase & { |
| 143 | + hook_event_name: 'Stop' |
| 144 | + stop_hook_active: boolean |
| 145 | + last_assistant_message?: string |
| 146 | + }) |
| 147 | + | (HookInputBase & { |
| 148 | + hook_event_name: 'StopFailure' |
| 149 | + error: string |
| 150 | + error_details?: unknown |
| 151 | + last_assistant_message?: string |
| 152 | + }) |
| 153 | + | (HookInputBase & { |
| 154 | + hook_event_name: 'SubagentStart' |
| 155 | + agent_id: string |
| 156 | + agent_type: string |
| 157 | + }) |
| 158 | + | (HookInputBase & { |
| 159 | + hook_event_name: 'SubagentStop' |
| 160 | + stop_hook_active: boolean |
| 161 | + agent_id: string |
| 162 | + agent_transcript_path: string |
| 163 | + agent_type: string |
| 164 | + last_assistant_message?: string |
| 165 | + }) |
| 166 | + | (HookInputBase & { |
| 167 | + hook_event_name: 'PreCompact' |
| 168 | + trigger: 'manual' | 'auto' |
| 169 | + custom_instructions: string | null |
| 170 | + }) |
| 171 | + | (HookInputBase & { |
| 172 | + hook_event_name: 'PostCompact' |
| 173 | + trigger: 'manual' | 'auto' |
| 174 | + compact_summary: string |
| 175 | + }) |
| 176 | + | (HookInputBase & { |
| 177 | + hook_event_name: 'TeammateIdle' |
| 178 | + teammate_name: string |
| 179 | + team_name: string |
| 180 | + }) |
| 181 | + | (HookInputBase & { |
| 182 | + hook_event_name: 'TaskCreated' |
| 183 | + task_id: string |
| 184 | + task_subject: string |
| 185 | + task_description?: string |
| 186 | + teammate_name?: string |
| 187 | + team_name?: string |
| 188 | + }) |
| 189 | + | (HookInputBase & { |
| 190 | + hook_event_name: 'TaskCompleted' |
| 191 | + task_id: string |
| 192 | + task_subject: string |
| 193 | + task_description?: string |
| 194 | + teammate_name?: string |
| 195 | + team_name?: string |
| 196 | + }) |
| 197 | + | (HookInputBase & { |
| 198 | + hook_event_name: 'Elicitation' |
| 199 | + mcp_server_name: string |
| 200 | + message: string |
| 201 | + mode?: 'form' | 'url' |
| 202 | + url?: string |
| 203 | + elicitation_id?: string |
| 204 | + requested_schema?: Record<string, unknown> |
| 205 | + }) |
| 206 | + | (HookInputBase & { |
| 207 | + hook_event_name: 'ElicitationResult' |
| 208 | + mcp_server_name: string |
| 209 | + elicitation_id?: string |
| 210 | + mode?: 'form' | 'url' |
| 211 | + action: 'accept' | 'decline' | 'cancel' |
| 212 | + content?: Record<string, unknown> |
| 213 | + }) |
| 214 | + | (HookInputBase & { |
| 215 | + hook_event_name: 'ConfigChange' |
| 216 | + source: |
| 217 | + | 'user_settings' |
| 218 | + | 'project_settings' |
| 219 | + | 'local_settings' |
| 220 | + | 'policy_settings' |
| 221 | + | 'skills' |
| 222 | + file_path?: string |
| 223 | + }) |
| 224 | + | (HookInputBase & { |
| 225 | + hook_event_name: 'InstructionsLoaded' |
| 226 | + file_path: string |
| 227 | + memory_type: 'User' | 'Project' | 'Local' | 'Managed' |
| 228 | + load_reason: |
| 229 | + | 'session_start' |
| 230 | + | 'nested_traversal' |
| 231 | + | 'path_glob_match' |
| 232 | + | 'include' |
| 233 | + | 'compact' |
| 234 | + globs?: string[] |
| 235 | + trigger_file_path?: string |
| 236 | + parent_file_path?: string |
| 237 | + }) |
| 238 | + | (HookInputBase & { hook_event_name: 'WorktreeCreate'; name: string }) |
| 239 | + | (HookInputBase & { |
| 240 | + hook_event_name: 'WorktreeRemove' |
| 241 | + worktree_path: string |
| 242 | + }) |
| 243 | + | (HookInputBase & { |
| 244 | + hook_event_name: 'CwdChanged' |
| 245 | + old_cwd: string |
| 246 | + new_cwd: string |
| 247 | + }) |
| 248 | + | (HookInputBase & { |
| 249 | + hook_event_name: 'FileChanged' |
| 250 | + file_path: string |
| 251 | + event: 'change' | 'add' | 'unlink' |
| 252 | + }) |
| 253 | + |
| 254 | +export type AsyncHookJSONOutput = { |
| 255 | + async: true |
| 256 | + asyncTimeout?: number |
| 257 | +} |
| 258 | + |
| 259 | +export type SyncHookJSONOutput = { |
| 260 | + continue?: boolean |
| 261 | + suppressOutput?: boolean |
| 262 | + stopReason?: string |
| 263 | + decision?: 'approve' | 'block' |
| 264 | + systemMessage?: string |
| 265 | + reason?: string |
| 266 | + hookSpecificOutput?: |
| 267 | + | { |
| 268 | + hookEventName: 'PreToolUse' |
| 269 | + permissionDecision?: string |
| 270 | + permissionDecisionReason?: string |
| 271 | + updatedInput?: Record<string, unknown> |
| 272 | + additionalContext?: string |
| 273 | + } |
| 274 | + | { hookEventName: 'UserPromptSubmit'; additionalContext?: string } |
| 275 | + | { |
| 276 | + hookEventName: 'SessionStart' |
| 277 | + additionalContext?: string |
| 278 | + initialUserMessage?: string |
| 279 | + watchPaths?: string[] |
| 280 | + } |
| 281 | + | { hookEventName: 'Setup'; additionalContext?: string } |
| 282 | + | { hookEventName: 'SubagentStart'; additionalContext?: string } |
| 283 | + | { |
| 284 | + hookEventName: 'PostToolUse' |
| 285 | + additionalContext?: string |
| 286 | + updatedMCPToolOutput?: unknown |
| 287 | + } |
| 288 | + | { hookEventName: 'PostToolUseFailure'; additionalContext?: string } |
| 289 | + | { hookEventName: 'PermissionDenied'; retry?: boolean } |
| 290 | + | { hookEventName: 'Notification'; additionalContext?: string } |
| 291 | + | { |
| 292 | + hookEventName: 'PermissionRequest' |
| 293 | + decision: |
| 294 | + | { |
| 295 | + behavior: 'allow' |
| 296 | + updatedInput?: Record<string, unknown> |
| 297 | + /** |
| 298 | + * 注意:钩子使用的 JSON schema 为 PermissionUpdateSchema(), |
| 299 | + * 它是一个比传统 `{path, permission}` 结构更丰富的联合类型。 |
| 300 | + */ |
| 301 | + updatedPermissions?: unknown[] |
| 302 | + } |
| 303 | + | { behavior: 'deny'; message?: string; interrupt?: boolean } |
| 304 | + } |
| 305 | + | { |
| 306 | + hookEventName: 'Elicitation' |
| 307 | + action?: 'accept' | 'decline' | 'cancel' |
| 308 | + content?: Record<string, unknown> |
| 309 | + } |
| 310 | + | { |
| 311 | + hookEventName: 'ElicitationResult' |
| 312 | + action?: 'accept' | 'decline' | 'cancel' |
| 313 | + content?: Record<string, unknown> |
| 314 | + } |
| 315 | + | { hookEventName: 'CwdChanged'; watchPaths?: string[] } |
| 316 | + | { hookEventName: 'FileChanged'; watchPaths?: string[] } |
| 317 | + | { hookEventName: 'WorktreeCreate'; worktreePath: string } |
| 318 | +} |
| 319 | + |
| 320 | +export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput |
73 | 321 |
|
74 | 322 | export type PreToolUseHookInput = HookInput & { tool_name: string } |
75 | 323 | export type PostToolUseHookInput = HookInput & { tool_name: string } |
|
0 commit comments