Skip to content

Commit ba5ed80

Browse files
authored
Merge pull request #329 from slkiser/v6
OpenCode Quota 6
2 parents 350122e + ef63f4d commit ba5ed80

835 files changed

Lines changed: 81204 additions & 107085 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md renamed to .github/CONTRIBUTING.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ Thanks for contributing! Please read this before you open an issue or PR.
1111

1212
## Setup
1313

14-
Node.js `^22.13.0 || >=23.4.0` and pnpm 11:
14+
Node.js 22.18+, 24.11+ or 26+ (what Vite+ needs; the published plugin itself runs on `^22.13.0 || >=23.4.0`) and pnpm 11:
1515

1616
```sh
1717
corepack enable
18-
corepack prepare pnpm@11.0.0 --activate
18+
corepack prepare pnpm@11.7.0 --activate
1919
pnpm install
2020
```
2121

22-
`pnpm install` also installs the Git hooks: pre-commit formats staged files with Biome; pre-push runs `pnpm verify`.
22+
`pnpm install` also installs the Git hooks: pre-commit formats and lints staged files and fixes what it can with Vite+ (`vp check --fix`); pre-push runs `pnpm verify`.
2323

2424
## Checks
2525

26-
Run `pnpm verify` before opening a PR. It runs lint and formatting, typecheck, build, all tests, the four-surface test, and package checks. CI runs the same command, then installs the packed package on Node 22 and 24 as a smoke test.
26+
Run `pnpm verify` before opening a PR. It runs lint and formatting, the TypeScript-version and history checks, the build (its `tsc` step is the type check), all tests (the cross-surface test among them), and the package contents check. CI runs the same command, then installs the packed package on Node 22 and 24 as a smoke test.
2727

2828
For quick iteration: `pnpm run test:watch`.
2929

3030
## Rules the code must keep
3131

3232
- **No AI calls.** Never send a request to an AI model to produce anything the plugin shows (quota rows, toasts, command output); it would spend the user's tokens. Calling a provider's quota or billing API is fine.
3333
- **OpenCode 2 only.** No OpenCode 1 code, APIs, or tables.
34-
- **Server vs. TUI.** The server plugin (`src/plugin.ts`) computes all text and registers the `quota_status` tool, the slash commands, and the `slkiser.opencode-quota` RPC. The TUI plugin (`src/tui-v2.tsx`) only draws what the RPC returns and never imports provider or credential code. Web and Desktop get slash commands only; OpenCode 2 has no plugin UI hooks there.
35-
- **One command path.** Every slash command, the `quota_status` tool, and the RPC `command` method go through `buildQuotaDialogCommandOutput()`.
34+
- **Server vs. TUI.** The server plugin (`src/plugin.ts`) reads providers, settings, and OpenCode's history, and registers the slash commands, the agent tools, and the `slkiser.opencode-quota` RPC. The TUI plugin (`src/tui/index.tsx`) only draws what the RPC returns and never imports provider or credential code. Web and Desktop get the slash commands only; OpenCode 2 has no plugin UI hooks there.
35+
- **One status report.** `/quota_status`, the `quota_status` tool, and the RPC `status` method go through `buildQuotaDialogCommandOutput()`; `opencode-quota status` uses `buildStatusReportData()`, which that function wraps. Every value the report prints comes from a known list, a formatted number, or a placeholder (`tests/lib.quota-status.test.ts` checks this).
3636
- **Credentials.** Read OpenCode logins only through `ctx.integration` in `src/lib/opencode-auth.ts`. The only exception is the terminal command (`src/lib/cli-show.ts`), which uses `src/lib/opencode-auth-sqlite.ts`; the plugins must never reach that file.
37-
- **Money.** Show amounts with the provider's ISO code through the shared formatter (e.g. `USD 12.50`). No symbols, conversions, or adding up different currencies.
38-
- Keep these boundary tests passing and up to date: `tests/plugin.command-handled-boundary.test.ts`, `tests/tui-dist-import-graph.test.ts`, `tests/plugin.question-hook.test.ts`, `tests/quota-provider-boundary.test.ts`.
37+
- **Money.** Use the shared formatter, which shows USD as `$12.50` and other currencies with an ISO code after the amount, such as `8.25 CNY`. Never convert amounts or add up different currencies.
38+
- Keep these boundary tests passing and up to date: `tests/plugin.command-handled-boundary.test.ts`, `tests/tui-dist-import-graph.test.ts`, `tests/quota-provider-boundary.test.ts`, `tests/v6-cross-surface.test.ts`.
3939

4040
## Provider changes
4141

