@firstpick/pi-package-webui 0.11.0 → 0.11.2

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 (318) hide show
  1. package/DEVELOPMENT.md +181 -12
  2. package/README.md +41 -9
  3. package/TECHNICAL.md +91 -8
  4. package/bin/pi-webui.mjs +5432 -11428
  5. package/index.ts +10 -3
  6. package/lib/codex-cli-usage.mjs +232 -0
  7. package/lib/codex-usage-auth.mjs +39 -3
  8. package/lib/codex-usage-source.mjs +36 -0
  9. package/lib/component-update-state.mjs +2 -2
  10. package/lib/git-workflow-preference-values.mjs +122 -0
  11. package/lib/git-workflow-preferences.mjs +35 -563
  12. package/lib/package-updates.mjs +260 -0
  13. package/lib/rpc-supervisor-client.mjs +8 -4
  14. package/lib/server/app-runners.mjs +1667 -0
  15. package/lib/server/codex-fast-mode.mjs +161 -0
  16. package/lib/server/conversation-mode.mjs +218 -0
  17. package/lib/server/conversation-voice.mjs +318 -0
  18. package/lib/server/extension-ui-requests.mjs +114 -0
  19. package/lib/server/git-generation.mjs +459 -0
  20. package/lib/server/git-mutations.mjs +1827 -0
  21. package/lib/server/git-reads.mjs +608 -0
  22. package/lib/server/git-worktree-sessions.mjs +408 -0
  23. package/lib/server/helper-requests.mjs +82 -0
  24. package/lib/server/no-project-workspaces.mjs +103 -0
  25. package/lib/server/rpc-transports.mjs +394 -0
  26. package/lib/server/settings-store.mjs +544 -0
  27. package/lib/server/sse-delivery.mjs +138 -0
  28. package/lib/server/workspace-files.mjs +563 -0
  29. package/lib/update/supervisor.mjs +4 -0
  30. package/lib/webui-workspaces.mjs +2 -0
  31. package/package.json +5 -5
  32. package/public/activity-agents-controller.mjs +269 -0
  33. package/public/activity-events-controller.mjs +236 -0
  34. package/public/activity-intercom-controller.mjs +627 -0
  35. package/public/activity-queue-controller.mjs +534 -0
  36. package/public/activity-todo-view.mjs +89 -0
  37. package/public/activity-usage-controller.mjs +589 -0
  38. package/public/app.js +3761 -3878
  39. package/public/conversation-overview.css +84 -0
  40. package/public/conversation-overview.mjs +193 -0
  41. package/public/draft-conversations.mjs +135 -0
  42. package/public/focused-composer-controls.css +111 -0
  43. package/public/focused-composer-controls.mjs +143 -0
  44. package/public/focused-composer-disclosure.mjs +223 -0
  45. package/public/focused-shell-adapter.css +264 -0
  46. package/public/focused-shell-adapter.mjs +257 -0
  47. package/public/index.html +137 -80
  48. package/public/model-catalog-order.mjs +63 -0
  49. package/public/platform-event-stream.mjs +64 -0
  50. package/public/project-artifact-controller.mjs +218 -0
  51. package/public/project-file-viewer-controller.mjs +383 -0
  52. package/public/project-git-tools-controller.mjs +181 -0
  53. package/public/project-runners-controller.mjs +220 -0
  54. package/public/service-worker.js +52 -1
  55. package/public/session-attention-scheduler.mjs +182 -0
  56. package/public/session-composer-store.mjs +56 -0
  57. package/public/session-context.mjs +51 -0
  58. package/public/session-extension-requests.mjs +63 -0
  59. package/public/session-shelf-state.mjs +151 -0
  60. package/public/session-shelves.css +171 -0
  61. package/public/session-shelves.mjs +95 -0
  62. package/public/settings-navigation-controller.mjs +249 -0
  63. package/public/settings-navigation.css +61 -0
  64. package/public/settings-resource-controller.mjs +232 -0
  65. package/public/settings-workspace.css +19 -0
  66. package/public/settings-workspace.mjs +175 -0
  67. package/public/shell-actions.mjs +87 -0
  68. package/public/shell-attention-inbox.css +72 -0
  69. package/public/shell-attention-inbox.mjs +198 -0
  70. package/public/shell-context-actions.css +61 -0
  71. package/public/shell-context-actions.mjs +168 -0
  72. package/public/shell-inspector-resize.mjs +124 -0
  73. package/public/shell-navigation-resize.mjs +107 -0
  74. package/public/shell-navigation.mjs +127 -0
  75. package/public/shell-preferences.mjs +108 -0
  76. package/public/shell-surfaces.mjs +99 -0
  77. package/public/shell-tools-launcher.css +97 -0
  78. package/public/shell-tools-launcher.mjs +222 -0
  79. package/public/shell-view-host.mjs +115 -0
  80. package/public/shell-workspace.css +266 -0
  81. package/public/shell-workspace.mjs +402 -0
  82. package/public/sidebar-update-menu.css +190 -0
  83. package/public/sidebar-update-menu.mjs +512 -0
  84. package/public/styles.css +320 -169
  85. package/public/subagent-launch-slot-state.mjs +2 -2
  86. package/public/theme-contract.mjs +1 -1
  87. package/public/themed-selects.css +156 -0
  88. package/public/workspace-choices.mjs +104 -0
  89. package/tests/activity-agents-controller.test.mjs +652 -0
  90. package/tests/activity-events-controller.test.mjs +511 -0
  91. package/tests/app-runner-terminal-static.test.mjs +3 -3
  92. package/tests/append-system-http.test.mjs +7 -6
  93. package/tests/append-system-selector-static.test.mjs +6 -6
  94. package/tests/aur-review-widget-static.test.mjs +11 -3
  95. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  96. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  97. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  98. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  99. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  100. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  101. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  102. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  103. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  104. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  105. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  106. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  107. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  108. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  109. package/tests/browser/control-visibility.spec.mjs +5 -0
  110. package/tests/browser/controls-layout.spec.mjs +21 -2
  111. package/tests/browser/conversation-overview.spec.mjs +251 -0
  112. package/tests/browser/draft-conversations.spec.mjs +276 -0
  113. package/tests/browser/empty-startup-fixture.mjs +135 -0
  114. package/tests/browser/empty-startup.spec.mjs +282 -0
  115. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  116. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  117. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  118. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  119. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  120. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  121. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  122. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  123. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  124. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  125. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  126. package/tests/browser/inspector-header.spec.mjs +221 -0
  127. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  128. package/tests/browser/inspector-resize.spec.mjs +227 -0
  129. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  130. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  131. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  132. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  133. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  134. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  135. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  136. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  137. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  138. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  139. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  140. package/tests/browser/more-row-menus.spec.mjs +258 -0
  141. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  142. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  143. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  144. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  145. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  146. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  147. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  148. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  149. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  150. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  151. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  152. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  153. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  154. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  155. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  156. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  157. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  158. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  159. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  160. package/tests/browser/session-fixture.mjs +118 -0
  161. package/tests/browser/session-ownership.spec.mjs +175 -0
  162. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  163. package/tests/browser/session-shelves.spec.mjs +340 -0
  164. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  165. package/tests/browser/session-summary.spec.mjs +17 -12
  166. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  167. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  168. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  169. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  170. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  171. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  172. package/tests/browser/shell-ownership.spec.mjs +398 -0
  173. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  174. package/tests/browser/shell-rollout.spec.mjs +357 -0
  175. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  176. package/tests/browser/shell-workspace.spec.mjs +433 -0
  177. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  178. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  179. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  180. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  181. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  182. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  183. package/tests/browser/themed-selects.spec.mjs +297 -0
  184. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  185. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  186. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  187. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  188. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  189. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  190. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  191. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  192. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  193. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  194. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  195. package/tests/codex-cli-usage.test.mjs +189 -0
  196. package/tests/codex-fast-mode-static.test.mjs +16 -11
  197. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  198. package/tests/codex-usage-auth.test.mjs +168 -9
  199. package/tests/codex-usage-http.test.mjs +124 -0
  200. package/tests/codex-usage-source.test.mjs +146 -0
  201. package/tests/component-update-api-static.test.mjs +2 -2
  202. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  203. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  204. package/tests/control-visibility-static.test.mjs +3 -3
  205. package/tests/controls-layout-static.test.mjs +5 -5
  206. package/tests/conversation-overview-adapter.test.mjs +100 -0
  207. package/tests/document-artifact-static.test.mjs +2 -1
  208. package/tests/draft-conversations.test.mjs +205 -0
  209. package/tests/empty-startup-launcher.test.mjs +197 -0
  210. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  211. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  212. package/tests/fast-mode-client-static.test.mjs +1 -1
  213. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  214. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  215. package/tests/file-viewer-image-static.test.mjs +15 -11
  216. package/tests/file-viewer-search-static.test.mjs +5 -5
  217. package/tests/fixtures/fake-codex-app-server.mjs +61 -0
  218. package/tests/fixtures/fake-pi.mjs +41 -9
  219. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  220. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  221. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  222. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  223. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  224. package/tests/git-workflow-dispatch.test.mjs +66 -0
  225. package/tests/git-workflow-preferences.test.mjs +9 -1
  226. package/tests/guided-git-activation-static.test.mjs +14 -11
  227. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  228. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  229. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  230. package/tests/http-endpoints-harness.test.mjs +29 -9
  231. package/tests/interaction-state-stability-static.test.mjs +4 -3
  232. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  233. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  234. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  235. package/tests/main-output-loading-static.test.mjs +4 -4
  236. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  237. package/tests/mobile-compact-layout.test.mjs +2 -2
  238. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  239. package/tests/mobile-foundation-static.test.mjs +10 -7
  240. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  241. package/tests/mobile-static.test.mjs +173 -135
  242. package/tests/model-catalog-order.test.mjs +103 -0
  243. package/tests/native-parity.test.mjs +6 -4
  244. package/tests/native-session-choice-owner.test.mjs +102 -0
  245. package/tests/native-update-lifecycle.test.mjs +10 -5
  246. package/tests/no-project-http-harness.test.mjs +328 -0
  247. package/tests/no-project-navigation.test.mjs +54 -0
  248. package/tests/no-project-workspaces.test.mjs +77 -0
  249. package/tests/open-issue-wizard-static.test.mjs +1 -1
  250. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  251. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  252. package/tests/package-updates.test.mjs +630 -0
  253. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  254. package/tests/platform-event-stream.test.mjs +253 -0
  255. package/tests/project-file-viewer-controller.test.mjs +652 -0
  256. package/tests/project-git-tools-adapter.test.mjs +103 -0
  257. package/tests/project-git-tools-controller.test.mjs +577 -0
  258. package/tests/project-runners-controller.test.mjs +453 -0
  259. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  260. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  261. package/tests/questionnaire-dialog.test.mjs +6 -6
  262. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  263. package/tests/rpc-supervisor-host.test.mjs +4 -1
  264. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  265. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  266. package/tests/server-app-runners.test.mjs +536 -0
  267. package/tests/server-codex-fast-mode.test.mjs +346 -0
  268. package/tests/server-conversation-mode.test.mjs +386 -0
  269. package/tests/server-conversation-voice.test.mjs +426 -0
  270. package/tests/server-extension-ui-requests.test.mjs +357 -0
  271. package/tests/server-git-generation.test.mjs +558 -0
  272. package/tests/server-git-mutations.test.mjs +729 -0
  273. package/tests/server-git-reads.test.mjs +381 -0
  274. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  275. package/tests/server-helper-requests.test.mjs +364 -0
  276. package/tests/server-rpc-transports.test.mjs +553 -0
  277. package/tests/server-settings-store.test.mjs +132 -0
  278. package/tests/server-shell-rollout.test.mjs +478 -0
  279. package/tests/server-sse-delivery.test.mjs +410 -0
  280. package/tests/server-workspace-files.test.mjs +546 -0
  281. package/tests/session-attention-scheduler.test.mjs +514 -0
  282. package/tests/session-composer-store.test.mjs +153 -0
  283. package/tests/session-context.test.mjs +134 -0
  284. package/tests/session-extension-requests.test.mjs +193 -0
  285. package/tests/session-ownership-adapter.test.mjs +130 -0
  286. package/tests/session-sampling-ui-static.test.mjs +10 -4
  287. package/tests/session-send-lifetime.test.mjs +140 -0
  288. package/tests/session-shelf-state.test.mjs +348 -0
  289. package/tests/session-shelves-adapter.test.mjs +79 -0
  290. package/tests/session-summary-lifetime.test.mjs +54 -0
  291. package/tests/settings-resource-controller.test.mjs +548 -0
  292. package/tests/shell-action-adapter.test.mjs +169 -0
  293. package/tests/shell-actions.test.mjs +182 -0
  294. package/tests/shell-navigation.test.mjs +348 -0
  295. package/tests/shell-preferences.test.mjs +367 -0
  296. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  297. package/tests/stream-output-isolation-static.test.mjs +1 -1
  298. package/tests/subagent-gate-visibility.test.mjs +1 -1
  299. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  300. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  301. package/tests/subagent-observability-static.test.mjs +2 -2
  302. package/tests/subagent-reliability-integration.test.mjs +13 -30
  303. package/tests/syntax-highlighting-static.test.mjs +3 -3
  304. package/tests/tab-close-continuity-static.test.mjs +1 -1
  305. package/tests/tab-metadata-ordering.test.mjs +99 -0
  306. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  307. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  308. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  309. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  310. package/tests/theme-contract.test.mjs +10 -3
  311. package/tests/theme-customizer-static.test.mjs +1 -1
  312. package/tests/thread-display-title.test.mjs +44 -0
  313. package/tests/update-api-harness.test.mjs +15 -14
  314. package/tests/update-tab-restore-harness.test.mjs +3 -0
  315. package/tests/webui-settings-locking.test.mjs +2 -2
  316. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  317. package/tests/workspace-choices.test.mjs +114 -0
  318. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,197 @@
