@firstpick/pi-package-webui 0.9.3 → 0.9.5

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.
Files changed (46) hide show
  1. package/README.md +4 -1
  2. package/lib/ui-layout-settings.mjs +37 -6
  3. package/package.json +1 -1
  4. package/public/app.js +535 -10
  5. package/public/index.html +33 -26
  6. package/public/service-worker.js +1 -1
  7. package/public/stream-output-controller.mjs +31 -2
  8. package/public/styles.css +62 -6
  9. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  10. package/tests/browser/control-deck-side-panels.spec.mjs +42 -0
  11. package/tests/browser/control-visibility.spec.mjs +396 -0
  12. package/tests/browser/intercom-conversation-viewer.spec.mjs +2 -0
  13. package/tests/browser/persistent-ui-layout.spec.mjs +9 -9
  14. package/tests/codex-fast-mode-static.test.mjs +2 -2
  15. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  16. package/tests/control-deck-side-panels-static.test.mjs +3 -1
  17. package/tests/control-visibility-static.test.mjs +294 -0
  18. package/tests/controls-layout-static.test.mjs +3 -3
  19. package/tests/fast-mode-client-static.test.mjs +1 -1
  20. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  21. package/tests/file-viewer-image-static.test.mjs +3 -3
  22. package/tests/fixtures/streaming-workloads.mjs +131 -0
  23. package/tests/git-workflow-preferences.test.mjs +2 -2
  24. package/tests/http-endpoints-harness.test.mjs +4 -4
  25. package/tests/intercom-conversation-viewer-static.test.mjs +6 -5
  26. package/tests/main-output-loading-static.test.mjs +3 -3
  27. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  28. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  29. package/tests/mobile-foundation-static.test.mjs +3 -3
  30. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  31. package/tests/mobile-static.test.mjs +6 -6
  32. package/tests/open-issue-wizard-static.test.mjs +2 -2
  33. package/tests/persistent-ui-layout-static.test.mjs +6 -6
  34. package/tests/questionnaire-dialog.test.mjs +3 -3
  35. package/tests/session-sampling-ui-static.test.mjs +3 -3
  36. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  37. package/tests/stream-output-isolation-static.test.mjs +7 -0
  38. package/tests/stream-output-workloads.test.mjs +239 -0
  39. package/tests/subagent-observability-static.test.mjs +4 -2
  40. package/tests/subagents-helper.test.mjs +109 -0
  41. package/tests/syntax-highlighting-static.test.mjs +3 -3
  42. package/tests/terminal-cwd-grouping-static.test.mjs +22 -0
  43. package/tests/theme-customizer-static.test.mjs +1 -1
  44. package/tests/ui-layout-settings.test.mjs +54 -7
  45. package/tests/webui-settings-locking.test.mjs +3 -3
  46. package/webui-rpc-helper.mjs +126 -5
