Rewrite the TUI plugin against the OpenCode v2 plugin API (``@opencode/plugin`` + ``@opencode/plugin/tui``): - ``src/index.ts``: minimal server-side ``Plugin.define`` entry. - ``src/tui.tsx``: CLI plugin registered as ``./tui``, appending the widget to the ``sidebar.content`` slot through ``context.ui.slot`` and exposing the refresh/reset commands via ``context.keymap.layer``. - ``src/store.ts``: durable plugin storage (``context.storage.store``) replaces the KV store; ``session.idle``/``session.status`` events and the ``client.session`` API drive reconciliation and backfill. - ``src/widget.tsx``: v2 semantic theme tokens (``theme.text.base``/``text.muted``/``text.feedback``). - Tests updated to a structural fake of the v2 context. The free ``HEAD /v1/chat/completions`` balance probe and the credential resolution order are unchanged. The ``order`` option is gone: v2 slot placement is additive.
1.7 KiB
1.7 KiB
AGENTS.md
Project
opencode-greenpt-usage — an OpenCode v2 CLI/TUI plugin (Solid + OpenTUI)
that shows the remaining GreenPT API credit balance in the sidebar.
Distributed by git clone; there is no npm publish. The main branch
targets OpenCode 1.x; this branch targets OpenCode >= 2.0.0.
Commands
npm install # install dev dependencies
npm test # unit tests (vitest)
npm run typecheck # tsc --noEmit
GREENPT_API_KEY=... npm run test:integration # live API test
Conventions
- The plugin has two entries:
src/index.ts(server side, minimalPlugin.define) andsrc/tui.tsx(CLI plugin, exposed as./tui). Types come from@opencode/pluginand@opencode/plugin/tui; the host providessolid-js,@opentui/solidand the theme at runtime. - The section is appended to the
sidebar.contentslot and is hidden when no GreenPT credential is present (showWhenUnavailableopts into a hint). - Commands are registered through
context.keymap.layer(palette). - Balance probing must stay free:
HEAD /v1/chat/completionsreturns400plusx-credits-remaining. Never replace it with a billable call. - Usage accounting lives in
src/usage.ts(pure) and is consumed by the balance store: real spend = delta ofx-credits-remainingbetween probes; per-model detail = reconciliation of local OpenCode assistant messages, idempotent by message id, persisted in the plugin durable storage (context.storage.store). - Credential resolution order:
apiKeyoption,GREENPT_API_KEY, active OpenCodeauth.json(greenpt,type: "api"). No profile-switching command may leak into this logic. - No code comments unless functionally required.