@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,367 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import {
4
+ SHELL_PREFERENCES_STORAGE_KEY,
5
+ effectiveShellPreferences,
6
+ readShellPreferences,
7
+ resolveShellMode,
8
+ writeShellPreferences,
9
+ } from "../public/shell-preferences.mjs";
10
+
11
+ const fallback = { v: 1, desktopLayout: "classic" };
12
+
13
+ function fakeStorage(initial = []) {
14
+ const records = new Map(initial);
15
+ const calls = [];
16
+ return {
17
+ records,
18
+ calls,
19
+ getItem(key) { calls.push(["get", key]); return records.get(key) ?? null; },
20
+ setItem(key, value) { calls.push(["set", key, value]); records.set(key, value); },
21
+ removeItem() { assert.fail("preferences must never erase storage"); },
22
+ clear() { assert.fail("preferences must never clear storage"); },
23
+ };
24
+ }
25
+
26
+ test("absent storage record falls back to Classic without writing defaults", () => {
27
+ const storage = fakeStorage();
28
+ assert.equal(SHELL_PREFERENCES_STORAGE_KEY, "pi-webui-shell-preferences-v1");
29
+ assert.deepEqual(readShellPreferences(storage), { status: "absent", value: fallback });
30
+ assert.deepEqual(storage.calls, [["get", SHELL_PREFERENCES_STORAGE_KEY]]);
31
+ assert.equal(storage.records.size, 0);
32
+ });
33
+
34
+ test("corrupt, invalid and future data survives reads byte for byte", () => {
35
+ for (const raw of [
36
+ "", "{", "null", "[]", "true", "1", '"focused"', "{}",
37
+ '{"v":2,"desktopLayout":"focused","futureSetting":true}',
38
+ '{"v":"1","desktopLayout":"focused"}', '{"v":1}',
39
+ '{"v":1,"desktopLayout":"unknown"}', '{"v":1,"desktopLayout":null}',
40
+ ]) {
41
+ const storage = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
42
+ assert.deepEqual(readShellPreferences(storage), { status: "invalid", value: fallback }, raw);
43
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw);
44
+ assert.deepEqual(storage.calls, [["get", SHELL_PREFERENCES_STORAGE_KEY]]);
45
+ }
46
+ });
47
+
48
+ test("missing and denied storage returns unavailable without throwing into chat", () => {
49
+ for (const storage of [undefined, null, {}, { getItem() { throw new Error("denied"); } },
50
+ { get getItem() { throw new Error("denied property access"); } }]) {
51
+ assert.deepEqual(readShellPreferences(storage), { status: "unavailable", value: fallback });
52
+ assert.deepEqual(writeShellPreferences(storage, fallback), { ok: false, reason: "unavailable" });
53
+ }
54
+ const storage = { setItem() { throw new Error("quota exceeded"); } };
55
+ assert.deepEqual(writeShellPreferences(storage, fallback), { ok: false, reason: "unavailable" });
56
+ });
57
+
58
+ test("valid writes roundtrip only the version and desktop choice", () => {
59
+ const otherRecords = [
60
+ ["pi-webui-ui-layout-v3", "durable layout"],
61
+ ["pi-webui-mobile-shell-v2", "preview"],
62
+ ["pi-webui-tablet-shell-v2", "legacy"],
63
+ ["other-browser-preference", "untouched"],
64
+ ];
65
+ const storage = fakeStorage(otherRecords);
66
+ for (const desktopLayout of ["focused", "classic"]) {
67
+ assert.deepEqual(writeShellPreferences(storage, { v: 1, desktopLayout, session: "must not persist", draft: "private" }), { ok: true, reason: null });
68
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), JSON.stringify({ v: 1, desktopLayout }));
69
+ assert.deepEqual(readShellPreferences(storage), { status: "valid", value: { v: 1, desktopLayout } });
70
+ }
71
+ for (const [key, value] of otherRecords) assert.equal(storage.records.get(key), value);
72
+ assert.equal(storage.calls.every(([, key]) => key === SHELL_PREFERENCES_STORAGE_KEY), true);
73
+ });
74
+
75
+ test("valid records normalize extra fields without modifying stored bytes", () => {
76
+ const raw = '{"v":1,"desktopLayout":"focused","unknown":true}';
77
+ const storage = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
78
+ assert.deepEqual(readShellPreferences(storage), { status: "valid", value: { v: 1, desktopLayout: "focused" } });
79
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw);
80
+ const first = readShellPreferences(fakeStorage());
81
+ first.value.desktopLayout = "focused";
82
+ assert.deepEqual(readShellPreferences(fakeStorage()).value, fallback, "fallback objects are not shared mutable state");
83
+ });
84
+
85
+ test("invalid writes leave prior future records and unrelated records untouched", () => {
86
+ const raw = '{"v":9,"desktopLayout":"future"}';
87
+ const storage = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
88
+ for (const value of [undefined, null, [], "focused", {}, { v: 2, desktopLayout: "classic" },
89
+ { v: 1, desktopLayout: "preview" }, { v: 1, get desktopLayout() { throw new Error("invalid accessor"); } }]) {
90
+ assert.deepEqual(writeShellPreferences(storage, value), { ok: false, reason: "invalid" });
91
+ }
92
+ assert.equal(storage.calls.length, 0);
93
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw);
94
+ });
95
+
96
+ test("desktop defaults to Classic and requires the explicit focused choice", () => {
97
+ assert.equal(resolveShellMode(), "classic");
98
+ for (const desktopLayout of [undefined, null, "classic", "preview", "future", true]) {
99
+ assert.equal(resolveShellMode({ desktopLayout, phoneMode: "v2", tabletMode: "v2" }), "classic");
100
+ }
101
+ assert.equal(resolveShellMode({ desktopLayout: "focused" }), "focused");
102
+ assert.equal(resolveShellMode({ viewportMode: "unknown", desktopLayout: "focused" }), "classic");
103
+ });
104
+
105
+ test("phone and tablet activation are independent and do not inherit desktop layout", () => {
106
+ for (const desktopLayout of ["classic", "focused"]) {
107
+ for (const phoneMode of ["legacy", "preview", "v2", "unknown"]) {
108
+ for (const tabletMode of ["legacy", "preview", "v2", "unknown"]) {
109
+ const modes = { desktopLayout, phoneMode, tabletMode };
110
+ assert.equal(resolveShellMode({ ...modes, viewportMode: "phone" }),
111
+ ["preview", "v2"].includes(phoneMode) ? "mobile-v2" : "classic");
112
+ assert.equal(resolveShellMode({ ...modes, viewportMode: "tablet" }),
113
+ ["preview", "v2"].includes(tabletMode) ? "tablet-v2" : "classic");
114
+ assert.equal(resolveShellMode({ ...modes, viewportMode: "desktop" }), desktopLayout);
115
+ }
116
+ }
117
+ }
118
+ });
119
+
120
+ test("recovery wins through viewport changes without altering preferences or modes", () => {
121
+ const modes = { recovery: true, desktopLayout: "focused", phoneMode: "preview", tabletMode: "v2" };
122
+ for (const viewportMode of ["desktop", "phone", "tablet", "phone", "desktop"]) {
123
+ assert.equal(resolveShellMode({ ...modes, viewportMode }), "classic");
124
+ }
125
+ assert.deepEqual(modes, { recovery: true, desktopLayout: "focused", phoneMode: "preview", tabletMode: "v2" });
126
+ assert.equal(resolveShellMode({ ...modes, recovery: false, viewportMode: "desktop" }), "focused");
127
+ assert.equal(resolveShellMode({ ...modes, recovery: false, viewportMode: "phone" }), "mobile-v2");
128
+ assert.equal(resolveShellMode({ ...modes, recovery: false, viewportMode: "tablet" }), "tablet-v2");
129
+ });
130
+
131
+ test("optional focused fields roundtrip independently without filling absent fields", () => {
132
+ for (const optional of [
133
+ { navigation: "left" }, { navigation: "top" },
134
+ { navCollapsed: false }, { navCollapsed: true },
135
+ { pinnedActions: [] }, { pinnedActions: ["project:files", "Session_New-1", "model:fake/fake-model", "command:with%20space"] },
136
+ { inspectorWidth: 240 }, { inspectorWidth: 320 }, { inspectorWidth: 640 },
137
+ ]) {
138
+ for (const desktopLayout of ["classic", "focused"]) {
139
+ const value = { v: 1, desktopLayout, ...optional };
140
+ const storage = fakeStorage();
141
+ assert.deepEqual(writeShellPreferences(storage, value), { ok: true, reason: null });
142
+ assert.deepEqual(JSON.parse(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY)), value);
143
+ assert.deepEqual(readShellPreferences(storage), { status: "valid", value });
144
+ assert.equal(storage.calls.every(([, key]) => key === SHELL_PREFERENCES_STORAGE_KEY), true);
145
+ }
146
+ }
147
+ });
148
+
149
+ test("pins keep first occurrence order and accept exactly twenty distinct stable IDs", () => {
150
+ const pins = ["a", `Z${"_".repeat(119)}`, "project:files", "Session_New-1",
151
+ ...Array.from({ length: 16 }, (_, i) => `action:${i}`)];
152
+ const input = { v: 1, desktopLayout: "focused", navigation: "top", navCollapsed: true,
153
+ pinnedActions: [pins[0], pins[1], pins[0], ...pins.slice(2), pins[1]], inspectorWidth: 640 };
154
+ const expected = { ...input, pinnedActions: pins };
155
+ const raw = JSON.stringify(input);
156
+ const storage = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
157
+ const read = readShellPreferences(storage);
158
+ assert.deepEqual(read, { status: "valid", value: expected });
159
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw, "read does not repair duplicate pins");
160
+ read.value.pinnedActions.pop();
161
+ assert.deepEqual(readShellPreferences(storage).value, expected, "reads do not share mutable pin arrays");
162
+ assert.deepEqual(writeShellPreferences(storage, input), { ok: true, reason: null });
163
+ assert.deepEqual(JSON.parse(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY)), expected);
164
+ assert.equal(JSON.stringify(input), raw, "write leaves caller pins intact");
165
+ input.pinnedActions.length = 0;
166
+ assert.deepEqual(readShellPreferences(storage).value, expected);
167
+ });
168
+
169
+ test("invalid optional fields reject the whole record and never write or repair storage", () => {
170
+ const invalid = [
171
+ ...[undefined, null, "bottom", "Left", true, 1].map((navigation) => ({ navigation })),
172
+ ...[undefined, null, "false", 0, 1].map((navCollapsed) => ({ navCollapsed })),
173
+ ...[undefined, null, "project:files", {}, [1], [null], [""], ["1action"], [" leading"],
174
+ ["trailing "], ["é"], ["a\n"], ["a\r"], [`a${"b".repeat(512)}`],
175
+ Array(1), Array.from({ length: 21 }, (_, i) => `action:${i}`)]
176
+ .map((pinnedActions) => ({ pinnedActions })),
177
+ ...[undefined, null, 239, 641, 320.5, "320", true, NaN, Infinity]
178
+ .map((inspectorWidth) => ({ inspectorWidth })),
179
+ ];
180
+ for (const optional of invalid) {
181
+ const original = '{"v":9,"desktopLayout":"future"}';
182
+ const storage = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, original], ["other", "untouched"]]);
183
+ const value = { v: 1, desktopLayout: "focused", ...optional };
184
+ assert.deepEqual(writeShellPreferences(storage, value), { ok: false, reason: "invalid" });
185
+ assert.deepEqual(storage.calls, []);
186
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), original);
187
+ assert.equal(storage.records.get("other"), "untouched");
188
+ const raw = JSON.stringify(value);
189
+ // JSON omits undefined, so only explicit fields reach the record reader.
190
+ if (Object.values(optional)[0] !== undefined) {
191
+ const reader = fakeStorage([[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
192
+ assert.deepEqual(readShellPreferences(reader), { status: "invalid", value: fallback }, raw);
193
+ assert.equal(reader.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw);
194
+ assert.deepEqual(reader.calls, [["get", SHELL_PREFERENCES_STORAGE_KEY]]);
195
+ }
196
+ }
197
+ });
198
+
199
+ test("focused optional fields preserve storage failure status and mobile recovery resolution", () => {
200
+ const value = { v: 1, desktopLayout: "focused", navigation: "top", navCollapsed: true,
201
+ pinnedActions: ["project:files"], inspectorWidth: 240 };
202
+ assert.deepEqual(writeShellPreferences({ setItem() { throw new Error("quota exceeded"); } }, value),
203
+ { ok: false, reason: "unavailable" });
204
+ const storage = fakeStorage();
205
+ writeShellPreferences(storage, value);
206
+ const preferences = readShellPreferences(storage).value;
207
+ const raw = storage.records.get(SHELL_PREFERENCES_STORAGE_KEY);
208
+ assert.equal(resolveShellMode(preferences), "focused");
209
+ assert.equal(resolveShellMode({ ...preferences, recovery: true }), "classic");
210
+ assert.equal(resolveShellMode({ ...preferences, viewportMode: "phone", phoneMode: "v2" }), "mobile-v2");
211
+ assert.equal(resolveShellMode({ ...preferences, viewportMode: "tablet", phoneMode: "v2" }), "classic");
212
+ assert.equal(resolveShellMode({ ...preferences, viewportMode: "tablet", tabletMode: "preview" }), "tablet-v2");
213
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw);
214
+ });
215
+
216
+ const serverCohorts = [
217
+ undefined, null, "fresh", "established", "legacy", "unknown", "future", "", "Fresh", "fresh ",
218
+ true, false, 1, 0, {}, { cohort: "fresh" }, ["fresh"], new String("fresh"),
219
+ ];
220
+
221
+ test("effective preferences cover every read status and cohort with conservative fallbacks", () => {
222
+ const cases = [
223
+ { name: "absent", record: { status: "absent", value: fallback }, fresh: true },
224
+ { name: "explicit Classic", record: { status: "valid", value: fallback } },
225
+ { name: "explicit focused", record: { status: "valid", value: { v: 1, desktopLayout: "focused" } }, focused: true },
226
+ ...["invalid", "unavailable", "future", "VALID", "", null, undefined].map((status) => ({
227
+ name: `unrecognized or failed status ${status}`, record: { status, value: { v: 1, desktopLayout: "focused" } },
228
+ })),
229
+ ...[undefined, null, false, 0, "absent", [], {}, fallback].map((record, i) => ({
230
+ name: `unrecognized record ${i}`, record,
231
+ })),
232
+ ...[undefined, null, [], true, "focused", {}, { v: 2, desktopLayout: "focused" },
233
+ { v: "1", desktopLayout: "focused" }, { v: 1 }, { v: 1, desktopLayout: "future" },
234
+ { v: 1, desktopLayout: "focused", navigation: "bottom" },
235
+ { v: 1, desktopLayout: "focused", navCollapsed: "false" },
236
+ { v: 1, desktopLayout: "focused", pinnedActions: ["invalid id"] },
237
+ { v: 1, desktopLayout: "focused", inspectorWidth: 641 },
238
+ { v: 1, get desktopLayout() { throw new Error("denied choice"); } },
239
+ ].map((value, i) => ({ name: `invalid explicit value ${i}`, record: { status: "valid", value } })),
240
+ { name: "unreadable status", record: { get status() { throw new Error("denied status"); } } },
241
+ { name: "unreadable value", record: { status: "valid", get value() { throw new Error("denied value"); } } },
242
+ ];
243
+ for (const { name, record, fresh, focused } of cases) {
244
+ for (const cohort of serverCohorts) {
245
+ assert.deepEqual(effectiveShellPreferences(record, cohort), {
246
+ v: 1, desktopLayout: focused || (fresh && cohort === "fresh") ? "focused" : "classic",
247
+ }, `${name}, cohort ${String(cohort)}`);
248
+ }
249
+ }
250
+ assert.deepEqual(effectiveShellPreferences(), fallback);
251
+ assert.deepEqual(effectiveShellPreferences({ status: "absent", value: fallback }), fallback);
252
+ });
253
+
254
+ test("effective explicit preferences preserve validated optional fields without sharing or mutating them", () => {
255
+ const optionals = [
256
+ {}, { navigation: "left" }, { navigation: "top" }, { navCollapsed: false }, { navCollapsed: true },
257
+ { pinnedActions: [] }, { pinnedActions: ["project:files", "session:new"] },
258
+ { inspectorWidth: 240 }, { inspectorWidth: 640 },
259
+ { navigation: "top", navCollapsed: true, pinnedActions: ["project:files", "project:files"], inspectorWidth: 320 },
260
+ ];
261
+ for (const desktopLayout of ["classic", "focused"]) {
262
+ for (const optional of optionals) {
263
+ const value = Object.freeze({ v: 1, desktopLayout, ...optional, unknown: "not a preference" });
264
+ if (value.pinnedActions) Object.freeze(value.pinnedActions);
265
+ const record = Object.freeze({ status: "valid", value });
266
+ const before = JSON.stringify(record);
267
+ const expected = { v: 1, desktopLayout, ...optional };
268
+ if (expected.pinnedActions) expected.pinnedActions = [...new Set(expected.pinnedActions)];
269
+ for (const cohort of serverCohorts) {
270
+ const effective = effectiveShellPreferences(record, cohort);
271
+ assert.deepEqual(effective, expected);
272
+ assert.notEqual(effective, value);
273
+ if (effective.pinnedActions) {
274
+ assert.notEqual(effective.pinnedActions, value.pinnedActions);
275
+ effective.pinnedActions.push("session:other");
276
+ }
277
+ effective.desktopLayout = "changed by caller";
278
+ assert.equal(JSON.stringify(record), before);
279
+ assert.deepEqual(effectiveShellPreferences(record, cohort), expected);
280
+ }
281
+ }
282
+ }
283
+ });
284
+
285
+ test("cohort hydration performs no storage operations and preserves original read results", () => {
286
+ for (const raw of [null, "{", '{"v":9,"desktopLayout":"focused"}',
287
+ '{"v":1,"desktopLayout":"classic"}', '{"v":1,"desktopLayout":"focused"}']) {
288
+ const storage = fakeStorage(raw === null ? [] : [[SHELL_PREFERENCES_STORAGE_KEY, raw]]);
289
+ const record = readShellPreferences(storage);
290
+ const before = JSON.stringify(record);
291
+ for (const cohort of serverCohorts) effectiveShellPreferences(record, cohort);
292
+ assert.deepEqual(storage.calls, [["get", SHELL_PREFERENCES_STORAGE_KEY]]);
293
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), raw ?? undefined);
294
+ assert.equal(JSON.stringify(record), before);
295
+ }
296
+ const storage = fakeStorage();
297
+ storage.getItem = (key) => { storage.calls.push(["get", key]); throw new Error("denied"); };
298
+ const record = readShellPreferences(storage);
299
+ for (const cohort of serverCohorts) assert.deepEqual(effectiveShellPreferences(record, cohort), fallback);
300
+ assert.deepEqual(record, { status: "unavailable", value: fallback });
301
+ assert.deepEqual(storage.calls, [["get", SHELL_PREFERENCES_STORAGE_KEY]]);
302
+ assert.equal(storage.records.size, 0);
303
+ });
304
+
305
+ test("explicit choices survive late cohort changes and only deliberate writes persist", () => {
306
+ const storage = fakeStorage();
307
+ const absent = readShellPreferences(storage);
308
+ assert.deepEqual(effectiveShellPreferences(absent, "fresh"), { v: 1, desktopLayout: "focused" });
309
+ for (const desktopLayout of ["classic", "focused"]) {
310
+ const value = { v: 1, desktopLayout, navigation: "top", navCollapsed: false };
311
+ assert.deepEqual(writeShellPreferences(storage, value), { ok: true, reason: null });
312
+ const explicit = readShellPreferences(storage);
313
+ const callsBeforeHydration = storage.calls.length;
314
+ for (const cohort of serverCohorts) assert.deepEqual(effectiveShellPreferences(explicit, cohort), value);
315
+ assert.equal(storage.calls.length, callsBeforeHydration);
316
+ assert.equal(storage.records.get(SHELL_PREFERENCES_STORAGE_KEY), JSON.stringify(value));
317
+ assert.equal(explicit.status, "valid");
318
+ }
319
+ assert.deepEqual(storage.calls.map(([operation]) => operation), ["get", "set", "get", "set", "get"]);
320
+ assert.deepEqual(absent, { status: "absent", value: fallback });
321
+ });
322
+
323
+ test("effective cohort defaults leave independent compact modes and recovery precedence unchanged", () => {
324
+ const record = Object.freeze({ status: "absent", value: Object.freeze({ ...fallback }) });
325
+ for (const cohort of serverCohorts) {
326
+ const preferences = effectiveShellPreferences(record, cohort);
327
+ for (const phoneMode of ["legacy", "preview", "v2", "unknown"]) {
328
+ for (const tabletMode of ["legacy", "preview", "v2", "unknown"]) {
329
+ const modes = { ...preferences, phoneMode, tabletMode };
330
+ for (const viewportMode of ["desktop", "phone", "tablet", "unknown"]) {
331
+ const expected = viewportMode === "desktop" ? preferences.desktopLayout
332
+ : viewportMode === "phone" && ["preview", "v2"].includes(phoneMode) ? "mobile-v2"
333
+ : viewportMode === "tablet" && ["preview", "v2"].includes(tabletMode) ? "tablet-v2" : "classic";
334
+ assert.equal(resolveShellMode({ ...modes, viewportMode }), expected);
335
+ assert.equal(resolveShellMode({ ...modes, viewportMode, recovery: true }), "classic");
336
+ assert.equal(resolveShellMode({ ...modes, viewportMode, recovery: false }), expected);
337
+ }
338
+ }
339
+ }
340
+ }
341
+ assert.deepEqual(record, { status: "absent", value: fallback });
342
+ });
343
+
344
+ test('sidebar width roundtrips within bounds without changing other preferences', () => {
345
+ for (const navigationWidth of [180, 202, 320, 420]) {
346
+ const storage = fakeStorage();
347
+ const value = { v: 1, desktopLayout: 'focused', navigation: 'left', navigationWidth, inspectorWidth: 320 };
348
+ assert.equal(writeShellPreferences(storage, value).ok, true);
349
+ assert.deepEqual(readShellPreferences(storage).value, value);
350
+ }
351
+ for (const navigationWidth of [179, 421, 202.5, '202', null]) {
352
+ assert.equal(writeShellPreferences(fakeStorage(), { v: 1, desktopLayout: 'focused', navigationWidth }).reason, 'invalid');
353
+ }
354
+ });
355
+
356
+ test('overview visibility is an optional browser preference with conservative validation', () => {
357
+ const storage = fakeStorage();
358
+ for (const overviewOpen of [true, false]) {
359
+ const value = { v: 1, desktopLayout: 'focused', overviewOpen };
360
+ assert.equal(writeShellPreferences(storage, value).ok, true);
361
+ assert.deepEqual(effectiveShellPreferences(readShellPreferences(storage), 'fresh'), value);
362
+ }
363
+ for (const overviewOpen of [1, 'true', null]) {
364
+ assert.equal(writeShellPreferences(storage, { v: 1, desktopLayout: 'focused', overviewOpen }).reason, 'invalid');
365
+ }
366
+ assert.equal(readShellPreferences(fakeStorage()).value.overviewOpen, undefined);
367
+ });
@@ -27,8 +27,8 @@ assert.doesNotMatch(layout, /sectionHeightMin|sectionHeightMax|validateSectionHe
27
27
  assert.match(app, /const UI_LAYOUT_SIDE_PANEL_FIELDS = \["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"\];/, "the browser durable layout field list should omit section heights");
28
28
  assert.match(app, /function clearRemovedSidePanelSectionHeightState\(\)[\s\S]*localStorage\.removeItem\(REMOVED_SIDE_PANEL_SECTION_HEIGHT_STORAGE_KEY\)[\s\S]*record\.field === "sidePanel" && record\.subfield === "sectionHeights"/, "startup should remove the retired cache and pending mutations");
29
29
  assert.match(app, /clearRemovedSidePanelSectionHeightState\(\);\s*restoreDurableUiLayoutPendingJournal\(\);/, "retired height state should be cleared before pending layout restoration");
30
- assert.match(html, /styles\.css\?v=154/, "removing section resize styles should advance the stylesheet revision");
31
- assert.match(html, /app\.js\?v=185/, "removing section resize behavior should advance the app revision");
32
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156"/, "removing browser assets should advance the PWA cache identity");
30
+ assert.match(html, /styles\.css\?v=167/, "removing section resize styles should advance the stylesheet revision");
31
+ assert.match(html, /app\.js\?v=220/, "removing section resize behavior should advance the app revision");
32
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "removing browser assets should advance the PWA cache identity");
33
33
 
