@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,329 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * One JSON read, with the cache that makes browsing cheap.
8
+ *
9
+ * Every request this plugin makes is CONDITIONAL, and that is not an
10
+ * optimisation — it is what makes a forge panel usable at all. GitHub's own
11
+ * documentation is explicit: a conditional request that answers `304` does not
12
+ * count against the primary rate limit *when it is authenticated*. So the panel
13
+ * can re-read on every mount and every Refresh and cost nothing while nothing
14
+ * changed, which is the common case for an issue list.
15
+ *
16
+ * Three rules follow from that:
17
+ *
18
+ * - **The cache stores the NORMALIZED payload, not the API body.** What a later
19
+ * `304` returns must be what the panel renders, and the adapters are the only
20
+ * code that knows how to turn a body into one. Caching the raw body would mean
21
+ * re-mapping on every hit, and caching nothing would mean a second round trip.
22
+ * - **A failure is a sentence, not a status code.** 401/403/404/429 each mean a
23
+ * different thing to the reader, and "HTTP 403" is the least useful way to say
24
+ * "your token cannot see this".
25
+ * - **The cache is bounded and self-pruning.** A key/value store with one entry
26
+ * per URL would grow for as long as a workspace is used; the oldest entries go
27
+ * when the count passes a ceiling, and anything a week old goes with them.
28
+ */
29
+
30
+ import type { PluginJson } from '@kabmo-labs/kabmo-sdk';
31
+ import type { ForgeProvider } from '../protocol';
32
+
33
+ /** One cached answer, keyed by its URL. */
34
+ export interface CachedResponse {
35
+ url: string;
36
+ etag: string | null;
37
+ lastModified: string | null;
38
+ /** The mapped payload the panel renders. */
39
+ value: PluginJson;
40
+ /** When it was written, for pruning. */
41
+ at: number;
42
+ }
43
+
44
+ /** The slice of the plugin's storage this module needs. */
45
+ export interface JsonCache {
46
+ read(key: string): Promise<CachedResponse | undefined>;
47
+ write(key: string, entry: CachedResponse): Promise<void>;
48
+ keys(): Promise<string[]>;
49
+ remove(key: string): Promise<void>;
50
+ }
51
+
52
+ export type GetResult =
53
+ | { ok: true; value: unknown; cached: boolean }
54
+ | { ok: false; status: number; message: string };
55
+
56
+ export interface GetOptions {
57
+ cache: JsonCache;
58
+ url: string;
59
+ headers?: Record<string, string>;
60
+ timeoutMs?: number;
61
+ /** Injected by the tests; the host always uses the platform's own `fetch`. */
62
+ fetchImpl?: typeof fetch;
63
+ now?: () => number;
64
+ }
65
+
66
+ /** Identifies this client to the host, as every API asks. */
67
+ const USER_AGENT = 'kabmo-forge';
68
+
69
+ const DEFAULT_TIMEOUT_MS = 15_000;
70
+
71
+ /** Entries kept before the oldest are dropped. */
72
+ const MAX_ENTRIES = 60;
73
+
74
+ /** Entries older than this are dropped on the next prune. */
75
+ const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
76
+
77
+ /** A stable short key: FNV-1a, because the store's keys are strings. */
78
+ export function cacheKey(url: string): string {
79
+ let hash = 0x811c9dc5;
80
+ for (let index = 0; index < url.length; index += 1) {
81
+ hash ^= url.charCodeAt(index);
82
+ hash = Math.imul(hash, 0x01000193) >>> 0;
83
+ }
84
+ return `cache:${hash.toString(16).padStart(8, '0')}:${url.length.toString(16)}`;
85
+ }
86
+
87
+ /**
88
+ * The credential header each host takes.
89
+ *
90
+ * Four spellings, and getting one wrong is a 401 that reads as a bad token:
91
+ * GitHub wants `Authorization: Bearer` (plus the API version pin, without which
92
+ * the response shape follows the account's default), GitLab wants its own
93
+ * `PRIVATE-TOKEN`, Gitea accepts `Authorization: token`, and Bitbucket's access
94
+ * tokens are Bearer while its APP PASSWORDS are Basic — which is why a token
95
+ * containing a colon is base64-encoded as a user/password pair rather than sent
96
+ * as a Bearer value the host will reject.
97
+ */
98
+ export function authHeaders(provider: ForgeProvider, token: string | null): Record<string, string> {
99
+ if (!token) return {};
100
+ if (provider === 'github') return { authorization: `Bearer ${token}`, 'x-github-api-version': '2022-11-28' };
101
+ if (provider === 'gitlab') return { 'private-token': token };
102
+ if (provider === 'gitea') return { authorization: `token ${token}` };
103
+ // Bitbucket: `user:app-password` is an app password, anything else is an
104
+ // access token.
105
+ return token.includes(':')
106
+ ? { authorization: `Basic ${Buffer.from(token, 'utf8').toString('base64')}` }
107
+ : { authorization: `Bearer ${token}` };
108
+ }
109
+
110
+ /** Whether a credential is present, from the headers it produced. */
111
+ export function isAuthenticated(headers: Record<string, string> | undefined): boolean {
112
+ if (!headers) return false;
113
+ return Boolean(headers.authorization || headers['private-token']);
114
+ }
115
+
116
+ /**
117
+ * What a failed status means to the person reading the panel.
118
+ *
119
+ * `authenticated` is a parameter because the same status means two different
120
+ * things. A 403 from a request that carried no credential is the host refusing
121
+ * an ANONYMOUS read — measured on a public GitLab project, where two of three
122
+ * sections answered 403 and the third answered 200 — and telling that reader
123
+ * their token lacks scope is advice about a token that does not exist.
124
+ */
125
+ export function describeFailure(response: Response, authenticated: boolean): string {
126
+ const status = response.status;
127
+ if (status === 401) {
128
+ // Anonymous is a different problem from a bad token, and the advice differs:
129
+ // GitLab answers 401 on the notes endpoint to a reader with NO credential
130
+ // (measured on a public project), where "check your token" is advice about a
131
+ // token that was never sent.
132
+ return authenticated
133
+ ? 'The host rejected the credential (401). Check the token in GITHUB_TOKEN / GH_TOKEN / GITLAB_TOKEN, or the one `gh` / `glab` has stored.'
134
+ : 'This endpoint needs a token (401) even on a public repository. Set GITHUB_TOKEN / GITLAB_TOKEN / GITEA_TOKEN in the server environment, or run `gh` / `glab` auth login.';
135
+ }
136
+ if (status === 403) {
137
+ const remaining = response.headers.get('x-ratelimit-remaining');
138
+ if (remaining === '0') return `Rate limit reached (403). ${resetHint(response.headers.get('x-ratelimit-reset'))}`;
139
+ if (!authenticated) {
140
+ return 'The host refused an anonymous read (403). Some hosts and projects require a token even to list; set GITHUB_TOKEN / GITLAB_TOKEN, or run `gh` / `glab` auth login.';
141
+ }
142
+ return 'Access refused (403). The token may not have scope for this repository.';
143
+ }
144
+ if (status === 404) {
145
+ return authenticated
146
+ ? 'Not found (404). The repository may be renamed, or the token may not see it.'
147
+ : 'Not found (404). The repository may be private or renamed; a private one needs a token.';
148
+ }
149
+ if (status === 429) {
150
+ return `Rate limited (429). ${resetHint(response.headers.get('retry-after'))}`;
151
+ }
152
+ return `The host answered ${status}.`;
153
+ }
154
+
155
+ /** "Try again after HH:MM", from a unix-seconds reset or a seconds delay. */
156
+ function resetHint(value: string | null): string {
157
+ const seconds = Number(value);
158
+ if (!Number.isFinite(seconds) || seconds <= 0) return 'Try again later.';
159
+ // `x-ratelimit-reset` is an absolute unix timestamp; `retry-after` is a delay.
160
+ const at = seconds > 1_000_000_000 ? new Date(seconds * 1000) : new Date(Date.now() + seconds * 1000);
161
+ return `Try again after ${at.toLocaleTimeString()}.`;
162
+ }
163
+
164
+ /**
165
+ * Read one URL as JSON, using and updating the cache.
166
+ *
167
+ * The conditional headers are sent only when there is something to compare
168
+ * against, and only one of them: a host that answers `304` to an `If-None-Match`
169
+ * it did not mint would otherwise hide a changed body behind a stale date.
170
+ */
171
+ export async function getJson(options: GetOptions): Promise<GetResult> {
172
+ const key = cacheKey(options.url);
173
+ const now = options.now ?? Date.now;
174
+ const entry = await options.cache.read(key);
175
+
176
+ const headers: Record<string, string> = {
177
+ accept: 'application/json',
178
+ 'user-agent': USER_AGENT,
179
+ ...options.headers,
180
+ };
181
+ if (entry?.etag) headers['if-none-match'] = entry.etag;
182
+ else if (entry?.lastModified) headers['if-modified-since'] = entry.lastModified;
183
+
184
+ const doFetch = options.fetchImpl ?? fetch;
185
+ let response: Response;
186
+ try {
187
+ response = await doFetch(options.url, {
188
+ headers,
189
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS),
190
+ });
191
+ } catch (cause) {
192
+ const reason = cause instanceof Error ? cause.message : String(cause);
193
+ return { ok: false, status: 0, message: `Could not reach the host: ${reason}` };
194
+ }
195
+
196
+ if (response.status === 304) {
197
+ // A 304 with nothing cached is a host bug; asking again without the header
198
+ // is the only answer that can produce a body.
199
+ if (entry) return { ok: true, value: entry.value, cached: true };
200
+ return { ok: false, status: 304, message: 'The host answered 304 to a request that carried no cache entry.' };
201
+ }
202
+
203
+ if (!response.ok) {
204
+ return { ok: false, status: response.status, message: describeFailure(response, isAuthenticated(options.headers)) };
205
+ }
206
+
207
+ let value: PluginJson;
208
+ try {
209
+ value = (await response.json()) as PluginJson;
210
+ } catch (cause) {
211
+ const reason = cause instanceof Error ? cause.message : String(cause);
212
+ return { ok: false, status: response.status, message: `The host sent a body that is not JSON: ${reason}` };
213
+ }
214
+
215
+ const fresh: CachedResponse = {
216
+ url: options.url,
217
+ etag: response.headers.get('etag'),
218
+ lastModified: response.headers.get('last-modified'),
219
+ value,
220
+ at: now(),
221
+ };
222
+ await options.cache.write(key, fresh);
223
+ await prune(options.cache, now());
224
+ return { ok: true, value, cached: false };
225
+ }
226
+
227
+ /**
228
+ * Read one URL as TEXT.
229
+ *
230
+ * Two hosts answer a diff as `text/plain` — Gitea's `.diff` route and
231
+ * Bitbucket's `/diff` — and `getJson` cannot read either: `response.json()`
232
+ * throws on `@@ -1 +1 @@`, so the whole file list came back empty with a note
233
+ * about a body that "is not JSON". The cache is shared, because a diff is a
234
+ * resource like any other and its validator works the same way.
235
+ */
236
+ export async function getText(options: GetOptions): Promise<GetResult> {
237
+ const key = cacheKey(options.url);
238
+ const now = options.now ?? Date.now;
239
+ const entry = await options.cache.read(key);
240
+
241
+ const headers: Record<string, string> = {
242
+ accept: 'text/plain',
243
+ 'user-agent': USER_AGENT,
244
+ ...options.headers,
245
+ };
246
+ if (entry?.etag) headers['if-none-match'] = entry.etag;
247
+ else if (entry?.lastModified) headers['if-modified-since'] = entry.lastModified;
248
+
249
+ const doFetch = options.fetchImpl ?? fetch;
250
+ let response: Response;
251
+ try {
252
+ response = await doFetch(options.url, {
253
+ headers,
254
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS),
255
+ });
256
+ } catch (cause) {
257
+ const reason = cause instanceof Error ? cause.message : String(cause);
258
+ return { ok: false, status: 0, message: `Could not reach the host: ${reason}` };
259
+ }
260
+
261
+ if (response.status === 304 && entry) return { ok: true, value: entry.value, cached: true };
262
+ if (!response.ok) {
263
+ return { ok: false, status: response.status, message: describeFailure(response, isAuthenticated(options.headers)) };
264
+ }
265
+
266
+ let value: string;
267
+ try {
268
+ value = await response.text();
269
+ } catch (cause) {
270
+ const reason = cause instanceof Error ? cause.message : String(cause);
271
+ return { ok: false, status: response.status, message: `The host's body could not be read: ${reason}` };
272
+ }
273
+
274
+ await options.cache.write(key, {
275
+ url: options.url,
276
+ etag: response.headers.get('etag'),
277
+ lastModified: response.headers.get('last-modified'),
278
+ value,
279
+ at: now(),
280
+ });
281
+ return { ok: true, value, cached: false };
282
+ }
283
+
284
+ /**
285
+ * Keep the cache bounded.
286
+ *
287
+ * Runs after a write and only when the ceiling is crossed, so the ordinary read
288
+ * costs one `keys()` at most. Entries are dropped oldest-first down to a
289
+ * watermark well below the ceiling, which is what makes the pass amortised
290
+ * rather than a full sort on every request.
291
+ */
292
+ async function prune(cache: JsonCache, now: number): Promise<void> {
293
+ const keys = await cache.keys();
294
+ if (keys.length <= MAX_ENTRIES) {
295
+ // Under the ceiling, but an expired entry is still worth dropping: a
296
+ // week-old ETag is a re-read that answers 200 anyway.
297
+ for (const key of keys) {
298
+ const entry = await cache.read(key);
299
+ if (entry && now - entry.at > MAX_AGE_MS) await cache.remove(key);
300
+ }
301
+ return;
302
+ }
303
+
304
+ const entries: Array<{ key: string; at: number }> = [];
305
+ for (const key of keys) {
306
+ const entry = await cache.read(key);
307
+ if (entry) entries.push({ key, at: entry.at });
308
+ else await cache.remove(key);
309
+ }
310
+ entries.sort((left, right) => left.at - right.at);
311
+ const keep = Math.floor(MAX_ENTRIES / 2);
312
+ const doomed = entries.slice(0, Math.max(0, entries.length - keep));
313
+ for (const entry of doomed) await cache.remove(entry.key);
314
+ }
315
+
316
+ /** The cache adapter over the plugin's own key/value store. */
317
+ export function kvCache(kv: {
318
+ read<T>(key: string): Promise<T | undefined>;
319
+ write(key: string, value: PluginJson): Promise<void>;
320
+ keys(): Promise<string[]>;
321
+ remove(key: string): Promise<void>;
322
+ }): JsonCache {
323
+ return {
324
+ read: (key) => kv.read<CachedResponse>(key),
325
+ write: (key, entry) => kv.write(key, entry as unknown as PluginJson),
326
+ keys: () => kv.keys(),
327
+ remove: (key) => kv.remove(key),
328
+ };
329
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Reading a JSON body nobody typed.
8
+ *
9
+ * Both adapters parse responses from a host this plugin does not control, so
10
+ * every field is `unknown` until a guard has said otherwise. The helpers here are
11
+ * the whole vocabulary of that: an object check, a string, a number, a boolean
12
+ * and a list — each answering a DEFAULT rather than throwing, because one
13
+ * missing field on one row must not lose the other twenty-nine.
14
+ *
15
+ * The functions are deliberately named for the shape they return (`asRecord`,
16
+ * `text`) rather than for the API they read, so the adapters read as a
17
+ * transcription of the response instead of a pile of casts.
18
+ */
19
+
20
+ export type Json = unknown;
21
+
22
+ /** A JSON object, or null. */
23
+ export function asRecord(value: Json): Record<string, Json> | null {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
25
+ ? (value as Record<string, Json>)
26
+ : null;
27
+ }
28
+
29
+ /** The array at `key`, or an empty list. */
30
+ export function listAt(value: Json): Json[] {
31
+ return Array.isArray(value) ? value : [];
32
+ }
33
+
34
+ /** A string field, or the fallback. */
35
+ export function text(value: Json, fallback = ''): string {
36
+ return typeof value === 'string' ? value : fallback;
37
+ }
38
+
39
+ /** A number field, or the fallback. */
40
+ export function count(value: Json, fallback = 0): number {
41
+ return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
42
+ }
43
+
44
+ /**
45
+ * A number the host may have sent as a STRING, or the fallback.
46
+ *
47
+ * GitLab reports `changes_count` as a string, and as `"1000+"` once a merge
48
+ * request passes its own cap — so a numeric-only read silently drops the fact
49
+ * for every MR with changes, which is every MR. The trailing `+` is dropped
50
+ * rather than the whole value: "at least 1000" is still worth showing.
51
+ */
52
+ export function numberish(value: Json, fallback: number): number {
53
+ if (typeof value === 'number') return Number.isFinite(value) ? value : fallback;
54
+ if (typeof value !== 'string') return fallback;
55
+ const parsed = Number(value.trim().replace(/\+$/, ''));
56
+ return Number.isFinite(parsed) ? parsed : fallback;
57
+ }
58
+
59
+ /** A boolean field, or false. */
60
+ export function flag(value: Json): boolean {
61
+ return value === true;
62
+ }
63
+
64
+ /** A field of a nested object, untyped — for a value that may be an ARRAY. */
65
+ export function fieldAt(value: Json, key: string): Json {
66
+ const parent = asRecord(value);
67
+ return parent ? parent[key] : undefined;
68
+ }
69
+
70
+ /** A nested object field, or null. */
71
+ export function recordAt(value: Json, key: string): Record<string, Json> | null {
72
+ const parent = asRecord(value);
73
+ return parent ? asRecord(parent[key]) : null;
74
+ }
75
+
76
+ /** A string field of a nested object, or the fallback. */
77
+ export function textAt(value: Json, key: string, fallback = ''): string {
78
+ const parent = asRecord(value);
79
+ return parent ? text(parent[key], fallback) : fallback;
80
+ }
81
+
82
+ /**
83
+ * A URL from a host's own link envelope: `{links: {html: {href}}}`.
84
+ *
85
+ * Three vendors nest a URL two levels deep, and reading it with one `textAt` call
86
+ * returns the OBJECT's stringification rather than the address — which is how a
87
+ * row's "open on the host" link became the literal text `[object Object]`.
88
+ */
89
+ export function hrefAt(value: Json, ...path: string[]): string {
90
+ let cursor: Json = value;
91
+ for (const key of path) {
92
+ cursor = asRecord(cursor)?.[key];
93
+ }
94
+ return text(cursor);
95
+ }
96
+
97
+ /**
98
+ * A label list from either vendor's spelling.
99
+ *
100
+ * GitHub sends `[{name, color}]` with the colour as six hex digits and no `#`;
101
+ * GitLab sends plain strings. Normalizing here is what lets one row component
102
+ * draw both, and a colour the host does not send stays null so the badge falls
103
+ * back to the theme's own ink rather than inventing a shade.
104
+ */
105
+ export function labelsOf(value: Json): Array<{ name: string; color: string | null }> {
106
+ const out: Array<{ name: string; color: string | null }> = [];
107
+ for (const entry of listAt(value)) {
108
+ if (typeof entry === 'string') {
109
+ if (entry.trim()) out.push({ name: entry.trim(), color: null });
110
+ continue;
111
+ }
112
+ const record = asRecord(entry);
113
+ if (!record) continue;
114
+ const name = text(record.name).trim();
115
+ if (!name) continue;
116
+ const color = text(record.color).replace(/^#/, '');
117
+ out.push({ name, color: /^[0-9a-f]{6}$/i.test(color) ? color : null });
118
+ }
119
+ return out;
120
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * One table from a provider to the module that speaks it.
8
+ *
9
+ * A lookup rather than a chain of `if`s at each call site: the server half has
10
+ * three verbs (list, detail, and a write that re-reads the detail) and four
11
+ * hosts, and twelve branches is twelve places a new host is forgotten. The table
12
+ * is also what makes a host addable as ONE row plus its module — which is how
13
+ * Gitea and Bitbucket were added.
14
+ */
15
+
16
+ import type { ForgeDetail, ForgeList, ForgeProvider, ForgeSection } from '../protocol';
17
+ import type { ForgeContext } from './context';
18
+ import { detailBitbucket, listBitbucket } from './bitbucket';
19
+ import { detailGitea, listGitea } from './gitea';
20
+ import { detailGithub, listGithub } from './github';
21
+ import { listGitlab } from './gitlab';
22
+ import { detailGitlab } from './gitlab-detail';
23
+
24
+ /** What every adapter provides. */
25
+ export interface ForgeAdapter {
26
+ list(context: ForgeContext): Promise<ForgeList>;
27
+ detail(context: ForgeContext, section: ForgeSection, id: string): Promise<ForgeDetail | { error: string }>;
28
+ }
29
+
30
+ /**
31
+ * The adapters, by provider.
32
+ *
33
+ * `Record<ForgeProvider, …>` rather than a partial map: adding a provider to the
34
+ * union without adding its row is a compile error, which is the only thing that
35
+ * keeps the four hosts in step.
36
+ */
37
+ export const ADAPTERS: Record<ForgeProvider, ForgeAdapter> = {
38
+ github: { list: listGithub, detail: detailGithub },
39
+ gitlab: { list: listGitlab, detail: detailGitlab },
40
+ gitea: { list: listGitea, detail: detailGitea },
41
+ bitbucket: { list: listBitbucket, detail: detailBitbucket },
42
+ };
43
+
44
+ /** The adapter for one provider. */
45
+ export function adapterFor(provider: ForgeProvider): ForgeAdapter {
46
+ return ADAPTERS[provider];
47
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The remote parser, over the shapes a real checkout actually holds.
8
+ *
9
+ * Every case here is a remote this workspace has used or one a self-hosted
10
+ * install produces, because the parser's job is to be right about the URL git
11
+ * reports rather than about a canonical form.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+
16
+ import { apiBaseFor, bitbucketPath, gitlabProject, parseRemote, providerForHost } from './remote';
17
+
18
+ function parsed(raw: string, options?: Parameters<typeof parseRemote>[1]) {
19
+ const result = parseRemote(raw, options);
20
+ if ('error' in result) throw new Error(`expected a remote, got: ${result.error}`);
21
+ return result;
22
+ }
23
+
24
+ describe('parseRemote', () => {
25
+ test('reads an https GitHub remote', () => {
26
+ const remote = parsed('https://github.com/kabmo-labs/kabmo.git');
27
+ expect(remote.provider).toBe('github');
28
+ expect(remote.host).toBe('github.com');
29
+ expect(remote.slug).toBe('kabmo-labs/kabmo');
30
+ expect(remote.webUrl).toBe('https://github.com/kabmo-labs/kabmo');
31
+ expect(remote.apiBase).toBe('https://api.github.com');
32
+ });
33
+
34
+ test('reads the scp form, which is what a checkout usually holds', () => {
35
+ const remote = parsed('git@github.com:kabmo-labs/kabmo.git');
36
+ expect(remote.provider).toBe('github');
37
+ expect(remote.host).toBe('github.com');
38
+ expect(remote.slug).toBe('kabmo-labs/kabmo');
39
+ expect(remote.webUrl).toBe('https://github.com/kabmo-labs/kabmo');
40
+ });
41
+
42
+ test('reads an ssh:// remote', () => {
43
+ const remote = parsed('ssh://git@github.com/kabmo-labs/kabmo.git');
44
+ expect(remote.slug).toBe('kabmo-labs/kabmo');
45
+ expect(remote.apiBase).toBe('https://api.github.com');
46
+ });
47
+
48
+ test('strips credentials instead of echoing them', () => {
49
+ const remote = parsed('https://user:ghp_secret@git-rbi.jatismobile.com/jns6_5/drrealhandler.git');
50
+ expect(remote.host).toBe('git-rbi.jatismobile.com');
51
+ expect(remote.webUrl).toBe('https://git-rbi.jatismobile.com/jns6_5/drrealhandler');
52
+ expect(JSON.stringify(remote)).not.toContain('ghp_secret');
53
+ });
54
+
55
+ test('treats a host that is not GitHub as GitLab', () => {
56
+ const remote = parsed('https://git-rbi.jatismobile.com/jns6_5/drrealhandler.git');
57
+ expect(remote.provider).toBe('gitlab');
58
+ expect(remote.apiBase).toBe('https://git-rbi.jatismobile.com/api/v4');
59
+ });
60
+
61
+ test('keeps a GitLab subgroup in the slug', () => {
62
+ const remote = parsed('git@gitlab.com:group/sub/project.git');
63
+ expect(remote.slug).toBe('group/sub/project');
64
+ expect(gitlabProject(remote.slug)).toBe('group%2Fsub%2Fproject');
65
+ });
66
+
67
+ test('reads a GitHub Enterprise host as GitHub, with its /api/v3 root', () => {
68
+ const remote = parsed('https://github.mycorp.com/team/app');
69
+ expect(remote.provider).toBe('github');
70
+ expect(remote.apiBase).toBe('https://github.mycorp.com/api/v3');
71
+ });
72
+
73
+ test('keeps a port and the http scheme', () => {
74
+ const remote = parsed('http://localhost:3000/team/app.git');
75
+ expect(remote.host).toBe('localhost:3000');
76
+ expect(remote.provider).toBe('gitlab');
77
+ expect(remote.apiBase).toBe('http://localhost:3000/api/v4');
78
+ expect(remote.webUrl).toBe('http://localhost:3000/team/app');
79
+ });
80
+
81
+ test('a provider setting beats the guess', () => {
82
+ const remote = parsed('https://github.com/kabmo-labs/kabmo.git', { provider: 'gitlab' });
83
+ expect(remote.provider).toBe('gitlab');
84
+ expect(remote.apiBase).toBe('https://github.com/api/v4');
85
+ });
86
+
87
+ test('an apiBase setting beats the derived root', () => {
88
+ const remote = parsed('https://github.com/kabmo-labs/kabmo.git', { apiBase: 'https://proxy.local/gh/' });
89
+ expect(remote.apiBase).toBe('https://proxy.local/gh');
90
+ });
91
+
92
+ test('refuses a local path', () => {
93
+ for (const raw of ['/srv/repo', './repo', 'C:\\repo', 'C:/repo']) {
94
+ expect('error' in parseRemote(raw)).toBe(true);
95
+ }
96
+ });
97
+
98
+ test('refuses a remote with no repository in it', () => {
99
+ expect('error' in parseRemote('https://github.com/onlyowner')).toBe(true);
100
+ expect('error' in parseRemote('')).toBe(true);
101
+ expect('error' in parseRemote(null)).toBe(true);
102
+ });
103
+ });
104
+
105
+ describe('providerForHost', () => {
106
+ test('the four hosts each resolve, and a name that contains another does not win', () => {
107
+ expect(providerForHost('github.com')).toBe('github');
108
+ expect(providerForHost('github.mycorp.com')).toBe('github');
109
+ expect(providerForHost('gitlab.com')).toBe('gitlab');
110
+ expect(providerForHost('git-rbi.jatismobile.com')).toBe('gitlab');
111
+ expect(providerForHost('gitea.example.com')).toBe('gitea');
112
+ expect(providerForHost('codeberg.org')).toBe('gitea');
113
+ expect(providerForHost('forgejo.internal')).toBe('gitea');
114
+ expect(providerForHost('bitbucket.org')).toBe('bitbucket');
115
+ // `gitbucket` contains `bucket` but is not Bitbucket, and its own name says
116
+ // nothing else either — so it falls to the default rather than matching a
117
+ // host it is not.
118
+ expect(providerForHost('gitbucket.example.com')).toBe('gitlab');
119
+ });
120
+ });
121
+
122
+ describe('bitbucketPath', () => {
123
+ test('two segments split; a subgroup is refused rather than guessed', () => {
124
+ expect(bitbucketPath('team/repo')).toEqual({ workspace: 'team', repo: 'repo' });
125
+ expect(bitbucketPath('group/sub/repo')).toBeNull();
126
+ expect(bitbucketPath('lonely')).toBeNull();
127
+ });
128
+ });
129
+
130
+ describe('apiBaseFor', () => {
131
+ test('github.com is the one host with no path prefix', () => {
132
+ expect(apiBaseFor('github', 'github.com', 'https')).toBe('https://api.github.com');
133
+ expect(apiBaseFor('github', 'ghe.internal', 'https')).toBe('https://ghe.internal/api/v3');
134
+ expect(apiBaseFor('gitlab', 'gitlab.com', 'https')).toBe('https://gitlab.com/api/v4');
135
+ expect(apiBaseFor('gitea', 'gitea.example.com', 'https')).toBe('https://gitea.example.com/api/v1');
136
+ });
137
+
138
+ test('Bitbucket Cloud is not on the repository hostname', () => {
139
+ expect(apiBaseFor('bitbucket', 'bitbucket.org', 'https')).toBe('https://api.bitbucket.org/2.0');
140
+ // A self-hosted Bitbucket SERVER is a different API (1.0, on its own host),
141
+ // so the override is the only way to reach one — documented, not guessed.
142
+ expect(apiBaseFor('bitbucket', 'bitbucket.internal', 'https', 'https://bitbucket.internal/rest/api/1.0/')).toBe(
143
+ 'https://bitbucket.internal/rest/api/1.0',
144
+ );
145
+ });
146
+ });