@kabmo-labs/kabmo 0.26.0 → 0.28.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 (354) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +502 -474
  3. package/dist/client/static/js/index-81f7berm.css +1 -0
  4. package/dist/client/static/js/{index-95b3n20k.js → index-xzvyrxya.js} +799 -799
  5. package/marketplace/plugins/command-runner/package.json +3 -17
  6. package/marketplace/plugins/command-runner/settings-schema.json +14 -0
  7. package/marketplace/plugins/git-forge/README.md +17 -7
  8. package/marketplace/plugins/git-forge/package.json +4 -30
  9. package/marketplace/plugins/git-forge/panel.css +16 -0
  10. package/marketplace/plugins/git-forge/settings-schema.json +27 -0
  11. package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
  12. package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
  13. package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
  14. package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
  15. package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
  16. package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
  17. package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
  18. package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
  19. package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
  20. package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
  21. package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
  22. package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
  23. package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
  24. package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
  25. package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
  26. package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
  27. package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
  28. package/marketplace/plugins/session-info/package.json +2 -10
  29. package/marketplace/plugins/session-info/settings-schema.json +8 -0
  30. package/marketplace/plugins/stats/README.md +17 -5
  31. package/marketplace/plugins/stats/package.json +3 -23
  32. package/marketplace/plugins/stats/settings-schema.json +20 -0
  33. package/marketplace/plugins/stats/src/app.tsx +1 -1
  34. package/marketplace/plugins/stats/src/groups.test.ts +46 -1
  35. package/marketplace/plugins/stats/src/groups.ts +22 -11
  36. package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
  37. package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
  38. package/marketplace/plugins/stats/src/labels.test.ts +54 -1
  39. package/marketplace/plugins/stats/src/labels.ts +33 -7
  40. package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
  41. package/marketplace/plugins/stats/src/sampler.ts +39 -5
  42. package/marketplace/plugins/stats/src/snapshot.ts +6 -0
  43. package/package.json +2 -2
  44. package/src/client/components/common/Toast.test.tsx +28 -2
  45. package/src/client/components/common/Toast.tsx +21 -9
  46. package/src/client/components/common/harness-glyph/index.tsx +18 -1
  47. package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
  48. package/src/client/components/common/session-actions-menu/index.tsx +43 -1
  49. package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
  50. package/src/client/components/common/session-row/index.tsx +4 -0
  51. package/src/client/components/common/session-row/session-row.test.tsx +6 -0
  52. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  53. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +4 -2
  54. package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
  55. package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
  56. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
  57. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -1
  58. package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
  59. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +12 -29
  60. package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
  61. package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
  62. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
  63. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
  64. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +5 -1
  65. package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
  66. package/src/client/components/mobile/SessionSidebar.tsx +2 -1
  67. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
  68. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
  69. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
  70. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +4 -2
  71. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
  72. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
  73. package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
  74. package/src/client/components/settings/Modal.tsx +7 -3
  75. package/src/client/components/settings/Sidebar.tsx +30 -3
  76. package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
  77. package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
  78. package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
  79. package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
  80. package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
  81. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
  82. package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
  83. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
  84. package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
  85. package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
  86. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  87. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
  88. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
  89. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
  90. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
  91. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
  92. package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
  93. package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
  94. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
  95. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +61 -56
  96. package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
  97. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
  98. package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
  99. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +11 -1
  100. package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
  101. package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
  102. package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
  103. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
  104. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
  105. package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
  106. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
  107. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
  108. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
  109. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
  110. package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
  111. package/src/client/components/workspace/chat-timeline/index.tsx +17 -6
  112. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +3 -10
  113. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
  114. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
  115. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
  116. package/src/client/components/workspace/editor/FilePane.tsx +9 -4
  117. package/src/client/components/workspace/editor/Notices.tsx +2 -2
  118. package/src/client/components/workspace/editor/Pane.tsx +2 -2
  119. package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
  120. package/src/client/components/workspace/editor/index.tsx +6 -10
  121. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
  122. package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
  123. package/src/client/components/workspace/git-panel/index.tsx +2 -2
  124. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +17 -6
  125. package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
  126. package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
  127. package/src/client/components/workspace/terminal-panel/index.tsx +17 -1
  128. package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
  129. package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
  130. package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
  131. package/src/client/hooks/chat/composer/use-draft.ts +45 -1
  132. package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
  133. package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
  134. package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
  135. package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
  136. package/src/client/hooks/chat/omp/session-list.tsx +5 -0
  137. package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
  138. package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
  139. package/src/client/hooks/chat/timeline/actions.ts +4 -4
  140. package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
  141. package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
  142. package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
  143. package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
  144. package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
  145. package/src/client/hooks/chat/timeline/index.ts +5 -2
  146. package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
  147. package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
  148. package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
  149. package/src/client/hooks/chat/timeline/modes.ts +32 -52
  150. package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
  151. package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
  152. package/src/client/hooks/chat/timeline/pending-branch.ts +9 -0
  153. package/src/client/hooks/chat/timeline/pending-dispatch.ts +53 -0
  154. package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
  155. package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
  156. package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
  157. package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
  158. package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
  159. package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
  160. package/src/client/hooks/chat/timeline/send-props.ts +2 -0
  161. package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
  162. package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
  163. package/src/client/hooks/chat/timeline/send.test.ts +1 -0
  164. package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
  165. package/src/client/hooks/chat/timeline/stop-with-queue.ts +1 -1
  166. package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
  167. package/src/client/hooks/chat/waiting/cancel.ts +15 -7
  168. package/src/client/hooks/chat/waiting/choice.ts +13 -16
  169. package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
  170. package/src/client/hooks/chat/waiting/dispatch.ts +50 -29
  171. package/src/client/hooks/chat/waiting/held.ts +38 -13
  172. package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
  173. package/src/client/hooks/chat/waiting/hold.ts +20 -11
  174. package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
  175. package/src/client/hooks/chat/waiting/restore.ts +34 -0
  176. package/src/client/hooks/chat/waiting/store.ts +9 -3
  177. package/src/client/hooks/editor/file-editor-types.ts +21 -12
  178. package/src/client/hooks/editor/save-file.test.ts +1 -1
  179. package/src/client/hooks/editor/save-file.ts +35 -8
  180. package/src/client/hooks/editor/target-key.ts +17 -0
  181. package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
  182. package/src/client/hooks/editor/use-disk-digest.ts +164 -0
  183. package/src/client/hooks/editor/use-disk-sync.ts +212 -0
  184. package/src/client/hooks/editor/use-file-cache.ts +113 -0
  185. package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
  186. package/src/client/hooks/editor/use-file-editor.ts +90 -52
  187. package/src/client/hooks/editor/use-file-read.ts +24 -10
  188. package/src/client/hooks/editor/use-file-writes.ts +4 -4
  189. package/src/client/hooks/models/harness-catalog.ts +15 -0
  190. package/src/client/hooks/settings/providers/actions.ts +3 -2
  191. package/src/client/hooks/settings/providers/messages.ts +9 -7
  192. package/src/client/hooks/settings/providers/model-actions.ts +2 -1
  193. package/src/client/hooks/ui/editor-error-toast.ts +2 -1
  194. package/src/client/hooks/ui/notifications.ts +17 -8
  195. package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
  196. package/src/client/hooks/workspace/batch-archive.ts +4 -2
  197. package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
  198. package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
  199. package/src/client/hooks/workspace/panel-registry.ts +1 -1
  200. package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
  201. package/src/client/hooks/workspace/session-actions.test.ts +2 -1
  202. package/src/client/hooks/workspace/session-actions.ts +2 -1
  203. package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
  204. package/src/client/hooks/workspace/terminal/connection.ts +47 -0
  205. package/src/client/hooks/workspace/terminal/index.ts +35 -4
  206. package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
  207. package/src/client/lib/notifications/os.test.ts +1 -30
  208. package/src/client/lib/notifications/os.ts +0 -15
  209. package/src/client/lib/notifications/platform.test.ts +68 -0
  210. package/src/client/lib/notifications/platform.ts +36 -0
  211. package/src/server/index.ts +7 -0
  212. package/src/server/lib/harness/acp/client.ts +81 -87
  213. package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
  214. package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
  215. package/src/server/lib/harness/acp/prompt.test.ts +70 -1
  216. package/src/server/lib/harness/acp/prompt.ts +32 -1
  217. package/src/server/lib/harness/acp/protocol.ts +23 -0
  218. package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
  219. package/src/server/lib/harness/acp/session-handshake.ts +22 -20
  220. package/src/server/lib/harness/acp/session-options.ts +16 -0
  221. package/src/server/lib/harness/acp/session-process.ts +43 -0
  222. package/src/server/lib/harness/acp/session.ts +11 -12
  223. package/src/server/lib/harness/acp/stdio.ts +129 -0
  224. package/src/server/lib/harness/acp/verbs.test.ts +97 -0
  225. package/src/server/lib/harness/acp/verbs.ts +16 -6
  226. package/src/server/lib/harness/auto-probe.server.ts +4 -3
  227. package/src/server/lib/harness/capabilities.ts +8 -0
  228. package/src/server/lib/harness/config.server.ts +3 -2
  229. package/src/server/lib/harness/custom.server.ts +209 -0
  230. package/src/server/lib/harness/launch.ts +6 -1
  231. package/src/server/lib/harness/register.server.ts +8 -1
  232. package/src/server/lib/harness/schema.server.ts +21 -0
  233. package/src/server/lib/harness/session-lease.server.test.ts +99 -0
  234. package/src/server/lib/harness/session-lease.server.ts +193 -0
  235. package/src/server/lib/harness/session-store.server.test.ts +8 -8
  236. package/src/server/lib/harness/session-store.server.ts +25 -4
  237. package/src/server/lib/harness/session-title.server.ts +12 -2
  238. package/src/server/lib/harness/spawn.server.ts +123 -20
  239. package/src/server/lib/harness/update-queue.server.ts +3 -3
  240. package/src/server/lib/lifecycle/after-listen.ts +12 -1
  241. package/src/server/lib/lifecycle/paths.ts +19 -1
  242. package/src/server/lib/mcp/registry.server.ts +155 -0
  243. package/src/server/lib/mcp/registry.test.ts +169 -0
  244. package/src/server/lib/mcp/store.server.ts +38 -0
  245. package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
  246. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
  247. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
  248. package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
  249. package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
  250. package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
  251. package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
  252. package/src/server/lib/omp/rpc/run-model.ts +4 -2
  253. package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
  254. package/src/server/lib/omp/session/standby.server.ts +13 -2
  255. package/src/server/lib/panels/manifest.test.ts +47 -1
  256. package/src/server/lib/panels/manifest.ts +19 -0
  257. package/src/server/lib/panels/registry.server.ts +19 -2
  258. package/src/server/lib/panels/scan.server.ts +26 -2
  259. package/src/server/lib/panels/settings-schema.server.ts +72 -0
  260. package/src/server/lib/plugins/background.server.ts +21 -3
  261. package/src/server/lib/plugins/background.test.ts +13 -0
  262. package/src/server/lib/plugins/loader.server.ts +35 -51
  263. package/src/server/lib/plugins/mcp.server.ts +100 -0
  264. package/src/server/lib/plugins/mcp.test.ts +75 -0
  265. package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
  266. package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
  267. package/src/server/lib/plugins/schedule-store.server.ts +107 -0
  268. package/src/server/lib/plugins/schema.server.ts +8 -0
  269. package/src/server/lib/plugins/settings.server.ts +56 -19
  270. package/src/server/lib/plugins/shutdown.server.ts +58 -0
  271. package/src/server/lib/plugins/shutdown.test.ts +28 -3
  272. package/src/server/lib/realtime/topics/global.server.ts +5 -1
  273. package/src/server/lib/schedule/rows.server.ts +9 -0
  274. package/src/server/lib/schedule/runtime.server.test.ts +91 -0
  275. package/src/server/lib/schedule/runtime.server.ts +101 -23
  276. package/src/server/lib/schedule/schema.server.ts +15 -0
  277. package/src/server/lib/schedule/store.server.test.ts +34 -0
  278. package/src/server/lib/schedule/store.server.ts +33 -9
  279. package/src/server/lib/sessions/fork.server.test.ts +47 -0
  280. package/src/server/lib/sessions/fork.server.ts +17 -1
  281. package/src/server/lib/sessions/spawn.server.ts +2 -2
  282. package/src/server/lib/usage/report.server.ts +57 -0
  283. package/src/server/lib/waiting/runtime.server.test.ts +48 -0
  284. package/src/server/lib/waiting/runtime.server.ts +22 -0
  285. package/src/server/lib/waiting/schema.server.ts +8 -0
  286. package/src/server/lib/waiting/store.server.test.ts +14 -0
  287. package/src/server/lib/waiting/store.server.ts +6 -2
  288. package/src/server/routes/agent/command-resume.test.ts +9 -4
  289. package/src/server/routes/agent/new-mode.test.ts +40 -0
  290. package/src/server/routes/agent/new.ts +31 -10
  291. package/src/server/routes/agent/prewarm.ts +48 -7
  292. package/src/server/routes/fs/action.ts +9 -1
  293. package/src/server/routes/fs/digest.test.ts +100 -0
  294. package/src/server/routes/fs/digest.ts +106 -0
  295. package/src/server/routes/fs/index.ts +2 -0
  296. package/src/server/routes/fs/read.ts +6 -1
  297. package/src/server/routes/harness/custom.test.ts +131 -0
  298. package/src/server/routes/harness/import-action.ts +2 -2
  299. package/src/server/routes/harness/root.ts +41 -8
  300. package/src/server/routes/harness/update.ts +2 -2
  301. package/src/server/routes/panels/bindings.ts +2 -0
  302. package/src/server/routes/panels/settings.test.ts +165 -0
  303. package/src/server/routes/panels/settings.ts +106 -0
  304. package/src/server/routes/schedule/body.ts +14 -0
  305. package/src/server/routes/schedule/index.ts +28 -4
  306. package/src/server/routes/settings/mcp.ts +9 -26
  307. package/src/server/routes/waiting/index.ts +21 -2
  308. package/src/server/routes/waiting/routes.test.ts +21 -0
  309. package/src/shared/lib/chat/composer/delegation.ts +3 -3
  310. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
  311. package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
  312. package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
  313. package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
  314. package/src/shared/lib/fs/content-hash.ts +29 -0
  315. package/src/shared/lib/harness/catalog.ts +48 -6
  316. package/src/shared/lib/harness/fork.ts +60 -0
  317. package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
  318. package/src/shared/lib/harness/mcp-facts.ts +65 -0
  319. package/src/shared/lib/harness/menu.test.ts +16 -1
  320. package/src/shared/lib/harness/menu.ts +2 -2
  321. package/src/shared/lib/harness/rewind.ts +6 -6
  322. package/src/shared/lib/harness/session-modes.ts +31 -0
  323. package/src/shared/lib/harness/transcript.test.ts +29 -0
  324. package/src/shared/lib/harness/transcript.ts +19 -0
  325. package/src/shared/lib/notifications/settings.test.ts +21 -0
  326. package/src/shared/lib/notifications/settings.ts +24 -0
  327. package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
  328. package/src/shared/lib/omp/session/prewarm.ts +25 -6
  329. package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
  330. package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
  331. package/src/shared/lib/panels/capabilities.test.ts +1 -1
  332. package/src/shared/lib/panels/capabilities.ts +3 -0
  333. package/src/shared/lib/plugins/settings.ts +22 -0
  334. package/src/shared/lib/schedule/parse.test.ts +48 -0
  335. package/src/shared/lib/schedule/parse.ts +69 -45
  336. package/src/shared/lib/schedule/timezone.ts +128 -0
  337. package/src/shared/lib/settings/defaults.ts +2 -0
  338. package/src/shared/lib/ui/toast-duration.test.ts +25 -1
  339. package/src/shared/lib/ui/toast-duration.ts +22 -4
  340. package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
  341. package/src/shared/lib/workspace/relative-time.ts +16 -0
  342. package/src/shared/lib/workspace/session-state/store.ts +4 -0
  343. package/src/shared/types/harness.ts +7 -0
  344. package/src/shared/types/omp/agent.ts +6 -0
  345. package/src/shared/types/panels-registry.ts +3 -3
  346. package/src/shared/types/panels.ts +4 -2
  347. package/src/shared/types/schedule.ts +13 -0
  348. package/src/shared/types/settings/state.ts +12 -1
  349. package/src/shared/types/waiting.ts +9 -0
  350. package/src/test-support/file-editor.test-util.ts +70 -5
  351. package/dist/client/static/js/index-p2yw9ywf.css +0 -1
  352. package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
  353. package/src/client/hooks/editor/use-external-change.test.ts +0 -88
  354. package/src/client/hooks/editor/use-external-change.ts +0 -146
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The editor's disk watcher: the periodic question "are the bytes behind this
8
+ * tab still the ones the buffer holds?".
9
+ *
10
+ * It asks `/api/fs/digest`, which answers with the file's CONTENT hash, and it
11
+ * compares that against the hash the buffer was read at (and, for a write, the
12
+ * hash of the bytes that write landed). Two consequences, both deliberate:
13
+ *
14
+ * - a file rewritten with identical bytes (`git checkout` of the revision
15
+ * already open, a formatter that changes nothing, a `touch`) does NOT reach
16
+ * the buffer, because nothing about the document changed. The caller hears
17
+ * `onUnchanged` instead and may adopt the moved mtime — the save path's
18
+ * conflict base is still an mtime, so a touched file would otherwise refuse
19
+ * the next save over a change that never happened;
20
+ * - a file whose mtime did not move but whose bytes did (two writes inside one
21
+ * filesystem clock tick) is still seen, which an mtime poll cannot do.
22
+ *
23
+ * **Polling, not a filesystem watch**: the server has no watcher to subscribe
24
+ * to, and this app runs on the same machine as the tree, so one scoped request
25
+ * every few seconds is cheaper than a watch per open tab. The probe is skipped
26
+ * while the page is hidden and never overlaps itself. A workspace refresh (`revision`)
27
+ * and the window regaining focus both ask immediately, so the common case —
28
+ * the user alt-tabs back after an external edit — does not wait for the next tick.
29
+ *
30
+ * A `gone` or `unknown` verdict reports NOTHING: a deleted file belongs to
31
+ * `useMissingFiles` (which owns the struck-through tab), and a dropped request
32
+ * must not be read as "the disk changed".
33
+ */
34
+
35
+ import { useEffect, useRef } from 'preact/hooks';
36
+
37
+ /**
38
+ * How often an open tab asks whether its file moved.
39
+ *
40
+ * 3s is chosen against what the answer costs: the server hashes the file (cached
41
+ * against its stat, so an unchanged file costs one `stat`), and a text file the
42
+ * editor opens is at most 32 MiB. A shorter interval buys nothing — the user is
43
+ * coming back from another window, and focus asks immediately — while a longer
44
+ * one lets a tool call and the next keystroke race visibly.
45
+ */
46
+ export const DISK_DIGEST_INTERVAL_MS = 3000;
47
+
48
+ /** What the disk says about the file behind a tab. */
49
+ export interface DiskDigest {
50
+ /** The file's content hash — the value every producer in the app agrees on. */
51
+ hash: string;
52
+ /** Rounded to a whole millisecond, exactly as the read route reports it. */
53
+ mtimeMs: number;
54
+ }
55
+
56
+ /**
57
+ * Ask the server for the digest of `path`, inside the tab's own scope.
58
+ *
59
+ * Exported because the three "no verdict" answers are the whole rule and are
60
+ * only testable without a mounted component.
61
+ */
62
+ export async function probeDiskDigest(
63
+ path: string,
64
+ root: string | null,
65
+ repo: string | null,
66
+ ): Promise<DiskDigest | 'gone' | 'unknown'> {
67
+ const params = new URLSearchParams({ path });
68
+ if (root) params.set('root', root);
69
+ if (repo && repo !== '.') params.set('repo', repo);
70
+ try {
71
+ const res = await fetch(`/api/fs/digest?${params.toString()}`);
72
+ const data = (await res.json().catch(() => null)) as
73
+ | { exists?: unknown; mtimeMs?: unknown; hash?: unknown }
74
+ | null;
75
+ if (!res.ok || !data || typeof data.exists !== 'boolean') return 'unknown';
76
+ if (data.exists === false) return 'gone';
77
+ // No hash is a file too large for the editor, or an unreadable one: there is
78
+ // nothing to compare, so there is no verdict.
79
+ if (typeof data.hash !== 'string' || typeof data.mtimeMs !== 'number') return 'unknown';
80
+ return { hash: data.hash, mtimeMs: data.mtimeMs };
81
+ } catch {
82
+ return 'unknown';
83
+ }
84
+ }
85
+
86
+ interface UseDiskDigestOptions {
87
+ /** The file the tab names; `null` disables the watcher. */
88
+ path: string | null;
89
+ root?: string | null;
90
+ repo?: string | null;
91
+ /** The hash the buffer was read at (or the one its last save wrote). */
92
+ baseHash: string | null;
93
+ /** Bumped whenever something may have written the tree — asks immediately. */
94
+ revision: number;
95
+ /** The bytes on disk are the ones the buffer holds; only the clock moved. */
96
+ onUnchanged: (mtimeMs: number) => void;
97
+ /** The disk bytes differ from the buffer's fingerprint. */
98
+ onChanged: (digest: DiskDigest) => void;
99
+ }
100
+
101
+ export function useDiskDigest({
102
+ path,
103
+ root = null,
104
+ repo = null,
105
+ baseHash,
106
+ revision,
107
+ onUnchanged,
108
+ onChanged,
109
+ }: UseDiskDigestOptions): void {
110
+ // The callbacks are rebuilt whenever the caller's state moves (and a new
111
+ // `baseHash` restarts this effect anyway), so they are read through refs: a
112
+ // dependency on their identity would tear the interval down on every keystroke.
113
+ const unchangedRef = useRef(onUnchanged);
114
+ unchangedRef.current = onUnchanged;
115
+ const changedRef = useRef(onChanged);
116
+ changedRef.current = onChanged;
117
+
118
+ useEffect(() => {
119
+ // No baseline means no comparison: an inline attachment, a handle-backed
120
+ // tab, a byte viewer or a file the read refused all land here.
121
+ if (!path || baseHash === null) return;
122
+
123
+ let cancelled = false;
124
+ let inFlight = false;
125
+ /** The hash already reported, so one external write fires once. */
126
+ let reported: string | null = null;
127
+
128
+ const check = async () => {
129
+ if (cancelled || inFlight || document.hidden) return;
130
+ inFlight = true;
131
+ try {
132
+ const verdict = await probeDiskDigest(path, root, repo);
133
+ if (cancelled || verdict === 'unknown' || verdict === 'gone') return;
134
+ if (verdict.hash === baseHash) {
135
+ unchangedRef.current(verdict.mtimeMs);
136
+ return;
137
+ }
138
+ if (reported === verdict.hash) return;
139
+ reported = verdict.hash;
140
+ changedRef.current(verdict);
141
+ } finally {
142
+ inFlight = false;
143
+ }
144
+ };
145
+
146
+ const timer = window.setInterval(() => void check(), DISK_DIGEST_INTERVAL_MS);
147
+ // A workspace refresh is a write somewhere, and coming back to the window is
148
+ // the moment the user expects the tab to be current.
149
+ void check();
150
+ const onFocus = () => void check();
151
+ const onVisibility = () => {
152
+ if (!document.hidden) void check();
153
+ };
154
+ window.addEventListener('focus', onFocus);
155
+ document.addEventListener('visibilitychange', onVisibility);
156
+
157
+ return () => {
158
+ cancelled = true;
159
+ window.clearInterval(timer);
160
+ window.removeEventListener('focus', onFocus);
161
+ document.removeEventListener('visibilitychange', onVisibility);
162
+ };
163
+ }, [path, root, repo, baseHash, revision]);
164
+ }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The editor's disk SYNCHRONISATION: the watcher, the two answers it produces,
8
+ * and the manual Reload.
9
+ *
10
+ * Split from `useFileEditor` because it is a self-contained cluster — one poll,
11
+ * one verdict, one counter the panel renders — and it is the piece with a rule
12
+ * worth naming:
13
+ *
14
+ * - **A CLEAN buffer follows the disk.** Nothing of the user's is at stake, so a
15
+ * file changed by an agent, a `git checkout` or another editor is re-read
16
+ * without asking. The bytes stay on screen until the response lands.
17
+ * - **A DIRTY buffer never does.** Its edits are the user's, and only the user
18
+ * can say which side wins, so the hook reports a revision instead and the
19
+ * panel asks (the external-change strip).
20
+ * - **A file that still hashes the same is not a change.** Its mtime may have
21
+ * moved (`touch`, a no-op formatter, a checkout of the revision already open);
22
+ * that only means the save path's conflict base must move with it, or the next
23
+ * save would be refused over a change that never happened.
24
+ *
25
+ * Reload is the manual counterpart: it re-reads even a clean buffer (the answer
26
+ * to "read it again"), and it discards a dirty one — including the debounced
27
+ * write sitting behind those edits, which would otherwise land after the read
28
+ * and put the discarded text back on disk.
29
+ */
30
+
31
+ import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
32
+ import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
33
+ import type { PendingWrite } from '@/client/hooks/editor/use-file-writes';
34
+ import { useDiskDigest, type DiskDigest } from '@/client/hooks/editor/use-disk-digest';
35
+ import { editorTargetKey } from '@/client/hooks/editor/target-key';
36
+ import { isProbeableTab } from '@/client/hooks/workspace/missing-files';
37
+
38
+ /** A mutable ref, typed structurally — every ref here is read without a null check. */
39
+ interface LiveRef<T> {
40
+ current: T;
41
+ }
42
+
43
+ export interface DiskSyncDeps {
44
+ /** The active buffer's key, or `''` when nothing is open. */
45
+ key: string;
46
+ target: FileEditorTarget | null;
47
+ /** The hash the ACTIVE buffer was read at (or the one its last save wrote). */
48
+ baseHash: string | null;
49
+ /** Bumped by `reset()`/a save; also what makes the watcher ask immediately. */
50
+ revision: number;
51
+ hashesRef: LiveRef<Record<string, string | null>>;
52
+ mtimesRef: LiveRef<Record<string, number | null>>;
53
+ contentsRef: LiveRef<Record<string, string>>;
54
+ baselinesRef: LiveRef<Record<string, string>>;
55
+ pendingRef: LiveRef<PendingWrite | null>;
56
+ /** Reads on their way — a verdict must not queue a second one. */
57
+ readingRef: LiveRef<number>;
58
+ loadedRef: LiveRef<Set<string>>;
59
+ /** Forces the read effect to re-run for the active file. */
60
+ bumpRevision: () => void;
61
+ /** Take the disk's mtime as this buffer's base, writing nothing. */
62
+ adoptDiskMtime: (diskMtimeMs: number) => void;
63
+ /** Drop one buffer's conflict entry without resolving anything. */
64
+ clearConflict: (fileKey: string) => void;
65
+ /** Discard the active buffer and re-read it. */
66
+ reloadDiscardingEdits: () => void;
67
+ /** Drop the debounced write for a key. */
68
+ discardPendingWrite: (fileKey: string) => void;
69
+ }
70
+
71
+ export interface DiskSync {
72
+ /**
73
+ * The disk bytes differ from a buffer that HAS edits, or null.
74
+ *
75
+ * Nothing was replaced: the panel renders this as the external-change strip, so
76
+ * the user chooses between the two copies. Cleared by itself as soon as the
77
+ * buffer and the disk agree again (a reload, a save, a "Keep mine" write).
78
+ */
79
+ diskChange: DiskDigest | null;
80
+ reloadFromDisk: () => void;
81
+ /**
82
+ * Answer the strip with the user's buffer: adopt the disk's mtime and stop
83
+ * asking about THIS change.
84
+ *
85
+ * Nothing is written — the buffer stays dirty and the autosave owns the write —
86
+ * and the accepted hash is remembered, so the watcher does not raise the same
87
+ * strip again on its next poll. A LATER change is a new hash and asks again.
88
+ */
89
+ keepMineAgainstDisk: () => void;
90
+ }
91
+
92
+ export function useDiskSync({
93
+ key,
94
+ target,
95
+ baseHash,
96
+ revision,
97
+ hashesRef,
98
+ mtimesRef,
99
+ contentsRef,
100
+ baselinesRef,
101
+ pendingRef,
102
+ readingRef,
103
+ loadedRef,
104
+ bumpRevision,
105
+ adoptDiskMtime,
106
+ clearConflict,
107
+ reloadDiscardingEdits,
108
+ discardPendingWrite,
109
+ }: DiskSyncDeps): DiskSync {
110
+ const [diskChange, setDiskChange] = useState<DiskDigest | null>(null);
111
+ /**
112
+ * The hash the user answered "Keep mine" about, so the same change is not
113
+ * reported again on the next poll.
114
+ *
115
+ * A ref rather than state: the watcher reads it from a callback that must stay
116
+ * stable, and dismissing a strip is not something the UI derives from.
117
+ */
118
+ const dismissedRef = useRef<string | null>(null);
119
+
120
+ // The verdict describes the tab it was made for; switching tabs must not carry
121
+ // a stale "changed on disk" strip onto another file.
122
+ useEffect(() => {
123
+ setDiskChange(null);
124
+ dismissedRef.current = null;
125
+ }, [key]);
126
+
127
+ const adoptUnchangedMtime = useCallback(
128
+ (diskMtimeMs: number) => {
129
+ if (!key) return;
130
+ // The bytes are the ones this buffer holds; only the clock moved. Adopting
131
+ // the mtime keeps the next save from being refused over nothing, and it is
132
+ // also the answer to a strip the user has already seen: the disk is not
133
+ // ahead of the buffer, so there is nothing left to ask.
134
+ if (mtimesRef.current[key] !== diskMtimeMs) adoptDiskMtime(diskMtimeMs);
135
+ setDiskChange(null);
136
+ // The bytes agree again, so a dismissal of an older change is spent.
137
+ dismissedRef.current = null;
138
+ },
139
+ [key, mtimesRef, adoptDiskMtime],
140
+ );
141
+
142
+ const adoptDiskChange = useCallback(
143
+ (digest: DiskDigest) => {
144
+ if (!key) return;
145
+ // A probe that started before the last read landed compares against a
146
+ // baseline that has since moved; the live hash is the truth, and the bytes
147
+ // it names are already on screen.
148
+ if (hashesRef.current[key] === digest.hash) {
149
+ setDiskChange(null);
150
+ return;
151
+ }
152
+ if (dismissedRef.current === digest.hash) return;
153
+ if (diskChange?.hash === digest.hash) return;
154
+ const typed = contentsRef.current[key];
155
+ const queued = pendingRef.current;
156
+ const dirty =
157
+ (typed !== undefined && typed !== baselinesRef.current[key]) ||
158
+ (queued !== null && editorTargetKey(queued.file) === key);
159
+ if (dirty) {
160
+ setDiskChange(digest);
161
+ return;
162
+ }
163
+ // A read already on its way (a workspace refresh, a manual Reload, an
164
+ // earlier verdict) will land these bytes; asking again would be one more
165
+ // request for the same answer.
166
+ if (readingRef.current > 0) return;
167
+ loadedRef.current.delete(key);
168
+ bumpRevision();
169
+ },
170
+ [key, hashesRef, contentsRef, baselinesRef, pendingRef, readingRef, loadedRef, bumpRevision, diskChange],
171
+ );
172
+
173
+ useDiskDigest({
174
+ // Same predicate the tab strip and the phone use for "this tab names a file
175
+ // on disk": a diff tab, an attachment chip and a handle/device file have no
176
+ // server path to ask about. The id only satisfies the predicate's shape.
177
+ path: target && isProbeableTab({ ...target, id: key }) ? target.path ?? null : null,
178
+ root: target?.root ?? null,
179
+ repo: target?.repo ?? null,
180
+ baseHash,
181
+ revision,
182
+ onUnchanged: adoptUnchangedMtime,
183
+ onChanged: adoptDiskChange,
184
+ });
185
+
186
+ const reloadFromDisk = useCallback(() => {
187
+ if (!target) return;
188
+ const fileKey = editorTargetKey(target);
189
+ const typed = contentsRef.current[fileKey];
190
+ const dirty = typed !== undefined && typed !== baselinesRef.current[fileKey];
191
+ if (dirty) {
192
+ discardPendingWrite(fileKey);
193
+ reloadDiscardingEdits();
194
+ return;
195
+ }
196
+ clearConflict(fileKey);
197
+ loadedRef.current.delete(fileKey);
198
+ bumpRevision();
199
+ }, [target, contentsRef, baselinesRef, discardPendingWrite, reloadDiscardingEdits, clearConflict, loadedRef, bumpRevision]);
200
+
201
+ const keepMineAgainstDisk = useCallback(() => {
202
+ if (!diskChange) return;
203
+ // Remember the exact change that was dismissed: the disk still has those
204
+ // bytes until the buffer's own write lands, so the watcher would otherwise
205
+ // raise the strip again three seconds later.
206
+ dismissedRef.current = diskChange.hash;
207
+ adoptDiskMtime(diskChange.mtimeMs);
208
+ setDiskChange(null);
209
+ }, [diskChange, adoptDiskMtime]);
210
+
211
+ return { diskChange, reloadFromDisk, keepMineAgainstDisk };
212
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The editor's per-file CACHE lifecycle: throw every cached read away, keep only
8
+ * the files still open, and switch the ending a buffer saves in.
9
+ *
10
+ * These three belong together because they all answer "what does the cache hold
11
+ * right now", and they must touch EVERY cache — the bytes, the baselines, the
12
+ * line endings, the mtimes and the content hashes. A `retain` that forgot one of
13
+ * them left an entry a later tab could inherit under the same key; the hash list
14
+ * is part of that set, or a reopened tab would compare the disk against a
15
+ * fingerprint from the file it used to be.
16
+ *
17
+ * `reset` deliberately does NOT clear the bytes: they stay on screen until the
18
+ * fresh read lands, so a workspace refresh can never blank the editor.
19
+ */
20
+
21
+ import { useCallback } from 'preact/hooks';
22
+ import { retainKeys } from '@/client/hooks/editor/save-file';
23
+ import { editorTargetKey } from '@/client/hooks/editor/target-key';
24
+ import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
25
+ import { detectLineEnding, toLf, type LineEnding } from '@/shared/lib/code/line-endings';
26
+
27
+ /** A mutable ref, typed structurally — every ref here is read without a null check. */
28
+ interface LiveRef<T> {
29
+ current: T;
30
+ }
31
+
32
+ export interface FileCacheDeps {
33
+ target: FileEditorTarget | null;
34
+ loadedRef: LiveRef<Set<string>>;
35
+ bumpRevision: () => void;
36
+ setContents: (update: (previous: Record<string, string>) => Record<string, string>) => void;
37
+ setBaselines: (update: (previous: Record<string, string>) => Record<string, string>) => void;
38
+ setLineEndings: (update: (previous: Record<string, LineEnding>) => Record<string, LineEnding>) => void;
39
+ setMtimes: (update: (previous: Record<string, number | null>) => Record<string, number | null>) => void;
40
+ setHashes: (update: (previous: Record<string, string | null>) => Record<string, string | null>) => void;
41
+ }
42
+
43
+ export interface FileCache {
44
+ /**
45
+ * Store one read's bytes in EVERY cache: the LF buffer, its baseline, the
46
+ * ending it arrived with, the mtime it was read at, and the content hash the
47
+ * disk watcher compares against.
48
+ */
49
+ remember: (fileKey: string, text: string, mtimeMs: number | null, hash: string | null) => void;
50
+ /** Re-read every cached file; a re-render cannot skip a key already marked read. */
51
+ reset: () => void;
52
+ /** Drop every cache entry for a tab that is no longer open. */
53
+ retain: (ids: Array<number | string>) => void;
54
+ /** Change the ending the NEXT save writes. */
55
+ setEol: (eol: LineEnding) => void;
56
+ }
57
+
58
+ export function useFileCache({
59
+ target,
60
+ loadedRef,
61
+ bumpRevision,
62
+ setContents,
63
+ setBaselines,
64
+ setLineEndings,
65
+ setMtimes,
66
+ setHashes,
67
+ }: FileCacheDeps): FileCache {
68
+ const remember = useCallback(
69
+ (fileKey: string, text: string, mtimeMs: number | null, hash: string | null) => {
70
+ // The buffer holds LF only; the style the bytes arrived with is kept beside
71
+ // it so the write can put the file back the way it was found.
72
+ const ending = detectLineEnding(text);
73
+ const lf = toLf(text);
74
+ setContents((previous) => ({ ...previous, [fileKey]: lf }));
75
+ setBaselines((previous) => ({ ...previous, [fileKey]: lf }));
76
+ setLineEndings((previous) => ({ ...previous, [fileKey]: ending }));
77
+ setMtimes((previous) => ({ ...previous, [fileKey]: mtimeMs }));
78
+ setHashes((previous) => ({ ...previous, [fileKey]: hash }));
79
+ },
80
+ [setContents, setBaselines, setLineEndings, setMtimes, setHashes],
81
+ );
82
+
83
+ const reset = useCallback(() => {
84
+ loadedRef.current.clear();
85
+ bumpRevision();
86
+ }, [loadedRef, bumpRevision]);
87
+
88
+ const retain = useCallback(
89
+ (ids: Array<number | string>) => {
90
+ const keep = new Set(ids.map(String));
91
+ for (const loaded of Array.from(loadedRef.current)) {
92
+ if (!keep.has(loaded)) loadedRef.current.delete(loaded);
93
+ }
94
+ setContents((previous) => retainKeys(previous, keep));
95
+ setLineEndings((previous) => retainKeys(previous, keep));
96
+ setMtimes((previous) => retainKeys(previous, keep));
97
+ setHashes((previous) => retainKeys(previous, keep));
98
+ },
99
+ [loadedRef, setContents, setLineEndings, setMtimes, setHashes],
100
+ );
101
+
102
+ // Only the ending moves: the BUFFER is LF-only either way, and the bytes are
103
+ // built at write time, so nothing on screen changes and no re-read is needed.
104
+ const setEol = useCallback(
105
+ (next: LineEnding) => {
106
+ if (!target) return;
107
+ setLineEndings((previous) => ({ ...previous, [editorTargetKey(target)]: next }));
108
+ },
109
+ [target, setLineEndings],
110
+ );
111
+
112
+ return { remember, reset, retain, setEol };
113
+ }
@@ -19,6 +19,7 @@ import {
19
19
  createEditorHarness,
20
20
  freshState,
21
21
  stubFetch,
22
+ stubHash,
22
23
  } from '@/test-support/file-editor.test-util';
23
24
 
24
25
  const editor = createEditorHarness();
@@ -118,6 +119,95 @@ describe('useFileEditor revalidation', () => {
118
119
  });
119
120
  });
