@firstpick/pi-package-webui 0.11.1 → 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 (309) 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 +320 -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/activity-intercom-controller.spec.mjs +457 -0
  93. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  94. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  95. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  96. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  97. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  98. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  99. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  100. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  101. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  102. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  103. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  104. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  105. package/tests/browser/control-visibility.spec.mjs +5 -0
  106. package/tests/browser/controls-layout.spec.mjs +21 -2
  107. package/tests/browser/conversation-overview.spec.mjs +251 -0
  108. package/tests/browser/draft-conversations.spec.mjs +276 -0
  109. package/tests/browser/empty-startup-fixture.mjs +135 -0
  110. package/tests/browser/empty-startup.spec.mjs +282 -0
  111. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  112. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  113. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  114. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  115. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  116. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  117. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  118. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  119. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  120. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  121. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  122. package/tests/browser/inspector-header.spec.mjs +221 -0
  123. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  124. package/tests/browser/inspector-resize.spec.mjs +227 -0
  125. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  126. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  127. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  128. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  129. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  130. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  131. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  132. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  133. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  134. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  135. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  136. package/tests/browser/more-row-menus.spec.mjs +258 -0
  137. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  138. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  139. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  140. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  141. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  142. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  143. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  144. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  145. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  146. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  147. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  148. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  149. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  150. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  151. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  152. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  153. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  154. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  155. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  156. package/tests/browser/session-fixture.mjs +118 -0
  157. package/tests/browser/session-ownership.spec.mjs +175 -0
  158. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  159. package/tests/browser/session-shelves.spec.mjs +340 -0
  160. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  161. package/tests/browser/session-summary.spec.mjs +17 -12
  162. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  163. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  164. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  165. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  166. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  167. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  168. package/tests/browser/shell-ownership.spec.mjs +398 -0
  169. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  170. package/tests/browser/shell-rollout.spec.mjs +357 -0
  171. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  172. package/tests/browser/shell-workspace.spec.mjs +433 -0
  173. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  174. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  175. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  176. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  177. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  178. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  179. package/tests/browser/themed-selects.spec.mjs +297 -0
  180. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  181. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  182. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  183. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  184. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  185. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  186. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  187. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  188. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  189. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  190. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  191. package/tests/codex-fast-mode-static.test.mjs +16 -11
  192. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  193. package/tests/codex-usage-source.test.mjs +4 -3
  194. package/tests/component-update-api-static.test.mjs +2 -2
  195. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  196. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  197. package/tests/control-visibility-static.test.mjs +3 -3
  198. package/tests/controls-layout-static.test.mjs +5 -5
  199. package/tests/conversation-overview-adapter.test.mjs +100 -0
  200. package/tests/document-artifact-static.test.mjs +2 -1
  201. package/tests/draft-conversations.test.mjs +205 -0
  202. package/tests/empty-startup-launcher.test.mjs +197 -0
  203. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  204. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  205. package/tests/fast-mode-client-static.test.mjs +1 -1
  206. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  207. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  208. package/tests/file-viewer-image-static.test.mjs +15 -11
  209. package/tests/file-viewer-search-static.test.mjs +5 -5
  210. package/tests/fixtures/fake-pi.mjs +41 -9
  211. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  212. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  213. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  214. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  215. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  216. package/tests/git-workflow-dispatch.test.mjs +66 -0
  217. package/tests/git-workflow-preferences.test.mjs +9 -1
  218. package/tests/guided-git-activation-static.test.mjs +14 -11
  219. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  220. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  221. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  222. package/tests/http-endpoints-harness.test.mjs +21 -9
  223. package/tests/interaction-state-stability-static.test.mjs +4 -3
  224. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  225. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  226. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  227. package/tests/main-output-loading-static.test.mjs +4 -4
  228. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  229. package/tests/mobile-compact-layout.test.mjs +2 -2
  230. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  231. package/tests/mobile-foundation-static.test.mjs +10 -7
  232. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  233. package/tests/mobile-static.test.mjs +173 -135
  234. package/tests/model-catalog-order.test.mjs +103 -0
  235. package/tests/native-parity.test.mjs +6 -4
  236. package/tests/native-session-choice-owner.test.mjs +102 -0
  237. package/tests/native-update-lifecycle.test.mjs +10 -5
  238. package/tests/no-project-http-harness.test.mjs +328 -0
  239. package/tests/no-project-navigation.test.mjs +54 -0
  240. package/tests/no-project-workspaces.test.mjs +77 -0
  241. package/tests/open-issue-wizard-static.test.mjs +1 -1
  242. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  243. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  244. package/tests/package-updates.test.mjs +630 -0
  245. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  246. package/tests/platform-event-stream.test.mjs +253 -0
  247. package/tests/project-file-viewer-controller.test.mjs +652 -0
  248. package/tests/project-git-tools-adapter.test.mjs +103 -0
  249. package/tests/project-git-tools-controller.test.mjs +577 -0
  250. package/tests/project-runners-controller.test.mjs +453 -0
  251. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  252. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  253. package/tests/questionnaire-dialog.test.mjs +6 -6
  254. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  255. package/tests/rpc-supervisor-host.test.mjs +4 -1
  256. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  257. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  258. package/tests/server-app-runners.test.mjs +536 -0
  259. package/tests/server-codex-fast-mode.test.mjs +346 -0
  260. package/tests/server-conversation-mode.test.mjs +386 -0
  261. package/tests/server-conversation-voice.test.mjs +426 -0
  262. package/tests/server-extension-ui-requests.test.mjs +357 -0
  263. package/tests/server-git-generation.test.mjs +558 -0
  264. package/tests/server-git-mutations.test.mjs +729 -0
  265. package/tests/server-git-reads.test.mjs +381 -0
  266. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  267. package/tests/server-helper-requests.test.mjs +364 -0
  268. package/tests/server-rpc-transports.test.mjs +553 -0
  269. package/tests/server-settings-store.test.mjs +132 -0
  270. package/tests/server-shell-rollout.test.mjs +478 -0
  271. package/tests/server-sse-delivery.test.mjs +410 -0
  272. package/tests/server-workspace-files.test.mjs +546 -0
  273. package/tests/session-attention-scheduler.test.mjs +514 -0
  274. package/tests/session-composer-store.test.mjs +153 -0
  275. package/tests/session-context.test.mjs +134 -0
  276. package/tests/session-extension-requests.test.mjs +193 -0
  277. package/tests/session-ownership-adapter.test.mjs +130 -0
  278. package/tests/session-sampling-ui-static.test.mjs +10 -4
  279. package/tests/session-send-lifetime.test.mjs +140 -0
  280. package/tests/session-shelf-state.test.mjs +348 -0
  281. package/tests/session-shelves-adapter.test.mjs +79 -0
  282. package/tests/session-summary-lifetime.test.mjs +54 -0
  283. package/tests/settings-resource-controller.test.mjs +548 -0
  284. package/tests/shell-action-adapter.test.mjs +169 -0
  285. package/tests/shell-actions.test.mjs +182 -0
  286. package/tests/shell-navigation.test.mjs +348 -0
  287. package/tests/shell-preferences.test.mjs +367 -0
  288. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  289. package/tests/stream-output-isolation-static.test.mjs +1 -1
  290. package/tests/subagent-gate-visibility.test.mjs +1 -1
  291. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  292. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  293. package/tests/subagent-observability-static.test.mjs +2 -2
  294. package/tests/subagent-reliability-integration.test.mjs +13 -30
  295. package/tests/syntax-highlighting-static.test.mjs +3 -3
  296. package/tests/tab-close-continuity-static.test.mjs +1 -1
  297. package/tests/tab-metadata-ordering.test.mjs +99 -0
  298. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  299. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  300. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  301. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  302. package/tests/theme-customizer-static.test.mjs +1 -1
  303. package/tests/thread-display-title.test.mjs +44 -0
  304. package/tests/update-api-harness.test.mjs +15 -14
  305. package/tests/update-tab-restore-harness.test.mjs +3 -0
  306. package/tests/webui-settings-locking.test.mjs +2 -2
  307. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  308. package/tests/workspace-choices.test.mjs +114 -0
  309. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -1,8 +1,11 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { readFile } from "node:fs/promises";
