Skip to content

feat(opencode): show token throughput metrics - #12434

Merged
marius-kilocode merged 19 commits into
Kilo-Org:mainfrom
Githubguy132010:feat/token-throughput-v2
Jul 23, 2026
Merged

feat(opencode): show token throughput metrics#12434
marius-kilocode merged 19 commits into
Kilo-Org:mainfrom
Githubguy132010:feat/token-throughput-v2

Conversation

@Githubguy132010

@Githubguy132010 Githubguy132010 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Issue

Closes #6579

Context

Adds tokens-per-second throughput metrics for #6579. The backend records a per-step generation rate on StepFinishPart; the Kilo CLI sidebar surfaces a TG row in its usage panel, and the VSCode webview integrates TG into the existing Tokens row at the top of the task header plus a per-message line beneath each assistant response. Both VSCode surfaces use the same plain-text styling as the surrounding tokens so throughput reads as one family of secondary info rather than a separate pill. A new "Show Token Throughput" toggle in Display settings (off by default) controls both VSCode surfaces.

Replaces the approach from closed PR #9773 — that one was shelved because Marius wanted a clearer UX before going forward and the token indicator stopped showing after upstream merges. This iteration narrows the wire shape, gates display behind a toggle, integrates TG into existing UI rather than adding standalone elements, and runs every change through three rounds of adversarial review (correctness / UX / merge-conflict) before shipping.

Implementation

  • Backend (packages/opencode/src/kilocode/session/metrics.ts): new computeMetrics helper derives generation rate from (output + reasoning) tokens * 1000 / elapsedMs. Optional metrics field added to StepFinishPart schema in packages/core/src/v1/session.ts with kilocode_change markers; SDK regenerated to expose the new field.

  • CLI (packages/opencode/src/kilocode/plugins/sidebar-usage.tsx): single TG row in the usage panel, hidden when no metrics are available. Local aggregation via token-weighted mean across step-finish parts.

  • VSCode (packages/kilo-vscode/webview-ui/):

    • Aggregated TG renders inline in the existing Tokens row of TaskUsage.tsx (alongside ↑ input, ↑ cache, ↓ output) — no separate element. TaskUsage accepts a throughput?: number prop and emits TG <rate> t/s as a plain-text span when present, matching the surrounding task-header-tokens-value style.
    • Per-message TG in AssistantMessage.tsx renders as plain text using var(--vscode-descriptionForeground) and font-variant-numeric: tabular-nums — same tone as the Tokens row, no pill background or border.
    • Both surfaces share a single display.throughputVisible() signal hoisted to DisplayProvider so toggling once updates both without round-trips.
    • Toggle hydrates from settings() via the existing chatSettingsLoaded pattern; onDidChangeConfiguration watcher pushes runtime setting changes to the webview.
  • PP deferred: the AI SDK adapter at packages/opencode/src/session/llm/ai-sdk.ts:64 wraps raw usage as { aiSdk: item.raw }, but @ai-sdk/openai-compatible's convertOpenAICompatibleChatUsage returns raw: usage — the response-level timings object (where llama.cpp puts prompt_per_second / predicted_per_second) never reaches providerMetadata. PP cannot be derived without patching the shared createOpenAICompatible call at packages/opencode/src/provider/provider.ts:131 (out of scope for a Kilo-only change). Follow-up tracked separately; the wire shape keeps the optional prompt field so the schema doesn't need to change.

  • Provider source dropped: same root cause. The providerRate branch was opportunistic detection of provider-reported rates — but with the upstream blocker, it's dead code. computeMetrics always emits source: "computed"; consumers (CLI sidebar, webview surfaces) handle the single literal.

Screenshots / Video

Schermopname.2026-07-21.om.19.25.04.mov

How to Test

Manual/local verification

  • VSCode: cd packages/kilo-vscode && bun run extension. Toggle "Show Token Throughput" in Display settings. Run a non-trivial assistant prompt. Confirm the TG value appears inline in the Tokens row at the top of the task header and as plain text under each assistant message. Toggle off — both surfaces should hide immediately without reload. Edit settings.json directly to flip the value — same behavior.
  • CLI: cd packages/opencode && bun run build && ./bin/kilo. Open the TUI sidebar, run a session, confirm the TG row appears in the usage panel alongside Input/Output/Reasoning/Cache.
  • Edge cases: very short responses (TG can look inflated for <50 generated tokens), reasoning-only turns (no TG at all because computeMetrics returns undefined when generated <= 0).

Reviewer test steps

  1. cd packages/kilo-vscode && bun run extension to launch the dev VS Code window.
  2. Settings → search "Show Token Throughput" → toggle on. Confirm the Switch visually flips on click.
  3. Open the Kilo sidebar, send "Write a Python function that computes fibonacci and explain it." Confirm TG <rate> t/s appears as plain text under the assistant message.
  4. Look at the Tokens row at the top of the task header. Confirm TG <rate> t/s appears inline there too (after the ↓ output value), in the same plain-text style as the surrounding tokens.
  5. Toggle the setting off. Confirm TG disappears from both surfaces immediately.
  6. Edit ~/.config/Code/User/settings.json to flip kilo-code.new.showTokenThroughput. Confirm the toggle reflects without reload.
  7. cd packages/opencode && bun run build && ./bin/kilo. Run a session, confirm TG row appears in the sidebar usage panel.

Blocked checks and substitute verification

  • bun turbo typecheck was excluded by design — it fans out to a Gradle/Kotlin build of packages/kilo-jetbrains (~9 min cold cache) that is unrelated to this feature. Per-package checks (packages/opencode typecheck + targeted tests; packages/kilo-vscode typecheck + lint + test:unit + knip + check-kilocode-change) cover the touched code and were green.
  • bun test:unit in packages/kilo-vscode/ reports 3251 pass / 1 fail. The single failing test is tests/unit/worktree-manager.test.ts:986 (WorktreeManager.resolveStartPoint > returns bare branch + remote when remote exists), which is a pre-existing failure on main unrelated to this branch (the test file is untouched here).

