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

Function spawnInProcessTeammate

src/utils/swarm/spawnInProcess.ts:104–216  ·  view source on GitHub ↗
(
  config: InProcessSpawnConfig,
  context: SpawnContext,
)

Source from the content-addressed store, hash-verified

102 * @returns Spawn result with teammate info
103 */
104export async function spawnInProcessTeammate(
105 config: InProcessSpawnConfig,
106 context: SpawnContext,
107): Promise<InProcessSpawnOutput> {
108 const { name, teamName, prompt, color, planModeRequired, model } = config
109 const { setAppState } = context
110
111 // Generate deterministic agent ID
112 const agentId = formatAgentId(name, teamName)
113 const taskId = generateTaskId('in_process_teammate')
114
115 logForDebugging(
116 `[spawnInProcessTeammate] Spawning ${agentId} (taskId: ${taskId})`,
117 )
118
119 try {
120 // Create independent AbortController for this teammate
121 // Teammates should not be aborted when the leader's query is interrupted
122 const abortController = createAbortController()
123
124 // Get parent session ID for transcript correlation
125 const parentSessionId = getSessionId()
126
127 // Create teammate identity (stored as plain data in AppState)
128 const identity: TeammateIdentity = {
129 agentId,
130 agentName: name,
131 teamName,
132 color,
133 planModeRequired,
134 parentSessionId,
135 }
136
137 // Create teammate context for AsyncLocalStorage
138 // This will be used by runWithTeammateContext() during agent execution
139 const teammateContext = createTeammateContext({
140 agentId,
141 agentName: name,
142 teamName,
143 color,
144 planModeRequired,
145 parentSessionId,
146 abortController,
147 })
148
149 // Register agent in Perfetto trace for hierarchy visualization
150 if (isPerfettoTracingEnabled()) {
151 registerPerfettoAgent(agentId, name, parentSessionId)
152 }
153
154 // Create task state
155 const description = `${name}: ${prompt.substring(0, 50)}${prompt.length > 50 ? '...' : ''}`
156
157 const taskState: InProcessTeammateTaskState = {
158 ...createTaskStateBase(
159 taskId,
160 'in_process_teammate',
161 description,

Callers 2

handleSpawnInProcessFunction · 0.85
spawnMethod · 0.85

Calls 11

formatAgentIdFunction · 0.85
generateTaskIdFunction · 0.85
logForDebuggingFunction · 0.85
createAbortControllerFunction · 0.85
getSessionIdFunction · 0.85
createTeammateContextFunction · 0.85
isPerfettoTracingEnabledFunction · 0.85
createTaskStateBaseFunction · 0.85
getSpinnerVerbsFunction · 0.85
registerCleanupFunction · 0.85
registerTaskFunction · 0.85

Tested by

no test coverage detected