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.
39 lines
1.7 KiB
Markdown
39 lines
1.7 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
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, minimal
|
|
`Plugin.define`) and `src/tui.tsx` (CLI plugin, exposed as `./tui`).
|
|
Types come from `@opencode/plugin` and `@opencode/plugin/tui`; the host
|
|
provides `solid-js`, `@opentui/solid` and the theme at runtime.
|
|
- The section is appended to the `sidebar.content` slot and is hidden when
|
|
no GreenPT credential is present (`showWhenUnavailable` opts into a hint).
|
|
- Commands are registered through `context.keymap.layer` (palette).
|
|
- Balance probing must stay **free**: `HEAD /v1/chat/completions` returns
|
|
`400` plus `x-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 of `x-credits-remaining` between
|
|
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: `apiKey` option, `GREENPT_API_KEY`, active
|
|
OpenCode `auth.json` (`greenpt`, `type: "api"`). No profile-switching
|
|
command may leak into this logic.
|
|
- No code comments unless functionally required.
|