120
121
 
122
+ describe('useFileEditor auto-refresh', () => {
123
+ /**
124
+ * Ask the watcher now, the way coming back to the window does.
125
+ *
126
+ * The probe is a promise, so the whole turn runs inside `act` (`runAsync`): a
127
+ * verdict delivered outside it updates state without committing the effects,
128
+ * and the re-read under test is an effect.
129
+ */
130
+ async function focusWindow() {
131
+ await editor.runAsync(async () => {
132
+ window.dispatchEvent(new Event('focus'));
133
+ await new Promise((resolve) => setTimeout(resolve, 0));
134
+ });
135
+ }
136
+
137
+ test('a file changed from outside replaces a CLEAN buffer', async () => {
138
+ const state = freshState();
139
+ stubFetch(state);
140
+ await editor.mount();
141
+ expect(editor.mounted?.content).toBe(DISK);
142
+
143
+ // Another process (an agent's tool call, `git checkout`) rewrote the file.
144
+ state.body = `${DISK}const c = 3;\n`;
145
+ await focusWindow();
146
+
147
+ expect(editor.mounted?.content).toBe(state.body);
148
+ expect(editor.mounted?.isDirty).toBe(false);
149
+ });
150
+
151
+ test('a file rewritten with the SAME bytes does not touch the buffer', async () => {
152
+ const state = freshState();
153
+ stubFetch(state);
154
+ await editor.mount();
155
+ const readsAfterMount = state.reads;
156
+
157
+ // A `touch`, a formatter that changed nothing, a checkout of the revision
158
+ // already open: the mtime moved, the bytes did not.
159
+ await focusWindow();
160
+
161
+ expect(state.reads).toBe(readsAfterMount);
162
+ expect(editor.mounted?.content).toBe(DISK);
163
+ });
164
+
165
+ test('a DIRTY buffer is never replaced — the panel is told instead', async () => {
166
+ const state = freshState();
167
+ stubFetch(state);
168
+ await editor.mount();
169
+
170
+ editor.mounted?.onChange('my own edit');
171
+ await editor.settle();
172
+
173
+ state.body = `${DISK}const c = 3;\n`;
174
+ await focusWindow();
175
+
176
+ expect(editor.mounted?.content).toBe('my own edit');
177
+ expect(editor.mounted?.isDirty).toBe(true);
178
+ // The panel is told, so the external-change strip can offer the two answers.
179
+ expect(editor.mounted?.diskChange?.hash).toBe(stubHash(state.body));
180
+ });
181
+
182
+ test('reloadFromDisk re-reads a clean buffer on demand', async () => {
183
+ const state = freshState();
184
+ stubFetch(state);
185
+ await editor.mount();
186
+ const readsAfterMount = state.reads;
187
+
188
+ state.body = `${DISK}const c = 3;\n`;
189
+ await editor.run(() => editor.mounted?.reloadFromDisk());
190
+ await editor.settle();
191
+
192
+ expect(state.reads).toBe(readsAfterMount + 1);
193
+ expect(editor.mounted?.content).toBe(state.body);
194
+ });
195
+
196
+ test('reloadFromDisk discards a dirty buffer', async () => {
197
+ const state = freshState();
198
+ stubFetch(state);
199
+ await editor.mount();
200
+
201
+ editor.mounted?.onChange('my own edit');
202
+ await editor.settle();
203
+ await editor.run(() => editor.mounted?.reloadFromDisk());
204
+ await editor.settle();
205
+
206
+ expect(editor.mounted?.content).toBe(DISK);
207
+ expect(editor.mounted?.isDirty).toBe(false);
208
+ });
209
+ });
210
+
121
211
  describe('useFileEditor unsupported files', () => {
122
212
  test('a kind refusal reports the server sentence as unsupported', async () => {
123
213
  const state = freshState();