Verification

The diff went through three rounds of adversarial review (correctness, UX, merge-conflict lenses), each with refuter-style finding verification. UI was iterated inline after review: pill styling replaced with plain text matched to the Tokens row, aggregated TG moved into the Tokens row itself rather than a standalone element. Final state: aggregated TG inline in TaskUsage, per-message TG as a plain-text line, both gated by display.throughputVisible(), toggle hydrates from settings() and reflects runtime changes via onDidChangeConfiguration.

Checklist

  • Issue linked above
  • Tests/verification described
  • Screenshots/video included for visual changes
  • Changeset considered (.changeset/token-throughput-v2.md, minor bump on @kilocode/kilo and @kilocode/sdk)
  • I personally reviewed the diff and can explain the changes

Get in Touch

Discord: thomas07374

@Githubguy132010
Githubguy132010 marked this pull request as ready for review July 21, 2026 17:33
Comment thread packages/kilo-vscode/src/KiloProvider.ts Outdated
Comment thread script/check-opencode-annotations.ts Outdated
Comment thread package.json Outdated
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx Outdated
Comment thread packages/opencode/src/kilocode/plugins/sidebar-usage.tsx Outdated
Comment thread packages/kilo-vscode/tests/unit/session-utils.test.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Reviewed the incremental diff since the last review (commit 582cf4defe7a3bcc3d6bafed5be35c28084a0b3ba2a6efe2e7dd11adbccef69a00a1398f4bc8f17d). gh pr diff --patch returns the PR's mailbox-formatted commit series rather than a single unified diff, so the incremental window was isolated by matching the previous review's SHA to commit 17/18 in that series; the only new commit is 18/18.

  • packages/opencode/src/session/processor.ts — adds a // kilocode_change marker comment on the existing time: { start: ctx.stepStartDate } line in the shared step-start emission. No behavior change; purely an annotation fix (this is the annotation-check housekeeping the fork-hygiene tooling expects, not a defect).

No new bugs, style violations, or fork-hygiene issues introduced by this commit. All 40 existing inline comments on this PR remain stale (line: null for every one via the Pulls Comments API), so none are carried forward.

Files Reviewed (1 file, incremental)
  • packages/opencode/src/session/processor.ts
Previous Review Summaries (8 snapshots, latest commit 582cf4d)

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

Previous review (commit 582cf4d)

Status: No Issues Found | Recommendation: Merge

Reviewed the incremental diff since the last review (verified via git diff against the previous review commit — 28 files, +84/-50 lines; gh pr diff returned stale/garbled content for this PR and was not used). The change is a cosmetic repositioning of the per-message throughput indicator, addressing reviewer feedback to move it beside the copy/feedback buttons instead of below the message, plus a changeset package-name correction.

  • packages/kilo-ui/src/components/message-part.tsx / message-part.css — added an optional throughput prop rendered inside the existing copy/feedback action row (assistant-throughput-inline slot), gated by the same showCopy() condition as the action row itself.
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsxThroughputBadge is now built only for the text part matching showAssistantCopyPartID and passed through as throughput; the old standalone <Show> below the message list was removed. Gating logic is consistent with showCopy().
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css — updated [data-component="assistant-throughput"] comment/layout (display: block / margin-top dropped) to match the new inline placement.
  • .changeset/token-throughput-v2.md — corrected package name from @kilocode/kilo to @kilocode/cli, matching packages/opencode/package.json.
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts and packages/kilo-vscode/tests/unit/session-utils.test.ts — formatting-only (line wrapping), no content changes.

All findings from the previous review round (guard blocking top-level settings persistence, samples reset on session change, tooltip duplicated unit, dead CSS rule, redundant checks in model-usage.ts, merge-commit regressions in package.json/bun.lock/script/check-opencode-annotations.ts) were already resolved prior to this incremental window and confirmed fixed via the PR's own review-comment replies; the 40 existing inline comments on this PR are all stale (GitHub reports line: null for every one), so none are carried forward.

Files Reviewed (28 files, incremental)
  • .changeset/token-throughput-v2.md
  • packages/kilo-ui/src/components/message-part.css
  • packages/kilo-ui/src/components/message-part.tsx
  • packages/kilo-vscode/tests/unit/session-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx
  • packages/kilo-vscode/webview-ui/src/context/session-utils.ts
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (22 locale files)
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css

Previous review (commit 65e552c)

Status: No Issues Found | Recommendation: Merge

All findings from the previous review have been addressed in the latest commits:

  • packages/kilo-vscode/src/KiloProvider.ts — the validThroughputSetting guard that blocked persistence of top-level settings has been removed; handleUpdateSetting now falls through correctly for keys with no dot-separated section.
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsxsamples is now reset via a createEffect keyed on props.session_id.
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx — the aggregated Tokens-row throughput display (and its tooltip/formatting issues) was removed entirely; throughput now surfaces only as the per-message footer in AssistantMessage.tsx, gated correctly by the display toggle.
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css — the dead [data-component="assistant-memory-badge"] rule was replaced with [data-component="assistant-throughput"], which matches the element actually rendered in AssistantMessage.tsx.
  • packages/opencode/src/kilocode/plugins/model-usage.tsaggregateMetrics was reworked into a weighted-by-elapsed-time calculation with a last-wins fallback; covered by new tests in packages/opencode/test/kilocode/tui/usage.test.ts.

Reviewed the incremental diff (34 files, ~495/-163 lines) covering the throughput wire-shape addition (time on StepStartPart/StepFinishPart, properly marked with kilocode_change and mirrored to the SDK/OpenAPI spec), the per-message weighted aggregation in session-utils.ts/model-usage.ts, and the processor timestamp plumbing in packages/opencode/src/session/processor.ts. No new correctness, security, or fork-hygiene issues found on the changed lines.

