* Get the agent name to poll for messages. * - In-process teammates return undefined (they use waitForNextPromptOrShutdown instead) * - Process-based teammates use their CLAUDE_CODE_AGENT_NAME * - Team leads use their name from teamContext.teammates * - Standalone sessions return undefined
(appState: AppState)
| 79 | * - Standalone sessions return undefined |
| 80 | */ |
| 81 | function getAgentNameToPoll(appState: AppState): string | undefined { |
| 82 | // In-process teammates should NOT use useInboxPoller - they have their own |
| 83 | // polling mechanism via waitForNextPromptOrShutdown() in inProcessRunner.ts. |
| 84 | // Using useInboxPoller would cause message routing issues since in-process |
| 85 | // teammates share the same React context and AppState with the leader. |
| 86 | // |
| 87 | // Note: This can be called when the leader's REPL re-renders while an |
| 88 | // in-process teammate's AsyncLocalStorage context is active (due to shared |
| 89 | // setAppState). We return undefined to gracefully skip polling rather than |
| 90 | // throwing, since this is a normal occurrence during concurrent execution. |
| 91 | if (isInProcessTeammate()) { |
| 92 | return undefined |
| 93 | } |
| 94 | if (isTeammate()) { |
| 95 | return getAgentName() |
| 96 | } |
| 97 | // Team lead polls using their agent name (not ID) |
| 98 | if (isTeamLead(appState.teamContext)) { |
| 99 | const leadAgentId = appState.teamContext!.leadAgentId |
| 100 | // Look up the lead's name from teammates map |
| 101 | const leadName = appState.teamContext!.teammates[leadAgentId]?.name |
| 102 | return leadName || 'team-lead' |
| 103 | } |
| 104 | return undefined |
| 105 | } |
| 106 | |
| 107 | const INBOX_POLL_INTERVAL_MS = 1000 |
| 108 |
no test coverage detected