@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.
- package/README.md +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `origin` remote → the API this plugin talks to.
|
|
8
|
+
*
|
|
9
|
+
* The remote is the ONLY input, and that is the design: a repository already
|
|
10
|
+
* says where it lives, so asking the user to configure a host per workspace
|
|
11
|
+
* would be a second answer to a question the checkout has already answered. The
|
|
12
|
+
* wiki panel makes the same bet with `.wiki.git` appended; this one reads the
|
|
13
|
+
* same URL and derives an API root from it.
|
|
14
|
+
*
|
|
15
|
+
* Five rules are load-bearing:
|
|
16
|
+
*
|
|
17
|
+
* - **Credentials are stripped.** A self-hosted GitLab remote is routinely
|
|
18
|
+
* `https://user:token@host/o/n.git`, and echoing that back would put a secret
|
|
19
|
+
* in the DOM and in every screenshot of the panel.
|
|
20
|
+
* - **The provider is a GUESS, and a setting overrides it.** The host's NAME is
|
|
21
|
+
* the only signal a remote carries, so `github.com` and any host containing
|
|
22
|
+
* `github` is GitHub, `gitea`/`forgejo`/`codeberg` is Gitea, `bitbucket` is
|
|
23
|
+
* Bitbucket, and everything else is GitLab — a self-hosted GitLab being the
|
|
24
|
+
* common non-GitHub case.
|
|
25
|
+
* - **A local path is not a remote.** `/srv/repo` and `C:\repo` parse as
|
|
26
|
+
* nothing, because there is no API behind them.
|
|
27
|
+
* - **The scheme survives.** A remote over plain `http` (a lab box, a tunnel)
|
|
28
|
+
* must reach an API over `http` too, or every read fails on TLS.
|
|
29
|
+
* - **Bitbucket is the one host whose API is not on the same hostname.** Its
|
|
30
|
+
* Cloud API lives at `api.bitbucket.org/2.0` while the repository page is at
|
|
31
|
+
* `bitbucket.org`, so the API root cannot be derived from the remote's host.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { ForgeProvider } from '../protocol';
|
|
35
|
+
|
|
36
|
+
/** The preference a setting carries. */
|
|
37
|
+
export type ProviderPreference = 'auto' | ForgeProvider;
|
|
38
|
+
|
|
39
|
+
export interface ForgeRemote {
|
|
40
|
+
provider: ForgeProvider;
|
|
41
|
+
/** Host, port included when the remote has one (`localhost:3000`). */
|
|
42
|
+
host: string;
|
|
43
|
+
/** `owner/name`, subgroups included, without `.git`. */
|
|
44
|
+
slug: string;
|
|
45
|
+
/** The project's page on the host, always https unless the remote was http. */
|
|
46
|
+
webUrl: string;
|
|
47
|
+
/** The API root every request is built on. */
|
|
48
|
+
apiBase: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RemoteOptions {
|
|
52
|
+
provider?: ProviderPreference;
|
|
53
|
+
/** A setting that overrides the derived API root. */
|
|
54
|
+
apiBase?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `git@host:owner/name.git` — the scheme-less scp form. */
|
|
58
|
+
const SCP_LIKE = /^(?:[^@/]+@)?([^:/]+):(.+)$/;
|
|
59
|
+
|
|
60
|
+
/** A drive-rooted path is local, not `host:path`. */
|
|
61
|
+
const WINDOWS_PATH = /^[a-z]:[\\/]/i;
|
|
62
|
+
|
|
63
|
+
interface SplitRemote {
|
|
64
|
+
host: string;
|
|
65
|
+
path: string;
|
|
66
|
+
scheme: 'http' | 'https';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function splitRemote(raw: string): SplitRemote | null {
|
|
70
|
+
const trimmed = raw.trim();
|
|
71
|
+
if (!trimmed) return null;
|
|
72
|
+
if (WINDOWS_PATH.test(trimmed)) return null;
|
|
73
|
+
|
|
74
|
+
if (trimmed.includes('://')) {
|
|
75
|
+
let url: URL;
|
|
76
|
+
try {
|
|
77
|
+
url = new URL(trimmed);
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
// `url.host` already excludes userinfo, which is what keeps a credential out
|
|
82
|
+
// of every later string.
|
|
83
|
+
if (!url.host) return null;
|
|
84
|
+
return { host: url.host, path: url.pathname, scheme: url.protocol === 'http:' ? 'http' : 'https' };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const scp = trimmed.match(SCP_LIKE);
|
|
88
|
+
if (!scp) return null;
|
|
89
|
+
return { host: scp[1], path: scp[2], scheme: 'https' };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The provider a host's name implies.
|
|
94
|
+
*
|
|
95
|
+
* Ordered, because one name can contain another: `gitbucket.example` is not
|
|
96
|
+
* Bitbucket, so the specific names are tested before the general ones and
|
|
97
|
+
* Bitbucket matches only its own host.
|
|
98
|
+
*/
|
|
99
|
+
export function providerForHost(host: string): ForgeProvider {
|
|
100
|
+
const name = host.toLowerCase();
|
|
101
|
+
if (name === 'github.com' || name.includes('github')) return 'github';
|
|
102
|
+
if (name === 'bitbucket.org' || name.startsWith('bitbucket.')) return 'bitbucket';
|
|
103
|
+
if (name.includes('gitea') || name.includes('forgejo') || name.includes('codeberg')) return 'gitea';
|
|
104
|
+
return 'gitlab';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Parse one remote into its API parts, or a sentence explaining why it cannot be
|
|
109
|
+
* one.
|
|
110
|
+
*/
|
|
111
|
+
export function parseRemote(
|
|
112
|
+
raw: string | null | undefined,
|
|
113
|
+
options: RemoteOptions = {},
|
|
114
|
+
): ForgeRemote | { error: string } {
|
|
115
|
+
const value = (raw ?? '').trim();
|
|
116
|
+
if (!value) return { error: 'This repository has no origin remote, so there is no forge to read.' };
|
|
117
|
+
|
|
118
|
+
const split = splitRemote(value);
|
|
119
|
+
if (!split) {
|
|
120
|
+
return {
|
|
121
|
+
error: `The origin remote (${value}) is a local path, so it has no forge behind it. Point origin at a GitHub, GitLab, Gitea or Bitbucket repository.`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const slug = split.path
|
|
126
|
+
.replace(/^\/+/, '')
|
|
127
|
+
.replace(/\/+$/, '')
|
|
128
|
+
.replace(/\.git$/i, '');
|
|
129
|
+
if (slug.split('/').filter(Boolean).length < 2) {
|
|
130
|
+
return { error: `The origin remote (${value}) does not name an owner and a repository.` };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const provider: ForgeProvider =
|
|
134
|
+
options.provider === 'github' ||
|
|
135
|
+
options.provider === 'gitlab' ||
|
|
136
|
+
options.provider === 'gitea' ||
|
|
137
|
+
options.provider === 'bitbucket'
|
|
138
|
+
? options.provider
|
|
139
|
+
: providerForHost(split.host);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
provider,
|
|
143
|
+
host: split.host,
|
|
144
|
+
slug,
|
|
145
|
+
webUrl: `${split.scheme}://${split.host}/${slug}`,
|
|
146
|
+
apiBase: apiBaseFor(provider, split.host, split.scheme, options.apiBase),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The API root for a provider and host.
|
|
152
|
+
*
|
|
153
|
+
* GitHub is the one host with a DIFFERENT path per deployment: github.com serves
|
|
154
|
+
* `/`, Enterprise serves `/api/v3`. GitLab serves `/api/v4` everywhere, Gitea
|
|
155
|
+
* `/api/v1` everywhere, and Bitbucket Cloud is not on the repository's hostname
|
|
156
|
+
* at all — which is why it takes no host.
|
|
157
|
+
*/
|
|
158
|
+
export function apiBaseFor(
|
|
159
|
+
provider: ForgeProvider,
|
|
160
|
+
host: string,
|
|
161
|
+
scheme: 'http' | 'https',
|
|
162
|
+
override?: string,
|
|
163
|
+
): string {
|
|
164
|
+
const given = (override ?? '').trim().replace(/\/+$/, '');
|
|
165
|
+
if (given) return given;
|
|
166
|
+
if (provider === 'bitbucket') return 'https://api.bitbucket.org/2.0';
|
|
167
|
+
if (provider === 'gitlab') return `${scheme}://${host}/api/v4`;
|
|
168
|
+
if (provider === 'gitea') return `${scheme}://${host}/api/v1`;
|
|
169
|
+
return host.toLowerCase() === 'github.com' ? 'https://api.github.com' : `${scheme}://${host}/api/v3`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The URL-encoded project path GitLab takes where GitHub takes `owner/name`. */
|
|
173
|
+
export function gitlabProject(slug: string): string {
|
|
174
|
+
return encodeURIComponent(slug);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Bitbucket addresses a repository as two path segments, so its slug is split.
|
|
179
|
+
*
|
|
180
|
+
* Null when the slug is not exactly `workspace/repo`: a nested path is a GitLab
|
|
181
|
+
* subgroup, and Bitbucket has no such thing — guessing which segment is the
|
|
182
|
+
* repository would read the wrong project.
|
|
183
|
+
*/
|
|
184
|
+
export function bitbucketPath(slug: string): { workspace: string; repo: string } | null {
|
|
185
|
+
const parts = slug.split('/').filter(Boolean);
|
|
186
|
+
if (parts.length !== 2) return null;
|
|
187
|
+
return { workspace: parts[0], repo: parts[1] };
|
|
188
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The scope probe, and the one rule that makes it honest.
|
|
8
|
+
*
|
|
9
|
+
* A probe that cannot read scopes answers `null`, never `false`: an unreachable
|
|
10
|
+
* endpoint, or a token type the host does not describe, is not evidence that a
|
|
11
|
+
* credential cannot write. Guessing `false` would hide every verb from a reader
|
|
12
|
+
* whose token is fine.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import { githubScopes, probeWriteScope, scopesAllowWrite } from './scope-probe';
|
|
18
|
+
import { hostContext } from './test-context';
|
|
19
|
+
|
|
20
|
+
describe('scopesAllowWrite', () => {
|
|
21
|
+
test('a write scope is a yes', () => {
|
|
22
|
+
expect(scopesAllowWrite('github', ['repo'])).toBe(true);
|
|
23
|
+
expect(scopesAllowWrite('github', ['read:user', 'public_repo'])).toBe(true);
|
|
24
|
+
expect(scopesAllowWrite('gitlab', ['api'])).toBe(true);
|
|
25
|
+
expect(scopesAllowWrite('gitlab', ['read_api', 'write_repository'])).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('read-only scopes are a no', () => {
|
|
29
|
+
expect(scopesAllowWrite('github', ['read:user', 'gist'])).toBe(false);
|
|
30
|
+
expect(scopesAllowWrite('gitlab', ['read_api'])).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('an empty list is unknown, not a no', () => {
|
|
34
|
+
expect(scopesAllowWrite('github', [])).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('a host with no scope model is unknown', () => {
|
|
38
|
+
expect(scopesAllowWrite('gitea', ['anything'])).toBeNull();
|
|
39
|
+
expect(scopesAllowWrite('bitbucket', ['anything'])).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('githubScopes', () => {
|
|
44
|
+
test('a comma-separated header is split and trimmed', () => {
|
|
45
|
+
expect(githubScopes('repo, read:user,gist')).toEqual(['repo', 'read:user', 'gist']);
|
|
46
|
+
expect(githubScopes('')).toEqual([]);
|
|
47
|
+
expect(githubScopes(null)).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('probeWriteScope', () => {
|
|
52
|
+
test('no credential is a definite no', async () => {
|
|
53
|
+
const { fetchImpl } = fake(() => new Response('{}'));
|
|
54
|
+
expect(await probeWriteScope(hostContext('github', fetchImpl, { token: null }))).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('GitHub reports through its header', async () => {
|
|
58
|
+
const { fetchImpl } = fake(
|
|
59
|
+
() => new Response('{}', { status: 200, headers: { 'x-oauth-scopes': 'repo, read:user' } }),
|
|
60
|
+
);
|
|
61
|
+
expect(await probeWriteScope(hostContext('github', fetchImpl))).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a fine-grained token reports no header, which is UNKNOWN rather than no', async () => {
|
|
65
|
+
const { fetchImpl } = fake(() => new Response('{}', { status: 200 }));
|
|
66
|
+
expect(await probeWriteScope(hostContext('github', fetchImpl))).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('a failed probe is unknown, never false', async () => {
|
|
70
|
+
const { fetchImpl } = fake(() => new Response('{}', { status: 403 }));
|
|
71
|
+
expect(await probeWriteScope(hostContext('github', fetchImpl))).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('GitLab reads its own self endpoint', async () => {
|
|
75
|
+
// The self endpoint's own shape: a top-level `scopes` array.
|
|
76
|
+
const { seen, fetchImpl } = fake(
|
|
77
|
+
() => new Response(JSON.stringify({ id: 1, scopes: ['read_api'] }), { status: 200 }),
|
|
78
|
+
);
|
|
79
|
+
expect(await probeWriteScope(hostContext('gitlab', fetchImpl))).toBe(false);
|
|
80
|
+
expect(seen[0]).toContain('/personal_access_tokens/self');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('a host with no scope model answers unknown without a request', async () => {
|
|
84
|
+
const { seen, fetchImpl } = fake(() => new Response('{}'));
|
|
85
|
+
expect(await probeWriteScope(hostContext('gitea', fetchImpl))).toBeNull();
|
|
86
|
+
expect(seen).toHaveLength(0);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** A fetch that answers once and records the URLs it was asked. */
|
|
91
|
+
function fake(response: () => Response) {
|
|
92
|
+
const seen: string[] = [];
|
|
93
|
+
const fetchImpl = (async (input: string | URL | Request) => {
|
|
94
|
+
seen.push(String(input));
|
|
95
|
+
return response();
|
|
96
|
+
}) as unknown as typeof fetch;
|
|
97
|
+
return { seen, fetchImpl };
|
|
98
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Can this credential WRITE, or only read?
|
|
8
|
+
*
|
|
9
|
+
* The panel asks because a read-only token is a panel full of buttons that can
|
|
10
|
+
* only fail — and the failure arrives as a 403 from an API the reader did not
|
|
11
|
+
* know was involved. Three hosts answer, one does not, and the honest answer is
|
|
12
|
+
* `null` for the one that does not:
|
|
13
|
+
*
|
|
14
|
+
* - **GitHub** reports `x-oauth-scopes` on a REST response for an OAuth token.
|
|
15
|
+
* A fine-grained PAT reports NOTHING, so absence is `null`, never `false`.
|
|
16
|
+
* - **GitLab** answers `GET /personal_access_tokens/self` with a `scopes` array
|
|
17
|
+
* — but only for a token that may read itself, which a project token cannot.
|
|
18
|
+
* - **Gitea** has no scope model at all: a token either can write or the host
|
|
19
|
+
* refuses the verb, so `null`.
|
|
20
|
+
* - **Bitbucket** app passwords carry permissions the API does not echo, so
|
|
21
|
+
* `null` as well.
|
|
22
|
+
*
|
|
23
|
+
* The probe is one cheap GET, run only when the reader opens the credential
|
|
24
|
+
* sheet — not on every panel mount, because it is a request against the same
|
|
25
|
+
* budget the reads use.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ForgeProvider } from '../protocol';
|
|
29
|
+
import { authHeaders } from './http';
|
|
30
|
+
import { get, joinUrl, type ForgeContext } from './context';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Scope names that grant a write, per host.
|
|
34
|
+
*
|
|
35
|
+
* Exact names where the host publishes an exact list, and a prefix only where it
|
|
36
|
+
* does not: GitHub's classic scopes are a closed set (`repo`, `public_repo`,
|
|
37
|
+
* `gist`, `workflow`, …) while a fine-grained token names resources
|
|
38
|
+
* (`pull_requests:write`). Matching `read:user` against a bare `repo` substring
|
|
39
|
+
* is the trap — it CONTAINS no write scope, and a `includes('repo')` test would
|
|
40
|
+
* say it does.
|
|
41
|
+
*/
|
|
42
|
+
const WRITE_SCOPES: Record<ForgeProvider, readonly string[]> = {
|
|
43
|
+
github: ['repo', 'public_repo', 'workflow', ':write'],
|
|
44
|
+
gitlab: ['api', 'write_repository', 'write_api'],
|
|
45
|
+
gitea: [],
|
|
46
|
+
bitbucket: [],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether a scope list contains something that can write.
|
|
51
|
+
*
|
|
52
|
+
* `null` means "this host does not say", which is a different answer from "no"
|
|
53
|
+
* and must not be collapsed into it.
|
|
54
|
+
*/
|
|
55
|
+
export function scopesAllowWrite(provider: ForgeProvider, scopes: readonly string[]): boolean | null {
|
|
56
|
+
if (scopes.length === 0) return null;
|
|
57
|
+
const allowed = WRITE_SCOPES[provider];
|
|
58
|
+
if (allowed.length === 0) return null;
|
|
59
|
+
return scopes.some((scope) => {
|
|
60
|
+
const name = scope.trim().toLowerCase();
|
|
61
|
+
return allowed.some((entry) => {
|
|
62
|
+
// `:write` is a SUFFIX rule, for a fine-grained GitHub token
|
|
63
|
+
// (`pull_requests:write`). Every other entry is an EXACT name: matching
|
|
64
|
+
// `read_api` against `api` by suffix is exactly the false positive that
|
|
65
|
+
// would show every write button to a read-only token.
|
|
66
|
+
if (entry.startsWith(':')) return name.endsWith(entry);
|
|
67
|
+
return name === entry;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The scopes GitHub reported, from a response's headers. */
|
|
73
|
+
export function githubScopes(header: string | null): string[] {
|
|
74
|
+
if (!header) return [];
|
|
75
|
+
return header
|
|
76
|
+
.split(',')
|
|
77
|
+
.map((scope) => scope.trim())
|
|
78
|
+
.filter(Boolean);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Probe the credential's write ability, or `null` when the host does not say.
|
|
83
|
+
*
|
|
84
|
+
* A probe that fails is `null`: an unreachable endpoint is not evidence that a
|
|
85
|
+
* token cannot write, and guessing `false` would hide every verb from a reader
|
|
86
|
+
* whose token is fine.
|
|
87
|
+
*/
|
|
88
|
+
export async function probeWriteScope(context: ForgeContext): Promise<boolean | null> {
|
|
89
|
+
if (!context.token) return false;
|
|
90
|
+
|
|
91
|
+
if (context.provider === 'github') {
|
|
92
|
+
// `/user` is the cheapest authenticated REST call, and it is the one that
|
|
93
|
+
// carries the scope header.
|
|
94
|
+
const result = await getWithHeaders(context, joinUrl(context.apiBase, '/user'));
|
|
95
|
+
if (!result.ok) return null;
|
|
96
|
+
return scopesAllowWrite('github', githubScopes(result.scopes));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (context.provider === 'gitlab') {
|
|
100
|
+
const result = await get(context, joinUrl(context.apiBase, '/personal_access_tokens/self'));
|
|
101
|
+
if (!result.ok) return null;
|
|
102
|
+
// `{scopes: ["api"]}` on the self endpoint; a token that may not read itself
|
|
103
|
+
// answers 403, which the `!result.ok` above already turned into `null`.
|
|
104
|
+
const record = typeof result.value === 'object' && result.value !== null ? (result.value as { scopes?: unknown }) : {};
|
|
105
|
+
const scopes = Array.isArray(record.scopes) ? record.scopes.filter((entry): entry is string => typeof entry === 'string') : [];
|
|
106
|
+
return scopesAllowWrite('gitlab', scopes);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** One GET that also reports the scope header. */
|
|
113
|
+
async function getWithHeaders(
|
|
114
|
+
context: ForgeContext,
|
|
115
|
+
url: string,
|
|
116
|
+
): Promise<{ ok: true; scopes: string | null } | { ok: false }> {
|
|
117
|
+
const doFetch = context.fetchImpl ?? fetch;
|
|
118
|
+
try {
|
|
119
|
+
const response = await doFetch(url, {
|
|
120
|
+
headers: { accept: 'application/json', 'user-agent': 'kabmo-forge', ...authHeaders(context.provider, context.token) },
|
|
121
|
+
signal: AbortSignal.timeout(10_000),
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) return { ok: false };
|
|
124
|
+
return { ok: true, scopes: response.headers.get('x-oauth-scopes') };
|
|
125
|
+
} catch {
|
|
126
|
+
return { ok: false };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The scope: which directory is read, and the remote it carries.
|
|
8
|
+
*
|
|
9
|
+
* A plugin's server half runs inside Kabmo's process, so a path the client sends
|
|
10
|
+
* is a path this plugin reads with the server's own rights. Two checks follow,
|
|
11
|
+
* and both are the same shape the command-runner applies for the same reason:
|
|
12
|
+
*
|
|
13
|
+
* - `root` must be ABSOLUTE, because a relative root would resolve against
|
|
14
|
+
* Kabmo's own cwd and read a repository nobody named;
|
|
15
|
+
* - `repo` must resolve INSIDE `root`, which is the check that stops
|
|
16
|
+
* `repo: '../../etc'`.
|
|
17
|
+
*
|
|
18
|
+
* Kabmo's own root allow-list is deliberately NOT re-implemented here: it needs
|
|
19
|
+
* Kabmo's database, and a plugin's server bundle cannot import Kabmo's source
|
|
20
|
+
* (`@/…` does not resolve in it). What this module can guarantee is the
|
|
21
|
+
* containment above, plus the one thing it actually needs — that the directory
|
|
22
|
+
* has an `origin`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { isAbsolute, resolve, sep } from 'path';
|
|
26
|
+
|
|
27
|
+
export interface Scope {
|
|
28
|
+
root: string;
|
|
29
|
+
repo: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The absolute directory a scope names, or null when it is not contained. */
|
|
33
|
+
export function resolveScope(scope: Scope): string | null {
|
|
34
|
+
if (!scope.root || !isAbsolute(scope.root)) return null;
|
|
35
|
+
const base = resolve(scope.root);
|
|
36
|
+
const target = resolve(base, scope.repo || '.');
|
|
37
|
+
if (target !== base && !target.startsWith(base + sep)) return null;
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The `origin` URL a checkout reports, or null when it has none. */
|
|
42
|
+
export function readOrigin(dir: string): string | null {
|
|
43
|
+
const result = Bun.spawnSync(['git', 'remote', 'get-url', 'origin'], {
|
|
44
|
+
cwd: dir,
|
|
45
|
+
stdout: 'pipe',
|
|
46
|
+
stderr: 'ignore',
|
|
47
|
+
timeout: 5_000,
|
|
48
|
+
// A repository with no remote is the ordinary answer here, and git reports
|
|
49
|
+
// it as exit 2 with a message — not a failure worth surfacing.
|
|
50
|
+
env: { ...Bun.env, GIT_TERMINAL_PROMPT: '0' },
|
|
51
|
+
});
|
|
52
|
+
if (result.exitCode !== 0) return null;
|
|
53
|
+
const url = result.stdout ? result.stdout.toString().trim() : '';
|
|
54
|
+
return url || null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether `dir` is inside a git work tree at all. */
|
|
58
|
+
export function isGitRepository(dir: string): boolean {
|
|
59
|
+
const result = Bun.spawnSync(['git', 'rev-parse', '--is-inside-work-tree'], {
|
|
60
|
+
cwd: dir,
|
|
61
|
+
stdout: 'ignore',
|
|
62
|
+
stderr: 'ignore',
|
|
63
|
+
timeout: 5_000,
|
|
64
|
+
});
|
|
65
|
+
return result.exitCode === 0;
|
|
66
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One `ForgeContext` per host, for the adapter suites.
|
|
8
|
+
*
|
|
9
|
+
* Shared rather than copied into each suite: four hosts × the same eight fields
|
|
10
|
+
* is four places a new field is forgotten, and a context that is missing one
|
|
11
|
+
* would make a suite pass against a shape the server never builds.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ForgeContext } from './context';
|
|
15
|
+
import type { ForgeFilter, ForgeProvider } from '../protocol';
|
|
16
|
+
import { coldCache } from './test-host';
|
|
17
|
+
|
|
18
|
+
/** The filter every suite starts from. */
|
|
19
|
+
export function openFilter(): ForgeFilter {
|
|
20
|
+
return { state: 'open', mine: false, label: '', query: '' };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The API roots the real parser derives, so a suite's URLs are the ones shipped. */
|
|
24
|
+
const ROOTS: Record<ForgeProvider, { apiBase: string; host: string; slug: string; webUrl: string }> = {
|
|
25
|
+
github: {
|
|
26
|
+
apiBase: 'https://api.github.com',
|
|
27
|
+
host: 'github.com',
|
|
28
|
+
slug: 'kabmo-labs/kabmo',
|
|
29
|
+
webUrl: 'https://github.com/kabmo-labs/kabmo',
|
|
30
|
+
},
|
|
31
|
+
gitlab: {
|
|
32
|
+
apiBase: 'https://gitlab.com/api/v4',
|
|
33
|
+
host: 'gitlab.com',
|
|
34
|
+
slug: 'group/project',
|
|
35
|
+
webUrl: 'https://gitlab.com/group/project',
|
|
36
|
+
},
|
|
37
|
+
gitea: {
|
|
38
|
+
apiBase: 'https://gitea.example.com/api/v1',
|
|
39
|
+
host: 'gitea.example.com',
|
|
40
|
+
slug: 'team/app',
|
|
41
|
+
webUrl: 'https://gitea.example.com/team/app',
|
|
42
|
+
},
|
|
43
|
+
bitbucket: {
|
|
44
|
+
apiBase: 'https://api.bitbucket.org/2.0',
|
|
45
|
+
host: 'bitbucket.org',
|
|
46
|
+
slug: 'team/app',
|
|
47
|
+
webUrl: 'https://bitbucket.org/team/app',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** A context for one host, with the fetch a suite supplies. */
|
|
52
|
+
export function hostContext(
|
|
53
|
+
provider: ForgeProvider,
|
|
54
|
+
fetchImpl: typeof fetch,
|
|
55
|
+
overrides: Partial<ForgeContext> = {},
|
|
56
|
+
): ForgeContext {
|
|
57
|
+
return {
|
|
58
|
+
provider,
|
|
59
|
+
...ROOTS[provider],
|
|
60
|
+
token: 'token_test',
|
|
61
|
+
perPage: 30,
|
|
62
|
+
filter: openFilter(),
|
|
63
|
+
cache: coldCache(),
|
|
64
|
+
fetchImpl,
|
|
65
|
+
...overrides,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The fake host both adapter suites read through.
|
|
8
|
+
*
|
|
9
|
+
* A live forge cannot be part of a test: it needs a credential, a network and a
|
|
10
|
+
* repository that does not change. So the mapping is driven against the exact
|
|
11
|
+
* JSON each vendor documents, through a fetch that answers from a table — which
|
|
12
|
+
* is the only part of an adapter that can be wrong, because the fetching is
|
|
13
|
+
* `http.ts`'s own subject.
|
|
14
|
+
*
|
|
15
|
+
* Shared rather than copied: two implementations of the envelope shape would
|
|
16
|
+
* let one suite pass while the other described a host that does not exist.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { CachedResponse, JsonCache } from './http';
|
|
20
|
+
|
|
21
|
+
/** A cache that never hits, so every read goes to the fake fetch. */
|
|
22
|
+
export function coldCache(): JsonCache {
|
|
23
|
+
const entries = new Map<string, CachedResponse>();
|
|
24
|
+
return {
|
|
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
|
+
/** A fetch that answers from a path → body table and records the URLs asked. */
|
|
37
|
+
export function host(table: Record<string, unknown | { status: number }>) {
|
|
38
|
+
const asked: string[] = [];
|
|
39
|
+
const fetchImpl = (async (input: string | URL | Request) => {
|
|
40
|
+
const url = String(input);
|
|
41
|
+
asked.push(url);
|
|
42
|
+
const path = url.replace(/^https?:\/\/[^/]+/, '').split('?')[0];
|
|
43
|
+
const body = table[path];
|
|
44
|
+
if (body === undefined) return new Response('{}', { status: 404 });
|
|
45
|
+
if (typeof body === 'object' && body !== null && 'status' in body && typeof body.status === 'number') {
|
|
46
|
+
return new Response('{}', { status: body.status });
|
|
47
|
+
}
|
|
48
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
49
|
+
}) as unknown as typeof fetch;
|
|
50
|
+
return { asked, fetchImpl };
|
|
51
|
+
}
|