@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,219 @@
1
+ # Forge
2
+
3
+ A right-panel view of a repository's **issues**, **pull / merge requests** and
4
+ **releases**, read from GitHub, GitLab, Gitea/Forgejo or Bitbucket — with the
5
+ comment, review, close and merge verbs each host actually supports.
6
+
7
+ It is the review side of a checkout: Source Control shows what you have changed,
8
+ this shows what is waiting on the host.
9
+
10
+ ## One plugin, three sections
11
+
12
+ The sidebar lists the three collections with their counts, in the shape the wiki
13
+ panel's nav already taught: a section is a place you go, not a filter you toggle.
14
+ A `+` on a count means the host returned a full page.
15
+
16
+ **The vocabulary follows the host**: `Pull requests` on GitHub, `Merge requests`
17
+ on GitLab, and the provider badge in the header says which one you are looking
18
+ at. One component, one data shape, one word per vendor.
19
+
20
+ ## Four hosts, one shape
21
+
22
+ | Host | Read from | Notes |
23
+ |---|---|---|
24
+ | GitHub | `search/issues` + `/pulls` + `/releases` | Issues AND pull requests come from the search endpoint — see below |
25
+ | GitLab | `/projects/:id/{issues,merge_requests,releases}` | Project path URL-encoded; `opened` not `open` |
26
+ | Gitea / Forgejo | `/repos/:id/issues?type=…` + `/releases` | One endpoint for issues and pull requests, split by `type` |
27
+ | Bitbucket Cloud | `api.bitbucket.org/2.0/repositories/:ws/:repo/…` | Paged envelopes, uppercase states, no label parameter |
28
+
29
+ The provider is derived from the remote's host name, and `auto` is the default:
30
+ `github.com` (or any host containing `github`) is GitHub, `bitbucket.org` is
31
+ Bitbucket, a name containing `gitea`/`forgejo`/`codeberg` is Gitea, and
32
+ everything else is GitLab — which is what a self-hosted GitLab needs.
33
+
34
+ ### Why GitHub's issues come from the search endpoint
35
+
36
+ `/repos/:owner/:repo/issues` returns pull requests too — they carry a
37
+ `pull_request` key — and the documented workaround is to filter them out of the
38
+ response. That works until a page is *full* of pull requests: measured on
39
+ `oven-sh/bun` with `state=open`, the five newest "issues" were all PRs, so
40
+ filtering left **zero** issues on screen while 3 595 were open.
41
+
42
+ `search/issues?q=repo:x is:issue` answers exactly the issue collection, and it
43
+ takes the same qualifier grammar as the pull-request search — so ONE path serves
44
+ both sections AND every filter. The cost is stated rather than hidden: search has
45
+ its own budget (30/min authenticated) and sends **no `ETag`**, so its re-read is
46
+ always a full response. The other sections revalidate and cost nothing while
47
+ nothing changed.
48
+
49
+ ## Filters
50
+
51
+ | Control | GitHub | GitLab | Gitea | Bitbucket |
52
+ |---|---|---|---|---|
53
+ | Open / Closed / All | `state:` | `state=opened\|closed` | `state=` | BBQL `state="…"` |
54
+ | Mine | `assignee:@me` | `scope=assigned_to_me` | `assigned=true` | not offered |
55
+ | Label | `label:` (quoted) | `labels=` | `labels=` | BBQL `labels ~` |
56
+ | Text | free qualifier | `search=` | `q=` | BBQL `title ~` |
57
+
58
+ Two rules are load-bearing and each was a defect first. **A label with a space
59
+ must be quoted** (`label:"good first issue"`), or the host reads the second word
60
+ as another qualifier and the filter returns nothing. **`all` is not a value on
61
+ GitHub** — the state qualifier is omitted rather than sent as `state:all`, which
62
+ matches nothing.
63
+
64
+ Typed filters are committed after a pause (400 ms): every keystroke would
65
+ otherwise be one request against a 30/minute budget.
66
+
67
+ ## Reading an item
68
+
69
+ A row opens the item: title, state badge, labels, the description rendered
70
+ through Kabmo's own markdown pipeline, and then — folded, with counts — the
71
+ change's **files** and **commits**, and the conversation below them.
72
+
73
+ - **Files** show path, status and `+n −n`; a row expands to its hunk. A binary
74
+ change is listed with no disclosure, because a code block over `Binary files
75
+ differ` reads as a broken diff.
76
+ - **Commits** show the first line, the short sha and the age.
77
+ - **The CI badge** is detail-only, and that is a measured decision: no host puts a
78
+ pipeline on a LIST response (GitLab's `head_pipeline` is `failed` on the merge
79
+ request and `null` on every collection row; GitHub's PR list carries no checks).
80
+ A row badge would cost one request per row.
81
+ - **A system or bot entry is drawn differently.** GitLab's `system` notes are
82
+ "changed the description", "approved this merge request"; GitHub's App accounts
83
+ are `dependabot[bot]`. Both are worth showing — an approval recorded only as a
84
+ system note is the one place a reader learns who approved — and neither is a
85
+ reply, so both are a muted line rather than a message.
86
+
87
+ ## Writing
88
+
89
+ The verbs come from the **server's** capability table, computed per read from the
90
+ provider, the section and whether a credential exists — so a public repository
91
+ read anonymously offers nothing, and the panel never has to guess.
92
+
93
+ | Verb | GitHub | GitLab | Gitea | Bitbucket |
94
+ |---|---|---|---|---|
95
+ | Comment | `POST …/issues/:n/comments` | `POST …/notes` | `POST …/issues/:n/comments` | `POST …/comments` with `{content:{raw}}` |
96
+ | Close / reopen | `PATCH {state}` | `PUT {state_event}` | `PATCH {state}` | `POST …/decline` (pull), `PUT {state}` (issue) |
97
+ | Approve | `POST …/reviews` | `POST …/approve` | `POST …/reviews` | `POST …/approve` |
98
+ | Request changes | `POST …/reviews` | **not offered** | `POST …/reviews` | **not offered** |
99
+ | Merge | `PUT …/merge {merge_method}` | `PUT …/merge {squash}` | `POST …/merge {Do}` | `POST …/merge {merge_strategy}` |
100
+
101
+ Three of those differences are silent when wrong, which is why they are stated
102
+ per host rather than assumed: **GitLab's close is an event** (`state_event`) and
103
+ sending `state: closed` is accepted and ignored, so the merge request stays open
104
+ while the panel reports success; **Bitbucket has no comment body at the top
105
+ level** and no state field on a pull request; **Gitea's merge style is `Do`**.
106
+
107
+ Every verb is confirmed by a dialog that names the consequence — the method, the
108
+ branch pair, that a squash discards the branch history — rather than asking
109
+ "are you sure?". A dialog that only asks whether you meant to click teaches you to
110
+ click through it.
111
+
112
+ **GitLab has no "request changes" event**, so that button is absent there and the
113
+ server refuses the verb by name with the alternative (add a comment, or approve).
114
+ Bitbucket has no review verdict at all.
115
+
116
+ After a write, every cached entry for the repository is dropped: a write changes
117
+ the item AND the list it came from, and those are different URLs.
118
+
119
+ ## Credential
120
+
121
+ Three sources, tried in this order:
122
+
123
+ 1. `GITHUB_TOKEN` / `GH_TOKEN` / `GITLAB_TOKEN` / `GITEA_TOKEN` /
124
+ `BITBUCKET_TOKEN` in the **server's** environment (the process that runs
125
+ `kabmo serve`, not your shell — restart it after exporting one);
126
+ 2. the vendor CLI — `gh auth token`, or `glab auth status` — read **once** per
127
+ process and cached, including a failure, so a logged-out machine pays one
128
+ spawn rather than one per panel open. Gitea and Bitbucket have no such CLI;
129
+ 3. nothing, which is legitimate: a public repository reads anonymously, and the
130
+ panel says so above the list.
131
+
132
+ Bitbucket accepts an access token (`Bearer`) or an app password
133
+ (`user:app-password`, sent as Basic) — the colon is what tells them apart.
134
+
135
+ The manifest also declares a `token` setting, and the server half reads it first —
136
+ but **this host has no editor for a panel plugin's declared settings yet** (no
137
+ route, no form), so today that value is only reachable if something else writes
138
+ it. The environment and CLI above are the sources that work out of the box, and
139
+ the panel's own sentences name them rather than pointing at a screen that does
140
+ not exist. The same applies to `provider`, `apiBase` and `perPage`.
141
+
142
+ The header carries a key glyph that opens a **credential sheet**: which source is
143
+ in use, and — on request — whether that credential can WRITE. The probe is one
144
+ request and answers three ways: `yes`, `no`, or "this host does not say" (a
145
+ fine-grained GitHub token, Gitea, Bitbucket). A read-only token is the reason a
146
+ panel would otherwise show verbs that can only fail, so it is worth one request
147
+ when the reader asks; it is never run on a panel mount.
148
+
149
+ ## The navbar readout and `/issue`
150
+
151
+ - **`Waiting on me`** in the navbar shows open issues and open requests assigned
152
+ to you, and opens the panel. It reads at most once every five minutes, and only
153
+ with a credential — an anonymous read has no authenticated user, so "assigned
154
+ to me" is a question the host cannot answer (measured: GitHub answers
155
+ `assignee:@me` with a total of 0, which would draw a confident zero over an
156
+ unanswerable question).
157
+ - **`/issue <number>`** quotes an item into the composer: its id, title, link and
158
+ the first paragraph of its description, then a `---` divider so you type your
159
+ question under it. `#12` and a full URL work too. The quote is INSERTED, not
160
+ set, so a draft you already had is kept.
161
+
162
+ ## What it does not do
163
+
164
+ - **No pagination past one page.** A section asks for `per_page` (default 30) and
165
+ says when it came back full rather than pretending the list is complete.
166
+ - **No counts without a token.** "Assigned to me" is not a question an anonymous
167
+ read can answer — measured on Gitea, where an anonymous `assigned=true` read
168
+ answered a full page and the readout said `3 issues · 3 PRs` for a reader who
169
+ has none — so the readout draws `—` with the reason.
170
+ - **No review threads or inline comments.** The conversation is shown; a
171
+ per-line review needs a diff view this panel does not own.
172
+ - **No notifications.** Nothing polls in the background except the readout's own
173
+ five-minute timer.
174
+ - **No search across repositories.** The scope is one checkout.
175
+ - **No issue-tracker features** (milestones, assignee editing, boards).
176
+
177
+ ## Settings
178
+
179
+ Declared in the manifest and read by the server half. **There is no editor for
180
+ these yet** — the host has no form or route for a panel plugin's declared
181
+ settings — so what an install runs on is the default column, plus the
182
+ environment/CLI credential above.
183
+
184
+ | Setting | Default | What it does |
185
+ |---|---|---|
186
+ | API token | empty | A token, read before the environment. |
187
+ | Forge | `auto` | `auto`, `github`, `gitlab`, `gitea` or `bitbucket`. |
188
+ | API base URL | empty | Overrides the derived API root, e.g. `https://github.mycorp.com/api/v3`. |
189
+ | Items per section | 30 | How many items one read asks for. |
190
+
191
+ ## Tests
192
+
193
+ ```
194
+ bun test marketplace/plugins/git-forge/
195
+ ```
196
+
197
+ 201 assertions across 17 files. Each suite owns one rule that fails silently:
198
+
199
+ - `remote.test.ts` — the remote parser: credentials, ports, subgroups, local
200
+ paths, and the four hosts' API roots.
201
+ - `token.test.ts` — the credential ladder, and that a CLI answer is read once.
202
+ - `http.test.ts` / `write-http.test.ts` — the conditional read (a second read of
203
+ an unchanged resource, a changed one, the cache bound) and the write path (no
204
+ validator, invalidation by repository).
205
+ - `filters.test.ts` — four hosts' filter grammars, including the quoting rule.
206
+ - `ci.test.ts` — the CI vocabulary: an in-flight run is pending, a skipped job is
207
+ not a failure, and an unknown word is neutral rather than red.
208
+ - `diff.test.ts` — the unified diff parser for the two hosts that answer text.
209
+ - `capabilities.test.ts` — what a read may offer, and the sentence a refusal uses.
210
+ - `scope-probe.test.ts` — the write-scope probe, where "cannot tell" must never be
211
+ read as "no".
212
+ - `writes.test.ts` — every verb on every host, through the injected fetch, so
213
+ nothing here can reach a real repository.
214
+ - `adapters.test.ts` / `gitlab.test.ts` / `forges.test.ts` — the four adapters
215
+ against recorded bodies, including the three sub-resources a host puts somewhere
216
+ other than on the item itself.
217
+ - `command.test.ts` — `/issue`'s parsing, the quotation and the insert.
218
+ - `panel/index.test.tsx` / `panel/write.test.tsx` — the assembled panel and its
219
+ write surface in a real DOM.
@@ -0,0 +1,20 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-label="Forge">
2
+ <title>Forge</title>
3
+ <!-- Geometry follows the built-in views' convention (Lucide): the art is inset
4
+ 2/24 of the box and strokes at 2/24, so a plugin's mark carries the same
5
+ ink weight as the icons it sits beside. Paint is `currentColor`: the host
6
+ draws a vector mark through a CSS mask, so the file supplies the shape and
7
+ the surrounding ink supplies the colour.
8
+
9
+ The shape is Lucide's `git-pull-request`, and the choice is deliberate:
10
+ Source Control already owns `git-branch`, and two buttons in one activity
11
+ bar carrying the same mark is the collision the command-runner's icon
12
+ note warns about. This panel is about the REVIEW side of a repository —
13
+ issues, requests and releases — which is exactly what this glyph means. -->
14
+ <g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
15
+ <circle cx="18" cy="18" r="3" />
16
+ <circle cx="6" cy="6" r="3" />
17
+ <path d="M13 6h3a2 2 0 0 1 2 2v7" />
18
+ <path d="M6 9v12" />
19
+ </g>
20
+ </svg>
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "git-forge",
3
+ "version": "0.3.0",
4
+ "private": true,
5
+ "description": "Reads and acts on a repository's issues, pull/merge requests and releases on GitHub, GitLab, Gitea or Bitbucket.",
6
+ "type": "module",
7
+ "kabmo": {
8
+ "id": "git-forge",
9
+ "name": "Forge",
10
+ "version": "0.3.0",
11
+ "description": "Reads and acts on a repository's issues, pull/merge requests and releases on GitHub, GitLab, Gitea or Bitbucket.",
12
+ "app": "dist/app.js",
13
+ "server": "dist/server.js",
14
+ "icon": "icon.svg",
15
+ "author": { "name": "Kabmo Labs", "url": "https://github.com/kabmo-labs" },
16
+ "slots": ["rightPanel", "headerPanel"],
17
+ "capabilities": ["server", "storage", "rpc", "settings", "repo-scope"],
18
+ "settings": {
19
+ "token": {
20
+ "type": "string",
21
+ "label": "API token",
22
+ "description": "A GitHub or GitLab token. Optional: a public repository reads anonymously, and the server environment (GITHUB_TOKEN / GH_TOKEN / GITLAB_TOKEN) or a logged-in gh / glab is tried before this.",
23
+ "secret": true,
24
+ "default": ""
25
+ },
26
+ "provider": {
27
+ "type": "string",
28
+ "label": "Forge (auto, github, gitlab, gitea, bitbucket)",
29
+ "description": "Which API the remote speaks. `auto` reads the host name: github.com (or any host containing github) is GitHub, bitbucket.org is Bitbucket, a name containing gitea/forgejo/codeberg is Gitea, and everything else is GitLab.",
30
+ "default": "auto"
31
+ },
32
+ "apiBase": {
33
+ "type": "string",
34
+ "label": "API base URL",
35
+ "description": "Overrides the derived API root, e.g. https://github.mycorp.com/api/v3. Leave empty unless the host serves its API somewhere unusual.",
36
+ "default": ""
37
+ },
38
+ "perPage": {
39
+ "type": "number",
40
+ "label": "Items per section",
41
+ "description": "How many issues, pull requests and releases one read asks for. A section that comes back full is reported as truncated.",
42
+ "default": 30
43
+ }
44
+ }
45
+ },
46
+ "peerDependencies": {
47
+ "@kabmo-labs/kabmo-sdk": "*",
48
+ "@kabmo-labs/kabmo-ui": "*",
49
+ "preact": "^10.29.8"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@kabmo-labs/kabmo-sdk": { "optional": true },
53
+ "@kabmo-labs/kabmo-ui": { "optional": true },
54
+ "preact": { "optional": true }
55
+ }
56
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The Forge's app half.
8
+ *
9
+ * Three contributions, and each answers a question the others cannot:
10
+ *
11
+ * - **`rightPanel`** is the view: the list, the item, the writes.
12
+ * - **`headerPanel`** is the readout — how many open items are assigned to the
13
+ * reader — and it OPENS the panel (`opensPanel`), so the number is a way back
14
+ * to the list it counts rather than a decoration. It is a readout and not a
15
+ * dropdown because a header dropdown is 320px in a 40px bar and the panel is
16
+ * already one click away.
17
+ * - **`commandPaletteAction`** is `/issue <n>`, which quotes an item into the
18
+ * composer. It is the one contribution that acts on the CONVERSATION, which is
19
+ * what makes the plugin useful for a repository nobody is reviewing.
20
+ *
21
+ * No content script: one exists when a plugin has work to do while its panel is
22
+ * unmounted (the command-runner's force-stop is the example). A forge read is
23
+ * only worth doing while somebody is looking at it — and the readout's own timer
24
+ * lives with the readout, which the host keeps mounted.
25
+ */
26
+
27
+ import { definePluginApp } from '@kabmo-labs/kabmo-sdk/app';
28
+ import { requireServices } from '@kabmo-labs/kabmo-ui';
29
+
30
+ import { ForgePanel } from './panel';
31
+ import { ForgeReadout } from './header';
32
+ import { runIssueCommand } from './command';
33
+
34
+ export default definePluginApp((app) => {
35
+ const pluginId = app.pluginId;
36
+
37
+ app.rightPanel({
38
+ id: 'forge',
39
+ title: 'Issues & requests',
40
+ component: ForgePanel,
41
+ // A row carries a state badge, a title, an id, an author, a count and up to
42
+ // two labels; below this the title is a fragment.
43
+ minWidth: 420,
44
+ });
45
+
46
+ app.headerPanel({
47
+ id: 'forge-counts',
48
+ title: 'Waiting on me',
49
+ component: ForgeReadout,
50
+ opensPanel: 'rightPanel',
51
+ });
52
+
53
+ /**
54
+ * `/issue <number>`.
55
+ *
56
+ * A command's `run` is not a component, so it reads the kit's SERVICES rather
57
+ * than hooks — the same reason the command-runner's content script does. The
58
+ * pure half lives in `command.ts`, which is what the tests drive.
59
+ */
60
+ app.commandPaletteAction({
61
+ id: 'issue',
62
+ command: 'issue',
63
+ description: 'Quote an issue or pull request into the prompt',
64
+ hint: '<number>',
65
+ run: (context) => {
66
+ const services = requireServices();
67
+ // The SHARED repo pick, not the workspace root: a monorepo's repository is
68
+ // a nested path, and reading the root would ask the wrong project's forge.
69
+ const scope = services.repoScope?.();
70
+ const target = scope?.root ? { root: scope.root, repo: scope.repo } : null;
71
+ return runIssueCommand(context.args, {
72
+ scope: target,
73
+ call: async (method, input) =>
74
+ services.callRpc
75
+ ? await services.callRpc(pluginId, method, input)
76
+ : { ok: false, error: { code: 'no_plugin', message: 'This component is not inside a plugin.' } },
77
+ insert: (text) => services.composer?.().insert(text),
78
+ report: (message) => services.composer?.().insert(`\n${message}\n`),
79
+ });
80
+ },
81
+ });
82
+ });
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * `/issue` and the readout's own rules, without a host.
8
+ *
9
+ * The command is a pure function over an injected `call`/`insert`/`report`, which
10
+ * is what makes it testable: the alternative is mounting the composer, the
11
+ * plugin runtime and a fake socket to check that a number was parsed.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+
16
+ import { firstParagraph, parseItemId, quoteFor, runIssueCommand, USAGE } from './command';
17
+ import type { ForgeDetail, ForgeItem } from './protocol';
18
+
19
+ function item(overrides: Partial<ForgeItem> = {}): ForgeItem {
20
+ return {
21
+ id: '12',
22
+ number: 12,
23
+ title: 'A crash on start',
24
+ state: 'open',
25
+ author: 'ana',
26
+ updatedAt: '2026-01-01T00:00:00Z',
27
+ url: 'https://github.com/o/n/issues/12',
28
+ labels: [],
29
+ comments: 0,
30
+ tag: null,
31
+ ...overrides,
32
+ };
33
+ }
34
+
35
+ function detail(body: string): ForgeDetail {
36
+ return {
37
+ item: item(),
38
+ body,
39
+ comments: [],
40
+ facts: [],
41
+ files: [],
42
+ commits: [],
43
+ ci: null,
44
+ capabilities: { comment: true, state: true, review: false, merge: false },
45
+ notes: [],
46
+ };
47
+ }
48
+
49
+ describe('parseItemId', () => {
50
+ test('a bare number, a hash and a URL all name the same item', () => {
51
+ expect(parseItemId('12')).toBe(12);
52
+ expect(parseItemId('#12')).toBe(12);
53
+ expect(parseItemId(' 12 ')).toBe(12);
54
+ expect(parseItemId('https://github.com/o/n/issues/12')).toBe(12);
55
+ expect(parseItemId('https://github.com/o/n/pull/12/')).toBe(12);
56
+ expect(parseItemId('https://gitlab.com/o/n/-/merge_requests/12')).toBe(12);
57
+ });
58
+
59
+ test('anything else is refused rather than read as a number', () => {
60
+ for (const args of ['', ' ', 'abc', '#', '12abc', '0', '-3', '1.5']) {
61
+ expect(parseItemId(args)).toBeNull();
62
+ }
63
+ });
64
+ });
65
+
66
+ describe('firstParagraph', () => {
67
+ test('stops at the first blank line', () => {
68
+ expect(firstParagraph('one\ntwo\n\nthree')).toBe('> one\n> two');
69
+ });
70
+
71
+ test('bounds a long paragraph and marks the cut', () => {
72
+ const long = 'x'.repeat(700);
73
+ const quoted = firstParagraph(long);
74
+ expect(quoted.endsWith('…')).toBe(true);
75
+ expect(quoted.length).toBeLessThan(700);
76
+ });
77
+
78
+ test('every line is quoted, so a fence cannot escape', () => {
79
+ expect(firstParagraph('```ts\nconst a = 1;\n```')).toBe('> ```ts\n> const a = 1;\n> ```');
80
+ });
81
+
82
+ test('an empty body yields nothing to quote', () => {
83
+ expect(firstParagraph(' ')).toBe('');
84
+ });
85
+ });
86
+
87
+ describe('quoteFor', () => {
88
+ test('the divider sits after the quote, and a blank line keeps it a rule', () => {
89
+ const text = quoteFor(detail('Body text.'));
90
+ expect(text).toContain('> #12 A crash on start');
91
+ expect(text).toContain('> https://github.com/o/n/issues/12');
92
+ expect(text).toContain('> Body text.');
93
+ // `---` directly under a line of text is a setext heading, so the blank line
94
+ // before it is what makes it a rule.
95
+ expect(text).toContain('\n\n---\n\n');
96
+ });
97
+
98
+ test('an item with no description still quotes its identity', () => {
99
+ const text = quoteFor(detail(''));
100
+ expect(text).toBe('> #12 A crash on start\n> https://github.com/o/n/issues/12\n\n---\n\n');
101
+ });
102
+
103
+ test('a release quotes its tag rather than a number', () => {
104
+ const text = quoteFor({
105
+ ...detail('Notes'),
106
+ item: item({ number: null, tag: 'v1.2.3', title: 'Release 1.2.3', url: 'https://x/v1.2.3' }),
107
+ });
108
+ expect(text).toContain('> v1.2.3 Release 1.2.3');
109
+ });
110
+ });
111
+
112
+ describe('runIssueCommand', () => {
113
+ test('an issue is quoted, and the text is INSERTED rather than set', async () => {
114
+ const inserted: string[] = [];
115
+ const set: string[] = [];
116
+ await runIssueCommand('12', {
117
+ scope: { root: '/ws', repo: '.' },
118
+ call: async (method) => (method === 'detail' ? { ok: true, value: detail('Body.') } : { ok: false }),
119
+ insert: (text) => inserted.push(text),
120
+ report: () => set.push('reported'),
121
+ });
122
+ expect(inserted).toHaveLength(1);
123
+ expect(inserted[0]).toContain('> #12');
124
+ expect(set).toEqual([]);
125
+ });
126
+
127
+ test('a number that names a pull request is found in the second collection', async () => {
128
+ const sections: string[] = [];
129
+ await runIssueCommand('#7', {
130
+ scope: { root: '/ws', repo: '.' },
131
+ call: async (_method, input) => {
132
+ const section = (input as { section: string }).section;
133
+ sections.push(section);
134
+ return section === 'pulls'
135
+ ? { ok: true, value: { ...detail('Body.'), item: item({ number: 7 }) } }
136
+ : { ok: false, error: { message: 'Not found (404).' } };
137
+ },
138
+ insert: () => {},
139
+ report: () => {},
140
+ });
141
+ expect(sections).toEqual(['issues', 'pulls']);
142
+ });
143
+
144
+ test('no id reports the usage line and calls nothing', async () => {
145
+ let called = false;
146
+ const reported: string[] = [];
147
+ await runIssueCommand('nope', {
148
+ scope: { root: '/ws', repo: '.' },
149
+ call: async () => {
150
+ called = true;
151
+ return { ok: false };
152
+ },
153
+ insert: () => {},
154
+ report: (message) => reported.push(message),
155
+ });
156
+ expect(called).toBe(false);
157
+ expect(reported).toEqual([USAGE]);
158
+ });
159
+
160
+ test('no workspace is reported, because there is no repository to ask about', async () => {
161
+ const reported: string[] = [];
162
+ await runIssueCommand('12', {
163
+ scope: null,
164
+ call: async () => ({ ok: false }),
165
+ insert: () => {},
166
+ report: (message) => reported.push(message),
167
+ });
168
+ expect(reported.join(' ')).toContain('open workspace');
169
+ });
170
+
171
+ test('both collections refusing reports the first reason', async () => {
172
+ const reported: string[] = [];
173
+ await runIssueCommand('12', {
174
+ scope: { root: '/ws', repo: '.' },
175
+ call: async () => ({ ok: false, error: { message: 'This repository has no origin remote.' } }),
176
+ insert: () => {},
177
+ report: (message) => reported.push(message),
178
+ });
179
+ expect(reported).toEqual(['This repository has no origin remote.']);
180
+ });
181
+ });
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * `/issue <number>` — put an item's context in the composer.
8
+ *
9
+ * The composer is where a question about a ticket gets asked ("why does #42377
10
+ * only happen under `--cpu-prof`?"), and retyping the title and the link is work
11
+ * the panel already has the answer to. So the command reads the item and inserts
12
+ * a QUOTATION — the title, the link, and the description's first paragraph — and
13
+ * the reader types their question under it.
14
+ *
15
+ * Three rules, each of which is a bug shape if dropped:
16
+ *
17
+ * - **The id is parsed, not trusted.** `/issue 12`, `/issue #12` and `/issue
18
+ * https://github.com/o/n/issues/12` all mean the same thing, and anything else
19
+ * is refused with the usage line rather than read as a number.
20
+ * - **Issues are tried first, then pull requests**, because the number alone
21
+ * cannot say which collection it belongs to and both are addressed by it.
22
+ * - **The insert is an INSERT, not a `set`**: the reader may already have a
23
+ * draft, and replacing it would throw away what they wrote before they asked
24
+ * for context.
25
+ */
26
+
27
+ import type { ForgeDetail, ForgeSection } from './protocol';
28
+ import { RPC } from './protocol';
29
+
30
+ /** The usage line, shown when the argument is not an id. */
31
+ export const USAGE = '/issue <number> — quote an issue or pull request into the prompt';
32
+
33
+ /**
34
+ * The number in an argument, or null.
35
+ *
36
+ * The URL form is accepted because that is what a reader copies from a browser,
37
+ * and it is read as the LAST path segment rather than by a regex over the whole
38
+ * string: a repository named `issues` would otherwise make the path ambiguous.
39
+ */
40
+ export function parseItemId(args: string): number | null {
41
+ const trimmed = args.trim();
42
+ if (!trimmed) return null;
43
+ const fromUrl = trimmed.match(/\/(?:issues|pull|merge_requests)\/(\d+)\/?$/);
44
+ if (fromUrl) return Number(fromUrl[1]);
45
+ const bare = trimmed.replace(/^#/, '');
46
+ if (!/^\d+$/.test(bare)) return null;
47
+ const value = Number(bare);
48
+ return Number.isSafeInteger(value) && value > 0 ? value : null;
49
+ }
50
+
51
+ /** The first paragraph of a description, bounded — a quote, not a copy. */
52
+ export function firstParagraph(markdown: string, limit = 600): string {
53
+ const body = markdown.replace(/\r\n/g, '\n').trim();
54
+ if (!body) return '';
55
+ const paragraph = body.split(/\n\s*\n/)[0].trim();
56
+ const text = paragraph.length > limit ? `${paragraph.slice(0, limit).trimEnd()}…` : paragraph;
57
+ // A quoted block: every line prefixed, so a heading or a fence inside the quote
58
+ // cannot escape it and turn the prompt into the ticket's own markdown.
59
+ return text
60
+ .split('\n')
61
+ .map((line) => `> ${line}`)
62
+ .join('\n');
63
+ }
64
+
65
+ /**
66
+ * The text to insert for one item.
67
+ *
68
+ * A blank line separates the quote from the cursor, and the divider sits AFTER
69
+ * it: a `---` directly under a line of text is a setext heading in markdown, and
70
+ * the timeline renders a user turn as markdown.
71
+ */
72
+ export function quoteFor(detail: ForgeDetail): string {
73
+ const item = detail.item;
74
+ const id = item.number !== null ? `#${item.number}` : item.tag;
75
+ // Both lines are quoted: a bare URL under a quoted title ends the block, and
76
+ // the link then reads as the prompt's own text rather than as part of the
77
+ // quotation.
78
+ const head = `> ${id} ${item.title}\n> ${item.url}`;
79
+ const body = firstParagraph(detail.body);
80
+ return body ? `${head}\n>\n${body}\n\n---\n\n` : `${head}\n\n---\n\n`;
81
+ }
82
+
83
+ /** What a caller needs to run the command: the RPC and the composer's insert. */
84
+ export interface IssueCommandDeps {
85
+ call: (method: string, input: unknown) => Promise<{ ok: boolean; value?: unknown; error?: { message: string } }>;
86
+ insert: (text: string) => void;
87
+ /** Where the repository is, or null when there is no workspace. */
88
+ scope: { root: string; repo: string } | null;
89
+ /** Reports a refusal where the reader is looking. */
90
+ report: (message: string) => void;
91
+ }
92
+
93
+ /** The sections a bare number may name, in the order they are tried. */
94
+ const SECTIONS: readonly ForgeSection[] = ['issues', 'pulls'];
95
+
96
+ export async function runIssueCommand(args: string, deps: IssueCommandDeps): Promise<void> {
97
+ const id = parseItemId(args);
98
+ if (id === null) {
99
+ deps.report(USAGE);
100
+ return;
101
+ }
102
+ if (!deps.scope) {
103
+ deps.report('/issue needs an open workspace with a repository.');
104
+ return;
105
+ }
106
+
107
+ const reasons: string[] = [];
108
+ for (const section of SECTIONS) {
109
+ const outcome = await deps.call(RPC.detail, { ...deps.scope, section, id: String(id) });
110
+ if (outcome.ok) {
111
+ deps.insert(quoteFor(outcome.value as ForgeDetail));
112
+ return;
113
+ }
114
+ if (outcome.error) reasons.push(outcome.error.message);
115
+ }
116
+ // Both collections refused: the first reason is the one that explains why (a
117
+ // missing remote, a bad credential), and the second is usually the same.
118
+ deps.report(reasons[0] ?? `No issue or pull request numbered ${id} in this repository.`);
119
+ }