@firstpick/pi-package-webui 0.7.5 → 0.7.7

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 (40) hide show
  1. package/README.md +37 -4
  2. package/bin/pi-webui-rpc-supervisor.mjs +518 -0
  3. package/bin/pi-webui.mjs +1003 -82
  4. package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
  5. package/lib/rpc-supervisor-client.mjs +301 -0
  6. package/lib/rpc-supervisor-protocol.mjs +236 -0
  7. package/lib/rpc-supervisor-state.mjs +165 -0
  8. package/lib/trust-boundaries.mjs +1 -0
  9. package/package.json +2 -2
  10. package/public/app.js +1243 -87
  11. package/public/index.html +334 -24
  12. package/public/service-worker.js +6 -1
  13. package/public/styles.css +642 -41
  14. package/public/subagent-gate-visibility.mjs +36 -0
  15. package/public/workflow-status-stack.mjs +69 -0
  16. package/tests/app-runner-process-tree-harness.test.mjs +37 -3
  17. package/tests/boot-failure-diagnostics.test.mjs +180 -0
  18. package/tests/compact-sections-static.test.mjs +111 -0
  19. package/tests/durable-rpc-supervisor-harness.test.mjs +252 -0
  20. package/tests/fast-mode-client-static.test.mjs +2 -2
  21. package/tests/fixtures/compacting-pi.mjs +0 -0
  22. package/tests/fixtures/fake-pi.mjs +81 -2
  23. package/tests/git-panel-file-preview-static.test.mjs +221 -0
  24. package/tests/http-endpoints-harness.test.mjs +458 -33
  25. package/tests/mobile-static.test.mjs +77 -9
  26. package/tests/native-parity-harness.test.mjs +2 -1
  27. package/tests/native-parity.test.mjs +11 -0
  28. package/tests/numpad-decimal-input-static.test.mjs +128 -0
  29. package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
  30. package/tests/prompt-routing-tab-status.test.mjs +103 -0
  31. package/tests/rpc-supervisor-host.test.mjs +275 -0
  32. package/tests/rpc-supervisor-protocol.test.mjs +67 -0
  33. package/tests/rpc-supervisor-state.test.mjs +62 -0
  34. package/tests/run-all.mjs +4 -1
  35. package/tests/streaming-ui-coupling.test.mjs +15 -0
  36. package/tests/subagent-gate-visibility.test.mjs +66 -0
  37. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  38. package/tests/subagents-helper.test.mjs +145 -8
  39. package/tests/workflow-status-stack.test.mjs +87 -0
  40. package/webui-rpc-helper.mjs +164 -4
