@firstpick/pi-package-webui 0.7.3 → 0.7.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 (34) hide show
  1. package/README.md +34 -20
  2. package/bin/pi-webui.mjs +332 -39
  3. package/index.ts +10 -1
  4. package/lib/git-workflow-preferences.mjs +91 -22
  5. package/lib/subagent-launch-slots.mjs +304 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/webui-output-mode.mjs +97 -0
  8. package/package.json +22 -22
  9. package/public/app.js +1629 -69
  10. package/public/fast-output-live.mjs +179 -0
  11. package/public/index.html +86 -12
  12. package/public/service-worker.js +3 -1
  13. package/public/styles.css +769 -37
  14. package/public/subagent-launch-slot-state.mjs +64 -0
  15. package/tests/chat-scroll-intent-static.test.mjs +59 -0
  16. package/tests/custom-message-markdown-static.test.mjs +15 -0
  17. package/tests/fast-mode-client-static.test.mjs +169 -0
  18. package/tests/fast-mode-output-work.test.mjs +69 -0
  19. package/tests/fast-mode-sse-harness.test.mjs +204 -0
  20. package/tests/fast-output-live.test.mjs +106 -0
  21. package/tests/fixtures/fake-pi.mjs +58 -0
  22. package/tests/fixtures/fast-mode-output-events.mjs +50 -0
  23. package/tests/footer-middle-truncation.test.mjs +2 -2
  24. package/tests/git-workflow-preferences.test.mjs +8 -2
  25. package/tests/http-endpoints-harness.test.mjs +74 -0
  26. package/tests/mobile-static.test.mjs +86 -15
  27. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  28. package/tests/side-panel-resize-static.test.mjs +43 -0
  29. package/tests/subagent-launch-slot-state.test.mjs +36 -0
  30. package/tests/subagent-launch-slots-static.test.mjs +34 -0
  31. package/tests/subagent-launch-slots.test.mjs +143 -0
  32. package/tests/subagents-helper.test.mjs +46 -0
  33. package/tests/webui-output-mode.test.mjs +73 -0
  34. package/webui-rpc-helper.mjs +37 -9