@@ -1,6 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import {
3
3
  UI_LAYOUT_LIMITS,
4
+ UI_LAYOUT_VERSION,
4
5
  defaultUiLayout,
5
6
  mergeUiLayout,
6
7
  normalizeUiLayout,
@@ -10,6 +11,8 @@ import {
10
11
 
11
12
  const defaults = defaultUiLayout();
12
13
  assert.deepEqual(normalizeUiLayout(undefined), defaults);
14
+ assert.equal(UI_LAYOUT_VERSION, 3);
15
+ assert.deepEqual(defaults.controlVisibility, { hiddenIds: null });
13
16
  assert.deepEqual(normalizeUiLayout({ version: 99, sidePanel: { placement: "both" } }), defaults, "unknown layout versions must fail soft to nullable defaults");
14
17
 
15
18
  const completeV1 = {
@@ -33,7 +36,7 @@ const completeV1 = {
33
36
  fileViewerWidth: 560.4,
34
37
  };
35
38
  const migrated = normalizeUiLayout(completeV1, { legacySidePanelWidth: 612.4 });
36
- assert.equal(migrated.version, 2);
39
+ assert.equal(migrated.version, 3);
37
40
  assert.equal(migrated.sidePanel.placement, "right", "v1 layouts must migrate to the existing right-side presentation");
38
41
  assert.deepEqual(migrated.sidePanel.sectionLayout, { order: ["files", "controls", "git"], leftSectionIds: [] });
39
42
  assert.deepEqual(migrated.sidePanel.collapsedSectionIds, ["git"]);
@@ -44,6 +47,7 @@ assert.deepEqual(migrated.composerActions, completeV1.composerActions, "composer
44
47
  assert.deepEqual(migrated.footerScopedModelOrder, completeV1.footerScopedModelOrder);
45
48
  assert.deepEqual(migrated.terminalTabs, { ...completeV1.terminalTabs, sidebarWidth: 285 }, "terminal placement, custom groups, and normalized sidebar width must survive migration");
46
49
  assert.equal(migrated.fileViewerWidth, 560);
50
+ assert.deepEqual(migrated.controlVisibility, { hiddenIds: null }, "v1 layouts must migrate to default control visibility");
47
51
 
48
52
  const malformedV1 = normalizeUiLayout({
49
53
  ...completeV1,
@@ -68,7 +72,7 @@ assert.equal(malformedV1.terminalTabs.layout, null);
68
72
  assert.deepEqual(malformedV1.terminalTabs.customGroups, completeV1.terminalTabs.customGroups);
69
73
  assert.equal(malformedV1.fileViewerWidth, null);
70
74
 
71
- const valid = normalizeUiLayout({
75
+ const completeV2 = {
72
76
  version: 2,
73
77
  sidePanel: {
74
78
  placement: "both",
@@ -82,6 +86,20 @@ const valid = normalizeUiLayout({
82
86
  footerScopedModelOrder: completeV1.footerScopedModelOrder,
83
87
  terminalTabs: completeV1.terminalTabs,
84
88
  fileViewerWidth: 560,
89
+ };
90
+ const migratedV2 = normalizeUiLayout(completeV2);
91
+ assert.equal(migratedV2.version, 3);
92
+ assert.deepEqual(migratedV2.controlVisibility, { hiddenIds: null }, "v2 layouts must gain default control visibility");
93
+ assert.deepEqual(migratedV2.sidePanel.sectionLayout, completeV2.sidePanel.sectionLayout, "v2 side-panel state must survive migration");
94
+ assert.deepEqual(migratedV2.composerActions, completeV2.composerActions, "v2 composer state must survive migration");
95
+ assert.deepEqual(migratedV2.footerScopedModelOrder, completeV2.footerScopedModelOrder);
96
+ assert.deepEqual(migratedV2.terminalTabs, { ...completeV2.terminalTabs, sidebarWidth: 285 });
97
+ assert.equal(migratedV2.fileViewerWidth, completeV2.fileViewerWidth);
98
+
99
+ const valid = normalizeUiLayout({
100
+ ...completeV2,
101
+ version: 3,
102
+ controlVisibility: { hiddenIds: ["tag.future-kind", "composer.new", "control-deck.sponsor"] },
85
103
  });
86
104
  assert.equal(valid.sidePanel.placement, "both");
87
105
  assert.deepEqual(valid.sidePanel.sectionLayout.leftSectionIds, ["files", "future-section"], "unknown historical section ids may be retained");
@@ -89,6 +107,11 @@ assert.deepEqual(valid.sidePanel.panelWidths, { left: 420, right: 641 });
89
107
  assert.equal(valid.fileViewerWidth, 560);
90
108
  assert.equal(valid.terminalTabs.layout, "left");
91
109
  assert.equal(valid.terminalTabs.sidebarWidth, 285);
110
+ assert.deepEqual(
111
+ valid.controlVisibility.hiddenIds,
112
+ ["composer.new", "control-deck.sponsor", "tag.future-kind"],
113
+ "visibility ids must normalize deterministically while retaining unknown well-formed future ids",
114
+ );
92
115
 
93
116
  const partiallyMalformed = normalizeUiLayout({
94
117
  ...valid,
@@ -105,15 +128,24 @@ assert.deepEqual(partiallyMalformed.sidePanel.sectionLayout, defaults.sidePanel.
105
128
  assert.deepEqual(partiallyMalformed.sidePanel.collapsedPanels, { left: null, right: true }, "malformed side values must not erase valid siblings on disk");
106
129
  assert.deepEqual(partiallyMalformed.sidePanel.panelWidths, { left: null, right: 700 });
107
130
  assert.deepEqual(partiallyMalformed.composerActions, valid.composerActions, "unrelated valid envelope fields must survive malformed side-panel fields");
131
+ assert.deepEqual(partiallyMalformed.controlVisibility, valid.controlVisibility, "unrelated visibility state must survive malformed side-panel fields");
132
+
133
+ const malformedVisibility = normalizeUiLayout({
134
+ ...valid,
135
+ controlVisibility: { hiddenIds: ["composer.new", "composer.new"] },
136
+ });
137
+ assert.deepEqual(malformedVisibility.controlVisibility, defaults.controlVisibility, "malformed persisted visibility must fail soft without affecting sibling fields");
138
+ assert.deepEqual(malformedVisibility.sidePanel, valid.sidePanel);
108
139
 
109
140
  const merged = mergeUiLayout(valid, {
110
- version: 2,
141
+ version: 3,
111
142
  sidePanel: {
112
143
  placement: "left",
113
144
  collapsedPanels: { right: true },
114
145
  panelWidths: { left: 500.2 },
115
146
  hiddenSectionIds: null,
116
147
  },
148
+ controlVisibility: { hiddenIds: [] },
117
149
  footerScopedModelOrder: [],
118
150
  fileViewerWidth: null,
119
151
  });
@@ -122,6 +154,7 @@ assert.deepEqual(merged.sidePanel.sectionLayout, valid.sidePanel.sectionLayout,
122
154
  assert.deepEqual(merged.sidePanel.collapsedPanels, { left: true, right: true }, "side-specific partial state must preserve its sibling");
123
155
  assert.deepEqual(merged.sidePanel.panelWidths, { left: 500, right: 641 });
124
156
  assert.equal(merged.sidePanel.hiddenSectionIds, null, "explicit null must clear only the named field");
157
+ assert.deepEqual(merged.controlVisibility, { hiddenIds: [] }, "an explicit empty visibility list must preserve show-all state");
125
158
  assert.deepEqual(merged.footerScopedModelOrder, [], "explicit empty arrays are valid resets");
126
159
  assert.equal(merged.fileViewerWidth, null);
127
160
 
@@ -131,10 +164,14 @@ const composerReset = mergeUiLayout(valid, { composerActions: { order: [], grid:
131
164
  assert.deepEqual(composerReset.composerActions, { order: [], grid: null });
132
165
  const terminalReset = mergeUiLayout(valid, { terminalTabs: null });
133
166
  assert.deepEqual(terminalReset.terminalTabs, defaults.terminalTabs);
167
+ const visibilityReset = mergeUiLayout(valid, { controlVisibility: { hiddenIds: null } });
168
+ assert.deepEqual(visibilityReset.controlVisibility, { hiddenIds: null }, "null hiddenIds must restore defaults/no explicit preference");
169
+ const visibilityObjectReset = mergeUiLayout(valid, { controlVisibility: null });
170
+ assert.deepEqual(visibilityObjectReset.controlVisibility, defaults.controlVisibility);
134
171
 
135
172
  assert.throws(() => validateUiLayoutPatch({}), /at least one mutable field/);
136
173
  assert.throws(() => validateUiLayoutPatch({ unknown: true }), /unsupported field/);
137
- assert.throws(() => validateUiLayoutPatch({ version: 1, fileViewerWidth: 500 }), /version must be 2/, "stale v1 writes must be rejected");
174
+ assert.throws(() => validateUiLayoutPatch({ version: 2, fileViewerWidth: 500 }), /version must be 3/, "stale v2 writes must be rejected");
138
175
  assert.throws(() => validateUiLayoutPatch({ composerActions: { order: ["send"] } }), /order and grid together/);
139
176
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionOrder: ["files"] } }), /unsupported field: sectionOrder/);
140
177
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsed: true } }), /unsupported field: collapsed/);
@@ -148,6 +185,11 @@ assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { left: UI
148
185
  assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { right: UI_LAYOUT_LIMITS.panelWidthMax + 1 } } }), /must be between/);
149
186
  assert.throws(() => validateUiLayoutPatch({ fileViewerWidth: UI_LAYOUT_LIMITS.fileViewerWidthMin - 1 }), /must be between/);
150
187
  assert.throws(() => validateUiLayoutPatch({ terminalTabs: { sidebarWidth: UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMin - 1 } }), /must be between/);
188
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: {} }), /must include hiddenIds/);
189
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: "composer.new" } }), /must be an array/);
190
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: ["composer.new", "composer.new"] } }), /duplicate/);
191
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: [" composer.new"] } }), /trimmed string/);
192
+ assert.throws(() => validateUiLayoutPatch({ controlVisibility: { hiddenIds: Array.from({ length: UI_LAYOUT_LIMITS.listItems + 1 }, (_, index) => `future.item-${index}`) } }), /at most/);
151
193
  assert.throws(() => validateUiLayoutPatch({ footerScopedModelOrder: Array(UI_LAYOUT_LIMITS.listItems + 1).fill("model") }), /at most/);
