# Changelog

All notable changes to this project are documented in this file.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [0.6.1] - 2026-09-16

### Changed

- **README (`Known limitations`, both languages): a fresh environment that has
  not sent a request yet falls back to the `deepseek-official` route.** With no
  `~/.dsh-tui/model.json` preference and no session event, that is the only route
  the host can report, so an account section reading "no key configured" on a
  machine that intends to use another provider is expected rather than a fault;
  the first request corrects the line.

## [0.6.0] - 2026-09-14

### Changed

- **A scan no longer re-reads a log it has already read.** The incremental cache
  now remembers, per log, how far into the file its record has been folded
  (`done`), a signature of the bytes just before that point, and the fold state
  to continue with. A log that was only *appended* to — every session that is
  still running, including the one `/hist` is open in — is finished by
  decompressing its new frames instead of the whole file. On the machine this was
  written on (437 logs, 112 MB, 190k frames) a refresh after the largest log grew
  fell from 314 ms to 17 ms, and the same round of appends across three large logs
  fell from 561 ms to 6 ms. A prefix is continued only when its bytes are
  provably unchanged (that signature), the file did not shrink, the fold saw the
  session header, and its fork cut resolved; anything else re-reads the log
  whole, which is what keeps a continued record byte-identical to a full read.
- **A cache written by an older version is migrated instead of discarded.**
  `CACHE_VERSION` is 4 and `CACHE_MIGRATIONS` upgrades a document entry by entry;
  a version with no migration step is still refused, exactly as before. This is
  what 0.5.1 lacked: bumping the version there retired every entry and made the
  next `/hist` rebuild the whole corpus (~12 s on the corpus above), while
  upgrading to 0.6.0 keeps all 436 entries in place and costs 81 ms.
- **Only lines that can change a record are parsed.** A frame that cannot carry
  `assistant/message`, `request/header`, `session` or `session/end-seed` is
  dropped before it is even turned into a string, and a line is decided by its
  leading `"type"` when the writer put that key first (the host does), falling
  back to a marker scan otherwise. In a real corpus ~95% of the lines are never
  handed to `JSON.parse`. A full rebuild still costs ~5–6 s there, because
  ~4.3 s of it is decompressing the frames one at a time: Node's
  `zstdDecompressSync` decodes a single frame per call, and its zstd *stream*
  refuses a chunk holding more than one (`Unknown frame descriptor`), so the
  per-frame call is not a choice this plugin can avoid.
- **A cold rebuild now paints as it goes.** `scanSessions` reports the records it
  has reduced on the same coalesced ticks as its progress, and `/hist` publishes
  each batch, so a board with no cache shows the recent weeks within the first
  second instead of holding a loading state for the whole scan. The walk visits
  the newest logs first, so each snapshot is already in the order the caller
  finally receives.

## [0.5.3] - 2026-09-14

### Fixed

- **The account section no longer reports a different account's figure on the
  first page after a restart.** A conversation the host restored at boot has no
  tracker in this process — the host replays its history privately and DSH emits
  `session/event` only for appends this process makes — so `auto` fell straight
  through to the historical `deepseek-official` default. On a machine whose
  current route is a subscription provider (Command Code, a relay), the first
  page therefore showed the official API balance until that conversation sent
  its first request. The target now has a middle tier: focused conversation →
  the host's persisted `/model` route → `deepseek-official`. The route is read
  from `~/.dsh-tui/model.json` (the file the picker re-applies after a restart,
  and only a complete `provider`+`model` pair counts), reported as its own
  `preference` source in `/quota`, and refreshed with the regular account
  refresh so a `/model` switch lands within one interval.

## [0.5.2] - 2026-09-13

### Changed

- Documentation only, no code change: a CI badge under the title, and the publishing section now records that the release workflow publishes through npm trusted publishing (OIDC) with no stored token.

## [0.5.1] - 2026-09-13

### Fixed

- **A settings write can no longer reset the settings it does not mention.** The
  settings watcher merged the host's payload over the schema *defaults* rather
  than over the current values, so a host that reports a one-key patch — and a
  scene `m`/`w`/`s` press is exactly that — brought every other key back to its
  default. The watcher now merges over what is in force, and a test drives the
  scope directly (the shared harness stubs `watch` as a no-op, which is why the
  path had no coverage at all).
- **The measured per-turn spend belongs to the conversation whose turn it was.**
  The provider's spend counter is global, but the baseline was a single
  plugin-wide instance: a parked conversation opening a turn rebased the counter
  the focused conversation was about to settle against (measured: 0.15 instead
  of 0.25 credits for the same window), and the figure was then credited to
  whichever conversation happened to be focused when the provider answered. The
  baseline, the retry budget and the pending retry now live on each
  conversation's tracker entry.
