MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / stopTask

Function stopTask

source code/tasks/stopTask.ts:40–102  ·  view source on GitHub ↗
(
  taskId: string,
  context: StopTaskContext,
)

Source from the content-addressed store, hash-verified

38 * distinguish the failure reason.
39 */
40export async function stopTask(
41 taskId: string,
42 context: StopTaskContext,
43): Promise<StopTaskResult> {
44 const { getAppState, setAppState } = context
45 const appState = getAppState()
46 const task = appState.tasks?.[taskId] as TaskStateBase | undefined
47
48 if (!task) {
49 throw new StopTaskError(`No task found with ID: ${taskId}`, 'not_found')
50 }
51
52 if (task.status !== 'running') {
53 throw new StopTaskError(
54 `Task ${taskId} is not running (status: ${task.status})`,
55 'not_running',
56 )
57 }
58
59 const taskImpl = getTaskByType(task.type)
60 if (!taskImpl) {
61 throw new StopTaskError(
62 `Unsupported task type: ${task.type}`,
63 'unsupported_type',
64 )
65 }
66
67 await taskImpl.kill(taskId, setAppState)
68
69 // Bash: suppress the "exit code 137" notification (noise). Agent tasks: don't
70 // suppress — the AbortError catch sends a notification carrying
71 // extractPartialResult(agentMessages), which is the payload not noise.
72 if (isLocalShellTask(task)) {
73 let suppressed = false
74 setAppState(prev => {
75 const prevTask = prev.tasks[taskId]
76 if (!prevTask || prevTask.notified) {
77 return prev
78 }
79 suppressed = true
80 return {
81 ...prev,
82 tasks: {
83 ...prev.tasks,
84 [taskId]: { ...prevTask, notified: true },
85 },
86 }
87 })
88 // Suppressing the XML notification also suppresses print.ts's parsed
89 // task_notification SDK event — emit it directly so SDK consumers see
90 // the task close.
91 if (suppressed) {
92 emitTaskTerminatedSdk(taskId, 'stopped', {
93 toolUseId: task.toolUseId,
94 summary: task.description,
95 })
96 }
97 }

Callers 2

callFunction · 0.85
runHeadlessStreamingFunction · 0.85

Calls 5

getTaskByTypeFunction · 0.85
isLocalShellTaskFunction · 0.85
emitTaskTerminatedSdkFunction · 0.85
getAppStateFunction · 0.50
killMethod · 0.45

Tested by

no test coverage detected