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.
|
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 |

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