@@ -106,6 +106,10 @@ assert.match(html, /id="pathPickerCreateButton"[^>]*>Create directory<\/button>/
106
106
  assert.match(html, /id="pathPickerSearchInput"[^>]*type="search"[^>]*placeholder="Search current directory…"/, "cwd picker should expose a current-directory search box");
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
+ assert.match(app, /function fileTreeExpander\(expanded = false\)[\s\S]*make\("span", "file-tree-expander", expanded \? "▾" : "▸"\)[\s\S]*aria-hidden/, "file tree arrows should be visual children rather than separate buttons");
110
+ assert.match(app, /function appendFileTreeEntry\(parent, entry, depth = 0\)[\s\S]*button\.append\([\s\S]*isDirectory \? fileTreeExpander\(expanded\)[\s\S]*file-tree-name[\s\S]*button\.addEventListener\("click"[\s\S]*toggleFileTreeDirectory\(path\)[\s\S]*item\.append\(button, fileTreeOverflowButton\(entry\)\)/, "each directory arrow and label should share one expansion button");
111
+ assert.match(app, /function appendFileSearchEntry\(parent, entry\)[\s\S]*button\.append\([\s\S]*isDirectory \? fileTreeExpander\(false\)[\s\S]*button\.addEventListener\("click"[\s\S]*revealFileTreeEntry\(entry\)[\s\S]*item\.append\(button, fileTreeOverflowButton\(entry\)\)/, "directory search results should also combine their arrow and label action");
112
+ assert.match(css, /\.file-tree-node \{[\s\S]*grid-template-columns: minmax\(0, 1fr\) auto[\s\S]*\.file-tree-item \{[\s\S]*grid-template-columns: auto auto minmax\(0, 1fr\) auto auto/, "file tree layout should reserve one row button plus the overflow action while keeping the arrow inside the row button");
109
113
  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
114
  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
115
  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");
@@ -145,12 +149,16 @@ assert.match(server, /async function readGitCommit\(cwd, requestedHash\)[\s\S]*\
145
149
  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
150
  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");
147
151
  assert.match(html, /id="optionalFeaturesBox"/, "side panel should expose optional feature status and controls");
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");
152
+ assert.match(html, /class="optional-features-description[\s\S]*href="https:\/\/github\.com\/Firstp1ck\/pi-coding-agent-forge\/issues\/new"[\s\S]*open a GitHub issue/, "optional features should link users to GitHub issues for additional feature requests");
149
153
  assert.doesNotMatch(html, /id="btwOverlayDialog"/, "/btw should not use a blocking modal overlay");
150
154
  assert.match(html, /id="codexUsageBox"/, "side panel should expose Codex subscription usage status");
151
155
  assert.match(html, /data-side-panel-section="codex-usage"/, "Codex usage should live in a collapsible side-panel section");
152
156
  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");
153
157
  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");
158
+ assert.match(html, /id="subagentLaunchSlots"[\s\S]*id="subagentLaunchSlotsTitle">Agent models<[\s\S]*id="subagentLaunchSlotScope"[\s\S]*<option value="user">User default<\/option>[\s\S]*<option value="project">This project<\/option>[\s\S]*id="subagentLaunchSlotRoles"[\s\S]*id="subagentLaunchSlotsSave"[\s\S]*Save agent models[\s\S]*id="subagentLaunchSlotsReload"[\s\S]*Reload active tab/, "Subagents should expose a separate scoped Agent models editor before the live monitor");
159
+ assert.match(html, /id="subagentLaunchSlotsInherit"[^>]*hidden[^>]*>Use user defaults<\/button>/, "project launch-slot overrides should expose an explicit inheritance reset");
160
+ assert.match(html, /id="subagentLaunchSlotScope"[^>]*aria-describedby="subagentLaunchSlotScopeStatus"/, "scope selection should use stable scope help rather than dynamic live status as its accessible description");
161
+ assert.match(html, /id="subagentLaunchSlotsAnnouncer"[^>]*aria-live="polite"[^>]*aria-atomic="true"/, "launch-slot additions and removals should have a dedicated live announcement");
154
162
  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");
155
163
  assert.doesNotMatch(html, /id="subagentOverlayDialog"/, "subagent output should not use a blocking modal dialog");
156
164
  assert.match(html, /data-side-panel-section="session"[\s\S]*data-side-panel-section="subagents"[\s\S]*data-side-panel-section="queue"/, "Subagents should appear between Session and Queue in the side panel");
@@ -198,6 +206,7 @@ assert.ok(html.includes('id="commandSuggest"') && html.indexOf('id="commandSugge
198
206
  assert.match(html, /id="busyPromptBehaviorTag"[\s\S]*class="composer-busy-mode-tag"[\s\S]*aria-controls="busyPromptBehaviorMenu"/, "composer should expose a clickable busy prompt behavior tag on the input frame");
199
207
  assert.doesNotMatch(html, /Busy send:/i, "busy prompt behavior tag should show only the current mode label");
200
208
  assert.match(html, /id="sessionSkillTags" class="composer-skill-tags"[\s\S]*hidden/, "composer should expose a hidden-until-used skill tag strip beside the busy mode tag");
209
+ assert.match(html, /id="featureCategoryTag" class="composer-feature-category-tag"[^>]*aria-live="polite"[^>]*aria-atomic="true"[^>]*hidden/, "composer should expose a hidden-until-used accessible feature category tag");
201
210
  assert.match(html, /id="skillEditorDialog"[\s\S]*id="skillEditorText"[\s\S]*id="skillEditorSaveButton"/, "skill tags should have an in-Web UI SKILL.md editing dialog");
202
211
  assert.match(html, /id="busyPromptBehaviorMenu"[\s\S]*data-busy-prompt-behavior="followUp"[\s\S]*data-busy-prompt-behavior="steer"/, "busy prompt behavior dropdown should expose follow-up and steer choices");
203
212
  assert.match(app, /const LONG_INPUT_ATTACHMENT_LINE_THRESHOLD = 20/, "long composer text should use a 20-line threshold before becoming an attachment");
@@ -240,6 +249,9 @@ assert.ok(
240
249
  assert.match(html, /id="optionsConversationModeButton"[^>]*data-command="\/talk"[^>]*hidden[\s\S]*?<span>Start Conversation<\/span>/, "Options menu should include the feature-gated Natural Conversation toggle");
241
250
  assert.match(html, /id="conversationModeChip" class="composer-conversation-mode-chip"[\s\S]*hidden>Voice: off<\/button>/, "composer should expose a hidden-until-active conversation status chip");
242
251
  const workflowModeButtonHtml = html.match(/<button\s+id="workflowModeButton"[\s\S]*?<\/button>/)?.[0] || "";
252
+ const workflowOverlayOpenButtonHtml = html.match(/<button\s+id="workflowOverlayOpenButton"[\s\S]*?<\/button>/)?.[0] || "";
253
+ assert.match(html, /id="workflowModeControls" class="composer-publish-menu composer-workflow-mode-controls"[\s\S]*id="workflowOverlayOpenButton"[\s\S]*aria-controls="widgetArea"[\s\S]*id="workflowModeButton"/, "Workflow controls should group a restore affordance with the mode button like the app-runner helper control");
254
+ assert.doesNotMatch(workflowOverlayOpenButtonHtml, /\stitle=/, "Workflow overlay restore should not combine a browser-native tooltip with its styled tooltip");
243
255
  assert.match(workflowModeButtonHtml, /class="composer-workflow-mode-button"[\s\S]*aria-pressed="false"[\s\S]*hidden[\s\S]*<span>Workflow<\/span>/, "composer actions should expose a capability-gated Workflow Mode toggle");
244
256
  assert.match(workflowModeButtonHtml, /data-tooltip="Workflow Mode:/, "Workflow Mode should retain its styled tooltip");
245
257
  assert.doesNotMatch(workflowModeButtonHtml, /\stitle=/, "Workflow Mode should not also expose a browser-native tooltip");
@@ -326,6 +338,7 @@ assert.match(css, /#promptInput \{[\s\S]*?overflow-y:\s*hidden/, "prompt input s
326
338
  assert.match(css, /\.composer-context-tags \{[\s\S]*?top:\s*-0\.48rem;[\s\S]*?left:\s*0\.75rem;/, "busy prompt behavior and skill tags should sit at the top-left of the input frame");
327
339
  assert.match(css, /\.composer-busy-mode-tag \{[\s\S]*?var\(--ctp-crust\)/, "busy prompt behavior tag should use an opaque base background");
328
340
  assert.match(css, /\.composer-skill-tag \{[\s\S]*?var\(--ctp-crust\)/, "skill tags should use an opaque base background");
341
+ assert.match(css, /\.composer-feature-category-tag \{[\s\S]*?var\(--ctp-crust\)[\s\S]*?\.composer-feature-category-tag\.complex-feature \{[\s\S]*?var\(--ctp-mauve\)[\s\S]*?\.composer-feature-category-tag\[hidden\]/, "feature category tags should use the existing composer-tag frame with a distinct complex state and hidden default");
329
342
  assert.match(css, /button\.composer-skill-tag:hover,[\s\S]*?button\.composer-skill-tag:focus-visible/, "skill tags should be styled as clickable controls");
330
343
  assert.match(css, /\.extension-dialog\.skill-editor-dialog \{[\s\S]*?--skill-editor-size:\s*min\(152rem[\s\S]*?width:\s*var\(--skill-editor-size\);[\s\S]*?height:\s*var\(--skill-editor-size\);[\s\S]*?aspect-ratio:\s*1 \/ 1/, "skill editor should use a square viewport-bounded modal layout");
331
344
  assert.match(css, /\.skill-editor-dialog form \{[\s\S]*?height:\s*100%;[\s\S]*?min-height:\s*0/, "skill editor form should fill the square modal without forcing overflow");
@@ -336,6 +349,12 @@ assert.match(css, /\.composer-busy-mode-menu \{[\s\S]*?bottom:\s*calc\(100% \+ 0
336
349
  assert.match(css, /\.sticky-user-prompt-button \{[\s\S]*?grid-template-columns:\s*auto minmax\(0, 1fr\) auto/, "last-user-prompt jump control should render as a fixed transcript header");
337
350
  assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(pointer: coarse\) and \(hover: none\)[\s\S]*?\.sticky-user-prompt-button \{\n\s+grid-template-columns:\s*minmax\(0, 1fr\) auto;\n\s+min-height:\s*36px;[\s\S]*?\.sticky-user-prompt-text \{[\s\S]*?font-size:\s*var\(--text-xs\)/, "mobile last-user-prompt card should preserve compact height while respecting the text floor");
338
351
  assert.match(css, /\.message\.extension,[\s\S]*?\.message\.native/, "extension and native command output should have visible transcript styling");
352
+ assert.match(app, /const FEATURE_CATEGORY_STATUS_KEY = "feature-category";[\s\S]*const featureCategoryByTab = new Map\(\)/, "feature category status should use a dedicated per-tab transport key and state map");
353
+ assert.match(app, /function normalizeFeatureCategory\(value\) \{\s+return value === "lightweight-feature" \|\| value === "complex-feature" \? value : "";/, "feature category normalization should accept only the two approved exact labels");
354
+ assert.match(app, /function renderFeatureCategoryTag\(tabId = activeTabId\) \{[\s\S]*featureCategoryByTab\.get\(tabId\)[\s\S]*tag\.hidden = !category[\s\S]*tag\.textContent = category/, "feature category rendering should be active-tab scoped and hidden when absent");
355
+ assert.match(app, /function handleFeatureCategoryStatus\(statusText, tabId = activeTabId\) \{[\s\S]*featureCategoryByTab\.set\(tabId, category\)[\s\S]*featureCategoryByTab\.delete\(tabId\)[\s\S]*tabId === activeTabId/, "feature category status should update and clear only the addressed terminal tab");
356
+ assert.match(app, /case "setStatus": \{[\s\S]*statusKey === FEATURE_CATEGORY_STATUS_KEY[\s\S]*handleFeatureCategoryStatus\(request\.statusText, request\.tabId \|\| activeTabId\);[\s\S]*return;[\s\S]*statusEntries\.set\(statusKey, request\.statusText\)/, "feature category status should be consumed before generic footer status storage");
357
+ assert.match(app, /function setActiveTabId\(tabId, \{ remember = false \} = \{\}\) \{[\s\S]*renderFeatureCategoryTag\(nextTabId\)[\s\S]*function syncTabMetadata\(nextTabs = \[\]\) \{[\s\S]*featureCategoryByTab\.delete\(tabId\)/, "tab activation and cleanup should render only the active category and remove closed-tab state");
339
358
  assert.match(app, /function remoteWebuiQrSvg\(qrLines = \[\]\)[\s\S]*?viewBox[\s\S]*?shape-rendering[\s\S]*?crispEdges/, "remote WebUI QR popup should render terminal QR output as square SVG modules");
340
359
  assert.match(app, /function showRemoteWebuiQrLoadingPopup\(message = "Opening Remote WebUI QR…"\)[\s\S]*?remote-qr-loading[\s\S]*?showModal\(\)/, "remote WebUI QR popup should show a loading state while QR generation is pending");
341
360
  assert.match(app, /function handleRemoteWebuiStatus\(statusText\)[\s\S]*?opening remote webui[\s\S]*?refreshing remote qr[\s\S]*?enabling remote pin auth[\s\S]*?showRemoteWebuiQrLoadingPopup/, "remote WebUI status updates should open the QR loading popup before widget lines arrive");
@@ -388,6 +407,8 @@ assert.match(css, /\.webui-dev-badge \{[\s\S]*?color:\s*var\(--ctp-yellow\)/, "W
388
407
  assert.match(css, /\.side-panel-section\.collapsed \.side-panel-section-content,\n\.side-panel-section-content\[hidden\] \{\n\s+display:\s*none;/, "collapsed side panel section content should be hidden");
389
408
  assert.match(css, /\.side-panel-section:not\(\.collapsed\) \.side-panel-section-chevron/, "expanded side panel sections should rotate the chevron");
390
409
  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");
410
+ assert.match(css, /\.subagent-launch-slots \{[\s\S]*\.subagent-launch-slot-role \{[\s\S]*\.subagent-launch-slot-controls \{[\s\S]*grid-template-columns: repeat\(2, minmax\(0, 1fr\)\)/, "launch-slot cards should group role slots with paired model and thinking controls");
411
+ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(pointer: coarse\) and \(hover: none\) \{[\s\S]*min-height: 44px[\s\S]*\.subagent-launch-slot-scope,[\s\S]*\.subagent-launch-slot-row,[\s\S]*\.subagent-launch-slot-controls \{ grid-template-columns: minmax\(0, 1fr\); \}/, "launch-slot controls should stack with coarse-pointer touch targets");
391
412
  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");
392
413
  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");
393
414
  assert.match(css, /\.subagent-agent-row:hover,[\s\S]*\.subagent-agent-row:focus-visible/, "subagent rows should expose clickable hover and keyboard focus states");
@@ -409,9 +430,14 @@ assert.match(css, /\.release-npm-widget \{[\s\S]*?border-left:\s*0\.28rem solid/
409
430
  assert.match(css, /\.release-npm-stream-header \{[\s\S]*?text-transform:\s*uppercase/, "release-npm output should label the output stream clearly");
410
431
  assert.match(css, /\.release-npm-output-summary \{[\s\S]*?cursor:\s*pointer/, "release-npm output should expose a local expand/collapse summary");
411
432
  assert.match(css, /\.release-npm-output-details\[open\] \.release-npm-output-toggle/, "release-npm expanded output should rotate the summary chevron");
433
+ assert.match(css, /\.release-npm-output-details \{[\s\S]*?grid-template-columns:\s*minmax\(0, 1fr\);[\s\S]*?min-width:\s*0;/, "release output should constrain its grid track so long subprocess lines scroll inside the terminal instead of widening the widget");
412
434
  assert.match(css, /\.widget-area:has\(\.release-npm-live-widget \.release-npm-output-details\[open\]\)[\s\S]*?flex:\s*0 0 min\(44rem, 68dvh\)/, "live release output should reserve a stable widget slot instead of resizing the transcript while streaming");
413
- assert.match(css, /\.widget-area:has\(\.workflow-widget\) \{[\s\S]*?flex:\s*0 1 auto;[\s\S]*?max-height:\s*min\(34rem, 52dvh\);[\s\S]*?overflow:\s*auto/, "workflow widgets should stay within a scrollable output-sized slot so the composer and footer remain visible");
414
- assert.match(css, /\.release-npm-live-widget \.release-npm-output-details\[open\] \.release-npm-terminal,[\s\S]*?height:\s*clamp\(15rem, 42dvh, 31rem\)/, "live release terminals should keep a fixed viewport height while output streams");
435
+ assert.match(css, /\.widget-area:has\(\.workflow-live-widget \.release-npm-output-details\[open\]\) \{[^}]*min-height:\s*0;[^}]*overflow-x:\s*hidden;[^}]*overflow-y:\s*auto/, "live workflow output should retain its local scroll boundary without forcing a fixed outer height");
436
+ assert.match(css, /\.widget-area:has\(\.workflow-widget:not\(\.minimized\)\) \{[^}]*--workflow-overlay-max-height:\s*min\(44rem, 68dvh\);[^}]*flex:\s*0 0 auto;[^}]*max-height:\s*var\(--workflow-overlay-max-height\);[^}]*overflow-x:\s*hidden;[^}]*overflow-y:\s*auto/, "restored workflow widgets should follow rendered content up to a viewport-safe scroll cap while minimized-only workflow content releases that sizing rule");
437
+ assert.match(css, /\.widget-area:has\(\.workflow-widget:not\(\.minimized\)\) \{ --workflow-overlay-max-height:\s*34dvh; \}/, "mobile workflow widgets should keep the existing compact viewport cap while sizing intrinsically");
438
+ assert.match(css, /\.release-npm-live-widget \.release-npm-output-details\[open\] \.release-npm-terminal,[\s\S]*?\.release-aur-live-widget[\s\S]*?height:\s*clamp\(15rem, 42dvh, 31rem\)/, "live release terminals should keep a fixed viewport height while output streams");
439
+ assert.match(css, /\.workflow-subprocess-widget \.release-npm-output-details\[open\] \.release-npm-terminal \{[^}]*max-height:\s*clamp\(12rem, 34dvh, 26rem\);[^}]*min-height:\s*0;[^}]*overscroll-behavior-y:\s*auto;[^}]*scrollbar-gutter:\s*stable/, "workflow output should grow with real line content up to a compact local scroll cap");
440
+ assert.match(css, /\.workflow-subprocess-widget \.workflow-meta \{[\s\S]*?grid-template-columns:[\s\S]*?\.workflow-meta-label \{[\s\S]*?text-transform:\s*uppercase/, "workflow run limits and status should render as clearly labeled metadata groups");
415
441
  assert.match(css, /\.release-npm-terminal \{[\s\S]*?rgba\(3, 4, 10, 0\.98\)/, "release-npm terminal should use a high-contrast stream panel");
416
442
  assert.match(css, /\.release-aur-widget \{[\s\S]*?border-color/, "release-aur output should render as a specialized Web UI widget variant");
417
443
  assert.match(css, /\.app-runner-widget \{[\s\S]*?border-color/, "app runner output should render as a specialized Web UI widget variant");
@@ -482,11 +508,12 @@ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(p
482
508
  assert.match(css, /\.terminal-tab-activity-indicator/, "terminal tabs should expose per-tab agent activity indicators");
483
509
  assert.match(css, /\.terminal-tab-app-runner-indicator \{[\s\S]*?terminal-tab-app-runner-pulse/, "terminal tabs should expose animated app-runner indicators");
484
510
  assert.match(css, /\.terminal-tab\.app-runner-running,\n\.terminal-tab-group-item\.app-runner-running/, "terminal tabs and grouped items should mark running app runners");
511
+ assert.match(css, /\.terminal-tab-group-menu \{[^}]*max-height:\s*none;[^}]*overflow:\s*visible;/, "grouped terminal tab menus should grow to show every open tab without an internal scrollbar");
485
512
  assert.match(css, /\.terminal-tab-group-item \{[\s\S]*?flex:\s*0 0 auto[\s\S]*?background:\s*var\(--ctp-crust\)/, "grouped terminal tab items should keep readable height and use opaque backgrounds");
486
- assert.match(css, /\.terminal-tab-group-add \{[\s\S]*?flex:\s*0 0 auto/, "grouped terminal tab menus should scroll instead of shrinking the add-tab action");
513
+ assert.match(css, /\.terminal-tab-group-add \{[\s\S]*?flex:\s*0 0 auto/, "grouped terminal tab menus should keep the add-tab action at its natural height");
487
514
  assert.match(css, /\.terminal-tab-group\.active \{[\s\S]*?background:[\s\S]*?var\(--ctp-crust\)/, "active terminal tab groups should keep opaque backgrounds");
488
515
  assert.match(css, /\.terminal-tab-group\.stopped \{[\s\S]*?opacity:\s*1/, "stopped terminal tab groups should not become transparent");
489
- assert.match(css, /\.terminal-tabs:has\(\.terminal-tab-group\.menu-open\)/, "open terminal tab groups should keep the tab strip usable across rerenders");
516
+ assert.match(css, /\.terminal-tabs:has\(\.terminal-tab-group\.menu-open\),[^{}]*\{[^}]*overflow:\s*visible;/, "open terminal tab groups should escape the tab strip without clipping");
490
517
  assert.match(css, /\.terminal-tab-group\.menu-open \.terminal-tab-group-menu \{[\s\S]*?display:\s*flex/, "open terminal tab group menus should remain visible without hover");
491
518
  assert.match(css, /\.terminal-tab\.activity-working > \.terminal-tab-button \.terminal-tab-activity-indicator[\s\S]*?terminal-tab-working-pulse/, "working tab indicators should be visibly animated");
492
519
  assert.match(css, /\.terminal-tab-group-item\.activity-working > \.terminal-tab-button \.terminal-tab-activity-indicator[\s\S]*?terminal-tab-working-pulse/, "working indicators should still animate on grouped tab menu items themselves");
@@ -630,7 +657,7 @@ assert.match(app, /remoteAuthToggle: \$\("#remoteAuthToggle"\)/, "Remote WebUI c
630
657
  assert.match(html, /id="networkControlField"[^>]*hidden/, "Remote WebUI browser controls should be hidden until the optional package is loaded and enabled");
631
658
  assert.match(app, /remoteWebuiCommand\(enable \? "authOn" : "authOff"/, "remote PIN auth toggle should dispatch through the Remote WebUI package command");
632
659
  assert.match(server, /webuiSettingsFile,[\s\S]*from "\.\.\/lib\/git-workflow-preferences\.mjs"/, "server should use the shared Pi Web UI settings persistence module");
633
- assert.match(server, /let persistedRemoteAuthEnabled = await readPersistedRemoteAuthEnabled\(\)/, "server should load the saved Remote PIN auth preference before startup");
660
+ assert.match(server, /const persistedStartupSettings = await readWebuiSettings\(undefined, \{ reportInvalidOutputMode: true \}\);[\s\S]*?let persistedRemoteAuthEnabled = persistedStartupSettings\.remoteAuthEnabled === true;/, "server should load the saved Remote PIN auth preference before startup");
634
661
  assert.match(server, /if \(remoteAuthStartupEnabled\(\)\) enableRemoteAuth\(remoteAuthStartupReason\(\)\)/, "saved Remote PIN auth preference should enable auth on startup");
635
662
  assert.match(server, /await saveRemoteAuthPreference\(true\)/, "enabling Remote PIN auth should persist the on preference");
636
663
  assert.match(server, /await saveRemoteAuthPreference\(false\)/, "disabling Remote PIN auth should persist the off preference");
@@ -690,7 +717,7 @@ assert.match(app, /function setOptionsMenuOpen\(open\)[\s\S]*scheduleMobileDropd
690
717
  assert.match(app, /function focusPromptInput\(\{ defer = false \} = \{\}\)/, "frontend should focus the prompt composer programmatically after tab/app startup");
691
718
  assert.match(app, /async function switchTab\(tabId\)[\s\S]*?restoreActiveDraft\(\);\n\s+focusPromptInput\(\{ defer: true \}\);/, "switching to a newly opened tab should focus the prompt input immediately");
692
719
  assert.match(app, /async function initializeTabs\(\)[\s\S]*?restoreActiveDraft\(\);[\s\S]*if \(!loadedTabs\.length\)[\s\S]*focusPromptInput\(\{ defer: true \}\);/, "starting the Web UI should prompt for cwd when needed and focus active tabs");
693
- assert.match(app, /resizePromptInput\(\);\nrestoreFileViewerWidthPreference\(\);\nfocusPromptInput\(\{ defer: true \}\);\nrestoreStoredSkillUsage\(\);\nrestoreBusyPromptBehaviorSetting\(\);\nupdateComposerModeButtons\(\);/, "startup should restore browser preferences, request prompt focus, and restore skill tags before waiting for tab state refreshes");
720
+ assert.match(app, /resizePromptInput\(\);\nrestoreSidePanelWidthPreference\(\);\nrestoreFileViewerWidthPreference\(\);\nfocusPromptInput\(\{ defer: true \}\);\nrestoreStoredSkillUsage\(\);\nrestoreBusyPromptBehaviorSetting\(\);\nupdateComposerModeButtons\(\);/, "startup should restore resizable panel preferences, request prompt focus, and restore skill tags before waiting for tab state refreshes");
694
721
  assert.match(app, /elements\.promptInput\.addEventListener\("focus", \(\) => \{\n\s+syncMobileChatToBottomForInput\(\);/, "focusing mobile input should scroll output to bottom");
695
722
  assert.match(app, /navigator\.serviceWorker\.register\("\/service-worker\.js"\)/, "PWA service worker should be registered by the app");
696
723
  assert.match(app, /function serverStartCommandText\(\)[\s\S]*return `pi-webui\$\{currentPortArg\(\)\}`/, "PWA/offline shell should build a pathless pi-webui recovery command");
@@ -764,6 +791,13 @@ assert.match(
764
791
  );
765
792
  assert.match(app, /function renderCodexUsage\(\)/, "frontend should render Codex usage buckets in the side panel");
766
793
  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");
794
+ 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");
795
+ assert.match(app, /function subagentLaunchSlotThinkingForModel\(model\)[\s\S]*modelThinkingLevels/, "launch-slot thinking choices should come from the selected model metadata");
796
+ assert.match(app, /function renderSubagentLaunchSlotCard\(role, slots\)[\s\S]*Default \/ inherit[\s\S]*"Add slot"[\s\S]*Remove/, "role cards should render independent same-role slots and inheritance controls");
797
+ assert.match(app, /async function saveSubagentLaunchSlotConfig[\s\S]*scope: subagentLaunchSlotScope,[\s\S]*revision: subagentLaunchSlotConfig\.revision,[\s\S]*body\.roles = cloneLaunchSlotRoles[\s\S]*async function reloadActiveTabForSubagentLaunchSlots[\s\S]*sendPrompt\("prompt", "\/reload"/, "launch-slot saves should be revision checked and offer active-tab reload through the existing path");
798
+ assert.match(app, /const subagentLaunchSlotReloadTabs = new Set\(\)[\s\S]*subagentLaunchSlotReloadTabs\.add\(activeTabId\)[\s\S]*subagentLaunchSlotReloadTabs\.delete\(activeTabId\)/, "reload-required reminders should survive tab switches until that tab is actually reloaded");
799
+ const subagentOverviewRefreshSource = appFunctionSource("refreshSubagents", "scheduleRefreshSubagents");
800
+ assert.doesNotMatch(subagentOverviewRefreshSource, /subagentLaunchSlot/, "live subagent polling must not recreate or reset the launch-slot editor");
767
801
  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");
768
802
  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");
769
803
  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");
@@ -1022,16 +1056,45 @@ assert.match(app, /function renderWorkflowInspectorAgent\(agent, run\)[\s\S]*Pro
1022
1056
  assert.match(app, /canPause[\s\S]*`\/workflow pause \$\{run\.runId\}`[\s\S]*canAbort[\s\S]*`\/workflow abort \$\{run\.runId\}`[\s\S]*Save user[\s\S]*Save project[\s\S]*Raw workflow script/, "WebUI Workflow controls should send canonical extension commands and expose raw scripts");
1023
1057
  assert.match(app, /confirmMessage && !window\.confirm\(confirmMessage\)/, "destructive WebUI Workflow actions should require browser confirmation");
1024
1058
  assert.match(app, /const workflowInspectorByTab = new Map\(\)[\s\S]*workflowInspectorSelectionByTab = new Map\(\)[\s\S]*workflowInspectorMinimizedByTab = new Set\(\)/, "Workflow inspector run, selection, and minimized state should be per tab");
1059
+ assert.match(app, /const workflowTerminalScrollByTab = new Map\(\);\s*const workflowSubprocessMinimizedByTab = new Set\(\);\s*const workflowOverlayMinimizedByTab = new Set\(\);/, "Workflow subprocess and complete-overlay minimize state should be isolated per browser tab");
1060
+ assert.match(app, /function setWorkflowOverlayMinimized\(minimized\)[\s\S]*workflowOverlayMinimizedByTab\.(?:add|delete)[\s\S]*renderWidgets\(\)[\s\S]*workflowOverlayOpenButton[\s\S]*workflow-overlay-close-button[\s\S]*focus\(\{ preventScroll: true \}\)/, "complete Workflow overlay minimize and restore should survive rerenders and move focus to the replacement control");
1061
+ assert.match(app, /function renderWidgets\(\)[\s\S]*if \(!workflowOverlayIsMinimized\(\)\)[\s\S]*attachWorkflowOverlayCloseButton\(workflowInspectorWidget \|\| workflowSubprocessWidget\)[\s\S]*renderWorkflowOverlayControls\(\)/, "the complete Workflow overlay should be omitted while minimized and expose one close control while open");
1062
+ assert.match(app, /workflowOverlayOpenButton\?\.addEventListener\("click", \(\) => setWorkflowOverlayMinimized\(false\)\)/, "the Workflow-button restore affordance should reopen the complete overlay");
1025
1063
  assert.match(app, /function workflowInspectorSetMinimized\(minimized\)[\s\S]*workflowInspectorMinimizedByTab\.(?:add|delete)[\s\S]*renderWidgets\(\)[\s\S]*requestAnimationFrame[\s\S]*workflow-inspector-minimize-button[\s\S]*focus\(\{ preventScroll: true \}\)/, "Workflow inspector minimize state should survive rerenders and restore focus to the replacement control");
1026
1064
  assert.match(app, /function renderWorkflowInspectorWidget\(\)[\s\S]*workflow-inspector-body[\s\S]*workflow-inspector-minimize-button[\s\S]*minimized \? "Restore" : "Minimize"[\s\S]*minimizeButton\.type = "button"[\s\S]*aria-controls[\s\S]*aria-expanded[\s\S]*aria-label[\s\S]*if \(minimized\) return node/, "Workflow inspector should expose an accessible minimize and restore disclosure control");
1027
- assert.match(app, /workflowInspectorMinimizedByTab\.delete\(tabId\)/, "closing a terminal tab should discard its Workflow inspector minimize state");
1065
+ assert.match(app, /function workflowSubprocessSetMinimized\(minimized\)[\s\S]*workflowSubprocessMinimizedByTab\.(?:add|delete)[\s\S]*renderWidgets\(\)[\s\S]*requestAnimationFrame[\s\S]*workflow-subprocess-minimize-button[\s\S]*focus\(\{ preventScroll: true \}\)/, "Workflow subprocess minimize state should survive live rerenders and restore focus to the replacement control");
1066
+ assert.match(app, /function renderWorkflowSubprocessWidget\(\)[\s\S]*workflow-subprocess-body[\s\S]*workflow-subprocess-minimize-button[\s\S]*minimized \? "Restore" : "Minimize"[\s\S]*minimizeButton\.type = "button"[\s\S]*aria-controls[\s\S]*aria-expanded[\s\S]*aria-label[\s\S]*node\.append\(header, body\);\s*if \(minimized\) return node;[\s\S]*body\.append\(outputDetails\)/, "Workflow subprocess output should expose an accessible minimize and restore disclosure control without rebuilding its terminal while minimized");
1067
+ assert.match(app, /workflowInspectorMinimizedByTab\.delete\(tabId\)[\s\S]*workflowSubprocessMinimizedByTab\.delete\(tabId\)[\s\S]*workflowOverlayMinimizedByTab\.delete\(tabId\)/, "closing a terminal tab should discard its Workflow inspector, subprocess, and complete-overlay minimize state");
1028
1068
  assert.match(app, /handleInactiveTabEvent\(event\)[\s\S]*WORKFLOW_INSPECTOR_WIDGET_KEY[\s\S]*updateWorkflowInspectorForTab\(event\.tabId, inspector\)[\s\S]*renderTabs\(\)/, "inactive tabs should consume replayed Workflow inspector payloads for badges");
1029
1069
  assert.match(app, /terminal-tab-workflow-indicator[\s\S]*workflowRunningCountForTab/, "terminal tabs should display Workflow Mode or active-run badges");
1030
1070
  assert.match(css, /\.workflow-inspector-layout \{[\s\S]*grid-template-columns:[\s\S]*\.workflow-inspector-run-list[\s\S]*\.workflow-inspector-agent/, "Workflow inspector should have responsive run and agent layout styling");
1031
- assert.match(css, /\.workflow-inspector-widget\.minimized \{[\s\S]*\.workflow-inspector-minimize-button/, "Workflow inspector should style its minimized state and toggle control");
1071
+ assert.match(css, /\.workflow-inspector-widget\.minimized,[\s\S]*\.workflow-subprocess-widget\.minimized \{[\s\S]*\.workflow-inspector-minimize-button,[\s\S]*\.workflow-subprocess-minimize-button/, "Workflow inspector and subprocess widgets should share visible minimized-state toggle styling");
1072
+ assert.match(css, /\.workflow-subprocess-widget\.minimized > \.release-npm-header \{[\s\S]*?padding-bottom:\s*0;[\s\S]*?border-bottom:\s*0;/, "minimized Workflow subprocess output should collapse its header divider and extra spacing");
1032
1073
  assert.match(css, /\.terminal-tab-workflow-indicator \{[\s\S]*color: var\(--ctp-mauve\)/, "inactive-tab Workflow badges should have a distinct accessible style");
1033
1074
  assert.match(css, /\.composer-workflow-mode-button\.active,[\s\S]*aria-pressed="true"/, "active Workflow Mode toggle should have persistent pressed styling");
1075
+ assert.match(css, /\.composer-workflow-mode-controls\.has-open-control \{[^}]*min-width:\s*1\.95rem;[^}]*min-height:\s*1\.95rem;/, "Workflow restore should retain an anchored box even if the Workflow Mode button is unavailable");
1076
+ assert.match(css, /\.composer-workflow-overlay-open-button \{[\s\S]*position:\s*absolute;[\s\S]*border-radius:\s*999px;[\s\S]*\.workflow-overlay-close-button \{/, "Workflow restore should use a visible helper badge and the complete overlay should expose a distinct close action");
1034
1077
  assert.match(css, /\.composer\.workflow-mode-active[\s\S]*body\.workflow-mode-active \.composer::before/, "active Workflow Mode should visibly accent the composer");
1078
+
1079
+ // Workflow raw-script inspector: narrowly specialized, structurally read-only, and viewport-safe.
1080
+ const workflowPreviewRequestSource = appFunctionSource("isWorkflowScriptPreviewRequest", "workflowScriptTokenClass");
1081
+ const workflowTokenRenderSource = appFunctionSource("appendWorkflowScriptTokens", "renderWorkflowScriptPreview");
1082
+ const workflowPreviewSource = appFunctionSource("renderWorkflowScriptPreview", "showNextDialog");
1083
+ const workflowDialogSource = appFunctionSource("showNextDialog", "handleInactiveTabEvent");
1084
+ assert.match(workflowPreviewRequestSource, /request\?\.method === "editor"[\s\S]*title\.startsWith\("Raw workflow script"\)[\s\S]*inspection only;\\s\*edits are ignored/, "workflow inspector specialization should require the editor method, raw-script title, and inspection-only wording");
1085
+ assert.match(workflowDialogSource, /else if \(isWorkflowScriptPreview\) \{\s*renderWorkflowScriptPreview\(request\);\s*\} else if \(request\.method === "editor"\) \{\s*const textarea = make\("textarea", "dialog-editor"\);[\s\S]*textarea\.value = request\.prefill \|\| ""/, "workflow previews should specialize before the unchanged generic editor textarea fallback");
1086
+ assert.doesNotMatch(workflowPreviewSource, /\btextarea\b/, "workflow previews should not create an editable textarea");
1087
+ assert.match(workflowTokenRenderSource, /document\.createTextNode\(line\.slice\(start, match\.index\)\)[\s\S]*make\("span", `workflow-script-token/, "workflow syntax tokens should be built from DOM text nodes and spans");
1088
+ assert.doesNotMatch(workflowTokenRenderSource, /innerHTML|insertAdjacentHTML/, "workflow syntax token rendering should not inject source through HTML APIs");
1089
+ assert.match(workflowPreviewSource, /search\.type = "search"[\s\S]*Previous match[\s\S]*Next match[\s\S]*Wrap lines[\s\S]*Copy source/, "workflow inspector should expose search navigation, wrap, and copy controls");
1090
+ assert.match(workflowPreviewSource, /search\.addEventListener\("keydown", \(event\) => \{\s*if \(event\.key !== "Enter"\) return;\s*event\.preventDefault\(\);\s*if \(matchingLineIndexes\.length === 0\) return;\s*setActiveMatch\(activeMatchIndex \+ \(event\.shiftKey \? -1 : 1\)\);\s*\}\);/, "workflow search should prevent Enter form submission before returning for no matches and navigate only when matches exist");
1091
+ assert.match(workflowPreviewSource, /workflow-script-search-status[\s\S]*aria-live", "polite"[\s\S]*workflow-script-copy-status[\s\S]*aria-live", "polite"/, "workflow search and copy feedback should be announced");
1092
+ assert.match(workflowPreviewSource, /addDialogButton\("Cancel workflow"[\s\S]*cancelled: true[\s\S]*addDialogButton\("Back to approval"[\s\S]*value: request\.prefill/, "workflow inspector actions should cancel explicitly or return the original prefill unchanged");
1093
+ assert.match(css, /\.extension-dialog\.workflow-script-dialog \{[\s\S]*width: min\(96rem, calc\(100vw - 2rem\)\)[\s\S]*height: min\(58rem, calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\)\)[\s\S]*overflow: hidden/, "workflow inspector should use a large visual-viewport-bounded desktop dialog");
1094
+ assert.match(css, /\.workflow-script-toolbar \{[\s\S]*grid-template-columns: minmax\(12rem, 1fr\) repeat\(4, auto\)[\s\S]*\.workflow-script-code \{[\s\S]*overflow: auto[\s\S]*font-family: ui-monospace[\s\S]*\.workflow-script-line-number \{[\s\S]*position: sticky/, "workflow inspector should style its toolbar, scrollable code surface, and persistent line-number gutter");
1095
+ assert.match(css, /\.workflow-script-code\.is-wrapped[\s\S]*white-space: pre-wrap[\s\S]*\.workflow-script-line\.is-search-match[\s\S]*\.workflow-script-line\.is-active-match[\s\S]*box-shadow:/, "workflow inspector should distinguish matches and support soft wrapping");
1096
+ assert.match(css, /\.workflow-script-code:focus-visible[\s\S]*outline:[\s\S]*\.workflow-script-token-keyword[\s\S]*var\(--ctp-mauve\)[\s\S]*\.workflow-script-token-string[\s\S]*var\(--ctp-green\)[\s\S]*\.workflow-script-token-number[\s\S]*var\(--ctp-peach\)[\s\S]*\.workflow-script-token-comment[\s\S]*var\(--ctp-subtext\)/, "workflow inspector should provide a visible focus ring and high-contrast token colors");
1097
+ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(pointer: coarse\) and \(hover: none\) \{[\s\S]*\.extension-dialog\.workflow-script-dialog \{[\s\S]*height: calc\(var\(--visual-viewport-height, 100dvh\) - 0\.25rem - env\(safe-area-inset-top\)\)[\s\S]*\.workflow-script-toolbar \{[\s\S]*grid-template-columns: repeat\(2, minmax\(0, 1fr\)\)[\s\S]*\.workflow-script-dialog #dialogActions \{[\s\S]*grid-template-columns: repeat\(2, minmax\(0, 1fr\)\)/, "workflow inspector mobile bottom sheet should respect the visual viewport and keep controls reachable");
1035
1098
  // Phase 3: browser voice loop (Web Speech STT/TTS) wiring.
1036
1099
  const voiceModule = await readFile(join(root, "public", "voice-conversation.mjs"), "utf8");
1037
1100
  assert.match(voiceModule, /export function createVoiceConversationController\(options = \{\}\)/, "voice loop should live in a dependency-injected module for Node tests");
@@ -1155,7 +1218,13 @@ assert.match(server, /function addCppRunners\(runners, cwd\)[\s\S]*C\/C\+\+ CMak
1155
1218
  assert.match(server, /function addDockerComposeRunner\(runners, cwd\)[\s\S]*docker compose up[\s\S]*docker-compose up/, "server should detect Docker Compose runners");
1156
1219
  assert.match(server, /APP_RUNNER_SHELL_SCRIPT_DIRS = \["", "dev", "scripts", "dev\/scripts"\][\s\S]*function addShellScriptRunners\(runners, cwd\)/, "server should detect bash\/zsh\/fish scripts in root, dev, scripts, and dev\/scripts");
1157
1220
  assert.match(app, /const releaseNpmOutputExpandedByTab = new Map\(\)/, "release-npm output collapse state should be tracked per browser tab");
1221
+ assert.match(app, /const workflowTerminalScrollByTab = new Map\(\)/, "workflow terminal follow state should be isolated per browser tab");
1158
1222
  assert.match(app, /function renderReleaseNpmOutputDetails\(key, streamHeader, terminal, controls = null\)[\s\S]*node\.open = releaseNpmOutputExpandedByTab\.get\(stateKey\) !== false[\s\S]*release-npm-output-toggle/, "release-npm output should render as a browser-side details expander");
1223
+ assert.match(app, /function workflowMetaItem\(label, value[\s\S]*workflow-meta-label[\s\S]*workflow-meta-value[\s\S]*workflow-meta-description/, "workflow metadata should pair human-readable labels and values with an optional visible description");
1224
+ assert.match(app, /function bindWorkflowTerminalScroll\([\s\S]*Auto-follow paused[\s\S]*distanceFromBottom <= 24[\s\S]*requestAnimationFrame\(restorePosition\)/, "workflow output should preserve reading position and follow only near the live tail");
1225
+ assert.match(app, /meta\.setAttribute\("role", "group"\)[\s\S]*meta\.setAttribute\("aria-label", "Workflow run summary"\)[\s\S]*"Limited history"[\s\S]*"Older output omitted from this view\."/, "workflow subprocess metadata should expose an accessible group and visible output-limit explanation");
1226
+ assert.match(app, /terminal\.dataset\.preserveScrollOnToggle = "true"[\s\S]*bindWorkflowTerminalScroll\(terminal, outputDetails, followStatus, \{ live, runId: payload\.runId \}\)/, "workflow output should opt into its own position restoration without changing shared terminal toggles");
1227
+ assert.match(app, /workflowMetaItem\("Run"[\s\S]*workflowMetaItem\("Phase"[\s\S]*workflowMetaItem\("Tasks"[\s\S]*"Limited history"/, "workflow subprocess summary should distinguish status, phase, task progress, and limited output history");
1159
1228
  assert.match(app, /releaseNpmStreamHeader\("Live output stream", outputLines\.length, \{ live: true \}\)/, "release-npm live output should expose a clear stream heading");
1160
1229
  assert.match(app, /renderReleaseNpmOutputDetails\("release-npm:output", streamHeader, terminal, controls\)/, "release-npm live stream should be wrapped in the local expander");
1161
1230
  assert.match(app, /function renderReleaseAurOutputWidget\(\)/, "release-aur live output should use a specialized Web UI renderer");
@@ -1479,9 +1548,9 @@ assert.match(readme, /Tracked subagent output[\s\S]*dedicated \*\*Subagent\*\* t
1479
1548
  assert.match(app, /let tabSeenCompletionSerials = new Map\(\)/, "frontend should track which tab completions have been seen");
1480
1549
  assert.match(app, /let activeTabGeneration = 0/, "frontend should version active-tab UI state to reject stale async work");
1481
1550
  assert.match(app, /function isCurrentTabContext\(context\)/, "frontend should identify stale active-tab refresh contexts");
1482
- assert.match(app, /function connectEvents\(tabContext = activeTabContext\(\)\)[\s\S]*?eventSource !== source/, "frontend should ignore stale SSE messages from old active tabs");
1551
+ assert.match(app, /function connectEvents\(tabContext = activeTabContext\(\), \{ requestedMode = "auto", fallbackAttempted = false \} = \{\}\)[\s\S]*?eventSource !== source/, "frontend should ignore stale SSE messages from old active tabs");
1483
1552
  assert.match(app, /let foregroundReconcileTimer = null/, "frontend should debounce foreground resume reconciliation");
1484
- assert.match(app, /case "webui_connected":[\s\S]*?scheduleForegroundReconcile\("event stream reconnect", 0\)/, "SSE reconnect should reconcile authoritative state and messages instead of only tabs");
1553
+ assert.match(app, /case "webui_connected":[\s\S]*?featureCategoryByTab\.delete\(connectedTabId\)[\s\S]*?renderFeatureCategoryTag\(connectedTabId\)[\s\S]*?scheduleForegroundReconcile\("event stream reconnect", 0\)/, "SSE reconnect should clear cached feature-category absence before replaying authoritative statuses and reconciling state");
1485
1554
  assert.match(app, /async function reconcileForegroundState\(reason = "resume"\)[\s\S]*?refreshTabs\(\)[\s\S]*?ensureActiveEventStream\(tabContext\)[\s\S]*?refreshAll\(tabContext\)/, "foreground reconciliation should refresh tabs plus active transcript after mobile backgrounding");
1486
1555
  assert.match(app, /document\.addEventListener\("visibilitychange"[\s\S]*?scheduleForegroundReconcile\("visibility resume", 0\)/, "returning to a hidden mobile tab should force a server snapshot refresh");
1487
1556
  assert.match(app, /window\.addEventListener\("pageshow", \(\) => scheduleForegroundReconcile\("page show", 0\)\)/, "BFCache or PWA page resume should force a server snapshot refresh");
@@ -1543,6 +1612,7 @@ assert.match(serviceWorker, /fetchThenCache\(request\)\.catch\(/, "PWA service w
1543
1612
  assert.match(serviceWorker, /ignoreSearch: true/, "PWA service worker offline fallback should ignore ?v= cache busters");
1544
1613
  assert.match(serviceWorker, /self\.addEventListener\("notificationclick"/, "PWA service worker should focus Web UI when blocked-tab notifications are clicked");
1545
1614
  assert.match(serviceWorker, /event\.notification\.data\?\.url/, "blocked-tab notifications should carry a URL for service-worker click handling");
1615
+ assert.match(serviceWorker, /"\/subagent-launch-slot-state\.mjs"/, "PWA service worker should cache the launch-slot state module imported by the app shell");
1546
1616
  assert.match(serviceWorker, /"\/apple-touch-icon\.png"/, "PWA service worker should cache the apple touch icon");
1547
1617
  assert.match(serviceWorker, /"\/matrix-background\.webp"/, "PWA service worker should cache the Matrix background image");
1548
1618
  assert.match(serviceWorker, /"\/catppuccin-mocha-background\.png"/, "PWA service worker should cache the Catppuccin Mocha background image");
@@ -1587,10 +1657,10 @@ assert.match(server, /function rememberExtensionWidgetEvent\(tab, event\)[\s\S]*
1587
1657
  assert.match(server, /rememberExtensionStatusEvent\(tab, scopedEvent\)[\s\S]*rememberExtensionWidgetEvent\(tab, scopedEvent\)[\s\S]*trackPendingExtensionUiRequest\(tab, scopedEvent\)/, "RPC events should retain extension statuses and widgets before broadcasting");
1588
1658
  assert.match(server, /trackPendingExtensionUiRequest\(tab, scopedEvent\)/, "RPC events should populate pending extension UI storage before broadcasting");
1589
1659
  assert.match(server, /scopedEvent = \{ \.\.\.scopedEvent,[\s\S]*?pendingExtensionUiRequestCount: pendingExtensionUiRequests\(tab\)\.length \}/, "RPC events should broadcast pending blocker counts for tab indicators");
1590
- assert.match(server, /function replayExtensionStatuses\(tab, res\)[\s\S]*method: "setStatus"/, "server should replay latest extension statuses on SSE reconnect");
1591
- assert.match(server, /function replayExtensionWidgets\(tab, res\)[\s\S]*method: "setWidget"/, "server should replay latest extension widgets on SSE reconnect");
1592
- assert.match(server, /function replayPendingExtensionUiRequests\(tab, res\)/, "server should be able to replay missed extension UI requests on SSE reconnect");
1593
- assert.match(server, /replayExtensionStatuses\(tab, res\);\n\s+replayExtensionWidgets\(tab, res\);\n\s+replayPendingExtensionUiRequests\(tab, res\)/, "SSE connections should replay extension statuses and widgets before pending blockers");
1660
+ assert.match(server, /function replayExtensionStatuses\(tab, client\)[\s\S]*method: "setStatus"/, "server should replay latest extension statuses on SSE reconnect");
1661
+ assert.match(server, /function replayExtensionWidgets\(tab, client\)[\s\S]*method: "setWidget"/, "server should replay latest extension widgets on SSE reconnect");
1662
+ assert.match(server, /function replayPendingExtensionUiRequests\(tab, client\)/, "server should be able to replay missed extension UI requests on SSE reconnect");
1663
+ assert.match(server, /replayExtensionStatuses\(tab, client\);\n\s+replayExtensionWidgets\(tab, client\);\n\s+replayPendingExtensionUiRequests\(tab, client\)/, "SSE connections should replay extension statuses and widgets before pending blockers");
1594
1664
  assert.match(server, /pendingExtensionUiRequests: pendingExtensionUiRequestSummaries\(tab\)/, "detailed Web UI status should expose pending extension UI blockers");
1595
1665
  assert.match(server, /resolvePendingExtensionUiRequest\(tab, payload\.id\)/, "extension UI responses should clear the pending blocker cache");
1596
1666
  assert.match(server, /type: "webui_extension_ui_resolved"[\s\S]*?pendingExtensionUiRequestCount/, "extension UI responses should notify clients that a blocker resolved");
@@ -1722,6 +1792,7 @@ assert.match(server, /writeFile\(tmpFile, body\.content[\s\S]*?rename\(tmpFile,
1722
1792
  assert.match(server, /url\.pathname === "\/api\/themes" && req\.method === "GET"/, "server should expose GET /api/themes");
1723
1793
  assert.match(server, /readBundledThemes\(\)/, "server should read bundled theme JSON files for the browser");
1724
1794
  assert.match(server, /"apple-touch-icon\.png", "icon-192\.png"/, "server should serve the conventional apple touch icon path");
1795
+ assert.match(server, /"fast-output-live\.mjs", "subagent-launch-slot-state\.mjs", "voice-conversation\.mjs"/, "server should serve the launch-slot state module imported by the browser app");
1725
1796
  assert.match(server, /"catppuccin-mocha-background\.png", "matrix-background\.webp", "manifest\.webmanifest", "service-worker\.js"/, "server should serve theme background images as static assets");
1726
1797
  assert.match(server, /\["\.webmanifest", "application\/manifest\+json; charset=utf-8"\]/, "server should serve manifest with the correct MIME type");
1727
1798
  assert.match(server, /\["\.png", "image\/png"\]/, "server should serve PWA PNG icons with the correct MIME type");
@@ -136,7 +136,7 @@ try {
136
136
  const disableAuth = await request("/api/remote-auth/settings", { method: "POST", body: { enabled: false } });
137
137
  assert.equal(disableAuth.status, 200);
138
138
  const savedAfterDisable = JSON.parse(await readFile(settingsFile, "utf8"));
139
- assert.equal(savedAfterDisable.version, 3, "Web UI settings should migrate to the resource-default schema version");
139
+ assert.equal(savedAfterDisable.version, 4, "Web UI settings should migrate to the output-mode schema version");
140
140
  assert.equal(savedAfterDisable.remoteAuthEnabled, false, "disabling Remote PIN auth should persist the off preference");
141
141
  assert.equal(savedAfterDisable.gitWorkflow?.generation?.modelId, "fake-model", "Remote PIN updates should preserve guided Git preferences");
142
142
 
@@ -0,0 +1,43 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
8
+ const html = fs.readFileSync(path.join(root, "public/index.html"), "utf8");
9
+ const css = fs.readFileSync(path.join(root, "public/styles.css"), "utf8");
10
+ const app = fs.readFileSync(path.join(root, "public/app.js"), "utf8");
11
+
12
+ test("Control Deck exposes an accessible resize separator", () => {
13
+ assert.match(html, /id="sidePanelResizeHandle"[^>]*role="separator"[^>]*aria-orientation="vertical"[^>]*aria-label="Resize Control Deck width"[^>]*tabindex="0"/);
14
+ assert.match(css, /--side-panel-width:\s*384px/);
15
+ assert.match(css, /\.side-panel-resize-handle[\s\S]*cursor:\s*col-resize[\s\S]*touch-action:\s*none/);
16
+ });
17
+
18
+ test("desktop layouts and Control Deck content follow the selected width", () => {
19
+ assert.match(css, /\.layout \{[\s\S]*grid-template-columns:\s*minmax\(0, 1fr\) minmax\(20rem, var\(--side-panel-width\)\)/);
20
+ assert.match(css, /body\.file-viewer-open \.layout \{[\s\S]*minmax\(24rem, var\(--file-viewer-width\)\) minmax\(20rem, var\(--side-panel-width\)\)/);
21
+ assert.match(css, /body\.terminal-split-open\.file-viewer-open \.layout \{[\s\S]*minmax\(20rem, var\(--side-panel-width\)\)/);
22
+ assert.match(css, /\.side-panel \{[\s\S]*width:\s*100%;[\s\S]*min-width:\s*0/);
23
+ });
24
+
25
+ test("Control Deck width is clamped, persisted, pointer-resizable, and keyboard-resizable", () => {
26
+ assert.match(app, /const SIDE_PANEL_WIDTH_STORAGE_KEY = "pi-webui-side-panel-width"/);
27
+ assert.match(app, /function sidePanelMaxWidth\(\)[\s\S]*fileViewerVisible[\s\S]*splitOpen[\s\S]*primaryMinWidth[\s\S]*available/);
28
+ assert.match(app, /function applySidePanelWidth\(width, \{ persist = false \} = \{\}\)[\s\S]*--side-panel-width[\s\S]*persistSidePanelWidth/);
29
+ assert.match(app, /function beginSidePanelResize\(event\)[\s\S]*setPointerCapture[\s\S]*pointermove[\s\S]*pointercancel/);
30
+ assert.match(app, /function updateSidePanelResize\(event\)[\s\S]*state\.startWidth \+ \(state\.startX - event\.clientX\)/);
31
+ assert.match(app, /function handleSidePanelResizeKeydown\(event\)[\s\S]*ArrowLeft[\s\S]*ArrowRight[\s\S]*Home[\s\S]*End/);
32
+ assert.match(app, /elements\.sidePanelResizeHandle\?\.addEventListener\("pointerdown", beginSidePanelResize\);\nelements\.sidePanelResizeHandle\?\.addEventListener\("keydown", handleSidePanelResizeKeydown\);/);
33
+ });
34
+
35
+ test("Control Deck resizing disables itself in overlay layouts and responds to viewport changes", () => {
36
+ assert.match(app, /const resizeAvailable = !isSidePanelOverlayView\(\) && !document\.body\.classList\.contains\("side-panel-collapsed"\)/);
37
+ assert.match(css, /@media \(max-width: 1050px\)[\s\S]*\.file-viewer-resize-handle,[\s\S]*\.side-panel-resize-handle \{\s*display:\s*none/);
38
+ assert.match(app, /window\.addEventListener\("resize", syncResizablePanelWidthsForViewport/);
39
+ assert.match(app, /function updateFileViewerUi\(\)[\s\S]*requestAnimationFrame\(syncResizablePanelWidthsForViewport\)/);
40
+ assert.match(app, /function closeFileViewer\(\)[\s\S]*requestAnimationFrame\(syncResizablePanelWidthsForViewport\)/);
41
+ assert.match(app, /function updateTerminalSplitUi\(\)[\s\S]*requestAnimationFrame\(syncResizablePanelWidthsForViewport\)/);
42
+ assert.match(app, /restoreSidePanelWidthPreference\(\);\nrestoreFileViewerWidthPreference\(\);/);
43
+ });
@@ -0,0 +1,36 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ addLaunchSlot,
4
+ cloneLaunchSlotRoles,
5
+ launchSlotRolesEqual,
6
+ removeLaunchSlot,
7
+ updateLaunchSlot,
8
+ } from "../public/subagent-launch-slot-state.mjs";
9
+
10
+ const initial = {
11
+ reviewer: [{ id: "reviewer:base", model: "anthropic/reviewer", thinking: "high" }],
12
+ worker: [{ id: "worker:base", model: null, thinking: null }],
13
+ };
14
+ const snapshot = cloneLaunchSlotRoles(initial);
15
+
16
+ const added = addLaunchSlot(initial, "reviewer", "reviewer:base", {
17
+ slotsPerRole: 8,
18
+ totalSlots: 32,
19
+ createId: () => "reviewer:slot-1",
20
+ });
21
+ assert.ok(added, "an available role capacity should create a slot");
22
+ assert.deepEqual(added.slot, { id: "reviewer:slot-1", model: "anthropic/reviewer", thinking: "high" }, "added slots should copy the source draft");
23
+ assert.equal(initial.reviewer.length, 1, "adding should not mutate the saved draft");
24
+ assert.equal(launchSlotRolesEqual(initial, added.roles), false, "a new slot should mark the draft dirty");
25
+
26
+ const changedModel = updateLaunchSlot(added.roles, "reviewer", "reviewer:slot-1", { model: null });
27
+ assert.deepEqual(changedModel.reviewer[1], { id: "reviewer:slot-1", model: null, thinking: null }, "inheriting a model should reset thinking inheritance");
28
+
29
+ const removed = removeLaunchSlot(added.roles, "reviewer", "reviewer:slot-1");
30
+ assert.ok(removed, "added slots should be removable");
31
+ assert.equal(removed.focusSlotId, "reviewer:base", "removal should return a sensible preceding focus target");
32
+ assert.equal(launchSlotRolesEqual(snapshot, removed.roles), true, "removing the added slot should restore a clean draft");
33
+ assert.equal(removeLaunchSlot(initial, "reviewer", "reviewer:base"), null, "base slots must remain non-removable");
34
+ assert.equal(addLaunchSlot(initial, "reviewer", "reviewer:base", { totalSlots: 2, createId: () => "reviewer:slot-2" }), null, "the total cap should prevent extra slots");
35
+
36
+ console.log("subagent-launch-slot-state.test.mjs passed");
@@ -0,0 +1,34 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
+ const [html, app, css, server, serviceWorker, pkg] = await Promise.all([
8
+ readFile(join(root, "public", "index.html"), "utf8"),
9
+ readFile(join(root, "public", "app.js"), "utf8"),
10
+ readFile(join(root, "public", "styles.css"), "utf8"),
11
+ readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
12
+ readFile(join(root, "public", "service-worker.js"), "utf8"),
13
+ readFile(join(root, "package.json"), "utf8"),
14
+ ]);
15
+
16
+ assert.match(html, /<details id="subagentLaunchSlots" class="subagent-launch-slots">[\s\S]*<summary class="subagent-launch-slots-summary">[\s\S]*id="subagentLaunchSlotsTitle">Agent models<[\s\S]*id="subagentLaunchSlotRoles"[\s\S]*id="subagentsStatus"[\s\S]*id="subagentsBox"/, "launch-slot configuration should be a native collapsible surface separate from the live monitor");
17
+ assert.doesNotMatch(html, /<details id="subagentLaunchSlots"[^>]*\sopen(?:\s|>)/, "Agent models should start collapsed to keep the Subagents panel compact");
18
+ assert.match(html, /id="subagentLaunchSlotScope"[^>]*aria-describedby="subagentLaunchSlotScopeStatus"/, "scope selection should use stable accessible help");
19
+ assert.match(html, /id="subagentLaunchSlotsAnnouncer"[^>]*aria-live="polite"[^>]*aria-atomic="true"/, "slot changes should be announced accessibly");
20
+ assert.match(app, /from "\.\/subagent-launch-slot-state\.mjs"/, "the browser should use the pure launch-slot state helper");
21
+ assert.match(app, /const subagentLaunchSlotReloadTabs = new Set\(\)[\s\S]*subagentLaunchSlotReloadTabs\.add\(activeTabId\)[\s\S]*subagentLaunchSlotReloadTabs\.delete\(activeTabId\)/, "reload reminders should be tracked per tab until reload");
22
+ assert.match(app, /subagentLaunchSlotsSummaryStatus\.textContent[\s\S]*"Unsaved changes"[\s\S]*"Saved · reload this tab"[\s\S]*subagentLaunchSlots\.open = true/, "the collapsed summary should surface state and reopen for errors or required reloads");
23
+ assert.doesNotMatch(app, /`(?:Model|Thinking) · \$\{slotLabel\}`/, "visible field labels should stay compact while aria-labels retain slot context");
24
+ assert.match(app, /api\(`\/api\/subagents\/config\?\$\{query\}`/, "the editor should load configuration through the tab-scoped API");
25
+ assert.match(app, /api\("\/api\/subagents\/config", \{ method: "POST", body, scoped: false \}\)/, "the editor should save through the localhost-scoped configuration API");
26
+ assert.match(css, /\.subagent-launch-slots \{[\s\S]*container: subagent-launch-slots \/ inline-size[\s\S]*@container subagent-launch-slots \(max-width: 30rem\)[\s\S]*\.subagent-launch-slot-controls \{ grid-template-columns: minmax\(0, 1fr\); \}/, "launch-slot controls should respond to the narrow side-panel container rather than only the viewport");
27
+ assert.match(css, /\.subagent-launch-slot-controls \{[\s\S]*grid-column: 1 \/ -1/, "model and thinking controls should own the full slot-row width before responsive stacking");
28
+ assert.match(css, /\.sr-only \{[\s\S]*clip-path: inset\(50%\)[\s\S]*white-space: nowrap/, "screen-reader announcements should stay visually hidden without leaving the accessibility tree");
29
+ assert.match(css, /\.subagent-launch-slot-remove \{[^}]*color: var\(--ctp-red\)/, "destructive slot removal should have a textual control and warning color");
30
+ assert.match(server, /"subagent-launch-slot-state\.mjs"/, "the pure browser module should be on the static allowlist");
31
+ assert.match(serviceWorker, /pi-webui-pwa-v44[\s\S]*"\/subagent-launch-slot-state\.mjs"/, "the refreshed PWA cache should include the browser module");
32
+ assert.match(pkg, /node --check public\/subagent-launch-slot-state\.mjs/, "package checks should syntax-check the browser state module");
33
+
34
+ console.log("subagent-launch-slots-static.test.mjs passed");
@@ -0,0 +1,143 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import {
6
+ SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG,
7
+ defaultSubagentLaunchSlotRoles,
8
+ formatSubagentLaunchSlotGuidance,
9
+ normalizeSubagentLaunchSlots,
10
+ resolveSubagentLaunchSlotProjectKey,
11
+ subagentLaunchSlotBaseId,
12
+ subagentLaunchSlotRevision,
13
+ subagentLaunchSlotScopeEntry,
14
+ validateSubagentLaunchSlotRoles,
15
+ } from "../lib/subagent-launch-slots.mjs";
16
+ import { readWebuiSettings, updateWebuiSettings, writeWebuiSettings } from "../lib/git-workflow-preferences.mjs";
17
+
18
+ function clone(value) {
19
+ return JSON.parse(JSON.stringify(value));
20
+ }
21
+
22
+ const defaultRoles = defaultSubagentLaunchSlotRoles();
23
+ assert.deepEqual(Object.keys(defaultRoles), SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG.map((role) => role.id));
24
+ for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
25
+ assert.deepEqual(defaultRoles[role.id], [{ id: subagentLaunchSlotBaseId(role.id), model: null, thinking: null }]);
26
+ }
27
+
28
+ const normalized = normalizeSubagentLaunchSlots({
29
+ user: {
30
+ roles: {
31
+ reviewer: [
32
+ { id: "reviewer-extra", model: "fake/reasoning", thinking: "high" },
33
+ { id: "reviewer:base", model: "fake/legacy:high", thinking: "high" },
34
+ { id: "reviewer-extra", model: "fake/reasoning", thinking: "high" },
35
+ { id: "unsafe id", model: "fake/reasoning", thinking: "high" },
36
+ ],
37
+ },
38
+ },
39
+ projects: {
40
+ relative: { roles: { reviewer: [{ id: "reviewer:base", model: "fake/reasoning", thinking: "high" }] } },
41
+ },
42
+ });
43
+ assert.equal(normalized.user.roles.reviewer[0].id, "reviewer:base", "normalization must materialize and order the stable base slot first");
44
+ assert.equal(normalized.user.roles.reviewer[0].model, null, "thinking-suffixed persisted model IDs must reset to inheritance");
45
+ assert.deepEqual(normalized.user.roles.reviewer.slice(1), [{ id: "reviewer-extra", model: "fake/reasoning", thinking: "high" }]);
46
+ assert.deepEqual(normalized.projects, {}, "unsafe project keys must be dropped without changing user defaults");
47
+ const overloadedRoles = defaultSubagentLaunchSlotRoles();
48
+ for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
49
+ overloadedRoles[role.id].push(...Array.from({ length: 7 }, (_unused, index) => ({
50
+ id: `${role.id}-extra-${index}`,
51
+ model: null,
52
+ thinking: null,
53
+ })));
54
+ }
55
+ const boundedRoles = normalizeSubagentLaunchSlots({ user: { roles: overloadedRoles } }).user.roles;
56
+ assert.equal(Object.values(boundedRoles).flat().length, 32, "normalization must cap slots globally while retaining all role bases");
57
+ for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
58
+ assert.equal(boundedRoles[role.id][0].id, subagentLaunchSlotBaseId(role.id), "global bounds must never displace a role base slot");
59
+ }
60
+
61
+ const availableModels = [
62
+ { provider: "fake", id: "reasoning", reasoning: true, thinkingLevelMap: { xhigh: "xhigh" } },
63
+ { provider: "fake", id: "basic", reasoning: false },
64
+ ];
65
+ const validRoles = clone(defaultRoles);
66
+ validRoles.reviewer[0] = { id: "reviewer:base", model: "fake/reasoning", thinking: "high" };
67
+ validRoles.reviewer.push({ id: "reviewer-extra", model: "fake/basic", thinking: "off" });
68
+ assert.deepEqual(validateSubagentLaunchSlotRoles(validRoles, availableModels).reviewer, validRoles.reviewer);
69
+ assert.throws(() => validateSubagentLaunchSlotRoles({ ...validRoles, unknown: [] }, availableModels), /Unknown subagent role/);
70
+ assert.throws(() => validateSubagentLaunchSlotRoles({ ...validRoles, reviewer: [{ id: "reviewer-extra", model: null, thinking: null }] }, availableModels), /base slot/);
71
+ assert.throws(() => validateSubagentLaunchSlotRoles({ ...validRoles, reviewer: [{ id: "reviewer:base", model: null, thinking: "high" }] }, availableModels), /cannot set thinking/);
72
+ assert.throws(() => validateSubagentLaunchSlotRoles({ ...validRoles, reviewer: [{ id: "reviewer:base", model: "fake/reasoning:high", thinking: "high" }] }, availableModels), /invalid model/);
73
+ assert.throws(() => validateSubagentLaunchSlotRoles({ ...validRoles, reviewer: [{ id: "reviewer:base", model: "fake/basic", thinking: "high" }] }, availableModels), /does not support/);
74
+
75
+ const projectRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-launch-slots-project-"));
76
+ const nested = path.join(projectRoot, "nested", "child");
77
+ const settingsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-launch-slots-settings-"));
78
+ const settingsFile = path.join(settingsRoot, "settings.json");
79
+ try {
80
+ await mkdir(path.join(projectRoot, ".git"));
81
+ await mkdir(nested, { recursive: true });
82
+ const projectKey = await resolveSubagentLaunchSlotProjectKey(nested);
83
+ assert.equal(projectKey, projectRoot, "nested tab cwd must resolve to the nearest canonical repository root");
84
+ const markerlessProjectKey = await resolveSubagentLaunchSlotProjectKey(settingsRoot);
85
+ assert.equal(markerlessProjectKey, settingsRoot, "a markerless tab cwd must not collapse to the filesystem root");
86
+
87
+ const config = normalizeSubagentLaunchSlots({ user: { roles: validRoles } });
88
+ const inherited = subagentLaunchSlotScopeEntry(config, "project", projectKey);
89
+ assert.equal(inherited.inherited, true);
90
+ assert.deepEqual(inherited.entry.roles.reviewer, validRoles.reviewer);
91
+ const inheritedRevision = subagentLaunchSlotRevision(config, "project", projectKey);
92
+ config.projects[projectKey] = { roles: clone(defaultRoles) };
93
+ const explicit = subagentLaunchSlotScopeEntry(config, "project", projectKey);
94
+ assert.equal(explicit.inherited, false);
95
+ assert.notEqual(subagentLaunchSlotRevision(config, "project", projectKey), inheritedRevision, "project revisions must distinguish inheritance from an explicit project entry");
96
+
97
+ const guidance = formatSubagentLaunchSlotGuidance(inherited.entry.roles);
98
+ assert.match(guidance, /^## WebUI subagent launch slots/m);
99
+ assert.match(guidance, /reviewer slot 1: agent=reviewer model=fake\/reasoning:high/);
100
+ assert.match(guidance, /reviewer slot 2: agent=reviewer model=fake\/basic:off/);
101
+ const mixedGuidanceRoles = clone(defaultRoles);
102
+ mixedGuidanceRoles.reviewer.push({ id: "reviewer-explicit", model: "fake/reasoning", thinking: "high" });
103
+ const mixedGuidance = formatSubagentLaunchSlotGuidance(mixedGuidanceRoles);
104
+ assert.match(mixedGuidance, /reviewer slot 1: agent=reviewer model=<inherit; omit the model field>/, "mixed same-role guidance must retain inherited slots");
105
+ assert.match(mixedGuidance, /reviewer slot 2: agent=reviewer model=fake\/reasoning:high/);
106
+ assert.equal(formatSubagentLaunchSlotGuidance(defaultRoles), "", "guidance should be omitted when every slot inherits");
107
+
108
+ await writeFile(settingsFile, `${JSON.stringify({ version: 4, unrelated: { preserve: true }, remoteAuthEnabled: true }, null, 2)}\n`, "utf8");
109
+ await writeWebuiSettings({ subagentLaunchSlots: config }, settingsFile);
110
+ const persisted = JSON.parse(await readFile(settingsFile, "utf8"));
111
+ assert.equal(persisted.version, 5, "persisted launch-slot settings must use the version-5 envelope");
112
+ assert.deepEqual(persisted.unrelated, { preserve: true }, "launch-slot saves must preserve unrelated WebUI settings");
113
+ assert.deepEqual((await readWebuiSettings(settingsFile)).subagentLaunchSlots.projects[projectKey].roles, defaultRoles);
114
+
115
+ let releaseFirstUpdate;
116
+ let markFirstUpdateStarted;
117
+ const firstUpdateStarted = new Promise((resolve) => { markFirstUpdateStarted = resolve; });
118
+ const holdFirstUpdate = new Promise((resolve) => { releaseFirstUpdate = resolve; });
119
+ const firstUpdate = updateWebuiSettings(async () => {
120
+ markFirstUpdateStarted();
121
+ await holdFirstUpdate;
122
+ return { remoteAuthEnabled: false };
123
+ }, settingsFile);
124
+ await firstUpdateStarted;
125
+ let secondUpdateEntered = false;
126
+ const secondUpdate = updateWebuiSettings((current) => {
127
+ secondUpdateEntered = true;
128
+ assert.equal(current.remoteAuthEnabled, false, "serialized settings updates must observe the preceding completed write");
129
+ return { outputModeDefault: "compact-v1" };
130
+ }, settingsFile);
131
+ await new Promise((resolve) => setImmediate(resolve));
132
+ assert.equal(secondUpdateEntered, false, "same-file settings updates must not interleave between revision read and atomic write");
133
+ releaseFirstUpdate();
134
+ await Promise.all([firstUpdate, secondUpdate]);
135
+ const serialized = await readWebuiSettings(settingsFile);
136
+ assert.equal(serialized.remoteAuthEnabled, false);
137
+ assert.equal(serialized.outputModeDefault, "compact-v1");
138
+
139
+ console.log("subagent-launch-slots.test.mjs passed");
140
+ } finally {
141
+ await rm(projectRoot, { recursive: true, force: true });
142
+ await rm(settingsRoot, { recursive: true, force: true });
143
+ }