152
194
  assert.throws(() => validateUiLayoutPatch({
153
195
  composerActions: { order: ["a", "b"], grid: { version: 2, columns: 2, positions: { a: 0, b: 0 } } },
@@ -165,13 +207,18 @@ assert.throws(() => validateUiLayoutPatch({
165
207
  }), /only one group/);
166
208
 
167
209
  assert.match(uiLayoutRevision(defaults), /^[a-f0-9]{64}$/);
168
- assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 2 })), "equivalent normalized layouts need stable revisions");
210
+ assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 3 })), "equivalent normalized layouts need stable revisions");
169
211
  assert.equal(
170
212
  uiLayoutRevision(completeV1),
171
213
  uiLayoutRevision(normalizeUiLayout(completeV1)),
172
- "a migrated v1 envelope and its canonical v2 representation need the same revision",
214
+ "a migrated v1 envelope and its canonical v3 representation need the same revision",
215
+ );
216
+ assert.equal(
217
+ uiLayoutRevision({ ...valid, controlVisibility: { hiddenIds: ["tag.future-kind", "control-deck.sponsor", "composer.new"] } }),
218
+ uiLayoutRevision(valid),
219
+ "equivalent hidden sets must have a stable revision independent of input order",
173
220
  );
174
- assert.notEqual(uiLayoutRevision(valid), uiLayoutRevision(merged), "placement, collapse, and width changes must change the revision");
221
+ assert.notEqual(uiLayoutRevision(valid), uiLayoutRevision(merged), "layout and visibility changes must change the revision");
175
222
  assert.notEqual(
176
223
  uiLayoutRevision(valid),
177
224
  uiLayoutRevision(mergeUiLayout(valid, { sidePanel: { sectionLayout: { order: ["controls", "files", "git", "future-section"], leftSectionIds: ["files"] } } })),
@@ -119,7 +119,7 @@ try {
119
119
  assert.equal(queued.interfacePreferences.sidePanelWidth, 611);
120
120
  assert.equal(queued.gitWorkflow.deliveryMode, "current");
121
121
 
122
- const futureLayout = { version: 3, futureSurface: { order: ["keep-this"] } };
122
+ const futureLayout = { version: 4, futureSurface: { order: ["keep-this"] } };
123
123
  const futureSettings = JSON.parse(await readFile(settingsFile, "utf8"));
124
124
  futureSettings.uiLayout = futureLayout;
125
125
  await writeFile(settingsFile, `${JSON.stringify(futureSettings, null, 2)}\n`, "utf8");
@@ -131,7 +131,7 @@ try {
131
131
  await writeWebuiSettings({
132
132
  interfacePreferences: { sidePanelWidth: 612 },
133
133
  uiLayout: {
134
- version: 2,
134
+ version: 3,
135
135
  sidePanel: {
136
136
  placement: "right",
137
137
  sectionLayout: { order: ["files", "controls", "git"], leftSectionIds: [] },
@@ -154,7 +154,7 @@ try {
154
154
  }), atomicWidthFile);
155
155
  const atomicWidth = JSON.parse(await readFile(atomicWidthFile, "utf8"));
156
156
  assert.equal(atomicWidth.interfacePreferences.sidePanelWidth, 700);
157
- assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.right, 700, "one locked settings update must atomically persist the v2 right width and legacy mirror");
157
+ assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.right, 700, "one locked settings update must atomically persist the v3 right width and legacy mirror");
158
158
  assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.left, 384);
159
159
 
160
160
  const liveLockTarget = path.join(root, "live-lock", "settings.json");
@@ -55,6 +55,9 @@ const SUBAGENT_RPC_VERSION = 1;
55
55
  const SUBAGENT_RPC_REQUEST_EVENT = "subagents:rpc:v1:request";
56
56
  const SUBAGENT_RPC_READY_EVENT = "subagents:rpc:v1:ready";
57
57
  const SUBAGENT_RPC_REPLY_PREFIX = "subagents:rpc:v1:reply:";
58
+ const SUBAGENT_ASYNC_STATUS_SNAPSHOT_KIND = "pi-subagents.async-status-snapshot";
59
+ const SUBAGENT_ASYNC_STATUS_SNAPSHOT_VERSION = 1;
60
+ const SUBAGENT_ASYNC_STATUS_SNAPSHOT_RUN_LIMIT = 32;
58
61
  const SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started";
59
62
  const SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete";
60
63
  const WORKFLOW_SUBAGENTS_EVENT = "firstpick:workflow-subagents:v1";
@@ -841,12 +844,13 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
841
844
  if (runMatch) {
842
845
  const id = subagentText(runMatch[1], 160);
843
846
  const segments = rawLine.split(" | ").map((part) => part.trim());
844
- const mode = segments.map((part) => part.match(/^(single|parallel|chain)\b/)?.[1]).find(Boolean);
847
+ const mode = segments.map((part) => part.match(/^(single|parallel|chain|workflow)\b/)?.[1]).find(Boolean);
845
848
  const previous = previousRuns.get(id);
846
849
  current = {
847
850
  id,
848
851
  source: "async",
849
852
  mode: subagentMode(mode, previous?.mode),
853
+ workflow: mode === "workflow" || previous?.workflow === true,
850
854
  status: runMatch[2].toLowerCase(),
851
855
  startedAt: previous?.startedAt || Date.now(),
852
856
  agents: [],
@@ -889,7 +893,40 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
889
893
  nested: /^\s{4,}\d+\./.test(rawLine),
890
894
  });
891
895
  }
892
- return runs.filter((run) => run.status === "running" && run.agents.length > 0);
896
+ // Keep active headers even before their first child step is persisted. Dynamic
897
+ // workflow runs can report a running header for several polls while their
898
+ // worker locator is still being written. Dropping that header makes absence
899
+ // reconciliation falsely finish the run, after which later worker details are
900
+ // deliberately ignored as stale and the UI is left with a fleet placeholder.
901
+ return runs.filter((run) => run.status === "running");
902
+ }
903
+
904
+ function parseAsyncSubagentSnapshot(value, previousRuns = new Map()) {
905
+ if (!value || typeof value !== "object"
906
+ || value.kind !== SUBAGENT_ASYNC_STATUS_SNAPSHOT_KIND
907
+ || value.version !== SUBAGENT_ASYNC_STATUS_SNAPSHOT_VERSION
908
+ || !Array.isArray(value.runs)) return [];
909
+ const runs = [];
910
+ const seen = new Set();
911
+ for (const candidate of value.runs.slice(0, SUBAGENT_ASYNC_STATUS_SNAPSHOT_RUN_LIMIT)) {
912
+ const id = subagentText(candidate?.id, 160);
913
+ if (!id || seen.has(id) || candidate?.state !== "running") continue;
914
+ seen.add(id);
915
+ const previous = previousRuns.get(id);
916
+ const workflow = candidate?.kind === "workflow" || previous?.workflow === true;
917
+ runs.push({
918
+ id,
919
+ source: "async",
920
+ mode: subagentMode(undefined, previous?.mode),
921
+ workflow,
922
+ status: "running",
923
+ startedAt: Number.isSafeInteger(candidate?.startedAt) && candidate.startedAt >= 0
924
+ ? candidate.startedAt
925
+ : Number.isFinite(previous?.startedAt) ? previous.startedAt : Date.now(),
926
+ agents: [],
927
+ });
928
+ }
929
+ return runs;
893
930
  }
