(taskId: string, description: string, status: 'completed' | 'failed' | 'killed', exitCode: number | undefined, setAppState: SetAppState, toolUseId?: string, kind: BashTaskKind = 'bash', agentId?: AgentId)
| 103 | }; |
| 104 | } |
| 105 | function enqueueShellNotification(taskId: string, description: string, status: 'completed' | 'failed' | 'killed', exitCode: number | undefined, setAppState: SetAppState, toolUseId?: string, kind: BashTaskKind = 'bash', agentId?: AgentId): void { |
| 106 | // Atomically check and set notified flag to prevent duplicate notifications. |
| 107 | // If the task was already marked as notified (e.g., by TaskStopTool), skip |
| 108 | // enqueueing to avoid sending redundant messages to the model. |
| 109 | let shouldEnqueue = false; |
| 110 | updateTaskState<LocalShellTaskState>(taskId, setAppState, task => { |
| 111 | if (task.notified) { |
| 112 | return task; |
| 113 | } |
| 114 | shouldEnqueue = true; |
| 115 | return { |
| 116 | ...task, |
| 117 | notified: true |
| 118 | }; |
| 119 | }); |
| 120 | if (!shouldEnqueue) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | // Abort any active speculation — background task state changed, so speculated |
| 125 | // results may reference stale task output. The prompt suggestion text is |
| 126 | // preserved; only the pre-computed response is discarded. |
| 127 | abortSpeculation(setAppState); |
| 128 | let summary: string; |
| 129 | if (feature('MONITOR_TOOL') && kind === 'monitor') { |
| 130 | // Monitor is streaming-only (post-#22764) — the script exiting means |
| 131 | // the stream ended, not "condition met". Distinct from the bash prefix |
| 132 | // so Monitor completions don't fold into the "N background commands |
| 133 | // completed" collapse. |
| 134 | switch (status) { |
| 135 | case 'completed': |
| 136 | summary = `Monitor "${description}" stream ended`; |
| 137 | break; |
| 138 | case 'failed': |
| 139 | summary = `Monitor "${description}" script failed${exitCode !== undefined ? ` (exit ${exitCode})` : ''}`; |
| 140 | break; |
| 141 | case 'killed': |
| 142 | summary = `Monitor "${description}" stopped`; |
| 143 | break; |
| 144 | } |
| 145 | } else { |
| 146 | switch (status) { |
| 147 | case 'completed': |
| 148 | summary = `${BACKGROUND_BASH_SUMMARY_PREFIX}"${description}" completed${exitCode !== undefined ? ` (exit code ${exitCode})` : ''}`; |
| 149 | break; |
| 150 | case 'failed': |
| 151 | summary = `${BACKGROUND_BASH_SUMMARY_PREFIX}"${description}" failed${exitCode !== undefined ? ` with exit code ${exitCode}` : ''}`; |
| 152 | break; |
| 153 | case 'killed': |
| 154 | summary = `${BACKGROUND_BASH_SUMMARY_PREFIX}"${description}" was stopped`; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | const outputPath = getTaskOutputPath(taskId); |
| 159 | const toolUseIdLine = toolUseId ? `\n<${TOOL_USE_ID_TAG}>${toolUseId}</${TOOL_USE_ID_TAG}>` : ''; |
| 160 | const message = `<${TASK_NOTIFICATION_TAG}> |
| 161 | <${TASK_ID_TAG}>${taskId}</${TASK_ID_TAG}>${toolUseIdLine} |
| 162 | <${OUTPUT_FILE_TAG}>${outputPath}</${OUTPUT_FILE_TAG}> |
no test coverage detected