@@ -96,8 +96,28 @@ assert.match(server, /const THINKING_LEVELS = \["off", "minimal", "low", "medium
96
96
  assert.match(html, /id="terminalTabsLayoutSelect"[\s\S]*<option value="left">Left sidebar<\/option>/, "side panel controls should expose a terminal-tabs layout selector");
97
97
  assert.match(html, /id="terminalTabsLayoutStatus"/, "terminal-tabs layout selector should expose status text");
98
98
  assert.match(html, /id="nativeCommandDialog"/, "native slash selector UI should have a dedicated dialog");
99
+ assert.match(html, /id="optionsWorkflowSetupButton"[^>]*data-command="\/workflow-setup"[^>]*hidden[\s\S]*Workflow Permission Setup/, "Common Pi options should expose catalog-gated Workflow Permission Setup");
99
100
  assert.match(html, /id="optionsSafetyGuardSetupButton"[\s\S]*data-command="\/safety-guard-setup"[\s\S]*Safety Guard Setup/, "Common Pi options should expose native Safety Guard Setup");
100
101
  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");
102
+ assert.match(app, /const NATIVE_SELECTOR_COMMANDS = new Set\(\[[^\]]*"workflow-setup"[^\]]*\]\)/, "exact /workflow-setup should be a browser-native selector command");
103
+ assert.match(app, /function normalizedWorkflowPolicyList\(value\)[\s\S]*new Set[\s\S]*\.filter\(Boolean\)\)\]\.sort\(\)/, "workflow policy list fields should trim, deduplicate, and sort for the canonical preview");
104
+ assert.match(app, /function parseWorkflowPolicyVerificationCommands\(value\)[\s\S]*JSON\.parse\(line\)[\s\S]*non-empty JSON string argv array[\s\S]*commands\.push\(command\)/, "workflow verification should accept one ordered JSON argv array per nonblank line");
105
+ assert.match(app, /async function openNativeWorkflowSetupDialog\(\)[\s\S]*api\("\/api\/workflow-policy", \{ scoped: false \}\)[\s\S]*nativeSettingToggle\("Allow write"[\s\S]*nativeSettingToggle\("Allow shell"[\s\S]*nativeSettingToggle\("Allow network"[\s\S]*Exact normalized JSON preview/, "workflow setup should load the localhost policy API and render accessible permission controls plus an exact normalized preview");
106
+ assert.match(app, /Authorization ceiling[\s\S]*not blanket authority[\s\S]*Shell safety[\s\S]*not an OS sandbox[\s\S]*explicit empty-verification waiver/, "workflow setup should explain ceiling, shell sandbox, and empty-verification limitations");
107
+ assert.match(app, /nativeSettingsDirty = workflowPolicyDraftSignature\(controls\) !== initialDraftSignature/, "workflow setup edits should participate in native dialog discard protection");
108
+ assert.match(app, /addNativeCommandAction\("Reset to all deny"[\s\S]*applyDeniedWorkflowPolicyControls\(controls\)[\s\S]*controls\.write\.input\.focus\(\)/, "workflow setup should expose an explicit reset-to-all-deny action");
109
+ assert.match(app, /title: "Save reviewed workflow permission ceiling\?"[\s\S]*Exact normalized JSON:[\s\S]*if \(!reviewed\) return;[\s\S]*api\("\/api\/workflow-policy", \{[\s\S]*body: \{ policy: policyToSave, expectedRevision: data\.revision \?\? null \}[\s\S]*No agent turn was started/, "workflow setup should require explicit normalized review before revision-protected save and report transient no-turn success");
110
+ assert.match(app, /name === "workflow-setup" && !hasLoadedRpcCommand\(name\)[\s\S]*case "workflow-setup":[\s\S]*await openNativeWorkflowSetupDialog\(\)/, "workflow setup native routing should require the active Pi tab's loaded extension command catalog");
111
+ assert.match(app, /function normalizeWorkflowPolicySuggestions\(value\)[\s\S]*if \(!value \|\| typeof value !== "object" \|\| Array\.isArray\(value\)\) return empty;[\s\S]*if \(!Array\.isArray\(group\) \|\| group\.some[\s\S]*return \[\];[\s\S]*shellAllowlist: normalizeStringGroup\(value\.shellAllowlist\)[\s\S]*networkAllowlist: normalizeStringGroup\(value\.networkAllowlist\)[\s\S]*verificationCommands: normalizeVerificationGroup\(value\.verificationCommands\)/, "workflow suggestions should defensively normalize each server-provided catalog group and render no fallback for malformed groups");
112
+ assert.match(app, /const suggestions = normalizeWorkflowPolicySuggestions\(data\.suggestions\)[\s\S]*suggestionLabel: "Shell executable suggestions"[\s\S]*suggestionLabel: "Network host suggestions"[\s\S]*suggestionLabel: "Verification command suggestions"/, "all three workflow policy textareas should consume only GET-provided suggestions in labelled groups");
113
+ const appendWorkflowPolicySuggestionSource = appFunctionSource("appendWorkflowPolicySuggestion", "workflowPolicySuggestionGroup");
114
+ assert.match(appendWorkflowPolicySuggestionSource, /const separator = textarea\.value && !textarea\.value\.endsWith\("\\n"\)[\s\S]*textarea\.value = `\$\{textarea\.value\}\$\{separator\}\$\{line\}`[\s\S]*dispatchEvent\(new Event\("input", \{ bubbles: true \}\)\)[\s\S]*textarea\.focus\(\)/, "workflow suggestions should append an exact line without replacing manual text and dispatch current input tracking");
115
+ assert.doesNotMatch(appendWorkflowPolicySuggestionSource, /\.checked|permissions|api\(/, "adding a workflow suggestion must not toggle permissions or persist anything");
116
+ const workflowPolicySuggestionGroupSource = appFunctionSource("workflowPolicySuggestionGroup", "workflowPolicyTextarea");
117
+ assert.match(workflowPolicySuggestionGroupSource, /setAttribute\("role", "group"\)[\s\S]*setAttribute\("aria-labelledby", labelNode\.id\)[\s\S]*button\.type = "button"[\s\S]*button\.disabled = present\.has\(line\)[\s\S]*textarea\.addEventListener\("input", sync\)/, "workflow suggestion controls should be labelled, keyboard-native buttons that disable and resync with manual edits");
118
+ assert.match(app, /function workflowPolicyPresentSuggestionLines\(textarea, kind\)[\s\S]*normalizedWorkflowPolicyList\(textarea\.value\)[\s\S]*JSON\.parse\(line\)[\s\S]*present\.add\(JSON\.stringify\(command\)\)/, "workflow suggestion deduplication should compare normalized exact list and verification values");
119
+ assert.match(app, /const renderPreview = \(\) => \{\s*controls\.shellAllowlist\.syncSuggestions\(\);\s*controls\.networkAllowlist\.syncSuggestions\(\);\s*controls\.verificationCommands\.syncSuggestions\(\);[\s\S]*addNativeCommandAction\("Reset to all deny"[\s\S]*applyDeniedWorkflowPolicyControls\(controls\);\s*renderPreview\(\);/, "workflow preview and reset should resync suggestion availability after additions or removals");
120
+ assert.match(app, /body: \{ policy: policyToSave, expectedRevision: data\.revision \?\? null \}/, "workflow save should persist only canonical policy and revision, never suggestion metadata");
101
121
  assert.match(html, /id="nativeCommandSearch"[^>]*type="search"/, "native slash selector dialog should expose a filter box");
102
122
  assert.match(html, /id="remoteQrDialog"[\s\S]*id="remoteQrBody"[\s\S]*id="remoteQrCopyButton"/, "remote WebUI should expose a dedicated QR popup dialog");
103
123
  assert.match(html, /id="commandPaletteCloseButton"[^>]*aria-label="Close command palette"[^>]*>Close<\/button>/, "command palette should expose a visible accessible close button");
@@ -250,9 +270,13 @@ assert.match(html, /id="optionsConversationModeButton"[^>]*data-command="\/talk"
250
270
  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");
251
271
  const workflowModeButtonHtml = html.match(/<button\s+id="workflowModeButton"[\s\S]*?<\/button>/)?.[0] || "";
252
272
  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");
273
+ const optionsMenuHtml = html.match(/<div id="optionsMenu"[\s\S]*?<\/div>/)?.[0] || "";
274
+ assert.match(html, /id="commandSuggest"[\s\S]*?<div class="composer-input-row">\s*<div id="workflowModeControls" class="composer-workflow-mode-dock" role="group" aria-label="Workflow Mode controls"[\s\S]*id="workflowOverlayOpenButton"[\s\S]*aria-controls="widgetArea"[\s\S]*id="workflowModeButton"[\s\S]*?<\/div>\s*<div class="composer-context-tags">/, "Workflow Mode should remain directly accessible as an isolated icon-only overlay inside the prompt frame");
275
+ assert.doesNotMatch(html, /composer-workflow-mode-dock-label|>Workflow mode<\/span>/, "Workflow Mode dock should not render visible text beside the icon");
276
+ assert.doesNotMatch(optionsMenuHtml, /id="workflowModeButton"|Workflow Mode/, "Options menu should not duplicate or hide the directly accessible Workflow Mode control");
254
277
  assert.doesNotMatch(workflowOverlayOpenButtonHtml, /\stitle=/, "Workflow overlay restore should not combine a browser-native tooltip with its styled tooltip");
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");
278
+ assert.match(workflowModeButtonHtml, /class="composer-icon-button composer-workflow-mode-button"[\s\S]*aria-label="Enable Workflow Mode"[\s\S]*aria-pressed="false"[\s\S]*hidden[\s\S]*<svg class="composer-icon"[\s\S]*aria-hidden="true"/, "composer actions should expose a capability-gated, accessible Workflow Mode icon toggle");
279
+ assert.doesNotMatch(workflowModeButtonHtml, /<span>Workflow<\/span>/, "Workflow Mode should use the shared icon treatment instead of a text label");
256
280
  assert.match(workflowModeButtonHtml, /data-tooltip="Workflow Mode:/, "Workflow Mode should retain its styled tooltip");
257
281
  assert.doesNotMatch(workflowModeButtonHtml, /\stitle=/, "Workflow Mode should not also expose a browser-native tooltip");
258
282
  assert.match(html, /id="workflowModeChip" class="composer-workflow-mode-chip"[\s\S]*hidden>Workflow: on<\/button>/, "composer should expose a hidden-until-active Workflow Mode chip");
@@ -279,6 +303,17 @@ assert.match(app, /appRunnerCustomPathInput[\s\S]*Browse/, "custom app-runner pa
279
303
  assert.match(server, /APP_RUNNER_CONFIG_FILE = "\.pi-webui-runners\.json"/, "server should use a project-local custom app-runner config file");
280
304
  assert.match(server, /\/api\/app-runner-config/, "server should expose custom app-runner config endpoints");
281
305
  assert.match(server, /\/api\/app-runner-files/, "server should expose project-scoped file browsing for custom runner paths");
306
+ assert.match(app, /function renderAppRunnerSearchPathSection\(\)[\s\S]*Project discovery paths/, "app-runner popup should offer a project discovery paths section");
307
+ assert.match(app, /body\.append\(current, renderAppRunnerSearchPathSection\(\), renderAppRunnerCustomSection\(\)/, "project discovery paths should render above custom project runners");
308
+ assert.match(app, /function renderAppRunnerSearchPathSection\(\)[\s\S]*relative to the project root[\s\S]*one level deep only \(no subdirectories\)[\s\S]*\.sh, \.bash, \.zsh, \.fish, and \.py[\s\S]*Python shebang[\s\S]*uv and\/or python3\/python/, "discovery-path copy should state project scope, non-recursive scanning, and supported shell/Python runtimes");
309
+ assert.match(app, /async function saveAppRunnerSearchPaths\(searchPaths[\s\S]*api\("\/api\/app-runner-config", \{ method: "POST", body: \{ searchPaths \}[\s\S]*setAppRunnerData\(tabContext\.tabId, response\.data \|\| \{\}\)[\s\S]*renderAppRunnerControls\(\)/, "discovery paths should be saved through the app-runner config endpoint and refresh runner data immediately");
310
+ assert.match(app, /async function addAppRunnerSearchPath\(container\)[\s\S]*already configured[\s\S]*APP_RUNNER_SEARCH_PATH_LIMIT/, "adding a discovery path should reject duplicates and respect the configured path limit");
311
+ assert.match(app, /async function removeAppRunnerSearchPath\(searchPath\)[\s\S]*offerUndo\(\{/, "removing a discovery path should stay undoable like other app-runner config edits");
312
+ assert.match(app, /async function loadAppRunnerDirectoryBrowser\(relativePath = ""\)[\s\S]*\/api\/app-runner-files\?path=/, "discovery paths should be browseable through the project-scoped file browser endpoint");
313
+ assert.match(app, /function renderAppRunnerDirectoryBrowser\(\)[\s\S]*Use this directory[\s\S]*chooseAppRunnerSearchPath/, "the discovery-path browser should let users pick the browsed directory");
314
+ assert.match(app, /appRunnerSearchPathInput[\s\S]*setAttribute\("aria-label", "Project-relative directory to scan for shell and Python scripts"\)/, "the discovery-path input should expose an accessible label for every supported script category");
315
+ assert.match(app, /elements\.appRunnerInfoButton\.hidden = false;\n\s+elements\.appRunnerInfoButton\.disabled = false;/, "app-runner configuration should stay reachable when no runner is detected");
316
+ assert.match(app, /function appRunnerSourceLabel\(runner = \{\}, displayCommand = ""\)[\s\S]*from \$\{projectFile\}/, "detected runners should disambiguate their project-relative source path");
282
317
  assert.doesNotMatch(html, /<code>\/release-(?:npm|aur)<\/code>/, "Publish menu should not show slash command names as option labels");
283
318
  assert.doesNotMatch(html, /data-tooltip="[^"]*\/release-(?:npm|aur)/, "Publish tooltip should not show slash command names");
284
319
  assert.match(html, /id="steerButton"[\s\S]*?data-tooltip="Steer usage:/, "Steer should explain type-first usage in a tooltip");
@@ -443,6 +478,11 @@ assert.match(css, /\.release-aur-widget \{[\s\S]*?border-color/, "release-aur ou
443
478
  assert.match(css, /\.app-runner-widget \{[\s\S]*?border-color/, "app runner output should render as a specialized Web UI widget variant");
444
479
  assert.match(css, /\.composer-app-runner-info-button \{[\s\S]*?position:\s*absolute;[\s\S]*?right:\s*-0\.48rem;[\s\S]*?flex:\s*none;[\s\S]*?pointer-events:\s*none/, "app runner info help should float over Run without consuming toolbar width");
445
480
  assert.match(css, /\.composer-app-runner-menu\.has-runners:hover \.composer-app-runner-info-button,[\s\S]*?\.composer-app-runner-info-button:focus-visible \{[\s\S]*?opacity:\s*1;[\s\S]*?pointer-events:\s*auto;[\s\S]*?transform:\s*translateY\(0\) scale\(1\)/, "app runner info help should reveal without reflowing neighboring composer buttons");
481
+ assert.match(css, /\.composer-app-runner-menu\.no-runners \.composer-app-runner-info-button,/, "app runner configuration help should stay visible when no runner is detected");
482
+ assert.match(css, /\.workflow-policy-suggestions \{[\s\S]*display:\s*flex;[\s\S]*flex-wrap:\s*wrap;[\s\S]*\.workflow-policy-suggestion:focus-visible \{[\s\S]*outline:/, "workflow policy suggestion buttons should wrap and expose a visible keyboard focus state");
483
+ assert.match(css, /@media \(max-width: 720px\)[\s\S]*\.workflow-policy-suggestions \{[\s\S]*flex-direction:\s*column;[\s\S]*\.workflow-policy-suggestion \{[\s\S]*width:\s*100%;[\s\S]*min-height:\s*44px;/, "workflow policy suggestions should stack into full-width touch targets on narrow screens");
484
+ assert.match(css, /\.app-runner-directory-row \{[\s\S]*?grid-template-columns:\s*minmax\(0, 1fr\) auto/, "discovery-path browser rows should pair navigation with a selection action");
485
+ assert.match(css, /@media \(max-width: 720px\)[\s\S]*?\.app-runner-directory-row,[\s\S]*?grid-template-columns:\s*1fr;/, "discovery-path browser rows should stack on narrow mobile widths");
446
486
  assert.match(css, /\.widget-area:has\(\.app-runner-live-widget \.release-npm-output-details\[open\]\)/, "live app runner output should reserve the same fixed top widget slot as release output");
447
487
  assert.match(css, /\.widget-area \.widget:not\(\.todo-widget\):not\(\.release-npm-widget\)/, "mobile widget filtering should keep release workflow output visible");
448
488
  assert.match(css, /\.message\.warn \.message-role \{ color: var\(--ctp-yellow\); \}/, "warning-level command output should be visually distinct");
@@ -461,8 +501,9 @@ assert.match(css, /\.action-feedback-controls \{[\s\S]*?opacity:\s*0/, "action r
461
501
  assert.match(css, /\.action-feedback-controls:hover,[\s\S]*?\.action-feedback-controls:focus-within/, "action reactions should reveal on hover or keyboard focus");
462
502
  assert.match(css, /\.action-feedback-controls:not\(:hover\):not\(:focus-within\) \.action-feedback-button/, "hidden action reactions should not expose button hit targets until the hover area is reached");
463
503
  assert.match(css, /\.action-feedback-button\.feedback-question\.active/, "question-mark reaction should have selected styling");
464
- assert.match(css, /\.composer-row button\[data-tooltip\]::after/, "composer button tooltips should be shared across Git, Steer, and Follow-up buttons");
465
- assert.match(css, /\.composer-row \.composer-workflow-mode-button\[data-tooltip\]::after \{\n\s+max-width:\s*min\(18rem, calc\(100vw - 2rem\)\);/, "Workflow Mode tooltip should stay narrow enough to remain inside the outer chat frame");
504
+ assert.match(css, /\.composer-row button\[data-tooltip\]::after/, "composer-row button tooltips should be shared across Git, Steer, and Follow-up buttons");
505
+ assert.doesNotMatch(css, /\.composer-row \.composer-workflow-mode-button\[data-tooltip\]/, "isolated Workflow Mode dock should not retain composer-row pseudo-tooltip overrides");
506
+ assert.match(css, /\.composer-input-row \.composer-workflow-mode-dock button\[data-tooltip\]::before,\s*\.composer-input-row \.composer-workflow-mode-dock button\[data-tooltip\]::after \{\s*display:\s*none;/, "Workflow Mode dock controls should suppress inherited pseudo-tooltips and keep only their floating styled tooltip");
466
507
  assert.match(css, /\.composer-row \.composer-git-button\[data-tooltip\]::after \{[\s\S]*?left:\s*0;[\s\S]*?right:\s*auto;/, "Git workflow tooltip should open rightward so it is not clipped off the left edge");
467
508
  assert.match(css, /\.composer-row button\[data-tooltip\]\.tooltip-open::after/, "composer button tooltips should be triggerable from JS for empty mobile taps");
468
509
  assert.match(css, /\.composer-row button\[data-tooltip\]:hover,[\s\S]*?\.composer-input-row button\[data-tooltip\]\.tooltip-open \{\n\s+z-index:\s*40;/, "active composer tooltip triggers should stack above context tags and adjacent controls");
@@ -798,14 +839,16 @@ assert.match(app, /async function saveSubagentLaunchSlotConfig[\s\S]*scope: suba
798
839
  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
840
  const subagentOverviewRefreshSource = appFunctionSource("refreshSubagents", "scheduleRefreshSubagents");
800
841
  assert.doesNotMatch(subagentOverviewRefreshSource, /subagentLaunchSlot/, "live subagent polling must not recreate or reset the launch-slot editor");
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");
842
+ assert.match(app, /function renderSubagentGateAttempt\(attempt\)[\s\S]*failureKind[\s\S]*function renderSubagentGate\(tab, gate\)[\s\S]*qualifyingSuccesses/, "frontend should render failure-classified attempts and gate quorum");
802
843
  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");
803
844
  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");
804
845
  assert.match(extension, /registerSubagentGate\(pi\)[\s\S]*session_shutdown[\s\S]*subagentGate\.dispose\(\)/, "the WebUI package extension should own the retry-gate tool lifecycle without another extension package");
805
846
  assert.match(server, /function normalizeWebuiSubagentPayload\(value\)[\s\S]*model: normalizeWebuiSubagentText\(rawAgent\.model, 240\)[\s\S]*thinking: normalizeWebuiSubagentText\(rawAgent\.thinking, 40\)/, "server should bound model and reasoning metadata in the cross-tab overview");
806
847
  assert.match(server, /WEBUI_SUBAGENT_GATE_LIMIT[\s\S]*rawGate\.attempts[\s\S]*failureKind: normalizeWebuiSubagentText\(rawAttempt\.failureKind, 80\)[\s\S]*totalGates/, "server should bound retry gates and expose their cross-tab total");
807
848
  assert.match(server, /function normalizeWebuiSubagentOutput\(value, selection\)[\s\S]*model: normalizeWebuiSubagentText\(rawAgent\.model, 240\)[\s\S]*thinking: normalizeWebuiSubagentText\(rawAgent\.thinking, 40\)/, "server should preserve model and reasoning metadata in selected child output");
849
+ assert.match(server, /function normalizeWebuiSubagentSource\(value\) \{[\s\S]*value === "foreground" \|\| value === "workflow"[\s\S]*function normalizeWebuiSubagentPayload\(value\)[\s\S]*source: normalizeWebuiSubagentSource\(rawRun\.source\)[\s\S]*function normalizeWebuiSubagentOutput\(value, selection\)[\s\S]*source: normalizeWebuiSubagentSource\(selection\.run\?\.source \|\| value\.source\)/, "server should preserve workflow source in overview and selected-output normalization");
808
850
  assert.match(app, /function subagentExecutionFacts\(agent = \{\}\)[\s\S]*model \$\{model \|\| "unknown"\}[\s\S]*reasoning \$\{thinking \|\| "unknown"\}/, "subagent metadata should use one honest model/reasoning formatter with unknown fallbacks");
851
+ assert.match(app, /function subagentSourceLabel\(source = ""\) \{[\s\S]*source === "foreground" \|\| source === "workflow"[\s\S]*function subagentOverlayStateFacts\(data = subagentOverlayData\)[\s\S]*subagentSourceLabel\(data\?\.source \|\| subagentOverlaySelection\?\.run\?\.source\)[\s\S]*function renderSubagentTerminalView\(\)[\s\S]*subagentSourceLabel\(view\.data\?\.source \|\| view\.run\?\.source\)[\s\S]*function renderSubagentTerminalTab\(view\)[\s\S]*subagentSourceLabel\(view\.data\?\.source \|\| view\.run\?\.source\)[\s\S]*function renderSubagentAgent\(tab, run, agent\)[\s\S]*subagentSourceLabel\(run\?\.source\)/, "one source-label helper should keep workflow rows, overlays, and virtual tabs honest");
809
852
  assert.match(app, /function renderSubagentAgent\(tab, run, agent\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "Subagents side-panel rows should show model and reasoning effort");
810
853
  assert.match(app, /function subagentOverlayStateFacts\(data = subagentOverlayData\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "subagent overlays should show model and reasoning effort");
811
854
  assert.match(app, /function renderSubagentTerminalView\(\)[\s\S]*\.\.\.subagentExecutionFacts\(agent\)/, "dedicated subagent terminal views should show model and reasoning effort");
@@ -976,6 +1019,10 @@ assert.match(css, /\.footer-branch-option-row \{[\s\S]*?grid-template-columns:\s
976
1019
  assert.match(css, /\.footer-branch-advanced-action:disabled \{[\s\S]*?cursor:\s*not-allowed/, "advanced branch switch action should visibly disable occupied branches");
977
1020
  assert.match(css, /\.footer-worktree \.footer-meta-value,[\s\S]*?\.footer-tui-worktree \{[\s\S]*?color:\s*var\(--ctp-green\)/, "worktree footer chips should have distinct green styling");
978
1021
  assert.match(css, /\.workspace-dashboard-action\.worktree \{[\s\S]*?color:\s*var\(--ctp-green\)/, "workspace dashboard should style the branch worktree action distinctly");
1022
+ assert.match(app, /const summary = make\("div", "workspace-dashboard-summary-row"\);[\s\S]*summary\.append\(make\("span", "workspace-dashboard-kicker", "Workspace"\), meta\);[\s\S]*const identity = make\("div", "workspace-dashboard-identity"\);[\s\S]*identity\.append\(heading, cwd\);/, "workspace dashboard should group status and identity into two compact rows");
1023
+ assert.match(css, /\.workspace-dashboard \{[\s\S]*?gap:\s*0\.52rem;[\s\S]*?padding:\s*0\.62rem 0\.78rem 0\.56rem;/, "workspace dashboard shell should use compact desktop spacing");
1024
+ assert.match(css, /\.workspace-dashboard-metric \{[\s\S]*?min-height:\s*3\.75rem;[\s\S]*?padding:\s*0\.48rem 0\.52rem;/, "workspace dashboard metrics should remain readable without tall cards");
1025
+ assert.match(css, /@media \(max-width: 720px\) \{[\s\S]*?\.workspace-dashboard-metrics \{ grid-template-columns: repeat\(2, minmax\(0, 1fr\)\); \}[\s\S]*?@media \(max-width: 480px\) \{\s*\.workspace-dashboard-metrics \{ grid-template-columns: 1fr; \}/, "workspace dashboard metrics should stay compact on tablets and stack on narrow phones");
979
1026
  assert.match(app, /async function createFooterGitBranchWorktree\(branch = footerBranchCreateName\(\)[\s\S]*chooseGitWorktreeBase\(branchName\)[\s\S]*api\("\/api\/git-worktrees", \{ method: "POST", body: \{ branchName, baseRef, sessionMode: "fork-current", openTab: true \}/, "new footer branch worktrees should ask for and submit the selected base ref");
980
1027
  assert.match(app, /async function openFooterGitWorktree\(path,[\s\S]*api\("\/api\/git-worktrees\/open", \{ method: "POST", body: \{ path: worktreePath, sessionMode: "fork-current", openTab: true \}/, "existing worktree actions should call the worktree open endpoint");
981
1028
  assert.match(app, /elements\.newTabWorktreeButton\?\.addEventListener\("click", \(\) => openBranchWorktreePicker\(\)\)/, "new-tab menu branch worktree item should open the picker");
@@ -1046,6 +1093,11 @@ assert.match(app, /const WORKFLOW_MODE_RPC_WIDGET_KEY = "workflow-mode:rpc"[\s\S
1046
1093
  assert.match(app, /function workflowModeStateFromRpcPayload\(lines\)[\s\S]*payload\?\.type !== WORKFLOW_MODE_RPC_PAYLOAD_TYPE[\s\S]*normalizeWorkflowModeState/, "frontend should strictly validate structured Workflow Mode payloads");
1047
1094
  assert.match(app, /const workflowModeByTab = new Map\(\)/, "frontend should track Workflow Mode independently for each Pi tab");
1048
1095
  assert.match(app, /function renderWorkflowModeControls\(\)[\s\S]*workflow-mode-active[\s\S]*workflowModeButton[\s\S]*workflowModeChip/, "frontend should render toggle, active chip, and composer state from extension status");
1096
+ assert.match(app, /if \(pending\) elements\.workflowModeButton\.setAttribute\("aria-busy", "true"\);[\s\S]*else elements\.workflowModeButton\.removeAttribute\("aria-busy"\);[\s\S]*pending\s*\? "Updating JavaScript Workflow Mode for this Pi tab\."/, "Workflow Mode icon should expose valid pending busy semantics and accessible tooltip feedback");
1097
+ assert.match(app, /workflowOverlayOpenButton\.setAttribute\("aria-expanded", openAvailable \? "false" : "true"\)/, "Workflow overlay restore should keep disclosure state synchronized while visible or hidden");
1098
+ assert.match(app, /applyStyledTooltip\(elements\.workflowOverlayOpenButton, "Open the minimized workflow overlay\.", \{ ariaLabel: true, align: "end" \}\)/, "isolated Workflow restore should use the viewport-clamped floating tooltip");
1099
+ assert.match(app, /applyStyledTooltip\(elements\.workflowModeButton, tooltip, \{ ariaLabel: true, align: "end" \}\)/, "isolated Workflow Mode should use the viewport-clamped floating tooltip");
1100
+ assert.match(app, /function applyStyledTooltip\([\s\S]*if \(options\.floating !== false\) bindStyledTooltipEvents\(node\)/, "styled tooltip setup should allow controls with native scoped tooltip CSS to opt out of the floating tooltip layer");
1049
1101
  assert.match(app, /async function setWorkflowModeEnabled\(enabled\)[\s\S]*`\/\$\{commandName\} mode \$\{enabled \? "on" : "off"\}`/, "Workflow Mode toggle should send canonical extension commands rather than rewrite prompts locally");
1050
1102
  assert.match(app, /if \(statusKey === WORKFLOW_MODE_STATUS_KEY\) handleWorkflowModeStatus/, "Workflow Mode should synchronize from replayable extension setStatus events");
1051
1103
  assert.match(app, /if \(widgetKey === WORKFLOW_MODE_RPC_WIDGET_KEY\)[\s\S]*workflowModeStateFromRpcPayload\(request\.widgetLines\)[\s\S]*updateWorkflowModeForTab/, "Workflow Mode should consume structured replay state without rendering an opaque widget");
@@ -1058,7 +1110,8 @@ assert.match(app, /confirmMessage && !window\.confirm\(confirmMessage\)/, "destr
1058
1110
  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
1111
  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
1112
  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");
1113
+ assert.match(app, /function workflowOverlayHasContent\(\)[\s\S]*getWidgetLines\("workflow"\)\.length[\s\S]*getWidgetLines\("workflow:subprocess"\)/, "the Workflow restore affordance should remain available when only the legacy status/details widget remains");
1114
+ assert.match(app, /function renderWidgets\(\)[\s\S]*if \(!workflowOverlayIsMinimized\(\)\)[\s\S]*attachWorkflowOverlayCloseButton\(workflowInspectorWidget \|\| workflowSubprocessWidget\)[\s\S]*for \(const \[key, value\] of widgets\)[\s\S]*widgetFeatureId === "workflows" && workflowOverlayIsMinimized\(\)/, "closing the complete Workflow overlay should omit specialized surfaces and the legacy workflow status/details widget");
1062
1115
  assert.match(app, /workflowOverlayOpenButton\?\.addEventListener\("click", \(\) => setWorkflowOverlayMinimized\(false\)\)/, "the Workflow-button restore affordance should reopen the complete overlay");
1063
1116
  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");
1064
1117
  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");
@@ -1071,8 +1124,18 @@ assert.match(css, /\.workflow-inspector-layout \{[\s\S]*grid-template-columns:[\
1071
1124
  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
1125
  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");
1073
1126
  assert.match(css, /\.terminal-tab-workflow-indicator \{[\s\S]*color: var\(--ctp-mauve\)/, "inactive-tab Workflow badges should have a distinct accessible style");
1127
+ const workflowModeDockCss = css.match(/\.composer-workflow-mode-dock \{[^}]*\}/)?.[0] || "";
1128
+ assert.match(workflowModeDockCss, /position:\s*absolute;[\s\S]*?top:\s*-0\.48rem;[\s\S]*?right:\s*3\.55rem;[\s\S]*?margin:\s*0;[\s\S]*?padding:\s*0;/, "Workflow Mode dock should overlay the prompt frame without adding composer height");
1129
+ assert.doesNotMatch(workflowModeDockCss, /border(?:-radius)?:|background:|box-shadow:/, "icon-only Workflow Mode control should not retain a decorative outer box");
1130
+ assert.match(css, /body:not\(\.mobile-keyboard-open\) \.composer-input-row:has\(\.composer-workflow-mode-dock:not\(\[hidden\]\)\) #promptInput \{[\s\S]*?padding-right:\s*3\.35rem;/, "visible icon-only Workflow dock should reserve prompt text space without adding a layout row or a hidden-keyboard gutter");
1131
+ assert.match(css, /body:not\(\.mobile-keyboard-open\) \.composer-input-row:has\(\.composer-workflow-mode-dock:not\(\[hidden\]\)\) \.composer-context-tags \{[\s\S]*?max-width:\s*calc\(100% - 7\.5rem\);/, "visible icon-only Workflow dock should reserve top-border space from context tags");
1132
+ assert.doesNotMatch(css, /\.composer-workflow-mode-dock-label/, "icon-only Workflow dock should not retain obsolete label styling");
1133
+ assert.match(css, /body:not\(\.mobile-keyboard-open\)[\s\S]*?\.composer-context-tags \{ max-width:\s*calc\(100% - 6\.5rem\); \}/, "compact dock should reserve mobile context-tag space only while the keyboard is closed");
1134
+ assert.match(css, /\.composer-workflow-mode-dock \.composer-workflow-overlay-open-button \{\s*top:\s*-0\.2rem;\s*right:\s*-0\.2rem;/, "mobile Workflow restore badge should not protrude above the compact composer");
1135
+ assert.match(css, /body\.mobile-keyboard-open \.composer-workflow-mode-dock \{ display:\s*none !important; \}/, "Workflow Mode dock should leave the compact mobile typing surface uncluttered");
1136
+ assert.match(css, /\.composer-workflow-mode-dock \.composer-workflow-mode-button \{[\s\S]*?width:\s*2\.25rem;[\s\S]*?min-height:\s*2\.25rem;/, "overlay Workflow icon should use a compact deliberate target inside its isolated dock");
1074
1137
  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");
1138
+ assert.match(css, /\.composer-workflow-mode-dock\.has-open-control \{[^}]*min-width:\s*1\.95rem;[^}]*min-height:\s*2\.35rem;/, "Workflow restore should retain an anchored dock even if the Workflow Mode button is unavailable");
1076
1139
  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");
1077
1140
  assert.match(css, /\.composer\.workflow-mode-active[\s\S]*body\.workflow-mode-active \.composer::before/, "active Workflow Mode should visibly accent the composer");
1078
1141
 
@@ -1411,6 +1474,8 @@ assert.match(app, /function setBusyPromptBehaviorMenuOpen\(open,[\s\S]*aria-expa
1411
1474
  assert.match(app, /busyPromptBehaviorTag\?\.addEventListener\("click"[\s\S]*setBusyPromptBehaviorMenuOpen\(nextOpen\)/, "clicking the busy prompt behavior tag should toggle its dropdown");
1412
1475
  assert.match(app, /busyPromptBehaviorMenu\?\.addEventListener\("click"[\s\S]*chooseBusyPromptBehaviorFromMenu/, "busy prompt behavior dropdown choices should update the setting");
1413
1476
  assert.match(app, /setBusyPromptBehavior\(controls\.busyBehavior\.select\.value\)/, "native settings should update the busy prompt behavior tag immediately");
1477
+ assert.match(app, /const initialRuntime = JSON\.stringify\(\{[\s\S]*?busyBehavior: busyPromptBehavior,[\s\S]*?\}\);/, "native settings should snapshot the defined busy prompt behavior before rendering Apply");
1478
+ assert.match(app, /applyButton = addNativeCommandAction\("Apply"/, "native settings should render the Apply action after initializing the runtime snapshot");
1414
1479
  assert.match(app, /sendPromptFromModeButton\("steer", elements\.steerButton\)/, "Steer should show tooltip instead of silently doing nothing when input is empty");
1415
1480
  assert.match(app, /sendPromptFromModeButton\("follow-up", elements\.followUpButton\)/, "Follow-up should show tooltip instead of silently doing nothing when input is empty");
1416
1481
  assert.match(app, /async function sendBtwQuestion\(question,[\s\S]*?`\/btw \$\{cleanQuestion\}`[\s\S]*?await sendPrompt\("prompt", message, \{ targetTabId, throwOnError: true \}\)/, "/btw helper should send text as an ephemeral slash command");
@@ -1423,6 +1488,9 @@ assert.match(app, /async function sendBtwPromptFromButton\(\)[\s\S]*?if \(!quest
1423
1488
  assert.match(app, /function renderBtwComposerForm\(\)[\s\S]*?form\.requestSubmit\(\)[\s\S]*?sendBtwQuestion\(question\)/, "/btw widget input should submit each message as a /btw trigger");
1424
1489
  assert.match(app, /function makeBtwTransferIcon\(\)[\s\S]*?class", "btw-transfer-icon"[\s\S]*?function transferBtwContextToMain\(button, \{ transferMode = "full" \} = \{\}\)[\s\S]*?`\/btw-transfer \$\{encoded\}`[\s\S]*?streamingBehavior: "steer"[\s\S]*?Summarize & Steer/, "/btw widget should expose full-context and summary transfer actions that send steering context during active runs");
1425
1490
  assert.match(app, /async function sendPrompt\(kind = "prompt", explicitMessage, \{ targetTabId = activeTabId, throwOnError = false, streamingBehavior \} = \{\}\)[\s\S]*?if \(targetWasBusy\) body\.streamingBehavior = streamingBehavior \|\| busyBehavior/, "prompt sending should support a per-call streaming behavior override");
1491
+ assert.match(app, /function appendOptimisticUserPrompt\([\s\S]*?role: "user"[\s\S]*?transient: true/, "new prompts should be appended to the transcript optimistically before routing finishes");
1492
+ assert.match(app, /if \(startsRun\) \{\n\s+markTabWorkingLocally\(targetTabId\);\n\s+if \(isCurrentTabContext\(tabContext\)\) \{\n\s+appendOptimisticUserPrompt\(originalMessage, attachments\.length\);\n\s+setRunIndicatorActivity\(attachments\.length \? "Preparing attachments for routing…" : "Routing prompt to the selected agent…"\);/, "new runs should show the prompt and routing progress immediately in the target tab");
1493
+ assert.match(app, /if \(startsRun && isCurrentTabContext\(tabContext\)\) setRunIndicatorActivity\("Routing complete; starting agent…"\);/, "prepared prompts should transition from routing to agent-start progress before dispatch");
1426
1494
  assert.match(app, /function runPublishWorkflow\(command\)[\s\S]*?sendPrompt\("prompt", `\/\$\{resolvedCommandName\}\$\{commandRest\}`\)/, "Publish workflows should send resolved slash commands directly without replacing the draft");
1427
1495
  assert.match(app, /async function runNativeCommandMenu\(command\)[\s\S]*?await handleNativeSlashSelectorCommand\(command\)/, "skills/tools command menu should open native selector dialogs directly");
1428
1496
  assert.match(app, /async function runNativeCommandMenu\(command\)[\s\S]*?sendPrompt\("prompt", command\)/, "generic native command menu should fall back to slash-command prompt execution");
@@ -1459,9 +1527,9 @@ assert.match(server, /url\.pathname === "\/api\/safety-guard\/config" && req\.me
1459
1527
  assert.match(app, /async function openNativeGitWorkflowSetupDialog\([\s\S]*\/api\/git-workflow\/preferences/, "Web UI should implement Guided Git Setup with the persisted preferences API");
1460
1528
  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");
1461
1529
  assert.match(app, /const rawMessage = usesPromptInput \? elements\.promptInput\.value : explicitMessage/, "direct prompt sends should not read the input textarea");
1462
- assert.match(app, /if \(usesPromptInput\) \{[\s\S]*?if \(targetStillActive\) \{[\s\S]*?elements\.promptInput\.value = "";/, "direct prompt sends should preserve the input textarea draft");
1530
+ assert.match(app, /function clearPromptInputForRouting\(\{ usesPromptInput,[\s\S]*?if \(!usesPromptInput\) return;/, "direct prompt sends should preserve the input textarea draft");
1463
1531
  assert.match(app, /make\("button", "command-item"\)[\s\S]*?sendPrompt\("prompt", `\/\$\{command\.name\}`\)/, "side-panel command clicks should send the slash command directly");
1464
- assert.match(app, /const NATIVE_SELECTOR_COMMANDS = new Set\(\["model", "settings", "safety-guard-setup", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"\]\)/, "frontend should route native slash commands, including safety and Guided Git setup, into selector UIs");
1532
+ assert.match(app, /const NATIVE_SELECTOR_COMMANDS = new Set\(\["model", "settings", "workflow-setup", "safety-guard-setup", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"\]\)/, "frontend should route native slash commands, including workflow permission, safety, and Guided Git setup, into selector UIs");
1465
1533
  assert.match(app, /async function handleNativeSlashSelectorCommand\(message/, "frontend should intercept exact native slash commands before prompt forwarding");
1466
1534
  assert.match(app, /kind === "prompt" && attachments\.length === 0 && await handleNativeSlashSelectorCommand/, "prompt sending should open native selector dialogs before marking a run active");
1467
1535
  assert.match(app, /function openNativeModelSelector\(\)[\s\S]*?nativeCommandApi\("\/api\/models"\)/, "native /model selector should load models through the active tab API");
@@ -43,6 +43,7 @@ assert.equal(isLocalRequest(remoteReq), false);
43
43
  assert.throws(() => requireLocalhost(remoteReq, "blocked"), (error) => error.statusCode === 403);
44
44
  assert.throws(() => requireLocalhostRoute(remoteReq, "/api/update"), (error) => error.statusCode === 403);
45
45
  assert.doesNotThrow(() => requireLocalhostRoute(localReq, "/api/update"));
46
+ assert.ok(LOCALHOST_ONLY_POST_ROUTES.has("/api/workflow-policy"), "workflow policy mutation must stay in the canonical localhost route registry");
46
47
 
47
48
  for (const pathname of LOCALHOST_ONLY_POST_ROUTES.keys()) {
48
49
  assert.match(pathname, /^\/api\//, `${pathname} should be an API route`);
@@ -129,7 +130,7 @@ for (const target of ["state", "tabs", "commands", "themes", "workspace"]) {
129
130
  }
130
131
 
131
132
  const slashCommands = nativeSlashCommandEntries(parity);
132
- assert.equal(slashCommands.length, 26);
133
+ assert.equal(slashCommands.length, 27);
133
134
  assert.equal(slashCommands[0].name, "settings");
134
135
  assert.equal(slashCommands.at(-1).name, "quit");
135
136
 
@@ -55,6 +55,7 @@ const requiredNativeCommands = [
55
55
  "settings",
56
56
  "safety-guard-setup",
57
57
  "git-workflow-setup",
58
+ "workflow-setup",
58
59
  "model",
59
60
  "theme",
60
61
  "scoped-models",
@@ -87,6 +88,12 @@ for (const surface of slashSurfaces) {
87
88
  assert.ok(surface.command.description.trim(), `${surface.id} command description should not be empty`);
88
89
  }
89
90
 
91
+ const workflowSetupSurface = slashSurfaces.find((surface) => surface.id === "/workflow-setup");
92
+ assert.ok(workflowSetupSurface, "/workflow-setup should be represented in the native parity matrix");
93
+ assert.equal(workflowSetupSurface.webStatus, "implemented", "/workflow-setup browser-native support should be implemented");
94
+ assert.equal(workflowSetupSurface.sensitive, true, "/workflow-setup should be tracked as a sensitive policy mutation");
95
+ assert.deepEqual(workflowSetupSurface.guards, ["localhost", "confirmation"], "/workflow-setup should require both localhost and explicit confirmation guards");
96
+
90
97
  const selectorMatch = app.match(/const NATIVE_SELECTOR_COMMANDS = new Set\(\[(.*?)\]\)/s);
91
98
  assert.ok(selectorMatch, "frontend native selector command set should be discoverable");
92
99
  const frontendSelectorCommands = [...selectorMatch[1].matchAll(/"([^"]+)"/g)].map((match) => match[1]);
@@ -132,6 +139,10 @@ assert.match(server, /url\.pathname === "\/api\/session-rename" && req\.method =
132
139
  assert.match(server, /url\.pathname === "\/api\/session-delete" && req\.method === "POST"/, "server should expose localhost-only POST /api/session-delete");
133
140
  assert.match(server, /url\.pathname === "\/api\/auth-providers" && req\.method === "GET"/, "server should expose GET /api/auth-providers");
134
141
  assert.match(server, /url\.pathname === "\/api\/auth-logout" && req\.method === "POST"/, "server should expose localhost-only POST /api/auth-logout");
142
+ assert.match(server, /url\.pathname === "\/api\/workflow-policy" && req\.method === "GET"[\s\S]*requireLocalhost\(req, "Workflow policy setup is only allowed from localhost\."\)/, "workflow policy reads should be localhost-only");
143
+ assert.match(server, /url\.pathname === "\/api\/workflow-policy" && req\.method === "POST"[\s\S]*requireLocalhostRoute\(req, url\.pathname\)[\s\S]*requireWorkflowPolicyJsonRequest\(req\)[\s\S]*expectedRevision: body\.expectedRevision/, "workflow policy saves should be registry-guarded, same-origin JSON, and revision protected");
144
+ assert.match(app, /name === "workflow-setup" && !hasLoadedRpcCommand\(name\)[\s\S]*case "workflow-setup":[\s\S]*openNativeWorkflowSetupDialog\(\)/, "frontend should gate exact /workflow-setup native routing on the active tab's loaded extension catalog");
145
+ assert.match(app, /title: "Save reviewed workflow permission ceiling\?"[\s\S]*if \(!reviewed\) return;[\s\S]*body: \{ policy: policyToSave, expectedRevision: data\.revision \?\? null \}/, "frontend should explicitly confirm the normalized workflow policy before revision-protected save");
135
146
  assert.match(server, /url\.pathname === "\/api\/native-parity" && req\.method === "GET"/, "server should expose the native parity matrix for clients/tests");
136
147
  assert.match(server, /const NATIVE_DOWNLOAD_TOKEN_TTL_MS = 10 \* 60 \* 1000/, "native downloads should use short-lived tokens");
137
148
  assert.match(server, /const WEBUI_HELPER_COMMAND = "webui-helper"/, "server should declare the hidden Web UI RPC helper command");
@@ -0,0 +1,128 @@
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
+ import vm from "node:vm";
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const app = await readFile(join(root, "public", "app.js"), "utf8");
9
+
10
+ function functionSource(name, nextName) {
11
+ const start = app.indexOf(`function ${name}(`);
12
+ const end = app.indexOf(`\nfunction ${nextName}(`, start);
13
+ assert.ok(start >= 0 && end > start, `${name} should remain a standalone frontend helper`);
14
+ return app.slice(start, end);
15
+ }
16
+
17
+ class TestInputEvent {
18
+ constructor(type, init = {}) {
19
+ this.type = type;
20
+ Object.assign(this, init);
21
+ }
22
+ }
23
+
24
+ const context = { InputEvent: TestInputEvent };
25
+ vm.runInNewContext(
26
+ `${functionSource("insertNumpadDecimal", "renderMessages")}\nthis.insertNumpadDecimal = insertNumpadDecimal;`,
27
+ context,
28
+ );
29
+
30
+ function createInput(value, selectionStart, selectionEnd = selectionStart) {
31
+ return {
32
+ value,
33
+ selectionStart,
34
+ selectionEnd,
35
+ disabled: false,
36
+ readOnly: false,
37
+ inputEvents: [],
38
+ setRangeText(replacement, start, end, selectionMode) {
39
+ assert.equal(selectionMode, "end");
40
+ this.value = `${this.value.slice(0, start)}${replacement}${this.value.slice(end)}`;
41
+ this.selectionStart = start + replacement.length;
42
+ this.selectionEnd = this.selectionStart;
43
+ },
44
+ dispatchEvent(event) {
45
+ this.inputEvents.push(event);
46
+ return true;
47
+ },
48
+ };
49
+ }
50
+
51
+ function createKeyEvent(input, overrides = {}) {
52
+ return {
53
+ currentTarget: input,
54
+ code: "NumpadDecimal",
55
+ key: ",",
56
+ keyCode: 0,
57
+ location: 3,
58
+ defaultPrevented: false,
59
+ ctrlKey: false,
60
+ metaKey: false,
61
+ altKey: false,
62
+ shiftKey: false,
63
+ isComposing: false,
64
+ preventDefault() { this.defaultPrevented = true; },
65
+ ...overrides,
66
+ };
67
+ }
68
+
69
+ const localizedInput = createInput("12,34", 2, 3);
70
+ const localizedEvent = createKeyEvent(localizedInput);
71
+ assert.equal(context.insertNumpadDecimal(localizedEvent), true, "localized numpad decimal should be handled");
72
+ assert.equal(localizedInput.value, "12.34", "localized numpad decimal should insert a dot at the selection");
73
+ assert.equal(localizedInput.selectionStart, 3, "cursor should follow the inserted dot");
74
+ assert.equal(localizedEvent.defaultPrevented, true, "native localized insertion should be replaced");
75
+ assert.equal(localizedInput.inputEvents.length, 1, "replacement should emit one input event");
76
+ assert.equal(localizedInput.inputEvents[0].type, "input");
77
+ assert.equal(localizedInput.inputEvents[0].data, ".");
78
+ assert.equal(localizedInput.inputEvents[0].inputType, "insertText");
79
+ assert.equal(localizedInput.inputEvents[0].bubbles, true);
80
+
81
+ const reportedDotInput = createInput("12", 2);
82
+ const reportedDotEvent = createKeyEvent(reportedDotInput, { key: "." });
83
+ assert.equal(context.insertNumpadDecimal(reportedDotEvent), true, "numpad decimal should be handled even when the browser reports a dot");
84
+ assert.equal(reportedDotInput.value, "12.", "explicit handling should not depend on native numpad insertion");
85
+ assert.equal(reportedDotEvent.defaultPrevented, true);
86
+
87
+ for (const overrides of [
88
+ { code: "", key: "Decimal", location: 3 },
89
+ { code: "", key: "Unidentified", keyCode: 110, location: 0 },
90
+ ]) {
91
+ const input = createInput("fallback", 8);
92
+ assert.equal(context.insertNumpadDecimal(createKeyEvent(input, overrides)), true, `legacy numpad identity should be handled: ${JSON.stringify(overrides)}`);
93
+ assert.equal(input.value, "fallback.");
94
+ }
95
+
96
+ for (const overrides of [
97
+ { code: "Period", key: ".", location: 0 },
98
+ { ctrlKey: true },
99
+ { metaKey: true },
100
+ { altKey: true },
101
+ { shiftKey: true },
102
+ { isComposing: true },
103
+ { defaultPrevented: true },
104
+ ]) {
105
+ const input = createInput("unchanged", 4);
106
+ const event = createKeyEvent(input, overrides);
107
+ assert.equal(context.insertNumpadDecimal(event), false, `unrelated or modified key should not be handled: ${JSON.stringify(overrides)}`);
108
+ assert.equal(input.value, "unchanged");
109
+ assert.equal(input.inputEvents.length, 0);
110
+ }
111
+
112
+ const readOnlyInput = createInput("read only", 4);
113
+ readOnlyInput.readOnly = true;
114
+ assert.equal(context.insertNumpadDecimal(createKeyEvent(readOnlyInput)), false, "read-only fields should remain untouched");
115
+ assert.equal(readOnlyInput.value, "read only");
116
+
117
+ assert.match(
118
+ app,
119
+ /function renderAppRunnerInputForm\(run\)[\s\S]*input\.addEventListener\("keydown", \(event\) => \{\s*if \(insertNumpadDecimal\(event\)\) return;/,
120
+ "app-runner stdin should apply the numpad decimal helper",
121
+ );
122
+ assert.match(
123
+ app,
124
+ /elements\.promptInput\.addEventListener\("keydown", \(event\) => \{\s*if \(event\.defaultPrevented \|\| insertNumpadDecimal\(event\)\) return;/,
125
+ "main prompt should apply the numpad decimal helper",
126
+ );
127
+
128
+ console.log("numpad decimal input static tests 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 app = await readFile(join(root, "public", "app.js"), "utf8");
8
+
9
+ function functionSource(name, nextName) {
10
+ const start = app.indexOf(`function ${name}(`);
11
+ const end = app.indexOf(`\nfunction ${nextName}(`, start);
12
+ assert.ok(start >= 0 && end > start, `${name} should remain a standalone frontend helper`);
13
+ return app.slice(start, end);
14
+ }
15
+
16
+ const clearSource = functionSource("clearPromptInputForRouting", "restorePromptInputAfterRoutingError");
17
+ assert.match(clearSource, /if \(!usesPromptInput\) return;/, "programmatic prompt sends should preserve the visible draft");
18
+ assert.match(clearSource, /tabDrafts\.set\(targetTabId, ""\);[\s\S]*elements\.promptInput\.value = "";[\s\S]*resizePromptInput\(\);[\s\S]*hideCommandSuggestions\(\);/, "input-backed sends should immediately clear their tab draft, textarea, and stale suggestions");
19
+
20
+ const sendSource = functionSource("sendPrompt", "hasQueuedDialogRequest");
21
+ const clearIndex = sendSource.indexOf("clearPromptInputForRouting({ usesPromptInput, targetTabId, tabContext });");
22
+ const routingIndex = sendSource.indexOf("if (startsRun) {");
23
+ const requestIndex = sendSource.indexOf('await api("/api/prompt"');
24
+ assert.ok(clearIndex >= 0, "sendPrompt should clear the captured input-backed draft");
25
+ assert.ok(routingIndex >= 0 && clearIndex < routingIndex, "the submitted prompt should be cleared before routing progress starts");
26
+ assert.ok(requestIndex >= 0 && clearIndex < requestIndex, "the submitted prompt should be cleared before the prompt request starts");
27
+ assert.match(sendSource, /catch \(error\) \{\n\s+restorePromptInputAfterRoutingError\(inputMessage,/, "a routing failure should restore the sent input when no replacement draft exists");
28
+
29
+ const successStart = sendSource.indexOf("applyResponseTab(response);");
30
+ const catchStart = sendSource.indexOf("} catch (error)", successStart);
31
+ assert.ok(successStart >= 0 && catchStart > successStart, "sendPrompt should keep a bounded success continuation");
32
+ assert.doesNotMatch(sendSource.slice(successStart, catchStart), /elements\.promptInput\.value = "";/, "a delayed routing response must not clear a newer draft");
33
+
34
+ console.log("prompt routing input-clear static checks passed");
@@ -0,0 +1,103 @@
1
+ import assert from "node:assert/strict";
2
+ import vm from "node:vm";
3
+ import { readFile } from "node:fs/promises";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const app = await readFile(join(root, "public", "app.js"), "utf8");
9
+
10
+ function functionSource(name) {
11
+ const start = app.indexOf(`function ${name}(`);
12
+ assert.ok(start >= 0, `${name} should exist`);
13
+ const next = app.slice(start + 1).match(/\nfunction [A-Za-z0-9_$]+\(/);
14
+ const end = next ? start + 1 + next.index : app.length;
15
+ return app.slice(start, end);
16
+ }
17
+
18
+ const context = vm.createContext({ console });
19
+ vm.runInContext(`
20
+ let activeTabId = "tab-1";
21
+ let tabs = [{
22
+ id: "tab-1",
23
+ activity: {
24
+ status: "done",
25
+ isWorking: false,
26
+ completionSerial: 2,
27
+ lastStartedAt: "2020-01-01T00:00:00.000Z",
28
+ lastChangedAt: "2020-01-01T00:00:01.000Z",
29
+ },
30
+ }];
31
+ let tabActivities = new Map();
32
+ const promptRoutingTabs = new Set();
33
+ let tabSeenCompletionSerials = new Map();
34
+ function scheduleTabsRender() {}
35
+
36
+ ${functionSource("normalizeTabActivity")}
37
+ ${functionSource("tabActivityStateChanged")}
38
+ ${functionSource("setTabActivity")}
39
+ ${functionSource("activityForTab")}
40
+ ${functionSource("markTabWorkingLocally")}
41
+ ${functionSource("markTabDoneLocally")}
42
+
43
+ globalThis.activityApi = {
44
+ startRouting() {
45
+ promptRoutingTabs.add("tab-1");
46
+ return markTabWorkingLocally("tab-1");
47
+ },
48
+ finishRouting() {
49
+ promptRoutingTabs.delete("tab-1");
50
+ },
51
+ ingest(activity) {
52
+ return setTabActivity("tab-1", activity);
53
+ },
54
+ markDone() {
55
+ return markTabDoneLocally("tab-1");
56
+ },
57
+ current() {
58
+ return tabActivities.get("tab-1");
59
+ },
60
+ };
61
+ `, context);
62
+
63
+ const api = context.activityApi;
64
+ api.ingest(context.tabs?.[0]?.activity || {
65
+ status: "done",
66
+ isWorking: false,
67
+ completionSerial: 2,
68
+ lastStartedAt: "2020-01-01T00:00:00.000Z",
69
+ lastChangedAt: "2020-01-01T00:00:01.000Z",
70
+ });
71
+ assert.equal(api.startRouting(), true);
72
+ const routingActivity = api.current();
73
+ assert.equal(routingActivity.status, "working");
74
+ assert.equal(routingActivity.isWorking, true);
75
+ assert.notEqual(routingActivity.lastStartedAt, "2020-01-01T00:00:00.000Z", "optimistic routing should start a fresh reconciliation grace period");
76
+ assert.equal(routingActivity.lastChangedAt, routingActivity.lastStartedAt);
77
+
78
+ const staleDone = {
79
+ status: "done",
80
+ isWorking: false,
81
+ completionSerial: 3,
82
+ lastCompletedAt: new Date().toISOString(),
83
+ };
84
+ assert.equal(api.ingest(staleDone).isWorking, true, "an idle/done snapshot must not replace active routing");
85
+ assert.equal(api.markDone(), false, "idle state reconciliation must not synthesize completion during routing");
86
+ assert.equal(api.current().completionSerial, 2, "routing must not create a false completion serial");
87
+
88
+ api.finishRouting();
89
+ assert.equal(api.ingest(staleDone).status, "done", "authoritative completion remains accepted after routing finishes");
90
+
91
+ const sendSource = functionSource("sendPrompt");
92
+ const routingAdd = sendSource.indexOf("promptRoutingTabs.add(targetTabId);");
93
+ const workingMark = sendSource.indexOf("markTabWorkingLocally(targetTabId);");
94
+ const responseApply = sendSource.indexOf("applyResponseTab(response);");
95
+ const successDelete = sendSource.indexOf("promptRoutingTabs.delete(targetTabId);", responseApply);
96
+ const catchStart = sendSource.indexOf("} catch (error)", successDelete);
97
+ const failureDelete = sendSource.indexOf("promptRoutingTabs.delete(targetTabId);", catchStart);
98
+ const idleMark = sendSource.indexOf("markTabIdleLocally(targetTabId);", catchStart);
99
+ assert.ok(routingAdd >= 0 && routingAdd < workingMark, "fresh prompts should enter routing protection before rendering working state");
100
+ assert.ok(responseApply >= 0 && successDelete > responseApply && successDelete < catchStart, "successful routing protection should end only after applying the server handoff response");
101
+ assert.ok(failureDelete > catchStart && failureDelete < idleMark, "failed routing should clear protection before restoring idle state");
102
+
103
+ console.log("prompt routing tab-status checks passed");