* Get agent identification for analytics. * Priority: AsyncLocalStorage context (subagents) > env vars (swarm teammates)
()
| 512 | * Priority: AsyncLocalStorage context (subagents) > env vars (swarm teammates) |
| 513 | */ |
| 514 | function getAgentIdentification(): { |
| 515 | agentId?: string |
| 516 | parentSessionId?: string |
| 517 | agentType?: 'teammate' | 'subagent' | 'standalone' |
| 518 | teamName?: string |
| 519 | } { |
| 520 | // Check AsyncLocalStorage first (for subagents running in same process) |
| 521 | const agentContext = getAgentContext() |
| 522 | if (agentContext) { |
| 523 | const result: ReturnType<typeof getAgentIdentification> = { |
| 524 | agentId: agentContext.agentId, |
| 525 | parentSessionId: agentContext.parentSessionId, |
| 526 | agentType: agentContext.agentType, |
| 527 | } |
| 528 | if (agentContext.agentType === 'teammate') { |
| 529 | result.teamName = agentContext.teamName |
| 530 | } |
| 531 | return result |
| 532 | } |
| 533 | |
| 534 | // Fall back to swarm helpers (for swarm agents) |
| 535 | const agentId = getAgentId() |
| 536 | const parentSessionId = getTeammateParentSessionId() |
| 537 | const teamName = getTeamName() |
| 538 | const isSwarmAgent = isTeammate() |
| 539 | // For standalone agents (have agent ID but not a teammate), set agentType to 'standalone' |
| 540 | const agentType = isSwarmAgent |
| 541 | ? ('teammate' as const) |
| 542 | : agentId |
| 543 | ? ('standalone' as const) |
| 544 | : undefined |
| 545 | if (agentId || agentType || parentSessionId || teamName) { |
| 546 | return { |
| 547 | ...(agentId ? { agentId } : {}), |
| 548 | ...(agentType ? { agentType } : {}), |
| 549 | ...(parentSessionId ? { parentSessionId } : {}), |
| 550 | ...(teamName ? { teamName } : {}), |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // Check bootstrap state for parent session ID (e.g., plan mode -> implementation) |
| 555 | const stateParentSessionId = getParentSessionIdFromState() |
| 556 | if (stateParentSessionId) { |
| 557 | return { parentSessionId: stateParentSessionId } |
| 558 | } |
| 559 | |
| 560 | return {} |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Extract base version from full version string. "2.0.36-dev.20251107.t174150.sha2709699" → "2.0.36-dev" |
no test coverage detected