@kabmo-labs/kabmo 0.11.1 → 0.12.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 (324) hide show
  1. package/README.md +67 -421
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +426 -413
  4. package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
  5. package/dist/client/static/js/index-shexbk5f.css +1 -0
  6. package/marketplace/marketplace.json +13 -3
  7. package/marketplace/plugins/command-runner/package.json +4 -2
  8. package/marketplace/plugins/git-forge/README.md +219 -0
  9. package/marketplace/plugins/git-forge/icon.svg +20 -0
  10. package/marketplace/plugins/git-forge/package.json +56 -0
  11. package/marketplace/plugins/git-forge/src/app.tsx +82 -0
  12. package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
  13. package/marketplace/plugins/git-forge/src/command.ts +119 -0
  14. package/marketplace/plugins/git-forge/src/header.tsx +87 -0
  15. package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
  16. package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
  17. package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
  18. package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
  19. package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
  20. package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
  21. package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
  22. package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
  23. package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
  24. package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
  25. package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
  26. package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
  27. package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
  28. package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
  29. package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
  30. package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
  31. package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
  32. package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
  33. package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
  34. package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
  35. package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
  36. package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
  37. package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
  38. package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
  39. package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
  40. package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
  41. package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
  42. package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
  43. package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
  44. package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
  45. package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
  46. package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
  47. package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
  48. package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
  49. package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
  50. package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
  51. package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
  52. package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
  53. package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
  54. package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
  55. package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
  56. package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
  57. package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
  58. package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
  59. package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
  60. package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
  61. package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
  62. package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
  63. package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
  64. package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
  65. package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
  66. package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
  67. package/marketplace/plugins/git-forge/src/server.ts +284 -0
  68. package/marketplace/plugins/git-forge/tsconfig.json +16 -0
  69. package/marketplace/plugins/session-info/package.json +4 -2
  70. package/marketplace/plugins/stats/package.json +4 -2
  71. package/package.json +6 -1
  72. package/src/client/components/common/code-surface/blame-hover.ts +188 -0
  73. package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
  74. package/src/client/components/common/code-surface/blame-panel.ts +306 -0
  75. package/src/client/components/common/code-surface/blame.test.ts +303 -0
  76. package/src/client/components/common/code-surface/blame.ts +227 -0
  77. package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
  78. package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
  79. package/src/client/components/common/code-surface/documents.ts +48 -1
  80. package/src/client/components/common/code-surface/extensions.test.ts +4 -0
  81. package/src/client/components/common/code-surface/extensions.ts +44 -0
  82. package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
  83. package/src/client/components/common/code-surface/indent.test.ts +5 -0
  84. package/src/client/components/common/code-surface/index.tsx +16 -2
  85. package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
  86. package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
  87. package/src/client/components/common/code-surface/lint.test.ts +101 -0
  88. package/src/client/components/common/code-surface/lint.ts +85 -0
  89. package/src/client/components/common/code-surface/props.ts +17 -0
  90. package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
  91. package/src/client/components/common/code-surface/theme.ts +71 -0
  92. package/src/client/components/common/header-controls/index.test.tsx +1 -1
  93. package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
  94. package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
  95. package/src/client/components/common/provider-icon/Plate.tsx +88 -0
  96. package/src/client/components/common/provider-icon/index.tsx +55 -11
  97. package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
  98. package/src/client/components/mobile/SessionSidebar.tsx +2 -10
  99. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
  100. package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
  101. package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
  102. package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
  103. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
  104. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
  105. package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
  106. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
  107. package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
  108. package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
  109. package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
  110. package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
  111. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
  112. package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
  113. package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
  114. package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
  115. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
  116. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
  117. package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
  118. package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
  119. package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
  120. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  121. package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
  122. package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
  123. package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
  124. package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
  125. package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
  126. package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
  127. package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
  128. package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
  129. package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
  130. package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
  131. package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
  132. package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
  133. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
  134. package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
  135. package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
  136. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
  137. package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
  138. package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
  139. package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
  140. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
  141. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
  142. package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
  143. package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
  144. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
  145. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
  146. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
  147. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
  148. package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
  149. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
  150. package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
  151. package/src/client/components/workspace/diff-panel/changes.ts +69 -0
  152. package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
  153. package/src/client/components/workspace/diff-panel/index.tsx +21 -1
  154. package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
  155. package/src/client/components/workspace/diff-panel/merge.ts +63 -68
  156. package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
  157. package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
  158. package/src/client/components/workspace/editor/FilePane.tsx +25 -1
  159. package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
  160. package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
  161. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
  162. package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
  163. package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
  164. package/src/client/components/workspace/git-panel/index.test.ts +46 -1
  165. package/src/client/components/workspace/git-panel/index.tsx +11 -38
  166. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
  167. package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
  168. package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
  169. package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
  170. package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
  171. package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
  172. package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
  173. package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
  174. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
  175. package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
  176. package/src/client/hooks/chat/omp/index.ts +20 -0
  177. package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
  178. package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
  179. package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
  180. package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
  181. package/src/client/hooks/chat/omp/stream.ts +8 -1
  182. package/src/client/hooks/chat/timeline/index.ts +1 -1
  183. package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
  184. package/src/client/hooks/editor/blame-settings.ts +67 -0
  185. package/src/client/hooks/editor/blame.test.ts +272 -0
  186. package/src/client/hooks/editor/blame.ts +232 -0
  187. package/src/client/hooks/editor/file-editor-types.ts +23 -0
  188. package/src/client/hooks/editor/save-file.test.ts +20 -0
  189. package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
  190. package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
  191. package/src/client/hooks/editor/use-editor-drop.ts +19 -36
  192. package/src/client/hooks/editor/use-file-editor.ts +7 -1
  193. package/src/client/hooks/settings/providers/actions.ts +90 -194
  194. package/src/client/hooks/settings/providers/api.ts +7 -1
  195. package/src/client/hooks/settings/providers/index.ts +171 -59
  196. package/src/client/hooks/settings/providers/login.test.ts +79 -0
  197. package/src/client/hooks/settings/providers/login.ts +276 -0
  198. package/src/client/hooks/settings/providers/messages.ts +28 -0
  199. package/src/client/hooks/settings/providers/model-actions.ts +178 -0
  200. package/src/client/hooks/ui/editor-error-toast.ts +47 -0
  201. package/src/client/hooks/ui/open-file.ts +7 -0
  202. package/src/client/hooks/ui/toasts.ts +7 -0
  203. package/src/client/hooks/workspace/file-tabs.ts +4 -1
  204. package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
  205. package/src/client/hooks/workspace/folder-expansion.ts +33 -0
  206. package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
  207. package/src/client/hooks/workspace/git-actions.ts +29 -2
  208. package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
  209. package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
  210. package/src/client/lib/editor-errors.test.ts +85 -0
  211. package/src/client/lib/editor-errors.ts +71 -0
  212. package/src/client/lib/fs/resolve-open.test.ts +125 -0
  213. package/src/client/lib/fs/resolve-open.ts +90 -0
  214. package/src/client/lib/git/action-message.test.ts +82 -0
  215. package/src/client/lib/git/action-message.ts +160 -0
  216. package/src/client/lib/launch/device-files.test.ts +160 -0
  217. package/src/client/lib/launch/device-files.ts +197 -0
  218. package/src/client/lib/native/open-paths.test.ts +140 -0
  219. package/src/client/lib/native/open-paths.ts +157 -0
  220. package/src/client/lib/plugins/bootstrap.test.ts +1 -1
  221. package/src/client/main.tsx +20 -0
  222. package/src/server/db.server.test.ts +39 -0
  223. package/src/server/db.server.ts +21 -2
  224. package/src/server/lib/db/schema.ts +2 -0
  225. package/src/server/lib/fs/external-roots.test.ts +100 -0
  226. package/src/server/lib/fs/external-roots.ts +101 -0
  227. package/src/server/lib/fs/git-actions-branch.ts +15 -2
  228. package/src/server/lib/fs/git-actions-shared.ts +24 -0
  229. package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
  230. package/src/server/lib/fs/git-actions-worktree.ts +5 -1
  231. package/src/server/lib/fs/git-blame.test.ts +206 -0
  232. package/src/server/lib/fs/git-blame.ts +189 -0
  233. package/src/server/lib/fs/root.ts +14 -0
  234. package/src/server/lib/http/same-origin.ts +28 -7
  235. package/src/server/lib/models/catalog.server.ts +230 -0
  236. package/src/server/lib/models/catalog.test.ts +83 -0
  237. package/src/server/lib/models/credential-origin.server.ts +108 -0
  238. package/src/server/lib/models/credential-origin.test.ts +132 -0
  239. package/src/server/lib/models/provider-icon-fetch.ts +115 -0
  240. package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
  241. package/src/server/lib/models/provider-icon-parse.ts +139 -0
  242. package/src/server/lib/models/provider-icon-store.server.ts +118 -0
  243. package/src/server/lib/models/provider-icon-store.test.ts +107 -0
  244. package/src/server/lib/models/provider-icon.server.ts +209 -0
  245. package/src/server/lib/models/provider-items.server.ts +211 -37
  246. package/src/server/lib/models/provider-items.test.ts +201 -0
  247. package/src/server/lib/models/provider-registry.server.test.ts +27 -9
  248. package/src/server/lib/models/provider-registry.server.ts +160 -67
  249. package/src/server/lib/models/registry.server.test.ts +3 -3
  250. package/src/server/lib/models/registry.server.ts +8 -0
  251. package/src/server/lib/omp/config/definitions.test.ts +5 -4
  252. package/src/server/lib/omp/config/models-config.ts +42 -0
  253. package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
  254. package/src/server/lib/omp/config/provider-entry.ts +197 -0
  255. package/src/server/lib/omp/config/provider-seeds.ts +10 -0
  256. package/src/server/lib/omp/core/models-json.ts +69 -0
  257. package/src/server/lib/omp/session/messages.ts +17 -3
  258. package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
  259. package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
  260. package/src/server/lib/panels/catalog-offers.server.ts +68 -0
  261. package/src/server/lib/panels/git-update.server.test.ts +14 -0
  262. package/src/server/lib/panels/git-update.server.ts +63 -1
  263. package/src/server/lib/panels/manifest.test.ts +65 -0
  264. package/src/server/lib/panels/manifest.ts +55 -1
  265. package/src/server/lib/panels/offers.server.test.ts +191 -0
  266. package/src/server/lib/panels/offers.server.ts +108 -0
  267. package/src/server/lib/panels/registry.server.test.ts +35 -1
  268. package/src/server/lib/panels/registry.server.ts +51 -142
  269. package/src/server/lib/panels/scan.server.ts +162 -0
  270. package/src/server/lib/route-adapter.ts +13 -2
  271. package/src/server/lib/tray/tray.test.ts +2 -1
  272. package/src/server/lib/usage/providers.server.ts +4 -1
  273. package/src/server/routes/chat/session.ts +7 -1
  274. package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
  275. package/src/server/routes/fs/git.ts +17 -0
  276. package/src/server/routes/fs/grant.test.ts +135 -0
  277. package/src/server/routes/fs/grant.ts +79 -0
  278. package/src/server/routes/fs/index.ts +2 -0
  279. package/src/server/routes/fs/scope.ts +34 -17
  280. package/src/server/routes/omp/login.ts +41 -14
  281. package/src/server/routes/omp/routes.test.ts +23 -10
  282. package/src/server/routes/settings/index.ts +8 -0
  283. package/src/server/routes/settings/provider-entry.ts +108 -0
  284. package/src/server/routes/settings/provider-icon.ts +99 -0
  285. package/src/server/routes/settings/provider-model.ts +4 -1
  286. package/src/server/routes/settings/provider-refresh.ts +87 -0
  287. package/src/server/routes/settings/providers.ts +31 -2
  288. package/src/shared/lib/chat/omp/fold.test.ts +34 -0
  289. package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
  290. package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
  291. package/src/shared/lib/chat/omp/tool-results.ts +29 -3
  292. package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
  293. package/src/shared/lib/fs/git-blame.test.ts +266 -0
  294. package/src/shared/lib/fs/git-blame.ts +246 -0
  295. package/src/shared/lib/git/url.ts +18 -0
  296. package/src/shared/lib/markdown/sanitize.test.ts +57 -0
  297. package/src/shared/lib/markdown/sanitize.ts +30 -7
  298. package/src/shared/lib/models/provider/connection.ts +135 -0
  299. package/src/shared/lib/models/provider/dialect.test.ts +4 -2
  300. package/src/shared/lib/models/provider/dialect.ts +76 -6
  301. package/src/shared/lib/models/provider/models.ts +2 -0
  302. package/src/shared/lib/models/provider/origin.ts +94 -0
  303. package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
  304. package/src/shared/lib/models/server-cache.ts +8 -3
  305. package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
  306. package/src/shared/lib/omp/session/messages-map.ts +34 -2
  307. package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
  308. package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
  309. package/src/shared/lib/omp/session/prewarm.ts +23 -1
  310. package/src/shared/lib/omp/session/wait.test.ts +28 -0
  311. package/src/shared/lib/omp/session/wait.ts +38 -3
  312. package/src/shared/lib/panels/slot-labels.test.ts +61 -0
  313. package/src/shared/lib/panels/slot-labels.ts +133 -0
  314. package/src/shared/lib/workspace/panel-ids.ts +11 -0
  315. package/src/shared/types/fs.ts +6 -0
  316. package/src/shared/types/index.ts +1 -0
  317. package/src/shared/types/models.ts +12 -0
  318. package/src/shared/types/panels-registry.ts +277 -0
  319. package/src/shared/types/panels.ts +46 -213
  320. package/src/shared/types/settings/provider.ts +58 -0
  321. package/src/shared/types/settings/usage.ts +10 -0
  322. package/src/test-support/pristine-globals.ts +7 -0
  323. package/dist/client/static/js/index-bq6qeayr.css +0 -1
  324. package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
