MCPcopy
hub / github.com/codeaashu/claude-code / registerAsyncAgent

Function registerAsyncAgent

src/tasks/LocalAgentTask/LocalAgentTask.tsx:466–515  ·  view source on GitHub ↗
({
  agentId,
  description,
  prompt,
  selectedAgent,
  setAppState,
  parentAbortController,
  toolUseId
}: {
  agentId: string;
  description: string;
  prompt: string;
  selectedAgent: AgentDefinition;
  setAppState: SetAppState;
  parentAbortController?: AbortController;
  toolUseId?: string;
})

Source from the content-addressed store, hash-verified

464 * This ensures subagents are aborted when their parent (e.g., in-process teammate) aborts.
465 */
466export function registerAsyncAgent({
467 agentId,
468 description,
469 prompt,
470 selectedAgent,
471 setAppState,
472 parentAbortController,
473 toolUseId
474}: {
475 agentId: string;
476 description: string;
477 prompt: string;
478 selectedAgent: AgentDefinition;
479 setAppState: SetAppState;
480 parentAbortController?: AbortController;
481 toolUseId?: string;
482}): LocalAgentTaskState {
483 void initTaskOutputAsSymlink(agentId, getAgentTranscriptPath(asAgentId(agentId)));
484
485 // Create abort controller - if parent provided, create child that auto-aborts with parent
486 const abortController = parentAbortController ? createChildAbortController(parentAbortController) : createAbortController();
487 const taskState: LocalAgentTaskState = {
488 ...createTaskStateBase(agentId, 'local_agent', description, toolUseId),
489 type: 'local_agent',
490 status: 'running',
491 agentId,
492 prompt,
493 selectedAgent,
494 agentType: selectedAgent.agentType ?? 'general-purpose',
495 abortController,
496 retrieved: false,
497 lastReportedToolCount: 0,
498 lastReportedTokenCount: 0,
499 isBackgrounded: true,
500 // registerAsyncAgent immediately backgrounds
501 pendingMessages: [],
502 retain: false,
503 diskLoaded: false
504 };
505
506 // Register cleanup handler
507 const unregisterCleanup = registerCleanup(async () => {
508 killAsyncAgent(agentId, setAppState);
509 });
510 taskState.unregisterCleanup = unregisterCleanup;
511
512 // Register task in AppState
513 registerTask(taskState, setAppState);
514 return taskState;
515}
516
517// Map of taskId -> resolve function for background signals
518// When backgroundAgentTask is called, it resolves the corresponding promise

Callers 2

resumeAgentBackgroundFunction · 0.85
callFunction · 0.85

Calls 9

initTaskOutputAsSymlinkFunction · 0.85
getAgentTranscriptPathFunction · 0.85
asAgentIdFunction · 0.85
createAbortControllerFunction · 0.85
createTaskStateBaseFunction · 0.85
registerCleanupFunction · 0.85
killAsyncAgentFunction · 0.85
registerTaskFunction · 0.85

Tested by

no test coverage detected