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

Function getAgentNameToPoll

src/hooks/useInboxPoller.ts:81–105  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

79 * - Standalone sessions return undefined
80 */
81function 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
107const INBOX_POLL_INTERVAL_MS = 1000
108

Callers 1

useInboxPollerFunction · 0.85

Calls 4

isInProcessTeammateFunction · 0.85
isTeammateFunction · 0.85
getAgentNameFunction · 0.85
isTeamLeadFunction · 0.85

Tested by

no test coverage detected