new: [opencode-greenpt-usage] port plugin to OpenCode v2
Rewrite the TUI plugin against the OpenCode v2 plugin API (``@opencode/plugin`` + ``@opencode/plugin/tui``): - ``src/index.ts``: minimal server-side ``Plugin.define`` entry. - ``src/tui.tsx``: CLI plugin registered as ``./tui``, appending the widget to the ``sidebar.content`` slot through ``context.ui.slot`` and exposing the refresh/reset commands via ``context.keymap.layer``. - ``src/store.ts``: durable plugin storage (``context.storage.store``) replaces the KV store; ``session.idle``/``session.status`` events and the ``client.session`` API drive reconciliation and backfill. - ``src/widget.tsx``: v2 semantic theme tokens (``theme.text.base``/``text.muted``/``text.feedback``). - Tests updated to a structural fake of the v2 context. The free ``HEAD /v1/chat/completions`` balance probe and the credential resolution order are unchanged. The ``order`` option is gone: v2 slot placement is additive.
This commit is contained in:
@@ -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", () => {
|
||||
@@ -50,26 +50,3 @@ describe("formatBalanceError", () => {
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user