Files Reviewed (34 files)
  • packages/core/src/v1/session.ts
  • packages/kilo-vscode/tests/unit/session-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx
  • packages/kilo-vscode/webview-ui/src/context/session-utils.ts
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (20 locale files)
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css
  • packages/kilo-vscode/webview-ui/src/types/messages/parts.ts
  • packages/opencode/src/kilocode/plugins/model-usage.ts
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsx
  • packages/opencode/src/session/processor.ts
  • packages/opencode/test/kilocode/tui/usage.test.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts
  • packages/sdk/openapi.json

Previous review (commit 41270b0)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 3
SUGGESTION 2

Note: No new commits with file changes since the last review. The only new commit (405a0c1f8d) is an empty CI re-run with no diff, so this update simply re-verifies the previously reported findings against current HEAD — all six remain present at the same locations.

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 3688 Guard still blocks persistence of every top-level (no-dot) setting key, not just showTokenThroughputvalidThroughputSetting only returns true for that one key.

WARNING

File Line Issue
packages/opencode/src/kilocode/plugins/sidebar-usage.tsx 76 samples is still never reset when props.session_id changes.
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 77 The throughput tooltip calls language.t("chat.throughput.speed.tooltip") without the speed param, so the {{speed}} placeholder resolves empty.
packages/kilo-vscode/webview-ui/src/styles/chat-layout.css 231 [data-component="assistant-memory-badge"] rule targets a component that no longer exists in the tree.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 30 Reimplements throughput-formatting logic instead of reusing the shared formatTG helper — likely the root cause of the tooltip bug above.
packages/opencode/src/kilocode/plugins/model-usage.ts 72, 110 Two small dead-code guards (value === undefined after Number.isFinite, and sample.generated ?? 0 on an already-required number).
Files Reviewed (0 new files — no diff since last review)

No file changes between the previously reviewed commit and current HEAD; the sole new commit is an empty CI re-run.

Fix these issues in Kilo Cloud

Previous review (commit 405a0c1)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 3
SUGGESTION 2

Note: No new commits with file changes since the last review. The only new commit (405a0c1f8d) is an empty CI re-run with no diff, so this update simply re-verifies the previously reported findings against current HEAD — all six remain present at the same locations.

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 3688 Guard still blocks persistence of every top-level (no-dot) setting key, not just showTokenThroughputvalidThroughputSetting only returns true for that one key.

WARNING

File Line Issue
packages/opencode/src/kilocode/plugins/sidebar-usage.tsx 76 samples is still never reset when props.session_id changes.
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 77 The throughput tooltip calls language.t("chat.throughput.speed.tooltip") without the speed param, so the {{speed}} placeholder resolves empty.
packages/kilo-vscode/webview-ui/src/styles/chat-layout.css 231 [data-component="assistant-memory-badge"] rule targets a component that no longer exists in the tree.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 30 Reimplements throughput-formatting logic instead of reusing the shared formatTG helper — likely the root cause of the tooltip bug above.
packages/opencode/src/kilocode/plugins/model-usage.ts 72, 110 Two small dead-code guards (value === undefined after Number.isFinite, and sample.generated ?? 0 on an already-required number).
Files Reviewed (0 new files — no diff since last review)

No file changes between the previously reviewed commit and current HEAD; the sole new commit is an empty CI re-run.

Fix these issues in Kilo Cloud

Previous review (commit aa3fe36)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 3
SUGGESTION 2

Note: The branch was rewritten again since the last review (the previous review commit is no longer in history), so this is a fresh full review. Good news: the merge-commit regression that had reverted several fixes (root package.json/bun.lock @ai-sdk/xai downgrade, script/check-opencode-annotations.ts --worktree removal, AGENTS.md/skill doc edits) is gone — those files are no longer touched by this PR, and the i18n translation and "aggregated vs. latest" comment-mismatch issues from the last review are now fixed (latestMetrics/aggregateMetrics semantics and docs now agree, no.ts has real Norwegian text, the duplicated t/s unit in AssistantMessage.tsx is gone).

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 3688 Guard still blocks persistence of every top-level (no-dot) setting key, not just showTokenThroughputvalidThroughputSetting only returns true for that one key. Not fixed since last review.

WARNING

