@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,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
|
+
}
|