- **A forced account refresh is no longer dropped while one is in flight.**
  `turn/end` settles a measured spend against a fresh reading; it used to join a
  refresh that had started *before* the provider booked the request, so the turn
  read as ≈0 credits until the retry budget ran out. A forced refresh now waits
  for the in-flight pass and then reads again.
- **A zero amount renders as `0`.** `formatMoney`/`formatDecimal` derived their
  precision from the magnitude, so a spent-out account printed `¥0.000000` and a
  freshly reset window printed `0.000000/1000.00`. An exact zero is now `¥0` /
  `0` / `0 credits`.
- **`/hist` keeps its caret across a span change.** `w` shrank the grid while the
  cursor still named a day the new grid no longer draws, and every arrow key then
  answered "no move" with the caret hidden. The cursor is validated against the
  current grid, falls back to the default day, and the visible window is
  re-clamped so the selection can never sit off-screen.
- **`/hist` budgets the rows it really draws.** The detail card and the totals
  block each occupy a leading blank row that the budget did not count, so a
  14-row terminal was handed 15 rows. Both are charged now, and the model table
  reserves its separator, header and rule before the rows.
- **The `openai-billing` relay adapter reads the dashboard pair correctly.**
  One API / New API return `soft_limit_usd` and `hard_limit_usd` as the *same*
  grant (remaining + used), not as a remaining amount — verified against upstream
  `controller/billing.go` — so the previous reading reported the full grant as
  the balance and pinned any percentage at 100%. The remaining is now
  `limit − total_usage/100`; a soft value that differs from the hard one is still
  read as a remaining amount, and the currency comes from the provider spec
  instead of a hard-coded `USD`, because a gateway with currency display turned
  off answers in raw quota units.
- **`allowUnofficialQuota` finally gates something.** A provider whose spec
  stanza (or spec document) declares `"allowUnofficial": true` is only queried
  while that setting is on. Previously the list of opt-in adapters was empty, so
  the documented safety switch gated nothing. **Migration:** a spec-based relay
  that declares `allowUnofficial` must now also turn the setting on, exactly as
  the README always described.
- **Provider routing by host is exact.** The registry decided ownership with
  `baseUrl.includes(host)`, so `https://api.moonshot.cn.example.tld/v1` could
  claim the Moonshot adapter and be handed that route's key; the comparison is
  now on parsed host names (exact or a real subdomain). The `kimi` / `moonshot`
  alias routes are claimed the same way, so an alias with no base URL is reported
  as having no quota interface instead of being sent to the CN host and labelled
  CNY.
- **A transport failure no longer reads as a bad payload.** In `fetchJson`, a
  body that dies mid-read because the request timed out is reported `network`
  rather than `invalid`, and a non-2xx response cancels its body instead of
  leaving the socket for the garbage collector.
- **A DeepSeek account with `balance_infos: []` is not reported as "no API".** An
  empty list is a 200 that carries no balance; it is now `invalid`, which is what
  "nothing usable in the payload" means, instead of a successful zero-meter
  snapshot that rendered as an unsupported provider.
- **One bad field can no longer fail a whole `/quota` report.** An out-of-range
  `resetAt` (only reachable from a spec file) made `toISOString()` throw a
  `RangeError` and replaced the report with one error line; the instant is now
  printed only when it is a real date. A relay's transport failure also stopped
  printing `HTTP undefined` — in both `openai-billing` and `openrouter`, the
  failure note names the reason when there is no status.
- **A credential in a spec URL's query string is not echoed back.** The
  `/quota` report renders a declared request's failure note, and the host
  persists command output in the session log, so `/api/usage?key=sk-…` is now
  reported as `/api/usage?…`.
- **The history scene no longer throws before it can say "loading".** The
  `view.providerFilter` / `view.days.get(...)` reads sat above the
  `view === undefined` guard, so the branch the file documents as "keeps a
  partial host renderable" was in fact a render-time throw. Unreachable through
  the plugin's own wiring (the scene is opened after a publish) and fixed as a
  guard.
- **A scan that finishes short of the whole corpus says so.** A log whose tail
  frame is still being written, or a corpus larger than the cache cap, now
  reaches the plugin's log through `scanSessions`' `onWarning` and is counted in
  the scan line (`truncated=` / `dropped=`), instead of being a silent
  difference between the board and the session directory.
- **The diagnostic log is trimmed by bytes at a line boundary.** Trimming used a
  UTF-16 `slice` over the same number as the byte budget and could cut a
  multi-byte character in half.

### Changed

- **`/hist` prints every money figure as CNY.** A cost comes from a rate card —
  the built-in table or `/th price` custom rates — and both are denominated in
  CNY per million tokens, so the totals block, the per-provider subtotals and the
  model table now agree instead of the model table printing `¥` while a
  per-provider row printed a `credits` label (and a provider the card had no
  entry for lost its money entirely, e.g. `deepseek-pro-vision`). The
  mixed-unit fallback to tokens is gone with it; a provider's `credits`
  denomination describes its own account meter on the status line, not a cost
  column. The history cache version is bumped to 3 for the key change below.
