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 — feat(tasks): surface an OpenCode pane's subagents like Claude Code's … · devswha/ovis@afdf3a7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • changelog.d
    • opencode-subagents.md
  • docs
    • guide.md
  • server
    • background-wait.test.ts
    • background-wait.ts
    • core
      • server-core.ts
      • status.test.ts
      • status.ts
    • index.ts
    • opencode-subagents.test.ts
    • opencode-subagents.ts
    • opencode.contract.test.ts
    • opencode.test.ts
    • opencode.ts
    • tasks-routes.test.ts
    • tasks-routes.ts
    • transcript-records.ts
  • shared
    • tasks.ts
  • src
    • components
      • BackgroundTasks.tsx
      • Composer.tsx
    • lib
      • api.ts
      • i18n
        • chat.ja.ts
        • chat.ko.ts
        • chat.zh.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎changelog.d/opencode-subagents.md‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Added
2+
- An OpenCode 2 pane's subagents are background tasks, as a Claude Code pane's are: the message
3+
box's button and the sidebar badge count those running, the list shows them with the newest ten
4+
that ended in the last day, a turn that ends while they run reads BG with its finish alerted
5+
once, and one whose pane no longer runs that session reads as lost. A subagent run in the
6+
background leaves a card in the chat with its answer, and a foreground one's answer no longer
7+
shows OpenCode's `<subagent>` tag.
Collapse file

‎docs/guide.md‎

Copy file name to clipboardExpand all lines: docs/guide.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ model's window, which is the file pi reads its own providers from; a model it st
232232
for shows no ring rather than a guessed one, because pi answers those from a catalogue or a
233233
running llama.cpp server that this app cannot ask. The model and reasoning effort come from what the session recorded, never from answer text. A todo list shows where the agent recorded it, in the turn's work block: Claude Code's `TodoWrite`, Codex's `update_plan`, or omp, omo and gjc todo calls. Plain-text plans are not reconstructed, and Claude Code `TaskCreate` / `TaskUpdate` calls are not drawn in the work block: the task list they build is the pane's plan, below. Details and verification are in the [chat-mode audit](chat-mode-audit.md).
234234

235-
Background tasks have a button by the message box, with a count while some run: an OmO pane's `task` children, and a Claude Code pane's subagents (the `Agent` tool), read from the session's own files. A Claude Code pane's background commands (`run_in_background`, Ctrl+B, or one moved there by its timeout) are listed with them. It lists what runs and the newest ten that ended in the last day, and the sidebar badge shows the running count. A Claude Code turn that ends while work it started still runs reads **BG**, not DONE: that work's notice starts the next turn by itself, and the finish is alerted once, when that turn ends (a turn is held at most 30 minutes). A subagent that ends leaves a card in the chat with its answer, and a Claude Code subagent whose pane no longer runs that session reads as lost.
235+
Background tasks have a button by the message box, with a count while some run: an OmO pane's `task` children, a Claude Code pane's subagents (the `Agent` tool), read from the session's own files, and an OpenCode 2 pane's subagents, the child sessions OpenCode keeps of the session in its store (one whose OpenCode service went away mid-run, without ending it, reads as lost once another service starts or the pane leaves that session; on Windows, where a service's start cannot be read, only once the pane leaves that session). A Claude Code pane's background commands (`run_in_background`, Ctrl+B, or one moved there by its timeout) are listed with them. It lists what runs and the newest ten that ended in the last day, and the sidebar badge shows the running count. A Claude Code or OpenCode turn that ends while work it started still runs reads **BG**, not DONE: that work's notice starts the next turn by itself, and the finish is alerted once, when that turn ends (a turn is held at most 30 minutes). A subagent that ends leaves a card in the chat with its answer (for OpenCode, one run in the background; a foreground one's answer is its call's output), and a Claude Code or OpenCode subagent whose pane no longer runs that session reads as lost.
236236

237237
A pane's plan is the task list a Claude Code agent keeps (`TaskCreate` / `TaskUpdate`) or the checklist Codex keeps (`update_plan`), read back from the session's transcript. While there is one, the background-task button by the message box starts with **Plan** and how many of its steps are done (`2/5`); the same button opens one list with the plan's steps first and the background tasks below. Steps are listed so a step comes after the steps it waits on (Claude Code's `blockedBy`; a Codex step waits on the one before it). The running step says what it does now, and each step shows how long it took. The sidebar row carries the same count. Claude Code empties its task list once every task is done, and so does this: the first task after that starts a new plan. A teammate of an agent team that changes a task writes that in its own transcript, which is not read.
238238