1
+ import assert from "node:assert/strict";
2
+ import { EventEmitter } from "node:events";
3
+ import { readFile } from "node:fs/promises";
4
+ import { stripTypeScriptTypes } from "node:module";
5
+ import path from "node:path";
6
+ import test from "node:test";
7
+ import { fileURLToPath } from "node:url";
8
+ import vm from "node:vm";
9
+ import { takeValue, tokenizeArgs } from "../../pi-utils/src/cli.ts";
10
+
11
+ const extensionUrl = new URL("../index.ts", import.meta.url);
12
+ const source = await readFile(extensionUrl, "utf8");
13
+ // Evaluate the actual extension without loading integrations or spawning a server.
14
+ const executable = stripTypeScriptTypes(source)
15
+ .replace(/^import\b[\s\S]*?from "[^"]+";\s*/gm, "")
16
+ .replaceAll("import.meta.url", JSON.stringify(extensionUrl.href))
17
+ .replace("export default function (", "function registerExtension(");
18
+ const plain = (value) => JSON.parse(JSON.stringify(value));
19
+ const launcher = fileURLToPath(new URL("../bin/pi-webui-launcher.mjs", import.meta.url));
20
+ const contextCwd = "/fixture/current-project";
21
+ const baseArgs = [launcher, "--host", "127.0.0.1", "--port", "31415"];
22
+
23
+ function harness({ env = {}, fetchJson = async () => ({ ok: false, status: 404 }) } = {}) {
24
+ const launches = [];
25
+ const restores = [];
26
+ const notifications = [];
27
+ const statuses = [];
28
+ const commands = new Map();
29
+ const processEnv = { PI_CODING_AGENT_DIR: "/fixture/agent", ...env };
30
+ const api = vm.runInNewContext(`${executable}\n({ parseStartWebuiArgs, startWebui, usage, registerExtension });`, {
31
+ path, fileURLToPath, tokenizeArgs, takeValue, setTimeout, clearTimeout,
32
+ homedir: () => "/fixture/home",
33
+ process: { env: processEnv, execPath: process.execPath, platform: process.platform },
34
+ spawn(command, args, options) {
35
+ launches.push(plain({ command, args, options }));
36
+ const child = new EventEmitter();
37
+ child.stdout = new EventEmitter();
38
+ child.stderr = new EventEmitter();
39
+ queueMicrotask(() => child.stdout.emit("data", "Pi Web UI: http://127.0.0.1:31415/\n"));
40
+ return child;
41
+ },
42
+ releaseStartedChild: () => {},
43
+ terminateFailedChild: () => assert.fail("fixture child should start successfully"),
44
+ fetchJsonWithTimeoutBase: fetchJson,
45
+ registerSubagentGate: () => ({ dispose() {} }),
46
+ createRestoreFile: async (agentDir, tabs) => {
47
+ restores.push(plain({ agentDir, tabs }));
48
+ return { file: "/fixture/private-restore.json" };
49
+ },
50
+ }, { filename: "index.ts" });
51
+ api.registerExtension({
52
+ on() {},
53
+ registerCommand: (name, command) => commands.set(name, command),
54
+ });
55
+ const ctx = {
56
+ cwd: contextCwd,
57
+ ui: {
58
+ notify: (message, level) => notifications.push({ message, level }),
59
+ setStatus: (name, value) => statuses.push({ name, value }),
60
+ },
61
+ };
62
+ return { ...api, launches, restores, notifications, statuses, ctx, processEnv,
63
+ run: (args) => commands.get("webui-start").handler(args, ctx) };
64
+ }
65
+
66
+ test("default parser leaves the startup project unspecified and preserves session persistence", () => {
67
+ const h = harness();
68
+ assert.deepEqual(plain(h.parseStartWebuiArgs("")), {
69
+ host: "127.0.0.1", port: 31415, open: true, noSession: false, remoteAuth: false, piArgs: [],
70
+ });
71
+ assert.match(h.usage(), /\[--cwd PATH\]/);
72
+ assert.match(h.usage(), /Starts empty unless tabs are restored or --cwd PATH selects a project/);
73
+ });
74
+
75
+ test("explicit cwd supports absolute, relative and quoted paths without consuming Pi arguments", () => {
76
+ const h = harness();
77
+ for (const [input, expected] of [
78
+ ["--cwd /projects/app", "/projects/app"],
79
+ ["--cwd ../other-project", "../other-project"],
80
+ ['--cwd "./project with spaces"', "./project with spaces"],
81
+ ["--cwd '~/project with spaces'", "~/project with spaces"],
82
+ ]) {
83
+ const parsed = h.parseStartWebuiArgs(`${input} -- --cwd /pi-owned --model provider/model`);
84
+ assert.equal(parsed.cwd, expected);
85
+ assert.deepEqual(plain(parsed.piArgs), ["--cwd", "/pi-owned", "--model", "provider/model"]);
86
+ }
87
+ const piOnly = h.parseStartWebuiArgs("-- --cwd /pi-owned");
88
+ assert.equal(piOnly.cwd, undefined);
89
+ });
90
+
91
+ test("cwd requires a value and existing option validation remains effective", () => {
92
+ const h = harness();
93
+ for (const args of ["--cwd", "--cwd --no-open", '--cwd ""']) {
94
+ assert.throws(() => h.parseStartWebuiArgs(args), /--cwd requires a value/);
95
+ }
96
+ assert.throws(() => h.parseStartWebuiArgs('--cwd "unfinished'), /Unclosed/);
97
+ assert.throws(() => h.parseStartWebuiArgs("--unknown"), /Unknown option/);
98
+ assert.throws(() => h.parseStartWebuiArgs("--output-mode invalid"), /normal or compact-v1/);
99
+ assert.throws(() => h.parseStartWebuiArgs("--port 65536"), /between 1 and 65535/);
100
+ });
101
+
102
+ test("default launch omits cwd and no-session flags while retaining spawn cwd and inherited environment", async () => {
103
+ const h = harness({ env: {
104
+ PI_WEBUI_OUTPUT_MODE: "compact-v1", PI_WEBUI_REMOTE_AUTH: "1", PI_WEBUI_RPC_SUPERVISOR: "0",
105
+ PI_WEBUI_RESTORE_FILE: "/fixture/inherited-restore.json", FIXTURE_SETTING: "retained",
106
+ } });
107
+ assert.equal(await h.startWebui(h.parseStartWebuiArgs(""), h.ctx), "http://127.0.0.1:31415/");
108
+ assert.deepEqual(h.launches, [{
109
+ command: process.execPath,
110
+ args: baseArgs,
111
+ options: { cwd: contextCwd, env: h.processEnv, detached: true,
112
+ stdio: ["ignore", "pipe", "pipe"], windowsHide: true },
113
+ }]);
114
+ assert.deepEqual(h.restores, []);
115
+ });
116
+
117
+ test("named options and explicit project forward before the untouched Pi argument tail", async () => {
118
+ const h = harness();
119
+ const options = h.parseStartWebuiArgs('32100 --port 32101 --host ::1 --cwd "../selected project" --no-open --no-session --remote-auth --output-mode compact-v1 --name "Review project" -- --model provider/model --thinking high');
120
+ assert.equal(options.open, false);
121
+ await h.startWebui(options, h.ctx);
122
+ assert.deepEqual(h.launches[0].args, [
123
+ launcher, "--host", "::1", "--port", "32101", "--cwd", "../selected project",
124
+ "--no-session", "--remote-auth", "--output-mode", "compact-v1", "--name", "Review project",
125
+ "--", "--model", "provider/model", "--thinking", "high",
126
+ ]);
127
+ assert.equal(h.launches[0].options.cwd, contextCwd);
128
+ assert.equal(h.parseStartWebuiArgs("--remote-auth --no-remote-auth").remoteAuth, false);
129
+ assert.equal(h.parseStartWebuiArgs("--output-mode normal").outputMode, "normal");
130
+ });
131
+
132
+ test("restore descriptors use a private file with or without an explicit project", async () => {
133
+ const tabs = [{ id: "tab-7", index: 7, title: "Existing", cwd: "/fixture/restored-project",
134
+ sessionFile: "/fixture/session.jsonl", conversationStarted: true }];
135
+ for (const args of ["", "--cwd /fixture/selected-project"]) {
136
+ const h = harness({ env: { PI_WEBUI_RESTORE_FILE: "/fixture/stale-restore.json" } });
137
+ await h.startWebui(h.parseStartWebuiArgs(args), h.ctx, tabs);
138
+ assert.deepEqual(h.restores, [{ agentDir: "/fixture/agent", tabs }]);
139
+ assert.deepEqual(h.launches[0].args, [...baseArgs, ...(args ? ["--cwd", "/fixture/selected-project"] : [])]);
140
+ assert.equal(h.launches[0].options.env.PI_WEBUI_RESTORE_FILE, "/fixture/private-restore.json");
141
+ assert.equal(h.processEnv.PI_WEBUI_RESTORE_FILE, "/fixture/stale-restore.json");
142
+ }
143
+ });
144
+
145
+ test("registered command starts empty when no server exists and reports parser failures without launch", async () => {
146
+ const h = harness();
147
+ await h.run("--no-open");
148
+ assert.equal(h.launches.length, 1);
149
+ assert.deepEqual(h.launches[0].args, baseArgs);
150
+ assert.match(h.notifications[0].message, /Pi Web UI started/);
151
+ assert.equal(h.notifications[0].level, "info");
152
+ await h.run("--cwd --no-open");
153
+ assert.equal(h.launches.length, 1);
154
+ assert.match(h.notifications.at(-1).message, /--cwd requires a value[\s\S]*Usage:.*--cwd PATH/);
155
+ assert.equal(h.notifications.at(-1).level, "error");
156
+ });
157
+
158
+ test("existing server restart retains open tabs, strips sessions only on request, and keeps empty servers empty", async () => {
159
+ for (const scenario of [
160
+ { args: "--no-open", tabs: [{ id: "open-1", cwd: "/fixture/project", sessionFile: "/fixture/session.jsonl" }] },
161
+ { args: "--no-open --no-session --cwd ./selected", tabs: [{ id: "open-1", cwd: "/fixture/project", sessionFile: "/fixture/session.jsonl" }] },
162
+ { args: "--no-open", tabs: [] },
163
+ ]) {
164
+ let online = true;
165
+ const requests = [];
166
+ const h = harness({ fetchJson: async (url, init) => {
167
+ const endpoint = new URL(url).pathname;
168
+ requests.push([endpoint, init.method || "GET"]);
169
+ if (endpoint === "/api/health") return { ok: online, status: online ? 200 : 404,
170
+ body: { ok: online, webuiVersion: "fixture", tabs: scenario.tabs } };
171
+ if (endpoint === "/api/webui-status") return { ok: true, status: 200,
172
+ body: { ok: true, data: { tabs: scenario.tabs, restorableTabs: [{ id: "closed-1" }] } } };
173
+ assert.equal(endpoint, "/api/shutdown");
174
+ online = false;
175
+ return { ok: true, status: 200, body: { ok: true } };
176
+ } });
177
+ await h.run(scenario.args);
178
+ assert.deepEqual(requests, [["/api/health", "GET"], ["/api/webui-status", "GET"],
179
+ ["/api/shutdown", "POST"], ["/api/health", "GET"]]);
180
+ assert.equal(h.launches.length, 1);
181
+ assert.equal(h.launches[0].options.cwd, contextCwd);
182
+ if (scenario.tabs.length) {
183
+ const restored = h.restores[0].tabs;
184
+ assert.equal(restored.length, 1);
185
+ assert.equal(restored[0].id, "open-1");
186
+ assert.equal(restored[0].cwd, "/fixture/project");
187
+ assert.equal(restored[0].sessionFile, scenario.args.includes("--no-session") ? undefined : "/fixture/session.jsonl");
188
+ assert.equal(h.launches[0].options.env.PI_WEBUI_RESTORE_FILE, "/fixture/private-restore.json");
189
+ assert.match(h.notifications[0].message, /Pi Web UI restarted[\s\S]*Restored 1 Web UI tab/);
190
+ } else {
191
+ assert.deepEqual(h.restores, []);
192
+ assert.deepEqual(h.launches[0].args, baseArgs);
193
+ assert.equal(h.launches[0].options.env.PI_WEBUI_RESTORE_FILE, undefined);
194
+ }
195
+ assert.equal(h.notifications[0].level, "info");
196
+ }
197
+ });
@@ -11,10 +11,12 @@ const [html, app, styles, serviceWorker] = await Promise.all([
11
11
  readFile(join(root, "public", "service-worker.js"), "utf8"),
12
12
  ]);
