@zyro-sec/app 0.0.0-stage → 1.0.1

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 (1360) hide show
  1. package/AGENTS.md +234 -0
  2. package/README.md +106 -2
  3. package/bunfig.toml +3 -0
  4. package/component-tests/activity-chips.spec.ts +47 -0
  5. package/component-tests/browser-pane-restore.spec.ts +1294 -0
  6. package/component-tests/browser-pane.spec.ts +2338 -0
  7. package/component-tests/browser-settings.spec.ts +315 -0
  8. package/component-tests/browser-site-chooser.spec.ts +628 -0
  9. package/component-tests/components-lab.spec.ts +24 -0
  10. package/component-tests/composer.spec.ts +876 -0
  11. package/component-tests/debug-bar.spec.ts +237 -0
  12. package/component-tests/dialog-popups.spec.ts +49 -0
  13. package/component-tests/file-icon.spec.ts +14 -0
  14. package/component-tests/focus-rescue.fixture.tsx +30 -0
  15. package/component-tests/focus-rescue.spec.ts +83 -0
  16. package/component-tests/focus-ring.spec.ts +112 -0
  17. package/component-tests/fork-dialog.spec.ts +61 -0
  18. package/component-tests/grow.fixture.tsx +42 -0
  19. package/component-tests/grow.spec.ts +74 -0
  20. package/component-tests/image-preview.spec.ts +157 -0
  21. package/component-tests/input-surfaces.spec.ts +351 -0
  22. package/component-tests/line-comment.spec.ts +118 -0
  23. package/component-tests/list.spec.ts +7 -0
  24. package/component-tests/model-picker.spec.ts +45 -0
  25. package/component-tests/new-session-wordmark.spec.ts +135 -0
  26. package/component-tests/open-in-border.spec.ts +18 -0
  27. package/component-tests/pairing.spec.ts +40 -0
  28. package/component-tests/panel-sidebar-side.spec.ts +103 -0
  29. package/component-tests/plugin-graph.spec.ts +61 -0
  30. package/component-tests/plugin-host.fixture.tsx +995 -0
  31. package/component-tests/plugin-host.spec.ts +2362 -0
  32. package/component-tests/presence.fixture.tsx +59 -0
  33. package/component-tests/presence.spec.ts +104 -0
  34. package/component-tests/session-containment.fixture.tsx +79 -0
  35. package/component-tests/session-containment.spec.ts +145 -0
  36. package/component-tests/session-location-missing.spec.ts +52 -0
  37. package/component-tests/session-question-dock.spec.ts +1655 -0
  38. package/component-tests/sources-experiment.spec.ts +98 -0
  39. package/component-tests/ssh-reconnect.spec.ts +97 -0
  40. package/component-tests/subagent-bar.spec.ts +29 -0
  41. package/component-tests/terminal.spec.ts +148 -0
  42. package/component-tests/timeline-detail.spec.ts +311 -0
  43. package/component-tests/timeline-virtualizer.fixture.tsx +272 -0
  44. package/component-tests/timeline-virtualizer.spec.ts +269 -0
  45. package/component-tests/toast.spec.ts +23 -0
  46. package/component-tests/tooltip.spec.ts +169 -0
  47. package/component-tests/websearch.spec.ts +86 -0
  48. package/e2e/AGENTS.md +25 -0
  49. package/e2e/QUARANTINE.md +12 -0
  50. package/e2e/regression/background-read-failure.spec.ts +43 -0
  51. package/e2e/regression/btw-sidebar.spec.ts +339 -0
  52. package/e2e/regression/command-palette.spec.ts +822 -0
  53. package/e2e/regression/composer.spec.ts +1727 -0
  54. package/e2e/regression/directory-picker.spec.ts +133 -0
  55. package/e2e/regression/home.spec.ts +779 -0
  56. package/e2e/regression/mcp-workspace-toggle.spec.ts +695 -0
  57. package/e2e/regression/menu-scrollbars.spec.ts +78 -0
  58. package/e2e/regression/mobile-composer-submit-focus.spec.ts +88 -0
  59. package/e2e/regression/mobile-model-pickers.spec.ts +433 -0
  60. package/e2e/regression/mobile-plugin-drawers.spec.ts +194 -0
  61. package/e2e/regression/mobile-plugins.spec.ts +309 -0
  62. package/e2e/regression/mobile-session-options.spec.ts +101 -0
  63. package/e2e/regression/mobile-session.spec.ts +442 -0
  64. package/e2e/regression/mobile-timeline-scroll.spec.ts +919 -0
  65. package/e2e/regression/multi-server.spec.ts +498 -0
  66. package/e2e/regression/new-session.spec.ts +1666 -0
  67. package/e2e/regression/panel-edges.spec.ts +79 -0
  68. package/e2e/regression/patch-border.spec.ts +69 -0
  69. package/e2e/regression/patch-sticky-header.spec.ts +320 -0
  70. package/e2e/regression/review.spec.ts +2397 -0
  71. package/e2e/regression/session-header.spec.ts +1020 -0
  72. package/e2e/regression/session-location-sync.spec.ts +412 -0
  73. package/e2e/regression/session-notice-truncation.spec.ts +92 -0
  74. package/e2e/regression/session-panel-scrollbar.spec.ts +46 -0
  75. package/e2e/regression/session-queue.spec.ts +1704 -0
  76. package/e2e/regression/session-request-docks.spec.ts +719 -0
  77. package/e2e/regression/session-summary.spec.ts +1092 -0
  78. package/e2e/regression/session-timeline-accessibility.spec.ts +216 -0
  79. package/e2e/regression/session-timeline-locale-projection.spec.ts +24 -0
  80. package/e2e/regression/session-timeline-reducer-projection.spec.ts +53 -0
  81. package/e2e/regression/session-timeline-tool-projection.spec.ts +94 -0
  82. package/e2e/regression/session-websearch-dock.spec.ts +122 -0
  83. package/e2e/regression/settings-search.spec.ts +516 -0
  84. package/e2e/regression/settings-wsl.spec.ts +433 -0
  85. package/e2e/regression/settings.spec.ts +2901 -0
  86. package/e2e/regression/shell-panel-spacing.spec.ts +95 -0
  87. package/e2e/regression/side-panels.spec.ts +524 -0
  88. package/e2e/regression/subagent-child-navigation.spec.ts +540 -0
  89. package/e2e/regression/tabs.spec.ts +3294 -0
  90. package/e2e/regression/terminal.spec.ts +691 -0
  91. package/e2e/regression/timeline-cache.spec.ts +798 -0
  92. package/e2e/regression/timeline-geometry.spec.ts +1204 -0
  93. package/e2e/regression/timeline-history.spec.ts +1073 -0
  94. package/e2e/regression/timeline-stream.spec.ts +3409 -0
  95. package/e2e/regression/whats-new.spec.ts +242 -0
  96. package/e2e/reproduction/timeline-suspense/index.html +34 -0
  97. package/e2e/reproduction/timeline-suspense/main.tsx +335 -0
  98. package/e2e/reproduction/timeline-suspense/playwright.config.ts +34 -0
  99. package/e2e/reproduction/timeline-suspense/timeline-suspense.repro.ts +182 -0
  100. package/e2e/reproduction/timeline-suspense/vite.config.ts +7 -0
  101. package/e2e/screenshots/session-project-menu.png +0 -0
  102. package/e2e/service-worker/cache.spec.ts +573 -0
  103. package/e2e/service-worker/playwright.config.ts +14 -0
  104. package/e2e/stability/README.md +61 -0
  105. package/e2e/stability/adverse.spec.ts +279 -0
  106. package/e2e/stability/environment-matrix.spec.ts +128 -0
  107. package/e2e/stability/file-matrix.spec.ts +133 -0
  108. package/e2e/stability/file-mutation.spec.ts +126 -0
  109. package/e2e/stability/fixture.test.ts +80 -0
  110. package/e2e/stability/interaction.spec.ts +232 -0
  111. package/e2e/stability/lifecycle.spec.ts +175 -0
  112. package/e2e/stability/oracle-browser.spec.ts +81 -0
  113. package/e2e/stability/oracle.test.ts +388 -0
  114. package/e2e/stability/playwright.config.ts +31 -0
  115. package/e2e/stability/scroll-interaction.spec.ts +520 -0
  116. package/e2e/stability/shell-matrix.spec.ts +299 -0
  117. package/e2e/stability/tool-mutation.spec.ts +58 -0
  118. package/e2e/stability/tools.spec.ts +232 -0
  119. package/e2e/stability/transition-matrix.spec.ts +214 -0
  120. package/e2e/tsconfig.json +11 -0
  121. package/e2e/user-story/model-selection-flow.spec.ts +216 -0
  122. package/e2e/utils/app-direction.fixture.tsx +105 -0
  123. package/e2e/utils/app-direction.html +25 -0
  124. package/e2e/utils/app.ts +227 -0
  125. package/e2e/utils/command-palette.ts +62 -0
  126. package/e2e/utils/console.ts +23 -0
  127. package/e2e/utils/direction.ts +28 -0
  128. package/e2e/utils/drafts.ts +52 -0
  129. package/e2e/utils/errors.ts +14 -0
  130. package/e2e/utils/markdown-sessions.ts +120 -0
  131. package/e2e/utils/mock-api.ts +570 -0
  132. package/e2e/utils/mock-server.ts +1726 -0
  133. package/e2e/utils/notifications.ts +51 -0
  134. package/e2e/utils/persistent-pty.ts +546 -0
  135. package/e2e/utils/prompt-motion.ts +116 -0
  136. package/e2e/utils/serve.ts +65 -0
  137. package/e2e/utils/session-fixture.ts +472 -0
  138. package/e2e/utils/settings-wsl.fixture.tsx +416 -0
  139. package/e2e/utils/settings-wsl.html +27 -0
  140. package/e2e/utils/side-panel.ts +41 -0
  141. package/e2e/utils/sse-transport.ts +352 -0
  142. package/e2e/utils/terminal.ts +31 -0
  143. package/e2e/utils/timeline.ts +1141 -0
  144. package/e2e/utils/visual-stability/analyzer.ts +259 -0
  145. package/e2e/utils/visual-stability/capture.ts +57 -0
  146. package/e2e/utils/visual-stability/index.ts +15 -0
  147. package/e2e/utils/visual-stability/invariant.ts +113 -0
  148. package/e2e/utils/visual-stability/model.ts +47 -0
  149. package/e2e/utils/visual-stability/probe.ts +261 -0
  150. package/e2e/utils/visual-stability/regions.ts +18 -0
  151. package/e2e/utils/visual-stability/reporter.ts +71 -0
  152. package/e2e/utils/visual-stability/scenario.ts +21 -0
  153. package/e2e/utils/visual-stability.ts +52 -0
  154. package/e2e/utils/waits.ts +25 -0
  155. package/e2e/utils/windows-menu.fixture.tsx +99 -0
  156. package/e2e/utils/windows-menu.html +22 -0
  157. package/e2e/utils/workspace.ts +222 -0
  158. package/happydom.ts +77 -0
  159. package/index.html +29 -0
  160. package/manifest.json +36 -0
  161. package/package.json +83 -4
  162. package/perf/README.md +190 -0
  163. package/perf/composer.bench.ts +107 -0
  164. package/perf/desktop.bench.ts +22 -0
  165. package/perf/diff.bench.ts +104 -0
  166. package/perf/docks.bench.ts +109 -0
  167. package/perf/fixtures/composer.ts +166 -0
  168. package/perf/fixtures/diffs.ts +165 -0
  169. package/perf/fixtures/drag.ts +73 -0
  170. package/perf/fixtures/events.ts +106 -0
  171. package/perf/fixtures/home.ts +274 -0
  172. package/perf/fixtures/mock.ts +118 -0
  173. package/perf/fixtures/review.ts +33 -0
  174. package/perf/fixtures/scripts.ts +37 -0
  175. package/perf/fixtures/storage.ts +29 -0
  176. package/perf/fixtures/tabs.ts +21 -0
  177. package/perf/fixtures/timeline.ts +458 -0
  178. package/perf/home.bench.ts +74 -0
  179. package/perf/model-picker.bench.ts +168 -0
  180. package/perf/navigation.bench.ts +310 -0
  181. package/perf/question.bench.ts +85 -0
  182. package/perf/review.bench.ts +109 -0
  183. package/perf/send.bench.ts +54 -0
  184. package/perf/stream.bench.ts +108 -0
  185. package/perf/subagent-pill.bench.ts +348 -0
  186. package/perf/tabs.bench.ts +229 -0
  187. package/perf/timeline.bench.ts +167 -0
  188. package/playwright.components.config.ts +7 -0
  189. package/playwright.config.ts +85 -0
  190. package/public/_headers +28 -0
  191. package/public/assets/Inter.ttf +0 -0
  192. package/public/assets/JetBrainsMonoNerdFontMono-Bold.woff2 +0 -0
  193. package/public/assets/JetBrainsMonoNerdFontMono-Regular.woff2 +0 -0
  194. package/public/oc-theme-preload.js +33 -0
  195. package/src/app.tsx +142 -0
  196. package/src/components-lab/browser.tsx +745 -0
  197. package/src/components-lab/catalog.test.ts +58 -0
  198. package/src/components-lab/catalog.ts +195 -0
  199. package/src/components-lab/dialog-story-runtime.tsx +840 -0
  200. package/src/components-lab/focus-rings.stories.tsx +710 -0
  201. package/src/components-lab/focus-visibility.stories.tsx +2669 -0
  202. package/src/components-lab/force-focus.ts +52 -0
  203. package/src/components-lab/inspector.css +28 -0
  204. package/src/components-lab/lab.tsx +114 -0
  205. package/src/components-lab/machine.test.ts +177 -0
  206. package/src/components-lab/machine.ts +229 -0
  207. package/src/components-lab/motion.test.ts +17 -0
  208. package/src/components-lab/motion.ts +100 -0
  209. package/src/composer/adapter.ts +151 -0
  210. package/src/composer/attachments/attachments.css +123 -0
  211. package/src/composer/attachments/attachments.ts +363 -0
  212. package/src/composer/attachments/destination.ts +81 -0
  213. package/src/composer/attachments/upload-machine.ts +185 -0
  214. package/src/composer/attachments/uploads.test.ts +127 -0
  215. package/src/composer/attachments/uploads.tsx +228 -0
  216. package/src/composer/client-slash-command.test.ts +20 -0
  217. package/src/composer/client-slash-command.ts +28 -0
  218. package/src/composer/commands.tsx +175 -0
  219. package/src/composer/comment-focus-machine.test.ts +112 -0
  220. package/src/composer/comment-focus-machine.ts +141 -0
  221. package/src/composer/comment-note.test.ts +82 -0
  222. package/src/composer/comment-note.ts +127 -0
  223. package/src/composer/comments.test.ts +109 -0
  224. package/src/composer/comments.tsx +279 -0
  225. package/src/composer/composer-touch.stories.tsx +298 -0
  226. package/src/composer/composer.stories.tsx +765 -0
  227. package/src/composer/composer.tsx +244 -0
  228. package/src/composer/dropzone.tsx +92 -0
  229. package/src/composer/editor/actions.test.ts +176 -0
  230. package/src/composer/editor/actions.ts +191 -0
  231. package/src/composer/editor/dom.test.ts +168 -0
  232. package/src/composer/editor/dom.ts +274 -0
  233. package/src/composer/editor/editor.css +101 -0
  234. package/src/composer/editor/editor.tsx +1764 -0
  235. package/src/composer/editor/interaction.test.ts +13 -0
  236. package/src/composer/editor/interaction.ts +838 -0
  237. package/src/composer/editor/machine.test.ts +47 -0
  238. package/src/composer/editor/machine.ts +63 -0
  239. package/src/composer/editor/mention-search-machine.test.ts +111 -0
  240. package/src/composer/editor/mention-search-machine.ts +226 -0
  241. package/src/composer/editor/quote-comment.stories.tsx +133 -0
  242. package/src/composer/editor/quote-comment.tsx +191 -0
  243. package/src/composer/history/entry.test.ts +100 -0
  244. package/src/composer/history/entry.ts +140 -0
  245. package/src/composer/history/store.ts +83 -0
  246. package/src/composer/machine.test.ts +459 -0
  247. package/src/composer/machine.ts +561 -0
  248. package/src/composer/media.ts +18 -0
  249. package/src/composer/model-chip-machine.test.ts +96 -0
  250. package/src/composer/model-chip-machine.ts +82 -0
  251. package/src/composer/model-label.test.ts +177 -0
  252. package/src/composer/model-label.ts +120 -0
  253. package/src/composer/model.ts +683 -0
  254. package/src/composer/persistence.tsx +163 -0
  255. package/src/composer/prompt-parts.ts +52 -0
  256. package/src/composer/prompt-status-machine.test.ts +76 -0
  257. package/src/composer/prompt-status-machine.ts +48 -0
  258. package/src/composer/prompt.test.ts +320 -0
  259. package/src/composer/prompt.ts +334 -0
  260. package/src/composer/quote-comment-machine.test.ts +154 -0
  261. package/src/composer/quote-comment-machine.ts +211 -0
  262. package/src/composer/quote-position.ts +32 -0
  263. package/src/composer/quote-source.ts +48 -0
  264. package/src/composer/reload-machine.ts +51 -0
  265. package/src/composer/request.test.ts +360 -0
  266. package/src/composer/request.ts +245 -0
  267. package/src/composer/retry.test.ts +107 -0
  268. package/src/composer/retry.ts +63 -0
  269. package/src/composer/schema.test.ts +317 -0
  270. package/src/composer/schema.ts +424 -0
  271. package/src/composer/selection.ts +354 -0
  272. package/src/composer/session-match.test.ts +20 -0
  273. package/src/composer/session-match.ts +18 -0
  274. package/src/composer/state.ts +271 -0
  275. package/src/composer/submission-state.ts +3 -0
  276. package/src/composer/submit.test.ts +1785 -0
  277. package/src/composer/submit.ts +1073 -0
  278. package/src/composer/suggestions/machine.test.ts +420 -0
  279. package/src/composer/suggestions/machine.ts +573 -0
  280. package/src/composer/types.ts +60 -0
  281. package/src/desktop.ts +25 -0
  282. package/src/entry.tsx +119 -0
  283. package/src/env.d.ts +41 -0
  284. package/src/home/home.standalone.stories.tsx +260 -0
  285. package/src/home/machine.test.ts +286 -0
  286. package/src/home/machine.ts +344 -0
  287. package/src/home/model.ts +162 -0
  288. package/src/home/projects/actions.tsx +189 -0
  289. package/src/home/projects/add.ts +10 -0
  290. package/src/home/projects/browse-view.tsx +264 -0
  291. package/src/home/projects/browse.tsx +33 -0
  292. package/src/home/projects/controller.tsx +109 -0
  293. package/src/home/projects/file-manager.ts +26 -0
  294. package/src/home/projects/import-machine.test.ts +117 -0
  295. package/src/home/projects/import-machine.ts +133 -0
  296. package/src/home/projects/landing.tsx +77 -0
  297. package/src/home/projects/menu.tsx +70 -0
  298. package/src/home/projects/region.tsx +63 -0
  299. package/src/home/projects/reveal.ts +39 -0
  300. package/src/home/projects/start.ts +114 -0
  301. package/src/home/projects/view.css +79 -0
  302. package/src/home/projects/view.tsx +763 -0
  303. package/src/home/route.tsx +177 -0
  304. package/src/home/scroll.ts +180 -0
  305. package/src/home/sessions/alt-hold.test.ts +45 -0
  306. package/src/home/sessions/alt-hold.ts +20 -0
  307. package/src/home/sessions/archive.test.ts +51 -0
  308. package/src/home/sessions/archive.ts +25 -0
  309. package/src/home/sessions/controller.tsx +669 -0
  310. package/src/home/sessions/delete-dialog.stories.tsx +70 -0
  311. package/src/home/sessions/index.test.ts +171 -0
  312. package/src/home/sessions/index.ts +60 -0
  313. package/src/home/sessions/load-machine.test.ts +223 -0
  314. package/src/home/sessions/load-machine.ts +430 -0
  315. package/src/home/sessions/open.test.ts +16 -0
  316. package/src/home/sessions/open.ts +18 -0
  317. package/src/home/sessions/queries.ts +95 -0
  318. package/src/home/sessions/records.test.ts +85 -0
  319. package/src/home/sessions/records.ts +58 -0
  320. package/src/home/sessions/region.tsx +66 -0
  321. package/src/home/sessions/row-machine.test.ts +203 -0
  322. package/src/home/sessions/row-machine.ts +365 -0
  323. package/src/home/sessions/search-machine.test.ts +117 -0
  324. package/src/home/sessions/search-machine.ts +181 -0
  325. package/src/home/sessions/search.ts +218 -0
  326. package/src/home/sessions/view.css +101 -0
  327. package/src/home/sessions/view.tsx +1123 -0
  328. package/src/home/start/command-palette.tsx +88 -0
  329. package/src/index.css +419 -0
  330. package/src/index.ts +5 -0
  331. package/src/new-session/brick-breaker-machine.test.ts +120 -0
  332. package/src/new-session/brick-breaker-machine.ts +110 -0
  333. package/src/new-session/brick-breaker.tsx +551 -0
  334. package/src/new-session/commands.tsx +61 -0
  335. package/src/new-session/composer-adapter.ts +309 -0
  336. package/src/new-session/draft.standalone.stories.tsx +214 -0
  337. package/src/new-session/layout.ts +2 -0
  338. package/src/new-session/location/dialog.css +204 -0
  339. package/src/new-session/location/dialog.standalone.stories.tsx +122 -0
  340. package/src/new-session/location/dialog.tsx +677 -0
  341. package/src/new-session/location/machine.test.ts +180 -0
  342. package/src/new-session/location/machine.ts +239 -0
  343. package/src/new-session/machine.test.ts +344 -0
  344. package/src/new-session/machine.ts +293 -0
  345. package/src/new-session/mcp.ts +132 -0
  346. package/src/new-session/pin-board-machine.test.ts +116 -0
  347. package/src/new-session/pin-board-machine.ts +188 -0
  348. package/src/new-session/pin-board.tsx +1072 -0
  349. package/src/new-session/pin-quads.ts +252 -0
  350. package/src/new-session/pin-sound.ts +193 -0
  351. package/src/new-session/project/controller.ts +111 -0
  352. package/src/new-session/project/selector.test.tsx +101 -0
  353. package/src/new-session/project/selector.tsx +108 -0
  354. package/src/new-session/route.tsx +115 -0
  355. package/src/new-session/screen.tsx +107 -0
  356. package/src/new-session/view.tsx +424 -0
  357. package/src/new-session/wordmark-machine.test.ts +236 -0
  358. package/src/new-session/wordmark-machine.ts +237 -0
  359. package/src/new-session/wordmark.css +71 -0
  360. package/src/new-session/wordmark.stories.tsx +109 -0
  361. package/src/new-session/wordmark.tsx +1222 -0
  362. package/src/new-session/workspace/branch-machine.test.ts +243 -0
  363. package/src/new-session/workspace/branch-machine.ts +233 -0
  364. package/src/new-session/workspace/checkout-machine.test.ts +73 -0
  365. package/src/new-session/workspace/checkout-machine.ts +69 -0
  366. package/src/new-session/workspace/controller.test.ts +82 -0
  367. package/src/new-session/workspace/controller.ts +291 -0
  368. package/src/new-session/workspace/selector.tsx +230 -0
  369. package/src/providers/catalog/console-settle.ts +80 -0
  370. package/src/providers/catalog/console.test.ts +21 -0
  371. package/src/providers/catalog/console.ts +37 -0
  372. package/src/providers/catalog/integrations.ts +30 -0
  373. package/src/providers/catalog/order.ts +10 -0
  374. package/src/providers/catalog/plugin.ts +15 -0
  375. package/src/providers/catalog/providers.ts +111 -0
  376. package/src/providers/catalog/settle-machine.test.ts +123 -0
  377. package/src/providers/catalog/settle-machine.ts +109 -0
  378. package/src/providers/connect/chatgpt-usage-limit.stories.tsx +25 -0
  379. package/src/providers/connect/chatgpt-usage-limit.tsx +83 -0
  380. package/src/providers/connect/chatgpt-welcome.stories.tsx +23 -0
  381. package/src/providers/connect/chatgpt-welcome.tsx +37 -0
  382. package/src/providers/connect/console.tsx +67 -0
  383. package/src/providers/connect/controller.ts +672 -0
  384. package/src/providers/connect/dialog-machine.test.ts +654 -0
  385. package/src/providers/connect/dialog-machine.ts +875 -0
  386. package/src/providers/connect/dialog.standalone.stories.tsx +187 -0
  387. package/src/providers/connect/dialog.tsx +1564 -0
  388. package/src/providers/connect/form-machine.test.ts +200 -0
  389. package/src/providers/connect/form-machine.ts +419 -0
  390. package/src/providers/connect/go-upsell-hero-art.test.ts +194 -0
  391. package/src/providers/connect/go-upsell-hero-art.ts +749 -0
  392. package/src/providers/connect/go-upsell-hero-machine.test.ts +88 -0
  393. package/src/providers/connect/go-upsell-hero-machine.ts +68 -0
  394. package/src/providers/connect/go-upsell-hero.tsx +17 -0
  395. package/src/providers/connect/machine.test.ts +513 -0
  396. package/src/providers/connect/machine.ts +644 -0
  397. package/src/providers/connect/mcp-dialog.stories.tsx +89 -0
  398. package/src/providers/connect/mcp-dialog.tsx +316 -0
  399. package/src/providers/connect/mcp-machine.test.ts +239 -0
  400. package/src/providers/connect/mcp-machine.ts +328 -0
  401. package/src/providers/connect/mcp-sign-in.tsx +112 -0
  402. package/src/providers/connect/mcp.tsx +298 -0
  403. package/src/providers/connect/models.css +71 -0
  404. package/src/providers/connect/remote.test.ts +50 -0
  405. package/src/providers/connect/remote.tsx +10 -0
  406. package/src/providers/connect/step-actions.tsx +18 -0
  407. package/src/providers/connect/tip.tsx +110 -0
  408. package/src/providers/connect/usage-exceeded.tsx +62 -0
  409. package/src/providers/custom-managed-provider.svg +31 -0
  410. package/src/providers/models/agent.test.ts +25 -0
  411. package/src/providers/models/agent.ts +7 -0
  412. package/src/providers/models/configured.ts +33 -0
  413. package/src/providers/models/details.tsx +168 -0
  414. package/src/providers/models/manage.css +97 -0
  415. package/src/providers/models/manage.standalone.stories.tsx +59 -0
  416. package/src/providers/models/manage.tsx +170 -0
  417. package/src/providers/models/models.test.ts +55 -0
  418. package/src/providers/models/models.tsx +279 -0
  419. package/src/providers/models/provider-group.tsx +293 -0
  420. package/src/providers/models/search.test.ts +13 -0
  421. package/src/providers/models/search.ts +20 -0
  422. package/src/providers/models/select-dialog-machine.test.ts +455 -0
  423. package/src/providers/models/select-dialog-machine.ts +702 -0
  424. package/src/providers/models/select-dialog.css +240 -0
  425. package/src/providers/models/select-dialog.standalone.stories.tsx +225 -0
  426. package/src/providers/models/select-dialog.tsx +1359 -0
  427. package/src/providers/models/selection-machine.test.ts +290 -0
  428. package/src/providers/models/selection-machine.ts +408 -0
  429. package/src/providers/models/selection.tsx +787 -0
  430. package/src/providers/models/speed.test.ts +17 -0
  431. package/src/providers/models/speed.ts +17 -0
  432. package/src/providers/models/tooltip.tsx +152 -0
  433. package/src/providers/models/unpaid.standalone.stories.tsx +76 -0
  434. package/src/providers/models/unpaid.tsx +199 -0
  435. package/src/providers/models/variant.test.ts +79 -0
  436. package/src/providers/models/variant.ts +74 -0
  437. package/src/providers/opencode-logo.tsx +17 -0
  438. package/src/runtime/animated-presence.ts +66 -0
  439. package/src/runtime/array-move.test.ts +19 -0
  440. package/src/runtime/array-move.ts +8 -0
  441. package/src/runtime/i18n/am.ts +1409 -0
  442. package/src/runtime/i18n/ar.ts +1560 -0
  443. package/src/runtime/i18n/az.ts +1481 -0
  444. package/src/runtime/i18n/bg.ts +1491 -0
  445. package/src/runtime/i18n/bn.ts +1477 -0
  446. package/src/runtime/i18n/br.ts +1527 -0
  447. package/src/runtime/i18n/bs.ts +1561 -0
  448. package/src/runtime/i18n/ca.ts +1523 -0
  449. package/src/runtime/i18n/cs.ts +1520 -0
  450. package/src/runtime/i18n/da.ts +1527 -0
  451. package/src/runtime/i18n/de.ts +1517 -0
  452. package/src/runtime/i18n/desktop-native.test.ts +84 -0
  453. package/src/runtime/i18n/desktop-native.ts +366 -0
  454. package/src/runtime/i18n/dv.ts +1519 -0
  455. package/src/runtime/i18n/dz.ts +1504 -0
  456. package/src/runtime/i18n/el.ts +1509 -0
  457. package/src/runtime/i18n/en.ts +1560 -0
  458. package/src/runtime/i18n/es.ts +1583 -0
  459. package/src/runtime/i18n/et.ts +1456 -0
  460. package/src/runtime/i18n/fa.ts +1470 -0
  461. package/src/runtime/i18n/fi.ts +1472 -0
  462. package/src/runtime/i18n/fo.ts +1469 -0
  463. package/src/runtime/i18n/fr.ts +1543 -0
  464. package/src/runtime/i18n/he.ts +1455 -0
  465. package/src/runtime/i18n/hi.ts +1475 -0
  466. package/src/runtime/i18n/hr.ts +1506 -0
  467. package/src/runtime/i18n/hu.ts +1492 -0
  468. package/src/runtime/i18n/hy.ts +1478 -0
  469. package/src/runtime/i18n/id.ts +1541 -0
  470. package/src/runtime/i18n/is.ts +1468 -0
  471. package/src/runtime/i18n/it.ts +1517 -0
  472. package/src/runtime/i18n/ja.ts +1484 -0
  473. package/src/runtime/i18n/ka.ts +1476 -0
  474. package/src/runtime/i18n/km.ts +1461 -0
  475. package/src/runtime/i18n/ko.ts +1469 -0
  476. package/src/runtime/i18n/language.test.ts +35 -0
  477. package/src/runtime/i18n/language.tsx +468 -0
  478. package/src/runtime/i18n/lo.ts +1454 -0
  479. package/src/runtime/i18n/lt.ts +1529 -0
  480. package/src/runtime/i18n/lv.ts +1509 -0
  481. package/src/runtime/i18n/machine.test.ts +148 -0
  482. package/src/runtime/i18n/machine.ts +164 -0
  483. package/src/runtime/i18n/mk.ts +1488 -0
  484. package/src/runtime/i18n/mn.ts +1485 -0
  485. package/src/runtime/i18n/ms.ts +1480 -0
  486. package/src/runtime/i18n/my.ts +1489 -0
  487. package/src/runtime/i18n/ne.ts +1478 -0
  488. package/src/runtime/i18n/nl.ts +1491 -0
  489. package/src/runtime/i18n/no.ts +1536 -0
  490. package/src/runtime/i18n/pa.ts +1478 -0
  491. package/src/runtime/i18n/pl.ts +1540 -0
  492. package/src/runtime/i18n/ro.ts +1511 -0
  493. package/src/runtime/i18n/ru.ts +1596 -0
  494. package/src/runtime/i18n/si.ts +1477 -0
  495. package/src/runtime/i18n/sk.ts +1526 -0
  496. package/src/runtime/i18n/sl.ts +1527 -0
  497. package/src/runtime/i18n/sq.ts +1480 -0
  498. package/src/runtime/i18n/sr.ts +1502 -0
  499. package/src/runtime/i18n/sv.ts +1478 -0
  500. package/src/runtime/i18n/tg.ts +1493 -0
  501. package/src/runtime/i18n/th.ts +1505 -0
  502. package/src/runtime/i18n/tk.ts +1472 -0
  503. package/src/runtime/i18n/tr.ts +1550 -0
  504. package/src/runtime/i18n/uk.ts +1598 -0
  505. package/src/runtime/i18n/ur.ts +1488 -0
  506. package/src/runtime/i18n/uz.ts +1490 -0
  507. package/src/runtime/i18n/vi.ts +1473 -0
  508. package/src/runtime/i18n/zh.ts +1474 -0
  509. package/src/runtime/i18n/zht.ts +1468 -0
  510. package/src/runtime/persistence/README.md +151 -0
  511. package/src/runtime/persistence/base64.ts +11 -0
  512. package/src/runtime/persistence/consumers.test.ts +168 -0
  513. package/src/runtime/persistence/drafts-machine.test.ts +214 -0
  514. package/src/runtime/persistence/drafts-machine.ts +385 -0
  515. package/src/runtime/persistence/drafts.test.ts +515 -0
  516. package/src/runtime/persistence/drafts.ts +687 -0
  517. package/src/runtime/persistence/equality.ts +9 -0
  518. package/src/runtime/persistence/namespace-machine.test.ts +232 -0
  519. package/src/runtime/persistence/namespace-machine.ts +304 -0
  520. package/src/runtime/persistence/namespace.test.ts +304 -0
  521. package/src/runtime/persistence/namespace.ts +126 -0
  522. package/src/runtime/persistence/persist-machine.test.ts +185 -0
  523. package/src/runtime/persistence/persist-machine.ts +192 -0
  524. package/src/runtime/persistence/persist.test.ts +243 -0
  525. package/src/runtime/persistence/persist.ts +159 -0
  526. package/src/runtime/persistence/schema.test.ts +208 -0
  527. package/src/runtime/persistence/schema.ts +130 -0
  528. package/src/runtime/persistence/storage-machine.test.ts +61 -0
  529. package/src/runtime/persistence/storage-machine.ts +57 -0
  530. package/src/runtime/persistence/storage.test.ts +70 -0
  531. package/src/runtime/persistence/storage.ts +707 -0
  532. package/src/runtime/platform/base-path-router.tsx +66 -0
  533. package/src/runtime/platform/base-path.test.ts +50 -0
  534. package/src/runtime/platform/base-path.ts +28 -0
  535. package/src/runtime/platform/drag-out.test.ts +58 -0
  536. package/src/runtime/platform/drag-out.ts +53 -0
  537. package/src/runtime/platform/external-link.tsx +21 -0
  538. package/src/runtime/platform/keyboard.ts +41 -0
  539. package/src/runtime/platform/platform.tsx +185 -0
  540. package/src/runtime/platform/pwa.ts +50 -0
  541. package/src/runtime/platform/web.ts +63 -0
  542. package/src/runtime/plugin/app-links.test.ts +17 -0
  543. package/src/runtime/plugin/app-links.ts +88 -0
  544. package/src/runtime/plugin/attach-machine.test.ts +174 -0
  545. package/src/runtime/plugin/attach-machine.ts +152 -0
  546. package/src/runtime/plugin/attachment.ts +15 -0
  547. package/src/runtime/plugin/builtins.ts +15 -0
  548. package/src/runtime/plugin/closed-tabs-view.tsx +315 -0
  549. package/src/runtime/plugin/closed-tabs.test.ts +82 -0
  550. package/src/runtime/plugin/closed-tabs.ts +196 -0
  551. package/src/runtime/plugin/commands.test.ts +23 -0
  552. package/src/runtime/plugin/commands.tsx +86 -0
  553. package/src/runtime/plugin/composer-write-machine.test.ts +151 -0
  554. package/src/runtime/plugin/composer-write-machine.ts +111 -0
  555. package/src/runtime/plugin/deferred-menu-machine.test.ts +127 -0
  556. package/src/runtime/plugin/deferred-menu-machine.ts +163 -0
  557. package/src/runtime/plugin/dialog-machine.test.ts +62 -0
  558. package/src/runtime/plugin/dialog-machine.ts +81 -0
  559. package/src/runtime/plugin/dialogs.stories.tsx +66 -0
  560. package/src/runtime/plugin/dialogs.tsx +177 -0
  561. package/src/runtime/plugin/embed-flight-machine.test.ts +350 -0
  562. package/src/runtime/plugin/embed-flight-machine.ts +468 -0
  563. package/src/runtime/plugin/embed-geometry.test.ts +18 -0
  564. package/src/runtime/plugin/embed-geometry.ts +19 -0
  565. package/src/runtime/plugin/embed-snapshot-machine.test.ts +242 -0
  566. package/src/runtime/plugin/embed-snapshot-machine.ts +267 -0
  567. package/src/runtime/plugin/embeds.tsx +773 -0
  568. package/src/runtime/plugin/extension-plugins.tsx +299 -0
  569. package/src/runtime/plugin/hmr.tsx +33 -0
  570. package/src/runtime/plugin/host-apis.tsx +1315 -0
  571. package/src/runtime/plugin/host-layout-machine.test.ts +214 -0
  572. package/src/runtime/plugin/host-layout-machine.ts +269 -0
  573. package/src/runtime/plugin/host.tsx +1106 -0
  574. package/src/runtime/plugin/instance-machine.test.ts +387 -0
  575. package/src/runtime/plugin/instance-machine.ts +409 -0
  576. package/src/runtime/plugin/ipc-machine.test.ts +172 -0
  577. package/src/runtime/plugin/ipc-machine.ts +213 -0
  578. package/src/runtime/plugin/ipc.test.ts +166 -0
  579. package/src/runtime/plugin/ipc.ts +220 -0
  580. package/src/runtime/plugin/link-check-machine.test.ts +115 -0
  581. package/src/runtime/plugin/link-check-machine.ts +142 -0
  582. package/src/runtime/plugin/link-check.ts +82 -0
  583. package/src/runtime/plugin/located-machine.test.ts +124 -0
  584. package/src/runtime/plugin/located-machine.ts +125 -0
  585. package/src/runtime/plugin/located.ts +82 -0
  586. package/src/runtime/plugin/machine.test.ts +222 -0
  587. package/src/runtime/plugin/machine.ts +318 -0
  588. package/src/runtime/plugin/menubar-items.ts +28 -0
  589. package/src/runtime/plugin/mobile.tsx +199 -0
  590. package/src/runtime/plugin/module.test.ts +57 -0
  591. package/src/runtime/plugin/module.ts +64 -0
  592. package/src/runtime/plugin/mounted-session.ts +420 -0
  593. package/src/runtime/plugin/new-tab-machine.test.ts +207 -0
  594. package/src/runtime/plugin/new-tab-machine.ts +240 -0
  595. package/src/runtime/plugin/pane-drag-machine.test.ts +217 -0
  596. package/src/runtime/plugin/pane-drag-machine.ts +263 -0
  597. package/src/runtime/plugin/pane-drag.tsx +290 -0
  598. package/src/runtime/plugin/panel-keys.ts +15 -0
  599. package/src/runtime/plugin/panel-menu.ts +29 -0
  600. package/src/runtime/plugin/panel-trigger.tsx +180 -0
  601. package/src/runtime/plugin/panels.tsx +733 -0
  602. package/src/runtime/plugin/plugin-gui-machine.test.ts +186 -0
  603. package/src/runtime/plugin/plugin-gui-machine.ts +178 -0
  604. package/src/runtime/plugin/plugins.tsx +137 -0
  605. package/src/runtime/plugin/prompt-gate.test.ts +113 -0
  606. package/src/runtime/plugin/prompt-gate.ts +36 -0
  607. package/src/runtime/plugin/render.tsx +348 -0
  608. package/src/runtime/plugin/root.tsx +141 -0
  609. package/src/runtime/plugin/server-shell.tsx +113 -0
  610. package/src/runtime/plugin/servers.tsx +270 -0
  611. package/src/runtime/plugin/session-store-machine.test.ts +82 -0
  612. package/src/runtime/plugin/session-store-machine.ts +140 -0
  613. package/src/runtime/plugin/settings-page-view.tsx +53 -0
  614. package/src/runtime/plugin/settings-pages.ts +23 -0
  615. package/src/runtime/plugin/side-region.tsx +635 -0
  616. package/src/runtime/plugin/startup.ts +107 -0
  617. package/src/runtime/plugin/store-machine.test.ts +69 -0
  618. package/src/runtime/plugin/store-machine.ts +139 -0
  619. package/src/runtime/plugin/stores.ts +339 -0
  620. package/src/runtime/plugin/tab-strip-scroll.test.ts +40 -0
  621. package/src/runtime/plugin/tab-strip-scroll.ts +130 -0
  622. package/src/runtime/plugin/titlebar-items.css +20 -0
  623. package/src/runtime/plugin/titlebar-items.stories.tsx +97 -0
  624. package/src/runtime/plugin/titlebar-items.tsx +96 -0
  625. package/src/runtime/plugin/ui.tsx +292 -0
  626. package/src/runtime/plugin/web-href.test.ts +11 -0
  627. package/src/runtime/plugin/web-href.ts +10 -0
  628. package/src/runtime/polyfills.test.ts +61 -0
  629. package/src/runtime/polyfills.ts +39 -0
  630. package/src/runtime/presence-machine.test.ts +260 -0
  631. package/src/runtime/presence-machine.ts +329 -0
  632. package/src/runtime/presence.ts +165 -0
  633. package/src/runtime/server/api.test.ts +64 -0
  634. package/src/runtime/server/api.ts +58 -0
  635. package/src/runtime/server/client.test.ts +131 -0
  636. package/src/runtime/server/client.tsx +308 -0
  637. package/src/runtime/server/current.tsx +55 -0
  638. package/src/runtime/server/data.test.ts +440 -0
  639. package/src/runtime/server/data.ts +286 -0
  640. package/src/runtime/server/errors.test.ts +151 -0
  641. package/src/runtime/server/errors.ts +135 -0
  642. package/src/runtime/server/global-sync/bootstrap.test.ts +179 -0
  643. package/src/runtime/server/global-sync/bootstrap.ts +96 -0
  644. package/src/runtime/server/global-sync/child-store.test.ts +47 -0
  645. package/src/runtime/server/global-sync/child-store.ts +206 -0
  646. package/src/runtime/server/global-sync/machine.test.ts +96 -0
  647. package/src/runtime/server/global-sync/machine.ts +84 -0
  648. package/src/runtime/server/global-sync/types.ts +46 -0
  649. package/src/runtime/server/global-sync/utils.test.ts +154 -0
  650. package/src/runtime/server/global-sync/utils.ts +165 -0
  651. package/src/runtime/server/health-machine.test.ts +227 -0
  652. package/src/runtime/server/health-machine.ts +357 -0
  653. package/src/runtime/server/health.test.ts +169 -0
  654. package/src/runtime/server/health.ts +236 -0
  655. package/src/runtime/server/image.test.ts +214 -0
  656. package/src/runtime/server/image.ts +40 -0
  657. package/src/runtime/server/loopback.test.ts +17 -0
  658. package/src/runtime/server/loopback.ts +22 -0
  659. package/src/runtime/server/machine.test.ts +162 -0
  660. package/src/runtime/server/machine.ts +275 -0
  661. package/src/runtime/server/media.ts +88 -0
  662. package/src/runtime/server/persistence.test.ts +117 -0
  663. package/src/runtime/server/persistence.ts +105 -0
  664. package/src/runtime/server/plugin-machine.test.ts +128 -0
  665. package/src/runtime/server/plugin-machine.ts +170 -0
  666. package/src/runtime/server/refcount.test.ts +30 -0
  667. package/src/runtime/server/refcount.ts +37 -0
  668. package/src/runtime/server/registry.test.ts +152 -0
  669. package/src/runtime/server/registry.tsx +363 -0
  670. package/src/runtime/server/request-queue-machine.test.ts +151 -0
  671. package/src/runtime/server/request-queue-machine.ts +307 -0
  672. package/src/runtime/server/request-queue.test.ts +315 -0
  673. package/src/runtime/server/request-queue.ts +173 -0
  674. package/src/runtime/server/runtime.tsx +396 -0
  675. package/src/runtime/server/scope.test.ts +52 -0
  676. package/src/runtime/server/scope.ts +69 -0
  677. package/src/runtime/server/scoped-cache.test.ts +72 -0
  678. package/src/runtime/server/scoped-cache.ts +119 -0
  679. package/src/runtime/server/server-sync/connection.ts +34 -0
  680. package/src/runtime/server/server-sync/endpoint-machine.test.ts +87 -0
  681. package/src/runtime/server/server-sync/endpoint-machine.ts +62 -0
  682. package/src/runtime/server/server-sync/machine.test.ts +86 -0
  683. package/src/runtime/server/server-sync/machine.ts +70 -0
  684. package/src/runtime/server/session-index.ts +23 -0
  685. package/src/runtime/server/sync.tsx +206 -0
  686. package/src/runtime/server/types.ts +151 -0
  687. package/src/servers/connect/browser.ts +15 -0
  688. package/src/servers/connect/connect.fixture.tsx +222 -0
  689. package/src/servers/connect/controller.ts +237 -0
  690. package/src/servers/connect/dialog.stories.tsx +67 -0
  691. package/src/servers/connect/dialog.tsx +255 -0
  692. package/src/servers/connect/machine.test.ts +487 -0
  693. package/src/servers/connect/machine.ts +427 -0
  694. package/src/servers/connect/method.tsx +31 -0
  695. package/src/servers/connect/pairing.test.ts +67 -0
  696. package/src/servers/connect/pairing.ts +134 -0
  697. package/src/servers/connect/redeem.ts +50 -0
  698. package/src/servers/connect/scanner-machine.test.ts +114 -0
  699. package/src/servers/connect/scanner-machine.ts +164 -0
  700. package/src/servers/connect/scanner.css +47 -0
  701. package/src/servers/connect/scanner.tsx +173 -0
  702. package/src/servers/connect/screen.css +108 -0
  703. package/src/servers/connect/screen.stories.tsx +63 -0
  704. package/src/servers/connect/screen.tsx +164 -0
  705. package/src/servers/registry/add-menu.tsx +62 -0
  706. package/src/servers/registry/controller.test.ts +26 -0
  707. package/src/servers/registry/controller.ts +86 -0
  708. package/src/servers/registry/label.tsx +23 -0
  709. package/src/servers/registry/management.test.ts +40 -0
  710. package/src/servers/registry/management.ts +17 -0
  711. package/src/servers/registry/plugin-row.tsx +57 -0
  712. package/src/servers/registry/row-items.tsx +18 -0
  713. package/src/servers/registry/row-menu.tsx +152 -0
  714. package/src/servers/registry/row.stories.tsx +51 -0
  715. package/src/servers/registry/row.tsx +47 -0
  716. package/src/session/commands/dialog-jump-to-message.tsx +197 -0
  717. package/src/session/commands/export-machine.test.ts +99 -0
  718. package/src/session/commands/export-machine.ts +117 -0
  719. package/src/session/commands/export-session.tsx +108 -0
  720. package/src/session/commands/export.test.ts +105 -0
  721. package/src/session/commands/export.ts +89 -0
  722. package/src/session/commands/fork-dialog.stories.tsx +68 -0
  723. package/src/session/commands/fork-dialog.tsx +198 -0
  724. package/src/session/commands/jump-to-message-machine.test.ts +123 -0
  725. package/src/session/commands/jump-to-message-machine.ts +161 -0
  726. package/src/session/commands/jump-to-message.stories.tsx +226 -0
  727. package/src/session/commands/jump-to-message.tsx +161 -0
  728. package/src/session/commands/machine.test.ts +305 -0
  729. package/src/session/commands/machine.ts +272 -0
  730. package/src/session/commands/rename-session.ts +31 -0
  731. package/src/session/commands/use-session-commands.tsx +813 -0
  732. package/src/session/composer/activity-chips.css +242 -0
  733. package/src/session/composer/activity-chips.stories.tsx +280 -0
  734. package/src/session/composer/activity-chips.tsx +485 -0
  735. package/src/session/composer/adapter.ts +74 -0
  736. package/src/session/composer/composer-docks.stories.tsx +278 -0
  737. package/src/session/composer/composer-lane.css +93 -0
  738. package/src/session/composer/composer-lane.tsx +45 -0
  739. package/src/session/composer/controller.ts +86 -0
  740. package/src/session/composer/focus-machine.test.ts +285 -0
  741. package/src/session/composer/focus-machine.ts +212 -0
  742. package/src/session/composer/focus.tsx +161 -0
  743. package/src/session/composer/free-limit-panel.standalone.stories.tsx +45 -0
  744. package/src/session/composer/free-limit-panel.tsx +133 -0
  745. package/src/session/composer/go-limit-tray.tsx +137 -0
  746. package/src/session/composer/location-missing-machine.test.ts +97 -0
  747. package/src/session/composer/location-missing-machine.ts +144 -0
  748. package/src/session/composer/location-missing.css +73 -0
  749. package/src/session/composer/location-missing.standalone.stories.tsx +161 -0
  750. package/src/session/composer/location-missing.tsx +193 -0
  751. package/src/session/composer/plugin-pills.tsx +215 -0
  752. package/src/session/composer/queue-machine.test.ts +565 -0
  753. package/src/session/composer/queue-machine.ts +934 -0
  754. package/src/session/composer/queue-panel-machine.test.ts +121 -0
  755. package/src/session/composer/queue-panel-machine.ts +229 -0
  756. package/src/session/composer/queue-panel.css +10 -0
  757. package/src/session/composer/queue-panel.stories.tsx +86 -0
  758. package/src/session/composer/queue-panel.tsx +314 -0
  759. package/src/session/composer/queue.test.ts +314 -0
  760. package/src/session/composer/queue.ts +610 -0
  761. package/src/session/composer/recovery-story.tsx +38 -0
  762. package/src/session/composer/region.tsx +689 -0
  763. package/src/session/composer/selection.test.ts +28 -0
  764. package/src/session/composer/selection.ts +28 -0
  765. package/src/session/composer/session-composer-region-controller.ts +28 -0
  766. package/src/session/composer/session-composer-region.tsx +115 -0
  767. package/src/session/composer/shell-panel-machine.test.ts +261 -0
  768. package/src/session/composer/shell-panel-machine.ts +338 -0
  769. package/src/session/composer/shell-panel.ts +181 -0
  770. package/src/session/composer/spring-height-machine.test.ts +380 -0
  771. package/src/session/composer/spring-height-machine.ts +489 -0
  772. package/src/session/composer/spring-height.tsx +586 -0
  773. package/src/session/composer/subagent-bar.tsx +116 -0
  774. package/src/session/composer/timeline-actions.ts +49 -0
  775. package/src/session/composer/todo-pill.css +32 -0
  776. package/src/session/composer/todo-pill.stories.tsx +158 -0
  777. package/src/session/composer/todo-pill.tsx +157 -0
  778. package/src/session/composer/todos.ts +43 -0
  779. package/src/session/delete-machine.test.ts +83 -0
  780. package/src/session/delete-machine.ts +128 -0
  781. package/src/session/fork-machine.test.ts +152 -0
  782. package/src/session/fork-machine.ts +169 -0
  783. package/src/session/fork.ts +164 -0
  784. package/src/session/handoff-machine.test.ts +262 -0
  785. package/src/session/handoff-machine.ts +256 -0
  786. package/src/session/handoff.ts +112 -0
  787. package/src/session/header/drag-area.tsx +86 -0
  788. package/src/session/header/fit-machine.test.ts +143 -0
  789. package/src/session/header/fit-machine.ts +95 -0
  790. package/src/session/header/fit.ts +134 -0
  791. package/src/session/header/separator.tsx +22 -0
  792. package/src/session/header/session-header-actions.stories.tsx +45 -0
  793. package/src/session/header/session-header-actions.tsx +89 -0
  794. package/src/session/header/session-header.tsx +12 -0
  795. package/src/session/header/session-working-indicator.tsx +44 -0
  796. package/src/session/helpers.ts +42 -0
  797. package/src/session/list.test.ts +64 -0
  798. package/src/session/list.ts +18 -0
  799. package/src/session/message-id-from-hash.test.ts +10 -0
  800. package/src/session/message-id-from-hash.ts +8 -0
  801. package/src/session/model.ts +150 -0
  802. package/src/session/preparing-composer.tsx +72 -0
  803. package/src/session/question-switch.stories.tsx +380 -0
  804. package/src/session/requests/auto-approve-machine.test.ts +345 -0
  805. package/src/session/requests/auto-approve-machine.ts +247 -0
  806. package/src/session/requests/auto-approve.ts +274 -0
  807. package/src/session/requests/background.ts +312 -0
  808. package/src/session/requests/elicitation-controller.ts +129 -0
  809. package/src/session/requests/elicitation-machine.test.ts +209 -0
  810. package/src/session/requests/elicitation-machine.ts +277 -0
  811. package/src/session/requests/job-list.test.ts +18 -0
  812. package/src/session/requests/model.ts +348 -0
  813. package/src/session/requests/permission-machine.test.ts +130 -0
  814. package/src/session/requests/permission-machine.ts +105 -0
  815. package/src/session/requests/question-controller.ts +130 -0
  816. package/src/session/requests/question-keys.test.ts +106 -0
  817. package/src/session/requests/question-keys.ts +81 -0
  818. package/src/session/requests/question-machine.test.ts +257 -0
  819. package/src/session/requests/question-machine.ts +293 -0
  820. package/src/session/requests/question-motion.ts +26 -0
  821. package/src/session/requests/question-state.ts +21 -0
  822. package/src/session/requests/question-switch-machine.test.ts +114 -0
  823. package/src/session/requests/question-switch-machine.ts +130 -0
  824. package/src/session/requests/session-elicitation-dock.css +49 -0
  825. package/src/session/requests/session-elicitation-dock.tsx +223 -0
  826. package/src/session/requests/session-permission-dock.tsx +108 -0
  827. package/src/session/requests/session-question-dock-classic.tsx +726 -0
  828. package/src/session/requests/session-question-dock-experimental.tsx +1510 -0
  829. package/src/session/requests/session-question-dock.tsx +15 -0
  830. package/src/session/requests/session-request-tree.test.ts +119 -0
  831. package/src/session/requests/session-request-tree.ts +87 -0
  832. package/src/session/requests/session-websearch-dock.css +61 -0
  833. package/src/session/requests/session-websearch-dock.tsx +112 -0
  834. package/src/session/requests/steer-background.test.ts +66 -0
  835. package/src/session/requests/steer-background.ts +28 -0
  836. package/src/session/requests/websearch-machine.test.ts +425 -0
  837. package/src/session/requests/websearch-machine.ts +627 -0
  838. package/src/session/requests/websearch.ts +152 -0
  839. package/src/session/resolution-machine.test.ts +414 -0
  840. package/src/session/resolution-machine.ts +330 -0
  841. package/src/session/revert-machine.test.ts +365 -0
  842. package/src/session/revert-machine.ts +345 -0
  843. package/src/session/revert.ts +340 -0
  844. package/src/session/route-error.tsx +73 -0
  845. package/src/session/route.tsx +299 -0
  846. package/src/session/screen-layout.ts +147 -0
  847. package/src/session/screen.tsx +625 -0
  848. package/src/session/search.ts +3 -0
  849. package/src/session/server-unavailable-panel.standalone.stories.tsx +88 -0
  850. package/src/session/server-unavailable-panel.tsx +86 -0
  851. package/src/session/session-domain.test.ts +57 -0
  852. package/src/session/session-domain.ts +33 -0
  853. package/src/session/session-frame.tsx +28 -0
  854. package/src/session/session-identity-header.css +142 -0
  855. package/src/session/session-identity-header.tsx +674 -0
  856. package/src/session/session-layout.ts +73 -0
  857. package/src/session/session-model-helpers.test.ts +29 -0
  858. package/src/session/session-model-helpers.ts +33 -0
  859. package/src/session/session-panel-width.test.ts +25 -0
  860. package/src/session/session-panel-width.ts +58 -0
  861. package/src/session/session-read-menu-item.tsx +54 -0
  862. package/src/session/session-reference-menu.tsx +106 -0
  863. package/src/session/session-resolution.ts +141 -0
  864. package/src/session/session-screen.stories.tsx +363 -0
  865. package/src/session/sizing-machine.test.ts +89 -0
  866. package/src/session/sizing-machine.ts +74 -0
  867. package/src/session/story-model.tsx +420 -0
  868. package/src/session/timeline/background-work.stories.tsx +27 -0
  869. package/src/session/timeline/cache-machine.test.ts +50 -0
  870. package/src/session/timeline/cache-machine.ts +37 -0
  871. package/src/session/timeline/cache.ts +200 -0
  872. package/src/session/timeline/cold-mount.test.ts +162 -0
  873. package/src/session/timeline/cold-mount.ts +179 -0
  874. package/src/session/timeline/controller-projection.test.ts +305 -0
  875. package/src/session/timeline/controller-projection.ts +131 -0
  876. package/src/session/timeline/controller.tsx +467 -0
  877. package/src/session/timeline/cursor-machine.test.ts +398 -0
  878. package/src/session/timeline/cursor-machine.ts +433 -0
  879. package/src/session/timeline/cursor.ts +207 -0
  880. package/src/session/timeline/follow.ts +40 -0
  881. package/src/session/timeline/header-actions-machine.test.ts +126 -0
  882. package/src/session/timeline/header-actions-machine.ts +204 -0
  883. package/src/session/timeline/history-machine.test.ts +304 -0
  884. package/src/session/timeline/history-machine.ts +296 -0
  885. package/src/session/timeline/inline-quotes.ts +4 -0
  886. package/src/session/timeline/interaction.ts +474 -0
  887. package/src/session/timeline/machine.test.ts +290 -0
  888. package/src/session/timeline/machine.ts +271 -0
  889. package/src/session/timeline/message-timeline.tsx +779 -0
  890. package/src/session/timeline/model.test.ts +393 -0
  891. package/src/session/timeline/model.ts +201 -0
  892. package/src/session/timeline/observe-element-offset.test.ts +323 -0
  893. package/src/session/timeline/observe-element-offset.ts +106 -0
  894. package/src/session/timeline/projection.ts +7 -0
  895. package/src/session/timeline/quote-background.ts +141 -0
  896. package/src/session/timeline/quote-highlight.ts +203 -0
  897. package/src/session/timeline/quote-machine.test.ts +277 -0
  898. package/src/session/timeline/quote-machine.ts +360 -0
  899. package/src/session/timeline/quote-text.ts +332 -0
  900. package/src/session/timeline/quote.stories.tsx +88 -0
  901. package/src/session/timeline/quote.tsx +547 -0
  902. package/src/session/timeline/reconnect-machine.test.ts +115 -0
  903. package/src/session/timeline/reconnect-machine.ts +130 -0
  904. package/src/session/timeline/search-bar.css +19 -0
  905. package/src/session/timeline/search-bar.stories.tsx +122 -0
  906. package/src/session/timeline/search-bar.tsx +94 -0
  907. package/src/session/timeline/search-controller.ts +364 -0
  908. package/src/session/timeline/search-machine.test.ts +320 -0
  909. package/src/session/timeline/search-machine.ts +342 -0
  910. package/src/session/timeline/selected-effect.ts +19 -0
  911. package/src/session/timeline/sources.stories.tsx +352 -0
  912. package/src/session/timeline/sync-machine.ts +265 -0
  913. package/src/session/timeline/turn-diff-machine.ts +115 -0
  914. package/src/session/timeline/turn-diffs.test.ts +178 -0
  915. package/src/session/timeline/turn-diffs.ts +67 -0
  916. package/src/session/timeline/virtual-items.ts +3 -0
  917. package/src/session/timeline/virtualizer.tsx +1321 -0
  918. package/src/session/timeline/voice-delegation.test.ts +69 -0
  919. package/src/session/timeline/voice-delegation.ts +38 -0
  920. package/src/session/title.ts +15 -0
  921. package/src/session/usage-exceeded-dialogs.test.ts +41 -0
  922. package/src/session/usage-exceeded-dialogs.tsx +158 -0
  923. package/src/session/viewed-machine.test.ts +27 -0
  924. package/src/session/viewed-machine.ts +24 -0
  925. package/src/settings/about/about.tsx +199 -0
  926. package/src/settings/about/animated-wordmark.tsx +85 -0
  927. package/src/settings/about/anomaly-brush.svg +1 -0
  928. package/src/settings/about/contributors.test.ts +17 -0
  929. package/src/settings/about/contributors.ts +27 -0
  930. package/src/settings/about/legal.svg +9 -0
  931. package/src/settings/about/machine.test.ts +90 -0
  932. package/src/settings/about/machine.ts +119 -0
  933. package/src/settings/about/notices/apache-2.0.txt +201 -0
  934. package/src/settings/about/notices/betteroffice-notice.txt +2 -0
  935. package/src/settings/about/notices/crates.ts +770 -0
  936. package/src/settings/about/notices/dialog.tsx +113 -0
  937. package/src/settings/about/notices/fonts/OFL-1.1.txt +91 -0
  938. package/src/settings/about/notices/fonts.ts +107 -0
  939. package/src/settings/about/notices/notices.ts +37 -0
  940. package/src/settings/appearance/appearance.tsx +176 -0
  941. package/src/settings/command.tsx +29 -0
  942. package/src/settings/experimental/experimental.tsx +93 -0
  943. package/src/settings/extension-load-machine.test.ts +117 -0
  944. package/src/settings/extension-load-machine.ts +158 -0
  945. package/src/settings/extension-load.tsx +85 -0
  946. package/src/settings/general/behavior.ts +102 -0
  947. package/src/settings/general/controllers.test.ts +56 -0
  948. package/src/settings/general/controllers.ts +271 -0
  949. package/src/settings/general/general.tsx +404 -0
  950. package/src/settings/general/interface-mode.css +261 -0
  951. package/src/settings/general/interface-mode.tsx +190 -0
  952. package/src/settings/general/machine.test.ts +188 -0
  953. package/src/settings/general/machine.ts +224 -0
  954. package/src/settings/general/sound-preview-machine.test.ts +114 -0
  955. package/src/settings/general/sound-preview-machine.ts +109 -0
  956. package/src/settings/keybinds/keybinds.tsx +624 -0
  957. package/src/settings/keybinds/machine.test.ts +142 -0
  958. package/src/settings/keybinds/machine.ts +149 -0
  959. package/src/settings/keybinds/migration.ts +42 -0
  960. package/src/settings/list.tsx +10 -0
  961. package/src/settings/model.test.ts +249 -0
  962. package/src/settings/model.tsx +685 -0
  963. package/src/settings/models/machine.test.ts +123 -0
  964. package/src/settings/models/machine.ts +161 -0
  965. package/src/settings/models/models.tsx +285 -0
  966. package/src/settings/navigation.tsx +223 -0
  967. package/src/settings/notifications/notifications.tsx +160 -0
  968. package/src/settings/pages.ts +33 -0
  969. package/src/settings/palette.ts +44 -0
  970. package/src/settings/providers/account-actions.ts +112 -0
  971. package/src/settings/providers/account-name.tsx +46 -0
  972. package/src/settings/providers/accounts.test.ts +29 -0
  973. package/src/settings/providers/accounts.ts +11 -0
  974. package/src/settings/providers/console-extensions.test.ts +103 -0
  975. package/src/settings/providers/console-extensions.ts +110 -0
  976. package/src/settings/providers/console-link.tsx +121 -0
  977. package/src/settings/providers/extensions.tsx +425 -0
  978. package/src/settings/providers/machine.test.ts +270 -0
  979. package/src/settings/providers/machine.ts +357 -0
  980. package/src/settings/providers/plugin-update-machine.test.ts +155 -0
  981. package/src/settings/providers/plugin-update-machine.ts +151 -0
  982. package/src/settings/providers/providers.tsx +702 -0
  983. package/src/settings/rename-machine.test.ts +123 -0
  984. package/src/settings/rename-machine.ts +167 -0
  985. package/src/settings/rename.ts +120 -0
  986. package/src/settings/route.test.ts +117 -0
  987. package/src/settings/route.ts +160 -0
  988. package/src/settings/row.tsx +21 -0
  989. package/src/settings/scroller.ts +6 -0
  990. package/src/settings/search-catalog.ts +319 -0
  991. package/src/settings/search-empty.tsx +87 -0
  992. package/src/settings/search-field.tsx +101 -0
  993. package/src/settings/search-index.ts +193 -0
  994. package/src/settings/search-machine.test.ts +249 -0
  995. package/src/settings/search-machine.ts +308 -0
  996. package/src/settings/search-results.test.ts +151 -0
  997. package/src/settings/search-results.ts +75 -0
  998. package/src/settings/search-reveal.ts +76 -0
  999. package/src/settings/search.css +168 -0
  1000. package/src/settings/search.tsx +283 -0
  1001. package/src/settings/server-scope.tsx +12 -0
  1002. package/src/settings/servers/inventory.test.ts +50 -0
  1003. package/src/settings/servers/inventory.ts +100 -0
  1004. package/src/settings/servers/machine.test.ts +148 -0
  1005. package/src/settings/servers/machine.ts +176 -0
  1006. package/src/settings/servers/servers.tsx +178 -0
  1007. package/src/settings/servers/switcher.tsx +77 -0
  1008. package/src/settings/servers/unavailable.tsx +99 -0
  1009. package/src/settings/settings.css +2478 -0
  1010. package/src/settings/shell.standalone.stories.tsx +60 -0
  1011. package/src/settings/shell.tsx +434 -0
  1012. package/src/settings/surface.tsx +297 -0
  1013. package/src/settings/tab-header.ts +12 -0
  1014. package/src/settings/timeline-detail.css +334 -0
  1015. package/src/settings/timeline-detail.stories.tsx +54 -0
  1016. package/src/settings/timeline-detail.tsx +221 -0
  1017. package/src/settings/workspaces/delete-machine.test.ts +298 -0
  1018. package/src/settings/workspaces/delete-machine.ts +392 -0
  1019. package/src/settings/workspaces/project-extensions.tsx +537 -0
  1020. package/src/settings/workspaces/project-folder-missing.tsx +29 -0
  1021. package/src/settings/workspaces/project-lsp.test.ts +65 -0
  1022. package/src/settings/workspaces/project-lsp.ts +31 -0
  1023. package/src/settings/workspaces/project-machine.test.ts +285 -0
  1024. package/src/settings/workspaces/project-machine.ts +374 -0
  1025. package/src/settings/workspaces/project-model.ts +201 -0
  1026. package/src/settings/workspaces/project-options.tsx +81 -0
  1027. package/src/settings/workspaces/project-row.tsx +121 -0
  1028. package/src/settings/workspaces/project.css +397 -0
  1029. package/src/settings/workspaces/project.tsx +266 -0
  1030. package/src/settings/workspaces/projects.tsx +199 -0
  1031. package/src/settings/workspaces/queries.ts +66 -0
  1032. package/src/settings/workspaces/workspaces.tsx +705 -0
  1033. package/src/shell/commands/command-search.tsx +41 -0
  1034. package/src/shell/commands/command.test.ts +118 -0
  1035. package/src/shell/commands/command.tsx +584 -0
  1036. package/src/shell/commands/desktop-menu.test.ts +48 -0
  1037. package/src/shell/commands/desktop-menu.ts +322 -0
  1038. package/src/shell/commands/desktop.tsx +27 -0
  1039. package/src/shell/commands/dialog.css +263 -0
  1040. package/src/shell/commands/dialog.standalone.stories.tsx +247 -0
  1041. package/src/shell/commands/dialog.tsx +318 -0
  1042. package/src/shell/commands/highlight-machine.test.ts +64 -0
  1043. package/src/shell/commands/highlight-machine.ts +54 -0
  1044. package/src/shell/commands/key-sequence.tsx +38 -0
  1045. package/src/shell/commands/keymap.test.ts +219 -0
  1046. package/src/shell/commands/keymap.ts +275 -0
  1047. package/src/shell/commands/palette.ts +466 -0
  1048. package/src/shell/commands/safe-triangle.ts +64 -0
  1049. package/src/shell/commands/search-machine.test.ts +218 -0
  1050. package/src/shell/commands/search-machine.ts +274 -0
  1051. package/src/shell/commands/search.ts +136 -0
  1052. package/src/shell/commands/session-search.tsx +111 -0
  1053. package/src/shell/commands/suspend-machine.test.ts +59 -0
  1054. package/src/shell/commands/suspend-machine.ts +46 -0
  1055. package/src/shell/deep-links/deep-links.ts +65 -0
  1056. package/src/shell/deep-links/machine.test.ts +67 -0
  1057. package/src/shell/deep-links/machine.ts +67 -0
  1058. package/src/shell/errors/description.test.ts +32 -0
  1059. package/src/shell/errors/description.ts +32 -0
  1060. package/src/shell/errors/error.tsx +515 -0
  1061. package/src/shell/errors/machine.test.ts +178 -0
  1062. package/src/shell/errors/machine.ts +217 -0
  1063. package/src/shell/layout/helpers.test.ts +76 -0
  1064. package/src/shell/layout/helpers.ts +78 -0
  1065. package/src/shell/layout/project-avatar-state.ts +157 -0
  1066. package/src/shell/layout/project-icon.tsx +31 -0
  1067. package/src/shell/layout/project-icons.tsx +34 -0
  1068. package/src/shell/layout/session-tab-avatar.tsx +28 -0
  1069. package/src/shell/mobile-drawer.css +90 -0
  1070. package/src/shell/mobile-drawer.tsx +53 -0
  1071. package/src/shell/mobile-panel-drawer.css +34 -0
  1072. package/src/shell/mobile-panel-drawer.tsx +98 -0
  1073. package/src/shell/notifications/coordinator.ts +160 -0
  1074. package/src/shell/notifications/focus-lock-machine.test.ts +79 -0
  1075. package/src/shell/notifications/focus-lock-machine.ts +76 -0
  1076. package/src/shell/notifications/machine.test.ts +297 -0
  1077. package/src/shell/notifications/machine.ts +313 -0
  1078. package/src/shell/notifications/notification.test.ts +28 -0
  1079. package/src/shell/notifications/notification.tsx +526 -0
  1080. package/src/shell/notifications/sound.ts +113 -0
  1081. package/src/shell/notifications/toast.tsx +53 -0
  1082. package/src/shell/palette-menu.css +105 -0
  1083. package/src/shell/panel-motion-machine.test.ts +167 -0
  1084. package/src/shell/panel-motion-machine.ts +217 -0
  1085. package/src/shell/panel-motion.test.ts +26 -0
  1086. package/src/shell/panel-motion.ts +435 -0
  1087. package/src/shell/project-navigation.ts +21 -0
  1088. package/src/shell/routes/routes.tsx +140 -0
  1089. package/src/shell/routes/session-reference-lookup-machine.test.ts +111 -0
  1090. package/src/shell/routes/session-reference-lookup-machine.ts +86 -0
  1091. package/src/shell/routes/session-ui-navigate-machine.test.ts +124 -0
  1092. package/src/shell/routes/session-ui-navigate-machine.ts +127 -0
  1093. package/src/shell/routes/session-ui-provider.tsx +267 -0
  1094. package/src/shell/routes/session.test.ts +46 -0
  1095. package/src/shell/routes/session.ts +30 -0
  1096. package/src/shell/search-list.css +366 -0
  1097. package/src/shell/shell.tsx +340 -0
  1098. package/src/shell/sidebar-peek-machine.test.ts +240 -0
  1099. package/src/shell/sidebar-peek-machine.ts +331 -0
  1100. package/src/shell/sidebar-peek.css +28 -0
  1101. package/src/shell/sidebar-peek.ts +482 -0
  1102. package/src/shell/sidebar-toggle.tsx +255 -0
  1103. package/src/shell/state/helpers.ts +69 -0
  1104. package/src/shell/state/intent-machine.test.ts +155 -0
  1105. package/src/shell/state/intent-machine.ts +216 -0
  1106. package/src/shell/state/layout.test.ts +169 -0
  1107. package/src/shell/state/layout.tsx +794 -0
  1108. package/src/shell/state/scoped-machine.test.ts +69 -0
  1109. package/src/shell/state/scoped-machine.ts +77 -0
  1110. package/src/shell/state/scroll-machine.test.ts +109 -0
  1111. package/src/shell/state/scroll-machine.ts +94 -0
  1112. package/src/shell/state/scroll.test.ts +83 -0
  1113. package/src/shell/state/scroll.ts +124 -0
  1114. package/src/shell/state/session-preferences.ts +62 -0
  1115. package/src/shell/state/session-tabs.test.ts +188 -0
  1116. package/src/shell/state/session-tabs.ts +257 -0
  1117. package/src/shell/tabs/closed.ts +83 -0
  1118. package/src/shell/tabs/hydration-machine.test.ts +98 -0
  1119. package/src/shell/tabs/hydration-machine.ts +115 -0
  1120. package/src/shell/tabs/memory.ts +41 -0
  1121. package/src/shell/tabs/navigation-switch.ts +75 -0
  1122. package/src/shell/tabs/pins.test.ts +68 -0
  1123. package/src/shell/tabs/pins.ts +194 -0
  1124. package/src/shell/tabs/preview-machine.test.ts +89 -0
  1125. package/src/shell/tabs/preview-machine.ts +46 -0
  1126. package/src/shell/tabs/preview.test.ts +153 -0
  1127. package/src/shell/tabs/preview.ts +102 -0
  1128. package/src/shell/tabs/project-sessions.ts +60 -0
  1129. package/src/shell/tabs/promotion-machine.test.ts +203 -0
  1130. package/src/shell/tabs/promotion-machine.ts +194 -0
  1131. package/src/shell/tabs/schema.ts +86 -0
  1132. package/src/shell/tabs/tabs.test.ts +331 -0
  1133. package/src/shell/tabs/tabs.tsx +927 -0
  1134. package/src/shell/time.test.ts +23 -0
  1135. package/src/shell/time.ts +31 -0
  1136. package/src/shell/titlebar/auto-tab-groups.test.ts +76 -0
  1137. package/src/shell/titlebar/auto-tab-groups.ts +88 -0
  1138. package/src/shell/titlebar/auto-tab-sections.tsx +207 -0
  1139. package/src/shell/titlebar/history-machine.test.ts +184 -0
  1140. package/src/shell/titlebar/history-machine.ts +149 -0
  1141. package/src/shell/titlebar/history.ts +64 -0
  1142. package/src/shell/titlebar/inbox-branch-machine.test.ts +146 -0
  1143. package/src/shell/titlebar/inbox-branch-machine.ts +265 -0
  1144. package/src/shell/titlebar/inbox-card.stories.tsx +197 -0
  1145. package/src/shell/titlebar/inbox-list.stories.tsx +342 -0
  1146. package/src/shell/titlebar/inbox-model.ts +539 -0
  1147. package/src/shell/titlebar/inbox-settle-machine.test.ts +108 -0
  1148. package/src/shell/titlebar/inbox-settle-machine.ts +141 -0
  1149. package/src/shell/titlebar/inbox-working.test.ts +26 -0
  1150. package/src/shell/titlebar/inbox-working.ts +22 -0
  1151. package/src/shell/titlebar/inbox.tsx +985 -0
  1152. package/src/shell/titlebar/mobile-tabs-machine.test.ts +105 -0
  1153. package/src/shell/titlebar/mobile-tabs-machine.ts +102 -0
  1154. package/src/shell/titlebar/navigation-story.tsx +207 -0
  1155. package/src/shell/titlebar/pinned-area.css +164 -0
  1156. package/src/shell/titlebar/pinned-area.tsx +629 -0
  1157. package/src/shell/titlebar/project-session-row.tsx +334 -0
  1158. package/src/shell/titlebar/recent-sessions-model.test.ts +657 -0
  1159. package/src/shell/titlebar/recent-sessions-model.ts +469 -0
  1160. package/src/shell/titlebar/recent-sessions.tsx +1415 -0
  1161. package/src/shell/titlebar/recent-view-menu.tsx +147 -0
  1162. package/src/shell/titlebar/recent-view.test.ts +99 -0
  1163. package/src/shell/titlebar/recent-view.ts +183 -0
  1164. package/src/shell/titlebar/recently-closed-tabs-menu.css +25 -0
  1165. package/src/shell/titlebar/recently-closed-tabs-menu.tsx +260 -0
  1166. package/src/shell/titlebar/route-machine.test.ts +259 -0
  1167. package/src/shell/titlebar/route-machine.ts +206 -0
  1168. package/src/shell/titlebar/route-sync.ts +191 -0
  1169. package/src/shell/titlebar/session-events.test.ts +23 -0
  1170. package/src/shell/titlebar/session-events.ts +41 -0
  1171. package/src/shell/titlebar/session-rename-dialog-machine.test.ts +151 -0
  1172. package/src/shell/titlebar/session-rename-dialog-machine.ts +159 -0
  1173. package/src/shell/titlebar/sidebar-customized.standalone.stories.tsx +16 -0
  1174. package/src/shell/titlebar/sidebar-customized.tsx +747 -0
  1175. package/src/shell/titlebar/sidebar-pins.tsx +462 -0
  1176. package/src/shell/titlebar/sidebar-sessions.test.ts +96 -0
  1177. package/src/shell/titlebar/sidebar-sessions.ts +29 -0
  1178. package/src/shell/titlebar/sidebar-view-menu.tsx +191 -0
  1179. package/src/shell/titlebar/sidebar-view.test.ts +185 -0
  1180. package/src/shell/titlebar/sidebar-view.ts +208 -0
  1181. package/src/shell/titlebar/tab-group-drag-machine.ts +1479 -0
  1182. package/src/shell/titlebar/tab-groups-ui.tsx +1246 -0
  1183. package/src/shell/titlebar/tab-groups.css +269 -0
  1184. package/src/shell/titlebar/tab-groups.test.ts +667 -0
  1185. package/src/shell/titlebar/tab-groups.ts +496 -0
  1186. package/src/shell/titlebar/tab-hints-machine.test.ts +97 -0
  1187. package/src/shell/titlebar/tab-hints-machine.ts +79 -0
  1188. package/src/shell/titlebar/tab-load-machine.test.ts +178 -0
  1189. package/src/shell/titlebar/tab-load-machine.ts +233 -0
  1190. package/src/shell/titlebar/tab-nav.css +581 -0
  1191. package/src/shell/titlebar/tab-nav.tsx +891 -0
  1192. package/src/shell/titlebar/tab-order.test.ts +22 -0
  1193. package/src/shell/titlebar/tab-order.ts +24 -0
  1194. package/src/shell/titlebar/tab-popover-machine.test.ts +79 -0
  1195. package/src/shell/titlebar/tab-popover-machine.ts +92 -0
  1196. package/src/shell/titlebar/tab-popover.css +129 -0
  1197. package/src/shell/titlebar/tab-popover.tsx +144 -0
  1198. package/src/shell/titlebar/tab-rename-machine.test.ts +206 -0
  1199. package/src/shell/titlebar/tab-rename-machine.ts +297 -0
  1200. package/src/shell/titlebar/tab-strip.standalone.stories.tsx +19 -0
  1201. package/src/shell/titlebar/tab-strip.tsx +1228 -0
  1202. package/src/shell/titlebar/tab-title.test.ts +14 -0
  1203. package/src/shell/titlebar/tab-title.ts +6 -0
  1204. package/src/shell/titlebar/titlebar.css +197 -0
  1205. package/src/shell/titlebar/titlebar.tsx +1075 -0
  1206. package/src/shell/titlebar/windows-menu.test.ts +20 -0
  1207. package/src/shell/titlebar/windows-menu.tsx +193 -0
  1208. package/src/sst-env.d.ts +12 -0
  1209. package/src/theme-preload.test.ts +56 -0
  1210. package/src/tips/model.ts +155 -0
  1211. package/src/tips/queue.test.ts +43 -0
  1212. package/src/tips/queue.ts +46 -0
  1213. package/src/usage/dialog.css +8 -0
  1214. package/src/usage/dialog.standalone.stories.tsx +137 -0
  1215. package/src/usage/dialog.tsx +570 -0
  1216. package/src/usage/format.ts +39 -0
  1217. package/src/usage/limits.test.ts +141 -0
  1218. package/src/usage/limits.ts +189 -0
  1219. package/src/usage/machine.test.ts +128 -0
  1220. package/src/usage/machine.ts +159 -0
  1221. package/src/usage/model.tsx +55 -0
  1222. package/src/voice/call-machine.test.ts +245 -0
  1223. package/src/voice/call-machine.ts +327 -0
  1224. package/src/voice/call.ts +362 -0
  1225. package/src/voice/composer.tsx +300 -0
  1226. package/src/voice/context.tsx +152 -0
  1227. package/src/voice/coordination.test.ts +58 -0
  1228. package/src/voice/fixtures/history.ts +51 -0
  1229. package/src/voice/gate-machine.test.ts +91 -0
  1230. package/src/voice/gate-machine.ts +148 -0
  1231. package/src/voice/handoff.test.ts +35 -0
  1232. package/src/voice/handoff.ts +20 -0
  1233. package/src/voice/machine.test.ts +303 -0
  1234. package/src/voice/machine.ts +349 -0
  1235. package/src/voice/messages.test.ts +49 -0
  1236. package/src/voice/messages.ts +15 -0
  1237. package/src/voice/panel-machine.test.ts +106 -0
  1238. package/src/voice/panel-machine.ts +167 -0
  1239. package/src/voice/protocol.ts +62 -0
  1240. package/src/voice/replies.ts +71 -0
  1241. package/src/voice/reply-machine.test.ts +290 -0
  1242. package/src/voice/reply-machine.ts +303 -0
  1243. package/src/voice/search.test.ts +35 -0
  1244. package/src/voice/search.ts +134 -0
  1245. package/src/voice/spec.ts +114 -0
  1246. package/src/voice/tail-machine.test.ts +124 -0
  1247. package/src/voice/tail-machine.ts +155 -0
  1248. package/src/voice/tail.ts +55 -0
  1249. package/src/voice/tools.test.ts +320 -0
  1250. package/src/voice/tools.ts +336 -0
  1251. package/src/voice/transport-machine.test.ts +295 -0
  1252. package/src/voice/transport-machine.ts +338 -0
  1253. package/src/voice/transport.test.ts +295 -0
  1254. package/src/voice/transport.ts +313 -0
  1255. package/src/voice/voice.css +84 -0
  1256. package/src/workspaces/create.test.ts +120 -0
  1257. package/src/workspaces/create.ts +23 -0
  1258. package/src/workspaces/files/artifact.test.ts +103 -0
  1259. package/src/workspaces/files/artifact.ts +74 -0
  1260. package/src/workspaces/files/content-cache-accounting.test.ts +79 -0
  1261. package/src/workspaces/files/content-cache.ts +74 -0
  1262. package/src/workspaces/files/content-machine.test.ts +269 -0
  1263. package/src/workspaces/files/content-machine.ts +243 -0
  1264. package/src/workspaces/files/model.tsx +423 -0
  1265. package/src/workspaces/files/path.test.ts +76 -0
  1266. package/src/workspaces/files/path.ts +143 -0
  1267. package/src/workspaces/files/tree-machine.test.ts +300 -0
  1268. package/src/workspaces/files/tree-machine.ts +286 -0
  1269. package/src/workspaces/files/tree-store.ts +142 -0
  1270. package/src/workspaces/files/types.ts +85 -0
  1271. package/src/workspaces/files/view-cache.ts +164 -0
  1272. package/src/workspaces/files/watcher.test.ts +114 -0
  1273. package/src/workspaces/files/watcher.ts +42 -0
  1274. package/src/workspaces/inventory.test.ts +151 -0
  1275. package/src/workspaces/inventory.ts +64 -0
  1276. package/src/workspaces/location-machine.test.ts +135 -0
  1277. package/src/workspaces/location-machine.ts +159 -0
  1278. package/src/workspaces/location.tsx +111 -0
  1279. package/src/workspaces/path-key.ts +5 -0
  1280. package/src/workspaces/paths.test.ts +193 -0
  1281. package/src/workspaces/paths.ts +123 -0
  1282. package/src/workspaces/selection/combobox-machine.test.ts +286 -0
  1283. package/src/workspaces/selection/combobox-machine.ts +331 -0
  1284. package/src/workspaces/selection/dialog.css +234 -0
  1285. package/src/workspaces/selection/dialog.standalone.stories.tsx +66 -0
  1286. package/src/workspaces/selection/dialog.tsx +867 -0
  1287. package/src/workspaces/selection/domain.test.ts +603 -0
  1288. package/src/workspaces/selection/domain.ts +609 -0
  1289. package/src/workspaces/selection/picker.test.ts +37 -0
  1290. package/src/workspaces/selection/picker.tsx +77 -0
  1291. package/src/workspaces/selection/policy.ts +8 -0
  1292. package/src/workspaces/selection/queue-machine.test.ts +116 -0
  1293. package/src/workspaces/selection/queue-machine.ts +203 -0
  1294. package/src/workspaces/selection/tree-machine.test.ts +293 -0
  1295. package/src/workspaces/selection/tree-machine.ts +506 -0
  1296. package/test-browser/animated-presence-state.test.ts +134 -0
  1297. package/test-browser/auto-scroll.test.ts +111 -0
  1298. package/test-browser/browser-pane-model.test.ts +522 -0
  1299. package/test-browser/child-store-eviction.test.ts +86 -0
  1300. package/test-browser/command-palette-search.test.ts +157 -0
  1301. package/test-browser/command-palette.test.ts +262 -0
  1302. package/test-browser/composer-attachment-errors.test.tsx +140 -0
  1303. package/test-browser/composer-attachment-ownership.test.tsx +132 -0
  1304. package/test-browser/composer-drag-cancel.test.tsx +41 -0
  1305. package/test-browser/composer-file-search.test.ts +183 -0
  1306. package/test-browser/composer-ime.test.ts +58 -0
  1307. package/test-browser/composer-submit-loading.test.ts +235 -0
  1308. package/test-browser/composer-write-batch.test.ts +201 -0
  1309. package/test-browser/draft-history-cache.test.ts +139 -0
  1310. package/test-browser/elicitation-dock.test.ts +110 -0
  1311. package/test-browser/file-tree-store.test.ts +113 -0
  1312. package/test-browser/fixtures/model-selection.ts +646 -0
  1313. package/test-browser/message-page-publication.test.ts +46 -0
  1314. package/test-browser/model-selection.test.ts +25 -0
  1315. package/test-browser/motion-dom.test.ts +367 -0
  1316. package/test-browser/motion-spring.test.ts +75 -0
  1317. package/test-browser/pane-drag.test.tsx +136 -0
  1318. package/test-browser/panel-motion.test.ts +398 -0
  1319. package/test-browser/persisted-consumers.test.ts +40 -0
  1320. package/test-browser/playwright-config.test.ts +72 -0
  1321. package/test-browser/plugin-catalog.test.ts +67 -0
  1322. package/test-browser/plugin-link-check.test.ts +102 -0
  1323. package/test-browser/plugin-migrations.test.ts +170 -0
  1324. package/test-browser/plugin-primitives.test.ts +616 -0
  1325. package/test-browser/plugin-server-stream.test.ts +88 -0
  1326. package/test-browser/presence.test.ts +236 -0
  1327. package/test-browser/project-avatar-hover.test.ts +143 -0
  1328. package/test-browser/prompt-motion.test.ts +10 -0
  1329. package/test-browser/prompt-persistence.test.ts +312 -0
  1330. package/test-browser/prompt-scope.test.ts +15 -0
  1331. package/test-browser/provider-catalog.test.ts +54 -0
  1332. package/test-browser/pwa-route.test.ts +96 -0
  1333. package/test-browser/question-dock.test.ts +128 -0
  1334. package/test-browser/schema-persistence.test.ts +294 -0
  1335. package/test-browser/selected-effect.test.ts +36 -0
  1336. package/test-browser/server-connection-sync.test.ts +34 -0
  1337. package/test-browser/server-notification-state.test.ts +662 -0
  1338. package/test-browser/session-activity-elapsed.test.ts +62 -0
  1339. package/test-browser/session-background.test.ts +377 -0
  1340. package/test-browser/session-message-handoffs.test.ts +118 -0
  1341. package/test-browser/session-resolution.test.ts +385 -0
  1342. package/test-browser/settings-keybinds.test.ts +196 -0
  1343. package/test-browser/shell-panel.test.ts +219 -0
  1344. package/test-browser/sidebar-peek.test.ts +149 -0
  1345. package/test-browser/solid-router-cleanup.test.ts +66 -0
  1346. package/test-browser/solid-runtime.test.ts +95 -0
  1347. package/test-browser/solid-virtual.test.ts +249 -0
  1348. package/test-browser/ssh-composer.test.ts +41 -0
  1349. package/test-browser/ssh-health.test.ts +142 -0
  1350. package/test-browser/theme-preload.test.ts +9 -0
  1351. package/test-browser/timeline-cache.test.ts +571 -0
  1352. package/test-browser/timeline-projection.test.ts +363 -0
  1353. package/test-browser/toast-owner.test.ts +66 -0
  1354. package/test-browser/websearch-request.test.ts +277 -0
  1355. package/tsconfig.json +35 -0
  1356. package/vite.config.ts +62 -0
  1357. package/vite.icons.test.ts +133 -0
  1358. package/vite.icons.ts +65 -0
  1359. package/vite.js +142 -0
  1360. package/vite.pwa.ts +69 -0
