@firstpick/pi-package-webui 0.7.1 → 0.7.2

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.
@@ -107,12 +107,49 @@ assert.match(html, /id="pathPickerSearchInput"[^>]*type="search"[^>]*placeholder
107
107
  assert.match(html, /id="pathPickerClearSearchButton"[^>]*hidden[^>]*>Clear<\/button>/, "cwd picker should expose a clear-search action");
108
108
  assert.match(app, /function fileTreeGitStatusForEntry\(entry = \{\}\) \{\s+return fileTreeState\.gitStatusByPath\.get\(normalizeFileTreePath\(entry\.path \|\| ""\)\) \|\| null;\s+\}/, "file tree rendering should use the refreshed Git-status snapshot instead of stale status embedded in cached entries");
109
109
  assert.match(app, /confirmLabel: activeAgentTabs\.length \? "Close and stop work" : count === 1 \? "Close tab" : "Close tabs"/, "single-tab confirmation should use singular close wording");
110
+ assert.match(html, /data-side-panel-section="git"[\s\S]*class="side-panel-section-label">Git<[\s\S]*id="gitPanelCountBadge"[\s\S]*id="gitPanelGroups"[\s\S]*aria-label="Git repositories"[\s\S]*id="gitPanelContextMenu"[\s\S]*role="menu"/, "side panel should expose a collapsed, globally deduplicated Git repository list with a count and dedicated action menu");
111
+ assert.match(app, /const GIT_PANEL_CACHE_MAX_AGE_MS = 5 \* 60 \* 1000/, "Git panel should use the approved five-minute page-local freshness window");
112
+ assert.match(app, /function gitPanelTerminalGroups\(\)[\s\S]*tabCwdGroups\(\)[\s\S]*shouldRenderTerminalTabGroup[\s\S]*key: `tab:\$\{tab\.id\}`[\s\S]*title: tabGroupTitle\(tab\.cwd, "Working directory"\)/, "Git panel discovery should mirror visible terminal groups while cwd—not session title—defines ungrouped labels");
113
+ assert.match(app, /function gitPanelCandidates\(groups = gitPanelTerminalGroups\(\)\)[\s\S]*const byCwd = new Map\(\)[\s\S]*key: `cwd:\$\{cwd\}`/, "Git panel discovery should deduplicate repeated cwd candidates globally across terminal groups");
114
+ assert.match(app, /function gitPanelRepositoryCards\(groups = gitPanelTerminalGroups\(\)\)[\s\S]*const identity = root \? `root:\$\{root\}` : candidate\.key[\s\S]*byIdentity/, "Git panel cards should deduplicate discovered repositories globally by canonical Git root");
115
+ assert.match(app, /const cards = gitPanelRepositoryCards\(groups\)/, "Git panel rendering should consume the globally deduplicated repository card list");
116
+ const gitPanelCandidatesSource = appFunctionSource("gitPanelCandidates", "gitPanelRepositoryCards");
117
+ const gitPanelRepositoryCardsSource = appFunctionSource("gitPanelRepositoryCards", "gitPanelRootLabel");
118
+ const gitPanelDeduplication = JSON.parse(vm.runInNewContext(`${gitPanelCandidatesSource}\n${gitPanelRepositoryCardsSource}\nJSON.stringify((() => {\n const groups = [\n { key: "group-a", tabs: [{ id: "tab-1", cwd: "/repo" }, { id: "tab-2", cwd: "/repo" }] },\n { key: "group-b", tabs: [{ id: "tab-3", cwd: "/repo" }, { id: "tab-4", cwd: "/repo/subdir" }] },\n ];\n gitPanelState.discovery.set("cwd:/repo", { root: "/repo", resolved: true });\n gitPanelState.discovery.set("cwd:/repo/subdir", { root: "/repo", resolved: true });\n return { candidates: gitPanelCandidates(groups), cards: gitPanelRepositoryCards(groups) };\n})())`, {
119
+ gitPanelState: { discovery: new Map() },
120
+ gitPanelTerminalGroups: () => [],
121
+ tabGroupTitle: (cwd) => cwd.split("/").filter(Boolean).pop() || "Working directory",
122
+ }));
123
+ assert.equal(gitPanelDeduplication.candidates.length, 2, "repeated cwd tabs across terminal groups should create one discovery candidate per cwd");
124
+ assert.equal(gitPanelDeduplication.cards.length, 1, "different cwd candidates in the same canonical repository should render one card globally");
125
+ assert.equal(gitPanelDeduplication.cards[0].key, "root:/repo", "the global repository card key should be based only on the canonical Git root");
126
+ assert.match(app, /function toggleGitPanelRepository\(card\)[\s\S]*gitPanelState\.expandedCardKey === card\.key[\s\S]*gitPanelState\.expandedCardKey = card\.key/, "only one Git repository card should be expanded at a time");
127
+ assert.match(app, /function loadGitPanelRepository\(card, \{ force = false \} = \{\}\)[\s\S]*!force && gitPanelSnapshotFresh\(existing\)[\s\S]*api\("\/api\/git-panel"/, "repository expansion should reuse fresh cache and otherwise load local status on demand");
128
+ assert.match(app, /ensureGitPanelRepositoriesDiscovered\(\{ retryUnavailable: true \}\)[\s\S]*function ensureGitPanelRepositoriesDiscovered\(\{ retryUnavailable = false \} = \{\}\)[\s\S]*discoverGitPanelCandidate\(candidate, \{ force: true \}\)/, "reopening the Git section should rediscover cwd entries that were previously not repositories");
129
+ assert.match(app, /function renderGitPanel\(\) \{\s+if \(!elements\.gitPanelGroups \|\| !gitPanelSectionExpanded\(\)\) return;/, "tab polling should not rebuild the Git panel while its top-level section is collapsed");
130
+ assert.doesNotMatch(app, /make\("div", "git-side-panel-tree"[\s\S]{0,180}setAttribute\("role", "tree"\)/, "Git file disclosures should use native details semantics instead of an incomplete ARIA tree");
131
+ assert.match(app, /function gitPanelStatsText\(entry = \{\}, category = ""\)[\s\S]*category === "staged"[\s\S]*category === "changes"/, "mixed index/worktree files should display category-specific numstat values");
132
+ assert.match(app, /function renderGitPanelChanges\(card, data\)[\s\S]*"Conflicts"[\s\S]*"Staged"[\s\S]*"Changes"[\s\S]*"Untracked"/, "Git panel should render every requested change category");
133
+ assert.match(app, /function runGitPanelAction\(card, action, path = ""\)[\s\S]*"stage-all"[\s\S]*"unstage-all"[\s\S]*confirm:[\s\S]*git restore --[\s\S]*Delete untracked file/, "Git panel actions should cover staging plus confirmed destructive discard/delete flows");
134
+ assert.match(app, /function renderGitPanelHistory\(card, data\)[\s\S]*openGitCommitDialog\(card\.tabId, commit\)/, "Git History should open bounded commit diffs from the selected repository");
135
+ assert.match(app, /elements\.gitPanelGroups\.replaceChildren\(\.\.\.cards\.map\(renderGitPanelRepositoryCard\)\)/, "Git repositories should render directly without a redundant terminal/session disclosure");
136
+ assert.doesNotMatch(app, /function renderGitPanelGroup\(/, "Git panel should not render terminal/session parent dropdowns");
137
+ assert.match(app, /function gitPanelContextMenuItems\(context\)[\s\S]*kind === "repository"[\s\S]*"View Diff"[\s\S]*"Stage All"[\s\S]*"Unstage All"[\s\S]*"Discard changes…"[\s\S]*"Delete file…"/, "repository and path actions should be provided by the Git context menu");
138
+ assert.match(app, /function bindGitPanelContextMenu\(trigger, context\)[\s\S]*"contextmenu"[\s\S]*"ContextMenu"[\s\S]*event\.shiftKey && event\.key === "F10"/, "Git context actions should support right click and keyboard-equivalent invocation");
139
+ assert.doesNotMatch(app, /git-side-panel-file-actions|git-side-panel-toolbar-actions|git-side-panel-stage-select|gitPanelSmallButton/, "Git rows should not render the removed inline action controls");
140
+ assert.match(app, /function renderGitPanelFolder\(node, card, category, depth = 0\)[\s\S]*const defaultOpen = depth === 0[\s\S]*details\.open =[\s\S]*git-side-panel-folder-chevron[\s\S]*aria-hidden/, "Git folders should render an explicit decorative disclosure arrow");
141
+ assert.match(css, /\.git-side-panel-folder-chevron[\s\S]*transform: rotate\(0deg\)[\s\S]*\.git-side-panel-folder\[open\][\s\S]*transform: rotate\(90deg\)/, "Git folder arrows should indicate collapsed and expanded states");
142
+ assert.match(css, /\.git-side-panel-repository[\s\S]*\.git-side-panel-file[\s\S]*grid-template-columns: 1\.3rem minmax\(5rem, 1fr\) auto[\s\S]*\.git-side-panel-context-menu[\s\S]*\.git-side-panel-commit/, "Git side panel should prioritize filename width and style repository, context-menu, and history surfaces");
143
+ assert.match(server, /async function readGitPanel\(cwd\)[\s\S]*GIT_PANEL_HISTORY_LIMIT[\s\S]*"status", "--porcelain=v1", "-z"[\s\S]*"--numstat", "-z"/, "server should build compact bounded local Git snapshots without full file contents");
144
+ assert.match(server, /async function readGitCommit\(cwd, requestedHash\)[\s\S]*\^\[a-f0-9\][\s\S]*"show", "--format="/, "commit inspection should require a full hash and use a bounded read-only Git show");
145
+ assert.match(server, /"\/api\/git-changes\/stage-all"[\s\S]*stageAllGitChanges[\s\S]*"\/api\/git-changes\/unstage-all"[\s\S]*unstageAllGitChanges/, "server should expose repository-wide stage and unstage mutations");
146
+ assert.match(readme, /side-panel \*\*Git\*\* section[\s\S]*five-minute cache window[\s\S]*confirmed discard\/delete actions[\s\S]*latest 30 commits/, "README should document Git panel grouping, refresh, actions, and history behavior");
110
147
  assert.match(html, /id="optionalFeaturesBox"/, "side panel should expose optional feature status and controls");
111
148
  assert.match(html, /class="optional-features-description[\s\S]*href="https:\/\/github\.com\/Firstp1ck\/npm-packages\/issues\/new"[\s\S]*open a GitHub issue/, "optional features should link users to GitHub issues for additional feature requests");
112
149
  assert.doesNotMatch(html, /id="btwOverlayDialog"/, "/btw should not use a blocking modal overlay");
113
150
  assert.match(html, /id="codexUsageBox"/, "side panel should expose Codex subscription usage status");
114
151
  assert.match(html, /data-side-panel-section="codex-usage"/, "Codex usage should live in a collapsible side-panel section");
115
- assert.match(html, /data-side-panel-section="subagents"[\s\S]*class="side-panel-section-label">Subagents<\/span>[\s\S]*id="subagentCountBadge"[\s\S]*class="subagents-help"[\s\S]*<code>subagent<\/code>[\s\S]*foreground or async mode[\s\S]*id="subagentsBox"/, "side panel should explain how to launch tracked subagents and expose grouped running agents with a live count");
152
+ assert.match(html, /data-side-panel-section="subagents"[\s\S]*class="side-panel-section-label">Subagents<\/span>[\s\S]*id="subagentCountBadge"[\s\S]*class="subagents-help"[\s\S]*<code>subagent<\/code>[\s\S]*<code>subagent_gate<\/code>[\s\S]*bounded retries or a success quorum[\s\S]*id="subagentsBox"/, "side panel should explain ordinary delegation and retry-gate workflows with a live count");
116
153
  assert.match(html, /id="subagentOpenModeSelect"[\s\S]*<option value="overlay">Overlay<\/option>[\s\S]*<option value="tab">Tab \/ terminal<\/option>[\s\S]*id="subagentOpenModeStatus"/, "Subagents should offer a browser-persisted overlay or terminal-tab opening choice");
117
154
  assert.match(html, /id="subagentTerminalView"[\s\S]*Subagent · view only[\s\S]*id="subagentTerminalTranscript"[\s\S]*id="subagentTerminalStatus"[^>]*aria-live="off"[\s\S]*id="subagentTerminalInput"[^>]*placeholder="View only — send messages from the parent terminal"[^>]*disabled[\s\S]*Use its parent terminal to interact with the run/, "dedicated subagent tabs should expose a view-only transcript, non-announcing routine status, and disabled input");
118
155
  assert.doesNotMatch(html, /id="subagentOverlayDialog"/, "subagent output should not use a blocking modal dialog");
@@ -350,6 +387,7 @@ assert.match(css, /\.side-panel-section\.collapsed \.side-panel-section-content,
350
387
  assert.match(css, /\.side-panel-section:not\(\.collapsed\) \.side-panel-section-chevron/, "expanded side panel sections should rotate the chevron");
351
388
  assert.match(css, /\.subagents-help \{[\s\S]*border-left:[\s\S]*font-size:\s*0\.7rem;[\s\S]*\.subagents-help code/, "subagent invocation guidance should render as a compact informational callout");
352
389
  assert.match(css, /\.subagents-box\.has-items[\s\S]*\.subagent-tab-group[\s\S]*\.subagent-agent-row/, "running subagents should render as grouped terminal/session cards");
390
+ assert.match(css, /\.subagent-gate-card[\s\S]*\.subagent-gate-status[\s\S]*\.subagent-gate-attempt[\s\S]*\.subagent-gate-attempt-error/, "retry gates should render quorum, attempt status, and failure details");
353
391
  assert.match(css, /\.subagent-agent-row:hover,[\s\S]*\.subagent-agent-row:focus-visible/, "subagent rows should expose clickable hover and keyboard focus states");
354
392
  assert.match(css, /\.subagent-overlay-widget[\s\S]*\.subagent-overlay-transcript[\s\S]*\.subagent-overlay-message[\s\S]*\.subagent-overlay-close-action/, "subagent output should combine the non-blocking widget shell with the main transcript message styling");
355
393
  assert.match(css, /\.terminal-tab-subagent-indicator[\s\S]*\.terminal-tab-subagent[\s\S]*\.subagent-terminal-view[\s\S]*\.subagent-terminal-composer textarea:disabled/, "subagent terminal tabs should be visibly marked and retain an explicit disabled composer");
@@ -718,7 +756,18 @@ assert.match(
718
756
  "side-panel section toggles should expand at most one section at a time",
719
757
  );
720
758
  assert.match(app, /function renderCodexUsage\(\)/, "frontend should render Codex usage buckets in the side panel");
721
- assert.match(app, /function renderSubagents\(\)[\s\S]*subagentTabsWithRunningAgents\(\)[\s\S]*renderSubagentTabGroup\(tab\)/, "frontend should group running subagents by terminal and session");
759
+ assert.match(app, /function renderSubagents\(\)[\s\S]*subagentTabsWithRunningAgents\(\)[\s\S]*totalGates[\s\S]*renderSubagentTabGroup\(tab\)/, "frontend should group running subagents and retained retry gates by terminal and session");
760
+ assert.match(app, /function renderSubagentGateAttempt\(attempt\)[\s\S]*failureKind[\s\S]*function renderSubagentGate\(gate\)[\s\S]*qualifyingSuccesses/, "frontend should render failure-classified attempts and gate quorum");
761
+ assert.match(helper, /async function enrichAsyncSubagentAgent\(run, agent, statusByDir\)[\s\S]*status\.json[\s\S]*agent\.model = subagentModel\(step\.model\)[\s\S]*agent\.thinking = subagentThinking\(step\.thinking\)/, "WebUI helper should enrich async children from effective lifecycle model and reasoning metadata");
762
+ assert.match(helper, /SUBAGENT_GATE_UPDATE_EVENT[\s\S]*function publicSubagentGates\(\)[\s\S]*failureKind[\s\S]*gates = publicSubagentGates\(\)/, "WebUI helper should publish bounded retry-gate lifecycle data");
763
+ assert.match(extension, /registerSubagentGate\(pi\)[\s\S]*session_shutdown[\s\S]*subagentGate\.dispose\(\)/, "the WebUI package extension should own the retry-gate tool lifecycle without another extension package");
764
+ assert.match(server, /function normalizeWebuiSubagentPayload\(value\)[\s\S]*model: normalizeWebuiSubagentText\(rawAgent\.model, 240\)[\s\S]*thinking: normalizeWebuiSubagentText\(rawAgent\.thinking, 40\)/, "server should bound model and reasoning metadata in the cross-tab overview");
765
+ assert.match(server, /WEBUI_SUBAGENT_GATE_LIMIT[\s\S]*rawGate\.attempts[\s\S]*failureKind: normalizeWebuiSubagentText\(rawAttempt\.failureKind, 80\)[\s\S]*totalGates/, "server should bound retry gates and expose their cross-tab total");
766
+ assert.match(server, /function normalizeWebuiSubagentOutput\(value, selection\)[\s\S]*model: normalizeWebuiSubagentText\(rawAgent\.model, 240\)[\s\S]*thinking: normalizeWebuiSubagentText\(rawAgent\.thinking, 40\)/, "server should preserve model and reasoning metadata in selected child output");
767
+ assert.match(app, /function subagentExecutionFacts\(agent = \{\}\)[\s\S]*model \$\{model \|\| "unknown"\}[\s\S]*reasoning \$\{thinking \|\| "unknown"\}/, "subagent metadata should use one honest model/reasoning formatter with unknown fallbacks");
768
+ assert.match(app, /function renderSubagentAgent\(tab, run, agent\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "Subagents side-panel rows should show model and reasoning effort");
769
+ assert.match(app, /function subagentOverlayStateFacts\(data = subagentOverlayData\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "subagent overlays should show model and reasoning effort");
770
+ assert.match(app, /function renderSubagentTerminalView\(\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "dedicated subagent terminal views should show model and reasoning effort");
722
771
  assert.match(app, /SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode"[\s\S]*function normalizeSubagentOpenMode\(value\)[\s\S]*function restoreSubagentOpenModeSetting\(\)/, "subagent opening mode should default safely and persist in this browser");
723
772
  assert.match(app, /function openSubagentOutput\(tab, run, agent\) \{[\s\S]*subagentOpenMode === "tab" \? openSubagentTerminal\(tab, run, agent\) : openSubagentOverlay\(tab, run, agent\)/, "clicking an agent should dispatch to the selected overlay or terminal-tab view");
724
773
  assert.match(app, /function openSubagentOverlay\(tab, run, agent\)[\s\S]*activeSubagentTerminalId[\s\S]*deactivateSubagentTerminalView\(\{ render: false \}\)[\s\S]*activeTabId !== tab\.tabId[\s\S]*await switchTab\(tab\.tabId\)[\s\S]*renderWidgets\(\)/, "opening an overlay should first leave any virtual child tab, then switch to its owning terminal before rendering the widget");
@@ -0,0 +1,300 @@
1
+ import assert from "node:assert/strict";
2
+ import { registerSubagentGate } from "../lib/subagent-gate.mjs";
3
+
4
+ class EventBus {
5
+ constructor() { this.handlers = new Map(); }
6
+ on(name, handler) {
7
+ const handlers = this.handlers.get(name) || new Set();
8
+ handlers.add(handler);
9
+ this.handlers.set(name, handlers);
10
+ return () => handlers.delete(handler);
11
+ }
12
+ emit(name, value) {
13
+ for (const handler of [...(this.handlers.get(name) || [])]) handler(value);
14
+ }
15
+ }
16
+
17
+ function createHarness(script) {
18
+ const events = new EventBus();
19
+ let tool;
20
+ let runSerial = 0;
21
+ const requests = [];
22
+ const pi = {
23
+ events,
24
+ registerTool(value) { tool = value; },
25
+ };
26
+ const registration = registerSubagentGate(pi);
27
+ events.on("subagents:rpc:v1:request", (request) => {
28
+ requests.push(request);
29
+ if (request.method === "stop") {
30
+ events.emit(`subagents:rpc:v1:reply:${request.requestId}`, { version: 1, requestId: request.requestId, success: true, data: { state: "stopping" } });
31
+ return;
32
+ }
33
+ assert.equal(request.method, "spawn");
34
+ const next = script.shift();
35
+ assert.ok(next, `unexpected spawn request for ${request.params?.agent}`);
36
+ if (next.spawnError) {
37
+ events.emit(`subagents:rpc:v1:reply:${request.requestId}`, {
38
+ version: 1,
39
+ requestId: request.requestId,
40
+ success: false,
41
+ error: { code: next.code || "execution_failed", message: next.spawnError },
42
+ });
43
+ return;
44
+ }
45
+ const runId = next.runId || `gate-run-${++runSerial}`;
46
+ const respond = () => {
47
+ if (next.completeBeforeReply && !next.noCompletion) events.emit("subagent:async-complete", { runId, ...next.completion });
48
+ events.emit(`subagents:rpc:v1:reply:${request.requestId}`, {
49
+ version: 1,
50
+ requestId: request.requestId,
51
+ success: true,
52
+ data: { details: next.noRunId ? {} : { asyncId: runId } },
53
+ });
54
+ if (!next.completeBeforeReply && !next.noCompletion) queueMicrotask(() => events.emit("subagent:async-complete", { runId, ...next.completion }));
55
+ };
56
+ if (next.replyDelayMs) setTimeout(respond, next.replyDelayMs);
57
+ else respond();
58
+ });
59
+ return { tool, requests, dispose: () => registration.dispose() };
60
+ }
61
+
62
+ function completion({ agent = "reviewer", model = "anthropic/claude-opus-4-8", output = "Useful result", error, success = true, state = success ? "complete" : "failed", ...extra } = {}) {
63
+ return {
64
+ success,
65
+ state,
66
+ summary: error || output,
67
+ results: [{ agent, model, output, error, success, ...extra }],
68
+ };
69
+ }
70
+
71
+ async function execute(tool, params, signal = new AbortController().signal) {
72
+ return tool.execute("test-call", params, signal, undefined);
73
+ }
74
+
75
+ async function executeFailure(tool, params, signal = new AbortController().signal) {
76
+ try {
77
+ await execute(tool, params, signal);
78
+ assert.fail("expected subagent gate failure");
79
+ } catch (error) {
80
+ assert.equal(error.name, "SubagentGateError");
81
+ return error.details;
82
+ }
83
+ }
84
+
85
+ {
86
+ const harness = createHarness([{ completeBeforeReply: true, completion: completion() }]);
87
+ const result = await execute(harness.tool, { tasks: [{ agent: "reviewer", task: "Review" }] });
88
+ assert.equal(result.isError, undefined);
89
+ assert.equal(result.details.gate.status, "satisfied");
90
+ assert.equal(result.details.gate.qualifyingSuccesses, 1);
91
+ assert.equal(result.details.gate.attempts.length, 1, "completion emitted before the spawn reply should be recovered from the cache");
92
+ harness.dispose();
93
+ }
94
+
95
+ {
96
+ const harness = createHarness([
97
+ { completion: completion({ success: false, error: "provider overloaded (503)", output: "" }) },
98
+ { completion: completion({ model: "openrouter/moonshotai/kimi-k3", output: "Recovered result" }) },
99
+ ]);
100
+ const result = await execute(harness.tool, {
101
+ tasks: [{
102
+ agent: "reviewer",
103
+ task: "Review",
104
+ model: "anthropic/claude-opus-4-8",
105
+ fallbackModels: ["openrouter/moonshotai/kimi-k3"],
106
+ retrySafety: "read-only",
107
+ }],
108
+ });
109
+ assert.equal(result.details.gate.status, "satisfied");
110
+ assert.deepEqual(result.details.gate.attempts.map((attempt) => [attempt.status, attempt.failureKind, attempt.provider]), [
111
+ ["failed", "transient-provider", "anthropic"],
112
+ ["succeeded", undefined, "openrouter"],
113
+ ]);
114
+ assert.equal(harness.requests.filter((request) => request.method === "spawn").length, 2);
115
+ harness.dispose();
116
+ }
117
+
118
+ {
119
+ const harness = createHarness([{ completion: completion({ success: false, error: "provider overloaded (503)", output: "" }) }]);
120
+ const details = await executeFailure(harness.tool, {
121
+ tasks: [{ agent: "worker", task: "Edit files", retrySafety: "may-write" }],
122
+ maxAttemptsPerTask: 3,
123
+ });
124
+ assert.equal(details.gate.status, "failed");
125
+ assert.equal(details.gate.attempts.length, 1, "a started may-write task must not be automatically retried");
126
+ harness.dispose();
127
+ }
128
+
129
+ {
130
+ const harness = createHarness([
131
+ { spawnError: "temporary async runner startup failure" },
132
+ { completion: completion({ agent: "worker", model: "openai-codex/gpt-5.6-terra", output: "Writer started only after retry" }) },
133
+ ]);
134
+ const result = await execute(harness.tool, {
135
+ tasks: [{ agent: "worker", task: "Edit files", retrySafety: "may-write" }],
136
+ });
137
+ assert.equal(result.details.gate.status, "satisfied");
138
+ assert.equal(result.details.gate.attempts.length, 2, "a pre-launch failure may be retried even for may-write tasks");
139
+ assert.equal(result.details.gate.attempts[0].failureKind, "pre-launch");
140
+ harness.dispose();
141
+ }
142
+
143
+ {
144
+ const harness = createHarness([{ completion: completion({ success: false, state: "stopped", error: "Stopped by user", output: "", stopped: true }) }]);
145
+ const details = await executeFailure(harness.tool, {
146
+ tasks: [{ agent: "reviewer", task: "Review", retrySafety: "read-only" }],
147
+ maxAttemptsPerTask: 3,
148
+ });
149
+ assert.equal(details.gate.attempts.length, 1);
150
+ assert.equal(details.gate.attempts[0].failureKind, "stopped");
151
+ harness.dispose();
152
+ }
153
+
154
+ {
155
+ const harness = createHarness([
156
+ { completion: completion({ agent: "reviewer-a", model: "anthropic/claude-opus-4-8", output: "First provider result" }) },
157
+ { completion: completion({ agent: "reviewer-b", model: "anthropic/claude-fable-5", output: "Duplicate provider result" }) },
158
+ { completion: completion({ agent: "reviewer-b", model: "openrouter/moonshotai/kimi-k3", output: "Distinct provider result" }) },
159
+ ]);
160
+ const result = await execute(harness.tool, {
161
+ tasks: [
162
+ { agent: "reviewer-a", task: "Review A", model: "anthropic/claude-opus-4-8", retrySafety: "read-only" },
163
+ {
164
+ agent: "reviewer-b",
165
+ task: "Review B",
166
+ model: "anthropic/claude-fable-5",
167
+ fallbackModels: ["openrouter/moonshotai/kimi-k3"],
168
+ retrySafety: "read-only",
169
+ },
170
+ ],
171
+ requiredSuccesses: 2,
172
+ requireDistinctProviders: true,
173
+ concurrency: 1,
174
+ });
175
+ assert.equal(result.details.gate.status, "satisfied");
176
+ assert.equal(result.details.gate.qualifyingSuccesses, 2);
177
+ assert.deepEqual(result.details.gate.attempts.map((attempt) => [attempt.status, attempt.failureKind, attempt.provider]), [
178
+ ["succeeded", undefined, "anthropic"],
179
+ ["not-qualifying", "provider-diversity", "anthropic"],
180
+ ["succeeded", undefined, "openrouter"],
181
+ ]);
182
+ harness.dispose();
183
+ }
184
+
185
+ {
186
+ const harness = createHarness([{ noCompletion: true }]);
187
+ const controller = new AbortController();
188
+ queueMicrotask(() => controller.abort());
189
+ const details = await executeFailure(harness.tool, {
190
+ tasks: [{ agent: "reviewer", task: "Review", retrySafety: "read-only" }],
191
+ }, controller.signal);
192
+ assert.equal(details.gate.status, "cancelled");
193
+ assert.equal(details.gate.attempts[0].status, "cancelled", "a cancelled gate must not retain a misleading running attempt");
194
+ assert.ok(details.gate.attempts[0].endedAt);
195
+ assert.equal(harness.requests.filter((request) => request.method === "stop").length, 1, "cancelling the gate should stop its live async child");
196
+ harness.dispose();
197
+ }
198
+
199
+ {
200
+ const harness = createHarness([{ replyDelayMs: 10, noCompletion: true }]);
201
+ const controller = new AbortController();
202
+ queueMicrotask(() => controller.abort());
203
+ const details = await executeFailure(harness.tool, {
204
+ tasks: [{ agent: "worker", task: "Edit files", retrySafety: "may-write", phase: "implementation" }],
205
+ maxAttemptsPerTask: 3,
206
+ }, controller.signal);
207
+ assert.equal(details.gate.attempts.length, 1, "abort during spawn must not be classified as a retryable pre-launch failure");
208
+ assert.equal(details.gate.attempts[0].status, "cancelled");
209
+ assert.equal(details.gate.attempts[0].phase, "implementation");
210
+ assert.equal(harness.requests.filter((request) => request.method === "stop").length, 1, "a late spawn reply must still be reconciled and stopped");
211
+ harness.dispose();
212
+ }
213
+
214
+ {
215
+ const harness = createHarness([{ noRunId: true, noCompletion: true }]);
216
+ const details = await executeFailure(harness.tool, {
217
+ tasks: [{ agent: "worker", task: "Edit files", retrySafety: "may-write" }],
218
+ maxAttemptsPerTask: 3,
219
+ });
220
+ assert.equal(details.gate.attempts.length, 1, "a success reply without a run id is ambiguous and must not relaunch a writer");
221
+ assert.equal(details.gate.attempts[0].failureKind, "protocol-ambiguous");
222
+ harness.dispose();
223
+ }
224
+
225
+ {
226
+ const harness = createHarness([{ completion: completion({ success: false, state: "interrupted", error: "Paused for input", output: "", interrupted: true }) }]);
227
+ const details = await executeFailure(harness.tool, {
228
+ tasks: [{ agent: "reviewer", task: "Review", retrySafety: "read-only" }],
229
+ maxAttemptsPerTask: 3,
230
+ });
231
+ assert.equal(details.gate.attempts.length, 1);
232
+ assert.equal(details.gate.attempts[0].failureKind, "interrupted");
233
+ harness.dispose();
234
+ }
235
+
236
+ {
237
+ const harness = createHarness([
238
+ { completion: completion({ success: false, error: "provider overloaded (503)", output: "" }) },
239
+ { completion: completion({ success: false, error: "provider overloaded again (503)", output: "" }) },
240
+ ]);
241
+ const details = await executeFailure(harness.tool, {
242
+ tasks: [{ agent: "reviewer", task: "Review", retrySafety: "read-only" }],
243
+ maxAttemptsPerTask: 2,
244
+ });
245
+ assert.equal(details.gate.attempts.length, 2, "transient retries must stop at the explicit attempt budget");
246
+ assert.deepEqual(details.exhaustedSlots, [0]);
247
+ harness.dispose();
248
+ }
249
+
250
+ {
251
+ const harness = createHarness([]);
252
+ const details = await executeFailure(harness.tool, {
253
+ tasks: [{ agent: "reviewer", task: "Review", model: "anthropic/claude-opus-4-8", retrySafety: "read-only" }],
254
+ excludedProviders: ["anthropic"],
255
+ });
256
+ assert.equal(details.gate.attempts[0].failureKind, "provider-exhausted");
257
+ assert.equal(harness.requests.filter((request) => request.method === "spawn").length, 0, "known-excluded model candidates must not spend a child launch");
258
+ harness.dispose();
259
+ }
260
+
261
+ {
262
+ const harness = createHarness([{ completion: completion() }]);
263
+ const result = await execute(harness.tool, {
264
+ tasks: [
265
+ { agent: "reviewer", task: "Review A", retrySafety: "read-only" },
266
+ { agent: "reviewer", task: "Review B", retrySafety: "read-only" },
267
+ ],
268
+ requiredSuccesses: 1,
269
+ concurrency: 1,
270
+ });
271
+ assert.equal(harness.requests.filter((request) => request.method === "spawn").length, 1, "queued slots must not launch after quorum is already satisfied");
272
+ assert.deepEqual(result.details.skippedSlots, [1]);
273
+ harness.dispose();
274
+ }
275
+
276
+ {
277
+ const harness = createHarness([{ noCompletion: true }]);
278
+ const details = await executeFailure(harness.tool, {
279
+ tasks: [{ agent: "reviewer", task: "Review", retrySafety: "read-only" }],
280
+ gateTimeoutMs: 5,
281
+ });
282
+ assert.equal(details.gate.status, "failed");
283
+ assert.equal(details.gate.attempts[0].status, "cancelled");
284
+ assert.equal(details.gate.attempts[0].failureKind, "timeout");
285
+ assert.equal(harness.requests.filter((request) => request.method === "stop").length, 1);
286
+ harness.dispose();
287
+ }
288
+
289
+ {
290
+ const harness = createHarness([{ spawnError: "Unknown agent: missing", code: "invalid_params" }]);
291
+ const details = await executeFailure(harness.tool, {
292
+ tasks: [{ agent: "missing", task: "Do work", retrySafety: "read-only" }],
293
+ maxAttemptsPerTask: 3,
294
+ });
295
+ assert.equal(details.gate.attempts.length, 1, "deterministic invalid configuration must not be repeated blindly");
296
+ assert.equal(details.gate.attempts[0].failureKind, "configuration");
297
+ harness.dispose();
298
+ }
299
+
300
+ console.log("subagent-gate.test.mjs passed");
@@ -75,8 +75,8 @@ await writeFile(asyncStatusFile, JSON.stringify({
75
75
  startedAt: Date.now() - 1000,
76
76
  lastUpdate: Date.now(),
77
77
  steps: [
78
- { agent: "reviewer", status: "running", sessionFile: asyncSessionFile, recentOutput: [], currentTool: "bash", currentToolArgs: "sleep 5" },
79
- { agent: "scout", status: "running" },
78
+ { agent: "reviewer", status: "running", sessionFile: asyncSessionFile, recentOutput: [], currentTool: "bash", currentToolArgs: "sleep 5", model: "anthropic/claude-opus-4-8:high", thinking: "high" },
79
+ { agent: "scout", status: "running", model: "openai-codex/gpt-5.6-sol", thinking: "high" },
80
80
  ],
81
81
  }));
82
82
 
@@ -121,8 +121,28 @@ let payload = latestPayload();
121
121
  assert.equal(payload.available, true, "successful pi-subagents RPC should mark status available");
122
122
  assert.deepEqual(payload.runs.map((run) => run.id), ["run-a", "run-b"]);
123
123
  assert.deepEqual(payload.runs[0].agents.map((agent) => [agent.name, agent.currentTool]), [["reviewer", "read"], ["scout", "grep"]]);
124
+ assert.deepEqual(payload.runs[0].agents.map((agent) => [agent.model, agent.thinking]), [["anthropic/claude-opus-4-8:high", "high"], ["openai-codex/gpt-5.6-sol", "high"]], "async overview should publish effective lifecycle model and reasoning metadata");
124
125
  assert.deepEqual(payload.runs[1].agents.map((agent) => [agent.name, agent.nested]), [["worker", false], ["nested-oracle", true]]);
125
126
 
127
+ bus.emit("webui:subagent-gate:v1:update", {
128
+ version: 1,
129
+ id: "gate-a",
130
+ status: "running",
131
+ requiredSuccesses: 2,
132
+ qualifyingSuccesses: 1,
133
+ requireDistinctProviders: true,
134
+ startedAt: Date.now() - 2000,
135
+ updatedAt: Date.now(),
136
+ attempts: [
137
+ { id: "gate-a:0:1", taskIndex: 0, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "review-1", model: "anthropic/claude-opus-4-8", provider: "anthropic", status: "succeeded" },
138
+ { id: "gate-a:1:1", taskIndex: 1, attempt: 1, maxAttempts: 2, agent: "reviewer", retrySafety: "read-only", runId: "review-2", model: "openrouter/moonshotai/kimi-k3", provider: "openrouter", status: "failed", failureKind: "transient-provider", error: "provider overloaded" },
139
+ ],
140
+ });
141
+ payload = latestPayload();
142
+ assert.equal(payload.gates.length, 1, "helper should publish retry gate lifecycle alongside running children");
143
+ assert.equal(payload.gates[0].qualifyingSuccesses, 1);
144
+ assert.deepEqual(payload.gates[0].attempts.map((attempt) => [attempt.status, attempt.failureKind]), [["succeeded", undefined], ["failed", "transient-provider"]]);
145
+
126
146
  const helperCommand = registeredCommands.get("webui-helper");
127
147
  assert.ok(helperCommand?.handler, "Web UI helper command should be registered");
128
148
  await helperCommand.handler(JSON.stringify({
@@ -134,6 +154,8 @@ const asyncOutputNotice = notifications.find((entry) => entry.message.includes("
134
154
  assert.ok(asyncOutputNotice, "async subagent output helper action should return a response notification");
135
155
  const asyncOutputResponse = JSON.parse(asyncOutputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
136
156
  assert.equal(asyncOutputResponse.ok, true);
157
+ assert.equal(asyncOutputResponse.data.agent.model, "anthropic/claude-opus-4-8:high");
158
+ assert.equal(asyncOutputResponse.data.agent.thinking, "high");
137
159
  assert.deepEqual(asyncOutputResponse.data.agent.recentOutput, [
138
160
  "REVIEWER STREAM 1 OF 18",
139
161
  "▶ bash {\"command\":\"sleep 5\"}",
@@ -222,12 +244,19 @@ for (const handler of extensionHandlers.get("tool_execution_start") || []) {
222
244
  type: "tool_execution_start",
223
245
  toolCallId: "foreground-call",
224
246
  toolName: "subagent",
225
- args: { tasks: [{ agent: "tester", task: "Run tests" }, { agent: "reviewer", task: "Review diff" }] },
247
+ args: {
248
+ model: "openai-codex/gpt-5.6-terra:xhigh",
249
+ tasks: [
250
+ { agent: "tester", task: "Run tests" },
251
+ { agent: "reviewer", task: "Review diff", model: "anthropic/claude-opus-4-8:high" },
252
+ ],
253
+ },
226
254
  }, ctx);
227
255
  }
228
256
  payload = latestPayload();
229
257
  let foreground = payload.runs.find((run) => run.source === "foreground");
230
258
  assert.deepEqual(foreground?.agents.map((agent) => agent.name), ["tester", "reviewer"], "foreground parallel children should appear while the tool runs");
259
+ assert.deepEqual(foreground?.agents.map((agent) => [agent.model, agent.thinking]), [["openai-codex/gpt-5.6-terra:xhigh", "xhigh"], ["anthropic/claude-opus-4-8:high", "high"]], "foreground overview should preserve run-level defaults and per-child model/reasoning overrides");
231
260
 
232
261
  for (const handler of extensionHandlers.get("tool_execution_update") || []) {
233
262
  handler({
@@ -272,6 +301,8 @@ const outputResponse = JSON.parse(outputNotice.message.slice("__PI_WEBUI_HELPER_
272
301
  assert.equal(outputResponse.ok, true);
273
302
  assert.equal(outputResponse.data.agent.currentTool, "bash");
274
303
  assert.equal(outputResponse.data.agent.currentToolArgs, "npm test");
304
+ assert.equal(outputResponse.data.agent.model, "openai-codex/gpt-5.6-terra:xhigh");
305
+ assert.equal(outputResponse.data.agent.thinking, "xhigh");
275
306
  assert.deepEqual(outputResponse.data.agent.recentOutput, ["Running focused tests", "12 assertions passed"]);
276
307
  assert.deepEqual(outputResponse.data.agent.transcript, [], "foreground snapshots without a child session transcript should retain the recentOutput-only fallback");
277
308
  assert.deepEqual(outputResponse.data.agent.recentTools, [{ tool: "read", args: "package.json", endMs: 1000 }]);