File Line Issue
packages/opencode/src/kilocode/plugins/sidebar-usage.tsx 76 samples is still never reset when props.session_id changes. Not fixed since last review.
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 77 New: the throughput tooltip calls language.t("chat.throughput.speed.tooltip") without the speed param, so the {{speed}} placeholder resolves to an empty string and the tooltip never shows the actual rate.
packages/kilo-vscode/webview-ui/src/styles/chat-layout.css 231 New: this PR adds a [data-component="assistant-memory-badge"] rule for a component that no longer exists in the tree (a repo test asserts its absence from AssistantMessage.tsx).

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx 30 New: reimplements the throughput-formatting logic instead of reusing the shared formatTG helper — likely the root cause of the tooltip bug above.
packages/opencode/src/kilocode/plugins/model-usage.ts 72, 110 New: two small dead-code guards (value === undefined after Number.isFinite, and sample.generated ?? 0 on an already-required number).
Files Reviewed (46 files)
  • .changeset/token-throughput-v2.md
  • packages/core/src/v1/session.ts
  • packages/kilo-ui/src/components/icon.tsx
  • packages/kilo-vscode/package.json
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/kilo-provider/throughput-settings.ts
  • packages/kilo-vscode/tests/unit/session-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx - 2 issues
  • packages/kilo-vscode/webview-ui/src/components/settings/DisplayTab.tsx
  • packages/kilo-vscode/webview-ui/src/context/config.tsx
  • packages/kilo-vscode/webview-ui/src/context/display.tsx
  • packages/kilo-vscode/webview-ui/src/context/session-utils.ts
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (19 locale files)
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css - 1 issue
  • packages/kilo-vscode/webview-ui/src/types/messages/*.ts
  • packages/opencode/src/kilocode/plugins/model-usage.ts - 2 issues
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsx - 1 issue
  • packages/opencode/src/kilocode/session/metrics.ts
  • packages/opencode/src/kilocode/session/processor.ts
  • packages/opencode/src/session/processor.ts
  • packages/opencode/test/kilocode/session-metrics.test.ts
  • packages/opencode/test/kilocode/tui/usage.test.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts, packages/sdk/openapi.json

Fix these issues in Kilo Cloud

Previous review (commit ec91f2a)

Status: 9 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 3
WARNING 5
SUGGESTION 1

Note: The branch history was rewritten since the last review (previous review commit is no longer an ancestor of HEAD), so this pass falls back to a full review. All issues from the prior review remain unresolved — the merge that landed on this branch (Merge origin/main into feat/token-throughput-v2) re-reverted fixes that had already landed on main.

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 3688 Guard still blocks persistence of every top-level (no-dot) setting key — fontSize, showTaskTimeline, claudeCodeCompat, etc. — not just showTokenThroughput. Not fixed since last review.
script/check-opencode-annotations.ts 8 The --worktree mode (flag, validation, untracked() helper) that exists on main is still missing here — reverted by the merge commit. Not fixed since last review.
package.json 163 @ai-sdk/xai is still pinned to 3.0.92 instead of main's 3.0.102, with the old patch restored (patches/@ai-sdk%2Fxai@3.0.92.patch). A follow-up commit (fix: regenerate bun.lock for @ai-sdk/xai 3.0.92) locked in this regression instead of correcting it. nix/hashes.json changed only as a downstream consequence of this same regression. Not fixed since last review.

WARNING

File Line Issue
packages/opencode/src/kilocode/plugins/sidebar-usage.tsx 76 samples is still never reset when props.session_id changes — no createEffect keyed on session exists in the current code. Not fixed since last review.
packages/kilo-vscode/tests/unit/session-utils.test.ts 782 Comment still says "the final step wins," but the assertion (and aggregateMetrics) show the first value winning. Not fixed since last review.
packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx 184 Tooltip still duplicates the t/s unit (formatTG already appends it, and the i18n string appends it again). Not fixed since last review.
AGENTS.md 23 New: doc edits (here and at line 39) describe the --worktree regression as intentional; should revert once the script fix lands.
.kilo/skills/kilocode-merge-minimizer/SKILL.md 100 New: same regression reflected in this skill's verification instructions.

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx 91 Comment still says throughput is aggregated "across every step-finish," but aggregateMetrics keeps the first value. Not fixed since last review.
Files Reviewed (48 files)
  • .changeset/token-throughput-v2.md
  • AGENTS.md
  • .kilo/skills/kilocode-merge-minimizer/SKILL.md
  • bun.lock, package.json, nix/hashes.json, patches/@ai-sdk%2Fxai@3.0.92.patch
  • packages/core/src/v1/session.ts
  • packages/kilo-vscode/package.json
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/kilo-provider/throughput-settings.ts
  • packages/kilo-vscode/tests/unit/session-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx
  • packages/kilo-vscode/webview-ui/src/components/settings/DisplayTab.tsx
  • packages/kilo-vscode/webview-ui/src/context/config.tsx
  • packages/kilo-vscode/webview-ui/src/context/display.tsx
  • packages/kilo-vscode/webview-ui/src/context/session-utils.ts
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (17 locale files)
  • packages/kilo-vscode/webview-ui/src/styles/chat-layout.css
  • packages/kilo-vscode/webview-ui/src/types/messages/*.ts
  • packages/opencode/src/kilocode/plugins/model-usage.ts
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsx
  • packages/opencode/src/kilocode/session/metrics.ts
  • packages/opencode/src/kilocode/session/processor.ts
  • packages/opencode/src/session/processor.ts
  • packages/opencode/test/kilocode/session-metrics.test.ts
  • packages/opencode/test/kilocode/tui/usage.test.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts, packages/sdk/openapi.json
  • script/check-opencode-annotations.ts

Fix these issues in Kilo Cloud

Previous review (commit aeff95a)

Status: No Issues Found | Recommendation: Merge

All issues from the previous review have been addressed in this update:

  • packages/kilo-vscode/src/KiloProvider.ts — guard now scoped to leaf === "showTokenThroughput", no longer blocks persistence of other top-level settings
  • script/check-opencode-annotations.ts--worktree mode and docs restored
  • package.json / bun.lock / patches/@ai-sdk/xai restored to 3.0.102 with its patch
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsxsamples now resets on session switch via a createEffect keyed on session_id, preventing cross-session blending and unbounded growth
  • packages/kilo-vscode/tests/unit/session-utils.test.ts — comment now accurately describes first-sample-wins behavior
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx — comment now accurately describes first-step-finish snapshot behavior

The remaining previously-flagged item (AssistantMessage.tsx duplicated t/s unit) was not touched in this update and is left as an open, non-blocking suggestion for a follow-up.

Files Reviewed in this incremental pass (28 files)
  • bun.lock
  • package.json
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/tests/unit/session-utils.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx
  • packages/kilo-vscode/webview-ui/src/i18n/*.ts (17 locale files)
  • packages/opencode/src/kilocode/plugins/sidebar-usage.tsx
  • patches/@ai-sdk%2Fxai@3.0.92.patch (removed)
  • script/check-opencode-annotations.ts

Previous review (commit 040dde6)

Status: 7 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 3
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/KiloProvider.ts 3688 New throughput-setting guard mis-scoped to section === "", silently blocking persistence of every other top-level setting (language, showTaskTimeline, fontSize, etc.)
script/check-opencode-annotations.ts 8 Merge commit reverts the --worktree mode added on main (#11842), along with its docs in AGENTS.md / merge-minimizer skill
package.json 163 Merge commit downgrades @ai-sdk/xai 3.0.102 → 3.0.92, reverting an already-merged fix (#12427); same regression in bun.lock / nix/hashes.json

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx 188 Tooltip renders duplicated unit ("t/s t/s") because formatTG and the i18n string both append t/s
packages/opencode/src/kilocode/plugins/sidebar-usage.tsx 76 samples accumulates across session switches with no per-session reset/filter, blending stale/unrelated session data into the TG figure and growing unbounded
packages/kilo-vscode/tests/unit/session-utils.test.ts 782 Comment says "final step wins" but the assertion and implementation both use the first sample — misleading for future maintainers

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx 91 Comment implies a whole-session average; implementation is actually a first-sample snapshot
Files Reviewed (53 files)
  • .changeset/token-throughput-v2.md
  • .kilo/skills/kilocode-merge-minimizer/SKILL.md
  • AGENTS.md
  • bun.lock
  • nix/hashes.json
  • package.json
  • packages/core/src/v1/session.ts
  • packages/kilo-vscode/package.json
  • packages/kilo-vscode/src/KiloProvider.ts - 1 issue
  • packages/kilo-vscode/src/kilo-provider/throughput-settings.ts
  • packages/kilo-vscode/tests/unit/session-utils.test.ts - 1 issue
  • packages/kilo-vscode/webview-ui/src/components/chat/AssistantMessage.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx -

[Snapshot truncated.]

Additional previous summary content was truncated to keep this comment within platform limits.


Reviewed by claude-sonnet-5 · Input: 44 · Output: 10.7K · Cached: 1.3M

Review guidance: REVIEW.md from base branch main

@Githubguy132010
Githubguy132010 force-pushed the feat/token-throughput-v2 branch from 4c4f567 to ec91f2a Compare July 22, 2026 08:46
Comment thread AGENTS.md Outdated
Comment thread .kilo/skills/kilocode-merge-minimizer/SKILL.md Outdated
@Githubguy132010
Githubguy132010 force-pushed the feat/token-throughput-v2 branch from 025b2ea to ec91f2a Compare July 22, 2026 09:09
Comment thread patches/@ai-sdk%2Fxai@3.0.92.patch Outdated
Comment thread AGENTS.md Outdated
Comment thread packages/kilo-vscode/webview-ui/src/i18n/no.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/src/i18n/en.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/TaskHeader.tsx Outdated
@Githubguy132010
Githubguy132010 force-pushed the feat/token-throughput-v2 branch from cb1c1d1 to 89ff124 Compare July 22, 2026 10:13
Thomas Brugman and others added 11 commits July 22, 2026 10:14
Capture prompt-processing and text-generation tokens/sec on every
StepFinishPart. The metrics helper prefers provider-reported rates
from llama.cpp / vLLM timings and falls back to wall-clock computation.
A new kilocode tui usage route renders PP/TG inline.

chore(sdk): regenerate types for StepFinishPart.metrics
feat(tui): render PP/TG in sidebar usage panel

feat(vscode): per-message and aggregated token throughput display

Surface throughput on each AssistantMessage badge (behind the
showTokenThroughput toggle) and as a compact PP/TG row in the
expanded TaskHeader. Adds session helpers, i18n entries in 20 locales,
and StepFinishPart.metrics to extension/webview messages.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…er branch

- Replace the dead sendThroughputSetting() private with the shared
  buildThroughputSettingMessage() helper and add validThroughputSetting
  to handleUpdateSetting so the showTokenThroughput setting has the same
  guard as the chat/indexing twins (fixes Knip regression).
- Bind the DisplayTab Switch to the local settings draft so the toggle
  flips on click instead of waiting for a Save round-trip (the user-facing
  kill switch for #6579).
- Narrow StepThroughputMetrics.source to "computed"; backend hard-codes
  computed metrics today because the upstream AI SDK drops provider
  timings. Drop the unused provider branches from AssistantMessage and
  TaskHeader so the rendering code has no dead paths.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
- Replace inline PP/TG labels in the CLI sidebar with a throughputLabel
  constant in model-usage so a future i18n sweep is one file instead
  of every rendering site.
- Tighten isStepMetrics in sidebar-usage back to a real discriminator
  check after dropping the unreachable "provider" union member.
- Drop formatPP/formatTG exports from model-usage since callers already
  use the shared formatRateValue; mirror the swap in the TUI usage test.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…nd test computed-only

- aggregateMetrics adopts the first non-empty computed sample per field
  across every step-finish in the session, replacing the dead provider-
  ranked last-wins strategy that shipped with the unreachable branch.
- Share the throughputVisible signal through DisplayProvider so every
  AssistantMessage and the TaskHeader row react to a single onMount
  requestThroughputSetting round-trip, instead of each message posting
  its own handshake.
- Drop the unused routes/session/usage.tsx TUI route (no remaining
  imports) and add the chat-layout badge/header pill styles it was
  gating on.
- Refresh session-utils tests to exercise only source: "computed"
  samples and follow the new first-wins rule.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…der branch

Seed the DisplayTab "Show Token Throughput" Switch on initial load by
mirroring the throughputSettingLoaded message into settings() (same
pattern as chat.shiftTabCyclesVariant). Without this, a persisted-true
setting renders unchecked on first open because the Switch was bound to
settings()["showTokenThroughput"] but no handler ever populated it.

Drop the dead data-source attributes on the per-message and task-header
throughput surfaces now that StepThroughputMetrics.source is narrowed
to "computed" only — the attribute was always the literal string.

Drop the unreachable chat.throughput.badge.provider and
.chat.throughput.badge.tooltip.provider i18n keys across all 20 locales.
The badges no longer branch on source === "provider" since the
provider-source branch is removed (the AI SDK adapter upstream strips
llama.cpp timings before they reach providerMetadata).

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
PP (prompt-processing rate) has no signal in this build: the AI SDK
adapter upstream strips llama.cpp's `prompt_per_second` before it reaches
providerMetadata, and computeMetrics has nothing else to derive it from.
Ship the TG (text-generation) rate only — the UI no longer renders the
"PP –" placeholder that made the feature look broken.

CLI sidebar drops the PP row; per-message badge and aggregated header
pill both lose the "PP – ·" prefix. The wire shape keeps the optional
prompt field so the follow-up that wires the upstream metadataExtractor
can populate it without another schema bump.

The `throughputLabel` constant on the opencode side and the `formatPP`
helper on the webview side are removed; tests that fabricated prompt
values are pruned to match.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
The standalone blue pills read as loud for what is secondary session
info. Move the aggregated TG into the existing Tokens row as another
spanned value (alongside ↑ input, ↑ cache, ↓ output) and restyle the
per-message badge as plain text in descriptionForeground so both surfaces
match the tokens family.

TaskUsage now accepts a `throughput` prop and renders `TG <rate> t/s`
inline in the Summary component when the toggle is on. TaskHeader no
longer emits a standalone [data-slot="task-header-throughput"] element;
its [data-slot="task-header-throughput"] CSS rule is removed. The
throughputText / throughputTooltip memos and the unused formatTG
import are dropped — the values flow straight into TaskUsage.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…Message

The "Merge origin/main into feat/token-throughput-v2" resolution kept the
throughput branch's memory-badge code (already removed from main by
28d015f), which broke the kilo-ui-contract test and the i18n-keys test.

Drop the dead code: `useMemory`/`MemoryMarkerMeta` imports, `mem`, the
`meta`/`recall`/`fmt`/`count`/`items`/`verbose` createMemos, the `tip`
function, and the `<Show when={mem.enabled() && recall()}>` block. The
file lands at 349 lines (down from 391), matching main + throughput only.

Verified locally:
- i18n-keys + kilo-ui-contract: 53 pass, 0 fail
- Full kilo-vscode suite: failures 138 → 136 (+2 from the two fixes)

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…Message

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
- Rename 'TG' to 'Generation speed' in en.ts and add a 'gauge' icon to
  packages/kilo-ui so the per-message badge and the Tokens row show
  '<icon> Generation speed <rate> t/s' instead of the cryptic 'TG <rate>'.
  Centralize the opencode sidebar label in throughputLabel.generation.
- Switch aggregateMetrics (both webview and CLI) to the latest non-empty
  step-finish snapshot so only the most recent assistant turn's generation
  rate is shown rather than a session-wide aggregate. Update tests and
  comments to match.
- Translate the throughput strings in no.ts to Norwegian; mirror the new
  key shape across the other locales (English fallback for untranslated
  strings).

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@Githubguy132010
Githubguy132010 force-pushed the feat/token-throughput-v2 branch from 89ff124 to a310090 Compare July 22, 2026 10:16
… formatting

The throughput rebases left a duplicated .vscode-session-turn-diffs
selector and let three files drift from prettier's expectations. Fix
the CSS unclosed-block (which broke the Storybook preview build) and
re-run prettier --write on the touched files.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx Outdated
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/TaskUsage.tsx Outdated
Comment thread packages/kilo-vscode/webview-ui/src/styles/chat-layout.css Outdated
Comment thread packages/opencode/src/kilocode/plugins/model-usage.ts Outdated
Comment thread packages/opencode/src/kilocode/plugins/model-usage.ts Outdated
Githubguy132010 and others added 2 commits July 22, 2026 10:37
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Kilo:
- CRITICAL: Remove the section === '' guard in KiloProvider.ts that
  blocked persistence of every top-level setting key. The throughput
  validator is now redundant, so drop it from throughput-settings.ts.
- WARNING: Reset samples in sidebar-usage.tsx when props.session_id
  changes via a keyed createEffect, so a session switch no longer
  blends step-finish metrics from the previous session and the array
  no longer grows without bound across long-lived plugin instances.
- WARNING: Pass {speed} to language.t for the TaskUsage throughput
  tooltip and reuse the shared formatTG helper instead of reformatting
  the value inline. Drop the dead [data-component='assistant-memory-badge']
  rule whose target component no longer exists in the tree.
- SUGGESTION: Drop redundant guards in model-usage.ts (undefined check
  after Number.isFinite, and the ?? 0 on an already-required number
  field). Use typeof === 'number' for the type narrowing.
Address Marius's review of the throughput UI:

Calculation
- Persist per-step timing (start/end/elapsed) on step-start and
  step-finish parts in the session processor.
- Add wire schemas in core/src/v1/session.ts and packages/sdk/openapi.json
  so the new time field round-trips end-to-end.
- Replace the last-wins 'latest step rate' snapshot with a weighted
  aggregate: sum(output + reasoning tokens) / sum(active generation
  duration) across the turn's step-finish parts. Tool execution and
  idle waiting are excluded.
- The CLI sidebar (model-usage.ts) gains the same weighted semantics
  when timing is available, falling back to last-wins otherwise so
  older callers keep working.

Presentation
- Strip the per-message badge to plain muted text (no icon, no label,
  no border). The chip in the upstream action row reads as metadata.
- Move throughput out of the task header Tokens row so each turn owns
  its own value (no flicker across turns, single source of truth).
- Read the throughput memo from the full message parts in the data
  store rather than the chunked row slice, so step-finish in any
  chunk produces the badge.

i18n
- Replace chat.throughput.speed.{label,row,tooltip,tooltip.missing}
  with chat.throughput.tooltip and chat.throughput.tooltip.missing
  across all 19 locale files.

Tests
- Add messageThroughput and sessionThroughput describe blocks
  exercising the weighted aggregate across multiple steps.
- Cover weighted + fallback paths in the CLI aggregateMetrics tests.
@marius-kilocode

Copy link
Copy Markdown
Collaborator
image I propose we move it up here instead.

Move the throughput badge from a footer line below the assistant message
into the copy/feedback action row of the text part that carries the copy
button. This avoids the extra vertical space the footer consumed.

Also apply prettier formatting to drifted PR files (i18n line wraps,
TaskHeader/session-utils/test reflows).

@marius-kilocode marius-kilocode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the full diff after the latest commits: backend schema additions are additive and optional (legacy sessions keep decoding), the processor timing/metrics plumbing is guarded against missing step-start, webview surfaces (per-message badge now inline beside the copy/feedback row + task header) share one toggle, and tests cover the aggregation paths. Fixed the changeset package name (@kilocode/kilo -> @kilocode/cli) and the missing kilocode_change marker on the step-start time field. No blockers.

@marius-kilocode
marius-kilocode enabled auto-merge (squash) July 23, 2026 09:15
@Githubguy132010

Copy link
Copy Markdown
Contributor Author

Reviewed the full diff after the latest commits: backend schema additions are additive and optional (legacy sessions keep decoding), the processor timing/metrics plumbing is guarded against missing step-start, webview surfaces (per-message badge now inline beside the copy/feedback row + task header) share one toggle, and tests cover the aggregation paths. Fixed the changeset package name (@kilocode/kilo -> @kilocode/cli) and the missing kilocode_change marker on the step-start time field. No blockers.

Alright, I would like to thank you for collaborating with me on the PR. It really helps me move faster.

@marius-kilocode
marius-kilocode merged commit dcc0d64 into Kilo-Org:main Jul 23, 2026
41 of 44 checks passed
@Githubguy132010
Githubguy132010 deleted the feat/token-throughput-v2 branch July 25, 2026 09:51
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
* feat(opencode): record per-step token throughput metrics

Capture prompt-processing and text-generation tokens/sec on every
StepFinishPart. The metrics helper prefers provider-reported rates
from llama.cpp / vLLM timings and falls back to wall-clock computation.
A new kilocode tui usage route renders PP/TG inline.

chore(sdk): regenerate types for StepFinishPart.metrics
feat(tui): render PP/TG in sidebar usage panel

feat(vscode): per-message and aggregated token throughput display

Surface throughput on each AssistantMessage badge (behind the
showTokenThroughput toggle) and as a compact PP/TG row in the
expanded TaskHeader. Adds session helpers, i18n entries in 20 locales,
and StepFinishPart.metrics to extension/webview messages.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(vscode): wire token throughput toggle and drop unreachable provider branch

- Replace the dead sendThroughputSetting() private with the shared
  buildThroughputSettingMessage() helper and add validThroughputSetting
  to handleUpdateSetting so the showTokenThroughput setting has the same
  guard as the chat/indexing twins (fixes Knip regression).
- Bind the DisplayTab Switch to the local settings draft so the toggle
  flips on click instead of waiting for a Save round-trip (the user-facing
  kill switch for Kilo-Org#6579).
- Narrow StepThroughputMetrics.source to "computed"; backend hard-codes
  computed metrics today because the upstream AI SDK drops provider
  timings. Drop the unused provider branches from AssistantMessage and
  TaskHeader so the rendering code has no dead paths.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(opencode): centralize token throughput labels and tighten type guard

- Replace inline PP/TG labels in the CLI sidebar with a throughputLabel
  constant in model-usage so a future i18n sweep is one file instead
  of every rendering site.
- Tighten isStepMetrics in sidebar-usage back to a real discriminator
  check after dropping the unreachable "provider" union member.
- Drop formatPP/formatTG exports from model-usage since callers already
  use the shared formatRateValue; mirror the swap in the TUI usage test.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* feat(token-throughput-v2): wire aggregation through DisplayProvider and test computed-only

- aggregateMetrics adopts the first non-empty computed sample per field
  across every step-finish in the session, replacing the dead provider-
  ranked last-wins strategy that shipped with the unreachable branch.
- Share the throughputVisible signal through DisplayProvider so every
  AssistantMessage and the TaskHeader row react to a single onMount
  requestThroughputSetting round-trip, instead of each message posting
  its own handshake.
- Drop the unused routes/session/usage.tsx TUI route (no remaining
  imports) and add the chat-layout badge/header pill styles it was
  gating on.
- Refresh session-utils tests to exercise only source: "computed"
  samples and follow the new first-wins rule.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): seed settings on hydration, drop dead provider branch

Seed the DisplayTab "Show Token Throughput" Switch on initial load by
mirroring the throughputSettingLoaded message into settings() (same
pattern as chat.shiftTabCyclesVariant). Without this, a persisted-true
setting renders unchecked on first open because the Switch was bound to
settings()["showTokenThroughput"] but no handler ever populated it.

Drop the dead data-source attributes on the per-message and task-header
throughput surfaces now that StepThroughputMetrics.source is narrowed
to "computed" only — the attribute was always the literal string.

Drop the unreachable chat.throughput.badge.provider and
.chat.throughput.badge.tooltip.provider i18n keys across all 20 locales.
The badges no longer branch on source === "provider" since the
provider-source branch is removed (the AI SDK adapter upstream strips
llama.cpp timings before they reach providerMetadata).

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): drop PP display until llama.cpp wiring lands

PP (prompt-processing rate) has no signal in this build: the AI SDK
adapter upstream strips llama.cpp's `prompt_per_second` before it reaches
providerMetadata, and computeMetrics has nothing else to derive it from.
Ship the TG (text-generation) rate only — the UI no longer renders the
"PP –" placeholder that made the feature look broken.

CLI sidebar drops the PP row; per-message badge and aggregated header
pill both lose the "PP – ·" prefix. The wire shape keeps the optional
prompt field so the follow-up that wires the upstream metadataExtractor
can populate it without another schema bump.

The `throughputLabel` constant on the opencode side and the `formatPP`
helper on the webview side are removed; tests that fabricated prompt
values are pruned to match.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): integrate TG into Tokens row, plain-text style

The standalone blue pills read as loud for what is secondary session
info. Move the aggregated TG into the existing Tokens row as another
spanned value (alongside ↑ input, ↑ cache, ↓ output) and restyle the
per-message badge as plain text in descriptionForeground so both surfaces
match the tokens family.

TaskUsage now accepts a `throughput` prop and renders `TG <rate> t/s`
inline in the Summary component when the toggle is on. TaskHeader no
longer emits a standalone [data-slot="task-header-throughput"] element;
its [data-slot="task-header-throughput"] CSS rule is removed. The
throughputText / throughputTooltip memos and the unused formatTG
import are dropped — the values flow straight into TaskUsage.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): finish removing memory badge from AssistantMessage

The "Merge origin/main into feat/token-throughput-v2" resolution kept the
throughput branch's memory-badge code (already removed from main by
8ec35e3), which broke the kilo-ui-contract test and the i18n-keys test.

Drop the dead code: `useMemory`/`MemoryMarkerMeta` imports, `mem`, the
`meta`/`recall`/`fmt`/`count`/`items`/`verbose` createMemos, the `tip`
function, and the `<Show when={mem.enabled() && recall()}>` block. The
file lands at 349 lines (down from 391), matching main + throughput only.

Verified locally:
- i18n-keys + kilo-ui-contract: 53 pass, 0 fail
- Full kilo-vscode suite: failures 138 → 136 (+2 from the two fixes)

Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): finish removing memory badge from AssistantMessage

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* formatting fixes

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): address Marius review comments

- Rename 'TG' to 'Generation speed' in en.ts and add a 'gauge' icon to
  packages/kilo-ui so the per-message badge and the Tokens row show
  '<icon> Generation speed <rate> t/s' instead of the cryptic 'TG <rate>'.
  Centralize the opencode sidebar label in throughputLabel.generation.
- Switch aggregateMetrics (both webview and CLI) to the latest non-empty
  step-finish snapshot so only the most recent assistant turn's generation
  rate is shown rather than a session-wide aggregate. Update tests and
  comments to match.
- Translate the throughput strings in no.ts to Norwegian; mirror the new
  key shape across the other locales (English fallback for untranslated
  strings).

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): close unclosed CSS block and apply prettier formatting

The throughput rebases left a duplicated .vscode-session-turn-diffs
selector and let three files drift from prettier's expectations. Fix
the CSS unclosed-block (which broke the Storybook preview build) and
re-run prettier --write on the touched files.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* ci: re-run after fixing CSS unclosed-block + prettier drift

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

* fix(token-throughput-v2): address kilo-code-bot review

Kilo:
- CRITICAL: Remove the section === '' guard in KiloProvider.ts that
  blocked persistence of every top-level setting key. The throughput
  validator is now redundant, so drop it from throughput-settings.ts.
- WARNING: Reset samples in sidebar-usage.tsx when props.session_id
  changes via a keyed createEffect, so a session switch no longer
  blends step-finish metrics from the previous session and the array
  no longer grows without bound across long-lived plugin instances.
- WARNING: Pass {speed} to language.t for the TaskUsage throughput
  tooltip and reuse the shared formatTG helper instead of reformatting
  the value inline. Drop the dead [data-component='assistant-memory-badge']
  rule whose target component no longer exists in the tree.
- SUGGESTION: Drop redundant guards in model-usage.ts (undefined check
  after Number.isFinite, and the ?? 0 on an already-required number
  field). Use typeof === 'number' for the type narrowing.

* feat(token-throughput-v2): weighted per-turn rate, plain text footer

Address Marius's review of the throughput UI:

Calculation
- Persist per-step timing (start/end/elapsed) on step-start and
  step-finish parts in the session processor.
- Add wire schemas in core/src/v1/session.ts and packages/sdk/openapi.json
  so the new time field round-trips end-to-end.
- Replace the last-wins 'latest step rate' snapshot with a weighted
  aggregate: sum(output + reasoning tokens) / sum(active generation
  duration) across the turn's step-finish parts. Tool execution and
  idle waiting are excluded.
- The CLI sidebar (model-usage.ts) gains the same weighted semantics
  when timing is available, falling back to last-wins otherwise so
  older callers keep working.

Presentation
- Strip the per-message badge to plain muted text (no icon, no label,
  no border). The chip in the upstream action row reads as metadata.
- Move throughput out of the task header Tokens row so each turn owns
  its own value (no flicker across turns, single source of truth).
- Read the throughput memo from the full message parts in the data
  store rather than the chunked row slice, so step-finish in any
  chunk produces the badge.

i18n
- Replace chat.throughput.speed.{label,row,tooltip,tooltip.missing}
  with chat.throughput.tooltip and chat.throughput.tooltip.missing
  across all 19 locale files.

Tests
- Add messageThroughput and sessionThroughput describe blocks
  exercising the weighted aggregate across multiple steps.
- Cover weighted + fallback paths in the CLI aggregateMetrics tests.

* fix(token-throughput-v2): render t/s inline beside copy/feedback buttons

Move the throughput badge from a footer line below the assistant message
into the copy/feedback action row of the text part that carries the copy
button. This avoids the extra vertical space the footer consumed.

Also apply prettier formatting to drifted PR files (i18n line wraps,
TaskHeader/session-utils/test reflows).

* fix(token-throughput-v2): correct changeset package name to @kilocode/cli

* fix(token-throughput-v2): annotate step-start time field with kilocode_change

---------

Co-authored-by: Thomas Brugman <thomas@kilocode.ai>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: marius-kilocode <marius@kilocode.ai>
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.

[FEATURE]: Add Tokens-Per-Second (tok/s) Metric to Kilo CLI

2 participants