(
permissionMode?: string,
sessionId?: string,
// Typed narrowly (not ToolUseContext) so callers can pass toolUseContext
// directly via structural typing without this function depending on Tool.ts.
agentInfo?: { agentId?: string; agentType?: string },
)
| 300 | * Creates the base hook input that's common to all hook types |
| 301 | */ |
| 302 | export function createBaseHookInput( |
| 303 | permissionMode?: string, |
| 304 | sessionId?: string, |
| 305 | // Typed narrowly (not ToolUseContext) so callers can pass toolUseContext |
| 306 | // directly via structural typing without this function depending on Tool.ts. |
| 307 | agentInfo?: { agentId?: string; agentType?: string }, |
| 308 | ): { |
| 309 | session_id: string |
| 310 | transcript_path: string |
| 311 | cwd: string |
| 312 | permission_mode?: string |
| 313 | agent_id?: string |
| 314 | agent_type?: string |
| 315 | } { |
| 316 | const resolvedSessionId = sessionId ?? getSessionId() |
| 317 | // agent_type: subagent's type (from toolUseContext) takes precedence over |
| 318 | // the session's --agent flag. Hooks use agent_id presence to distinguish |
| 319 | // subagent calls from main-thread calls in a --agent session. |
| 320 | const resolvedAgentType = agentInfo?.agentType ?? getMainThreadAgentType() |
| 321 | return { |
| 322 | session_id: resolvedSessionId, |
| 323 | transcript_path: getTranscriptPathForSession(resolvedSessionId), |
| 324 | cwd: getCwd(), |
| 325 | permission_mode: permissionMode, |
| 326 | agent_id: agentInfo?.agentId, |
| 327 | agent_type: resolvedAgentType, |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | export interface HookBlockingError { |
| 332 | blockingError: string |
no test coverage detected