()
| 111 | } |
| 112 | |
| 113 | export async function checkForAsyncHookResponses(): Promise< |
| 114 | Array<{ |
| 115 | processId: string |
| 116 | response: SyncHookJSONOutput |
| 117 | hookName: string |
| 118 | hookEvent: HookEvent | 'StatusLine' | 'FileSuggestion' |
| 119 | toolName?: string |
| 120 | pluginId?: string |
| 121 | stdout: string |
| 122 | stderr: string |
| 123 | exitCode?: number |
| 124 | }> |
| 125 | > { |
| 126 | const responses: { |
| 127 | processId: string |
| 128 | response: SyncHookJSONOutput |
| 129 | hookName: string |
| 130 | hookEvent: HookEvent | 'StatusLine' | 'FileSuggestion' |
| 131 | toolName?: string |
| 132 | pluginId?: string |
| 133 | stdout: string |
| 134 | stderr: string |
| 135 | exitCode?: number |
| 136 | }[] = [] |
| 137 | |
| 138 | const pendingCount = pendingHooks.size |
| 139 | logForDebugging(`Hooks: Found ${pendingCount} total hooks in registry`) |
| 140 | |
| 141 | // Snapshot hooks before processing — we'll mutate the map after. |
| 142 | const hooks = Array.from(pendingHooks.values()) |
| 143 | |
| 144 | const settled = await Promise.allSettled( |
| 145 | hooks.map(async hook => { |
| 146 | const stdout = (await hook.shellCommand?.taskOutput.getStdout()) ?? '' |
| 147 | const stderr = hook.shellCommand?.taskOutput.getStderr() ?? '' |
| 148 | logForDebugging( |
| 149 | `Hooks: Checking hook ${hook.processId} (${hook.hookName}) - attachmentSent: ${hook.responseAttachmentSent}, stdout length: ${stdout.length}`, |
| 150 | ) |
| 151 | |
| 152 | if (!hook.shellCommand) { |
| 153 | logForDebugging( |
| 154 | `Hooks: Hook ${hook.processId} has no shell command, removing from registry`, |
| 155 | ) |
| 156 | hook.stopProgressInterval() |
| 157 | return { type: 'remove' as const, processId: hook.processId } |
| 158 | } |
| 159 | |
| 160 | logForDebugging(`Hooks: Hook shell status ${hook.shellCommand.status}`) |
| 161 | |
| 162 | if (hook.shellCommand.status === 'killed') { |
| 163 | logForDebugging( |
| 164 | `Hooks: Hook ${hook.processId} is ${hook.shellCommand.status}, removing from registry`, |
| 165 | ) |
| 166 | hook.stopProgressInterval() |
| 167 | hook.shellCommand.cleanup() |
| 168 | return { type: 'remove' as const, processId: hook.processId } |
| 169 | } |
| 170 |
no test coverage detected