Collapse file

‎server/background-wait.test.ts‎

Copy file name to clipboardExpand all lines: server/background-wait.test.ts
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,31 @@ describe("BackgroundWait", () => {
207207
expect(waits.waiting("p1")).toBe(true);
208208
});
209209

210+
it("keeps, past another agent's lifetime, only the rests seen since the agent that followed began", () => {
211+
const time = clock();
212+
const waits = new BackgroundWait(time.now);
213+
// one agent's turn rests on its work
214+
waits.status("p", "working");
215+
waits.running("p", 1, null);
216+
waits.status("p", "done");
217+
expect(waits.waiting("p")).toBe(true);
218+
time.pass(1000);
219+
const since = time.now();
220+
// the next agent's turn rests before its tracker knows its session
221+
waits.status("p", "working");
222+
time.pass(1000);
223+
waits.status("p", "idle");
224+
waits.resetBefore("p", since);
225+
expect(waits.waiting("p")).toBe(false);
226+
// its tracker counts what that turn started: the turn holds
227+
waits.running("p", 1, since);
228+
expect(waits.waiting("p")).toBe(true);
229+
// a reset keeps no rest
230+
waits.reset("p");
231+
waits.running("p", 1, since);
232+
expect(waits.waiting("p")).toBe(false);
233+
});
234+
210235
it("forgets a pane", () => {
211236
const waits = new BackgroundWait(clock().now);
212237
waits.running("p1", 1);
Collapse file

‎server/background-wait.ts‎

Copy file name to clipboardExpand all lines: server/background-wait.ts
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ export class BackgroundWait {
101101
pane.waiting = false;
102102
}
103103

104+
/**
105+
* reset, keeping the rests observed from `since` on: another agent's lifetime ended there, and the one that
106+
* followed was seen rest before its tracker knew its session. Its counts come afresh from that tracker.
107+
*/
108+
resetBefore(paneId: string, since: number): void {
109+
const pane = this.panes.get(paneId);
110+
if (!pane) return;
111+
const rests = pane.rests.filter((at) => at >= since);
112+
this.reset(paneId);
113+
pane.rests = rests;
114+
}
115+
104116
forget(paneId: string): void {
105117
this.panes.delete(paneId);
106118
}
Collapse file

‎server/core/server-core.ts‎

Copy file name to clipboardExpand all lines: server/core/server-core.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function createCore({ options, devices, preferences, usage, usageLogin, T
7676
const { pending, holdPending, holdPendingPane, drainPending, pendingFrames, queueFirstMessage, attached, closeConnection, reconcilePiDeliveries } = createPendingDelivery({ options, clients, attachments, sight, serialize, lastTyped, submitText, authorizeSocket: (client) => authorizeSocket(client), clientSnapshot: () => clientSnapshot(), omo: { sessionOf: (paneId) => omo.sessionOf(paneId) }, SUBMIT_DEADLINE_MS, SUBMIT_DELAY_MS, TYPED_SETTLE_MS });
7777

7878
const { mayType, authorizeSocket, admit, setRole, watchPane, unwatchPane, killWatches, end } = createConnections({ clients, present, pending: { close: closeConnection }, devices, detachClaimed, dropClaims });
79-
const { push, omo, gjc, claudeAgents, plans, clientSnapshot, countVisit, machines, broadcastAll, logPushError, collector, waitTimer } = createStatusHub({ options, devices, preferences, clients, present, pending, drainPending, holdPendingPane, usage, usageLogin });
79+
const { push, omo, gjc, claudeAgents, opencodeAgents, plans, clientSnapshot, countVisit, machines, broadcastAll, logPushError, collector, waitTimer } = createStatusHub({ options, devices, preferences, clients, present, pending, drainPending, holdPendingPane, usage, usageLogin });
8080
const websocket = createSocket({
8181
clients, present, stopped: () => stopped, admit, setRole, watchPane, unwatchPane, end, holdPending, attachments, clientSnapshot, countVisit, drainOutput,
8282
// each frame type by name, with the handler of the module that owns it: anything else on a frame object never
@@ -100,7 +100,7 @@ export function createCore({ options, devices, preferences, usage, usageLogin, T
100100
let outputTimer: ReturnType<typeof setInterval> | undefined;
101101

102102
return {
103-
sidecar, serialize, push, logPushError, omo, claudeAgents, plans, clientSnapshot, machines, broadcastAll, collector, websocket, queueFirstMessage,
103+
sidecar, serialize, push, logPushError, omo, claudeAgents, opencodeAgents, plans, clientSnapshot, machines, broadcastAll, collector, websocket, queueFirstMessage,
104104
/** once the server listens */
105105
start(): void {
106106
// ACKs can stop arriving entirely (a suspended tab). Bound the pause even then.
@@ -119,6 +119,7 @@ export function createCore({ options, devices, preferences, usage, usageLogin, T
119119
omo.stop();
120120
gjc.stop();
121121
claudeAgents.stop();
122+
opencodeAgents.stop();
122123
clearInterval(waitTimer);
123124
plans.stop();
124125
machines?.stop();
Collapse file

‎server/core/status.test.ts‎

Copy file name to clipboard
+166Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import { afterAll, afterEach, describe, expect, it, mock, spyOn } from "bun:test";
2+
import { Database } from "bun:sqlite";
3+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { join } from "node:path";
6+
7+
import type { HerdrPane } from "../../shared/protocol.ts";
8+
import * as collector from "../collector.ts";
9+
import * as conversation from "../conversation.ts";
10+
import * as herdr from "../herdr/client.ts";
11+
import * as service from "../opencode-service.ts";
12+
import { connectionData, type Client } from "./connections.ts";
13+
14+
// herdr's status events come from the test, as the collector would hand them over
15+
type Handlers = { onStatus: (paneId: string, status: string, agent: string) => void; onBaseline: (panes: unknown[]) => void };
16+
let handlers: Handlers;
17+
const originalCollector = collector.startStatusCollector;
18+
mock.module("../collector.ts", () => ({
19+
...collector,
20+
startStatusCollector: (seen: Handlers) => {
21+
handlers = seen;
22+
return { ready: Promise.resolve(), structureReady: Promise.resolve(), focusReady: Promise.resolve(), trackPane() {}, stop() {} };
23+
},
24+
}));
25+
const { createStatusHub } = await import("./status.ts");
26+
27+
const root = mkdtempSync(join(tmpdir(), "herdr-status-hub-"));
28+
afterAll(() => {
29+
mock.module("../collector.ts", () => ({ ...collector, startStatusCollector: originalCollector }));
30+
rmSync(root, { recursive: true, force: true });
31+
});
32+
const stubs: { mockRestore(): void }[] = [];
33+
afterEach(() => { for (const stub of stubs.splice(0)) stub.mockRestore(); });
34+
35+
// an OpenCode parent session whose one child runs, and a resting Claude session with a background subagent its prompt started
36+
const at = Date.now() - 10_000;
37+
const store = join(root, "opencode.db");
38+
{
39+
const db = new Database(store, { create: true });
40+
db.exec(`CREATE TABLE session_v2 (id text PRIMARY KEY, parent_id text, time_created integer);
41+
CREATE TABLE session_message (id text PRIMARY KEY, session_id text, type text, seq integer, time_created integer, data text)`);
42+
db.query("INSERT INTO session_v2 VALUES ('ses_child', 'ses_parent', ?)").run(at + 1000);
43+
const row = db.query("INSERT INTO session_message VALUES (?, ?, 'user', 1, ?, ?)");
44+
row.run("msg_parent", "ses_parent", at, JSON.stringify({ time: { created: at } }));
45+
row.run("msg_child", "ses_child", at + 1000, JSON.stringify({ time: { created: at + 1000 } }));
46+
db.close();
47+
}
48+
const CLAUDE = "11111111-1111-4111-8111-111111111111";
49+
const transcript = join(root, `${CLAUDE}.jsonl`);
50+
{
51+
const line = (value: unknown) => `${JSON.stringify(value)}\n`;
52+
mkdirSync(join(root, CLAUDE, "subagents"), { recursive: true });
53+
writeFileSync(transcript, line({ type: "user", origin: { kind: "human" }, timestamp: new Date(at - 1000).toISOString(), permissionMode: "default", message: { role: "user", content: "go" } }));
54+
writeFileSync(join(root, CLAUDE, "subagents", "agent-a1.meta.json"), JSON.stringify({ agentType: "reviewer", description: "review", toolUseId: "toolu_a1", requestShape: "background" }));
55+
writeFileSync(join(root, CLAUDE, "subagents", "agent-a1.jsonl"), line({ isSidechain: true, sessionId: CLAUDE, agentId: "a1", type: "user", timestamp: new Date(at).toISOString(), message: { role: "user", content: "review" } }));
56+
}
57+
58+
const base = { pane_id: "w1:p1", workspace_id: "w1", tab_id: "w1:t1", agent_status: "idle" };
59+
const opencode = (session: string | null) => ({ ...base, agent: "opencode", ...(session ? { agent_session: { agent: "opencode", source: "herdr:opencode", kind: "id", value: session } } : {}) });
60+
const claude = { ...base, agent: "claude", agent_session: { agent: "claude", source: "hook", kind: "id", value: CLAUDE } };
61+
62+
let hubs = 0;
63+
/** The status hub with herdr, OpenCode's service and the Claude lookup stood in for; what a browser and web push are sent. */
64+
function hub() {
65+
let panes: unknown[] = [];
66+
let gate: Promise<void> | null = null;
67+
const answer = () => ({ agents: [], layouts: [], panes: structuredClone(panes), protocol: 1, tabs: [], version: "test", workspaces: [] });
68+
stubs.push(
69+
spyOn(herdr, "sessionSnapshot").mockImplementation(async () => { const read = answer(); if (gate) await gate; return read as never; }),
70+
spyOn(herdr, "paneGet").mockImplementation(async () => structuredClone(panes[0]) as never),
71+
spyOn(service, "readOpenCodeService").mockReturnValue(null),
72+
spyOn(conversation, "claudePaneSession").mockResolvedValue({ path: transcript, startedAt: null, pid: null } as never),
73+
spyOn(conversation, "claudePanePid").mockResolvedValue(null as never),
74+
);
75+
const frames: { type: string; agent_status?: string; background_tasks?: number; background_wait?: boolean }[] = [];
76+
const client = { data: connectionData({ deviceId: undefined, readOnly: false }), getBufferedAmount: () => 0, send: (encoded: string) => { frames.push(JSON.parse(encoded)); return 1; } } as unknown as Client;
77+
const status = createStatusHub({
78+
options: { stateDir: join(root, `state${++hubs}`), opencodeDb: store, machines: false },
79+
devices: { gated: false, has: () => true } as never, preferences: { get: () => ({ muted_panes: [] }), subscribe: () => () => {} } as never,
80+
clients: new Set([client]), present: new Set(), pending: { status() {}, forget() {} } as never, drainPending() {}, holdPendingPane() {},
81+
usage: { invalidate() {} } as never, usageLogin: { ended: () => false } as never,
82+
});
83+
const alerts: string[] = [];
84+
stubs.push(spyOn(status.push, "onStatus").mockImplementation(async (_paneId: string, alert: string) => { alerts.push(alert); }));
85+
stubs.push({ mockRestore: () => { status.collector.stop(); status.omo.stop(); status.gjc.stop(); status.claudeAgents.stop(); status.opencodeAgents.stop(); status.plans.stop(); clearInterval(status.waitTimer); } });
86+
return {
87+
alerts,
88+
/** herdr's panes from now on, as a snapshot or a pane lookup reads them */
89+
herdrSays: (pane: unknown) => { panes = [pane]; },
90+
/** a snapshot, both trackers reading it (Claude's lookup awaited) */
91+
snapshot: async () => { await status.clientSnapshot(); await status.claudeAgents.refresh(panes as HerdrPane[]); },
92+
/** a snapshot whose read begins now and is answered when `open` is called */
93+
heldSnapshot: async () => {
94+
let open!: () => void;
95+
gate = new Promise((resolve) => { open = resolve; });
96+
const read = status.clientSnapshot();
97+
await new Promise((resolve) => setTimeout(resolve, 0));
98+
gate = null;
99+
return async () => { open(); await read; };
100+
},
101+
/** the pane's last status frame */
102+
last: () => {
103+
const frame = frames.filter((seen) => seen.type === "pane-status").at(-1);
104+
return { status: frame?.agent_status, tasks: frame?.background_tasks ?? 0, bg: frame?.background_wait === true };
105+
},
106+
/** the lookups and reads a status event set off */
107+
settle: () => new Promise((resolve) => setTimeout(resolve, 0)),
108+
};
109+
}
110+
111+
describe("the status hub's OpenCode subagents", () => {
112+
it("holds an OpenCode turn after Claude Code's on its subagent though its session is found after the turn, and calls its finish off", async () => {
113+
const h = hub();
114+
h.herdrSays(claude);
115+
handlers.onBaseline([claude]);
116+
await h.snapshot();
117+
handlers.onStatus("w1:p1", "working", "claude");
118+
handlers.onStatus("w1:p1", "idle", "claude");
119+
expect(h.last()).toEqual({ status: "done", tasks: 1, bg: true });
120+
// OpenCode's first turn there starts a subagent and ends before any snapshot
121+
h.herdrSays(opencode("ses_parent"));
122+
const from = h.alerts.length;
123+
handlers.onStatus("w1:p1", "working", "opencode");
124+
handlers.onStatus("w1:p1", "idle", "opencode");
125+
await h.settle();
126+
expect(h.last()).toEqual({ status: "done", tasks: 1, bg: true });
127+
expect(h.alerts.slice(from).at(-1)).toBe("working");
128+
// the snapshot that follows, Claude's tracker letting go of the pane, keeps it
129+
await h.snapshot();
130+
expect(h.last()).toEqual({ status: "done", tasks: 1, bg: true });
131+
});
132+
133+
it("keeps an OpenCode turn held though a snapshot read before its session was found is answered after", async () => {
134+
const h = hub();
135+
h.herdrSays(claude);
136+
handlers.onBaseline([claude]);
137+
await h.snapshot();
138+
handlers.onStatus("w1:p1", "working", "claude");
139+
handlers.onStatus("w1:p1", "idle", "claude");
140+
// what herdr says as a snapshot's read begins: OpenCode's home screen
141+
h.herdrSays(opencode(null));
142+
const answer = await h.heldSnapshot();
143+
h.herdrSays(opencode("ses_parent"));
144+
handlers.onStatus("w1:p1", "working", "opencode");
145+
await h.settle();
146+
await answer();
147+
handlers.onStatus("w1:p1", "idle", "opencode");
148+
await h.settle();
149+
expect(h.last()).toEqual({ status: "done", tasks: 1, bg: true });
150+
});
151+
152+
it("lets a Claude Code session that follows OpenCode's in the pane hold nothing of OpenCode's", async () => {
153+
const h = hub();
154+
h.herdrSays(opencode("ses_parent"));
155+
handlers.onBaseline([opencode("ses_parent")]);
156+
await h.snapshot();
157+
handlers.onStatus("w1:p1", "working", "opencode");
158+
handlers.onStatus("w1:p1", "idle", "opencode");
159+
expect(h.last()).toEqual({ status: "done", tasks: 1, bg: true });
160+
// a resting Claude session with a subagent running from before
161+
h.herdrSays(claude);
162+
await h.snapshot();
163+
handlers.onStatus("w1:p1", "idle", "claude");
164+
expect(h.last().bg).toBe(false);
165+
});
166+
});

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.