- **The totals row says what it counts.** It has always aggregated all history
  rather than the weeks on screen; it now says so inline (`1,079,834,040
  (全部历史) · …`) — the scope rides next to the figure rather than inside the
  fixed-width label cell, which is 12 cells wide and would truncate it.
- **The account section no longer has a legacy renderer.** `buildDisplay` takes
  the provider-neutral `quota` model only.
- **Every command contribution now gets its localized completion tree.** `/quota`
  was declared in the manifest and registered as a command but had no tree, so
  its menu entry fell back to the English registry description — the completion
  tree now covers all four roots (the retry loop tracks them by name, so a root
  that fails while the others land is still filled in).
- A provider-less bucket key whose model id contains a slash
  (`inclusionai/ling-3.0-flash-sante:free`) is marked with a leading `/`, so
  splitting a key can no longer invent a provider from the model name.
- A relay's cumulative usage meter is now `lifetimeSpend` (One API's `/usage`
  ignores any date range) and is selectable from `Quota metric` like every other
  meter id.
- **A money figure whose currency the provider never named is printed without a
  symbol.** `formatMoney` defaults to CNY for the plugin's own cost estimates,
  but a vendor that answers a bare number (SiliconFlow's `totalBalance`) has not
  said the figure is yuan — so the meter now reads `赠金 0.8800` instead of
  stamping `¥` on it, which is the guess the adapters deliberately refuse to
  make.
- **A known cap with an unknown figure renders as `—/cap`** rather than
  collapsing to a bare label: a relay whose `/usage` read failed shows
  `余额 —/$20.00` instead of `余额`. The relay adapters never over-report a
  remaining amount, so this is the honest presentation of "the grant is known,
  the spend is not".
- The scan reports the files it dropped at the 3000-log cap and the logs it found
  with a partial trailing frame, instead of shortening history silently; the walk
  no longer follows links and stops at a nesting depth of 8.

### Removed

- The legacy DeepSeek balance path — `fetchBalance`, `BALANCE_ENDPOINT`,
  `BALANCE_TIMEOUT_MS`, `cnyBalance`, `balanceStateOf`, and `buildDisplay`'s
  `balance` option with `balancePart`. It had been unreachable since 0.4.0 (the
  wiring publishes `quota`) and re-implemented the timeout/abort/failure
  classification that `providers/http.js` exists to centralize.- Other unreferenced helpers: `formatBeijingClock`, `PRICE_CARD_SOURCE`,
  `CATALOG_SOURCE`, `BILLING_MODES`, `spendCounterOf`, `meterRatio`,
  `meterRemaining`, `withoutAllRates`, `describeEntry`, `PEAK_WINDOW_TEXT`,
  `clockText`, `sameLocalDay`, `unitKeyOf`, `PROVIDER_UNITS`, `providerUnitOf`,
  the dead local `spendOwnerId`, `tracker`'s `emptyTotals` re-export, and the
  i18n keys `balance`, `quotaSpent`, `quotaLeft`, `historySubagent` and
  `historyCostMixed`.

## [0.5.0] - 2026-09-13

### Changed

- **The kind of account readout follows the provider's billing method.** A
  pay-as-you-go provider (a currency balance, debited per token) keeps showing
  amounts; a subscription (capped rolling windows over a monthly pool) now shows
  **percentages** — the status line reports how much of the cap is left and what
  share of it the turn just drew, instead of a raw credit count. Which is which
  is declared by each adapter (`commandcode-plan` is a plan, `deepseek-balance`
  is money, a relay stays `auto` and is judged by its own figures), may be
  declared per provider in the spec file, and can be overridden with the new
  `Billing mode` setting. The inference is conservative: an unknown shape reads
  as money, which renders absolute figures rather than an invented denominator.
- **A percentage says what it is a percentage of.** `Percentage base` picks the
  denominator: the window the line is showing (default — the tightest limit, the
  one whose reset countdown is on screen) or the whole monthly pool. Each falls
  back to the other, so a provider reporting only one of them still gets a
  meaningful figure. A meter with no cap has no percentage, and falls back to
  absolute amounts.
- **Narrow terminals drop the absolute figures, not the percentage.** Every part
  may carry a compact form (`本轮 1.79%` beside `本轮 1.79%(0.2500)`); when the
  full line does not fit, the compact forms are swapped in from the right, which
  is where the host truncates first. The width comes from the host's
  terminal-size hook when the status-view kit offers one, and from
  `process.stdout.columns` otherwise; with neither, the line renders in full
  exactly as before.
- Percentage precision follows magnitude: two decimals below 10% (a subscription
  turn is often a fraction of a percent, where one decimal would look frozen),
  one at or above it, `<0.01%` for anything smaller, and `0%` for a true zero.

### Added

- `Billing mode` and `Percentage base` settings fields, and a `billing` field
  for spec-file providers.

## [0.4.0] - 2026-09-13

### Added

- **A provider-neutral account readout.** The line above the prompt no longer
  assumes DeepSeek's own balance endpoint: an adapter layer discovers the
  provider the focused conversation actually runs through (from
  `request/header.config.provider`), resolves its base URL and credential
  reference through the harness seams — the LLM directory, a registered settings
  namespace, the credentials seam — and renders whatever that provider reports
  as a list of *meters* (`balance`, 5-hour/weekly/daily/monthly windows, plan
  remainder, key limit, period spend). Built-in adapters ship for DeepSeek's
  official balance, Command Code's subscription plan, OpenRouter, Moonshot/Kimi
  and SiliconFlow, plus the OpenAI-compatible dashboard-billing pair that One
  API and New API relays implement; anything else is described in a JSON spec
  file instead of a release. Nothing is ever guessed: a provider with no known
  interface is simply left off the line.
- **Per-turn spend measured from the provider's own counter.** When an adapter
  exposes a monotonic spend counter (Command Code's `usage.totalCredits`,
  OpenRouter's `key.usage`, a relay's `total_usage`), a turn's spend is the
  difference between two readings rather than a token-based estimate. A counter
  that has not moved yet is retried for about 15 s and then settled as inexact
  (`≈`); a counter that goes *backwards* is a new billing period, not a refund,
  and re-baselines instead of printing a negative cost.
- **`/quota` diagnostics.** Reports the resolved target, the adapter that
  claimed it, the last outcome with its failure reason, every meter with its
  figures, and every provider route this process could ask about (marked with `*`
  when the host says the route exists only because configuration declared it).
  `/quota check <provider>` probes one provider on the spot, and `/quota meter
  <id>` switches the status-line meter.
- **A generated provider catalog** (`scripts/gen-provider-catalog.mjs` →
  `lib/providers/catalog.js`): 40 routes with their base URLs and conventional
  credential references, taken from the locally installed
  `@earendil-works/pi-ai` and stamped with its version. Runtime never depends on
  pi-ai.
- **A declarative provider spec file**
  (`~/.dsh-tui/dsh-peak-balance-providers.json`): base URL, credential reference,
  requests and dot-path meters, so a relay nobody shipped an adapter for becomes
  usable without a code change. The README carries worked examples (One API
  account endpoint, Anthropic cost report, MiniMax plan remains, 智谱 balance).
- **Per-provider history.** Session logs already carry the provider route next to
  the model; the board now folds usage into `provider/model` buckets, subtotals
  per provider, prefixes the model column with its source once more than one
  account is present, and offers a `p` key that cycles the filter. Custom rates
  accept a provider-qualified key (`/hist price set commandcode:<model> …`),
  which is what lets the same model be priced differently per account.
- **The `rotate` meter**, which cycles every meter a provider reports, and
  per-request failure notes on a partially answered provider.

### Changed

- **A cost total that mixes units is refused, not printed.** An official CNY
  estimate and a subscription's credits are different currencies; when the
  selection contains both, the `cost` grid metric falls back to tokens, the
  totals say so, the totals block gains a per-provider breakdown, and the model
  table keeps one row per (provider, model) pair.
- **The account section follows the conversation, not the configuration.** With
  `quotaProvider: auto` the section re-targets the moment a session event names a
  different provider (throttled to one request every 3 s). The settings card
  gains a **Provider quota** subpage with five fields: source, meter, turn-spend
  mode, unofficial-endpoint opt-in and the spec-file path.
- **The history cache moved to version 2** (bucket keys carry the provider), so
  the first `/hist` after upgrading rebuilds it from the session logs.
- **`Show balance` now gates the whole account section** — the quota meter and
  the legacy balance readout alike.

### Fixed

- A provider whose adapter ships a canonical endpoint (the official API, Command
  Code's own host) is no longer rejected as "no base URL known".
- The account section no longer falls back to a legacy balance renderer with an
  empty state, which printed `余额 暂不可用` for a provider that simply had
  nothing to show.
- A provider change is applied after the event has claimed the status line, so
  the refresh targets the conversation that is actually on screen.

### Notes

- **Which adapters were verified against a real account:** DeepSeek official and
  Command Code. Command Code's figures were read from a live account
  (`/alpha/billing/credits` reported the 5-hour cap at 14, the weekly cap at 35
  and ~70 monthly credits on a GOAT plan, matching the plan table and the
  rendered meter), and `/alpha/usage/summary` supplied the spend counter. The
  **measured per-turn difference** itself is covered end-to-end by an integration
  test that drives a session through `turn/start` → `assistant/message` →
  `turn/end` against a counter that moves the way a provider's does; confirming
  it against a real turn on a live subscription is left to the account owner,
  because this repository's own sessions run through the official provider. The
  named third-party adapters are implemented from each provider's own
  documentation and exercised against fixture payloads taken from it; the README
  says so per adapter rather than implying otherwise.
- **Undocumented endpoints are opt-in.** `allowUnofficialQuota` (off by default)
  gates adapters built on endpoints no provider documents. Command Code's
  `/alpha/*` routes are not gated: they are the ones the provider's own CLI
  drives, the same source the ecosystem's provider plugin uses.
- **No Command Code price card was added.** Its model catalog carries no prices
  and its pricing page is generated client-side, so an estimate would have been
  invented. Subscription models show tokens only until rates are set with
  `/hist price set`, while the per-turn figure stays the provider's own measured
  number.
- **Deviation from the reviewed plan:** the three planned `/quota` commands were
  implemented as one command with `status` / `check` / `meter` subcommands, which
  keeps the manifest's contribution and permission surface at four ids instead of
  six.

## [0.3.3] - 2026-09-12

### Performance

- **Opening `/hist` no longer waits for a scan.** The plugin reads the
  incremental cache at activation and publishes the grid from it, so the scene
  paints finished numbers on the first frame instead of a spinner; the scan that
  follows only refreshes what changed and leaves the figures on screen (the
  status line gains a `刷新中` / `refreshing` chip) instead of dropping back to a
  loading state. Reading the cache, folding it into records and building the view
  measured 4 ms against the 20–30 ms of an incremental scan.
- **A fully cached scan no longer pays per file.** The loop yielded to the event
  loop and reported progress for *every* file, cached ones included, and each
  report re-rendered the whole scene: 344 files meant 344 round trips and 344
  full re-renders. On this machine's corpus that cost 614–857 ms *inside the TUI*
  for a scan whose actual work was 20 ms, and the grid only appeared when it
  finished. Only a decoded file yields or reports now, and reports are coalesced
  to one per 60 ms — the same cached corpus completes in one turn with a single
  store update.
- **A rebuild checkpoint the cache and survive an interruption.** The cache was
  written once, at the very end, so a host restart or dispose during the
  multi-second first scan threw all of it away; an aborted scan even wrote back
  only the files it had reached, discarding the rest. The scan now checkpoints
  every 64 decoded files and merges instead of truncating when it is cut short,
  so the work already paid for is resumed rather than repeated.

### Fixed

- **An empty `~/.dsh-tui/resume.txt` no longer mutes the status line.** The host
  writes that marker empty both on `/new` and when it exits a session it cannot
  resume (`clearResumeTarget`), so an empty marker is a normal resting state. The
  fallback focus poll re-applied its reading once per second; after a conversation
  claimed the line, the next tick cleared the focus again — and because the
  cleared-focus guard then skipped that conversation's own events, its figure
  stayed `本轮 —` for good. The poll now applies a reading only when the file's
  content or mtime actually changed (`createMarkerWatcher`), so `/new` still gives
  up the line and a resting empty marker does not.
- **`totalTokens` counts cache reads.** `lib/pricing.js` counted `input +
  output`, while `lib/history.js` and the provider's own `totalTokens` count
  `input + cacheRead + cacheWrite + output`. On a sampled real turn the plugin's
  figure was 61,026 against the provider's 31,282,786, and the `tokens <= 0` guard
  in `estimateCostCny` read a cache-only report as "nothing spent" (no figure at
  all). The CNY total was never affected — it prices the buckets directly.
- **A turn that reported no tokens clears the line** instead of leaving the
  previous figure in place under a "this turn" label. About 2.5% of 448 sampled
  real turns end this way (interrupted rounds, tool-only rounds); `forgetSettled`
  drops the remembered figure as well.
- **The balance is labelled with its own currency.** `cnyBalance` falls back to
  the first reported entry, so a USD account rendered as `余额 ¥5.00`; the state
  object now carries `currency` and `formatMoney` picks the matching symbol.
- **A usage report is filed under the tier its request STARTED in.** Bucketing
  used the assistant message's own timestamp — the instant the answer landed —
  while the comment claimed "the request's own timestamp". `step/start` carries
  the request's instant, so a request issued at 11:59 and answered at 12:01 stays
  off-peak. A turn's rates and model now come from its first report
  (`turnModel` / `turnAt`), so a mid-turn `/model` switch or the 2026-09-14
  Pro→Flash route change cannot reprice a whole turn.
- **Subagent spend is folded into the parent turn.** Child sessions
  (`origin: subagent` / `delegationDepth > 0`) were dropped entirely, so a
  delegation-heavy turn under-reported by the child's whole share (6.76% of
  tokens across this machine's logs). Child usage now lands in the parent
  conversation's open turn through `parentSession`, and a background child
  finishing after the turn closed cannot reopen it.

### Changed

- **The status line reports the running turn live.** While a turn is in flight
  the figure is `本轮·计费中 ¥…` (`Turn · live`), refreshed on every usage
  report; the settled `本轮 ¥…` appears once the turn closes. Previously the line
  only ever showed a settled figure, so a turn in progress read `本轮 —` — or,
  worse, the previous turn's number.
- Part order is phase → countdown → turn → balance: a narrow terminal truncates
  the tail, and the balance can also be had from `/balance`, while the turn cost
  is the figure being watched.
- `beginTurn()` (`turn/start`) drops a running bucket left behind by a turn that
  never emitted `turn/end`, so an aborted round cannot be settled into the next
  one.

## [0.3.2] - 2026-09-12

### Added

- **The plugin follows dsh-TUI's `/lang` switch.** The status line, the history
  scene and every command reply now repaint in the host's language the moment it
  changes. dsh-TUI mirrors its choice into its own `dsh-tui` settings namespace,
  and the dsh settings service emits `settings/updated(ns, next, prev, source)`
  on every commit — the plugin subscribes to that (a public Cordis event, no host
  internals) and repaints both surfaces. A 1 s poll of `~/.dsh-tui/lang.json`,
  guarded by an mtime/size stamp, covers hosts that serve no `dsh-tui`
  namespace, so `/lang` still lands within about a second there.
- Startup resolution now matches dsh-TUI's own order: `DSH_TUI_LANG` → the live
  `dsh-tui.lang` setting → `~/.dsh-tui/lang.json` → the OS locale. An ABSENT
  locale keeps the historical `zh`, while any other unsupported locale falls
  back to `en` (a German user must not be handed a Chinese UI), exactly as the
  host does.
- `DSH_PEAK_BALANCE_LANG_FILE` overrides the preference-file path for tests and
  diagnostics, mirroring `DSH_PEAK_BALANCE_FOCUS_FILE`.
- Both READMEs now open with a **language switcher** (`English · 中文` /
  `中文 · English`) and cover the same sections: the Chinese one gained the
  "Publishing and versioning" and "Listing" sections it was missing.

### Changed

- `resolveLang()` is still pure and injectable; the host's live language is read
  separately through `settings.get('dsh-tui')`, so a `/lang` switch made after
  the process started is visible to the plugin.

## [0.3.1] - 2026-09-12

### Fixed

- **The model table's columns drifted on a CJK interface.** Every cell was
  padded by `String#length`, which counts CJK and emoji as ONE cell while a
  terminal draws them as TWO — so the header `总 token` (8 cells, 7 code points)
  pushed every column to its right out of line with its values. Cells are now
  laid out as fixed-width `Box`es (the host pads and right-aligns inside them),
  and every fit/truncate decision uses a cell-accurate width
  (`displayWidth` / `clipWidth`), so a wide label can neither shift a neighbour
  nor spill into it.
- The detail card and the totals rows put their labels in one fixed 12-cell
  column instead of a hand-padded one, so both blocks start their values on the
  same cell; the totals row uses the short label (`子代理` / `subagents`) rather
  than a wide sentence.
- `hit rate` (8 cells) no longer truncates in the English header: the hit-rate
  column gained the cell its gap needs.
- Month labels (`9月` / `Sep` are 3-4 cells in a 2-cell week column) claim the
  next column's empty slot, so the axis stays cell-exact above the grid.

## [0.3.0] - 2026-09-12

### Added

- **`/hist` — the short name that actually runs.** A bare `/th` + Enter cannot
  reach this plugin: dsh-tui's slash-completion overlay executes the HIGHLIGHTED
  suggestion, the merged list is built-ins first, and `theme`/`thinking` both
  match the `th` prefix, so `/th` + Enter switched the theme. `/hist` is a
  prefix of no built-in, so the overlay offers exactly one row and Enter runs it.
  `/th` (with a trailing space) and `/tokenhistory` still work.
- **`alt+h` opens the history scene** from the plain chat state, through
  `ctx.tuiShortcuts` (ctrl/alt required; `alt+h` collides with nothing).
- **`Scene layout` setting** (`card` / `plain`): the card frames the scene in a
  rounded box with section separators and an inline day card; plain drops the
  chrome and spends those 2 rows / 4 columns on content. The card degrades to
  plain by itself when the terminal cannot hold it.
- **Subagent-switch feedback**: a permanent `subagents counted/excluded` chip in
  the title bar, a 1.2 s inversion on the `s` key, and a totals row that spells
  out `excluded N sessions / M reports` (the aggregation now reports what the
  filter dropped instead of discarding it silently).

### Changed

- **The arrows move the SELECTED SQUARE, not the calendar**: `←`/`→` step one
  week column (same weekday), `↑`/`↓` step one weekday row (±1 day) inside the
  column, and a move into a future square or past the grid edge is refused. `t`
  jumps back to today. Previously `←`/`→` were ±1 day and `↑`/`↓` were ±7 days.
- **The selected square is lightened and a `▲` row under the grid points at its
  column**, instead of drawing `[]` inside the tile (which obscured the color
  that carries the data).
- **`m` / `w` / `s` now write back to the settings namespace** (they persist and
  survive a restart) instead of changing only the current viewing session. The
  optimistic local override flips the UI immediately; a refused write keeps the
  change for the session and logs once.
- **Responsive layout**: rows and columns are budgeted explicitly. Width trims
  week columns (with a `showing 27/53w` chip and a window that scrolls one column
  at a time to follow the selection) rather than shrinking squares; height drops
  the model table, then the day card's fields one by one, then the totals. Under
  12 rows or 40 columns the scene switches to a fallback list. Every row is drawn
  with `truncate`, so nothing depends on the host clipping.
- The model table's column widths are computed from the terminal width, numbers
  are right-aligned, and the rate-source column is dropped on a narrow terminal.

## [0.1.11] - 2026-09-12

### Fixed

- **Leaving a conversation and coming back lost its figure.** A settled turn is
  a fact about the CONVERSATION, but it lived only inside the tracker of the
  session object that reported it — and switching away through `/resume`
  disposes that session. Coming back reuses the conversation id with a fresh
  agent, and the host replays the conversation privately (no `session/event`),
  so nothing rebuilt the tracker and the line showed `—`. Settled turns are now
  also remembered by conversation id (bounded, newest 24), which is what the
  line falls back to for a known focus with no live tracker. An unknown or
  cleared focus still never resurrects a conversation, so `/new` keeps showing
  `—`.

## [0.1.10] - 2026-09-12

### Fixed

- **`/new` kept the previous conversation's per-turn figure.** The host starts a
  fresh conversation by EMPTYING its focus marker, which 0.1.9 read as "no
  information" and answered with the last-event fallback — i.e. it put back the
  very conversation the user had just left. An emptied marker is now read as the
  statement it is (`{ state: 'cleared' }`, not `{ state: 'absent' }`): the line
  gives up the figure, and the first conversation that is not the one left
  behind claims it, so a parked conversation finishing a background turn cannot
  take the line back. A marker that cannot be read at all still falls back to the
  last session event, which is what a host that never writes one needs.

### Added

- Regression tests covering a `/new` the fallback poll notices both before and
  after the fresh conversation's first turn lands.

## [0.1.9] - 2026-09-12

### Fixed

- **The per-turn cost belonged to the wrong conversation after a switch.** The
  line followed "the session that appended last", but switching conversations
  publishes no `session/event`: the host replays the target session straight
  into its own projector, and DSH only fires that event for appends the current
  process makes ("constructor seeds do not emit"). Switching therefore left the
  *previous* conversation's figure on screen, and a parked conversation
  settling a background turn stole it back. The line now follows the
  conversation the host reports as focused.
- **Disposing the shown conversation fell back to the stalest tracker.** The
  tracker map keeps recency order (newest last) and the fallback read its first
  key — the *least* recently active conversation. It now moves to the newest
  survivor.
- **A reused session id could leak turn state between agents.** Trackers were
  keyed by session id, and dsh-tui reuses ids ("A → /new → /resume A lands back
  on the same id with a fresh agent"): an abandoned mid-turn got priced into the
  replacement agent's first settled turn, and disposing the parked agent deleted
  the live one's data. Trackers are now keyed by the session object.

### Added

- Focus tracking from two independent sources: the host-mediated
  `tui/session-switched` DecisionEvents notification (exact, used when the host
  mounts its plugin-interop row) and the launcher marker the host rewrites on
  every switch, polled once a second as the fallback. A conversation with no
  settled turn in this process now shows `—` instead of another conversation's
  amount.
- The manifest requires `tui.dsh/v1alpha1#DecisionEvents` as an **optional**
  contract with the fallback spelled out, so a host without the capability
  degrades (`compatible_degraded`) instead of refusing admission. Admission was
  verified against the host's own parser/validator/negotiator.
- `DSH_PEAK_BALANCE_FOCUS_FILE` overrides the marker path for tests and
  diagnostics, and the seam probe line now reports `host=<n>`.
- Regression tests for the switch, the marker fallback, a refusing host, the
  disposal fallback order and the reused-id case. `test-support/harness.js`
  carries the shared fake context for the wiring tests.

## [0.1.8] - 2026-09-10

### Fixed

- **The cost formula under-priced cached turns by several times.** It mirrored
  the host's estimator and treated `cacheReadTokens` as a subset of
  `inputTokens` (`(input − cacheRead) × miss + cacheRead × hit`). The provider
  reports the cache-miss input, the cache-hit input and the output as three
  *disjoint* counts — its `totalTokens` is their sum, and dsh-tui derives its
  cache-hit rate from `cacheRead / (input + cacheRead + cacheWrite)` — so
  clamping one against the other silently dropped most of the miss-priced
  prompt. Measured against a real balance drop: a turn that cost ¥0.20 was
  estimated at ¥0.03 before and ¥0.23 after.

### Added

- A regression test pinning the disjoint semantics (a large cache read must not
  be capped by a small miss count).

## [0.1.7] - 2026-09-10

### Changed

- Plain line: a blank row above it (so it never touches the transcript) and two
  cells of indent, one past the prompt cursor's column. The warning frame keeps
  the two-cell indent but no top gap — it already fills the host's three-row
  budget, and a margin would push its bottom border into the clipped area.

## [0.1.6] - 2026-09-10

### Changed

- The contribution is indented by one cell so it lines up with the prompt's own
  content column instead of hugging the terminal edge. The warning frame shifts
  as a whole, keeping both shapes on the same column.

## [0.1.5] - 2026-09-10

### Fixed

- **The entry module must export exactly `name`, `Config` and `apply`.** With
  its helpers (`seamServices`, `settingsSection`, …) also exported from
  `lib/index.js`, the loader wrapped the activation differently and every
  dsh-tui seam registration from that activation was rejected with
  `requires a live Cordis activation context`: the settings namespace still
  registered (that service does not verify the caller), so the plugin looked
  half-alive — no settings card, no status line. `lib/index.js` is now a shell
  that re-exports those three symbols from `lib/plugin.js`, the same shape the
  shipped TUI plugins use.
- A rich status view refused once (the first tick can land while the seam row is
  still activating) is no longer treated as final: the view is retried and only
  a run of refusals degrades it.

### Added

- `test/entry.test.js` pins the export shape and the manifest→shell wiring.
- Regression tests for the seam-resolution order, a refusing shadow
  placeholder, and the retry-then-give-up status behaviour.

## [0.1.4] - 2026-09-10

### Fixed

- **The plugin registered nothing on a real dsh-tui boot.** Services were
  resolved with the non-strict `ctx.get(name, false)`, which — in compositions
  where the dsh-tui seam rows are shadowed — hands back a placeholder whose
  method calls the host rejects with `requires a live Cordis activation
  context`. The settings namespace still registered (the settings service does
  not verify the caller), so the plugin looked half-alive: no settings card, no
  status line. `seamServices()` now asks strictly first — the form the shipped
  TUI plugins use — and keeps the non-strict accessor only as a fallback, so
  both host shapes resolve. Reported by the 0.1.3 lifecycle log.

### Added

- Regression tests for the seam resolution order and for a refusing shadow
  placeholder, so the bug cannot come back silently.

## [0.1.3] - 2026-09-10

### Added

- A bounded lifecycle log at `~/.dsh-tui/dsh-peak-balance.log`: one line when
  the module is imported, one when `apply()` starts (with pid and file path),
  the resolved config, a probe of which host seams are mounted, the outcome of
  every registration, and the teardown. Diagnosing a silently inert plugin
  previously required guessing; the host's own diagnostics never reach a file.
  The log trims itself to its newest half past 128 KiB and stays untouched
  under `node --test`.

## [0.1.2] - 2026-09-10

### Added

- `DSH_PEAK_BALANCE_FORCE_PEAK=1` diagnostic override: renders the peak
  presentation (and the warning frame) outside a real peak window, so the
  effect can be previewed without waiting for the next 09:00 Beijing. The
  countdown keeps describing the real clock, and the switch is off unless the
  variable is set.

## [0.1.1] - 2026-09-10

### Changed

- The warning-color setting is validated at use time instead of by the settings
  schema, so a stale or hand-edited value in the settings document can no longer
  fail the namespace registration (which would have rendered the card as
  unavailable and left it unrepairable from the UI). Unknown colors fall back to
  red.

## [0.1.0] - 2026-09-10

### Added

- Peak/off-peak billing clock above the prompt (Beijing time, Mon-Fri
  09:00-12:00 and 14:00-18:00), with a live countdown to the next switch.
- Live DeepSeek account balance, refreshed after every completed turn and on a
  60 s background interval.
- Per-turn cost estimate for the turn that just finished, priced with the
  official 2026-09-10 rate card (idle and peak buckets are priced separately by
  each request's own timestamp).
- Warning mode: while the current window is peak, the status contribution turns
  into a three-row frame that pulses in one of seven selectable colors.
- A settings card ("Peak & Balance") on the `/settings` screen with four
  switches: balance display, per-turn cost display, warning mode, warning color.
- Graceful degradation: with no `tuiStatus` / `tuiSettingsSections` service (or
  no credentials) the plugin stays inert instead of failing the host.
