@neurocode-ai/app 1.18.8

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 (577) hide show
  1. package/AGENTS.md +35 -0
  2. package/README.md +50 -0
  3. package/V1_API_MIGRATION.md +220 -0
  4. package/bunfig.toml +3 -0
  5. package/create-effect-simplification-spec.md +515 -0
  6. package/e2e/performance/AGENTS.md +13 -0
  7. package/e2e/performance/README.md +79 -0
  8. package/e2e/performance/benchmark.ts +144 -0
  9. package/e2e/performance/chrome-trace.ts +95 -0
  10. package/e2e/performance/playwright.config.ts +20 -0
  11. package/e2e/performance/playwright.uncapped.config.ts +13 -0
  12. package/e2e/performance/timeline/first-navigation-benchmark.spec.ts +87 -0
  13. package/e2e/performance/timeline/first-navigation-metrics.ts +32 -0
  14. package/e2e/performance/timeline/first-navigation-probe.ts +86 -0
  15. package/e2e/performance/timeline/home-tab-navigation-benchmark.spec.ts +114 -0
  16. package/e2e/performance/timeline/navigation-milestones.ts +128 -0
  17. package/e2e/performance/timeline/review-pane-scaling-benchmark.spec.ts +312 -0
  18. package/e2e/performance/timeline/session-parent-hydration-benchmark.spec.ts +172 -0
  19. package/e2e/performance/timeline/session-tab-flash.spec.ts +67 -0
  20. package/e2e/performance/timeline/session-tab-repaint-probe.ts +251 -0
  21. package/e2e/performance/timeline/session-tab-switch-benchmark.spec.ts +144 -0
  22. package/e2e/performance/timeline/session-tab-switch-metrics.ts +59 -0
  23. package/e2e/performance/timeline/session-tab-switch-probe.ts +226 -0
  24. package/e2e/performance/timeline/session-timeline-benchmark.fixture.ts +504 -0
  25. package/e2e/performance/timeline/session-timeline-benchmark.spec.ts +306 -0
  26. package/e2e/performance/timeline/session-timeline-profile.ts +40 -0
  27. package/e2e/performance/timeline/session-timeline-stream-probe.ts +547 -0
  28. package/e2e/performance/timeline/session-timeline-stress.fixture.ts +369 -0
  29. package/e2e/performance/timeline/timeline-test-helpers.ts +134 -0
  30. package/e2e/performance/timeline-stability/README.md +61 -0
  31. package/e2e/performance/timeline-stability/adverse.spec.ts +250 -0
  32. package/e2e/performance/timeline-stability/context-matrix.spec.ts +192 -0
  33. package/e2e/performance/timeline-stability/environment-matrix.spec.ts +113 -0
  34. package/e2e/performance/timeline-stability/file-matrix.spec.ts +121 -0
  35. package/e2e/performance/timeline-stability/file-mutation.spec.ts +113 -0
  36. package/e2e/performance/timeline-stability/fixture.test.ts +68 -0
  37. package/e2e/performance/timeline-stability/fixture.ts +566 -0
  38. package/e2e/performance/timeline-stability/interaction.spec.ts +242 -0
  39. package/e2e/performance/timeline-stability/lifecycle.spec.ts +157 -0
  40. package/e2e/performance/timeline-stability/oracle-browser.spec.ts +75 -0
  41. package/e2e/performance/timeline-stability/playwright.config.ts +17 -0
  42. package/e2e/performance/timeline-stability/scroll-interaction.spec.ts +353 -0
  43. package/e2e/performance/timeline-stability/shell-matrix.spec.ts +255 -0
  44. package/e2e/performance/timeline-stability/tool-mutation.spec.ts +106 -0
  45. package/e2e/performance/timeline-stability/tools.spec.ts +198 -0
  46. package/e2e/performance/timeline-stability/transition-matrix.spec.ts +272 -0
  47. package/e2e/performance/unit/chrome-trace-write.test.ts +15 -0
  48. package/e2e/performance/unit/first-navigation-metrics.test.ts +32 -0
  49. package/e2e/performance/unit/mock-server.test.ts +46 -0
  50. package/e2e/performance/unit/navigation-milestones.test.ts +34 -0
  51. package/e2e/performance/unit/session-tab-repaint-probe.test.ts +42 -0
  52. package/e2e/performance/unit/session-tab-switch-metrics.test.ts +86 -0
  53. package/e2e/performance/unit/session-tab-switch-probe.test.ts +55 -0
  54. package/e2e/performance/unit/session-timeline-stream-probe.test.ts +14 -0
  55. package/e2e/performance/unit/session-timeline-visual-tracking.test.ts +16 -0
  56. package/e2e/performance/unit/timeline-test-helpers.test.ts +10 -0
  57. package/e2e/performance/unit/visual-stability.test.ts +392 -0
  58. package/e2e/regression/cross-server-tab-close.spec.ts +153 -0
  59. package/e2e/regression/file-browser-sidebar-tab-switch.spec.ts +150 -0
  60. package/e2e/regression/legacy-new-session.spec.ts +41 -0
  61. package/e2e/regression/new-session-panel-corner.spec.ts +83 -0
  62. package/e2e/regression/prompt-input-v2-command-draft.spec.ts +50 -0
  63. package/e2e/regression/prompt-thinking-level.spec.ts +84 -0
  64. package/e2e/regression/remote-session-settings.spec.ts +302 -0
  65. package/e2e/regression/remote-tab-busy.spec.ts +131 -0
  66. package/e2e/regression/review-image-flash.spec.ts +202 -0
  67. package/e2e/regression/review-line-comment.spec.ts +158 -0
  68. package/e2e/regression/review-open-file.spec.ts +163 -0
  69. package/e2e/regression/review-state-persistence.spec.ts +155 -0
  70. package/e2e/regression/review-tab-switch.spec.ts +147 -0
  71. package/e2e/regression/review-terminal-stacked.spec.ts +308 -0
  72. package/e2e/regression/session-list-path-loading.spec.ts +41 -0
  73. package/e2e/regression/session-request-docks.spec.ts +221 -0
  74. package/e2e/regression/session-timeline-accessibility.spec.ts +22 -0
  75. package/e2e/regression/session-timeline-collapse-state.spec.ts +439 -0
  76. package/e2e/regression/session-timeline-context-resize.spec.ts +374 -0
  77. package/e2e/regression/session-timeline-context-state.spec.ts +31 -0
  78. package/e2e/regression/session-timeline-file-projection.spec.ts +52 -0
  79. package/e2e/regression/session-timeline-file-state.spec.ts +94 -0
  80. package/e2e/regression/session-timeline-history-root.spec.ts +242 -0
  81. package/e2e/regression/session-timeline-lifecycle-state.spec.ts +111 -0
  82. package/e2e/regression/session-timeline-locale-projection.spec.ts +25 -0
  83. package/e2e/regression/session-timeline-projection.spec.ts +287 -0
  84. package/e2e/regression/session-timeline-reasoning-projection.spec.ts +93 -0
  85. package/e2e/regression/session-timeline-reducer-projection.spec.ts +43 -0
  86. package/e2e/regression/session-timeline-shell-outline.spec.ts +228 -0
  87. package/e2e/regression/session-timeline-tool-projection.spec.ts +99 -0
  88. package/e2e/regression/session-timeline-tool-state.spec.ts +77 -0
  89. package/e2e/regression/session-timeline-transport.spec.ts +116 -0
  90. package/e2e/regression/session-todo-dock-navigation.spec.ts +190 -0
  91. package/e2e/regression/subagent-child-navigation.spec.ts +203 -0
  92. package/e2e/regression/tab-navigate-mousedown.spec.ts +127 -0
  93. package/e2e/regression/terminal-composer-focus.spec.ts +227 -0
  94. package/e2e/regression/terminal-hidden.spec.ts +117 -0
  95. package/e2e/regression/terminal-tab-switch.spec.ts +165 -0
  96. package/e2e/reproduction/timeline-suspense/index.html +34 -0
  97. package/e2e/reproduction/timeline-suspense/main.tsx +315 -0
  98. package/e2e/reproduction/timeline-suspense/playwright.config.ts +34 -0
  99. package/e2e/reproduction/timeline-suspense/timeline-suspense.repro.ts +179 -0
  100. package/e2e/reproduction/timeline-suspense/vite.config.ts +7 -0
  101. package/e2e/smoke/session-timeline.fixture.ts +315 -0
  102. package/e2e/smoke/session-timeline.spec.ts +740 -0
  103. package/e2e/tsconfig.json +20 -0
  104. package/e2e/utils/errors.ts +18 -0
  105. package/e2e/utils/mock-server.ts +443 -0
  106. package/e2e/utils/sse-transport.ts +312 -0
  107. package/e2e/utils/visual-stability/analyzer.ts +209 -0
  108. package/e2e/utils/visual-stability/capture.ts +51 -0
  109. package/e2e/utils/visual-stability/index.ts +8 -0
  110. package/e2e/utils/visual-stability/invariant.ts +112 -0
  111. package/e2e/utils/visual-stability/model.ts +47 -0
  112. package/e2e/utils/visual-stability/probe.ts +226 -0
  113. package/e2e/utils/visual-stability/regions.ts +18 -0
  114. package/e2e/utils/visual-stability/reporter.ts +63 -0
  115. package/e2e/utils/visual-stability/scenario.ts +20 -0
  116. package/e2e/utils/visual-stability.ts +54 -0
  117. package/e2e/utils/waits.ts +11 -0
  118. package/happydom.ts +75 -0
  119. package/index.html +28 -0
  120. package/package.json +96 -0
  121. package/playwright.config.ts +45 -0
  122. package/public/_headers +17 -0
  123. package/public/apple-touch-icon-v3.png +1 -0
  124. package/public/apple-touch-icon.png +1 -0
  125. package/public/assets/Inter.ttf +0 -0
  126. package/public/assets/JetBrainsMonoNerdFontMono-Regular.woff2 +0 -0
  127. package/public/favicon-96x96-v3.png +1 -0
  128. package/public/favicon-96x96.png +1 -0
  129. package/public/favicon-v3.ico +1 -0
  130. package/public/favicon-v3.svg +1 -0
  131. package/public/favicon.ico +1 -0
  132. package/public/favicon.svg +1 -0
  133. package/public/oc-theme-preload.js +40 -0
  134. package/public/site.webmanifest +1 -0
  135. package/public/social-share-zen.png +1 -0
  136. package/public/social-share.png +1 -0
  137. package/public/web-app-manifest-192x192.png +1 -0
  138. package/public/web-app-manifest-512x512.png +1 -0
  139. package/src/addons/serialize.test.ts +327 -0
  140. package/src/addons/serialize.ts +642 -0
  141. package/src/app.tsx +659 -0
  142. package/src/assets/help/home.png +0 -0
  143. package/src/assets/help/introducing-tabs.mp4 +0 -0
  144. package/src/assets/help/placeholder.png +0 -0
  145. package/src/assets/help/tabs.png +0 -0
  146. package/src/components/command-palette.ts +281 -0
  147. package/src/components/command-tooltip-keybind.test.ts +22 -0
  148. package/src/components/command-tooltip-keybind.ts +11 -0
  149. package/src/components/debug-bar.tsx +550 -0
  150. package/src/components/dialog-command-palette-v2.css +220 -0
  151. package/src/components/dialog-command-palette-v2.tsx +342 -0
  152. package/src/components/dialog-connect-provider.stories.tsx +73 -0
  153. package/src/components/dialog-connect-provider.tsx +1178 -0
  154. package/src/components/dialog-custom-provider-form.ts +158 -0
  155. package/src/components/dialog-custom-provider.test.ts +80 -0
  156. package/src/components/dialog-custom-provider.tsx +330 -0
  157. package/src/components/dialog-edit-project-v2.tsx +156 -0
  158. package/src/components/dialog-edit-project.tsx +170 -0
  159. package/src/components/dialog-fork.tsx +104 -0
  160. package/src/components/dialog-manage-models.tsx +265 -0
  161. package/src/components/dialog-release-notes.tsx +144 -0
  162. package/src/components/dialog-select-directory-v2.css +107 -0
  163. package/src/components/dialog-select-directory-v2.tsx +378 -0
  164. package/src/components/dialog-select-directory.tsx +191 -0
  165. package/src/components/dialog-select-file.tsx +189 -0
  166. package/src/components/dialog-select-mcp.tsx +92 -0
  167. package/src/components/dialog-select-model-search.test.ts +19 -0
  168. package/src/components/dialog-select-model-search.ts +18 -0
  169. package/src/components/dialog-select-model-unpaid-v2.stories.tsx +55 -0
  170. package/src/components/dialog-select-model-unpaid-v2.tsx +175 -0
  171. package/src/components/dialog-select-model-unpaid.tsx +147 -0
  172. package/src/components/dialog-select-model.tsx +549 -0
  173. package/src/components/dialog-select-server.tsx +722 -0
  174. package/src/components/dialog-settings.tsx +94 -0
  175. package/src/components/dialog-usage-exceeded.tsx +44 -0
  176. package/src/components/directory-picker-domain.test.ts +248 -0
  177. package/src/components/directory-picker-domain.ts +407 -0
  178. package/src/components/directory-picker-policy.ts +7 -0
  179. package/src/components/directory-picker.test.ts +21 -0
  180. package/src/components/directory-picker.tsx +45 -0
  181. package/src/components/edit-project.ts +122 -0
  182. package/src/components/file-tree-v2-model.test.ts +74 -0
  183. package/src/components/file-tree-v2-model.ts +107 -0
  184. package/src/components/file-tree-v2.tsx +299 -0
  185. package/src/components/file-tree.test.ts +80 -0
  186. package/src/components/file-tree.tsx +509 -0
  187. package/src/components/help-button.tsx +148 -0
  188. package/src/components/link.tsx +26 -0
  189. package/src/components/model-tooltip.tsx +124 -0
  190. package/src/components/pierre-tree.test.ts +23 -0
  191. package/src/components/prompt-input/attachments.test.ts +108 -0
  192. package/src/components/prompt-input/attachments.ts +228 -0
  193. package/src/components/prompt-input/build-request-parts.test.ts +396 -0
  194. package/src/components/prompt-input/build-request-parts.ts +213 -0
  195. package/src/components/prompt-input/context-items.tsx +98 -0
  196. package/src/components/prompt-input/contracts.ts +57 -0
  197. package/src/components/prompt-input/drag-overlay.tsx +25 -0
  198. package/src/components/prompt-input/editor-dom.test.ts +99 -0
  199. package/src/components/prompt-input/editor-dom.ts +148 -0
  200. package/src/components/prompt-input/files.ts +98 -0
  201. package/src/components/prompt-input/history-store.ts +47 -0
  202. package/src/components/prompt-input/history.test.ts +153 -0
  203. package/src/components/prompt-input/history.ts +256 -0
  204. package/src/components/prompt-input/image-attachments.css +43 -0
  205. package/src/components/prompt-input/image-attachments.tsx +168 -0
  206. package/src/components/prompt-input/paste.ts +24 -0
  207. package/src/components/prompt-input/placeholder.test.ts +48 -0
  208. package/src/components/prompt-input/placeholder.ts +20 -0
  209. package/src/components/prompt-input/slash-popover.tsx +376 -0
  210. package/src/components/prompt-input/submission-state.ts +33 -0
  211. package/src/components/prompt-input/submit.test.ts +598 -0
  212. package/src/components/prompt-input/submit.ts +634 -0
  213. package/src/components/prompt-input/transient-state.ts +46 -0
  214. package/src/components/prompt-input-v2.tsx +592 -0
  215. package/src/components/prompt-input.stories.tsx +223 -0
  216. package/src/components/prompt-input.tsx +1790 -0
  217. package/src/components/prompt-project-selector.tsx +593 -0
  218. package/src/components/prompt-workspace-selector.tsx +128 -0
  219. package/src/components/server/server-row-menu.tsx +96 -0
  220. package/src/components/server/server-row.tsx +127 -0
  221. package/src/components/session/index.ts +7 -0
  222. package/src/components/session/open-in-app-v2.tsx +98 -0
  223. package/src/components/session/open-in-app.tsx +229 -0
  224. package/src/components/session/session-context-breakdown.test.ts +61 -0
  225. package/src/components/session/session-context-breakdown.ts +132 -0
  226. package/src/components/session/session-context-format.ts +20 -0
  227. package/src/components/session/session-context-metrics.test.ts +99 -0
  228. package/src/components/session/session-context-metrics.ts +65 -0
  229. package/src/components/session/session-context-tab.tsx +343 -0
  230. package/src/components/session/session-header.tsx +568 -0
  231. package/src/components/session/session-new-design-view.tsx +16 -0
  232. package/src/components/session/session-new-view.tsx +91 -0
  233. package/src/components/session/session-sortable-tab-v2.tsx +74 -0
  234. package/src/components/session/session-sortable-tab.tsx +78 -0
  235. package/src/components/session/session-sortable-terminal-tab-v2.tsx +284 -0
  236. package/src/components/session/session-sortable-terminal-tab.tsx +193 -0
  237. package/src/components/session-context-usage.tsx +169 -0
  238. package/src/components/settings-dialog.tsx +43 -0
  239. package/src/components/settings-general.tsx +794 -0
  240. package/src/components/settings-keybinds.tsx +553 -0
  241. package/src/components/settings-list.tsx +5 -0
  242. package/src/components/settings-models.tsx +149 -0
  243. package/src/components/settings-providers.tsx +264 -0
  244. package/src/components/settings-server-picker.tsx +106 -0
  245. package/src/components/settings-servers.tsx +33 -0
  246. package/src/components/settings-v2/dialog-server-v2.tsx +134 -0
  247. package/src/components/settings-v2/dialog-settings-v2.tsx +98 -0
  248. package/src/components/settings-v2/general.tsx +722 -0
  249. package/src/components/settings-v2/index.tsx +1 -0
  250. package/src/components/settings-v2/interface-transition.stories.tsx +76 -0
  251. package/src/components/settings-v2/interface-transition.tsx +54 -0
  252. package/src/components/settings-v2/models.tsx +138 -0
  253. package/src/components/settings-v2/parts/list.tsx +6 -0
  254. package/src/components/settings-v2/parts/row.tsx +20 -0
  255. package/src/components/settings-v2/providers.tsx +264 -0
  256. package/src/components/settings-v2/servers.tsx +139 -0
  257. package/src/components/settings-v2/settings-v2.css +675 -0
  258. package/src/components/status-popover-body.tsx +514 -0
  259. package/src/components/status-popover-indicator.test.ts +36 -0
  260. package/src/components/status-popover-indicator.ts +20 -0
  261. package/src/components/status-popover.tsx +190 -0
  262. package/src/components/terminal.tsx +759 -0
  263. package/src/components/titlebar-history.test.ts +63 -0
  264. package/src/components/titlebar-history.ts +57 -0
  265. package/src/components/titlebar-session-events.test.ts +32 -0
  266. package/src/components/titlebar-session-events.ts +35 -0
  267. package/src/components/titlebar-tab-gesture.test.ts +33 -0
  268. package/src/components/titlebar-tab-gesture.ts +17 -0
  269. package/src/components/titlebar-tab-nav.css +100 -0
  270. package/src/components/titlebar-tab-nav.tsx +429 -0
  271. package/src/components/titlebar-tab-popover.css +127 -0
  272. package/src/components/titlebar-tab-popover.tsx +92 -0
  273. package/src/components/titlebar-tab-strip.tsx +333 -0
  274. package/src/components/titlebar.css +77 -0
  275. package/src/components/titlebar.tsx +776 -0
  276. package/src/components/ui/drawer.tsx +119 -0
  277. package/src/components/updater-action.test.ts +26 -0
  278. package/src/components/updater-action.ts +51 -0
  279. package/src/components/virtual-scroll-element.test.ts +18 -0
  280. package/src/components/virtual-scroll-element.ts +4 -0
  281. package/src/components/windows-app-menu.tsx +131 -0
  282. package/src/constants/file-picker.ts +89 -0
  283. package/src/context/closed-tabs.ts +40 -0
  284. package/src/context/command-keybind.test.ts +69 -0
  285. package/src/context/command.test.ts +55 -0
  286. package/src/context/command.tsx +467 -0
  287. package/src/context/comments.test.ts +188 -0
  288. package/src/context/comments.tsx +261 -0
  289. package/src/context/directory-sync.ts +155 -0
  290. package/src/context/file/content-cache.ts +88 -0
  291. package/src/context/file/path.test.ts +360 -0
  292. package/src/context/file/path.ts +151 -0
  293. package/src/context/file/tree-store.ts +174 -0
  294. package/src/context/file/types.ts +41 -0
  295. package/src/context/file/view-cache.ts +147 -0
  296. package/src/context/file/watcher.test.ts +149 -0
  297. package/src/context/file/watcher.ts +53 -0
  298. package/src/context/file-content-eviction-accounting.test.ts +65 -0
  299. package/src/context/file.tsx +303 -0
  300. package/src/context/global-sync/bootstrap.test.ts +231 -0
  301. package/src/context/global-sync/bootstrap.ts +536 -0
  302. package/src/context/global-sync/child-store.test.ts +276 -0
  303. package/src/context/global-sync/child-store.ts +396 -0
  304. package/src/context/global-sync/event-reducer.test.ts +616 -0
  305. package/src/context/global-sync/event-reducer.ts +478 -0
  306. package/src/context/global-sync/eviction.ts +28 -0
  307. package/src/context/global-sync/home-session-index.test.ts +154 -0
  308. package/src/context/global-sync/home-session-index.ts +174 -0
  309. package/src/context/global-sync/mcp.test.ts +54 -0
  310. package/src/context/global-sync/mcp.ts +19 -0
  311. package/src/context/global-sync/queue.test.ts +46 -0
  312. package/src/context/global-sync/queue.ts +87 -0
  313. package/src/context/global-sync/session-cache.test.ts +104 -0
  314. package/src/context/global-sync/session-cache.ts +62 -0
  315. package/src/context/global-sync/session-load.ts +33 -0
  316. package/src/context/global-sync/session-trim.test.ts +59 -0
  317. package/src/context/global-sync/session-trim.ts +57 -0
  318. package/src/context/global-sync/types.ts +135 -0
  319. package/src/context/global-sync/utils.test.ts +133 -0
  320. package/src/context/global-sync/utils.ts +171 -0
  321. package/src/context/global.tsx +161 -0
  322. package/src/context/highlights.tsx +233 -0
  323. package/src/context/language.tsx +243 -0
  324. package/src/context/layout-helpers.ts +38 -0
  325. package/src/context/layout-scroll.test.ts +64 -0
  326. package/src/context/layout-scroll.ts +126 -0
  327. package/src/context/layout-tabs.test.ts +82 -0
  328. package/src/context/layout-tabs.ts +103 -0
  329. package/src/context/layout.test.ts +69 -0
  330. package/src/context/layout.tsx +1075 -0
  331. package/src/context/local-agent.test.ts +29 -0
  332. package/src/context/local-agent.ts +7 -0
  333. package/src/context/local.tsx +417 -0
  334. package/src/context/mcp.ts +19 -0
  335. package/src/context/model-variant.test.ts +86 -0
  336. package/src/context/model-variant.ts +52 -0
  337. package/src/context/models.tsx +173 -0
  338. package/src/context/notification.tsx +478 -0
  339. package/src/context/permission-auto-respond.test.ts +125 -0
  340. package/src/context/permission-auto-respond.ts +60 -0
  341. package/src/context/permission.tsx +484 -0
  342. package/src/context/platform.tsx +142 -0
  343. package/src/context/prompt-state.test.ts +29 -0
  344. package/src/context/prompt-state.ts +266 -0
  345. package/src/context/prompt.tsx +170 -0
  346. package/src/context/sdk.tsx +17 -0
  347. package/src/context/server-sdk.test.ts +196 -0
  348. package/src/context/server-sdk.tsx +444 -0
  349. package/src/context/server-session-v2-reducer.test.ts +156 -0
  350. package/src/context/server-session-v2-reducer.ts +502 -0
  351. package/src/context/server-session.test.ts +1638 -0
  352. package/src/context/server-session.ts +1425 -0
  353. package/src/context/server-sync.test.ts +231 -0
  354. package/src/context/server-sync.tsx +753 -0
  355. package/src/context/server.test.ts +245 -0
  356. package/src/context/server.tsx +360 -0
  357. package/src/context/settings.test.ts +79 -0
  358. package/src/context/settings.tsx +531 -0
  359. package/src/context/sync-optimistic.test.ts +123 -0
  360. package/src/context/sync.tsx +119 -0
  361. package/src/context/tab-memory.ts +36 -0
  362. package/src/context/tabs.test.ts +107 -0
  363. package/src/context/tabs.tsx +387 -0
  364. package/src/context/terminal-title.ts +24 -0
  365. package/src/context/terminal.test.ts +91 -0
  366. package/src/context/terminal.tsx +546 -0
  367. package/src/custom-elements.d.ts +1 -0
  368. package/src/desktop-menu.test.ts +13 -0
  369. package/src/desktop-menu.ts +223 -0
  370. package/src/entry.tsx +182 -0
  371. package/src/env.d.ts +31 -0
  372. package/src/hooks/provider-catalog.test.ts +59 -0
  373. package/src/hooks/provider-catalog.ts +27 -0
  374. package/src/hooks/use-providers.ts +71 -0
  375. package/src/i18n/ar.ts +1008 -0
  376. package/src/i18n/br.ts +1024 -0
  377. package/src/i18n/bs.ts +1100 -0
  378. package/src/i18n/da.ts +1092 -0
  379. package/src/i18n/de.ts +1037 -0
  380. package/src/i18n/en.ts +1102 -0
  381. package/src/i18n/es.ts +1108 -0
  382. package/src/i18n/fr.ts +1037 -0
  383. package/src/i18n/ja.ts +1016 -0
  384. package/src/i18n/ko.ts +1015 -0
  385. package/src/i18n/no.ts +1111 -0
  386. package/src/i18n/parity.test.ts +118 -0
  387. package/src/i18n/pl.ts +1024 -0
  388. package/src/i18n/ru.ts +1103 -0
  389. package/src/i18n/th.ts +1087 -0
  390. package/src/i18n/tr.ts +1106 -0
  391. package/src/i18n/uk.ts +1105 -0
  392. package/src/i18n/zh.ts +1078 -0
  393. package/src/i18n/zht.ts +1074 -0
  394. package/src/index.css +330 -0
  395. package/src/index.ts +30 -0
  396. package/src/pages/directory-layout.tsx +122 -0
  397. package/src/pages/error-description.test.ts +17 -0
  398. package/src/pages/error-description.ts +11 -0
  399. package/src/pages/error.tsx +372 -0
  400. package/src/pages/home/home-controller.ts +108 -0
  401. package/src/pages/home/home-projects-controller.tsx +128 -0
  402. package/src/pages/home/home-projects-view.tsx +615 -0
  403. package/src/pages/home/home-projects.tsx +40 -0
  404. package/src/pages/home/home-scroll-controller.ts +145 -0
  405. package/src/pages/home/home-session-search-controller.ts +114 -0
  406. package/src/pages/home/home-sessions-controller.tsx +314 -0
  407. package/src/pages/home/home-sessions-view.tsx +550 -0
  408. package/src/pages/home/home-sessions.tsx +48 -0
  409. package/src/pages/home/legacy-home.tsx +142 -0
  410. package/src/pages/home-session-archive.test.ts +51 -0
  411. package/src/pages/home-session-archive.ts +27 -0
  412. package/src/pages/home-session-open.test.ts +31 -0
  413. package/src/pages/home-session-open.ts +14 -0
  414. package/src/pages/home.tsx +50 -0
  415. package/src/pages/layout/deep-links.ts +50 -0
  416. package/src/pages/layout/helpers.test.ts +321 -0
  417. package/src/pages/layout/helpers.ts +150 -0
  418. package/src/pages/layout/inline-editor.tsx +126 -0
  419. package/src/pages/layout/project-avatar-state.ts +49 -0
  420. package/src/pages/layout/session-tab-avatar.tsx +60 -0
  421. package/src/pages/layout/sidebar-items.tsx +335 -0
  422. package/src/pages/layout/sidebar-project.tsx +377 -0
  423. package/src/pages/layout/sidebar-shell.tsx +125 -0
  424. package/src/pages/layout/sidebar-workspace.tsx +488 -0
  425. package/src/pages/layout-new.tsx +53 -0
  426. package/src/pages/layout.tsx +2441 -0
  427. package/src/pages/new-session.tsx +282 -0
  428. package/src/pages/session/composer/index.ts +4 -0
  429. package/src/pages/session/composer/prompt-model-selection.ts +133 -0
  430. package/src/pages/session/composer/session-composer-controls.ts +129 -0
  431. package/src/pages/session/composer/session-composer-region-controller.ts +145 -0
  432. package/src/pages/session/composer/session-composer-region.tsx +168 -0
  433. package/src/pages/session/composer/session-composer-state.test.ts +138 -0
  434. package/src/pages/session/composer/session-composer-state.ts +204 -0
  435. package/src/pages/session/composer/session-followup-dock.tsx +109 -0
  436. package/src/pages/session/composer/session-permission-dock.tsx +74 -0
  437. package/src/pages/session/composer/session-question-dock.tsx +640 -0
  438. package/src/pages/session/composer/session-request-tree.ts +52 -0
  439. package/src/pages/session/composer/session-revert-dock.stories.tsx +124 -0
  440. package/src/pages/session/composer/session-revert-dock.tsx +188 -0
  441. package/src/pages/session/composer/session-todo-dock.tsx +277 -0
  442. package/src/pages/session/composer/todo-panel-motion.stories.tsx +622 -0
  443. package/src/pages/session/file-tab-scroll.test.ts +40 -0
  444. package/src/pages/session/file-tab-scroll.ts +67 -0
  445. package/src/pages/session/file-tabs.tsx +800 -0
  446. package/src/pages/session/handoff.ts +36 -0
  447. package/src/pages/session/helpers.test.ts +214 -0
  448. package/src/pages/session/helpers.ts +209 -0
  449. package/src/pages/session/message-gesture.test.ts +62 -0
  450. package/src/pages/session/message-gesture.ts +21 -0
  451. package/src/pages/session/message-id-from-hash.ts +6 -0
  452. package/src/pages/session/new-session-layout.ts +2 -0
  453. package/src/pages/session/review-tab.tsx +172 -0
  454. package/src/pages/session/session-layout.ts +30 -0
  455. package/src/pages/session/session-lineage.ts +69 -0
  456. package/src/pages/session/session-model-helpers.test.ts +151 -0
  457. package/src/pages/session/session-model-helpers.ts +63 -0
  458. package/src/pages/session/session-ownership.ts +37 -0
  459. package/src/pages/session/session-panel-layout.test.ts +19 -0
  460. package/src/pages/session/session-panel-layout.ts +6 -0
  461. package/src/pages/session/session-panel-width.test.ts +52 -0
  462. package/src/pages/session/session-panel-width.ts +19 -0
  463. package/src/pages/session/session-side-panel.tsx +865 -0
  464. package/src/pages/session/terminal-label.ts +16 -0
  465. package/src/pages/session/terminal-panel-v2.tsx +352 -0
  466. package/src/pages/session/terminal-panel.test.ts +25 -0
  467. package/src/pages/session/terminal-panel.tsx +343 -0
  468. package/src/pages/session/timeline/measure.test.ts +30 -0
  469. package/src/pages/session/timeline/measure.ts +5 -0
  470. package/src/pages/session/timeline/message-timeline.tsx +1864 -0
  471. package/src/pages/session/timeline/model.test.ts +95 -0
  472. package/src/pages/session/timeline/model.ts +128 -0
  473. package/src/pages/session/timeline/observe-element-offset.test.ts +199 -0
  474. package/src/pages/session/timeline/observe-element-offset.ts +73 -0
  475. package/src/pages/session/timeline/projection.test.ts +96 -0
  476. package/src/pages/session/timeline/projection.ts +81 -0
  477. package/src/pages/session/timeline/row-reconciliation.ts +56 -0
  478. package/src/pages/session/timeline/rows-current.test.ts +170 -0
  479. package/src/pages/session/timeline/rows.ts +344 -0
  480. package/src/pages/session/timeline/summary-diffs.test.ts +42 -0
  481. package/src/pages/session/timeline/summary-diffs.ts +20 -0
  482. package/src/pages/session/timeline/timeline-row.ts +80 -0
  483. package/src/pages/session/timeline/virtual-items.ts +3 -0
  484. package/src/pages/session/usage-exceeded-dialogs.tsx +104 -0
  485. package/src/pages/session/use-composer-commands.tsx +83 -0
  486. package/src/pages/session/use-session-commands.tsx +606 -0
  487. package/src/pages/session/use-session-hash-scroll.test.ts +16 -0
  488. package/src/pages/session/use-session-hash-scroll.ts +202 -0
  489. package/src/pages/session/v2/review-diff-kinds.test.ts +70 -0
  490. package/src/pages/session/v2/review-diff-kinds.ts +62 -0
  491. package/src/pages/session/v2/review-panel-v2-state.ts +41 -0
  492. package/src/pages/session/v2/review-panel-v2.tsx +255 -0
  493. package/src/pages/session/v2/session-file-browser-tab.tsx +181 -0
  494. package/src/pages/session/v2/session-file-list-v2.tsx +166 -0
  495. package/src/pages/session.tsx +2385 -0
  496. package/src/sst-env.d.ts +12 -0
  497. package/src/theme-preload.test.ts +46 -0
  498. package/src/updater.ts +17 -0
  499. package/src/utils/agent.ts +44 -0
  500. package/src/utils/aim.ts +138 -0
  501. package/src/utils/base64.ts +10 -0
  502. package/src/utils/comment-note.ts +88 -0
  503. package/src/utils/diffs.test.ts +75 -0
  504. package/src/utils/diffs.ts +50 -0
  505. package/src/utils/file-manager.ts +24 -0
  506. package/src/utils/id.ts +93 -0
  507. package/src/utils/notification-click.test.ts +27 -0
  508. package/src/utils/notification-click.ts +13 -0
  509. package/src/utils/path-key.ts +24 -0
  510. package/src/utils/persist.test.ts +211 -0
  511. package/src/utils/persist.ts +661 -0
  512. package/src/utils/prompt.test.ts +44 -0
  513. package/src/utils/prompt.ts +203 -0
  514. package/src/utils/refcount.test.ts +49 -0
  515. package/src/utils/refcount.ts +32 -0
  516. package/src/utils/runtime-adapters.test.ts +64 -0
  517. package/src/utils/runtime-adapters.ts +39 -0
  518. package/src/utils/same.ts +6 -0
  519. package/src/utils/scoped-cache.test.ts +69 -0
  520. package/src/utils/scoped-cache.ts +104 -0
  521. package/src/utils/search-keydown.ts +116 -0
  522. package/src/utils/server-compat.test.ts +193 -0
  523. package/src/utils/server-compat.ts +512 -0
  524. package/src/utils/server-errors.test.ts +175 -0
  525. package/src/utils/server-errors.ts +109 -0
  526. package/src/utils/server-health.test.ts +178 -0
  527. package/src/utils/server-health.ts +172 -0
  528. package/src/utils/server-protocol.test.ts +40 -0
  529. package/src/utils/server-protocol.ts +35 -0
  530. package/src/utils/server-scope.test.ts +61 -0
  531. package/src/utils/server-scope.ts +73 -0
  532. package/src/utils/server.test.ts +23 -0
  533. package/src/utils/server.ts +62 -0
  534. package/src/utils/session-message.test.ts +214 -0
  535. package/src/utils/session-message.ts +355 -0
  536. package/src/utils/session-route.test.ts +71 -0
  537. package/src/utils/session-route.ts +39 -0
  538. package/src/utils/session-title.ts +7 -0
  539. package/src/utils/session.test.ts +94 -0
  540. package/src/utils/session.ts +37 -0
  541. package/src/utils/solid-dnd.tsx +49 -0
  542. package/src/utils/sound.ts +102 -0
  543. package/src/utils/terminal-websocket-url.test.ts +80 -0
  544. package/src/utils/terminal-websocket-url.ts +35 -0
  545. package/src/utils/terminal-writer.test.ts +64 -0
  546. package/src/utils/terminal-writer.ts +65 -0
  547. package/src/utils/time.ts +22 -0
  548. package/src/utils/toast.tsx +34 -0
  549. package/src/utils/uuid.test.ts +78 -0
  550. package/src/utils/uuid.ts +12 -0
  551. package/src/utils/worktree.test.ts +58 -0
  552. package/src/utils/worktree.ts +76 -0
  553. package/src/wsl/add-server-probes.ts +57 -0
  554. package/src/wsl/context.tsx +36 -0
  555. package/src/wsl/dialog-add-server.tsx +463 -0
  556. package/src/wsl/dialog-add-wsl-server.css +392 -0
  557. package/src/wsl/settings-model.test.ts +231 -0
  558. package/src/wsl/settings-model.ts +341 -0
  559. package/src/wsl/settings.tsx +173 -0
  560. package/src/wsl/types.ts +85 -0
  561. package/sst-env.d.ts +10 -0
  562. package/test-browser/command-palette.test.ts +78 -0
  563. package/test-browser/motion-spring.test.ts +20 -0
  564. package/test-browser/prompt-attachments.test.ts +90 -0
  565. package/test-browser/prompt-persistence.test.ts +71 -0
  566. package/test-browser/prompt-scope.test.ts +14 -0
  567. package/test-browser/prompt-submission-state.test.ts +73 -0
  568. package/test-browser/prompt-transient-state.test.ts +38 -0
  569. package/test-browser/review-panel-v2-state.test.ts +65 -0
  570. package/test-browser/session-lineage.test.ts +231 -0
  571. package/test-browser/session-ownership.test.ts +45 -0
  572. package/test-browser/solid-virtual.test.ts +112 -0
  573. package/test-browser/toast-owner.test.ts +26 -0
  574. package/tsconfig.json +26 -0
  575. package/vendor/opencode-ai-client-1.17.13.tgz +0 -0
  576. package/vite.config.ts +33 -0
  577. package/vite.js +48 -0
