@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,92 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * A pull request's files and commits.
8
+ *
9
+ * Both are separate collections on GitHub, and both are OPTIONAL to the item
10
+ * itself: a PR whose file list fails (a huge diff, a rate limit) still has a
11
+ * title, a body and a conversation, so a failure here is a note rather than a
12
+ * failed read.
13
+ *
14
+ * The patch text is carried as the host sends it. GitHub omits `patch` for a
15
+ * binary file and for a diff over its own size ceiling, and an absent patch is
16
+ * the signal the panel renders as a name-and-status row instead of an empty code
17
+ * block.
18
+ */
19
+
20
+ import type { ForgeCommit, ForgeFile } from '../protocol';
21
+ import { get, joinUrl, type ForgeContext } from './context';
22
+ import { asRecord, count, listAt, text, textAt } from './map';
23
+
24
+ /** The ceiling both reads ask for: enough for an ordinary change, bounded. */
25
+ const MAX_FILES = 100;
26
+ const MAX_COMMITS = 50;
27
+
28
+ function fileOf(raw: unknown): ForgeFile | null {
29
+ const record = asRecord(raw);
30
+ if (!record) return null;
31
+ const path = text(record.filename);
32
+ if (!path) return null;
33
+ return {
34
+ path,
35
+ status: text(record.status, 'modified'),
36
+ additions: count(record.additions, 0),
37
+ deletions: count(record.deletions, 0),
38
+ patch: text(record.patch),
39
+ };
40
+ }
41
+
42
+ function commitOf(raw: unknown): ForgeCommit | null {
43
+ const record = asRecord(raw);
44
+ if (!record) return null;
45
+ const sha = text(record.sha);
46
+ if (!sha) return null;
47
+ const commit = asRecord(record.commit) ?? {};
48
+ const author = asRecord(commit.author) ?? {};
49
+ return {
50
+ sha,
51
+ // Only the first line: a commit body is often a paragraph, and a row is one
52
+ // line. The full message is on the commit's own page.
53
+ message: text(commit.message).split('\n')[0],
54
+ author: text(author.name) || textAt(record.author, 'login', 'unknown'),
55
+ at: text(author.date),
56
+ };
57
+ }
58
+
59
+ export interface PullExtras {
60
+ files: ForgeFile[];
61
+ commits: ForgeCommit[];
62
+ }
63
+
64
+ export async function githubExtras(
65
+ context: ForgeContext,
66
+ id: string,
67
+ notes: string[],
68
+ ): Promise<PullExtras> {
69
+ const base = `/repos/${context.slug}/pulls/${encodeURIComponent(id)}`;
70
+ const [files, commits] = await Promise.all([
71
+ get(context, joinUrl(context.apiBase, `${base}/files?per_page=${MAX_FILES}`)),
72
+ get(context, joinUrl(context.apiBase, `${base}/commits?per_page=${MAX_COMMITS}`)),
73
+ ]);
74
+
75
+ if (!files.ok) notes.push(`files: ${files.message}`);
76
+ if (!commits.ok) notes.push(`commits: ${commits.message}`);
77
+
78
+ return {
79
+ files: files.ok
80
+ ? listAt(files.value).flatMap((raw) => {
81
+ const file = fileOf(raw);
82
+ return file ? [file] : [];
83
+ })
84
+ : [],
85
+ commits: commits.ok
86
+ ? listAt(commits.value).flatMap((raw) => {
87
+ const commit = commitOf(raw);
88
+ return commit ? [commit] : [];
89
+ })
90
+ : [],
91
+ };
92
+ }
@@ -0,0 +1,320 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * GitHub's REST API, transcribed into this plugin's own shapes.
8
+ *
9
+ * ## Issues and pull requests BOTH come from the search endpoint
10
+ *
11
+ * `/repos/{owner}/{repo}/issues` returns pull requests too — they carry a
12
+ * `pull_request` key — and filtering them out works only while a page is not
13
+ * full of them: measured on `oven-sh/bun` with `state=open`, the five newest
14
+ * "issues" were all PRs, so filtering left ZERO issues on screen while 3 595
15
+ * were open. `/repos/{id}/pulls` cannot filter by label, assignee or text at
16
+ * all. Search answers both collections with the same qualifier grammar, so one
17
+ * path serves the two sections AND the filters.
18
+ *
19
+ * The cost is stated rather than hidden:
20
+ *
21
+ * - search has its own budget (30/min authenticated) and sends **no `ETag`**, so
22
+ * its re-read is always a full response;
23
+ * - a search row's `labels` are NAMES only, with no colour, so a list row's chips
24
+ * fall back to the theme's ink. The item's own page reads the REST object,
25
+ * which does carry colours.
26
+ *
27
+ * ## A pull request's state is three answers, not two
28
+ *
29
+ * `merged_at` is what makes a merged PR different from a closed one, and `draft`
30
+ * is what makes a draft different from an open one. Both are on the search row
31
+ * (`pull_request.merged_at`, `draft`), which is why the same mapper serves the
32
+ * list and the detail.
33
+ */
34
+
35
+ import type { ForgeDetail, ForgeItem, ForgeItemState, ForgeList, ForgeSection } from '../protocol';
36
+ import { capabilitiesFor } from './capabilities';
37
+ import { githubChecks, githubStatus } from './ci';
38
+ import { get, joinUrl, type ForgeContext } from './context';
39
+ import { githubSearch } from './filters';
40
+ import { githubExtras } from './github-extras';
41
+ import { asRecord, count, fieldAt, flag, labelsOf, listAt, recordAt, text, textAt } from './map';
42
+
43
+ /**
44
+ * Whether a user object names a bot.
45
+ *
46
+ * GitHub sets `type: "Bot"` on an App's account and spells its login with a
47
+ * `[bot]` suffix; both appear, and a row that reads a bot's "closed as duplicate"
48
+ * as a human's reply is a row the reader has to re-read twice.
49
+ */
50
+ export function isBotUser(raw: unknown): boolean {
51
+ const login = textAt(raw, 'login');
52
+ return textAt(raw, 'type') === 'Bot' || /\[bot\]$/.test(login) || /-bot$/.test(login);
53
+ }
54
+
55
+ /** An issue from a search row (which carries names, not coloured labels). */
56
+ export function issueItem(raw: unknown): ForgeItem | null {
57
+ const record = asRecord(raw);
58
+ if (!record) return null;
59
+ if (record.pull_request) return null;
60
+ const number = count(record.number, 0);
61
+ if (!number) return null;
62
+ return {
63
+ id: String(number),
64
+ number,
65
+ title: text(record.title, '(untitled)'),
66
+ state: text(record.state) === 'closed' ? 'closed' : 'open',
67
+ author: textAt(record.user, 'login', 'unknown'),
68
+ updatedAt: text(record.updated_at),
69
+ url: text(record.html_url),
70
+ labels: labelsOf(record.labels),
71
+ comments: count(record.comments, 0),
72
+ tag: null,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * A pull request's state, which is three answers rather than two.
78
+ *
79
+ * The merged marker has two spellings: the REST pull object carries `merged_at`
80
+ * at the top level, while a SEARCH row carries it under `pull_request`. Reading
81
+ * only one of them made the same PR report `merged` on its page and `closed` in
82
+ * the list.
83
+ */
84
+ export function pullState(record: Record<string, unknown>): ForgeItemState {
85
+ const merged = record.merged_at || recordAt(record, 'pull_request')?.merged_at;
86
+ if (merged) return 'merged';
87
+ if (text(record.state) === 'closed') return 'closed';
88
+ return flag(record.draft) ? 'draft' : 'open';
89
+ }
90
+
91
+ export function pullItem(raw: unknown): ForgeItem | null {
92
+ const record = asRecord(raw);
93
+ if (!record) return null;
94
+ const number = count(record.number, 0);
95
+ if (!number) return null;
96
+ return {
97
+ id: String(number),
98
+ number,
99
+ title: text(record.title, '(untitled)'),
100
+ state: pullState(record),
101
+ author: textAt(record.user, 'login', 'unknown'),
102
+ updatedAt: text(record.updated_at),
103
+ url: text(record.html_url),
104
+ labels: labelsOf(record.labels),
105
+ comments: count(record.comments, 0),
106
+ tag: null,
107
+ };
108
+ }
109
+
110
+ export function releaseItem(raw: unknown): ForgeItem | null {
111
+ const record = asRecord(raw);
112
+ if (!record) return null;
113
+ const tag = text(record.tag_name);
114
+ if (!tag) return null;
115
+ const published = text(record.published_at) || text(record.created_at);
116
+ return {
117
+ id: tag,
118
+ number: null,
119
+ title: text(record.name) || tag,
120
+ state: flag(record.prerelease) ? 'prerelease' : 'published',
121
+ author: textAt(record.author, 'login', 'unknown'),
122
+ updatedAt: published,
123
+ url: text(record.html_url),
124
+ labels: [],
125
+ comments: 0,
126
+ tag,
127
+ };
128
+ }
129
+
130
+ /** The page size a read asks for, clamped to what the search endpoint accepts. */
131
+ function asked(context: ForgeContext): number {
132
+ // Search caps `per_page` at 100; the REST endpoints accept the same ceiling.
133
+ return Math.min(100, Math.max(1, Math.round(context.perPage)));
134
+ }
135
+
136
+ /** Read one section. A failure is a note, never a failed read. */
137
+ async function readSection(
138
+ context: ForgeContext,
139
+ section: ForgeSection,
140
+ notes: string[],
141
+ ): Promise<{ items: ForgeItem[]; truncated: boolean; total: number | null }> {
142
+ const perPage = asked(context);
143
+ const base = `/repos/${context.slug}`;
144
+ const url =
145
+ section === 'releases'
146
+ ? joinUrl(context.apiBase, `${base}/releases?per_page=${perPage}`)
147
+ : joinUrl(
148
+ context.apiBase,
149
+ `/search/issues?q=${encodeURIComponent(githubSearch(context.slug, section, context.filter))}&sort=updated&order=desc&per_page=${perPage}`,
150
+ );
151
+
152
+ const result = await get(context, url);
153
+ if (!result.ok) {
154
+ notes.push(`${section}: ${result.message}`);
155
+ return { items: [], truncated: false, total: null };
156
+ }
157
+
158
+ // The search endpoint wraps its rows in an envelope; the REST collection
159
+ // answers a bare array.
160
+ const rows = section === 'releases' ? listAt(result.value) : listAt(fieldAt(result.value, 'items'));
161
+ const mapper = section === 'issues' ? issueItem : section === 'pulls' ? pullItem : releaseItem;
162
+ const items = rows.map(mapper).filter((item): item is ForgeItem => item !== null);
163
+ const reported = section === 'releases' ? null : count(fieldAt(result.value, 'total_count'), items.length);
164
+ const total = reported === 0 ? null : reported;
165
+ return { items, truncated: total !== null ? total > items.length : rows.length >= perPage, total };
166
+ }
167
+
168
+ export async function listGithub(context: ForgeContext): Promise<ForgeList> {
169
+ const notes: string[] = [];
170
+ if (!context.token) {
171
+ notes.push(
172
+ 'Reading anonymously: public repositories only. Set GITHUB_TOKEN or GH_TOKEN in the server environment, or run `gh auth login`, to read a private one.',
173
+ );
174
+ }
175
+
176
+ const [issues, pulls, releases] = await Promise.all([
177
+ readSection(context, 'issues', notes),
178
+ readSection(context, 'pulls', notes),
179
+ readSection(context, 'releases', notes),
180
+ ]);
181
+
182
+ return {
183
+ provider: 'github',
184
+ host: context.host,
185
+ slug: context.slug,
186
+ webUrl: context.webUrl,
187
+ filter: context.filter,
188
+ sections: { issues, pulls, releases },
189
+ notes,
190
+ };
191
+ }
192
+
193
+ /** The URL for one item, by section. */
194
+ export function itemUrl(context: ForgeContext, section: ForgeSection, id: string): string {
195
+ const base = `/repos/${context.slug}`;
196
+ if (section === 'issues') return joinUrl(context.apiBase, `${base}/issues/${encodeURIComponent(id)}`);
197
+ if (section === 'pulls') return joinUrl(context.apiBase, `${base}/pulls/${encodeURIComponent(id)}`);
198
+ return joinUrl(context.apiBase, `${base}/releases/tags/${encodeURIComponent(id)}`);
199
+ }
200
+
201
+ /** A pull request's review facts, which no issue has. */
202
+ function pullFacts(record: Record<string, unknown>): Array<{ label: string; value: string }> {
203
+ const facts: Array<{ label: string; value: string }> = [];
204
+ const head = textAt(record.head, 'ref');
205
+ const base = textAt(record.base, 'ref');
206
+ if (head || base) facts.push({ label: 'branch', value: `${base || '?'} ← ${head || '?'}` });
207
+ const additions = count(record.additions, -1);
208
+ const deletions = count(record.deletions, -1);
209
+ if (additions >= 0 && deletions >= 0) facts.push({ label: 'diff', value: `+${additions} −${deletions}` });
210
+ const files = count(record.changed_files, 0);
211
+ if (files > 0) facts.push({ label: 'files', value: String(files) });
212
+ const mergeable = record.mergeable;
213
+ if (mergeable === true) facts.push({ label: 'mergeable', value: 'yes' });
214
+ else if (mergeable === false) facts.push({ label: 'mergeable', value: 'conflicts' });
215
+ return facts;
216
+ }
217
+
218
+ /** One item's conversation, with system and bot rows marked. */
219
+ async function readComments(
220
+ context: ForgeContext,
221
+ section: ForgeSection,
222
+ id: string,
223
+ notes: string[],
224
+ ): Promise<ForgeDetail['comments']> {
225
+ if (section === 'releases') return [];
226
+ const result = await get(
227
+ context,
228
+ joinUrl(context.apiBase, `/repos/${context.slug}/issues/${encodeURIComponent(id)}/comments?per_page=100`),
229
+ );
230
+ if (!result.ok) {
231
+ notes.push(`comments: ${result.message}`);
232
+ return [];
233
+ }
234
+ return listAt(result.value).flatMap((raw) => {
235
+ const entry = asRecord(raw);
236
+ if (!entry) return [];
237
+ return [
238
+ {
239
+ id: text(entry.node_id) || String(count(entry.id, 0)),
240
+ author: textAt(entry.user, 'login', 'unknown'),
241
+ body: text(entry.body),
242
+ createdAt: text(entry.created_at),
243
+ url: text(entry.html_url) || null,
244
+ system: false,
245
+ bot: isBotUser(entry.user),
246
+ },
247
+ ];
248
+ });
249
+ }
250
+
251
+ /** The CI verdict for a pull request, from its head commit. */
252
+ async function readCi(
253
+ context: ForgeContext,
254
+ record: Record<string, unknown>,
255
+ notes: string[],
256
+ ): Promise<ForgeDetail['ci']> {
257
+ const sha = textAt(record.head, 'sha');
258
+ if (!sha) return null;
259
+ // `head.html_url` is NULL on the pull payload — measured — so the run's page is
260
+ // built from the slug and the sha. Without it the badge is inert text, and the
261
+ // one thing a reader wants from a failing check is the log.
262
+ const runUrl = textAt(record.head, 'html_url') || `https://${context.host}/${context.slug}/commit/${sha}/checks`;
263
+ const checks = await get(context, joinUrl(context.apiBase, `/repos/${context.slug}/commits/${sha}/check-runs`));
264
+ if (checks.ok) {
265
+ const badge = githubChecks(checks.value, runUrl);
266
+ if (badge) return badge;
267
+ }
268
+ // A repository using the older commit-status API has no check runs at all, and
269
+ // answering "no CI" for one that has a red status is a wrong answer.
270
+ const status = await get(context, joinUrl(context.apiBase, `/repos/${context.slug}/commits/${sha}/status`));
271
+ if (status.ok) return githubStatus(status.value, runUrl);
272
+ if (!checks.ok && !status.ok) notes.push(`checks: ${checks.message}`);
273
+ return null;
274
+ }
275
+
276
+ export async function detailGithub(
277
+ context: ForgeContext,
278
+ section: ForgeSection,
279
+ id: string,
280
+ ): Promise<ForgeDetail | { error: string }> {
281
+ const notes: string[] = [];
282
+ const result = await get(context, itemUrl(context, section, id));
283
+ if (!result.ok) return { error: result.message };
284
+
285
+ const record = asRecord(result.value) ?? {};
286
+ const mapper = section === 'issues' ? issueItem : section === 'pulls' ? pullItem : releaseItem;
287
+ const item = mapper(record);
288
+ if (!item) return { error: 'The host returned an item this panel could not read.' };
289
+
290
+ const facts: Array<{ label: string; value: string }> = [];
291
+ if (section === 'pulls') facts.push(...pullFacts(record));
292
+ if (section === 'releases') {
293
+ const tag = text(record.tag_name);
294
+ if (tag) facts.push({ label: 'tag', value: tag });
295
+ const target = text(record.target_commitish);
296
+ if (target) facts.push({ label: 'target', value: target });
297
+ }
298
+ if (section === 'issues') {
299
+ const comments = count(record.comments, 0);
300
+ if (comments > 0) facts.push({ label: 'comments', value: String(comments) });
301
+ }
302
+
303
+ const [comments, ci, extras] = await Promise.all([
304
+ readComments(context, section, id, notes),
305
+ section === 'pulls' ? readCi(context, record, notes) : Promise.resolve(null),
306
+ section === 'pulls' ? githubExtras(context, id, notes) : Promise.resolve({ files: [], commits: [] }),
307
+ ]);
308
+
309
+ return {
310
+ item,
311
+ body: text(record.body),
312
+ comments,
313
+ facts,
314
+ files: extras.files,
315
+ commits: extras.commits,
316
+ ci,
317
+ capabilities: capabilitiesFor({ provider: 'github', section, hasCredential: Boolean(context.token) }),
318
+ notes,
319
+ };
320
+ }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * GitLab's DETAIL read: one item, plus the four sub-resources that make it
8
+ * readable.
9
+ *
10
+ * Split from `gitlab.ts` because the two answer different questions — the list is
11
+ * three collections, the detail is one item and its conversation, change, commits
12
+ * and pipeline — and because a merge request's files are NOT on the merge request
13
+ * (see `readFiles`).
14
+ */
15
+
16
+ import type { ForgeCommit, ForgeDetail, ForgeFile, ForgeSection } from '../protocol';
17
+ import { capabilitiesFor } from './capabilities';
18
+ import { ciBadge } from './ci';
19
+ import { get, joinUrl, withParams, type ForgeContext } from './context';
20
+ import { asRecord, count, flag, listAt, numberish, recordAt, text, textAt } from './map';
21
+ import { issueItem, mergeItem, projectPath, releaseItem } from './gitlab';
22
+
23
+ export function itemUrl(context: ForgeContext, section: ForgeSection, id: string): string {
24
+ const project = projectPath(context);
25
+ const encoded = encodeURIComponent(id);
26
+ if (section === 'issues') return joinUrl(context.apiBase, `${project}/issues/${encoded}`);
27
+ if (section === 'pulls') return joinUrl(context.apiBase, `${project}/merge_requests/${encoded}`);
28
+ return joinUrl(context.apiBase, `${project}/releases/${encoded}`);
29
+ }
30
+
31
+ function mergeFacts(record: Record<string, unknown>): Array<{ label: string; value: string }> {
32
+ const facts: Array<{ label: string; value: string }> = [];
33
+ const source = text(record.source_branch);
34
+ const target = text(record.target_branch);
35
+ if (source || target) facts.push({ label: 'branch', value: `${target || '?'} ← ${source || '?'}` });
36
+ const changes = numberish(record.changes_count, -1);
37
+ if (changes >= 0) facts.push({ label: 'files', value: String(changes) });
38
+ if (record.has_conflicts === true) facts.push({ label: 'mergeable', value: 'conflicts' });
39
+ else if (record.detailed_merge_status === 'mergeable') facts.push({ label: 'mergeable', value: 'yes' });
40
+ return facts;
41
+ }
42
+
43
+ /**
44
+ * The notes thread, with GitLab's own audit entries marked rather than dropped.
45
+ *
46
+ * A `system` note is "changed the description", "added 1 commit", "approved this
47
+ * merge request" — not a reply, but also not nothing: an approval recorded only
48
+ * as a system note is the one place a reader learns who approved. So the row is
49
+ * kept and flagged, and the panel draws it as a line rather than as a message.
50
+ */
51
+ async function readNotes(
52
+ context: ForgeContext,
53
+ section: ForgeSection,
54
+ id: string,
55
+ notes: string[],
56
+ ): Promise<ForgeDetail['comments']> {
57
+ if (section === 'releases') return [];
58
+ const kind = section === 'issues' ? 'issues' : 'merge_requests';
59
+ const url = withParams(
60
+ joinUrl(context.apiBase, `${projectPath(context)}/${kind}/${encodeURIComponent(id)}/notes`),
61
+ { per_page: '100', sort: 'asc' },
62
+ );
63
+ const result = await get(context, url);
64
+ if (!result.ok) {
65
+ notes.push(`comments: ${result.message}`);
66
+ return [];
67
+ }
68
+ return listAt(result.value).flatMap((raw) => {
69
+ const entry = asRecord(raw);
70
+ if (!entry) return [];
71
+ return [
72
+ {
73
+ id: String(count(entry.id, 0)),
74
+ author: textAt(entry.author, 'username', 'unknown'),
75
+ body: text(entry.body),
76
+ createdAt: text(entry.created_at),
77
+ url: null,
78
+ system: flag(entry.system),
79
+ bot: false,
80
+ },
81
+ ];
82
+ });
83
+ }
84
+
85
+ /** The pipeline's verdict for a merge request, from its own detail. */
86
+ function pipelineOf(record: Record<string, unknown>): ForgeDetail['ci'] {
87
+ const pipeline = recordAt(record, 'head_pipeline');
88
+ if (!pipeline) return null;
89
+ return ciBadge([text(pipeline.status)], text(pipeline.web_url) || null);
90
+ }
91
+
92
+ /**
93
+ * A merge request's changed files.
94
+ *
95
+ * They are NOT on the merge request itself: measured on a real project, the
96
+ * detail payload carries `changes_count: "15"` and NO `changes` array, and the
97
+ * files live at `/merge_requests/:iid/changes`. Reading the array off the detail
98
+ * reported zero files for every merge request — a wrong answer that looks like a
99
+ * small change.
100
+ */
101
+ async function readFiles(
102
+ context: ForgeContext,
103
+ id: string,
104
+ notes: string[],
105
+ ): Promise<ForgeFile[]> {
106
+ const url = joinUrl(context.apiBase, `${projectPath(context)}/merge_requests/${encodeURIComponent(id)}/changes`);
107
+ const result = await get(context, url);
108
+ if (!result.ok) {
109
+ notes.push(`files: ${result.message}`);
110
+ return [];
111
+ }
112
+ return filesOf(asRecord(result.value) ?? {});
113
+ }
114
+
115
+ /** The `changes` array, mapped. */
116
+ function filesOf(record: Record<string, unknown>): ForgeFile[] {
117
+ return listAt(record.changes).flatMap((raw) => {
118
+ const entry = asRecord(raw);
119
+ if (!entry) return [];
120
+ const path = text(entry.new_path) || text(entry.old_path);
121
+ if (!path) return [];
122
+ const renamed = flag(entry.renamed_file);
123
+ return [
124
+ {
125
+ path,
126
+ status: flag(entry.new_file) ? 'added' : flag(entry.deleted_file) ? 'removed' : renamed ? 'renamed' : 'modified',
127
+ additions: 0,
128
+ deletions: 0,
129
+ patch: text(entry.diff),
130
+ },
131
+ ];
132
+ });
133
+ }
134
+
135
+ /**
136
+ * A merge request's commits.
137
+ *
138
+ * GitLab reports neither a count nor an author per commit on the MR object, so
139
+ * this is a second read — and a failure is a note, because the diff and the
140
+ * conversation are already on screen.
141
+ */
142
+ async function readCommits(
143
+ context: ForgeContext,
144
+ id: string,
145
+ notes: string[],
146
+ ): Promise<ForgeCommit[]> {
147
+ const url = joinUrl(context.apiBase, `${projectPath(context)}/merge_requests/${encodeURIComponent(id)}/commits`);
148
+ const result = await get(context, url);
149
+ if (!result.ok) {
150
+ notes.push(`commits: ${result.message}`);
151
+ return [];
152
+ }
153
+ return listAt(result.value).flatMap((raw) => {
154
+ const entry = asRecord(raw);
155
+ if (!entry) return [];
156
+ const sha = text(entry.id) || text(entry.short_id);
157
+ if (!sha) return [];
158
+ return [
159
+ {
160
+ sha,
161
+ message: text(entry.title) || text(entry.message).split('\n')[0],
162
+ author: text(entry.author_name, 'unknown'),
163
+ at: text(entry.authored_date) || text(entry.created_at),
164
+ },
165
+ ];
166
+ });
167
+ }
168
+
169
+ export async function detailGitlab(
170
+ context: ForgeContext,
171
+ section: ForgeSection,
172
+ id: string,
173
+ ): Promise<ForgeDetail | { error: string }> {
174
+ const notes: string[] = [];
175
+ const result = await get(context, itemUrl(context, section, id));
176
+ if (!result.ok) return { error: result.message };
177
+
178
+ const record = asRecord(result.value) ?? {};
179
+ const mapper = section === 'issues' ? issueItem : section === 'pulls' ? mergeItem : releaseItem;
180
+ const item = mapper(record);
181
+ if (!item) return { error: 'The host returned an item this plugin could not read.' };
182
+
183
+ const facts: Array<{ label: string; value: string }> = [];
184
+ if (section === 'pulls') facts.push(...mergeFacts(record));
185
+ if (section === 'releases') {
186
+ const tag = text(record.tag_name);
187
+ if (tag) facts.push({ label: 'tag', value: tag });
188
+ }
189
+
190
+ const [comments, commits, files] = await Promise.all([
191
+ readNotes(context, section, id, notes),
192
+ section === 'pulls' ? readCommits(context, id, notes) : Promise.resolve([]),
193
+ section === 'pulls' ? readFiles(context, id, notes) : Promise.resolve([]),
194
+ ]);
195
+
196
+ return {
197
+ item,
198
+ body: text(record.description),
199
+ comments,
200
+ facts,
201
+ files,
202
+ commits,
203
+ ci: section === 'pulls' ? pipelineOf(record) : null,
204
+ capabilities: capabilitiesFor({ provider: 'gitlab', section, hasCredential: Boolean(context.token) }),
205
+ notes,
206
+ };
207
+ }