new: [opencode-greenpt-usage] port plugin to OpenCode v2
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.
This commit is contained in:
20
AGENTS.md
20
AGENTS.md
@@ -2,9 +2,10 @@
|
||||
|
||||
## Project
|
||||
|
||||
`opencode-greenpt-usage` — an OpenCode **TUI** plugin (Solid + OpenTUI) that
|
||||
shows the remaining GreenPT API credit balance in the sidebar. Distributed by
|
||||
`git clone`; there is no npm publish.
|
||||
`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
|
||||
|
||||
@@ -17,17 +18,20 @@ GREENPT_API_KEY=... npm run test:integration # live API test
|
||||
|
||||
## Conventions
|
||||
|
||||
- The plugin entry is the `default export { id, tui }` in `src/index.tsx`.
|
||||
Types come from `@opencode-ai/plugin/tui` as **type-only** imports; the
|
||||
host provides `solid-js` and `@opentui/solid` at runtime.
|
||||
- The section is registered on the `sidebar_content` slot and is hidden when
|
||||
- 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 KV store.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user