@kabmo-labs/kabmo 0.8.0 → 0.10.0

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 (391) hide show
  1. package/README.md +52 -0
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +336 -336
  4. package/dist/client/static/js/index-18xe7655.css +1 -0
  5. package/dist/client/static/js/{index-qwpvd9fv.js → index-nxpe7835.js} +933 -898
  6. package/package.json +11 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
  8. package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
  9. package/src/client/components/common/code-surface/documents.test.ts +122 -0
  10. package/src/client/components/common/code-surface/documents.ts +286 -0
  11. package/src/client/components/common/code-surface/extensions.test.ts +115 -0
  12. package/src/client/components/common/code-surface/extensions.ts +295 -0
  13. package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
  14. package/src/client/components/common/code-surface/fold.test.ts +148 -0
  15. package/src/client/components/common/code-surface/fold.ts +118 -0
  16. package/src/client/components/common/code-surface/handle.ts +102 -0
  17. package/src/client/components/common/code-surface/indent-guide.ts +104 -0
  18. package/src/client/components/common/code-surface/indent.test.ts +239 -0
  19. package/src/client/components/common/code-surface/indent.ts +124 -0
  20. package/src/client/components/common/code-surface/index.tsx +283 -314
  21. package/src/client/components/common/code-surface/keymap.test.ts +133 -0
  22. package/src/client/components/common/code-surface/keymap.ts +256 -0
  23. package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
  24. package/src/client/components/common/code-surface/line-commands.ts +103 -0
  25. package/src/client/components/common/code-surface/marks.ts +74 -0
  26. package/src/client/components/common/code-surface/props.ts +87 -0
  27. package/src/client/components/common/code-surface/shiki.ts +234 -0
  28. package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
  29. package/src/client/components/common/code-surface/stream-language.ts +123 -0
  30. package/src/client/components/common/code-surface/sync.test.ts +185 -0
  31. package/src/client/components/common/code-surface/sync.ts +58 -0
  32. package/src/client/components/common/code-surface/theme.test.ts +237 -0
  33. package/src/client/components/common/code-surface/theme.ts +224 -0
  34. package/src/client/components/common/code-surface/typing.test.ts +97 -0
  35. package/src/client/components/common/code-surface/typing.ts +111 -0
  36. package/src/client/components/common/editor-view-buttons/index.test.tsx +148 -0
  37. package/src/client/components/common/editor-view-buttons/index.tsx +109 -0
  38. package/src/client/components/common/shell-update-button/Modal.tsx +163 -0
  39. package/src/client/components/common/shell-update-button/index.test.tsx +251 -0
  40. package/src/client/components/common/shell-update-button/index.tsx +125 -0
  41. package/src/client/components/common/toolbar-row/index.test.tsx +215 -0
  42. package/src/client/components/common/toolbar-row/index.tsx +260 -0
  43. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +58 -78
  44. package/src/client/components/layout/desktop-layout/index.tsx +65 -67
  45. package/src/client/components/layout/desktop-layout/resizer/index.tsx +6 -3
  46. package/src/client/components/layout/session-sidebar/Footer.tsx +8 -15
  47. package/src/client/components/mobile/LayoutWrapper.tsx +1 -0
  48. package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +3 -0
  49. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +98 -71
  50. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
  51. package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.test.tsx +137 -0
  52. package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.tsx +14 -3
  53. package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
  54. package/src/client/components/mobile/mobile-session-sidebar/Footer.tsx +9 -21
  55. package/src/client/components/settings/Modal.tsx +8 -0
  56. package/src/client/components/settings/categories/AppearanceSettings.tsx +9 -0
  57. package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
  58. package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +167 -0
  59. package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +184 -0
  60. package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
  61. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +8 -2
  62. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +16 -8
  63. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +9 -4
  64. package/src/client/components/workspace/chat-timeline/TaskResultContent.tsx +9 -7
  65. package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
  66. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
  67. package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
  68. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +132 -0
  69. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +120 -0
  70. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.test.tsx +319 -0
  71. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +285 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -0
  73. package/src/client/components/workspace/chat-timeline/tool-renderers/hashline-patch/index.tsx +34 -29
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AstEdit.tsx +11 -9
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +10 -7
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +25 -8
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.tsx +8 -11
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.test.ts +114 -0
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.tsx +111 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +7 -7
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/SearchTool.tsx +9 -59
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactBody.tsx +2 -7
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +43 -30
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +49 -32
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ExcerptCode.tsx +8 -8
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/HighlightedCode.tsx +35 -0
  87. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock.tsx +4 -4
  88. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +179 -0
  89. package/src/client/components/workspace/diff-panel/ThemedMergeDiffView.tsx +24 -0
  90. package/src/client/components/workspace/diff-panel/Toolbar.tsx +224 -186
  91. package/src/client/components/workspace/diff-panel/ToolbarSegments.tsx +98 -0
  92. package/src/client/components/workspace/diff-panel/index.tsx +76 -145
  93. package/src/client/components/workspace/diff-panel/merge.ts +315 -0
  94. package/src/client/components/workspace/editor/Body.tsx +28 -7
  95. package/src/client/components/workspace/editor/CommandPalette.tsx +6 -6
  96. package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
  97. package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
  98. package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
  99. package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
  100. package/src/client/components/workspace/editor/FileDocument.tsx +146 -63
  101. package/src/client/components/workspace/editor/FilePane.tsx +47 -7
  102. package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
  103. package/src/client/components/workspace/editor/FindWidget.tsx +36 -2
  104. package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
  105. package/src/client/components/workspace/editor/Notices.tsx +71 -0
  106. package/src/client/components/workspace/editor/Pane.tsx +118 -0
  107. package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
  108. package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
  109. package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
  110. package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
  111. package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
  112. package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
  113. package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
  114. package/src/client/components/workspace/editor/Tabs.tsx +195 -18
  115. package/src/client/components/workspace/editor/Toolbar.tsx +110 -140
  116. package/src/client/components/workspace/editor/index.tsx +201 -193
  117. package/src/client/components/workspace/editor/props.ts +64 -0
  118. package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
  119. package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
  120. package/src/client/components/workspace/file-explorer/OutlineSection.test.tsx +18 -0
  121. package/src/client/components/workspace/file-explorer/OutlineSection.tsx +10 -3
  122. package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
  123. package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
  124. package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
  125. package/src/client/components/workspace/file-explorer/index.tsx +10 -48
  126. package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
  127. package/src/client/components/workspace/search-panel/Body.tsx +7 -2
  128. package/src/client/components/workspace/worktree-modal/index.test.tsx +118 -0
  129. package/src/client/hooks/chat/composer/file-drop.ts +22 -37
  130. package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
  131. package/src/client/hooks/chat/composer/pipeline.ts +12 -1
  132. package/src/client/hooks/chat/omp/reconnect.test.ts +338 -0
  133. package/src/client/hooks/chat/omp/reconnect.ts +187 -0
  134. package/src/client/hooks/chat/omp/run-liveness.test.ts +71 -0
  135. package/src/client/hooks/chat/omp/run-liveness.ts +65 -0
  136. package/src/client/hooks/chat/omp/session-list.activity.test.ts +114 -0
  137. package/src/client/hooks/chat/omp/session-list.test-util.ts +164 -0
  138. package/src/client/hooks/chat/omp/session-list.test.ts +30 -150
  139. package/src/client/hooks/chat/omp/session-list.tsx +69 -9
  140. package/src/client/hooks/chat/timeline/generating.ts +19 -2
  141. package/src/client/hooks/chat/timeline/index.ts +19 -24
  142. package/src/client/hooks/chat/timeline/lost-run.test.ts +329 -0
  143. package/src/client/hooks/chat/timeline/lost-run.ts +177 -0
  144. package/src/client/hooks/chat/timeline/session-load.test-util.ts +205 -0
  145. package/src/client/hooks/chat/timeline/session-load.test.ts +61 -162
  146. package/src/client/hooks/chat/timeline/session-load.ts +69 -37
  147. package/src/client/hooks/chat/timeline/session-switch.test.ts +65 -0
  148. package/src/client/hooks/chat/timeline/session-switch.ts +63 -0
  149. package/src/client/hooks/code/deferred-highlight.test.ts +182 -0
  150. package/src/client/hooks/code/deferred-highlight.ts +129 -0
  151. package/src/client/hooks/editor/caret-position.test.ts +58 -0
  152. package/src/client/hooks/editor/caret-position.ts +48 -0
  153. package/src/client/hooks/editor/file-editor-types.ts +200 -0
  154. package/src/client/hooks/editor/find-history.test.ts +132 -0
  155. package/src/client/hooks/editor/find-history.ts +46 -0
  156. package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
  157. package/src/client/hooks/editor/find-selection-range.ts +49 -0
  158. package/src/client/hooks/editor/find-state.ts +14 -1
  159. package/src/client/hooks/editor/font.test.ts +0 -93
  160. package/src/client/hooks/editor/indent-settings.test.ts +104 -0
  161. package/src/client/hooks/editor/indent-settings.ts +88 -0
  162. package/src/client/hooks/editor/quick-open.test.ts +141 -0
  163. package/src/client/hooks/editor/quick-open.ts +127 -0
  164. package/src/client/hooks/editor/save-as.test.ts +156 -0
  165. package/src/client/hooks/editor/save-as.ts +122 -0
  166. package/src/client/hooks/editor/save-file.test.ts +179 -0
  167. package/src/client/hooks/editor/save-file.ts +73 -28
  168. package/src/client/hooks/editor/theme.test.ts +206 -0
  169. package/src/client/hooks/editor/theme.ts +82 -0
  170. package/src/client/hooks/editor/typing-settings.test.ts +73 -0
  171. package/src/client/hooks/editor/typing-settings.ts +65 -0
  172. package/src/client/hooks/editor/use-close-guard.ts +98 -0
  173. package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
  174. package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
  175. package/src/client/hooks/editor/use-editor-drop.test.ts +101 -0
  176. package/src/client/hooks/editor/use-editor-drop.ts +120 -77
  177. package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
  178. package/src/client/hooks/editor/use-editor-find.ts +45 -10
  179. package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
  180. package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
  181. package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
  182. package/src/client/hooks/editor/use-external-change.test.ts +88 -0
  183. package/src/client/hooks/editor/use-external-change.ts +146 -0
  184. package/src/client/hooks/editor/use-file-editor.ts +83 -116
  185. package/src/client/hooks/editor/use-file-read.ts +16 -8
  186. package/src/client/hooks/editor/use-file-writes.ts +28 -3
  187. package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
  188. package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
  189. package/src/client/hooks/editor/use-outline-view.test.ts +182 -0
  190. package/src/client/hooks/editor/use-outline-view.ts +94 -7
  191. package/src/client/hooks/editor/use-scroll-restore.test.ts +55 -2
  192. package/src/client/hooks/editor/use-scroll-restore.ts +124 -4
  193. package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
  194. package/src/client/hooks/editor/use-search-reveal.ts +1 -1
  195. package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
  196. package/src/client/hooks/editor/use-split-editor.ts +91 -0
  197. package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
  198. package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
  199. package/src/client/hooks/editor/use-write-conflict.ts +152 -0
  200. package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
  201. package/src/client/hooks/editor/wheel-zoom.ts +96 -0
  202. package/src/client/hooks/ui/drag-presence.test.ts +193 -0
  203. package/src/client/hooks/ui/drag-presence.ts +108 -0
  204. package/src/client/hooks/ui/settings-modal.test.ts +115 -0
  205. package/src/client/hooks/ui/settings-modal.ts +56 -0
  206. package/src/client/hooks/ui/updates/shell-download.test.ts +2 -0
  207. package/src/client/hooks/ui/updates/shell-download.ts +55 -14
  208. package/src/client/hooks/ui/updates/shell-offer.test.ts +26 -0
  209. package/src/client/hooks/ui/updates/shell-update.test.ts +140 -0
  210. package/src/client/hooks/ui/updates/shell-update.ts +119 -0
  211. package/src/client/hooks/workspace/diff-file.ts +29 -10
  212. package/src/client/hooks/workspace/diff-git-actions.ts +147 -0
  213. package/src/client/hooks/workspace/editor-view.ts +61 -0
  214. package/src/client/hooks/workspace/file-listing.ts +36 -24
  215. package/src/client/hooks/workspace/file-tabs.test.ts +152 -5
  216. package/src/client/hooks/workspace/file-tabs.ts +70 -11
  217. package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
  218. package/src/client/hooks/workspace/navbar-session-actions.ts +72 -0
  219. package/src/client/hooks/workspace/worktree/index.ts +20 -5
  220. package/src/client/lib/desktop/bridge.ts +45 -0
  221. package/src/client/lib/desktop/dropped-paths.ts +83 -0
  222. package/src/client/lib/editor/tab-menu.test.ts +127 -0
  223. package/src/client/lib/editor/tab-menu.ts +127 -0
  224. package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
  225. package/src/client/lib/editor-dirty-tabs.ts +103 -0
  226. package/src/client/lib/native/resume.test.ts +66 -0
  227. package/src/client/lib/native/resume.ts +42 -0
  228. package/src/client/lib/search-reveal.ts +1 -1
  229. package/src/client/main.tsx +13 -1
  230. package/src/client/tailwind.css +75 -8
  231. package/src/server/lib/auth/guard.test.ts +28 -0
  232. package/src/server/lib/auth/guard.ts +10 -0
  233. package/src/server/lib/bundler/css.test.ts +31 -0
  234. package/src/server/lib/fs/listing.test.ts +81 -16
  235. package/src/server/lib/fs/listing.ts +72 -5
  236. package/src/server/lib/fs/worktree/create.ts +2 -3
  237. package/src/server/lib/fs/worktree/list.ts +13 -0
  238. package/src/server/lib/fs/worktree/remove.ts +3 -3
  239. package/src/server/lib/fs/write-conflict.test.ts +68 -0
  240. package/src/server/lib/fs/write-conflict.ts +84 -0
  241. package/src/server/lib/lifecycle/claim-port.test.ts +156 -0
  242. package/src/server/lib/lifecycle/port-guard.test.ts +20 -164
  243. package/src/server/lib/lifecycle/port-guard.ts +39 -7
  244. package/src/server/lib/lifecycle/probe-health.test.ts +166 -0
  245. package/src/server/lib/lifecycle/probe.test.ts +77 -164
  246. package/src/server/lib/lifecycle/probe.ts +121 -13
  247. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +112 -0
  248. package/src/server/lib/omp/rpc/frame-fold.ts +10 -5
  249. package/src/server/lib/omp/session/sidebar-activity.server.test.ts +162 -0
  250. package/src/server/lib/omp/session/sidebar-activity.server.ts +70 -0
  251. package/src/server/lib/omp/session/telemetry/compute.ts +13 -1
  252. package/src/server/lib/omp/session/telemetry.test.ts +33 -0
  253. package/src/server/lib/realtime/signals.server.ts +10 -0
  254. package/src/server/lib/realtime/topics/catalog.server.ts +4 -1
  255. package/src/server/lib/realtime/topics.server.ts +16 -0
  256. package/src/server/lib/updates/shell-assets.ts +94 -3
  257. package/src/server/lib/updates/shell-cache.ts +105 -0
  258. package/src/server/lib/updates/shell-pages.test.ts +33 -2
  259. package/src/server/lib/updates/shell-pages.ts +17 -5
  260. package/src/server/lib/updates/shell-release-desktop.test.ts +166 -0
  261. package/src/server/lib/updates/shell-release.test.ts +10 -27
  262. package/src/server/lib/updates/shell-release.ts +107 -111
  263. package/src/server/routes/fs/action-save-as.test.ts +82 -0
  264. package/src/server/routes/fs/action.test.ts +82 -0
  265. package/src/server/routes/fs/action.ts +54 -1
  266. package/src/server/routes/fs/exists.ts +11 -1
  267. package/src/server/routes/fs/git-merge.test.ts +11 -1
  268. package/src/server/routes/fs/read.test.ts +24 -7
  269. package/src/server/routes/fs/read.ts +6 -1
  270. package/src/server/routes/fs/scope.test.ts +15 -10
  271. package/src/server/routes/fs/scope.ts +3 -14
  272. package/src/server/routes/updates/android.ts +6 -1
  273. package/src/server/routes/updates/desktop.ts +29 -7
  274. package/src/server/routes/updates/ios.ts +5 -1
  275. package/src/server/routes/worktrees/list.ts +11 -1
  276. package/src/server/routes/worktrees/routes.test.ts +17 -0
  277. package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +36 -0
  278. package/src/shared/lib/chat/timeline/omp-callbacks.ts +18 -0
  279. package/src/shared/lib/chat/timeline/run-signals.test.ts +2 -0
  280. package/src/shared/lib/code/editor/comment-syntax.test.ts +37 -0
  281. package/src/shared/lib/code/editor/comment-syntax.ts +55 -0
  282. package/src/shared/lib/code/editor/find-replace.test.ts +134 -0
  283. package/src/shared/lib/code/editor/{find.ts → find-replace.ts} +23 -107
  284. package/src/shared/lib/code/editor/{find.test.ts → find-scan.test.ts} +20 -74
  285. package/src/shared/lib/code/editor/find-scan.ts +198 -0
  286. package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
  287. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
  288. package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
  289. package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
  290. package/src/shared/lib/code/editor/indent-rules.ts +198 -0
  291. package/src/shared/lib/code/editor/keymap.test.ts +23 -0
  292. package/src/shared/lib/code/editor/keymap.ts +43 -6
  293. package/src/shared/lib/code/editor/lines.test.ts +7 -55
  294. package/src/shared/lib/code/editor/lines.ts +8 -48
  295. package/src/shared/lib/code/editor/marks.test.ts +4 -5
  296. package/src/shared/lib/code/editor/marks.ts +13 -25
  297. package/src/shared/lib/code/editor/palette.test.ts +25 -2
  298. package/src/shared/lib/code/editor/palette.ts +10 -0
  299. package/src/shared/lib/code/editor/stream-modes.ts +225 -0
  300. package/src/shared/lib/code/editor/theme-loader.ts +97 -0
  301. package/src/shared/lib/code/editor/themes.generated.ts +156 -0
  302. package/src/shared/lib/code/editor/themes.test.ts +165 -0
  303. package/src/shared/lib/code/editor/themes.ts +165 -0
  304. package/src/shared/lib/code/highlight-memo.test.ts +103 -0
  305. package/src/shared/lib/code/highlight-memo.ts +149 -0
  306. package/src/shared/lib/code/highlighter-warmup.ts +112 -0
  307. package/src/shared/lib/code/highlighter.ts +3 -1
  308. package/src/shared/lib/code/idle.ts +37 -0
  309. package/src/shared/lib/code/outline/rows.test.ts +96 -0
  310. package/src/shared/lib/code/outline/rows.ts +94 -0
  311. package/src/shared/lib/code/syntax-highlight.test.ts +2 -80
  312. package/src/shared/lib/code/syntax-highlight.ts +2 -3
  313. package/src/shared/lib/fs/file-kind-classify.test.ts +25 -11
  314. package/src/shared/lib/fs/file-kind.ts +47 -13
  315. package/src/shared/lib/fs/file-tree.test.ts +41 -0
  316. package/src/shared/lib/fs/file-tree.ts +126 -34
  317. package/src/shared/lib/fs/file-url.test.ts +52 -0
  318. package/src/shared/lib/fs/file-url.ts +37 -0
  319. package/src/shared/lib/fs/folder-chain.test.ts +87 -0
  320. package/src/shared/lib/fs/folder-chain.ts +91 -0
  321. package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
  322. package/src/shared/lib/fs/patch-sides.test.ts +114 -0
  323. package/src/shared/lib/fs/patch-sides.ts +139 -0
  324. package/src/shared/lib/realtime/connection.test.ts +5 -1
  325. package/src/shared/lib/realtime/connection.ts +25 -119
  326. package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
  327. package/src/shared/lib/realtime/protocol.ts +16 -0
  328. package/src/shared/lib/realtime/resume.ts +223 -0
  329. package/src/shared/lib/realtime/state.ts +22 -0
  330. package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
  331. package/src/shared/lib/realtime/watchdog.test.ts +99 -0
  332. package/src/shared/lib/realtime/watchdog.ts +72 -0
  333. package/src/shared/lib/ui/toolbar-overflow.test.ts +83 -0
  334. package/src/shared/lib/ui/toolbar-overflow.ts +86 -0
  335. package/src/shared/lib/updates/shell-arch.ts +54 -0
  336. package/src/shared/lib/updates/shell-ua.ts +4 -4
  337. package/src/shared/lib/workspace/editor-view-mode.test.ts +70 -0
  338. package/src/shared/lib/workspace/editor-view-mode.ts +48 -0
  339. package/src/shared/lib/workspace/panel-widths.test.ts +30 -0
  340. package/src/shared/lib/workspace/panel-widths.ts +25 -5
  341. package/src/shared/lib/workspace/session-state/cache.ts +159 -0
  342. package/src/shared/lib/workspace/session-state/harness.test-util.ts +55 -0
  343. package/src/shared/lib/workspace/session-state/merge.ts +100 -0
  344. package/src/shared/lib/workspace/session-state/store-load.test.ts +206 -0
  345. package/src/shared/lib/workspace/session-state/store.test.ts +17 -139
  346. package/src/shared/lib/workspace/session-state/store.ts +92 -130
  347. package/src/shared/lib/workspace/split-editor.test.ts +104 -0
  348. package/src/shared/lib/workspace/split-editor.ts +129 -0
  349. package/src/shared/lib/workspace/workspace-panel-widths.ts +124 -0
  350. package/src/shared/types/realtime.ts +29 -0
  351. package/src/shared/types/settings/state.ts +10 -0
  352. package/src/test-support/file-explorer-disk.test-util.ts +30 -3
  353. package/src/test-support/loopback.ts +183 -0
  354. package/src/test-support/pristine-globals.ts +7 -0
  355. package/dist/client/static/js/index-gtbpewr7.css +0 -1
  356. package/src/client/components/common/code-editor/handler.test.ts +0 -274
  357. package/src/client/components/common/code-editor/handler.ts +0 -175
  358. package/src/client/components/common/code-editor/index.tsx +0 -314
  359. package/src/client/components/common/code-surface/measure.ts +0 -148
  360. package/src/client/components/workspace/chat-timeline/target-picker/index.test.tsx +0 -227
  361. package/src/client/components/workspace/chat-timeline/target-picker/index.tsx +0 -260
  362. package/src/client/components/workspace/diff-panel/SplitView.tsx +0 -209
  363. package/src/client/components/workspace/diff-panel/UnifiedView.tsx +0 -150
  364. package/src/client/hooks/editor/scroll-container.test.ts +0 -102
  365. package/src/client/hooks/editor/scroll-container.ts +0 -26
  366. package/src/client/hooks/editor/use-code-window.ts +0 -100
  367. package/src/client/hooks/editor/use-editor-history.test.ts +0 -216
  368. package/src/client/hooks/editor/use-editor-history.ts +0 -134
  369. package/src/client/hooks/editor/use-occurrences.test.ts +0 -236
  370. package/src/client/hooks/editor/use-occurrences.ts +0 -98
  371. package/src/shared/lib/code/editor/commands.test.ts +0 -155
  372. package/src/shared/lib/code/editor/commands.ts +0 -260
  373. package/src/shared/lib/code/editor/edits.test.ts +0 -100
  374. package/src/shared/lib/code/editor/edits.ts +0 -122
  375. package/src/shared/lib/code/editor/history.test.ts +0 -118
  376. package/src/shared/lib/code/editor/history.ts +0 -101
  377. package/src/shared/lib/code/editor/layers.test.ts +0 -77
  378. package/src/shared/lib/code/editor/layers.ts +0 -67
  379. package/src/shared/lib/code/editor/line-edits.test.ts +0 -131
  380. package/src/shared/lib/code/editor/line-edits.ts +0 -159
  381. package/src/shared/lib/code/editor/occurrences.test.ts +0 -117
  382. package/src/shared/lib/code/editor/occurrences.ts +0 -111
  383. package/src/shared/lib/code/editor/reset-css.test.ts +0 -35
  384. package/src/shared/lib/code/editor/reset-css.ts +0 -32
  385. package/src/shared/lib/code/editor/text-commands.test.ts +0 -178
  386. package/src/shared/lib/code/editor/text-commands.ts +0 -154
  387. package/src/shared/lib/code/lazy-window.test.ts +0 -161
  388. package/src/shared/lib/code/lazy-window.ts +0 -156
  389. package/src/shared/lib/code/windowed-highlight.ts +0 -114
  390. package/src/shared/lib/fs/diff-parser.test.ts +0 -116
  391. package/src/shared/lib/fs/diff-parser.ts +0 -213
