Commit Graph

2 Commits

Author SHA1 Message Date
Stéphan Sainléger
dadc93a22d chg: [opencode-greenpt-usage] port the TUI plugin to OpenCode 2
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.
2026-11-18 23:01:40 +01:00
Stéphan Sainléger
9c84473266 new: [opencode-greenpt-usage] track API key consumption per day and model
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.
2026-10-19 11:36:45 +02:00