894
931
 
895
932
  export default function webuiRpcHelper(pi) {
@@ -1543,9 +1580,79 @@ export default function webuiRpcHelper(pi) {
1543
1580
  if (sessionFile && path.isAbsolute(sessionFile) && path.extname(sessionFile) === ".jsonl") agent.sessionFile = path.normalize(sessionFile);
1544
1581
  }
1545
1582
 
1583
+ function subagentRunningAgentsFromStatus(run, status) {
1584
+ return (Array.isArray(status?.steps) ? status.steps : [])
1585
+ .slice(0, 128)
1586
+ .map((step, offset) => {
1587
+ if (step?.status !== "running") return undefined;
1588
+ const name = subagentAgentName(step.agent);
1589
+ if (!name) return undefined;
1590
+ const index = Number.isInteger(step.index) && step.index >= 0 ? step.index : offset;
1591
+ const sessionFile = subagentText(step.sessionFile, 4096);
1592
+ return {
1593
+ id: `${run.id}:step:${index}:${name}`,
1594
+ name,
1595
+ status: "running",
1596
+ index,
1597
+ currentTool: subagentText(step.currentTool, 120) || undefined,
1598
+ activityState: subagentText(step.activityState, 80) || undefined,
1599
+ currentPath: subagentText(step.currentPath, 1000) || undefined,
1600
+ turnCount: Number.isFinite(step.turnCount) ? step.turnCount : undefined,
1601
+ toolCount: Number.isFinite(step.toolCount) ? step.toolCount : undefined,
1602
+ tokens: Number.isFinite(step.tokens?.total) ? step.tokens.total : Number.isFinite(step.tokens) ? step.tokens : undefined,
1603
+ model: subagentModel(step.model) || undefined,
1604
+ thinking: subagentThinking(step.thinking) || subagentThinkingFromModel(step.model) || undefined,
1605
+ recentTools: subagentRecentTools(step.recentTools),
1606
+ recentOutput: subagentOutputLines(step.recentOutput),
1607
+ sessionFile: sessionFile && path.isAbsolute(sessionFile) && path.extname(sessionFile) === ".jsonl" ? path.normalize(sessionFile) : undefined,
1608
+ nested: false,
1609
+ };
1610
+ })
1611
+ .filter(Boolean);
1612
+ }
1613
+
1546
1614
  async function enrichAsyncSubagentRun(run) {
1547
1615
  const statusByDir = new Map();
1616
+ const agents = Array.isArray(run?.agents) ? run.agents : [];
1617
+ if (!agents.some((agent) => agent?.status === "running")) {
1618
+ const targetRunId = subagentText(run?.id, 160);
1619
+ let asyncDir = subagentText(run?.asyncDir, 4096);
1620
+ if (!asyncDir && targetRunId) {
1621
+ try {
1622
+ const data = await requestSubagentStatus({ id: targetRunId });
1623
+ asyncDir = subagentAsyncDirFromStatusText(data?.text);
1624
+ } catch {
1625
+ // The aggregate snapshot still keeps the run alive until a locator resolves.
1626
+ }
1627
+ }
1628
+ if (asyncDir) {
1629
+ run.asyncDir = asyncDir;
1630
+ let status = null;
1631
+ try {
1632
+ status = JSON.parse(readFileSync(path.join(asyncDir, "status.json"), "utf8"));
1633
+ } catch {
1634
+ // A status write can be briefly between atomic replacements.
1635
+ }
1636
+ if (status && (!status.runId || status.runId === targetRunId)) {
1637
+ statusByDir.set(asyncDir, status);
1638
+ run.workflow = status.mode === "workflow" || run.workflow === true;
1639
+ run.mode = subagentMode(status.mode, run.mode);
1640
+ if (!Number.isFinite(run.startedAt) && Number.isFinite(status.startedAt)) run.startedAt = status.startedAt;
1641
+ const discovered = subagentRunningAgentsFromStatus(run, status);
1642
+ if (discovered.length) {
1643
+ run.agents = [
1644
+ ...agents.filter((agent) => !discovered.some((candidate) => candidate.index === agent.index && candidate.name === agent.name)),
1645
+ ...discovered.map((agent) => ({
1646
+ ...agents.find((candidate) => candidate.index === agent.index && candidate.name === agent.name),
1647
+ ...agent,
1648
+ })),
1649
+ ];
1650
+ }
1651
+ }
1652
+ }
1653
+ }
1548
1654
  for (const agent of Array.isArray(run?.agents) ? run.agents : []) {
1655
+ if (agent?.status !== "running") continue;
1549
1656
  await enrichAsyncSubagentAgent(run, agent, statusByDir);
1550
1657
  }
1551
1658
  }
@@ -1742,9 +1849,16 @@ export default function webuiRpcHelper(pi) {
1742
1849
  const addSlots = (runs, priority) => {
1743
1850
  for (const run of runs) {
1744
1851
  if (run?.status !== "running") continue;
1852
+ const slotPriority = parsedIds.has(run.id) ? 0 : priority;
1853
+ // pi-subagents publishes one aggregate fleet entry named "workflow" for
1854
+ // each orchestration run. It is a controller, not a model-powered agent.
1855
+ // Claim it against the known workflow container so it cannot become an
1856
+ // empty recovered Workflow row beside the real child agent.
1857
+ if (run.workflow === true) slots.push({ run, identity: "workflow", priority: slotPriority, claimed: false });
1745
1858
  for (const agent of Array.isArray(run.agents) ? run.agents : []) {
1746
- if (agent?.status !== "running" || !subagentAgentName(agent.name)) continue;
1747
- slots.push({ run, agent, priority: parsedIds.has(run.id) ? 0 : priority, claimed: false });
1859
+ const identity = subagentAgentName(agent?.name);
1860
+ if (agent?.status !== "running" || !identity) continue;
1861
+ slots.push({ run, agent, identity, priority: slotPriority, claimed: false });
1748
1862
  }
1749
1863
  }
1750
1864
  };
@@ -1755,7 +1869,7 @@ export default function webuiRpcHelper(pi) {
1755
1869
  const matchedRunIds = new Set();
1756
1870
  const unmatched = [];
1757
1871
  for (const entry of fleet.entries) {
1758
- const slot = slots.find((candidate) => !candidate.claimed && candidate.agent.name === entry.agent);
1872
+ const slot = slots.find((candidate) => !candidate.claimed && candidate.identity === entry.agent);
1759
1873
  if (!slot) {
1760
1874
  unmatched.push(entry);
1761
1875
  continue;
@@ -1802,6 +1916,12 @@ export default function webuiRpcHelper(pi) {
1802
1916
  const data = await requestSubagentStatus();
1803
1917
  if (generation !== subagentPollGeneration || sequence <= subagentAppliedPollSequence) return;
1804
1918
  const parsedRuns = parseSubagentStatusText(data?.text, asyncSubagentRuns);
1919
+ const parsedRunIds = new Set(parsedRuns.map((run) => run.id));
1920
+ for (const run of parseAsyncSubagentSnapshot(data?.asyncSnapshot, asyncSubagentRuns)) {
1921
+ if (parsedRunIds.has(run.id)) continue;
1922
+ parsedRunIds.add(run.id);
1923
+ parsedRuns.push(run);
1924
+ }
1805
1925
  const nextRuns = [];
1806
1926
  for (const run of parsedRuns) {
1807
1927
  const previous = asyncSubagentRuns.get(run.id);
@@ -1908,6 +2028,7 @@ export default function webuiRpcHelper(pi) {
1908
2028
  id,
1909
2029
  source: "async",
1910
2030
  mode: subagentMode(info.mode, Array.isArray(info.chain) ? "chain" : "single"),
2031
+ workflow: info.mode === "workflow" || undefined,
1911
2032
  status: "running",
1912
2033
  startedAt: Date.now(),
1913
2034
  eventSeenAt: Date.now(),