feat(vscode): add setting to toggle token/cost counter visibility - #1128
feat(vscode): add setting to toggle token/cost counter visibility#1128awhite0030 wants to merge 1 commit into
Conversation
Added the `nanocoder.showTokenUsage` setting to toggle visibility of the token usage and cost estimator in the VS Code chat panel.
will-lamerton
left a comment
There was a problem hiding this comment.
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-harnessandchat-panel-turn-footer.spec.tsalready 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 theignorelist in.changeset/config.json, sochangeset statusbumps nothing and this ships with no changelog entry.validate-changesets.jspasses because the name is a real workspace package. #1098, also VS Code only, used"@nanocollective/nanocoder": patch.
|
Hi @awhite0030, thanks for this PR! It looks like a maintainer has left feedback Whenever you get a chance, could you take a look at the open comments? |
Description
Brief description of what this PR does
Type of Change
Changeset
pnpm changeset) describing this change for the changelogDocs-only or internal chores need no changeset (or run
pnpm changeset --emptyto note that intentionally).Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist
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 testspnpm test:ava plugins/vscode/src/. All passed. Validated changeset logic withnode scripts/validate-changesets.js.Fixes #1096
Fixes #1096