@firstpick/pi-package-webui 0.7.8 → 0.7.9
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/bin/pi-webui.mjs +380 -56
- package/lib/queue-mutation.mjs +109 -0
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +1 -1
- package/public/app.js +1483 -112
- package/public/index.html +87 -0
- package/public/styles.css +592 -73
- package/public/voice-conversation.mjs +1 -1
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/cwd-footer-reliability-static.test.mjs +5 -0
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/fake-pi.mjs +175 -43
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/http-endpoints-harness.test.mjs +160 -1
- package/tests/mobile-static.test.mjs +56 -38
- package/tests/native-parity.test.mjs +1 -1
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +4 -2
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
|
@@ -58,6 +58,66 @@ let dynamicLeafId = "u0000002";
|
|
|
58
58
|
let scriptedStreaming = false;
|
|
59
59
|
let continuityRun = 0;
|
|
60
60
|
let largeTranscriptEnabled = false;
|
|
61
|
+
const fixtureSubagentRuns = [];
|
|
62
|
+
const fixtureSubagentGates = [];
|
|
63
|
+
const runtimeQueue = {
|
|
64
|
+
steering: ["runtime steering"],
|
|
65
|
+
followUp: ["runtime first", "runtime second", "runtime third"],
|
|
66
|
+
steeringMessages: [],
|
|
67
|
+
followUpMessages: [],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function runtimeQueuedMessage(text, timestamp) {
|
|
71
|
+
return {
|
|
72
|
+
role: "user",
|
|
73
|
+
timestamp,
|
|
74
|
+
metadata: { fixture: "runtime-queue" },
|
|
75
|
+
content: [{ type: "text", text }, { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" }],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
runtimeQueue.steeringMessages = runtimeQueue.steering.map((text, index) => runtimeQueuedMessage(text, 100 + index));
|
|
80
|
+
runtimeQueue.followUpMessages = runtimeQueue.followUp.map((text, index) => runtimeQueuedMessage(text, 200 + index));
|
|
81
|
+
|
|
82
|
+
function runtimeQueueSnapshot() {
|
|
83
|
+
return { source: "pi-runtime", steering: [...runtimeQueue.steering], followUp: [...runtimeQueue.followUp] };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sameRuntimeQueue(expected) {
|
|
87
|
+
return Array.isArray(expected?.steering) && Array.isArray(expected?.followUp)
|
|
88
|
+
&& expected.steering.length === runtimeQueue.steering.length
|
|
89
|
+
&& expected.followUp.length === runtimeQueue.followUp.length
|
|
90
|
+
&& expected.steering.every((text, index) => text === runtimeQueue.steering[index])
|
|
91
|
+
&& expected.followUp.every((text, index) => text === runtimeQueue.followUp[index]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function mutateRuntimeQueue(payload = {}) {
|
|
95
|
+
const failed = (reason) => ({ mutated: false, reason, queue: runtimeQueueSnapshot() });
|
|
96
|
+
if (payload.source !== "pi-runtime" || payload.kind !== "followUp" || !sameRuntimeQueue(payload.expected)) return failed("queue-changed");
|
|
97
|
+
const operation = payload.operation;
|
|
98
|
+
if (!operation || typeof operation.expectedText !== "string") return failed("invalid-request");
|
|
99
|
+
if (operation.type === "edit") {
|
|
100
|
+
if (!Number.isInteger(operation.index) || operation.index < 0 || operation.index >= runtimeQueue.followUp.length
|
|
101
|
+
|| runtimeQueue.followUp[operation.index] !== operation.expectedText || typeof operation.text !== "string" || !operation.text.trim()) return failed("invalid-request");
|
|
102
|
+
const message = runtimeQueue.followUpMessages[operation.index];
|
|
103
|
+
const textPartIndex = message.content.findIndex((part) => part?.type === "text");
|
|
104
|
+
if (textPartIndex < 0) return failed("queue-desynchronized");
|
|
105
|
+
runtimeQueue.followUp[operation.index] = operation.text;
|
|
106
|
+
runtimeQueue.followUpMessages[operation.index] = { ...message, content: message.content.map((part, index) => index === textPartIndex ? { ...part, text: operation.text } : part) };
|
|
107
|
+
} else if (operation.type === "move") {
|
|
108
|
+
if (!Number.isInteger(operation.from) || !Number.isInteger(operation.to) || operation.from < 0 || operation.to < 0
|
|
109
|
+
|| operation.from >= runtimeQueue.followUp.length || operation.to >= runtimeQueue.followUp.length || operation.from === operation.to
|
|
110
|
+
|| runtimeQueue.followUp[operation.from] !== operation.expectedText) return failed("invalid-request");
|
|
111
|
+
const [text] = runtimeQueue.followUp.splice(operation.from, 1);
|
|
112
|
+
const [message] = runtimeQueue.followUpMessages.splice(operation.from, 1);
|
|
113
|
+
runtimeQueue.followUp.splice(operation.to, 0, text);
|
|
114
|
+
runtimeQueue.followUpMessages.splice(operation.to, 0, message);
|
|
115
|
+
} else {
|
|
116
|
+
return failed("invalid-request");
|
|
117
|
+
}
|
|
118
|
+
emitEvent({ type: "queue_update", steering: [...runtimeQueue.steering], followUp: [...runtimeQueue.followUp] });
|
|
119
|
+
return { mutated: true, source: "pi-runtime", queue: runtimeQueueSnapshot() };
|
|
120
|
+
}
|
|
61
121
|
|
|
62
122
|
function allSessionEntries() {
|
|
63
123
|
return [...staticEntries, ...dynamicEntries];
|
|
@@ -310,26 +370,35 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
310
370
|
respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
|
|
311
371
|
return true;
|
|
312
372
|
}
|
|
313
|
-
case "
|
|
373
|
+
case "queue-mutate":
|
|
374
|
+
respondHelper({ requestId, ok: true, data: mutateRuntimeQueue(request.payload) });
|
|
375
|
+
return true;
|
|
376
|
+
case "subagent-output": {
|
|
377
|
+
const run = fixtureSubagentRuns.find((candidate) => candidate.id === request.payload?.runId);
|
|
378
|
+
const agent = run?.agents?.find((candidate) => candidate.id === request.payload?.agentId);
|
|
379
|
+
if (!run || !agent) {
|
|
380
|
+
respondHelper({ requestId, ok: false, error: "Subagent output is no longer tracked" });
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
314
383
|
respondHelper({
|
|
315
384
|
requestId,
|
|
316
385
|
ok: true,
|
|
317
386
|
data: {
|
|
318
387
|
version: 1,
|
|
319
|
-
runId:
|
|
320
|
-
source:
|
|
321
|
-
mode:
|
|
322
|
-
startedAt:
|
|
323
|
-
updatedAt: Date.now(),
|
|
388
|
+
runId: run.id,
|
|
389
|
+
source: run.source,
|
|
390
|
+
mode: run.mode,
|
|
391
|
+
startedAt: run.startedAt,
|
|
392
|
+
updatedAt: run.endedAt || Date.now(),
|
|
324
393
|
agent: {
|
|
325
|
-
id:
|
|
326
|
-
name:
|
|
327
|
-
index:
|
|
328
|
-
status:
|
|
394
|
+
id: agent.id,
|
|
395
|
+
name: agent.name,
|
|
396
|
+
index: agent.index,
|
|
397
|
+
status: agent.status,
|
|
329
398
|
currentTool: "read",
|
|
330
399
|
currentToolArgs: "README.md",
|
|
331
|
-
model: "anthropic/claude-opus-4-8:high",
|
|
332
|
-
thinking: "high",
|
|
400
|
+
model: agent.model || "anthropic/claude-opus-4-8:high",
|
|
401
|
+
thinking: agent.thinking || "high",
|
|
333
402
|
recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
|
|
334
403
|
recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
|
|
335
404
|
transcript: [
|
|
@@ -359,6 +428,37 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
359
428
|
},
|
|
360
429
|
});
|
|
361
430
|
return true;
|
|
431
|
+
}
|
|
432
|
+
case "subagent-cancel": {
|
|
433
|
+
const run = fixtureSubagentRuns.find((candidate) => candidate.id === request.payload?.runId);
|
|
434
|
+
if (!run || run.status !== "running") {
|
|
435
|
+
respondHelper({ requestId, ok: false, error: "Subagent run is not running" });
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
const reason = String(request.payload?.reason || "").trim().slice(0, 120) || undefined;
|
|
439
|
+
const note = String(request.payload?.note || "").trim().slice(0, 2000) || undefined;
|
|
440
|
+
run.status = "cancelled";
|
|
441
|
+
run.endedAt = Date.now();
|
|
442
|
+
run.cancelReason = reason;
|
|
443
|
+
run.cancelNote = note;
|
|
444
|
+
run.cancelledBy = "user";
|
|
445
|
+
run.agents = run.agents.map((agent) => ({ ...agent, status: "cancelled" }));
|
|
446
|
+
emitSubagentFixtureStatus();
|
|
447
|
+
respondHelper({ requestId, ok: true, data: { runId: run.id, state: "cancelled", delivery: "context", rpcMethod: "stop" } });
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
case "subagent-dismiss": {
|
|
451
|
+
const index = fixtureSubagentRuns.findIndex((candidate) => candidate.id === request.payload?.runId);
|
|
452
|
+
const run = fixtureSubagentRuns[index];
|
|
453
|
+
if (!run || run.status === "running") {
|
|
454
|
+
respondHelper({ requestId, ok: false, error: "Subagent run cannot be dismissed" });
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
fixtureSubagentRuns.splice(index, 1);
|
|
458
|
+
emitSubagentFixtureStatus();
|
|
459
|
+
respondHelper({ requestId, ok: true, data: { runId: request.payload?.runId, dismissed: true } });
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
362
462
|
default:
|
|
363
463
|
respondHelper({ requestId, ok: false, error: `Unknown webui-helper action: ${String(request.action || "")}` });
|
|
364
464
|
return true;
|
|
@@ -460,43 +560,75 @@ function handleTransportFixturePrompt(command, base) {
|
|
|
460
560
|
return false;
|
|
461
561
|
}
|
|
462
562
|
|
|
463
|
-
function
|
|
464
|
-
const message = String(command.message || "").trim();
|
|
465
|
-
if (message !== "fixture subagents running" && message !== "fixture subagents clear") return false;
|
|
466
|
-
const clearing = message.endsWith("clear");
|
|
467
|
-
const runs = clearing ? [] : [{
|
|
468
|
-
id: "fixture-run",
|
|
469
|
-
source: "async",
|
|
470
|
-
mode: "parallel",
|
|
471
|
-
status: "running",
|
|
472
|
-
startedAt: Date.now() - 2500,
|
|
473
|
-
agents: [
|
|
474
|
-
{ id: "fixture-run:0", name: "reviewer", status: "running", index: 0, currentTool: "read", model: "anthropic/claude-opus-4-8:high", thinking: "high", nested: false },
|
|
475
|
-
{ id: "fixture-run:1", name: "scout", status: "running", index: 1, model: "openai-codex/gpt-5.6-sol", thinking: "high", nested: false },
|
|
476
|
-
],
|
|
477
|
-
}];
|
|
478
|
-
const gates = clearing ? [] : [{
|
|
479
|
-
version: 1,
|
|
480
|
-
id: "fixture-gate",
|
|
481
|
-
status: "running",
|
|
482
|
-
requiredSuccesses: 2,
|
|
483
|
-
qualifyingSuccesses: 1,
|
|
484
|
-
requireDistinctProviders: true,
|
|
485
|
-
startedAt: Date.now() - 3000,
|
|
486
|
-
updatedAt: Date.now(),
|
|
487
|
-
attempts: [
|
|
488
|
-
{ id: "fixture-gate:0:1", taskIndex: 0, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-1", model: "anthropic/claude-opus-4-8", provider: "anthropic", status: "succeeded" },
|
|
489
|
-
{ id: "fixture-gate:1:1", taskIndex: 1, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-2", model: "openrouter/moonshotai/kimi-k3", provider: "openrouter", status: "failed", failureKind: "transient-provider", error: "provider overloaded" },
|
|
490
|
-
],
|
|
491
|
-
}];
|
|
492
|
-
respond({ ...base, data: { output: "fake subagent status emitted" } });
|
|
563
|
+
function emitSubagentFixtureStatus() {
|
|
493
564
|
emitEvent({
|
|
494
565
|
type: "extension_ui_request",
|
|
495
566
|
id: randomUUID(),
|
|
496
567
|
method: "setStatus",
|
|
497
568
|
statusKey: "webui-subagents",
|
|
498
|
-
statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs, gates })}`,
|
|
569
|
+
statusText: `PI_WEBUI_SUBAGENTS_V1 ${JSON.stringify({ version: 1, available: true, updatedAt: Date.now(), runs: fixtureSubagentRuns, gates: fixtureSubagentGates })}`,
|
|
499
570
|
});
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function handleSubagentFixturePrompt(command, base) {
|
|
574
|
+
const message = String(command.message || "").trim();
|
|
575
|
+
if (!["fixture subagents running", "fixture subagents clear", "fixture subagents retained"].includes(message)) return false;
|
|
576
|
+
const now = Date.now();
|
|
577
|
+
fixtureSubagentRuns.splice(0, fixtureSubagentRuns.length);
|
|
578
|
+
fixtureSubagentGates.splice(0, fixtureSubagentGates.length);
|
|
579
|
+
if (message === "fixture subagents running") {
|
|
580
|
+
fixtureSubagentRuns.push({
|
|
581
|
+
id: "fixture-run",
|
|
582
|
+
source: "async",
|
|
583
|
+
mode: "parallel",
|
|
584
|
+
status: "running",
|
|
585
|
+
startedAt: now - 2500,
|
|
586
|
+
agents: [
|
|
587
|
+
{ id: "fixture-run:0", name: "reviewer", status: "running", index: 0, currentTool: "read", model: "anthropic/claude-opus-4-8:high", thinking: "high", nested: false },
|
|
588
|
+
{ id: "fixture-run:1", name: "scout", status: "running", index: 1, model: "openai-codex/gpt-5.6-sol", thinking: "high", nested: false },
|
|
589
|
+
],
|
|
590
|
+
});
|
|
591
|
+
fixtureSubagentGates.push({
|
|
592
|
+
version: 1,
|
|
593
|
+
id: "fixture-gate",
|
|
594
|
+
status: "running",
|
|
595
|
+
requiredSuccesses: 2,
|
|
596
|
+
qualifyingSuccesses: 1,
|
|
597
|
+
requireDistinctProviders: true,
|
|
598
|
+
startedAt: now - 3000,
|
|
599
|
+
updatedAt: now,
|
|
600
|
+
attempts: [
|
|
601
|
+
{ id: "fixture-gate:0:1", taskIndex: 0, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-1", model: "anthropic/claude-opus-4-8", provider: "anthropic", status: "succeeded" },
|
|
602
|
+
{ id: "fixture-gate:1:1", taskIndex: 1, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "fixture-review-2", model: "openrouter/moonshotai/kimi-k3", provider: "openrouter", status: "failed", failureKind: "transient-provider", error: "provider overloaded" },
|
|
603
|
+
],
|
|
604
|
+
});
|
|
605
|
+
} else if (message === "fixture subagents retained") {
|
|
606
|
+
fixtureSubagentRuns.push(
|
|
607
|
+
{
|
|
608
|
+
id: "fixture-done",
|
|
609
|
+
source: "foreground",
|
|
610
|
+
mode: "single",
|
|
611
|
+
status: "done",
|
|
612
|
+
startedAt: now - 5000,
|
|
613
|
+
endedAt: now - 2000,
|
|
614
|
+
agents: [{ id: "fixture-done:0", name: "tester", status: "done", index: 0, model: "openai-codex/gpt-5.6-sol", thinking: "high", nested: false }],
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
id: "fixture-cancelled",
|
|
618
|
+
source: "async",
|
|
619
|
+
mode: "parallel",
|
|
620
|
+
status: "cancelled",
|
|
621
|
+
startedAt: now - 4000,
|
|
622
|
+
endedAt: now - 1000,
|
|
623
|
+
cancelledBy: "user",
|
|
624
|
+
cancelReason: "Taking too long",
|
|
625
|
+
cancelNote: "Use the existing result instead.",
|
|
626
|
+
agents: [{ id: "fixture-cancelled:0", name: "reviewer", status: "cancelled", index: 0, model: "anthropic/claude-opus-4-8:high", thinking: "high", nested: false }],
|
|
627
|
+
},
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
respond({ ...base, data: { output: "fake subagent status emitted" } });
|
|
631
|
+
emitSubagentFixtureStatus();
|
|
500
632
|
return true;
|
|
501
633
|
}
|
|
502
634
|
|
|
@@ -31,8 +31,11 @@ const combinedSyntaxSource = sourceBetween("function gitFileDiffUsesCombinedSynt
|
|
|
31
31
|
const snapshotSource = sourceBetween("async function loadGitFileChangesSnapshot(", "\nfunction gitFileChangesPlaceholder(", "loadGitFileChangesSnapshot");
|
|
32
32
|
const applySnapshotSource = sourceBetween("function gitFileChangesPlaceholder(", "\nasync function openFileInViewer(", "gitFileChangesPlaceholder");
|
|
33
33
|
const openFileSource = sourceBetween("async function openFileInViewer(", "\nasync function openAurReviewReportInViewer(", "openFileInViewer");
|
|
34
|
-
const
|
|
34
|
+
const viewerPersistenceSource = sourceBetween("function cacheActiveFileViewerForTab(", "\n// Side-panel Git categories are UI labels", "file viewer tab persistence");
|
|
35
35
|
const moveSource = sourceBetween("function updateActiveFileViewerAfterMove(", "\nfunction closeActiveFileViewerIfDeleted(", "updateActiveFileViewerAfterMove");
|
|
36
|
+
const resetActiveTabUiSource = sourceBetween("function resetActiveTabUi(", "\nfunction tabGroupStatusRank(", "resetActiveTabUi");
|
|
37
|
+
const switchTabSource = sourceBetween("async function switchTab(", "\nfunction currentDirectoryForNewTab(", "switchTab");
|
|
38
|
+
const closeTabsSource = sourceBetween("async function closeTerminalTabs(", "\nasync function closeTerminalTab(", "closeTerminalTabs");
|
|
36
39
|
|
|
37
40
|
const targets = JSON.parse(vm.runInNewContext(`${normalizePathSource}\n${targetSource}\nJSON.stringify([
|
|
38
41
|
gitFileViewerTarget("sub/active.js", "/repo", [{ tabId: "repo-tab", cwd: "/repo" }]),
|
|
@@ -152,8 +155,8 @@ assert.match(app, /let fileViewerGitChangesRequestSerial = 0;/, "Git changes ope
|
|
|
152
155
|
assert.match(applySnapshotSource, /loading: true, requestSerial/, "the viewer should show an identified loading snapshot until the bounded diff arrives");
|
|
153
156
|
assert.match(
|
|
154
157
|
applySnapshotSource,
|
|
155
|
-
/
|
|
156
|
-
"a late diff response should
|
|
158
|
+
/const viewer = tabContext\.tabId === activeTabId \? activeFileViewer : fileViewersByTab\.get\(tabContext\.tabId\);\s*if \(!viewer\?\.gitChanges\?\.loading \|\| viewer\.path !== viewerPath \|\| viewer\.gitChanges\.requestSerial !== requestSerial\) return;/,
|
|
159
|
+
"a late diff response should update the owning terminal's cached viewer while still rejecting stale viewer identities",
|
|
157
160
|
);
|
|
158
161
|
|
|
159
162
|
// --- Open flow: Git default, normal-open isolation, deleted files ---
|
|
@@ -180,10 +183,22 @@ assert.match(
|
|
|
180
183
|
assert.match(openFileSource, /mode: "changes",\s*dirty: false,\s*readOnly: true,\s*sourceAvailable: false,/, "a deleted tracked file should open read-only in Changes mode");
|
|
181
184
|
assert.match(openFileSource, /setFileViewerStatus\("File content unavailable; showing Git changes \(read-only\)\.", "warn"\)/, "the deleted-file fallback should explain itself in the viewer status");
|
|
182
185
|
assert.match(openFileSource, /setFileViewerStatus\(message, "error"\);\s*addEvent\(`file open failed: \$\{message\}`, "error"\);/, "a total failure should still report the original open error");
|
|
183
|
-
assert.match(
|
|
184
|
-
assert.match(
|
|
186
|
+
assert.match(viewerPersistenceSource, /function resetFileViewerUi\(\) \{\s*fileViewerOpenRequestSerial \+= 1;\s*activeFileViewer = null;/, "resetting the visible viewer should invalidate pending source and deleted-file opens");
|
|
187
|
+
assert.match(viewerPersistenceSource, /elements\.fileViewerChanges\.hidden = true;\s*elements\.fileViewerChanges\.replaceChildren\(\);/, "resetting the visible viewer should clear the changes surface");
|
|
185
188
|
assert.match(moveSource, /gitChanges: null,/, "renaming the open file should drop its stale open-time diff snapshot");
|
|
186
189
|
|
|
190
|
+
// --- Per-terminal viewer persistence ---
|
|
191
|
+
|
|
192
|
+
assert.match(app, /let fileViewersByTab = new Map\(\);/, "open file viewers should be stored per terminal tab");
|
|
193
|
+
assert.match(app, /let fileViewerSelectionsByTab = new Map\(\);/, "viewer selections should be stored with their owning terminal tab");
|
|
194
|
+
assert.match(viewerPersistenceSource, /fileViewersByTab\.set\(tabId, activeFileViewer\)/, "caching a terminal should retain its active viewer object, including dirty edits and mode");
|
|
195
|
+
assert.match(viewerPersistenceSource, /fileViewerSelectionsByTab\.set\(tabId, fileViewerSelection\)/, "caching a terminal should retain its active file selection");
|
|
196
|
+
assert.match(viewerPersistenceSource, /activeFileViewer = activeTabId \? fileViewersByTab\.get\(activeTabId\) \|\| null : null;\s*fileViewerSelection = activeTabId \? fileViewerSelectionsByTab\.get\(activeTabId\) \|\| null : null;\s*updateFileViewerUi\(\);/, "activating a terminal should restore its own viewer and selection");
|
|
197
|
+
assert.match(viewerPersistenceSource, /function closeFileViewer\(\) \{\s*if \(activeTabId\) \{\s*fileViewersByTab\.delete\(activeTabId\);\s*fileViewerSelectionsByTab\.delete\(activeTabId\);/, "explicitly closing a viewer should remove only the active terminal's cached state");
|
|
198
|
+
assert.match(switchTabSource, /cacheActiveFileViewerForTab\(activeTabId\);\s*const tabContext = setActiveTabId\(tabId, \{ remember: true \}\);/, "switching terminals should cache the outgoing viewer before changing the active tab identity");
|
|
199
|
+
assert.match(resetActiveTabUiSource, /resetFileViewerUi\(\);\s*resetFileTreeState\(\);\s*restoreFileViewerForActiveTab\(\);/, "resetting tab UI should restore the incoming terminal's viewer instead of closing it");
|
|
200
|
+
assert.match(closeTabsSource, /fileViewersByTab\.delete\(id\);\s*fileViewerSelectionsByTab\.delete\(id\);/, "closing terminal tabs should discard their cached viewers and selections");
|
|
201
|
+
|
|
187
202
|
// --- Changes rendering contracts ---
|
|
188
203
|
|
|
189
204
|
const combined = JSON.parse(vm.runInNewContext(`${combinedSyntaxSource}\nJSON.stringify([
|
|
@@ -391,6 +391,63 @@ try {
|
|
|
391
391
|
const tabId = tabList[0].id;
|
|
392
392
|
assert.ok(tabId, "tab should have an id");
|
|
393
393
|
|
|
394
|
+
const runtimeQueueBefore = { steering: ["runtime steering"], followUp: ["runtime first", "runtime second", "runtime third"] };
|
|
395
|
+
const runtimeQueueEdit = await waitForSseEvent(
|
|
396
|
+
tabId,
|
|
397
|
+
(event) => event.type === "queue_update" && event.source === "pi-runtime" && event.followUp?.[0] === "runtime edited",
|
|
398
|
+
() => request("127.0.0.1", "/api/queue/mutate", {
|
|
399
|
+
method: "POST",
|
|
400
|
+
body: {
|
|
401
|
+
tab: tabId,
|
|
402
|
+
source: "pi-runtime",
|
|
403
|
+
kind: "followUp",
|
|
404
|
+
expected: runtimeQueueBefore,
|
|
405
|
+
operation: { type: "edit", index: 0, expectedText: "runtime first", text: " runtime edited " },
|
|
406
|
+
},
|
|
407
|
+
}),
|
|
408
|
+
);
|
|
409
|
+
assert.equal(runtimeQueueEdit.triggerResult.status, 200, `runtime queue edit should succeed: ${runtimeQueueEdit.triggerResult.body?.error || ""}`);
|
|
410
|
+
assert.deepEqual(runtimeQueueEdit.triggerResult.body?.data, {
|
|
411
|
+
mutated: true,
|
|
412
|
+
source: "pi-runtime",
|
|
413
|
+
queue: { source: "pi-runtime", steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
|
|
414
|
+
}, "queue mutation should return the authoritative normalized runtime snapshot");
|
|
415
|
+
assert.equal(runtimeQueueEdit.event.source, "pi-runtime", "runtime queue events must retain their source");
|
|
416
|
+
|
|
417
|
+
const staleRuntimeQueueEdit = await request("127.0.0.1", "/api/queue/mutate", {
|
|
418
|
+
method: "POST",
|
|
419
|
+
body: {
|
|
420
|
+
tab: tabId,
|
|
421
|
+
source: "pi-runtime",
|
|
422
|
+
kind: "followUp",
|
|
423
|
+
expected: runtimeQueueBefore,
|
|
424
|
+
operation: { type: "move", from: 0, to: 2, expectedText: "runtime first" },
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
assert.equal(staleRuntimeQueueEdit.status, 409, "stale runtime queue snapshots must conflict");
|
|
428
|
+
assert.equal(staleRuntimeQueueEdit.body?.ok, false);
|
|
429
|
+
assert.equal(staleRuntimeQueueEdit.body?.data?.reason, "queue-changed");
|
|
430
|
+
assert.deepEqual(staleRuntimeQueueEdit.body?.data?.queue?.followUp, ["runtime edited", "runtime second", "runtime third"], "conflicts return the authoritative runtime queue");
|
|
431
|
+
|
|
432
|
+
const runtimeQueueMove = await request("127.0.0.1", "/api/queue/mutate", {
|
|
433
|
+
method: "POST",
|
|
434
|
+
body: {
|
|
435
|
+
tab: tabId,
|
|
436
|
+
source: "pi-runtime",
|
|
437
|
+
kind: "followUp",
|
|
438
|
+
expected: { steering: ["runtime steering"], followUp: ["runtime edited", "runtime second", "runtime third"] },
|
|
439
|
+
operation: { type: "move", from: 0, to: 2, expectedText: "runtime edited" },
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
assert.equal(runtimeQueueMove.status, 200, "runtime queue moves should use final zero-based indices");
|
|
443
|
+
assert.deepEqual(runtimeQueueMove.body?.data?.queue?.followUp, ["runtime second", "runtime third", "runtime edited"]);
|
|
444
|
+
|
|
445
|
+
const invalidRuntimeQueueMutation = await request("127.0.0.1", "/api/queue/mutate", {
|
|
446
|
+
method: "POST",
|
|
447
|
+
body: { tab: tabId, source: "pi-runtime", kind: "steering", expected: { steering: [], followUp: [] }, operation: { type: "edit", index: 0, expectedText: "x", text: "y" } },
|
|
448
|
+
});
|
|
449
|
+
assert.equal(invalidRuntimeQueueMutation.status, 400, "queue mutation must stay follow-up-only and reject malformed source contracts");
|
|
450
|
+
|
|
394
451
|
const extensionResponseId = `fixture-extension-response-${Date.now()}`;
|
|
395
452
|
const extensionResponseStartedAt = Date.now();
|
|
396
453
|
const extensionResponse = await request("127.0.0.1", "/api/extension-ui-response", {
|
|
@@ -626,6 +683,10 @@ try {
|
|
|
626
683
|
}
|
|
627
684
|
assert.equal(subagentsResponse?.status, 200, "subagent overview endpoint should respond");
|
|
628
685
|
assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "subagent overview should count all running agents");
|
|
686
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 1, "subagent overview should expose running run counts separately from retained totals");
|
|
687
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 2, "subagent overview should expose running agent counts separately from retained totals");
|
|
688
|
+
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningRuns, 1);
|
|
689
|
+
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runningAgents, 2);
|
|
629
690
|
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.tabId, tabId, "subagent overview should group agents under their terminal tab");
|
|
630
691
|
assert.equal(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.source, "async", "ordinary async overview rows should retain their source");
|
|
631
692
|
assert.deepEqual(subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.agents?.map((agent) => agent.name), ["reviewer", "scout"], "subagent overview should preserve agent order within the session run");
|
|
@@ -662,6 +723,104 @@ try {
|
|
|
662
723
|
], "subagent output endpoint should preserve normalized structured transcript roles, order, IDs, and tool metadata");
|
|
663
724
|
const unknownSubagentOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=missing&agent=missing`);
|
|
664
725
|
assert.equal(unknownSubagentOutput.status, 404, "subagent output endpoint should reject untracked selections");
|
|
726
|
+
|
|
727
|
+
const dismissRunningSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
|
|
728
|
+
method: "POST",
|
|
729
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
730
|
+
});
|
|
731
|
+
assert.equal(dismissRunningSubagent.status, 400, "dismiss endpoint should reject running runs through the helper");
|
|
732
|
+
const cancelUnknownSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
733
|
+
method: "POST",
|
|
734
|
+
body: { tab: tabId, runId: "missing" },
|
|
735
|
+
});
|
|
736
|
+
assert.equal(cancelUnknownSubagent.status, 400, "cancel endpoint should return helper errors for unknown runs");
|
|
737
|
+
|
|
738
|
+
const cancelledSubagent = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
739
|
+
method: "POST",
|
|
740
|
+
body: { tab: tabId, runId: "fixture-run", reason: "Taking too long", note: "Use the existing result instead." },
|
|
741
|
+
});
|
|
742
|
+
assert.equal(cancelledSubagent.status, 200, `cancel endpoint should relay helper cancellation: ${cancelledSubagent.body?.error || ""}`);
|
|
743
|
+
assert.deepEqual(cancelledSubagent.body?.data, {
|
|
744
|
+
runId: "fixture-run",
|
|
745
|
+
state: "cancelled",
|
|
746
|
+
delivery: "context",
|
|
747
|
+
rpcMethod: "stop",
|
|
748
|
+
}, "cancel endpoint should preserve the helper cancellation response contract");
|
|
749
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
750
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
751
|
+
if (subagentsResponse.body?.data?.tabs?.[0]?.runs?.[0]?.status === "cancelled") break;
|
|
752
|
+
await delay(50);
|
|
753
|
+
}
|
|
754
|
+
const cancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-run");
|
|
755
|
+
assert.deepEqual(cancelledRun && {
|
|
756
|
+
status: cancelledRun.status,
|
|
757
|
+
endedAt: typeof cancelledRun.endedAt,
|
|
758
|
+
cancelledBy: cancelledRun.cancelledBy,
|
|
759
|
+
cancelReason: cancelledRun.cancelReason,
|
|
760
|
+
cancelNote: cancelledRun.cancelNote,
|
|
761
|
+
agentStatuses: cancelledRun.agents.map((agent) => agent.status),
|
|
762
|
+
}, {
|
|
763
|
+
status: "cancelled",
|
|
764
|
+
endedAt: "number",
|
|
765
|
+
cancelledBy: "user",
|
|
766
|
+
cancelReason: "Taking too long",
|
|
767
|
+
cancelNote: "Use the existing result instead.",
|
|
768
|
+
agentStatuses: ["cancelled", "cancelled"],
|
|
769
|
+
}, "subagent normalization should retain cancelled run and agent metadata");
|
|
770
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 1, "retained runs should remain included in total counts");
|
|
771
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 0, "retained cancelled runs should not count as running");
|
|
772
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 0, "retained cancelled agents should not count as running");
|
|
773
|
+
const retainedCancelledOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-run&agent=fixture-run%3A0`);
|
|
774
|
+
assert.equal(retainedCancelledOutput.status, 200, "subagent output should remain accessible for retained cancelled runs");
|
|
775
|
+
assert.equal(retainedCancelledOutput.body?.data?.agent?.status, "cancelled");
|
|
776
|
+
const duplicateCancel = await request("127.0.0.1", "/api/subagents/cancel", {
|
|
777
|
+
method: "POST",
|
|
778
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
779
|
+
});
|
|
780
|
+
assert.equal(duplicateCancel.status, 400, "cancel endpoint should reject an already-finished run");
|
|
781
|
+
|
|
782
|
+
const dismissedSubagent = await request("127.0.0.1", "/api/subagents/dismiss", {
|
|
783
|
+
method: "POST",
|
|
784
|
+
body: { tab: tabId, runId: "fixture-run" },
|
|
785
|
+
});
|
|
786
|
+
assert.equal(dismissedSubagent.status, 200, `dismiss endpoint should relay helper dismissal: ${dismissedSubagent.body?.error || ""}`);
|
|
787
|
+
assert.deepEqual(dismissedSubagent.body?.data, { runId: "fixture-run", dismissed: true });
|
|
788
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
789
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 0, "dismissed runs should be removed from the overview");
|
|
790
|
+
|
|
791
|
+
const retainedFixture = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents retained" } });
|
|
792
|
+
assert.equal(retainedFixture.status, 200, "retained subagent fixture should be accepted");
|
|
793
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
794
|
+
subagentsResponse = await request("127.0.0.1", "/api/subagents");
|
|
795
|
+
if (subagentsResponse.body?.data?.totalRuns === 2) break;
|
|
796
|
+
await delay(50);
|
|
797
|
+
}
|
|
798
|
+
assert.equal(subagentsResponse.body?.data?.totalRuns, 2, "finished runs should survive payload normalization");
|
|
799
|
+
assert.equal(subagentsResponse.body?.data?.totalAgents, 2, "finished agents should remain represented in retained totals");
|
|
800
|
+
assert.equal(subagentsResponse.body?.data?.runningRuns, 0);
|
|
801
|
+
assert.equal(subagentsResponse.body?.data?.runningAgents, 0);
|
|
802
|
+
const normalizedDoneRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-done");
|
|
803
|
+
const normalizedCancelledRun = subagentsResponse.body?.data?.tabs?.[0]?.runs?.find((run) => run.id === "fixture-cancelled");
|
|
804
|
+
assert.deepEqual(normalizedDoneRun && { status: normalizedDoneRun.status, endedAt: typeof normalizedDoneRun.endedAt, agentStatus: normalizedDoneRun.agents[0]?.status }, {
|
|
805
|
+
status: "done", endedAt: "number", agentStatus: "done",
|
|
806
|
+
}, "normalization should retain completed run state and final agent status");
|
|
807
|
+
assert.deepEqual(normalizedCancelledRun && {
|
|
808
|
+
status: normalizedCancelledRun.status,
|
|
809
|
+
cancelledBy: normalizedCancelledRun.cancelledBy,
|
|
810
|
+
cancelReason: normalizedCancelledRun.cancelReason,
|
|
811
|
+
cancelNote: normalizedCancelledRun.cancelNote,
|
|
812
|
+
agentStatus: normalizedCancelledRun.agents[0]?.status,
|
|
813
|
+
}, {
|
|
814
|
+
status: "cancelled",
|
|
815
|
+
cancelledBy: "user",
|
|
816
|
+
cancelReason: "Taking too long",
|
|
817
|
+
cancelNote: "Use the existing result instead.",
|
|
818
|
+
agentStatus: "cancelled",
|
|
819
|
+
}, "normalization should retain bounded user cancellation metadata");
|
|
820
|
+
const retainedDoneOutput = await request("127.0.0.1", `/api/subagents/output?tab=${encodeURIComponent(tabId)}&run=fixture-done&agent=fixture-done%3A0`);
|
|
821
|
+
assert.equal(retainedDoneOutput.status, 200, "subagent output should remain accessible for retained completed runs");
|
|
822
|
+
assert.equal(retainedDoneOutput.body?.data?.agent?.status, "done");
|
|
823
|
+
|
|
665
824
|
const subagentFixtureClear = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture subagents clear" } });
|
|
666
825
|
assert.equal(subagentFixtureClear.status, 200, "subagent fixture clear should be accepted");
|
|
667
826
|
for (let attempt = 0; attempt < 20; attempt++) {
|
|
@@ -669,7 +828,7 @@ try {
|
|
|
669
828
|
if (subagentsResponse.body?.data?.totalAgents === 0) break;
|
|
670
829
|
await delay(50);
|
|
671
830
|
}
|
|
672
|
-
assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "
|
|
831
|
+
assert.equal(subagentsResponse.body?.data?.totalAgents, 0, "an empty helper snapshot should clear retained subagent rows");
|
|
673
832
|
assert.equal(subagentsResponse.body?.data?.totalGates, 0, "cleared retry gates should disappear from the overview");
|
|
674
833
|
|
|
675
834
|
const state = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(tabId)}`);
|