@@ -0,0 +1,1785 @@
1
+ import { afterEach, describe, expect, jest, test } from "bun:test"
2
+ import type { SessionRef } from "@zyro-sec/plugin/gui"
3
+ import type { ModelSelection } from "@/providers/models/selection"
4
+ import { PROMPT_GATE_TIMEOUT_MS, settlePromptGates } from "@/runtime/plugin/prompt-gate"
5
+ import type { SessionMessageHandoff } from "@/session/handoff"
6
+ import { Skill } from "@zyro-sec/schema/skill"
7
+ import { createRoot } from "solid-js"
8
+ import type {
9
+ ActiveComposerAdapter,
10
+ ComposerControls,
11
+ ComposerDelivery,
12
+ ComposerSession,
13
+ NewSessionComposerAdapter,
14
+ } from "./adapter"
15
+ import { createMemoryComposerState, type Prompt } from "./state"
16
+ import { composerSubmitView } from "./machine"
17
+ import { createComposerSubmit } from "./submit"
18
+ import { createSteerBackground } from "@/session/requests/steer-background"
19
+ import { setMediaBlobLoader } from "@/runtime/persistence/drafts"
20
+ import type { ComposerStateTarget } from "./submission-state"
21
+
22
+ // SAFETY: submission reads only the selected model's id, name, and provider id.
23
+ const selectedModel = {
24
+ id: "model-1",
25
+ name: "Model 1",
26
+ provider: { id: "provider-1" },
27
+ } as NonNullable<ReturnType<ModelSelection["current"]>>
28
+
29
+ const selection = {
30
+ ready: Object.assign(() => true, { promise: undefined }),
31
+ key: () => ({ providerID: "provider-1", modelID: "model-1" }),
32
+ current: () => selectedModel,
33
+ recent: () => [selectedModel],
34
+ favorite: { list: () => [], toggle() {} },
35
+ list: () => [selectedModel],
36
+ cycle() {},
37
+ set() {},
38
+ visible: () => true,
39
+ setVisibility() {},
40
+ variant: {
41
+ configured: () => undefined,
42
+ current: () => "balanced",
43
+ list: () => ["balanced"],
44
+ set() {},
45
+ cycle() {},
46
+ },
47
+ } satisfies ModelSelection
48
+
49
+ function controls(): ComposerControls {
50
+ return {
51
+ agents: {
52
+ available: [{ name: "build", mode: "primary" }],
53
+ options: ["build"],
54
+ current: "build",
55
+ visible: true,
56
+ select() {},
57
+ },
58
+ model: { selection, paid: true, loading: false },
59
+ }
60
+ }
61
+
62
+ function active(state: ComposerStateTarget, target: ComposerSession, ctl = controls): ActiveComposerAdapter {
63
+ return {
64
+ kind: "active-session",
65
+ state,
66
+ ready: () => true,
67
+ controls: ctl,
68
+ working: () => false,
69
+ session: () => target,
70
+ interrupt: async () => undefined,
71
+ submitted() {},
72
+ setEditor() {},
73
+ }
74
+ }
75
+
76
+ function fresh(state: ComposerStateTarget, start: NewSessionComposerAdapter["start"]): NewSessionComposerAdapter {
77
+ return { kind: "new-session", state, ready: () => true, controls, working: () => false, submitted() {}, start }
78
+ }
79
+
80
+ function submitInput(
81
+ adapter: ActiveComposerAdapter | NewSessionComposerAdapter,
82
+ notify: Parameters<typeof createComposerSubmit>[0]["notify"] = {
83
+ missingSelection() {},
84
+ unqueueable() {},
85
+ failed() {},
86
+ },
87
+ mode: "normal" | "shell" = "normal",
88
+ commands: () => readonly { name: string }[] | undefined = () => [],
89
+ history: string[] = [],
90
+ clientCommand?: (text: string) => (() => void | Promise<void>) | undefined,
91
+ delivery: (alternate: boolean) => ComposerDelivery = () => "steer",
92
+ ready?: Parameters<typeof createComposerSubmit>[0]["ready"],
93
+ comments: Parameters<typeof createComposerSubmit>[0]["comments"] = {
94
+ capture: () => [],
95
+ clear() {},
96
+ remove() {},
97
+ restore() {},
98
+ },
99
+ ) {
100
+ return createComposerSubmit({
101
+ adapter,
102
+ ready,
103
+ mode: () => mode,
104
+ commands,
105
+ clientCommand,
106
+ delivery,
107
+ editor: () => undefined,
108
+ queueScroll() {},
109
+ addToHistory: (prompt) =>
110
+ history.push(`add:${prompt.map((part) => ("content" in part ? part.content : part.type)).join("")}`),
111
+ removeFromHistory: (prompt) =>
112
+ history.push(`remove:${prompt.map((part) => ("content" in part ? part.content : part.type)).join("")}`),
113
+ resetHistory() {},
114
+ closePopover() {},
115
+ notify,
116
+ comments,
117
+ })
118
+ }
119
+
120
+ const sessions = { count: 0 }
121
+
122
+ function session(input: {
123
+ calls: string[]
124
+ prompt?: (value: Parameters<ComposerSession["data"]["session"]["prompt"]>[0]) => Promise<void>
125
+ handoff?: ComposerSession["handoff"]
126
+ statuses?: ("idle" | "running")[]
127
+ current?: ComposerSession["current"]
128
+ admitted?: (messageID: string) => boolean
129
+ shell?: ComposerSession["api"]["shell"]
130
+ command?: ComposerSession["api"]["command"]
131
+ switchAgent?: ComposerSession["api"]["switchAgent"]
132
+ switchModel?: ComposerSession["api"]["switchModel"]
133
+ background?: ComposerSession["background"]
134
+ accept?: () => void
135
+ /** Requests leave as the data layer's send chain lets them: each once the one before it has settled. */
136
+ chained?: boolean
137
+ }): ComposerSession {
138
+ // The requests made so far, settled or not: the next one starts once they all have.
139
+ const chain: Promise<unknown>[] = []
140
+
141
+ const sequence: ComposerSession["data"]["session"]["sequence"] = (_sessionID, send, prepare) => {
142
+ const run = async () => {
143
+ await prepare?.()
144
+
145
+ return send()
146
+ }
147
+
148
+ if (!input.chained) return run()
149
+ const next = Promise.all(chain.splice(0)).then(run)
150
+
151
+ chain.push(next.catch(() => undefined))
152
+
153
+ return next
154
+ }
155
+
156
+ return {
157
+ // Unique per test: what this client knows about a session outlives the test that sent to it.
158
+ id: `session-${++sessions.count}`,
159
+ background: input.background,
160
+ directory: "C:/repo",
161
+ handoff: input.handoff ?? { set() {}, hold() {}, settle() {}, clear() {} },
162
+ current: input.current ?? (() => undefined),
163
+ admitted: input.admitted ?? (() => false),
164
+ api: {
165
+ switchAgent:
166
+ input.switchAgent ??
167
+ (async () => {
168
+ input.calls.push("switch-agent")
169
+ }),
170
+ switchModel:
171
+ input.switchModel ??
172
+ (async () => {
173
+ input.calls.push("switch-model")
174
+ }),
175
+ shell:
176
+ input.shell ??
177
+ (async () => {
178
+ input.calls.push("shell")
179
+ }),
180
+ command: input.command ?? (async () => undefined),
181
+ revert: {
182
+ commit: async () => {
183
+ input.calls.push("revert-commit")
184
+ },
185
+ },
186
+ },
187
+ file: { list: async () => ({ data: [{ path: "src/api.ts" }] }) },
188
+ data: {
189
+ location: { command: { list: () => [] } },
190
+ session: {
191
+ setStatus: (_sessionID, status) => input.statuses?.push(status),
192
+ acceptSend: () => {
193
+ input.calls.push("accept-send")
194
+ input.accept?.()
195
+ },
196
+ sequence,
197
+ // Like the data layer: admit locally, then prepare and send in the session's send chain.
198
+ prompt: (value) => {
199
+ input.calls.push("admit")
200
+
201
+ return sequence(value.sessionID, async () => {
202
+ await value.prepare?.()
203
+ input.calls.push("send")
204
+ await input.prompt?.(value)
205
+
206
+ // The admitted inbox item, as the server returns it.
207
+ return {
208
+ id: value.id ?? "msg_admitted",
209
+ sessionID: value.sessionID,
210
+ time: { created: 0 },
211
+ type: "user" as const,
212
+ payload: { text: value.text },
213
+ delivery: value.delivery ?? "steer",
214
+ }
215
+ })
216
+ },
217
+ },
218
+ },
219
+ }
220
+ }
221
+
222
+ function text(state: ComposerStateTarget) {
223
+ return state
224
+ .current()
225
+ .map((part) => ("content" in part ? part.content : ""))
226
+ .join("")
227
+ }
228
+
229
+ describe("Composer submission", () => {
230
+ test("retains the submitting session before waiting for server admission", async () => {
231
+ const calls: string[] = []
232
+
233
+ const admitted = Promise.withResolvers<void>()
234
+
235
+ const state = createMemoryComposerState({ prompt: "Hello" }).capture()
236
+
237
+ const adapter = {
238
+ ...active(state, session({ calls, prompt: () => admitted.promise })),
239
+ beforeSubmit: () => calls.push("keep-preview"),
240
+ }
241
+
242
+ const submitted = submitInput(adapter).submit(new Event("submit"))
243
+
244
+ expect(calls).toEqual(["keep-preview"])
245
+ await submitted
246
+ admitted.resolve()
247
+ expect(calls[0]).toBe("keep-preview")
248
+ expect(calls).toContain("admit")
249
+ })
250
+
251
+ // Runs the promise jobs queued so far: more turns than a send's longest chain before its request leaves.
252
+ const flush = async () => {
253
+ for (const _ of Array.from({ length: 32 })) await Promise.resolve()
254
+ }
255
+
256
+ const typed = (content: string): Prompt => [{ type: "text", content, start: 0, end: content.length }]
257
+
258
+ // A composer of `target` whose sends wait on `ready`, with what it reported as failed.
259
+ const gated = (
260
+ target: ComposerSession,
261
+ ready: (sessionID: string) => Promise<void>,
262
+ input: { prompt: string; mode?: "normal" | "shell"; calls?: string[] },
263
+ ) => {
264
+ const state = createMemoryComposerState({ prompt: input.prompt }).capture()
265
+ const failures: string[] = []
266
+ const history: string[] = []
267
+ const adapter = { ...active(state, target), interrupt: async () => void input.calls?.push("interrupt") }
268
+
269
+ const submission = submitInput(
270
+ adapter,
271
+ { missingSelection() {}, unqueueable() {}, failed: (kind) => failures.push(kind) },
272
+ input.mode ?? "normal",
273
+ () => [{ name: "review" }],
274
+ history,
275
+ undefined,
276
+ () => "steer",
277
+ ready,
278
+ )
279
+
280
+ return { state, submission, failures, history }
281
+ }
282
+
283
+ test("a prompt shows at once, and its composer takes no other send until what the plugins prepare is ready", async () => {
284
+ const calls: string[] = []
285
+ const gate = Promise.withResolvers<void>()
286
+ const sent = Promise.withResolvers<void>()
287
+ const target = session({ calls, prompt: async () => sent.resolve() })
288
+
289
+ const composer = gated(
290
+ target,
291
+ (sessionID) => {
292
+ calls.push(sessionID === target.id ? "gate" : "gate for another session")
293
+
294
+ return gate.promise
295
+ },
296
+ { prompt: "Hello" },
297
+ )
298
+
299
+ const submitted = composer.submission.submit(new Event("submit"))
300
+ await flush()
301
+
302
+ // The prompt is admitted locally and the composer cleared, but nothing has left, and the send is still the
303
+ // composer's: its view offers Stop for it.
304
+ expect(calls.filter((call) => call === "gate" || call === "admit" || call === "send")).toEqual(["gate", "admit"])
305
+ expect(text(composer.state)).toBe("")
306
+ expect(composer.submission.state().type).toBe("sending")
307
+
308
+ // A second Enter, on whatever was typed meanwhile, starts no second send.
309
+ composer.state.set(typed("again"), 5)
310
+ await composer.submission.submit(new Event("submit"))
311
+ expect(calls.filter((call) => call === "gate" || call === "admit")).toEqual(["gate", "admit"])
312
+ expect(text(composer.state)).toBe("again")
313
+
314
+ gate.resolve()
315
+ await submitted
316
+ await sent.promise
317
+ expect(calls.filter((call) => call === "gate" || call === "admit" || call === "send")).toEqual(["gate", "admit", "send"])
318
+ expect(composer.submission.state()).toEqual({ type: "idle", attempt: 1 })
319
+ })
320
+
321
+ test.each([
322
+ { name: "a prompt", prompt: "Hello", left: "Hello" },
323
+ { name: "a prompt, with a draft typed since", prompt: "Hello", edit: "next", left: "Hello\n\nnext" },
324
+ { name: "a server command", prompt: "/review now", left: "/review now" },
325
+ ])("Stop while $name waits on the gate cancels that send: nothing reaches the server and its text comes back", async (row) => {
326
+ const calls: string[] = []
327
+ const timeline: string[] = []
328
+ const statuses: ("idle" | "running")[] = []
329
+ const gate = Promise.withResolvers<void>()
330
+
331
+ const target = session({
332
+ calls,
333
+ statuses,
334
+ handoff: { set: () => timeline.push("set"), hold() {}, settle: () => timeline.push("settle"), clear: () => timeline.push("clear") },
335
+ command: async () => void calls.push("command"),
336
+ })
337
+
338
+ const composer = gated(target, () => gate.promise, { prompt: row.prompt, calls })
339
+ const submitted = composer.submission.submit(new Event("submit"))
340
+ await flush()
341
+ expect(composer.submission.state().type).toBe("sending")
342
+ expect(text(composer.state)).toBe("")
343
+
344
+ if (row.edit) composer.state.set(typed(row.edit), row.edit.length)
345
+ await composer.submission.stop()
346
+ await submitted
347
+ await flush()
348
+
349
+ // Neither the request nor an interrupt: the Session was never told of this send.
350
+ expect(calls.filter((call) => call === "send" || call === "command" || call === "interrupt")).toEqual([])
351
+ expect(text(composer.state)).toBe(row.left)
352
+ expect(composer.failures).toEqual([])
353
+ expect(composer.submission.state()).toEqual({ type: "idle", attempt: 1 })
354
+ // A prompt that showed in the Session is taken out of it again, and the Session is not left looking busy.
355
+ expect(timeline).toEqual(row.prompt.startsWith("/") ? [] : ["set", "clear"])
356
+ expect(statuses.at(-1) ?? "idle").toBe("idle")
357
+ expect(composer.history).toEqual([`add:${row.prompt}`, `remove:${row.prompt}`])
358
+
359
+ // What the send waited for is ready later: the result belongs to a send that no longer exists.
360
+ gate.resolve()
361
+ await flush()
362
+ expect(calls.filter((call) => call === "send" || call === "command")).toEqual([])
363
+ expect(composer.submission.state()).toEqual({ type: "idle", attempt: 1 })
364
+ })
365
+
366
+ test.each([
367
+ {
368
+ name: "a prompt into a staged revert, with another agent and model selected",
369
+ prompt: "Hello",
370
+ current: { agent: "plan", model: { id: "old", providerID: "old" }, revert: { messageID: "msg_reverted" } },
371
+ },
372
+ {
373
+ name: "a prompt with another agent and model selected",
374
+ prompt: "Hello",
375
+ current: { agent: "plan", model: { id: "old", providerID: "old" } },
376
+ },
377
+ {
378
+ name: "a server command with another agent and model selected",
379
+ prompt: "/review now",
380
+ current: { agent: "plan", model: { id: "old", providerID: "old" } },
381
+ },
382
+ ])("Stop while $name waits on the gate changes nothing on the server", async (row) => {
383
+ const calls: string[] = []
384
+ const gate = Promise.withResolvers<void>()
385
+ const target = session({ calls, current: () => row.current, command: async () => void calls.push("command") })
386
+ const composer = gated(target, () => gate.promise, { prompt: row.prompt, calls })
387
+ const submitted = composer.submission.submit(new Event("submit"))
388
+
389
+ await flush()
390
+ await composer.submission.stop()
391
+ await submitted
392
+ gate.resolve()
393
+ await flush()
394
+
395
+ // Only the prompt's local admission, which the cancelled send takes back: no revert commit, switch or request.
396
+ expect(calls.filter((call) => call !== "admit")).toEqual([])
397
+ expect(text(composer.state)).toBe(row.prompt)
398
+ })
399
+
400
+ test("Stop while a prompt waits on the gate keeps a comment added meanwhile, though no text was typed", async () => {
401
+ const gate = Promise.withResolvers<void>()
402
+ const composer = gated(session({ calls: [] }), () => gate.promise, { prompt: "Hello" })
403
+ composer.state.context.add({ type: "file", path: "src/sent.ts", comment: "Sent with it", commentID: "sent" })
404
+ const submitted = composer.submission.submit(new Event("submit"))
405
+
406
+ await flush()
407
+ expect(composer.state.context.items()).toEqual([])
408
+ composer.state.context.add({ type: "file", path: "src/later.ts", comment: "Added while it waited", commentID: "later" })
409
+ await composer.submission.stop()
410
+ await submitted
411
+ await flush()
412
+
413
+ expect(text(composer.state)).toBe("Hello")
414
+ expect(composer.state.context.items().map((item) => item.type === "file" && item.comment)).toEqual([
415
+ "Sent with it",
416
+ "Added while it waited",
417
+ ])
418
+ })
419
+
420
+ // The composer the person presses Stop in is not always the one that made the send: a new session's composer
421
+ // unmounts as soon as Enter is pressed, and a tab switch away and back mounts a session's composer anew.
422
+ test.each([
423
+ { name: "a new session's first prompt, from the session's own composer", draft: true },
424
+ { name: "a prompt whose composer a tab switch has replaced", draft: false },
425
+ ])("Stop cancels $name while it waits on the gate", async (row) => {
426
+ const calls: string[] = []
427
+ const timeline: string[] = []
428
+ const failures: string[] = []
429
+ const gate = Promise.withResolvers<void>()
430
+ // The send ends one way or the other: its prompt leaves the timeline, or its request leaves the window.
431
+ const ended = Promise.withResolvers<void>()
432
+
433
+ const target = session({
434
+ calls,
435
+ prompt: async () => ended.resolve(),
436
+ handoff: {
437
+ set: () => timeline.push("set"),
438
+ hold() {},
439
+ settle() {},
440
+ clear: () => {
441
+ timeline.push("clear")
442
+ ended.resolve()
443
+ },
444
+ },
445
+ })
446
+
447
+ const image = {
448
+ type: "image" as const,
449
+ id: "attachment",
450
+ filename: "shot.png",
451
+ mime: "image/png",
452
+ blob: { id: "attachment", url: "data:image/png;base64,YQ==" },
453
+ }
454
+
455
+ const draft = createMemoryComposerState({ prompt: "first prompt" }).capture()
456
+ draft.set([...draft.current(), image])
457
+ // What the session's composer holds: its own draft, which a new session's first prompt is moved to.
458
+ const seen = row.draft ? createMemoryComposerState().capture() : draft
459
+
460
+ const sender = row.draft
461
+ ? fresh(draft, async (_selection, submission) => {
462
+ submission.retarget(seen)
463
+
464
+ return { session: target, cleanupReady: Promise.resolve() }
465
+ })
466
+ : active(draft, target)
467
+
468
+ const notify = { missingSelection() {}, unqueueable() {}, failed: (kind: string) => void failures.push(kind) }
469
+
470
+ const compose = (adapter: ActiveComposerAdapter | NewSessionComposerAdapter) =>
471
+ submitInput(adapter, notify, undefined, undefined, undefined, undefined, undefined, () => gate.promise)
472
+
473
+ const unmount = createRoot((dispose) => {
474
+ void compose(sender).submit(new Event("submit"))
475
+
476
+ return dispose
477
+ })
478
+
479
+ // A new session's composer goes at Enter; a tab switch comes once the prompt shows and waits.
480
+ if (row.draft) unmount()
481
+ await flush()
482
+
483
+ if (!row.draft) unmount()
484
+ expect(timeline).toEqual(["set"])
485
+ expect(text(seen)).toBe("")
486
+
487
+ await compose({ ...active(seen, target), interrupt: async () => void calls.push("interrupt") }).stop()
488
+ // What the send waited for is ready later: the cancelled prompt must not leave then either.
489
+ gate.resolve()
490
+ await ended.promise
491
+ await flush()
492
+
493
+ expect(calls.filter((call) => call === "send" || call === "interrupt")).toEqual([])
494
+ expect(timeline).toEqual(["set", "clear"])
495
+ expect(text(seen)).toBe("first prompt")
496
+ expect(seen.current()).toContainEqual(image)
497
+ expect(failures).toEqual([])
498
+
499
+ // Nothing waits any more, so the next Stop interrupts the session as before.
500
+ await compose({ ...active(seen, target), interrupt: async () => void calls.push("interrupt") }).stop()
501
+ expect(calls.filter((call) => call === "interrupt")).toEqual(["interrupt"])
502
+ })
503
+
504
+ // A session's draft composer and its own composer are two of these. Each press of Enter is one send, and the server
505
+ // must receive them in that order, whatever each waited for: here the prompt waits on the gate, the server command
506
+ // on the gate and on the prompt, and the shell command, which has no gate, on both.
507
+ describe("order", () => {
508
+ afterEach(() => void jest.useRealTimers())
509
+
510
+ test.each(["is ready", "times out"] as const)(
511
+ "a prompt, a server command and a shell command reach the server in that order when the gate %s",
512
+ async (how) => {
513
+ if (how === "times out") jest.useFakeTimers()
514
+ const calls: string[] = []
515
+ const gate = Promise.withResolvers<void>()
516
+
517
+ const target = session({
518
+ calls,
519
+ chained: true,
520
+ prompt: async () => void calls.push("prompt"),
521
+ command: async () => void calls.push("command"),
522
+ shell: async () => void calls.push("shell"),
523
+ })
524
+
525
+ // SAFETY: the gate under test never reads the session.
526
+ const ref = { key: `server\n${target.id}`, id: target.id } as SessionRef
527
+ const never = { plugin: "browser", value: { ready: () => new Promise<void>(() => undefined) } }
528
+
529
+ const ready = () =>
530
+ how === "times out" ? settlePromptGates([never], () => true, ref) : gate.promise
531
+
532
+ const sends = [
533
+ gated(target, ready, { prompt: "Hello" }),
534
+ gated(target, ready, { prompt: "/review now" }),
535
+ gated(target, ready, { prompt: "ls", mode: "shell" }),
536
+ ].map((composer) => composer.submission.submit(new Event("submit")))
537
+
538
+ await flush()
539
+ // The shell command has nothing to wait for of its own, and still does not go first.
540
+ expect(calls.filter((call) => call === "prompt" || call === "command" || call === "shell")).toEqual([])
541
+
542
+ if (how === "times out") jest.advanceTimersByTime(PROMPT_GATE_TIMEOUT_MS)
543
+ gate.resolve()
544
+ await Promise.all(sends)
545
+ await flush()
546
+ expect(calls.filter((call) => call === "prompt" || call === "command" || call === "shell")).toEqual([
547
+ "prompt",
548
+ "command",
549
+ "shell",
550
+ ])
551
+ },
552
+ )
553
+ })
554
+
555
+ test("marks the session accepted only once the send is admitted", async () => {
556
+ const calls: string[] = []
557
+ const accepted = Promise.withResolvers<void>()
558
+ const state = createMemoryComposerState({ prompt: "Hello" }).capture()
559
+
560
+ await submitInput(active(state, session({ calls, accept: () => accepted.resolve() }))).submit(
561
+ new Event("submit"),
562
+ )
563
+ await accepted.promise
564
+
565
+ expect(calls.filter((call) => call === "accept-send")).toHaveLength(1)
566
+ })
567
+
568
+ test("an empty submit does not retain a preview", async () => {
569
+ const calls: string[] = []
570
+
571
+ const state = createMemoryComposerState().capture()
572
+
573
+ const adapter = {
574
+ ...active(state, session({ calls })),
575
+ beforeSubmit: () => calls.push("keep-preview"),
576
+ }
577
+
578
+ await submitInput(adapter).submit(new Event("submit"))
579
+ expect(calls).toEqual([])
580
+ })
581
+
582
+ test("pressing Enter and then Send while an image attachment resolves sends the prompt once", async () => {
583
+ const state = createMemoryComposerState({ prompt: "ship it" }).capture()
584
+ const id = `media:${"a".repeat(64)}`
585
+ state.set([
586
+ ...state.current(),
587
+ { type: "image", id, filename: "shot.png", mime: "image/png", blob: { id, url: "" } },
588
+ ])
589
+ // The image's bytes load through the media loader, which answers only when the test lets it.
590
+ const loaded = Promise.withResolvers<string | undefined>()
591
+ setMediaBlobLoader("composer-double-submit", () => loaded.promise)
592
+ const handoffs: SessionMessageHandoff[] = []
593
+
594
+ const calls: string[] = []
595
+
596
+ const submission = submitInput({
597
+ ...active(
598
+ state,
599
+ session({ calls, handoff: { set: (handoff) => handoffs.push(handoff), hold() {}, settle() {}, clear() {} } }),
600
+ ),
601
+ beforeSubmit: () => calls.push("keep-preview"),
602
+ })
603
+
604
+ const enter = submission.submit(new Event("submit"))
605
+ const send = submission.submit(new Event("submit"))
606
+
607
+ expect(calls).toEqual(["keep-preview"])
608
+ loaded.resolve("data:image/png;base64,YQ==")
609
+ await Promise.all([enter, send])
610
+ setMediaBlobLoader("composer-double-submit", undefined)
611
+
612
+ expect(handoffs.map((handoff) => handoff.message.text)).toEqual(["ship it"])
613
+ expect(state.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }])
614
+ })
615
+
616
+ test.each(["steer", "queue"] as const)(
617
+ "sends only the selected quote as a %s, including its comment mentions, without clearing the draft",
618
+ async (delivery) => {
619
+ const state = createMemoryComposerState({ prompt: "/review keep this draft" }).capture()
620
+
621
+ const image = {
622
+ type: "image" as const,
623
+ id: "unrelated-image",
624
+ filename: "draft.png",
625
+ mime: "image/png",
626
+ blob: { id: "unrelated-image", url: "data:image/png;base64,YQ==" },
627
+ }
628
+
629
+ state.set([...state.current(), image], 5)
630
+ state.mode.set("shell")
631
+ state.context.add({ type: "quote", text: "Selected passage", commentID: "selected", comment: "Old comment" })
632
+ state.context.add({ type: "quote", text: "Unrelated passage", commentID: "other" })
633
+ state.context.add({ type: "file", path: "unrelated.ts" })
634
+ const before = state.current()
635
+
636
+ const requests: Parameters<ComposerSession["data"]["session"]["prompt"]>[0][] = []
637
+
638
+ const calls: string[] = []
639
+
640
+ const submission = submitInput(
641
+ {
642
+ ...active(state, session({ calls, prompt: async (value) => void requests.push(value) })),
643
+ beforeSubmit: () => calls.push("keep-preview"),
644
+ },
645
+ undefined,
646
+ "shell",
647
+ undefined,
648
+ undefined,
649
+ undefined,
650
+ (alternate) => {
651
+ expect(alternate).toBe(true)
652
+
653
+ return delivery
654
+ },
655
+ )
656
+
657
+ expect(await submission.submitComment("quote:c=selected", "Compare @src/api.ts with @here")).toBe(true)
658
+ expect(calls[0]).toBe("keep-preview")
659
+ expect(requests).toHaveLength(1)
660
+ expect(requests[0]?.text).toBe(
661
+ "> Selected passage\n\nCompare @src/api.ts with @here",
662
+ )
663
+ expect(requests[0]).toMatchObject({
664
+ delivery,
665
+ files: [{ uri: "file:///C:/repo/src/api.ts", name: "api.ts" }],
666
+ agents: [],
667
+ skills: [],
668
+ metadata: {
669
+ displayText: "",
670
+ comments: [{ type: "quote", text: "Selected passage", comment: "Compare @src/api.ts with @here" }],
671
+ attachments: [],
672
+ },
673
+ })
674
+ expect(state.current()).toBe(before)
675
+ expect(state.cursor()).toBe(5)
676
+ expect(state.mode.current()).toBe("shell")
677
+ expect(state.context.items().map((item) => item.key)).toEqual([
678
+ "quote:c=other",
679
+ "file:unrelated.ts:undefined:undefined",
680
+ ])
681
+ },
682
+ )
683
+
684
+ test("a file comment sends alone with Enter's delivery and leaves the composer and the file's comments", async () => {
685
+ const state = createMemoryComposerState({ prompt: "Keep this draft" }).capture()
686
+
687
+ state.context.add({
688
+ type: "file",
689
+ path: "src/api.ts",
690
+ selection: { startLine: 2, startChar: 0, endLine: 3, endChar: 0 },
691
+ comment: "Rename this",
692
+ commentID: "c1",
693
+ })
694
+ state.context.add({ type: "quote", text: "Unrelated passage", commentID: "other" })
695
+ const key = state.context.items()[0]?.key ?? ""
696
+
697
+ const requests: Parameters<ComposerSession["data"]["session"]["prompt"]>[0][] = []
698
+
699
+ const removed: string[] = []
700
+
701
+ const alternates: boolean[] = []
702
+
703
+ const submission = submitInput(
704
+ active(state, session({ calls: [], prompt: async (value) => void requests.push(value) })),
705
+ undefined,
706
+ undefined,
707
+ undefined,
708
+ undefined,
709
+ undefined,
710
+ (alternate) => {
711
+ alternates.push(alternate)
712
+
713
+ return "queue"
714
+ },
715
+ undefined,
716
+ { capture: () => [], clear() {}, remove: (path, id) => void removed.push(`${path}#${id}`), restore() {} },
717
+ )
718
+
719
+ expect(await submission.submitComment(key, "Rename this", { alternate: false })).toBe(true)
720
+ expect(alternates).toEqual([false])
721
+ expect(requests[0]?.delivery).toBe("queue")
722
+ expect(requests[0]?.metadata).toMatchObject({ comments: [{ path: "src/api.ts", comment: "Rename this" }] })
723
+ expect(removed).toEqual(["src/api.ts#c1"])
724
+ expect(state.current()).toEqual([{ type: "text", content: "Keep this draft", start: 0, end: 15 }])
725
+ expect(state.context.items().map((item) => item.key)).toEqual(["quote:c=other"])
726
+ })
727
+
728
+ test("a failed quote send retains its latest comment and prevents duplicate submissions while pending", async () => {
729
+ const state = createMemoryComposerState({ prompt: "Keep this draft" }).capture()
730
+
731
+ state.context.add({ type: "quote", text: "Selected passage", commentID: "selected" })
732
+ const failed = Promise.withResolvers<void>()
733
+
734
+ const started = Promise.withResolvers<void>()
735
+
736
+ const errors: string[] = []
737
+
738
+ const calls: string[] = []
739
+
740
+ const submission = submitInput(
741
+ active(
742
+ state,
743
+ session({
744
+ calls,
745
+ prompt: async () => {
746
+ started.resolve()
747
+ await failed.promise
748
+ },
749
+ }),
750
+ ),
751
+ { missingSelection() {}, unqueueable() {}, failed: (_kind, error) => void errors.push(String(error)) },
752
+ )
753
+
754
+ const pending = submission.submitComment("quote:c=selected", "Latest comment")
755
+
756
+ await started.promise
757
+ expect(await submission.submitComment("quote:c=selected", "Duplicate")).toBe(false)
758
+ failed.reject(new Error("Could not send"))
759
+ expect(await pending).toBe(false)
760
+ expect(errors).toHaveLength(1)
761
+ expect(state.current()).toEqual([{ type: "text", content: "Keep this draft", start: 0, end: 15 }])
762
+ expect(state.context.items()).toMatchObject([
763
+ { key: "quote:c=selected", text: "Selected passage", comment: "Latest comment" },
764
+ ])
765
+ expect(calls.filter((call) => call === "send")).toHaveLength(2)
766
+ })
767
+
768
+ test("a quote send keeps sending while the composer sends it, and fails only once the composer can retry", async () => {
769
+ const state = createMemoryComposerState().capture()
770
+ state.context.add({ type: "quote", text: "Selected passage", commentID: "selected" })
771
+ const release = Promise.withResolvers<void>()
772
+ const failed = Promise.withResolvers<void>()
773
+
774
+ const submission = submitInput(active(state, session({ calls: [], prompt: () => release.promise })), {
775
+ missingSelection() {},
776
+ unqueueable() {},
777
+ failed: () => failed.resolve(),
778
+ })
779
+
780
+ jest.useFakeTimers()
781
+ state.quoteComment.set("quote:c=selected")
782
+ state.quoteComment.send("note", submission.submitComment)
783
+ // A silent server holds a prompt for a minute per attempt; the send has not failed until the composer says so.
784
+ jest.advanceTimersByTime(5 * 60_000)
785
+ jest.useRealTimers()
786
+ expect(state.quoteComment.state()).toMatchObject({ status: "sending", draft: "note" })
787
+ expect(composerSubmitView(submission.state()).canSubmit).toBe(false)
788
+
789
+ release.reject(new Error("offline"))
790
+ await failed.promise
791
+ await new Promise((resolve) => setTimeout(resolve, 0))
792
+ expect(state.quoteComment.state()).toMatchObject({ status: "failed", draft: "note" })
793
+ expect(composerSubmitView(submission.state()).canSubmit).toBe(true)
794
+ })
795
+
796
+ test("a prompt that fails after a newer one went out leaves the Session running", async () => {
797
+ const state = createMemoryComposerState({ prompt: "first" }).capture()
798
+ const statuses: ("idle" | "running")[] = []
799
+ const first = Promise.withResolvers<void>()
800
+ const second = Promise.withResolvers<void>()
801
+ const failed = { count: 0, settled: Promise.withResolvers<void>() }
802
+
803
+ const target = session({
804
+ calls: [],
805
+ statuses,
806
+ prompt: async (value) => {
807
+ if (value.text === "first") return first.promise
808
+ await second.promise
809
+ },
810
+ })
811
+
812
+ const submission = submitInput(
813
+ { ...active(state, target), working: () => statuses.at(-1) === "running" },
814
+ {
815
+ missingSelection() {},
816
+ unqueueable() {},
817
+ failed: () => {
818
+ failed.count++
819
+ failed.settled.resolve()
820
+ },
821
+ },
822
+ )
823
+
824
+ await submission.submit(new Event("submit"))
825
+ state.set([{ type: "text", content: "second", start: 0, end: 6 }])
826
+ await submission.submit(new Event("submit"))
827
+ first.reject(new Error("offline"))
828
+ await failed.settled.promise
829
+ // The second prompt's turn may already run; only the server's events may end it.
830
+ expect(statuses).toEqual(["running"])
831
+
832
+ failed.settled = Promise.withResolvers<void>()
833
+ second.reject(new Error("offline"))
834
+ await failed.settled.promise
835
+ expect(failed.count).toBe(2)
836
+ expect(statuses).toEqual(["running", "idle"])
837
+ })
838
+
839
+ test("resends a failed prompt under its ID only while what it sends is unchanged", async () => {
840
+ const state = createMemoryComposerState({ prompt: "ship it" }).capture()
841
+
842
+ const note = {
843
+ type: "note" as const,
844
+ origin: "browser",
845
+ label: "button#save",
846
+ icon: "select-element",
847
+ subject: 'the "button#save" element',
848
+ live: { subject: 'the "button#save" element (browser ref @e42)' },
849
+ comment: "Rename this",
850
+ commentID: "note",
851
+ }
852
+
853
+ state.context.add(note)
854
+ const sent: string[] = []
855
+ const run = { fail: true, queued: false, settled: Promise.withResolvers<void>() }
856
+
857
+ const submission = submitInput(
858
+ active(
859
+ state,
860
+ session({
861
+ calls: [],
862
+ prompt: async (value) => {
863
+ sent.push(value.id ?? "")
864
+
865
+ if (run.fail) throw new Error("offline")
866
+ run.settled.resolve()
867
+ },
868
+ }),
869
+ ),
870
+ { missingSelection() {}, unqueueable() {}, failed: () => run.settled.resolve() },
871
+ "normal",
872
+ undefined,
873
+ undefined,
874
+ undefined,
875
+ () => (run.queued ? "queue" : "steer"),
876
+ )
877
+
878
+ const send = async () => {
879
+ run.settled = Promise.withResolvers<void>()
880
+ sent.length = 0
881
+ await submission.submit(new Event("submit"))
882
+ await run.settled.promise
883
+
884
+ return sent[0]
885
+ }
886
+
887
+ const first = await send()
888
+ expect(state.retry.current()).toMatchObject({ id: first })
889
+ expect(await send()).toBe(first)
890
+
891
+ // The browser plugin re-picked the element, so the note now names another ref.
892
+ state.context.replaceComments([{ ...note, live: { subject: 'the "button#save" element (browser ref @e7)' } }])
893
+ const edited = await send()
894
+ expect(edited).not.toBe(first)
895
+
896
+ run.queued = true
897
+ const queued = await send()
898
+ expect(queued).not.toBe(edited)
899
+
900
+ run.fail = false
901
+ expect(await send()).toBe(queued)
902
+ expect(state.retry.current()).toBeUndefined()
903
+ })
904
+
905
+ test("an unedited resend after a failed send keeps its ID and its file order", async () => {
906
+ const state = createMemoryComposerState({ prompt: "review these" }).capture()
907
+ state.context.add({ type: "file", path: "src/a.ts" })
908
+ state.context.add({ type: "file", path: "src/b.ts", comment: "Check this", commentID: "b" })
909
+ const keys = state.context.items().map((item) => item.key)
910
+ const sent: string[] = []
911
+ const failed = { settled: Promise.withResolvers<void>() }
912
+
913
+ const submission = submitInput(
914
+ active(
915
+ state,
916
+ session({
917
+ calls: [],
918
+ prompt: async (value) => {
919
+ sent.push(value.id ?? "")
920
+ throw new Error("offline")
921
+ },
922
+ }),
923
+ ),
924
+ { missingSelection() {}, unqueueable() {}, failed: () => failed.settled.resolve() },
925
+ )
926
+
927
+ const send = async () => {
928
+ failed.settled = Promise.withResolvers<void>()
929
+ sent.length = 0
930
+ await submission.submit(new Event("submit"))
931
+ await failed.settled.promise
932
+
933
+ return sent[0]
934
+ }
935
+
936
+ const first = await send()
937
+ // Restoring used to list the commented file first, so the resend fingerprinted differently and took a new ID.
938
+ expect(state.context.items().map((item) => item.key)).toEqual(keys)
939
+ expect(await send()).toBe(first)
940
+ })
941
+
942
+ test("a failed server command restores its draft without a retry ID, which it never sent", async () => {
943
+ const state = createMemoryComposerState({ prompt: "/review" }).capture()
944
+ const failed = Promise.withResolvers<void>()
945
+
946
+ await submitInput(
947
+ active(
948
+ state,
949
+ session({
950
+ calls: [],
951
+ command: async () => {
952
+ throw new Error("offline")
953
+ },
954
+ }),
955
+ ),
956
+ { missingSelection() {}, unqueueable() {}, failed: () => failed.resolve() },
957
+ "normal",
958
+ () => [{ name: "review" }],
959
+ ).submit(new Event("submit"))
960
+ await failed.promise
961
+
962
+ expect(text(state)).toBe("/review")
963
+ expect(state.retry.current()).toBeUndefined()
964
+ })
965
+
966
+ test("applies the selection and runs a client argument command without admitting it to the session", async () => {
967
+ const state = createMemoryComposerState().capture()
968
+
969
+ const image = {
970
+ type: "image" as const,
971
+ id: "attachment",
972
+ filename: "diagram.png",
973
+ mime: "image/png",
974
+ blob: { id: "attachment", url: "data:image/png;base64,YQ==" },
975
+ }
976
+
977
+ state.set([{ type: "text", content: "/btw why this approach?", start: 0, end: 23 }, image])
978
+ state.context.add({ type: "file", path: "src/retry.ts" })
979
+ const calls: string[] = []
980
+ const history: string[] = []
981
+
982
+ await submitInput(
983
+ { ...active(state, session({ calls })), beforeSubmit: () => calls.push("keep-preview") },
984
+ undefined,
985
+ "normal",
986
+ undefined,
987
+ history,
988
+ (text) => {
989
+ expect(text).toBe("/btw why this approach?")
990
+
991
+ return () => {
992
+ calls.push("btw")
993
+ }
994
+ },
995
+ ).submit(new Event("submit"))
996
+
997
+ // Client commands such as /btw generate with the session's model, so the composer's selection commits first.
998
+ expect(calls).toEqual(["keep-preview", "switch-agent", "switch-model", "btw"])
999
+ expect(history).toEqual([])
1000
+ expect(state.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }, image])
1001
+ expect(state.context.items()).toHaveLength(1)
1002
+ })
1003
+
1004
+ test.each([
1005
+ // The prompt admits before the selection commits, so a steer shows as pending while it does.
1006
+ {
1007
+ current: { agent: "plan", model: { id: "old", providerID: "old" } },
1008
+ calls: ["admit", "switch-agent", "switch-model", "send"],
1009
+ },
1010
+ // An unchanged selection sends without a model request to wait on.
1011
+ {
1012
+ current: { agent: "build", model: { providerID: "provider-1", id: "model-1", variant: "balanced" } },
1013
+ calls: ["admit", "send"],
1014
+ },
1015
+ // A prompt commits a staged revert, which would delete the model switch made after its boundary. The revert
1016
+ // settles before admission, whose row it would also delete.
1017
+ {
1018
+ current: { agent: "plan", model: { id: "old", providerID: "old" }, revert: { messageID: "msg_reverted" } },
1019
+ calls: ["switch-agent", "revert-commit", "switch-model", "admit", "send"],
1020
+ },
1021
+ ])("applies the selection before sending one captured value: $calls", async (row) => {
1022
+ const state = createMemoryComposerState({ prompt: "ship it" }).capture()
1023
+ state.context.add({ type: "file", path: "notes.md", description: "the failing version" })
1024
+ const calls: string[] = []
1025
+ const admitted = Promise.withResolvers<Parameters<ComposerSession["data"]["session"]["prompt"]>[0]>()
1026
+ const target = session({ calls, current: () => row.current, prompt: async (value) => admitted.resolve(value) })
1027
+
1028
+ await submitInput(active(state, target)).submit(new Event("submit"))
1029
+ const request = await admitted.promise
1030
+
1031
+ expect(calls).toEqual([...row.calls])
1032
+ expect(request.delivery).toBe("steer")
1033
+ expect(request.text).toBe("ship it")
1034
+ expect(request.id).toMatch(/^msg_/)
1035
+ expect(request.metadata).toMatchObject({
1036
+ displayText: "ship it",
1037
+ agent: "build",
1038
+ model: { providerID: "provider-1", modelID: "model-1", variant: "balanced" },
1039
+ })
1040
+ // A file chip goes with this prompt only, like the TUI's mentionless files.
1041
+ expect(request.files).toMatchObject([{ name: "notes.md", description: "the failing version" }])
1042
+ expect(request.files?.[0]?.mention).toBeUndefined()
1043
+ expect(state.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }])
1044
+ expect(state.context.items()).toEqual([])
1045
+ })
1046
+
1047
+ test.each(["", "Align these targets"])("hands off and admits uncommented notes with instruction %j", async (text) => {
1048
+ const draft = createMemoryComposerState({ prompt: text }).capture()
1049
+
1050
+ const notes = [
1051
+ {
1052
+ type: "note" as const,
1053
+ origin: "example",
1054
+ label: "Save",
1055
+ title: "button#save",
1056
+ subtitle: "Browser annotation",
1057
+ icon: "select-element",
1058
+ subject: 'the "Save" element',
1059
+ href: "example:save",
1060
+ live: { subject: 'the "Save" element (live reference @e42)', href: "example:save#e42" },
1061
+ comment: "",
1062
+ },
1063
+ {
1064
+ type: "note" as const,
1065
+ origin: "another-plugin",
1066
+ label: "Cancel",
1067
+ icon: "select-element",
1068
+ subject: 'the "Cancel" element',
1069
+ comment: "",
1070
+ },
1071
+ ]
1072
+
1073
+ notes.forEach((note, index) => draft.context.add({ ...note, commentID: `${index}` }))
1074
+ const handoffs: SessionMessageHandoff[] = []
1075
+ const first: Parameters<NewSessionComposerAdapter["start"]>[2][] = []
1076
+ const admitted = Promise.withResolvers<Parameters<ComposerSession["data"]["session"]["prompt"]>[0]>()
1077
+ const calls: string[] = []
1078
+
1079
+ const target = session({
1080
+ calls,
1081
+ handoff: { set: (value) => handoffs.push(value), hold() {}, settle() {}, clear() {} },
1082
+ prompt: async (value) => admitted.resolve(value),
1083
+ })
1084
+
1085
+ await submitInput(
1086
+ fresh(draft, async (_selection, _submission, message) => {
1087
+ first.push(message)
1088
+
1089
+ return { session: target, cleanupReady: Promise.resolve() }
1090
+ }),
1091
+ ).submit(new Event("submit"))
1092
+
1093
+ expect(calls).toContain("admit")
1094
+ const request = await admitted.promise
1095
+ expect(request.metadata).toMatchObject({ displayText: text, comments: notes })
1096
+ expect(first).toMatchObject([{ text, metadata: { displayText: text, comments: notes } }])
1097
+ expect(handoffs).toMatchObject([{ message: { text, metadata: { displayText: text, comments: notes } } }])
1098
+ expect(draft.context.items()).toEqual([])
1099
+ })
1100
+
1101
+ test.each(["steer", "queue"] as const)(
1102
+ "shows a %s in the session as the composer clears, before its selection commits",
1103
+ async (delivery) => {
1104
+ const state = createMemoryComposerState({ prompt: "ship it" }).capture()
1105
+ const committed = Promise.withResolvers<void>()
1106
+ const handoffs: SessionMessageHandoff[] = []
1107
+ const statuses: ("idle" | "running")[] = []
1108
+
1109
+ const target = session({
1110
+ calls: [],
1111
+ statuses,
1112
+ handoff: { set: (handoff) => handoffs.push(handoff), hold() {}, settle() {}, clear() {} },
1113
+ switchModel: async () => committed.promise,
1114
+ })
1115
+
1116
+ await submitInput(
1117
+ active(state, target),
1118
+ undefined,
1119
+ "normal",
1120
+ undefined,
1121
+ undefined,
1122
+ undefined,
1123
+ () => delivery,
1124
+ ).submit(new Event("submit"))
1125
+
1126
+ expect(state.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }])
1127
+ expect(statuses).toEqual(["running"])
1128
+ // A queued prompt shows in the queue once admitted, not in the transcript.
1129
+ expect(handoffs).toMatchObject(
1130
+ delivery === "steer"
1131
+ ? [
1132
+ {
1133
+ message: { type: "user", text: "ship it" },
1134
+ selection: { agent: "build", model: { id: "model-1", providerID: "provider-1", variant: "balanced" } },
1135
+ },
1136
+ ]
1137
+ : [],
1138
+ )
1139
+ committed.resolve()
1140
+ },
1141
+ )
1142
+
1143
+ test("applies the captured agent and model before a custom command without passing over its overrides", async () => {
1144
+ const state = createMemoryComposerState({ prompt: "/review changes" }).capture()
1145
+ const calls: string[] = []
1146
+ const selected = controls()
1147
+ const agent = Promise.withResolvers<void>()
1148
+ const started = Promise.withResolvers<void>()
1149
+ const committed = Promise.withResolvers<void>()
1150
+ const completed = Promise.withResolvers<void>()
1151
+ const accepted = Promise.withResolvers<void>()
1152
+
1153
+ const target = session({
1154
+ calls,
1155
+ accept: () => accepted.resolve(),
1156
+ switchAgent: async (request) => {
1157
+ expect(request.agent).toBe("build")
1158
+ calls.push("agent")
1159
+ started.resolve()
1160
+ await agent.promise
1161
+ },
1162
+ switchModel: async (request) => {
1163
+ expect(request.model).toEqual({ providerID: "provider-1", id: "model-1", variant: "balanced" })
1164
+ calls.push("model")
1165
+ await committed.promise
1166
+ },
1167
+ command: async (request) => {
1168
+ expect(request).toMatchObject({ name: "review", text: "changes", delivery: "steer" })
1169
+ expect(request).not.toHaveProperty("model")
1170
+ expect(request).not.toHaveProperty("agent")
1171
+ calls.push("command")
1172
+ completed.resolve()
1173
+ },
1174
+ })
1175
+
1176
+ selected.model.selection = {
1177
+ ...selection,
1178
+ trackSessionCommit: (_id, value) => {
1179
+ expect(value).toEqual({
1180
+ agent: "build",
1181
+ model: { providerID: "provider-1", modelID: "model-1" },
1182
+ variant: "balanced",
1183
+ })
1184
+ calls.push("track")
1185
+
1186
+ return () => calls.push("cancel")
1187
+ },
1188
+ }
1189
+ await submitInput(
1190
+ active(state, target, () => selected),
1191
+ undefined,
1192
+ "normal",
1193
+ () => [{ name: "review" }],
1194
+ ).submit(new Event("submit"))
1195
+ await started.promise
1196
+ expect(calls).toEqual(["track", "agent"])
1197
+ selected.agents.current = "plan"
1198
+ selected.model.selection = { ...selection, variant: { ...selection.variant, current: () => "high" } }
1199
+ agent.resolve()
1200
+ committed.resolve()
1201
+ await completed.promise
1202
+ await accepted.promise
1203
+ expect(calls).toEqual(["track", "agent", "model", "command", "accept-send"])
1204
+ })
1205
+
1206
+ test("cancels selection tracking and does not execute a command when selection fails", async () => {
1207
+ const state = createMemoryComposerState({ prompt: "/review changes" }).capture()
1208
+ const calls: string[] = []
1209
+ const selected = controls()
1210
+ const failed = Promise.withResolvers<unknown>()
1211
+ const error = new Error("model unavailable")
1212
+
1213
+ const target = session({
1214
+ calls,
1215
+ switchModel: async () => {
1216
+ throw error
1217
+ },
1218
+ command: async () => {
1219
+ calls.push("command")
1220
+ },
1221
+ })
1222
+
1223
+ selected.model.selection = {
1224
+ ...selection,
1225
+ trackSessionCommit: () => {
1226
+ calls.push("track")
1227
+
1228
+ return () => {
1229
+ calls.push("cancel")
1230
+ }
1231
+ },
1232
+ }
1233
+ await submitInput(
1234
+ active(state, target, () => selected),
1235
+ { missingSelection() {}, unqueueable() {}, failed: (_kind, error) => failed.resolve(error) },
1236
+ "normal",
1237
+ () => [{ name: "review" }],
1238
+ ).submit(new Event("submit"))
1239
+ expect(await failed.promise).toBe(error)
1240
+ expect(calls).toEqual(["track", "switch-agent", "cancel"])
1241
+ expect(state.current()[0]).toMatchObject({ content: "/review changes" })
1242
+ })
1243
+
1244
+ test("restores and retries an unacknowledged admission", async () => {
1245
+ const state = createMemoryComposerState().capture()
1246
+
1247
+ const prompt: Prompt = [
1248
+ { type: "text", content: "retry ", start: 0, end: 6 },
1249
+ { type: "file", path: "src/app.ts", content: "@src/app.ts", start: 6, end: 17 },
1250
+ {
1251
+ type: "image",
1252
+ id: "attachment",
1253
+ filename: "image.png",
1254
+ mime: "image/png",
1255
+ blob: { id: "attachment", url: "data:image/png;base64,YQ==" },
1256
+ },
1257
+ ]
1258
+
1259
+ state.set(prompt)
1260
+ state.context.add({ type: "file", path: "notes.md", description: "the failing version" })
1261
+
1262
+ const note = {
1263
+ type: "note" as const,
1264
+ origin: "example",
1265
+ label: "Target",
1266
+ title: "#target",
1267
+ subtitle: "Browser annotation",
1268
+ icon: "select-element",
1269
+ subject: "the target",
1270
+ live: { subject: "the live target" },
1271
+ comment: "",
1272
+ commentID: "target",
1273
+ }
1274
+
1275
+ state.context.add(note)
1276
+ const attempts: string[] = []
1277
+ const calls: string[] = []
1278
+ const statuses: ("idle" | "running")[] = []
1279
+ const first = Promise.withResolvers<void>()
1280
+ const second = Promise.withResolvers<void>()
1281
+
1282
+ const target = session({
1283
+ calls,
1284
+ statuses,
1285
+ prompt: async (value) => {
1286
+ attempts.push(value.id ?? "")
1287
+ throw new Error("network unavailable")
1288
+ },
1289
+ })
1290
+
1291
+ const notify = {
1292
+ missingSelection() {},
1293
+ unqueueable() {},
1294
+ failed: () => (attempts.length === 2 ? first.resolve() : second.resolve()),
1295
+ }
1296
+
1297
+ const history: string[] = []
1298
+ const submission = submitInput(active(state, target), notify, "normal", () => [], history)
1299
+
1300
+ await submission.submit(new Event("submit"))
1301
+ await first.promise
1302
+ await submission.submit(new Event("submit"))
1303
+ await second.promise
1304
+
1305
+ expect(attempts).toHaveLength(4)
1306
+ expect(new Set(attempts).size).toBe(1)
1307
+ // A retried admission reuses its submission's selection commit.
1308
+ const submitted = ["admit", "switch-agent", "switch-model", "send", "admit", "send"]
1309
+ expect(calls).toEqual([...submitted, ...submitted])
1310
+ expect(statuses).toEqual(["running", "idle", "running", "idle"])
1311
+ expect(state.current()).toEqual(prompt)
1312
+ // In the order it was sent, so the resend's request matches the first.
1313
+ expect(state.context.items()).toMatchObject([
1314
+ { type: "file", path: "notes.md", description: "the failing version" },
1315
+ note,
1316
+ ])
1317
+ // The caret returns after the mention text; attachments take no caret positions.
1318
+ expect(state.cursor()).toBe(17)
1319
+ // The restored prompt is the draft again, so history does not also keep it (and its attachments).
1320
+ const entry = "retry @src/app.tsimage"
1321
+ expect(history).toEqual([`add:${entry}`, `remove:${entry}`, `add:${entry}`, `remove:${entry}`])
1322
+ })
1323
+
1324
+ test("restores first-prompt comments into the promoted Session", async () => {
1325
+ const draft = createMemoryComposerState({ prompt: "first prompt" }).capture()
1326
+ draft.store[1]("context", "items", [
1327
+ {
1328
+ key: "file:src/app.ts:1:1:comment",
1329
+ type: "file",
1330
+ path: "src/app.ts",
1331
+ comment: "Keep this comment",
1332
+ selection: { startLine: 1, startChar: 0, endLine: 1, endChar: 4 },
1333
+ },
1334
+ ])
1335
+ expect(draft.context.items()).toHaveLength(1)
1336
+ const promoted = createMemoryComposerState().capture()
1337
+ const failed = Promise.withResolvers<void>()
1338
+ const target = session({ calls: [], shell: async () => Promise.reject(new Error("send failed")) })
1339
+
1340
+ const adapter = fresh(draft, async (_selection, submission) => {
1341
+ submission.retarget(promoted)
1342
+
1343
+ return { session: target, cleanupReady: Promise.resolve() }
1344
+ })
1345
+
1346
+ await submitInput(
1347
+ adapter,
1348
+ { missingSelection() {}, unqueueable() {}, failed: () => failed.resolve() },
1349
+ "shell",
1350
+ ).submit(new Event("submit"))
1351
+ await failed.promise
1352
+
1353
+ expect(promoted.current()).toMatchObject([{ type: "text", content: "first prompt" }])
1354
+ expect(promoted.context.items()).toMatchObject([{ type: "file", path: "src/app.ts", comment: "Keep this comment" }])
1355
+ expect(promoted.mode.current()).toBe("shell")
1356
+ })
1357
+
1358
+ test("moves a first prompt and its quote sources to the promoted Session, and recovers it with the follow-up typed there", async () => {
1359
+ const draft = createMemoryComposerState({ prompt: "first prompt" }).capture()
1360
+ draft.context.add({ type: "quote", commentID: "quote-source", text: "quoted passage" })
1361
+ const key = draft.context.items()[0]!.key
1362
+ const source = [{ partID: "part-source", revealID: "message-source", start: 4, end: 18, text: "quoted passage" }]
1363
+ draft.quoteSource.add(key, source)
1364
+ // The Session's composer already holds a follow-up typed while it prepared.
1365
+ const promoted = createMemoryComposerState({ prompt: "follow-up" }).capture()
1366
+ const moved: (typeof promoted.quoteSource.state.sources)[string][] = []
1367
+ const release = Promise.withResolvers<void>()
1368
+ const failed = Promise.withResolvers<void>()
1369
+
1370
+ const target = session({
1371
+ calls: [],
1372
+ prompt: async () => {
1373
+ await release.promise
1374
+ throw new Error("network unavailable")
1375
+ },
1376
+ })
1377
+
1378
+ await submitInput(
1379
+ fresh(draft, async (_selection, submission) => {
1380
+ submission.retarget(promoted, { preserveDraft: true })
1381
+ moved.push(promoted.quoteSource.state.sources[key])
1382
+
1383
+ return { session: target, cleanupReady: Promise.resolve() }
1384
+ }),
1385
+ { missingSelection() {}, unqueueable() {}, failed: () => failed.resolve() },
1386
+ ).submit(new Event("submit"))
1387
+
1388
+ expect(moved).toEqual([source])
1389
+ expect(text(draft)).toBe("")
1390
+ expect(text(promoted)).toBe("follow-up")
1391
+ release.resolve()
1392
+ await failed.promise
1393
+
1394
+ expect(text(promoted)).toBe("first prompt\n\nfollow-up")
1395
+ expect(promoted.context.items()).toMatchObject([{ key, type: "quote", text: "quoted passage" }])
1396
+ expect(promoted.quoteSource.state.sources[key]).toEqual(source)
1397
+ // A recovered follow-up changes the payload, so it is not a retry of the failed admission.
1398
+ expect(promoted.retry.current()).toBeUndefined()
1399
+ })
1400
+
1401
+ test("does not restore a failed prompt over one typed after the composer cleared", async () => {
1402
+ const state = createMemoryComposerState({ prompt: "submitted" }).capture()
1403
+ const release = Promise.withResolvers<void>()
1404
+ const failed = Promise.withResolvers<void>()
1405
+ const history: string[] = []
1406
+
1407
+ const target = session({
1408
+ calls: [],
1409
+ prompt: async () => {
1410
+ await release.promise
1411
+ throw new Error("network unavailable")
1412
+ },
1413
+ })
1414
+
1415
+ await submitInput(
1416
+ active(state, target),
1417
+ { missingSelection() {}, unqueueable() {}, failed: () => failed.resolve() },
1418
+ "normal",
1419
+ () => [],
1420
+ history,
1421
+ ).submit(new Event("submit"))
1422
+ state.set([{ type: "text", content: "new draft", start: 0, end: 9 }])
1423
+ release.resolve()
1424
+ await failed.promise
1425
+
1426
+ expect(text(state)).toBe("new draft")
1427
+ expect(history).toEqual(["add:submitted"])
1428
+ })
1429
+
1430
+ test("does not restore a prompt already acknowledged by the durable inbox", async () => {
1431
+ const state = createMemoryComposerState({ prompt: "admitted prompt" }).capture()
1432
+ const checked = Promise.withResolvers<void>()
1433
+ const attempts: string[] = []
1434
+
1435
+ const target = session({
1436
+ calls: [],
1437
+ admitted: () => {
1438
+ checked.resolve()
1439
+
1440
+ return true
1441
+ },
1442
+ prompt: async (value) => {
1443
+ attempts.push(value.id ?? "")
1444
+ throw new Error("response lost")
1445
+ },
1446
+ })
1447
+
1448
+ await submitInput(active(state, target)).submit(new Event("submit"))
1449
+ await checked.promise
1450
+
1451
+ expect(state.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }])
1452
+ expect(attempts).toHaveLength(2)
1453
+ expect(new Set(attempts).size).toBe(1)
1454
+ })
1455
+
1456
+ describe("steering while foreground work runs", () => {
1457
+ // A long shell command blocks the run; moving it resolves only the move, never the admission.
1458
+ // `unstarted` moves before the shell's job starts, so the server finds nothing to move and the call still blocks.
1459
+ function running(
1460
+ input: {
1461
+ fail?: boolean
1462
+ failOnce?: boolean
1463
+ unstarted?: boolean
1464
+ blocking?: { partID: string }[]
1465
+ prompt?: () => Promise<void>
1466
+ } = {},
1467
+ ) {
1468
+ const calls: string[] = []
1469
+ const failures: string[] = []
1470
+ const state = createMemoryComposerState({ prompt: "use Beta instead" }).capture()
1471
+ const blocking = { parts: input.blocking ?? [{ partID: "prt_shell" }] }
1472
+
1473
+ const claim = createSteerBackground({
1474
+ sessionID: () => "session-1",
1475
+ blocking: () => blocking.parts,
1476
+ move: async () => {
1477
+ calls.push("background")
1478
+
1479
+ if (input.fail) throw new Error("server unavailable")
1480
+
1481
+ if (input.failOnce) {
1482
+ input.failOnce = false
1483
+ throw new Error("server unavailable")
1484
+ }
1485
+
1486
+ if (input.unstarted) {
1487
+ input.unstarted = false
1488
+
1489
+ return
1490
+ }
1491
+
1492
+ blocking.parts = []
1493
+ },
1494
+ })
1495
+
1496
+ const target = session({ calls, prompt: input.prompt, background: () => claim("session-1") })
1497
+ const adapter = { ...active(state, target), working: () => true }
1498
+ const notify = { missingSelection() {}, unqueueable() {}, failed: () => void failures.push("failed") }
1499
+
1500
+ const submit = async (delivery: ComposerDelivery = "steer", working = true) => {
1501
+ state.set([{ type: "text", content: "use Beta instead", start: 0, end: 16 }])
1502
+ await submitInput(
1503
+ { ...adapter, working: () => working },
1504
+ notify,
1505
+ "normal",
1506
+ () => [],
1507
+ [],
1508
+ undefined,
1509
+ () => delivery,
1510
+ ).submit(new Event("submit"))
1511
+ // The send settles after submit returns; let it and the move that follows it finish.
1512
+ await new Promise((resolve) => setTimeout(resolve, 0))
1513
+ }
1514
+
1515
+ return { calls, failures, submit, blocking }
1516
+ }
1517
+
1518
+ test("moves the work to the background once the steer is admitted, and only once", async () => {
1519
+ const run = running()
1520
+
1521
+ await run.submit()
1522
+ expect(run.calls).toEqual(["admit", "switch-agent", "switch-model", "send", "accept-send", "background"])
1523
+
1524
+ await run.submit()
1525
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(1)
1526
+ })
1527
+
1528
+ test("a steer moves work that its previous steer's move missed", async () => {
1529
+ const run = running({ unstarted: true })
1530
+
1531
+ await run.submit()
1532
+ await run.submit()
1533
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(2)
1534
+ })
1535
+
1536
+ test("a steer sent while the previous one is admitted moves the work when the previous move fails", async () => {
1537
+ const admitted = Promise.withResolvers<void>()
1538
+ const attempts = { count: 0 }
1539
+
1540
+ const run = running({
1541
+ failOnce: true,
1542
+ prompt: async () => {
1543
+ attempts.count++
1544
+
1545
+ if (attempts.count === 1) await admitted.promise
1546
+ },
1547
+ })
1548
+
1549
+ await run.submit()
1550
+ await run.submit()
1551
+ admitted.resolve()
1552
+ await new Promise((resolve) => setTimeout(resolve, 0))
1553
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(2)
1554
+ expect(run.blocking.parts).toEqual([])
1555
+ })
1556
+
1557
+ test("moves a shell that starts while the steer is admitted", async () => {
1558
+ const run = running({
1559
+ blocking: [],
1560
+ prompt: async () => {
1561
+ run.blocking.parts = [{ partID: "prt_shell" }]
1562
+ },
1563
+ })
1564
+
1565
+ await run.submit()
1566
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(1)
1567
+ expect(run.blocking.parts).toEqual([])
1568
+ })
1569
+
1570
+ test("leaves the work alone for a queued prompt or an idle session", async () => {
1571
+ const run = running()
1572
+
1573
+ await run.submit("queue")
1574
+ await run.submit("steer", false)
1575
+ expect(run.calls).not.toContain("background")
1576
+ })
1577
+
1578
+ test("still sends the steer when the move fails, and a later steer tries again", async () => {
1579
+ const run = running({ fail: true })
1580
+
1581
+ await run.submit()
1582
+ await run.submit()
1583
+ expect(run.failures).toEqual([])
1584
+ expect(run.calls.filter((call) => call === "send")).toHaveLength(2)
1585
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(2)
1586
+ })
1587
+
1588
+ test("a steer that fails to send leaves the work for the next one", async () => {
1589
+ const attempts = { count: 0 }
1590
+
1591
+ const run = running({
1592
+ prompt: async () => {
1593
+ attempts.count++
1594
+
1595
+ // The first submission's admission and its single retry both fail.
1596
+ if (attempts.count <= 2) throw new Error("network unavailable")
1597
+ },
1598
+ })
1599
+
1600
+ await run.submit()
1601
+ expect(run.failures).toEqual(["failed"])
1602
+ expect(run.calls).not.toContain("background")
1603
+
1604
+ await run.submit()
1605
+ expect(run.calls.filter((call) => call === "background")).toHaveLength(1)
1606
+ })
1607
+ })
1608
+
1609
+ test("hands off image-only first prompts and admits them before cleanup is ready", async () => {
1610
+ const draft = createMemoryComposerState().capture()
1611
+
1612
+ const prompt: Prompt = [
1613
+ { type: "text", content: "", start: 0, end: 0 },
1614
+ {
1615
+ type: "image",
1616
+ id: "attachment",
1617
+ filename: "image.png",
1618
+ mime: "image/png",
1619
+ blob: { id: "attachment", url: "data:image/png;base64,YQ==" },
1620
+ },
1621
+ ]
1622
+
1623
+ draft.set(prompt)
1624
+ const handedOff = Promise.withResolvers<SessionMessageHandoff>()
1625
+ const admitted = Promise.withResolvers<void>()
1626
+ const cleanup = Promise.withResolvers<void>()
1627
+
1628
+ const target = session({
1629
+ calls: [],
1630
+ handoff: { set: handedOff.resolve, hold() {}, settle() {}, clear() {} },
1631
+ prompt: async () => admitted.resolve(),
1632
+ })
1633
+
1634
+ const submitted = submitInput(
1635
+ fresh(draft, async () => ({ session: target, cleanupReady: cleanup.promise })),
1636
+ ).submit(new Event("submit"))
1637
+
1638
+ await admitted.promise
1639
+ expect(draft.current()).toEqual(prompt)
1640
+ cleanup.resolve()
1641
+ await submitted
1642
+ expect(draft.current()).toEqual([{ type: "text", content: "", start: 0, end: 0 }])
1643
+
1644
+ expect((await handedOff.promise).message).toMatchObject({
1645
+ type: "user",
1646
+ text: "",
1647
+ files: [
1648
+ {
1649
+ data: "",
1650
+ mime: "image/png",
1651
+ source: { type: "uri", uri: "data:image/png;base64,YQ==" },
1652
+ name: "image.png",
1653
+ },
1654
+ ],
1655
+ })
1656
+ })
1657
+
1658
+ test.each([
1659
+ { case: "is admitted", fails: false, admitted: false, result: "settle" },
1660
+ { case: "loses its response after admission", fails: true, admitted: true, result: "settle" },
1661
+ { case: "fails", fails: true, admitted: false, result: "clear" },
1662
+ ])("a steer's handoff waits for its echo or ends when its send $case", async (row) => {
1663
+ const state = createMemoryComposerState({ prompt: "steer" }).capture()
1664
+ const handoff: string[] = []
1665
+ const ended = Promise.withResolvers<void>()
1666
+
1667
+ const target = session({
1668
+ calls: [],
1669
+ admitted: () => row.admitted,
1670
+ handoff: {
1671
+ set: (value) => handoff.push(`set:${value.message.id}`),
1672
+ hold: (value) => handoff.push(`hold:${value.message.id}`),
1673
+ settle: (id) => {
1674
+ handoff.push(`settle:${id}`)
1675
+ ended.resolve()
1676
+ },
1677
+ clear: (id) => {
1678
+ handoff.push(`clear:${id}`)
1679
+ ended.resolve()
1680
+ },
1681
+ },
1682
+ prompt: async () => {
1683
+ if (row.fails) throw new Error("response lost")
1684
+ },
1685
+ })
1686
+
1687
+ await submitInput(active(state, target)).submit(new Event("submit"))
1688
+ await ended.promise
1689
+
1690
+ expect(handoff).toHaveLength(2)
1691
+ expect(handoff[1]).toBe(handoff[0]!.replace("set:", `${row.result}:`))
1692
+ })
1693
+
1694
+ test("forwards structured mentions to custom commands", async () => {
1695
+ const state = createMemoryComposerState().capture()
1696
+ state.set([
1697
+ { type: "text", content: "/review ", start: 0, end: 8 },
1698
+ { type: "file", path: "src/app.ts", content: "@src/app.ts", start: 8, end: 19 },
1699
+ { type: "text", content: " ", start: 19, end: 20 },
1700
+ { type: "agent", name: "review", content: "@review", start: 20, end: 27 },
1701
+ { type: "text", content: " ", start: 27, end: 28 },
1702
+ {
1703
+ type: "skill",
1704
+ id: Skill.ID.make("effect"),
1705
+ name: Skill.Name.make("Effect"),
1706
+ content: "@effect",
1707
+ start: 28,
1708
+ end: 35,
1709
+ },
1710
+ ])
1711
+ const sent = Promise.withResolvers<Parameters<ComposerSession["api"]["command"]>[0]>()
1712
+ const target = session({ calls: [], command: async (value) => sent.resolve(value) })
1713
+
1714
+ await submitInput(active(state, target), undefined, "normal", () => [{ name: "review" }]).submit(
1715
+ new Event("submit"),
1716
+ )
1717
+ const request = await sent.promise
1718
+
1719
+ expect(request.files).toMatchObject([{ name: "app.ts", mention: { text: "@src/app.ts" } }])
1720
+ expect(request.agents).toMatchObject([{ name: "review", mention: { text: "@review" } }])
1721
+ expect(request.skills).toMatchObject([{ id: "effect", name: "Effect", mention: { text: "@effect" } }])
1722
+ expect(request.delivery).toBe("steer")
1723
+ })
1724
+
1725
+ test("captures commands before creating a session in a new worktree", async () => {
1726
+ const state = createMemoryComposerState({ prompt: "/review https://github.com/example/repo/pull/1" }).capture()
1727
+ const catalog = [{ name: "review" }]
1728
+ const sent = Promise.withResolvers<"prompt" | "command">()
1729
+ const requests: Parameters<ComposerSession["api"]["command"]>[0][] = []
1730
+
1731
+ const target = session({
1732
+ calls: [],
1733
+ prompt: async () => sent.resolve("prompt"),
1734
+ command: async (value) => {
1735
+ requests.push(value)
1736
+ sent.resolve("command")
1737
+ },
1738
+ })
1739
+
1740
+ target.directory = "C:/new-worktree"
1741
+ target.data.location.command.list = () => undefined
1742
+
1743
+ const adapter = fresh(state, async () => {
1744
+ // The destination catalog has not loaded, and the source composer is leaving.
1745
+ catalog.splice(0)
1746
+
1747
+ return { session: target, cleanupReady: Promise.resolve() }
1748
+ })
1749
+
1750
+ await submitInput(adapter, undefined, "normal", () => catalog).submit(new Event("submit"))
1751
+
1752
+ expect(await sent.promise).toBe("command")
1753
+ expect(requests).toEqual([
1754
+ {
1755
+ sessionID: target.id,
1756
+ name: "review",
1757
+ text: "https://github.com/example/repo/pull/1",
1758
+ files: [],
1759
+ agents: [],
1760
+ skills: [],
1761
+ delivery: "steer",
1762
+ },
1763
+ ])
1764
+ })
1765
+
1766
+ test("does not run an empty shell command from hidden attachments", async () => {
1767
+ const state = createMemoryComposerState().capture()
1768
+ state.set([
1769
+ { type: "text", content: "", start: 0, end: 0 },
1770
+ {
1771
+ type: "image",
1772
+ id: "attachment",
1773
+ filename: "notes.txt",
1774
+ mime: "text/plain",
1775
+ blob: { id: "attachment", url: "data:text/plain;base64,bm90ZXM=" },
1776
+ },
1777
+ ])
1778
+ const calls: string[] = []
1779
+
1780
+ await submitInput(active(state, session({ calls })), undefined, "shell").submit(new Event("submit"))
1781
+
1782
+ expect(calls).toEqual([])
1783
+ expect(state.current().some((part) => part.type === "image")).toBe(true)
1784
+ })
1785
+ })