chg: [opencode-greenpt-usage] port the TUI plugin to OpenCode 2

V1 TUI modules no longer load: replace ``{ id, tui }`` with
``Plugin.define({ id, setup })``, register the section on
``sidebar.content``, and expose commands through ``context.keymap.layer``.

Move balance, clock and usage state onto ``context.storage.store/memory``
so host subscribers rerender; plugin-created signals stayed stale in the
V2 renderer. Read V2 assistant messages (``type``,
``model.providerID``/``model.id``) and subscribe through ``context.data``.

Configure the package directory in ``cli.json`` instead of the source
file; document the V2 install. Typecheck, 49 unit tests and the live
GreenPT integration test pass, and the sidebar renders the balance.
This commit is contained in:
Stéphan Sainléger
2026-11-18 23:01:40 +01:00
parent 9c84473266
commit dadc93a22d
13 changed files with 4757 additions and 671 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { formatBalanceError, formatCredits, formatTokens, readFoldOpen } from "../src/format"
import { formatBalanceError, formatCredits, formatTokens } from "../src/format"
describe("formatCredits", () => {
it("formats with two decimals", () => {
@@ -49,27 +49,3 @@ describe("formatBalanceError", () => {
expect(formatBalanceError({ kind: "no-credential", reason: "missing" })).toContain("GreenPT")
})
})
describe("readFoldOpen", () => {
it("defaults to open when the KV store is absent", () => {
expect(readFoldOpen(undefined)).toBe(true)
})
it("reads a persisted boolean", () => {
expect(readFoldOpen({ get: () => false })).toBe(false)
})
it("falls back when the stored value is not a boolean", () => {
expect(readFoldOpen({ get: () => "nope" })).toBe(true)
})
it("survives a throwing KV store", () => {
expect(
readFoldOpen({
get: () => {
throw new Error("kv down")
},
}),
).toBe(true)
})
})