Skip to content

feat(sidebar): percent-only usage, opt-in local cost, /cmd-settings - #19

Merged
JeffreyJYZ merged 2 commits into
mainfrom
feat/cmd-settings
Nov 14, 2026
Merged

JeffreyJYZ merged 2 commits into
mainfrom
feat/cmd-settings

Conversation

@jyzbot

@jyzbot jyzbot commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

What

Makes the Command Code sidebar percentage-only by default and moves the local cost figure behind an opt-in setting, then adds /cmd-settings to change these from inside opencode.

Why

The per-model cost row ran a json_extract(data, '$.cost') ... GROUP BY over session_message on every five-second poll. On a 1.3 GiB store that is a full scan with a disk-spilling sort, and it ran on the TUI's own main thread: measured 6 database opens in 25 seconds at 0.5 to 1.2 seconds each, with the main thread 49.8 percent busy. Keystrokes queue behind that thread.

With the plugin disabled the same measurement showed zero database reads and 21.5 percent busy, which is what confirmed the cause.

Changes

  • src/sidebar/local-cost.ts (new): every local cost read is memoised per key for costMs and returns before opening a database when cost is off.
  • src/sidebar/useRows.ts: no longer imports usageDb; the poll cadence comes from prefs.pollMs; cost rows are omitted unless the user enables them.
  • src/sidebar/prefs.ts: Prefs gains pollMs, cost and costMs, with strict validation, plus savePrefs writing the shared config file atomically and preserving unknown keys.
  • src/sidebar/settings.tsx, src/sidebar/settings-rows.ts (new): the /cmd-settings dialog, built the same way the wallpaper plugin builds its picker.
  • src/tui-commands.tsx (new): command registration moved out of tui.tsx, which drops from 214 to 114 lines.
  • Tests: prefs validation and save round-trip, plus the settings row definitions.

Behaviour

Defaults are cost: off, pollMs: 5000, costMs: 60000, so an existing install keeps its account percentages and stops reading the store at all. cost: session adds the indexed session reads, cost: window adds the account-wide window scans.

Verification

bun check clean, bun test 263 pass, bun run build clean, and dist/tui.js contains the settings command.

The per-model cost row summed json_extract over session_message on every
5 second poll: a main-thread scan with a disk-spilling sort, which is what
made typing lag. Cost now defaults to off and, when enabled, answers from a
memo for costMs instead of rescanning per tick. Poll cadence, colour, plan
and the cost mode are editable from /cmd-settings, which follows the
wallpaper plugin's dialog pattern.
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cmdcode-tools-site Ready Ready Preview Nov 14, 2026 10:31am UTC

@JeffreyJYZ
JeffreyJYZ merged commit 61441ae into main Nov 14, 2026
10 checks passed
@JeffreyJYZ
JeffreyJYZ deleted the feat/cmd-settings branch November 14, 2026 10:35

This branch was successfully deployed

1 active deployment
Preview — 2be74581 Deployed Nov 14, 2026 by vercel[bot]
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