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

Function killInProcessTeammate

src/utils/swarm/spawnInProcess.ts:228–351  ·  view source on GitHub ↗
(
  taskId: string,
  setAppState: SetAppStateFn,
)

Source from the content-addressed store, hash-verified

226 * @returns true if killed successfully
227 */
228export function killInProcessTeammate(
229 taskId: string,
230 setAppState: SetAppStateFn,
231): boolean {
232 let killed = false
233 let teamName: string | null = null
234 let agentId: string | null = null
235 let toolUseId: string | undefined
236 let description: string | undefined
237 let pendingAutonomyRuns: Array<{ runId: string; rootDir?: string }> = []
238
239 setAppState((prev: AppState) => {
240 const task = prev.tasks[taskId]
241 if (!task || task.type !== 'in_process_teammate') {
242 return prev
243 }
244
245 const teammateTask = task as InProcessTeammateTaskState
246
247 if (teammateTask.status !== 'running') {
248 return prev
249 }
250
251 // Capture identity for cleanup after state update
252 teamName = teammateTask.identity.teamName
253 agentId = teammateTask.identity.agentId
254 toolUseId = teammateTask.toolUseId
255 description = teammateTask.description
256
257 // Capture pending autonomy run IDs before clearing them
258 pendingAutonomyRuns = teammateTask.pendingUserMessages.flatMap(message =>
259 message.autonomyRunId
260 ? [
261 {
262 runId: message.autonomyRunId,
263 ...(message.autonomyRootDir
264 ? { rootDir: message.autonomyRootDir }
265 : {}),
266 },
267 ]
268 : [],
269 )
270
271 // Abort the controller to stop execution
272 teammateTask.abortController?.abort()
273
274 // Call cleanup handler
275 teammateTask.unregisterCleanup?.()
276
277 // Update task state and remove from teamContext.teammates
278 killed = true
279
280 // Call pending idle callbacks to unblock any waiters (e.g., engine.waitForIdle)
281 teammateTask.onIdleCallbacks?.forEach(cb => cb())
282
283 // Remove from teamContext.teammates using the agentId
284 let updatedTeamContext = prev.teamContext
285 if (prev.teamContext && prev.teamContext.teammates && agentId) {

Callers 3

killMethod · 0.85
killFunction · 0.85

Calls 8

cbFunction · 0.85
removeMemberByAgentIdFunction · 0.85
markAutonomyRunFailedFunction · 0.85
evictTaskOutputFunction · 0.85
emitTaskTerminatedSdkFunction · 0.85
nowMethod · 0.80
abortMethod · 0.65
setAppStateFunction · 0.50

Tested by

no test coverage detected