@@ -27,7 +27,7 @@ import { OPERATION_LABELS } from '@/shared/lib/fs/git-unmerged';
27
27
  import { continueArgsFor, mergeBranch, resolveConflict, type ConflictSide } from '@/server/lib/fs/git-merge';
28
28
  import { deleteBranch, renameBranch } from '@/server/lib/fs/git-branch';
29
29
  import { applyStash, dropStash, pushStash } from '@/server/lib/fs/git-stash';
30
- import { expectOk, field, fileForAction, flag, type GitActionHandler } from '@/server/lib/fs/git-actions-shared';
30
+ import { expectOk, field, fileForAction, flag, stoppedOperationPayload, type GitActionHandler } from '@/server/lib/fs/git-actions-shared';
31
31
 
32
32
  /**
33
33
  * Refuse an action git will not accept while a conflict is unresolved.
@@ -50,6 +50,9 @@ export const GIT_BRANCH_ACTIONS: Record<string, GitActionHandler> = {
50
50
  // By NAME, not by hash: `git merge <sha>` writes `Merge commit '<sha>'`
51
51
  // where `git merge <branch>` writes `Merge branch '<name>'` (measured).
52
52
  await mergeBranch(targetDir, field(formData, 'branch'));
53
+ // A merge that stops on a conflict SUCCEEDS and leaves the tree to the
54
+ // operation bar, so the panel's toast must not claim it merged.
55
+ return stoppedOperationPayload(targetDir);
53
56
  },
54
57
 
55
58
  async abort_operation({ targetDir }) {
@@ -99,6 +102,10 @@ export const GIT_BRANCH_ACTIONS: Record<string, GitActionHandler> = {
99
102
  async pull({ targetDir }) {
100
103
  await pullBranch(targetDir);
101
104
  markRemoteRefsFresh(targetDir);
105
+ // `pullBranch` stands down on a branch with no upstream (nothing to pull is
106
+ // not a failure) and accepts a merge that stopped on a conflict — the
107
+ // second leaves the tree to the operation bar, and the toast says so.
108
+ return stoppedOperationPayload(targetDir);
102
109
  },
103
110
 
104
111
  async sync({ targetDir }) {
@@ -118,12 +125,14 @@ export const GIT_BRANCH_ACTIONS: Record<string, GitActionHandler> = {
118
125
  // remote contains work…") and the route would report a failed Sync over a
119
126
  // conflict the panel is about to offer to resolve. The operation bar is
120
127
  // the surface that has to be reached, so the push is skipped and the
121
- // working tree is left exactly as the pull left it.
128
+ // working tree is left exactly as the pull left it — and the answer says
129
+ // which operation is now waiting, because nothing was pushed.
122
130
  const after = await readGitState(targetDir);
123
131
  if (!after.operation) await pushBranch(targetDir);
124
132
  // Both commands already moved the tracking ref; the next read must not
125
133
  // fetch again to see a state it just produced.
126
134
  markRemoteRefsFresh(targetDir);
135
+ return after.operation ? { success: true, stopped: after.operation } : undefined;
127
136
  },
128
137
 
129
138
  async rename_branch({ formData, targetDir }) {
@@ -157,6 +166,10 @@ export const GIT_BRANCH_ACTIONS: Record<string, GitActionHandler> = {
157
166
  ref: field(formData, 'ref') || 'stash@{0}',
158
167
  pop: flag(formData, 'pop'),
159
168
  });
169
+ // A conflicting `git stash pop` leaves its conflicts in the working tree
170
+ // with no operation file at all (`stash-pop`), so the toast must not claim
171
+ // the stash was popped cleanly.
172
+ return stoppedOperationPayload(targetDir);
160
173
  },
161
174
 
162
175
  async stash_drop({ formData, targetDir }) {
@@ -15,6 +15,8 @@
15
15
  */
