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.
1.2 KiB
1.2 KiB
AGENTS.md
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.
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 entry is the
default export { id, tui }insrc/index.tsx. Types come from@opencode-ai/plugin/tuias type-only imports; the host providessolid-jsand@opentui/solidat runtime. - The section is registered on the
sidebar_contentslot and is hidden when no GreenPT credential is present (showWhenUnavailableopts into a hint). - Balance probing must stay free:
HEAD /v1/chat/completionsreturns400plusx-credits-remaining. Never replace it with a billable call. - 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.