MCPcopy Index your code
hub / github.com/codeaashu/claude-code / enqueueMainSessionNotification

Function enqueueMainSessionNotification

src/tasks/LocalMainSessionTask.ts:224–263  ·  view source on GitHub ↗

* Enqueue a notification about the backgrounded session completing.

(
  taskId: string,
  description: string,
  status: 'completed' | 'failed',
  setAppState: SetAppState,
  toolUseId?: string,
)

Source from the content-addressed store, hash-verified

222 * Enqueue a notification about the backgrounded session completing.
223 */
224function enqueueMainSessionNotification(
225 taskId: string,
226 description: string,
227 status: 'completed' | 'failed',
228 setAppState: SetAppState,
229 toolUseId?: string,
230): void {
231 // Atomically check and set notified flag to prevent duplicate notifications.
232 let shouldEnqueue = false
233 updateTaskState(taskId, setAppState, task => {
234 if (task.notified) {
235 return task
236 }
237 shouldEnqueue = true
238 return { ...task, notified: true }
239 })
240
241 if (!shouldEnqueue) {
242 return
243 }
244
245 const summary =
246 status === 'completed'
247 ? `Background session "${description}" completed`
248 : `Background session "${description}" failed`
249
250 const toolUseIdLine = toolUseId
251 ? `\n<${TOOL_USE_ID_TAG}>${toolUseId}</${TOOL_USE_ID_TAG}>`
252 : ''
253
254 const outputPath = getTaskOutputPath(taskId)
255 const message = `<${TASK_NOTIFICATION_TAG}>
256<${TASK_ID_TAG}>${taskId}</${TASK_ID_TAG}>${toolUseIdLine}
257<${OUTPUT_FILE_TAG}>${outputPath}</${OUTPUT_FILE_TAG}>
258<${STATUS_TAG}>${status}</${STATUS_TAG}>
259<${SUMMARY_TAG}>${summary}</${SUMMARY_TAG}>
260</${TASK_NOTIFICATION_TAG}>`
261
262 enqueuePendingNotification({ value: message, mode: 'task-notification' })
263}
264
265/**
266 * Foreground a main session task - mark it as foregrounded so its output

Callers 1

completeMainSessionTaskFunction · 0.85

Calls 3

getTaskOutputPathFunction · 0.85
updateTaskStateFunction · 0.50

Tested by

no test coverage detected