@@ -0,0 +1,1790 @@
1
+ import { useFilteredList } from "@neurocode-ai/ui/hooks"
2
+ import { useSpring } from "@neurocode-ai/ui/motion-spring"
3
+ import {
4
+ createEffect,
5
+ on,
6
+ Component,
7
+ Show,
8
+ onCleanup,
9
+ createMemo,
10
+ createSignal,
11
+ createResource,
12
+ Switch,
13
+ Match,
14
+ type JSX,
15
+ } from "solid-js"
16
+ import { selectionFromLines, type SelectedLineRange, useFile } from "@/context/file"
17
+ import {
18
+ ContentPart,
19
+ DEFAULT_PROMPT,
20
+ isCommentItem,
21
+ isPromptEqual,
22
+ Prompt,
23
+ usePrompt,
24
+ ImageAttachmentPart,
25
+ AgentPart,
26
+ FileAttachmentPart,
27
+ } from "@/context/prompt"
28
+ import { useLayout } from "@/context/layout"
29
+ import { useSDK } from "@/context/sdk"
30
+ import { useSync } from "@/context/sync"
31
+ import { useComments } from "@/context/comments"
32
+ import { Button } from "@neurocode-ai/ui/button"
33
+ import { DockShellForm, DockTray } from "@neurocode-ai/ui/dock-surface"
34
+ import { Icon } from "@neurocode-ai/ui/icon"
35
+ import { ProviderIcon } from "@neurocode-ai/ui/provider-icon"
36
+ import { Tooltip, TooltipKeybind } from "@neurocode-ai/ui/tooltip"
37
+ import { ButtonV2 } from "@neurocode-ai/ui/v2/button-v2"
38
+ import { Icon as IconV2 } from "@neurocode-ai/ui/v2/icon"
39
+ import { IconButtonV2 } from "@neurocode-ai/ui/v2/icon-button-v2"
40
+ import { KeybindV2 } from "@neurocode-ai/ui/v2/keybind-v2"
41
+ import { MenuV2 } from "@neurocode-ai/ui/v2/menu-v2"
42
+ import { TooltipV2 } from "@neurocode-ai/ui/v2/tooltip-v2"
43
+ import { IconButton } from "@neurocode-ai/ui/icon-button"
44
+ import { Select } from "@neurocode-ai/ui/select"
45
+ import { useDialog } from "@neurocode-ai/ui/context/dialog"
46
+ import { ModelSelectorPopover, ModelSelectorPopoverV2 } from "@/components/dialog-select-model"
47
+ import { DialogSelectModelUnpaid } from "@/components/dialog-select-model-unpaid"
48
+ import { DialogSelectModelUnpaidV2 } from "@/components/dialog-select-model-unpaid-v2"
49
+ import { useCommand } from "@/context/command"
50
+ import { usePermission } from "@/context/permission"
51
+ import { useLanguage } from "@/context/language"
52
+ import { usePlatform } from "@/context/platform"
53
+ import { createSessionTabs } from "@/pages/session/helpers"
54
+ import { createTextFragment, getCursorPosition, setCursorPosition, setRangeEdge } from "./prompt-input/editor-dom"
55
+ import { createPromptAttachments } from "./prompt-input/attachments"
56
+ import { ACCEPTED_FILE_TYPES, pickAttachmentFiles } from "./prompt-input/files"
57
+ import {
58
+ canNavigateHistoryAtCursor,
59
+ navigatePromptHistory,
60
+ type PromptHistoryComment,
61
+ type PromptHistoryEntry,
62
+ promptLength,
63
+ } from "./prompt-input/history"
64
+ import {
65
+ createPersistedPromptInputHistory,
66
+ createPromptInputHistory,
67
+ type PromptInputHistory,
68
+ } from "./prompt-input/history-store"
69
+ import {
70
+ type PromptInputControls,
71
+ type PromptInputProps,
72
+ type PromptInputState,
73
+ type PromptInputSubmission,
74
+ } from "./prompt-input/contracts"
75
+ import { createPromptSubmit } from "./prompt-input/submit"
76
+ import { PromptPopover, type AtOption, type SlashCommand } from "./prompt-input/slash-popover"
77
+ import { PromptContextItems } from "./prompt-input/context-items"
78
+ import { PromptImageAttachments } from "./prompt-input/image-attachments"
79
+ import { PromptDragOverlay } from "./prompt-input/drag-overlay"
80
+ import { promptDesignPlaceholder, promptPlaceholder } from "./prompt-input/placeholder"
81
+ import { createPromptInputTransientState } from "./prompt-input/transient-state"
82
+ import { showToast } from "@/utils/toast"
83
+ import { ImagePreview } from "@neurocode-ai/ui/image-preview"
84
+ import type { ReferenceInfo } from "@neurocode-ai/sdk/v2/client"
85
+
86
+ export { createPromptInputHistory }
87
+ export type { PromptInputControls, PromptInputHistory, PromptInputProps, PromptInputState, PromptInputSubmission }
88
+
89
+ const EXAMPLES = [
90
+ "prompt.example.1",
91
+ "prompt.example.2",
92
+ "prompt.example.3",
93
+ "prompt.example.4",
94
+ "prompt.example.5",
95
+ "prompt.example.6",
96
+ "prompt.example.7",
97
+ "prompt.example.8",
98
+ "prompt.example.9",
99
+ "prompt.example.10",
100
+ "prompt.example.11",
101
+ "prompt.example.12",
102
+ "prompt.example.13",
103
+ "prompt.example.14",
104
+ "prompt.example.15",
105
+ "prompt.example.16",
106
+ "prompt.example.17",
107
+ "prompt.example.18",
108
+ "prompt.example.19",
109
+ "prompt.example.20",
110
+ "prompt.example.21",
111
+ "prompt.example.22",
112
+ "prompt.example.23",
113
+ "prompt.example.24",
114
+ "prompt.example.25",
115
+ ] as const
116
+
117
+ export const PromptInput: Component<PromptInputProps> = (props) => {
118
+ const sdk = useSDK()
119
+
120
+ const sync = useSync()
121
+ const files = useFile()
122
+ const prompt = props.state ?? usePrompt()
123
+ const layout = useLayout()
124
+ const comments = useComments()
125
+ const dialog = useDialog()
126
+ const command = useCommand()
127
+ const permission = usePermission()
128
+ const language = useLanguage()
129
+ const platform = usePlatform()
130
+ const tabs = () => props.controls.session.tabs
131
+ let editorRef!: HTMLDivElement
132
+ let fileInputRef: HTMLInputElement | undefined
133
+ let scrollRef!: HTMLDivElement
134
+ let slashPopoverRef!: HTMLDivElement
135
+ let restoreEndOnFocus = true
136
+ let savedCursor: number | null = null
137
+
138
+ const mirror = { input: false }
139
+ const inset = 56
140
+ const space = `${inset}px`
141
+
142
+ const scrollCursorIntoView = () => {
143
+ const container = scrollRef
144
+ const selection = window.getSelection()
145
+ if (!container || !selection || selection.rangeCount === 0) return
146
+
147
+ const range = selection.getRangeAt(0)
148
+ if (!editorRef.contains(range.startContainer)) return
149
+
150
+ const cursor = getCursorPosition(editorRef)
151
+ const length = promptLength(prompt.current().filter((part) => part.type !== "image"))
152
+ if (cursor >= length) {
153
+ container.scrollTop = container.scrollHeight
154
+ return
155
+ }
156
+
157
+ const rect = range.getClientRects().item(0) ?? range.getBoundingClientRect()
158
+ if (!rect.height) return
159
+
160
+ const containerRect = container.getBoundingClientRect()
161
+ const top = rect.top - containerRect.top + container.scrollTop
162
+ const bottom = rect.bottom - containerRect.top + container.scrollTop
163
+ const padding = 12
164
+
165
+ if (top < container.scrollTop + padding) {
166
+ container.scrollTop = Math.max(0, top - padding)
167
+ return
168
+ }
169
+
170
+ if (bottom > container.scrollTop + container.clientHeight - inset) {
171
+ container.scrollTop = bottom - container.clientHeight + inset
172
+ }
173
+ }
174
+
175
+ const queueScroll = (count = 2) => {
176
+ requestAnimationFrame(() => {
177
+ scrollCursorIntoView()
178
+ if (count > 1) queueScroll(count - 1)
179
+ })
180
+ }
181
+
182
+ const activeFileTab = createSessionTabs({
183
+ tabs,
184
+ pathFromTab: files.pathFromTab,
185
+ normalizeTab: (tab) => (tab.startsWith("file://") ? files.tab(tab) : tab),
186
+ }).activeFileTab
187
+
188
+ const commentInReview = (path: string) => {
189
+ const sessionID = props.controls.session.id
190
+ if (!sessionID) return false
191
+
192
+ const diffs = sync().data.session_diff[sessionID]
193
+ if (!diffs) return false
194
+ return diffs.some((diff) => diff.file === path)
195
+ }
196
+
197
+ const openComment = (item: { path: string; commentID?: string; commentOrigin?: "review" | "file" }) => {
198
+ if (!item.commentID) return
199
+
200
+ const focus = { file: item.path, id: item.commentID }
201
+ comments.setActive(focus)
202
+
203
+ const queueCommentFocus = (attempts = 6) => {
204
+ const schedule = (left: number) => {
205
+ requestAnimationFrame(() => {
206
+ comments.setFocus({ ...focus })
207
+ if (left <= 0) return
208
+ requestAnimationFrame(() => {
209
+ const current = comments.focus()
210
+ if (!current) return
211
+ if (current.file !== focus.file || current.id !== focus.id) return
212
+ schedule(left - 1)
213
+ })
214
+ })
215
+ }
216
+
217
+ schedule(attempts)
218
+ }
219
+
220
+ const wantsReview = item.commentOrigin === "review" || (item.commentOrigin !== "file" && commentInReview(item.path))
221
+ if (wantsReview) {
222
+ if (!props.controls.session.reviewPanel.opened()) props.controls.session.reviewPanel.open()
223
+ layout.fileTree.setTab("changes")
224
+ tabs().setActive("review")
225
+ queueCommentFocus()
226
+ return
227
+ }
228
+
229
+ if (!props.controls.session.reviewPanel.opened()) props.controls.session.reviewPanel.open()
230
+ layout.fileTree.setTab("all")
231
+ const tab = files.tab(item.path)
232
+ void tabs().open(tab)
233
+ tabs().setActive(tab)
234
+ void Promise.resolve(files.load(item.path)).finally(() => queueCommentFocus())
235
+ }
236
+
237
+ const recent = createMemo(() => {
238
+ const all = tabs().all()
239
+ const active = activeFileTab()
240
+ const order = active ? [active, ...all.filter((x) => x !== active)] : all
241
+ const seen = new Set<string>()
242
+ const paths: string[] = []
243
+
244
+ for (const tab of order) {
245
+ const path = files.pathFromTab(tab)
246
+ if (!path) continue
247
+ if (seen.has(path)) continue
248
+ seen.add(path)
249
+ paths.push(path)
250
+ }
251
+
252
+ return paths
253
+ })
254
+ const info = createMemo(() => (props.controls.session.id ? sync().session.get(props.controls.session.id) : undefined))
255
+ const working = createMemo(() => sync().data.session_working(props.controls.session.id ?? ""))
256
+ const imageAttachments = createMemo(() =>
257
+ prompt.current().filter((part): part is ImageAttachmentPart => part.type === "image"),
258
+ )
259
+
260
+ const [store, setStore] = createPromptInputTransientState(
261
+ () => prompt.capture(),
262
+ Math.floor(Math.random() * EXAMPLES.length),
263
+ )
264
+ const buttonsSpring = useSpring(() => (store.mode === "normal" ? 1 : 0), { visualDuration: 0.2, bounce: 0 })
265
+ const motion = (value: number) => ({
266
+ opacity: value,
267
+ transform: `scale(${0.98 + value * 0.02})`,
268
+ filter: `blur(${(1 - value) * 2}px)`,
269
+ "pointer-events": value > 0.5 ? ("auto" as const) : ("none" as const),
270
+ })
271
+ const buttons = createMemo(() => motion(buttonsSpring()))
272
+ const shell = createMemo(() => motion(1 - buttonsSpring()))
273
+ const control = createMemo(() => ({ height: "28px", ...buttons() }))
274
+
275
+ const commentCount = createMemo(() => {
276
+ if (store.mode === "shell") return 0
277
+ return prompt.context.items().filter((item) => !!item.comment?.trim()).length
278
+ })
279
+ const blank = createMemo(() => {
280
+ const text = prompt
281
+ .current()
282
+ .map((part) => ("content" in part ? part.content : ""))
283
+ .join("")
284
+ return text.trim().length === 0 && imageAttachments().length === 0 && commentCount() === 0
285
+ })
286
+ const stopping = createMemo(() => working() && blank())
287
+ const tip = () => {
288
+ if (stopping()) {
289
+ return (
290
+ <div class="flex items-center gap-2">
291
+ <span>{language.t("prompt.action.stop")}</span>
292
+ <span class="text-icon-base text-12-medium text-[10px]!">{language.t("common.key.esc")}</span>
293
+ </div>
294
+ )
295
+ }
296
+
297
+ return (
298
+ <div class="flex items-center gap-2">
299
+ <span>{language.t("prompt.action.send")}</span>
300
+ <Icon name="enter" size="small" class="text-icon-base" />
301
+ </div>
302
+ )
303
+ }
304
+
305
+ const contextItems = createMemo(() => {
306
+ const items = prompt.context.items()
307
+ if (store.mode !== "shell") return items
308
+ return items.filter((item) => !item.comment?.trim())
309
+ })
310
+
311
+ const hasUserPrompt = createMemo(() => {
312
+ const sessionID = props.controls.session.id
313
+ if (!sessionID) return false
314
+ const messages = sync().data.message[sessionID]
315
+ if (!messages) return false
316
+ return messages.some((m) => m.role === "user")
317
+ })
318
+
319
+ const history = props.history ?? createPersistedPromptInputHistory()
320
+
321
+ const suggest = createMemo(() => !hasUserPrompt())
322
+
323
+ const placeholder = createMemo(() =>
324
+ promptPlaceholder({
325
+ mode: store.mode,
326
+ commentCount: commentCount(),
327
+ example: suggest() ? (store.mode === "shell" ? "git status" : language.t(EXAMPLES[store.placeholder])) : "",
328
+ suggest: suggest(),
329
+ t: (key, params) => language.t(key as Parameters<typeof language.t>[0], params as never),
330
+ }),
331
+ )
332
+
333
+ const historyComments = () => {
334
+ const byID = new Map(comments.all().map((item) => [`${item.file}\n${item.id}`, item] as const))
335
+ return prompt.context.items().flatMap((item) => {
336
+ if (item.type !== "file") return []
337
+ const comment = item.comment?.trim()
338
+ if (!comment) return []
339
+
340
+ const selection = item.commentID ? byID.get(`${item.path}\n${item.commentID}`)?.selection : undefined
341
+ const nextSelection =
342
+ selection ??
343
+ (item.selection
344
+ ? ({
345
+ start: item.selection.startLine,
346
+ end: item.selection.endLine,
347
+ } satisfies SelectedLineRange)
348
+ : undefined)
349
+ if (!nextSelection) return []
350
+
351
+ return [
352
+ {
353
+ id: item.commentID ?? item.key,
354
+ path: item.path,
355
+ selection: { ...nextSelection },
356
+ comment,
357
+ time: item.commentID ? (byID.get(`${item.path}\n${item.commentID}`)?.time ?? Date.now()) : Date.now(),
358
+ origin: item.commentOrigin,
359
+ preview: item.preview,
360
+ } satisfies PromptHistoryComment,
361
+ ]
362
+ })
363
+ }
364
+
365
+ const applyHistoryComments = (items: PromptHistoryComment[]) => {
366
+ comments.replace(
367
+ items.map((item) => ({
368
+ id: item.id,
369
+ file: item.path,
370
+ selection: { ...item.selection },
371
+ comment: item.comment,
372
+ time: item.time,
373
+ })),
374
+ )
375
+ prompt.context.replaceComments(
376
+ items.map((item) => ({
377
+ type: "file" as const,
378
+ path: item.path,
379
+ selection: selectionFromLines(item.selection),
380
+ comment: item.comment,
381
+ commentID: item.id,
382
+ commentOrigin: item.origin,
383
+ preview: item.preview,
384
+ })),
385
+ )
386
+ }
387
+
388
+ const applyHistoryPrompt = (entry: PromptHistoryEntry, position: "start" | "end") => {
389
+ const p = entry.prompt
390
+ const length = position === "start" ? 0 : promptLength(p)
391
+ setStore("applyingHistory", true)
392
+ applyHistoryComments(entry.comments)
393
+ prompt.set(p, length)
394
+ requestAnimationFrame(() => {
395
+ editorRef.focus()
396
+ setCursorPosition(editorRef, length)
397
+ setStore("applyingHistory", false)
398
+ queueScroll()
399
+ })
400
+ }
401
+
402
+ const getCaretState = () => {
403
+ const selection = window.getSelection()
404
+ const textLength = promptLength(prompt.current())
405
+ if (!selection || selection.rangeCount === 0) {
406
+ return { collapsed: false, cursorPosition: 0, textLength }
407
+ }
408
+ const anchorNode = selection.anchorNode
409
+ if (!anchorNode || !editorRef.contains(anchorNode)) {
410
+ return { collapsed: false, cursorPosition: 0, textLength }
411
+ }
412
+ return {
413
+ collapsed: selection.isCollapsed,
414
+ cursorPosition: getCursorPosition(editorRef),
415
+ textLength,
416
+ }
417
+ }
418
+
419
+ const escBlur = () => platform.platform === "desktop" && platform.os === "macos"
420
+
421
+ const pick = () => {
422
+ pickAttachmentFiles({
423
+ picker: platform.openAttachmentPickerDialog,
424
+ directory: () => sdk().directory,
425
+ fallback: () => fileInputRef?.click(),
426
+ onFile: addAttachment,
427
+ onError: (error) =>
428
+ showToast({
429
+ variant: "error",
430
+ title: language.t("common.requestFailed"),
431
+ description: error instanceof Error ? error.message : String(error),
432
+ }),
433
+ })
434
+ }
435
+
436
+ const setMode = (mode: "normal" | "shell") => {
437
+ setStore("mode", mode)
438
+ setStore({ popover: null, slashMenu: false, slashMenuQuery: "" })
439
+ requestAnimationFrame(() => editorRef?.focus())
440
+ }
441
+
442
+ const shellModeKey = "mod+shift+x"
443
+ const normalModeKey = "mod+shift+e"
444
+
445
+ command.register("prompt-input", () => [
446
+ {
447
+ id: "file.attach",
448
+ title: language.t("prompt.action.attachFile"),
449
+ category: language.t("command.category.file"),
450
+ keybind: "mod+u",
451
+ disabled: store.mode !== "normal",
452
+ onSelect: pick,
453
+ },
454
+ {
455
+ id: "prompt.mode.shell",
456
+ title: language.t("command.prompt.mode.shell"),
457
+ category: language.t("command.category.session"),
458
+ keybind: shellModeKey,
459
+ disabled: store.mode === "shell",
460
+ onSelect: () => setMode("shell"),
461
+ },
462
+ {
463
+ id: "prompt.mode.normal",
464
+ title: language.t("command.prompt.mode.normal"),
465
+ category: language.t("command.category.session"),
466
+ keybind: normalModeKey,
467
+ disabled: store.mode === "normal",
468
+ onSelect: () => setMode("normal"),
469
+ },
470
+ ])
471
+
472
+ const closePopover = () => setStore({ popover: null, slashMenu: false, slashMenuQuery: "" })
473
+
474
+ const resetHistoryNavigation = (force = false) => {
475
+ if (!force && (store.historyIndex < 0 || store.applyingHistory)) return
476
+ setStore("historyIndex", -1)
477
+ setStore("savedPrompt", null)
478
+ }
479
+
480
+ const clearEditor = () => {
481
+ editorRef.innerHTML = ""
482
+ }
483
+
484
+ const setEditorText = (text: string) => {
485
+ clearEditor()
486
+ editorRef.textContent = text
487
+ }
488
+
489
+ const focusEditorEnd = () => {
490
+ requestAnimationFrame(() => {
491
+ editorRef.focus()
492
+ const range = document.createRange()
493
+ const selection = window.getSelection()
494
+ range.selectNodeContents(editorRef)
495
+ range.collapse(false)
496
+ selection?.removeAllRanges()
497
+ selection?.addRange(range)
498
+ })
499
+ }
500
+
501
+ const currentCursor = () => {
502
+ const selection = window.getSelection()
503
+ if (!selection || selection.rangeCount === 0 || !editorRef.contains(selection.anchorNode)) return null
504
+ return getCursorPosition(editorRef)
505
+ }
506
+
507
+ const restoreFocus = () => {
508
+ requestAnimationFrame(() => {
509
+ const cursor = savedCursor ?? prompt.cursor() ?? promptLength(prompt.current())
510
+ editorRef.focus()
511
+ setCursorPosition(editorRef, cursor)
512
+ queueScroll()
513
+ })
514
+ }
515
+
516
+ const handleFocus = () => {
517
+ if (!restoreEndOnFocus) return
518
+ restoreEndOnFocus = false
519
+ requestAnimationFrame(() => {
520
+ if (document.activeElement !== editorRef) return
521
+ setCursorPosition(editorRef, prompt.cursor() ?? promptLength(prompt.current()))
522
+ queueScroll()
523
+ })
524
+ }
525
+
526
+ const renderEditorWithCursor = (parts: Prompt) => {
527
+ const cursor = currentCursor()
528
+ renderEditor(parts)
529
+ if (cursor !== null) setCursorPosition(editorRef, cursor)
530
+ }
531
+
532
+ createEffect(() => {
533
+ props.controls.session.id
534
+ if (props.controls.session.id) return
535
+ if (!suggest()) return
536
+ const interval = setInterval(() => {
537
+ setStore("placeholder", (prev) => (prev + 1) % EXAMPLES.length)
538
+ }, 6500)
539
+ onCleanup(() => clearInterval(interval))
540
+ })
541
+
542
+ const [composing, setComposing] = createSignal(false)
543
+ const isImeComposing = (event: KeyboardEvent) => event.isComposing || composing() || event.keyCode === 229
544
+
545
+ const handleBlur = () => {
546
+ const cursor = currentCursor()
547
+ savedCursor = cursor
548
+ if (cursor !== null && cursor !== prompt.cursor()) prompt.set(prompt.current(), cursor)
549
+ closePopover()
550
+ setComposing(false)
551
+ }
552
+
553
+ const handleCompositionStart = () => {
554
+ setComposing(true)
555
+ }
556
+
557
+ const handleCompositionEnd = () => {
558
+ setComposing(false)
559
+ requestAnimationFrame(() => {
560
+ if (composing()) return
561
+ reconcile(prompt.current().filter((part) => part.type !== "image"))
562
+ })
563
+ }
564
+
565
+ const referenceDescription = (reference: ReferenceInfo) =>
566
+ reference.source.type === "git" ? reference.source.repository : reference.source.path
567
+
568
+ const referenceList = createMemo(() =>
569
+ sync()
570
+ .data.reference.filter((reference) => !reference.hidden)
571
+ .map(
572
+ (reference): AtOption => ({
573
+ type: "reference",
574
+ name: reference.name,
575
+ path: reference.path,
576
+ display: reference.name,
577
+ description: reference.description ?? referenceDescription(reference),
578
+ }),
579
+ ),
580
+ )
581
+
582
+ const agentList = createMemo(() =>
583
+ props.controls.agents.available
584
+ .filter((agent) => !agent.hidden && agent.mode !== "primary")
585
+ .map((agent): AtOption => ({ type: "agent", name: agent.name, display: agent.name })),
586
+ )
587
+
588
+ const mcpResourceList = createMemo(() =>
589
+ Object.values(sync().data.mcp_resource).map(
590
+ (resource): AtOption => ({
591
+ type: "resource",
592
+ name: resource.name,
593
+ uri: resource.uri,
594
+ client: resource.server,
595
+ display: resource.name,
596
+ description: resource.description,
597
+ mime: resource.mimeType,
598
+ }),
599
+ ),
600
+ )
601
+
602
+ const handleAtSelect = (option: AtOption | undefined) => {
603
+ if (!option) return
604
+ if (option.type === "agent") {
605
+ addPart({ type: "agent", name: option.name, content: "@" + option.name, start: 0, end: 0 })
606
+ return
607
+ }
608
+ if (option.type === "reference") {
609
+ addPart({
610
+ type: "file",
611
+ path: option.path,
612
+ content: "@" + option.name,
613
+ start: 0,
614
+ end: 0,
615
+ mime: "application/x-directory",
616
+ filename: option.name,
617
+ })
618
+ return
619
+ }
620
+ if (option.type === "resource") {
621
+ addPart({
622
+ type: "file",
623
+ path: option.uri,
624
+ content: "@" + option.name,
625
+ start: 0,
626
+ end: 0,
627
+ mime: option.mime ?? "text/plain",
628
+ filename: option.name,
629
+ url: option.uri,
630
+ source: {
631
+ type: "resource",
632
+ text: { value: "@" + option.name, start: 0, end: 0 },
633
+ clientName: option.client,
634
+ uri: option.uri,
635
+ },
636
+ })
637
+ return
638
+ }
639
+ addPart({ type: "file", path: option.path, content: "@" + option.path, start: 0, end: 0 })
640
+ }
641
+
642
+ const atKey = (x: AtOption | undefined) => {
643
+ if (!x) return ""
644
+ if (x.type === "agent") return `agent:${x.name}`
645
+ if (x.type === "reference") return `reference:${x.name}`
646
+ if (x.type === "resource") return `resource:${x.client}:${x.uri}`
647
+ return `file:${x.path}`
648
+ }
649
+
650
+ const {
651
+ flat: atFlat,
652
+ active: atActive,
653
+ setActive: setAtActive,
654
+ onInput: atOnInput,
655
+ onKeyDown: atOnKeyDown,
656
+ } = useFilteredList<AtOption>({
657
+ items: async (query) => {
658
+ const references = referenceList()
659
+ const agents = agentList()
660
+ const mcpResources = mcpResourceList()
661
+ const open = recent()
662
+ const seen = new Set(open)
663
+ const pinned: AtOption[] = open.map((path) => ({ type: "file", path, display: path, recent: true }))
664
+ if (!query.trim()) return [...references, ...agents, ...mcpResources, ...pinned]
665
+ const paths = await files.searchFilesAndDirectories(query)
666
+ const fileOptions: AtOption[] = paths
667
+ .filter((path) => !seen.has(path))
668
+ .map((path) => ({ type: "file", path, display: path }))
669
+ return [...references, ...agents, ...mcpResources, ...pinned, ...fileOptions]
670
+ },
671
+ key: atKey,
672
+ filterKeys: ["display"],
673
+ skipFilter: (item) => item.type === "file" && !item.recent,
674
+ groupBy: (item) => {
675
+ if (item.type === "reference") return "reference"
676
+ if (item.type === "agent") return "agent"
677
+ if (item.type === "resource") return "resource"
678
+ if (item.recent) return "recent"
679
+ return "file"
680
+ },
681
+ sortGroupsBy: (a, b) => {
682
+ const rank = (category: string) => {
683
+ if (category === "reference") return 0
684
+ if (category === "agent") return 1
685
+ if (category === "resource") return 2
686
+ if (category === "recent") return 3
687
+ return 4
688
+ }
689
+ return rank(a.category) - rank(b.category)
690
+ },
691
+ onSelect: handleAtSelect,
692
+ })
693
+
694
+ const slashCommands = createMemo<SlashCommand[]>(() => {
695
+ const builtin = command.options
696
+ .filter((opt) => !opt.disabled && !opt.id.startsWith("suggested.") && opt.slash)
697
+ .map((opt) => ({
698
+ id: opt.id,
699
+ trigger: opt.slash!,
700
+ title: opt.title,
701
+ description: opt.description,
702
+ keybind: opt.keybind,
703
+ type: "builtin" as const,
704
+ }))
705
+
706
+ const custom = sync().data.command.map((cmd) => ({
707
+ id: `custom.${cmd.name}`,
708
+ trigger: cmd.name,
709
+ title: cmd.name,
710
+ description: cmd.description,
711
+ type: "custom" as const,
712
+ source: cmd.source,
713
+ }))
714
+
715
+ return [...custom, ...builtin]
716
+ })
717
+
718
+ const handleSlashSelect = (cmd: SlashCommand | undefined) => {
719
+ if (!cmd) return
720
+ const menu = store.slashMenu
721
+ closePopover()
722
+ const images = imageAttachments()
723
+
724
+ if (cmd.type === "custom") {
725
+ const text = `/${cmd.trigger} `
726
+ if (menu) {
727
+ editorRef.focus()
728
+ setCursorPosition(editorRef, 0)
729
+ addPart({ type: "text", content: text, start: 0, end: text.length })
730
+ focusEditorEnd()
731
+ return
732
+ }
733
+ setEditorText(text)
734
+ prompt.set([{ type: "text", content: text, start: 0, end: text.length }, ...images], text.length)
735
+ focusEditorEnd()
736
+ return
737
+ }
738
+
739
+ if (menu) {
740
+ command.trigger(cmd.id, "slash")
741
+ return
742
+ }
743
+
744
+ clearEditor()
745
+ prompt.set([...DEFAULT_PROMPT, ...images], 0)
746
+ command.trigger(cmd.id, "slash")
747
+ }
748
+
749
+ const {
750
+ flat: slashFlat,
751
+ active: slashActive,
752
+ setActive: setSlashActive,
753
+ onInput: slashOnInput,
754
+ onKeyDown: slashOnKeyDown,
755
+ } = useFilteredList<SlashCommand>({
756
+ items: slashCommands,
757
+ key: (x) => x?.id,
758
+ filterKeys: ["trigger", "title"],
759
+ onSelect: handleSlashSelect,
760
+ })
761
+
762
+ const createPill = (part: FileAttachmentPart | AgentPart) => {
763
+ const pill = document.createElement("span")
764
+ pill.textContent = part.content
765
+ pill.setAttribute("data-type", part.type)
766
+ if (part.type === "file") {
767
+ pill.setAttribute("data-path", part.path)
768
+ if (part.mime) pill.setAttribute("data-mime", part.mime)
769
+ if (part.filename) pill.setAttribute("data-filename", part.filename)
770
+ if (part.url) pill.setAttribute("data-url", part.url)
771
+ if (part.source?.type === "resource") {
772
+ pill.setAttribute("data-source-type", part.source.type)
773
+ pill.setAttribute("data-source-client-name", part.source.clientName)
774
+ pill.setAttribute("data-source-uri", part.source.uri)
775
+ }
776
+ }
777
+ if (part.type === "agent") pill.setAttribute("data-name", part.name)
778
+ pill.setAttribute("contenteditable", "false")
779
+ pill.style.userSelect = "text"
780
+ pill.style.cursor = "default"
781
+ return pill
782
+ }
783
+
784
+ const isNormalizedEditor = () =>
785
+ Array.from(editorRef.childNodes).every((node) => {
786
+ if (node.nodeType === Node.TEXT_NODE) {
787
+ const text = node.textContent ?? ""
788
+ if (!text.includes("\u200B")) return true
789
+ if (text !== "\u200B") return false
790
+
791
+ const prev = node.previousSibling
792
+ const next = node.nextSibling
793
+ const prevIsBr = prev?.nodeType === Node.ELEMENT_NODE && (prev as HTMLElement).tagName === "BR"
794
+ return !!prevIsBr && !next
795
+ }
796
+ if (node.nodeType !== Node.ELEMENT_NODE) return false
797
+ const el = node as HTMLElement
798
+ if (el.dataset.type === "file") return true
799
+ if (el.dataset.type === "agent") return true
800
+ return el.tagName === "BR"
801
+ })
802
+
803
+ const renderEditor = (parts: Prompt) => {
804
+ clearEditor()
805
+ for (const part of parts) {
806
+ if (part.type === "text") {
807
+ editorRef.appendChild(createTextFragment(part.content))
808
+ continue
809
+ }
810
+ if (part.type === "file" || part.type === "agent") {
811
+ editorRef.appendChild(createPill(part))
812
+ }
813
+ }
814
+
815
+ const last = editorRef.lastChild
816
+ if (last?.nodeType === Node.ELEMENT_NODE && (last as HTMLElement).tagName === "BR") {
817
+ editorRef.appendChild(document.createTextNode("\u200B"))
818
+ }
819
+ }
820
+
821
+ const scrollSlashActiveIntoView = () => {
822
+ const activeId = slashActive()
823
+ if (!activeId || !slashPopoverRef) return
824
+
825
+ requestAnimationFrame(() => {
826
+ const element = slashPopoverRef.querySelector(`[data-slash-id="${activeId}"]`)
827
+ element?.scrollIntoView({ block: "nearest", behavior: "smooth" })
828
+ })
829
+ }
830
+ const selectPopoverActive = () => {
831
+ if (store.popover === "at") {
832
+ const items = atFlat()
833
+ if (items.length === 0) return
834
+ const active = atActive()
835
+ const item = items.find((entry) => atKey(entry) === active) ?? items[0]
836
+ handleAtSelect(item)
837
+ return
838
+ }
839
+
840
+ if (store.popover === "slash") {
841
+ const items = slashFlat()
842
+ if (items.length === 0) return
843
+ const active = slashActive()
844
+ const item = items.find((entry) => entry.id === active) ?? items[0]
845
+ handleSlashSelect(item)
846
+ }
847
+ }
848
+
849
+ const reconcile = (input: Prompt) => {
850
+ if (mirror.input) {
851
+ mirror.input = false
852
+ if (isNormalizedEditor()) return
853
+
854
+ renderEditorWithCursor(input)
855
+ return
856
+ }
857
+
858
+ const dom = parseFromDOM()
859
+ if (isNormalizedEditor() && isPromptEqual(input, dom)) return
860
+
861
+ renderEditorWithCursor(input)
862
+ }
863
+
864
+ createEffect(
865
+ on(
866
+ () => prompt.current(),
867
+ (parts) => {
868
+ if (composing()) return
869
+ reconcile(parts.filter((part) => part.type !== "image"))
870
+ },
871
+ ),
872
+ )
873
+
874
+ const parseFromDOM = (): Prompt => {
875
+ const parts: Prompt = []
876
+ let position = 0
877
+ let buffer = ""
878
+
879
+ const flushText = () => {
880
+ let content = buffer
881
+ if (content.includes("\r")) content = content.replace(/\r\n?/g, "\n")
882
+ if (content.includes("\u200B")) content = content.replace(/\u200B/g, "")
883
+ buffer = ""
884
+ if (!content) return
885
+ parts.push({ type: "text", content, start: position, end: position + content.length })
886
+ position += content.length
887
+ }
888
+
889
+ const pushFile = (file: HTMLElement) => {
890
+ const content = file.textContent ?? ""
891
+ const source =
892
+ file.dataset.sourceType === "resource" && file.dataset.sourceClientName && file.dataset.sourceUri
893
+ ? {
894
+ type: "resource" as const,
895
+ text: {
896
+ value: content,
897
+ start: position,
898
+ end: position + content.length,
899
+ },
900
+ clientName: file.dataset.sourceClientName,
901
+ uri: file.dataset.sourceUri,
902
+ }
903
+ : undefined
904
+ parts.push({
905
+ type: "file",
906
+ path: file.dataset.path!,
907
+ content,
908
+ start: position,
909
+ end: position + content.length,
910
+ ...(file.dataset.mime ? { mime: file.dataset.mime } : {}),
911
+ ...(file.dataset.filename ? { filename: file.dataset.filename } : {}),
912
+ ...(file.dataset.url ? { url: file.dataset.url } : {}),
913
+ ...(source ? { source } : {}),
914
+ })
915
+ position += content.length
916
+ }
917
+
918
+ const pushAgent = (agent: HTMLElement) => {
919
+ const content = agent.textContent ?? ""
920
+ parts.push({
921
+ type: "agent",
922
+ name: agent.dataset.name!,
923
+ content,
924
+ start: position,
925
+ end: position + content.length,
926
+ })
927
+ position += content.length
928
+ }
929
+
930
+ const visit = (node: Node) => {
931
+ if (node.nodeType === Node.TEXT_NODE) {
932
+ buffer += node.textContent ?? ""
933
+ return
934
+ }
935
+ if (node.nodeType !== Node.ELEMENT_NODE) return
936
+
937
+ const el = node as HTMLElement
938
+ if (el.dataset.type === "file") {
939
+ flushText()
940
+ pushFile(el)
941
+ return
942
+ }
943
+ if (el.dataset.type === "agent") {
944
+ flushText()
945
+ pushAgent(el)
946
+ return
947
+ }
948
+ if (el.tagName === "BR") {
949
+ buffer += "\n"
950
+ return
951
+ }
952
+
953
+ for (const child of Array.from(el.childNodes)) {
954
+ visit(child)
955
+ }
956
+ }
957
+
958
+ const children = Array.from(editorRef.childNodes)
959
+ children.forEach((child, index) => {
960
+ const isBlock = child.nodeType === Node.ELEMENT_NODE && ["DIV", "P"].includes((child as HTMLElement).tagName)
961
+ visit(child)
962
+ if (isBlock && index < children.length - 1) {
963
+ buffer += "\n"
964
+ }
965
+ })
966
+
967
+ flushText()
968
+
969
+ if (parts.length === 0) parts.push(...DEFAULT_PROMPT)
970
+ return parts
971
+ }
972
+
973
+ const handleInput = () => {
974
+ const rawParts = parseFromDOM()
975
+ const images = imageAttachments()
976
+ const cursorPosition = getCursorPosition(editorRef)
977
+ const rawText =
978
+ rawParts.length === 1 && rawParts[0]?.type === "text"
979
+ ? rawParts[0].content
980
+ : rawParts.map((p) => ("content" in p ? p.content : "")).join("")
981
+ const hasNonText = rawParts.some((part) => part.type !== "text")
982
+ const textContent = (editorRef.textContent ?? "").replace(/\u200B/g, "")
983
+ const shouldReset =
984
+ textContent.length === 0 && rawText.replace(/\n/g, "").length === 0 && !hasNonText && images.length === 0
985
+
986
+ if (shouldReset) {
987
+ closePopover()
988
+ resetHistoryNavigation()
989
+ if (prompt.dirty()) {
990
+ mirror.input = true
991
+ prompt.set(DEFAULT_PROMPT, 0)
992
+ }
993
+ queueScroll()
994
+ return
995
+ }
996
+
997
+ const shellMode = store.mode === "shell"
998
+
999
+ if (!shellMode) {
1000
+ const atMatch = rawText.substring(0, cursorPosition).match(/@(\S*)$/)
1001
+ const slashMatch = rawText.match(/^\/(\S*)$/)
1002
+
1003
+ if (atMatch) {
1004
+ atOnInput(atMatch[1])
1005
+ setStore({ popover: "at", slashMenu: false, slashMenuQuery: "" })
1006
+ } else if (slashMatch) {
1007
+ slashOnInput(slashMatch[1])
1008
+ setStore({ popover: "slash", slashMenu: false, slashMenuQuery: "" })
1009
+ } else {
1010
+ closePopover()
1011
+ }
1012
+ } else {
1013
+ closePopover()
1014
+ }
1015
+
1016
+ resetHistoryNavigation()
1017
+
1018
+ mirror.input = true
1019
+ prompt.set([...rawParts, ...images], cursorPosition)
1020
+ queueScroll()
1021
+ }
1022
+
1023
+ const addPart = (part: ContentPart) => {
1024
+ if (part.type === "image") return false
1025
+
1026
+ const selection = window.getSelection()
1027
+ if (!selection) return false
1028
+
1029
+ if (selection.rangeCount === 0 || !editorRef.contains(selection.anchorNode)) {
1030
+ editorRef.focus()
1031
+ const cursor = prompt.cursor() ?? promptLength(prompt.current())
1032
+ setCursorPosition(editorRef, cursor)
1033
+ }
1034
+
1035
+ if (selection.rangeCount === 0) return false
1036
+ const range = selection.getRangeAt(0)
1037
+ if (!editorRef.contains(range.startContainer)) return false
1038
+
1039
+ if (part.type === "file" || part.type === "agent") {
1040
+ const cursorPosition = getCursorPosition(editorRef)
1041
+ const rawText = prompt
1042
+ .current()
1043
+ .map((p) => ("content" in p ? p.content : ""))
1044
+ .join("")
1045
+ const textBeforeCursor = rawText.substring(0, cursorPosition)
1046
+ const atMatch = textBeforeCursor.match(/@(\S*)$/)
1047
+ const pill = createPill(part)
1048
+ const gap = document.createTextNode(" ")
1049
+
1050
+ if (atMatch) {
1051
+ const start = atMatch.index ?? cursorPosition - atMatch[0].length
1052
+ setRangeEdge(editorRef, range, "start", start)
1053
+ setRangeEdge(editorRef, range, "end", cursorPosition)
1054
+ }
1055
+
1056
+ range.deleteContents()
1057
+ range.insertNode(gap)
1058
+ range.insertNode(pill)
1059
+ range.setStartAfter(gap)
1060
+ range.collapse(true)
1061
+ selection.removeAllRanges()
1062
+ selection.addRange(range)
1063
+ }
1064
+
1065
+ if (part.type === "text") {
1066
+ const fragment = createTextFragment(part.content)
1067
+ const last = fragment.lastChild
1068
+ range.deleteContents()
1069
+ range.insertNode(fragment)
1070
+ if (last) {
1071
+ if (last.nodeType === Node.TEXT_NODE) {
1072
+ const text = last.textContent ?? ""
1073
+ if (text === "\u200B") {
1074
+ range.setStart(last, 0)
1075
+ }
1076
+ if (text !== "\u200B") {
1077
+ range.setStart(last, text.length)
1078
+ }
1079
+ }
1080
+ if (last.nodeType !== Node.TEXT_NODE) {
1081
+ const isBreak = last.nodeType === Node.ELEMENT_NODE && (last as HTMLElement).tagName === "BR"
1082
+ const next = last.nextSibling
1083
+ const emptyText = next?.nodeType === Node.TEXT_NODE && (next.textContent ?? "") === ""
1084
+ if (isBreak && (!next || emptyText)) {
1085
+ const placeholder = next && emptyText ? next : document.createTextNode("\u200B")
1086
+ if (!next) last.parentNode?.insertBefore(placeholder, null)
1087
+ placeholder.textContent = "\u200B"
1088
+ range.setStart(placeholder, 0)
1089
+ } else {
1090
+ range.setStartAfter(last)
1091
+ }
1092
+ }
1093
+ }
1094
+ range.collapse(true)
1095
+ selection.removeAllRanges()
1096
+ selection.addRange(range)
1097
+ }
1098
+
1099
+ handleInput()
1100
+ closePopover()
1101
+ return true
1102
+ }
1103
+
1104
+ const addToHistory = (prompt: Prompt, mode: "normal" | "shell") => {
1105
+ history.add(prompt, mode, mode === "shell" ? [] : historyComments())
1106
+ }
1107
+
1108
+ createEffect(
1109
+ on(
1110
+ () => props.edit?.id,
1111
+ (id) => {
1112
+ const edit = props.edit
1113
+ if (!id || !edit) return
1114
+
1115
+ for (const item of prompt.context.items()) {
1116
+ prompt.context.remove(item.key)
1117
+ }
1118
+
1119
+ for (const item of edit.context) {
1120
+ prompt.context.add({
1121
+ type: item.type,
1122
+ path: item.path,
1123
+ selection: item.selection,
1124
+ comment: item.comment,
1125
+ commentID: item.commentID,
1126
+ commentOrigin: item.commentOrigin,
1127
+ preview: item.preview,
1128
+ })
1129
+ }
1130
+
1131
+ setStore("mode", "normal")
1132
+ closePopover()
1133
+ setStore("historyIndex", -1)
1134
+ setStore("savedPrompt", null)
1135
+ prompt.set(edit.prompt, promptLength(edit.prompt))
1136
+ requestAnimationFrame(() => {
1137
+ editorRef.focus()
1138
+ setCursorPosition(editorRef, promptLength(edit.prompt))
1139
+ queueScroll()
1140
+ })
1141
+ props.onEditLoaded?.()
1142
+ },
1143
+ { defer: true },
1144
+ ),
1145
+ )
1146
+
1147
+ const navigateHistory = (direction: "up" | "down") => {
1148
+ const result = navigatePromptHistory({
1149
+ direction,
1150
+ entries: history.entries(store.mode),
1151
+ historyIndex: store.historyIndex,
1152
+ currentPrompt: prompt.current(),
1153
+ currentComments: historyComments(),
1154
+ savedPrompt: store.savedPrompt,
1155
+ })
1156
+ if (!result.handled) return false
1157
+ setStore("historyIndex", result.historyIndex)
1158
+ setStore("savedPrompt", result.savedPrompt)
1159
+ applyHistoryPrompt(result.entry, result.cursor)
1160
+ return true
1161
+ }
1162
+
1163
+ const { addAttachment, addAttachments, removeAttachment, handlePaste } = createPromptAttachments({
1164
+ prompt,
1165
+ editor: () => editorRef,
1166
+ isDialogActive: () => !!dialog.active,
1167
+ setDraggingType: (type) => setStore("draggingType", type),
1168
+ focusEditor: () => {
1169
+ editorRef.focus()
1170
+ setCursorPosition(editorRef, promptLength(prompt.current()))
1171
+ },
1172
+ addPart,
1173
+ readClipboardImage: platform.readClipboardImage,
1174
+ getPathForFile: platform.getPathForFile,
1175
+ })
1176
+
1177
+ const fileAttachmentInput = () => (
1178
+ <input
1179
+ ref={(el) => (fileInputRef = el)}
1180
+ type="file"
1181
+ multiple
1182
+ accept={ACCEPTED_FILE_TYPES.join(",")}
1183
+ class="hidden"
1184
+ onChange={(e) => {
1185
+ const list = e.currentTarget.files
1186
+ if (list) void addAttachments(Array.from(list))
1187
+ e.currentTarget.value = ""
1188
+ }}
1189
+ />
1190
+ )
1191
+
1192
+ const variants = createMemo(() => ["default", ...props.controls.model.selection.variant.list()])
1193
+ // Check provider variants directly: `variants` also includes the UI-only default option.
1194
+ const showVariantControl = createMemo(() => props.controls.model.selection.variant.list().length > 0)
1195
+ const accepting = createMemo(() => {
1196
+ const id = props.controls.session.id
1197
+ if (!id) return permission.isAutoAcceptingDirectory(sdk().directory)
1198
+ return permission.isAutoAccepting(id, sdk().directory)
1199
+ })
1200
+
1201
+ const { abort, handleSubmit } =
1202
+ props.submission ??
1203
+ createPromptSubmit({
1204
+ prompt,
1205
+ info,
1206
+ imageAttachments,
1207
+ commentCount,
1208
+ autoAccept: () => accepting(),
1209
+ mode: () => store.mode,
1210
+ working,
1211
+ editor: () => editorRef,
1212
+ queueScroll,
1213
+ promptLength,
1214
+ addToHistory,
1215
+ resetHistoryNavigation: () => {
1216
+ resetHistoryNavigation(true)
1217
+ },
1218
+ setMode: (mode) => setStore("mode", mode),
1219
+ setPopover: (popover) => {
1220
+ if (!popover) return closePopover()
1221
+ setStore({ popover, slashMenu: false, slashMenuQuery: "" })
1222
+ },
1223
+ newSessionWorktree: () => props.newSessionWorktree,
1224
+ onNewSessionWorktreeReset: props.onNewSessionWorktreeReset,
1225
+ shouldQueue: props.shouldQueue,
1226
+ onQueue: props.onQueue,
1227
+ onAbort: props.onAbort,
1228
+ onSubmit: props.onSubmit,
1229
+ model: props.controls.model.selection,
1230
+ })
1231
+
1232
+ const handleKeyDown = (event: KeyboardEvent) => {
1233
+ if ((event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "u") {
1234
+ event.preventDefault()
1235
+ if (store.mode !== "normal") return
1236
+ pick()
1237
+ return
1238
+ }
1239
+
1240
+ if (event.key === "Backspace") {
1241
+ const selection = window.getSelection()
1242
+ if (selection && selection.isCollapsed) {
1243
+ const node = selection.anchorNode
1244
+ const offset = selection.anchorOffset
1245
+ if (node && node.nodeType === Node.TEXT_NODE) {
1246
+ const text = node.textContent ?? ""
1247
+ if (/^\u200B+$/.test(text) && offset > 0) {
1248
+ const range = document.createRange()
1249
+ range.setStart(node, 0)
1250
+ range.collapse(true)
1251
+ selection.removeAllRanges()
1252
+ selection.addRange(range)
1253
+ }
1254
+ }
1255
+ }
1256
+ }
1257
+
1258
+ if (event.key === "!" && store.mode === "normal") {
1259
+ const cursorPosition = getCursorPosition(editorRef)
1260
+ if (cursorPosition === 0) {
1261
+ setStore("mode", "shell")
1262
+ closePopover()
1263
+ event.preventDefault()
1264
+ return
1265
+ }
1266
+ }
1267
+
1268
+ if (event.key === "Escape") {
1269
+ if (store.popover) {
1270
+ closePopover()
1271
+ event.preventDefault()
1272
+ event.stopPropagation()
1273
+ return
1274
+ }
1275
+
1276
+ if (store.mode === "shell") {
1277
+ setStore("mode", "normal")
1278
+ event.preventDefault()
1279
+ event.stopPropagation()
1280
+ return
1281
+ }
1282
+
1283
+ if (working()) {
1284
+ void abort()
1285
+ event.preventDefault()
1286
+ event.stopPropagation()
1287
+ return
1288
+ }
1289
+
1290
+ if (escBlur()) {
1291
+ editorRef.blur()
1292
+ event.preventDefault()
1293
+ event.stopPropagation()
1294
+ return
1295
+ }
1296
+ }
1297
+
1298
+ if (store.mode === "shell") {
1299
+ const { collapsed, cursorPosition, textLength } = getCaretState()
1300
+ if (event.key === "Backspace" && collapsed && cursorPosition === 0 && textLength === 0) {
1301
+ setStore("mode", "normal")
1302
+ event.preventDefault()
1303
+ return
1304
+ }
1305
+ }
1306
+
1307
+ // Handle Shift+Enter BEFORE IME check - Shift+Enter is never used for IME input
1308
+ // and should always insert a newline regardless of composition state
1309
+ if (event.key === "Enter" && event.shiftKey) {
1310
+ addPart({ type: "text", content: "\n", start: 0, end: 0 })
1311
+ event.preventDefault()
1312
+ return
1313
+ }
1314
+
1315
+ if (event.key === "Enter" && isImeComposing(event)) {
1316
+ return
1317
+ }
1318
+
1319
+ const ctrl = event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey
1320
+
1321
+ if (store.popover) {
1322
+ if (event.key === "Tab") {
1323
+ selectPopoverActive()
1324
+ event.preventDefault()
1325
+ return
1326
+ }
1327
+ const nav = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Enter"
1328
+ const ctrlNav = ctrl && (event.key === "n" || event.key === "p")
1329
+ if (nav || ctrlNav) {
1330
+ if (store.popover === "at") {
1331
+ atOnKeyDown(event)
1332
+ event.preventDefault()
1333
+ return
1334
+ }
1335
+ if (store.popover === "slash") {
1336
+ slashOnKeyDown(event)
1337
+ if (event.key === "ArrowUp" || event.key === "ArrowDown" || ctrlNav) {
1338
+ scrollSlashActiveIntoView()
1339
+ }
1340
+ }
1341
+ event.preventDefault()
1342
+ return
1343
+ }
1344
+ }
1345
+
1346
+ if (ctrl && event.code === "KeyG") {
1347
+ if (store.popover) {
1348
+ closePopover()
1349
+ event.preventDefault()
1350
+ return
1351
+ }
1352
+ if (working()) {
1353
+ void abort()
1354
+ event.preventDefault()
1355
+ }
1356
+ return
1357
+ }
1358
+
1359
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
1360
+ if (event.altKey || event.ctrlKey || event.metaKey) return
1361
+ const { collapsed } = getCaretState()
1362
+ if (!collapsed) return
1363
+
1364
+ const cursorPosition = getCursorPosition(editorRef)
1365
+ const textContent = prompt
1366
+ .current()
1367
+ .map((part) => ("content" in part ? part.content : ""))
1368
+ .join("")
1369
+ const direction = event.key === "ArrowUp" ? "up" : "down"
1370
+ if (!canNavigateHistoryAtCursor(direction, textContent, cursorPosition, store.historyIndex >= 0)) return
1371
+ if (navigateHistory(direction)) {
1372
+ event.preventDefault()
1373
+ }
1374
+ return
1375
+ }
1376
+
1377
+ // Note: Shift+Enter is handled earlier, before IME check
1378
+ if (event.key === "Enter" && !event.shiftKey) {
1379
+ event.preventDefault()
1380
+ if (event.repeat) return
1381
+ if (
1382
+ working() &&
1383
+ prompt
1384
+ .current()
1385
+ .map((part) => ("content" in part ? part.content : ""))
1386
+ .join("")
1387
+ .trim().length === 0 &&
1388
+ imageAttachments().length === 0 &&
1389
+ commentCount() === 0
1390
+ ) {
1391
+ return
1392
+ }
1393
+ void handleSubmit(event)
1394
+ }
1395
+ }
1396
+
1397
+ const handleSlashMenuKeyDown = (event: KeyboardEvent) => {
1398
+ if (event.key === "Escape") {
1399
+ closePopover()
1400
+ requestAnimationFrame(() => editorRef.focus())
1401
+ event.preventDefault()
1402
+ return
1403
+ }
1404
+
1405
+ if (event.key === "Tab") {
1406
+ selectPopoverActive()
1407
+ event.preventDefault()
1408
+ return
1409
+ }
1410
+
1411
+ const ctrl = event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey
1412
+ const nav = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Enter"
1413
+ const ctrlNav = ctrl && (event.key === "n" || event.key === "p")
1414
+ if (!nav && !ctrlNav) return
1415
+ slashOnKeyDown(event)
1416
+ if (event.key === "ArrowUp" || event.key === "ArrowDown" || ctrlNav) scrollSlashActiveIntoView()
1417
+ event.preventDefault()
1418
+ }
1419
+
1420
+ const agentsLoading = () => props.controls.agents.loading
1421
+ const agentsShouldFadeIn = createMemo<boolean>((prev) => prev ?? agentsLoading())
1422
+ const providersLoading = () => props.controls.model.loading
1423
+ const providersShouldFadeIn = createMemo<boolean>((prev) => prev ?? providersLoading())
1424
+
1425
+ const [promptReady] = createResource(
1426
+ () => prompt.ready.promise,
1427
+ (p) => p,
1428
+ )
1429
+
1430
+ const bindEditorRef = (el: HTMLDivElement) => {
1431
+ editorRef = el
1432
+ restoreEndOnFocus = true
1433
+ props.ref?.(el)
1434
+ }
1435
+ return (
1436
+ <div class="relative size-full flex flex-col gap-0">
1437
+ {(promptReady(), null)}
1438
+ <PromptPopover
1439
+ popover={store.popover}
1440
+ setSlashPopoverRef={(el) => (slashPopoverRef = el)}
1441
+ atFlat={atFlat()}
1442
+ atActive={atActive() ?? undefined}
1443
+ atKey={atKey}
1444
+ setAtActive={setAtActive}
1445
+ onAtSelect={handleAtSelect}
1446
+ slashFlat={slashFlat()}
1447
+ slashActive={slashActive() ?? undefined}
1448
+ setSlashActive={setSlashActive}
1449
+ onSlashSelect={handleSlashSelect}
1450
+ slashMenu={store.slashMenu}
1451
+ slashMenuQuery={store.slashMenuQuery}
1452
+ onSlashMenuInput={(value) => {
1453
+ setStore("slashMenuQuery", value)
1454
+ slashOnInput(value)
1455
+ }}
1456
+ onSlashMenuKeyDown={handleSlashMenuKeyDown}
1457
+ commandKeybind={command.keybind}
1458
+ commandKeybindParts={command.keybindParts}
1459
+ newLayoutDesigns={false}
1460
+ t={(key) => language.t(key as Parameters<typeof language.t>[0])}
1461
+ />
1462
+ <DockShellForm
1463
+ data-dock-border-underlay="legacy"
1464
+ onSubmit={handleSubmit}
1465
+ classList={{
1466
+ "group/prompt-input": true,
1467
+ "border-icon-info-active border-dashed": store.draggingType !== null,
1468
+ [props.class ?? ""]: !!props.class,
1469
+ }}
1470
+ >
1471
+ <PromptDragOverlay
1472
+ type={store.draggingType}
1473
+ label={language.t(store.draggingType === "@mention" ? "prompt.dropzone.file.label" : "prompt.dropzone.label")}
1474
+ />
1475
+ <PromptContextItems
1476
+ items={contextItems()}
1477
+ active={(item) => {
1478
+ const active = comments.active()
1479
+ return !!item.commentID && item.commentID === active?.id && item.path === active?.file
1480
+ }}
1481
+ openComment={openComment}
1482
+ remove={(item) => {
1483
+ if (item.commentID) comments.remove(item.path, item.commentID)
1484
+ prompt.context.remove(item.key)
1485
+ }}
1486
+ newLayoutDesigns={false}
1487
+ t={(key) => language.t(key as Parameters<typeof language.t>[0])}
1488
+ />
1489
+ <PromptImageAttachments
1490
+ attachments={imageAttachments()}
1491
+ onOpen={(attachment) =>
1492
+ dialog.show(() => <ImagePreview src={attachment.dataUrl} alt={attachment.filename} />)
1493
+ }
1494
+ onRemove={removeAttachment}
1495
+ removeLabel={language.t("prompt.attachment.remove")}
1496
+ newLayoutDesigns={false}
1497
+ />
1498
+ <div
1499
+ class="relative"
1500
+ onMouseDown={(e) => {
1501
+ const target = e.target
1502
+ if (!(target instanceof HTMLElement)) return
1503
+ if (target.closest('[data-action="prompt-attach"], [data-action="prompt-submit"]')) {
1504
+ return
1505
+ }
1506
+ editorRef?.focus()
1507
+ }}
1508
+ >
1509
+ <div
1510
+ class="relative max-h-[240px] overflow-y-auto no-scrollbar"
1511
+ ref={(el) => (scrollRef = el)}
1512
+ style={{ "scroll-padding-bottom": space }}
1513
+ >
1514
+ <div
1515
+ data-component="prompt-input"
1516
+ ref={bindEditorRef}
1517
+ role="textbox"
1518
+ aria-multiline="true"
1519
+ aria-label={placeholder()}
1520
+ contenteditable="true"
1521
+ autocapitalize={store.mode === "normal" ? "sentences" : "off"}
1522
+ autocorrect={store.mode === "normal" ? "on" : "off"}
1523
+ spellcheck={store.mode === "normal"}
1524
+ inputMode="text"
1525
+ // @ts-expect-error
1526
+ autocomplete="off"
1527
+ onInput={handleInput}
1528
+ onPaste={handlePaste}
1529
+ onCompositionStart={handleCompositionStart}
1530
+ onCompositionEnd={handleCompositionEnd}
1531
+ onFocus={handleFocus}
1532
+ onBlur={handleBlur}
1533
+ onKeyDown={handleKeyDown}
1534
+ classList={{
1535
+ "select-text": true,
1536
+ "w-full pl-3 pr-2 pt-2 text-14-regular text-text-strong focus:outline-none whitespace-pre-wrap": true,
1537
+ "[&_[data-type=file]]:text-syntax-property": true,
1538
+ "[&_[data-type=agent]]:text-syntax-type": true,
1539
+ "font-mono!": store.mode === "shell",
1540
+ }}
1541
+ style={{ "padding-bottom": space }}
1542
+ />
1543
+ <div
1544
+ class="absolute top-0 inset-x-0 pl-3 pr-2 pt-2 text-14-regular text-text-weak pointer-events-none whitespace-nowrap truncate"
1545
+ classList={{ "font-mono!": store.mode === "shell" }}
1546
+ style={{ "padding-bottom": space, display: prompt.dirty() ? "none" : undefined }}
1547
+ >
1548
+ {placeholder()}
1549
+ </div>
1550
+ </div>
1551
+
1552
+ <div
1553
+ aria-hidden="true"
1554
+ class="pointer-events-none absolute inset-x-0 bottom-0"
1555
+ style={{
1556
+ height: space,
1557
+ background:
1558
+ "linear-gradient(to top, var(--surface-raised-stronger-non-alpha) calc(100% - 20px), transparent)",
1559
+ }}
1560
+ />
1561
+
1562
+ <div class="pointer-events-none absolute bottom-2 right-2 flex items-center gap-2">
1563
+ <input
1564
+ ref={fileInputRef}
1565
+ type="file"
1566
+ multiple
1567
+ accept={ACCEPTED_FILE_TYPES.join(",")}
1568
+ class="hidden"
1569
+ onChange={(e) => {
1570
+ const list = e.currentTarget.files
1571
+ if (list) void addAttachments(Array.from(list))
1572
+ e.currentTarget.value = ""
1573
+ }}
1574
+ />
1575
+
1576
+ <div class="flex items-center gap-1 pointer-events-auto">
1577
+ <Tooltip placement="top" inactive={!working() && blank()} value={tip()}>
1578
+ <IconButton
1579
+ data-action="prompt-submit"
1580
+ type="submit"
1581
+ disabled={!working() && blank()}
1582
+ tabIndex={store.mode === "normal" ? undefined : -1}
1583
+ icon={stopping() ? "stop" : store.mode === "shell" ? "arrow-undo-down" : "arrow-up"}
1584
+ variant="primary"
1585
+ class="size-8"
1586
+ aria-label={stopping() ? language.t("prompt.action.stop") : language.t("prompt.action.send")}
1587
+ />
1588
+ </Tooltip>
1589
+ </div>
1590
+ </div>
1591
+
1592
+ <div class="pointer-events-none absolute bottom-2 left-2">
1593
+ <div
1594
+ aria-hidden={store.mode !== "normal"}
1595
+ class="pointer-events-auto"
1596
+ style={{
1597
+ "pointer-events": buttonsSpring() > 0.5 ? "auto" : "none",
1598
+ }}
1599
+ >
1600
+ <TooltipKeybind
1601
+ placement="top"
1602
+ title={language.t("prompt.action.attachFile")}
1603
+ keybind={command.keybind("file.attach")}
1604
+ >
1605
+ <Button
1606
+ data-action="prompt-attach"
1607
+ type="button"
1608
+ variant="ghost"
1609
+ class="size-8 p-0"
1610
+ style={buttons()}
1611
+ onClick={pick}
1612
+ disabled={store.mode !== "normal"}
1613
+ tabIndex={store.mode === "normal" ? undefined : -1}
1614
+ aria-label={language.t("prompt.action.attachFile")}
1615
+ >
1616
+ <Icon name="plus" class="size-4.5" />
1617
+ </Button>
1618
+ </TooltipKeybind>
1619
+ </div>
1620
+ </div>
1621
+ </div>
1622
+ </DockShellForm>
1623
+ <Show when={store.mode === "normal" || store.mode === "shell"}>
1624
+ <DockTray attach="top">
1625
+ <div class="px-1.75 pt-5.5 pb-2 flex items-center gap-2 min-w-0">
1626
+ <div class="flex items-center gap-1.5 min-w-0 flex-1 relative">
1627
+ <div
1628
+ class="h-7 flex items-center gap-1.5 min-w-0 absolute inset-0"
1629
+ style={{
1630
+ padding: "0 0px 0 8px",
1631
+ ...shell(),
1632
+ }}
1633
+ >
1634
+ <Icon name="console" />
1635
+ <span class="truncate text-13-medium text-text-base">{language.t("prompt.mode.shell")}</span>
1636
+ <div class="flex-1" />
1637
+ <Button
1638
+ variant="ghost"
1639
+ class="text-text-base"
1640
+ onClick={() => {
1641
+ setStore("mode", "normal")
1642
+ }}
1643
+ >
1644
+ {language.t("common.cancel")}
1645
+ </Button>
1646
+ </div>
1647
+ <div class="flex items-center gap-1.5 min-w-0 flex-1 h-7">
1648
+ <Show when={!agentsLoading()}>
1649
+ <div
1650
+ data-component="prompt-agent-control"
1651
+ classList={{ "animate-in fade-in duration-300": agentsShouldFadeIn() }}
1652
+ >
1653
+ <TooltipKeybind
1654
+ placement="top"
1655
+ gutter={4}
1656
+ title={language.t("command.agent.cycle")}
1657
+ keybind={command.keybind("agent.cycle")}
1658
+ >
1659
+ <Select
1660
+ size="normal"
1661
+ options={props.controls.agents.options}
1662
+ current={props.controls.agents.current}
1663
+ onSelect={(value) => {
1664
+ props.controls.agents.select(value)
1665
+ restoreFocus()
1666
+ }}
1667
+ class="capitalize max-w-[160px] text-text-base"
1668
+ valueClass="truncate text-13-regular text-text-base"
1669
+ triggerStyle={control()}
1670
+ triggerProps={{ "data-action": "prompt-agent" }}
1671
+ variant="ghost"
1672
+ />
1673
+ </TooltipKeybind>
1674
+ </div>
1675
+ </Show>
1676
+ <Show when={!providersLoading()}>
1677
+ <Show when={store.mode !== "shell"}>
1678
+ <div
1679
+ data-component="prompt-model-control"
1680
+ classList={{ "animate-in fade-in duration-300": providersShouldFadeIn() }}
1681
+ >
1682
+ <Show
1683
+ when={props.controls.model.paid}
1684
+ fallback={
1685
+ <TooltipKeybind
1686
+ placement="top"
1687
+ gutter={4}
1688
+ title={language.t("command.model.choose")}
1689
+ keybind={command.keybind("model.choose")}
1690
+ >
1691
+ <Button
1692
+ data-action="prompt-model"
1693
+ as="div"
1694
+ variant="ghost"
1695
+ size="normal"
1696
+ class="min-w-0 max-w-[320px] text-13-regular text-text-base group"
1697
+ style={control()}
1698
+ onClick={() => {
1699
+ dialog.show(() => <DialogSelectModelUnpaid model={props.controls.model.selection} />)
1700
+ }}
1701
+ >
1702
+ <Show when={props.controls.model.selection.current()?.provider?.id}>
1703
+ <ProviderIcon
1704
+ id={props.controls.model.selection.current()?.provider?.id ?? ""}
1705
+ class="size-4 shrink-0 opacity-40 group-hover:opacity-100 transition-opacity duration-150"
1706
+ style={{ "will-change": "opacity", transform: "translateZ(0)" }}
1707
+ />
1708
+ </Show>
1709
+ <span class="truncate">
1710
+ {props.controls.model.selection.current()?.name ??
1711
+ language.t("dialog.model.select.title")}
1712
+ </span>
1713
+ <Icon name="chevron-down" size="small" class="shrink-0" />
1714
+ </Button>
1715
+ </TooltipKeybind>
1716
+ }
1717
+ >
1718
+ <TooltipKeybind
1719
+ placement="top"
1720
+ gutter={4}
1721
+ title={language.t("command.model.choose")}
1722
+ keybind={command.keybind("model.choose")}
1723
+ >
1724
+ <ModelSelectorPopover
1725
+ model={props.controls.model.selection}
1726
+ triggerAs={Button}
1727
+ triggerProps={{
1728
+ variant: "ghost",
1729
+ size: "normal",
1730
+ style: control(),
1731
+ class: "min-w-0 max-w-[320px] text-13-regular text-text-base group",
1732
+ "data-action": "prompt-model",
1733
+ }}
1734
+ onClose={restoreFocus}
1735
+ >
1736
+ <Show when={props.controls.model.selection.current()?.provider?.id}>
1737
+ <ProviderIcon
1738
+ id={props.controls.model.selection.current()?.provider?.id ?? ""}
1739
+ class="size-4 shrink-0 opacity-40 group-hover:opacity-100 transition-opacity duration-150"
1740
+ style={{ "will-change": "opacity", transform: "translateZ(0)" }}
1741
+ />
1742
+ </Show>
1743
+ <span class="truncate">
1744
+ {props.controls.model.selection.current()?.name ??
1745
+ language.t("dialog.model.select.title")}
1746
+ </span>
1747
+ <Icon name="chevron-down" size="small" class="shrink-0" />
1748
+ </ModelSelectorPopover>
1749
+ </TooltipKeybind>
1750
+ </Show>
1751
+ </div>
1752
+ <Show when={showVariantControl()}>
1753
+ <div
1754
+ data-component="prompt-variant-control"
1755
+ classList={{ "animate-in fade-in duration-300": providersShouldFadeIn() }}
1756
+ >
1757
+ <TooltipKeybind
1758
+ placement="top"
1759
+ gutter={4}
1760
+ title={language.t("command.model.variant.cycle")}
1761
+ keybind={command.keybind("model.variant.cycle")}
1762
+ >
1763
+ <Select
1764
+ size="normal"
1765
+ options={variants()}
1766
+ current={props.controls.model.selection.variant.current() ?? "default"}
1767
+ label={(x) => (x === "default" ? language.t("common.default") : x)}
1768
+ onSelect={(value) => {
1769
+ props.controls.model.selection.variant.set(value === "default" ? undefined : value)
1770
+ restoreFocus()
1771
+ }}
1772
+ class="capitalize max-w-[160px] text-text-base"
1773
+ valueClass="truncate text-13-regular text-text-base"
1774
+ triggerStyle={control()}
1775
+ triggerProps={{ "data-action": "prompt-model-variant" }}
1776
+ variant="ghost"
1777
+ />
1778
+ </TooltipKeybind>
1779
+ </div>
1780
+ </Show>
1781
+ </Show>
1782
+ </Show>
1783
+ </div>
1784
+ </div>
1785
+ </div>
1786
+ </DockTray>
1787
+ </Show>
1788
+ </div>
1789
+ )
1790
+ }