@@ -53,30 +53,29 @@ Even then, it needs a reasonable maintenance cost.
5353
| You want to… | Use |
5454
| --- | --- |
5555
| Use an OpenAI-compatible model service OpenCode doesn't include | an OpenCode custom provider |
56-
| Track quota for a provider OpenCode already exposes (request estimates or one fixed quota endpoint) | an OpenCode Quota custom provider (`provider add`); its `providerId` must match OpenCode's |
56+
| Track quota for a provider OpenCode already exposes (request estimates or one fixed quota endpoint) | an OpenCode Quota custom provider ([ask your agent](../docs/readme/providers.md#custom-providers)); its `providerId` must match OpenCode's |
5757
| Anything the custom path can't do, and the policy above is met | a built-in provider |
5858

59-
**Building one:** for API-key or token providers, start from `contributing/provider-template/` (see its README), replace every example name, and add tests for every auth source. Use the README setup label that matches reality: `Automatic` or `Needs setup`.
59+
**Building one:** for API-key or token providers, start from `.github/provider-template/` (see its README), replace every example name, and add tests for every auth source. Use the setup label in `docs/readme/providers.md` that matches reality: `Automatic` or `Needs setup`.
6060

61-
**Every row** carries `AccountingMetadata`. Pick `resultType` by what the number means (`quota`, `rate_limit`, `usage`, `spend`, `budget`, `balance`, `status`), not by what's easiest to draw, and name the real source in `authority`. `user_configured` is only for a basis fact such as a user-set limit, never a row.
61+
**Every row** follows the row contract in `src/providers/contract.ts`. Pick `type` by what the number means (`quota`, `budget`, `usage`, `balance`, `status`), not by what's easiest to draw; `method` by how it was read (`remote_api`, `dashboard_scrape`, `local_cli`, `local_estimation`); and `authority` by who worked it out (`provider_reported` or `locally_derived`). A row's `key` is part of its id, which users' settings use, so it never changes once released.
6262

6363
Rich providers (more than a percentage) also:
6464

65-
- send numbers as typed `quantity` rows or percentage `basis` facts, and booleans as `boolean` rows; never pre-formatted money strings;
66-
- set `semantic` with an explicit `primary` or `supplementary` prominence;
65+
- send numbers as typed `used`, `limit`, `remaining` or `amount` values and yes/no as `flag`; never pre-formatted money strings;
66+
- set an explicit `primary` or `supplementary` prominence;
6767
- keep `used`, `limit`, and `remaining` literal;
68-
- keep labels short: the concept only, no values, units, or reset text;
69-
- format through the shared accounting formatter.
68+
- keep labels short: the concept only, no values, units, or reset text.
7069

71-
A simple percentage-only provider may keep the plain percent row, with accurate `AccountingMetadata`.
70+
A simple percentage-only provider may keep the plain percent row (`quotaRow`).
7271

7372
## Fixes
7473

7574
Make the smallest safe fix for the root cause. Match current OpenCode behavior instead of adding extra hook layers. Test against the current released OpenCode version and name it in the PR.
7675

7776
## Before-and-after screenshots (required)
7877

79-
Every PR that changes what users see must include before-and-after screenshots taken with the same config, model, theme, and window size, with credentials, account identifiers, and private paths hidden. For quota changes, report each surface: Web, TUI sidebar, toast, and the compact line under the message input (plus the prompt bar or command dialog if relevant). Say which ones you didn't test. Tests don't replace screenshots, and screenshots don't replace tests. No visible change? Write `Not applicable` and why.
78+
Every PR that changes what users see must include before-and-after screenshots taken with the same config, model, theme, and window size, with credentials, account identifiers, and private paths hidden. Report each surface the change can reach: TUI sidebar (open and collapsed), the status line below the message input, toasts, the `/quota` window tabs (Usage, Limits, Plugin, and the Settings tabs), Web and Desktop text commands, and CLI `show`/`status`. For export, telemetry, or agent tools, paste the output before and after. Say which ones you didn't test. Tests don't replace screenshots, and screenshots don't replace tests. No visible change? Write `Not applicable` and why.
8079

8180
## PR checklist
8281

‎.github/ISSUE_TEMPLATE/bug_report.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ body:
2222
id: opencode_version
2323
attributes:
2424
label: Your OpenCode version
25-
description: Example `2.0.20`
25+
description: "`/quota_status` shows it under `environment:`, in the `opencode:` line. Example `2.0.20`"
2626
placeholder: 2.0.20
2727
validations:
2828
required: true
@@ -32,7 +32,7 @@ body:
3232
attributes:
3333
label: Your plugin version
3434
description: Run `/quota_status` in OpenCode. The version is in the first line. If it has `beta` in it, update first, because it may already be fixed.
35-
placeholder: 5.0.1
35+
placeholder: 6.0.0
3636
validations:
3737
required: true
3838

@@ -60,5 +60,5 @@ body:
6060
id: logs
6161
attributes:
6262
label: Paste what `/quota_status` shows (optional)
63-
description: It never shows your keys or passwords. It does show folder paths, which can include your computer's username.
63+
description: It never shows your keys, passwords, account names or your own folder names. Read it before you paste it.
6464
render: shell

‎.github/ISSUE_TEMPLATE/config.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Contribution Guidelines
4-
url: https://github.com/slkiser/opencode-quota/blob/main/CONTRIBUTING.md
4+
url: https://github.com/slkiser/opencode-quota/blob/main/.github/CONTRIBUTING.md
55
about: Review contribution policy, quality bar, and PR checklist.
66
- name: Track any provider yourself (custom providers)
77
url: https://github.com/slkiser/opencode-quota/blob/main/docs/readme/providers.md#custom-providers

‎.github/ISSUE_TEMPLATE/feature_request.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ body:
3838
attributes:
3939
label: Your plugin version
4040
description: Run `/quota_status` in OpenCode. The version is in the first line. If it has `beta` in it, update first, because it may already work.
41-
placeholder: 5.0.1
41+
placeholder: 6.0.0
4242
validations:
4343
required: true
4444

File renamed without changes.
File renamed without changes.
File renamed without changes.

images/opencode-quota_opencode-quota-statusbar.webp renamed to .github/images/opencode-quota_opencode-quota-statusbar.webp

File renamed without changes.
File renamed without changes.

images/opencode-quota_opencode-quota-tokens-command.webp renamed to .github/images/opencode-quota_opencode-quota-tokens-command.webp

File renamed without changes.

0 commit comments

Comments
 (0)