Skip to content

feat(extension): show session cost in the context popover - #4751

Merged
iscekic merged 5 commits into
mainfrom
feat/ext-session-cost
Jul 24, 2026
Merged

feat(extension): show session cost in the context popover#4751
iscekic merged 5 commits into
mainfrom
feat/ext-session-cost

Conversation

@iscekic

@iscekic iscekic commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Shows the running total session cost next to context usage in the browser extension side panel. The existing ContextDonut popover gains a Session cost row (under the token summary, above "Compact now"), formatted $X.XXXX identical to the mobile app's formatCost.

  • Client-side sum of streamed usage.cost from the gateway chat-completions stream; no backend changes.
  • usageSchema accepts cost: z.number().nullish(): a chunk with no cost or cost: null contributes $0 and never breaks prompt_tokens parsing (free models, where the gateway strips cost fields, correctly read $0.0000).
  • Cost is forwarded per completion via the existing onUsage (a tool-round turn sums multiple completions), accumulated into a per-conversation in-memory jotai atom with the same lifecycle as contextUsageAtomFamily (kept across close, evicted on delete and sign-out, reset on reload).
  • Session cost survives manual and auto compaction (compaction resets only measured context usage).

Test plan

  • pnpm --filter kilo-extension verify — typecheck, lint, format:check, 230 vitest tests (new: stream-client cost parsing present/missing/null, runner per-completion forwarding incl. in-turn tool-round order, atom eviction/sign-out lifecycle, formatSessionCost/addSessionCost edge cases).
  • pnpm --filter kilo-extension e2e:chrome — 53 passed; new E2E proves empty $0.0000 state, in-turn tool-round accumulation ($0.0130), cross-turn accumulation ($0.0140), unchanged donut aria-label, and cost surviving manual compaction ($0.0123).
  • pnpm --filter kilo-extension build / build:firefox / e2e:firefox — green (existing scenarios; the new row has Chrome-only E2E, matching the existing context-usage coverage).

@kilo-code-bot

kilo-code-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Re-reviewed after new commits added assistant-streaming-id tracking (streamingMessageIdAtomFamily, onAssistantStreaming) and a Bedrock empty-tool-call-arguments fix; found no correctness, security, or reliability issues in the changed lines.

Files Reviewed (12 files)
  • apps/extension/entrypoints/sidepanel/agent-chat-atoms.ts
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
  • apps/extension/entrypoints/sidepanel/context-donut.tsx
  • apps/extension/src/shared/agent-chat-atoms.test.ts
  • apps/extension/src/shared/agent-llm-turn-runner-core.test.ts
  • apps/extension/src/shared/agent-llm-turn-runner-core.ts
  • apps/extension/src/shared/kilo-gateway-chat-client.ts
  • apps/extension/src/shared/kilo-gateway-chat-stream-client.test.ts
  • apps/extension/src/shared/kilo-gateway-chat-stream-client.ts
  • apps/extension/src/shared/session-cost.test.ts
  • apps/extension/src/shared/session-cost.ts
  • apps/extension/tests/e2e/context-usage.test.ts
Previous Review Summary (commit a3a3322)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit a3a3322)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the session-cost tracking feature (in-memory atom, gateway usage parsing, and context-popover UI) with high confidence and found no correctness, security, or reliability issues in the changed lines.

Files Reviewed (12 files)
  • apps/extension/entrypoints/sidepanel/agent-chat-atoms.ts
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
  • apps/extension/entrypoints/sidepanel/context-donut.tsx
  • apps/extension/src/shared/agent-chat-atoms.test.ts
  • apps/extension/src/shared/agent-llm-turn-runner-core.test.ts
  • apps/extension/src/shared/agent-llm-turn-runner-core.ts
  • apps/extension/src/shared/kilo-gateway-chat-client.ts
  • apps/extension/src/shared/kilo-gateway-chat-stream-client.test.ts
  • apps/extension/src/shared/kilo-gateway-chat-stream-client.ts
  • apps/extension/src/shared/session-cost.test.ts
  • apps/extension/src/shared/session-cost.ts
  • apps/extension/tests/e2e/context-usage.test.ts

Reviewed by claude-sonnet-5 · Input: 24 · Output: 8.6K · Cached: 539.2K

Review guidance: REVIEW.md from base branch main

@iscekic
iscekic enabled auto-merge (squash) July 24, 2026 15:59

@pandemicsyn pandemicsyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Comment thread apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx Outdated
iscekic added 2 commits July 24, 2026 21:12
# Conflicts:
#	apps/extension/entrypoints/sidepanel/agent-chat-atoms.ts
#	apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
#	apps/extension/src/shared/agent-chat-atoms.test.ts
@iscekic
iscekic merged commit d8f3696 into main Jul 24, 2026
17 checks passed
@iscekic
iscekic deleted the feat/ext-session-cost branch July 24, 2026 19:25
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.

2 participants