16
16
 
17
17
  import { repoRelative, resolveRepoPath, runGit } from '@/server/lib/fs/git-run';
18
+ import { readGitState } from '@/server/lib/fs/git-state';
19
+ import type { GitOperation } from '@/shared/types';
18
20
 
19
21
  export interface GitActionContext {
20
22
  formData: FormData;
@@ -84,3 +86,25 @@ export function field(formData: FormData, name: string): string {
84
86
  export function flag(formData: FormData, name: string): boolean {
85
87
  return formData.get(name) === '1';
86
88
  }
89
+
90
+ /**
91
+ * The answer an action that can START an operation returns: whether one is now
92
+ * stopped on a conflict.
93
+ *
94
+ * `git merge`, `cherry-pick`, `revert`, `rebase` and `git pull` exit zero (or
95
+ * with the conflict left behind) and leave the tree in a state the operation bar
96
+ * owns — so the action SUCCEEDED, but what it did is not what its verb promised.
97
+ * The panel says so in its toast, which is why the name travels back: "Merged
98
+ * feature" over a merge that stopped on a conflict claims an outcome git never
99
+ * produced. A conflicting `git stash pop` reports `stash-pop` here too, from the
100
+ * conflicts it leaves with no operation file at all.
101
+ *
102
+ * `undefined` — the handler's "success, nothing to report" — when the tree is
103
+ * clean afterwards, so an ordinary merge answers exactly what it used to.
104
+ */
105
+ export async function stoppedOperationPayload(
106
+ targetDir: string,
107
+ ): Promise<{ success: true; stopped: GitOperation } | undefined> {
108
+ const state = await readGitState(targetDir);
109
+ return state.operation ? { success: true, stopped: state.operation } : undefined;
110
+ }
@@ -99,10 +99,18 @@ function counts(cwd: string): string {
99
99
  return git(cwd, 'rev-list', '--count', '--left-right', 'HEAD...@{upstream}').trim();
100
100
  }
101
101
 
102
- /** One sync, through the same handler the route dispatches. */
103
- async function sync(cwd: string): Promise<void> {
102
+ /**
103
+ * One sync, through the same handler the route dispatches.
104
+ *
105
+ * The ANSWER is returned rather than dropped: it carries `stopped` — the
106
+ * operation a pull left behind — which is what the panel's toast reads to avoid
107
+ * reporting "Synced" over a merge that stopped on a conflict.
108
+ */
109
+ async function sync(cwd: string): Promise<{ success: true; stopped?: string } | undefined> {
104
110
  const handler = GIT_BRANCH_ACTIONS.sync;
105
- await handler({ formData: new FormData(), targetDir: cwd });
111
+ return (await handler({ formData: new FormData(), targetDir: cwd })) as
112
+ | { success: true; stopped?: string }
113
+ | undefined;
106
114
  }
107
115
 
108
116
  afterAll(() => {
@@ -117,9 +125,9 @@ describe('the sync action', () => {
117
125
  git(clone, 'fetch', '-q');
118
126
  expect(counts(clone)).toBe('1\t1');
119
127
 
120
- await sync(clone);
121
-
122
- // Both sides landed and the remote has them: nothing ahead or behind.
128
+ // A clean reconcile reports NOTHING stopped, so the panel toasts plain
129
+ // success rather than a conflict that is not there.
130
+ expect(await sync(clone)).toBeUndefined();
123
131
  expect(counts(clone)).toBe('0\t0');
124
132
  expect(fs.existsSync(path.join(clone, 'other.txt'))).toBe(true);
125
133
  expect(git(clone, 'log', '-1', '--pretty=%s')).toContain('Merge branch');
@@ -133,8 +141,11 @@ describe('the sync action', () => {
133
141
 
134
142
  // The pull exits 1 with MERGE_HEAD in place; the handler must treat that as
135
143
  // the state to show, not as a failure.
136
- await sync(clone);
144
+ const answer = await sync(clone);
137
145
 
146
+ // ...and must SAY which operation is waiting, because the push never ran:
147
+ // the panel's toast would otherwise report a sync that did not publish.
148
+ expect(answer).toEqual({ success: true, stopped: 'merge' });
138
149
  expect(fs.existsSync(path.join(clone, '.git', 'MERGE_HEAD'))).toBe(true);
139
150
  expect(git(clone, 'status', '--porcelain=v1')).toContain('UU seed.txt');
140
151
  });
@@ -35,7 +35,7 @@ import {
35
35
  revertCommit,
36
36
  } from '@/server/lib/fs/git-merge';
37
37
  import { fetchCommitsPage, fetchDiffActions } from '@/server/lib/fs/git-actions-history';
38
- import { expectOk, field, fileForAction, hashFor, refExists, type GitActionHandler } from '@/server/lib/fs/git-actions-shared';
38
+ import { expectOk, field, fileForAction, hashFor, refExists, stoppedOperationPayload, type GitActionHandler } from '@/server/lib/fs/git-actions-shared';
39
39
 
40
40
  /**
41
41
  * Checkout a branch, a remote-tracking ref or a commit.
@@ -189,14 +189,17 @@ export const GIT_WORKTREE_ACTIONS: Record<string, GitActionHandler> = {
189
189
 
190
190
  async merge_commit({ formData, targetDir }) {
191
191
  await mergeCommit(targetDir, hashFor(formData));
192
+ return stoppedOperationPayload(targetDir);
192
193
  },
193
194
 
194
195
  async cherry_pick({ formData, targetDir }) {
195
196
  await cherryPick(targetDir, hashFor(formData));
197
+ return stoppedOperationPayload(targetDir);
196
198
  },
197
199
 
198
200
  async revert_commit({ formData, targetDir }) {
199
201
  await revertCommit(targetDir, hashFor(formData));
202
+ return stoppedOperationPayload(targetDir);
200
203
  },
201
204
 
202
205
  async reset_commit({ formData, targetDir }) {
@@ -206,5 +209,6 @@ export const GIT_WORKTREE_ACTIONS: Record<string, GitActionHandler> = {
206
209
 
207
210
  async rebase_commit({ formData, targetDir }) {
208
211
  await rebaseOnto(targetDir, hashFor(formData));
212
+ return stoppedOperationPayload(targetDir);
209
213
  },
210
214
  };
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Blame against a REAL repository on a temp disk.
8
+ *
9
+ * A stubbed `git` would prove nothing here: every branch this module has is a
10
+ * sentence git itself produced (measured — `fatal: no such path 'x' in HEAD`
11
+ * for an untracked file, `fatal: Needed a single revision` for an unborn HEAD,
12
+ * `fatal: not a git repository (or any of the parent directories)` outside a
13
+ * repository), and the cache key is a fact about the FILESYSTEM, not about the
14
+ * call. So each case builds a repository, commits, and asks.
15
+ */
16
+
17
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
18
+ import { mkdtempSync, rmSync, writeFileSync } from 'fs';
19
+ import { tmpdir } from 'os';
20
+ import { join } from 'path';
21
+
22
+ import { readBlame, readBlameHistory, resetBlameCache } from '@/server/lib/fs/git-blame';
23
+ import { isUncommittedSha } from '@/shared/lib/fs/git-blame';
24
+
25
+ let root: string;
26
+
27
+ function git(cwd: string, args: string[]): void {
28
+ const result = Bun.spawnSync({
29
+ cmd: ['git', ...args],
30
+ cwd,
31
+ env: {
32
+ ...Bun.env,
33
+ GIT_AUTHOR_NAME: 'Ada Lovelace',
34
+ GIT_AUTHOR_EMAIL: 'ada@example.com',
35
+ GIT_COMMITTER_NAME: 'Ada Lovelace',
36
+ GIT_COMMITTER_EMAIL: 'ada@example.com',
37
+ GIT_AUTHOR_DATE: '2023-11-14T22:13:20Z',
38
+ GIT_COMMITTER_DATE: '2023-11-14T22:13:20Z',
39
+ },
40
+ stdout: 'ignore',
41
+ stderr: 'pipe',
42
+ });
43
+ if (result.exitCode !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`);
44
+ }
45
+
46
+ beforeAll(() => {
47
+ root = mkdtempSync(join(tmpdir(), 'kabmo-blame-'));
48
+ });
49
+
50
+ afterAll(() => {
51
+ rmSync(root, { recursive: true, force: true });
52
+ });
53
+
54
+ /** A fresh repository with one committed file, per test. */
55
+ function repo(name: string, files: Record<string, string>): string {
56
+ const dir = join(root, name);
57
+ mkdtempSync(join(root, `${name}-`));
58
+ Bun.spawnSync({ cmd: ['mkdir', '-p', dir] });
59
+ git(dir, ['init', '-q', '-b', 'main']);
60
+ for (const [path, body] of Object.entries(files)) writeFileSync(join(dir, path), body);
61
+ git(dir, ['add', '.']);
62
+ git(dir, ['commit', '-q', '-m', 'feat: the first commit']);
63
+ return dir;
64
+ }
65
+
66
+ describe('readBlame', () => {
67
+ test('attributes every line and reports the line count', async () => {
68
+ const dir = repo('basic', { 'a.ts': 'one\ntwo\nthree\n' });
69
+ const payload = await readBlame(dir, 'a.ts');
70
+
71
+ expect(payload.available).toBe(true);
72
+ expect(payload.lines).toBe(3);
73
+ expect(payload.runs).toEqual([{ from: 1, to: 3, sha: payload.head! }]);
74
+ const commit = payload.commits[payload.head!];
75
+ expect(commit.author).toBe('Ada Lovelace');
76
+ expect(commit.summary).toBe('feat: the first commit');
77
+ // 2023-11-14T22:13:20Z, and the fixture pins the date so this is exact.
78
+ expect(commit.time).toBe(1700000000);
79
+ });
80
+
81
+ test('a later commit splits the runs, and the older lines keep their author', async () => {
82
+ const dir = repo('two-commits', { 'b.ts': 'one\ntwo\nthree\n' });
83
+ writeFileSync(join(dir, 'b.ts'), 'one\nTWO\nthree\n');
84
+ git(dir, ['commit', '-q', '-am', 'fix: change the middle line']);
85
+
86
+ const payload = await readBlame(dir, 'b.ts');
87
+ expect(payload.runs).toHaveLength(3);
88
+ const middle = payload.runs[1];
89
+ expect(middle.from).toBe(2);
90
+ expect(payload.commits[middle.sha].summary).toBe('fix: change the middle line');
91
+ expect(payload.commits[payload.runs[0].sha].summary).toBe('feat: the first commit');
92
+ });
93
+
94
+ test('a line in the working tree that HEAD does not have is the all-zero sha', async () => {
95
+ const dir = repo('dirty', { 'c.ts': 'one\ntwo\n' });
96
+ // Three lines on disk, two in HEAD: line 3 is unattributable.
97
+ writeFileSync(join(dir, 'c.ts'), 'one\ntwo\nthree\n');
98
+
99
+ const payload = await readBlame(dir, 'c.ts');
100
+ expect(payload.available).toBe(true);
101
+ const last = payload.runs[payload.runs.length - 1];
102
+ expect(last.to).toBe(3);
103
+ expect(isUncommittedSha(last.sha)).toBe(true);
104
+ });
105
+
106
+ test('an untracked file is answered, not thrown', async () => {
107
+ const dir = repo('untracked', { 'kept.ts': 'x\n' });
108
+ writeFileSync(join(dir, 'new.ts'), 'x\n');
109
+
110
+ const payload = await readBlame(dir, 'new.ts');
111
+ expect(payload.available).toBe(false);
112
+ expect(payload.reason).toBe('untracked');
113
+ expect(payload.message).toContain('no such path');
114
+ });
115
+
116
+ test('a directory that is not a repository says so', async () => {
117
+ const dir = join(root, 'plain');
118
+ Bun.spawnSync({ cmd: ['mkdir', '-p', dir] });
119
+ writeFileSync(join(dir, 'x.ts'), 'x\n');
120
+
121
+ const payload = await readBlame(dir, 'x.ts');
122
+ expect(payload.available).toBe(false);
123
+ expect(payload.reason).toBe('not-repo');
124
+ });
125
+
126
+ test('an empty file has no lines rather than an empty answer', async () => {
127
+ const dir = repo('empty', { 'e.ts': '' });
128
+ const payload = await readBlame(dir, 'e.ts');
129
+ expect(payload.available).toBe(false);
130
+ expect(payload.reason).toBe('empty');
131
+ });
132
+
133
+ test('a path escaping the repository is refused before git sees it', async () => {
134
+ const dir = repo('escape', { 'a.ts': 'x\n' });
135
+ const payload = await readBlame(dir, '../../etc/passwd');
136
+ expect(payload.available).toBe(false);
137
+ expect(payload.reason).toBe('error');
138
+ expect(payload.message).toBe('Invalid path');
139
+ });
140
+
141
+ test('the second read is served from the cache, and a commit invalidates it', async () => {
142
+ const dir = repo('cache', { 'a.ts': 'one\ntwo\n' });
143
+ resetBlameCache();
144
+
145
+ const first = await readBlame(dir, 'a.ts');
146
+ expect(first.head).toBeTruthy();
147
+ // A different HEAD must not be served the previous answer: every line's
148
+ // author can change with one commit, which is what the key carries.
149
+ writeFileSync(join(dir, 'a.ts'), 'one\ntwo\nthree\n');
150
+ git(dir, ['commit', '-q', '-am', 'feat: a third line']);
151
+
152
+ const second = await readBlame(dir, 'a.ts');
153
+ expect(second.head).not.toBe(first.head);
154
+ expect(second.lines).toBe(3);
155
+ });
156
+
157
+ test('an edit on disk invalidates it even with HEAD unmoved', async () => {
158
+ const dir = repo('mtime', { 'a.ts': 'one\ntwo\n' });
159
+ resetBlameCache();
160
+ const first = await readBlame(dir, 'a.ts');
161
+ expect(first.lines).toBe(2);
162
+
163
+ // The autosave path: the file grows, HEAD does not move, and line 3 has no
164
+ // attribution — a cached payload would report a 2-line file forever.
165
+ writeFileSync(join(dir, 'a.ts'), 'one\ntwo\nthree\n');
166
+ const second = await readBlame(dir, 'a.ts');
167
+ expect(second.lines).toBe(3);
168
+ });
169
+ });
170
+
171
+ describe('readBlameHistory', () => {
172
+ test('lists every commit that touched the line, newest first', async () => {
173
+ const dir = repo('history', { 'a.ts': 'alpha\nbeta\ngamma\n' });
174
+ writeFileSync(join(dir, 'a.ts'), 'alpha\nBETA\ngamma\n');
175
+ git(dir, ['commit', '-q', '-am', 'fix: the middle again']);
176
+
177
+ const history = await readBlameHistory(dir, 'a.ts', 2);
178
+ expect(history.entries.length).toBe(2);
179
+ expect(history.entries[0].summary).toBe('fix: the middle again');
180
+ expect(history.entries[1].summary).toBe('feat: the first commit');
181
+ expect(history.entries[0].author).toBe('Ada Lovelace');
182
+ expect(history.truncated).toBe(false);
183
+ });
184
+
185
+ test('a line no commit touched is the single commit that created it', async () => {
186
+ const dir = repo('history-one', { 'a.ts': 'alpha\nbeta\n' });
187
+ const history = await readBlameHistory(dir, 'a.ts', 1);
188
+ expect(history.entries.map((entry) => entry.summary)).toEqual(['feat: the first commit']);
189
+ });
190
+
191
+ test('a line past the end of the file is empty, not an error', async () => {
192
+ const dir = repo('history-past', { 'a.ts': 'alpha\n' });
193
+ expect(await readBlameHistory(dir, 'a.ts', 99)).toEqual({ entries: [], truncated: false });
194
+ });
195
+
196
+ test('a non-positive line is refused without spawning git', async () => {
197
+ const dir = repo('history-bad', { 'a.ts': 'alpha\n' });
198
+ expect(await readBlameHistory(dir, 'a.ts', 0)).toEqual({ entries: [], truncated: false });
199
+ expect(await readBlameHistory(dir, 'a.ts', 1.5)).toEqual({ entries: [], truncated: false });
200
+ });
201
+
202
+ test('a file outside the repository is refused', async () => {
203
+ const dir = repo('history-escape', { 'a.ts': 'alpha\n' });
204
+ expect(await readBlameHistory(dir, '../outside.ts', 1)).toEqual({ entries: [], truncated: false });
205
+ });
206
+ });
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Line blame for the editor, and the line's own history.
8
+ *
9
+ * ## One read for the WHOLE file, never one per hover
10
+ *
11
+ * `git blame -L n,n` costs a spawn (measured 10–20 ms warm, 39 ms average over
12
+ * 20 sequential calls), and a reader hovers a dozen lines in a minute. The
13
+ * whole-file read costs 30–110 ms ONCE and then answers every line from memory:
14
+ * `--porcelain` reports each commit's metadata a single time (295 content lines
15
+ * carried 5 `author` records on a 336-line file), so the payload is already
16
+ * compressed — 34 KB raw for that file, 10 KB after the parse drops the
17
+ * document text it does not need.
18
+ *
19
+ * The cost that has to be bounded is the OUTPUT, not the parse: `--porcelain`
20
+ * on a 20 000-line file is 1.7 MB and `--line-porcelain` is 5.4 MB, while
21
+ * `runGit` defaults to a 1 MiB `maxBuffer` — which would TRUNCATE the answer
22
+ * silently and leave the bottom of the file with no attribution at all.
23
+ *
24
+ * ## The cache key is the answer
25
+ *
26
+ * A blame is only true for one (file contents, HEAD) pair. The key carries the
27
+ * file's mtime — Kabmo's autosave rewrites it, which shifts every line number —
28
+ * and the resolved HEAD sha, because a commit made by the agent while the panel
29
+ * is open changes every answer. Neither is optional: keying on the path alone
30
+ * serves the previous commit's authors for the current file.
31
+ */
32
+
33
+ import {
34
+ parseBlameHistory,
35
+ parseBlamePorcelain,
36
+ type BlameHistory,
37
+ type BlamePayload,
38
+ type BlameUnavailable,
39
+ } from '@/shared/lib/fs/git-blame';
40
+ import { repoRelative, resolveRepoPath, runGit } from '@/server/lib/fs/git-run';
41
+
42
+ /** Past this a blame is refused: 20 000 lines already costs 0.5 s and 1.7 MB. */
43
+ const MAX_BLAME_BYTES = 8 * 1024 * 1024;
44
+ /** `--porcelain` measured 1.7 MB at 20 000 lines; 16 MiB is headroom, not a guess. */
45
+ const MAX_BLAME_OUTPUT = 16 * 1024 * 1024;
46
+ const BLAME_TIMEOUT_MS = 15_000;
47
+ const HISTORY_TIMEOUT_MS = 15_000;
48
+ /** A line touched by more commits than this is a line nobody reads to the end. */
49
+ const HISTORY_LIMIT = 50;
50
+ /** Files kept in memory. One entry is the parse of a whole file. */
51
+ const CACHE_LIMIT = 64;
52
+
53
+ declare global {
54
+ // eslint-disable-next-line no-var
55
+ var __kabmoGitBlame: Map<string, BlamePayload> | undefined;
56
+ }
57
+
58
+ function store(): Map<string, BlamePayload> {
59
+ return (globalThis.__kabmoGitBlame ??= new Map());
60
+ }
61
+
62
+ function cached(key: string): BlamePayload | undefined {
63
+ const map = store();
64
+ const hit = map.get(key);
65
+ if (!hit) return undefined;
66
+ // Re-insert so the LRU drop takes the entry nobody has asked for in longest.
67
+ map.delete(key);
68
+ map.set(key, hit);
69
+ return hit;
70
+ }
71
+
72
+ function remember(key: string, payload: BlamePayload): void {
73
+ const map = store();
74
+ map.set(key, payload);
75
+ while (map.size > CACHE_LIMIT) {
76
+ const oldest = map.keys().next();
77
+ if (oldest.done) return;
78
+ map.delete(oldest.value);
79
+ }
80
+ }
81
+
82
+ /** Drop every cached answer. The test seam, and what a reload engine calls. */
83
+ export function resetBlameCache(): void {
84
+ store().clear();
85
+ }
86
+
87
+ function unavailable(reason: BlameUnavailable, message?: string): BlamePayload {
88
+ return { available: false, head: null, lines: 0, runs: [], commits: {}, reason, message };
89
+ }
90
+
91
+ /**
92
+ * Blame every line of `file` against HEAD.
93
+ *
94
+ * `file` is repo-relative, exactly as the diff panel names it; a path that
95
+ * resolves outside `targetDir` is refused before git sees it.
96
+ */
97
+ export async function readBlame(targetDir: string, file: string): Promise<BlamePayload> {
98
+ const rel = repoRelative(file);
99
+ const absolute = resolveRepoPath(targetDir, rel);
100
+ if (!absolute) return unavailable('error', 'Invalid path');
101
+
102
+ let stat: { size: number; mtime: Date };
103
+ try {
104
+ stat = await Bun.file(absolute).stat();
105
+ } catch {
106
+ // A tab whose file was deleted: the answer is "there is nothing to blame",
107
+ // not a failure — the editor already shows the deleted-file strip.
108
+ return unavailable('untracked', 'This file is not on disk.');
109
+ }
110
+ if (stat.size > MAX_BLAME_BYTES) {
111
+ return unavailable('too-large', `This file is ${(stat.size / (1024 * 1024)).toFixed(1)} MiB — too large to blame.`);
112
+ }
113
+
114
+ // One spawn answers both questions. A repository with no commit and a
115
+ // directory that is not a repository fail differently, and git says which.
116
+ const headResult = await runGit(['rev-parse', '--verify', 'HEAD'], { cwd: targetDir, timeout: 5000 });
117
+ if (headResult.exitCode !== 0 || headResult.error) {
118
+ const stderr = headResult.stderr.trim();
119
+ return unavailable(/not a git repository/i.test(stderr) ? 'not-repo' : 'no-commit', stderr);
120
+ }
121
+ const head = headResult.stdout.trim();
122
+
123
+ const key = `${absolute}\u0000${stat.mtime.getTime()}\u0000${head}`;
124
+ const hit = cached(key);
125
+ if (hit) return hit;
126
+
127
+ const result = await runGit(['blame', '--porcelain', '--', rel], {
128
+ cwd: targetDir,
129
+ timeout: BLAME_TIMEOUT_MS,
130
+ maxBuffer: MAX_BLAME_OUTPUT,
131
+ });
132
+ if (result.exitCode !== 0 || result.error) {
133
+ const stderr = result.stderr.trim();
134
+ if (/not a git repository/i.test(stderr)) return unavailable('not-repo', stderr);
135
+ // An untracked file, a path git cannot resolve, and a repository with an
136
+ // unborn HEAD all land here with git's own sentence.
137
+ if (/no such path|no such file|no such ref|did not match any file/i.test(stderr)) {
138
+ return unavailable('untracked', stderr);
139
+ }
140
+ return unavailable('error', stderr || result.error?.message || 'git blame failed');
141
+ }
142
+
143
+ const { commits, runs } = parseBlamePorcelain(result.stdout);
144
+ if (runs.length === 0) {
145
+ const payload = unavailable('empty', 'git reported no lines for this file.');
146
+ remember(key, payload);
147
+ return payload;
148
+ }
149
+
150
+ const payload: BlamePayload = {
151
+ available: true,
152
+ head,
153
+ // Blame covers the whole file, so the last run's end is the line count.
154
+ lines: runs[runs.length - 1].to,
155
+ runs,
156
+ commits,
157
+ };
158
+ remember(key, payload);
159
+ return payload;
160
+ }
161
+
162
+ /**
163
+ * Every commit that touched `line`, newest first — the "who created it" answer.
164
+ *
165
+ * `git log -L n,n:<file>` follows the line as the file changed, which is why it
166
+ * costs more than a blame (22–78 ms measured, against 10–20 for one blamed
167
+ * line) and why it is a SECOND read the panel asks for only when the reader
168
+ * opens the history: the blame already answers "who touched it last".
169
+ *
170
+ * `-s` suppresses the per-commit patch. Without it the output carries the diff
171
+ * of every step, which the panel never draws.
172
+ */
173
+ export async function readBlameHistory(targetDir: string, file: string, line: number): Promise<BlameHistory> {
174
+ if (!Number.isInteger(line) || line < 1) return { entries: [], truncated: false };
175
+ const rel = repoRelative(file);
176
+ if (!resolveRepoPath(targetDir, rel)) return { entries: [], truncated: false };
177
+
178
+ const result = await runGit(
179
+ ['log', '-L', `${line},${line}:${rel}`, '-s', '--format=%H%x1f%an%x1f%at%x1f%s%x1e'],
180
+ { cwd: targetDir, timeout: HISTORY_TIMEOUT_MS, maxBuffer: 4 * 1024 * 1024 },
181
+ );
182
+ // A line past the end of the file, a file that is not in HEAD, and a
183
+ // repository with no commits all exit non-zero. Each means "no history for
184
+ // this line", which the panel words; none of them is a failure to report.
185
+ if (result.exitCode !== 0 || result.error) return { entries: [], truncated: false };
186
+
187
+ const entries = parseBlameHistory(result.stdout);
188
+ return { entries: entries.slice(0, HISTORY_LIMIT), truncated: entries.length > HISTORY_LIMIT };
189
+ }
@@ -15,6 +15,7 @@ import path from 'path';
15
15
  import { getDb } from '@/server/db.server';
16
16
  import { pathExists } from '@/server/lib/omp/core/paths';
17
17
  import { canonicalPath } from '@/server/lib/fs/canonical';
18
+ import { externalRoots, isExternalRoot } from '@/server/lib/fs/external-roots';
18
19
  import { resolveProjectRoot } from '@/server/lib/omp/core/worktree';
19
20
 
20
21
  const APP_ROOT = process.cwd();
@@ -51,6 +52,9 @@ export async function resolveReferencedPath(rawPath: string): Promise<string | n
51
52
  return (await pathExists(resolved)) ? resolved : null;
52
53
  }
53
54
 
55
+ // A directory the user dropped a file from (see `external-roots.ts`).
56
+ if (isExternalRoot(path.dirname(resolved)) && (await pathExists(resolved))) return resolved;
57
+
54
58
  try {
55
59
  const db = await getDb();
56
60
  const rows = (await db.all(
@@ -89,6 +93,10 @@ export async function resolveScopeForAbsolutePath(rawPath: string): Promise<{ ro
89
93
  const roots: string[] = [];
90
94
 
91
95
  if (isWithinRoot(APP_ROOT, resolved)) roots.push(APP_ROOT);
96
+ // A dropped file's own directory, granted by the gesture that dropped it.
97
+ for (const granted of externalRoots()) {
98
+ if (isWithinRoot(granted, resolved)) roots.push(granted);
99
+ }
92
100
 
93
101
  try {
94
102
  const db = await getDb();
@@ -153,6 +161,12 @@ export async function resolveRoot(
153
161
  return resolved;
154
162
  }
155
163
 
164
+ // A directory the user DROPPED a file from. `external-roots.ts` holds the
165
+ // rules; the gesture is what created it, and it is checked before the
166
+ // database because a drop outside every workspace is the case this exists
167
+ // for — the DB read would be a round trip that always answers no.
168
+ if (isExternalRoot(resolved)) return resolved;
169
+
156
170
  // Registered workspaces are user-opted project roots — allow exact matches,
157
171
  // compared by canonical path so a `/tmp` vs `/private/tmp` spelling of one
158
172
  // directory is not read as two.
@@ -4,16 +4,37 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Origin check for WebSocket upgrades.
7
+ * "Did this request come from a page this console served?"
8
8
  *
9
- * A WebSocket upgrade carries the page's `Origin`, and no preflight protects
10
- * it: browsers happily open a socket to `localhost` from any page it loads, so
11
- * without this check a cross-origin page could drive a shell on this machine
12
- * (the terminal PTY) or trigger real work (dictation's model download and
13
- * decode). Requests without an Origin — curl, tests — are allowed: they are not
14
- * a browser being tricked into dialing localhost.
9
+ * One rule with two callers, because the two need it for the same reason: a
10
+ * browser will happily send a cross-origin request to `localhost`, and a
11
+ * request that LOOKS like a normal one can still make this machine do work.
12
+ *
13
+ * - **A WebSocket upgrade** (`isSameOriginUpgrade`): no preflight protects an
14
+ * upgrade, so without the check a cross-origin page could drive the terminal
15
+ * PTY or trigger dictation's model download.
16
+ * - **A mutating route with a lasting side effect** (`isSameOriginRequest`): a
17
+ * `no-cors` POST reaches localhost without the page reading the answer, which
18
+ * is enough for a request whose point is the EFFECT — `POST /api/fs/grant`
19
+ * widens what the console may read.
20
+ *
21
+ * Requests without an Origin — curl, a test, a native shell's own HTTP client —
22
+ * are allowed: they are not a browser being tricked into dialing localhost.
15
23
  */
16
24
  export function isSameOriginUpgrade(request: Request): boolean {
25
+ return isSameOriginRequest(request);
26
+ }
27
+
28
+ /**
29
+ * The same test, for an ordinary request.
30
+ *
31
+ * A mutating route that changes what the console may READ needs it too: a
32
+ * cross-origin page can fire a `no-cors` POST at localhost without reading the
33
+ * answer, and a grant registered as a side effect would be live for every
34
+ * same-origin caller afterwards. The check is the `Origin` header, which a
35
+ * browser sets on every cross-origin POST and cannot be forged from a page.
36
+ */
37
+ export function isSameOriginRequest(request: Request): boolean {
17
38
  const origin = request.headers.get('origin');
18
39
  if (!origin) return true;
19
40
  const host = request.headers.get('host');