@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
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The git loader's blame branches, driven through the real handler.
8
+ *
9
+ * The editor asks by QUERY PARAMETER (`?blame=1`, `?blameHistory=1&line=N`), so
10
+ * a renamed parameter does not fail loudly — the branch never runs, the panel
11
+ * shows nothing, and every line of every file looks unattributed. That is the
12
+ * same class of silent failure `git-loader.test.ts` pins for the amend draft,
13
+ * and it is why the contract is asserted here rather than only in a browser.
14
+ *
15
+ * `file` is REPO-relative (the same shape `?fileDiff=1` takes), so the nested
16
+ * case is the one that proves the scope: a path read against the wrong
17
+ * repository resolves to nothing and the answer is an empty history.
18
+ */
19
+
20
+ import { afterAll, describe, expect, test } from 'bun:test';
21
+ import fs from 'node:fs';
22
+ import path from 'node:path';
23
+ import { loader } from '@/server/routes/fs/git';
24
+ import type { BlameHistory, BlamePayload } from '@/shared/lib/fs/git-blame';
25
+ import { removeDir } from '@/test-support/remove-dir';
26
+
27
+ /** Inside the app root, because `resolveRoot` only honors that or a workspace. */
28
+ const FIXTURE_ROOT = path.join(process.cwd(), 'tmp-test-git-blame');
29
+ const repos: string[] = [];
30
+
31
+ function git(cwd: string, ...args: string[]): void {
32
+ const result = Bun.spawnSync({
33
+ cmd: ['git', ...args],
34
+ cwd,
35
+ env: {
36
+ ...Bun.env,
37
+ GIT_EDITOR: 'true',
38
+ GIT_AUTHOR_NAME: 'Ada Lovelace',
39
+ GIT_AUTHOR_EMAIL: 'ada@example.com',
40
+ GIT_COMMITTER_NAME: 'Ada Lovelace',
41
+ GIT_COMMITTER_EMAIL: 'ada@example.com',
42
+ },
43
+ });
44
+ if (result.exitCode !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`);
45
+ }
46
+
47
+ function makeRepo(): string {
48
+ fs.mkdirSync(FIXTURE_ROOT, { recursive: true });
49
+ const dir = fs.mkdtempSync(path.join(FIXTURE_ROOT, 'repo-'));
50
+ repos.push(dir);
51
+ git(dir, 'init', '-q', '-b', 'main');
52
+ fs.writeFileSync(path.join(dir, 'f.ts'), 'alpha\nbeta\ngamma\n');
53
+ git(dir, 'add', '-A');
54
+ git(dir, 'commit', '-q', '-m', 'feat: the first commit');
55
+ return dir;
56
+ }
57
+
58
+ async function read(params: Record<string, string>) {
59
+ const url = new URL('http://localhost/api/fs/git');
60
+ for (const [key, value] of Object.entries(params)) url.searchParams.set(key, value);
61
+ const res = await loader({ request: new Request(url) } as never);
62
+ return { status: res.status, body: (await res.json()) as Record<string, unknown> };
63
+ }
64
+
65
+ afterAll(() => {
66
+ for (const dir of repos) removeDir(dir);
67
+ removeDir(FIXTURE_ROOT);
68
+ });
69
+
70
+ describe('the git loader blame read', () => {
71
+ test('?blame=1 answers the whole file, attributed', async () => {
72
+ const repo = makeRepo();
73
+ const { status, body } = await read({ root: repo, blame: '1', file: 'f.ts' });
74
+ const payload = body as unknown as BlamePayload;
75
+
76
+ expect(status).toBe(200);
77
+ expect(payload.available).toBe(true);
78
+ expect(payload.lines).toBe(3);
79
+ expect(payload.runs).toEqual([{ from: 1, to: 3, sha: payload.head! }]);
80
+ expect(payload.commits[payload.head!].author).toBe('Ada Lovelace');
81
+ expect(payload.commits[payload.head!].summary).toBe('feat: the first commit');
82
+ });
83
+
84
+ test('a file with no history is an answer, not a 4xx', async () => {
85
+ const repo = makeRepo();
86
+ fs.writeFileSync(path.join(repo, 'new.ts'), 'x\n');
87
+ const { status, body } = await read({ root: repo, blame: '1', file: 'new.ts' });
88
+ const payload = body as unknown as BlamePayload;
89
+
90
+ expect(status).toBe(200);
91
+ expect(payload.available).toBe(false);
92
+ expect(payload.reason).toBe('untracked');
93
+ });
94
+
95
+ test('the path is read against the REPO, not the root', async () => {
96
+ const outer = makeRepo();
97
+ const nested = path.join(outer, 'nested');
98
+ fs.mkdirSync(nested);
99
+ git(nested, 'init', '-q', '-b', 'main');
100
+ fs.writeFileSync(path.join(nested, 'f.ts'), 'one\n');
101
+ git(nested, 'add', '-A');
102
+ git(nested, 'commit', '-q', '-m', 'nested commit');
103
+
104
+ const { body } = await read({ root: outer, repo: 'nested', blame: '1', file: 'f.ts' });
105
+ const payload = body as unknown as BlamePayload;
106
+ expect(payload.lines).toBe(1);
107
+ expect(payload.commits[payload.head!].summary).toBe('nested commit');
108
+ });
109
+
110
+ test('a missing file parameter is a 400 rather than a read of the root', async () => {
111
+ const repo = makeRepo();
112
+ const { status, body } = await read({ root: repo, blame: '1' });
113
+ expect(status).toBe(400);
114
+ expect(body.error).toBe('file is required');
115
+ });
116
+
117
+ test('?blameHistory=1 answers the commits that touched one line', async () => {
118
+ const repo = makeRepo();
119
+ fs.writeFileSync(path.join(repo, 'f.ts'), 'alpha\nBETA\ngamma\n');
120
+ git(repo, 'commit', '-q', '-am', 'fix: the middle line');
121
+
122
+ const { status, body } = await read({ root: repo, blameHistory: '1', file: 'f.ts', line: '2' });
123
+ const history = body as unknown as BlameHistory;
124
+
125
+ expect(status).toBe(200);
126
+ expect(history.entries.map((entry) => entry.summary)).toEqual([
127
+ 'fix: the middle line',
128
+ 'feat: the first commit',
129
+ ]);
130
+ expect(history.truncated).toBe(false);
131
+ });
132
+
133
+ test('a line past the end of the file answers an empty history', async () => {
134
+ const repo = makeRepo();
135
+ const { status, body } = await read({ root: repo, blameHistory: '1', file: 'f.ts', line: '99' });
136
+ expect(status).toBe(200);
137
+ expect((body as unknown as BlameHistory).entries).toEqual([]);
138
+ });
139
+
140
+ test('without either parameter the read is still a status payload', async () => {
141
+ const repo = makeRepo();
142
+ const { body } = await read({ root: repo });
143
+ expect(body.branch).toBe('main');
144
+ expect(body.runs).toBeUndefined();
145
+ });
146
+ });
@@ -25,6 +25,7 @@ import { fetchWorkingFileDiff } from '@/server/lib/fs/git-diff';
25
25
  import { repoRelative, resolveRepoPath } from '@/server/lib/fs/git-run';
26
26
  import { parseConflictMarkers } from '@/shared/lib/fs/git-unmerged';
27
27
  import { readGitStatus } from '@/server/lib/fs/git-status-read';
28
+ import { readBlame, readBlameHistory } from '@/server/lib/fs/git-blame';
28
29
  import { listBranchDetails } from '@/server/lib/fs/git-branch';
29
30
  import { listStashes } from '@/server/lib/fs/git-stash';
30
31
  import { GIT_ACTIONS } from '@/server/lib/fs/git-actions';
@@ -137,6 +138,22 @@ export async function loader({ request }: LoaderFunctionArgs) {
137
138
  return json({ success: true, markers: parseConflictMarkers(text) });
138
139
  }
139
140
 
141
+ // The editor's line blame, read on demand.
142
+ //
143
+ // NOT part of the status payload and NOT on the realtime `git:` topic: that
144
+ // topic republishes on every tool call, and a blame is one spawn plus a parse
145
+ // of the whole file. The panel asks for one file when a tab opens, and the
146
+ // server caches the answer per (path, mtime, HEAD).
147
+ if (url.searchParams.get('blame') === '1' || url.searchParams.get('blameHistory') === '1') {
148
+ const file = url.searchParams.get('file') || '';
149
+ if (!file) return json({ error: 'file is required' }, { status: 400 });
150
+ if (url.searchParams.get('blameHistory') === '1') {
151
+ const line = Number(url.searchParams.get('line') || '0');
152
+ return json({ success: true, ...(await readBlameHistory(targetDir, file, line)) });
153
+ }
154
+ return json({ success: true, ...(await readBlame(targetDir, file)) });
155
+ }
156
+
140
157
  // Ahead/behind are only requested by the git panel (`?sync=1`); the
141
158
  // status-only reads (activity bar, file explorer) must not trigger a network
142
159
  // fetch, and must not pay for a count they never read.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * `POST /api/fs/grant` — the one route that lets a DROP widen what the console
8
+ * may read.
9
+ *
10
+ * Every case here is a security property, and each fails silently in the app:
11
+ * a grant that fires for a cross-origin request, or one that names a directory
12
+ * instead of a file, still opens the tab the user asked for — it just also
13
+ * hands out more than the gesture meant.
14
+ */
15
+
16
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
17
+ import fs from 'fs';
18
+ import os from 'os';
19
+ import path from 'path';
20
+ import { action } from '@/server/routes/fs/grant';
21
+ import { resolveFileScope } from '@/server/routes/fs/scope';
22
+ import { clearExternalRoots, externalRoots, isExternalRoot } from '@/server/lib/fs/external-roots';
23
+
24
+ /** A file OUTSIDE the app root and outside every workspace. */
25
+ let outside: string;
26
+ let outsideFile: string;
27
+
28
+ beforeEach(() => {
29
+ clearExternalRoots();
30
+ outside = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-grant-'));
31
+ outsideFile = path.join(outside, 'report.md');
32
+ fs.writeFileSync(outsideFile, '# report\n');
33
+ });
34
+
35
+ afterEach(() => {
36
+ clearExternalRoots();
37
+ fs.rmSync(outside, { recursive: true, force: true });
38
+ });
39
+
40
+ function grantRequest(body: unknown, headers: Record<string, string> = {}): Request {
41
+ return new Request('http://localhost/api/fs/grant', {
42
+ method: 'POST',
43
+ headers: { 'content-type': 'application/json', host: 'localhost', ...headers },
44
+ body: JSON.stringify(body),
45
+ });
46
+ }
47
+
48
+ /** The `code` on a refusal body, narrowed rather than asserted. */
49
+ function refusalCode(body: unknown): string | null {
50
+ if (typeof body !== 'object' || body === null || !('code' in body)) return null;
51
+ return typeof body.code === 'string' ? body.code : null;
52
+ }
53
+
54
+ async function grant(body: unknown, headers: Record<string, string> = {}) {
55
+ const res = await action({ request: grantRequest(body, headers) } as never);
56
+ return { status: res.status, body: (await res.json()) as { root?: string; path?: string; name?: string; error?: string } };
57
+ }
58
+
59
+ describe('fs grant route', () => {
60
+ test('a file outside every workspace is refused by scope, then granted', async () => {
61
+ // The refusal the client retries on, and the reason the retry exists.
62
+ const before = await resolveFileScope({
63
+ request: new Request(`http://localhost/api/fs/scope?path=${encodeURIComponent(outsideFile)}`),
64
+ } as never);
65
+ expect(before.status).toBe(403);
66
+ expect(refusalCode(await before.json())).toBe('outside_workspace');
67
+
68
+ const granted = await grant({ path: outsideFile });
69
+ expect(granted.status).toBe(200);
70
+ expect(granted.body.root).toBe(outside);
71
+ expect(granted.body.path).toBe('report.md');
72
+
73
+ // And the SAME reference now resolves through the ordinary route, which is
74
+ // what makes the retry worth making.
75
+ const after = await resolveFileScope({
76
+ request: new Request(`http://localhost/api/fs/scope?path=${encodeURIComponent(outsideFile)}`),
77
+ } as never);
78
+ expect(after.status).toBe(200);
79
+ });
80
+
81
+ test('the grant is the file’s own DIRECTORY, not its parent', () => {
82
+ return grant({ path: outsideFile }).then(() => {
83
+ expect(isExternalRoot(outside)).toBe(true);
84
+ expect(isExternalRoot(path.dirname(outside))).toBe(false);
85
+ expect(externalRoots()).toEqual([path.resolve(outside)]);
86
+ });
87
+ });
88
+
89
+ test('a folder is refused — a drop of a file is the gesture, and a tab needs one', async () => {
90
+ const { status, body } = await grant({ path: outside });
91
+ expect(status).toBe(400);
92
+ expect(body.error).toContain('folder');
93
+ expect(externalRoots()).toEqual([]);
94
+ });
95
+
96
+ test('a missing file is refused and grants nothing', async () => {
97
+ const { status } = await grant({ path: path.join(outside, 'gone.md') });
98
+ expect(status).toBe(404);
99
+ expect(externalRoots()).toEqual([]);
100
+ });
101
+
102
+ test('a cross-origin request cannot grant', async () => {
103
+ const { status } = await grant({ path: outsideFile }, { origin: 'https://evil.example' });
104
+ expect(status).toBe(403);
105
+ expect(externalRoots()).toEqual([]);
106
+ });
107
+
108
+ test('a same-origin request is accepted, and no Origin at all is too', async () => {
109
+ const same = await grant({ path: outsideFile }, { origin: 'http://localhost' });
110
+ expect(same.status).toBe(200);
111
+ clearExternalRoots();
112
+ // A request with no Origin is curl or a test, never a browser being tricked.
113
+ const none = await grant({ path: outsideFile });
114
+ expect(none.status).toBe(200);
115
+ });
116
+
117
+ test('a GET is refused — the verb is part of the gate', async () => {
118
+ const res = await action({
119
+ request: new Request('http://localhost/api/fs/grant', { method: 'GET' }),
120
+ } as never);
121
+ expect(res.status).toBe(405);
122
+ });
123
+
124
+ test('a relative path is refused', async () => {
125
+ const { status } = await grant({ path: 'report.md' });
126
+ expect(status).toBe(400);
127
+ expect(externalRoots()).toEqual([]);
128
+ });
129
+
130
+ test('a file:// URL names the same file', async () => {
131
+ const { status, body } = await grant({ path: `file://${outsideFile}` });
132
+ expect(status).toBe(200);
133
+ expect(body.path).toBe('report.md');
134
+ });
135
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * POST /api/fs/grant — open a file that lives outside every workspace.
8
+ *
9
+ * Dropping `~/Desktop/report.pdf` on the editor is a real gesture on a real
10
+ * file, and the console used to answer "outside every workspace this console can
11
+ * read": the tab the user asked for was refused for a reason that had nothing to
12
+ * do with the file. This route is the one place that turns such a gesture into a
13
+ * grant — it registers the file's own DIRECTORY (`lib/fs/external-roots.ts`
14
+ * holds the rules and the bounds) and then answers the same scope payload
15
+ * `/api/fs/scope` would have.
16
+ *
17
+ * It is a POST with a JSON body, and that is a security decision rather than a
18
+ * style one:
19
+ *
20
+ * - a cross-origin page can fire a `no-cors` GET or POST at localhost without
21
+ * reading the answer, and a grant is a lasting change to what the console may
22
+ * read — so the same-origin check below is the gate;
23
+ * - a JSON body means the browser sends a preflight for any cross-origin
24
+ * attempt, which the same-origin check then refuses.
25
+ *
26
+ * Only a FILE can grant: a dropped folder has no tab, and registering a
27
+ * directory the user merely hovered over is not a gesture the console should
28
+ * invent.
29
+ */
30
+
31
+ import { json, type ActionFunctionArgs } from '@/server/lib/remix-compat';
32
+ import { errorResponse, methodNotAllowedResponse } from '@/server/lib/route-adapter';
33
+ import { isSameOriginRequest } from '@/server/lib/http/same-origin';
34
+ import { grantExternalRoot } from '@/server/lib/fs/external-roots';
35
+ import { pathFromReference, describeFileReference } from '@/server/routes/fs/scope';
36
+ import fs from 'fs';
37
+ import path from 'path';
38
+
39
+ export async function action({ request }: ActionFunctionArgs): Promise<Response> {
40
+ if (request.method !== 'POST') return methodNotAllowedResponse();
41
+ if (!isSameOriginRequest(request)) {
42
+ return json({ error: 'Cross-origin requests cannot open a file.' }, { status: 403 });
43
+ }
44
+
45
+ let body: { path?: unknown };
46
+ try {
47
+ body = (await request.json()) as typeof body;
48
+ } catch {
49
+ return json({ error: 'Expected a JSON body' }, { status: 400 });
50
+ }
51
+
52
+ const raw = typeof body.path === 'string' ? body.path.trim() : '';
53
+ if (!raw) return json({ error: 'Missing path' }, { status: 400 });
54
+
55
+ const reference = pathFromReference(raw);
56
+ if (!reference) return json({ error: 'Malformed file URL' }, { status: 400 });
57
+ if (!path.isAbsolute(reference)) {
58
+ return json({ error: 'Expected an absolute path' }, { status: 400 });
59
+ }
60
+
61
+ const stat = await fs.promises.stat(reference).catch(() => null);
62
+ if (!stat) return json({ error: 'File not found' }, { status: 404 });
63
+ if (stat.isDirectory()) {
64
+ return json({ error: 'That is a folder, not a file.' }, { status: 400 });
65
+ }
66
+
67
+ // The parent is what becomes readable: a grant names a directory, and the tab
68
+ // needs a root to be `root` + relative path like every other tab.
69
+ const granted = grantExternalRoot(path.dirname(reference));
70
+ if (!granted) {
71
+ return json({ error: 'That directory cannot be opened from here.' }, { status: 400 });
72
+ }
73
+
74
+ try {
75
+ return await describeFileReference(reference);
76
+ } catch (error) {
77
+ return errorResponse(error);
78
+ }
79
+ }
@@ -5,6 +5,7 @@ import { fileExists } from '@/server/routes/fs/exists';
5
5
  import { serveRawFile } from '@/server/routes/fs/raw';
