MCPcopy Create free account
hub / github.com/Noumena-Network/code / handleSpawnSeparateWindow

Function handleSpawnSeparateWindow

src/tools/shared/spawnMultiAgent.ts:534–742  ·  view source on GitHub ↗

* Handle spawn operation using separate windows (legacy behavior). * Creates each teammate in its own tmux window.

(
  input: SpawnInput,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

532 * Creates each teammate in its own tmux window.
533 */
534async function handleSpawnSeparateWindow(
535 input: SpawnInput,
536 context: ToolUseContext,
537): Promise<{ data: SpawnOutput }> {
538 const { setAppState, getAppState } = context
539 const { name, prompt, agent_type, cwd, plan_mode_required } = input
540
541 // Resolve model: 'inherit' → leader's model; undefined → default Opus
542 const model = resolveTeammateModel(input.model, getAppState().mainLoopModel)
543
544 if (!name || !prompt) {
545 throw new Error('name and prompt are required for spawn operation')
546 }
547
548 // Get team name from input or inherit from leader's team context
549 const appState = getAppState()
550 const teamName = input.team_name || appState.teamContext?.teamName
551
552 if (!teamName) {
553 throw new Error(
554 'team_name is required for spawn operation. Either provide team_name in input or call spawnTeam first to establish team context.',
555 )
556 }
557
558 // Generate unique name if duplicate exists in team
559 const uniqueName = await generateUniqueTeammateName(name, teamName)
560
561 // Sanitize the name to prevent @ in agent IDs (would break agentName@teamName format)
562 const sanitizedName = sanitizeAgentName(uniqueName)
563
564 // Generate deterministic agent ID from name and team
565 const teammateId = formatAgentId(sanitizedName, teamName)
566 const windowName = `teammate-${sanitizeName(sanitizedName)}`
567 const workingDir = cwd || getCwd()
568
569 // Ensure the swarm session exists
570 await ensureSession(SWARM_SESSION_NAME)
571
572 // Assign a unique color to this teammate
573 const teammateColor = assignTeammateColor(teammateId)
574
575 // Create a new window for this teammate
576 const createWindowResult = await execFileNoThrow(TMUX_COMMAND, [
577 'new-window',
578 '-t',
579 SWARM_SESSION_NAME,
580 '-n',
581 windowName,
582 '-P',
583 '-F',
584 '#{pane_id}',
585 ])
586
587 if (createWindowResult.code !== 0) {
588 throw new Error(
589 `Failed to create tmux window: ${createWindowResult.stderr}`,
590 )
591 }

Callers 1

handleSpawnFunction · 0.85

Calls 15

resolveTeammateModelFunction · 0.85
sanitizeAgentNameFunction · 0.85
formatAgentIdFunction · 0.85
getCwdFunction · 0.85
ensureSessionFunction · 0.85
assignTeammateColorFunction · 0.85
quoteFunction · 0.85
getSessionIdFunction · 0.85
buildInheritedEnvVarsFunction · 0.85

Tested by

no test coverage detected