@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,56 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The desktop layout's settings modal: whether it is open, which category it
8
+ * opens on, and whether a provider dialog follows.
9
+ *
10
+ * A hook because two different triggers drive it — the sidebar footer's button
11
+ * and the `omp:open-settings` window event (dispatched by the model dropdown,
12
+ * the phone's footer and any plugin) — and the event carries the category it
13
+ * wants. Stated once, the two paths cannot open the same modal on different
14
+ * screens.
15
+ */
16
+
17
+ import { useState } from 'preact/hooks';
18
+ import { useKabmoEvent } from '@/client/hooks/ui/window-event';
19
+ import type { SettingsCategoryId } from '@/shared/types';
20
+
21
+ export interface SettingsModalState {
22
+ isOpen: boolean;
23
+ category: SettingsCategoryId;
24
+ /** The "add provider" dialog opens on top of the modal's Providers screen. */
25
+ autoOpenAddProvider: boolean;
26
+ open: (category?: SettingsCategoryId, autoOpenAdd?: boolean) => void;
27
+ close: () => void;
28
+ }
29
+
30
+ export function useSettingsModal(): SettingsModalState {
31
+ const [isOpen, setOpen] = useState(false);
32
+ const [category, setCategory] = useState<SettingsCategoryId>('appearance');
33
+ const [autoOpenAddProvider, setAutoOpenAddProvider] = useState(false);
34
+
35
+ const open = (next?: SettingsCategoryId, autoOpenAdd = false) => {
36
+ setCategory(next ?? 'appearance');
37
+ setAutoOpenAddProvider(autoOpenAdd);
38
+ setOpen(true);
39
+ };
40
+
41
+ useKabmoEvent('omp:open-settings', (event) => {
42
+ const detail = (event as CustomEvent<{ category?: SettingsCategoryId; autoOpenAdd?: boolean }>).detail;
43
+ open(detail?.category, Boolean(detail?.autoOpenAdd));
44
+ });
45
+
46
+ return {
47
+ isOpen,
48
+ category,
49
+ autoOpenAddProvider,
50
+ open,
51
+ close: () => {
52
+ setOpen(false);
53
+ setAutoOpenAddProvider(false);
54
+ },
55
+ };
56
+ }
@@ -21,6 +21,7 @@ const RELEASE = {
21
21
  url: 'https://github.com/kabmo-labs/kabmo/releases/download/v1.2.3/Kabmo-1.2.3-android.apk',
22
22
  latest: '1.2.3',
23
23
  releaseUrl: 'https://github.com/kabmo-labs/kabmo/releases/tag/v1.2.3',
24
+ direct: true,
24
25
  };
25
26
 
26
27
  const UPDATE: ShellDownload = { ...RELEASE, kind: 'update', platform: 'android' };
@@ -209,6 +210,7 @@ describe('desktopShellFromIdentity', () => {
209
210
  expect(desktopShellFromIdentity({ platform: 'macos', shellVersion: '0.2.0' })).toEqual({
210
211
  platform: 'macos',
211
212
  version: '0.2.0',
213
+ arch: null,
212
214
  });
213
215
  expect(desktopShellFromIdentity({ platform: 'windows', shellVersion: '0.2.0' })?.platform).toBe('windows');
214
216
  expect(desktopShellFromIdentity({ platform: 'linux', shellVersion: '0.2.0' })?.platform).toBe('linux');
@@ -29,6 +29,7 @@
29
29
 
30
30
  import { useEffect, useState } from 'preact/hooks';
31
31
  import { isNewer } from '@/shared/lib/updates/semver';
32
+ import { parseShellArch, type ShellArch } from '@/shared/lib/updates/shell-arch';
32
33
  import {
33
34
  isDesktopShellKind,
34
35
  type DesktopShellKind,
@@ -43,11 +44,13 @@ export type ShellOfferKind = 'update' | 'install';
43
44
 
44
45
  export interface ShellDownload {
45
46
  /**
46
- * What the control links to.
47
+ * What the control points at.
47
48
  *
48
49
  * The artifact itself for the mobile pair (an APK the shell installs, an IPA
49
- * the release page explains), and the RELEASE PAGE for a desktop shell: every
50
- * desktop build is per-architecture, so the console cannot name one file.
50
+ * the release page explains), and for a desktop shell EITHER its own
51
+ * per-architecture artifact (when it reported `arch`) or the RELEASE PAGE (when
52
+ * it did not). `direct` says which, and that is what decides between a button
53
+ * and a link.
51
54
  */
52
55
  url: string;
53
56
  /** The version that artifact ships. */
@@ -58,12 +61,22 @@ export interface ShellDownload {
58
61
  kind: ShellOfferKind;
59
62
  /** Which shell this offer is for. */
60
63
  platform: ShellPlatform;
64
+ /**
65
+ * True when `url` is the artifact itself, so the SHELL can install it.
66
+ *
67
+ * False means `url` is the release page: the console cannot name one file
68
+ * (a desktop shell that did not report its architecture), so the offer is a
69
+ * link a human follows. That distinction is what decides between an `<a>` and
70
+ * a button that drives `update_apply`.
71
+ */
72
+ direct: boolean;
61
73
  }
62
74
 
63
75
  interface ReleasePayload {
64
76
  url?: unknown;
65
77
  latest?: unknown;
66
78
  releaseUrl?: unknown;
79
+ direct?: unknown;
67
80
  }
68
81
 
69
82
  /** The platform's own name, as the label says it. */
@@ -91,6 +104,10 @@ export function parseShellRelease(payload: unknown): Omit<ShellDownload, 'kind'
91
104
  url: body.url,
92
105
  latest: body.latest,
93
106
  releaseUrl: typeof body.releaseUrl === 'string' ? body.releaseUrl : null,
107
+ // Absent means "not installable": a shell that cannot install the bytes must
108
+ // fall back to the link rather than to a button that would download into
109
+ // nowhere.
110
+ direct: body.direct === true,
94
111
  };
95
112
  }
96
113
 
@@ -147,8 +164,14 @@ export function shellDownloadLabel(download: ShellDownload): string {
147
164
  * The desktop trio shares ONE route with an explicit `kind`, so no absence can
148
165
  * silently mean a platform — the reason the mobile pair has two.
149
166
  */
150
- export function shellReleasePath(platform: ShellPlatform): string {
151
- if (isDesktopShellKind(platform)) return `/api/updates/desktop?kind=${platform}`;
167
+ export function shellReleasePath(platform: ShellPlatform, arch: ShellArch | null = null): string {
168
+ if (isDesktopShellKind(platform)) {
169
+ // The arch is what makes the answer a FILE rather than a page. A shell that
170
+ // did not report one still asks, and still gets the page that lists every
171
+ // architecture — the offer is then a link, which is the honest fallback.
172
+ const base = `/api/updates/desktop?kind=${platform}`;
173
+ return arch ? `${base}&arch=${arch}` : base;
174
+ }
152
175
  return `/api/updates/${platform}`;
153
176
  }
154
177
 
@@ -182,10 +205,17 @@ export function shellFromBootstrap(bootstrap: {
182
205
  export function desktopShellFromIdentity(identity: {
183
206
  platform?: string;
184
207
  shellVersion?: string;
185
- } | null | undefined): { platform: DesktopShellKind; version: string } | null {
208
+ arch?: string;
209
+ } | null | undefined): { platform: DesktopShellKind; version: string; arch: ShellArch | null } | null {
186
210
  if (!identity?.platform || !identity.shellVersion) return null;
187
211
  if (!isDesktopShellKind(identity.platform)) return null;
188
- return { platform: identity.platform, version: identity.shellVersion };
212
+ return {
213
+ platform: identity.platform,
214
+ version: identity.shellVersion,
215
+ // A shell too old to report one keeps working: the offer degrades to the
216
+ // release page instead of disappearing.
217
+ arch: parseShellArch(identity.arch),
218
+ };
189
219
  }
190
220
 
191
221
  /**
@@ -200,6 +230,7 @@ export function useShellDownload(
200
230
  version: string | null | undefined,
201
231
  onAndroid: boolean | null | undefined,
202
232
  fetchImpl: typeof fetch = fetch,
233
+ arch: ShellArch | null = null,
203
234
  ): ShellDownload | null {
204
235
  /**
205
236
  * The answer, TAGGED with the platform it was read for.
@@ -210,10 +241,14 @@ export function useShellDownload(
210
241
  * — offering an Android APK to a Mac for one render.
211
242
  */
212
243
  const [answer, setAnswer] = useState<{
213
- platform: ShellPlatform;
244
+ key: string;
214
245
  release: Omit<ShellDownload, 'kind' | 'platform'> | null;
215
246
  } | null>(null);
216
247
  const wanted = Boolean(version) || (platform === 'android' && Boolean(onAndroid));
248
+ // The question this hook is asking, arch included: two windows on one console
249
+ // differ only by architecture, and an answer read for the other one is not an
250
+ // answer.
251
+ const key = `${platform}:${arch ?? ''}`;
217
252
 
218
253
  useEffect(() => {
219
254
  if (!wanted) return;
@@ -221,10 +256,10 @@ export function useShellDownload(
221
256
  let cancelled = false;
222
257
  void (async () => {
223
258
  try {
224
- const response = await fetchImpl(shellReleasePath(platform));
259
+ const response = await fetchImpl(shellReleasePath(platform, arch));
225
260
  if (!response.ok) return;
226
261
  const payload: unknown = await response.json();
227
- if (!cancelled) setAnswer({ platform, release: parseShellRelease(payload) });
262
+ if (!cancelled) setAnswer({ key, release: parseShellRelease(payload) });
228
263
  } catch {
229
264
  // A probe that cannot answer is a button that must not appear.
230
265
  }
@@ -233,10 +268,10 @@ export function useShellDownload(
233
268
  return () => {
234
269
  cancelled = true;
235
270
  };
236
- }, [wanted, platform, fetchImpl]);
271
+ }, [wanted, key, platform, arch, fetchImpl]);
237
272
 
238
- // A stale answer belongs to the platform it was read for, not this one.
239
- const release = answer?.platform === platform ? answer.release : null;
273
+ // A stale answer belongs to the question it was read for, not this one.
274
+ const release = answer?.key === key ? answer.release : null;
240
275
  return shouldOfferShellDownload(platform, version, onAndroid, release);
241
276
  }
242
277
 
@@ -285,7 +320,13 @@ export function useShellOffer(
285
320
  const platform = fromBridge?.platform ?? mobile?.platform ?? 'android';
286
321
  const version = fromBridge?.version ?? mobile?.version ?? null;
287
322
 
288
- return useShellDownload(platform, version, fromBridge ? null : bootstrap?.isAndroid, fetchImpl);
323
+ return useShellDownload(
324
+ platform,
325
+ version,
326
+ fromBridge ? null : bootstrap?.isAndroid,
327
+ fetchImpl,
328
+ fromBridge?.arch ?? null,
329
+ );
289
330
  }
290
331
 
291
332
  /**
@@ -35,6 +35,7 @@ const RELEASE = {
35
35
  url: 'https://github.com/kabmo-labs/kabmo/releases/download/v0.7.0/Kabmo-0.6.0-android.apk',
36
36
  latest: '0.6.0',
37
37
  releaseUrl: 'https://github.com/kabmo-labs/kabmo/releases/tag/v0.7.0',
38
+ direct: true,
38
39
  };
39
40
 
40
41
  function Harness({ fetchImpl }: { fetchImpl: typeof fetch }) {
@@ -169,6 +170,31 @@ describe('the desktop shells', () => {
169
170
  expect(await mount(stubFetch([]))).toBe('update:linux:0.6.0');
170
171
  });
171
172
 
173
+ /**
174
+ * A shell that reports its architecture asks for THAT machine's artifact.
175
+ *
176
+ * Without it the console can only answer the release page — every desktop
177
+ * artifact is per-architecture — so the offer is a link a human follows instead
178
+ * of an update the shell installs.
179
+ */
180
+ test('reports the arch, so the answer is a file rather than a page', async () => {
181
+ shell({ desktop: { platform: 'macos', shellVersion: '0.1.0', arch: 'arm64' } });
182
+ const asked: string[] = [];
183
+
184
+ await mount(stubFetch(asked));
185
+ expect(asked).toEqual(['/api/updates/desktop?kind=macos&arch=arm64']);
186
+ });
187
+
188
+ test('a shell with no arch still asks, and gets the page', async () => {
189
+ // An older shell must keep working: the offer degrades to the release page
190
+ // instead of disappearing.
191
+ shell({ desktop: { platform: 'macos', shellVersion: '0.1.0' } });
192
+ const asked: string[] = [];
193
+
194
+ await mount(stubFetch(asked));
195
+ expect(asked).toEqual(['/api/updates/desktop?kind=macos']);
196
+ });
197
+
172
198
  test('a refused probe draws no button', async () => {
173
199
  shell({ desktop: { platform: 'macos', shellVersion: '0.1.0' } });
174
200
  const refusing = (async () => ({ ok: false, json: async () => ({}) }) as Response) as unknown as typeof fetch;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The desktop self-update's client half.
8
+ *
9
+ * Two facts are pinned here and both were decisions rather than accidents:
10
+ *
11
+ * 1. **Which offers the shell can install itself** — a FILE (`direct`) in a
12
+ * DESKTOP shell. An Android offer installs through `PackageInstaller` (its own
13
+ * path), an iOS one cannot install at all, and a browser has no shell to ask.
14
+ * 2. **A failure is reported, never swallowed.** The shell's own sentence is what
15
+ * a user can act on, and a run that reported success before the shell said so
16
+ * would be a lie about an app that is still on the old build.
17
+ */
18
+
19
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
20
+ import { Window } from 'happy-dom';
21
+ import { h, render } from 'preact';
22
+ import { act } from 'preact/test-utils';
23
+ import { canSelfUpdate, useShellUpdate } from '@/client/hooks/ui/updates/shell-update';
24
+ import type { ShellDownload } from '@/client/hooks/ui/updates/shell-download';
25
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
26
+
27
+ const DESKTOP: ShellDownload = {
28
+ url: 'https://x/Kabmo-1.2.3-mac-arm64.zip',
29
+ latest: '1.2.3',
30
+ releaseUrl: 'https://x/app',
31
+ direct: true,
32
+ kind: 'update',
33
+ platform: 'macos',
34
+ };
35
+
36
+ const PAGE: ShellDownload = { ...DESKTOP, url: 'https://x/app', direct: false };
37
+
38
+ let container: HTMLElement;
39
+
40
+ /** Install (or remove) a bridge on the page. */
41
+ function bridge(call: ((method: string, params?: Record<string, unknown>) => Promise<unknown>) | null): void {
42
+ const page = globalThis as unknown as { window: { __kabmoCall?: unknown } };
43
+ if (call) page.window.__kabmoCall = call;
44
+ else delete page.window.__kabmoCall;
45
+ }
46
+
47
+ beforeAll(() => {
48
+ installDomGlobals(new Window({ url: 'http://localhost' }));
49
+ container = document.createElement('div');
50
+ document.body.appendChild(container);
51
+ });
52
+
53
+ afterEach(() => {
54
+ act(() => render(null, container));
55
+ bridge(null);
56
+ });
57
+
58
+ afterAll(() => {
59
+ container.remove();
60
+ restoreDomGlobals();
61
+ });
62
+
63
+ describe('canSelfUpdate', () => {
64
+ test('a direct desktop offer inside the shell is installable', () => {
65
+ bridge(async () => null);
66
+ expect(canSelfUpdate(DESKTOP)).toBe(true);
67
+ expect(canSelfUpdate({ ...DESKTOP, platform: 'windows' })).toBe(true);
68
+ expect(canSelfUpdate({ ...DESKTOP, platform: 'linux' })).toBe(true);
69
+ });
70
+
71
+ test('a release PAGE is not installable, whatever the platform', () => {
72
+ bridge(async () => null);
73
+ // The console could not name a file, so there is nothing to hand the shell.
74
+ expect(canSelfUpdate(PAGE)).toBe(false);
75
+ });
76
+
77
+ test('the mobile shells keep their own paths', () => {
78
+ bridge(async () => null);
79
+ // Android installs through PackageInstaller, iOS cannot install at all.
80
+ expect(canSelfUpdate({ ...DESKTOP, platform: 'android' })).toBe(false);
81
+ expect(canSelfUpdate({ ...DESKTOP, platform: 'ios' })).toBe(false);
82
+ });
83
+
84
+ test('a browser has no shell to ask', () => {
85
+ bridge(null);
86
+ expect(canSelfUpdate(DESKTOP)).toBe(false);
87
+ });
88
+
89
+ test('an absent offer is not installable', () => {
90
+ bridge(async () => null);
91
+ expect(canSelfUpdate(null)).toBe(false);
92
+ expect(canSelfUpdate(undefined)).toBe(false);
93
+ });
94
+ });
95
+
96
+ describe('useShellUpdate', () => {
97
+ /** A harness that exposes the hook's state and its one action. */
98
+ function Harness({ run }: { run: boolean }) {
99
+ const state = useShellUpdate();
100
+ if (run && state.phase === 'idle') void state.apply(DESKTOP);
101
+ return h('span', { id: 'state' }, `${state.phase}:${state.message ?? ''}`);
102
+ }
103
+
104
+ async function mount(run: boolean): Promise<string> {
105
+ await act(async () => {
106
+ render(h(Harness, { run }), container);
107
+ });
108
+ for (let i = 0; i < 20; i += 1) await act(async () => {});
109
+ return container.querySelector('#state')?.textContent ?? '';
110
+ }
111
+
112
+ test('passes the offer to the shell, and reports its own sentence', async () => {
113
+ const calls: { method: string; params?: Record<string, unknown> }[] = [];
114
+ bridge(async (method, params) => {
115
+ calls.push({ method, params });
116
+ return { success: true, version: '1.2.3', message: 'Kabmo 1.2.3 installed — restarting.', relaunching: true };
117
+ });
118
+
119
+ expect(await mount(true)).toBe('done:Kabmo 1.2.3 installed — restarting.');
120
+ expect(calls).toEqual([
121
+ { method: 'update_apply', params: { url: DESKTOP.url, version: DESKTOP.latest } },
122
+ ]);
123
+ });
124
+
125
+ test('a refused update keeps the shell’s reason', async () => {
126
+ // The shell verified the bytes and declined: "the downloaded file is not a
127
+ // signed Kabmo build" is the only thing that tells a user what to do next.
128
+ bridge(async () => ({ success: false, message: 'The downloaded file is not a signed Kabmo build.' }));
129
+
130
+ expect(await mount(true)).toBe('error:The downloaded file is not a signed Kabmo build.');
131
+ });
132
+
133
+ test('a shell that cannot answer is reported rather than assumed to have worked', async () => {
134
+ bridge(async () => {
135
+ throw new Error('Unknown shell command: update_apply');
136
+ });
137
+
138
+ expect(await mount(true)).toBe('error:Unknown shell command: update_apply');
139
+ });
140
+ });
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Installing a desktop shell's own update, from the console.
8
+ *
9
+ * ## Why the shell does the work
10
+ *
11
+ * A page cannot replace the executable it runs inside, and a browser download
12
+ * leaves a file in a folder the user has to find and open. So the button asks
13
+ * the SHELL (`update_apply` over the bridge), and the shell downloads, verifies,
14
+ * replaces and relaunches. What this hook owns is only the part a page can own:
15
+ * the run's state, and reporting the outcome where the user clicked.
16
+ *
17
+ * ## Why it is a hook rather than a function at the call site
18
+ *
19
+ * Both sidebars draw this control and each one unmounts at a different moment (a
20
+ * phone closes the drawer, a desktop swaps sessions). The state has to live with
21
+ * the control that shows it, and the two must report the SAME vocabulary — so the
22
+ * phases and their sentences are here, not in either footer.
23
+ *
24
+ * ## A failure is always a sentence
25
+ *
26
+ * The shell sends its own reason ("the downloaded file is not a signed Kabmo
27
+ * build", "the installer refused with code 5"), which is the only thing that can
28
+ * tell a user what to do next. Nothing here replaces it with a generic failure,
29
+ * and nothing reports success before the shell said so.
30
+ */
31
+
32
+ import { useCallback, useRef, useState } from 'preact/hooks';
33
+ import {
34
+ applyShellUpdate,
35
+ bridgeError,
36
+ isDesktopShell,
37
+ type ShellUpdateOutcome,
38
+ } from '@/client/lib/desktop/bridge';
39
+ import type { ShellDownload } from '@/client/hooks/ui/updates/shell-download';
40
+
41
+ /** What the control is doing right now. */
42
+ export type ShellUpdatePhase = 'idle' | 'working' | 'done' | 'error';
43
+
44
+ export interface ShellUpdateState {
45
+ phase: ShellUpdatePhase;
46
+ /** The shell's own sentence, for `done` and `error`. */
47
+ message: string | null;
48
+ }
49
+
50
+ export interface UseShellUpdateResult extends ShellUpdateState {
51
+ /** Run the update this offer names. */
52
+ apply: (download: ShellDownload) => Promise<void>;
53
+ /**
54
+ * Forget the last run, back to `idle`.
55
+ *
56
+ * The dialog calls this when it OPENS: a run that failed last time must not greet
57
+ * the user with its old refusal the next time they press the control.
58
+ */
59
+ reset: () => void;
60
+ /** True while a run is in flight, so the control can disable itself. */
61
+ working: boolean;
62
+ }
63
+
64
+ /**
65
+ * Whether this offer is something the shell can install by itself.
66
+ *
67
+ * Two facts, and both are required. The artifact must be a FILE (`direct`), and
68
+ * the page must be inside the desktop shell that can install it — an Android
69
+ * shell installs through `PackageInstaller` and iOS cannot install at all, so
70
+ * neither belongs to this path. A browser on a desktop gets neither, because
71
+ * there is no shell to ask.
72
+ */
73
+ export function canSelfUpdate(download: ShellDownload | null | undefined): boolean {
74
+ if (!download) return false;
75
+ if (!download.direct) return false;
76
+ if (download.platform === 'android' || download.platform === 'ios') return false;
77
+ return isDesktopShell();
78
+ }
79
+
80
+ export function useShellUpdate(): UseShellUpdateResult {
81
+ const [state, setState] = useState<ShellUpdateState>({ phase: 'idle', message: null });
82
+ // A second click while the shell is replacing itself would be a second
83
+ // installer beside the first, so the run is claimed by a ref rather than by
84
+ // the render state — a fast double click lands before the state is read.
85
+ const running = useRef(false);
86
+
87
+ const apply = useCallback(async (download: ShellDownload) => {
88
+ if (running.current) return;
89
+ running.current = true;
90
+ setState({ phase: 'working', message: null });
91
+
92
+ try {
93
+ const outcome: ShellUpdateOutcome = await applyShellUpdate(download.url, download.latest);
94
+ setState({
95
+ phase: outcome.success ? 'done' : 'error',
96
+ // The shell's sentence is the report. `?? null` rather than a fallback
97
+ // string: a shell that answered nothing has said nothing, and inventing
98
+ // "Update failed" over it would hide that.
99
+ message: outcome.message ?? null,
100
+ });
101
+ } catch (cause) {
102
+ // A refused command (an older shell with no `update_apply`) lands here,
103
+ // and its own message says so.
104
+ setState({ phase: 'error', message: bridgeError(cause) });
105
+ } finally {
106
+ running.current = false;
107
+ }
108
+ }, []);
109
+
110
+ const reset = useCallback(() => {
111
+ // A run in flight is NOT resettable: the shell is already replacing itself, and
112
+ // reporting `idle` over it would re-arm a control whose second press would start
113
+ // a second installer.
114
+ if (running.current) return;
115
+ setState({ phase: 'idle', message: null });
116
+ }, []);
117
+
118
+ return { ...state, apply, reset, working: state.phase === 'working' };
119
+ }
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
2
- import type { DiffContentMode } from '@/client/components/workspace/diff-panel/Toolbar';
3
2
 
4
3
  interface UseFileDiffOptions {
5
4
  filePath: string;
@@ -7,11 +6,14 @@ interface UseFileDiffOptions {
7
6
  isStaged: boolean;
8
7
  repo: string;
9
8
  root?: string;
10
- contentMode: DiffContentMode;
11
9
  }
12
10
 
13
11
  export interface FileDiffState {
14
12
  rawDiff: string;
13
+ /** The document before the change (HEAD, or the index for an unstaged read). */
14
+ oldContent: string;
15
+ /** The document after it (the working file). */
16
+ newContent: string;
15
17
  currentStatus: string;
16
18
  currentStaged: boolean;
17
19
  isLoading: boolean;
@@ -31,8 +33,10 @@ export interface FileDiffState {
31
33
  * earlier read overwriting a newer one, and a dependency on the staged/status
32
34
  * copies re-keying the callback and firing a fetch per render.
33
35
  */
34
- export function useFileDiff({ filePath, status, isStaged, repo, root, contentMode }: UseFileDiffOptions): FileDiffState {
36
+ export function useFileDiff({ filePath, status, isStaged, repo, root }: UseFileDiffOptions): FileDiffState {
35
37
  const [rawDiff, setRawDiff] = useState<string>('');
38
+ const [oldContent, setOldContent] = useState<string>('');
39
+ const [newContent, setNewContent] = useState<string>('');
36
40
  const [currentStatus, setCurrentStatus] = useState<string>(status);
37
41
  const [currentStaged, setCurrentStaged] = useState<boolean>(isStaged);
38
42
  const [isLoading, setIsLoading] = useState<boolean>(true);
@@ -62,11 +66,9 @@ export function useFileDiff({ filePath, status, isStaged, repo, root, contentMod
62
66
  staged: staged ? '1' : '0',
63
67
  repo: repo || '.',
64
68
  });
65
- // `fullContext=1` makes git emit the whole file rather than the hunks.
66
- // Only the user's own toggle changes it, so it is safe as a callback
67
- // dependency (unlike the staged/status copies above, which the action
68
- // path updates while a fetch of its own is already in flight).
69
- if (contentMode === 'full') params.set('fullContext', '1');
69
+ // No `fullContext`: the panel renders both SIDES of the file now, and
70
+ // how much of them is shown is a client-side collapse. Asking the server
71
+ // for the whole file as a patch would be a second answer to that question.
70
72
  if (statusForFetch) params.set('status', statusForFetch);
71
73
  if (root) params.set('root', root);
72
74
 
@@ -74,6 +76,8 @@ export function useFileDiff({ filePath, status, isStaged, repo, root, contentMod
74
76
  const data = (await res.json().catch(() => null)) as {
75
77
  success?: boolean;
76
78
  diff?: string;
79
+ oldContent?: string;
80
+ newContent?: string;
77
81
  status?: string;
78
82
  staged?: boolean;
79
83
  error?: string;
@@ -83,6 +87,11 @@ export function useFileDiff({ filePath, status, isStaged, repo, root, contentMod
83
87
  if (seq !== fetchSeqRef.current) return;
84
88
  if (data?.success) {
85
89
  setRawDiff(data.diff || '');
90
+ // Both sides travel on every read: the merge view compares documents,
91
+ // and a whitespace fold has to be applied to the ORIGINAL, not to the
92
+ // patch (see `foldWhitespaceOnly`).
93
+ setOldContent(data.oldContent ?? '');
94
+ setNewContent(data.newContent ?? '');
86
95
  if (data.status) {
87
96
  statusRef.current = data.status;
88
97
  setCurrentStatus(data.status);
@@ -100,7 +109,7 @@ export function useFileDiff({ filePath, status, isStaged, repo, root, contentMod
100
109
  } finally {
101
110
  if (seq === fetchSeqRef.current) setIsLoading(false);
102
111
  }
103
- }, [filePath, repo, root, contentMode]);
112
+ }, [filePath, repo, root]);
104
113
 
105
114
  useEffect(() => {
106
115
  setCurrentStatus(status);
@@ -124,5 +133,15 @@ export function useFileDiff({ filePath, status, isStaged, repo, root, contentMod
124
133
  }
125
134
  }, []);
126
135
 
127
- return { rawDiff, currentStatus, currentStaged, isLoading, errorMessage, fetchDiff, adoptState };
136
+ return {
137
+ rawDiff,
138
+ oldContent,
139
+ newContent,
140
+ currentStatus,
141
+ currentStaged,
142
+ isLoading,
143
+ errorMessage,
144
+ fetchDiff,
145
+ adoptState,
146
+ };
128
147
  }