@firstpick/pi-package-webui 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/bin/pi-webui.mjs +401 -37
- package/index.ts +124 -0
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/git-workflow-preferences.mjs +153 -0
- package/package.json +3 -3
- package/public/app.js +702 -30
- package/public/index.html +26 -7
- package/public/styles.css +218 -2
- package/tests/fixtures/fake-pi.mjs +53 -0
- package/tests/git-workflow-preferences.test.mjs +67 -0
- package/tests/http-endpoints-harness.test.mjs +28 -0
- package/tests/markdown-links.test.mjs +113 -0
- package/tests/mobile-static.test.mjs +61 -17
- package/tests/native-parity-harness.test.mjs +1 -1
- package/tests/native-parity.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +41 -0
- package/tests/subagents-helper.test.mjs +210 -0
- package/tests/theme-scheme-mode.test.mjs +5 -5
- package/webui-rpc-helper.mjs +536 -2
|
@@ -28,8 +28,8 @@ const helper = await readFile(join(root, "webui-rpc-helper.mjs"), "utf8");
|
|
|
28
28
|
const companionDependencies = {
|
|
29
29
|
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.1",
|
|
30
30
|
"@firstpick/pi-extension-btw": "^0.1.2",
|
|
31
|
-
"@firstpick/pi-extension-fish-user-bash": "^0.2.
|
|
32
|
-
"@firstpick/pi-extension-git-footer-status": "^0.3.
|
|
31
|
+
"@firstpick/pi-extension-fish-user-bash": "^0.2.1",
|
|
32
|
+
"@firstpick/pi-extension-git-footer-status": "^0.3.8",
|
|
33
33
|
"@firstpick/pi-extension-release-aur": "^0.1.7",
|
|
34
34
|
"@firstpick/pi-extension-release-npm": "^0.4.0",
|
|
35
35
|
"@firstpick/pi-extension-safety-guard": "^0.2.3",
|
|
@@ -71,9 +71,14 @@ assert.match(html, /id="agentDoneNotificationsToggle"/, "side panel should expos
|
|
|
71
71
|
assert.match(html, /id="agentDoneNotificationsStatus"/, "agent-done notifications toggle should expose status text");
|
|
72
72
|
assert.match(html, /id="thinkingVisibilityToggle"/, "side panel should expose a thinking-output visibility toggle");
|
|
73
73
|
assert.match(html, /id="thinkingVisibilityStatus"/, "thinking-output visibility toggle should expose status text");
|
|
74
|
+
assert.match(html, /<option value="xhigh">xhigh<\/option>\s*<option value="max">max<\/option>/, "side panel should expose Pi's max thinking effort after xhigh");
|
|
75
|
+
assert.match(app, /const SETTINGS_THINKING_OPTIONS = \["off", "minimal", "low", "medium", "high", "xhigh", "max"\]/, "native settings should expose every Pi thinking effort");
|
|
76
|
+
assert.match(app, /return levels\.length \? levels : \["off", "minimal", "low", "medium", "high", "xhigh", "max"\]/, "footer thinking picker fallback should include max effort");
|
|
77
|
+
assert.match(server, /const THINKING_LEVELS = \["off", "minimal", "low", "medium", "high", "xhigh", "max"\]/, "server should accept Pi's max thinking effort");
|
|
74
78
|
assert.match(html, /id="terminalTabsLayoutSelect"[\s\S]*<option value="left">Left sidebar<\/option>/, "side panel controls should expose a terminal-tabs layout selector");
|
|
75
79
|
assert.match(html, /id="terminalTabsLayoutStatus"/, "terminal-tabs layout selector should expose status text");
|
|
76
80
|
assert.match(html, /id="nativeCommandDialog"/, "native slash selector UI should have a dedicated dialog");
|
|
81
|
+
assert.match(html, /id="optionsGitWorkflowSetupButton"[\s\S]*data-command="\/git-workflow-setup"[\s\S]*Guided Git Setup/, "Common Pi options should expose native Guided Git Setup");
|
|
77
82
|
assert.match(html, /id="nativeCommandSearch"[^>]*type="search"/, "native slash selector dialog should expose a filter box");
|
|
78
83
|
assert.match(html, /id="remoteQrDialog"[\s\S]*id="remoteQrBody"[\s\S]*id="remoteQrCopyButton"/, "remote WebUI should expose a dedicated QR popup dialog");
|
|
79
84
|
assert.match(html, /id="commandPaletteCloseButton"[^>]*aria-label="Close command palette"[^>]*>Close<\/button>/, "command palette should expose a visible accessible close button");
|
|
@@ -86,6 +91,9 @@ assert.match(html, /class="optional-features-description[\s\S]*href="https:\/\/g
|
|
|
86
91
|
assert.doesNotMatch(html, /id="btwOverlayDialog"/, "/btw should not use a blocking modal overlay");
|
|
87
92
|
assert.match(html, /id="codexUsageBox"/, "side panel should expose Codex subscription usage status");
|
|
88
93
|
assert.match(html, /data-side-panel-section="codex-usage"/, "Codex usage should live in a collapsible side-panel section");
|
|
94
|
+
assert.match(html, /data-side-panel-section="subagents"[\s\S]*class="side-panel-section-label">Subagents<\/span>[\s\S]*id="subagentCountBadge"[\s\S]*id="subagentsBox"/, "side panel should expose grouped running subagents with a live count");
|
|
95
|
+
assert.doesNotMatch(html, /id="subagentOverlayDialog"/, "subagent output should not use a blocking modal dialog");
|
|
96
|
+
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");
|
|
89
97
|
assert.match(html, /data-side-panel-section="queue"[\s\S]*id="createPromptListButton"[\s\S]*>Create prompt list<\/button>/, "Queue section should expose prompt-list creation");
|
|
90
98
|
assert.match(html, /id="loadPromptListButton"[\s\S]*>Load List<\/button>[\s\S]*id="runLoadedPromptListButton"[^>]*disabled[^>]*>Run<\/button>/, "Queue section should expose load and run controls for saved prompt lists");
|
|
91
99
|
assert.match(html, /id="promptListDialog"[\s\S]*id="promptListAddPromptButton"[\s\S]*\+ Add follow-up prompt/, "prompt-list dialog should add follow-up prompt rows");
|
|
@@ -151,6 +159,9 @@ assert.match(html, /id="nativeSkillsButton"[^>]*data-command="\/skills"[\s\S]*?<
|
|
|
151
159
|
assert.match(html, /id="nativeToolsButton"[^>]*data-command="\/tools"[\s\S]*?<span>Tools Setup<\/span>/, "skills/tools command menu should include Tools Setup");
|
|
152
160
|
assert.match(html, /id="appRunnerInfoButton"[\s\S]*?aria-controls="appRunnerInfoDialog"/, "detected app-runner controls should expose an explanation popup button");
|
|
153
161
|
assert.match(html, /id="appRunnerMenuButton"[\s\S]*?aria-controls="appRunnerMenuPanel"/, "composer should expose a detected app-runner dropdown button");
|
|
162
|
+
for (const menuId of ["publishMenu", "nativeCommandMenu", "optionsMenu", "appRunnerMenuPanel"]) {
|
|
163
|
+
assert.match(html, new RegExp(`id="${menuId}"[^>]*class="[^"]*composer-auto-height-menu-panel`), `${menuId} should opt into content-height sizing without internal scrolling`);
|
|
164
|
+
}
|
|
154
165
|
assert.ok(html.indexOf('id="optionsMenuButton"') < html.indexOf('id="appRunnerMenuButton"'), "app-runner dropdown should render to the right of the settings/options button");
|
|
155
166
|
assert.match(html, /id="optionsRemoteButton"[^>]*data-command="\/remote"[^>]*hidden[\s\S]*?<span>Open Remote<\/span>/, "Options menu should include the Remote WebUI launcher by label");
|
|
156
167
|
const optionsRemoteIndex = html.indexOf('id="optionsRemoteButton"');
|
|
@@ -274,6 +285,12 @@ assert.match(css, /\.webui-version-badge,\n\.webui-dev-badge \{[\s\S]*?border-ra
|
|
|
274
285
|
assert.match(css, /\.webui-dev-badge \{[\s\S]*?color:\s*var\(--ctp-yellow\)/, "Web UI dev indicator should have distinct warning styling");
|
|
275
286
|
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");
|
|
276
287
|
assert.match(css, /\.side-panel-section:not\(\.collapsed\) \.side-panel-section-chevron/, "expanded side panel sections should rotate the chevron");
|
|
288
|
+
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");
|
|
289
|
+
assert.match(css, /\.subagent-agent-row:hover,[\s\S]*\.subagent-agent-row:focus-visible/, "subagent rows should expose clickable hover and keyboard focus states");
|
|
290
|
+
assert.match(css, /\.subagent-overlay-widget[\s\S]*\.subagent-overlay-terminal[\s\S]*\.subagent-overlay-close-action/, "subagent output should reuse the non-blocking App Runner widget visual language");
|
|
291
|
+
assert.match(css, /\.subagent-output-waiting-dot[\s\S]*@keyframes subagent-output-waiting-pulse/, "subagent output should animate one transient ellipsis while waiting");
|
|
292
|
+
assert.doesNotMatch(css, /\.extension-dialog\.subagent-overlay-dialog/, "subagent output should not retain blocking dialog styles");
|
|
293
|
+
assert.match(css, /@keyframes subagent-running-pulse/, "running subagents should expose a live activity indicator");
|
|
277
294
|
assert.match(css, /\.optional-feature-pill\.enabled/, "optional features should visually distinguish enabled state");
|
|
278
295
|
assert.match(css, /\.todo-widget \{[\s\S]*?display:\s*grid/, "todo-progress widget should render as a styled checklist card");
|
|
279
296
|
assert.match(css, /\.todo-widget-summary \{[\s\S]*?cursor:\s*pointer/, "todo-progress widget should expose a compact expandable summary");
|
|
@@ -320,10 +337,11 @@ assert.match(css, /\.composer-publish-menu:hover > \.composer-publish-button\[da
|
|
|
320
337
|
assert.match(css, /\.composer-publish-menu-panel \{[\s\S]*?display:\s*none;[\s\S]*?flex-direction:\s*column/, "Publish workflow menu should hide when closed and expand like grouped tabs");
|
|
321
338
|
assert.match(css, /\.composer-publish-menu:hover \.composer-publish-menu-panel,[\s\S]*?\.composer-publish-menu:focus-within \.composer-publish-menu-panel,[\s\S]*?\.composer-publish-menu\.open \.composer-publish-menu-panel \{\n\s+display:\s*flex;/, "Publish workflow menu should open on hover, focus, or explicit open state");
|
|
322
339
|
assert.match(css, /\.composer-native-command-button \{[\s\S]*?color:\s*var\(--ctp-mauve\)/, "skills/tools command menu should have a distinct slash-command button style");
|
|
323
|
-
assert.match(css, /\.composer-
|
|
324
|
-
assert.match(css, /\.composer-publish-menu-panel \{[\s\S]*?overscroll-behavior:\s*contain;[\s\S]*?-webkit-overflow-scrolling:\s*touch/, "dropdown panels should
|
|
325
|
-
assert.match(css, /\.composer-actions-panel > \.composer-publish-menu \.composer-publish-menu-panel \{[\s\S]*?max-height:\s*min\(var\(--mobile-dropdown-max-height, 34dvh\), calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\)\)/, "mobile composer dropdowns should
|
|
326
|
-
assert.match(css, /\.composer-actions-panel > \.composer-options-menu \.composer-publish-menu-panel,\n\s+\.composer-actions-panel > \.composer-app-runner-menu \.composer-publish-menu-panel \{\n\s+inset-inline:\s*auto 0;/, "mobile Options and app-runner dropdowns should share
|
|
340
|
+
assert.match(css, /\.composer-auto-height-menu-panel \{[\s\S]*?height:\s*auto;[\s\S]*?max-height:\s*none;[\s\S]*?overflow:\s*visible;[\s\S]*?overflow-y:\s*visible;/, "content-height composer menus should grow with their active commands without an internal scrollbar");
|
|
341
|
+
assert.match(css, /\.composer-publish-menu-panel \{[\s\S]*?overscroll-behavior:\s*contain;[\s\S]*?-webkit-overflow-scrolling:\s*touch/, "dropdown panels should default to contained momentum scrolling when their options overflow");
|
|
342
|
+
assert.match(css, /\.composer-actions-panel > \.composer-publish-menu \.composer-publish-menu-panel \{[\s\S]*?max-height:\s*min\(var\(--mobile-dropdown-max-height, 34dvh\), calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\)\)/, "mobile composer dropdowns should default to an in-viewport scroll height");
|
|
343
|
+
assert.match(css, /\.composer-actions-panel > \.composer-options-menu \.composer-publish-menu-panel,\n\s+\.composer-actions-panel > \.composer-app-runner-menu \.composer-publish-menu-panel \{\n\s+inset-inline:\s*auto 0;/, "mobile Options and app-runner dropdowns should share right-aligned popover placement");
|
|
344
|
+
assert.match(css, /\.composer-actions-panel > \.composer-publish-menu \.composer-auto-height-menu-panel \{[\s\S]*?height:\s*auto;[\s\S]*?max-height:\s*none;[\s\S]*?overflow:\s*visible;[\s\S]*?overflow-y:\s*visible;/, "mobile content-height menus should grow with their active commands without an internal scrollbar");
|
|
327
345
|
assert.match(css, /\.composer-native-command-menu-item \{[\s\S]*?color:\s*var\(--ctp-mauve\)/, "skills/tools command menu items should be styled separately from publish actions");
|
|
328
346
|
assert.match(css, /\.composer-actions-panel > \.composer-publish-menu[\s\S]*?grid-column: span 1/, "Publish and command menu buttons should fit beside Git workflow in mobile actions");
|
|
329
347
|
assert.match(css, /\.composer-actions-panel[\s\S]*?bottom:\s*calc\(100% \+ 0\.42rem\)/, "mobile composer actions should open as an above-composer sheet");
|
|
@@ -488,7 +506,7 @@ assert.match(app, /const hadNetworkStatus = networkStatusLoaded;[\s\S]*if \(!had
|
|
|
488
506
|
assert.match(app, /remoteAuthToggle: \$\("#remoteAuthToggle"\)/, "Remote WebUI controls should bind the remote PIN auth toggle");
|
|
489
507
|
assert.match(html, /id="networkControlField"[^>]*hidden/, "Remote WebUI browser controls should be hidden until the optional package is loaded and enabled");
|
|
490
508
|
assert.match(app, /remoteWebuiCommand\(enable \? "authOn" : "authOff"/, "remote PIN auth toggle should dispatch through the Remote WebUI package command");
|
|
491
|
-
assert.match(server, /
|
|
509
|
+
assert.match(server, /webuiSettingsFile,[\s\S]*from "\.\.\/lib\/git-workflow-preferences\.mjs"/, "server should use the shared Pi Web UI settings persistence module");
|
|
492
510
|
assert.match(server, /let persistedRemoteAuthEnabled = await readPersistedRemoteAuthEnabled\(\)/, "server should load the saved Remote PIN auth preference before startup");
|
|
493
511
|
assert.match(server, /if \(remoteAuthStartupEnabled\(\)\) enableRemoteAuth\(remoteAuthStartupReason\(\)\)/, "saved Remote PIN auth preference should enable auth on startup");
|
|
494
512
|
assert.match(server, /await saveRemoteAuthPreference\(true\)/, "enabling Remote PIN auth should persist the on preference");
|
|
@@ -542,7 +560,7 @@ assert.match(app, /function setOptionsMenuOpen\(open\)[\s\S]*scheduleMobileDropd
|
|
|
542
560
|
assert.match(app, /function focusPromptInput\(\{ defer = false \} = \{\}\)/, "frontend should focus the prompt composer programmatically after tab/app startup");
|
|
543
561
|
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");
|
|
544
562
|
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");
|
|
545
|
-
assert.match(app, /resizePromptInput\(\);\nfocusPromptInput\(\{ defer: true \}\);\nrestoreStoredSkillUsage\(\);\nrestoreBusyPromptBehaviorSetting\(\);\nupdateComposerModeButtons\(\);/, "startup should request prompt focus and restore skill tags before waiting for tab state refreshes");
|
|
563
|
+
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");
|
|
546
564
|
assert.match(app, /elements\.promptInput\.addEventListener\("focus", \(\) => \{\n\s+syncMobileChatToBottomForInput\(\);/, "focusing mobile input should scroll output to bottom");
|
|
547
565
|
assert.match(app, /navigator\.serviceWorker\.register\("\/service-worker\.js"\)/, "PWA service worker should be registered by the app");
|
|
548
566
|
assert.match(app, /function serverStartCommandText\(\)[\s\S]*return `pi-webui\$\{currentPortArg\(\)\}`/, "PWA/offline shell should build a pathless pi-webui recovery command");
|
|
@@ -615,6 +633,23 @@ assert.match(
|
|
|
615
633
|
"side-panel section toggles should expand at most one section at a time",
|
|
616
634
|
);
|
|
617
635
|
assert.match(app, /function renderCodexUsage\(\)/, "frontend should render Codex usage buckets in the side panel");
|
|
636
|
+
assert.match(app, /function renderSubagents\(\)[\s\S]*subagentTabsWithRunningAgents\(\)[\s\S]*renderSubagentTabGroup\(tab\)/, "frontend should group running subagents by terminal and session");
|
|
637
|
+
assert.match(app, /function openSubagentOverlay\(tab, run, agent\)[\s\S]*activeTabId !== tab\.tabId[\s\S]*await switchTab\(tab\.tabId\)[\s\S]*renderWidgets\(\)/, "clicking an agent should switch to its owning tab before rendering the live widget");
|
|
638
|
+
assert.match(app, /function renderWidgets\(\)[\s\S]*renderAppRunnerWidget\(\)[\s\S]*renderSubagentOverlayWidget\(\)/, "subagent output should render in the shared non-blocking top widget area after App Runner");
|
|
639
|
+
assert.doesNotMatch(app, /subagentOverlayDialog\.showModal|elements\.subagentOverlayDialog/, "subagent output should not open or depend on a modal dialog");
|
|
640
|
+
assert.match(app, /api\(`\/api\/subagents\/output\?\$\{query\}`, \{ scoped: false \}\)/, "subagent overlay should fetch selected live output from the owning tab");
|
|
641
|
+
assert.match(app, /SUBAGENT_OVERLAY_REFRESH_MS = 1000/, "subagent overlay should poll selected live output at a fast cadence");
|
|
642
|
+
assert.match(app, /function appendSubagentOutputWaitingIndicator\(parent\)[\s\S]*subagent-output-waiting-dot[\s\S]*if \(running && agent\.currentTool\) appendSubagentOutputWaitingIndicator\(terminal\)/, "subagent widget should render one replaceable waiting animation instead of transcript spam");
|
|
643
|
+
assert.match(app, /api\("\/api\/subagents", \{ scoped: false \}\)/, "frontend should refresh the cross-tab subagent overview");
|
|
644
|
+
assert.match(app, /SUBAGENTS_ACTIVE_REFRESH_MS = 1500/, "running subagents should receive a fast live refresh cadence");
|
|
645
|
+
assert.match(server, /url\.pathname === "\/api\/subagents" && req\.method === "GET"[\s\S]*webuiSubagentsData\(\)/, "server should expose a cross-tab running-subagent endpoint");
|
|
646
|
+
assert.match(server, /url\.pathname === "\/api\/subagents\/output" && req\.method === "GET"[\s\S]*webuiSubagentOutputData\(tab, runId, agentId\)/, "server should expose selected running subagent output only through its owning tab");
|
|
647
|
+
assert.match(server, /rememberWebuiSubagentsStatusEvent\(tab, event\)/, "server should ingest the helper's structured subagent status without forwarding internal JSON to the browser footer");
|
|
648
|
+
assert.match(helper, /SUBAGENT_RPC_REQUEST_EVENT = "subagents:rpc:v1:request"/, "Web UI helper should use pi-subagents' stable status RPC");
|
|
649
|
+
assert.match(helper, /case "subagent-output":[\s\S]*subagentOutputSnapshot\(payload\)/, "Web UI helper should return bounded live state and recent output for the selected child agent");
|
|
650
|
+
assert.match(helper, /line\.trim\(\)\.toLowerCase\(\) === "\(no output\)"/, "subagent transcript extraction should suppress empty tool-result markers");
|
|
651
|
+
assert.match(helper, /SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started"[\s\S]*SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete"/, "Web UI helper should track async subagent lifecycle events");
|
|
652
|
+
assert.match(helper, /pi\.on\("tool_execution_start"[\s\S]*event\.toolName !== "subagent"[\s\S]*pi\.on\("tool_execution_end"/, "Web UI helper should track foreground subagent executions");
|
|
618
653
|
assert.match(app, /if \(normalized === "prolite"\) return "Usage";/, "Codex Prolite plan labels should display as Usage in the side panel");
|
|
619
654
|
assert.match(app, /api\(`\/api\/codex-usage\$\{suffix\}`, \{ scoped: false \}\)/, "Codex usage should load through a server endpoint without browser credentials");
|
|
620
655
|
assert.match(app, /restoreSidePanelSectionState\(\);\nbindSidePanelSectionToggles\(\);/, "side panel section state should restore before toggles are bound");
|
|
@@ -632,7 +667,7 @@ assert.match(app, /function footerPayloadWithLiveModel\(payload\)[\s\S]*?shortMo
|
|
|
632
667
|
assert.match(app, /function footerContextDisplayWithAuto\(value, state = currentState\)[\s\S]*footerAutoCompactionEnabled\(state\)[\s\S]*`\$\{withoutAuto\} \(auto\)`/, "context displays should append the auto-compaction indicator when enabled");
|
|
633
668
|
assert.match(app, /function footerPayloadWithLiveModel\(payload\)[\s\S]*const contextChip = \(chip\)[\s\S]*footerContextDisplayWithAuto\(chip\?\.value\)[\s\S]*if \(chip\?\.key === "context"\) return \[contextChip\(chip\)\]/, "git footer context chips should use live Web UI auto-compaction state");
|
|
634
669
|
assert.match(app, /async function toggleFooterAutoCompaction\(tabContext = activeTabContext\(\)\)[\s\S]*currentState = \{ \.\.\.currentState, autoCompactionEnabled: enabled \}[\s\S]*api\("\/api\/auto-compaction", \{ method: "POST", body: \{ enabled \}, tabId: tabContext\.tabId \}\)/, "git footer context box should optimistically toggle auto-compaction through the Web UI API");
|
|
635
|
-
assert.match(app, /function renderGitFooterPayload\(payload\)[\s\S]*classList\.remove\("statusbar-tui-footer"\)[\s\S]*classList\.add\("statusbar-git-footer"\)[\s\S]*payload\.main\.map\(renderGitFooterPayloadMetric\)[\s\S]*payload\.meta\.map/, "enabled git footer payload should use the styled extension chip renderer, not the default TUI line");
|
|
670
|
+
assert.match(app, /function renderGitFooterPayload\(payload\)[\s\S]*classList\.remove\("statusbar-tui-footer"\)[\s\S]*classList\.add\("statusbar-git-footer"\)[\s\S]*payload\.main\.map\(\(chip\) => renderGitFooterPayloadMetric\(chip, payload\)\)[\s\S]*payload\.meta\.map\(\(chip\) => renderGitFooterPayloadMeta\(chip, tab, payload\)\)/, "enabled git footer payload should use the styled extension chip renderer, not the default TUI line");
|
|
636
671
|
assert.match(app, /function ensureFooterTooltipNode\(\)[\s\S]*footer-floating-tooltip[\s\S]*document\.body\.append\(footerTooltipNode\)/, "git footer tooltips should render into a single floating viewport-level node");
|
|
637
672
|
const footerTooltipSource = app.match(/function applyFooterTooltip\(node, tooltip, options = \{\}\)[\s\S]*?\n}\n\nfunction footerMetric/)?.[0] || "";
|
|
638
673
|
assert.ok(footerTooltipSource, "git footer tooltip application source should be inspectable");
|
|
@@ -641,10 +676,10 @@ assert.match(app, /const GIT_FOOTER_TOOLTIP_COPY = \{[\s\S]*tokens:[\s\S]*cache:
|
|
|
641
676
|
assert.match(app, /function gitFooterPayloadTooltip\(chip, options = \{\}\)[\s\S]*GIT_FOOTER_TOOLTIP_COPY\[key\][\s\S]*`Current: \$\{value\}`/, "git footer tooltips should combine explanations with the current chip value");
|
|
642
677
|
assert.match(app, /function isRedundantFooterTooltipTitle\(sourceTitle, chip, value\)[\s\S]*labels\.map\(\(label\) => `\$\{label\}: \$\{value\}`\)/, "git footer tooltips should suppress duplicate label/current title lines");
|
|
643
678
|
assert.match(app, /function gitFooterTooltipAlign\(chip\)[\s\S]*\["tokens", "cwd"\][\s\S]*return "start";[\s\S]*\["model", "thinking"\][\s\S]*return "end";/, "git footer tooltip alignment should keep edge boxes readable");
|
|
644
|
-
assert.match(app, /function renderGitFooterPayloadMetric\(chip\)[\s\S]*applyGitFooterContextToggleOptions\(chip, options\)[\s\S]*gitFooterPayloadTooltip\(chip, \{ action \}\)[\s\S]*footerMetric\(chip\.icon/, "git footer main payload chips should render as styled metrics with explanatory tooltips and context action support");
|
|
645
|
-
assert.match(app, /function applyFooterChangedFilesDropdown\(node, chip\)[\s\S]*chip\?\.key !== "changes"[\s\S]*footer-changes-with-files[\s\S]*footer-changed-files-popover/, "git footer changes chip should render a changed-files hover popover when files are present");
|
|
679
|
+
assert.match(app, /function renderGitFooterPayloadMetric\(chip, payload\)[\s\S]*applyGitFooterContextToggleOptions\(chip, options\)[\s\S]*gitFooterPayloadTooltip\(chip, \{ action \}\)[\s\S]*footerMetric\(chip\.icon/, "git footer main payload chips should render as styled metrics with explanatory tooltips and context action support");
|
|
680
|
+
assert.match(app, /function applyFooterChangedFilesDropdown\(node, chip, payload\)[\s\S]*gitFooterPayloadVisible\(payload, "webui-changed-files-popover"\)[\s\S]*chip\?\.key !== "changes"[\s\S]*footer-changes-with-files[\s\S]*footer-changed-files-popover/, "git footer changes chip should render a changed-files hover popover when files are present");
|
|
646
681
|
assert.match(app, /function insertChangedFilePathReference\(path\)[\s\S]*formatPathReference\(path\)[\s\S]*input\.focus\(\)/, "clicking changed files should insert an @path reference and focus the composer");
|
|
647
|
-
assert.match(app, /function renderGitFooterPayloadMeta\(chip, tab\)[\s\S]*options\.title = gitFooterPayloadTooltip\(chip, \{ action \}\)[\s\S]*footerMeta\(chip\.label, chip\.value, footerMetaClassForPayload\(chip\), options\)[\s\S]*applyFooterChangedFilesDropdown\(node, chip\)/, "git footer meta payload chips should render as styled metadata with explanatory tooltips and changes popovers");
|
|
682
|
+
assert.match(app, /function renderGitFooterPayloadMeta\(chip, tab, payload\)[\s\S]*options\.title = gitFooterPayloadTooltip\(chip, \{ action \}\)[\s\S]*footerMeta\(chip\.label, chip\.value, footerMetaClassForPayload\(chip\), options\)[\s\S]*applyFooterChangedFilesDropdown\(node, chip, payload\)/, "git footer meta payload chips should render as styled metadata with explanatory tooltips and changes popovers");
|
|
648
683
|
assert.match(app, /chip\.key === "git"[\s\S]*setFooterBranchPickerOpen\(!footerBranchPickerOpen\)[\s\S]*Worktree actions are the safe default for parallel work/, "git branch footer chip should open the worktree-aware branch picker");
|
|
649
684
|
assert.match(app, /chip\.key === "worktree"[\s\S]*setFooterBranchPickerOpen\(!footerBranchPickerOpen\)[\s\S]*Click to manage branch worktrees/, "worktree footer chip should open the branch worktree picker");
|
|
650
685
|
assert.match(app, /function footerPayloadWithLiveModel\(payload\)[\s\S]*const worktreeLabel = gitWorkspaceBadgeLabel\(workspace\)[\s\S]*key: "worktree"/, "git footer payload should inject a live worktree chip from tab metadata");
|
|
@@ -794,7 +829,7 @@ assert.match(app, /const gitWorkflowsByTab = new Map\(\)/, "guided git workflow
|
|
|
794
829
|
assert.match(app, /function bindGitWorkflowToActiveTab\(\) \{\n\s+gitWorkflow = gitWorkflowForTab\(activeTabId\) \|\| createGitWorkflowState\(\);/, "guided git workflow should render only the active terminal tab's workflow state");
|
|
795
830
|
assert.match(app, /function setGitWorkflow\(patch, \{ tabId = activeTabId \} = \{\}\)[\s\S]*if \(tabId === activeTabId\) \{[\s\S]*renderGitWorkflow\(\);/, "guided git workflow should not render inactive terminal workflows globally");
|
|
796
831
|
assert.match(html, /id="gitPrDialog"[\s\S]*id="gitPrTitleInput"[\s\S]*id="gitPrBodyEditor"[\s\S]*id="gitPrCreateButton"/, "guided git workflow should expose a PR review dialog with title and body editing");
|
|
797
|
-
assert.match(app, /addGitWorkflowAction\("Create PR worktree", \(\) => createGitPrBranch\(\), "primary", false, GIT_WORKFLOW_CREATE_PR_TOOLTIP\)/, "guided git workflow should offer a Create PR worktree action after message generation");
|
|
832
|
+
assert.match(app, /addGitWorkflowAction\("Create PR worktree", \(\) => createGitPrBranch\(\), deliveryMode === "pr-worktree" \? "primary" : "", false, GIT_WORKFLOW_CREATE_PR_TOOLTIP\)/, "guided git workflow should offer and preference-highlight a Create PR worktree action after message generation");
|
|
798
833
|
assert.match(app, /const GIT_WORKFLOW_CREATE_PR_TOOLTIP = \[[\s\S]*"Create PR worktree:"[\s\S]*"1\. Ask Pi to generate a type\/feature-name branch from staged changes\."[\s\S]*"4\. Create or open a Git worktree for that branch instead of switching this checkout\."[\s\S]*"7\. Push and Create PR will push upstream, run \/pr, let you review, then run gh pr create\."/, "Create PR worktree should have an up-to-date step-by-step tooltip");
|
|
799
834
|
assert.match(app, /const GIT_WORKFLOW_MANUAL_BRANCH_TOOLTIP = \[[\s\S]*"Manual PR worktree:"[\s\S]*"1\. Skip agent branch-name generation\."[\s\S]*"4\. Create or open a Git worktree for that branch instead of switching this checkout\."[\s\S]*"7\. Push and Create PR will push upstream, run \/pr, let you review, then run gh pr create\."/, "Manual worktree should have an up-to-date step-by-step tooltip");
|
|
800
835
|
assert.match(app, /addGitWorkflowAction\("Manual worktree", \(\) => createGitPrBranchManually\(\), "", false, GIT_WORKFLOW_MANUAL_BRANCH_TOOLTIP\)/, "Manual worktree should render with its tooltip");
|
|
@@ -812,7 +847,13 @@ assert.match(app, /async function createGitPrBranchWithSuggestion\([\s\S]*prompt
|
|
|
812
847
|
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");
|
|
813
848
|
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");
|
|
814
849
|
assert.match(app, /addGitWorkflowAction\("Push and Create PR", \(\) => pushAndCreatePrGitWorkflow\(\), "primary", false\)/, "guided git workflow should replace push with Push and Create PR in PR mode");
|
|
815
|
-
assert.match(app, /async function runGitPrPrompt\(tabId = gitWorkflowActionTabId\(\), \{ prefixOutput = "" \} = \{\}\)[\s\S]*
|
|
850
|
+
assert.match(app, /async function runGitPrPrompt\(tabId = gitWorkflowActionTabId\(\), \{ prefixOutput = "" \} = \{\}\)[\s\S]*\/api\/git-workflow\/generate"[\s\S]*kind: "pr"/, "guided git workflow should generate PR descriptions with the configured generation profile");
|
|
851
|
+
assert.match(app, /async function runGitMessagePrompt\([\s\S]*\/api\/git-workflow\/generate"[\s\S]*kind: "commit"/, "guided git workflow should generate commit messages with the configured model and effort");
|
|
852
|
+
assert.match(app, /async function runGitBranchNamePrompt\([\s\S]*\/api\/git-workflow\/generate"[\s\S]*kind: "branch"/, "guided git workflow should generate branch names with the configured model and effort");
|
|
853
|
+
assert.match(app, /async function acceptCurrentGitStaging\([\s\S]*summary\?\.staged[\s\S]*No staged files are available/, "review staging should require a non-empty current staged set");
|
|
854
|
+
assert.match(app, /Pre-commit verification reminder[\s\S]*Continue with this commit/, "configured verification reminders should run before committing");
|
|
855
|
+
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");
|
|
856
|
+
assert.match(server, /event\?\.type === "agent_settled"[\s\S]*restoreGitWorkflowGenerationProfile\(tab\)/, "server should restore the active tab model and effort after generation settles");
|
|
816
857
|
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");
|
|
817
858
|
assert.match(server, /case "\/api\/git-workflow\/branch":[\s\S]*createGitWorkflowBranchWorktree\(tab, body\)/, "server should route guided PR branch creation through worktree tabs");
|
|
818
859
|
assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*snapshotGitWorkflowBranchState\(root, tab\.cwd\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should copy staged state before opening the worktree tab");
|
|
@@ -895,8 +936,8 @@ assert.match(app, /function thinkingFormatOpenMatch\(text\)[\s\S]*?CHANNEL_THINK
|
|
|
895
936
|
assert.match(app, /function splitThinkingFormatText\(text, \{ streaming = false \} = \{\}\)[\s\S]*?thinkingFormatOpenMatch\(rest\)[\s\S]*?finalText: stripThinkingFormatOutputSeparator\(rest\)/, "tagged thinking output should split thinking text from final response text");
|
|
896
937
|
assert.match(app, /function visibleThinkingText\(text\)[\s\S]*?trimmed === UNEXPOSED_THINKING_TEXT[\s\S]*?return "";/, "provider no-thinking placeholders should normalize to empty thinking output");
|
|
897
938
|
assert.match(app, /if \(isThinkingPart\) \{[\s\S]*?visibleThinkingText\(assistantThinkingText\(part\)\)[\s\S]*?if \(thinking\) displayMessages\.push/, "assistant transcript splitting should skip empty or unexposed thinking parts");
|
|
898
|
-
assert.match(app, /message\.role === "thinking"[\s\S]*?visibleThinkingText\(message\.thinking \|\| textFromContent\(message\.content\)\)[\s\S]*?if \(thinkingOutputVisible && thinkingText\)
|
|
899
|
-
assert.match(app, /function showStreamingThinking\(initialText = ""\)[\s\S]*?if \(initialText && !streamThinking\.textContent\) streamThinking
|
|
939
|
+
assert.match(app, /message\.role === "thinking"[\s\S]*?visibleThinkingText\(message\.thinking \|\| textFromContent\(message\.content\)\)[\s\S]*?if \(thinkingOutputVisible && thinkingText\) appendThinkingMarkdown\(body, thinkingText\);/, "thinking cards should suppress empty and provider no-thinking placeholder output while rendering visible reasoning as markdown");
|
|
940
|
+
assert.match(app, /function showStreamingThinking\(initialText = ""\)[\s\S]*?if \(initialText && !streamThinking\.textContent\) renderThinkingMarkdown\(streamThinking, initialText\);/, "live thinking should not create a visible placeholder card before content arrives");
|
|
900
941
|
assert.match(app, /function setStreamingThinkingText\(text\)[\s\S]*?const thinking = visibleThinkingText\(text\);[\s\S]*?if \(!thinkingOutputVisible \|\| !thinking\) return false;[\s\S]*?return true;/, "live thinking text setters should ignore empty text instead of clearing or flashing the card");
|
|
901
942
|
assert.match(app, /function syncStreamingThinkingFromUpdate\(event, update, \{ placeholder = "" \} = \{\}\)[\s\S]*?return setStreamingThinkingText\(streamThinkingRawText \|\| placeholder\);/, "incremental thinking sync should only report success after setting visible thinking text");
|
|
902
943
|
assert.doesNotMatch(app, /text \|\| placeholder \|\| streamThinkingBubble/, "partial-message thinking sync should not clear an existing thinking card when a partial carries no visible thinking text");
|
|
@@ -1061,11 +1102,14 @@ for (const command of ["resume", "reload", "remote", "name", "clone", "settings"
|
|
|
1061
1102
|
const id = command.replace(/^./, (letter) => letter.toUpperCase());
|
|
1062
1103
|
assert.match(app, new RegExp(`options${id}Button\\.addEventListener\\("click", \\(\\) => runNativeCommandMenu\\("\\/${command}"\\)\\)`), `Options menu should launch /${command}`);
|
|
1063
1104
|
}
|
|
1105
|
+
assert.match(app, /optionsGitWorkflowSetupButton\?\.addEventListener\("click", \(\) => runNativeCommandMenu\("\/git-workflow-setup"\)\)/, "Options menu should launch native Guided Git Setup");
|
|
1106
|
+
assert.match(extension, /registerCommand\("git-workflow-setup"[\s\S]*runGitWorkflowSetup/, "Pi extension should register the reusable /git-workflow-setup command");
|
|
1107
|
+
assert.match(app, /async function openNativeGitWorkflowSetupDialog\([\s\S]*\/api\/git-workflow\/preferences/, "Web UI should implement Guided Git Setup with the persisted preferences API");
|
|
1064
1108
|
assert.match(app, /async function sendPrompt\(kind = "prompt", explicitMessage, \{ targetTabId = activeTabId, throwOnError = false, streamingBehavior \} = \{\}\)/, "prompt sending should accept direct messages that bypass the input field and optional target tab");
|
|
1065
1109
|
assert.match(app, /const rawMessage = usesPromptInput \? elements\.promptInput\.value : explicitMessage/, "direct prompt sends should not read the input textarea");
|
|
1066
1110
|
assert.match(app, /if \(usesPromptInput\) \{[\s\S]*?if \(targetStillActive\) \{[\s\S]*?elements\.promptInput\.value = "";/, "direct prompt sends should preserve the input textarea draft");
|
|
1067
1111
|
assert.match(app, /make\("button", "command-item"\)[\s\S]*?sendPrompt\("prompt", `\/\$\{command\.name\}`\)/, "side-panel command clicks should send the slash command directly");
|
|
1068
|
-
assert.match(app, /const NATIVE_SELECTOR_COMMANDS = new Set\(\["model", "settings", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"\]\)/, "frontend should route native slash commands into selector UIs");
|
|
1112
|
+
assert.match(app, /const NATIVE_SELECTOR_COMMANDS = new Set\(\["model", "settings", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"\]\)/, "frontend should route native slash commands, including Guided Git Setup, into selector UIs");
|
|
1069
1113
|
assert.match(app, /async function handleNativeSlashSelectorCommand\(message/, "frontend should intercept exact native slash commands before prompt forwarding");
|
|
1070
1114
|
assert.match(app, /kind === "prompt" && attachments\.length === 0 && await handleNativeSlashSelectorCommand/, "prompt sending should open native selector dialogs before marking a run active");
|
|
1071
1115
|
assert.match(app, /function openNativeModelSelector\(\)[\s\S]*?nativeCommandApi\("\/api\/models"\)/, "native /model selector should load models through the active tab API");
|
|
@@ -129,7 +129,7 @@ for (const target of ["state", "tabs", "commands", "themes", "workspace"]) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const slashCommands = nativeSlashCommandEntries(parity);
|
|
132
|
-
assert.equal(slashCommands.length,
|
|
132
|
+
assert.equal(slashCommands.length, 25);
|
|
133
133
|
assert.equal(slashCommands[0].name, "settings");
|
|
134
134
|
assert.equal(slashCommands.at(-1).name, "quit");
|
|
135
135
|
|
|
@@ -53,6 +53,7 @@ const slashSurfaces = parity.surfaces.filter((surface) => surface.kind === "slas
|
|
|
53
53
|
const slashCommandNames = slashSurfaces.map((surface) => surface.command?.name).filter(Boolean);
|
|
54
54
|
const requiredNativeCommands = [
|
|
55
55
|
"settings",
|
|
56
|
+
"git-workflow-setup",
|
|
56
57
|
"model",
|
|
57
58
|
"theme",
|
|
58
59
|
"scoped-models",
|
|
@@ -62,10 +62,51 @@ try {
|
|
|
62
62
|
assert.equal(startupAuth.body?.data?.auth?.enabled, true, "saved Remote PIN auth setting should enable auth at next startup");
|
|
63
63
|
assert.match(startupAuth.body?.data?.auth?.pin, /^\d{4}$/, "startup auth should generate a fresh PIN, not persist one");
|
|
64
64
|
|
|
65
|
+
const initialGitSetup = await request("/api/git-workflow/preferences");
|
|
66
|
+
assert.equal(initialGitSetup.status, 200);
|
|
67
|
+
assert.equal(initialGitSetup.body?.data?.configured, false, "guided Git should require first-time model setup");
|
|
68
|
+
assert.equal(initialGitSetup.body?.data?.preferences?.stagingPolicy, "review", "review/select should be the safe staging default");
|
|
69
|
+
assert.equal(initialGitSetup.body?.data?.models?.[0]?.id, "fake-model");
|
|
70
|
+
|
|
71
|
+
const unsupportedEffort = await request("/api/git-workflow/preferences", {
|
|
72
|
+
method: "POST",
|
|
73
|
+
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "low" } } },
|
|
74
|
+
});
|
|
75
|
+
assert.equal(unsupportedEffort.status, 400, "setup should reject effort levels unsupported by the selected model");
|
|
76
|
+
|
|
77
|
+
const invalidStagingPolicy = await request("/api/git-workflow/preferences", {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: { preferences: { generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" }, stagingPolicy: "everything" } },
|
|
80
|
+
});
|
|
81
|
+
assert.equal(invalidStagingPolicy.status, 400, "setup should reject invalid preference choices instead of silently normalizing them");
|
|
82
|
+
|
|
83
|
+
const savedGitSetup = await request("/api/git-workflow/preferences", {
|
|
84
|
+
method: "POST",
|
|
85
|
+
body: {
|
|
86
|
+
preferences: {
|
|
87
|
+
generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", unavailablePolicy: "ask" },
|
|
88
|
+
commit: { language: "de", defaultVariant: "long", scope: "required" },
|
|
89
|
+
stagingPolicy: "review",
|
|
90
|
+
deliveryMode: "ask",
|
|
91
|
+
verificationPolicy: "ask",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
assert.equal(savedGitSetup.status, 200);
|
|
96
|
+
assert.equal(savedGitSetup.body?.data?.configured, true);
|
|
97
|
+
assert.equal(savedGitSetup.body?.data?.preferences?.commit?.language, "de");
|
|
98
|
+
|
|
99
|
+
const generation = await request("/api/git-workflow/generate", { method: "POST", body: { kind: "commit" } });
|
|
100
|
+
assert.equal(generation.status, 200);
|
|
101
|
+
assert.equal(generation.body?.data?.message, "/git-staged-msg de required");
|
|
102
|
+
assert.deepEqual(generation.body?.data?.generation, { provider: "fake", modelId: "fake-model", thinkingLevel: "off" });
|
|
103
|
+
|
|
65
104
|
const disableAuth = await request("/api/remote-auth/settings", { method: "POST", body: { enabled: false } });
|
|
66
105
|
assert.equal(disableAuth.status, 200);
|
|
67
106
|
const savedAfterDisable = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
107
|
+
assert.equal(savedAfterDisable.version, 2, "Web UI settings should migrate to the guided Git schema version");
|
|
68
108
|
assert.equal(savedAfterDisable.remoteAuthEnabled, false, "disabling Remote PIN auth should persist the off preference");
|
|
109
|
+
assert.equal(savedAfterDisable.gitWorkflow?.generation?.modelId, "fake-model", "Remote PIN updates should preserve guided Git preferences");
|
|
69
110
|
|
|
70
111
|
const enableAuth = await request("/api/remote-auth/settings", { method: "POST", body: { enabled: true } });
|
|
71
112
|
assert.equal(enableAuth.status, 200);
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import webuiRpcHelper from "../webui-rpc-helper.mjs";
|
|
6
|
+
|
|
7
|
+
class EventBus {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.handlers = new Map();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
on(name, handler) {
|
|
13
|
+
const handlers = this.handlers.get(name) || new Set();
|
|
14
|
+
handlers.add(handler);
|
|
15
|
+
this.handlers.set(name, handlers);
|
|
16
|
+
return () => {
|
|
17
|
+
handlers.delete(handler);
|
|
18
|
+
if (handlers.size === 0) this.handlers.delete(name);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
emit(name, value) {
|
|
23
|
+
for (const handler of [...(this.handlers.get(name) || [])]) handler(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bus = new EventBus();
|
|
28
|
+
const extensionHandlers = new Map();
|
|
29
|
+
const registeredCommands = new Map();
|
|
30
|
+
const statuses = [];
|
|
31
|
+
const notifications = [];
|
|
32
|
+
const pi = {
|
|
33
|
+
events: bus,
|
|
34
|
+
on(name, handler) {
|
|
35
|
+
const handlers = extensionHandlers.get(name) || [];
|
|
36
|
+
handlers.push(handler);
|
|
37
|
+
extensionHandlers.set(name, handlers);
|
|
38
|
+
},
|
|
39
|
+
registerCommand(name, command) { registeredCommands.set(name, command); },
|
|
40
|
+
getAllTools() { return []; },
|
|
41
|
+
getActiveTools() { return []; },
|
|
42
|
+
setActiveTools() {},
|
|
43
|
+
appendEntry() {},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const ctx = {
|
|
47
|
+
mode: "rpc",
|
|
48
|
+
hasUI: true,
|
|
49
|
+
cwd: "/tmp/subagent-helper-test",
|
|
50
|
+
sessionManager: {
|
|
51
|
+
getBranch() { return []; },
|
|
52
|
+
},
|
|
53
|
+
ui: {
|
|
54
|
+
setStatus(key, text) {
|
|
55
|
+
statuses.push({ key, text });
|
|
56
|
+
},
|
|
57
|
+
notify(message, type) {
|
|
58
|
+
notifications.push({ message, type });
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const asyncRunDir = await mkdtemp(path.join(tmpdir(), "pi-webui-subagent-output-test-"));
|
|
64
|
+
const asyncSessionFile = path.join(asyncRunDir, "reviewer-session.jsonl");
|
|
65
|
+
await writeFile(asyncSessionFile, [
|
|
66
|
+
JSON.stringify({ type: "message", message: { role: "assistant", content: [{ type: "text", text: "REVIEWER STREAM 1 OF 18" }, { type: "toolCall", name: "bash", arguments: { command: "sleep 5" } }] } }),
|
|
67
|
+
JSON.stringify({ type: "message", message: { role: "toolResult", content: [{ type: "text", text: "(no output)\nreviewer tool output line" }] } }),
|
|
68
|
+
"",
|
|
69
|
+
].join("\n"));
|
|
70
|
+
await writeFile(path.join(asyncRunDir, "status.json"), JSON.stringify({
|
|
71
|
+
runId: "run-a",
|
|
72
|
+
mode: "parallel",
|
|
73
|
+
state: "running",
|
|
74
|
+
startedAt: Date.now() - 1000,
|
|
75
|
+
lastUpdate: Date.now(),
|
|
76
|
+
steps: [
|
|
77
|
+
{ agent: "reviewer", status: "running", sessionFile: asyncSessionFile, recentOutput: [], currentTool: "bash", currentToolArgs: "sleep 5" },
|
|
78
|
+
{ agent: "scout", status: "running" },
|
|
79
|
+
],
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
const statusText = `Active async runs: 2
|
|
83
|
+
|
|
84
|
+
- run-a | running | active | parallel | 2/2 running | ~/repo
|
|
85
|
+
1. reviewer | running | tool read
|
|
86
|
+
2. scout | running | tool grep
|
|
87
|
+
|
|
88
|
+
- run-b | running | active | chain | step 2/2 | ~/repo
|
|
89
|
+
1. planner | completed
|
|
90
|
+
2. [Implementation] Apply fixes (worker) | running | tool edit
|
|
91
|
+
↳ nested-oracle [nested-1] running | tool grep`;
|
|
92
|
+
|
|
93
|
+
webuiRpcHelper(pi);
|
|
94
|
+
const unsubscribeRpc = bus.on("subagents:rpc:v1:request", (request) => {
|
|
95
|
+
const text = request.params?.id === "run-a"
|
|
96
|
+
? `Run: run-a\nState: running\nMode: parallel\nDir: ${asyncRunDir}`
|
|
97
|
+
: statusText;
|
|
98
|
+
bus.emit(`subagents:rpc:v1:reply:${request.requestId}`, {
|
|
99
|
+
version: 1,
|
|
100
|
+
requestId: request.requestId,
|
|
101
|
+
method: request.method,
|
|
102
|
+
success: true,
|
|
103
|
+
data: { text, details: { mode: "single", results: [] } },
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "startup" }, ctx);
|
|
108
|
+
for (let attempt = 0; attempt < 20 && !statuses.some((entry) => entry.text?.startsWith("PI_WEBUI_SUBAGENTS_V1 ") && entry.text.includes("run-a")); attempt++) {
|
|
109
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function latestPayload() {
|
|
113
|
+
const entry = statuses.filter((item) => item.key === "webui-subagents").at(-1);
|
|
114
|
+
assert.ok(entry, "helper should publish the internal WebUI subagent status");
|
|
115
|
+
assert.match(entry.text, /^PI_WEBUI_SUBAGENTS_V1 /);
|
|
116
|
+
return JSON.parse(entry.text.slice("PI_WEBUI_SUBAGENTS_V1 ".length));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let payload = latestPayload();
|
|
120
|
+
assert.equal(payload.available, true, "successful pi-subagents RPC should mark status available");
|
|
121
|
+
assert.deepEqual(payload.runs.map((run) => run.id), ["run-a", "run-b"]);
|
|
122
|
+
assert.deepEqual(payload.runs[0].agents.map((agent) => [agent.name, agent.currentTool]), [["reviewer", "read"], ["scout", "grep"]]);
|
|
123
|
+
assert.deepEqual(payload.runs[1].agents.map((agent) => [agent.name, agent.nested]), [["worker", false], ["nested-oracle", true]]);
|
|
124
|
+
|
|
125
|
+
const helperCommand = registeredCommands.get("webui-helper");
|
|
126
|
+
assert.ok(helperCommand?.handler, "Web UI helper command should be registered");
|
|
127
|
+
await helperCommand.handler(JSON.stringify({
|
|
128
|
+
requestId: "async-subagent-output-test",
|
|
129
|
+
action: "subagent-output",
|
|
130
|
+
payload: { runId: "run-a", agentId: "run-a:step:0:reviewer" },
|
|
131
|
+
}), ctx);
|
|
132
|
+
const asyncOutputNotice = notifications.find((entry) => entry.message.includes("async-subagent-output-test"));
|
|
133
|
+
assert.ok(asyncOutputNotice, "async subagent output helper action should return a response notification");
|
|
134
|
+
const asyncOutputResponse = JSON.parse(asyncOutputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
135
|
+
assert.equal(asyncOutputResponse.ok, true);
|
|
136
|
+
assert.deepEqual(asyncOutputResponse.data.agent.recentOutput, [
|
|
137
|
+
"REVIEWER STREAM 1 OF 18",
|
|
138
|
+
"▶ bash {\"command\":\"sleep 5\"}",
|
|
139
|
+
"reviewer tool output line",
|
|
140
|
+
], "async output should be recovered from the child session transcript when status recentOutput is empty");
|
|
141
|
+
|
|
142
|
+
for (const handler of extensionHandlers.get("tool_execution_start") || []) {
|
|
143
|
+
handler({
|
|
144
|
+
type: "tool_execution_start",
|
|
145
|
+
toolCallId: "foreground-call",
|
|
146
|
+
toolName: "subagent",
|
|
147
|
+
args: { tasks: [{ agent: "tester", task: "Run tests" }, { agent: "reviewer", task: "Review diff" }] },
|
|
148
|
+
}, ctx);
|
|
149
|
+
}
|
|
150
|
+
payload = latestPayload();
|
|
151
|
+
let foreground = payload.runs.find((run) => run.source === "foreground");
|
|
152
|
+
assert.deepEqual(foreground?.agents.map((agent) => agent.name), ["tester", "reviewer"], "foreground parallel children should appear while the tool runs");
|
|
153
|
+
|
|
154
|
+
for (const handler of extensionHandlers.get("tool_execution_update") || []) {
|
|
155
|
+
handler({
|
|
156
|
+
type: "tool_execution_update",
|
|
157
|
+
toolCallId: "foreground-call",
|
|
158
|
+
toolName: "subagent",
|
|
159
|
+
partialResult: {
|
|
160
|
+
details: {
|
|
161
|
+
mode: "parallel",
|
|
162
|
+
progress: [{
|
|
163
|
+
index: 0,
|
|
164
|
+
agent: "tester",
|
|
165
|
+
status: "running",
|
|
166
|
+
currentTool: "bash",
|
|
167
|
+
currentToolArgs: "npm test",
|
|
168
|
+
currentPath: "/tmp/subagent-helper-test",
|
|
169
|
+
recentTools: [{ tool: "read", args: "package.json", endMs: 1000 }],
|
|
170
|
+
recentOutput: ["Running focused tests", "12 assertions passed"],
|
|
171
|
+
turnCount: 2,
|
|
172
|
+
toolCount: 3,
|
|
173
|
+
tokens: 420,
|
|
174
|
+
}],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
}, ctx);
|
|
178
|
+
}
|
|
179
|
+
payload = latestPayload();
|
|
180
|
+
foreground = payload.runs.find((run) => run.source === "foreground");
|
|
181
|
+
assert.deepEqual(foreground?.agents.map((agent) => agent.name), ["tester"], "foreground live updates should expose currently running children");
|
|
182
|
+
|
|
183
|
+
await helperCommand.handler(JSON.stringify({
|
|
184
|
+
requestId: "subagent-output-test",
|
|
185
|
+
action: "subagent-output",
|
|
186
|
+
payload: { runId: "foreground-call", agentId: "foreground-call:0:tester" },
|
|
187
|
+
}), ctx);
|
|
188
|
+
const outputNotice = notifications.find((entry) => {
|
|
189
|
+
if (!entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")) return false;
|
|
190
|
+
return JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === "subagent-output-test";
|
|
191
|
+
});
|
|
192
|
+
assert.ok(outputNotice, "subagent output helper action should return a response notification");
|
|
193
|
+
const outputResponse = JSON.parse(outputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
194
|
+
assert.equal(outputResponse.ok, true);
|
|
195
|
+
assert.equal(outputResponse.data.agent.currentTool, "bash");
|
|
196
|
+
assert.equal(outputResponse.data.agent.currentToolArgs, "npm test");
|
|
197
|
+
assert.deepEqual(outputResponse.data.agent.recentOutput, ["Running focused tests", "12 assertions passed"]);
|
|
198
|
+
assert.deepEqual(outputResponse.data.agent.recentTools, [{ tool: "read", args: "package.json", endMs: 1000 }]);
|
|
199
|
+
|
|
200
|
+
for (const handler of extensionHandlers.get("tool_execution_end") || []) {
|
|
201
|
+
handler({ type: "tool_execution_end", toolCallId: "foreground-call", toolName: "subagent" }, ctx);
|
|
202
|
+
}
|
|
203
|
+
payload = latestPayload();
|
|
204
|
+
assert.equal(payload.runs.some((run) => run.source === "foreground"), false, "foreground children should disappear when their tool finishes");
|
|
205
|
+
|
|
206
|
+
for (const handler of extensionHandlers.get("session_shutdown") || []) await handler({ reason: "quit" }, ctx);
|
|
207
|
+
unsubscribeRpc();
|
|
208
|
+
await rm(asyncRunDir, { recursive: true, force: true });
|
|
209
|
+
|
|
210
|
+
console.log("subagents-helper.test.mjs passed");
|
|
@@ -73,18 +73,18 @@ assert.match(
|
|
|
73
73
|
|
|
74
74
|
// Persistence lives inside applyTheme's validated persist branch (matching light/dark
|
|
75
75
|
// scheme slot + legacy key), reached only after setThemeByName found and classified
|
|
76
|
-
// the theme. chooseTheme is the single persist:true entry point;
|
|
77
|
-
//
|
|
78
|
-
// clobber
|
|
76
|
+
// the theme. chooseTheme is the single theme persist:true entry point; unrelated
|
|
77
|
+
// browser preferences may use the same option name. applySchemeTheme (init, mode
|
|
78
|
+
// switches, OS changes) never persists, so a degraded bundle load cannot clobber picks.
|
|
79
79
|
assert.match(
|
|
80
80
|
app,
|
|
81
81
|
/if \(persist\) \{\s*storeSchemeTheme\(isLight \? "light" : "dark", theme\.name\);\s*storeThemeName\(theme\.name\);\s*\}/,
|
|
82
82
|
"applyTheme's persist branch must write the theme's matching scheme slot and the legacy key",
|
|
83
83
|
);
|
|
84
84
|
assert.equal(
|
|
85
|
-
(app.match(/persist: true/g) || []).length,
|
|
85
|
+
(app.match(/setThemeByName\([^;]*persist: true/g) || []).length,
|
|
86
86
|
1,
|
|
87
|
-
"chooseTheme must be the only persist:true call site",
|
|
87
|
+
"chooseTheme must be the only theme persist:true call site",
|
|
88
88
|
);
|
|
89
89
|
assert.match(
|
|
90
90
|
app,
|