@@ -0,0 +1,200 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The file-editing contract's own types.
8
+ *
9
+ * Split out of `use-file-editor.ts` for the repository's per-file ceiling, and they
10
+ * belong here anyway: the phone's full-screen editor, the desktop pane and the
11
+ * write path all name these, and importing a type from a hook module couples them
12
+ * to an implementation file.
13
+ */
14
+
15
+ export type FileEditorSaveStatus = 'idle' | 'saving' | 'saved' | 'error' | 'needs-permission';
16
+
17
+ import type { ViewerKind } from '@/shared/lib/fs/document-kind';
18
+ import type { LineEnding } from '@/shared/lib/code/line-endings';
19
+ import type { ByteSource } from '@/client/components/workspace/editor/viewers/bytes';
20
+
21
+ /** The single file a code surface is editing; `id` keys the in-memory cache. */
22
+ export interface FileEditorTarget {
23
+ id?: number | string;
24
+ name: string;
25
+ path?: string;
26
+ content?: string;
27
+ root?: string;
28
+ repo?: string;
29
+ /** The live handle a PWA launch opened this file through, when there is one. */
30
+ handleId?: string;
31
+ }
32
+
33
+ export interface UseFileEditorOptions {
34
+ /** Flush a pending debounced write on unmount so closing the editor cannot drop an edit. */
35
+ flushOnUnmount?: boolean;
36
+ /** Mark a failed write as `'error'`; otherwise the status returns to `'idle'`. */
37
+ reportSaveError?: boolean;
38
+ /** Blob MIME type for downloads. */
39
+ downloadMimeType?: string;
40
+ /** Fired after a write lands, so workspace panels can refresh. */
41
+ onFileSaved?: () => void;
42
+ /**
43
+ * The file this tab names is gone from disk (the tab strip strikes it
44
+ * through; see `useMissingFiles`).
45
+ *
46
+ * A save then means something the user did not ask for — writing the buffer
47
+ * back would CREATE the file again — so the debounced autosave stands down
48
+ * and an explicit Save asks first. Without this, a keystroke in a tab whose
49
+ * file was deleted a moment ago silently resurrected it on disk.
50
+ */
51
+ missing?: boolean;
52
+ }
53
+
54
+ export interface UseFileEditorResult {
55
+ content: string;
56
+ onChange: (next: string) => void;
57
+ isLoading: boolean;
58
+ /**
59
+ * The current file's bytes have arrived (or it is an image / carries inline
60
+ * content). Distinguishes "the buffer is empty" from "the buffer is not read
61
+ * yet" — `isLoading` cannot, because it starts `false` on the first render and
62
+ * a consumer that trusted it would act on an empty buffer.
63
+ */
64
+ loaded: boolean;
65
+ loadError: string | null;
66
+ /**
67
+ * The server refused this file as a document (binary, or larger than the
68
+ * editor opens), with its own sentence. Distinct from `loadError` only in
69
+ * WORDING — both leave an empty buffer and disable Save — but the difference
70
+ * is what the user needs: a zip was read fine and is simply not text.
71
+ */
72
+ unsupported: string | null;
73
+ saveStatus: FileEditorSaveStatus;
74
+ copied: boolean;
75
+ isDirty: boolean;
76
+ /**
77
+ * The ACTIVE buffer's own line ending, which the next save restores.
78
+ *
79
+ * Detected from the bytes on read, never from a setting: a CRLF file must stay
80
+ * CRLF, and the buffer itself is LF-only so this is the only place the style
81
+ * survives.
82
+ */
83
+ eol: LineEnding;
84
+ /**
85
+ * Change the ending the NEXT save writes.
86
+ *
87
+ * A UI over an existing capability: the write path has always carried `eol` (a
88
+ * multipart body normalizes bare LF, so the ending cannot ride in the payload). What
89
+ * was missing was a way to CHOOSE it — a file that arrived as CRLF stayed CRLF and
90
+ * one that arrived as LF stayed LF, with no way to convert either.
91
+ */
92
+ setEol: (eol: LineEnding) => void;
93
+ /**
94
+ * The mtime the ACTIVE buffer was read at, or null when it has none (an inline
95
+ * attachment, a handle-backed file, a read that failed).
96
+ *
97
+ * The conflict guard sends it as `baseMtime` and the change watcher compares the
98
+ * disk against it.
99
+ */
100
+ baseMtimeMs: number | null;
101
+ /**
102
+ * EVERY cached buffer holding edits that are not on disk — not just the active
103
+ * one.
104
+ *
105
+ * `isDirty` answers for the tab on screen, which is all a single hook can see;
106
+ * the tab strip needs the answer for the tab the user is about to CLOSE, and a
107
+ * background buffer is exactly what `isDirty` cannot describe. Keys are the
108
+ * buffer keys, which for an opened tab is `String(tab.id)`.
109
+ */
110
+ dirtyKeys: ReadonlySet<string>;
111
+ language: string;
112
+ /**
113
+ * A handle-backed tab whose live handle is gone — the page reloaded since the
114
+ * file was launched, and a `FileSystemFileHandle` cannot be persisted. Save
115
+ * is refused (there is nothing to write through), so the surface says why
116
+ * instead of showing a button that silently fails.
117
+ */
118
+ handleMissing: boolean;
119
+ /** True for raster images: the surface renders `imageUrl`, not `content`. */
120
+ isImage: boolean;
121
+ /** Raw-byte URL of the active image (cache-busted per revision), else null. */
122
+ imageUrl: string | null;
123
+ /**
124
+ * Which surface draws this file (see `shared/lib/fs/document-kind`). The pane
125
+ * dispatches on it, and `isImage` is now one case of it rather than its own
126
+ * axis.
127
+ */
128
+ viewerKind: ViewerKind;
129
+ /**
130
+ * The bytes a byte-drawing viewer reads, from the tab's path or its live
131
+ * handle. `loadBytes` is null for a text viewer and for an inline attachment
132
+ * (nothing to fetch); `url` is additionally null when the file came from a
133
+ * handle rather than a workspace path.
134
+ */
135
+ byteSource: ByteSource;
136
+ /**
137
+ * True for the viewers that read BYTES rather than the text buffer (image,
138
+ * PDF, DOCX, workbook). Their read path is skipped and their writes refused,
139
+ * because a byte surface has no buffer to save.
140
+ */
141
+ isBinaryViewer: boolean;
142
+ /**
143
+ * Bumped by `reset()` (a workspace refresh). A byte viewer that fetches its
144
+ * own bytes has no read effect to re-run, so it takes this as its re-read
145
+ * lever; the text path already re-reads through `useFileRead`.
146
+ */
147
+ revision: number;
148
+ saveNow: () => void;
149
+ copy: () => void;
150
+ download: () => void;
151
+ /**
152
+ * Re-read every cached file from disk (e.g. a workspace refresh). Content
153
+ * already on screen stays until the fresh bytes land, and a file with
154
+ * unsaved edits is left alone.
155
+ */
156
+ reset: () => void;
157
+ /** Drop cached content for files no longer open. */
158
+ retain: (ids: Array<number | string>) => void;
159
+ /** The file was deleted, so a Save is waiting on the user's answer. */
160
+ saveMissingConfirm: boolean;
161
+ /** Write the buffer anyway — this recreates the file on disk. */
162
+ confirmSaveMissing: () => void;
163
+ /** Dismiss the dialog; nothing is written and the buffer stays dirty. */
164
+ cancelSaveMissing: () => void;
165
+ /**
166
+ * The disk copy moved since this buffer was read, so the last write was refused.
167
+ *
168
+ * `null` for the active file means there is no conflict to report. The panel
169
+ * offers two answers — reload the disk copy, or write over it — because
170
+ * reporting it as a failed save would leave the user with no way forward.
171
+ */
172
+ conflict: { diskMtimeMs: number | null } | null;
173
+ /** Take the disk copy, discarding the buffer's edits. */
174
+ resolveConflictByReload: () => void;
175
+ /**
176
+ * Write the buffer anyway, adopting the disk mtime as the new base.
177
+ *
178
+ * This is the "Keep mine" answer: the user has seen that the disk moved and
179
+ * chosen their buffer over it.
180
+ */
181
+ resolveConflictByKeepingMine: () => void;
182
+ /**
183
+ * Throw the buffer away and take the file from disk.
184
+ *
185
+ * The user-facing Revert. Distinct from `reset()` (a workspace refresh, which
186
+ * deliberately KEEPS a dirty buffer) and from `resolveConflictByReload` only in
187
+ * that it needs no conflict to exist — the reason to revert is usually that the
188
+ * user wants the disk copy back, not that anyone else wrote it.
189
+ */
190
+ revertToDisk: () => void;
191
+ /**
192
+ * Adopt the disk's mtime as this buffer's base WITHOUT writing anything.
193
+ *
194
+ * The answer to an external-change notice when the user wants to keep editing:
195
+ * their next save must not be refused with a `409` over a change they have
196
+ * already been shown and accepted. Nothing is written here — the buffer stays
197
+ * dirty and the autosave owns the write.
198
+ */
199
+ adoptDiskMtime: (diskMtimeMs: number) => void;
200
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The find bar's recent queries.
8
+ *
9
+ * Newest first, no duplicates, bounded — and only queries that were actually USED, which
10
+ * is why `remember` is called from the bar's close rather than from every keystroke. A
11
+ * half-written regex that never ran is noise in a list whose value is that each entry is
12
+ * something you searched for.
13
+ */
14
+
15
+ import { afterAll, afterEach, describe, expect, test } from 'bun:test';
16
+ import { Window } from 'happy-dom';
17
+ import { h, render } from 'preact';
18
+ import { act } from 'preact/test-utils';
19
+
20
+ import { FIND_HISTORY_LIMIT, useFindHistory, type FindHistory } from '@/client/hooks/editor/find-history';
21
+ import { forgetSession } from '@/shared/lib/workspace/session-state/store';
22
+ import type { ComponentChildren } from 'preact';
23
+ import type { ComponentType } from 'preact/compat';
24
+
25
+ const SESSION = 'find-history-test';
26
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'CustomEvent'] as const;
27
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
28
+ const win = new Window({ url: 'http://localhost' });
29
+ for (const key of DOM_GLOBALS) {
30
+ const target = globalThis as unknown as Record<string, unknown>;
31
+ native[key] = target[key];
32
+ target[key] = (win as unknown as Record<string, unknown>)[key];
33
+ }
34
+
35
+ afterAll(() => {
36
+ const target = globalThis as unknown as Record<string, unknown>;
37
+ for (const key of DOM_GLOBALS) target[key] = native[key];
38
+ });
39
+
40
+ afterEach(() => {
41
+ forgetSession(SESSION);
42
+ });
43
+
44
+ /**
45
+ * Mounted through the REAL session-state provider: `useFindHistory` persists through
46
+ * `useSessionState`, and a local stub would not exercise the store the history actually
47
+ * lives in.
48
+ */
49
+ let SessionStateProvider: ComponentType<{ sessionId: string; children: ComponentChildren }>;
50
+
51
+ async function mount(): Promise<{ api: () => FindHistory; unmount: () => void }> {
52
+ globalThis.fetch = (async () => ({
53
+ ok: true,
54
+ json: async () => ({ sessionId: SESSION, state: {} }),
55
+ text: async () => JSON.stringify({ sessionId: SESSION, state: {} }),
56
+ })) as unknown as typeof fetch;
57
+ const provider = await import('@/client/components/common/session-state-provider/index');
58
+ SessionStateProvider = provider.SessionStateProvider as typeof SessionStateProvider;
59
+
60
+ let slot: FindHistory | null = null;
61
+ function Probe() {
62
+ slot = useFindHistory();
63
+ return null;
64
+ }
65
+ const host = document.createElement('div');
66
+ document.body.appendChild(host);
67
+ await act(async () => {
68
+ render(h(SessionStateProvider, { sessionId: SESSION, children: h(Probe, {}) }), host);
69
+ });
70
+ for (let turn = 0; turn < 12; turn++) {
71
+ await act(async () => { for (let inner = 0; inner < 8; inner++) await Promise.resolve(); });
72
+ }
73
+ return {
74
+ api: () => {
75
+ if (!slot) throw new Error('not mounted');
76
+ return slot;
77
+ },
78
+ unmount: () => render(null, host),
79
+ };
80
+ }
81
+
82
+ describe('useFindHistory', () => {
83
+ test('starts empty', async () => {
84
+ const { api, unmount } = await mount();
85
+ expect(api().entries).toEqual([]);
86
+ unmount();
87
+ });
88
+
89
+ test('records newest first', async () => {
90
+ const { api, unmount } = await mount();
91
+ act(() => api().remember('alpha'));
92
+ act(() => api().remember('beta'));
93
+ expect(api().entries).toEqual(['beta', 'alpha']);
94
+ unmount();
95
+ });
96
+
97
+ test('re-searching an entry moves it to the front instead of duplicating it', async () => {
98
+ const { api, unmount } = await mount();
99
+ act(() => api().remember('alpha'));
100
+ act(() => api().remember('beta'));
101
+ act(() => api().remember('alpha'));
102
+ expect(api().entries).toEqual(['alpha', 'beta']);
103
+ unmount();
104
+ });
105
+
106
+ test('an empty or whitespace query is not recorded', async () => {
107
+ const { api, unmount } = await mount();
108
+ act(() => api().remember(' '));
109
+ act(() => api().remember(''));
110
+ expect(api().entries).toEqual([]);
111
+ unmount();
112
+ });
113
+
114
+ test('trims before comparing, so " alpha " and "alpha" are one entry', async () => {
115
+ const { api, unmount } = await mount();
116
+ act(() => api().remember(' alpha '));
117
+ act(() => api().remember('alpha'));
118
+ expect(api().entries).toEqual(['alpha']);
119
+ unmount();
120
+ });
121
+
122
+ test('is bounded, dropping the oldest', async () => {
123
+ const { api, unmount } = await mount();
124
+ for (let index = 0; index < FIND_HISTORY_LIMIT + 5; index++) {
125
+ act(() => api().remember(`query-${index}`));
126
+ }
127
+ expect(api().entries).toHaveLength(FIND_HISTORY_LIMIT);
128
+ expect(api().entries[0]).toBe(`query-${FIND_HISTORY_LIMIT + 4}`);
129
+ expect(api().entries).not.toContain('query-0');
130
+ unmount();
131
+ });
132
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The find bar's recent queries.
8
+ *
9
+ * Persisted per session like the query itself — a reload should not forget the string
10
+ * you were hunting for — and bounded, because a long editing session would otherwise
11
+ * keep every search it ever ran.
12
+ *
13
+ * A query is remembered when it was actually USED (the bar closing, or a history entry
14
+ * being picked again), not when it was typed: a half-written regex that never ran is
15
+ * noise in a list whose whole value is that each entry is something you searched for.
16
+ */
17
+
18
+ import { useCallback } from 'preact/hooks';
19
+
20
+ import { useSessionState } from '@/client/hooks/workspace/session-state';
21
+
22
+ /** How many recent queries the bar remembers. */
23
+ export const FIND_HISTORY_LIMIT = 20;
24
+
25
+ export interface FindHistory {
26
+ entries: readonly string[];
27
+ /** Record a query as the most recent, without duplicating it. */
28
+ remember: (query: string) => void;
29
+ }
30
+
31
+ export function useFindHistory(): FindHistory {
32
+ const [entries, setEntries] = useSessionState<string[]>('editor.findHistory', []);
33
+
34
+ const remember = useCallback(
35
+ (query: string) => {
36
+ const trimmed = query.trim();
37
+ if (!trimmed) return;
38
+ setEntries((previous) =>
39
+ [trimmed, ...previous.filter((entry) => entry !== trimmed)].slice(0, FIND_HISTORY_LIMIT),
40
+ );
41
+ },
42
+ [setEntries],
43
+ );
44
+
45
+ return { entries, remember };
46
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The range an "in selection" search is restricted to.
8
+ *
9
+ * The rule is capture-on-arm: a range the user then MOVES must not change what is being
10
+ * searched, because the toggle says "the text I had selected". Arming with nothing selected
11
+ * answers false, so the caller can refuse to turn the toggle on rather than promise a
12
+ * restriction it cannot apply.
13
+ */
14
+
15
+ import { afterAll, describe, expect, test } from 'bun:test';
16
+ import { Window } from 'happy-dom';
17
+ import { h, render } from 'preact';
18
+ import { act } from 'preact/test-utils';
19
+
20
+ import { useSelectionRange, type FindSelectionRange } from '@/client/hooks/editor/find-selection-range';
21
+
22
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event'] as const;
23
+ const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
24
+ const win = new Window({ url: 'http://localhost' });
25
+ for (const key of DOM_GLOBALS) {
26
+ const target = globalThis as unknown as Record<string, unknown>;
27
+ native[key] = target[key];
28
+ target[key] = (win as unknown as Record<string, unknown>)[key];
29
+ }
30
+
31
+ afterAll(() => {
32
+ const target = globalThis as unknown as Record<string, unknown>;
33
+ for (const key of DOM_GLOBALS) target[key] = native[key];
34
+ });
35
+
36
+ function mount(): { api: () => FindSelectionRange; unmount: () => void } {
37
+ let slot: FindSelectionRange | null = null;
38
+ function Probe() {
39
+ slot = useSelectionRange();
40
+ return null;
41
+ }
42
+ const host = document.createElement('div');
43
+ render(h(Probe, {}), host);
44
+ return {
45
+ api: () => {
46
+ if (!slot) throw new Error('not mounted');
47
+ return slot;
48
+ },
49
+ unmount: () => render(null, host),
50
+ };
51
+ }
52
+
53
+ describe('useSelectionRange', () => {
54
+ test('starts with no range', () => {
55
+ const { api, unmount } = mount();
56
+ expect(api().range).toBeNull();
57
+ unmount();
58
+ });
59
+
60
+ test('arming captures the selection it was given', () => {
61
+ const { api, unmount } = mount();
62
+ let armed = false;
63
+ act(() => { armed = api().arm(() => ({ start: 4, end: 9 })); });
64
+ expect(armed).toBe(true);
65
+ expect(api().range).toEqual({ start: 4, end: 9 });
66
+ unmount();
67
+ });
68
+
69
+ test('a range that MOVES afterwards does not change the captured one', () => {
70
+ const { api, unmount } = mount();
71
+ let selection = { start: 4, end: 9 };
72
+ act(() => { api().arm(() => selection); });
73
+ // The user drags a new selection; the armed range must not follow it.
74
+ selection = { start: 20, end: 30 };
75
+ expect(api().range).toEqual({ start: 4, end: 9 });
76
+ unmount();
77
+ });
78
+
79
+ test('arming with nothing selected answers false and leaves no range', () => {
80
+ const { api, unmount } = mount();
81
+ let armed = true;
82
+ act(() => { armed = api().arm(() => ({ start: 5, end: 5 })); });
83
+ expect(armed).toBe(false);
84
+ expect(api().range).toBeNull();
85
+ act(() => { armed = api().arm(() => null); });
86
+ expect(armed).toBe(false);
87
+ expect(api().range).toBeNull();
88
+ unmount();
89
+ });
90
+
91
+ test('disarming drops the range, so a later arm takes the THEN-current selection', () => {
92
+ const { api, unmount } = mount();
93
+ act(() => { api().arm(() => ({ start: 1, end: 3 })); });
94
+ act(() => api().disarm());
95
+ expect(api().range).toBeNull();
96
+ act(() => { api().arm(() => ({ start: 7, end: 9 })); });
97
+ expect(api().range).toEqual({ start: 7, end: 9 });
98
+ unmount();
99
+ });
100
+ });
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The range an "in selection" search is restricted to.
8
+ *
9
+ * Captured when the toggle is ARMED, never read live: a range the user then moves would
10
+ * silently change what is searched, which is the opposite of what the toggle says it
11
+ * does. Disarming drops it, so a later arm takes whatever is selected THEN rather than
12
+ * a stale range.
13
+ *
14
+ * `arm` answers false when nothing is selected — a toggle that promised "the selection"
15
+ * and searched the whole document instead would be a lie about the count.
16
+ */
17
+
18
+ import { useCallback, useState } from 'preact/hooks';
19
+
20
+ export interface SelectionRange {
21
+ start: number;
22
+ end: number;
23
+ }
24
+
25
+ export interface FindSelectionRange {
26
+ /** The captured range, or null while the toggle is off. */
27
+ range: SelectionRange | null;
28
+ /** Capture `readSelection()`; false when there is nothing selected to capture. */
29
+ arm: (readSelection: () => SelectionRange | null) => boolean;
30
+ disarm: () => void;
31
+ }
32
+
33
+ export function useSelectionRange(): FindSelectionRange {
34
+ const [range, setRange] = useState<SelectionRange | null>(null);
35
+
36
+ const arm = useCallback((readSelection: () => SelectionRange | null) => {
37
+ const selection = readSelection();
38
+ if (!selection || selection.start === selection.end) {
39
+ setRange(null);
40
+ return false;
41
+ }
42
+ setRange(selection);
43
+ return true;
44
+ }, []);
45
+
46
+ const disarm = useCallback(() => setRange(null), []);
47
+
48
+ return { range, arm, disarm };
49
+ }
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  import type { EditorCommand } from '@/shared/lib/code/editor/keymap';
17
- import type { FindOptions } from '@/shared/lib/code/editor/find';
17
+ import type { FindOptions } from '@/shared/lib/code/editor/find-scan';
18
18
 
19
19
  export interface UseEditorFindOptions {
20
20
  /** The buffer on screen. */
@@ -61,7 +61,20 @@ export interface EditorFindState {
61
61
  * lines it is showing.
62
62
  */
63
63
  revealMatch: (request: { query: string; options: FindOptions; line: number }) => void;
64
+ /**
65
+ * Flip one option.
66
+ *
67
+ * `inSelection` is armed from the CURRENT selection at the moment it is switched on,
68
+ * and the range is remembered: a range that the user then moves must not silently
69
+ * change what is being searched.
70
+ */
64
71
  toggleOption: (key: keyof FindOptions) => void;
72
+ /** The range an "in selection" search is restricted to, or null when it is off. */
73
+ selectionRange: { start: number; end: number } | null;
74
+ /** The last `FIND_HISTORY_LIMIT` queries, newest first. */
75
+ history: readonly string[];
76
+ /** Re-run a query from the history and step to its first match. */
77
+ useHistoryEntry: (query: string) => void;
65
78
  step: (direction: 1 | -1) => void;
66
79
  replaceCurrent: () => void;
67
80
  replaceAll: () => void;
@@ -32,7 +32,6 @@ import {
32
32
  useEditorFontStack,
33
33
  } from '@/client/hooks/editor/font';
34
34
  import { copyImageToClipboard, downloadUrl, saveBlob } from '@/client/hooks/editor/file-actions';
35
- import { retainKeys, saveEditorFile } from '@/client/hooks/editor/save-file';
36
35
  import { EDITOR_DEFAULT_FONT_FAMILY, EDITOR_FONT_FAMILY } from '@/shared/lib/code/editor/typography';
37
36
  import { primeKabmoSettings } from '@/shared/lib/settings/client';
38
37
 
@@ -250,95 +249,3 @@ describe('copyImageToClipboard', () => {
250
249
  await expect(copyImageToClipboard('/api/fs/raw?path=a.png')).rejects.toThrow('Image clipboard unavailable');
251
250
  });
252
251
  });
253
-
254
- // ── save-file.ts ────────────────────────────────────────────────────────────
255
-
256
- interface Write {
257
- url: string;
258
- method: string;
259
- form: FormData;
260
- }
261
-
262
- /** Captures the write request and answers it with `answer`. */
263
- function stubWrite(answer: { ok: boolean; body?: unknown; throwOnJson?: boolean }): Write[] {
264
- const writes: Write[] = [];
265
- globalThis.fetch = (async (input: unknown, init?: RequestInit) => {
266
- writes.push({ url: String(input), method: init?.method ?? 'GET', form: init?.body as FormData });
267
- return {
268
- ok: answer.ok,
269
- json: async () => {
270
- if (answer.throwOnJson) throw new Error('not json');
271
- return answer.body ?? null;
272
- },
273
- };
274
- }) as unknown as typeof fetch;
275
- return writes;
276
- }
277
-
278
- describe('saveEditorFile', () => {
279
- test('posts the buffer with the path and the ending as its own field', async () => {
280
- const writes = stubWrite({ ok: true, body: { success: true } });
281
- const ok = await saveEditorFile({ path: 'src/a.ts', root: '/repo' }, 'const a = 1;\n', 'lf');
282
-
283
- expect(ok).toBe('written');
284
- expect(writes.length).toBe(1);
285
- expect(writes[0].url).toBe('/api/fs/action');
286
- expect(writes[0].method).toBe('POST');
287
- // A multipart body normalizes bare LF, so the ending cannot travel in it.
288
- expect(writes[0].form.get('actionType')).toBe('save');
289
- expect(writes[0].form.get('path')).toBe('src/a.ts');
290
- expect(writes[0].form.get('content')).toBe('const a = 1;\n');
291
- expect(writes[0].form.get('eol')).toBe('lf');
292
- expect(writes[0].form.get('root')).toBe('/repo');
293
- });
294
-
295
- test('omits the root when the file has none and the repo when it is the cwd marker', async () => {
296
- const writes = stubWrite({ ok: true, body: { success: true } });
297
- await saveEditorFile({ path: 'a.ts', repo: '.' }, 'x', 'crlf');
298
- expect(writes[0].form.get('root')).toBeNull();
299
- expect(writes[0].form.get('repo')).toBeNull();
300
- });
301
-
302
- test('a named repo travels with the write', async () => {
303
- const writes = stubWrite({ ok: true, body: { success: true } });
304
- await saveEditorFile({ path: 'a.ts', repo: 'other' }, 'x', 'crlf');
305
- expect(writes[0].form.get('repo')).toBe('other');
306
- });
307
-
308
- test('a file with no path is refused without touching the network', async () => {
309
- const writes = stubWrite({ ok: true, body: { success: true } });
310
- expect(await saveEditorFile({}, 'x', 'lf')).toBe('failed');
311
- expect(writes).toEqual([]);
312
- });
313
-
314
- test('every refusal reports failed: non-2xx, an error body, a non-JSON body, a dropped connection', async () => {
315
- stubWrite({ ok: false, body: { success: true } });
316
- expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf')).toBe('failed');
317
-
318
- stubWrite({ ok: true, body: { success: false } });
319
- expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf')).toBe('failed');
320
-
321
- stubWrite({ ok: true, body: null });
322
- expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf')).toBe('failed');
323
-
324
- stubWrite({ ok: true, throwOnJson: true });
325
- expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf')).toBe('failed');
326
-
327
- globalThis.fetch = (async () => { throw new Error('offline'); }) as unknown as typeof fetch;
328
- expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf')).toBe('failed');
329
- });
330
- });
331
-
332
- describe('retainKeys', () => {
333
- test('keeps the same object when nothing was dropped, so children keep their identity', () => {
334
- const record = { a: 1, b: 2 };
335
- expect(retainKeys(record, new Set(['a', 'b']))).toBe(record);
336
- });
337
-
338
- test('drops the keys that left the tab set and keeps the rest', () => {
339
- const record = { a: 1, b: 2, c: 3 };
340
- expect(retainKeys(record, new Set(['a', 'c']))).toEqual({ a: 1, c: 3 });
341
- expect(retainKeys(record, new Set())).toEqual({});
342
- });
343
- });
344
-