Skip to content

feat(tokens): report per-session token usage to the dashboard#52

Merged
Aniketvish0 merged 2 commits into
mainfrom
feat/token-usage-reporting
Jul 8, 2026
Merged

feat(tokens): report per-session token usage to the dashboard#52
Aniketvish0 merged 2 commits into
mainfrom
feat/token-usage-reporting

Conversation

@Pulkit7070

Copy link
Copy Markdown
Contributor

What

Reports per-session LLM token usage from ArmorCodex to the ArmorIQ dashboard so the Token Usage page (tools.armoriq) is populated — reaching parity with ArmorClaude.

Why it was broken

  • The token-reporting code called SDK methods (summarizeTranscriptUsage, recordTokenUsage) that only exist in @armoriq/sdk 0.4.x, while the plugin pinned ^0.3.8 — so the code was dead.
  • Even on 0.4.x, the shared SDK summarizeTranscriptUsage only parses Claude Code's message.usage shape and returns [] for Codex CLI's rollout transcript (event_msgtoken_counttotal_token_usage).

How

  • Bump @armoriq/sdk^0.4.3.
  • Add summarizeCodexTranscriptUsage (scripts/lib/token-usage.mjs): reads the cumulative total_token_usage and turn_context.model, splitting cached_input_tokens out of input_tokens to match the Claude convention. Posts through the shared client.recordTokenUsage.
  • Sends product="armorcodex" (from config.productSlug) explicitly, so a single product-agnostic API key works.

Tests

node --test tests/*.test.mjs: 98 pass / 0 fail, including 6 new parser tests.

🤖 Generated with Claude Code

Pulkit7070 and others added 2 commits July 7, 2026 18:30
Codex CLI's rollout transcript uses a different shape than Claude Code, so the
shared SDK summarizeTranscriptUsage (Anthropic-only) returns nothing for it.
Add a Codex-specific parser (summarizeCodexTranscriptUsage) that reads the
event_msg/token_count events (cumulative total_token_usage) and turn_context
model, splitting cached tokens out of input_tokens to match the Claude
convention. Post through the shared SDK transport (client.recordTokenUsage).

Bumps @armoriq/sdk to ^0.4.3 (the token methods only exist in 0.4.x; the prior
^0.3.8 pin left the token code dead). Sends product="armorcodex" explicitly so
a single generic API key works. Adds unit tests for the parser.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add config.productSlug ("armorcodex") and use it for the token-usage report
instead of a hard-coded string, matching ArmorClaude. Product attribution for
intent/audit/sessions is handled backend-side by classifyProductFromSource
(agent_id -> product), so no per-product API key is required.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 7, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Aniketvish0 Aniketvish0 merged commit 0cc810b into main Jul 8, 2026
2 checks passed
@Aniketvish0 Aniketvish0 deleted the feat/token-usage-reporting branch July 8, 2026 18:43
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.

3 participants