@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,107 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The credential ladder, with the CLI and the environment faked.
8
+ *
9
+ * The order is the whole contract: a token the user typed must beat one the
10
+ * shell exported, and both must beat whatever a CLI happens to have stored —
11
+ * otherwise setting a token in the panel would appear to do nothing on a machine
12
+ * where `gh` is logged into a different account.
13
+ */
14
+
15
+ import { afterEach, describe, expect, test } from 'bun:test';
16
+
17
+ import { resetTokenCache, resolveToken } from './token';
18
+
19
+ afterEach(() => resetTokenCache());
20
+
21
+ const noCli = () => ({ ok: false, stdout: '' });
22
+
23
+ describe('resolveToken', () => {
24
+ test('the setting wins over everything', () => {
25
+ const resolved = resolveToken('github', {
26
+ setting: 'ghp_setting',
27
+ env: { GITHUB_TOKEN: 'ghp_env' },
28
+ run: () => ({ ok: true, stdout: 'ghp_cli_0123456789abcdef' }),
29
+ });
30
+ expect(resolved).toEqual({ token: 'ghp_setting', source: 'setting' });
31
+ });
32
+
33
+ test('an empty setting falls through to the environment', () => {
34
+ expect(resolveToken('github', { setting: ' ', env: { GITHUB_TOKEN: 'ghp_env' }, run: noCli })).toEqual({
35
+ token: 'ghp_env',
36
+ source: 'environment',
37
+ });
38
+ expect(resolveToken('github', { setting: null, env: { GH_TOKEN: 'gho_env' }, run: noCli })).toEqual({
39
+ token: 'gho_env',
40
+ source: 'environment',
41
+ });
42
+ });
43
+
44
+ test('the environment falls through to the CLI', () => {
45
+ expect(
46
+ resolveToken('github', { setting: null, env: {}, run: () => ({ ok: true, stdout: 'ghp_cli_0123456789abcdef\n' }) }),
47
+ ).toEqual({
48
+ token: 'ghp_cli_0123456789abcdef',
49
+ source: 'cli',
50
+ });
51
+ });
52
+
53
+ test('gitlab reads its own variables, never github ones', () => {
54
+ expect(resolveToken('gitlab', { setting: null, env: { GITHUB_TOKEN: 'ghp_x' }, run: noCli })).toEqual({
55
+ token: null,
56
+ source: 'none',
57
+ });
58
+ expect(resolveToken('gitlab', { setting: null, env: { GITLAB_TOKEN: 'glpat-x' }, run: noCli })).toEqual({
59
+ token: 'glpat-x',
60
+ source: 'environment',
61
+ });
62
+ });
63
+
64
+ test('nothing anywhere is a legitimate answer', () => {
65
+ expect(resolveToken('github', { setting: null, env: {}, run: noCli })).toEqual({ token: null, source: 'none' });
66
+ });
67
+
68
+ test('a CLI answer is read once per provider', () => {
69
+ let calls = 0;
70
+ const run = () => {
71
+ calls += 1;
72
+ return { ok: true, stdout: 'ghp_cli_0123456789abcdef' };
73
+ };
74
+ resolveToken('github', { setting: null, env: {}, run });
75
+ resolveToken('github', { setting: null, env: {}, run });
76
+ expect(calls).toBe(1);
77
+ });
78
+
79
+ test('a CLI failure is cached too, so a logged-out machine pays once', () => {
80
+ let calls = 0;
81
+ const run = () => {
82
+ calls += 1;
83
+ return { ok: false, stdout: '' };
84
+ };
85
+ expect(resolveToken('github', { setting: null, env: {}, run }).token).toBeNull();
86
+ expect(resolveToken('github', { setting: null, env: {}, run }).token).toBeNull();
87
+ expect(calls).toBe(1);
88
+ });
89
+
90
+ test('glab answers through its own status text', () => {
91
+ const resolved = resolveToken('gitlab', {
92
+ setting: null,
93
+ env: {},
94
+ run: () => ({ ok: true, stdout: 'gitlab.example.com\n ✓ Logged in\n Token: glpat-from-cli\n' }),
95
+ });
96
+ expect(resolved).toEqual({ token: 'glpat-from-cli', source: 'cli' });
97
+ });
98
+
99
+ test('a CLI line that is not a token is refused rather than used', () => {
100
+ const resolved = resolveToken('github', {
101
+ setting: null,
102
+ env: {},
103
+ run: () => ({ ok: true, stdout: 'not logged in' }),
104
+ });
105
+ expect(resolved.token).toBeNull();
106
+ });
107
+ });
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Where the credential comes from.
8
+ *
9
+ * Four sources, tried in an order that keeps the common case zero-config:
10
+ *
11
+ * 1. the plugin's own setting (the only one that works on a machine with no
12
+ * `gh`/`glab` installed, and the one a panel user can edit);
13
+ * 2. the environment (`GITHUB_TOKEN`, `GH_TOKEN`, `GITLAB_TOKEN`) — what a CI
14
+ * runner or a shell already exports;
15
+ * 3. the vendor CLI, when one is installed and logged in. `gh auth token` is the
16
+ * reason a developer who has never opened this panel still sees a private
17
+ * repository's issues on the first click;
18
+ * 4. nothing, which is a legitimate state: public repositories read anonymously.
19
+ *
20
+ * The CLI is read ONCE per host per process and cached, because it costs a
21
+ * process spawn (~40 ms measured for `gh auth token`) and the answer does not
22
+ * change while the server runs. A failure is cached too: a machine with `gh`
23
+ * installed but not logged in must not pay that spawn on every panel open.
24
+ *
25
+ * **The token never leaves this module.** It is passed to the adapters as a
26
+ * header value and is never part of an RPC result, a note or a log line — the
27
+ * settings screen shows a secret as "set", and a panel has no reason to know it.
28
+ */
29
+
30
+ import type { ForgeProvider } from '../protocol';
31
+
32
+ export interface TokenSources {
33
+ /** The plugin's own `token` setting. */
34
+ setting: string | null;
35
+ env: NodeJS.ProcessEnv;
36
+ /** Injected by the tests; production reads the environment and the CLI. */
37
+ run?: (argv: string[]) => { ok: boolean; stdout: string };
38
+ }
39
+
40
+ /**
41
+ * The environment variable each provider's tooling already uses.
42
+ *
43
+ * Gitea and Bitbucket have no CLI of their own, so a token is the only source
44
+ * for them — stated rather than invented, because guessing a binary name would
45
+ * spawn a process that does not exist on every read.
46
+ */
47
+ const ENV_KEYS: Record<ForgeProvider, readonly string[]> = {
48
+ github: ['GITHUB_TOKEN', 'GH_TOKEN'],
49
+ gitlab: ['GITLAB_TOKEN', 'GLAB_TOKEN'],
50
+ gitea: ['GITEA_TOKEN'],
51
+ bitbucket: ['BITBUCKET_TOKEN'],
52
+ };
53
+
54
+ /**
55
+ * The CLI that can answer a stored credential, per provider.
56
+ *
57
+ * Absent for Gitea and Bitbucket: neither ships a credential-reading CLI, and a
58
+ * table entry naming one that does not exist would spawn a missing binary on
59
+ * every panel open.
60
+ */
61
+ const CLI: Partial<Record<ForgeProvider, readonly string[]>> = {
62
+ github: ['gh', 'auth', 'token'],
63
+ gitlab: ['glab', 'auth', 'status'],
64
+ };
65
+
66
+ /** One resolved token, and the source that supplied it. */
67
+ export interface ResolvedToken {
68
+ token: string | null;
69
+ /** `setting`, `environment`, `cli` or `none` — for the panel's own note. */
70
+ source: 'setting' | 'environment' | 'cli' | 'none';
71
+ }
72
+
73
+ /** A CLI answer, cached per provider for the life of the process. */
74
+ const cliCache = new Map<ForgeProvider, string | null>();
75
+
76
+ /**
77
+ * The default runner: an argv spawn, never a shell string.
78
+ *
79
+ * **A missing binary THROWS from `Bun.spawnSync`** (`Executable not found in
80
+ * $PATH`), and it is the ordinary case here — a machine without `gh` or `glab`
81
+ * installed. Measured: the throw escaped `resolveToken` and failed the whole
82
+ * read with "Executable not found in $PATH: glab", so a repository with a public
83
+ * forge could not be browsed at all. A missing CLI is simply no answer.
84
+ */
85
+ function defaultRun(argv: string[]): { ok: boolean; stdout: string } {
86
+ try {
87
+ const result = Bun.spawnSync(argv, { stdout: 'pipe', stderr: 'ignore', timeout: 5_000 });
88
+ return { ok: result.exitCode === 0, stdout: result.stdout ? result.stdout.toString() : '' };
89
+ } catch {
90
+ return { ok: false, stdout: '' };
91
+ }
92
+ }
93
+
94
+ /**
95
+ * The CLI's answer, or null.
96
+ *
97
+ * `glab` has no `auth token` verb, so its answer is parsed out of `auth status`,
98
+ * whose output carries the token when it prints one. A version that does not
99
+ * print it answers null and the panel simply reads anonymously — the honest
100
+ * outcome, rather than a guessed token.
101
+ */
102
+ function fromCli(provider: ForgeProvider, run: (argv: string[]) => { ok: boolean; stdout: string }): string | null {
103
+ const argv = CLI[provider];
104
+ if (!argv) return null;
105
+ if (cliCache.has(provider)) return cliCache.get(provider) ?? null;
106
+
107
+ const result = run([...argv]);
108
+ let token: string | null = null;
109
+ if (result.ok) {
110
+ const line = result.stdout.trim();
111
+ if (provider === 'github') {
112
+ token = /^[A-Za-z0-9_\-.]{20,}$/.test(line) ? line : null;
113
+ } else {
114
+ const match = line.match(/Token:\s*(\S+)/);
115
+ token = match ? match[1] : null;
116
+ }
117
+ }
118
+ cliCache.set(provider, token);
119
+ return token;
120
+ }
121
+
122
+ /** Clear the CLI cache. The tests use it; a running server has no reason to. */
123
+ export function resetTokenCache(): void {
124
+ cliCache.clear();
125
+ }
126
+
127
+ /** The credential for one provider, and where it came from. */
128
+ export function resolveToken(provider: ForgeProvider, sources: TokenSources): ResolvedToken {
129
+ const setting = (sources.setting ?? '').trim();
130
+ if (setting) return { token: setting, source: 'setting' };
131
+
132
+ for (const key of ENV_KEYS[provider]) {
133
+ const value = (sources.env[key] ?? '').trim();
134
+ if (value) return { token: value, source: 'environment' };
135
+ }
136
+
137
+ const token = fromCli(provider, sources.run ?? defaultRun);
138
+ return token ? { token, source: 'cli' } : { token: null, source: 'none' };
139
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The write path: a mutating request and the invalidation it owes.
8
+ *
9
+ * The two properties here are the ones a cached read gets wrong by default: a
10
+ * write must never carry a validator (a replayed 304 would report success for
11
+ * something that did not happen), and its success must DROP the entries it
12
+ * changed — the item and the list it came from are different URLs.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+
17
+ import { cacheKey, type CachedResponse, type JsonCache } from './http';
18
+ import { invalidateWhere, sendJson } from './write-http';
19
+
20
+ /** An in-memory cache with the plugin's storage shape. */
21
+ function memoryCache(): JsonCache & { entries: Map<string, CachedResponse> } {
22
+ const entries = new Map<string, CachedResponse>();
23
+ return {
24
+ entries,
25
+ read: async (key) => entries.get(key),
26
+ write: async (key, entry) => {
27
+ entries.set(key, entry);
28
+ },
29
+ keys: async () => [...entries.keys()],
30
+ remove: async (key) => {
31
+ entries.delete(key);
32
+ },
33
+ };
34
+ }
35
+
36
+ describe('sendJson', () => {
37
+ /** A fetch that records the request and answers once. */
38
+ function once(response: Response) {
39
+ const seen: Array<{ method?: string; body?: unknown; headers?: Record<string, string> }> = [];
40
+ const fetchImpl = (async (_url: string | URL | Request, init?: RequestInit) => {
41
+ seen.push({
42
+ method: init?.method,
43
+ body: init?.body ? JSON.parse(String(init.body)) : undefined,
44
+ headers: (init?.headers ?? {}) as Record<string, string>,
45
+ });
46
+ return response;
47
+ }) as unknown as typeof fetch;
48
+ return { seen, fetchImpl };
49
+ }
50
+
51
+ test('a write is never conditional and never cached', async () => {
52
+ const { seen, fetchImpl } = once(new Response(JSON.stringify({ ok: 1 }), { status: 201 }));
53
+ const result = await sendJson({
54
+ url: 'https://api.example/x',
55
+ method: 'POST',
56
+ body: { a: 1 },
57
+ headers: { authorization: 'Bearer x' },
58
+ fetchImpl,
59
+ });
60
+ expect(result).toEqual({ ok: true, value: { ok: 1 }, status: 201 });
61
+ expect(seen[0].method).toBe('POST');
62
+ expect(seen[0].body).toEqual({ a: 1 });
63
+ expect(seen[0].headers?.['if-none-match']).toBeUndefined();
64
+ expect(seen[0].headers?.['content-type']).toBe('application/json');
65
+ });
66
+
67
+ test('204 is a success with no body', async () => {
68
+ const { fetchImpl } = once(new Response(null, { status: 204 }));
69
+ expect(await sendJson({ url: 'u', method: 'PUT', body: {}, fetchImpl })).toEqual({
70
+ ok: true,
71
+ value: null,
72
+ status: 204,
73
+ });
74
+ });
75
+
76
+ test('a 200 whose body is not JSON is still a success', async () => {
77
+ const { fetchImpl } = once(new Response('<html>', { status: 200 }));
78
+ expect(await sendJson({ url: 'u', method: 'POST', body: {}, fetchImpl })).toEqual({
79
+ ok: true,
80
+ value: null,
81
+ status: 200,
82
+ });
83
+ });
84
+
85
+ test('a refusal carries the host wording', async () => {
86
+ const { fetchImpl } = once(new Response('{}', { status: 403 }));
87
+ const result = await sendJson({
88
+ url: 'u',
89
+ method: 'POST',
90
+ body: {},
91
+ headers: { authorization: 'Bearer x' },
92
+ fetchImpl,
93
+ });
94
+ expect(result.ok).toBe(false);
95
+ if (result.ok) return;
96
+ expect(result.status).toBe(403);
97
+ expect(result.message).toContain('scope');
98
+ });
99
+
100
+ test('an unreachable host is reported, never thrown', async () => {
101
+ const fetchImpl = (async () => {
102
+ throw new Error('ECONNREFUSED');
103
+ }) as unknown as typeof fetch;
104
+ const result = await sendJson({ url: 'u', method: 'POST', body: {}, fetchImpl });
105
+ expect(result.ok).toBe(false);
106
+ if (result.ok) return;
107
+ expect(result.message).toContain('ECONNREFUSED');
108
+ });
109
+ });
110
+
111
+ describe('invalidateWhere', () => {
112
+ test('drops exactly the entries the predicate names, and prunes orphans', async () => {
113
+ const cache = memoryCache();
114
+ const write = (url: string) =>
115
+ cache.write(cacheKey(url), { url, etag: null, lastModified: null, value: {}, at: 1 });
116
+ await write('https://api.example/repos/o/n/issues');
117
+ await write('https://api.example/repos/o/n/pulls/1');
118
+ await write('https://api.example/repos/other/repo/issues');
119
+ cache.entries.set('orphan', { url: '', etag: null, lastModified: null, value: {}, at: 0 });
120
+
121
+ const dropped = await invalidateWhere(cache, (url) => url.includes('/repos/o/n'));
122
+ expect(dropped).toBe(2);
123
+ expect(cache.entries.has(cacheKey('https://api.example/repos/other/repo/issues'))).toBe(true);
124
+ expect(cache.entries.has('orphan')).toBe(false);
125
+ });
126
+ });
127
+
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Writing: one mutating request, and the invalidation it owes.
8
+ *
9
+ * Split from `http.ts` because the two answer opposite questions. A READ is
10
+ * conditional and cached — a second read of an unchanged resource costs nothing,
11
+ * which is what makes a forge panel usable at all. A WRITE must never be either:
12
+ * a replayed `304` to a POST would report success for something that did not
13
+ * happen, and a cached answer would hide the state the write produced.
14
+ *
15
+ * The invalidation is scoped to the REPOSITORY rather than to the item, because
16
+ * a write changes two cached URLs at once — the item and the list it came from —
17
+ * and enumerating them per verb drifts the moment a new read is added.
18
+ */
19
+
20
+ import { describeFailure, isAuthenticated, type JsonCache } from './http';
21
+
22
+ /** Identifies this client to the host, as every API asks. */
23
+ const USER_AGENT = 'kabmo-forge';
24
+ const DEFAULT_TIMEOUT_MS = 15_000;
25
+
26
+
27
+ export interface SendOptions {
28
+ url: string;
29
+ method: 'POST' | 'PATCH' | 'PUT';
30
+ body: unknown;
31
+ headers?: Record<string, string>;
32
+ timeoutMs?: number;
33
+ fetchImpl?: typeof fetch;
34
+ }
35
+
36
+ export type SendResult = { ok: true; value: unknown; status: number } | { ok: false; status: number; message: string };
37
+
38
+ /**
39
+ * One mutating request.
40
+ *
41
+ * Deliberately NOT cached, and deliberately not conditional: a write is the one
42
+ * request whose answer must be the host's real one, and a replayed 304 to a POST
43
+ * would report success for something that did not happen.
44
+ *
45
+ * A 204 (GitHub answers one for several verbs) is a success with no body, which
46
+ * is why `value` is null rather than a parse failure.
47
+ */
48
+ export async function sendJson(options: SendOptions): Promise<SendResult> {
49
+ const doFetch = options.fetchImpl ?? fetch;
50
+ let response: Response;
51
+ try {
52
+ response = await doFetch(options.url, {
53
+ method: options.method,
54
+ headers: {
55
+ accept: 'application/json',
56
+ 'content-type': 'application/json',
57
+ 'user-agent': USER_AGENT,
58
+ ...options.headers,
59
+ },
60
+ body: JSON.stringify(options.body),
61
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS),
62
+ });
63
+ } catch (cause) {
64
+ const reason = cause instanceof Error ? cause.message : String(cause);
65
+ return { ok: false, status: 0, message: `Could not reach the host: ${reason}` };
66
+ }
67
+
68
+ if (!response.ok) {
69
+ return { ok: false, status: response.status, message: describeFailure(response, isAuthenticated(options.headers)) };
70
+ }
71
+
72
+ if (response.status === 204 || response.headers.get('content-length') === '0') {
73
+ return { ok: true, value: null, status: response.status };
74
+ }
75
+
76
+ try {
77
+ return { ok: true, value: (await response.json()) as unknown, status: response.status };
78
+ } catch {
79
+ // A 200 whose body is not JSON is still a success for a verb whose answer
80
+ // the panel does not read (a merge reports nothing useful anyway).
81
+ return { ok: true, value: null, status: response.status };
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Drop every cached entry whose URL satisfies `match`.
87
+ *
88
+ * A write invalidates reads it did not touch directly: merging a PR changes the
89
+ * PR's detail AND the list it came from, and the two are different URLs. Rather
90
+ * than enumerate the affected keys per verb — which drifts the moment a new read
91
+ * is added — the invalidation is scoped to the repository's own URLs, which is
92
+ * every entry a write could have changed and nothing outside it.
93
+ */
94
+ export async function invalidateWhere(cache: JsonCache, match: (url: string) => boolean): Promise<number> {
95
+ let dropped = 0;
96
+ for (const key of await cache.keys()) {
97
+ const entry = await cache.read(key);
98
+ // An entry with no URL can never match anything, so it is dead weight rather
99
+ // than a survivor: dropping it is what keeps a half-written record from
100
+ // living for the life of the install.
101
+ if (!entry || !entry.url) {
102
+ await cache.remove(key);
103
+ continue;
104
+ }
105
+ if (!match(entry.url)) continue;
106
+ await cache.remove(key);
107
+ dropped += 1;
108
+ }
109
+ return dropped;
110
+ }