feat(tui): migrate quota sidebar and commands to TUI V2 - #196
Conversation
|
@dmmop Thanks for the PR, code looks good. I believe OpenCode v2 is still in beta, so I'd hold off on releasing this on main for now. If there is support for v2 or when v2 is out of beta I'll definitely return to the PR. |
|
@slkiser Thanks you for this plugin! Yes, v2 is still in beta, thats why "opencode-next.db" is hardcoded in the code. I adapted the plugin to suit my needs in v2, i'll keep this PR update if they introduce any breaking change. |
585fc6f to
4d36e34
Compare
|
this has been great to have, thank you! |
|
Tested locally on Windows with opencode2 (beta-17728), at head 2143358, loaded as a TUI plugin via
One more thing — right now this won't load on V1 anymore, because Let me know if I can help test anything further :) |
- Extend `src/lib/opencode-auth.ts` with a credential database reader - Add `CredentialDatabase` and `CredentialDatabaseConstructor` types - Add `runtimeRequire` to conditionally load `better-sqlite3` - Implement `getCredentialDbPaths`, `readCredentialDatabase`, `openCredentialDatabase`, and `parseCredentialValue` - Modify `readAuthFile` and add `readAuthFiles` + `readCredentialDatabases` to merge credentials from auth.json and OpenCode's database - Preserve precedence: entries in auth.json override database credentials; database serves as a fallback for OAuth credentials - Add tests covering database fallback and auth.json precedence in `tests/lib.opencode-auth.test.ts`
- src/lib/opencode-auth.ts: update `getCredentialDbPaths` to compute credential database paths from a single base path and return them in a consistent format. - tests/lib.opencode-auth.test.ts: update the `createCredentialDatabase` helper to construct expected paths using the same base-path logic. Why: path construction was duplicated across callers, which made it easy for the test helper to drift from production behavior. Centralizing the path calculation keeps runtime and tests aligned on where credential databases are located.
- package.json: update @opentui/core and @opentui/solid from ^0.4.3 to ^0.5.3 - pnpm-lock.yaml: refresh lockfile for updated dependency resolution - src/tui-v2.tsx: update `TuiContext` and `plugin::setup` to align with the @OpenTui 0.5 API; `trigger` helper has a cosmetic-only change - tests/tui-v2-commands.test.ts: update "registers every quota command as a local slash command" test to cover the updated setup behavior
Compile the V2 TUI entry to the filename imported by the package and verify the clean distribution can be loaded. Use the current compaction and tool lifecycle events so automatic quota notifications run on OpenCode V2.
Merge upstream changes through 5158aa3 while preserving the fork's opencode.db credential source and adopting the new OpenCode Go config precedence and responsible update workflow.
Read every native credential row and report quota independently for each connection. Preserve provider plans, aliases, active markers, partial errors, and per-connection accounting across supported providers.
|
Confirmed on a newer beta build. Additional diagnostics for the V2 port (cc #229). Environment
Observed failure
Both entry points reject the module. The server loader expects Root cause in the 4.8.2 dist
// Module is valid only when the default export has id: string (non-empty) and setup: function
(mod) =>
typeof mod === "object" && mod !== null &&
"id" in mod && typeof mod.id === "string" && mod.id.length > 0 &&
"setup" in mod && typeof mod.setup === "function"
// On failure it throws: `Invalid V2 TUI plugin module: ${spec}`
Target shape (per current V2 plugin docs)import { Plugin } from "@opencode-ai/plugin/tui"
export default Plugin.define({
id: "@slkiser/opencode-quota",
async setup(context) {
// context.ui.slot(...), context.keymap.layer(...), context.data.*, context.ui.toast.show(...)
return () => {
/* cleanup */
}
},
})Also required:
Notes for the install and setup path
I can test a prerelease build against |
|
I've been testing this against I now have the V2 TUI working on the current
I also fixed two issues encountered while testing:
Validated on beta-18314:
Follow-on branch: https://github.com/christian-taillon/opencode-quota/tree/v2-native-multi-connection-quota This is based on #196 rather than upstream main, so I don't want to create a competing V2 PR. Happy to open a follow-up PR against |
Thanks, that would be very useful! I’ve just pushed my own implementation of native multi-connection quota support. It covers the credential-backed providers rather than only OpenAI, and I’m currently testing it. After reviewing your changes, I noticed that your branch also fixes two separate issues that my implementation does not currently cover:
I’d be very happy for you to open a follow-up PR against I’d also appreciate it if you could review my latest push and share any feedback on the multi-provider implementation. |
Use the plan returned by GitHub for user-scoped Copilot quota presentation instead of inferring a personal license from the billing mode. Preserve the user billing scope in diagnostics.
Add the conventional local TUI entrypoint and align OpenTUI with the beta-19151 runtime without changing server or TUI behavior.
|
i've been integrating both dmmop-v2 and upstream for a bit now into my own copy, to run in v2. i humbly submit my own fork that i intend to keep juggling for the foreseeable. it's definitely not as well maintained, caveat emptor, but also, i am excited to share and expect to keep updating for the foreseeable. https://github.com/rektide/opencode-quota-plus/ i also have some features like pro rata #252 that are very helpful to me, and multiple different view formats, which i haven't really been using heavily tbh. i'm making stronger use of the opencode v2 view slots that opencode has been evolving. i used to juggle v1+v2 support but dropped that (v2 is so much better, switch switch switch!). this plugin is the #1 must have opencode addition to me, and i'm so thankful for all the work folks have put in, and look forward to ongoingly contributing upstream here too. 🙇 |
Absorb 13 upstream commits (credential-scoped quota cache, cache security review, Windows portability) while preserving fork changes: multi-connection fan-out, opencode.db credential source and root tui.ts entrypoint. Adopt upstream removal of account_email/account_id from OpenAI status details. Adapt the new cache-isolation test mock to the opencode.db field contract.

Summary
/quotaand token-usage slash commands.auth.jsonas credential source.Testing
pnpm run typecheckpnpm exec vitest run tests/tui-v2-commands.test.tsgit diff --check 87e6540...HEAD/quotain the OpenCode V2 TUI