Skip to content

Add sessionId extraction and displayName() to KnownAgent#9

Open
impruthvi wants to merge 2 commits intoshipfastlabs:mainfrom
impruthvi:feat/session-id-and-display-name
Open

Add sessionId extraction and displayName() to KnownAgent#9
impruthvi wants to merge 2 commits intoshipfastlabs:mainfrom
impruthvi:feat/session-id-and-display-name

Conversation

@impruthvi
Copy link
Copy Markdown

What

Two non-breaking additions to AgentResult and KnownAgent:

Session ID extraction
AgentResult gains an optional sessionId property. AgentDetector now reads
session/thread env vars per agent before returning:

  • CODEX_THREAD_ID → Codex
  • AMP_CURRENT_THREAD_ID → Amp
  • CLAUDE_CODE_SESSION_ID → Claude (future-ready)

All other agents return null — fully backwards compatible.

Display names
KnownAgent::displayName() returns a human-readable name for each agent:
KnownAgent::Claude->displayName()"Claude Code"
KnownAgent::Copilot->displayName()"GitHub Copilot"

Useful for logging, UI, and response headers where the internal key (claude, copilot) is too terse.

Why

Downstream tooling (log formatters, observability layers) needs both a pretty name
and a session ID to produce useful output. Without session IDs, all Codex log lines
are indistinguishable across runs.

Changes

  • src/AgentResult.php — add ?string $sessionId = null
  • src/AgentDetector.php — extract session IDs via match before returning
  • src/KnownAgent.php — add displayName(): string
  • tests/AgentDetectorTest.php — 19 new tests (session ID + display names)
  • README.md — updated usage examples and agents table

Testing

composer test:unit

All 59 tests pass.

- AgentResult gains optional `sessionId` property (non-breaking)
- AgentDetector extracts CODEX_THREAD_ID, AMP_CURRENT_THREAD_ID, and
  CLAUDE_CODE_SESSION_ID from env vars per detected agent
- KnownAgent gains displayName() returning human-readable agent names
  (e.g. "Claude Code", "GitHub Copilot", "Gemini CLI")
- 19 new tests covering sessionId extraction and all displayName() cases
@pushpak1300 pushpak1300 self-requested a review April 19, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant