MCPcopy
hub / github.com/claude-code-best/claude-code / registerTask

Function registerTask

src/utils/task/framework.ts:77–117  ·  view source on GitHub ↗
(task: TaskState, setAppState: SetAppState)

Source from the content-addressed store, hash-verified

75 * Register a new task in AppState.
76 */
77export function registerTask(task: TaskState, setAppState: SetAppState): void {
78 let isReplacement = false
79 setAppState(prev => {
80 const existing = prev.tasks[task.id]
81 isReplacement = existing !== undefined
82 // Carry forward UI-held state on re-register (resumeAgentBackground
83 // replaces the task; user's retain shouldn't reset). startTime keeps
84 // the panel sort stable; messages + diskLoaded preserve the viewed
85 // transcript across the replace (the user's just-appended prompt lives
86 // in messages and isn't on disk yet).
87 const merged =
88 existing && 'retain' in existing
89 ? {
90 ...task,
91 retain: existing.retain,
92 startTime: existing.startTime,
93 messages: existing.messages,
94 diskLoaded: existing.diskLoaded,
95 pendingMessages: existing.pendingMessages,
96 }
97 : task
98 return { ...prev, tasks: { ...prev.tasks, [task.id]: merged } }
99 })
100
101 // Replacement (resume) — not a new start. Skip to avoid double-emit.
102 if (isReplacement) return
103
104 enqueueSdkEvent({
105 type: 'system',
106 subtype: 'task_started',
107 task_id: task.id,
108 tool_use_id: task.toolUseId,
109 description: task.description,
110 task_type: task.type,
111 workflow_name:
112 'workflowName' in task
113 ? (task.workflowName as string | undefined)
114 : undefined,
115 prompt: 'prompt' in task ? (task.prompt as string) : undefined,
116 })
117}
118
119/**
120 * Eagerly evict a terminal task from AppState.

Callers 12

framework.test.tsFile · 0.85
spawnInProcessTeammateFunction · 0.85
registerMainSessionTaskFunction · 0.85
registerMonitorMcpTaskFunction · 0.85
registerRemoteAgentTaskFunction · 0.85
registerDreamTaskFunction · 0.85
spawnShellTaskFunction · 0.85
registerForegroundFunction · 0.85
registerAsyncAgentFunction · 0.85
registerAgentForegroundFunction · 0.85

Calls 2

enqueueSdkEventFunction · 0.85
setAppStateFunction · 0.50

Tested by

no test coverage detected