@firstpick/pi-package-webui 0.11.1 → 0.11.3

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 (310) hide show
  1. package/DEVELOPMENT.md +151 -12
  2. package/README.md +34 -6
  3. package/TECHNICAL.md +75 -8
  4. package/bin/pi-webui.mjs +5390 -11423
  5. package/index.ts +10 -3
  6. package/lib/component-update-state.mjs +2 -2
  7. package/lib/git-workflow-preference-values.mjs +122 -0
  8. package/lib/git-workflow-preferences.mjs +35 -563
  9. package/lib/package-updates.mjs +260 -0
  10. package/lib/rpc-supervisor-client.mjs +8 -4
  11. package/lib/server/app-runners.mjs +1667 -0
  12. package/lib/server/codex-fast-mode.mjs +161 -0
  13. package/lib/server/conversation-mode.mjs +218 -0
  14. package/lib/server/conversation-voice.mjs +318 -0
  15. package/lib/server/extension-ui-requests.mjs +114 -0
  16. package/lib/server/git-generation.mjs +459 -0
  17. package/lib/server/git-mutations.mjs +1827 -0
  18. package/lib/server/git-reads.mjs +608 -0
  19. package/lib/server/git-worktree-sessions.mjs +408 -0
  20. package/lib/server/helper-requests.mjs +82 -0
  21. package/lib/server/no-project-workspaces.mjs +103 -0
  22. package/lib/server/rpc-transports.mjs +394 -0
  23. package/lib/server/settings-store.mjs +544 -0
  24. package/lib/server/sse-delivery.mjs +138 -0
  25. package/lib/server/workspace-files.mjs +563 -0
  26. package/lib/update/supervisor.mjs +4 -0
  27. package/lib/webui-workspaces.mjs +2 -0
  28. package/package.json +4 -4
  29. package/public/activity-agents-controller.mjs +269 -0
  30. package/public/activity-events-controller.mjs +236 -0
  31. package/public/activity-intercom-controller.mjs +627 -0
  32. package/public/activity-queue-controller.mjs +534 -0
  33. package/public/activity-todo-view.mjs +89 -0
  34. package/public/activity-usage-controller.mjs +589 -0
  35. package/public/app.js +3761 -3886
  36. package/public/conversation-overview.css +84 -0
  37. package/public/conversation-overview.mjs +193 -0
  38. package/public/draft-conversations.mjs +135 -0
  39. package/public/focused-composer-controls.css +111 -0
  40. package/public/focused-composer-controls.mjs +143 -0
  41. package/public/focused-composer-disclosure.mjs +223 -0
  42. package/public/focused-shell-adapter.css +264 -0
  43. package/public/focused-shell-adapter.mjs +257 -0
  44. package/public/index.html +137 -80
  45. package/public/model-catalog-order.mjs +63 -0
  46. package/public/platform-event-stream.mjs +64 -0
  47. package/public/project-artifact-controller.mjs +218 -0
  48. package/public/project-file-viewer-controller.mjs +383 -0
  49. package/public/project-git-tools-controller.mjs +181 -0
  50. package/public/project-runners-controller.mjs +220 -0
  51. package/public/service-worker.js +52 -1
  52. package/public/session-attention-scheduler.mjs +182 -0
  53. package/public/session-composer-store.mjs +56 -0
  54. package/public/session-context.mjs +51 -0
  55. package/public/session-extension-requests.mjs +63 -0
  56. package/public/session-shelf-state.mjs +151 -0
  57. package/public/session-shelves.css +171 -0
  58. package/public/session-shelves.mjs +95 -0
  59. package/public/settings-navigation-controller.mjs +249 -0
  60. package/public/settings-navigation.css +61 -0
  61. package/public/settings-resource-controller.mjs +232 -0
  62. package/public/settings-workspace.css +19 -0
  63. package/public/settings-workspace.mjs +175 -0
  64. package/public/shell-actions.mjs +87 -0
  65. package/public/shell-attention-inbox.css +72 -0
  66. package/public/shell-attention-inbox.mjs +198 -0
  67. package/public/shell-context-actions.css +61 -0
  68. package/public/shell-context-actions.mjs +168 -0
  69. package/public/shell-inspector-resize.mjs +124 -0
  70. package/public/shell-navigation-resize.mjs +107 -0
  71. package/public/shell-navigation.mjs +127 -0
  72. package/public/shell-preferences.mjs +108 -0
  73. package/public/shell-surfaces.mjs +99 -0
  74. package/public/shell-tools-launcher.css +97 -0
  75. package/public/shell-tools-launcher.mjs +222 -0
  76. package/public/shell-view-host.mjs +115 -0
  77. package/public/shell-workspace.css +266 -0
  78. package/public/shell-workspace.mjs +402 -0
  79. package/public/sidebar-update-menu.css +190 -0
  80. package/public/sidebar-update-menu.mjs +512 -0
  81. package/public/styles.css +322 -169
  82. package/public/subagent-launch-slot-state.mjs +2 -2
  83. package/public/themed-selects.css +156 -0
  84. package/public/workspace-choices.mjs +104 -0
  85. package/tests/activity-agents-controller.test.mjs +652 -0
  86. package/tests/activity-events-controller.test.mjs +511 -0
  87. package/tests/app-runner-terminal-static.test.mjs +3 -3
  88. package/tests/append-system-http.test.mjs +7 -6
  89. package/tests/append-system-selector-static.test.mjs +6 -6
  90. package/tests/aur-review-widget-static.test.mjs +11 -3
  91. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  92. package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
  93. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  94. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  95. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  96. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  97. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  98. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  99. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  100. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  101. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  102. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  103. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  104. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  105. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  106. package/tests/browser/control-visibility.spec.mjs +5 -0
  107. package/tests/browser/controls-layout.spec.mjs +21 -2
  108. package/tests/browser/conversation-overview.spec.mjs +251 -0
  109. package/tests/browser/draft-conversations.spec.mjs +276 -0
  110. package/tests/browser/empty-startup-fixture.mjs +135 -0
  111. package/tests/browser/empty-startup.spec.mjs +282 -0
  112. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  113. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  114. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  115. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  116. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  117. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  118. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  119. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  120. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  121. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  122. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  123. package/tests/browser/inspector-header.spec.mjs +221 -0
  124. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  125. package/tests/browser/inspector-resize.spec.mjs +227 -0
  126. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  127. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  128. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  129. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  130. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  131. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  132. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  133. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  134. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  135. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  136. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  137. package/tests/browser/more-row-menus.spec.mjs +258 -0
  138. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  139. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  140. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  141. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  142. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  143. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  144. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  145. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  146. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  147. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  148. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  149. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  150. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  151. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  152. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  153. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  154. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  155. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  156. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  157. package/tests/browser/session-fixture.mjs +118 -0
  158. package/tests/browser/session-ownership.spec.mjs +175 -0
  159. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  160. package/tests/browser/session-shelves.spec.mjs +340 -0
  161. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  162. package/tests/browser/session-summary.spec.mjs +17 -12
  163. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  164. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  165. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  166. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  167. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  168. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  169. package/tests/browser/shell-ownership.spec.mjs +398 -0
  170. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  171. package/tests/browser/shell-rollout.spec.mjs +357 -0
  172. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  173. package/tests/browser/shell-workspace.spec.mjs +433 -0
  174. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  175. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  176. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  177. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  178. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  179. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  180. package/tests/browser/themed-selects.spec.mjs +297 -0
  181. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  182. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  183. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  184. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  185. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  186. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  187. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  188. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  189. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  190. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  191. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  192. package/tests/codex-fast-mode-static.test.mjs +16 -11
  193. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  194. package/tests/codex-usage-source.test.mjs +4 -3
  195. package/tests/component-update-api-static.test.mjs +2 -2
  196. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  197. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  198. package/tests/control-visibility-static.test.mjs +3 -3
  199. package/tests/controls-layout-static.test.mjs +5 -5
  200. package/tests/conversation-overview-adapter.test.mjs +100 -0
  201. package/tests/document-artifact-static.test.mjs +2 -1
  202. package/tests/draft-conversations.test.mjs +205 -0
  203. package/tests/empty-startup-launcher.test.mjs +197 -0
  204. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  205. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  206. package/tests/fast-mode-client-static.test.mjs +1 -1
  207. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  208. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  209. package/tests/file-viewer-image-static.test.mjs +15 -11
  210. package/tests/file-viewer-search-static.test.mjs +5 -5
  211. package/tests/fixtures/fake-pi.mjs +41 -9
  212. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  213. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  214. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  215. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  216. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  217. package/tests/git-workflow-dispatch.test.mjs +66 -0
  218. package/tests/git-workflow-preferences.test.mjs +9 -1
  219. package/tests/guided-git-activation-static.test.mjs +14 -11
  220. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  221. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  222. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  223. package/tests/http-endpoints-harness.test.mjs +21 -9
  224. package/tests/interaction-state-stability-static.test.mjs +4 -3
  225. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  226. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  227. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  228. package/tests/main-output-loading-static.test.mjs +4 -4
  229. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  230. package/tests/mobile-compact-layout.test.mjs +2 -2
  231. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  232. package/tests/mobile-foundation-static.test.mjs +10 -7
  233. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  234. package/tests/mobile-static.test.mjs +173 -135
  235. package/tests/model-catalog-order.test.mjs +103 -0
  236. package/tests/native-parity.test.mjs +6 -4
  237. package/tests/native-session-choice-owner.test.mjs +102 -0
  238. package/tests/native-update-lifecycle.test.mjs +10 -5
  239. package/tests/no-project-http-harness.test.mjs +328 -0
  240. package/tests/no-project-navigation.test.mjs +54 -0
  241. package/tests/no-project-workspaces.test.mjs +77 -0
  242. package/tests/open-issue-wizard-static.test.mjs +1 -1
  243. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  244. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  245. package/tests/package-updates.test.mjs +630 -0
  246. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  247. package/tests/platform-event-stream.test.mjs +253 -0
  248. package/tests/project-file-viewer-controller.test.mjs +652 -0
  249. package/tests/project-git-tools-adapter.test.mjs +103 -0
  250. package/tests/project-git-tools-controller.test.mjs +577 -0
  251. package/tests/project-runners-controller.test.mjs +453 -0
  252. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  253. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  254. package/tests/questionnaire-dialog.test.mjs +6 -6
  255. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  256. package/tests/rpc-supervisor-host.test.mjs +4 -1
  257. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  258. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  259. package/tests/server-app-runners.test.mjs +536 -0
  260. package/tests/server-codex-fast-mode.test.mjs +346 -0
  261. package/tests/server-conversation-mode.test.mjs +386 -0
  262. package/tests/server-conversation-voice.test.mjs +426 -0
  263. package/tests/server-extension-ui-requests.test.mjs +357 -0
  264. package/tests/server-git-generation.test.mjs +558 -0
  265. package/tests/server-git-mutations.test.mjs +729 -0
  266. package/tests/server-git-reads.test.mjs +381 -0
  267. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  268. package/tests/server-helper-requests.test.mjs +364 -0
  269. package/tests/server-rpc-transports.test.mjs +553 -0
  270. package/tests/server-settings-store.test.mjs +132 -0
  271. package/tests/server-shell-rollout.test.mjs +478 -0
  272. package/tests/server-sse-delivery.test.mjs +410 -0
  273. package/tests/server-workspace-files.test.mjs +546 -0
  274. package/tests/session-attention-scheduler.test.mjs +514 -0
  275. package/tests/session-composer-store.test.mjs +153 -0
  276. package/tests/session-context.test.mjs +134 -0
  277. package/tests/session-extension-requests.test.mjs +193 -0
  278. package/tests/session-ownership-adapter.test.mjs +130 -0
  279. package/tests/session-sampling-ui-static.test.mjs +10 -4
  280. package/tests/session-send-lifetime.test.mjs +140 -0
  281. package/tests/session-shelf-state.test.mjs +348 -0
  282. package/tests/session-shelves-adapter.test.mjs +79 -0
  283. package/tests/session-summary-lifetime.test.mjs +54 -0
  284. package/tests/settings-resource-controller.test.mjs +548 -0
  285. package/tests/shell-action-adapter.test.mjs +169 -0
  286. package/tests/shell-actions.test.mjs +182 -0
  287. package/tests/shell-navigation.test.mjs +348 -0
  288. package/tests/shell-preferences.test.mjs +367 -0
  289. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  290. package/tests/stream-output-isolation-static.test.mjs +1 -1
  291. package/tests/subagent-gate-visibility.test.mjs +1 -1
  292. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  293. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  294. package/tests/subagent-observability-static.test.mjs +2 -2
  295. package/tests/subagent-reliability-integration.test.mjs +13 -30
  296. package/tests/syntax-highlighting-static.test.mjs +3 -3
  297. package/tests/tab-close-continuity-static.test.mjs +1 -1
  298. package/tests/tab-metadata-ordering.test.mjs +99 -0
  299. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  300. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  301. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  302. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  303. package/tests/theme-customizer-static.test.mjs +1 -1
  304. package/tests/thread-display-title.test.mjs +44 -0
  305. package/tests/update-api-harness.test.mjs +15 -14
  306. package/tests/update-tab-restore-harness.test.mjs +3 -0
  307. package/tests/webui-settings-locking.test.mjs +2 -2
  308. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  309. package/tests/workspace-choices.test.mjs +114 -0
  310. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,103 @@
