GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(tui): setup-time keymap layer, typed setup, reactive target · rphang/opencode-workflows@c9755c2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • PARITY.md
  • src/tui
    • index.tsx
  • tests/parity
    • tui-client.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/PARITY.md‎

Copy file name to clipboardExpand all lines: docs/PARITY.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Design: [`docs/design/steering-and-live-tree.md`](design/steering-and-live-tree.
147147

148148
## Test evidence
149149

150-
`npm run test:parity` (`bun test tests/parity`) runs 334 tests in 15 files, and all pass. They
150+
`npm run test:parity` (`bun test tests/parity`) runs 335 tests in 15 files, and all pass. They
151151
enter at the highest level possible: the plugin's `setup()` over a fake opencode v2 Context
152152
(`tests/helpers/plugin-harness.ts`), then the `workflow` and `workflow_control` tools
153153
(`execute`), the slash commands, and the `<task-notification>` delivered through
Collapse file

‎src/tui/index.tsx‎

Copy file name to clipboardExpand all lines: src/tui/index.tsx
+52-43Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
// events delta / finished → one global stream, filtered here by Location and session
88
//
99
// Surfaces: the prompt footer (`wf <name> 7/12 · 81.2k · $0.42`), the home footer (`wf 2 running`), a
10-
// session panel "workflows" with the tree (<leader>o, /wf), <leader>j to message an agent, and a
11-
// desktop notification (or a toast) when a run finishes. If the RPC is unavailable (plugin disabled,
12-
// older opencode) it stays silent; /workflows keeps working.
10+
// session panel "workflows" with the tree (<leader>o, /wf), the agent dialog (<leader>j, X25), a
11+
// sidebar summary (X26), and a desktop notification (or a toast) when a run finishes. If the RPC is
12+
// unavailable (plugin disabled) it retries a few times (X27), then stays quiet; /workflows keeps working.
13+
//
14+
// The host-agnostic state and sync live in src/client/ (shared with a GUI companion); this file only
15+
// wires them to the opencode 2.3 TUI plugin API (@opencode/plugin/tui, types only: the host provides it).
1316

14-
import { createMemo, createSignal, Show } from "solid-js"
17+
import type { Plugin } from "@opencode/plugin/tui"
18+
import { createEffect, createMemo, createRoot, createSignal, Show, untrack } from "solid-js"
1519
import { TreeSync } from "../client/sync.ts"
1620
import { definition } from "../plugin/rpc-def.ts"
1721
import { Panel } from "./panel.tsx"
@@ -55,7 +59,7 @@ function clip(s: string, n = 400): string {
5559

5660
const plugin = {
5761
id: "dynamic-workflows.tui",
58-
setup(ctx: any) {
62+
setup(ctx: Plugin.Context) {
5963
const rpc = ctx.client.rpc(definition)
6064
const tree = new TreeStore()
6165
const [version, setVersion] = createSignal(0)
@@ -98,18 +102,25 @@ const plugin = {
98102
const offPlugins = ctx.data?.on?.("plugin.updated", () => void sync.refresh())
99103
if (typeof offPlugins === "function") cleanups.push(offPlugins)
100104

101-
// Resync when the viewed session (and so the target) or the scope changes, and periodically
102-
// while a run is active (missed events, reconnects).
103-
const watchTarget = setInterval(() => sync.checkTarget(), 500)
105+
// Resync when the viewed session (and so the target) or the scope changes: the router's route and
106+
// the session data are Solid stores in opencode 2.3 (route.tsx createStore/reconcile, the client's
107+
// data store), so an effect over filter() sees every change. Its own root: setup has no owner.
108+
createRoot((dispose) => {
109+
cleanups.push(dispose)
110+
createEffect(() => {
111+
filter()
112+
untrack(() => sync.checkTarget())
113+
})
114+
})
115+
// Periodically while a run is active (missed events, reconnects).
104116
const periodic = setInterval(() => {
105117
if ([...tree.runs.values()].some(isActive)) void resync()
106118
}, RESYNC_MS)
107119
const ticker = setInterval(() => {
108120
if ([...tree.runs.values()].some(isActive)) setNow(Date.now())
109121
}, TICK_MS)
110-
for (const t of [watchTarget, periodic, ticker]) (t as any).unref?.()
122+
for (const t of [periodic, ticker]) (t as { unref?: () => void }).unref?.()
111123
cleanups.push(() => {
112-
clearInterval(watchTarget)
113124
clearInterval(periodic)
114125
clearInterval(ticker)
115126
})
@@ -130,7 +141,8 @@ const plugin = {
130141

131142
const control = async (req: ControlRequest) => {
132143
try {
133-
const res = await rpc.control(req, location())
144+
// The output schema is a plain object; the handler answers {ok, message} (src/plugin/rpc-def.ts).
145+
const res = (await rpc.control(req, location())) as { ok?: boolean; message?: string } | undefined
134146
toast(String(res?.message ?? "done"), res?.ok ? "success" : "warning", "Workflows")
135147
} catch (e) {
136148
toast(errText(e), "error", "Workflows")
@@ -222,6 +234,33 @@ const plugin = {
222234
if (picked) await runAction(pickerAction(tree, picked, "steer"))
223235
}
224236

237+
// ---- global commands ----------------------------------------------------------------------
238+
239+
// A setup-time layer (opencode 2.3 registers it for the plugin's lifetime; it used to need an
240+
// `app` slot render that returned null).
241+
ctx.keymap.layer(() => ({
242+
mode: "global",
243+
commands: [
244+
{
245+
id: "workflows.panel",
246+
title: "Workflows: toggle the live progress tree",
247+
group: "Workflows",
248+
bind: "<leader>o",
249+
palette: true,
250+
slash: { name: "wf" },
251+
run: () => openPanel(),
252+
},
253+
{
254+
id: "workflows.message",
255+
title: "Workflows: agents (steer, stop, open)",
256+
group: "Workflows",
257+
bind: "<leader>j",
258+
palette: true,
259+
run: () => void agentDialog(),
260+
},
261+
],
262+
}))
263+
225264
// ---- surfaces -----------------------------------------------------------------------------
226265

227266
const muted = () => ctx.theme?.text?.muted
@@ -272,7 +311,7 @@ const plugin = {
272311
cleanups.push(
273312
ctx.ui.slot({
274313
append: "session.panel",
275-
render: (input: any) => (
314+
render: (input) => (
276315
<Show when={input.name === PANEL}>
277316
<Panel
278317
ctx={ctx}
@@ -302,36 +341,6 @@ const plugin = {
302341
),
303342
}),
304343
)
305-
cleanups.push(
306-
ctx.ui.slot({
307-
append: "app",
308-
render() {
309-
ctx.keymap.layer(() => ({
310-
mode: "global",
311-
commands: [
312-
{
313-
id: "workflows.panel",
314-
title: "Workflows: toggle the live progress tree",
315-
group: "Workflows",
316-
bind: "<leader>o",
317-
palette: true,
318-
slash: { name: "wf" },
319-
run: () => openPanel(),
320-
},
321-
{
322-
id: "workflows.message",
323-
title: "Workflows: agents (steer, stop, open)",
324-
group: "Workflows",
325-
bind: "<leader>j",
326-
palette: true,
327-
run: () => void agentDialog(),
328-
},
329-
],
330-
}))
331-
return null
332-
},
333-
}),
334-
)
335344

336345
return () => {
337346
for (const c of cleanups.splice(0).reverse()) {
@@ -341,6 +350,6 @@ const plugin = {
341350
}
342351
}
343352
},
344-
}
353+
} satisfies Plugin.Definition
345354

346355
export default plugin
Collapse file

‎tests/parity/tui-client.test.ts‎

Copy file name to clipboardExpand all lines: tests/parity/tui-client.test.ts
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ describe("X25 agent dialog", () => {
115115
})
116116
})
117117

118+
describe("X15 X25 TUI entry on opencode 2.3", () => {
119+
test("X15 X25 the global commands are a setup-time keymap layer (no `app` slot render), setup is typed against the TUI plugin definition, and the target is watched reactively", () => {
120+
const src = readFileSync(join(root, "src", "tui", "index.tsx"), "utf8")
121+
expect(src).not.toMatch(/append: "app"/)
122+
expect(src).toMatch(/import type \{ Plugin \} from "@opencode\/plugin\/tui"/)
123+
expect(src).toMatch(/satisfies Plugin\.Definition/)
124+
expect(src).not.toMatch(/setup\(ctx: any\)/)
125+
// The keymap layer is created in setup itself, before any slot.
126+
const layer = src.indexOf("ctx.keymap.layer(")
127+
expect(layer).toBeGreaterThan(0)
128+
expect(layer).toBeLessThan(src.indexOf("ctx.ui.slot("))
129+
// The 500 ms poll of the route is gone: a Solid effect on the (reactive) router and session data.
130+
expect(src).not.toMatch(/setInterval\(\(\) => sync\.checkTarget\(\), 500\)/)
131+
expect(src).toMatch(/createEffect\(/)
132+
})
133+
})
134+
118135
describe("X26 sidebar summary", () => {
119136
const research = { title: "Research", model: null, agents: 8, done: 5, running: 3, tokens: 60_000, elapsedMs: 1000 }
120137
const judge = { title: "Judge", model: null, agents: 4, done: 0, running: 0, tokens: 0, elapsedMs: null }

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.