initial tui plugin meta pass down

This commit is contained in:
Sebastian Herrlinger
2026-03-09 20:00:36 +01:00
parent 731d840afd
commit 8e1392cad5
5 changed files with 154 additions and 17 deletions

View File

@@ -2,7 +2,7 @@
import { extend, useKeyboard, useTerminalDimensions, type RenderableConstructor } from "@opentui/solid"
import { RGBA, VignetteEffect, type OptimizedBuffer, type RenderContext } from "@opentui/core"
import { ThreeRenderable, THREE } from "@opentui/core/3d"
import type { TuiApi, TuiKeybindSet, TuiPluginInput } from "@opencode-ai/plugin/tui"
import type { TuiApi, TuiKeybindSet, TuiPluginInit, TuiPluginInput } from "@opencode-ai/plugin/tui"
const tabs = ["overview", "counter", "help"]
const bind = {
@@ -51,6 +51,25 @@ const cfg = (options: Record<string, unknown> | undefined) => {
}
}
const boot = (meta?: TuiPluginInit) => {
if (!meta) {
return {
state: "unknown",
first: false,
updated: false,
count: 0,
source: "n/a",
}
}
return {
state: meta.state,
first: meta.first,
updated: meta.updated,
count: meta.entry.load_count,
source: meta.entry.source,
}
}
const names = (input: ReturnType<typeof cfg>) => {
return {
modal: `${input.route}.modal`,
@@ -339,6 +358,7 @@ const Screen = (props: {
input: ReturnType<typeof cfg>
route: ReturnType<typeof names>
keys: Keys
meta: ReturnType<typeof boot>
params?: Record<string, unknown>
}) => {
const dim = useTerminalDimensions()
@@ -526,6 +546,12 @@ const Screen = (props: {
{value.tab === 0 ? (
<box flexDirection="column" gap={1}>
<text fg={skin.text}>Route: {props.route.screen}</text>
<text fg={skin.muted}>plugin state: {props.meta.state}</text>
<text fg={skin.muted}>
first: {props.meta.first ? "yes" : "no"} · updated: {props.meta.updated ? "yes" : "no"} · loads:{" "}
{props.meta.count}
</text>
<text fg={skin.muted}>plugin source: {props.meta.source}</text>
<text fg={skin.muted}>source: {value.source}</text>
<text fg={skin.muted}>note: {value.note || "(none)"}</text>
<text fg={skin.muted}>selected: {value.selected || "(none)"}</text>
@@ -849,7 +875,7 @@ const reg = (api: TuiApi, input: ReturnType<typeof cfg>, keys: Keys) => {
])
}
const tui = async (input: TuiPluginInput, options?: Record<string, unknown>) => {
const tui = async (input: TuiPluginInput, options?: Record<string, unknown>, meta?: TuiPluginInit) => {
if (options?.enabled === false) return
await input.api.theme.install("./smoke-theme.json")
@@ -859,12 +885,15 @@ const tui = async (input: TuiPluginInput, options?: Record<string, unknown>) =>
const route = names(value)
const keys = input.api.keybind.create(bind, value.keybinds)
const fx = new VignetteEffect(value.vignette)
const info = boot(meta)
input.renderer.addPostProcessFn(fx.apply.bind(fx))
input.api.route.register([
{
name: route.screen,
render: ({ params }) => <Screen api={input.api} input={value} route={route} keys={keys} params={params} />,
render: ({ params }) => (
<Screen api={input.api} input={value} route={route} keys={keys} meta={info} params={params} />
),
},
{
name: route.modal,