1
+ import assert from "node:assert/strict";
2
+ import { groupModelCatalog, modelReleaseDate } from "../public/model-catalog-order.mjs";
3
+
4
+ for (const value of [
5
+ "2026-11-15", "2024-02-29", "2000-02-29", "0001-01-01", "9999-12-31",
6
+ "2026-11-15T00:00:00Z", "2026-11-15T23:59:59.123456Z",
7
+ "2026-11-15T00:15:00+14:00", "2026-11-15T23:45:00-12:00",
8
+ "2026-11-15T12:00:00+05:30", "2026-11-15T12:00:00-03:30",
9
+ ]) {
10
+ assert.equal(modelReleaseDate({ releaseDate: value }), value.slice(0, 10), value);
11
+ assert.equal(modelReleaseDate({ release_date: value }), value.slice(0, 10), value);
12
+ }
13
+
14
+ for (const value of [
15
+ undefined, null, true, 20261115, 1794700800000, NaN, {}, [], new Date("2026-11-15"),
16
+ "", "2026", "20261115", "2026-1-15", "2026-11-5", "15/11/2026",
17
+ "0000-01-01", "2026-00-15", "2026-13-15", "2026-11-00", "2026-11-31",
18
+ "2026-02-29", "1900-02-29", "2100-02-29", "2024-02-30", "2026-04-31",
19
+ "2026-11-15T12:00:00", "2026-11-15T12:00Z", "2026-11-15 12:00:00Z",
20
+ "2026-11-15t12:00:00z", "2026-11-15T24:00:00Z", "2026-11-15T12:60:00Z",
21
+ "2026-11-15T12:00:60Z", "2026-11-15T12:00:00.Z", "2026-11-15T12:00:00+24:00",
22
+ "2026-11-15T12:00:00+01:60", "2026-11-15T12:00:00-24:00", "2026-11-15T12:00:00+0100",
23
+ "2026-02-30T12:00:00+01:00", "2026-11-15Z", "2026-11-15T12:00:00Zjunk",
24
+ " 2026-11-15", "2026-11-15 ", "2026-11-15\n", "2026-11-15T12:00:00Z\n",
25
+ ]) {
26
+ assert.equal(modelReleaseDate({ releaseDate: value }), null, String(value));
27
+ assert.equal(modelReleaseDate({ release_date: value }), null, String(value));
28
+ }
29
+
30
+ assert.equal(modelReleaseDate(null), null);
31
+ assert.equal(modelReleaseDate(undefined), null);
32
+ assert.equal(modelReleaseDate({ releaseDate: "2025-01-01", release_date: "2026-01-01" }), "2025-01-01");
33
+ assert.equal(modelReleaseDate({ releaseDate: "invalid", release_date: "2026-01-01" }), "2026-01-01");
34
+ assert.equal(modelReleaseDate({ id: "model-2026-11-15-v100", name: "Model 2099", version: "2099-01-01" }), null);
35
+
36
+ const catalog = [
37
+ { provider: "zeta", id: "model-1", name: "Model 1", releaseDate: "2026-12-01" },
38
+ { provider: "alpha", id: "undated-10", name: "Model 10" },
39
+ { provider: "alpha", id: "tie-10", name: "Same", release_date: "2026-11-01" },
40
+ { provider: "alpha", id: "old", name: "A model", releaseDate: "2025-01-01" },
41
+ { provider: "alpha", id: "undated-2", name: "Model 2" },
42
+ { provider: "alpha", id: "tie-2", name: "Same", releaseDate: "2026-11-01T23:00:00-12:00" },
43
+ { provider: "alpha", id: "new", name: "Z model", releaseDate: "2026-11-02T00:00:00+14:00" },
44
+ { provider: "alpha", id: "tie-name", name: "Before", releaseDate: "2026-11-01" },
45
+ { provider: "alpha", id: "bad", name: "Bad calendar", releaseDate: "2026-02-30" },
46
+ { provider: "Beta", id: "vendor/model:batch", name: "Model" },
47
+ ];
48
+ const grouped = groupModelCatalog(catalog);
49
+ assert.deepEqual(grouped.map(({ provider }) => provider), ["alpha", "Beta", "zeta"]);
50
+ assert.deepEqual(grouped[0].models.map(({ id }) => id), [
51
+ "new", "tie-name", "tie-2", "tie-10", "old", "bad", "undated-2", "undated-10",
52
+ ]);
53
+ assert.deepEqual(groupModelCatalog([...catalog].reverse()), grouped);
54
+
55
+ const undated = [
56
+ { provider: "p", id: "v10", name: "Model 10" },
57
+ { provider: "p", id: "v2", name: "Model 2" },
58
+ { provider: "p", id: "model-20261115", name: "A model" },
59
+ { provider: "p", id: "fallback 10" },
60
+ { provider: "p", id: "fallback 2", name: " " },
61
+ { provider: "p", id: "fallback 1", name: "" },
62
+ { provider: "p", id: "space", name: " Model 1 " },
63
+ ];
64
+ assert.deepEqual(groupModelCatalog(undated)[0].models.map(({ id }) => id), [
65
+ "model-20261115", "fallback 1", "fallback 2", "fallback 10", "space", "v2", "v10",
66
+ ]);
67
+
68
+ const ties = [
69
+ { provider: "p", id: "id10", name: "model" },
70
+ { provider: "p", id: "id2", name: "Model" },
71
+ { provider: "p", id: "ID2", name: "Model" },
72
+ ];
73
+ assert.deepEqual(groupModelCatalog(ties)[0].models.map(({ id }) => id), ["ID2", "id2", "id10"]);
74
+ assert.deepEqual(groupModelCatalog([...ties].reverse()), groupModelCatalog(ties));
75
+
76
+ const exactProviders = ["provider10", "provider2", "Provider2", "__proto__", "constructor"];
77
+ const exactModels = exactProviders.map((provider) => ({ provider, id: " Vendor/Model:Batch " }));
78
+ const exactGroups = groupModelCatalog(exactModels);
79
+ assert.deepEqual(exactGroups.map(({ provider }) => provider), ["__proto__", "constructor", "Provider2", "provider2", "provider10"]);
80
+ assert.equal(exactGroups.length, exactModels.length);
81
+ for (const model of exactModels) {
82
+ const group = exactGroups.find(({ provider }) => provider === model.provider);
83
+ assert.strictEqual(group.models[0], model);
84
+ assert.equal(group.models[0].id, " Vendor/Model:Batch ");
85
+ }
86
+
87
+ const frozenModels = Object.freeze(catalog.map((model) => Object.freeze({ ...model })));
88
+ const originalSnapshot = structuredClone(frozenModels);
89
+ const frozenGroups = groupModelCatalog(frozenModels);
90
+ assert.deepEqual(frozenModels, originalSnapshot);
91
+ assert.notStrictEqual(frozenGroups[0].models, frozenModels);
92
+ for (const model of frozenModels) {
93
+ assert.strictEqual(frozenGroups.find(({ provider }) => provider === model.provider).models.find((item) => item.id === model.id), model);
94
+ }
95
+ const duplicate = Object.freeze({ provider: "p", id: "same", name: "Same" });
96
+ assert.deepEqual(groupModelCatalog([duplicate, duplicate])[0].models, [duplicate, duplicate]);
97
+ const equalIdentity = Object.freeze({ ...duplicate, contextWindow: 1000 });
98
+ const stableTies = groupModelCatalog([equalIdentity, duplicate])[0].models;
99
+ assert.strictEqual(stableTies[0], equalIdentity);
100
+ assert.strictEqual(stableTies[1], duplicate);
101
+ assert.deepEqual(groupModelCatalog([]), []);
102
+
103
+ console.log("model-catalog-order.test.mjs passed");
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
+ const helperRequests = await readFile(new URL("../lib/server/helper-requests.mjs", import.meta.url), "utf8");
6
7
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
8
  const [parityRaw, server, app, pkgRaw] = await Promise.all([
8
9
  readFile(join(root, "lib", "WEBUI_TUI_NATIVE_PARITY.json"), "utf8"),
@@ -167,7 +168,8 @@ assert.match(server, /const SESSION_SUMMARY_GENERATE_TIMEOUT_MS = 105 \* 1000[\s
167
168
  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");
168
169
  assert.match(server, /url\.pathname === "\/api\/native-parity" && req\.method === "GET"/, "server should expose the native parity matrix for clients/tests");
169
170
  assert.match(server, /const NATIVE_DOWNLOAD_TOKEN_TTL_MS = 10 \* 60 \* 1000/, "native downloads should use short-lived tokens");
170
- assert.match(server, /const WEBUI_HELPER_COMMAND = "webui-helper"/, "server should declare the hidden Web UI RPC helper command");
171
+ assert.match(helperRequests, /export const WEBUI_HELPER_COMMAND = "webui-helper"/, "server should declare the hidden Web UI RPC helper command");
172
+ assert.match(server, /import \{ createHelperRequestService, WEBUI_HELPER_COMMAND \} from "\.\.\/lib\/server\/helper-requests\.mjs"/, "server command discovery must use the same helper command identity");
171
173
  assert.match(server, /args\.push\("--extension", webuiHelperExtensionPath\)/, "Web UI tabs should force-load the browser-native RPC helper extension");
172
174
  assert.match(server, /url\.pathname === "\/api\/tools" && req\.method === "GET"/, "server should expose GET /api/tools for native /tools");
173
175
  assert.match(server, /url\.pathname === "\/api\/tools" && req\.method === "POST"/, "server should expose POST /api/tools for native /tools updates");
@@ -177,9 +179,9 @@ assert.match(server, /function requireResourceScope\(value\)[\s\S]*scope !== "se
177
179
  assert.match(server, /updateWebuiSettings\([\s\S]*resourceDefaults[\s\S]*tools[\s\S]*enabledTools/, "global tool choices should persist through the locked Web UI settings updater");
178
180
  assert.match(server, /updateWebuiSettings\([\s\S]*resourceDefaults[\s\S]*skills[\s\S]*enabledSkills/, "global skill choices should persist through the locked Web UI settings updater");
179
181
  assert.match(app, /function nativeResourceScopeControl\(scope,[\s\S]*Session only[\s\S]*Global default[\s\S]*Model default/, "Tools and Skills Setup should expose session/global/model scope choices");
180
- assert.match(app, /const body = \{ enabledTools: \[\.\.\.enabledTools\], scope \};/, "Tools Setup should submit its selected persistence scope");
181
- assert.match(app, /const body = \{ enabledSkills: \[\.\.\.enabledSkills\], scope \};/, "Skills Setup should submit its selected persistence scope");
182
- assert.match(app, /Unpinned active tools update immediately; pinned tools are unchanged\./, "global selector feedback should explain live precedence");
182
+ assert.match(app, /const body = \{ scope: selection\.scope \};[\s\S]*if \(selection\.scope === "model"\) Object\.assign\(body, \{ provider: selection\.provider, modelId: selection\.modelId \}\)/, "resource writes should retain the selected scope and exact model identity");
183
+ assert.match(app, /if \(change\.inherit\) body\.inherit = true;[\s\S]*body\[kind === "tools" \? "enabledTools" : "enabledSkills"\] = change\.enabled;[\s\S]*method: "POST", body, tabId: target\.tabId/, "resource writes should preserve inheritance versus the full enabled list and captured tab");
184
+ assert.match(app, /Unpinned active \$\{kind\} update immediately; pinned \$\{kind\} are unchanged\./, "global selector feedback should explain live precedence");
183
185
  assert.match(app, /aria-pressed/, "resource toggles should expose their enabled state programmatically");
184
186
  assert.match(app, /const HIDDEN_COMMAND_NAMES = new Set\(\["webui-tree-navigate", "webui-helper"\]\)/, "frontend should hide Web UI internal helper commands");
185
187
  assert.match(app, /"scoped-models", "tools", "skills"/, "frontend native selector commands should include /tools and /skills");
@@ -0,0 +1,102 @@
1
+ import assert from 'node:assert/strict';
2
+ import { readFileSync } from 'node:fs';
3
+ import vm from 'node:vm';
4
+ import { test } from 'node:test';
5
+
6
+ const source = readFileSync(new URL('../public/app.js', import.meta.url), 'utf8');
7
+ const start = source.indexOf('function nativeSessionChoiceOwner(');
8
+ const end = source.indexOf('\nasync function openNativeModelSelector', start);
9
+ assert.ok(start > 0 && end > start);
10
+
11
+ function fixture() {
12
+ let resolve;
13
+ let reject;
14
+ const pending = new Promise((yes, no) => { resolve = yes; reject = no; });
15
+ const calls = [];
16
+ const applied = [];
17
+ const errors = [];
18
+ const attributes = new Map();
19
+ const body = { inert: false, setAttribute: (key, value) => attributes.set(key, value), removeAttribute: key => attributes.delete(key) };
20
+ const dialog = { open: true };
21
+ const target = { tabId: 'origin', generation: 1 };
22
+ let targetCurrent = true;
23
+ const context = vm.createContext({
24
+ nativeCommandDialogGeneration: 0, nativeCommandTabId: null,
25
+ elements: { nativeCommandBody: body, nativeCommandDialog: dialog, nativeCommandSearch: { disabled: false } },
26
+ projectTargetFromContext: () => target,
27
+ isCurrentProjectTarget: value => value === target && targetCurrent,
28
+ openNativeCommandDialog: () => ++context.nativeCommandDialogGeneration,
29
+ nativeCommandApi: (path, options) => { calls.push({ path, options }); return pending; },
30
+ closeNativeCommandDialog: () => { dialog.open = false; context.nativeCommandDialogGeneration++; },
31
+ refreshState: async value => { calls.push({ refresh: value }); },
32
+ setNativeCommandError: value => errors.push(value),
33
+ });
34
+ vm.runInContext(source.slice(start, end), context);
35
+ const owner = context.nativeSessionChoiceOwner({ title: 'Model' });
36
+ return { owner, calls, applied, errors, body, dialog, attributes, context, resolve, reject,
37
+ invalidate: () => { targetCurrent = false; },
38
+ apply: () => owner.apply('/api/model', { provider: 'fixture', modelId: 'second' }, value => applied.push(value)),
39
+ };
40
+ }
41
+
42
+ test('one choice dispatches once to the captured tab and closes only after success', async () => {
43
+ const f = fixture();
44
+ const first = f.apply();
45
+ await f.apply();
46
+ assert.equal(f.calls.length, 1);
47
+ assert.equal(f.calls[0].options.tabId, 'origin');
48
+ assert.equal(f.body.inert, true);
49
+ f.resolve({ data: { id: 'second' } });
50
+ await first;
51
+ assert.deepEqual(f.applied, [{ id: 'second' }]);
52
+ assert.equal(f.dialog.open, false);
53
+ assert.equal(f.calls[1].refresh.tabId, 'origin');
54
+ });
55
+
56
+ test('failure stays in the picker and restores retry controls', async () => {
57
+ const f = fixture();
58
+ const request = f.apply();
59
+ f.reject(new Error('Provider unavailable'));
60
+ await request;
61
+ assert.equal(f.dialog.open, true);
62
+ assert.equal(f.body.inert, false);
63
+ assert.equal(f.attributes.has('aria-busy'), false);
64
+ assert.equal(f.context.elements.nativeCommandSearch.disabled, false);
65
+ assert.equal(f.errors.at(-1), 'Provider unavailable');
66
+ await f.apply();
67
+ assert.equal(f.calls.length, 2);
68
+ assert.equal(f.applied.length, 0);
69
+ });
70
+
71
+ for (const outcome of ['success', 'failure']) {
72
+ test(`late ${outcome} cannot update or close a replacement dialog`, async () => {
73
+ const f = fixture();
74
+ const request = f.apply();
75
+ f.context.nativeCommandDialogGeneration++;
76
+ f.body.inert = false;
77
+ if (outcome === 'success') f.resolve({ data: { id: 'second' } });
78
+ else f.reject(new Error('Old failure'));
79
+ await request;
80
+ assert.equal(f.dialog.open, true);
81
+ assert.equal(f.body.inert, false);
82
+ assert.equal(f.applied.length, 0);
83
+ assert.equal(f.calls.length, 1);
84
+ assert.deepEqual(f.errors, ['']);
85
+ });
86
+ }
87
+
88
+ test('same-tab session replacement prevents both old dispatch and late completion', async () => {
89
+ const old = fixture();
90
+ old.invalidate();
91
+ await old.apply();
92
+ assert.equal(old.calls.length, 0);
93
+ assert.match(old.errors.at(-1), /session changed/);
94
+ const pending = fixture();
95
+ const request = pending.apply();
96
+ pending.invalidate();
97
+ pending.resolve({ data: { id: 'second' } });
98
+ await request;
99
+ assert.equal(pending.applied.length, 0);
100
+ assert.equal(pending.dialog.open, true);
101
+ assert.equal(pending.calls.length, 1);
102
+ });
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { spawn } from "node:child_process";
3
3
  import { createServer } from "node:net";
4
- import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
4
+ import { chmod, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
5
5
  import { tmpdir } from "node:os";
6
6
  import path from "node:path";
7
7
  import { setTimeout as delay } from "node:timers/promises";
@@ -36,7 +36,8 @@ try {
36
36
  await mkdir(path.join(npmRoot, "bin"), { recursive: true });
37
37
  await writeFile(manifest, JSON.stringify({ name: "@earendil-works/pi-coding-agent", version: "0.87.1", bin: { pi: "dist/cli.js" } }));
38
38
  const fakePi = path.join(packageRoot, "tests", "fixtures", "fake-pi.mjs");
39
- await writeFile(cli, `import { readFileSync, writeFileSync } from 'node:fs';\nconst manifest = ${JSON.stringify(manifest)};\nconst current = JSON.parse(readFileSync(manifest, 'utf8'));\nif (process.argv.includes('--version')) { console.log(current.version); process.exit(0); }\nif (process.argv.includes('update')) { current.version = '0.87.2'; writeFileSync(manifest, JSON.stringify(current)); process.exit(0); }\nawait import(${JSON.stringify(pathToFileURL(fakePi).href)});\n`);
39
+ await writeFile(cli, `#!${process.execPath}\nimport { readFileSync, writeFileSync } from 'node:fs';\nconst manifest = ${JSON.stringify(manifest)};\nconst current = JSON.parse(readFileSync(manifest, 'utf8'));\nif (process.argv.includes('--version')) { console.log(current.version); process.exit(0); }\nif (process.argv.includes('update')) { current.version = '0.87.2'; writeFileSync(manifest, JSON.stringify(current)); process.exit(0); }\nawait import(${JSON.stringify(pathToFileURL(fakePi).href)});\n`);
40
+ await chmod(cli, 0o755);
40
41
  if (windows) {
41
42
  await writeFile(path.join(bin, "pi.cmd"), `@echo off\r\nnode "%dp0%\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js" %*\r\n`);
42
43
  } else await symlink(cli, path.join(bin, "pi"));
@@ -48,7 +49,7 @@ try {
48
49
  env: { ...process.env, PATH: `${bin}${path.delimiter}${process.env.PATH || ""}`,
49
50
  PI_CODING_AGENT_DIR: path.join(temp, "agent"), PI_WEBUI_NPM_BIN: path.join(npmRoot, "bin", "npm-cli.js"),
50
51
  PI_WEBUI_UPDATE_TEST_HOME: temp, NODE_ENV: "test", PI_OFFLINE: "1",
51
- // Supervised tabs are the only ones a fenced native restart can preserve; run-all disables the supervisor by default.
52
+ // Exercise an existing supervised session while the fake update runs without restarting it.
52
53
  PI_WEBUI_RPC_SUPERVISOR: "1" },
53
54
  });
54
55
  child.stdout.on("data", (chunk) => { output += chunk; });
@@ -58,6 +59,7 @@ try {
58
59
  try { if ((await api("/api/health")).ok) break; } catch {}
59
60
  await delay(100);
60
61
  }
62
+ const originalBoot = (await (await api("/api/health")).json()).bootIdentity;
61
63
  const planned = await api("/api/update/plan", { targets: ["pi"] });
62
64
  const planResult = await planned.json();
63
65
  assert.equal(planned.status, 201, JSON.stringify(planResult) + output);
@@ -72,8 +74,11 @@ try {
72
74
  await delay(200);
73
75
  }
74
76
  assert.equal(result.phase, "success", JSON.stringify(result) + output);
75
- assert.equal(result.receipts[0].status, "changed");
76
- assert.equal(result.verifiedTargets[0].status, "healthy");
77
+ assert.equal(result.receipts[0].status, "success");
78
+ assert.equal(result.receipts[0].exitCode, 0);
79
+ assert.deepEqual(result.verifiedTargets, [], "command exit is not a health claim");
80
+ assert.equal(result.restartRequired, true);
81
+ assert.equal((await (await api("/api/health")).json()).bootIdentity, originalBoot, "updates leave restart to the user");
77
82
  assert.equal(JSON.parse(await readFile(manifest, "utf8")).version, "0.87.2");
78
83
  const state = await api("/api/state");
79
84
  assert.equal(state.status, 200, output);
@@ -0,0 +1,328 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { createServer } from "node:net";
4
+ import { mkdir, mkdtemp, readFile, readdir, rename, rm, stat, symlink, writeFile } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import path from "node:path";
7
+ import { setTimeout as delay } from "node:timers/promises";
8
+ import { fileURLToPath, pathToFileURL } from "node:url";
9
+ import { terminateProcessTree } from "../lib/process-tree.mjs";
10
+
11
+ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
12
+ const fakePi = path.join(packageRoot, "tests", "fixtures", "fake-pi.mjs");
13
+
14
+ async function waitFor(label, predicate, timeoutMs = 20_000) {
15
+ const deadline = Date.now() + timeoutMs;
16
+ let lastError;
17
+ while (Date.now() < deadline) {
18
+ try {
19
+ const value = await predicate();
20
+ if (value) return value;
21
+ } catch (error) { lastError = error; }
22
+ await delay(80);
23
+ }
24
+ throw new Error(`${label} timed out${lastError ? `: ${lastError.message}` : ""}`);
25
+ }
26
+
27
+ async function freePort() {
28
+ const reservation = createServer();
29
+ await new Promise((resolve, reject) => { reservation.once("error", reject); reservation.listen(0, "127.0.0.1", resolve); });
30
+ const port = reservation.address().port;
31
+ await new Promise((resolve) => reservation.close(resolve));
32
+ return port;
33
+ }
34
+
35
+ function identity(tab) {
36
+ return { id: tab.id, cwd: tab.cwd, workspaceKind: tab.workspaceKind, noProjectId: tab.noProjectId };
37
+ }
38
+
39
+ async function scenario({ supervised, noSession = false, compacting = false }) {
40
+ const work = await mkdtemp(path.join(tmpdir(), "webui-no-project-http-"));
41
+ const project = path.join(work, "project");
42
+ const agentDir = path.join(work, "agent");
43
+ const sessions = path.join(work, "sessions");
44
+ const failFile = path.join(work, "fail-launch");
45
+ const argvLog = path.join(work, "argv.jsonl");
46
+ const commandLog = path.join(work, "commands.jsonl");
47
+ const wrapper = path.join(work, "fake-wrapper.mjs");
48
+ const port = await freePort();
49
+ const children = [];
50
+ const output = [];
51
+ let latestServerPid;
52
+ const env = {
53
+ ...process.env,
54
+ HOME: path.join(work, "home"),
55
+ XDG_CONFIG_HOME: path.join(work, "config"),
56
+ XDG_CACHE_HOME: path.join(work, "cache"),
57
+ XDG_STATE_HOME: path.join(work, "state"),
58
+ XDG_DATA_HOME: path.join(work, "data"),
59
+ XDG_RUNTIME_DIR: path.join(work, "runtime"),
60
+ npm_config_cache: path.join(work, "npm-cache"),
61
+ GIT_CONFIG_NOSYSTEM: "1",
62
+ GIT_CONFIG_GLOBAL: "/dev/null",
63
+ PI_CODING_AGENT_DIR: agentDir,
64
+ PI_WEBUI_SETTINGS_FILE: path.join(work, "settings.json"),
65
+ PI_WEBUI_WORKSPACES_FILE: path.join(work, "workspaces.json"),
66
+ PI_WEBUI_UPDATE_TEST_HOME: path.join(work, "update"),
67
+ PI_WEBUI_SESSION_SUMMARY_DIR: path.join(work, "summaries"),
68
+ PI_WEBUI_RPC_SUPERVISOR: supervised ? "1" : "0",
69
+ FAKE_PI_SESSION_OWNERSHIP: "1",
70
+ FAKE_PI_LOG_FILE: commandLog,
71
+ FAKE_PI_GUIDED_GIT_STATE: compacting ? "compacting" : "",
72
+ NODE_ENV: "test",
73
+ };
74
+ async function request(route, body, method = body === undefined ? "GET" : "POST") {
75
+ const response = await fetch(`http://127.0.0.1:${port}${route}`, {
76
+ method,
77
+ headers: body === undefined ? undefined : { "content-type": "application/json" },
78
+ body: body === undefined ? undefined : JSON.stringify(body),
79
+ signal: AbortSignal.timeout(12_000),
80
+ });
81
+ return { status: response.status, body: await response.json() };
82
+ }
83
+ async function health() {
84
+ const value = await request("/api/health");
85
+ if (value.status !== 200 || !value.body.ok || value.body.optionalFeatures?.ready === false) return null;
86
+ latestServerPid = value.body.webuiPid;
87
+ return value.body;
88
+ }
89
+ async function tabs() {
90
+ const value = await request("/api/tabs");
91
+ assert.equal(value.status, 200);
92
+ return value.body.data.tabs;
93
+ }
94
+ async function create(body = { workspaceKind: "no-project" }) {
95
+ const value = await request("/api/tabs", body);
96
+ assert.equal(value.status, 201, JSON.stringify(value));
97
+ return value.body.data.tab;
98
+ }
99
+ async function log(file) {
100
+ return (await readFile(file, "utf8").catch(() => "")).split("\n").filter(Boolean).map((line) => JSON.parse(line));
101
+ }
102
+ function launch() {
103
+ const args = [path.join(packageRoot, "bin", "pi-webui.mjs"), "--cwd", project, "--host", "127.0.0.1", "--port", String(port), "--pi", wrapper];
104
+ if (noSession) args.push("--no-session");
105
+ args.push("--", "--session", path.join(sessions, "inherited.jsonl"), "--continue", "--resume", "--model", "fake/fake-model", "--thinking", "off", "--session-dir", sessions, "initial inherited input", "@inherited.txt");
106
+ const child = spawn(process.execPath, args, { env, detached: true, stdio: ["ignore", "pipe", "pipe"] });
107
+ children.push(child);
108
+ child.stdout.on("data", (chunk) => output.push(String(chunk)));
109
+ child.stderr.on("data", (chunk) => output.push(String(chunk)));
110
+ return child;
111
+ }
112
+ try {
113
+ for (const directory of [project, agentDir, sessions, env.HOME, env.XDG_CONFIG_HOME, env.XDG_CACHE_HOME, env.XDG_STATE_HOME, env.XDG_DATA_HOME, env.XDG_RUNTIME_DIR]) await mkdir(directory, { recursive: true });
114
+ await writeFile(env.PI_WEBUI_SETTINGS_FILE, "{}\n");
115
+ await writeFile(path.join(sessions, "inherited.jsonl"), `${JSON.stringify({ type: "session", version: 3, id: "project-startup", timestamp: new Date().toISOString(), cwd: project })}\n`);
116
+ await writeFile(wrapper, `import { appendFileSync, existsSync } from "node:fs";
117
+ appendFileSync(${JSON.stringify(argvLog)}, JSON.stringify({cwd: process.cwd(), args: process.argv.slice(2), pid: process.pid}) + "\\n");
118
+ if (process.cwd() !== ${JSON.stringify(project)} && existsSync(${JSON.stringify(failFile)})) process.exit(42);
119
+ await new Promise(resolve => setTimeout(resolve, 100));
120
+ await import(${JSON.stringify(pathToFileURL(fakePi).href)});
121
+ `);
122
+ let child = launch();
123
+ await waitFor("isolated server health", health);
124
+ await waitFor("tab creation readiness", async () => {
125
+ const value = await request("/api/tabs", { workspaceKind: "typo" });
126
+ return value.status === 400;
127
+ });
128
+ const initial = (await tabs())[0];
129
+ assert.equal(initial.cwd, project);
130
+ assert.equal(initial.workspaceKind, undefined);
131
+ const first = await create();
132
+ const second = await create();
133
+ assert.notEqual(first.cwd, second.cwd);
134
+ assert.notEqual(first.noProjectId, second.noProjectId);
135
+ assert.equal(first.workspaceKind, "no-project");
136
+ assert.equal(first.cwd, path.join(agentDir, "webui", "no-project", first.noProjectId));
137
+ assert.deepEqual(await readdir(first.cwd), []);
138
+ assert.equal((await stat(first.cwd)).isDirectory(), true);
139
+ await writeFile(path.join(first.cwd, "retained.txt"), "source work");
140
+ const firstState = (await request(`/api/state?tab=${first.id}`)).body.data;
141
+ const startup = (await log(argvLog)).find((entry) => entry.cwd === first.cwd);
142
+ assert.ok(startup, "child actually launches in the allocated leaf");
143
+ for (const removed of ["--session", "--continue", "--resume", "initial inherited input", "@inherited.txt"]) assert.equal(startup.args.includes(removed), false, removed);
144
+ assert.equal(startup.args[startup.args.indexOf("--model") + 1], "fake/fake-model");
145
+ assert.equal(startup.args[startup.args.indexOf("--session-dir") + 1], sessions);
146
+ assert.equal(startup.args.includes("--no-session"), noSession);
147
+ const count = (await tabs()).length;
148
+ for (const body of [{ workspaceKind: "typo" }, { workspaceKind: "no-project", cwd: project }, { workspaceKind: "no-project", sessionFile: "ignored" }, { workspaceKind: "no-project", noProjectId: first.noProjectId }, { cwd: first.cwd }]) {
149
+ assert.equal((await request("/api/tabs", body)).status, 400);
150
+ }
151
+ assert.equal((await tabs()).length, count);
152
+ const post = (route, tab, extra = {}) => request(route, { tab: tab.id, ...extra });
153
+
154
+ if (compacting) {
155
+ for (const route of ["/api/new-session", "/api/prompt"]) {
156
+ const value = await post(route, first, route === "/api/prompt" ? { message: "/new" } : {});
157
+ assert.equal(value.status, 409, JSON.stringify(value));
158
+ }
159
+ assert.equal((await tabs()).length, count);
160
+ return;
161
+ }
162
+
163
+ assert.equal((await post("/api/prompt", first, { message: "ordinary stable prompt" })).status, 200);
164
+ assert.deepEqual(identity((await tabs()).find((tab) => tab.id === first.id)), identity(first));
165
+ assert.equal((await post("/api/prompt", first, { message: "/talk on" })).status, 200);
166
+ await waitFor("natural conversation admission", async () => (await tabs()).find((tab) => tab.id === first.id)?.conversationMode.enabled);
167
+ assert.equal((await post("/api/new-session", first)).status, 409);
168
+ assert.equal((await post("/api/prompt", first, { message: "/new" })).status, 409);
169
+ assert.equal((await post("/api/prompt", first, { message: "/talk off" })).status, 200);
170
+ await waitFor("natural conversation off", async () => !(await tabs()).find((tab) => tab.id === first.id)?.conversationMode.enabled);
171
+
172
+ const reset = await post("/api/new-session", first);
173
+ assert.equal(reset.status, 200, JSON.stringify(reset));
174
+ assert.equal(reset.body.command, "new_session");
175
+ assert.equal(reset.body.success, true);
176
+ assert.equal(reset.body.tab.id, first.id, "outer compatibility tab identifies source request context");
177
+ assert.equal(reset.body.data.nextTabId, reset.body.data.tab.id);
178
+ assert.equal(reset.body.data.sourceTab.id, first.id);
179
+ assert.notEqual(reset.body.data.tab.cwd, first.cwd);
180
+ assert.equal((await request(`/api/state?tab=${first.id}`)).body.data.sessionId, firstState.sessionId, "source RPC session is never reset");
181
+ assert.equal((await tabs()).find((tab) => tab.id === first.id).pid, first.pid);
182
+ const slashReset = await post("/api/prompt", second, { message: "/new" });
183
+ assert.equal(slashReset.status, 200, JSON.stringify(slashReset));
184
+ assert.equal(slashReset.body.command, "native_slash_command");
185
+ assert.equal(slashReset.body.data.command, "new");
186
+ assert.equal(slashReset.body.data.status, "succeeded");
187
+ assert.equal(slashReset.body.data.nextTabId, slashReset.body.data.tab.id);
188
+ assert.equal(slashReset.body.data.sourceTab.id, second.id);
189
+ assert.notEqual(slashReset.body.data.tab.cwd, second.cwd);
190
+ const duplicate = await Promise.all([post("/api/new-session", first), post("/api/new-session", first)]);
191
+ assert.deepEqual(duplicate.map((value) => value.status).sort(), [200, 409]);
192
+ assert.equal((await log(commandLog)).filter((entry) => entry.direction === "command" && entry.type === "new_session").length, 0, "No Project reset never sends new_session to any RPC");
193
+ const projectReset = await post("/api/new-session", initial);
194
+ assert.equal(projectReset.status, 200);
195
+ assert.equal(projectReset.body.data.nextTabId, undefined);
196
+ assert.equal(projectReset.body.tab.cwd, project);
197
+
198
+ const beforeFailure = (await tabs()).map(identity);
199
+ const leavesBeforeFailure = await readdir(path.dirname(first.cwd));
200
+ await writeFile(failFile, "fail");
201
+ const failure = await post("/api/new-session", first);
202
+ assert.equal(failure.status, 500, JSON.stringify(failure));
203
+ assert.deepEqual((await tabs()).map(identity), beforeFailure);
204
+ const retainedFailedLeaves = (await readdir(path.dirname(first.cwd))).filter((leaf) => !leavesBeforeFailure.includes(leaf));
205
+ assert.equal(retainedFailedLeaves.length, 1, "failed launches retain their allocated leaf");
206
+ assert.equal((await request(`/api/state?tab=${first.id}`)).body.data.sessionId, firstState.sessionId);
207
+ await rm(failFile);
208
+
209
+ if (!noSession) {
210
+ const resumeFile = path.join(sessions, "resume.jsonl");
211
+ await writeFile(resumeFile, `${JSON.stringify({ type: "session", version: 3, id: "owned-resume", timestamp: new Date().toISOString(), cwd: first.cwd })}\n`);
212
+ const resumed = await post("/api/switch-session", initial, { sessionPath: resumeFile });
213
+ assert.equal(resumed.status, 200, JSON.stringify(resumed));
214
+ assert.equal(resumed.body.data.tab.cwd, first.cwd);
215
+ assert.equal(resumed.body.data.tab.noProjectId, first.noProjectId);
216
+ const messages = (await request(`/api/fork-messages?tab=${first.id}`)).body.data.messages;
217
+ const forked = await post("/api/fork", first, { entryId: messages[0].entryId });
218
+ assert.equal(forked.status, 200, JSON.stringify(forked));
219
+ assert.equal(forked.body.data.tab.cwd, first.cwd);
220
+ assert.equal(forked.body.data.tab.noProjectId, first.noProjectId);
221
+ }
222
+
223
+ assert.equal((await post("/api/prompt", first, { message: "/reload" })).status, 200);
224
+ assert.deepEqual(identity((await tabs()).find((tab) => tab.id === first.id)), identity(first));
225
+ const saved = await request("/api/workspaces", { name: "Owned work", activeTabId: first.id });
226
+ assert.equal(saved.status, 201, JSON.stringify(saved));
227
+ const savedId = saved.body.data.workspace.id;
228
+ const savedDocument = JSON.parse(await readFile(env.PI_WEBUI_WORKSPACES_FILE, "utf8"));
229
+ assert.equal(savedDocument.workspaces[0].tabs.find((tab) => tab.id === first.id).noProjectId, first.noProjectId);
230
+
231
+ const beforeRestart = (await tabs()).map(identity);
232
+ const oldPid = latestServerPid;
233
+ const restarted = await request("/api/restart", {});
234
+ assert.equal(restarted.status, 200, JSON.stringify(restarted));
235
+ latestServerPid = restarted.body.nextWebuiPid;
236
+ await waitFor("private restore/supervisor restart", async () => { const value = await health(); return value?.webuiPid !== oldPid && value; });
237
+ assert.deepEqual((await tabs()).map(identity), beforeRestart);
238
+ if (supervised) {
239
+ const managedBefore = (await tabs()).map((tab) => ({ ...identity(tab), pid: tab.pid }));
240
+ process.kill(latestServerPid, "SIGKILL");
241
+ await delay(250);
242
+ child = launch();
243
+ await waitFor("supervisor reattach after abrupt HTTP exit", health);
244
+ assert.deepEqual((await tabs()).map((tab) => ({ ...identity(tab), pid: tab.pid })), managedBefore);
245
+ }
246
+
247
+ const loaded = await request(`/api/workspaces/${savedId}/load`, { replaceOpenTabs: true, discardCurrent: true });
248
+ assert.equal(loaded.status, 200, JSON.stringify(loaded));
249
+ assert.deepEqual(loaded.body.data.warnings, []);
250
+ const reopenedFirst = loaded.body.data.tabs.find((tab) => tab.noProjectId === first.noProjectId);
251
+ assert.ok(reopenedFirst);
252
+ assert.equal(reopenedFirst.cwd, first.cwd);
253
+ const closed = await request("/api/tabs/close", { ids: [reopenedFirst.id] });
254
+ assert.equal(closed.status, 200);
255
+ assert.equal(await readFile(path.join(first.cwd, "retained.txt"), "utf8"), "source work");
256
+ const reopened = await request("/api/tabs/reopen", { id: reopenedFirst.id });
257
+ assert.equal(reopened.status, 201, JSON.stringify(reopened));
258
+ assert.equal(reopened.body.data.tab.cwd, first.cwd);
259
+ assert.equal(reopened.body.data.tab.noProjectId, first.noProjectId);
260
+
261
+ const missing = `${first.cwd}.missing`;
262
+ await rename(first.cwd, missing);
263
+ const missingLoad = await request(`/api/workspaces/${savedId}/load`, { replaceOpenTabs: true, discardCurrent: true });
264
+ assert.equal(missingLoad.status, 200);
265
+ assert.ok(missingLoad.body.data.warnings.some((warning) => /owned working directory is missing/.test(warning.message)));
266
+ assert.equal(missingLoad.body.data.tabs.some((tab) => tab.noProjectId === first.noProjectId), false);
267
+ await symlink(project, first.cwd, "dir");
268
+ const escaped = await request(`/api/workspaces/${savedId}/load`, { replaceOpenTabs: true, discardCurrent: true });
269
+ assert.equal(escaped.status, 200);
270
+ assert.ok(escaped.body.data.warnings.some((warning) => /canonical owned leaf/.test(warning.message)));
271
+ assert.equal(escaped.body.data.tabs.some((tab) => tab.noProjectId === first.noProjectId), false);
272
+ await rm(first.cwd);
273
+ await rename(missing, first.cwd);
274
+ assert.equal(await readFile(path.join(first.cwd, "retained.txt"), "utf8"), "source work");
275
+
276
+ if (!noSession) {
277
+ const lone = await create();
278
+ const otherIds = (await tabs()).filter((tab) => tab.id !== lone.id).map((tab) => tab.id);
279
+ assert.equal((await request("/api/tabs/close", { ids: otherIds })).status, 200);
280
+ const unavailable = `${lone.cwd}.unavailable`;
281
+ await rename(lone.cwd, unavailable);
282
+ if (supervised) {
283
+ process.kill(latestServerPid, "SIGTERM");
284
+ await waitFor("HTTP detach before invalid managed restore", async () => {
285
+ try { return (await request("/api/health")).status !== 200; } catch { return true; }
286
+ });
287
+ const invalidRestore = launch();
288
+ latestServerPid = invalidRestore.pid;
289
+ await waitFor("missing managed cwd rejects startup", () => invalidRestore.exitCode !== null);
290
+ assert.notEqual(invalidRestore.exitCode, 0);
291
+ assert.match(output.join(""), /owned working directory is missing/);
292
+ await rename(unavailable, lone.cwd);
293
+ child = launch();
294
+ await waitFor("managed restore after directory recovery", health);
295
+ assert.deepEqual((await tabs()).map(identity), [identity(lone)]);
296
+ } else {
297
+ const retiringPid = latestServerPid;
298
+ const restartMissing = await request("/api/restart", {});
299
+ assert.equal(restartMissing.status, 200);
300
+ latestServerPid = restartMissing.body.nextWebuiPid;
301
+ await waitFor("missing private restore finishes without project fallback", async () => {
302
+ const value = await health();
303
+ return value?.webuiPid !== retiringPid && value;
304
+ });
305
+ // The detached replacement discards stdio; verify its authoritative tab state.
306
+ assert.deepEqual(await tabs(), [], "missing owned restore must not fall back to startup project");
307
+ await rename(unavailable, lone.cwd);
308
+ }
309
+ }
310
+ console.log(`No Project HTTP lifecycle passed: ${supervised ? "supervised" : "direct"}${noSession ? ", no-session" : ""}`);
311
+ } catch (error) {
312
+ error.message += `\nIsolated server output:\n${output.join("").slice(-12000)}`;
313
+ throw error;
314
+ } finally {
315
+ await request("/api/shutdown", {}).catch(() => {});
316
+ await delay(400);
317
+ if (latestServerPid) { try { process.kill(latestServerPid, "SIGTERM"); } catch {} }
318
+ for (const child of children) terminateProcessTree(child, "SIGKILL");
319
+ await rm(work, { recursive: true, force: true });
320
+ }
321
+ }
322
+
323
+ await scenario({ supervised: false });
324
+ await scenario({ supervised: true });
325
+ await scenario({ supervised: false, noSession: true });
326
+ await scenario({ supervised: true, noSession: true });
327
+ await scenario({ supervised: false, compacting: true });
328
+ console.log("No Project HTTP admission and lifecycle tests passed");