@firstpick/pi-package-webui 0.11.1 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/DEVELOPMENT.md +151 -12
  2. package/README.md +34 -6
  3. package/TECHNICAL.md +75 -8
  4. package/bin/pi-webui.mjs +5390 -11423
  5. package/index.ts +10 -3
  6. package/lib/component-update-state.mjs +2 -2
  7. package/lib/git-workflow-preference-values.mjs +122 -0
  8. package/lib/git-workflow-preferences.mjs +35 -563
  9. package/lib/package-updates.mjs +260 -0
  10. package/lib/rpc-supervisor-client.mjs +8 -4
  11. package/lib/server/app-runners.mjs +1667 -0
  12. package/lib/server/codex-fast-mode.mjs +161 -0
  13. package/lib/server/conversation-mode.mjs +218 -0
  14. package/lib/server/conversation-voice.mjs +318 -0
  15. package/lib/server/extension-ui-requests.mjs +114 -0
  16. package/lib/server/git-generation.mjs +459 -0
  17. package/lib/server/git-mutations.mjs +1827 -0
  18. package/lib/server/git-reads.mjs +608 -0
  19. package/lib/server/git-worktree-sessions.mjs +408 -0
  20. package/lib/server/helper-requests.mjs +82 -0
  21. package/lib/server/no-project-workspaces.mjs +103 -0
  22. package/lib/server/rpc-transports.mjs +394 -0
  23. package/lib/server/settings-store.mjs +544 -0
  24. package/lib/server/sse-delivery.mjs +138 -0
  25. package/lib/server/workspace-files.mjs +563 -0
  26. package/lib/update/supervisor.mjs +4 -0
  27. package/lib/webui-workspaces.mjs +2 -0
  28. package/package.json +4 -4
  29. package/public/activity-agents-controller.mjs +269 -0
  30. package/public/activity-events-controller.mjs +236 -0
  31. package/public/activity-intercom-controller.mjs +627 -0
  32. package/public/activity-queue-controller.mjs +534 -0
  33. package/public/activity-todo-view.mjs +89 -0
  34. package/public/activity-usage-controller.mjs +589 -0
  35. package/public/app.js +3761 -3886
  36. package/public/conversation-overview.css +84 -0
  37. package/public/conversation-overview.mjs +193 -0
  38. package/public/draft-conversations.mjs +135 -0
  39. package/public/focused-composer-controls.css +111 -0
  40. package/public/focused-composer-controls.mjs +143 -0
  41. package/public/focused-composer-disclosure.mjs +223 -0
  42. package/public/focused-shell-adapter.css +264 -0
  43. package/public/focused-shell-adapter.mjs +257 -0
  44. package/public/index.html +137 -80
  45. package/public/model-catalog-order.mjs +63 -0
  46. package/public/platform-event-stream.mjs +64 -0
  47. package/public/project-artifact-controller.mjs +218 -0
  48. package/public/project-file-viewer-controller.mjs +383 -0
  49. package/public/project-git-tools-controller.mjs +181 -0
  50. package/public/project-runners-controller.mjs +220 -0
  51. package/public/service-worker.js +52 -1
  52. package/public/session-attention-scheduler.mjs +182 -0
  53. package/public/session-composer-store.mjs +56 -0
  54. package/public/session-context.mjs +51 -0
  55. package/public/session-extension-requests.mjs +63 -0
  56. package/public/session-shelf-state.mjs +151 -0
  57. package/public/session-shelves.css +171 -0
  58. package/public/session-shelves.mjs +95 -0
  59. package/public/settings-navigation-controller.mjs +249 -0
  60. package/public/settings-navigation.css +61 -0
  61. package/public/settings-resource-controller.mjs +232 -0
  62. package/public/settings-workspace.css +19 -0
  63. package/public/settings-workspace.mjs +175 -0
  64. package/public/shell-actions.mjs +87 -0
  65. package/public/shell-attention-inbox.css +72 -0
  66. package/public/shell-attention-inbox.mjs +198 -0
  67. package/public/shell-context-actions.css +61 -0
  68. package/public/shell-context-actions.mjs +168 -0
  69. package/public/shell-inspector-resize.mjs +124 -0
  70. package/public/shell-navigation-resize.mjs +107 -0
  71. package/public/shell-navigation.mjs +127 -0
  72. package/public/shell-preferences.mjs +108 -0
  73. package/public/shell-surfaces.mjs +99 -0
  74. package/public/shell-tools-launcher.css +97 -0
  75. package/public/shell-tools-launcher.mjs +222 -0
  76. package/public/shell-view-host.mjs +115 -0
  77. package/public/shell-workspace.css +266 -0
  78. package/public/shell-workspace.mjs +402 -0
  79. package/public/sidebar-update-menu.css +190 -0
  80. package/public/sidebar-update-menu.mjs +512 -0
  81. package/public/styles.css +322 -169
  82. package/public/subagent-launch-slot-state.mjs +2 -2
  83. package/public/themed-selects.css +156 -0
  84. package/public/workspace-choices.mjs +104 -0
  85. package/tests/activity-agents-controller.test.mjs +652 -0
  86. package/tests/activity-events-controller.test.mjs +511 -0
  87. package/tests/app-runner-terminal-static.test.mjs +3 -3
  88. package/tests/append-system-http.test.mjs +7 -6
  89. package/tests/append-system-selector-static.test.mjs +6 -6
  90. package/tests/aur-review-widget-static.test.mjs +11 -3
  91. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  92. package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
  93. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  94. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  95. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  96. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  97. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  98. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  99. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  100. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  101. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  102. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  103. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  104. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  105. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  106. package/tests/browser/control-visibility.spec.mjs +5 -0
  107. package/tests/browser/controls-layout.spec.mjs +21 -2
  108. package/tests/browser/conversation-overview.spec.mjs +251 -0
  109. package/tests/browser/draft-conversations.spec.mjs +276 -0
  110. package/tests/browser/empty-startup-fixture.mjs +135 -0
  111. package/tests/browser/empty-startup.spec.mjs +282 -0
  112. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  113. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  114. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  115. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  116. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  117. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  118. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  119. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  120. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  121. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  122. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  123. package/tests/browser/inspector-header.spec.mjs +221 -0
  124. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  125. package/tests/browser/inspector-resize.spec.mjs +227 -0
  126. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  127. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  128. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  129. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  130. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  131. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  132. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  133. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  134. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  135. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  136. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  137. package/tests/browser/more-row-menus.spec.mjs +258 -0
  138. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  139. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  140. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  141. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  142. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  143. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  144. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  145. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  146. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  147. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  148. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  149. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  150. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  151. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  152. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  153. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  154. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  155. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  156. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  157. package/tests/browser/session-fixture.mjs +118 -0
  158. package/tests/browser/session-ownership.spec.mjs +175 -0
  159. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  160. package/tests/browser/session-shelves.spec.mjs +340 -0
  161. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  162. package/tests/browser/session-summary.spec.mjs +17 -12
  163. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  164. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  165. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  166. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  167. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  168. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  169. package/tests/browser/shell-ownership.spec.mjs +398 -0
  170. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  171. package/tests/browser/shell-rollout.spec.mjs +357 -0
  172. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  173. package/tests/browser/shell-workspace.spec.mjs +433 -0
  174. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  175. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  176. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  177. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  178. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  179. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  180. package/tests/browser/themed-selects.spec.mjs +297 -0
  181. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  182. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  183. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  184. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  185. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  186. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  187. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  188. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  189. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  190. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  191. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  192. package/tests/codex-fast-mode-static.test.mjs +16 -11
  193. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  194. package/tests/codex-usage-source.test.mjs +4 -3
  195. package/tests/component-update-api-static.test.mjs +2 -2
  196. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  197. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  198. package/tests/control-visibility-static.test.mjs +3 -3
  199. package/tests/controls-layout-static.test.mjs +5 -5
  200. package/tests/conversation-overview-adapter.test.mjs +100 -0
  201. package/tests/document-artifact-static.test.mjs +2 -1
  202. package/tests/draft-conversations.test.mjs +205 -0
  203. package/tests/empty-startup-launcher.test.mjs +197 -0
  204. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  205. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  206. package/tests/fast-mode-client-static.test.mjs +1 -1
  207. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  208. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  209. package/tests/file-viewer-image-static.test.mjs +15 -11
  210. package/tests/file-viewer-search-static.test.mjs +5 -5
  211. package/tests/fixtures/fake-pi.mjs +41 -9
  212. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  213. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  214. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  215. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  216. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  217. package/tests/git-workflow-dispatch.test.mjs +66 -0
  218. package/tests/git-workflow-preferences.test.mjs +9 -1
  219. package/tests/guided-git-activation-static.test.mjs +14 -11
  220. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  221. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  222. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  223. package/tests/http-endpoints-harness.test.mjs +21 -9
  224. package/tests/interaction-state-stability-static.test.mjs +4 -3
  225. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  226. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  227. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  228. package/tests/main-output-loading-static.test.mjs +4 -4
  229. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  230. package/tests/mobile-compact-layout.test.mjs +2 -2
  231. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  232. package/tests/mobile-foundation-static.test.mjs +10 -7
  233. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  234. package/tests/mobile-static.test.mjs +173 -135
  235. package/tests/model-catalog-order.test.mjs +103 -0
  236. package/tests/native-parity.test.mjs +6 -4
  237. package/tests/native-session-choice-owner.test.mjs +102 -0
  238. package/tests/native-update-lifecycle.test.mjs +10 -5
  239. package/tests/no-project-http-harness.test.mjs +328 -0
  240. package/tests/no-project-navigation.test.mjs +54 -0
  241. package/tests/no-project-workspaces.test.mjs +77 -0
  242. package/tests/open-issue-wizard-static.test.mjs +1 -1
  243. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  244. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  245. package/tests/package-updates.test.mjs +630 -0
  246. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  247. package/tests/platform-event-stream.test.mjs +253 -0
  248. package/tests/project-file-viewer-controller.test.mjs +652 -0
  249. package/tests/project-git-tools-adapter.test.mjs +103 -0
  250. package/tests/project-git-tools-controller.test.mjs +577 -0
  251. package/tests/project-runners-controller.test.mjs +453 -0
  252. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  253. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  254. package/tests/questionnaire-dialog.test.mjs +6 -6
  255. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  256. package/tests/rpc-supervisor-host.test.mjs +4 -1
  257. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  258. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  259. package/tests/server-app-runners.test.mjs +536 -0
  260. package/tests/server-codex-fast-mode.test.mjs +346 -0
  261. package/tests/server-conversation-mode.test.mjs +386 -0
  262. package/tests/server-conversation-voice.test.mjs +426 -0
  263. package/tests/server-extension-ui-requests.test.mjs +357 -0
  264. package/tests/server-git-generation.test.mjs +558 -0
  265. package/tests/server-git-mutations.test.mjs +729 -0
  266. package/tests/server-git-reads.test.mjs +381 -0
  267. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  268. package/tests/server-helper-requests.test.mjs +364 -0
  269. package/tests/server-rpc-transports.test.mjs +553 -0
  270. package/tests/server-settings-store.test.mjs +132 -0
  271. package/tests/server-shell-rollout.test.mjs +478 -0
  272. package/tests/server-sse-delivery.test.mjs +410 -0
  273. package/tests/server-workspace-files.test.mjs +546 -0
  274. package/tests/session-attention-scheduler.test.mjs +514 -0
  275. package/tests/session-composer-store.test.mjs +153 -0
  276. package/tests/session-context.test.mjs +134 -0
  277. package/tests/session-extension-requests.test.mjs +193 -0
  278. package/tests/session-ownership-adapter.test.mjs +130 -0
  279. package/tests/session-sampling-ui-static.test.mjs +10 -4
  280. package/tests/session-send-lifetime.test.mjs +140 -0
  281. package/tests/session-shelf-state.test.mjs +348 -0
  282. package/tests/session-shelves-adapter.test.mjs +79 -0
  283. package/tests/session-summary-lifetime.test.mjs +54 -0
  284. package/tests/settings-resource-controller.test.mjs +548 -0
  285. package/tests/shell-action-adapter.test.mjs +169 -0
  286. package/tests/shell-actions.test.mjs +182 -0
  287. package/tests/shell-navigation.test.mjs +348 -0
  288. package/tests/shell-preferences.test.mjs +367 -0
  289. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  290. package/tests/stream-output-isolation-static.test.mjs +1 -1
  291. package/tests/subagent-gate-visibility.test.mjs +1 -1
  292. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  293. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  294. package/tests/subagent-observability-static.test.mjs +2 -2
  295. package/tests/subagent-reliability-integration.test.mjs +13 -30
  296. package/tests/syntax-highlighting-static.test.mjs +3 -3
  297. package/tests/tab-close-continuity-static.test.mjs +1 -1
  298. package/tests/tab-metadata-ordering.test.mjs +99 -0
  299. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  300. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  301. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  302. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  303. package/tests/theme-customizer-static.test.mjs +1 -1
  304. package/tests/thread-display-title.test.mjs +44 -0
  305. package/tests/update-api-harness.test.mjs +15 -14
  306. package/tests/update-tab-restore-harness.test.mjs +3 -0
  307. package/tests/webui-settings-locking.test.mjs +2 -2
  308. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  309. package/tests/workspace-choices.test.mjs +114 -0
  310. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,169 @@
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 { createSessionContext } from '../public/session-context.mjs';
6
+ import { createSessionComposerStore } from '../public/session-composer-store.mjs';
7
+ import { checkActionTarget } from '../public/shell-actions.mjs';
8
+
9
+ const source = readFileSync(new URL('../public/app.js', import.meta.url), 'utf8');
10
+ const names = ['threadDisplayTitle', 'activeTabContext', 'isCurrentTabContext', 'invalidateShellSessionActions', 'shellActionTarget',
11
+ 'commandPaletteCoreItems', 'commandPaletteTabItems', 'commandPaletteModelItems',
12
+ 'commandPaletteSlashItems', 'buildCommandPaletteItems', 'closeCommandPalette',
13
+ 'executeCommandPaletteItem', 'refreshState', 'requestManualCompaction'];
14
+ // Exercise the actual adapters while keeping unrelated rendering and transport isolated.
15
+ const functions = names.map(name => {
16
+ const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
17
+ assert.ok(start >= 0, name);
18
+ const end = source.indexOf('\n}', start);
19
+ assert.ok(end > start, name);
20
+ return source.slice(start, end + 2);
21
+ }).join('\n');
22
+
23
+ function fixture() {
24
+ const context = vm.createContext({ checkActionTarget, createSessionContext, createSessionComposerStore, console, assert });
25
+ vm.runInContext(`
26
+ let activeTabId='tab_12345678', activeTabGeneration=4, shellActionSessionEpoch=0;
27
+ const sessionContext = createSessionContext();
28
+ sessionContext.activate(activeTabId);
29
+ activeTabGeneration=sessionContext.generation;
30
+ const composerStore = createSessionComposerStore();
31
+ const observeSessionState = (context,state) => {sessionContext.observeSession(context.tabId,state?.sessionId); return sessionContext.capture(context.tabId);};
32
+ let tabs=[{id:activeTabId,title:'A',cwd:'/project'}];
33
+ let currentState={sessionId:'session-A',isCompacting:false};
34
+ sessionContext.observeSession(activeTabId,currentState.sessionId);
35
+ let responseState=currentState, requests=[], errors=[], latestMessages=[];
36
+ let tabStateCache=new Map(), availableModels=[];
37
+ let workspaceDashboardCollapsed=false, thinkingOutputVisible=false;
38
+ let toolOutputGloballyExpanded=false, mobilePhoneExperienceInstalled=false;
39
+ const document={body:{classList:{contains(){return false;}}}};
40
+ const elements={compactButton:{disabled:false,textContent:'Compact'},
41
+ commandPaletteDialog:{open:true,close(){this.open=false;}}};
42
+ const noop=()=>{};
43
+ const contextUsageDetail=()=>'', footerAutoCompactionEnabled=()=>true;
44
+ const footerAutoCompactionToggleAction=()=>'', isOptionalFeatureEnabled=()=>false;
45
+ const OPTIONAL_FEATURE_BY_ID=new Map([
46
+ ['tuiToolsCommand',{id:'tuiToolsCommand',setupAvailable:true}],
47
+ ['tuiSkillsCommand',{id:'tuiSkillsCommand',setupAvailable:false}],
48
+ ]);
49
+ const optionalFeatureSetupAvailable=feature=>feature?.setupAvailable===true;
50
+ const setupRequests=[];
51
+ const openOptionalFeatureSetup=feature=>setupRequests.push(feature.id);
52
+ const tabIndicator=()=>({label:'Idle'}), normalizeDisplayPath=value=>value;
53
+ const hasLoadedRpcCommand=()=>false, commandUnavailableMessage=()=>"Unavailable in this fixture";
54
+ const visibleCommands=()=>[], gitFooterRelevantStateChanged=()=>false;
55
+ const modelStateKey=()=>'';
56
+ const syncActiveTabActivityFromState=noop, syncRunIndicatorFromState=noop;
57
+ const renderStatus=noop, requestGitFooterWebuiPayload=noop;
58
+ const setRunIndicatorActivity=noop, scrollChatToBottom=noop;
59
+ const markContextUsageUnknownAfterCompaction=noop, renderFooter=noop;
60
+ const renderContextMeter=noop, renderWorkspaceDashboard=noop;
61
+ const scheduleRefreshState=noop, scheduleRefreshMessages=noop;
62
+ const scheduleRefreshFooter=noop;
63
+ const addEvent=(message,level)=>{if(level==='error')errors.push(message);};
64
+ async function api(path,options={}) {
65
+ requests.push({path,tabId:options.tabId,sessionId:currentState.sessionId});
66
+ return {data:responseState};
67
+ }
68
+ ${functions}
69
+ `, context);
70
+ return code => vm.runInContext(code, context);
71
+ }
72
+
73
+ test('captured action cannot mutate a replacement session in the same tab', async () => {
74
+ const run = fixture();
75
+ await run(`(async () => {
76
+ const captured = buildCommandPaletteItems().find(a => a.id === 'session:compact');
77
+ responseState = { sessionId: 'session-B', isCompacting: false };
78
+ await refreshState();
79
+ requests = [];
80
+ await executeCommandPaletteItem(captured);
81
+ assert.equal(requests.length, 0);
82
+ assert.match(errors[0], /session has changed/);
83
+ assert.equal(elements.commandPaletteDialog.open, true);
84
+ const refreshed = buildCommandPaletteItems().find(a => a.id === 'session:compact');
85
+ await executeCommandPaletteItem(refreshed);
86
+ assert.equal(requests[0].path, '/api/compact');
87
+ assert.equal(requests[0].sessionId, 'session-B');
88
+ })()`);
89
+ });
90
+
91
+ test('confirmed new session invalidates actions before its state refresh', async () => {
92
+ const run = fixture();
93
+ await run(`(async () => {
94
+ const captured = buildCommandPaletteItems().find(a => a.id === 'session:compact');
95
+ invalidateShellSessionActions(activeTabId);
96
+ await executeCommandPaletteItem(captured);
97
+ assert.equal(requests.length, 0);
98
+ assert.match(errors[0], /session has changed/);
99
+ assert.equal(activeTabGeneration, 1);
100
+ })()`);
101
+ assert.match(source, /event.command === "new_session"[\s\S]*?invalidateShellSessionActions\(tabId\)/);
102
+ assert.match(source, /await api\("\/api\/new-session"[\s\S]*?invalidateShellSessionActions\(tabContext.tabId\)/);
103
+ });
104
+
105
+ for (const transition of ['currentState.isCompacting = true', 'composerStore.beginCompaction(activeTabId)']) {
106
+ test(`Compact rechecks live availability: ${transition}`, async () => {
107
+ const run = fixture();
108
+ await run(`(async () => {
109
+ const captured = buildCommandPaletteItems().find(a => a.id === 'session:compact');
110
+ assert.equal(captured.available, true);
111
+ ${transition};
112
+ await executeCommandPaletteItem(captured);
113
+ assert.equal(requests.length, 0);
114
+ assert.match(errors[0], /compaction is already running/);
115
+ assert.equal(elements.commandPaletteDialog.open, true);
116
+ })()`);
117
+ });
118
+ }
119
+
120
+ test('unrelated tab invalidation and same-session refresh retain actions', async () => {
121
+ const run = fixture();
122
+ await run(`(async () => {
123
+ const captured = buildCommandPaletteItems().find(a => a.id === 'session:compact');
124
+ invalidateShellSessionActions('other-tab');
125
+ await refreshState();
126
+ requests = [];
127
+ await executeCommandPaletteItem(captured);
128
+ assert.equal(requests[0].path, '/api/compact');
129
+ assert.equal(errors.length, 0);
130
+ })()`);
131
+ });
132
+
133
+ test('a pending real compaction request rejects a second palette invocation and releases its lock', async () => {
134
+ const run = fixture();
135
+ await run(`(async () => {
136
+ const captured = buildCommandPaletteItems().find(a => a.id === 'session:compact');
137
+ let release, requestCount = 0;
138
+ api = async () => { requestCount += 1; return new Promise(resolve => { release = resolve; }); };
139
+ const first = requestManualCompaction();
140
+ assert.equal(composerStore.isCompactionPending(activeTabId), true);
141
+ await executeCommandPaletteItem(captured);
142
+ assert.equal(requestCount, 1);
143
+ assert.match(errors[0], /compaction is already running/);
144
+ release({ data: {} });
145
+ await first;
146
+ assert.equal(composerStore.isCompactionPending(activeTabId), false);
147
+ assert.equal(buildCommandPaletteItems().find(a => a.id === 'session:compact').available, true);
148
+ })()`);
149
+ });
150
+
151
+
152
+ test('explicit Setup actions retain current availability and captured session checks', async () => {
153
+ const run = fixture();
154
+ await run(`(async () => {
155
+ const tools = buildCommandPaletteItems().find(action => action.id === 'settings:tools-setup');
156
+ const skills = buildCommandPaletteItems().find(action => action.id === 'settings:skills-setup');
157
+ assert.equal(tools.available, true);
158
+ assert.equal(skills.available, false);
159
+ await executeCommandPaletteItem(skills);
160
+ assert.equal(setupRequests.length, 0);
161
+ await executeCommandPaletteItem(tools);
162
+ assert.equal(setupRequests[0], 'tuiToolsCommand');
163
+ setupRequests.length = 0;
164
+ invalidateShellSessionActions(activeTabId);
165
+ await executeCommandPaletteItem(tools);
166
+ assert.equal(setupRequests.length, 0);
167
+ assert.match(errors.at(-1), /session has changed/);
168
+ })()`);
169
+ });
@@ -0,0 +1,182 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { filterActionItems, checkActionTarget } from "../public/shell-actions.mjs";
4
+
5
+ test("search matches every case-insensitive token across the existing metadata fields", () => {
6
+ const matching = { label: "Files panel", description: "Browse the project", kind: "Action", keywords: "tree explorer" };
7
+ const items = [matching, { label: "Files", description: "Browse", kind: "Action", keywords: "tree" }];
8
+ assert.deepEqual(filterActionItems(items, " FILES\tproject\nACTION explorer "), [matching]);
9
+ assert.deepEqual(filterActionItems(items, "files missing"), []);
10
+ assert.deepEqual(filterActionItems([{ label: 42, keywords: ["Alpha", "Beta"] }], "42 alpha beta"), [
11
+ { label: 42, keywords: ["Alpha", "Beta"] },
12
+ ]);
13
+ });
14
+
15
+ test("ranking preserves label prefix, slash prefix, word start, substring and metadata order", () => {
16
+ const items = [
17
+ { label: "Other", description: "model" },
18
+ { label: "Remodel" },
19
+ { label: "Choose model" },
20
+ { label: "/model" },
21
+ { label: "Model picker" },
22
+ ];
23
+ assert.deepEqual(filterActionItems(items, "MODEL"), [items[4], items[3], items[2], items[1], items[0]]);
24
+ assert.deepEqual(filterActionItems(items, "/mod"), [items[3]]);
25
+ });
26
+
27
+ test("word starts include spaces, slashes, underscores and hyphens, with stable ties", () => {
28
+ const items = ["remodel", "choose/model", "choose_model", "choose-model", "choose model"].map((label) => ({ label }));
29
+ assert.deepEqual(filterActionItems(items, "model"), [...items.slice(1), items[0]]);
30
+ const ties = [{ label: "One", keywords: "find" }, { label: "Two", description: "find" }, { label: "Three", kind: "find" }];
31
+ assert.deepEqual(filterActionItems(ties, "find"), ties);
32
+ });
33
+
34
+ test("scores accumulate across tokens rather than favoring only the first token", () => {
35
+ const items = [
36
+ { label: "Open result", keywords: "file" },
37
+ { label: "Open file" },
38
+ { label: "File open" },
39
+ ];
40
+ assert.deepEqual(filterActionItems(items, "open file"), [items[1], items[2], items[0]]);
41
+ });
42
+
43
+ test("regular expression characters in queries stay literal", () => {
44
+ for (const token of [".", "*", "+", "?", "^", "$", "{", "}", "(", ")", "|", "[", "]", "\\", "a+b", "[x]", "foo.bar"]) {
45
+ const items = [{ label: `inside${token}value` }, { label: `choose ${token}value` }, { label: "Unrelated" }];
46
+ assert.deepEqual(filterActionItems(items, token), [items[1], items[0]], token);
47
+ }
48
+ });
49
+
50
+ test("empty queries retain catalog order and both search paths honor default and custom limits", () => {
51
+ const items = Array.from({ length: 100 }, (_, index) => ({ label: `Action ${index}` }));
52
+ for (const query of ["", " \t\n ", undefined, null, "action"]) {
53
+ assert.deepEqual(filterActionItems(items, query), items.slice(0, 80));
54
+ assert.deepEqual(filterActionItems(items, query, { limit: 3 }), items.slice(0, 3));
55
+ assert.deepEqual(filterActionItems(items, query, { limit: 0 }), []);
56
+ assert.deepEqual(filterActionItems(items, query, { limit: 120 }), items);
57
+ }
58
+ const ranked = [{ label: "Other", keywords: "model" }, { label: "Model" }];
59
+ assert.deepEqual(filterActionItems(ranked, "model", { limit: 1 }), [ranked[1]]);
60
+ assert.deepEqual(filterActionItems([], "anything"), []);
61
+ });
62
+
63
+ test("aliases extend discovery without changing labels or label-based ranking", () => {
64
+ const items = [
65
+ { label: "Files", aliases: ["Explorer", "Project browser"] },
66
+ { label: "Other", aliases: "Explorer" },
67
+ { label: "Explorer" },
68
+ ];
69
+ assert.deepEqual(filterActionItems(items, "explorer"), [items[2], items[0], items[1]]);
70
+ assert.deepEqual(filterActionItems(items, "FILES project BROWSER"), [items[0]]);
71
+ assert.deepEqual(filterActionItems(items, "other EXPLORER"), [items[1]]);
72
+ });
73
+
74
+ test("discovery preserves unavailable entries and never mutates records or runs handlers", () => {
75
+ const run = () => assert.fail("Discovery must not execute an action");
76
+ const items = Object.freeze([
77
+ Object.freeze({ label: "Other", keywords: "model", run }),
78
+ Object.freeze({ label: "Model", aliases: Object.freeze(["llm"]), available: false, unavailableReason: "No provider", run }),
79
+ ]);
80
+ const result = filterActionItems(items, "model");
81
+ assert.equal(result[0], items[1]);
82
+ assert.equal(result[1], items[0]);
83
+ assert.equal(items[0].label, "Other");
84
+ assert.equal(items[1].available, false);
85
+ assert.notEqual(filterActionItems(items, ""), items);
86
+ });
87
+
88
+ const currentTarget = Object.freeze({ tabId: "tab-a", generation: 4, sessionIdentity: "session-a", cwd: "/project", liveTabIds: Object.freeze(["tab-a", "tab-b"]) });
89
+ const sessionTarget = Object.freeze({ tabId: "tab-a", generation: 4, sessionIdentity: "session-a" });
90
+
91
+ function assertRejected(action, current, reasonPattern) {
92
+ const result = checkActionTarget(action, current);
93
+ assert.equal(result.ok, false);
94
+ assert.equal(typeof result.reason, "string");
95
+ assert.ok(result.reason.trim().length > 0);
96
+ if (reasonPattern) assert.match(result.reason, reasonPattern);
97
+ }
98
+
99
+ test("browser and server actions require no session identity", () => {
100
+ for (const scope of ["browser", "server"]) {
101
+ assert.deepEqual(checkActionTarget({ scope }), { ok: true, reason: "" });
102
+ assert.deepEqual(checkActionTarget({ scope, target: { tabId: "old", generation: -1 } }, currentTarget), { ok: true, reason: "" });
103
+ }
104
+ });
105
+
106
+ test("session actions require the captured tab and numeric nonnegative integer generation", () => {
107
+ assert.deepEqual(checkActionTarget({ scope: "session", target: sessionTarget }, currentTarget), { ok: true, reason: "" });
108
+ assert.deepEqual(checkActionTarget({ scope: "session", target: { tabId: "tab-a", generation: 0, sessionIdentity: "session-a" } }, { tabId: "tab-a", generation: 0, sessionIdentity: "session-a" }), { ok: true, reason: "" });
109
+ assertRejected({ scope: "session", target: sessionTarget }, { ...currentTarget, generation: 5 }, /session/i);
110
+ assertRejected({ scope: "session", target: sessionTarget }, { ...currentTarget, tabId: "tab-b" }, /thread/i);
111
+ for (const generation of [undefined, null, "4", -1, 1.5, NaN, Infinity, -Infinity, false]) {
112
+ assertRejected({ scope: "session", target: { tabId: "tab-a", generation } }, { ...currentTarget, generation }, /generation/i);
113
+ }
114
+ for (const current of [undefined, null, {}, { tabId: "tab-a" }, { generation: 4 }, { tabId: "tab-a", generation: "4" }]) {
115
+ assertRejected({ scope: "session", target: sessionTarget }, current);
116
+ }
117
+ });
118
+
119
+ test("project actions additionally require the exact captured working directory", () => {
120
+ const action = { scope: "project", target: { ...sessionTarget, cwd: "/project" } };
121
+ assert.deepEqual(checkActionTarget(action, currentTarget), { ok: true, reason: "" });
122
+ for (const cwd of [undefined, null, "", " ", 42]) {
123
+ assertRejected({ ...action, target: { ...sessionTarget, cwd } }, { ...currentTarget, cwd }, /directory/i);
124
+ }
125
+ for (const cwd of [undefined, "/other", "/Project", "/project/", "/project "]) {
126
+ assertRejected(action, { ...currentTarget, cwd }, /directory/i);
127
+ }
128
+ assertRejected(action, { ...currentTarget, generation: 5 }, /session/i);
129
+ assertRejected(action, { ...currentTarget, tabId: "tab-b" }, /thread/i);
130
+ assert.deepEqual(checkActionTarget({ scope: "session", target: sessionTarget }, { ...currentTarget, cwd: "/other" }), { ok: true, reason: "" });
131
+ });
132
+
133
+ test("missing or unknown scopes and incomplete target identities fail closed", () => {
134
+ for (const action of [undefined, null, {}, { target: sessionTarget }, { scope: "workspace" }, { scope: "Session" }, { scope: "" }]) {
135
+ assertRejected(action, currentTarget, /scope/i);
136
+ }
137
+ for (const scope of ["session", "project", "tab"]) {
138
+ for (const target of [undefined, null, {}, { generation: 4 }, { tabId: "" }, { tabId: " " }, { tabId: 42 }]) {
139
+ assertRejected({ scope, target }, currentTarget, /thread/i);
140
+ }
141
+ }
142
+ });
143
+
144
+ test("availability rejects every scope with an explicit reason or meaningful default", () => {
145
+ for (const scope of ["browser", "server", "session", "project", "tab"]) {
146
+ assert.deepEqual(checkActionTarget({ scope, available: false, unavailableReason: "Enable the companion first" }, currentTarget), {
147
+ ok: false, reason: "Enable the companion first",
148
+ });
149
+ for (const unavailableReason of [undefined, null, "", " ", 42]) {
150
+ assertRejected({ scope, available: false, unavailableReason }, currentTarget, /unavailable/i);
151
+ }
152
+ }
153
+ assert.deepEqual(checkActionTarget({ scope: "browser", available: true, unavailableReason: "Old reason" }), { ok: true, reason: "" });
154
+ });
155
+
156
+ test("explicit tab selection checks live membership independently of the active tab or generation", () => {
157
+ const action = { scope: "tab", target: { tabId: "tab-b" } };
158
+ assert.deepEqual(checkActionTarget(action, currentTarget), { ok: true, reason: "" });
159
+ assert.deepEqual(checkActionTarget(action, { liveTabIds: ["tab-b"] }), { ok: true, reason: "" });
160
+ assertRejected(action, { ...currentTarget, liveTabIds: ["tab-a"] }, /thread/i);
161
+ for (const current of [undefined, {}, { liveTabIds: "tab-b" }, { liveTabIds: new Set(["tab-b"]) }]) {
162
+ assertRejected(action, current);
163
+ }
164
+ assertRejected({ ...action, available: false }, currentTarget, /unavailable/i);
165
+ });
166
+
167
+ test("target checks retain no state, mutate no records and never execute handlers", () => {
168
+ const action = Object.freeze({ scope: "project", target: Object.freeze({ ...sessionTarget, cwd: "/project" }), run: () => assert.fail("Target checks must not execute actions") });
169
+ assert.deepEqual(checkActionTarget(action, currentTarget), { ok: true, reason: "" });
170
+ assertRejected(action, { ...currentTarget, generation: 5 });
171
+ assert.deepEqual(checkActionTarget(action, currentTarget), { ok: true, reason: "" });
172
+ });
173
+
174
+ test("same-tab session identity changes invalidate session and project actions", () => {
175
+ for (const scope of ["session", "project"]) {
176
+ const action = { scope, target: { ...sessionTarget, cwd: "/project" } };
177
+ for (const sessionIdentity of ["session-b", "", undefined, null]) {
178
+ assertRejected(action, { ...currentTarget, sessionIdentity }, /session/i);
179
+ }
180
+ assertRejected({ ...action, target: { ...action.target, sessionIdentity: undefined } }, currentTarget, /session/i);
181
+ }
182
+ });