MCPcopy Create free account
hub / github.com/WJX20/claude-code / registerAsyncAgent

Function registerAsyncAgent

src/tasks/LocalAgentTask/LocalAgentTask.tsx:467–516  ·  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

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