Put the balance on the section header line and keep the folded header to
one row with today's spend. Remove the gap between the title and the
metrics line, then indent model tokens below the full model name so they
read as subordinate detail instead of wrapping mid-name.
The stacked model rows avoid the narrow sidebar splitting a model id;
costs stay right-aligned. Typecheck and the 49 unit tests pass.
V1 TUI modules no longer load: replace ``{ id, tui }`` with
``Plugin.define({ id, setup })``, register the section on
``sidebar.content``, and expose commands through ``context.keymap.layer``.
Move balance, clock and usage state onto ``context.storage.store/memory``
so host subscribers rerender; plugin-created signals stayed stale in the
V2 renderer. Read V2 assistant messages (``type``,
``model.providerID``/``model.id``) and subscribe through ``context.data``.
Configure the package directory in ``cli.json`` instead of the source
file; document the V2 install. Typecheck, 49 unit tests and the live
GreenPT integration test pass, and the sidebar renders the balance.
Show real credit spend and a per-model breakdown under the balance:
- ``src/usage.ts`` (new, pure): idempotent day buckets keyed by message
id, day/month totals, retention pruning, validated KV serialization.
- Real spend = delta of ``x-credits-remaining`` between two free probes
(top-ups are not counted as spend), covering every client of the key.
- Per-model detail = reconciliation of local GreenPT assistant messages
(tokens + estimated cost, marked ``~``), re-run on every refresh and
on ``session.idle``; last 10 sessions backfilled at startup.
- Buckets persisted in the plugin KV store (90-day window) with new
options ``trackUsage``, ``usageWindowDays``, ``usageBackfill`` and a
``greenpt.usage.reset`` command.
Show the remaining GreenPT API credit balance in the OpenCode TUI
sidebar. The key is resolved from the ``apiKey`` option, the
``GREENPT_API_KEY`` environment variable, or the active OpenCode
``auth.json`` (provider ``greenpt``); the section is hidden when no key
is present, so the plugin stays portable across machines and profiles.
The balance is read from the ``x-credits-remaining`` header returned by
a free ``HEAD /v1/chat/completions`` probe (HTTP 400 before any credit
is consumed), which avoids a billable call per refresh. Tests cover the
credential resolution, the header parsing and the live API.
Distribute via git clone; there is no npm publish.