({
processId,
hookId,
asyncResponse,
hookName,
hookEvent,
command,
shellCommand,
toolName,
pluginId,
}: {
processId: string
hookId: string
asyncResponse: AsyncHookJSONOutput
hookName: string
hookEvent: HookEvent | 'StatusLine' | 'FileSuggestion'
command: string
shellCommand: ShellCommand
toolName?: string
pluginId?: string
})
| 28 | const pendingHooks = new Map<string, PendingAsyncHook>() |
| 29 | |
| 30 | export function registerPendingAsyncHook({ |
| 31 | processId, |
| 32 | hookId, |
| 33 | asyncResponse, |
| 34 | hookName, |
| 35 | hookEvent, |
| 36 | command, |
| 37 | shellCommand, |
| 38 | toolName, |
| 39 | pluginId, |
| 40 | }: { |
| 41 | processId: string |
| 42 | hookId: string |
| 43 | asyncResponse: AsyncHookJSONOutput |
| 44 | hookName: string |
| 45 | hookEvent: HookEvent | 'StatusLine' | 'FileSuggestion' |
| 46 | command: string |
| 47 | shellCommand: ShellCommand |
| 48 | toolName?: string |
| 49 | pluginId?: string |
| 50 | }): void { |
| 51 | const timeout = asyncResponse.asyncTimeout || 15000 // Default 15s |
| 52 | logForDebugging( |
| 53 | `Hooks: Registering async hook ${processId} (${hookName}) with timeout ${timeout}ms`, |
| 54 | ) |
| 55 | const stopProgressInterval = startHookProgressInterval({ |
| 56 | hookId, |
| 57 | hookName, |
| 58 | hookEvent, |
| 59 | getOutput: async () => { |
| 60 | const taskOutput = pendingHooks.get(processId)?.shellCommand?.taskOutput |
| 61 | if (!taskOutput) { |
| 62 | return { stdout: '', stderr: '', output: '' } |
| 63 | } |
| 64 | const stdout = await taskOutput.getStdout() |
| 65 | const stderr = taskOutput.getStderr() |
| 66 | return { stdout, stderr, output: stdout + stderr } |
| 67 | }, |
| 68 | }) |
| 69 | pendingHooks.set(processId, { |
| 70 | processId, |
| 71 | hookId, |
| 72 | hookName, |
| 73 | hookEvent, |
| 74 | toolName, |
| 75 | pluginId, |
| 76 | command, |
| 77 | startTime: Date.now(), |
| 78 | timeout, |
| 79 | responseAttachmentSent: false, |
| 80 | shellCommand, |
| 81 | stopProgressInterval, |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | export function getPendingAsyncHooks(): PendingAsyncHook[] { |
| 86 | return Array.from(pendingHooks.values()).filter( |
no test coverage detected