@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
@@ -4,6 +4,8 @@ import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import vm from "node:vm";
6
6
 
7
+ const fileService = await readFile(new URL("../lib/server/workspace-files.mjs", import.meta.url), "utf8");
8
+ const fileOwner = await readFile(new URL("../public/project-file-viewer-controller.mjs", import.meta.url), "utf8");
7
9
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
10
  const [app, css, html, server, readme, technical, development, serviceWorker] = await Promise.all([
9
11
  readFile(join(root, "public", "app.js"), "utf8"),
@@ -23,9 +25,11 @@ function sourceBetween(source, startMarker, endMarker, label) {
23
25
  return source.slice(start, end);
24
26
  }
25
27
 
28
+ assert.match(server, /createWorkspaceFilesService\(\{/, "the server should bind the Files owner");
29
+
26
30
  const imageHelpers = sourceBetween(app, "const FILE_VIEWER_IMAGE_MIME_TYPES", "\n// Changes mode only exists", "image data helper");
27
- const modeSource = sourceBetween(app, "function resolveFileViewerMode(", "\nfunction setFileViewerMode(", "image-aware mode resolver");
28
- const openSource = sourceBetween(app, "async function openFileInViewer(", "\nasync function openAurReviewReportInViewer(", "file open flow");
31
+ const modeSource = sourceBetween(fileOwner, "export function resolveFileViewerMode(", "\n/**", "image-aware mode resolver").replace("export ", "");
32
+ const openSource = sourceBetween(fileOwner, " async function open(", "\n async function openReport(", "file open flow");
29
33
  const uiSource = sourceBetween(app, "function updateFileViewerUi(", "\nconst FILE_VIEWER_SEARCH_MATCH_LIMIT", "file viewer UI renderer");
30
34
 
31
35
  const helperResults = JSON.parse(vm.runInNewContext(`${imageHelpers}\nJSON.stringify([
@@ -43,18 +47,18 @@ const modes = JSON.parse(vm.runInNewContext(`${modeSource}\nJSON.stringify([
43
47
  ])`));
44
48
  assert.deepEqual(modes, ["image", "image", "changes", "preview"], "supported images should default back to Image mode while preserving Git Changes mode");
45
49
 
46
- assert.match(server, /const FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION = Object\.freeze\(\{[\s\S]*"\.png": "image\/png"[\s\S]*"\.jpe?g": "image\/jpeg"[\s\S]*"\.gif": "image\/gif"[\s\S]*"\.webp": "image\/webp"[\s\S]*"\.avif": "image\/avif"/, "the server should use an explicit raster extension allowlist");
47
- assert.doesNotMatch(server, /"\.svg": "image\/svg\+xml"/, "active SVG documents should remain outside image-viewer scope");
48
- assert.match(server, /if \(imageMimeType\) \{\s*return \{ \.\.\.shared, kind: "image", mimeType: imageMimeType, data: buffer\.toString\("base64"\) \};\s*\}/, "the bounded content endpoint should return image bytes without UTF-8 reinterpretation");
49
- assert.match(server, /resolved\.info\.size > FILE_VIEWER_MAX_BYTES[\s\S]*const buffer = await readFile\(resolved\.targetPath\);[\s\S]*const imageMimeType = fileViewerImageMimeType/, "image reads should stay behind the existing workspace file size limit");
50
+ assert.match(fileService, /const FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION = Object\.freeze\(\{[\s\S]*"\.png": "image\/png"[\s\S]*"\.jpe?g": "image\/jpeg"[\s\S]*"\.gif": "image\/gif"[\s\S]*"\.webp": "image\/webp"[\s\S]*"\.avif": "image\/avif"/, "the server should use an explicit raster extension allowlist");
51
+ assert.doesNotMatch(fileService, /"\.svg": "image\/svg\+xml"/, "active SVG documents should remain outside image-viewer scope");
52
+ assert.match(fileService, /if \(imageMimeType\) \{\s*return \{ \.\.\.shared, kind: "image", mimeType: imageMimeType, data: buffer\.toString\("base64"\) \};\s*\}/, "the bounded content endpoint should return image bytes without UTF-8 reinterpretation");
53
+ assert.match(fileService, /resolved\.info\.size > FILE_VIEWER_MAX_BYTES[\s\S]*const buffer = await readFile\(resolved\.targetPath\);[\s\S]*const imageMimeType = fileViewerImageMimeType/, "image reads should stay behind the existing workspace file size limit");
50
54
 
51
55
  assert.match(html, /id="fileViewerImage"[^>]*role="group"[^>]*aria-label="Image preview"[^>]*hidden>[\s\S]*<img id="fileViewerImageElement" alt="" \/>/, "the viewer should expose a labelled, initially hidden image surface");
52
56
  assert.match(app, /fileViewerImage: \$\("#fileViewerImage"\)[\s\S]*fileViewerImageElement: \$\("#fileViewerImageElement"\)/, "the image surface should be registered in the frontend element map");
53
- assert.match(openSource, /const kind = data\.kind === "image" \? "image" : "text";[\s\S]*const imageUrl = kind === "image" \? fileViewerImageDataUrl\(data\) : "";/, "the standard file-open flow should validate image payloads through the allowlisted data URL helper");
57
+ assert.match(openSource, /const kind = data\.kind === "image" \? "image" : "text";[\s\S]*const imageUrl = kind === "image" \? imageDataUrl\(data\) : "";/, "the standard file-open flow should validate image payloads through the allowlisted data URL helper");
54
58
  assert.match(openSource, /readOnly: kind === "image",\s*sourceAvailable: kind === "text"/, "images should be read-only and unavailable to the source editor");
55
59
  assert.match(uiSource, /elements\.fileViewerImage\.hidden = mode !== "image"/, "the image surface should render only in image mode");
56
60
  assert.match(uiSource, /elements\.fileViewerImageElement\.alt = `Preview of \$\{viewer\.name \|\| fileDisplayName\(viewer\.path\)\}`/, "rendered images should receive a useful filename-based alternative label");
57
- assert.match(app, /if \(!activeFileViewer \|\| activeFileViewer\.kind === "image" \|\| !elements\.fileViewerSearchBar\) return;/, "text search should not open for image previews");
61
+ assert.match(app, /if \(!projectFiles\.viewer \|\| projectFiles\.viewer\.kind === "image" \|\| !elements\.fileViewerSearchBar\) return;/, "text search should not open for image previews");
58
62
  assert.match(app, /elements\.fileViewerImageElement\.removeAttribute\("src"\);\s*elements\.fileViewerImageElement\.alt = "";/, "closing or replacing a viewer should release stale image source state");
59
63
 
60
64
  assert.match(css, /\.file-viewer-image \{[\s\S]*display: grid;[\s\S]*place-items: center;/, "the image surface should center its preview");
@@ -62,8 +66,8 @@ assert.match(css, /\.file-viewer-image img \{[\s\S]*max-width: 100%;[\s\S]*max-h
62
66
  assert.match(readme, /PNG, JPEG, GIF, WebP, and AVIF/i, "the Files panel guide should list supported image formats");
63
67
  assert.match(technical, /supported raster images[\s\S]*2 MiB/i, "the advanced reference should document image support and its size limit");
64
68
  assert.match(development, /kind: "image"[\s\S]*base64/i, "the contributor guide should document the image response contract");
65
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v156"/, "changed viewer assets should advance the PWA cache identity");
66
- assert.match(html, /styles\.css\?v=154/, "changed image styles should advance the stylesheet revision");
67
- assert.match(html, /app\.js\?v=185/, "changed image rendering should advance the app revision");
69
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "changed viewer assets should advance the PWA cache identity");
70
+ assert.match(html, /styles\.css\?v=167/, "changed image styles should advance the stylesheet revision");
71
+ assert.match(html, /app\.js\?v=220/, "changed image rendering should advance the app revision");
68
72
 
69
73
  console.log("file viewer image static tests passed");
@@ -28,19 +28,19 @@ const helperEnd = app.indexOf("\nfunction updateFileViewerSearchCount()", helper
28
28
  assert.ok(helperStart >= 0 && helperEnd > helperStart, "file viewer search matching should remain independently testable");
29
29
  const helperSource = app.slice(helperStart, helperEnd);
30
30
  const sourceMatches = JSON.parse(vm.runInNewContext(`${helperSource}\nJSON.stringify(collectFileViewerSearchMatches("alpha"))`, {
31
- activeFileViewer: { mode: "source", content: "stale" },
31
+ projectFiles: { viewer: { mode: "source", content: "stale" } },
32
32
  elements: { fileViewerEditor: { value: "Alpha beta ALPHA" }, fileViewerPreview: { textContent: "preview" }, fileViewerChanges: { textContent: "changes" } },
33
33
  resolveFileViewerMode: (viewer) => viewer.mode,
34
34
  }));
35
35
  assert.deepEqual(sourceMatches, { matches: [{ start: 0, end: 5 }, { start: 11, end: 16 }], truncated: false }, "source search should use live edited text and match case-insensitively");
36
36
  const previewMatches = JSON.parse(vm.runInNewContext(`${helperSource}\nJSON.stringify(collectFileViewerSearchMatches("rendered"))`, {
37
- activeFileViewer: { mode: "preview" },
37
+ projectFiles: { viewer: { mode: "preview" } },
38
38
  elements: { fileViewerEditor: { value: "source" }, fileViewerPreview: { textContent: "Rendered preview" }, fileViewerChanges: { textContent: "changes" } },
39
39
  resolveFileViewerMode: (viewer) => viewer.mode,
40
40
  }));
41
41
  assert.deepEqual(previewMatches, { matches: [{ start: 0, end: 8 }], truncated: false }, "preview search should use the rendered file surface instead of hidden source text");
42
42
  const truncatedMatches = JSON.parse(vm.runInNewContext(`${helperSource}\nJSON.stringify(collectFileViewerSearchMatches("a"))`, {
43
- activeFileViewer: { mode: "source" },
43
+ projectFiles: { viewer: { mode: "source" } },
44
44
  elements: { fileViewerEditor: { value: "a".repeat(10_001) }, fileViewerPreview: { textContent: "" }, fileViewerChanges: { textContent: "" } },
45
45
  resolveFileViewerMode: (viewer) => viewer.mode,
46
46
  }));
@@ -52,13 +52,13 @@ assert.match(app, /function renderFileViewerSearchHighlights\(\)[\s\S]*new Highl
52
52
  assert.match(app, /function focusFileViewerSearchMatch\(\)[\s\S]*setSelectionRange\(match\.start, match\.end\)[\s\S]*syncFileViewerSearchOverlayScroll\(\)[\s\S]*textOffsetPosition\(surface, match\.start\)[\s\S]*scrollIntoView/, "match navigation should select and center source or rendered matches without mutating document selection");
53
53
  assert.doesNotMatch(app.slice(app.indexOf("function focusFileViewerSearchMatch("), app.indexOf("\nfunction runFileViewerSearch(", app.indexOf("function focusFileViewerSearchMatch("))), /getSelection|addRange|removeAllRanges/, "rendered file search must not overwrite selections used by the Send to Pi workflow");
54
54
  assert.match(app, /function runFileViewerSearch\([\s\S]*setAttribute\("aria-controls", surface\.id\)/, "the search input should identify the active Source, Preview, or Changes surface");
55
- assert.match(app, /function setFileViewerMode\([\s\S]*updateFileViewerUi\(\);[\s\S]*runFileViewerSearch\(\{ navigate: true \}\)/, "an explicit mode switch should reveal the first match on the new surface");
55
+ assert.match(app, /function setFileViewerMode\([\s\S]*projectFiles\.setMode\(mode\);[\s\S]*runFileViewerSearch\(\{ navigate: true \}\)/, "an explicit mode switch should reveal the first match on the new surface");
56
56
  assert.match(app, /function updateFileViewerUi\([\s\S]*runFileViewerSearch\(\{ navigate: false \}\)/, "background viewer refreshes should reindex without stealing focus or scrolling to a match");
57
57
  assert.match(app, /fileViewerSearchInput\?\.addEventListener\("input"[\s\S]*setTimeout\([\s\S]*runFileViewerSearch\(\{ navigate: true \}\)[\s\S]*150/, "typing should debounce search work for large files");
58
58
  assert.match(app, /fileViewerSearchInput\?\.addEventListener\("keydown"[\s\S]*event\.key === "Enter"[\s\S]*stepFileViewerSearch\(event\.shiftKey \? -1 : 1\)[\s\S]*event\.key === "Escape"[\s\S]*closeFileViewerSearch\(\)/, "Enter, Shift+Enter, and Escape should navigate or close in-file search");
59
59
  assert.match(
60
60
  app,
61
- /if \(activeFileViewer && elements\.fileViewerPane\?\.contains\(event\.target\)\) openFileViewerSearch\(\);\s*else openChatSearch\(\);/,
61
+ /if \(projectFiles\.viewer && elements\.fileViewerPane\?\.contains\(event\.target\)\) openFileViewerSearch\(\);\s*else openChatSearch\(\);/,
62
62
  "Ctrl/Cmd+F should route to in-file search only when the event target is inside the open file viewer",
63
63
  );
64
64
  assert.match(app, /function openChatSearch\(\)[\s\S]*closeFileViewerSearch\(\{ restoreFocus: false \}\)/, "opening transcript search should close any stale in-file search bar");
@@ -0,0 +1,61 @@
1
+ import { appendFileSync } from "node:fs";
2
+ import { createInterface } from "node:readline";
3
+ import { spawn } from "node:child_process";
4
+
5
+ const mode = process.env.FAKE_CODEX_MODE || "success";
6
+ const log = (entry) => {
7
+ if (process.env.FAKE_CODEX_LOG) appendFileSync(process.env.FAKE_CODEX_LOG, `${JSON.stringify(entry)}\n`);
8
+ };
9
+ log({ kind: "start", pid: process.pid, args: process.argv.slice(2) });
10
+ if (["hang", "stubborn", "tree"].includes(mode)) setInterval(() => {}, 1000);
11
+ if (mode === "tree") {
12
+ const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], { stdio: "ignore" });
13
+ log({ kind: "descendant", pid: child.pid });
14
+ }
15
+ const send = (frame) => {
16
+ const bytes = Buffer.from(`${JSON.stringify(frame)}\n`);
17
+ if (mode === "fragmented") {
18
+ for (let start = 0; start < bytes.length; start += 7) process.stdout.write(bytes.subarray(start, start + 7));
19
+ } else process.stdout.write(bytes);
20
+ };
21
+ const primary = { usedPercent: 25, windowDurationMins: 300, resetsAt: 2_000_000_000 };
22
+ const secondary = { usedPercent: 42, windowDurationMins: 10080, resetsAt: 2_000_500_000 };
23
+ createInterface({ input: process.stdin }).on("line", (line) => {
24
+ const frame = JSON.parse(line);
25
+ log({ kind: "frame", ...frame });
26
+ if (!frame.method || frame.method === "initialized") return;
27
+ if (frame.method === "initialize") {
28
+ if (mode === "hang") return;
29
+ if (mode === "early-exit") { process.exit(7); return; }
30
+ if (mode === "malformed") { process.stdout.write("not JSON\n"); return; }
31
+ if (mode === "oversized") { process.stdout.write("x".repeat(1024 * 1024 + 1)); return; }
32
+ if (mode === "stderr-flood") { process.stderr.write("x".repeat(4 * 1024 * 1024 + 1)); return; }
33
+ send({ id: frame.id, result: { userAgent: "fixture" } });
34
+ if (mode === "server-request") send({ id: "server-auth-request", method: "account/chatgptAuthTokens/refresh", params: { reason: "expired" } });
35
+ send({ method: "account/updated", params: { email: "private-fixture@example.invalid", secret: "fixture-notification-secret" } });
36
+ return;
37
+ }
38
+ if (frame.method === "account/read") {
39
+ const account = mode === "logged-out" ? null : mode === "api-key" ? { type: "apiKey" } : { type: "chatgpt", planType: "plus", email: "private-fixture@example.invalid", accountId: "private-account", accessToken: "fixture-access-secret" };
40
+ send({ id: frame.id, result: { account, requiresOpenaiAuth: true } });
41
+ return;
42
+ }
43
+ if (frame.method === "account/rateLimits/read") {
44
+ if (mode === "rpc-error") {
45
+ process.stderr.write("Bearer fixture-stderr-secret\n");
46
+ send({ id: frame.id, error: { code: -32603, message: "upstream 401 Bearer fixture-error-secret", data: { refreshToken: "fixture-refresh-secret" } } });
47
+ return;
48
+ }
49
+ const limits = mode === "empty" ? {} : { limitId: "codex", limitName: "Codex 漢字", primary: mode === "weekly-only" ? null : primary, secondary, credits: { hasCredits: true, unlimited: false, balance: "12.50", accessToken: "fixture-credit-secret" }, planType: "plus" };
50
+ send({ id: frame.id, result: {
51
+ rateLimits: limits,
52
+ rateLimitsByLimitId: mode === "multi-bucket" ? { codex: limits, extra: { limitId: "extra", primary: { ...primary, usedPercent: 70 } } } : null,
53
+ accountId: "private-account",
54
+ accessToken: "fixture-usage-secret",
55
+ profile: { email: "private-fixture@example.invalid" },
56
+ } });
57
+ return;
58
+ }
59
+ send({ id: frame.id, error: { code: -32601, message: "Unexpected operation" } });
60
+ });
61
+ process.stdin.on("end", () => { if (!["hang", "stubborn", "tree"].includes(mode)) process.exit(0); });
@@ -23,9 +23,12 @@
23
23
  // prompt and emit a generic Intercom tool stream with visible unrelated output.
24
24
  // - FAKE_PI_GUIDED_GIT_ACTIVATION=1: advertise the Guided Git extension and
25
25
  // prompt companion, then emit its exact transient set/clear activation status.
26
+ // - FAKE_PI_SESSION_OWNERSHIP=1: retain model choices and give each process its
27
+ // own session identity, or a stable identity for a normalized session path.
26
28
  import { createHash, randomUUID } from "node:crypto";
27
29
  import { createInterface } from "node:readline";
28
30
  import { appendFileSync } from "node:fs";
31
+ import { resolve } from "node:path";
29
32
  import {
30
33
  BUILTIN_SAMPLING_APIS,
31
34
  filterSupportedSamplingParameters,
@@ -38,6 +41,11 @@ const sessionIndex = process.argv.indexOf("--session");
38
41
  const sessionFile = sessionIndex !== -1
39
42
  ? process.argv[sessionIndex + 1]
40
43
  : process.env.FAKE_PI_CONTINUITY_MODE === "1" ? process.env.FAKE_PI_CONTINUITY_SESSION_FILE || undefined : undefined;
44
+ const sessionOwnershipEnabled = process.env.FAKE_PI_SESSION_OWNERSHIP === "1";
45
+ let ownedSessionId = sessionOwnershipEnabled
46
+ ? `fake-session-${sessionFile ? createHash("sha256").update(resolve(sessionFile)).digest("hex") : randomUUID()}`
47
+ : "fake-session";
48
+ let selectedModel = { provider: "fake", id: "fake-model" };
41
49
 
42
50
  let activeBash = 0;
43
51
  let peakBash = 0;
@@ -405,7 +413,7 @@ function handleIntercomLivePrompt(command, base) {
405
413
  return true;
406
414
  }
407
415
 
408
- function runContinuityDelayedStream() {
416
+ function runContinuityDelayedStream({ holdOpen = false } = {}) {
409
417
  scriptedStreaming = true;
410
418
  const text = "continuity stream complete";
411
419
  const run = ++continuityRun;
@@ -421,7 +429,7 @@ function runContinuityDelayedStream() {
421
429
  appendDynamicMessage(message);
422
430
  emitScriptedEvent(tagged({ type: "message_end", continuityStep: "message-end", message }));
423
431
  } },
424
- { afterMs: 80, run: () => emitScriptedEvent(tagged({ type: "agent_end", continuityStep: "end" })) },
432
+ { afterMs: holdOpen ? 30_000 : 80, run: () => emitScriptedEvent(tagged({ type: "agent_end", continuityStep: "end" })) },
425
433
  { afterMs: 10, run: () => {
426
434
  scriptedStreaming = false;
427
435
  emitScriptedEvent(tagged({ type: "agent_settled", continuityStep: "settled" }));
@@ -594,15 +602,28 @@ function handleMobileBlockerPrompt(command, base) {
594
602
  return true;
595
603
  }
596
604
 
605
+ function handleActivityDecisionPrompt(command, base) {
606
+ if (String(command.message || "").trim() !== "fixture activity model decision") return false;
607
+ respond({ ...base, data: { output: "activity decision fixture accepted" } });
608
+ emitEvent({
609
+ type: "extension_ui_request",
610
+ id: "fixture-workflow-model-exception",
611
+ method: "select",
612
+ title: "Workflow model exception for fixture run",
613
+ options: ["Approve fixture model", "Reject fixture model"],
614
+ });
615
+ return true;
616
+ }
617
+
597
618
  function handleContinuityPrompt(command, base) {
598
619
  if (!continuityModeEnabled) return false;
599
620
  const message = String(command.message || "").trim();
600
- if (!["fixture continuity delayed stream", "fixture continuity delayed start", "fixture continuity confirmed before tool"].includes(message)) return false;
621
+ if (!["fixture continuity delayed stream", "fixture continuity held stream", "fixture continuity delayed start", "fixture continuity confirmed before tool"].includes(message)) return false;
601
622
  appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
602
623
  respond({ ...base, data: { output: "fake continuity stream accepted", pid: process.pid } });
603
624
  if (message === "fixture continuity delayed start") runContinuityDelayedStart();
604
625
  else if (message === "fixture continuity confirmed before tool") runContinuityConfirmedBeforeTool();
605
- else runContinuityDelayedStream();
626
+ else runContinuityDelayedStream({ holdOpen: message === "fixture continuity held stream" });
606
627
  return true;
607
628
  }
608
629
 
@@ -1230,7 +1251,7 @@ function emitSubagentFixtureStatus({ legacyOnly = false } = {}) {
1230
1251
  version: 1,
1231
1252
  instanceId: agent.id,
1232
1253
  runId: run.id,
1233
- parentSessionId: "fake-session",
1254
+ parentSessionId: ownedSessionId,
1234
1255
  launcher: run.source === "workflow" ? "workflow" : "pi-subagents",
1235
1256
  provider: run.source === "workflow" ? "workflow-run" : "pi-subagents",
1236
1257
  origin: run.source,
@@ -1575,14 +1596,14 @@ rl.on("line", (line) => {
1575
1596
  respond({
1576
1597
  ...base,
1577
1598
  data: {
1578
- model: codexFixtureModel || { provider: "fake", id: "fake-model" },
1599
+ model: codexFixtureModel || (sessionOwnershipEnabled ? selectedModel : { provider: "fake", id: "fake-model" }),
1579
1600
  thinkingLevel,
1580
1601
  isStreaming: scriptedStreaming || guidedGitStateMode === "streaming",
1581
1602
  isCompacting: guidedGitStateMode === "compacting",
1582
1603
  steeringMode: "one-at-a-time",
1583
1604
  followUpMode: "one-at-a-time",
1584
1605
  sessionFile,
1585
- sessionId: "fake-session",
1606
+ sessionId: ownedSessionId,
1586
1607
  sessionName: "fake",
1587
1608
  autoCompactionEnabled: false,
1588
1609
  messageCount: 0,
@@ -1659,6 +1680,7 @@ rl.on("line", (line) => {
1659
1680
  if (handleCodexFastModePrompt(command, base)) return;
1660
1681
  if (handleTalkPrompt(command, base)) return;
1661
1682
  if (handleMobileBlockerPrompt(command, base)) return;
1683
+ if (handleActivityDecisionPrompt(command, base)) return;
1662
1684
  if (handleTranscriptContinuityPrompt(command, base)) return;
1663
1685
  if (handleContinuityPrompt(command, base)) return;
1664
1686
  if (handleLargePayloadPrompt(command, base)) return;
@@ -1688,10 +1710,20 @@ rl.on("line", (line) => {
1688
1710
  return;
1689
1711
  case "set_model":
1690
1712
  if (command.modelId === "missing-model") respond({ ...base, success: false, error: "Model not found: fake/missing-model" });
1691
- else respond({ ...base, data: { provider: command.provider, id: command.modelId } });
1713
+ else {
1714
+ if (sessionOwnershipEnabled) selectedModel = { provider: command.provider, id: command.modelId };
1715
+ respond({ ...base, data: { provider: command.provider, id: command.modelId } });
1716
+ }
1692
1717
  return;
1693
1718
  case "get_available_models":
1694
- respond({ ...base, data: { models: [{ provider: "fake", id: "fake-model", name: "Fake Model" }] } });
1719
+ respond({ ...base, data: { models: [
1720
+ { provider: "fake", id: "fake-model", name: "Fake Model" },
1721
+ ...(sessionOwnershipEnabled ? [{ provider: "fake", id: "fake-model-alt", name: "Fake Alternate Model" }] : []),
1722
+ ] } });
1723
+ return;
1724
+ case "new_session":
1725
+ if (sessionOwnershipEnabled) ownedSessionId = `fake-session-${randomUUID()}`;
1726
+ respond({ ...base, data: {} });
1695
1727
  return;
1696
1728
  case "get_session_stats":
1697
1729
  respond({
@@ -1,11 +1,12 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { readFile } from "node:fs/promises";
3
3
 
4
- const [app, css, producer, parser] = await Promise.all([
4
+ const [app, css, producer, parser, usage] = await Promise.all([
5
5
  readFile(new URL("../public/app.js", import.meta.url), "utf8"),
6
6
  readFile(new URL("../public/styles.css", import.meta.url), "utf8"),
7
7
  readFile(new URL("../../pi-extension-git-footer-status/index.ts", import.meta.url), "utf8"),
8
8
  readFile(new URL("../../pi-extension-git-footer-status/provider-usage.ts", import.meta.url), "utf8"),
9
+ readFile(new URL("../public/activity-usage-controller.mjs", import.meta.url), "utf8"),
9
10
  ]);
10
11
 
11
12
  const between = (source, start, end) => {
@@ -22,8 +23,8 @@ const applyUsage = between(app, "function applyFooterUsageWindows", "const FOOTE
22
23
  const shapeKey = between(app, "function gitFooterChipShapeKey", "function footerBranchPickerRenderKey");
23
24
  const inPlaceUpdate = between(app, "function updateGitFooterChipNodeValue", "let gitFooterRenderCache");
24
25
  const providerUsageNormalization = between(app, "function normalizeFooterProviderUsageWindow", "function currentGitFooterCacheCwd");
25
- const claudeUsageSync = between(app, "function claudeUsageWindowFromProvider", "function claudeUsageResetDate");
26
- const claudeUsageRefresh = between(app, "async function refreshClaudeUsage", "function scheduleRefreshClaudeUsage");
26
+ const claudeUsageSync = between(usage, "function claudeUsageWindowFromProvider", "function claudeUsageResetDate");
27
+ const claudeUsageRefresh = between(usage, "async function refreshClaude", "function schedule(provider");
27
28
 
28
29
  assert.match(parser, /x-codex-primary-window-minutes/, "Codex parser should read the primary window duration");
29
30
  assert.match(parser, /x-codex-secondary-window-minutes/, "Codex parser should read the secondary window duration");
@@ -43,10 +44,10 @@ assert.match(providerUsageNormalization, /normalizeFooterProviderUsageWindow\(va
43
44
  assert.match(app, /const providerUsage = normalizeFooterProviderUsage\(parsed\.providerUsage\);[\s\S]*\{ providerUsage \}/, "footer payload parsing should retain normalized provider usage metadata");
44
45
  assert.match(claudeUsageSync, /providerUsage\?\.provider !== "anthropic"[\s\S]*source: "git-footer-status-provider-headers"[\s\S]*windows/, "Claude Usage should consume the same live Anthropic header snapshot as the footer");
45
46
  assert.match(claudeUsageSync, /capturedAt \+ resetAfterSeconds \* 1000/, "relative reset times should be anchored to provider capture time instead of drifting on each render");
46
- assert.match(claudeUsageRefresh, /if \(!forceCli && syncClaudeUsageFromGitFooterPayload\(\)\) return;/, "scheduled Claude refreshes should prefer the live footer snapshot");
47
- assert.match(app, /if \(footerPayload\) syncClaudeUsageFromGitFooterPayload\(footerPayload\);/, "incoming footer status should update the Claude Usage panel immediately");
47
+ assert.match(claudeUsageRefresh, /if \(!forceCli && syncFooter\(\)\) return;/, "scheduled Claude refreshes should prefer the live footer snapshot");
48
+ assert.match(app, /if \(footerPayload\) activityUsage\.syncFooter\(footerPayload\);/, "incoming footer status should update the Claude Usage panel immediately");
48
49
  assert.match(app, /function applyOptimisticGitFooterBranch[\s\S]*payload\.providerUsage \? \{ providerUsage: payload\.providerUsage \}/, "optimistic branch updates should preserve the provider snapshot used by Claude Usage");
49
- assert.match(app, /refreshClaudeUsage\(\{ forceCli: true \}\)/, "the explicit Refresh usage button should retain the CLI fallback path");
50
+ assert.match(app, /activityUsage\.refreshClaude\(\{ forceCli: true \}\)/, "the explicit Refresh usage button should retain the CLI fallback path");
50
51
 
51
52
  assert.match(usageNormalization, /value\.usageWindows\.primaryPercent/, "consumer should read structured primary metadata");
52
53
  assert.match(usageNormalization, /value\.usageWindows\.secondaryPercent/, "consumer should read structured secondary metadata");
@@ -1,3 +1,4 @@
1
+ import { createSessionEventStream } from "../public/platform-event-stream.mjs";
1
2
  import assert from "node:assert/strict";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import { dirname, join } from "node:path";
@@ -34,7 +35,7 @@ assert.match(app, /let foregroundTranscriptCatchUpRequired = document\.visibilit
34
35
  const beginCatchUp = functionBody(app, "beginForegroundTranscriptCatchUp");
35
36
  assert.match(beginCatchUp, /foregroundTranscriptCatchUpRequired = true/);
36
37
  assert.match(beginCatchUp, /streamOutputController\.cancel\(\)/, "backgrounding should discard pending frame work rather than replaying it later");
37
- assert.match(beginCatchUp, /eventStreamPausedForBackground = true[\s\S]*?eventSource = null[\s\S]*?source\.close\(\)/, "backgrounding should close the EventSource so Chromium cannot retain and replay an SSE backlog");
38
+ assert.match(beginCatchUp, /eventStreamPausedForBackground = true[\s\S]*?sessionEvents\.close\(\)/, "backgrounding should close the EventSource so Chromium cannot retain and replay an SSE backlog");
38
39
 
39
40
  const dispatch = functionBody(app, "dispatchTranscriptStreamEvent");
40
41
  assert.match(dispatch, /classifyTranscriptStreamEvent\(event\)/);
@@ -68,18 +69,20 @@ assert.match(
68
69
  assert.match(app, /case "webui_connected":[\s\S]*?resumedWithFreshSnapshot[\s\S]*?if \(!resumedWithFreshSnapshot\) scheduleForegroundReconcile/, "the deliberate reconnect must not immediately trigger a second full refresh");
69
70
  assert.match(app, /case "webui_supervisor_reconnected":[\s\S]*?foregroundReconnectSnapshotFreshUntil/, "initial supervisor replay must reuse the fresh foreground snapshot");
70
71
 
71
- const executeBeginCatchUp = new Function("eventSource", "streamOutputController", "flushNormalStreamRenders", `
72
+ const executeBeginCatchUp = new Function("sessionEvents", "streamOutputController", "flushNormalStreamRenders", `
72
73
  let foregroundTranscriptCatchUpRequired = false;
73
74
  let backgroundReconnectSnapshotFresh = true;
74
75
  let eventStreamPausedForBackground = false;
75
76
  ${beginCatchUp}
76
- return { foregroundTranscriptCatchUpRequired, backgroundReconnectSnapshotFresh, eventStreamPausedForBackground, eventSource };
77
+ return { foregroundTranscriptCatchUpRequired, backgroundReconnectSnapshotFresh, eventStreamPausedForBackground, eventSource: sessionEvents.source };
77
78
  `);
78
79
  let closeCount = 0;
79
80
  let cancelCount = 0;
80
81
  let normalRenderFlushCount = 0;
82
+ const stream = createSessionEventStream({ createSource: () => ({ close() { closeCount += 1; } }), isCurrent: () => true });
83
+ stream.connect("/events", {});
81
84
  const pausedState = executeBeginCatchUp(
82
- { close() { closeCount += 1; } },
85
+ stream,
83
86
  { cancel() { cancelCount += 1; } },
84
87
  (reason) => {
85
88
  assert.equal(reason, "visibility-hidden");
@@ -37,7 +37,7 @@ assert.match(
37
37
  );
38
38
  assert.match(
39
39
  app,
40
- /async function disableGitFooterContextChip\(key, label\)[\s\S]*runGitFooterVisibilityCommand\("hide", \[key\]\)[\s\S]*requestGitFooterWebuiPayload/,
40
+ /async function disableGitFooterContextChip\(key, label\)[\s\S]*runGitFooterVisibilityCommand\("hide", \[key\], target, \{ dialogOwned: false \}\)[\s\S]*requestGitFooterWebuiPayload/,
41
41
  "disabling a box should persist its matching WebUI visibility key and refresh the payload",
42
42
  );
43
43
  assert.match(
@@ -4,6 +4,7 @@ import { dirname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import vm from "node:vm";
6
6
 
7
+ const owner = await readFile(new URL("../public/project-file-viewer-controller.mjs", import.meta.url), "utf8");
7
8
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
9
  const [app, css, html] = await Promise.all([
9
10
  readFile(join(root, "public", "app.js"), "utf8"),
@@ -11,27 +12,27 @@ const [app, css, html] = await Promise.all([
11
12
  readFile(join(root, "public", "index.html"), "utf8"),
12
13
  ]);
13
14
 
14
- function sourceBetween(startMarker, endMarker, label) {
15
- const start = app.indexOf(startMarker);
16
- const end = app.indexOf(endMarker, start);
15
+ function sourceBetween(startMarker, endMarker, label, source = app) {
16
+ const start = source.indexOf(startMarker);
17
+ const end = source.indexOf(endMarker, start);
17
18
  assert.ok(start >= 0 && end > start, `${label} should remain a standalone frontend helper`);
18
- return app.slice(start, end);
19
+ return source.slice(start, end);
19
20
  }
20
21
 
21
22
  const normalizePathSource = sourceBetween("function normalizeFileTreePath(", "\nfunction fileApiPath(", "normalizeFileTreePath");
22
23
  const targetSource = sourceBetween("function gitFileViewerTarget(", "\nasync function openGitFileInViewer(", "gitFileViewerTarget");
23
24
  const openSource = sourceBetween("async function openGitFileInViewer(", "\nasync function openGitFileFromChanges(", "openGitFileInViewer");
24
25
  const renderSource = sourceBetween("function renderGitPanelFile(", "\nfunction renderGitPanelTreeSection(", "renderGitPanelFile");
25
- const categorySource = sourceBetween("const GIT_FILE_DIFF_CATEGORY_BY_PANEL = Object.freeze({", "\nasync function loadGitFileChangesSnapshot(", "gitFileDiffCategory");
26
- const modeSource = sourceBetween("function resolveFileViewerMode(", "\nfunction setFileViewerMode(", "resolveFileViewerMode");
26
+ const categorySource = sourceBetween("const GIT_FILE_DIFF_CATEGORY_BY_PANEL", "export function resolveFileViewerMode", "categories", owner).replaceAll("export ", "");
27
+ const modeSource = sourceBetween("export function resolveFileViewerMode", "\n/**", "mode", owner).replace("export ", "");
27
28
  const setModeSource = sourceBetween("function setFileViewerMode(", "\nfunction setFileViewerDirty(", "setFileViewerMode");
28
29
  const viewerUiSource = sourceBetween("function updateFileViewerUi(", "\nfunction fileViewerChangesNotice(", "updateFileViewerUi");
29
30
  const changesRenderSource = sourceBetween("function fileViewerChangesNotice(", "\nfunction clearFileViewerSelection(", "file viewer changes rendering");
30
31
  const combinedSyntaxSource = sourceBetween("function gitFileDiffUsesCombinedSyntax(", "\nfunction renderFileViewerUntrackedChanges(", "gitFileDiffUsesCombinedSyntax");
31
- const snapshotSource = sourceBetween("async function loadGitFileChangesSnapshot(", "\nfunction gitFileChangesPlaceholder(", "loadGitFileChangesSnapshot");
32
- const applySnapshotSource = sourceBetween("function gitFileChangesPlaceholder(", "\nasync function openFileInViewer(", "gitFileChangesPlaceholder");
33
- const openFileSource = sourceBetween("async function openFileInViewer(", "\nasync function openAurReviewReportInViewer(", "openFileInViewer");
34
- const viewerPersistenceSource = sourceBetween("function cacheActiveFileViewerForTab(", "\n// Side-panel Git categories are UI labels", "file viewer tab persistence");
32
+ const snapshotSource = sourceBetween(" async function loadDiff(", "\n async function applyDiff(", "diff request", owner);
33
+ const applySnapshotSource = sourceBetween(" async function applyDiff(", "\n async function open(", "diff ownership", owner);
34
+ const openFileSource = sourceBetween(" async function open(", "\n async function openReport(", "open owner", owner);
35
+ const viewerPersistenceSource = sourceBetween("function cacheActiveFileViewerForTab(", "\nfunction handleProjectFileChange(", "viewer adapter");
35
36
  const moveSource = sourceBetween("function updateActiveFileViewerAfterMove(", "\nfunction closeActiveFileViewerIfDeleted(", "updateActiveFileViewerAfterMove");
36
37
  const resetActiveTabUiSource = sourceBetween("function resetActiveTabUi(", "\nfunction tabGroupStatusRank(", "resetActiveTabUi");
37
38
  const switchTabSource = sourceBetween("async function switchTab(", "\nfunction currentDirectoryForNewTab(", "switchTab");
@@ -55,7 +56,7 @@ assert.equal(targets[4], null, "Git files outside every available tab cwd should
55
56
 
56
57
  assert.match(openSource, /gitFileViewerTarget\(repoRelPath, root, candidates\)/, "Git file opening should use the shared repo-to-workspace path resolver");
57
58
  assert.match(openSource, /target\.tabId !== activeTabId[\s\S]*await switchTab\(target\.tabId\)[\s\S]*openFileInViewer\(target\.path/, "Git file opening should activate the owning tab before using the standard WebUI viewer");
58
- assert.match(openSource, /its terminal tab is no longer available/, "a stale Git-card tab should produce visible failure feedback");
59
+ assert.match(openSource, /its thread is no longer available/, "a stale Git-card tab should produce visible failure feedback");
59
60
  assert.match(renderSource, /row\.setAttribute\("role", "button"\)/, "Git file rows should expose button semantics");
60
61
  assert.match(renderSource, /row\.addEventListener\("click", open\)/, "clicking a Git file row should open its preview");
61
62
  assert.match(renderSource, /event\.repeat \|\| \(event\.key !== "Enter" && event\.key !== " "\)/, "Git file rows should support keyboard activation without key-repeat request bursts");
@@ -110,8 +111,8 @@ assert.equal(modes[7], "changes", "a deleted tracked file without live source sh
110
111
  assert.equal(modes[8], "source", "a missing source without any Git snapshot should not invent a Changes view");
111
112
  assert.equal(modes[9], "source", "mode resolution should fail closed without a viewer");
112
113
 
113
- assert.match(setModeSource, /activeFileViewer\.mode = resolveFileViewerMode\(\{ \.\.\.activeFileViewer, mode \}\);/, "mode switching should route every request through the shared resolver");
114
- assert.match(setModeSource, /if \(activeFileViewer\.mode === "changes" && previousMode !== "changes"\) clearFileViewerSelection\(\);/, "entering Changes mode should clear a stale Source or Preview selection bar");
114
+ assert.match(owner, /viewer\.mode = resolveFileViewerMode\(\{ \.\.\.viewer, mode \}\)/, "mode switching should route every request through the shared resolver");
115
+ assert.match(owner, /if \(viewer\.mode === "changes" && previousMode !== "changes"\) selection = null/, "entering Changes mode should clear a stale Source or Preview selection bar");
115
116
  assert.match(viewerUiSource, /const hasChanges = !!viewer\.gitChanges;/, "the viewer UI should derive Changes availability from the open-time snapshot");
116
117
  assert.match(viewerUiSource, /elements\.fileViewerChangesModeButton\.hidden = !hasChanges;\s*elements\.fileViewerChangesModeButton\.disabled = !hasChanges;/, "the Changes control should stay hidden and disabled for non-Git opens");
117
118
  assert.match(viewerUiSource, /elements\.fileViewerSourceModeButton\.disabled = !sourceAvailable;/, "Source should be disabled when the live file content is unavailable");
@@ -145,59 +146,51 @@ assert.deepEqual(
145
146
 
146
147
  // --- Backend request contract ---
147
148
 
148
- assert.match(snapshotSource, /new URLSearchParams\(\{ path: repoRelPath, category \}\)/, "the changes request should send the repo-relative path and the mapped category");
149
+ assert.match(snapshotSource, /new URLSearchParams\(\{ path, category \}\)/, "the changes request should send the repo-relative path and the mapped category");
149
150
  assert.match(snapshotSource, /api\(`\/api\/git-file-diff\?\$\{params\.toString\(\)\}`, \{ tabId \}\)/, "the changes request should call the read-only Git file diff endpoint on the owning tab");
150
151
  assert.match(snapshotSource, /if \(!response\.ok\) throw new Error\(response\.error \|\| "Failed to load Git changes for this file"\)/, "an ok:false response should surface a readable error");
151
152
  assert.match(snapshotSource, /truncated: data\.truncated === true/, "truncation should be carried into the viewer snapshot");
152
153
  assert.match(snapshotSource, /contentError: data\.error \? String\(data\.error\) : ""/, "an untracked read error should stay distinct from a request failure");
153
154
  assert.match(snapshotSource, /return \{ \.\.\.snapshot, error: error\.message \|\| String\(error\) \};/, "a failed changes request should resolve to an error snapshot instead of rejecting the open");
154
- assert.match(app, /let fileViewerGitChangesRequestSerial = 0;/, "Git changes opens should have a request identity counter");
155
- assert.match(applySnapshotSource, /loading: true, requestSerial/, "the viewer should show an identified loading snapshot until the bounded diff arrives");
156
- assert.match(
157
- applySnapshotSource,
158
- /const viewer = tabContext\.tabId === activeTabId \? activeFileViewer : fileViewersByTab\.get\(tabContext\.tabId\);\s*if \(!viewer\?\.gitChanges\?\.loading \|\| viewer\.path !== viewerPath \|\| viewer\.gitChanges\.requestSerial !== requestSerial\) return;/,
159
- "a late diff response should update the owning terminal's cached viewer while still rejecting stale viewer identities",
160
- );
155
+ assert.match(owner, /let diffSerial = 0/, "Git changes opens should have a request identity counter");
156
+ assert.match(openFileSource, /loading: true, requestSerial/, "the viewer should show an identified loading snapshot until the bounded diff arrives");
157
+ assert.match(applySnapshotSource, /tabs\.get\(token\.target\.tabId\) !== token\.owner[\s\S]*token\.owner\.viewer !== buffer[\s\S]*buffer\.path !== path[\s\S]*buffer\.gitChanges !== placeholder[\s\S]*!isTargetAlive\(token\.target\)/, "a late diff response should update the owning terminal's cached viewer while still rejecting stale viewer identities");
161
158
 
162
159
  // --- Open flow: Git default, normal-open isolation, deleted files ---
163
160
 
164
161
  assert.match(openSource, /category = "" \} = \{\}/, "Git opens should accept an optional side-panel category");
165
162
  assert.match(openSource, /openFileInViewer\(target\.path, \{ gitCategory: category, gitPath: normalizeFileTreePath\(repoRelPath\) \}\)/, "Git opens should hand the category and repo path to the standard viewer");
166
- assert.match(openFileSource, /async function openFileInViewer\(path = "", \{ gitCategory = "", gitPath = "" \} = \{\}\)/, "the standard viewer should accept optional Git context without changing its default signature");
167
- assert.match(app, /let fileViewerOpenRequestSerial = 0;/, "file viewer opens should have a shared request identity counter");
168
- assert.match(openFileSource, /const openRequestSerial = \+\+fileViewerOpenRequestSerial;/, "every viewer open should capture a unique request identity");
169
- assert.match(openFileSource, /const category = gitFileDiffCategory\(gitCategory\);/, "the viewer should map the side-panel category through the shared allowlist");
170
- assert.match(openFileSource, /const changesRequestSerial = category \? \+\+fileViewerGitChangesRequestSerial : 0;/, "each Git-originated open should receive a unique changes request identity");
171
- assert.match(openFileSource, /const changesRequest = category \? loadGitFileChangesSnapshot\(changesPath, category, tabContext\.tabId\) : null;/, "only category-carrying opens should request a diff");
172
- assert.match(openFileSource, /const gitChanges = changesRequest \? gitFileChangesPlaceholder\(category, changesPath, changesRequestSerial\) : null;/, "normal File-section opens should carry no Git snapshot at all");
173
- assert.match(openFileSource, /applyGitFileChangesSnapshot\(changesRequest, tabContext, activeFileViewer\.path, changesRequestSerial\)/, "same-path Git requests should apply only through their captured request identity");
163
+ assert.match(openFileSource, /async function open\(path = "", \{ gitCategory = "", gitPath = "" \} = \{\}\)/, "the standard viewer should accept optional Git context without changing its default signature");
164
+ assert.match(owner, /let openSerial = 0/, "file viewer opens should have a shared request identity counter");
165
+ assert.match(owner, /serial: \+\+openSerial/, "every viewer open should capture a unique request identity");
166
+ assert.match(openFileSource, /category = gitFileDiffCategory\(gitCategory\)/, "the viewer should map the side-panel category through the shared allowlist");
167
+ assert.match(openFileSource, /const requestSerial = category \? \+\+diffSerial : 0/, "each Git-originated open should receive a unique changes request identity");
168
+ assert.match(openFileSource, /changesRequest = category \? loadDiff\(changesPath, category, token\.target\.tabId\) : null/, "only category-carrying opens should request a diff");
169
+ assert.match(openFileSource, /const gitChanges = changesRequest \? \{[\s\S]*\} : null/, "normal File-section opens should carry no Git snapshot at all");
170
+ assert.match(openFileSource, /applyDiff\(changesRequest, token, next, gitChanges\)/, "same-path Git requests should apply only through their captured request identity");
174
171
  assert.match(openFileSource, /mode: gitChanges \? "changes" : kind === "image" \? "image" : data\.language === "markdown" \? "preview" : "source",/, "Git opens should default to Changes while normal opens keep the Image/Markdown/Source default");
175
- assert.match(openFileSource, /if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;/, "the source-success path should reject stale same-tab viewer opens");
176
- assert.match(openFileSource, /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;/, "the deleted-file fallback should reject stale same-tab viewer opens after awaiting the diff");
172
+ assert.match(openFileSource, /await api\(fileApiPath[\s\S]*if \(!isOpenCurrent\(token\)\) return \{ success: false, reason: "stale" \}/, "the source-success path should reject stale same-tab viewer opens");
173
+ assert.match(openFileSource, /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isOpenCurrent\(token\)\) return \{ success: false, reason: "stale" \}/, "the deleted-file fallback should reject stale same-tab viewer opens after awaiting the diff");
177
174
  assert.match(openFileSource, /readOnly: kind === "image",\s*sourceAvailable: kind === "text",/, "a live Git-originated text file should stay editable while image previews remain read-only");
178
- assert.match(
179
- openFileSource,
180
- /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isCurrentTabContext\(tabContext\) \|\| openRequestSerial !== fileViewerOpenRequestSerial\) return;\s*if \(gitChanges && !gitChanges\.error\) \{/,
181
- "a current failed source load should fall back to the diff only when that diff actually loaded",
182
- );
175
+ assert.match(openFileSource, /const gitChanges = changesRequest \? await changesRequest : null;\s*if \(!isOpenCurrent\(token\)\) return \{ success: false, reason: "stale" \};\s*if \(gitChanges && !gitChanges\.error\)/, "a current failed source load should fall back to the diff only when that diff actually loaded");
183
176
  assert.match(openFileSource, /mode: "changes",\s*dirty: false,\s*readOnly: true,\s*sourceAvailable: false,/, "a deleted tracked file should open read-only in Changes mode");
184
- assert.match(openFileSource, /setFileViewerStatus\("File content unavailable; showing Git changes \(read-only\)\.", "warn"\)/, "the deleted-file fallback should explain itself in the viewer status");
185
- assert.match(openFileSource, /setFileViewerStatus\(message, "error"\);\s*addEvent\(`file open failed: \$\{message\}`, "error"\);/, "a total failure should still report the original open error");
186
- assert.match(viewerPersistenceSource, /function resetFileViewerUi\(\) \{\s*fileViewerOpenRequestSerial \+= 1;\s*activeFileViewer = null;/, "resetting the visible viewer should invalidate pending source and deleted-file opens");
177
+ assert.match(openFileSource, /onStatus\("File content unavailable; showing Git changes \(read-only\)\.", "warn"\)/, "the deleted-file fallback should explain itself in the viewer status");
178
+ assert.match(openFileSource, /onStatus\(message, "error"\);\s*addEvent\(`file open failed: \$\{message\}`, "error"\)/, "a total failure should still report the original open error");
179
+ assert.match(owner, /function resetActive\(\) \{\s*openSerial \+= 1;\s*viewer = null/, "resetting the visible viewer should invalidate pending source and deleted-file opens");
187
180
  assert.match(viewerPersistenceSource, /elements\.fileViewerChanges\.hidden = true;\s*elements\.fileViewerChanges\.replaceChildren\(\);/, "resetting the visible viewer should clear the changes surface");
188
- assert.match(moveSource, /gitChanges: null,/, "renaming the open file should drop its stale open-time diff snapshot");
181
+ assert.match(owner, /function remapPath[\s\S]*gitChanges: null/, "renaming the open file should drop its stale open-time diff snapshot");
189
182
 
190
183
  // --- Per-terminal viewer persistence ---
191
184
 
192
- assert.match(app, /let fileViewersByTab = new Map\(\);/, "open file viewers should be stored per terminal tab");
193
- assert.match(app, /let fileViewerSelectionsByTab = new Map\(\);/, "viewer selections should be stored with their owning terminal tab");
194
- assert.match(viewerPersistenceSource, /fileViewersByTab\.set\(tabId, activeFileViewer\)/, "caching a terminal should retain its active viewer object, including dirty edits and mode");
195
- assert.match(viewerPersistenceSource, /fileViewerSelectionsByTab\.set\(tabId, fileViewerSelection\)/, "caching a terminal should retain its active file selection");
196
- assert.match(viewerPersistenceSource, /activeFileViewer = activeTabId \? fileViewersByTab\.get\(activeTabId\) \|\| null : null;\s*fileViewerSelection = activeTabId \? fileViewerSelectionsByTab\.get\(activeTabId\) \|\| null : null;\s*updateFileViewerUi\(\);/, "activating a terminal should restore its own viewer and selection");
197
- assert.match(viewerPersistenceSource, /function closeFileViewer\(\) \{\s*if \(activeTabId\) \{\s*fileViewersByTab\.delete\(activeTabId\);\s*fileViewerSelectionsByTab\.delete\(activeTabId\);/, "explicitly closing a viewer should remove only the active terminal's cached state");
185
+ assert.match(owner, /const tabs = new Map\(\)/, "open file viewers should be stored per terminal tab");
186
+ assert.match(owner, /owner = \{ viewer: null, selection: null \}/, "viewer selections should be stored with their owning terminal tab");
187
+ assert.match(owner, /owner\.viewer = viewer/, "caching a terminal should retain its active viewer object, including dirty edits and mode");
188
+ assert.match(owner, /owner\.selection = selection/, "caching a terminal should retain its active file selection");
189
+ assert.match(owner, /function activate\(tabId\)[\s\S]*viewer = tabs\.get\(activeTabId\)\?\.viewer \|\| null;\s*selection = tabs\.get\(activeTabId\)\?\.selection \|\| null;/, "activating a terminal should restore its own viewer and selection");
190
+ assert.match(owner, /function close\(\) \{\s*if \(activeTabId\) tabs.delete\(activeTabId\)/, "explicitly closing a viewer should remove only the active terminal's cached state");
198
191
  assert.match(switchTabSource, /cacheActiveFileViewerForTab\(activeTabId\);[\s\S]*?const tabContext = setActiveTabId\(tabId, \{ remember: true \}\);/, "switching terminals should cache the outgoing viewer before changing the active tab identity");
199
- assert.match(resetActiveTabUiSource, /resetFileViewerUi\(\);\s*resetFileTreeState\(\);\s*restoreFileViewerForActiveTab\(\);/, "resetting tab UI should restore the incoming terminal's viewer instead of closing it");
200
- assert.match(closeTabsSource, /fileViewersByTab\.delete\(id\);\s*fileViewerSelectionsByTab\.delete\(id\);/, "closing terminal tabs should discard their cached viewers and selections");
192
+ assert.match(resetActiveTabUiSource, /resetFileViewerUi\(\);\s*if \(!preserveFileTree\) resetFileTreeState\(\);\s*restoreFileViewerForActiveTab\(\);/, "resetting tab UI should restore the incoming terminal's viewer instead of closing it");
193
+ assert.match(closeTabsSource, /projectFiles\.forgetTab\(id\)/, "closing terminal tabs should discard their cached viewers and selections");
201
194
 
202
195
  // --- Changes rendering contracts ---
203
196
 
@@ -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 gitReads = await readFile(new URL("../lib/server/git-reads.mjs", import.meta.url), "utf8");
6
7
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
8
  const [app, server, watcher, development] = await Promise.all([
8
9
  readFile(join(root, "public", "app.js"), "utf8"),
@@ -35,7 +36,7 @@ assert.match(watcher, /if \(!record\.tabs\.size\) closeRoot/, "the last tab unsu
35
36
  assert.match(watcher, /function closeAll\(\)[\s\S]*closeRoot\(root\)/, "server shutdown should release every root watcher");
36
37
 
37
38
  assert.match(server, /createGitLiveWatcher\(\{[\s\S]*type: "webui_git_changed"[\s\S]*broadcastServerEvent/, "watcher changes should use the existing server-wide SSE channel");
38
- assert.match(server, /env: \{ GIT_OPTIONAL_LOCKS: "0" \}/, "read-only Git commands should not feed optional index refreshes back into the watcher");
39
+ assert.match(gitReads, /env: \{ GIT_OPTIONAL_LOCKS: "0" \}/, "read-only Git commands should not feed optional index refreshes back into the watcher");
39
40
  assert.match(server, /trackGitRepositoryForTab\(tab, await getGitRoot\(tab\.cwd\)\)/, "Git-root discovery should register the tab watcher");
40
41
  assert.match(server, /trackGitRepositoryForTab\(tab, data\.root\)/, "Git-panel reads should ensure watcher registration");
41
42
  assert.match(server, /async function updateTabCwd[\s\S]*gitLiveWatcher\.unsubscribe\(tab\.id\)/, "cwd changes should release old repository subscriptions");