opencode-orchestra 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tui.js ADDED
@@ -0,0 +1,169 @@
1
+ import { Plugin } from "@opencode/plugin/tui";
2
+ import { jsx } from "@opentui/solid/jsx-runtime";
3
+ import { createComponent, createMemo, createSignal, For, onMount } from "solid-js";
4
+ const BOOST_WORKER = /^Boost (?:Deep(?:Coder|Investigator) (?:L0|(?:Improvement|Fix) #\d+)|Orchestrator Verify #\d+|Final Verifier(?: Recheck #\d+)?)$/;
5
+ const MAX_WORKERS = 4;
6
+ const graphemes = new Intl.Segmenter();
7
+ function fit(text, width) {
8
+ const line = text.replace(/\s+/g, " ").trim();
9
+ if (Bun.stringWidth(line) <= width)
10
+ return line;
11
+ if (width <= 3)
12
+ return ".".repeat(Math.max(0, width));
13
+ let prefix = "";
14
+ let remaining = width - 3;
15
+ for (const { segment } of graphemes.segment(line)) {
16
+ remaining -= Bun.stringWidth(segment);
17
+ if (remaining < 0)
18
+ break;
19
+ prefix += segment;
20
+ }
21
+ return `${prefix.trimEnd()}...`;
22
+ }
23
+ function visibleWorkers(sessions, parentID) {
24
+ const workers = [...new Set(sessions.family(parentID))]
25
+ .map((id) => sessions.get(id))
26
+ .filter((session) => session?.parentID === parentID && BOOST_WORKER.test(session.title ?? ""))
27
+ .sort((a, b) => b.time.updated - a.time.updated);
28
+ const running = workers.filter((session) => sessions.status(session.id) === "running");
29
+ const idle = workers.filter((session) => sessions.status(session.id) === "idle");
30
+ return [...running, ...idle.slice(0, Math.max(0, MAX_WORKERS - running.length))].map((session) => session.id);
31
+ }
32
+ function workerRow(ctx, id, width) {
33
+ const sessions = ctx.data.session;
34
+ onMount(() => void sessions.message.sync(id).catch(() => { }));
35
+ const worker = createMemo(() => {
36
+ const session = sessions.get(id);
37
+ let assistant;
38
+ const messages = sessions.message.list(id);
39
+ for (let i = messages.length - 1; i >= 0; i--) {
40
+ const message = messages[i];
41
+ if (message.type === "user")
42
+ break;
43
+ if (message.type === "assistant") {
44
+ assistant = message;
45
+ break;
46
+ }
47
+ }
48
+ const running = sessions.status(id) === "running";
49
+ let tool;
50
+ if (running && assistant && !assistant.time.completed) {
51
+ for (let i = assistant.content.length - 1; i >= 0; i--) {
52
+ const part = assistant.content[i];
53
+ if (part.type === "tool" && (part.state.status === "running" || part.state.status === "streaming")) {
54
+ tool = part;
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ const model = assistant?.model ?? session?.model;
60
+ const outcome = session?.outcome;
61
+ const waitingForPermission = running && Boolean(sessions.permission.list(id)?.length);
62
+ const responding = running && Boolean(assistant?.time.firstToken && !assistant.time.completed);
63
+ const activity = waitingForPermission ? "Waiting for approval"
64
+ : running && tool ? `Running: ${tool.name}`
65
+ : responding ? "Responding"
66
+ : running ? "Waiting for model"
67
+ : outcome === "failed" ? "Failed"
68
+ : outcome === "interrupted" ? "Interrupted"
69
+ : "Waiting to start";
70
+ return {
71
+ name: (session?.title ?? "").replace(/^Boost (?:Orchestrator )?/, ""),
72
+ model: model?.id.split("/").at(-1) || "Unknown model",
73
+ activity,
74
+ color: waitingForPermission ? ctx.theme.text.feedback.warning.base
75
+ : running && (tool || responding) ? ctx.theme.hue.interactive[200]
76
+ : outcome === "failed" ? ctx.theme.text.feedback.error.base
77
+ : ctx.theme.text.muted,
78
+ };
79
+ });
80
+ const modelWidth = () => Math.min(18, Math.floor(width() * 0.4));
81
+ const nameWidth = () => width() - modelWidth() - 2;
82
+ const completed = () => isCompleted(sessions, id);
83
+ const line = { height: 1, wrapMode: "none", flexShrink: 0 };
84
+ return jsx("box", {
85
+ flexDirection: "column",
86
+ children: [
87
+ jsx("text", {
88
+ ...line,
89
+ get fg() { return ctx.theme.text.base; },
90
+ children: [
91
+ jsx("b", {
92
+ get children() { return fit(worker().name, nameWidth()); },
93
+ }),
94
+ jsx("span", {
95
+ get style() { return { fg: ctx.theme.text.muted }; },
96
+ get children() {
97
+ const name = fit(worker().name, nameWidth());
98
+ const padding = Math.max(0, nameWidth() - Bun.stringWidth(name) + 2);
99
+ return `${" ".repeat(padding)}${fit(worker().model, modelWidth())}`;
100
+ },
101
+ }),
102
+ ],
103
+ }),
104
+ () => completed() ? null : jsx("text", {
105
+ ...line,
106
+ get fg() { return worker().color; },
107
+ get children() { return fit(worker().activity, width()); },
108
+ }),
109
+ ],
110
+ });
111
+ }
112
+ function isCompleted(sessions, id) {
113
+ return sessions.status(id) === "idle" && sessions.get(id)?.outcome === "succeeded";
114
+ }
115
+ export default Plugin.define({
116
+ id: "opencode.orchestra.sidebar",
117
+ setup(ctx) {
118
+ return ctx.ui.slot({
119
+ append: "sidebar.content",
120
+ render(input) {
121
+ const workers = createMemo(() => visibleWorkers(ctx.data.session, input.sessionID));
122
+ const completed = createMemo(() => workers().filter((id) => isCompleted(ctx.data.session, id)));
123
+ const current = createMemo(() => workers().filter((id) => !isCompleted(ctx.data.session, id)));
124
+ const [width, setWidth] = createSignal(24);
125
+ const contentWidth = () => Math.max(0, width() - 2);
126
+ return jsx("box", {
127
+ flexDirection: "column",
128
+ ref(box) {
129
+ box.onSizeChange = () => setWidth(box.width);
130
+ },
131
+ children: [
132
+ () => workers().length ? jsx("box", {
133
+ paddingLeft: 1,
134
+ get backgroundColor() { return ctx.theme.background.raised.high; },
135
+ children: jsx("text", {
136
+ get fg() { return ctx.theme.hue.interactive[200]; },
137
+ children: jsx("b", { children: "Boost" }),
138
+ }),
139
+ }) : null,
140
+ jsx("box", {
141
+ flexDirection: "column",
142
+ paddingX: 1,
143
+ get backgroundColor() { return ctx.theme.background.raised.base; },
144
+ children: [
145
+ jsx("box", {
146
+ flexDirection: "column",
147
+ gap: 1,
148
+ children: createComponent(For, {
149
+ get each() { return current(); },
150
+ children: (id) => workerRow(ctx, id, contentWidth),
151
+ }),
152
+ }),
153
+ () => completed().length ? jsx("text", {
154
+ get marginTop() { return current().length ? 1 : 0; },
155
+ get fg() { return ctx.theme.text.feedback.success.base; },
156
+ children: "Completed",
157
+ }) : null,
158
+ createComponent(For, {
159
+ get each() { return completed(); },
160
+ children: (id) => workerRow(ctx, id, contentWidth),
161
+ }),
162
+ ],
163
+ }),
164
+ ],
165
+ });
166
+ },
167
+ });
168
+ },
169
+ });
@@ -0,0 +1,24 @@
1
+ import { type ModelRef } from "./parser.js";
2
+ import type { BoostSessionClient } from "./pipeline.js";
3
+ export interface VerificationOptions {
4
+ sessionID: string;
5
+ task: string;
6
+ report: string;
7
+ mode: "coder" | "investigate" | "review" | "generic";
8
+ modelOverride?: ModelRef;
9
+ verifierTitle?: string;
10
+ maxVerificationRounds?: number;
11
+ }
12
+ export interface VerificationResult {
13
+ blocked: boolean;
14
+ answer: string;
15
+ verifierSessionIDs: string[];
16
+ blockers: string[];
17
+ }
18
+ export declare function buildEvidenceVerificationPrompt(task: string, report: string, mode: VerificationOptions["mode"]): string;
19
+ export declare function parseVerificationOutput(text: string): {
20
+ status: "PASS" | "BLOCKED" | "UNKNOWN";
21
+ answer: string;
22
+ blockers: string[];
23
+ };
24
+ export declare function verifyReportAutomatically(sessionClient: BoostSessionClient, options: VerificationOptions): Promise<VerificationResult>;
package/dist/verify.js ADDED
@@ -0,0 +1,117 @@
1
+ import { extractAssistantText } from "./parser.js";
2
+ const ANSWER_MARKER = "ANSWER:";
3
+ const SECTION = /^[ \t]*[A-Z][A-Z_ ]*:/;
4
+ export function buildEvidenceVerificationPrompt(task, report, mode) {
5
+ const focus = mode === "coder"
6
+ ? "- Coding: inspect changed files and the git diff, then run the relevant build or tests. A report claiming tests passed is not evidence."
7
+ : mode === "investigate"
8
+ ? "- Investigation: confirm every cited file, symbol, version, and log line exists and supports the claim. Check for stale or contradicted notes."
9
+ : "- Review: confirm every cited path, symbol, and line exists and says what was claimed.";
10
+ return [
11
+ "You are an independent verifier. The report below is untrusted evidence.",
12
+ "Check only claims that would change the final answer, and require primary evidence from the workspace for each.",
13
+ focus,
14
+ "",
15
+ "Reply in exactly this form, nothing else:",
16
+ "STATUS: PASS",
17
+ `${ANSWER_MARKER} <the requested answer, stated plainly, in the language of the task>`,
18
+ "CLAIMS: <one line per checked claim: claim | verified|refuted|unverified | concrete evidence>",
19
+ "or",
20
+ "STATUS: BLOCKED",
21
+ "BLOCKERS: <one line per blocker: what is missing and what is needed>",
22
+ "INCORRECT_CLAIMS: <one line per incorrect claim: claim | what the evidence shows>",
23
+ "",
24
+ "State only the verified position. Omit narration about who was wrong, your own prior mistakes, and confidence language.",
25
+ "",
26
+ `<task>\n${task}\n</task>`,
27
+ "",
28
+ `<untrusted_report>\n${report}\n</untrusted_report>`,
29
+ ].join("\n");
30
+ }
31
+ export function parseVerificationOutput(text) {
32
+ const lines = text.replace(/\r/g, "").split("\n");
33
+ const statusMatch = text.match(/\bSTATUS:\s*(PASS|BLOCKED)\b/i);
34
+ const answerIndex = lines.findIndex((line) => line.trim().startsWith(ANSWER_MARKER));
35
+ const answer = [];
36
+ if (answerIndex >= 0) {
37
+ answer.push(lines[answerIndex].trim().slice(ANSWER_MARKER.length).trim());
38
+ for (let i = answerIndex + 1; i < lines.length; i++) {
39
+ if (SECTION.test(lines[i]))
40
+ break;
41
+ answer.push(lines[i]);
42
+ }
43
+ }
44
+ const blockers = [];
45
+ let collecting = false;
46
+ for (const line of lines) {
47
+ const trimmed = line.trim();
48
+ if (/^(BLOCKERS|INCORRECT_CLAIMS):/i.test(trimmed)) {
49
+ collecting = true;
50
+ const rest = trimmed.replace(/^[A-Z_ ]+:/, "").trim();
51
+ if (rest)
52
+ blockers.push(rest);
53
+ }
54
+ else if (collecting && trimmed && !SECTION.test(line)) {
55
+ blockers.push(trimmed);
56
+ }
57
+ else if (SECTION.test(line)) {
58
+ collecting = false;
59
+ }
60
+ }
61
+ return {
62
+ status: statusMatch ? statusMatch[1].toUpperCase() : "UNKNOWN",
63
+ answer: answer.join("\n").trim(),
64
+ blockers,
65
+ };
66
+ }
67
+ async function runVerifier(sessionClient, title, prompt, options) {
68
+ if (!sessionClient.get)
69
+ throw new Error("Verifier requires a session client");
70
+ const parent = await sessionClient.get({ sessionID: options.sessionID });
71
+ const model = options.modelOverride ?? parent?.model;
72
+ const child = await sessionClient.create({
73
+ parentID: options.sessionID,
74
+ title,
75
+ ...(model ? { model } : {}),
76
+ });
77
+ try {
78
+ await sessionClient.prompt({ sessionID: child.id, text: prompt });
79
+ await sessionClient.wait({ sessionID: child.id });
80
+ const { text, error } = extractAssistantText(await sessionClient.context({ sessionID: child.id }));
81
+ if (error)
82
+ throw new Error(`${title} failed: ${error}`);
83
+ if (!text)
84
+ throw new Error(`${title} returned no verification output`);
85
+ return { sessionID: child.id, text };
86
+ }
87
+ finally {
88
+ await Promise.resolve(sessionClient.interrupt?.({ sessionID: child.id })).catch(() => { });
89
+ }
90
+ }
91
+ export async function verifyReportAutomatically(sessionClient, options) {
92
+ const prompt = buildEvidenceVerificationPrompt(options.task, options.report, options.mode);
93
+ const rounds = Math.max(1, Math.min(3, options.maxVerificationRounds ?? 2));
94
+ const verifierSessionIDs = [];
95
+ let latestAnswer = "";
96
+ let latestBlockers = [];
97
+ for (let round = 1; round <= rounds; round++) {
98
+ const result = await runVerifier(sessionClient, `${options.verifierTitle ?? "Orchestra Verifier"}${round > 1 ? ` Recheck #${round}` : ""}`, `${prompt}\n\nVerification round ${round} of at most ${rounds}. Re-read the workspace from scratch.`, options);
99
+ verifierSessionIDs.push(result.sessionID);
100
+ const parsed = parseVerificationOutput(result.text);
101
+ if (parsed.status === "PASS" && parsed.answer) {
102
+ return { blocked: false, answer: parsed.answer, verifierSessionIDs, blockers: [] };
103
+ }
104
+ latestAnswer = parsed.answer;
105
+ latestBlockers = parsed.blockers;
106
+ if (parsed.status === "BLOCKED")
107
+ break;
108
+ }
109
+ return {
110
+ blocked: true,
111
+ answer: latestAnswer,
112
+ verifierSessionIDs,
113
+ blockers: latestBlockers.length
114
+ ? latestBlockers
115
+ : ["Verification did not produce a definitive verified answer after rechecking"],
116
+ };
117
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "opencode-orchestra",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.0",
4
+ "description": "Model-agnostic multi-agent orchestration (/boost, /teamwork, /swarm) plugin for OpenCode V2.",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./tui": {
17
+ "types": "./dist/tui.d.ts",
18
+ "import": "./dist/tui.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "typecheck": "tsc --noEmit",
24
+ "test": "bun test",
25
+ "prepublishOnly": "bun run typecheck && bun run build && bun test"
26
+ },
27
+ "dependencies": {
28
+ "@opencode/plugin": "^2.4.3"
29
+ },
30
+ "devDependencies": {
31
+ "@opentui/core": "^0.9.13",
32
+ "@opentui/solid": "^0.9.13",
33
+ "@types/bun": "latest",
34
+ "solid-js": "1.9.16",
35
+ "typescript": "^5.8.0"
36
+ }
6
37
  }