34
34
  console.log("side-panel-section-height-removal-static.test.mjs passed");
@@ -94,7 +94,7 @@ assert.match(app, /applyToolExecutionUpdate: \(event\) => \{\s+if \(!compactOutp
94
94
  assert.doesNotMatch(app.slice(app.indexOf("const streamOutputController"), app.indexOf("let assistantErrorSurfacedThisRun")), /renderWidgets|renderFooter|renderTabs|renderStatus|renderFeedbackTray|setRunIndicatorActivity|scheduleLiveTodoProgressWidgetSync|addEvent|fetch\(|api\(/, "controller integration must inject transcript-only sinks");
95
95
  const connectEvents = functionBody(app, "connectEvents");
96
96
  assert.match(connectEvents, /flushNormalStreamRenders\("reconnect"\);[\s\S]*?cancelNormalStreamRenders\(\);[\s\S]*?streamOutputController\.cancel\(\);[\s\S]*?resetCompactLiveOutput\(\);/, "reconnect and tab switches should flush normal formatting before canceling retained raw frames");
97
- assert.match(connectEvents, /source\.onerror = \(\) => \{[\s\S]*?streamOutputController\.flush\(\);[\s\S]*?flushNormalStreamRenders\("disconnect"\);[\s\S]*?streamOutputController\.cancel\(\);/, "an actual EventSource disconnect must flush formatting and cancel retained transcript work before browser retry");
97
+ assert.match(functionBody(app, "handleSessionStreamError"), /streamOutputController\.flush\(\);[\s\S]*?flushNormalStreamRenders\("disconnect"\);[\s\S]*?streamOutputController\.cancel\(\);/, "an actual EventSource disconnect must flush formatting and cancel retained transcript work before browser retry");
98
98
  const barrier = functionBody(app, "flushTranscriptStreamBarrier");
99
99
  const abort = functionBody(app, "abortActiveRun");
100
100
  assert.match(barrier, /streamOutputController\.barrier\(event\.type\);[\s\S]*?fallbackStreamDerivedOutput[\s\S]*?flushNormalStreamRenders\(event\.type\);/, "semantic lifecycle boundaries should flush raw state, reconcile authoritative derivation, and then publish pending formatting");
@@ -74,7 +74,7 @@ assert.match(app, /from "\.\/subagent-gate-visibility\.mjs"/, "the browser shoul
74
74
  assert.match(app, /function subagentOverviewGroups[\s\S]*Number\(data\?\.version\) === 2[\s\S]*displayRuns: runs/, "the side panel should render canonical v2 runs without recounting gate references");
75
75
  assert.match(app, /const gates = visibleSubagentGates\(tab, dismissedSubagentGateKeys, now\);[\s\S]*const displayRuns = ungatedSubagentRuns\(tab\);[\s\S]*displayRuns,/, "the v1 fallback should retain gate-owned run filtering before deriving count-neutral workflow totals");
76
76
  assert.match(app, /function renderSubagentGate\(tab, gate\)[\s\S]*subagentGateIsTerminal\(gate\)[\s\S]*Hide finished retry gate[\s\S]*dismissedSubagentGateKeys\.add\(key\)[\s\S]*renderSubagents\(\)[\s\S]*event\.detail === 0[\s\S]*focusTarget\?\.focus/, "terminal gate cards should expose an accessible hide button and preserve keyboard focus after rerendering");
77
- assert.match(app, /pruneDismissedSubagentGateKeys\(latestSubagents\?\.tabs, dismissedSubagentGateKeys\)/, "polling should prune stale dismissal keys");
77
+ assert.match(app, /pruneDismissedSubagentGateKeys\(data\?\.tabs, dismissedSubagentGateKeys\)/, "polling should prune stale dismissal keys");
78
78
  assert.match(css, /\.subagent-gate-actions[\s\S]*\.subagent-gate-close[\s\S]*min-width:\s*1\.45rem[\s\S]*background:\s*transparent[\s\S]*\.subagent-gate-close:hover,[\s\S]*\.subagent-gate-close:focus-visible/, "the close control should remain minimal, compact, and keyboard-visible");
79
79
  assert.match(serviceWorker, /"\/subagent-gate-visibility\.mjs"/, "the PWA app shell should cache the visibility module");
80
80
  assert.match(server, /STATIC_PUBLIC_FILE_EXTENSIONS[\s\S]*"\.mjs"/, "the server should serve typed visibility modules from the public asset boundary");
@@ -15,7 +15,7 @@ assert.deepEqual(
15
15
  );
16
16
  assert.deepEqual(
17
17
  subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, dirty: true, activeConfigTab: false }),
18
- { disabled: true, reason: "Switch back to the tab where these changes were made to save them." },
18
+ { disabled: true, reason: "Switch back to the thread where these changes were made to save them." },
19
19
  "a dirty draft should explain that its owning tab must be active",
20
20
  );
21
21
  assert.deepEqual(
@@ -35,7 +35,7 @@ assert.deepEqual(
35
35
  );
36
36
  assert.deepEqual(
37
37
  subagentLaunchSlotSaveState(),
38
- { disabled: true, reason: "Agent model configuration is not available for this tab." },
38
+ { disabled: true, reason: "Agent model configuration is not available for this thread." },
39
39
  "missing configuration should explain why saving is unavailable",
40
40
  );
41
41
 
@@ -20,7 +20,7 @@ assert.match(html, /id="subagentLaunchSlotsSave"[^>]*aria-describedby="subagentL
20
20
  assert.match(html, /id="subagentLaunchSlotsAnnouncer"[^>]*aria-live="polite"[^>]*aria-atomic="true"/, "slot changes should be announced accessibly");
21
21
  assert.match(app, /from "\.\/subagent-launch-slot-state\.mjs"/, "the browser should use the pure launch-slot state helper");
22
22
  assert.match(app, /const subagentLaunchSlotReloadTabs = new Set\(\)[\s\S]*subagentLaunchSlotReloadTabs\.add\(activeTabId\)[\s\S]*subagentLaunchSlotReloadTabs\.delete\(activeTabId\)/, "reload reminders should be tracked per tab until reload");
23
- assert.match(app, /subagentLaunchSlotsSummaryStatus\.textContent[\s\S]*"Unsaved changes"[\s\S]*"Saved · reload this tab"[\s\S]*subagentLaunchSlots\.open = true/, "the collapsed summary should surface state and reopen for errors or required reloads");
23
+ assert.match(app, /subagentLaunchSlotsSummaryStatus\.textContent[\s\S]*"Unsaved changes"[\s\S]*"Saved · reload this thread"[\s\S]*subagentLaunchSlots\.open = true/, "the collapsed summary should surface state and reopen for errors or required reloads");
24
24
  assert.match(app, /const saveState = subagentLaunchSlotSaveState\([\s\S]*subagentLaunchSlotsSave\.disabled = saveState\.disabled[\s\S]*`Unsaved changes · \$\{saveState\.reason\}`/, "save eligibility and its adjacent explanation should come from one canonical state");
25
25
  assert.doesNotMatch(app, /`(?:Model|Thinking) · \$\{slotLabel\}`/, "visible field labels should stay compact while aria-labels retain slot context");
26
26
  assert.doesNotMatch(app, /make\("(?:p|span)", "subagent-launch-slot-(?:meta|id)"/, "redundant assignment summaries and internal slot IDs should stay out of the compact editor");
@@ -28,7 +28,7 @@ assert.match(app, /const SUBAGENT_ASYNC_WIDGET_KEY = "subagent-async"[\s\S]*case
28
28
  assert.match(app, /for \(const \[key, value\] of widgets\)[\s\S]*if \(key === SUBAGENT_ASYNC_WIDGET_KEY\) continue;/, "stale cached async-status widgets should remain hidden defensively");
29
29
  assert.match(css, /\.subagent-source-badge[\s\S]*text-overflow: ellipsis[\s\S]*@media \(max-width: 720px\)/, "source badges should remain compact and responsive");
30
30
  assert.match(html, /Managed and registered Pi agent runs[\s\S]*External agents/, "help should explain managed, registered, and external groups");
31
- assert.match(html, /styles\.css\?v=154[\s\S]*app\.js\?v=185/, "browser assets should use the current subagent-observability revisions");
32
- assert.match(worker, /pi-webui-pwa-v156/, "PWA cache identity should advance with subagent widget suppression");
31
+ assert.match(html, /styles\.css\?v=167[\s\S]*app\.js\?v=220/, "browser assets should use the current subagent-observability revisions");
32
+ assert.match(worker, /pi-webui-pwa-v200/, "PWA cache identity should advance with subagent widget suppression");
33
33
 
34
34
  console.log("subagent-observability-static.test.mjs passed");
@@ -1,3 +1,4 @@
1
+ import { createActivityAgentsController } from "../public/activity-agents-controller.mjs";
1
2
  import assert from "node:assert/strict";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import vm from "node:vm";
@@ -135,38 +136,18 @@ assert.match(viewSyncSource, /run && !subagentRunCanOpen\(run,[\s\S]*subagentOve
135
136
  assert.match(app, /async function openSubagentOverlay\(tab, run, agent\)[\s\S]*!subagentRunCanOpen\(run, agent\)/, "direct overlay entry should reject unsupported rows");
136
137
  assert.match(app, /function subagentGateAttemptTarget\(tab, attempt\)[\s\S]*subagentRunCanOpen\(run, agent\)/, "retry-gate output entry should reject unsupported rows");
137
138
 
138
- const refreshSource = sourceBetween(app, "async function refreshSubagents(", "\nfunction scheduleRefreshSubagents(");
139
+ const refreshSource = sourceBetween(app, "function refreshSubagents(", "\nfunction scheduleRefreshSubagents(");
139
140
  let resolveFirst;
140
141
  let resolveSecond;
141
142
  let apiCalls = 0;
142
143
  const firstResponse = new Promise((resolve) => { resolveFirst = resolve; });
143
144
  const secondResponse = new Promise((resolve) => { resolveSecond = resolve; });
144
- const refreshContext = {
145
- subagentsRefreshPromise: null,
146
- subagentsRefreshQueued: false,
147
- subagentsLoading: false,
148
- latestSubagents: null,
149
- subagentsError: null,
150
- dismissedSubagentGateKeys: new Set(),
151
- subagentOverlaySelection: null,
152
- activeTabId: "tab-a",
153
- activeSubagentTerminalId: null,
154
- subagentAutoClearEnabled: false,
155
- renderSubagents() {},
156
- pruneDismissedSubagentGateKeys() {},
157
- syncSubagentTerminalViewsFromOverview() { return false; },
158
- materializeRetainedSubagentTerminalViews() { return false; },
159
- renderWidgets() {},
160
- renderSubagentTerminalView() {},
161
- scheduleSubagentTerminalRefresh() {},
162
- renderTabs() {},
163
- finishedSubagentRunSelections() { return []; },
164
- async clearFinishedSubagentRuns() {},
165
- api() {
166
- apiCalls += 1;
167
- return apiCalls === 1 ? firstResponse : secondResponse;
168
- },
169
- };
145
+ const overviewOwner = createActivityAgentsController({
146
+ getVisibility: () => "visible", getAutoClear: () => false, finishedSelections: () => [],
147
+ canCancel: () => false, canDismiss: () => false, isAttachedProjection: () => false, agentCount: () => 0,
148
+ api() { apiCalls += 1; return apiCalls === 1 ? firstResponse : secondResponse; },
149
+ });
150
+ const refreshContext = { activityAgents: overviewOwner };
170
151
  vm.runInNewContext(`${refreshSource}\nthis.runRefreshSubagents = refreshSubagents;`, refreshContext);
171
152
  const initialRefresh = refreshContext.runRefreshSubagents();
172
153
  const overlappingRefresh = refreshContext.runRefreshSubagents();
@@ -176,8 +157,10 @@ await new Promise((resolve) => setImmediate(resolve));
176
157
  assert.equal(apiCalls, 2, "an overlapping request should guarantee one trailing authoritative refresh");
177
158
  resolveSecond({ data: { revision: "authoritative" } });
178
159
  await Promise.all([initialRefresh, overlappingRefresh]);
179
- assert.equal(refreshContext.latestSubagents?.revision, "authoritative", "the trailing refresh should own final browser state");
180
- assert.equal(refreshContext.subagentsLoading, false, "coalesced refresh should release its loading guard");
181
- assert.equal(refreshContext.subagentsRefreshPromise, null, "coalesced refresh should clear its shared promise");
160
+ assert.equal(overviewOwner.getSnapshot().data?.revision, "authoritative", "the trailing refresh should own final browser state");
161
+ assert.equal(overviewOwner.getSnapshot().loading, false, "coalesced refresh should release its loading guard");
162
+ await refreshContext.runRefreshSubagents();
163
+ assert.equal(apiCalls, 3, "settled refresh should release its shared promise for new work");
164
+ overviewOwner.dispose();
182
165
 
183
166
  console.log("subagent-reliability-integration.test.mjs passed");
@@ -60,9 +60,9 @@ assert.match(css, /\.markdown-code \.syntax-comment \{[^}]*font-style: italic;/,
60
60
 
61
61
  // --- Offline/PWA startup closure and coherent revisions ---
62
62
  assert.match(serviceWorker, /"\/syntax-highlight\.mjs",/, "the eagerly imported tokenizer must be part of the offline app shell");
63
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156"/, "adding a startup module should advance the PWA cache identity");
64
- assert.match(html, /styles\.css\?v=154/, "new token styles should advance the stylesheet revision");
65
- assert.match(html, /data-app-src="\/app\.js\?v=185"/, "new renderer wiring should advance the app module revision");
63
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "adding a startup module should advance the PWA cache identity");
64
+ assert.match(html, /styles\.css\?v=167/, "new token styles should advance the stylesheet revision");
65
+ assert.match(html, /data-app-src="\/app\.js\?v=220"/, "new renderer wiring should advance the app module revision");
66
66
  assert.match(pkg, /node --check public\/syntax-highlight\.mjs/, "the package check should syntax-check the startup-critical tokenizer");
67
67
 
68
68
  const appShell = serviceWorker.slice(serviceWorker.indexOf("const APP_SHELL"), serviceWorker.indexOf("];", serviceWorker.indexOf("const APP_SHELL")));
@@ -19,7 +19,7 @@ assert.match(app, /const closingTerminalTabIds = new Set\(\)/, "the frontend sho
19
19
  assert.match(schedule, /closingTerminalTabIds\.has\(tabContext\.tabId\)/, "continuity refreshes should skip tabs that are intentionally closing");
20
20
  assert.match(schedule, /if \(!isCurrentTabContext\(tabContext\) \|\| closingTerminalTabIds\.has\(tabContext\.tabId\)\) return;[\s\S]*continuity refresh failed/, "an in-flight refresh rejected by intentional shutdown should not produce a false error");
21
21
  assert.match(closeTabs, /for \(const id of targetIds\) closingTerminalTabIds\.add\(id\);[\s\S]*finally \{\s*for \(const id of targetIds\) closingTerminalTabIds\.delete\(id\);/, "the close lifecycle should mark every target before the request and always clear the marker afterward");
22
- assert.match(closeTabs, /addEvent\(`closed \$\{closedIds\.length \|\| targetTabs\.length\} terminal \$\{closedIds\.length === 1 \? "tab" : "tabs"\}`, "info"\)/, "successful terminal tab closure should be recorded as information rather than a warning");
22
+ assert.match(closeTabs, /addEvent\(`closed \$\{closedIds\.length \|\| targetTabs\.length\} \$\{closedIds\.length === 1 \? "thread" : "threads"\}`, "info"\)/, "successful terminal tab closure should be recorded as information rather than a warning");
23
23
  assert.doesNotMatch(closeTabs, /addEvent\(`closed [^`]+`, "warn"\)/, "successful terminal tab closure should never be classified as a warning");
24
24
 
25
25
  console.log("tab-close-continuity-static.test.mjs passed");
@@ -0,0 +1,99 @@
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 names = ['refreshTabs', 'closeTerminalTabs', 'applyAuthoritativeTabSnapshot', 'applyTabMetadata', 'syncResponseTabs'];
8
+ const functions = names.map(name => {
9
+ const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
10
+ assert.ok(start >= 0, name);
11
+ return source.slice(start, source.indexOf('\n}', start) + 2);
12
+ }).join('\n');
13
+
14
+ function fixture() {
15
+ const context = vm.createContext({ assert, AbortController });
16
+ vm.runInContext(`
17
+ let tabs=[{id:'a',title:'A',running:true,activity:{isWorking:false}},{id:'b',title:'B',running:true,activity:{isWorking:false}}];
18
+ let activeTabId='a',tabsRefreshSerial=0;
19
+ const oldSnapshot=tabs.map(tab=>({...tab,activity:{isWorking:true}}));
20
+ const closingTerminalTabIds=new Set(), activityIntercom={prune(){}},subagentTerminalViews=new Map();
21
+ const commandCatalogsByTab=new Map(),appRunnerDataByTab=new Map(),tabMessagesCache=new Map(),fileViewersByTab=new Map(),fileViewerSelectionsByTab=new Map(),btwWidgetDismissedIdsByTab=new Map();
22
+ const composerStore={clearTab(){}},sessionContext={invalidate(){}},sessionEvents={close(){assert.fail('inactive close must not close foreground SSE')}};
23
+ const noop=()=>{},syncTabMetadata=noop,syncBlockedTabNotificationsFromTabs=noop,syncAgentDoneNotificationsFromTabs=noop,rememberServerStartCwd=noop,renderSessionSkillTags=noop,renderTabs=noop,syncTabPolling=noop,prefetchInactiveTabCommandCatalogs=noop;
24
+ const clearAttachments=noop,clearGitWorkflowForTab=noop,clearFeatureDecisionStateForTab=noop,removeSubagentTerminalViewsForParent=noop,syncTerminalCustomGroupsWithTabs=noop,clearOpenTerminalTabGroup=noop,offerUndo=noop;
25
+ const setTabActivity=noop,updateConversationModeForTab=noop,updateSessionSummaryForTab=noop,renderConversationModeControls=noop,renderWorkflowModeControls=noop,renderSessionSummaryControls=noop;
26
+ const addEvent=noop,tabHasActiveAgent=()=>false;
27
+ const tabsSnapshotSignature=JSON.stringify,tabsRenderSnapshotSignature=JSON.stringify;
28
+ const polls=[];
29
+ const api=(path)=>path==='/api/tabs'
30
+ ? new Promise(resolve=>polls.push(resolve))
31
+ : Promise.resolve({data:{closedIds:['b'],tabs:[{id:'a',title:'A',running:true,activity:{isWorking:false}}]}});
32
+ ${functions}
33
+ `,context);
34
+ return code => vm.runInContext(code,context);
35
+ }
36
+
37
+ test('a changed old poll cannot resurrect a successfully closed idle tab', async () => {
38
+ await fixture()(`(async()=>{
39
+ const pending=refreshTabs({signal:new AbortController().signal});
40
+ await closeTerminalTabs(['b']);
41
+ assert.deepEqual(tabs.map(tab=>tab.id),['a']);
42
+ polls[0]({data:{tabs:oldSnapshot}});
43
+ await pending;
44
+ assert.deepEqual(tabs.map(tab=>tab.id),['a']);
45
+ assert.equal(tabs[0].activity.isWorking,false);
46
+ })()`);
47
+ });
48
+
49
+ test('a newer single-tab mutation wins over an old changed collection', async () => {
50
+ await fixture()(`(async()=>{
51
+ const pending=refreshTabs();
52
+ applyTabMetadata({id:'b',title:'Renamed B'});
53
+ polls[0]({data:{tabs:oldSnapshot}});
54
+ await pending;
55
+ assert.equal(tabs.find(tab=>tab.id==='b').title,'Renamed B');
56
+ })()`);
57
+ });
58
+
59
+ test('create or resume collection metadata cannot be erased by an older poll', async () => {
60
+ await fixture()(`(async()=>{
61
+ const pending=refreshTabs();
62
+ const added={id:'c',title:'Resumed',activity:{isWorking:false}};
63
+ syncResponseTabs({data:{tabs:[...tabs,added],tab:added}});
64
+ polls[0]({data:{tabs:oldSnapshot}});
65
+ await pending;
66
+ assert.deepEqual(tabs.map(tab=>tab.id),['a','b','c']);
67
+ })()`);
68
+ });
69
+
70
+ test('reverse refresh completion retains the newer snapshot', async () => {
71
+ await fixture()(`(async()=>{
72
+ const first=refreshTabs(),second=refreshTabs();
73
+ polls[1]({data:{tabs:[{id:'a',title:'Newest'}]}});
74
+ await second;
75
+ polls[0]({data:{tabs:oldSnapshot}});
76
+ await first;
77
+ assert.equal(tabs[0].title,'Newest');
78
+ assert.equal(tabs.length,1);
79
+ })()`);
80
+ });
81
+
82
+ test('aborted scheduled results never mutate metadata even if transport resolves', async () => {
83
+ await fixture()(`(async()=>{
84
+ const controller=new AbortController();
85
+ const pending=refreshTabs({signal:controller.signal});
86
+ controller.abort();
87
+ polls[0]({data:{tabs:oldSnapshot}});
88
+ await pending;
89
+ assert.equal(tabs[0].activity.isWorking,false);
90
+ assert.equal(tabs.length,2);
91
+ })()`);
92
+ });
93
+
94
+ test('all authoritative collection writers use the invalidating boundary', () => {
95
+ const refresh = functions.slice(functions.indexOf('async function refreshTabs'), functions.indexOf('\n}', functions.indexOf('async function refreshTabs')) + 2);
96
+ const apply = functions.slice(functions.indexOf('function applyAuthoritativeTabSnapshot'), functions.indexOf('\n}', functions.indexOf('function applyAuthoritativeTabSnapshot')) + 2);
97
+ const remaining = source.replace(refresh, '').replace(apply, '');
98
+ assert.doesNotMatch(remaining, /^\s*tabs =/m, 'new collection writers must invalidate in-flight snapshots');
99
+ });