6
6
  import * as fsAction from '@/server/routes/fs/action';
7
7
  import * as fsGit from '@/server/routes/fs/git';
8
+ import * as fsGrant from '@/server/routes/fs/grant';
8
9
  import * as fsReplace from '@/server/routes/fs/replace';
9
10
  import * as fsSearch from '@/server/routes/fs/search';
10
11
  import * as fsValidate from '@/server/routes/fs/validate';
@@ -12,6 +13,7 @@ import * as fsValidate from '@/server/routes/fs/validate';
12
13
  export const fsBindings: HandlerBinding[] = [
13
14
  ...bindingsFor(fsAction, '/api/fs/action'),
14
15
  ...bindingsFor(fsGit, '/api/fs/git'),
16
+ ...bindingsFor(fsGrant, '/api/fs/grant', { mutating: ['POST'] }),
15
17
  ...bindingsFor(fsReplace, '/api/fs/replace'),
16
18
  ...bindingsFor(fsSearch, '/api/fs/search'),
17
19
  ...bindingsFor(fsValidate, '/api/fs/validate'),
@@ -19,6 +19,11 @@
19
19
  * it does not recognise, so answering with a scope the reader will reject is
20
20
  * worse than refusing now — the refusal can name the reason.
21
21
  *
22
+ * A refusal is tagged `code: 'outside_workspace'` rather than being a bare 403,
23
+ * because it is the one refusal the drop path can DO something about: the file
24
+ * exists and the user pointed at it, so `POST /api/fs/grant` may register its
25
+ * directory and the same reference then resolves. Every other 403 here is final.
26
+ *
22
27
  * The file's KIND travels with the answer so the drop target can decline a
23
28
  * binary or oversized file before opening a tab that would only report it.
24
29
  */
@@ -31,35 +36,32 @@ import fs from 'fs';
31
36
  import path from 'path';
32
37
 
33
38
  /** A `file://` URL to the path it names; see `pathFromFileUrl` for the rules. */
34
- function pathFromReference(reference: string): string | null {
39
+ export function pathFromReference(reference: string): string | null {
35
40
  if (!/^file:\/\//i.test(reference)) return reference;
36
41
  return pathFromFileUrl(reference);
37
42
  }
38
43
 
39
- export async function resolveFileScope({ request }: LoaderFunctionArgs) {
40
- const url = new URL(request.url);
41
- const raw = url.searchParams.get('path');
42
- if (!raw) {
43
- return json({ error: 'Missing path' }, { status: 400 });
44
- }
45
-
46
- const reference = pathFromReference(raw);
47
- if (!reference) {
48
- return json({ error: 'Malformed file URL' }, { status: 400 });
49
- }
44
+ /** The sentence a drop shows when the file is real but outside every root. */
45
+ export const OUTSIDE_WORKSPACE_MESSAGE = 'That file is outside every workspace this console can read.';
50
46
 
47
+ /**
48
+ * The scope payload for one absolute reference, or the refusal that names why.
49
+ *
50
+ * Shared by the GET above and by `POST /api/fs/grant`, which registers the
51
+ * directory and then asks this SAME question again — a second copy of the
52
+ * classification is how a granted file and a workspace file end up opening with
53
+ * different kinds.
54
+ */
55
+ export async function describeFileReference(reference: string): Promise<Response> {
51
56
  const scope = await resolveScopeForAbsolutePath(reference);
52
57
  if (!scope) {
53
- return json(
54
- { error: 'That file is outside every workspace this console can read.' },
55
- { status: 403 },
56
- );
58
+ return json({ error: OUTSIDE_WORKSPACE_MESSAGE, code: 'outside_workspace' }, { status: 403 });
57
59
  }
58
60
 
59
61
  const fullPath = path.resolve(scope.root, scope.path);
60
62
  // `Bun.file().exists()` is false for a directory, so a folder dropped on the
61
63
  // editor would be answered "File not found" — true as far as the file is
62
- // concerned, and useless to the user. `statSync` sees either shape, so the
64
+ // concerned, and useless to the user. `stat` sees either shape, so the
63
65
  // refusal can name the folder it actually is.
64
66
  const stat = await fs.promises.stat(fullPath).catch(() => null);
65
67
  if (!stat) {
@@ -93,3 +95,18 @@ export async function resolveFileScope({ request }: LoaderFunctionArgs) {
93
95
  : {}),
94
96
  });
95
97
  }
98
+
99
+ export async function resolveFileScope({ request }: LoaderFunctionArgs) {
100
+ const url = new URL(request.url);
101
+ const raw = url.searchParams.get('path');
102
+ if (!raw) {
103
+ return json({ error: 'Missing path' }, { status: 400 });
104
+ }
105
+
106
+ const reference = pathFromReference(raw);
107
+ if (!reference) {
108
+ return json({ error: 'Malformed file URL' }, { status: 400 });
109
+ }
110
+
111
+ return describeFileReference(reference);
112
+ }
@@ -6,11 +6,25 @@
6
6
  /**
7
7
  * Provider login flow over a dedicated throwaway omp RPC process.
8
8
  *
9
- * POST returns an SSE stream of `extension_ui_request` frames (open_url for
10
- * OAuth, input/confirm for API keys, notify for status). The client replies
11
- * by POSTing `extension_ui_response` frames to the same endpoint; they are
9
+ * POST returns an SSE stream of `extension_ui_request` frames — `open_url` for
10
+ * OAuth, `input` for a pasted code, `notify` for status. The client replies by
11
+ * POSTing `extension_ui_response` frames to the same endpoint; they are
12
12
  * forwarded into the running login process. The stream ends when the login
13
13
  * command resolves, fails, or the client disconnects.
14
+ *
15
+ * Two shapes in the `open_url` frame matter and each was a bug:
16
+ *
17
+ * - `url` is the authorization URL and is ALWAYS present; `launchUrl` is an
18
+ * optional loopback shortcut that omp omits for manual-input-only flows and
19
+ * for non-loopback redirect URIs. A client that keys on `launchUrl` cancels
20
+ * the login the moment it is absent.
21
+ * - the flow may be a DEVICE flow, where `instructions` carries the code the
22
+ * user has to type on another device. That text is the only way to finish it.
23
+ *
24
+ * Each stream owns a `loginId`, because the response sink used to be ONE global
25
+ * slot: two tabs logging in at once overwrote each other, and whichever
26
+ * finished first deleted the other's sink, so the survivor's replies were
27
+ * dropped with no error anywhere.
14
28
  */
15
29
 
16
30
  import { json } from '@/server/lib/remix-compat';
@@ -23,18 +37,29 @@ import { createSseStream } from '@/server/lib/sse';
23
37
  const READY_TIMEOUT_MS = 30_000;
24
38
  const LOGIN_TIMEOUT_MS = 300_000;
25
39
 
40
+ type UiFrameSink = (frame: { type: string; [key: string]: unknown }) => void;
41
+
42
+ /** Every in-flight login, keyed by its own id. */
43
+ function loginSinks(): Map<string, UiFrameSink> {
44
+ if (!globalThis.__kabmoLoginSinks) globalThis.__kabmoLoginSinks = new Map();
45
+ return globalThis.__kabmoLoginSinks;
46
+ }
47
+
26
48
  export async function action({ request, params }: ActionFunctionArgs) {
27
49
  if (request.method !== 'POST') {
28
50
  return methodNotAllowed({ request, params });
29
51
  }
30
52
  const body = await request.json().catch(() => null);
31
53
 
32
- // Response forwarding: an in-flight login posts an extension_ui_response frame.
33
- const isUiResponse = body && typeof body.id === 'string' && body.type === 'extension_ui_response';
34
- const forward = isUiResponse
35
- ? (globalThis.__kabmoLoginResponseSink as ((frame: { type: string; [key: string]: unknown }) => void) | undefined)
36
- : undefined;
37
- if (forward) {
54
+ // Response forwarding: an in-flight login posts an extension_ui_response.
55
+ if (body && typeof body.id === 'string' && body.type === 'extension_ui_response') {
56
+ const loginId = typeof body.loginId === 'string' ? body.loginId : '';
57
+ const forward = loginId ? loginSinks().get(loginId) : undefined;
58
+ if (!forward) {
59
+ // Naming the expiry is the difference between "this dialog is stale,
60
+ // reopen it" and a click that appears to do nothing.
61
+ return json({ error: 'This login session has ended — reopen the sign-in dialog.' }, { status: 409 });
62
+ }
38
63
  forward(body as { type: string; [key: string]: unknown });
39
64
  return json({ success: true });
40
65
  }
@@ -47,16 +72,17 @@ export async function action({ request, params }: ActionFunctionArgs) {
47
72
  }
48
73
 
49
74
  const providerId = body.providerId;
75
+ const loginId = crypto.randomUUID();
50
76
 
51
77
  const stream = createSseStream({
52
78
  async onStart(handlers) {
53
79
  let closed = false;
54
- let sink: ((frame: Record<string, unknown>) => void) | null = null;
80
+ let sink: UiFrameSink | null = null;
55
81
 
56
82
  const cleanup = () => {
57
83
  if (closed) return;
58
84
  closed = true;
59
- globalThis.__kabmoLoginResponseSink = undefined;
85
+ loginSinks().delete(loginId);
60
86
  handlers.close();
61
87
  };
62
88
  const send = (data: unknown) => {
@@ -64,7 +90,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
64
90
  handlers.send('', data);
65
91
  };
66
92
 
67
- globalThis.__kabmoLoginResponseSink = (frame) => sink?.(frame);
93
+ loginSinks().set(loginId, (frame) => sink?.(frame));
94
+ send({ type: 'login_started', loginId, providerId });
68
95
 
69
96
  const proc = new RpcProcess({ cwd: '/', extraArgs: ['--no-session', '--no-skills', '--no-lsp'] });
70
97
  const onAbort = () => { void proc.dispose(); cleanup(); };
@@ -77,7 +104,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
77
104
  if (frame.type === 'extension_ui_request') send(frame);
78
105
  });
79
106
 
80
- sink = (frame) => proc.sendFrame({ type: 'extension_ui_response', ...frame });
107
+ sink = (frame) => proc.sendFrame({ ...frame, type: 'extension_ui_response' });
81
108
 
82
109
  let loginOk = false;
83
110
  let loginError: string | undefined;
@@ -108,5 +135,5 @@ export async function action({ request, params }: ActionFunctionArgs) {
108
135
 
109
136
  declare global {
110
137
  // eslint-disable-next-line no-var
111
- var __kabmoLoginResponseSink: ((frame: Record<string, unknown>) => void) | undefined;
138
+ var __kabmoLoginSinks: Map<string, UiFrameSink> | undefined;
112
139
  }
@@ -58,7 +58,7 @@ afterEach(() => {
58
58
  }
59
59
  invalidateOmpCliCache();
60
60
  globalThis.fetch = originalFetch;
61
- delete (globalThis as { __kabmoLoginResponseSink?: unknown }).__kabmoLoginResponseSink;
61
+ globalThis.__kabmoLoginSinks?.clear();
62
62
  delete (globalThis as { __kabmoModelsDevCatalog?: unknown }).__kabmoModelsDevCatalog;
63
63
  });
64
64
 
@@ -108,26 +108,39 @@ describe('POST /api/omp/login', () => {
108
108
  expect((await payload(res)).error).toBe('Login is unavailable in mock mode');
109
109
  });
110
110
 
111
- test('forwards an in-flight extension_ui_response to the registered sink', async () => {
111
+ test('forwards an in-flight extension_ui_response to the sink of ITS login', async () => {
112
112
  const seen: Array<Record<string, unknown>> = [];
113
- (globalThis as { __kabmoLoginResponseSink?: (frame: Record<string, unknown>) => void }).__kabmoLoginResponseSink =
114
- (frame) => seen.push(frame);
115
- const frame = { id: 'ui-1', type: 'extension_ui_response', value: 'sk-abc' };
113
+ const other: Array<Record<string, unknown>> = [];
114
+ globalThis.__kabmoLoginSinks = new Map([
115
+ ['login-a', (frame) => seen.push(frame)],
116
+ ['login-b', (frame) => other.push(frame)],
117
+ ]);
118
+ const frame = { id: 'ui-1', type: 'extension_ui_response', loginId: 'login-a', value: 'sk-abc' };
116
119
 
117
120
  const res = (await login({ request: post(url, frame), params: {} } as never)) as Response;
118
121
  expect(res.status).toBe(200);
119
122
  expect(await payload(res)).toEqual({ success: true });
123
+ // The sibling login is untouched: one global slot made the two tabs
124
+ // overwrite each other, so a reply landed in the other provider's flow.
120
125
  expect(seen).toEqual([frame]);
126
+ expect(other).toEqual([]);
121
127
  });
122
128
 
123
- test('an extension_ui_response with no login in flight is not treated as a login start', async () => {
124
- // No sink is registered, so the frame falls through to the providerId check
125
- // rather than spawning a process.
129
+ test('a reply for an expired login is reported, not silently dropped', async () => {
130
+ globalThis.__kabmoLoginSinks = new Map();
131
+ const res = (await login({
132
+ request: post(url, { id: 'ui-1', type: 'extension_ui_response', loginId: 'gone' }),
133
+ params: {},
134
+ } as never)) as Response;
135
+ expect(res.status).toBe(409);
136
+ expect((await payload(res)).error).toContain('login session has ended');
137
+ });
138
+
139
+ test('an extension_ui_response with no login id is not treated as a login start', async () => {
126
140
  const res = (await login({
127
141
  request: post(url, { id: 'ui-1', type: 'extension_ui_response' }),
128
142
  params: {},
129
143
  } as never)) as Response;
130
- expect(res.status).toBe(400);
131
- expect((await payload(res)).error).toBe('providerId is required');
144
+ expect(res.status).toBe(409);
132
145
  });
133
146
  });