MCPcopy Index your code
hub / github.com/codeaashu/claude-code / computeInitialTeamContext

Function computeInitialTeamContext

src/utils/swarm/reconnection.ts:23–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 * @returns The teamContext object to include in initialState, or undefined if not a teammate
22 */
23export function computeInitialTeamContext():
24 | AppState['teamContext']
25 | undefined {
26 // dynamicTeamContext is set in main.tsx from CLI args
27 const context = getDynamicTeamContext()
28
29 if (!context?.teamName || !context?.agentName) {
30 logForDebugging(
31 '[Reconnection] computeInitialTeamContext: No teammate context set (not a teammate)',
32 )
33 return undefined
34 }
35
36 const { teamName, agentId, agentName } = context
37
38 // Read team file to get lead agent ID
39 const teamFile = readTeamFile(teamName)
40 if (!teamFile) {
41 logError(
42 new Error(
43 `[computeInitialTeamContext] Could not read team file for ${teamName}`,
44 ),
45 )
46 return undefined
47 }
48
49 const teamFilePath = getTeamFilePath(teamName)
50
51 const isLeader = !agentId
52
53 logForDebugging(
54 `[Reconnection] Computed initial team context for ${isLeader ? 'leader' : `teammate ${agentName}`} in team ${teamName}`,
55 )
56
57 return {
58 teamName,
59 teamFilePath,
60 leadAgentId: teamFile.leadAgentId,
61 selfAgentId: agentId,
62 selfAgentName: agentName,
63 isLeader,
64 teammates: {},
65 }
66}
67
68/**
69 * Initialize teammate context from a resumed session.

Callers 1

runFunction · 0.85

Calls 5

getDynamicTeamContextFunction · 0.85
logForDebuggingFunction · 0.85
readTeamFileFunction · 0.85
getTeamFilePathFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected