Skip to content

feat(vscode): add setting to toggle token/cost counter visibility - #1128

Open
awhite0030 wants to merge 1 commit into
Nano-Collective:mainfrom
awhite0030:feature/toggle-token-counter-4051822223044640502
Open

feat(vscode): add setting to toggle token/cost counter visibility#1128
awhite0030 wants to merge 1 commit into
Nano-Collective:mainfrom
awhite0030:feature/toggle-token-counter-4051822223044640502

Conversation

@awhite0030

Copy link
Copy Markdown
Contributor

Description

Brief description of what this PR does

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Root cause: The token and cost counter is shown unconditionally, which creates visual noise for some users.
Fix: Added a VS Code setting nanocoder.showTokenUsage (defaulting to false) and plumbed it into the webview payload so that the UI only renders the counter when enabled. Created a changeset.
Validation: Ran pnpm run build, pnpm test:format, pnpm test:lint, pnpm test:types, pnpm test:knip, and targeted tests pnpm test:ava plugins/vscode/src/. All passed. Validated changeset logic with node scripts/validate-changesets.js.
Fixes #1096

Fixes #1096

Added the `nanocoder.showTokenUsage` setting to toggle visibility of
the token usage and cost estimator in the VS Code chat panel.
@github-actions github-actions Bot added the area:vscode VS Code extension and host integration label Sep 2, 2026

@will-lamerton will-lamerton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up. The setting itself is right (default: false matches what #1096 asked for, and workspace.getConfiguration is the correct source here rather than SettingsManager, which models agents.config.json). One blocker though.

Blocker: this reverts #1098

The branch predates 8a46cd3 ("restore usage footers when reopening chats"), which added a second call site for appendUsageIndicator in the history-replay path. Only the live-turn call site is updated, so after merging main:

plugins/vscode/media/chat-panel.js
2065:  function appendUsageIndicator(usage, cost, showTokenUsage) {
2429:      appendUsageIndicator(replayedUsage, replayedUsage.cost);        // 2 args, never gated
2446:      appendUsageIndicator(update.usage, update.cost, update.showTokenUsage);

Line 2429 passes no third argument, so showTokenUsage is undefined, the new guard bails, and reopened chats lose their token/cost line permanently even with the setting on. Merging origin/main into this branch (clean merge) and running the existing spec confirms it:

✘ [fail]: replayed response usage metadata restores the token and cost line
  source/vscode/chat-panel-turn-footer.spec.ts:102
  Value is not truthy: undefined

CI is green only because the branch has not been rebased.

Suggested fix: gate once, off syncState

Attaching the flag to the per-turn ACP update payload is why the replay path was missed, and it has two more costs: it only arrives on prompt_response/done, so toggling the setting does nothing until the next completed turn (no onDidChangeConfiguration listener, though the pattern exists at extension.ts:130 and acp-client.ts:47), and it mixes a UI preference into the ACP message shape.

Pushing it once over syncState (chat-webview-provider.ts:112, handled at chat-panel.js:2162) into a module-level variable read inside appendUsageIndicator fixes the replay bug and the live-toggle gap together, and leaves the signature unchanged.

Also

  • No tests. source/vscode/chat-panel-harness and chat-panel-turn-footer.spec.ts already drive this renderer and assert on the usage line, so on/off across both the live and replay paths is a few lines.
  • The changeset targets nanocoder-vscode, which is in the ignore list in .changeset/config.json, so changeset status bumps nothing and this ships with no changelog entry. validate-changesets.js passes because the name is a real workspace package. #1098, also VS Code only, used "@nanocollective/nanocoder": patch.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hi @awhite0030, thanks for this PR! It looks like a maintainer has left feedback
or review activity and there are still some outstanding items to wrap up.

Whenever you get a chance, could you take a look at the open comments?
If anything is unclear or you'd like a hand, just reply here and we'll help you get it across the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:vscode VS Code extension and host integration stale:nudged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add setting to toggle Token/Cost counter visibility (default to off)

2 participants