3
+
3
4
  import { dirname, join } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
6
 
7
+ const codexSpeed = await readFile(new URL("../lib/server/codex-fast-mode.mjs", import.meta.url), "utf8");
8
+
6
9
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
10
  const [server, app, html, styles, serviceWorker, technical, development, packageRaw, lockRaw, optionalFeatureCatalog] = await Promise.all([
8
11
  readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
@@ -27,26 +30,26 @@ assert.equal(lock.packages?.[`node_modules/${packageName}`], undefined, "lockfil
27
30
  assert.match(optionalFeatureCatalog, /\["codexFastMode", "@firstpick\/pi-extension-codex-fast-mode", "\^0\.1\.0"\]/, "Optional Features should retain the Pi-installable Fast-mode package mapping");
28
31
 
29
32
  assert.match(server, /const OPTIONAL_FEATURE_PACKAGES = new Map\(OPTIONAL_FEATURE_CATALOG/, "server should derive Fast-mode installation from the shared Optional Features catalog");
30
- assert.match(server, /CODEX_FAST_MODE_STATUS_KEY = "codex-fast-mode"[\s\S]*?CODEX_FAST_MODE_COMMAND_NAME = "fast-mode"/, "server should use the extension-owned status and command contracts");
31
- assert.match(server, /function codexFastModeStatusState\(statusText\)[\s\S]*?codexSpeedModeFromStatus\(stripAnsi\(statusText\)\)/, "server should use the tested exact status parser");
32
- assert.match(server, /function codexFastModeSnapshot\(tab, patch = \{\}\)[\s\S]*?extensionStatusMap\(tab\)\.get\(CODEX_FAST_MODE_STATUS_KEY\)/, "server snapshots should come from remembered extension status");
33
- assert.match(server, /async function codexFastModeFeatureData[\s\S]*?codexFastModeSnapshot\(tab\)[\s\S]*?tabHasActiveOutput\(tab\)[\s\S]*?ultrafastModelEligible:[\s\S]*?CODEX_FAST_MODE_CREDIT_NOTICE/, "GET state should be tab-scoped, extension-owned, busy-aware, model-gated, and disclose credit use");
34
- assert.match(server, /async function waitForCodexFastModeStatus\(tab, desired\)[\s\S]*?snapshot\.statusKnown && snapshot\.mode === desired[\s\S]*?makeHttpError\(409,[\s\S]*?did not confirm/, "server should require bounded exact-mode confirmation");
35
- assert.match(server, /async function setCodexFastMode[\s\S]*?codexSpeedModeFromIntent\(body\)[\s\S]*?feature\.busy[\s\S]*?desired === "ultrafast" && !feature\.ultrafastModelEligible[\s\S]*?type: "prompt", message: `\/\$\{feature\.commandName\} \$\{argument\}`[\s\S]*?waitForCodexFastModeStatus\(tab, desired\)/, "PUT should validate intent, reject busy or ineligible tabs, invoke the extension, and require exact confirmed state");
36
- assert.doesNotMatch(server, /codexFastModeSnapshot\(tab, \{ enabled: desired/, "server must not infer effective Fast state from RPC success");
33
+ assert.match(codexSpeed, /CODEX_FAST_MODE_STATUS_KEY = "codex-fast-mode"[\s\S]*?CODEX_FAST_MODE_COMMAND_NAME = "fast-mode"/, "server should use the extension-owned status and command contracts");
34
+ assert.match(codexSpeed, /function codexFastModeStatusState\(statusText\)[\s\S]*?codexSpeedModeFromStatus\(stripAnsi\(statusText\)\)/, "server should use the tested exact status parser");
35
+ assert.match(codexSpeed, /function codexFastModeSnapshot\(tab, patch = \{\}\)[\s\S]*?extensionStatusMap\(tab\)\.get\(CODEX_FAST_MODE_STATUS_KEY\)/, "server snapshots should come from remembered extension status");
36
+ assert.match(codexSpeed, /async function codexFastModeFeatureData[\s\S]*?codexFastModeSnapshot\(tab\)[\s\S]*?tabHasActiveOutput\(tab\)[\s\S]*?ultrafastModelEligible:[\s\S]*?CODEX_FAST_MODE_CREDIT_NOTICE/, "GET state should be tab-scoped, extension-owned, busy-aware, model-gated, and disclose credit use");
37
+ assert.match(codexSpeed, /async function waitForCodexFastModeStatus\(tab, desired\)[\s\S]*?snapshot\.statusKnown && snapshot\.mode === desired[\s\S]*?makeHttpError\(409,[\s\S]*?did not confirm/, "server should require bounded exact-mode confirmation");
38
+ assert.match(codexSpeed, /async function setCodexFastMode[\s\S]*?codexSpeedModeFromIntent\(body\)[\s\S]*?feature\.busy[\s\S]*?desired === "ultrafast" && !feature\.ultrafastModelEligible[\s\S]*?type: "prompt", message: `\/\$\{feature\.commandName\} \$\{argument\}`[\s\S]*?waitForCodexFastModeStatus\(tab, desired\)/, "PUT should validate intent, reject busy or ineligible tabs, invoke the extension, and require exact confirmed state");
39
+ assert.doesNotMatch(codexSpeed, /codexFastModeSnapshot\(tab, \{ enabled: desired/, "server must not infer effective Fast state from RPC success");
37
40
  assert.match(server, /url\.pathname === "\/api\/codex-fast-mode" && req\.method === "GET"[\s\S]*?url\.pathname === "\/api\/codex-fast-mode" && req\.method === "PUT"/, "server should expose GET and PUT routes");
38
41
 
39
42
  assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>[\s\S]*?<option value="compact-v1">Compact<\/option>/, "legacy output processing should be presented as Compact mode while retaining compact-v1");
40
43
  assert.doesNotMatch(html, /<label for="fastOutputModeSelect">Fast mode/, "legacy output processing should no longer be presented as Fast mode");
41
44
  assert.match(html, /data-side-panel-section="codex-usage"[\s\S]*?id="codexUsageBox"[\s\S]*?class="control-field codex-fast-mode-control"[\s\S]*?class="codex-fast-mode-row"[\s\S]*?id="codexFastModeLabel"[\s\S]*?id="codexFastModeSelect"[\s\S]*?<option value="normal">Normal<\/option>[\s\S]*?<option value="fast">Fast<\/option>[\s\S]*?<option value="ultrafast" disabled>Ultrafast<\/option>[\s\S]*?id="setCodexFastModeButton"[\s\S]*?id="codexFastModeStatus"/, "Codex Usage should render before the compact session Fast-mode row");
42
45
  assert.match(styles, /\.codex-fast-mode-control \{[\s\S]*?margin-top: 0\.58rem[\s\S]*?padding: 0\.48rem 0\.55rem[\s\S]*?\.codex-fast-mode-row \{[\s\S]*?grid-template-columns: minmax\(0, 1fr\) minmax\(6\.5rem, 8rem\) auto/, "Codex Fast mode should use a compact horizontal control surface");
43
- assert.match(app, /function codexFastModeStatusText\(\)[\s\S]*?codexSpeedModeLabel\(codexFastModeState\.mode\)[\s\S]*?return `\$\{label\} · This tab`;/, "mode status should distinguish all three preferences concisely");
46
+ assert.match(app, /function codexFastModeStatusText\(\)[\s\S]*?codexSpeedModeLabel\(codexFastModeState\.mode\)[\s\S]*?return `\$\{label\} · This thread`;/, "mode status should distinguish all three preferences concisely");
44
47
 
45
48
  assert.match(app, /id: "codexFastMode"[\s\S]*?packageName: "@firstpick\/pi-extension-codex-fast-mode"[\s\S]*?capabilityLabel: "\/fast-mode"/, "browser Optional Features should catalog Fast mode");
46
49
  assert.match(app, /OPTIONAL_FEATURE_DISABLE_PREREQUISITES = new Map\([\s\S]*?\["codexFastMode", \(\) => disableCodexFastModeIntegration\(\)\]/, "browser should register disable-off-first behavior");
47
50
  assert.match(app, /if \(disabled\) \{[\s\S]*?OPTIONAL_FEATURE_DISABLE_PREREQUISITES\.get\(feature\.id\)[\s\S]*?await turnOff\(\)[\s\S]*?setOptionalFeatureDisabled\(feature\.id, disabled\)/, "Optional Features Disable should abort before hiding integration if turn-off fails");
48
51
  assert.match(app, /function applyCodexFastModeStatus\(statusText\)[\s\S]*?codexSpeedModeFromStatus\(statusText\)[\s\S]*?if \(mode === null\) return false[\s\S]*?enabled: mode !== "normal"[\s\S]*?statusKnown: true/, "browser should consume only exact extension status values");
49
- assert.match(app, /async function refreshCodexFastMode\(tabContext = activeTabContext\(\)\)[\s\S]*?api\("\/api\/codex-fast-mode", \{ tabId: tabContext\.tabId \}\)[\s\S]*?!featureEnabled && data\.available[\s\S]*?enabled: false[\s\S]*?isCurrentTabContext\(tabContext\)/, "browser status refresh should stay tab-scoped and disarm restored branches while the feature is hidden");
52
+ assert.match(app, /async function refreshCodexFastMode\(tabContext = activeTabContext\(\), \{ readOnly = false \} = \{\}\)[\s\S]*?api\("\/api\/codex-fast-mode", \{ tabId: tabContext\.tabId \}\)[\s\S]*?!readOnly && !featureEnabled && data\.available[\s\S]*?enabled: false[\s\S]*?isCurrentTabContext\(tabContext\)/, "browser status refresh should stay tab-scoped and disarm restored branches while the feature is hidden");
50
53
  assert.match(app, /async function applyCodexFastMode\(\)[\s\S]*?await appConfirm\([\s\S]*?8x Standard included usage[\s\S]*?6x purchased-credit[\s\S]*?if \(!confirmed[\s\S]*?body: \{ mode \}, tabId: tabContext\.tabId/, "browser should confirm Ultrafast costs before applying explicit mode intent");
51
54
  assert.match(app, /async function disableCodexFastModeIntegration\(\)[\s\S]*?tabs\.filter[\s\S]*?Promise\.all\(tabIds\.map[\s\S]*?data\.busy[\s\S]*?enabled: false[\s\S]*?codexFastModeConfirmedOff\(response\.data\)/, "browser-global Disable should preflight every live tab and require each mutation to confirm off");
52
55
  assert.match(app, /refreshNaturalConversationMode\(tabContext\),[\s\S]*?refreshCodexFastMode\(tabContext\),/, "tab refreshes should reload branch-scoped Fast-mode state");
@@ -56,7 +59,9 @@ assert.match(technical, /## Normal and compact output[\s\S]*?select \*\*Compact\
56
59
  assert.match(development, /### Codex subscription Fast mode[\s\S]*?service_tier: "priority"[\s\S]*?service_tier: "ultrafast"[\s\S]*?8× Standard included usage[\s\S]*?6×/, "development guide should document both tiers and cost semantics");
57
60
  assert.match(technical, /Normal \/ Fast \/ Ultrafast[\s\S]*?Pro \$500/, "technical reference should document the third mode and subscription eligibility");
58
61
  // Intent preserved: browser-asset changes must advance the coherent cache tuple.
59
- assert.match(serviceWorker, /pi-webui-pwa-v156[\s\S]*?"\/codex-speed-mode\.mjs"/, "PWA should refresh and cache the shared mode helper");
60
- assert.match(html, /data-app-src="\/app\.js\?v=185"/, "browser module URL should be cache-busted for speed-mode wiring");
62
+ assert.match(serviceWorker, /pi-webui-pwa-v200[\s\S]*?"\/codex-speed-mode\.mjs"/, "PWA should refresh and cache the shared mode helper");
63
+ assert.match(html, /data-app-src="\/app\.js\?v=220"/, "browser module URL should be cache-busted for speed-mode wiring");
64
+
65
+ assert.match(server, /createCodexFastModeService\(\{[\s\S]*packageName: OPTIONAL_FEATURE_PACKAGES\.get\("codexFastMode"\)/, "server must wire the speed adapter to the canonical package catalog");
61
66
 
62
67
  console.log("codex-fast-mode-static.test.mjs passed");
@@ -5,7 +5,7 @@ import * as modes from "../public/codex-speed-mode.mjs";
5
5
 
6
6
  const source = await readFile(new URL("../public/app.js", import.meta.url), "utf8");
7
7
  const start = source.indexOf("// Codex subscription Fast mode is owned");
8
- const end = source.indexOf("function scheduleRefreshCodexUsage", start);
8
+ const end = source.indexOf("const SUBAGENT_LAUNCHER_LABELS", start);
9
9
  assert.ok(start >= 0 && end > start, "execute the actual browser speed-control implementation");
10
10
  const controlSource = source.slice(start, end);
11
11
 
@@ -13,6 +13,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
13
13
  const calls = [];
14
14
  const confirmations = [];
15
15
  const events = [];
16
+ let shellRenders = 0;
16
17
  const ultrafastOption = { disabled: true };
17
18
  const select = { value: "normal", disabled: true, querySelector: () => ultrafastOption };
18
19
  let currentTab = "tab-one";
@@ -36,6 +37,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
36
37
  normalizeSelectedModel: (model) => model,
37
38
  modelStateKey: (model) => `${model?.provider}/${model?.id}`,
38
39
  renderStatus() {},
40
+ scheduleFocusedShellRender() { shellRenders++; },
39
41
  requestGitFooterWebuiPayload() {},
40
42
  queueMicrotask,
41
43
  async appConfirm(options) {
@@ -57,14 +59,14 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
57
59
  context.applyCodexFastModeData(data("normal"));
58
60
  vm.runInContext("codexFastModeLoaded = true", context);
59
61
  context.renderCodexFastModeControl();
60
- return { context, calls, confirmations, events, select, tabModes, ultrafastOption, data, setEligible(value) { eligible = value; } };
62
+ return { context, calls, confirmations, events, get shellRenders() { return shellRenders; }, select, tabModes, ultrafastOption, data, setEligible(value) { eligible = value; } };
61
63
  }
62
64
 
63
65
  {
64
66
  const h = harness();
65
67
  assert.equal(h.context.applyCodexFastModeStatus("ultrafast"), true);
66
68
  assert.equal(h.select.value, "ultrafast");
67
- assert.equal(h.context.codexFastModeStatusText(), "Ultrafast · This tab");
69
+ assert.equal(h.context.codexFastModeStatusText(), "Ultrafast · This thread");
68
70
  assert.equal(h.context.applyCodexFastModeStatus("ultrafast now"), false);
69
71
  assert.equal(h.select.value, "ultrafast");
70
72
  assert.equal(h.context.codexFastModeConfirmedOff({ statusKnown: true, mode: "ultrafast", enabled: false }), false);
@@ -98,6 +100,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
98
100
  h.select.value = "ultrafast";
99
101
  await h.context.applyCodexFastMode();
100
102
  assert.equal(h.calls.length, 0, "changing tabs during cost confirmation must cancel the mutation");
103
+ assert.equal(h.shellRenders, 1, "settling the old confirmation schedules current Settings controls");
101
104
  }
102
105
  {
103
106
  const h = harness({ eligible: false });
@@ -117,18 +117,19 @@ test("the server gives a sanitized combined error when CLI and direct-flow Pi fa
117
117
  });
118
118
 
119
119
  test("the browser labels the usage account and redraws when source changes", async () => {
120
- const source = await readFile(new URL("../public/app.js", import.meta.url), "utf8");
120
+ const source = await readFile(new URL("../public/activity-usage-controller.mjs", import.meta.url), "utf8");
121
121
  const signatureStart = source.indexOf("function codexUsageStructureSignature(");
122
122
  const signatureEnd = source.indexOf("function updateCodexUsageValues(", signatureStart);
123
123
  const renderStart = source.indexOf("function renderCodexUsage(");
124
- const renderEnd = source.indexOf("async function refreshCodexUsage(", renderStart);
124
+ const renderEnd = source.indexOf("function renderClaudeUsageWindow(", renderStart);
125
125
  const nodes = [];
126
126
  let rebuilds = 0;
127
127
  const box = { replaceChildren: () => { nodes.length = 0; rebuilds++; }, classList: { toggle() {} }, append: (...items) => nodes.push(...items) };
128
128
  const context = vm.createContext({
129
129
  latestCodexUsage: { source: "codex-cli", planType: "plus" },
130
130
  codexUsageLoading: false, codexUsageError: null, codexUsageRenderSignature: "",
131
- elements: { codexUsageBox: box },
131
+ nodes: { codexUsageBox: box },
132
+ disposed: false,
132
133
  formatCodexPlanType: (value) => value,
133
134
  codexUsageBuckets: () => [],
134
135
  updateCodexUsageValues: () => true,
@@ -14,8 +14,8 @@ const [server, state, launcher, runner, trust] = await Promise.all([
14
14
  assert.match(state, /validateUpdatePlanRequest[\s\S]*targets must contain exactly one value/);
15
15
  assert.match(state, /validateUpdateApplyRequest[\s\S]*Apply accepts only transactionId and planDigest/);
16
16
  assert.match(server, /url\.pathname === "\/api\/update\/plan"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdatePlanRequest[\s\S]*sendJson\(res, 201/);
17
- assert.match(server, /url\.pathname === "\/api\/update\/apply"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdateApplyRequest[\s\S]*applyNativeServerPlan/);
18
- assert.match(server, /createNativeServerPlan\(validation\.targets\)/);
17
+ assert.match(server, /url\.pathname === "\/api\/update\/apply"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdateApplyRequest[\s\S]*packageUpdates\.apply/);
18
+ assert.match(server, /packageUpdates\.plan\(validation\.targets\[0\]\)/);
19
19
  assert.match(server, /validateNativePlan\(job\.plan, digest\)/);
20
20
  assert.match(server, /url\.pathname === "\/api\/restart"[\s\S]*requireLocalhostRoute[\s\S]*assertNativeMutationAdmission\(\)/,
21
21
  "ordinary server restarts must not race a native update fence");
@@ -57,8 +57,8 @@ assert.match(app, /function initializeComposerActionOrdering\(\)[\s\S]*MutationO
57
57
  assert.match(app, /event\.key === COMPOSER_ACTION_ORDER_STORAGE_KEY\) restoreComposerActionOrder\(\)[\s\S]*event\.key === COMPOSER_ACTION_LAYOUT_STORAGE_KEY\) restoreComposerActionSlotLayout\(\)/, "other tabs should apply persisted composer order and sparse-layout changes");
58
58
  assert.match(app, /initializeComposerActionOrdering\(\);[\s\S]*restoreSidePanelSectionOrder\(\);/, "composer ordering should initialize during guarded app startup");
59
59
 
60
- assert.match(html, /styles\.css\?v=154/, "changed composer styles should advance the stylesheet revision");
61
- assert.match(html, /app\.js\?v=185/, "changed composer behavior should advance the app revision");
62
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156"/, "changed browser assets should advance the PWA cache identity");
60
+ assert.match(html, /styles\.css\?v=167/, "changed composer styles should advance the stylesheet revision");
61
+ assert.match(html, /app\.js\?v=220/, "changed composer behavior should advance the app revision");
62
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "changed browser assets should advance the PWA cache identity");
63
63
 
64
64
  console.log("composer-action-grid-reorder-static.test.mjs passed");
@@ -10,6 +10,9 @@ const [html, css, app, development] = await Promise.all([
10
10
  readFile(join(root, "public/app.js"), "utf8"),
11
11
  readFile(join(root, "DEVELOPMENT.md"), "utf8"),
12
12
  ]);
13
+ assert.match(app, /const COMPONENT_UPDATE_TARGETS = \["all", "pi", "webui"\]/);
14
+ assert.match(app, /createSidebarUpdateMenu\(\{ button: elements\.sidebarUpdateButton, onSelect: startComponentUpdate \}\)/);
15
+ assert.match(html, /id="sidebarUpdateButton"[^>]*aria-label="Updates"/);
13
16
  for (const target of ["pi", "webui"]) {
14
17
  assert.match(app, new RegExp(`startComponentUpdate\\("${target}"\\)`));
15
18
  assert.match(html, new RegExp(`id="${target}ComponentUpdateStatus"[^>]*aria-live="polite"`));
@@ -20,14 +23,16 @@ assert.doesNotMatch(html, /update-all|Update all|Pi \+ Web UI update/);
20
23
  assert.doesNotMatch(app, /runPiUpdateAndRestart|managed Web UI activation|side-by-side managed runtime/);
21
24
  assert.match(app, /body: \{ targets: \[target\] \}/);
22
25
  assert.match(app, /body: \{ transactionId: plan.transactionId, planDigest: plan.digest \}/);
23
- assert.match(app, /componentUpdateConfirmationText\(plan\)[\s\S]*installedRoot[\s\S]*effectRoot[\s\S]*command\.command[\s\S]*command\.args[\s\S]*context\.cwd[\s\S]*context\.agentDir[\s\S]*context\.npmPrefix[\s\S]*plan\.refusals[\s\S]*plan\.warning[\s\S]*plan\.digest/);
26
+ const startUpdate = app.slice(app.indexOf("async function startComponentUpdate(target)"), app.indexOf("async function openWebuiPackageDialog()"));
27
+ assert.doesNotMatch(startUpdate, /appConfirm|window\.confirm/);
28
+ assert.match(startUpdate, /plan\?\.requested !== target[\s\S]*!plan\.transactionId[\s\S]*!plan\.digest[\s\S]*!Array\.isArray\(plan\.targets\)/);
24
29
  assert.match(app, /nativeJobs[\s\S]*nativeJobDiscoveryError/);
25
- assert.match(app, /plan\.pathPi\?\.eligible[\s\S]*plan\.pathPi\.version[\s\S]*plan\.pathPi\.packageRoot[\s\S]*plan\.pathPi\.executable[\s\S]*plan\.pathPi\.cli/);
30
+ assert.match(app, /sidebarUpdateError = "Update preview is incomplete; no command was launched\."/);
26
31
  assert.match(app, /uncertainApplyJobs\[target\] = plan\.transactionId[\s\S]*phase: "launching"/);
27
32
  assert.match(app, /if \(latestUpdateStatus\?\.nativeJobs && !latestUpdateStatus\.nativeJobDiscoveryError\) nativeJobPollError = ""/);
28
33
  assert.match(app, /api\/update\/transactions\/\$\{encodeURIComponent\(job\.transactionId\)\}/);
29
- assert.match(app, /case "unknown"[\s\S]*Do not retry or restart/);
30
- assert.match(app, /case "partial"[\s\S]*Verified healthy active changes may have restarted/);
34
+ assert.match(app, /case "unknown"[\s\S]*Check the command output/);
35
+ assert.match(app, /case "partial"[\s\S]*Some commands failed/);
31
36
  assert.match(css, /\.component-update-status\[data-update-running\]::before[\s\S]*component-update-spin/);
32
37
  assert.match(development, /Native Pi and Web UI updates[\s\S]*GET \/api\/update\/transactions\/.*[\s\S]*Native lifecycle scripts are not sandboxed/);
33
38
  console.log("control deck component update static tests passed");
@@ -348,10 +348,10 @@ assert.match(
348
348
 
349
349
  assert.match(
350
350
  serviceWorker,
351
- /const CACHE_NAME = "pi-webui-pwa-v156";/,
351
+ /const CACHE_NAME = "pi-webui-pwa-v200";/,
352
352
  "browser asset changes should advance the PWA cache identity",
353
353
  );
354
- assert.match(html, /styles\.css\?v=154/, "visibility styles should advance the stylesheet query revision");
355
- assert.match(html, /data-app-src="\/app\.js\?v=185"/, "visibility behavior should advance the app query revision");
354
+ assert.match(html, /styles\.css\?v=167/, "visibility styles should advance the stylesheet query revision");
355
+ assert.match(html, /data-app-src="\/app\.js\?v=220"/, "visibility behavior should advance the app query revision");
356
356
 
357
357
  console.log("control-visibility-static.test.mjs passed");
@@ -9,14 +9,14 @@ const css = readFileSync(join(root, "public/styles.css"), "utf8");
9
9
  const app = readFileSync(join(root, "public/app.js"), "utf8");
10
10
  const serviceWorker = readFileSync(join(root, "public/service-worker.js"), "utf8");
11
11
 
12
- assert.equal((html.match(/class="control-row(?:\s[^"]*)?"/g) || []).length, 14, "Controls should render one two-column row per setting, including optional remote-access settings");
12
+ assert.equal((html.match(/class="control-row(?:\s[^"]*)?"/g) || []).length, 16, "Controls should render one two-column row per setting, including optional remote-access settings");
13
13
  assert.match(css, /\.control-row \{[\s\S]*grid-template-columns:\s*minmax\(6\.2rem, 0\.44fr\) minmax\(0, 1fr\)/, "Controls settings should use stable name and parameter columns");
14
- assert.equal((html.match(/class="control-row-label"[^>]*data-tooltip=/g) || []).length, 14, "Every Controls setting name should provide user-friendly help");
14
+ assert.equal((html.match(/class="control-row-label"[^>]*data-tooltip=/g) || []).length, 16, "Every Controls setting name should provide user-friendly help");
15
15
  assert.match(app, /function initializeControlSettingTooltips\(\)[\s\S]*#sidePanelSectionControls \.control-row-label\[data-tooltip\][\s\S]*bindStyledTooltipEvents\(label\)[\s\S]*showFooterTooltip\(label\)/, "Controls help should use the viewport-safe floating tooltip for hover and keyboard access");
16
16
  assert.match(html, /class="control-row remote-auth-control-row" hidden[\s\S]*id="remoteAuthToggle"/, "optional PIN protection should retain its guarded visibility");
17
17
  assert.match(app, /remoteAuthToggle\?\.closest\("\.remote-auth-control-row"\)[\s\S]*remoteAuthRow\.hidden = false/, "loading remote status should reveal the optional PIN protection setting");
18
- assert.match(html, /styles\.css\?v=154/, "Controls stylesheet changes should advance the cache query");
19
- assert.match(html, /app\.js\?v=185/, "Controls tooltip wiring should advance the app cache query");
20
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156"/, "Controls browser assets should advance the PWA cache identity");
18
+ assert.match(html, /styles\.css\?v=167/, "Controls stylesheet changes should advance the cache query");
19
+ assert.match(html, /app\.js\?v=220/, "Controls tooltip wiring should advance the app cache query");
20
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "Controls browser assets should advance the PWA cache identity");
21
21
 
22
22
  console.log("controls-layout-static.test.mjs passed");
@@ -0,0 +1,100 @@
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
+ import { checkActionTarget } from '../public/shell-actions.mjs';
6
+
7
+ const source = readFileSync(new URL('../public/app.js', import.meta.url), 'utf8');
8
+ const functions = ['threadDisplayTitle', 'focusedOverviewSnapshot', 'invokeOverviewAction'].map(name => {
9
+ const start = source.indexOf(`function ${name}(`);
10
+ assert.ok(start >= 0);
11
+ return source.slice(start, source.indexOf('\n}', start) + 2);
12
+ }).join('\n');
13
+
14
+ function fixture() {
15
+ const context = vm.createContext({ checkActionTarget });
16
+ vm.runInContext(`
17
+ let shellPreferenceState = {value:{overviewOpen:true}};
18
+ let enabled = true, dataReads = 0, focusedShellState = {destination:'conversation'};
19
+ let tab = {id:'tab-a',title:'A',cwd:'/a',gitWorkspace:{branch:'feature'}};
20
+ let target = {tabId:'tab-a',generation:1,sessionIdentity:'session-a',cwd:'/a'};
21
+ let payload = null, currentState = {pendingMessageCount:2}, runner = null;
22
+ let agentState = {data:null}, usageContext = null, events = [], invoked = [];
23
+ const activeTab = () => tab;
24
+ const shellActionTarget = () => ({...target});
25
+ const isFocusedShellRequested = () => enabled;
26
+ const parseGitFooterWebuiPayload = () => {dataReads++; return payload;};
27
+ const normalizeGitWorkspaceInfo = value => value;
28
+ const tabAppRunnerRun = () => runner;
29
+ const activityAgents = {getSnapshot:() => agentState};
30
+ const subagentOverviewGroups = data => data.groups;
31
+ const contextUsageSnapshot = () => usageContext;
32
+ const contextUsageDisplay = value => value ? '25% of 200k' : 'Context unknown';
33
+ const contextUsageDetail = () => 'Current session context';
34
+ const cleanStatusText = value => String(value || '');
35
+ const tabIndicator = () => ({label:'Working'});
36
+ const focusedToolsActions = () => ['files','git','runners','subagents','queue','session','codex-usage','claude-usage'].map(id => ({id:'view:'+id,scope:'browser',available:true}));
37
+ const addEvent = (message,level) => events.push({message,level});
38
+ const invokeFocusedTool = action => invoked.push(action);
39
+ ${functions}
40
+ `, context);
41
+ return code => vm.runInContext(code, context);
42
+ }
43
+
44
+ test('closed and noncompact overview read no feature data', () => {
45
+ const run = fixture();
46
+ run('shellPreferenceState.value.overviewOpen=false');
47
+ assert.equal(run('focusedOverviewSnapshot().open'), false);
48
+ run('shellPreferenceState.value.overviewOpen=true; enabled=false');
49
+ assert.equal(run('focusedOverviewSnapshot().open'), false);
50
+ assert.equal(run('dataReads'), 0);
51
+ });
52
+
53
+ test('overview distinguishes unknown data and scopes agent counts to the selected session', () => {
54
+ const run = fixture();
55
+ assert.equal(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value"), 'Not loaded');
56
+ assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-unknown').value"), 'Not loaded');
57
+ run("agentState.data={groups:[{groupKind:'tab',tabId:'tab-a',runningAgents:1,agentCount:3},{groupKind:'tab',tabId:'tab-b',runningAgents:9,agentCount:20}]}");
58
+ assert.equal(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value"), '1 running · 3 total');
59
+ run("payload={meta:[{key:'git',value:'main'},{key:'changes',value:'+3 -1'}],providerUsage:{provider:'anthropic',capturedAt:1700000000000,secondary:{label:'Weekly',usedPercent:42}}}; usageContext={percent:25}");
60
+ assert.equal(run("focusedOverviewSnapshot().sections[0].items.find(row=>row.id==='branch').value"), 'main');
61
+ assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-secondary').progress"), 42);
62
+ assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-secondary').actionId"), 'view:claude-usage');
63
+ });
64
+
65
+ for (const mutation of ["target.tabId='tab-b'", "target.generation=2", "target.sessionIdentity='replacement'", "target.cwd='/b'"]) {
66
+ test(`overview rejects a stale action after ${mutation}`, () => {
67
+ const run = fixture();
68
+ run('const captured=focusedOverviewSnapshot().target');
69
+ run(mutation);
70
+ run("invokeOverviewAction('view:git',captured)");
71
+ assert.equal(run('invoked.length'), 0);
72
+ assert.equal(run('events.length'), 1);
73
+ });
74
+ }
75
+
76
+ test('current overview actions use the canonical catalog; no-session actions are unavailable', () => {
77
+ const run = fixture();
78
+ run("invokeOverviewAction('view:queue',focusedOverviewSnapshot().target)");
79
+ assert.equal(run('invoked[0].id'), 'view:queue');
80
+ run("invokeOverviewAction('made-up',focusedOverviewSnapshot().target)");
81
+ assert.equal(run('invoked.length'), 1);
82
+ run("tab=null;target={tabId:null,generation:2,sessionIdentity:'',cwd:''}");
83
+ assert.equal(run('focusedOverviewSnapshot().sections.flatMap(section=>section.items).filter(row=>row.actionId).every(row=>row.disabled)'), true);
84
+ });
85
+
86
+
87
+ test('overview separates external agents, capability absence and stale observations', () => {
88
+ const run = fixture();
89
+ const value = () => run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value");
90
+ run("agentState.data={tabs:[{tabId:'tab-a',available:true},{tabId:'tab-b',available:false}],groups:[{groupKind:'external',tabId:'tab-a',runningAgents:4,agentCount:4}]}");
91
+ assert.equal(value(), '0 running · 0 total');
92
+ run("tab={id:'tab-b'}");
93
+ assert.equal(value(), 'Reporting unavailable');
94
+ run("tab={id:'unknown'}");
95
+ assert.equal(value(), 'Not loaded');
96
+ run("tab={id:'tab-b'};agentState.data.groups.push({groupKind:'tab',tabId:'tab-b',runningAgents:1,agentCount:2})");
97
+ assert.equal(value(), '1 running · 2 total');
98
+ run("agentState.error='offline'");
99
+ assert.match(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').detail"), /previous snapshot/);
100
+ });
@@ -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 artifactOwner = await readFile(new URL("../public/project-artifact-controller.mjs", import.meta.url), "utf8");
6
7
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
8
  const [server, app, styles] = await Promise.all([
8
9
  readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
@@ -12,7 +13,7 @@ const [server, app, styles] = await Promise.all([
12
13
 
13
14
  for (const contract of ["pi.artifact/v1", "registerDocumentArtifact", "rewriteArtifactsForTab", "documentArtifactRecord", "sendDocumentArtifactFile", "/api/artifacts/"]) assert.ok(server.includes(contract), `server should contain ${contract}`);
14
15
  for (const privateField of ["manifestPath", "downloadPath", "outputPath", "sourcePath", "stagedPath", "pdfPath", "workspace", "recoveryPath"]) assert.match(server, new RegExp(`PRIVATE_ARTIFACT_KEYS[^;]+[\\s\\S]*?${privateField}`), `artifact sanitizer should cover ${privateField}`);
15
- for (const feature of ["openDocumentArtifact", "appendDocumentArtifact", "Send page to composer", "Previous", "Rotate", "Semantic structure, revisions, warnings, and diff"]) assert.ok(app.includes(feature), `browser viewer should contain ${feature}`);
16
+ for (const feature of ["openDocumentArtifact", "appendDocumentArtifact", "Send page to composer", "Previous", "Rotate", "Semantic structure, revisions, warnings, and diff"]) assert.ok((app + artifactOwner).includes(feature), `browser viewer should contain ${feature}`);
16
17
  for (const selector of [".document-artifact-dialog", ".document-artifact-sidebar", ".document-artifact-page", "@media (max-width: 720px)"]) assert.ok(styles.includes(selector), `viewer stylesheet should contain ${selector}`);
17
18
  assert.equal(/details\.artifact\s*=/.test(server), false, "server should replace details immutably rather than mutating raw RPC artifacts");
18
19
  console.log("document-artifact-static.test.mjs passed");
@@ -0,0 +1,205 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { createDraftConversations, DRAFT_STORAGE_KEY, DRAFT_LIMITS } from "../public/draft-conversations.mjs";
4
+
5
+ function fixture(initial = null) {
6
+ let raw = initial;
7
+ let blocked = false;
8
+ let serial = 0;
9
+ const storage = {
10
+ getItem: () => raw,
11
+ setItem(key, value) {
12
+ assert.equal(key, DRAFT_STORAGE_KEY);
13
+ if (blocked) throw new Error("Storage denied");
14
+ raw = value;
15
+ },
16
+ };
17
+ const options = { storage: () => storage, randomId: () => `test-${++serial}`, now: () => 100 };
18
+ return { store: createDraftConversations(options), reload: () => createDraftConversations(options), raw: () => raw, block: value => { blocked = value; } };
19
+ }
20
+
21
+ test("blank identities stay separate and only meaningful saved text enters the roster", () => {
22
+ const { store, reload } = fixture();
23
+ const first = store.create();
24
+ store.edit(first, " \n\t");
25
+ store.save(first);
26
+ assert.deepEqual(store.list(), []);
27
+ const second = store.create();
28
+ assert.notEqual(first, second);
29
+ store.edit(second, " Exact text\nwith λ ");
30
+ store.save(second);
31
+ assert.deepEqual(store.list().map(record => record.text), [" Exact text\nwith λ "]);
32
+ const restored = reload();
33
+ assert.equal(restored.activeId, second);
34
+ assert.equal(restored.get(second).text, " Exact text\nwith λ ");
35
+ assert.equal(restored.get(first), null);
36
+ });
37
+
38
+ test("revisions detect edits back to original and returned records cannot mutate ownership", () => {
39
+ const { store } = fixture();
40
+ const id = store.create();
41
+ store.edit(id, "original");
42
+ const captured = store.get(id);
43
+ store.edit(id, "edit");
44
+ store.edit(id, "original");
45
+ assert.ok(store.get(id).revision > captured.revision);
46
+ captured.text = "external";
47
+ assert.equal(store.get(id).text, "original");
48
+ assert.equal(store.select("server-tab"), false);
49
+ assert.equal(store.edit("server-tab", "invalid"), false);
50
+ });
51
+
52
+ test("saved draft edits persist, close discards only one identity, blank selection survives reload", () => {
53
+ const { store, reload } = fixture();
54
+ const first = store.create();
55
+ store.edit(first, "first");
56
+ store.save(first);
57
+ const second = store.create();
58
+ store.edit(second, "second");
59
+ store.save(second);
60
+ store.select(first);
61
+ store.edit(first, "updated");
62
+ assert.equal(reload().get(first).text, "updated");
63
+ store.remove(first);
64
+ assert.deepEqual(reload().list().map(record => record.id), [second]);
65
+ store.select(store.create());
66
+ assert.ok(reload().activeId);
67
+ store.select(null);
68
+ assert.equal(reload().activeId, null);
69
+ });
70
+
71
+ test("denied writes retain all edits in memory and expose failure until recovery", () => {
72
+ const f = fixture();
73
+ const id = f.store.create();
74
+ f.store.edit(id, "saved");
75
+ f.store.save(id);
76
+ const previous = f.raw();
77
+ f.block(true);
78
+ f.store.edit(id, "newer memory edit");
79
+ assert.match(f.store.error, /could not be saved.*Storage denied/);
80
+ assert.equal(f.store.get(id).text, "newer memory edit");
81
+ assert.equal(f.raw(), previous);
82
+ f.block(false);
83
+ assert.equal(f.store.persist(), true);
84
+ assert.equal(f.reload().get(id).text, "newer memory edit");
85
+ assert.equal(f.store.error, "");
86
+ });
87
+
88
+ test("denied reads retain new memory drafts and report storage failure", () => {
89
+ const store = createDraftConversations({ storage: () => { throw new Error("Storage disabled"); }, randomId: () => "new" });
90
+ const id = store.create();
91
+ store.edit(id, "memory");
92
+ assert.equal(store.save(id), false);
93
+ assert.equal(store.get(id).text, "memory");
94
+ assert.match(store.error, /could not be loaded.*Storage disabled/);
95
+ });
96
+
97
+ for (const raw of ["{broken", JSON.stringify({ version: 2, records: [], activeId: null }), JSON.stringify({ version: 1, records: [{ id: "backend-tab", text: "hello" }], activeId: null })]) {
98
+ test(`unreadable data remains untouched: ${raw.slice(0, 30)}`, () => {
99
+ const f = fixture(raw);
100
+ assert.match(f.store.error, /could not be loaded/);
101
+ const id = f.store.create();
102
+ f.store.edit(id, "new draft");
103
+ f.store.save(id);
104
+ assert.equal(f.raw(), raw);
105
+ assert.equal(f.store.get(id).text, "new draft");
106
+ });
107
+ }
108
+
109
+ test("oversized edits stay in memory without truncation or replacing stored drafts", () => {
110
+ const f = fixture();
111
+ const id = f.store.create();
112
+ f.store.edit(id, "stored");
113
+ f.store.save(id);
114
+ const previous = f.raw();
115
+ const oversized = "x".repeat(DRAFT_LIMITS.text + 1);
116
+ f.store.edit(id, oversized);
117
+ assert.equal(f.store.get(id).text, oversized);
118
+ assert.equal(f.raw(), previous);
119
+ assert.match(f.store.error, /storage limit/);
120
+ });
121
+
122
+ test("record count and total size limits preserve the last stored value and all in-memory drafts", () => {
123
+ const f = fixture();
124
+ for (let index = 0; index < DRAFT_LIMITS.records; index += 1) {
125
+ const id = f.store.create();
126
+ f.store.edit(id, `Draft ${index}`);
127
+ assert.equal(f.store.save(id), true);
128
+ }
129
+ const previous = f.raw();
130
+ const extra = f.store.create();
131
+ f.store.edit(extra, "One more draft");
132
+ assert.equal(f.store.save(extra), false);
133
+ assert.equal(f.raw(), previous);
134
+ assert.equal(f.store.list().length, DRAFT_LIMITS.records + 1);
135
+ f.store.remove(extra);
136
+ for (const record of f.store.list().slice(0, 11)) f.store.edit(record.id, "x".repeat(DRAFT_LIMITS.text));
137
+ assert.match(f.store.error, /storage limit/);
138
+ assert.equal(f.store.list().filter(record => record.text.length === DRAFT_LIMITS.text).length, 11);
139
+ });
140
+
141
+ test("invalid revisions, duplicate identities and invalid selections preserve unreadable storage", () => {
142
+ const record = { id: "draft:example", text: "saved", revision: 1, updatedAt: 100 };
143
+ for (const value of [
144
+ { version: 1, activeId: null, records: [record, record] },
145
+ { version: 1, activeId: "draft:missing", records: [record] },
146
+ { version: 1, activeId: null, records: [{ ...record, revision: -1 }] },
147
+ { version: 1, activeId: null, records: [{ ...record, updatedAt: 1.5 }] },
148
+ { version: 1, activeId: null, records: [{ ...record, text: "" }] },
149
+ { version: 1, activeId: null, records: Array.from({ length: DRAFT_LIMITS.records + 1 }, (_, index) => ({ ...record, id: `draft:${index}` })) },
150
+ ]) {
151
+ const raw = JSON.stringify(value);
152
+ const f = fixture(raw);
153
+ assert.match(f.store.error, /could not be loaded/);
154
+ assert.equal(f.store.persist(), false);
155
+ assert.equal(f.raw(), raw);
156
+ }
157
+ });
158
+
159
+ test("optional workspace survives saved draft navigation and version-1 reload without saving blanks", () => {
160
+ const f = fixture();
161
+ const blank = f.store.create();
162
+ assert.equal(f.store.setCwd(blank, "/tmp/blank workspace"), true);
163
+ assert.equal(f.store.save(blank), true);
164
+ assert.deepEqual(f.store.list(), []);
165
+ assert.deepEqual(JSON.parse(f.raw()).records, []);
166
+ f.store.edit(blank, "Text with a workspace");
167
+ f.store.save(blank);
168
+ const revision = f.store.get(blank).revision;
169
+ f.store.setCwd(blank, "/tmp/updated workspace");
170
+ assert.ok(f.store.get(blank).revision > revision);
171
+ f.store.select(f.store.create());
172
+ const restored = f.reload();
173
+ restored.select(blank);
174
+ assert.equal(restored.get(blank).text, "Text with a workspace");
175
+ assert.equal(restored.get(blank).cwd, "/tmp/updated workspace");
176
+ const copy = restored.get(blank);
177
+ copy.cwd = "/external";
178
+ assert.equal(restored.get(blank).cwd, "/tmp/updated workspace");
179
+ const beforeClear = restored.get(blank).revision;
180
+ assert.equal(restored.setCwd(blank, ""), true);
181
+ assert.equal(restored.get(blank).cwd, undefined, "clearing removes the folder so the draft starts a No Project thread");
182
+ assert.equal(Object.hasOwn(restored.get(blank), "cwd"), false);
183
+ assert.equal(restored.get(blank).revision, beforeClear + 1);
184
+ restored.setCwd(blank, "");
185
+ assert.equal(restored.get(blank).revision, beforeClear + 1, "clearing an unset folder is not an edit");
186
+ assert.equal(f.reload().get(blank).cwd, undefined);
187
+ assert.equal(Object.hasOwn(JSON.parse(f.raw()).records.find(record => record.id === blank), "cwd"), false);
188
+ assert.equal(restored.setCwd("draft:missing", "/tmp/valid"), false);
189
+ });
190
+
191
+ test("old version-1 drafts remain readable and invalid workspace metadata never replaces storage", () => {
192
+ const record = { id: "draft:legacy", text: "Legacy text", revision: 1, updatedAt: 100 };
193
+ const legacy = fixture(JSON.stringify({ version: 1, records: [record], activeId: record.id }));
194
+ assert.equal(legacy.store.error, "");
195
+ assert.equal(legacy.store.get(record.id).cwd, undefined);
196
+ for (const cwd of [null, 123, "x".repeat(DRAFT_LIMITS.cwd + 1), "/tmp/\u0000bad"]) {
197
+ const raw = JSON.stringify({ version: 1, records: [{ ...record, cwd }], activeId: record.id });
198
+ const f = fixture(raw);
199
+ assert.match(f.store.error, /could not be loaded/);
200
+ assert.equal(f.store.persist(), false);
201
+ assert.equal(f.raw(), raw);
202
+ assert.throws(() => legacy.store.setCwd(record.id, cwd), /invalid or too long/);
203
+ assert.equal(legacy.store.get(record.id).cwd, undefined);
204
+ }
205
+ });