@firstpick/pi-package-webui 0.7.6 → 0.7.8
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/README.md +60 -4
- package/bin/pi-webui-rpc-supervisor.mjs +612 -0
- package/bin/pi-webui.mjs +1051 -95
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +317 -0
- package/lib/rpc-supervisor-protocol.mjs +245 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +4 -4
- package/public/app.js +1986 -170
- package/public/index.html +388 -25
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +8 -1
- package/public/styles.css +578 -52
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +107 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +275 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/fake-pi.mjs +90 -6
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +79 -16
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +13 -2
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +108 -0
- package/tests/rpc-supervisor-host.test.mjs +408 -0
- package/tests/rpc-supervisor-protocol.test.mjs +93 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +18 -2
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +136 -0
- package/tests/terminal-tab-workspace-static.test.mjs +99 -0
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +160 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
SUBAGENT_GATE_RETENTION_MS,
|
|
7
|
+
pruneDismissedSubagentGateKeys,
|
|
8
|
+
subagentGateIsTerminal,
|
|
9
|
+
subagentGateKey,
|
|
10
|
+
visibleSubagentGates,
|
|
11
|
+
} from "../public/subagent-gate-visibility.mjs";
|
|
12
|
+
|
|
13
|
+
const now = 100_000;
|
|
14
|
+
const tab = {
|
|
15
|
+
tabId: "tab-a",
|
|
16
|
+
gates: [
|
|
17
|
+
{ id: "running", status: "running", endedAt: 1 },
|
|
18
|
+
{ id: "fresh", status: "failed", endedAt: now - SUBAGENT_GATE_RETENTION_MS + 1 },
|
|
19
|
+
{ id: "expired", status: "satisfied", endedAt: now - SUBAGENT_GATE_RETENTION_MS },
|
|
20
|
+
{ id: "updated", status: "cancelled", updatedAt: now - 1_000 },
|
|
21
|
+
{ id: "untimed", status: "failed" },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
assert.equal(SUBAGENT_GATE_RETENTION_MS, 30_000, "terminal retry gates should remain readable for 30 seconds");
|
|
26
|
+
assert.equal(subagentGateKey("tab-a", "gate-a"), "tab-a:gate-a");
|
|
27
|
+
assert.equal(subagentGateKey("", "gate-a"), "");
|
|
28
|
+
assert.equal(subagentGateIsTerminal({ status: "running" }), false);
|
|
29
|
+
assert.equal(subagentGateIsTerminal({ status: "failed" }), true);
|
|
30
|
+
|
|
31
|
+
assert.deepEqual(
|
|
32
|
+
visibleSubagentGates(tab, new Set(), now).map((gate) => gate.id),
|
|
33
|
+
["running", "fresh", "updated", "untimed"],
|
|
34
|
+
"running gates should remain visible while terminal gates should expire after the retention window",
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
assert.deepEqual(
|
|
38
|
+
visibleSubagentGates(tab, new Set(["tab-a:fresh"]), now).map((gate) => gate.id),
|
|
39
|
+
["running", "updated", "untimed"],
|
|
40
|
+
"manual dismissal should hide a terminal gate immediately",
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const dismissed = new Set(["tab-a:fresh", "tab-z:gone"]);
|
|
44
|
+
pruneDismissedSubagentGateKeys([tab], dismissed);
|
|
45
|
+
assert.deepEqual([...dismissed], ["tab-a:fresh"], "dismissal state should be pruned after its gate leaves the server snapshot");
|
|
46
|
+
|
|
47
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
48
|
+
const [app, css, serviceWorker, server, pkgRaw] = await Promise.all([
|
|
49
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
50
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
51
|
+
readFile(join(root, "public", "service-worker.js"), "utf8"),
|
|
52
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
53
|
+
readFile(join(root, "package.json"), "utf8"),
|
|
54
|
+
]);
|
|
55
|
+
const pkg = JSON.parse(pkgRaw);
|
|
56
|
+
|
|
57
|
+
assert.match(app, /from "\.\/subagent-gate-visibility\.mjs"/, "the browser should load the retry-gate visibility policy");
|
|
58
|
+
assert.match(app, /function subagentTabsWithRunningAgents\(\)[\s\S]*latestSubagents\?\.updatedAt[\s\S]*visibleSubagentGates\(tab, dismissedSubagentGateKeys, now\)/, "the side panel should use server time and filter expired or dismissed gates before deriving counts");
|
|
59
|
+
assert.match(app, /function renderSubagentGate\(tab, gate\)[\s\S]*subagentGateIsTerminal\(gate\)[\s\S]*Hide finished retry gate[\s\S]*dismissedSubagentGateKeys\.add\(key\)[\s\S]*renderSubagents\(\)[\s\S]*event\.detail === 0[\s\S]*focusTarget\?\.focus/, "terminal gate cards should expose an accessible hide button and preserve keyboard focus after rerendering");
|
|
60
|
+
assert.match(app, /pruneDismissedSubagentGateKeys\(latestSubagents\?\.tabs, dismissedSubagentGateKeys\)/, "polling should prune stale dismissal keys");
|
|
61
|
+
assert.match(css, /\.subagent-gate-actions[\s\S]*\.subagent-gate-close[\s\S]*min-width:\s*1\.75rem[\s\S]*\.subagent-gate-close:hover,[\s\S]*\.subagent-gate-close:focus-visible/, "the close control should remain compact and keyboard-visible");
|
|
62
|
+
assert.match(serviceWorker, /"\/subagent-gate-visibility\.mjs"/, "the PWA app shell should cache the visibility module");
|
|
63
|
+
assert.match(server, /"subagent-gate-visibility\.mjs"/, "the server static allowlist should serve the visibility module");
|
|
64
|
+
assert.match(pkg.scripts.check, /node --check public\/subagent-gate-visibility\.mjs/, "the package check should syntax-check the visibility module");
|
|
65
|
+
|
|
66
|
+
console.log("subagent gate visibility tests passed");
|
|
@@ -28,7 +28,7 @@ assert.match(css, /\.subagent-launch-slot-controls \{[\s\S]*grid-column: 1 \/ -1
|
|
|
28
28
|
assert.match(css, /\.sr-only \{[\s\S]*clip-path: inset\(50%\)[\s\S]*white-space: nowrap/, "screen-reader announcements should stay visually hidden without leaving the accessibility tree");
|
|
29
29
|
assert.match(css, /\.subagent-launch-slot-remove \{[^}]*color: var\(--ctp-red\)/, "destructive slot removal should have a textual control and warning color");
|
|
30
30
|
assert.match(server, /"subagent-launch-slot-state\.mjs"/, "the pure browser module should be on the static allowlist");
|
|
31
|
-
assert.match(serviceWorker, /pi-webui-pwa-
|
|
31
|
+
assert.match(serviceWorker, /pi-webui-pwa-v\d+[\s\S]*"\/subagent-launch-slot-state\.mjs"/, "the refreshed PWA cache should include the browser module");
|
|
32
32
|
assert.match(pkg, /node --check public\/subagent-launch-slot-state\.mjs/, "package checks should syntax-check the browser state module");
|
|
33
33
|
|
|
34
34
|
console.log("subagent-launch-slots-static.test.mjs passed");
|
|
@@ -30,6 +30,7 @@ const extensionHandlers = new Map();
|
|
|
30
30
|
const registeredCommands = new Map();
|
|
31
31
|
const statuses = [];
|
|
32
32
|
const notifications = [];
|
|
33
|
+
let subagentStatusRequestCount = 0;
|
|
33
34
|
const pi = {
|
|
34
35
|
events: bus,
|
|
35
36
|
on(name, handler) {
|
|
@@ -111,6 +112,7 @@ const statusText = `Active async runs: 2
|
|
|
111
112
|
|
|
112
113
|
webuiRpcHelper(pi);
|
|
113
114
|
const unsubscribeRpc = bus.on("subagents:rpc:v1:request", (request) => {
|
|
115
|
+
subagentStatusRequestCount += 1;
|
|
114
116
|
const text = request.params?.id === "run-a"
|
|
115
117
|
? `Run: run-a\nState: running\nMode: parallel\nDir: ${asyncRunDir}`
|
|
116
118
|
: statusText;
|
|
@@ -189,8 +191,90 @@ assert.equal(payload.gates.length, 1, "helper should publish retry gate lifecycl
|
|
|
189
191
|
assert.equal(payload.gates[0].qualifyingSuccesses, 1);
|
|
190
192
|
assert.deepEqual(payload.gates[0].attempts.map((attempt) => [attempt.status, attempt.failureKind]), [["succeeded", undefined], ["failed", "transient-provider"]]);
|
|
191
193
|
|
|
194
|
+
const workflowRunId = "workflow:run-42";
|
|
195
|
+
const workflowAgentId = "workflow:run-42:phase:implement:call:call-0123456789abcdef";
|
|
196
|
+
const workflowSnapshot = {
|
|
197
|
+
version: 1,
|
|
198
|
+
updatedAt: "2026-07-26T12:00:05.000Z",
|
|
199
|
+
runs: [{
|
|
200
|
+
id: workflowRunId,
|
|
201
|
+
source: "workflow",
|
|
202
|
+
name: "Workflow build",
|
|
203
|
+
status: "running",
|
|
204
|
+
startedAt: "2026-07-26T12:00:00.000Z",
|
|
205
|
+
agents: [{
|
|
206
|
+
id: workflowAgentId,
|
|
207
|
+
name: "Implementation worker",
|
|
208
|
+
status: "running",
|
|
209
|
+
index: 0,
|
|
210
|
+
activityState: "stdout",
|
|
211
|
+
model: "openai-codex/gpt-5.6-terra:xhigh",
|
|
212
|
+
recentOutput: ["Inspecting helper contract", "Implementing local output route"],
|
|
213
|
+
}],
|
|
214
|
+
}],
|
|
215
|
+
};
|
|
216
|
+
bus.emit("firstpick:workflow-subagents:v1", workflowSnapshot);
|
|
217
|
+
payload = latestPayload();
|
|
218
|
+
const workflowRun = payload.runs.find((run) => run.id === workflowRunId);
|
|
219
|
+
assert.deepEqual(workflowRun && {
|
|
220
|
+
id: workflowRun.id,
|
|
221
|
+
source: workflowRun.source,
|
|
222
|
+
name: workflowRun.name,
|
|
223
|
+
agents: workflowRun.agents.map((agent) => [agent.id, agent.name, agent.activityState, agent.model, agent.thinking]),
|
|
224
|
+
}, {
|
|
225
|
+
id: workflowRunId,
|
|
226
|
+
source: "workflow",
|
|
227
|
+
name: "Workflow build",
|
|
228
|
+
agents: [[workflowAgentId, "Implementation worker", "stdout", "openai-codex/gpt-5.6-terra:xhigh", undefined]],
|
|
229
|
+
}, "workflow snapshots should preserve stable IDs, source, name, activity, model, and unknown thinking alongside ordinary rows");
|
|
230
|
+
assert.ok(payload.runs.some((run) => run.id === "run-a") && payload.runs.some((run) => run.id === "run-b"), "workflow rows should coexist with ordinary async rows");
|
|
231
|
+
|
|
232
|
+
const requestsBeforeWorkflowPoll = subagentStatusRequestCount;
|
|
233
|
+
bus.emit("subagents:rpc:v1:ready", { version: 1 });
|
|
234
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
235
|
+
payload = latestPayload();
|
|
236
|
+
assert.ok(subagentStatusRequestCount > requestsBeforeWorkflowPoll, "ordinary pi-subagents polling should still run after workflow snapshots arrive");
|
|
237
|
+
assert.ok(payload.runs.some((run) => run.id === workflowRunId), "pi-subagents polling must not reconcile away workflow rows");
|
|
238
|
+
|
|
192
239
|
const helperCommand = registeredCommands.get("webui-helper");
|
|
193
240
|
assert.ok(helperCommand?.handler, "Web UI helper command should be registered");
|
|
241
|
+
const requestsBeforeWorkflowOutput = subagentStatusRequestCount;
|
|
242
|
+
await helperCommand.handler(JSON.stringify({
|
|
243
|
+
requestId: "workflow-subagent-output-test",
|
|
244
|
+
action: "subagent-output",
|
|
245
|
+
payload: { runId: workflowRunId, agentId: workflowAgentId },
|
|
246
|
+
}), ctx);
|
|
247
|
+
const workflowOutputNotice = notifications.find((entry) => entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")
|
|
248
|
+
&& JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === "workflow-subagent-output-test");
|
|
249
|
+
assert.ok(workflowOutputNotice, "workflow output should return a local helper response");
|
|
250
|
+
const workflowOutputResponse = JSON.parse(workflowOutputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
251
|
+
assert.equal(workflowOutputResponse.ok, true);
|
|
252
|
+
assert.equal("thinking" in workflowOutputResponse.data.agent, false, "workflow output must leave unknown thinking metadata absent rather than infer it from the model");
|
|
253
|
+
assert.deepEqual(workflowOutputResponse.data, {
|
|
254
|
+
version: 1,
|
|
255
|
+
runId: workflowRunId,
|
|
256
|
+
source: "workflow",
|
|
257
|
+
mode: "single",
|
|
258
|
+
startedAt: Date.parse("2026-07-26T12:00:00.000Z"),
|
|
259
|
+
updatedAt: Date.parse("2026-07-26T12:00:05.000Z"),
|
|
260
|
+
agent: {
|
|
261
|
+
id: workflowAgentId,
|
|
262
|
+
name: "Implementation worker",
|
|
263
|
+
index: 0,
|
|
264
|
+
nested: false,
|
|
265
|
+
status: "running",
|
|
266
|
+
activityState: "stdout",
|
|
267
|
+
model: "openai-codex/gpt-5.6-terra:xhigh",
|
|
268
|
+
recentTools: [],
|
|
269
|
+
recentOutput: ["Inspecting helper contract", "Implementing local output route"],
|
|
270
|
+
transcript: [],
|
|
271
|
+
},
|
|
272
|
+
}, "workflow output should use only cached bounded workflow fields");
|
|
273
|
+
assert.equal(subagentStatusRequestCount, requestsBeforeWorkflowOutput, "workflow output must not request pi-subagents status or filesystem data");
|
|
274
|
+
|
|
275
|
+
assert.doesNotThrow(() => bus.emit("firstpick:workflow-subagents:v1", { version: 1, runs: "not-an-array" }), "malformed workflow payloads must not crash the helper");
|
|
276
|
+
payload = latestPayload();
|
|
277
|
+
assert.ok(payload.runs.some((run) => run.id === workflowRunId), "malformed workflow payloads must not clear the prior valid snapshot");
|
|
194
278
|
await helperCommand.handler(JSON.stringify({
|
|
195
279
|
requestId: "async-subagent-output-test",
|
|
196
280
|
action: "subagent-output",
|
|
@@ -359,6 +443,58 @@ for (const handler of extensionHandlers.get("tool_execution_end") || []) {
|
|
|
359
443
|
payload = latestPayload();
|
|
360
444
|
assert.equal(payload.runs.some((run) => run.source === "foreground"), false, "foreground children should disappear when their tool finishes");
|
|
361
445
|
|
|
446
|
+
const boundedWorkflowSnapshot = {
|
|
447
|
+
version: 1,
|
|
448
|
+
updatedAt: "2026-07-26T12:01:00.000Z",
|
|
449
|
+
runs: Array.from({ length: 33 }, (_unused, runIndex) => ({
|
|
450
|
+
id: `workflow:bounded-run-${runIndex}`,
|
|
451
|
+
source: "workflow",
|
|
452
|
+
name: `Bounded workflow ${runIndex}`,
|
|
453
|
+
status: "running",
|
|
454
|
+
startedAt: "2026-07-26T12:00:00.000Z",
|
|
455
|
+
agents: Array.from({ length: 33 }, (_agentUnused, agentIndex) => ({
|
|
456
|
+
id: `workflow:bounded-run-${runIndex}:phase:phase-${agentIndex}:call:call-${agentIndex}`,
|
|
457
|
+
name: `Bounded worker ${agentIndex}`,
|
|
458
|
+
status: "running",
|
|
459
|
+
index: agentIndex,
|
|
460
|
+
activityState: "x".repeat(200),
|
|
461
|
+
model: "m".repeat(300),
|
|
462
|
+
recentOutput: Array.from({ length: 9 }, (_lineUnused, lineIndex) => `line-${lineIndex}:${"o".repeat(700)}`),
|
|
463
|
+
})),
|
|
464
|
+
})),
|
|
465
|
+
};
|
|
466
|
+
assert.doesNotThrow(() => bus.emit("firstpick:workflow-subagents:v1", boundedWorkflowSnapshot), "oversized workflow snapshots should be bounded safely at ingress");
|
|
467
|
+
payload = latestPayload();
|
|
468
|
+
const boundedWorkflowRuns = payload.runs.filter((run) => run.source === "workflow");
|
|
469
|
+
assert.equal(boundedWorkflowRuns.length, 32, "workflow ingress should cap the number of cached runs");
|
|
470
|
+
assert.equal(boundedWorkflowRuns[0].agents.length, 32, "workflow ingress should cap agents per run");
|
|
471
|
+
assert.equal(boundedWorkflowRuns[0].agents[0].activityState.length, 80, "workflow ingress should bound activity text");
|
|
472
|
+
assert.equal(boundedWorkflowRuns[0].agents[0].model.length, 240, "workflow ingress should bound model text");
|
|
473
|
+
|
|
474
|
+
const boundedWorkflowRun = boundedWorkflowRuns[0];
|
|
475
|
+
const boundedWorkflowAgent = boundedWorkflowRun.agents[0];
|
|
476
|
+
await helperCommand.handler(JSON.stringify({
|
|
477
|
+
requestId: "bounded-workflow-subagent-output-test",
|
|
478
|
+
action: "subagent-output",
|
|
479
|
+
payload: { runId: boundedWorkflowRun.id, agentId: boundedWorkflowAgent.id },
|
|
480
|
+
}), ctx);
|
|
481
|
+
const boundedWorkflowOutputNotice = notifications.find((entry) => entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")
|
|
482
|
+
&& JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === "bounded-workflow-subagent-output-test");
|
|
483
|
+
assert.ok(boundedWorkflowOutputNotice, "bounded workflow output should return a local helper response");
|
|
484
|
+
const boundedWorkflowOutput = JSON.parse(boundedWorkflowOutputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
485
|
+
assert.equal(boundedWorkflowOutput.data.agent.recentOutput.length, 8, "workflow ingress should cap cached output lines");
|
|
486
|
+
assert.equal(boundedWorkflowOutput.data.agent.recentOutput[0].length, 500, "workflow ingress should cap cached output line length");
|
|
487
|
+
assert.match(boundedWorkflowOutput.data.agent.recentOutput[0], /^line-1:/, "workflow ingress should retain the bounded output tail");
|
|
488
|
+
|
|
489
|
+
bus.emit("firstpick:workflow-subagents:v1", {
|
|
490
|
+
version: 1,
|
|
491
|
+
updatedAt: "2026-07-26T12:02:00.000Z",
|
|
492
|
+
runs: [],
|
|
493
|
+
});
|
|
494
|
+
payload = latestPayload();
|
|
495
|
+
assert.equal(payload.runs.some((run) => run.source === "workflow"), false, "an empty workflow snapshot should clear only workflow rows");
|
|
496
|
+
assert.ok(payload.runs.some((run) => run.id === "run-a") && payload.runs.some((run) => run.id === "run-b"), "workflow cleanup must preserve ordinary async rows");
|
|
497
|
+
|
|
362
498
|
for (const handler of extensionHandlers.get("session_shutdown") || []) await handler({ reason: "quit" }, ctx);
|
|
363
499
|
unsubscribeRpc();
|
|
364
500
|
delete process.env.PI_WEBUI_SETTINGS_FILE;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
9
|
+
const styles = await readFile(join(root, "public", "styles.css"), "utf8");
|
|
10
|
+
|
|
11
|
+
function appFunctionSource(name, nextName) {
|
|
12
|
+
const start = app.indexOf(`function ${name}(`);
|
|
13
|
+
const end = app.indexOf(`\nfunction ${nextName}(`, start);
|
|
14
|
+
assert.ok(start >= 0 && end > start, `${name} should remain a standalone frontend helper`);
|
|
15
|
+
return app.slice(start, end);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function appFunctionToMarker(name, marker) {
|
|
19
|
+
const start = app.indexOf(`function ${name}(`);
|
|
20
|
+
const end = app.indexOf(marker, start);
|
|
21
|
+
assert.ok(start >= 0 && end > start, `${name} should remain extractable for behavioral tests`);
|
|
22
|
+
return app.slice(start, end);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const sources = [
|
|
26
|
+
appFunctionSource("tabGroupTitle", "terminalDisplayGroupTitle"),
|
|
27
|
+
appFunctionSource("normalizeGitWorkspaceInfo", "gitWorkspaceBadgeLabel"),
|
|
28
|
+
appFunctionSource("terminalTabWorkspaceName", "terminalTabMeta"),
|
|
29
|
+
appFunctionSource("terminalTabMeta", "terminalTabGitTooltip"),
|
|
30
|
+
appFunctionSource("terminalTabGitTooltip", "terminalTabActiveTooltip"),
|
|
31
|
+
appFunctionSource("terminalTabActiveTooltip", "terminalTabTooltip"),
|
|
32
|
+
appFunctionSource("terminalTabTooltip", "terminalTabGroupStatusTooltip"),
|
|
33
|
+
appFunctionSource("terminalTabGroupStatusTooltip", "terminalTabGroupWorkspaceTooltip"),
|
|
34
|
+
appFunctionSource("terminalTabGroupWorkspaceTooltip", "terminalTabGroupActiveTooltip"),
|
|
35
|
+
appFunctionSource("terminalTabGroupActiveTooltip", "terminalTabGroupTooltip"),
|
|
36
|
+
appFunctionSource("terminalTabGroupTooltip", "appendTerminalTabContent"),
|
|
37
|
+
appFunctionToMarker("cleanTooltipText", "\n\nconst TOOLTIP_HOVER_DELAY_MS"),
|
|
38
|
+
].join("\n");
|
|
39
|
+
const terminalTabMetaSource = appFunctionSource("terminalTabMeta", "terminalTabGitTooltip");
|
|
40
|
+
const renderTerminalTabGroupSource = appFunctionSource("renderTerminalTabGroup", "updateTerminalTabGroupOpenState");
|
|
41
|
+
|
|
42
|
+
const context = {
|
|
43
|
+
normalizeDisplayPath: (value) => String(value || "").replace(/\\/g, "/"),
|
|
44
|
+
cleanStatusText: (value) => String(value || "").trim(),
|
|
45
|
+
stripAnsi: (value) => String(value || ""),
|
|
46
|
+
tabIndicator: (tab) => ({ state: tab.running ? (tab.state || "idle") : "idle", label: tab.running ? (tab.label || "Idle") : "Stopped" }),
|
|
47
|
+
tabAppRunnerRunningRun: (tab) => tab.appRunner || null,
|
|
48
|
+
terminalAppRunnerLabel: (run) => `app runner: ${run.label}`,
|
|
49
|
+
tabConversationMode: (tab) => tab.conversationMode || { enabled: false },
|
|
50
|
+
tabConversationModeActive: (tab) => tab.conversationMode?.enabled === true,
|
|
51
|
+
tabWorkflowModeActive: (tab) => tab.workflowMode === true,
|
|
52
|
+
workflowRunningCountForTab: (id) => id === "tab-1" ? 2 : 0,
|
|
53
|
+
terminalDisplayGroupTitle: () => "Workspace group",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const results = vm.runInNewContext(`
|
|
57
|
+
${sources}
|
|
58
|
+
const runningTab = {
|
|
59
|
+
id: "tab-1",
|
|
60
|
+
title: "Tooltip work",
|
|
61
|
+
running: true,
|
|
62
|
+
state: "working",
|
|
63
|
+
label: "Working",
|
|
64
|
+
cwd: "/home/user/projects/pi-package-webui",
|
|
65
|
+
gitWorkspace: { worktreePath: "/home/user/projects/pi-package-webui", branch: "feat/readable-tooltip", isMainWorktree: true },
|
|
66
|
+
appRunner: { label: "npm test" },
|
|
67
|
+
conversationMode: { enabled: true, uiState: "listening" },
|
|
68
|
+
workflowMode: true,
|
|
69
|
+
};
|
|
70
|
+
const stoppedTab = { id: "tab-2", title: "Closed tab", running: false, cwd: "/tmp/other/pi-package-webui", pid: 4242, command: "secret-command", sessionFile: "/private/session.jsonl" };
|
|
71
|
+
({
|
|
72
|
+
metadata: terminalTabMeta(runningTab, { meta: "working" }),
|
|
73
|
+
running: cleanTooltipText(terminalTabTooltip(runningTab)),
|
|
74
|
+
stopped: cleanTooltipText(terminalTabTooltip(stoppedTab)),
|
|
75
|
+
group: terminalTabGroupTooltip({ custom: true, tabs: [runningTab, stoppedTab] }, "Tooltip group"),
|
|
76
|
+
});
|
|
77
|
+
`, context);
|
|
78
|
+
|
|
79
|
+
assert.equal(results.metadata, "working · pi-package-webui · app runner · voice · workflow mode · 2 workflows", "compact tab metadata should keep workspace and live-mode context");
|
|
80
|
+
assert.equal(results.running.split("\n").length, 5, "a fully populated workspace tooltip should remain bounded to five lines");
|
|
81
|
+
assert.match(results.running, /^Tooltip work · Working\nWorking folder: \/home\/user\/projects\/pi-package-webui/m, "rendered tooltip should lead with identity/status and the full readable workspace path");
|
|
82
|
+
assert.match(results.running, /Git: feat\/readable-tooltip · main worktree/, "rendered tooltip should show optional branch/worktree context");
|
|
83
|
+
assert.match(results.running, /Active: app runner: npm test · voice: listening · workflow: 2 runs/, "rendered tooltip should summarize active workspace modes");
|
|
84
|
+
assert.equal((results.stopped.match(/Stopped/g) || []).length, 1, "stopped status should appear exactly once");
|
|
85
|
+
assert.match(results.stopped, /Working folder: \/tmp\/other\/pi-package-webui/, "same-basename workspaces should remain distinguishable by full path");
|
|
86
|
+
assert.doesNotMatch(`${results.running}\n${results.stopped}`, /4242|secret-command|session\.jsonl|\bpid\b/i, "tooltips should exclude diagnostic and private session details");
|
|
87
|
+
assert.match(results.group, /^Tooltip group · 2 tabs\nWorkspaces: projects\/pi-package-webui, other\/pi-package-webui\nStatus: 1 working · 1 stopped/m, "group hover summary should distinguish same-basename workspaces and aggregate status");
|
|
88
|
+
assert.match(results.group, /Click to switch · Drop tabs here to add$/, "group hover summary should preserve the drop-target affordance");
|
|
89
|
+
assert.doesNotMatch(terminalTabMetaSource, /\bpid\b/i, "compact tab metadata should not expose the process PID");
|
|
90
|
+
assert.equal(app.match(/applyStyledTooltip\(button, terminalTabTooltip\(tab\)/g)?.length, 2, "single and grouped-item tabs should share one tooltip formatter");
|
|
91
|
+
assert.match(renderTerminalTabGroupSource, /terminal-tab-group-summary[\s\S]*terminalTabGroupTooltip\(group, groupTitle\)[\s\S]*button\.setAttribute\("aria-describedby", summary\.id\)[\s\S]*menu\.append\(summary\)/, "group hover disclosure should expose its non-overlapping summary as an accessible description");
|
|
92
|
+
assert.match(app, /footerTooltipNode\.setAttribute\("role", "tooltip"\)/, "the shared visual tooltip should expose tooltip semantics");
|
|
93
|
+
assert.match(app, /document\.addEventListener\("keydown", \(event\) => \{[\s\S]*event\.key === "Escape" && footerTooltipTarget[\s\S]*hideFooterTooltip\(footerTooltipTarget\)[\s\S]*\}, true\)/, "Escape should dismiss both hover- and focus-triggered tooltips from the document capture phase");
|
|
94
|
+
assert.match(app, /data-tooltip-variant"\) === "workspace" && !node\.matches\(":focus-visible"\)/, "touch focus should not flash the large workspace tooltip while keyboard focus remains supported");
|
|
95
|
+
assert.match(app, /styled-tooltip-description[\s\S]*aria-describedby/, "detailed tab tooltip text should be available as an accessible description");
|
|
96
|
+
assert.match(styles, /footer-floating-tooltip\[data-variant="workspace"\][\s\S]*line-height: 1\.52/, "workspace tooltips should use the readable visual variant");
|
|
97
|
+
assert.match(styles, /terminal-tab-group-summary[\s\S]*white-space: pre-wrap/, "group summaries should preserve the readable multiline hierarchy");
|
|
98
|
+
|
|
99
|
+
console.log("terminal tab workspace static tests passed");
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
groupConsecutiveWorkflowStatusItems,
|
|
7
|
+
isCompletedWorkflowStatusExecution,
|
|
8
|
+
workflowStatusSnapshot,
|
|
9
|
+
} from "../public/workflow-status-stack.mjs";
|
|
10
|
+
|
|
11
|
+
function statusItem(id, status = "running", patch = {}) {
|
|
12
|
+
return {
|
|
13
|
+
messageIndex: Number(id.replace(/\D/g, "")) || 0,
|
|
14
|
+
order: Number(id.replace(/\D/g, "")) || 0,
|
|
15
|
+
message: {
|
|
16
|
+
role: "toolExecution",
|
|
17
|
+
toolName: "workflow_status",
|
|
18
|
+
toolCallId: id,
|
|
19
|
+
timestamp: `2026-07-26T19:00:0${id.at(-1)}Z`,
|
|
20
|
+
arguments: {},
|
|
21
|
+
result: { content: [{ type: "text", text: `Workflow: release\nRun: run-1\nStatus: ${status}\nTasks: 1/3 completed` }] },
|
|
22
|
+
...patch,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
assert.equal(isCompletedWorkflowStatusExecution(statusItem("call-1").message), true, "completed workflow_status executions should be eligible");
|
|
28
|
+
assert.equal(isCompletedWorkflowStatusExecution(statusItem("call-1", "running", { isPartial: true }).message), false, "partial workflow_status executions should remain standalone");
|
|
29
|
+
assert.equal(isCompletedWorkflowStatusExecution(statusItem("call-1", "completed", { live: true }).message), false, "live workflow_status executions should remain standalone until persisted");
|
|
30
|
+
assert.equal(isCompletedWorkflowStatusExecution({ ...statusItem("call-1").message, toolName: "workflow_run" }), false, "other workflow tools should remain standalone");
|
|
31
|
+
|
|
32
|
+
const one = groupConsecutiveWorkflowStatusItems([statusItem("call-1")]);
|
|
33
|
+
assert.equal(one.length, 1, "a single status update should not gain stack chrome");
|
|
34
|
+
assert.equal(one[0].message.role, "toolExecution");
|
|
35
|
+
|
|
36
|
+
const stacked = groupConsecutiveWorkflowStatusItems([statusItem("call-1"), statusItem("call-2", "completed")]);
|
|
37
|
+
assert.equal(stacked.length, 1, "adjacent completed status updates should collapse into one transcript item");
|
|
38
|
+
assert.equal(stacked[0].message.role, "workflowStatusStack");
|
|
39
|
+
assert.equal(stacked[0].message.workflowStatusUpdates.length, 2);
|
|
40
|
+
assert.equal(stacked[0].message.workflowStatusUpdates[0].toolCallId, "call-1", "stack members should remain chronological");
|
|
41
|
+
assert.equal(stacked[0].message.workflowStatusUpdates.at(-1).toolCallId, "call-2", "the latest update should remain last");
|
|
42
|
+
assert.match(stacked[0].transcriptKey, /^workflow-status-stack:call-1$/, "the first tool call should provide a stable stack key");
|
|
43
|
+
const noIdStack = groupConsecutiveWorkflowStatusItems([
|
|
44
|
+
{ ...statusItem("call-1"), messageIndex: 0, message: { ...statusItem("call-1").message, toolCallId: "" } },
|
|
45
|
+
{ ...statusItem("call-2"), messageIndex: 1, message: { ...statusItem("call-2").message, toolCallId: "" } },
|
|
46
|
+
]);
|
|
47
|
+
assert.equal(noIdStack[0].transcriptKey, "workflow-status-stack:m:0", "zero-valued message indices should remain valid collision-resistant fallback keys");
|
|
48
|
+
|
|
49
|
+
const barrier = { messageIndex: 2, order: 2, message: { role: "user", content: "continue" } };
|
|
50
|
+
const separated = groupConsecutiveWorkflowStatusItems([statusItem("call-1"), barrier, statusItem("call-2")]);
|
|
51
|
+
assert.equal(separated.length, 3, "non-status transcript items should break a stack");
|
|
52
|
+
assert.deepEqual(separated.map((item) => item.message.role), ["toolExecution", "user", "toolExecution"]);
|
|
53
|
+
|
|
54
|
+
const withLiveBoundary = groupConsecutiveWorkflowStatusItems([
|
|
55
|
+
statusItem("call-1"),
|
|
56
|
+
statusItem("call-2", "running", { isPartial: true }),
|
|
57
|
+
statusItem("call-3"),
|
|
58
|
+
]);
|
|
59
|
+
assert.equal(withLiveBoundary.length, 3, "a live status update should be a hard stack boundary");
|
|
60
|
+
|
|
61
|
+
const errored = groupConsecutiveWorkflowStatusItems([
|
|
62
|
+
statusItem("call-1"),
|
|
63
|
+
statusItem("call-2", "failed", { isError: true, result: { isError: true, content: [{ type: "text", text: "Status: failed" }] } }),
|
|
64
|
+
]);
|
|
65
|
+
assert.equal(errored[0].message.isError, true, "a member error should mark the aggregate stack");
|
|
66
|
+
|
|
67
|
+
assert.deepEqual(
|
|
68
|
+
workflowStatusSnapshot("Workflow: release\nRun: run-1\nStatus: completed\nTasks: 3/3 completed"),
|
|
69
|
+
{ workflow: "release", run: "run-1", status: "completed", tasks: "3/3 completed", fallback: "Workflow: release" },
|
|
70
|
+
"the latest workflow result should produce a concise structured snapshot",
|
|
71
|
+
);
|
|
72
|
+
assert.equal(workflowStatusSnapshot("No workflow run has been recorded in this session.").fallback, "No workflow run has been recorded in this session.");
|
|
73
|
+
|
|
74
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
75
|
+
const [app, css] = await Promise.all([
|
|
76
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
77
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
78
|
+
]);
|
|
79
|
+
assert.match(app, /function workflowStatusExecutionFromTranscriptItem\(item, toolResults\)[\s\S]*visibleMessages\.length !== 1[\s\S]*toolCall\.toolName !== "workflow_status"[\s\S]*toolResults instanceof Map[\s\S]*toolExecutionMessageFromCall/, "app integration should project only isolated, completed workflow_status calls using the prebuilt result map");
|
|
80
|
+
assert.match(app, /function groupWorkflowStatusTranscriptItems\(items, toolResults\)[\s\S]*compactOutputActive\(\)[\s\S]*groupConsecutiveWorkflowStatusItems\(projected\)/, "compact mode should remain unchanged and normal transcript items should group before reconciliation");
|
|
81
|
+
assert.match(app, /function toolExecutionMessageFromCall\([\s\S]*function appendTranscriptMessage[\s\S]*toolExecutionMessageFromCall\(displayMessage\)/, "normal and stacked transcript paths should share tool-call projection");
|
|
82
|
+
assert.match(app, /function renderWorkflowStatusStack\(parent, message\)[\s\S]*snapshotFields[\s\S]*make\("details", "workflow-status-stack-details"\)[\s\S]*make\("summary", "workflow-status-stack-summary"\)[\s\S]*aria-label[\s\S]*renderSingleToolExecution\(memberBody, update\)/, "the stack should use an accessible native disclosure and retain the normal renderer for every member");
|
|
83
|
+
assert.doesNotMatch(app.match(/function renderWorkflowStatusStack\(parent, message\)[\s\S]*?\n\}/)?.[0] || "", /aria-live/, "historical status stacks should not create repetitive live-region announcements");
|
|
84
|
+
assert.match(css, /\.workflow-status-stack-summary:focus-visible[\s\S]*outline:/, "the stack disclosure should expose keyboard focus");
|
|
85
|
+
assert.match(css, /\.workflow-status-stack-members[\s\S]*max-height:[\s\S]*overflow:\s*auto/, "expanded status history should remain bounded and scrollable");
|
|
86
|
+
|
|
87
|
+
console.log("workflow-status-stack.test.mjs passed");
|
package/webui-rpc-helper.mjs
CHANGED
|
@@ -22,6 +22,19 @@ const SUBAGENT_RPC_READY_EVENT = "subagents:rpc:v1:ready";
|
|
|
22
22
|
const SUBAGENT_RPC_REPLY_PREFIX = "subagents:rpc:v1:reply:";
|
|
23
23
|
const SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started";
|
|
24
24
|
const SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete";
|
|
25
|
+
const WORKFLOW_SUBAGENTS_EVENT = "firstpick:workflow-subagents:v1";
|
|
26
|
+
const WORKFLOW_SUBAGENTS_VERSION = 1;
|
|
27
|
+
const WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS = {
|
|
28
|
+
runs: 32,
|
|
29
|
+
agentsPerRun: 32,
|
|
30
|
+
runIdentifierLength: 160,
|
|
31
|
+
agentIdentifierLength: 240,
|
|
32
|
+
nameLength: 160,
|
|
33
|
+
activityLength: 80,
|
|
34
|
+
modelLength: 240,
|
|
35
|
+
recentOutputLines: 8,
|
|
36
|
+
recentOutputLineLength: 500,
|
|
37
|
+
};
|
|
25
38
|
const SUBAGENT_STATUS_POLL_MS = 1500;
|
|
26
39
|
const SUBAGENT_STATUS_RPC_TIMEOUT_MS = 900;
|
|
27
40
|
const SUBAGENT_OUTPUT_LINE_LIMIT = 120;
|
|
@@ -257,6 +270,76 @@ function subagentOutputLines(value) {
|
|
|
257
270
|
.map((line) => String(line ?? "").replace(/\r/g, "").slice(0, SUBAGENT_OUTPUT_LINE_LENGTH));
|
|
258
271
|
}
|
|
259
272
|
|
|
273
|
+
function workflowSubagentText(value, maxLength) {
|
|
274
|
+
return typeof value === "string" ? value.slice(0, maxLength).replace(/\r/g, "") : "";
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function workflowSubagentIdentifier(value, maxLength) {
|
|
278
|
+
if (typeof value !== "string" || !value.trim() || value.length > maxLength) return "";
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function workflowSubagentTimestamp(value) {
|
|
283
|
+
if (typeof value !== "string" || value.length > 128) return undefined;
|
|
284
|
+
const timestamp = Date.parse(value);
|
|
285
|
+
return Number.isFinite(timestamp) ? timestamp : undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function workflowSubagentRun(value, updatedAt) {
|
|
289
|
+
if (!value || typeof value !== "object" || value.source !== "workflow") return undefined;
|
|
290
|
+
const id = workflowSubagentIdentifier(value.id, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.runIdentifierLength);
|
|
291
|
+
const name = workflowSubagentText(value.name, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.nameLength).trim();
|
|
292
|
+
const startedAt = workflowSubagentTimestamp(value.startedAt);
|
|
293
|
+
if (!id || !name || startedAt === undefined || typeof value.status !== "string") return undefined;
|
|
294
|
+
|
|
295
|
+
const agents = [];
|
|
296
|
+
const agentIds = new Set();
|
|
297
|
+
for (const [fallbackIndex, agent] of (Array.isArray(value.agents) ? value.agents : []).slice(0, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.agentsPerRun).entries()) {
|
|
298
|
+
if (!agent || typeof agent !== "object" || agent.status !== "running") continue;
|
|
299
|
+
const agentId = workflowSubagentIdentifier(agent.id, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.agentIdentifierLength);
|
|
300
|
+
const agentName = workflowSubagentText(agent.name, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.nameLength).trim();
|
|
301
|
+
if (!agentId || !agentName || agentIds.has(agentId)) continue;
|
|
302
|
+
agentIds.add(agentId);
|
|
303
|
+
const recentOutput = (Array.isArray(agent.recentOutput) ? agent.recentOutput : [])
|
|
304
|
+
.slice(-WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.recentOutputLines)
|
|
305
|
+
.flatMap((line) => typeof line === "string"
|
|
306
|
+
? [workflowSubagentText(line, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.recentOutputLineLength)]
|
|
307
|
+
: []);
|
|
308
|
+
agents.push({
|
|
309
|
+
id: agentId,
|
|
310
|
+
name: agentName,
|
|
311
|
+
status: "running",
|
|
312
|
+
index: Number.isInteger(agent.index) && agent.index >= 0 ? agent.index : fallbackIndex,
|
|
313
|
+
activityState: workflowSubagentText(agent.activityState, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.activityLength).trim() || undefined,
|
|
314
|
+
model: workflowSubagentText(agent.model, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.modelLength).trim() || undefined,
|
|
315
|
+
recentOutput,
|
|
316
|
+
nested: false,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
id,
|
|
322
|
+
source: "workflow",
|
|
323
|
+
name,
|
|
324
|
+
mode: agents.length > 1 ? "parallel" : "single",
|
|
325
|
+
status: "running",
|
|
326
|
+
startedAt,
|
|
327
|
+
updatedAt,
|
|
328
|
+
agents,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function workflowSubagentSnapshot(value) {
|
|
333
|
+
if (!value || typeof value !== "object" || value.version !== WORKFLOW_SUBAGENTS_VERSION || !Array.isArray(value.runs)) return undefined;
|
|
334
|
+
const updatedAt = workflowSubagentTimestamp(value.updatedAt) || Date.now();
|
|
335
|
+
const runs = new Map();
|
|
336
|
+
for (const candidate of value.runs.slice(0, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.runs)) {
|
|
337
|
+
const run = workflowSubagentRun(candidate, updatedAt);
|
|
338
|
+
if (run) runs.set(run.id, run);
|
|
339
|
+
}
|
|
340
|
+
return runs;
|
|
341
|
+
}
|
|
342
|
+
|
|
260
343
|
function subagentRecentTools(value) {
|
|
261
344
|
return (Array.isArray(value) ? value : []).slice(-20).map((entry) => ({
|
|
262
345
|
tool: subagentText(entry?.tool, 120),
|
|
@@ -556,10 +639,11 @@ export default function webuiRpcHelper(pi) {
|
|
|
556
639
|
let lastPublishedSubagentSignature = "";
|
|
557
640
|
const asyncSubagentRuns = new Map();
|
|
558
641
|
const foregroundSubagentRuns = new Map();
|
|
642
|
+
const workflowSubagentRuns = new Map();
|
|
559
643
|
const subagentGates = new Map();
|
|
560
644
|
|
|
561
645
|
function publicSubagentRuns() {
|
|
562
|
-
|
|
646
|
+
const ordinaryRuns = [...foregroundSubagentRuns.values(), ...asyncSubagentRuns.values()]
|
|
563
647
|
.map((run) => ({
|
|
564
648
|
id: subagentText(run.id, 160),
|
|
565
649
|
source: run.source === "foreground" ? "foreground" : "async",
|
|
@@ -580,7 +664,28 @@ export default function webuiRpcHelper(pi) {
|
|
|
580
664
|
thinking: subagentThinking(agent.thinking) || subagentThinkingFromModel(agent.model) || undefined,
|
|
581
665
|
nested: agent.nested === true,
|
|
582
666
|
})),
|
|
583
|
-
}))
|
|
667
|
+
}));
|
|
668
|
+
const workflowRuns = [...workflowSubagentRuns.values()]
|
|
669
|
+
.map((run) => ({
|
|
670
|
+
id: run.id,
|
|
671
|
+
source: "workflow",
|
|
672
|
+
name: run.name,
|
|
673
|
+
mode: subagentMode(run.mode),
|
|
674
|
+
status: "running",
|
|
675
|
+
startedAt: run.startedAt,
|
|
676
|
+
agents: run.agents.map((agent) => ({
|
|
677
|
+
id: agent.id,
|
|
678
|
+
name: agent.name,
|
|
679
|
+
status: "running",
|
|
680
|
+
index: agent.index,
|
|
681
|
+
activityState: agent.activityState,
|
|
682
|
+
model: agent.model,
|
|
683
|
+
// Workflow snapshots do not publish thinking metadata, so unknown must remain unknown.
|
|
684
|
+
thinking: undefined,
|
|
685
|
+
nested: false,
|
|
686
|
+
})),
|
|
687
|
+
}));
|
|
688
|
+
return [...ordinaryRuns, ...workflowRuns]
|
|
584
689
|
.filter((run) => run.id && run.agents.length > 0)
|
|
585
690
|
.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id));
|
|
586
691
|
}
|
|
@@ -669,6 +774,39 @@ export default function webuiRpcHelper(pi) {
|
|
|
669
774
|
return { run, agent };
|
|
670
775
|
}
|
|
671
776
|
|
|
777
|
+
function findWorkflowSubagent(runId, agentId) {
|
|
778
|
+
const run = workflowSubagentRuns.get(runId);
|
|
779
|
+
if (!run) return undefined;
|
|
780
|
+
const agent = run.agents.find((candidate) => candidate.id === agentId);
|
|
781
|
+
if (!agent) throw new Error(`Running subagent not found: ${agentId}`);
|
|
782
|
+
return { run, agent };
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function workflowSubagentOutputSnapshot(run, agent) {
|
|
786
|
+
return {
|
|
787
|
+
version: 1,
|
|
788
|
+
runId: run.id,
|
|
789
|
+
source: "workflow",
|
|
790
|
+
mode: subagentMode(run.mode),
|
|
791
|
+
startedAt: run.startedAt,
|
|
792
|
+
updatedAt: run.updatedAt,
|
|
793
|
+
agent: {
|
|
794
|
+
id: agent.id,
|
|
795
|
+
name: agent.name,
|
|
796
|
+
index: agent.index,
|
|
797
|
+
nested: false,
|
|
798
|
+
status: "running",
|
|
799
|
+
activityState: agent.activityState,
|
|
800
|
+
model: agent.model,
|
|
801
|
+
// Workflow snapshots do not carry reasoning data.
|
|
802
|
+
thinking: undefined,
|
|
803
|
+
recentTools: [],
|
|
804
|
+
recentOutput: agent.recentOutput,
|
|
805
|
+
transcript: [],
|
|
806
|
+
},
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
672
810
|
function subagentAsyncDirFromStatusText(text) {
|
|
673
811
|
const match = String(text || "").match(/^Dir:\s+(.+)$/m);
|
|
674
812
|
const value = String(match?.[1] || "").trim();
|
|
@@ -752,6 +890,13 @@ export default function webuiRpcHelper(pi) {
|
|
|
752
890
|
}
|
|
753
891
|
|
|
754
892
|
async function subagentOutputSnapshot(payload = {}) {
|
|
893
|
+
const workflowRunId = workflowSubagentIdentifier(payload.runId, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.runIdentifierLength);
|
|
894
|
+
const workflowAgentId = workflowSubagentIdentifier(payload.agentId, WORKFLOW_SUBAGENT_SNAPSHOT_LIMITS.agentIdentifierLength);
|
|
895
|
+
if (workflowRunId && workflowAgentId) {
|
|
896
|
+
const workflow = findWorkflowSubagent(workflowRunId, workflowAgentId);
|
|
897
|
+
if (workflow) return workflowSubagentOutputSnapshot(workflow.run, workflow.agent);
|
|
898
|
+
}
|
|
899
|
+
|
|
755
900
|
const runId = subagentText(payload.runId, 160);
|
|
756
901
|
const agentId = subagentText(payload.agentId, 240);
|
|
757
902
|
if (!runId || !agentId) throw new Error("Subagent output requires runId and agentId");
|
|
@@ -836,6 +981,17 @@ export default function webuiRpcHelper(pi) {
|
|
|
836
981
|
}
|
|
837
982
|
|
|
838
983
|
const subagentEventUnsubscribers = [
|
|
984
|
+
pi.events.on(WORKFLOW_SUBAGENTS_EVENT, (value) => {
|
|
985
|
+
try {
|
|
986
|
+
const nextRuns = workflowSubagentSnapshot(value);
|
|
987
|
+
if (!nextRuns) return;
|
|
988
|
+
workflowSubagentRuns.clear();
|
|
989
|
+
for (const [id, run] of nextRuns) workflowSubagentRuns.set(id, run);
|
|
990
|
+
publishSubagentStatus();
|
|
991
|
+
} catch {
|
|
992
|
+
// Ignore malformed cross-extension events without disrupting current live rows.
|
|
993
|
+
}
|
|
994
|
+
}),
|
|
839
995
|
pi.events.on(SUBAGENT_RPC_READY_EVENT, () => {
|
|
840
996
|
subagentBridgeAvailable = true;
|
|
841
997
|
publishSubagentStatus();
|
|
@@ -1078,6 +1234,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1078
1234
|
subagentPollGeneration += 1;
|
|
1079
1235
|
foregroundSubagentRuns.clear();
|
|
1080
1236
|
asyncSubagentRuns.clear();
|
|
1237
|
+
workflowSubagentRuns.clear();
|
|
1081
1238
|
subagentGates.clear();
|
|
1082
1239
|
lastPublishedSubagentSignature = "";
|
|
1083
1240
|
publishSubagentStatus();
|
|
@@ -1155,6 +1312,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1155
1312
|
subagentPollTimer = null;
|
|
1156
1313
|
foregroundSubagentRuns.clear();
|
|
1157
1314
|
asyncSubagentRuns.clear();
|
|
1315
|
+
workflowSubagentRuns.clear();
|
|
1158
1316
|
subagentGates.clear();
|
|
1159
1317
|
for (const unsubscribe of subagentEventUnsubscribers) unsubscribe();
|
|
1160
1318
|
});
|