13
13
 
14
+ const events = await readFile(join(root, "public", "activity-events-controller.mjs"), "utf8");
15
+
14
16
  function functionSource(source, name) {
15
17
  const start = source.indexOf(`function ${name}(`);
16
18
  assert.ok(start >= 0, `${name} should exist`);
17
- const next = source.slice(start + 1).match(/\n(?:async )?function [A-Za-z0-9_$]+\(/);
19
+ const next = source.slice(start + 1).match(/\n\s*(?:async )?function [A-Za-z0-9_$]+\(/);
18
20
  const end = next ? start + 1 + next.index : source.length;
19
21
  return source.slice(start, end);
20
22
  }
@@ -27,27 +29,27 @@ assert.match(html, /role="separator"[\s\S]*id="eventTreeContextMenuAction"[^>]*r
27
29
  assert.match(html, /<label for="eventFilterSelect">Show<\/label>[\s\S]*id="eventFilterSelect"[\s\S]*value="all">All events<[\s\S]*value="errors">Errors \/ failures<[\s\S]*value="warnings">Warnings<[\s\S]*value="tools">Tool activity<[\s\S]*value="tree">Tree available</, "Events should expose the recommended native filter choices");
28
30
  assert.match(html, /id="eventFilterStatus"[^>]*role="status"[^>]*aria-live="polite"[\s\S]*id="eventFilterEmpty"[^>]*hidden/, "the filter should expose live counts and an empty state");
29
31
 
30
- const normalizeDisplaySource = functionSource(app, "normalizeEventDisplayMode");
32
+ const normalizeDisplaySource = functionSource(events, "normalizeEventDisplayMode");
31
33
  assert.match(normalizeDisplaySource, /value === "compact" \? "compact" : "detailed"/, "unknown values should fall back to detailed mode");
32
- assert.match(functionSource(app, "readStoredEventDisplayMode"), /localStorage\.getItem\(EVENT_DISPLAY_MODE_STORAGE_KEY\)/, "the display preference should restore from browser-local storage");
33
- const setDisplaySource = functionSource(app, "setEventDisplayMode");
34
- assert.match(setDisplaySource, /localStorage\.setItem\(EVENT_DISPLAY_MODE_STORAGE_KEY, eventDisplayMode\)/, "display choices should persist");
35
- assert.match(functionSource(app, "syncEventDisplayModeUi"), /eventLog\.dataset\.displayMode = eventDisplayMode[\s\S]*eventDisplayDetailedAction[\s\S]*eventDisplayCompactAction/, "the current choice should update the log and radio menu state");
34
+ assert.match(functionSource(events, "readStoredEventDisplayMode"), /readPreference\(EVENT_DISPLAY_MODE_STORAGE_KEY\)/, "the display preference should restore from browser-local storage");
35
+ const setDisplaySource = functionSource(events, "setEventDisplayMode");
36
+ assert.match(setDisplaySource, /writePreference\(EVENT_DISPLAY_MODE_STORAGE_KEY, eventDisplayMode\)/, "display choices should persist");
37
+ assert.match(functionSource(events, "syncEventDisplayModeUi"), /eventLog\.dataset\.displayMode = eventDisplayMode[\s\S]*eventDisplayDetailedAction[\s\S]*eventDisplayCompactAction/, "the current choice should update the log and radio menu state");
36
38
 
37
- const normalizeFilterSource = functionSource(app, "normalizeEventFilter");
39
+ const normalizeFilterSource = functionSource(events, "normalizeEventFilter");
38
40
  assert.match(normalizeFilterSource, /EVENT_FILTER_VALUES\.has\(value\) \? value : "all"/, "unknown filters should fall back to all events");
39
- assert.match(functionSource(app, "readStoredEventFilter"), /localStorage\.getItem\(EVENT_FILTER_STORAGE_KEY\)/, "the event filter should restore from browser-local storage");
40
- const filterMatchSource = functionSource(app, "eventRowMatchesFilter");
41
+ assert.match(functionSource(events, "readStoredEventFilter"), /readPreference\(EVENT_FILTER_STORAGE_KEY\)/, "the event filter should restore from browser-local storage");
42
+ const filterMatchSource = functionSource(events, "eventRowMatchesFilter");
41
43
  for (const contract of [
42
44
  /filter === "errors"[\s\S]*eventLevel === "error"/,
43
45
  /filter === "warnings"[\s\S]*eventLevel === "warn"/,
44
46
  /filter === "tools"[\s\S]*eventToolPhase/,
45
47
  /filter === "tree"[\s\S]*eventTreeAvailable === "true"/,
46
48
  ]) assert.match(filterMatchSource, contract, "each visible filter should have an explicit row predicate");
47
- const applyFilterSource = functionSource(app, "applyEventFilter");
49
+ const applyFilterSource = functionSource(events, "applyEventFilter");
48
50
  assert.match(applyFilterSource, /line\.hidden = !matches[\s\S]*eventFilterStatus[\s\S]*eventFilterEmpty\.hidden/, "filtering should hide rows in place and update count and empty-state feedback");
49
- const setFilterSource = functionSource(app, "setEventFilter");
50
- assert.match(setFilterSource, /localStorage\.setItem\(EVENT_FILTER_STORAGE_KEY, eventFilter\)/, "filter choices should persist");
51
+ const setFilterSource = functionSource(events, "setEventFilter");
52
+ assert.match(setFilterSource, /writePreference\(EVENT_FILTER_STORAGE_KEY, eventFilter\)/, "filter choices should persist");
51
53
  assert.match(app, /eventFilterSelect\?\.addEventListener\("change"[\s\S]*setEventFilter\(elements\.eventFilterSelect\.value\)/, "the native select should apply its selected filter");
52
54
  assert.match(app, /event\.key === EVENT_FILTER_STORAGE_KEY[\s\S]*setEventFilter\(event\.newValue, \{ persist: false \}\)/, "filter changes should synchronize across same-origin tabs");
53
55
 
@@ -71,13 +73,15 @@ assert.match(lifecycleArgumentsSource, /toolLifecycleEventDetails[\s\S]*toolEven
71
73
  assert.match(detailsSource, /phase === "finish"[\s\S]*toolEventStartedAt\.get\(toolEventTimerKey\(event\)\)[\s\S]*boundedToolEventTarget\(event\) \|\| startRecord\?\.target/, "finish rows should reuse the matching bounded start target when completion args omit it");
72
74
 
73
75
  // Every row exposes display choices; stable lifecycle rows alone expose Tree navigation.
74
- const addEventSource = functionSource(app, "addEvent");
76
+ const addEventSource = functionSource(events, "addEvent");
75
77
  assert.match(addEventSource, /const toolLifecycle = \["start", "finish"\]\.includes\(toolEventPhase\)[\s\S]*stableToolCallId && toolLifecycle/, "only stable lifecycle rows should be Tree eligible");
76
78
  assert.match(addEventSource, /line\.dataset\.eventLevel = String\(level[\s\S]*line\.dataset\.eventTreeAvailable = String\(!!treeEligible\)/, "rows should retain bounded filter metadata without copying payloads");
77
79
  assert.match(addEventSource, /if \(toolLifecycle\) line\.dataset\.eventToolPhase = toolEventPhase/, "all tool lifecycle rows should remain visually identifiable in compact mode");
78
- assert.match(addEventSource, /while \(elements\.eventLog\.children\.length > 120\)[\s\S]*applyEventFilter\(\)/, "new rows should apply the active filter after preserving the existing history bound");
80
+ assert.match(addEventSource, /while \(nodes\.eventLog\.children\.length > 120\)[\s\S]*applyEventFilter\(\)/, "new rows should apply the active filter after preserving the existing history bound");
79
81
  assert.match(addEventSource, /setAttribute\("aria-keyshortcuts", "ContextMenu Shift\+F10"\)/, "every event row should expose keyboard display choices");
80
- assert.match(addEventSource, /addEventListener\("click", \(\) => jumpToChatEvent\(line\)\)/, "event rows should preserve click-to-jump");
82
+ assert.match(events, /nodes\.eventLog\.addEventListener\("click", jumpToEvent\)/, "the canonical log should own delegated click-to-jump");
83
+ assert.match(functionSource(events, "jumpToEvent"), /row\.parentNode !== nodes\.eventLog[\s\S]*onJump\(row\)/, "delegated clicks should retain the exact canonical row");
84
+ assert.match(app, /onJump: jumpToChatEvent/, "the controller should use existing chat navigation");
81
85
  assert.match(
82
86
  functionSource(app, "handleEvent"),
83
87
  /case "tool_execution_start":[\s\S]*isIntercomTransportToolName\(event\.toolName\)[\s\S]*break;[\s\S]*toolLifecycleEventArguments\(event, "start"\)[\s\S]*case "tool_execution_end":[\s\S]*isIntercomTransportToolName\(event\.toolName\)[\s\S]*break;[\s\S]*toolLifecycleEventArguments\(event, "finish"\)/,
@@ -124,8 +128,8 @@ assert.match(styles, /\.event-log\[data-display-mode="compact"\] \.event\[data-e
124
128
  assert.match(styles, /\.event-tree-context-menu \{[\s\S]*max-width: calc\(100vw - 1rem\)/, "the dedicated menu should remain viewport bounded");
125
129
 
126
130
  // Cache tuple for this browser-asset change.
127
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156";/, "the PWA cache identity should advance");
128
- assert.match(html, /styles\.css\?v=154/, "compact-mode styles should advance the stylesheet revision");
129
- assert.match(html, /data-app-src="\/app\.js\?v=185"/, "the app query revision should advance");
131
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200";/, "the PWA cache identity should advance");
132
+ assert.match(html, /styles\.css\?v=167/, "compact-mode styles should advance the stylesheet revision");
133
+ assert.match(html, /data-app-src="\/app\.js\?v=220"/, "the app query revision should advance");
130
134
 
131
135
  console.log("events-tree-context-menu-static.test.mjs passed");
@@ -0,0 +1,302 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { randomUUID } from "node:crypto";
4
+ import { tmpdir } from "node:os";
5
+ import { resolve } from "node:path";
6
+ import { createInterface } from "node:readline";
7
+ import test from "node:test";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const fixture = fileURLToPath(new URL("./fixtures/fake-pi.mjs", import.meta.url));
11
+ const defaultModel = { provider: "fake", id: "fake-model" };
12
+ const alternateModel = { provider: "fake", id: "fake-model-alt" };
13
+ const catalog = [
14
+ { ...defaultModel, name: "Fake Model" },
15
+ { ...alternateModel, name: "Fake Alternate Model" },
16
+ ];
17
+
18
+ function startFixture(t, { env = {}, args = [], cwd = tmpdir() } = {}) {
19
+ // Ambient fixture flags must not turn a compatibility check into another mode.
20
+ const cleanEnv = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("FAKE_PI_")));
21
+ const child = spawn(process.execPath, [fixture, ...args], {
22
+ cwd,
23
+ env: { ...cleanEnv, ...env },
24
+ stdio: ["pipe", "pipe", "pipe"],
25
+ });
26
+ const pending = new Map();
27
+ const records = [];
28
+ let nextId = 0;
29
+ let failure;
30
+ let stderr = "";
31
+ const fail = (error) => {
32
+ failure = error;
33
+ for (const request of pending.values()) request.reject(error);
34
+ pending.clear();
35
+ };
36
+ child.on("error", fail);
37
+ child.stdin.on("error", fail);
38
+ child.stderr.setEncoding("utf8");
39
+ child.stderr.on("data", (text) => {
40
+ stderr = (stderr + text).slice(-8192);
41
+ });
42
+ const lines = createInterface({ input: child.stdout });
43
+ lines.on("line", (line) => {
44
+ try {
45
+ assert.ok(records.length < 200, "fixture output exceeded the test bound");
46
+ const record = JSON.parse(line);
47
+ records.push(record);
48
+ if (record.type === "response") {
49
+ const request = pending.get(record.id);
50
+ assert.ok(request, `unexpected response ${record.id}`);
51
+ assert.equal(record.command, request.type);
52
+ pending.delete(record.id);
53
+ request.resolve(record);
54
+ }
55
+ } catch (error) {
56
+ fail(error);
57
+ child.kill("SIGKILL");
58
+ }
59
+ });
60
+ const exited = new Promise((resolveExit) => {
61
+ child.once("close", (code, signal) => {
62
+ fail(new Error(`fixture closed: code=${code}, signal=${signal}, stderr=${stderr}`));
63
+ resolveExit({ code, signal });
64
+ });
65
+ });
66
+ let closing;
67
+ const close = () => {
68
+ closing ||= (async () => {
69
+ let forced = false;
70
+ const timer = setTimeout(() => {
71
+ forced = true;
72
+ child.kill("SIGKILL");
73
+ }, 1500);
74
+ child.stdin.end();
75
+ try {
76
+ const result = await exited;
77
+ assert.equal(forced, false, "fixture did not exit after stdin closed");
78
+ assert.deepEqual(result, { code: 0, signal: null }, stderr);
79
+ assert.equal(stderr, "");
80
+ } finally {
81
+ clearTimeout(timer);
82
+ lines.close();
83
+ }
84
+ })();
85
+ return closing;
86
+ };
87
+ t.after(close);
88
+ return {
89
+ records,
90
+ close,
91
+ request(type, data = {}) {
92
+ if (failure) return Promise.reject(failure);
93
+ const id = `request-${++nextId}`;
94
+ return new Promise((resolveReply, reject) => {
95
+ const timer = setTimeout(() => {
96
+ pending.delete(id);
97
+ reject(new Error(`fixture timed out on ${type}: ${stderr}`));
98
+ }, 2000);
99
+ pending.set(id, {
100
+ type,
101
+ resolve: (reply) => {
102
+ clearTimeout(timer);
103
+ resolveReply(reply);
104
+ },
105
+ reject: (error) => {
106
+ clearTimeout(timer);
107
+ reject(error);
108
+ },
109
+ });
110
+ child.stdin.write(`${JSON.stringify({ ...data, id, type })}\n`);
111
+ });
112
+ },
113
+ };
114
+ }
115
+
116
+ async function state(driver) {
117
+ const reply = await driver.request("get_state");
118
+ assert.equal(reply.success, true);
119
+ return reply.data;
120
+ }
121
+
122
+ async function selectModel(driver, model) {
123
+ const reply = await driver.request("set_model", { provider: model.provider, modelId: model.id });
124
+ assert.equal(reply.success, true);
125
+ assert.deepEqual(reply.data, model);
126
+ }
127
+
128
+ test("ownership catalog is deterministic and successful models survive rejection", { timeout: 10_000 }, async (t) => {
129
+ const driver = startFixture(t, { env: { FAKE_PI_SESSION_OWNERSHIP: "1" } });
130
+ assert.deepEqual((await state(driver)).model, defaultModel);
131
+ assert.deepEqual((await driver.request("get_available_models")).data, { models: catalog });
132
+ for (const model of [alternateModel, defaultModel, alternateModel]) {
133
+ await selectModel(driver, model);
134
+ assert.deepEqual((await state(driver)).model, model);
135
+ }
136
+ const rejected = await driver.request("set_model", { provider: "fake", modelId: "missing-model" });
137
+ assert.equal(rejected.success, false);
138
+ assert.equal(rejected.error, "Model not found: fake/missing-model");
139
+ assert.deepEqual((await state(driver)).model, alternateModel);
140
+ assert.deepEqual((await driver.request("get_available_models")).data, { models: catalog });
141
+ const customModel = { provider: "custom-fake", id: "custom-model" };
142
+ await selectModel(driver, customModel);
143
+ assert.deepEqual((await state(driver)).model, customModel);
144
+ });
145
+
146
+ test("processes own distinct sessions and new sessions preserve models and peers", { timeout: 10_000 }, async (t) => {
147
+ const first = startFixture(t, { env: { FAKE_PI_SESSION_OWNERSHIP: "1" } });
148
+ const second = startFixture(t, { env: { FAKE_PI_SESSION_OWNERSHIP: "1" } });
149
+ const initialFirst = await state(first);
150
+ const initialSecond = await state(second);
151
+ assert.notEqual(initialFirst.sessionId, initialSecond.sessionId);
152
+ assert.match(initialFirst.sessionId, /^fake-session-.+/);
153
+ assert.equal(initialFirst.sessionFile, undefined);
154
+ assert.equal(initialSecond.sessionFile, undefined);
155
+ await selectModel(first, alternateModel);
156
+ assert.deepEqual(await state(second), initialSecond);
157
+ const ids = new Set([initialFirst.sessionId, initialSecond.sessionId]);
158
+ for (let generation = 0; generation < 2; generation += 1) {
159
+ const reply = await first.request("new_session");
160
+ assert.equal(reply.success, true);
161
+ assert.deepEqual(reply.data, {});
162
+ const current = await state(first);
163
+ assert.equal(ids.has(current.sessionId), false);
164
+ ids.add(current.sessionId);
165
+ assert.deepEqual(current.model, alternateModel);
166
+ assert.equal(current.sessionFile, undefined);
167
+ assert.equal((await state(first)).sessionId, current.sessionId);
168
+ assert.deepEqual(await state(second), initialSecond);
169
+ }
170
+ });
171
+
172
+ test("explicit and continuity paths share stable normalized identities without session files", { timeout: 15_000 }, async (t) => {
173
+ const relativePath = `fake-pi-ownership-${randomUUID()}/../fake-pi-${randomUUID()}.jsonl`;
174
+ const absolutePath = resolve(tmpdir(), relativePath);
175
+ const explicit = startFixture(t, {
176
+ args: ["--session", relativePath],
177
+ env: { FAKE_PI_SESSION_OWNERSHIP: "1" },
178
+ });
179
+ const initial = await state(explicit);
180
+ assert.equal(initial.sessionFile, relativePath);
181
+ const samePath = startFixture(t, {
182
+ cwd: process.cwd(),
183
+ args: ["--session", absolutePath],
184
+ env: {
185
+ FAKE_PI_SESSION_OWNERSHIP: "1",
186
+ FAKE_PI_CONTINUITY_MODE: "1",
187
+ FAKE_PI_CONTINUITY_SESSION_FILE: `${absolutePath}.ignored`,
188
+ },
189
+ });
190
+ assert.equal((await state(samePath)).sessionId, initial.sessionId);
191
+ assert.equal((await state(samePath)).sessionFile, absolutePath);
192
+ const continuity = startFixture(t, {
193
+ env: { FAKE_PI_SESSION_OWNERSHIP: "1", FAKE_PI_CONTINUITY_MODE: "1", FAKE_PI_CONTINUITY_SESSION_FILE: absolutePath },
194
+ });
195
+ assert.equal((await state(continuity)).sessionId, initial.sessionId);
196
+ const differentPath = startFixture(t, {
197
+ args: ["--session", `${absolutePath}.other`],
198
+ env: { FAKE_PI_SESSION_OWNERSHIP: "1" },
199
+ });
200
+ assert.notEqual((await state(differentPath)).sessionId, initial.sessionId);
201
+ await selectModel(explicit, alternateModel);
202
+ await explicit.request("new_session");
203
+ const renewed = await state(explicit);
204
+ assert.notEqual(renewed.sessionId, initial.sessionId);
205
+ assert.deepEqual(renewed.model, alternateModel);
206
+ assert.equal((await state(samePath)).sessionId, initial.sessionId);
207
+ assert.deepEqual((await state(samePath)).model, defaultModel);
208
+ const restarted = startFixture(t, {
209
+ args: ["--session", absolutePath],
210
+ env: { FAKE_PI_SESSION_OWNERSHIP: "1" },
211
+ });
212
+ assert.equal((await state(restarted)).sessionId, initial.sessionId);
213
+ assert.deepEqual((await state(restarted)).model, defaultModel);
214
+ });
215
+
216
+ test("continuity path is ignored unless continuity mode is enabled", { timeout: 10_000 }, async (t) => {
217
+ const env = { FAKE_PI_SESSION_OWNERSHIP: "1", FAKE_PI_CONTINUITY_SESSION_FILE: "ignored.jsonl" };
218
+ const first = await state(startFixture(t, { env }));
219
+ const second = await state(startFixture(t, { env }));
220
+ assert.equal(first.sessionFile, undefined);
221
+ assert.equal(second.sessionFile, undefined);
222
+ assert.notEqual(first.sessionId, second.sessionId);
223
+ });
224
+
225
+ test("unflagged explicit and continuity paths keep their original reply shapes", { timeout: 10_000 }, async (t) => {
226
+ const sessionFile = "./unresolved/../fake-session.jsonl";
227
+ const explicit = startFixture(t, { args: ["--session", sessionFile] });
228
+ const continuity = startFixture(t, {
229
+ env: { FAKE_PI_CONTINUITY_MODE: "1", FAKE_PI_CONTINUITY_SESSION_FILE: sessionFile },
230
+ });
231
+ for (const driver of [explicit, continuity]) {
232
+ const initial = await state(driver);
233
+ assert.equal(initial.sessionFile, sessionFile);
234
+ assert.equal(initial.sessionId, "fake-session");
235
+ await driver.request("new_session");
236
+ assert.deepEqual(await state(driver), initial);
237
+ }
238
+ });
239
+
240
+ for (const flag of [undefined, "0", "true"]) {
241
+ test(`ownership is default off for ${String(flag)} and preserves baseline replies`, { timeout: 10_000 }, async (t) => {
242
+ const driver = startFixture(t, { env: flag === undefined ? {} : { FAKE_PI_SESSION_OWNERSHIP: flag } });
243
+ const baseline = {
244
+ model: defaultModel,
245
+ thinkingLevel: "off",
246
+ isStreaming: false,
247
+ isCompacting: false,
248
+ steeringMode: "one-at-a-time",
249
+ followUpMode: "one-at-a-time",
250
+ sessionId: "fake-session",
251
+ sessionName: "fake",
252
+ autoCompactionEnabled: false,
253
+ messageCount: 0,
254
+ pendingMessageCount: 0,
255
+ };
256
+ assert.deepEqual(await state(driver), baseline);
257
+ assert.deepEqual((await driver.request("get_available_models")).data, { models: [catalog[0]] });
258
+ await selectModel(driver, alternateModel);
259
+ assert.deepEqual(await state(driver), baseline);
260
+ assert.equal((await driver.request("set_model", { provider: "fake", modelId: "missing-model" })).success, false);
261
+ assert.deepEqual((await driver.request("new_session")).data, {});
262
+ assert.deepEqual(await state(driver), baseline);
263
+ assert.deepEqual((await driver.request("prompt", { message: "normal baseline prompt" })).data, { output: "fake prompt accepted" });
264
+ assert.deepEqual((await driver.request("get_messages")).data.messages, [
265
+ { role: "user", content: "fake prompt", timestamp: 1000 },
266
+ { role: "assistant", content: [{ type: "text", text: "fake answer" }], timestamp: 2000 },
267
+ { role: "user", content: "fake follow-up", timestamp: 3000 },
268
+ ]);
269
+ assert.ok(driver.records.every((record) => record.type === "response"));
270
+ });
271
+ }
272
+
273
+ for (const enabled of [false, true]) {
274
+ test(`Codex model retains precedence with ownership ${enabled}`, { timeout: 10_000 }, async (t) => {
275
+ const driver = startFixture(t, { env: enabled ? { FAKE_PI_SESSION_OWNERSHIP: "1" } : {} });
276
+ await selectModel(driver, alternateModel);
277
+ await driver.request("prompt", { message: "fixture codex astra" });
278
+ const codexModel = { provider: "openai-codex", api: "openai-codex-responses", id: "gpt-6-astra" };
279
+ assert.deepEqual((await state(driver)).model, codexModel);
280
+ await selectModel(driver, defaultModel);
281
+ await selectModel(driver, alternateModel);
282
+ await driver.request("new_session");
283
+ assert.deepEqual((await state(driver)).model, codexModel);
284
+ await driver.request("prompt", { message: "fixture codex reset" });
285
+ assert.deepEqual((await state(driver)).model, enabled ? alternateModel : defaultModel);
286
+ assert.deepEqual(driver.records.filter((record) => record.type !== "response").map((record) => record.type), [
287
+ "agent_start", "agent_settled", "agent_start", "agent_settled",
288
+ ]);
289
+ });
290
+ }
291
+
292
+ for (const enabled of [false, true]) {
293
+ test(`stdin close cancels pending scripted voice events with ownership ${enabled}`, { timeout: 10_000 }, async (t) => {
294
+ const driver = startFixture(t, {
295
+ env: { FAKE_PI_VOICE_SCRIPTS: "1", ...(enabled ? { FAKE_PI_SESSION_OWNERSHIP: "1" } : {}) },
296
+ });
297
+ assert.deepEqual((await driver.request("prompt", { message: "voice test slow" })).data, { output: "voice scripted prompt accepted" });
298
+ assert.equal((await state(driver)).isStreaming, true);
299
+ await driver.close();
300
+ assert.equal(driver.records.some((record) => record.type === "agent_settled"), false);
301
+ });
302
+ }
@@ -159,7 +159,7 @@ assert.match(worker, /pi-webui-pwa-v\d+[\s\S]*?"\/fast-output-live\.mjs"/, "PWA
159
159
  assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>/, "the sidebar should mark compact mode as experimental");
160
160
  assert.match(html, /Lightweight browser rendering; Markdown final output; live thinking expanded; stored thinking grouped and collapsed/, "the sidebar should distinguish compact rendering from model inference");
161
161
  // Intent preserved: the guarded PWA entry point must advance whenever app wiring changes.
162
- assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=185"/, "the guarded PWA entry point should cache-bust browser wiring");
162
+ assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=220"/, "the guarded PWA entry point should cache-bust browser wiring");
163
163
  assert.match(JSON.parse(packageRaw).scripts.check, /node --check public\/fast-output-live\.mjs/, "package checks should parse the compact helper");
164
164
 
165
165
  const events = createFastModeOutputEvents();
@@ -166,7 +166,7 @@ assert.match(functionSource("closeTerminalTabs"), /clearFeatureDecisionStateForT
166
166
  assert.match(app, /case "webui_connected":[\s\S]*clearFeatureDecisionStateForTab\(connectedTabId, \{ render: true \}\)[\s\S]*scheduleForegroundReconcile\("event stream reconnect", 0\)/, "reconnect should clear local state before authoritative replay");
167
167
  assert.match(app, /statusKey === FEATURE_DECISION_OUTPUT_STATUS_KEY[\s\S]*handleFeatureDecisionOutputStatus[\s\S]*return;[\s\S]*statusKey === FEATURE_CATEGORY_STATUS_KEY[\s\S]*return;[\s\S]*statusEntries\.set/, "both feature statuses should be intercepted before generic footer storage while preserving category handling");
168
168
 
169
- assert.match(html, /\/styles\.css\?v=154/, "integrated stylesheet changes should advance the cache query");
170
- assert.match(html, /\/app\.js\?v=185/, "integrated app changes should advance the cache query");
169
+ assert.match(html, /\/styles\.css\?v=167/, "integrated stylesheet changes should advance the cache query");
170
+ assert.match(html, /\/app\.js\?v=220/, "integrated app changes should advance the cache query");
171
171
 
172
172
  console.log("feature decision-output popup static checks passed");
@@ -9,7 +9,7 @@ const [catalog, app, development, manifest] = await Promise.all([
9
9
  ]);
10
10
 
11
11
  assert.equal(manifest.name, "@firstpick/pi-extension-feature-system-prompt");
12
- assert.equal(manifest.version, "0.1.6");
12
+ assert.equal(manifest.version, "0.1.7");
13
13
  assert.match(
14
14
  catalog,
15
15
  /\["featureSystemPrompt", "@firstpick\/pi-extension-feature-system-prompt", "\^0\.1\.3"\]/,