@firstpick/pi-package-webui 0.9.6 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +13 -5
  2. package/bin/pi-webui.mjs +480 -96
  3. package/index.ts +2 -1
  4. package/lib/git-workflow-preferences.mjs +21 -1
  5. package/lib/optional-feature-catalog.mjs +1 -1
  6. package/lib/session-tree-event-targets.mjs +70 -0
  7. package/lib/subagent-launch-policy.mjs +375 -0
  8. package/lib/subagent-launch-slots.mjs +2 -1
  9. package/package.json +1 -1
  10. package/public/app.js +1348 -131
  11. package/public/guided-git-command-state.mjs +175 -1
  12. package/public/index.html +48 -9
  13. package/public/service-worker.js +1 -1
  14. package/public/styles.css +387 -34
  15. package/public/transcript-renderer.mjs +62 -0
  16. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  17. package/tests/browser/control-visibility.spec.mjs +141 -2
  18. package/tests/browser/events-tree-context-menu.spec.mjs +240 -0
  19. package/tests/browser/footer-model-advanced-layout.spec.mjs +512 -0
  20. package/tests/browser/guided-git-extension-command.spec.mjs +180 -0
  21. package/tests/browser/guided-git-fallback.spec.mjs +218 -0
  22. package/tests/browser/interaction-continuity.spec.mjs +33 -0
  23. package/tests/codex-fast-mode-static.test.mjs +2 -2
  24. package/tests/compact-sections-static.test.mjs +4 -0
  25. package/tests/compaction-static.test.mjs +1 -1
  26. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  27. package/tests/control-visibility-static.test.mjs +66 -3
  28. package/tests/controls-layout-static.test.mjs +3 -3
  29. package/tests/events-tree-context-menu-static.test.mjs +131 -0
  30. package/tests/fast-mode-client-static.test.mjs +5 -2
  31. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  32. package/tests/file-viewer-image-static.test.mjs +3 -3
  33. package/tests/fixtures/fake-pi.mjs +34 -3
  34. package/tests/git-footer-context-menu-static.test.mjs +103 -1
  35. package/tests/git-workflow-preferences.test.mjs +30 -1
  36. package/tests/guided-git-activation-http.test.mjs +194 -0
  37. package/tests/guided-git-activation-static.test.mjs +80 -0
  38. package/tests/guided-git-activation.test.mjs +244 -0
  39. package/tests/guided-git-fallback-runtime.test.mjs +419 -0
  40. package/tests/guided-git-fallback-ui-static.test.mjs +60 -0
  41. package/tests/guided-git-message-reliability-static.test.mjs +9 -7
  42. package/tests/guided-git-optional-feature.test.mjs +31 -0
  43. package/tests/http-endpoints-harness.test.mjs +3 -0
  44. package/tests/interaction-state-stability-static.test.mjs +1 -1
  45. package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
  46. package/tests/main-output-loading-static.test.mjs +11 -9
  47. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  48. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  49. package/tests/mobile-foundation-static.test.mjs +3 -3
  50. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  51. package/tests/mobile-static.test.mjs +92 -9
  52. package/tests/open-issue-wizard-static.test.mjs +1 -1
  53. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  54. package/tests/prompt-input-vertical-scroll-static.test.mjs +6 -6
  55. package/tests/prompt-routing-input-clear-static.test.mjs +1 -1
  56. package/tests/questionnaire-dialog.test.mjs +3 -3
  57. package/tests/remote-auth-settings-harness.test.mjs +23 -0
  58. package/tests/resource-defaults-helper.test.mjs +12 -0
  59. package/tests/session-sampling-helper.test.mjs +1 -0
  60. package/tests/session-sampling-ui-static.test.mjs +3 -3
  61. package/tests/session-tree-event-targets.test.mjs +106 -0
  62. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  63. package/tests/subagent-launch-policy.test.mjs +532 -0
  64. package/tests/subagent-observability-static.test.mjs +2 -2
  65. package/tests/subagents-helper.test.mjs +211 -1
  66. package/tests/syntax-highlighting-static.test.mjs +3 -3
  67. package/tests/tab-close-continuity-static.test.mjs +25 -0
  68. package/tests/theme-customizer-static.test.mjs +1 -1
  69. package/tests/thinking-block-grouping.test.mjs +79 -0
  70. package/webui-rpc-helper.mjs +220 -3
@@ -22,8 +22,8 @@ function sourceBetween(startMarker, endMarker, label) {
22
22
 
23
23
  assert.match(
24
24
  html,
25
- /id="mainOutputLoading" class="main-output-loading" role="status" aria-live="polite" aria-atomic="true" aria-controls="chat" hidden>[\s\S]*?main-output-loading-spinner[\s\S]*?Loading agent output…[\s\S]*?<div id="chat" class="chat" aria-live="polite" aria-busy="false">/,
26
- "the main output should own an inline, accessible loading status before the transcript",
25
+ /class="main-output-surface">[\s\S]*?id="mainOutputLoading" class="main-output-loading" role="status" aria-live="polite" aria-atomic="true" aria-controls="chat" hidden>[\s\S]*?main-output-loading-spinner[\s\S]*?Loading agent output…[\s\S]*?<div id="chat" class="chat" aria-live="polite" aria-busy="false">/,
26
+ "the main output surface should own an accessible loading status over the transcript",
27
27
  );
28
28
  assert.doesNotMatch(html, /<dialog[^>]+id="mainOutputLoading"/, "loading feedback must not use a popup dialog");
29
29
  assert.match(app, /mainOutputLoading: \$\("#mainOutputLoading"\)/, "the browser should bind the inline status element");
@@ -42,17 +42,19 @@ assert.match(refreshMessages, /const loadingRequest = beginMainOutputLoading\(ta
42
42
  assert.match(refreshMessages, /finally \{\s*finishMainOutputLoading\(loadingRequest\);\s*\}/, "success, failure, and stale responses should all clear their request token");
43
43
  assert.match(app, /activeTabId = nextTabId;\s*renderMainOutputLoading\(\);/, "tab changes should immediately reconcile stale and current request visibility");
44
44
 
45
- assert.match(css, /\.main-output-loading\[hidden\] \{ display: none !important; \}/, "hidden loading feedback should not consume layout space");
46
- assert.match(css, /\.main-output-loading \{[\s\S]*?pointer-events: none;[\s\S]*?font-size: var\(--text-xs\)/, "the inline status should remain compact and non-blocking");
45
+ assert.match(css, /\.main-output-loading\[hidden\] \{ display: none !important; \}/, "hidden loading feedback should not render");
46
+ assert.match(css, /\.main-output-surface \{[\s\S]*?position: relative;[\s\S]*?flex: 1 1 auto;[\s\S]*?min-height: 0;/, "the transcript and loading status should share one stable layout surface");
47
+ assert.match(css, /\.main-output-loading \{[\s\S]*?position: absolute;[\s\S]*?left: 50%;[\s\S]*?transform: translateX\(-50%\);[\s\S]*?pointer-events: none;/, "the loading status should overlay the transcript without changing its layout");
48
+ assert.match(css, /\.main-output-loading \{[\s\S]*?font-size: var\(--text-xs\)/, "the loading status should remain compact");
47
49
  assert.match(css, /\.main-output-loading-spinner \{[\s\S]*?animation: main-output-loading-spin 780ms linear infinite/, "the status should include a visible spinner animation");
48
50
  assert.match(css, /@keyframes main-output-loading-spin/, "the spinner should have a local animation contract");
49
51
  assert.match(css, /@media \(prefers-reduced-motion: reduce\)[\s\S]*?animation-duration: 1ms !important;[\s\S]*?animation-iteration-count: 1 !important;/, "the existing reduced-motion policy should stop repeated spinner motion");
50
- assert.match(css, /body\.terminal-tabs-left \.main-output-loading,[\s\S]*?body\.terminal-tabs-left \.chat \{ grid-row: 4; \}/, "sidebar tab placement should keep the status inside the transcript grid row");
51
- assert.match(css, /body\.subagent-terminal-active \.main-output-loading,/, "main-output loading feedback should stay hidden in the dedicated subagent view");
52
+ assert.match(css, /body\.terminal-tabs-left \.main-output-surface \{ grid-row: 4; \}/, "sidebar tab placement should keep the stable output surface in the transcript grid row");
53
+ assert.match(css, /body\.subagent-terminal-active \.main-output-surface,/, "the main output surface should stay hidden in the dedicated subagent view");
52
54
 
53
- assert.match(html, /styles\.css\?v=132/, "the stylesheet cache query should advance");
54
- assert.match(html, /app\.js\?v=157/, "the app cache query should advance");
55
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "the PWA cache identity should advance with browser assets");
55
+ assert.match(html, /styles\.css\?v=142/, "the stylesheet cache query should advance");
56
+ assert.match(html, /app\.js\?v=172/, "the app cache query should advance");
57
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "the PWA cache identity should advance with browser assets");
56
58
  assert.match(readme, /Loading agent output/, "user documentation should describe the visible loading feedback");
57
59
  assert.match(development, /main output loading/i, "developer documentation should preserve the request-ownership contract");
58
60
 
@@ -16,9 +16,9 @@ assert.match(app, /import \{ installMiddleButtonDragScroll \} from "\.\/middle-b
16
16
  assert.match(app, /installMiddleButtonDragScroll\(\{[\s\S]*onDirection: \(\{ target, offsetY \}\)[\s\S]*noteChatUserScrollIntent\(\{ type: "middle-drag", deltaY: offsetY \}\)/, "chat auto-scroll direction should feed the existing follow/pause intent state");
17
17
  assert.match(app, /event\?\.type === "middle-drag"\) return event\.deltaY > 0;/, "moving below the press point should be recognized as intent to read later chat output");
18
18
  assert.match(css, /body\.middle-button-auto-scrolling,[\s\S]*cursor: all-scroll !important;[\s\S]*user-select: none !important;/, "active automatic scrolling should expose a directional-scroll affordance and suppress accidental selection");
19
- assert.match(html, /styles\.css\?v=132/, "changed drag-scroll styles should advance the stylesheet revision");
20
- assert.match(html, /app\.js\?v=157/, "changed drag-scroll wiring should advance the app revision");
21
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123";[\s\S]*"\/middle-button-drag-scroll\.mjs"/, "offline PWA installs should refresh and cache the new controller module");
19
+ assert.match(html, /styles\.css\?v=142/, "changed drag-scroll styles should advance the stylesheet revision");
20
+ assert.match(html, /app\.js\?v=172/, "changed drag-scroll wiring should advance the app revision");
21
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139";[\s\S]*"\/middle-button-drag-scroll\.mjs"/, "offline PWA installs should refresh and cache the new controller module");
22
22
  assert.match(JSON.parse(packageJson).scripts.check, /node --check public\/middle-button-drag-scroll\.mjs/, "the package check should parse the startup-critical controller module");
23
23
 
24
24
  console.log("middle-button-drag-scroll-static.test.mjs passed");
@@ -47,9 +47,9 @@ assert.match(css, /html\[data-tablet-shell="v2"\] \.mobile-shell-nav[\s\S]*?widt
47
47
  assert.match(css, /html\[data-tablet-shell="v2"\] \.mobile-shell-surface[\s\S]*?width: min\(30rem, 72vw\)/, "tablet inspector must be a bounded right-side sheet");
48
48
  assert.match(css, /html\[data-tablet-shell="v2"\] \.file-viewer-pane[\s\S]*?position: fixed[\s\S]*?inset: 0/, "tablet files must default to full-screen replacement");
49
49
  assert.match(css, /and \(pointer: coarse\)[\s\S]*?min-height: 44px/, "coarse tablet pointers must retain the 44px target floor");
50
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "continuity/tablet assets need a coherent cache identity");
51
- assert.match(html, /styles\.css\?v=132/, "tablet CSS must have a coherent HTML revision");
52
- assert.match(html, /app\.js\?v=157/, "continuity app logic must have a coherent HTML revision");
50
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "continuity/tablet assets need a coherent cache identity");
51
+ assert.match(html, /styles\.css\?v=142/, "tablet CSS must have a coherent HTML revision");
52
+ assert.match(html, /app\.js\?v=172/, "continuity app logic must have a coherent HTML revision");
53
53
  assert.match(technical, /tabletShell=v2[\s\S]*tabletShell=legacy/, "technical reference should document tablet preview and rollback");
54
54
 
55
55
  console.log("mobile-continuity-tablet-static.test.mjs passed");
@@ -37,9 +37,9 @@ assert.match(pkg.scripts.check, /node --check public\/transcript-renderer\.mjs/,
37
37
  assert.match(server, /STATIC_PUBLIC_FILE_EXTENSIONS[\s\S]*"\.mjs"/, "the server must serve typed startup modules from the public asset boundary");
38
38
  assert.match(serviceWorker, /"\/mobile-shell-state\.mjs"/, "the PWA shell must cache the new startup module");
39
39
  assert.match(serviceWorker, /"\/transcript-renderer\.mjs"/, "the PWA shell must cache the transcript startup module");
40
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "the cache identity must change with the startup graph");
41
- assert.match(html, /styles\.css\?v=132/, "the stylesheet revision must change with mobile/tablet CSS fixes");
42
- assert.match(html, /app\.js\?v=157/, "the app revision must change with continuity/tablet wiring");
40
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "the cache identity must change with the startup graph");
41
+ assert.match(html, /styles\.css\?v=142/, "the stylesheet revision must change with mobile/tablet CSS fixes");
42
+ assert.match(html, /app\.js\?v=172/, "the app revision must change with continuity/tablet wiring");
43
43
  assert.match(serviceWorker, /const APP_SHELL_NETWORK_TIMEOUT_MS = 8_000;[\s\S]*?event\.waitUntil\([\s\S]*?cache\.put\(request, response\.clone\(\)\)[\s\S]*?return networkResponse;/, "runtime cache writes must extend the event lifetime without blocking bounded network responses");
44
44
  assert.match(serviceWorker, /MOBILE_NAVIGATION_MESSAGE_TYPE = "pi-webui:navigate:v1"/, "the service worker must use a versioned active-client navigation message");
45
45
  assert.match(serviceWorker, /client\.postMessage\(\{ type: MOBILE_NAVIGATION_MESSAGE_TYPE, target \}\)/, "existing clients must receive only a validated target message");
@@ -60,6 +60,6 @@ assert.match(css, /data-mobile-presentation="essential"/, "Essential presentatio
60
60
  assert.match(css, /html\[data-mobile-shell="v2"\] body\.mobile-keyboard-open \.widget-area,[\s\S]*?\.composer-actions-button \{ display: block !important; \}/, "v2 keyboard mode must keep run widgets and the actions entry available");
61
61
  assert.match(css, /@media \(prefers-reduced-motion: reduce\)/, "reduced-motion behavior is required");
62
62
  assert.match(css, /@media \(forced-colors: active\)/, "forced-color affordances are required");
63
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "browser asset changes need a coherent cache tuple");
63
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "browser asset changes need a coherent cache tuple");
64
64
 
65
65
  console.log("mobile-phone-experience-static.test.mjs passed");
@@ -287,11 +287,11 @@ assert.match(html, /data-side-panel-section="controls"/, "side panel controls sh
287
287
  assert.match(html, /data-side-panel-section="commands"/, "side panel commands should live in a collapsible section");
288
288
  assert.match(html, /class="side-panel-section-toggle"[^>]*aria-controls="sidePanelSectionControls"/, "side panel section toggles should target their content panels");
289
289
  assert.match(html, /class="side-panel-section-label">Events<\/span>/, "side panel events should expose a section toggle label");
290
- assert.match(app, /function addEvent\(message, level = "info", \{ toolCallId = "", notify = true \} = \{\}\)[\s\S]*?make\("button", `event \$\{level\}`[\s\S]*?chatEventTimestamp[\s\S]*?jumpToChatEvent\(line\)/, "event log entries should be keyboard-accessible controls that navigate into the chat");
290
+ assert.match(app, /function addEvent\(message, level = "info", \{ toolCallId = "", toolEventPhase = "", details = \[\], notify = true,[\s\S]*?make\("button", `event \$\{level\}`[\s\S]*?chatEventTimestamp[\s\S]*?jumpToChatEvent\(line\)/, "event log entries should be keyboard-accessible controls that navigate into the chat");
291
291
  assert.match(app, /function chatEventTargetForLine\(line\)[\s\S]*?chatToolCallId[\s\S]*?data-tool-call-id[\s\S]*?\.message\[data-chat-timestamp\]/, "event navigation should prefer exact tool cards and otherwise match the closest chat timestamp");
292
292
  assert.match(app, /function jumpToChatEvent\(line\)[\s\S]*?setChatScrollTopInstant[\s\S]*?highlightChatEventTarget[\s\S]*?setSidePanelCollapsed\(true, \{ persist: false \}\)/, "event navigation should dismiss overlay sidebars, scroll the chat, and highlight its target");
293
293
  assert.match(app, /function applyChatEventMetadata\(bubble, message\)[\s\S]*?bubble\.dataset\.chatTimestamp/, "rendered chat events should expose timestamps for sidebar navigation");
294
- assert.match(app, /addEvent\(`tool \$\{event\.toolName\} started`, "info", \{ toolCallId: event\.toolCallId \}\)/, "tool start events should navigate to their exact tool card");
294
+ assert.match(app, /case "tool_execution_start":[\s\S]*?addEvent\(\.\.\.toolLifecycleEventArguments\(event, "start"\)\)/, "tool start events should retain exact tool-card navigation while adding bounded lifecycle details");
295
295
  assert.match(css, /\.event:hover,[\s\S]*?\.message\.chat-event-target[\s\S]*?@keyframes chat-event-target-pulse/, "clickable events and highlighted chat targets should have visible interaction states");
296
296
  const sidePanelToggleStates = Array.from(
297
297
  html.matchAll(/class="side-panel-section-toggle"[^>]*aria-expanded="([^"]+)"/g),
@@ -310,6 +310,22 @@ assert.equal(
310
310
  "side-panel section panels should be hidden by default",
311
311
  );
312
312
  assert.match(html, /id="jumpToLatestButton"/, "chat should expose a jump-to-latest control for non-forced streaming");
313
+ assert.match(
314
+ html,
315
+ /<div class="main-output-surface">[\s\S]*?<div id="chat"[\s\S]*?<\/div>\s*<button id="jumpToLatestButton"[\s\S]*?<\/button>\s*<\/div>\s*<div id="runIndicatorHost"/,
316
+ "jump-to-latest should overlay the output surface above the separate run indicator",
317
+ );
318
+ assert.match(
319
+ css,
320
+ /\.jump-to-latest-button \{[\s\S]*?position: absolute;[\s\S]*?z-index: 14;[\s\S]*?bottom: 0\.75rem;[\s\S]*?left: 50%;[\s\S]*?transform: translateX\(-50%\);/,
321
+ "jump-to-latest should stay centered in the top overlay layer without taking a layout row",
322
+ );
323
+ assert.match(
324
+ css,
325
+ /\.jump-to-latest-button:hover \{[\s\S]*?transform: translateX\(-50%\) translateY\(-1px\);[\s\S]*?\.jump-to-latest-button:active \{[\s\S]*?transform: translateX\(-50%\) translateY\(0\);/,
326
+ "jump-to-latest hover and press feedback should preserve horizontal centering",
327
+ );
328
+ assert.doesNotMatch(css, /terminal-tabs-left \.jump-to-latest-button \{ grid-row:/, "sidebar terminal layout should not assign the overlay its own row");
313
329
  assert.match(html, /id="stickyUserPromptButton"/, "chat should expose a fixed last-user-prompt jump control");
314
330
  assert.match(html, /id="feedbackTray"/, "chat should expose a queued action-feedback tray");
315
331
  assert.match(html, /id="sendFeedbackButton"/, "action feedback should be submittable after the agent finishes");
@@ -1269,7 +1285,7 @@ const clearFinishedContext = {
1269
1285
  async api(path, options) { clearFinishedCalls.push({ path, options }); },
1270
1286
  async refreshSubagents() { clearFinishedRefreshes += 1; },
1271
1287
  scheduleRefreshSubagents() {},
1272
- addEvent(message, level) { clearFinishedEvents.push({ message, level }); },
1288
+ addEvent(message, level, options = {}) { clearFinishedEvents.push({ message, level, options }); },
1273
1289
  };
1274
1290
  vm.runInNewContext(`${app.slice(clearFinishedSourceStart, clearFinishedSourceEnd)}\nthis.runClearFinishedSubagentRuns = clearFinishedSubagentRuns;`, clearFinishedContext);
1275
1291
  await clearFinishedContext.runClearFinishedSubagentRuns();
@@ -1280,10 +1296,73 @@ assert.deepEqual(JSON.parse(JSON.stringify(clearFinishedCalls)), [
1280
1296
  ], "clear-finished should call the existing dismiss endpoint only for visible terminal ordinary runs");
1281
1297
  assert.equal(clearFinishedRefreshes, 1, "clear-finished should refresh the overview once after all dismissals");
1282
1298
  assert.equal(clearFinishedContext.subagentsClearingFinished, false, "clear-finished should always release its in-flight guard");
1283
- assert.deepEqual(clearFinishedEvents, [{ message: "cleared 3 finished subagent runs", level: "info" }]);
1299
+ assert.deepEqual(clearFinishedEvents, [{ message: "cleared 3 finished subagent runs", level: "info", options: {} }]);
1284
1300
  clearFinishedContext.latestSubagents = { tabs: [{ tabId: "tab-c", runs: [{ id: "done-c", status: "done", source: "async" }] }] };
1285
1301
  await clearFinishedContext.runClearFinishedSubagentRuns({ automatic: true });
1286
- assert.deepEqual(clearFinishedEvents.at(-1), { message: "auto-cleared 1 finished subagent run", level: "info" }, "automatic clearing should identify its action without changing terminal-run selection semantics");
1302
+ assert.deepEqual(JSON.parse(JSON.stringify(clearFinishedEvents.at(-1))), {
1303
+ message: "auto-cleared",
1304
+ level: "info",
1305
+ options: {
1306
+ aggregateKey: "subagent-auto-clear",
1307
+ aggregateIncrement: 1,
1308
+ aggregateSingular: "finished subagent run",
1309
+ aggregatePlural: "finished subagent runs",
1310
+ },
1311
+ }, "automatic clearing should use one keyed event whose cleared-run counter can accumulate");
1312
+ const addEventSource = appFunctionSource("addEvent", "closeEventTreeContextMenu");
1313
+ assert.match(addEventSource, /eventAggregateKey === stableAggregateKey[\s\S]*eventAggregateCount[\s\S]*priorAggregate\?\.remove\(\)[\s\S]*eventLog\.prepend\(line\)/, "keyed events should replace their prior row, retain a cumulative count, and return to the top of the log");
1314
+ assert.match(addEventSource, /aggregateCount === 1 \? aggregateSingular : aggregatePlural/, "aggregate rows should keep singular and plural summaries accurate");
1315
+ const aggregateEventLog = {
1316
+ children: [],
1317
+ prepend(node) {
1318
+ node.parent = this;
1319
+ this.children.unshift(node);
1320
+ },
1321
+ get lastElementChild() { return this.children.at(-1) || null; },
1322
+ };
1323
+ function aggregateEventNode(_tag, className = "", text = "") {
1324
+ return {
1325
+ className,
1326
+ dataset: {},
1327
+ children: [],
1328
+ attributes: {},
1329
+ textContent: text,
1330
+ classList: { contains: (value) => className.split(/\s+/).includes(value) },
1331
+ append(...children) {
1332
+ this.children.push(...children);
1333
+ this.textContent += children.map((child) => child?.textContent || "").join("");
1334
+ },
1335
+ setAttribute(name, value) { this.attributes[name] = String(value); },
1336
+ addEventListener() {},
1337
+ remove() {
1338
+ if (!this.parent) return;
1339
+ this.parent.children = this.parent.children.filter((child) => child !== this);
1340
+ this.parent = null;
1341
+ },
1342
+ };
1343
+ }
1344
+ const aggregateEventContext = {
1345
+ elements: { eventLog: aggregateEventLog },
1346
+ make: aggregateEventNode,
1347
+ applyEventFilter() {},
1348
+ jumpToChatEvent() {},
1349
+ showNoticeToast() {},
1350
+ noteUnreadEvent() {},
1351
+ };
1352
+ vm.runInNewContext(`${addEventSource}\nthis.runAddEvent = addEvent;`, aggregateEventContext);
1353
+ const aggregateOptions = {
1354
+ aggregateKey: "subagent-auto-clear",
1355
+ aggregateIncrement: 1,
1356
+ aggregateSingular: "finished subagent run",
1357
+ aggregatePlural: "finished subagent runs",
1358
+ };
1359
+ aggregateEventContext.runAddEvent("auto-cleared", "info", aggregateOptions);
1360
+ aggregateEventContext.runAddEvent("unrelated event", "info");
1361
+ aggregateEventContext.runAddEvent("auto-cleared", "info", { ...aggregateOptions, aggregateIncrement: 2 });
1362
+ assert.equal(aggregateEventLog.children.length, 2, "repeated keyed events should occupy one row alongside unrelated events");
1363
+ assert.equal(aggregateEventLog.children[0].dataset.eventAggregateCount, "3", "the keyed row should accumulate the supplied run counts");
1364
+ assert.equal(aggregateEventLog.children[0].children[0].children[1].textContent, "auto-cleared 3 finished subagent runs", "the keyed row should show its current cumulative count");
1365
+ assert.equal(aggregateEventLog.children[1].children[0].children[1].textContent, "unrelated event", "updating a keyed row should not remove unrelated history");
1287
1366
  assert.match(app, /function materializeRetainedSubagentTerminalViews\(\)[\s\S]*subagentOverviewGroups\(\)[\s\S]*restoreKey = `\$\{tab\.tabId\}\\u0000\$\{tab\.sessionFile[\s\S]*tab\.displayRuns[\s\S]*\["queued", "running", "stale"\]\.includes\(subagentAgentStatus\(run\)\)[\s\S]*ensureSubagentTerminalView/, "terminal mode should materialize only ungated restored retained agent views once per parent session identity without touching overlay mode");
1288
1367
  assert.match(app, /from "\.\/subagent-launch-slot-state\.mjs"[\s\S]*function renderSubagentLaunchSlots\(\)[\s\S]*function loadSubagentLaunchSlotConfig\([\s\S]*\/api\/subagents\/config/, "launch-slot configuration should have its own browser state and API loader");
1289
1368
  assert.match(app, /function subagentLaunchSlotThinkingForModel\(model\)[\s\S]*modelThinkingLevels/, "launch-slot thinking choices should come from the selected model metadata");
@@ -1759,7 +1838,8 @@ assert.match(app, /if \(!isOptionalFeatureDetected\("todoProgressWidget"\)\) ret
1759
1838
  assert.match(app, /const releasePrompt = detectedReleasePrompt && isOptionalFeatureEnabled\(detectedReleasePrompt\.featureId\) \? detectedReleasePrompt : null/, "release confirmation dialogs should use specialized rendering only when their release optional feature is enabled");
1760
1839
  assert.match(app, /case "webui_tab_reloaded":[\s\S]*resetOptionalFeatureAvailability\(\)/, "optional feature state should reset when the RPC tab reloads resources");
1761
1840
  assert.match(app, /function runPublishWorkflow\(command\)[\s\S]*resolveAvailableCommandName\(commandName, \{ rpcOnly: true \}\)/, "publish workflow launch should guard on loaded slash commands, including duplicate-suffixed RPC command names");
1762
- assert.match(app, /if \(!isOptionalFeatureEnabled\("gitWorkflow"\)\)/, "guided git workflow should guard on enabled /git-staged-msg feature");
1841
+ assert.match(app, /function guidedGitPromptCompanionAvailable\(tabId\)[\s\S]*hasLoadedRpcCommand\("git-staged-msg", \{ tabId \}\)/, "guided Git must guard the full browser workflow on the originating tab's prompt companion");
1842
+ assert.match(app, /function launchGuidedGitWorkflow\(tabId = activeTabId\)[\s\S]*resolveAvailableCommandName\("git-guided-workflow", \{ tabId, rpcOnly: true \}\)/, "guided Git visible entry points should prefer the tab-local extension command");
1763
1843
  assert.doesNotMatch(html, /gitWorkflowProcessSelect/, "guided git workflow should not expose process selection as a dropdown");
1764
1844
  assert.match(app, /const GIT_WORKFLOW_PROCESSES = \[[\s\S]*value: "stage", label: "Stage"[\s\S]*value: "message", label: "Message"[\s\S]*value: "commit", label: "Commit"[\s\S]*value: "push", label: "Push"/, "guided git workflow should define Stage/Message/Commit/Push process buttons");
1765
1845
  assert.match(app, /function selectGitWorkflowProcess\(processValue, tabId = gitWorkflowActionTabId\(\)\)[\s\S]*process === "commit"[\s\S]*loadGitWorkflowMessage\(\{ requireFresh: false, runId, tabId \}\)/, "guided git workflow process buttons should jump to Commit by loading current generated message files");
@@ -1790,7 +1870,7 @@ assert.match(server, /\["short", "long", "input"\][\s\S]*cleanGitCommitMessageIn
1790
1870
  assert.match(css, /\.git-workflow-message-input-row \{[\s\S]*flex:\s*1 1 100%/, "manual git workflow commit input should span the Message stage actions row");
1791
1871
  assert.match(css, /\.git-workflow-actions button\[data-tooltip\]::after \{[\s\S]*content:\s*attr\(data-tooltip\)[\s\S]*white-space:\s*pre-line/, "guided git workflow action tooltips should render multiline step lists");
1792
1872
  assert.match(app, /function gitBranchNamePromptMessage\(\)[\s\S]*hasAvailableCommand\("git-branch-name"\)[\s\S]*return "\/git-branch-name"/, "guided git workflow should ask the agent to generate PR branch names when the prompt is available");
1793
- assert.match(app, /async function loadGitWorkflowBranchName\([\s\S]*gitWorkflowRequest\("\/api\/git-workflow\/branch-name"/, "guided git workflow should load generated agent branch names before branch creation");
1873
+ assert.match(app, /async function loadGitWorkflowBranchName\([\s\S]*generationId[\s\S]*gitWorkflowRequest\(`\/api\/git-workflow\/branch-name\$\{query\}`/, "guided git workflow should load exactly correlated generated branch names before branch creation");
1794
1874
  assert.match(app, /async function createGitPrBranchWithSuggestion\([\s\S]*appPromptText\(\{ title: "New PR branch worktree"[\s\S]*chooseGitWorktreeBase\(branch\)[\s\S]*assertGuidedGitStagedContentBinding\(tabId, "PR worktree creation"\)[\s\S]*gitWorkflowRequest\("\/api\/git-workflow\/branch", \{ body: \{ branch, baseRef, sessionMode: "fork-current", openTab: true, [\s\S]*expectedStagedContentHash/, "guided git worktrees should ask for a base ref before verifying and carrying staged content");
1795
1875
  assert.match(app, /function syncGitWorkflowWorktreeTabs\(result\)[\s\S]*Array\.isArray\(result\?\.tabs\)[\s\S]*applyTabMetadata\(result\.tab\)/, "guided git workflow should merge worktree tab metadata returned by the branch endpoint");
1796
1876
  assert.match(app, /const targetTabId = result\.tab\?\.id[\s\S]*setGitWorkflow\(nextState, \{ tabId: targetTabId \}\)[\s\S]*switchTab\(targetTabId\)/, "guided git workflow should transfer PR state to the opened worktree tab");
@@ -1813,8 +1893,9 @@ assert.doesNotMatch(app, /visibility = "(?:public|private)"/, "publication visib
1813
1893
  assert.match(server, /async function gitAddAllPayload\([\s\S]*platform\(\) === "win32"[\s\S]*findWindowsReservedGitPath\([\s\S]*windowsReservedGitPathFailure\(/, "guided git add should preflight Windows-reserved untracked paths before staging");
1814
1894
  assert.match(app, /Pre-commit verification reminder[\s\S]*Continue with this commit/, "configured verification reminders should run before committing");
1815
1895
  assert.match(server, /async function startGitWorkflowGeneration\([\s\S]*set_model[\s\S]*setThinkingLevelForTab[\s\S]*type: "prompt"/, "server should apply the configured generation profile before prompting Pi");
1816
- assert.match(server, /event\?\.type === "agent_settled"[\s\S]*restoreGitWorkflowGenerationProfile\(tab\)/, "server should restore the active tab model and effort after generation settles");
1817
- assert.match(server, /case "\/api\/git-workflow\/branch-name":[\s\S]*readGitWorkflowBranchName\(cwd\)/, "server should expose generated branch-name file loading for the guided PR workflow");
1896
+ assert.match(server, /function consumeGitWorkflowGenerationEvent\(tab, event[\s\S]*event\?\.type !== "agent_settled"[\s\S]*settleGitWorkflowGeneration\(tab, record, settlement\)/, "server should settle the owned Guided Git attempt only after agent settlement");
1897
+ assert.match(server, /async function finishGitWorkflowGeneration\(tab, record[\s\S]*restoreGitWorkflowGenerationProfile\(tab, record\)/, "server should restore the active tab model and effort after Guided Git generation finishes");
1898
+ assert.match(server, /case "\/api\/git-workflow\/branch-name": \{[\s\S]*generationId[\s\S]*readGitWorkflowBranchName\(cwd, \{ generationId/, "server should expose exactly correlated generated branch-name loading for the guided PR workflow");
1818
1899
  assert.match(server, /case "\/api\/git-workflow\/branch":[\s\S]*createGitWorkflowBranchWorktree\(tab, body\)/, "server should route guided PR branch creation through worktree tabs");
1819
1900
  assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*expectedStagedContentHashFromBody\(body\)[\s\S]*snapshotGitWorkflowBranchState\(root, tab\.cwd, expectedStagedContentHash\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should verify and copy exact staged state before opening the worktree tab");
1820
1901
  assert.match(server, /case "\/api\/git-workflow\/create-pr":[\s\S]*runGitHubWorkflowCommand\(\["pr", "create"/, "server should create PRs with the GitHub CLI after confirmation");
@@ -2198,6 +2279,7 @@ assert.match(app, /function bindTerminalTabDragAndDrop\(/, "terminal tabs should
2198
2279
  assert.match(app, /function handleTerminalTabDrop\(sourceTabId, target\)[\s\S]*?createTerminalCustomGroup/, "dropping a terminal tab onto another tab or group should create or update a custom group");
2199
2280
  assert.match(css, /\.terminal-tab\.terminal-tab-drag-over,[\s\S]*?\.terminal-tab-group-item\.terminal-tab-drag-over/, "terminal tab drop targets should show drag-over affordance");
2200
2281
  assert.match(app, /function closeTerminalTabGroup\(group\)[\s\S]*?closeTerminalTabs\(group\.tabs\.map\(\(tab\) => tab\.id\)/, "terminal tab groups should be closable as a batch");
2282
+ assert.match(app, /const closedActiveCwd = closedActiveTab \? tabs\.find\(\(tab\) => tab\.id === activeTabId\)\?\.cwd \|\| "" : ""[\s\S]*?const sameCwdFallbackTabId = closedActiveCwd[\s\S]*?item\.cwd === closedActiveCwd/, "closing the active terminal should prefer another open tab in the same cwd");
2201
2283
  assert.match(app, /function closeAllTerminalTabs\(\)[\s\S]*?closeTerminalTabs\(tabs\.map\(\(tab\) => tab\.id\)/, "tab header should close all terminal tabs as a batch");
2202
2284
  assert.match(app, /WARNING: \$\{activeAgentTabs\.length\}[\s\S]*?still running or waiting for input/, "tab close confirmations should warn when agents are still running");
2203
2285
  assert.match(app, /elements\.closeAllTabsButton\.addEventListener\("click", \(\) => closeAllTerminalTabs\(\)\)/, "close-all tabs button should be wired in JS");
@@ -2360,6 +2442,7 @@ assert.match(extension, /if \(openTabSources\.length > 0\) return mergeRestorabl
2360
2442
  assert.match(extension, /return mergeRestorableTabsFromStatusSources\(\[statusData\?\.restorableTabs, existing\.restorableTabs\], options\)/, "launcher should use restorableTabs only as a legacy fallback");
2361
2443
  assert.match(extension, /env\.PI_WEBUI_RESTORE_FILE = \(await createRestoreFile\(agentDir, restoreTabs\)\)\.file/, "launcher should pass restorable tabs through a private read-once file");
2362
2444
  assert.match(extension, /pi\.registerCommand\("webui-start"/, "extension should expose the canonical /webui-start command");
2445
+ assert.match(extension, /const child = spawn\(nodeExecutable, args, \{/, "/webui-start should use Node instead of treating a standalone Pi executable as a JavaScript runtime");
2363
2446
  assert.match(extension, /pi\.registerCommand\("webui-tree-navigate"/, "extension should expose the internal Web UI tree navigation command");
2364
2447
  assert.match(extension, /ctx\.navigateTree\(payload\.entryId/, "internal Web UI tree command should call the native session tree navigation API");
2365
2448
  assert.doesNotMatch(extension, /pi\.registerCommand\("start-webui"/, "extension should not expose the older /start-webui alias");
@@ -68,7 +68,7 @@ assert.match(server, /STATIC_PUBLIC_FILE_EXTENSIONS[\s\S]*"\.mjs"/, "the server
68
68
  assert.match(serviceWorker, /"\/issue-wizard-state\.mjs"/, "the PWA shell must keep caching the pure wizard module");
69
69
  assert.match(serviceWorker, /"\/issue-bot-client\.mjs"/, "the PWA shell must cache the browser client module");
70
70
  // Intent preserved: changing the public startup graph advances the PWA cache identity.
71
- assert.match(serviceWorker, /pi-webui-pwa-v123/, "the PWA cache name must change with browser wiring updates");
71
+ assert.match(serviceWorker, /pi-webui-pwa-v139/, "the PWA cache name must change with browser wiring updates");
72
72
  assert.match(packageJson, /node --check public\/issue-wizard-state\.mjs/, "the package check must keep syntax-checking the pure wizard module");
73
73
  assert.match(packageJson, /node --check public\/issue-bot-client\.mjs/, "the package check must syntax-check the browser client module");
74
74
 
@@ -271,8 +271,8 @@ assert.match(
271
271
 
272
272
  // --- Coherent browser asset revisions --------------------------------------
273
273
 
274
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "changed browser assets should advance the PWA cache identity");
275
- assert.match(html, /styles\.css\?v=132/, "the page should request the updated layout stylesheet revision");
276
- assert.match(html, /data-app-src="\/app\.js\?v=157"/, "the boot loader should request the updated app module revision");
274
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "changed browser assets should advance the PWA cache identity");
275
+ assert.match(html, /styles\.css\?v=142/, "the page should request the updated layout stylesheet revision");
276
+ assert.match(html, /data-app-src="\/app\.js\?v=172"/, "the boot loader should request the updated app module revision");
277
277
 
278
278
  console.log("persistent-ui-layout-static.test.mjs passed");
@@ -16,11 +16,11 @@ const resizeEnd = app.indexOf("\nfunction updateComposerModeButtons", resizeStar
16
16
  assert.ok(resizeStart >= 0 && resizeEnd > resizeStart, "resizePromptInput should remain inspectable");
17
17
  const resizePromptInput = app.slice(resizeStart, resizeEnd);
18
18
 
19
- assert.match(css, /#promptInput \{[\s\S]*max-height: min\(25vh, 10rem\);[\s\S]*overflow-y: auto;[\s\S]*overscroll-behavior-y: contain;/, "the prompt should retain bounded growth with native vertical scrolling as its CSS fallback");
20
- assert.match(resizePromptInput, /input\.style\.height = "auto";[\s\S]*Math\.min\(input\.scrollHeight, maxHeight\)[\s\S]*input\.style\.overflowY = "auto";/, "every auto-resize pass should preserve vertical scrolling after the height cap is reached or growth stalls");
21
- assert.doesNotMatch(resizePromptInput, /overflowY[^\n]+"hidden"/, "auto-resizing must not disable the prompt's vertical overflow fallback");
22
- assert.match(html, /styles\.css\?v=132/, "the page should request the scroll-enabled stylesheet revision");
23
- assert.match(html, /app\.js\?v=157/, "the page should request the scroll-enabled app revision");
24
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "the PWA cache identity should advance with the prompt scroll assets");
19
+ assert.match(css, /#promptInput \{[\s\S]*--prompt-input-block-chrome: calc\(1\.8rem \+ 2px\);[\s\S]*max-height: calc\(6lh \+ var\(--prompt-input-block-chrome\)\);[\s\S]*overflow-y: auto;[\s\S]*overscroll-behavior-y: contain;/, "the prompt should show six complete lines before native vertical scrolling begins");
20
+ assert.match(resizePromptInput, /input\.style\.height = "auto";[\s\S]*borderTopWidth[\s\S]*borderBottomWidth[\s\S]*naturalHeight = input\.scrollHeight \+ borderBlock[\s\S]*isCapped \? "auto" : "hidden"/, "auto-resizing should include the textarea borders and enable vertical scrolling only after the six-line cap");
21
+ assert.doesNotMatch(resizePromptInput, /input\.style\.overflowY = "auto";/, "auto-resizing must not force a scrollbar below the six-line cap");
22
+ assert.match(html, /styles\.css\?v=142/, "the page should request the six-line prompt stylesheet revision");
23
+ assert.match(html, /app\.js\?v=172/, "the page should request the current app revision");
24
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "the PWA cache identity should advance with the prompt scroll assets");
25
25
 
26
26
  console.log("prompt-input-vertical-scroll-static.test.mjs passed");
@@ -24,7 +24,7 @@ const requestIndex = sendSource.indexOf('await api("/api/prompt"');
24
24
  assert.ok(clearIndex >= 0, "sendPrompt should clear the captured input-backed draft");
25
25
  assert.ok(routingIndex >= 0 && clearIndex < routingIndex, "the submitted prompt should be cleared before routing progress starts");
26
26
  assert.ok(requestIndex >= 0 && clearIndex < requestIndex, "the submitted prompt should be cleared before the prompt request starts");
27
- assert.match(sendSource, /catch \(error\) \{\n\s+restorePromptInputAfterRoutingError\(inputMessage,/, "a routing failure should restore the sent input when no replacement draft exists");
27
+ assert.match(sendSource, /catch \(error\) \{\n\s+(?:if \(guidedGitPermitGranted\) guidedGitLaunchPermits\.clearTab\(targetTabId\);\n\s+)?restorePromptInputAfterRoutingError\(inputMessage,/, "a routing failure should revoke any activation permit and restore the sent input when no replacement draft exists");
28
28
 
29
29
  const successStart = sendSource.indexOf("applyResponseTab(response);");
30
30
  const catchStart = sendSource.indexOf("} catch (error)", successStart);
@@ -504,8 +504,8 @@ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(p
504
504
  assert.match(css, /\.questionnaire-options button\s*\{\s*min-height:\s*3\.35rem/, "mobile questionnaire targets must exceed the 44px floor");
505
505
  assert.match(css, /@media \(prefers-reduced-motion: reduce\)\s*\{[\s\S]*?\*, \*::before, \*::after[\s\S]*?transition-duration:\s*1ms !important/, "global reduced-motion rules must cover questionnaire transitions");
506
506
 
507
- assert.match(html, /styles\.css\?v=132/, "questionnaire CSS needs the current stylesheet revision");
508
- assert.match(html, /app\.js\?v=157/, "questionnaire behavior needs the current app revision");
509
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "questionnaire public assets need a coherent PWA cache revision");
507
+ assert.match(html, /styles\.css\?v=142/, "questionnaire CSS needs the current stylesheet revision");
508
+ assert.match(html, /app\.js\?v=172/, "questionnaire behavior needs the current app revision");
509
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "questionnaire public assets need a coherent PWA cache revision");
510
510
 
511
511
  console.log("questionnaire-dialog.test.mjs passed");
@@ -133,6 +133,11 @@ try {
133
133
  assert.equal(initialGitSetup.body?.data?.configured, false, "guided Git should require first-time model setup");
134
134
  assert.equal(initialGitSetup.body?.data?.preferences?.stagingPolicy, "review", "review/select should be the safe staging default");
135
135
  assert.equal(initialGitSetup.body?.data?.preferences?.reviewProcessEnabled, true, "manual review should remain enabled by default for compatibility");
136
+ assert.deepEqual(initialGitSetup.body?.data?.preferences?.generation?.fallback, {
137
+ provider: "",
138
+ modelId: "",
139
+ thinkingLevel: "low",
140
+ }, "existing settings should expose fallback as disabled until explicitly selected");
136
141
  assert.equal(initialGitSetup.body?.data?.models?.[0]?.id, "fake-model");
137
142
 
138
143
  const unsupportedEffort = await request("/api/git-workflow/preferences", {
@@ -141,6 +146,24 @@ try {
141
146
  });
142
147
  assert.equal(unsupportedEffort.status, 400, "setup should reject effort levels unsupported by the selected model");
143
148
 
149
+ const sameAsPrimaryFallback = await request("/api/git-workflow/preferences", {
150
+ method: "POST",
151
+ body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" } } } },
152
+ });
153
+ assert.equal(sameAsPrimaryFallback.status, 400, "setup should reject a fallback equal to the primary model");
154
+
155
+ const unavailableFallback = await request("/api/git-workflow/preferences", {
156
+ method: "POST",
157
+ body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "fake", modelId: "missing-model", thinkingLevel: "off" } } } },
158
+ });
159
+ assert.equal(unavailableFallback.status, 400, "setup should reject unavailable fallback models");
160
+
161
+ const invalidFallbackEffort = await request("/api/git-workflow/preferences", {
162
+ method: "POST",
163
+ body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", fallback: { provider: "", modelId: "", thinkingLevel: "extreme" } } } },
164
+ });
165
+ assert.equal(invalidFallbackEffort.status, 400, "setup should reject unsupported fallback effort values even while fallback is disabled");
166
+
144
167
  const invalidStagingPolicy = await request("/api/git-workflow/preferences", {
145
168
  method: "POST",
146
169
  body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" }, stagingPolicy: "everything" } },
@@ -58,6 +58,7 @@ try {
58
58
  extensionHandlers.set(name, handlers);
59
59
  },
60
60
  registerCommand(name, command) { registeredCommands.set(name, command); },
61
+ registerTool() {},
61
62
  getAllTools() {
62
63
  return ["read", "bash", "write"].map((name) => ({ name, description: `${name} tool`, sourceInfo: { source: "builtin" } }));
63
64
  },
@@ -109,9 +110,20 @@ try {
109
110
  for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "startup" }, ctx);
110
111
  assert.deepEqual(activeTools, ["read", "bash", "write"], "an initial settings-read failure must leave Pi's runtime tools unchanged");
111
112
  assert.ok(notifications.some((entry) => /tools and skills remain unchanged/i.test(entry.message)), "initial settings failure should emit a bounded warning");
113
+ const applyLaunchSlotDefaults = (extensionHandlers.get("tool_call") || [])[0];
114
+ assert.ok(applyLaunchSlotDefaults, "resource defaults helper should register launch-slot admission");
115
+ const unavailableReviewer = await applyLaunchSlotDefaults({ toolName: "subagent", input: { agent: "reviewer", task: "Review while settings are unavailable" } }, ctx);
116
+ assert.equal(unavailableReviewer?.block, true, "a reviewer-bearing direct launch must fail closed after snapshot load failure");
117
+ assert.match(unavailableReviewer?.reason || "", /snapshot could not be loaded.*Reload the active tab/i);
118
+ const unavailableWorkflow = await applyLaunchSlotDefaults({ toolName: "subagent", input: { workflowScript: "return runs.run('review', {agent:'reviewer', task:'Review'})" } }, ctx);
119
+ assert.equal(unavailableWorkflow?.block, true, "an opaque workflow launch must fail closed after snapshot load failure");
120
+ const unaffectedDelegate = { agent: "delegate", task: "Continue non-reviewer work", model: "provider/delegate" };
121
+ assert.equal(await applyLaunchSlotDefaults({ toolName: "subagent", input: unaffectedDelegate }, ctx), undefined, "a non-reviewer direct launch should remain available after snapshot load failure");
122
+ assert.equal(unaffectedDelegate.model, "provider/delegate");
112
123
 
113
124
  await writeFile(settingsFile, `${JSON.stringify(settingsPayload, null, 2)}\n`, "utf8");
114
125
  for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "settings-restored" }, ctx);
126
+ assert.equal(await applyLaunchSlotDefaults({ toolName: "subagent", input: { agent: "reviewer", task: "Review after reload" } }, ctx), undefined, "a successful reload should clear snapshot-failure admission blocking");
115
127
  availableSkills = ["skill-a", "skill-b", "skill-c"];
116
128
  assert.deepEqual(activeTools, ["read", "write"], "a new session should inherit the global tool allowlist");
117
129
  assert.deepEqual(
@@ -50,6 +50,7 @@ try {
50
50
  extensionHandlers.set(name, handlers);
51
51
  },
52
52
  registerCommand(name, command) { registeredCommands.set(name, command); },
53
+ registerTool() {},
53
54
  getAllTools() { return []; },
54
55
  getActiveTools() { return []; },
55
56
  setActiveTools() {},
@@ -57,10 +57,10 @@ assert.match(css, /\.sampling-parameter-control\.unsupported:hover:not\(\.sampli
57
57
  assert.match(css, /\.sampling-parameter-control\.unsupported:focus-visible:not\(\.sampling-tooltip-dismissed\) > \.sampling-parameter-unsupported-tooltip/, "keyboard focus should reveal dismissible unsupported reasons");
58
58
  assert.match(css, /\.sampling-parameter-unsupported-tooltip\.sampling-tooltip-below/, "bounded placement should support flipping below top-edge rows");
59
59
  assert.match(css, /pointer-events: auto;/, "a visible unsupported tooltip should remain pointer-hoverable");
60
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "native-control assets should advance the cache identity");
60
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "native-control assets should advance the cache identity");
61
61
  assert.match(serviceWorker, /"\/sampling-parameter-controls\.mjs"/, "the pure sampling module should be part of the offline app shell");
62
- assert.match(html, /styles\.css\?v=132/, "the changed stylesheet should have a new revision");
63
- assert.match(html, /app\.js\?v=157/, "the changed app module should have a new revision");
62
+ assert.match(html, /styles\.css\?v=142/, "the changed stylesheet should have a new revision");
63
+ assert.match(html, /app\.js\?v=172/, "the changed app module should have a new revision");
64
64
 
65
65
  // --- Browser state behavior -------------------------------------------------
66
66
 
@@ -0,0 +1,106 @@
1
+ import assert from "node:assert/strict";
2
+ import { sessionTreeEventTargets } from "../lib/session-tree-event-targets.mjs";
3
+
4
+ function messageEntry(id, message) {
5
+ return { type: "message", id, parentId: null, timestamp: "2026-08-20T12:00:00.000Z", message };
6
+ }
7
+
8
+ {
9
+ const entries = [
10
+ messageEntry("assistant-1", {
11
+ role: "assistant",
12
+ content: [
13
+ { type: "text", text: "PRIVATE_ASSISTANT_TEXT" },
14
+ { type: "toolCall", id: "call-read", name: "read", arguments: { path: "/private/secret.txt" } },
15
+ { type: "toolCall", toolCallId: "call-bash", toolName: "bash", arguments: { command: "printenv TOKEN" } },
16
+ ],
17
+ }),
18
+ messageEntry("result-read", {
19
+ role: "toolResult",
20
+ toolCallId: "call-read",
21
+ toolName: "read",
22
+ content: [{ type: "text", text: "PRIVATE_READ_RESULT" }],
23
+ }),
24
+ messageEntry("result-bash", {
25
+ role: "toolResult",
26
+ toolCallId: "call-bash",
27
+ toolName: "bash",
28
+ content: [{ type: "text", text: "PRIVATE_BASH_RESULT" }],
29
+ }),
30
+ ];
31
+
32
+ const targets = sessionTreeEventTargets(entries);
33
+ assert.deepEqual(targets, [
34
+ { toolCallId: "call-read", toolName: "read", startEntryId: "assistant-1", finishEntryId: "result-read" },
35
+ { toolCallId: "call-bash", toolName: "bash", startEntryId: "assistant-1", finishEntryId: "result-bash" },
36
+ ], "multiple calls should map their shared assistant start and distinct result finishes in call order");
37
+ assert.equal(JSON.stringify(targets).includes("PRIVATE_"), false, "message and result content must not enter event targets");
38
+ assert.equal(JSON.stringify(targets).includes("/private/secret.txt"), false, "tool arguments must not enter event targets");
39
+ assert.deepEqual(Object.keys(targets[0]), ["toolCallId", "toolName", "startEntryId", "finishEntryId"], "the contract should expose only the four approved fields");
40
+ assert.doesNotThrow(() => JSON.stringify(targets), "event targets should be JSON-safe");
41
+ }
42
+
43
+ {
44
+ const entries = [
45
+ messageEntry("assistant-first", {
46
+ role: "assistant",
47
+ content: [
48
+ { type: "toolCall", id: "duplicate", name: "first-name", arguments: { secret: "FIRST_ARGUMENT_SECRET" } },
49
+ { type: "toolCall", id: "", name: "missing-id" },
50
+ { type: "toolCall", name: "also-missing-id" },
51
+ ],
52
+ }),
53
+ messageEntry("assistant-later", {
54
+ role: "assistant",
55
+ content: [{ type: "toolCall", id: "duplicate", name: "later-name", arguments: { secret: "LATER_ARGUMENT_SECRET" } }],
56
+ }),
57
+ messageEntry("result-first", {
58
+ role: "toolResult",
59
+ toolCallId: "duplicate",
60
+ toolName: "result-name",
61
+ content: "FIRST_RESULT_SECRET",
62
+ }),
63
+ messageEntry("result-later", {
64
+ role: "toolResult",
65
+ toolCallId: "duplicate",
66
+ toolName: "later-result-name",
67
+ content: "LATER_RESULT_SECRET",
68
+ }),
69
+ messageEntry("result-missing-id", { role: "toolResult", toolName: "read", content: "MISSING_ID_RESULT_SECRET" }),
70
+ messageEntry("not-a-tool-call", { role: "assistant", content: [{ type: "text", text: "ignore" }] }),
71
+ { type: "message", message: { role: "toolResult", toolCallId: "missing-entry-id", toolName: "read" } },
72
+ ];
73
+
74
+ assert.deepEqual(sessionTreeEventTargets(entries), [
75
+ { toolCallId: "duplicate", toolName: "first-name", startEntryId: "assistant-first", finishEntryId: "result-first" },
76
+ ], "missing IDs should be ignored and duplicate boundaries should keep their first stable entry IDs and tool name");
77
+ }
78
+
79
+ {
80
+ const finishOnly = sessionTreeEventTargets([
81
+ messageEntry("finish-only-entry", {
82
+ role: "toolResult",
83
+ toolCallId: "finish-only",
84
+ toolName: "write",
85
+ content: [{ type: "text", text: "FINISH_ONLY_RESULT_SECRET" }],
86
+ }),
87
+ ]);
88
+ assert.deepEqual(finishOnly, [
89
+ { toolCallId: "finish-only", toolName: "write", startEntryId: null, finishEntryId: "finish-only-entry" },
90
+ ], "persisted finish-only records should remain navigable without inventing a start boundary");
91
+ }
92
+
93
+ {
94
+ const resultBeforeCall = sessionTreeEventTargets([
95
+ messageEntry("finish-before-start", { role: "toolResult", toolCallId: "out-of-order", toolName: "bash", content: "secret" }),
96
+ messageEntry("start-after-finish", { role: "assistant", content: [{ type: "toolCall", id: "out-of-order", name: "bash", arguments: {} }] }),
97
+ ]);
98
+ assert.deepEqual(resultBeforeCall, [
99
+ { toolCallId: "out-of-order", toolName: "bash", startEntryId: "start-after-finish", finishEntryId: "finish-before-start" },
100
+ ], "merge logic should fill either boundary without depending on entry ordering");
101
+ }
102
+
103
+ assert.deepEqual(sessionTreeEventTargets(undefined), [], "non-array input should return an empty JSON-safe list");
104
+ assert.deepEqual(sessionTreeEventTargets([null, {}, { type: "message", id: "empty-message" }]), [], "malformed entries should be ignored");
105
+
106
+ console.log("session-tree-event-targets.test.mjs passed");
@@ -27,8 +27,8 @@ assert.doesNotMatch(layout, /sectionHeightMin|sectionHeightMax|validateSectionHe
27
27
  assert.match(app, /const UI_LAYOUT_SIDE_PANEL_FIELDS = \["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"\];/, "the browser durable layout field list should omit section heights");
28
28
  assert.match(app, /function clearRemovedSidePanelSectionHeightState\(\)[\s\S]*localStorage\.removeItem\(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY\)[\s\S]*record\.field === "sidePanel" && record\.subfield === "sectionHeights"/, "startup should remove the retired cache and pending mutations");
29
29
  assert.match(app, /clearRemovedSidePanelSectionHeightState\(\);\s*restoreDurableUiLayoutPendingJournal\(\);/, "retired height state should be cleared before pending layout restoration");
30
- assert.match(html, /styles\.css\?v=132/, "removing section resize styles should advance the stylesheet revision");
31
- assert.match(html, /app\.js\?v=157/, "removing section resize behavior should advance the app revision");
32
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v123"/, "removing browser assets should advance the PWA cache identity");
30
+ assert.match(html, /styles\.css\?v=142/, "removing section resize styles should advance the stylesheet revision");
31
+ assert.match(html, /app\.js\?v=172/, "removing section resize behavior should advance the app revision");
32
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v139"/, "removing browser assets should advance the PWA cache identity");
33
33
 
34
34
  console.log("side-panel-section-height-removal-static.test.mjs passed");