@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,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The blame parser and its lookups.
|
|
8
|
+
*
|
|
9
|
+
* The fixtures are SHAPED LIKE MEASURED git output rather than idealized: one
|
|
10
|
+
* header per line with the group count on the first, metadata only where a
|
|
11
|
+
* commit first appears, and a `\t`-prefixed content line ending each record.
|
|
12
|
+
* Every one of those facts was wrong in a first cut and produced a payload that
|
|
13
|
+
* looked plausible — overlapping runs, and commits with an empty author.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
blameAt,
|
|
20
|
+
blameLabel,
|
|
21
|
+
blameRunAt,
|
|
22
|
+
blameUnavailableText,
|
|
23
|
+
formatBlameAge,
|
|
24
|
+
isUncommittedSha,
|
|
25
|
+
parseBlameHistory,
|
|
26
|
+
parseBlamePorcelain,
|
|
27
|
+
type BlamePayload,
|
|
28
|
+
} from '@/shared/lib/fs/git-blame';
|
|
29
|
+
|
|
30
|
+
const SHA_A = 'a'.repeat(40);
|
|
31
|
+
const SHA_B = 'b'.repeat(40);
|
|
32
|
+
const UNCOMMITTED = '0'.repeat(40);
|
|
33
|
+
|
|
34
|
+
/** Real `--porcelain` shape: header, metadata once, `\t` content, repeat. */
|
|
35
|
+
const PORCELAIN = [
|
|
36
|
+
`${SHA_A} 1 1 3`,
|
|
37
|
+
'author Ada Lovelace',
|
|
38
|
+
'author-mail <ada@example.com>',
|
|
39
|
+
'author-time 1700000000',
|
|
40
|
+
'author-tz +0000',
|
|
41
|
+
'committer Ada Lovelace',
|
|
42
|
+
'committer-mail <ada@example.com>',
|
|
43
|
+
'committer-time 1700000000',
|
|
44
|
+
'committer-tz +0000',
|
|
45
|
+
'summary feat: open the file',
|
|
46
|
+
'previous 1111111111111111111111111111111111111111 src/old name.ts',
|
|
47
|
+
'filename src/new name.ts',
|
|
48
|
+
'\tconst a = 1;',
|
|
49
|
+
// Second and third lines of the SAME commit: a bare header each, no metadata.
|
|
50
|
+
`${SHA_A} 2 2`,
|
|
51
|
+
'\tconst b = 2;',
|
|
52
|
+
`${SHA_A} 3 3`,
|
|
53
|
+
'\tconst c = 3;',
|
|
54
|
+
// A different commit: metadata again, because this sha is new.
|
|
55
|
+
`${SHA_B} 4 4 1`,
|
|
56
|
+
'author Grace Hopper',
|
|
57
|
+
'author-mail <grace@example.com>',
|
|
58
|
+
'author-time 1700100000',
|
|
59
|
+
'summary fix: the bug',
|
|
60
|
+
'\tconst d = 4;',
|
|
61
|
+
// A line that is not in HEAD.
|
|
62
|
+
`${UNCOMMITTED} 5 5 1`,
|
|
63
|
+
'author Not Committed Yet',
|
|
64
|
+
'author-mail <not.committed.yet>',
|
|
65
|
+
'author-time 1700200000',
|
|
66
|
+
'summary Version of src/new name.ts from src/new name.ts',
|
|
67
|
+
'\tconst e = 5;',
|
|
68
|
+
'',
|
|
69
|
+
].join('\n');
|
|
70
|
+
|
|
71
|
+
describe('parseBlamePorcelain', () => {
|
|
72
|
+
test('merges consecutive lines of one commit into a single run', () => {
|
|
73
|
+
const { runs } = parseBlamePorcelain(PORCELAIN);
|
|
74
|
+
expect(runs).toEqual([
|
|
75
|
+
{ from: 1, to: 3, sha: SHA_A },
|
|
76
|
+
{ from: 4, to: 4, sha: SHA_B },
|
|
77
|
+
{ from: 5, to: 5, sha: UNCOMMITTED },
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('reads metadata once per commit, not once per line', () => {
|
|
82
|
+
const { commits } = parseBlamePorcelain(PORCELAIN);
|
|
83
|
+
expect(commits[SHA_A]).toEqual({
|
|
84
|
+
sha: SHA_A,
|
|
85
|
+
author: 'Ada Lovelace',
|
|
86
|
+
mail: 'ada@example.com',
|
|
87
|
+
time: 1700000000,
|
|
88
|
+
summary: 'feat: open the file',
|
|
89
|
+
});
|
|
90
|
+
// Three headers named SHA_A; only the first carried metadata, and the
|
|
91
|
+
// record must still be complete.
|
|
92
|
+
expect(commits[SHA_B].author).toBe('Grace Hopper');
|
|
93
|
+
expect(commits[UNCOMMITTED].author).toBe('Not Committed Yet');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('ignores boundary, previous and filename lines', () => {
|
|
97
|
+
const { commits, runs } = parseBlamePorcelain(
|
|
98
|
+
[`${SHA_A} 1 1 1`, 'boundary', 'author Ada', 'author-time 1', '\tone', ''].join('\n'),
|
|
99
|
+
);
|
|
100
|
+
expect(runs).toEqual([{ from: 1, to: 1, sha: SHA_A }]);
|
|
101
|
+
expect(commits[SHA_A]).toEqual({ sha: SHA_A, author: 'Ada', mail: '', time: 1, summary: '' });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('a content line with no header is ignored rather than attributed', () => {
|
|
105
|
+
const { runs } = parseBlamePorcelain('\tstray\n');
|
|
106
|
+
expect(runs).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('sorts runs by their first line, whatever order git emitted', () => {
|
|
110
|
+
const out = [
|
|
111
|
+
`${SHA_B} 9 9 1`,
|
|
112
|
+
'author G',
|
|
113
|
+
'\tnine',
|
|
114
|
+
`${SHA_A} 2 2 1`,
|
|
115
|
+
'author A',
|
|
116
|
+
'\ttwo',
|
|
117
|
+
'',
|
|
118
|
+
].join('\n');
|
|
119
|
+
expect(parseBlamePorcelain(out).runs.map((run) => run.from)).toEqual([2, 9]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('an empty document yields no runs and no commits', () => {
|
|
123
|
+
expect(parseBlamePorcelain('')).toEqual({ commits: {}, runs: [] });
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('blameRunAt', () => {
|
|
128
|
+
const runs = [
|
|
129
|
+
{ from: 1, to: 3, sha: SHA_A },
|
|
130
|
+
{ from: 5, to: 9, sha: SHA_B },
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
test('finds a line inside a run and on both of its edges', () => {
|
|
134
|
+
expect(blameRunAt(runs, 1)?.sha).toBe(SHA_A);
|
|
135
|
+
expect(blameRunAt(runs, 3)?.sha).toBe(SHA_A);
|
|
136
|
+
expect(blameRunAt(runs, 7)?.sha).toBe(SHA_B);
|
|
137
|
+
expect(blameRunAt(runs, 9)?.sha).toBe(SHA_B);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('a gap between runs and a line past the end answer null', () => {
|
|
141
|
+
expect(blameRunAt(runs, 4)).toBeNull();
|
|
142
|
+
expect(blameRunAt(runs, 10)).toBeNull();
|
|
143
|
+
expect(blameRunAt([], 1)).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('blameAt', () => {
|
|
148
|
+
const payload: BlamePayload = {
|
|
149
|
+
available: true,
|
|
150
|
+
head: SHA_B,
|
|
151
|
+
lines: 5,
|
|
152
|
+
...parseBlamePorcelain(PORCELAIN),
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
test('pairs the run with its commit', () => {
|
|
156
|
+
expect(blameAt(payload, 4)?.commit.author).toBe('Grace Hopper');
|
|
157
|
+
expect(blameAt(payload, 4)?.run).toEqual({ from: 4, to: 4, sha: SHA_B });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('an unavailable payload answers null even for a line it could place', () => {
|
|
161
|
+
const empty: BlamePayload = {
|
|
162
|
+
available: false,
|
|
163
|
+
head: null,
|
|
164
|
+
lines: 0,
|
|
165
|
+
runs: [],
|
|
166
|
+
commits: {},
|
|
167
|
+
reason: 'untracked',
|
|
168
|
+
};
|
|
169
|
+
expect(blameAt(empty, 1)).toBeNull();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('a run whose commit is missing answers null rather than a blank card', () => {
|
|
173
|
+
const broken: BlamePayload = {
|
|
174
|
+
available: true,
|
|
175
|
+
head: SHA_A,
|
|
176
|
+
lines: 1,
|
|
177
|
+
runs: [{ from: 1, to: 1, sha: SHA_A }],
|
|
178
|
+
commits: {},
|
|
179
|
+
};
|
|
180
|
+
expect(blameAt(broken, 1)).toBeNull();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('formatBlameAge', () => {
|
|
185
|
+
const now = 1_700_000_000_000;
|
|
186
|
+
|
|
187
|
+
test('every unit boundary reads as the smaller unit', () => {
|
|
188
|
+
expect(formatBlameAge(now / 1000, now)).toBe('just now');
|
|
189
|
+
expect(formatBlameAge(now / 1000 - 59, now)).toBe('just now');
|
|
190
|
+
expect(formatBlameAge(now / 1000 - 60, now)).toBe('1m ago');
|
|
191
|
+
expect(formatBlameAge(now / 1000 - 3599, now)).toBe('59m ago');
|
|
192
|
+
expect(formatBlameAge(now / 1000 - 3600, now)).toBe('1h ago');
|
|
193
|
+
expect(formatBlameAge(now / 1000 - 86_400, now)).toBe('1d ago');
|
|
194
|
+
expect(formatBlameAge(now / 1000 - 86_400 * 30, now)).toBe('1mo ago');
|
|
195
|
+
expect(formatBlameAge(now / 1000 - 86_400 * 365, now)).toBe('1y ago');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('a clock ahead of now reads as just now rather than a negative age', () => {
|
|
199
|
+
expect(formatBlameAge(now / 1000 + 600, now)).toBe('just now');
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('blameLabel', () => {
|
|
204
|
+
test('names the author and the age', () => {
|
|
205
|
+
const commit = { sha: SHA_A, author: 'Ada Lovelace', mail: '', time: 0, summary: '' };
|
|
206
|
+
expect(blameLabel(commit, 86_400_000)).toBe('Ada Lovelace · 1d ago');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('an uncommitted line says so instead of naming a fake author', () => {
|
|
210
|
+
const commit = { sha: UNCOMMITTED, author: 'Not Committed Yet', mail: '', time: 0, summary: '' };
|
|
211
|
+
expect(blameLabel(commit, 0)).toBe('Not committed yet');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('an empty author falls back rather than drawing a bare separator', () => {
|
|
215
|
+
const commit = { sha: SHA_A, author: ' ', mail: '', time: 0, summary: '' };
|
|
216
|
+
expect(blameLabel(commit, 0)).toBe('Unknown · just now');
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('isUncommittedSha', () => {
|
|
221
|
+
test('only the all-zero sha is uncommitted', () => {
|
|
222
|
+
expect(isUncommittedSha(UNCOMMITTED)).toBe(true);
|
|
223
|
+
expect(isUncommittedSha(SHA_A)).toBe(false);
|
|
224
|
+
expect(isUncommittedSha('0'.repeat(39))).toBe(false);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('blameUnavailableText', () => {
|
|
229
|
+
test('each reason has its own sentence', () => {
|
|
230
|
+
const seen = new Set(
|
|
231
|
+
(['not-repo', 'no-commit', 'untracked', 'too-large', 'empty', 'error'] as const).map((reason) =>
|
|
232
|
+
blameUnavailableText(reason),
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
expect(seen.size).toBe(6);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('a reason that carries git’s own message prints it', () => {
|
|
239
|
+
expect(blameUnavailableText('too-large', 'This file is 12.0 MiB.')).toBe('This file is 12.0 MiB.');
|
|
240
|
+
expect(blameUnavailableText('error', 'fatal: bad object')).toBe('fatal: bad object');
|
|
241
|
+
// The two reasons with a fixed sentence ignore a stray message.
|
|
242
|
+
expect(blameUnavailableText('untracked', 'ignored')).toContain('never been committed');
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('parseBlameHistory', () => {
|
|
247
|
+
test('reads `\\x1f` fields out of `\\x1e` records, newest first as git emits', () => {
|
|
248
|
+
const out = [
|
|
249
|
+
`${SHA_B}\x1fGrace Hopper\x1f1700100000\x1ffix: the bug`,
|
|
250
|
+
`${SHA_A}\x1fAda Lovelace\x1f1700000000\x1ffeat: open the file: part 2`,
|
|
251
|
+
].join('\x1e');
|
|
252
|
+
expect(parseBlameHistory(out)).toEqual([
|
|
253
|
+
{ sha: SHA_B, author: 'Grace Hopper', time: 1700100000, summary: 'fix: the bug' },
|
|
254
|
+
{ sha: SHA_A, author: 'Ada Lovelace', time: 1700000000, summary: 'feat: open the file: part 2' },
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('skips a record without four fields and one whose sha is not a sha', () => {
|
|
259
|
+
const out = ['not-a-record', `deadbeef\x1fX\x1f1\x1fsubject`, `${SHA_A}\x1fA\x1f1\x1fok`].join('\x1e');
|
|
260
|
+
expect(parseBlameHistory(out).map((entry) => entry.summary)).toEqual(['ok']);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('empty output yields no entries', () => {
|
|
264
|
+
expect(parseBlameHistory('')).toEqual([]);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Line blame, as DATA: the payload, its parser, and the two lookups a reader
|
|
8
|
+
* makes.
|
|
9
|
+
*
|
|
10
|
+
* The parser is here rather than in the server module because it is pure text
|
|
11
|
+
* in and text out — which is what lets it be pinned by a test without spawning
|
|
12
|
+
* git, and what would let a future client fold a payload it already has.
|
|
13
|
+
*
|
|
14
|
+
* ## `--porcelain` is one header per LINE, not one per group
|
|
15
|
+
*
|
|
16
|
+
* The header carries a group count (`<sha> <orig> <final> <count>`), and it is
|
|
17
|
+
* tempting to expand it into a range. Measured on a 336-line file: git prints
|
|
18
|
+
* `sha 1 1 40` and then `sha 2 2`, `sha 3 3` … — one header per line, with the
|
|
19
|
+
* count on the FIRST only. Expanding by the count produced overlapping runs
|
|
20
|
+
* (`1-40`, then `2-40`), so the runs are built from the line each header names
|
|
21
|
+
* and merged when consecutive lines share a sha.
|
|
22
|
+
*
|
|
23
|
+
* ## Metadata appears once per COMMIT, not per line
|
|
24
|
+
*
|
|
25
|
+
* 295 content lines carried 5 `author` lines on that file. So a commit record
|
|
26
|
+
* is filled wherever its metadata first appears, and a later header naming the
|
|
27
|
+
* same sha adds nothing — which is why the parse keeps a map keyed by sha
|
|
28
|
+
* instead of a record per line.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** One commit a blame run refers to. `time` is seconds since the epoch. */
|
|
32
|
+
export interface BlameCommit {
|
|
33
|
+
sha: string;
|
|
34
|
+
author: string;
|
|
35
|
+
mail: string;
|
|
36
|
+
time: number;
|
|
37
|
+
summary: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A run of consecutive lines attributed to one commit. 1-based, inclusive. */
|
|
41
|
+
export interface BlameRun {
|
|
42
|
+
from: number;
|
|
43
|
+
to: number;
|
|
44
|
+
sha: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Why a file has no blame, as a value rather than a sentence at each surface. */
|
|
48
|
+
export type BlameUnavailable =
|
|
49
|
+
| 'not-repo'
|
|
50
|
+
| 'no-commit'
|
|
51
|
+
| 'untracked'
|
|
52
|
+
| 'too-large'
|
|
53
|
+
| 'empty'
|
|
54
|
+
| 'error';
|
|
55
|
+
|
|
56
|
+
export interface BlamePayload {
|
|
57
|
+
available: boolean;
|
|
58
|
+
/** The commit the answer was computed against, so a reader can say which. */
|
|
59
|
+
head: string | null;
|
|
60
|
+
/**
|
|
61
|
+
* How many lines the blamed document had.
|
|
62
|
+
*
|
|
63
|
+
* Carried rather than derived at the surface: a line the payload cannot place
|
|
64
|
+
* is either a line that does not exist yet (the buffer is longer than the
|
|
65
|
+
* file) or one the parse lost, and the panel has to say which. Blame covers
|
|
66
|
+
* the whole file, so the last run's end IS the count.
|
|
67
|
+
*/
|
|
68
|
+
lines: number;
|
|
69
|
+
runs: BlameRun[];
|
|
70
|
+
commits: Record<string, BlameCommit>;
|
|
71
|
+
reason?: BlameUnavailable;
|
|
72
|
+
message?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One entry of `git log -L`, newest first. */
|
|
76
|
+
export interface BlameHistoryEntry {
|
|
77
|
+
sha: string;
|
|
78
|
+
author: string;
|
|
79
|
+
time: number;
|
|
80
|
+
summary: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface BlameHistory {
|
|
84
|
+
entries: BlameHistoryEntry[];
|
|
85
|
+
/** More commits touched this line than the server would send. */
|
|
86
|
+
truncated: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The sha git reports for a line that is not in HEAD. */
|
|
90
|
+
const UNCOMMITTED_SHA = '0'.repeat(40);
|
|
91
|
+
|
|
92
|
+
const HEADER = /^([0-9a-f]{40}) \d+ (\d+)(?: \d+)?$/;
|
|
93
|
+
|
|
94
|
+
/** `0000…` is git's own spelling of "this line is not committed". */
|
|
95
|
+
export function isUncommittedSha(sha: string): boolean {
|
|
96
|
+
return sha === UNCOMMITTED_SHA;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Parse `git blame --porcelain` output.
|
|
101
|
+
*
|
|
102
|
+
* Runs are sorted by their first line so `blameRunAt` can binary-search them —
|
|
103
|
+
* git emits in file order, and sorting is the cheap way not to depend on it.
|
|
104
|
+
*/
|
|
105
|
+
export function parseBlamePorcelain(out: string): {
|
|
106
|
+
commits: Record<string, BlameCommit>;
|
|
107
|
+
runs: BlameRun[];
|
|
108
|
+
} {
|
|
109
|
+
const commits: Record<string, BlameCommit> = {};
|
|
110
|
+
const runs: BlameRun[] = [];
|
|
111
|
+
let sha: string | null = null;
|
|
112
|
+
let line = 0;
|
|
113
|
+
|
|
114
|
+
const pushLine = (from: number, at: string) => {
|
|
115
|
+
const last = runs[runs.length - 1];
|
|
116
|
+
if (last && last.sha === at && last.to + 1 === from) last.to = from;
|
|
117
|
+
else runs.push({ from, to: from, sha: at });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
for (const raw of out.split('\n')) {
|
|
121
|
+
if (raw.length === 0) continue;
|
|
122
|
+
// The line's own text. It is the only thing that ends a header's record,
|
|
123
|
+
// and it is deliberately discarded: the caller already holds the document.
|
|
124
|
+
if (raw.charCodeAt(0) === 9) {
|
|
125
|
+
if (sha !== null) pushLine(line, sha);
|
|
126
|
+
sha = null;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const header = HEADER.exec(raw);
|
|
130
|
+
if (header) {
|
|
131
|
+
sha = header[1];
|
|
132
|
+
line = Number(header[2]);
|
|
133
|
+
commits[sha] ??= { sha, author: '', mail: '', time: 0, summary: '' };
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (sha === null) continue;
|
|
137
|
+
const space = raw.indexOf(' ');
|
|
138
|
+
if (space < 0) continue;
|
|
139
|
+
const key = raw.slice(0, space);
|
|
140
|
+
const value = raw.slice(space + 1);
|
|
141
|
+
const commit = commits[sha];
|
|
142
|
+
if (key === 'author') commit.author = value;
|
|
143
|
+
else if (key === 'author-mail') commit.mail = value.replace(/^</, '').replace(/>$/, '');
|
|
144
|
+
else if (key === 'author-time') commit.time = Number(value);
|
|
145
|
+
else if (key === 'summary') commit.summary = value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
runs.sort((a, b) => a.from - b.from);
|
|
149
|
+
return { commits, runs };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The run covering `line`, or null when the line is outside the file. */
|
|
153
|
+
export function blameRunAt(runs: readonly BlameRun[], line: number): BlameRun | null {
|
|
154
|
+
let low = 0;
|
|
155
|
+
let high = runs.length - 1;
|
|
156
|
+
while (low <= high) {
|
|
157
|
+
const mid = (low + high) >> 1;
|
|
158
|
+
const run = runs[mid];
|
|
159
|
+
if (line < run.from) high = mid - 1;
|
|
160
|
+
else if (line > run.to) low = mid + 1;
|
|
161
|
+
else return run;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The commit that last touched `line`, or null when the payload has none. */
|
|
167
|
+
export function blameAt(
|
|
168
|
+
payload: BlamePayload,
|
|
169
|
+
line: number,
|
|
170
|
+
): { run: BlameRun; commit: BlameCommit } | null {
|
|
171
|
+
if (!payload.available) return null;
|
|
172
|
+
const run = blameRunAt(payload.runs, line);
|
|
173
|
+
if (!run) return null;
|
|
174
|
+
const commit = payload.commits[run.sha];
|
|
175
|
+
if (!commit) return null;
|
|
176
|
+
return { run, commit };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A short age, as a label can hold: `just now`, `7m ago`, `3d ago`, `2mo ago`.
|
|
181
|
+
*
|
|
182
|
+
* Compact rather than prose because it sits at the end of a code line, and
|
|
183
|
+
* because the panel prints the same string — one formatter, so the label and
|
|
184
|
+
* the panel cannot disagree about how old the commit is.
|
|
185
|
+
*/
|
|
186
|
+
export function formatBlameAge(epochSeconds: number, nowMs: number = Date.now()): string {
|
|
187
|
+
const seconds = Math.max(0, Math.floor(nowMs / 1000) - epochSeconds);
|
|
188
|
+
if (seconds < 60) return 'just now';
|
|
189
|
+
const minutes = Math.floor(seconds / 60);
|
|
190
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
191
|
+
const hours = Math.floor(minutes / 60);
|
|
192
|
+
if (hours < 24) return `${hours}h ago`;
|
|
193
|
+
const days = Math.floor(hours / 24);
|
|
194
|
+
if (days < 30) return `${days}d ago`;
|
|
195
|
+
const months = Math.floor(days / 30);
|
|
196
|
+
if (months < 12) return `${months}mo ago`;
|
|
197
|
+
return `${Math.floor(days / 365)}y ago`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The sentence a surface prints for a file with no blame. */
|
|
201
|
+
export function blameUnavailableText(reason: BlameUnavailable, message?: string): string {
|
|
202
|
+
switch (reason) {
|
|
203
|
+
case 'not-repo':
|
|
204
|
+
return 'This folder is not a git repository.';
|
|
205
|
+
case 'no-commit':
|
|
206
|
+
return 'This repository has no commits yet.';
|
|
207
|
+
case 'untracked':
|
|
208
|
+
return 'This file has never been committed, so it has no history.';
|
|
209
|
+
case 'too-large':
|
|
210
|
+
return message ?? 'This file is too large to blame.';
|
|
211
|
+
case 'empty':
|
|
212
|
+
return 'This file is empty.';
|
|
213
|
+
default:
|
|
214
|
+
return message ?? 'git could not read this file.';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The one-line label a line wears: `Ada Lovelace · 4d ago`. */
|
|
219
|
+
export function blameLabel(commit: BlameCommit, nowMs: number = Date.now()): string {
|
|
220
|
+
if (isUncommittedSha(commit.sha)) return 'Not committed yet';
|
|
221
|
+
const author = commit.author.trim() || 'Unknown';
|
|
222
|
+
return `${author} · ${formatBlameAge(commit.time, nowMs)}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Parse `git log -L` output written with `\x1f` field separators and `\x1e`
|
|
227
|
+
* record separators.
|
|
228
|
+
*
|
|
229
|
+
* A record separator is required: a commit subject is free to contain a
|
|
230
|
+
* newline-free `\x1f`-free string but nothing stops it from containing the
|
|
231
|
+
* characters a plain newline split would rely on, and git's own `%s` is
|
|
232
|
+
* single-line only by convention, not by rule.
|
|
233
|
+
*/
|
|
234
|
+
export function parseBlameHistory(out: string): BlameHistoryEntry[] {
|
|
235
|
+
const entries: BlameHistoryEntry[] = [];
|
|
236
|
+
for (const record of out.split('\x1e')) {
|
|
237
|
+
const trimmed = record.replace(/^\n+/, '');
|
|
238
|
+
if (!trimmed) continue;
|
|
239
|
+
const fields = trimmed.split('\x1f');
|
|
240
|
+
if (fields.length < 4) continue;
|
|
241
|
+
const [sha, author, time, summary] = fields;
|
|
242
|
+
if (!/^[0-9a-f]{40}$/.test(sha)) continue;
|
|
243
|
+
entries.push({ sha, author, time: Number(time), summary });
|
|
244
|
+
}
|
|
245
|
+
return entries;
|
|
246
|
+
}
|
|
@@ -18,6 +18,24 @@
|
|
|
18
18
|
* repository work.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* True for a REMOTE source `git clone` accepts.
|
|
23
|
+
*
|
|
24
|
+
* The distinction from {@link isGitUrl} is a local path: `git clone` takes
|
|
25
|
+
* `/srv/repo` and `~/repo` too, and a marketplace catalog resolves those
|
|
26
|
+
* against its own root — so only a scheme or the `git@host:path` form is a
|
|
27
|
+
* remote here. Anything else is a directory, and a directory that escapes the
|
|
28
|
+
* marketplace is refused rather than cloned.
|
|
29
|
+
*/
|
|
30
|
+
export function isRemoteGitUrl(value: string): boolean {
|
|
31
|
+
const trimmed = value.trim();
|
|
32
|
+
if (!trimmed || /\s/.test(trimmed)) return false;
|
|
33
|
+
if (/^https?:\/\/\S+$/i.test(trimmed)) return true;
|
|
34
|
+
if (/^ssh:\/\/\S+$/i.test(trimmed)) return true;
|
|
35
|
+
if (/^git@[^:/\s]+:\S+$/.test(trimmed)) return true;
|
|
36
|
+
return /^file:\/\/\S+$/i.test(trimmed);
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
/** True for a source `git clone` accepts. */
|
|
22
40
|
export function isGitUrl(value: string): boolean {
|
|
23
41
|
const trimmed = value.trim();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The purifier follows the WINDOW, not the import.
|
|
8
|
+
*
|
|
9
|
+
* DOMPurify binds to the window that exists when it is constructed; with none
|
|
10
|
+
* it reports `isSupported: false`, and `sanitize()` then returns its input
|
|
11
|
+
* UNCHANGED. The module registry is shared across test files, so a file that
|
|
12
|
+
* loaded `sanitize.ts` before installing a DOM used to leave every later caller
|
|
13
|
+
* unsanitized — measured in CI: `viewers.test.ts` received an SVG's `<script>`
|
|
14
|
+
* in the container on Windows whenever another file had imported this module
|
|
15
|
+
* first. Each case here changes the window UNDER the module and re-asks.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
19
|
+
import { Window } from 'happy-dom';
|
|
20
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
21
|
+
import { sanitizeHtml, sanitizeMermaidSvg } from '@/shared/lib/markdown/sanitize';
|
|
22
|
+
|
|
23
|
+
const SCRIPTED_SVG =
|
|
24
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><script>window.__pwned = 1;</script><rect width="10" height="10"/></svg>';
|
|
25
|
+
/** A script-free SVG: happy-dom's sanitizer empties a document that holds one,
|
|
26
|
+
* so this is the input that proves the markup was parsed and re-emitted. */
|
|
27
|
+
const PLAIN_SVG =
|
|
28
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10"/></svg>';
|
|
29
|
+
|
|
30
|
+
afterEach(() => restoreDomGlobals());
|
|
31
|
+
|
|
32
|
+
describe('the sanitizers bind to the live window', () => {
|
|
33
|
+
test('with no document the input is returned untouched, as SSR requires', () => {
|
|
34
|
+
// A bare stub: `window` exists but carries no `document`, which is exactly
|
|
35
|
+
// the shape of a non-DOM runtime.
|
|
36
|
+
installDomGlobals({});
|
|
37
|
+
expect(sanitizeMermaidSvg(SCRIPTED_SVG)).toBe(SCRIPTED_SVG);
|
|
38
|
+
expect(sanitizeHtml('<img src=x onerror="window.__pwned=1">')).toContain('onerror');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('a window installed AFTER the import is the one that sanitizes', () => {
|
|
42
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
43
|
+
// Parsed and re-emitted, not passed through: happy-dom drops the root
|
|
44
|
+
// `<svg>` wrapper and keeps the shape.
|
|
45
|
+
expect(sanitizeMermaidSvg(PLAIN_SVG)).toContain('<rect');
|
|
46
|
+
expect(sanitizeMermaidSvg(SCRIPTED_SVG)).not.toContain('<script');
|
|
47
|
+
expect(sanitizeHtml('<img src=x onerror="window.__pwned=1">')).not.toContain('onerror');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('a REPLACED window is picked up rather than the first one', () => {
|
|
51
|
+
installDomGlobals(new Window({ url: 'http://first.test' }));
|
|
52
|
+
expect(sanitizeMermaidSvg(PLAIN_SVG)).toContain('<rect');
|
|
53
|
+
installDomGlobals(new Window({ url: 'http://second.test' }));
|
|
54
|
+
expect(sanitizeMermaidSvg(PLAIN_SVG)).toContain('<rect');
|
|
55
|
+
expect(sanitizeMermaidSvg(SCRIPTED_SVG)).not.toContain('<script');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -13,9 +13,29 @@
|
|
|
13
13
|
* and let the browser dev server apply it on the client.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import DOMPurify, { type Config } from 'dompurify';
|
|
16
|
+
import DOMPurify, { type Config, type DOMPurify as Purifier } from 'dompurify';
|
|
17
17
|
import { DIRECTIVE_ATTRS_ATTR, DIRECTIVE_BLOCK_CLASS, DIRECTIVE_NAME_ATTR } from '@/shared/lib/markdown/directives';
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A purifier bound to the window that exists NOW.
|
|
21
|
+
*
|
|
22
|
+
* DOMPurify binds itself to the window it was imported under, and with no
|
|
23
|
+
* window it degrades to `isSupported: false`, where `sanitize()` returns the
|
|
24
|
+
* input UNCHANGED. Measured: this module is imported once per process, and a
|
|
25
|
+
* test file that loads it before installing a DOM left every later call — in a
|
|
26
|
+
* file that HAD a DOM — passing markup straight through, so an SVG's `<script>`
|
|
27
|
+
* reached the container. Bind per live window and rebuild when it is replaced;
|
|
28
|
+
* no hooks or `setConfig` state is kept on the instance, so a fresh one is
|
|
29
|
+
* equivalent.
|
|
30
|
+
*/
|
|
31
|
+
let bound: { root: unknown; purifier: Purifier } | null = null;
|
|
32
|
+
|
|
33
|
+
function purifierForCurrentWindow(): Purifier | null {
|
|
34
|
+
if (typeof window === 'undefined' || !window.document) return null;
|
|
35
|
+
if (bound?.root !== window) bound = { root: window, purifier: DOMPurify(window) };
|
|
36
|
+
return bound.purifier;
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
const KATEX_MATHML_TAGS = [
|
|
20
40
|
'math',
|
|
21
41
|
'annotation',
|
|
@@ -101,7 +121,8 @@ function buildMermaidConfig(hasUri: boolean): Config {
|
|
|
101
121
|
*/
|
|
102
122
|
export function sanitizeHtml(html: string): string {
|
|
103
123
|
if (!html) return html;
|
|
104
|
-
|
|
124
|
+
const purifier = purifierForCurrentWindow();
|
|
125
|
+
if (!purifier) return html;
|
|
105
126
|
|
|
106
127
|
const hasSvgIcon = /<svg[^>]*>/.test(html);
|
|
107
128
|
const hasMathPlaceholder = html.includes('math-pending');
|
|
@@ -131,7 +152,7 @@ export function sanitizeHtml(html: string): string {
|
|
|
131
152
|
: { USE_PROFILES: { html: true } as const };
|
|
132
153
|
|
|
133
154
|
try {
|
|
134
|
-
return
|
|
155
|
+
return purifier.sanitize(html, config);
|
|
135
156
|
} catch {
|
|
136
157
|
return html;
|
|
137
158
|
}
|
|
@@ -146,11 +167,12 @@ export function sanitizeHtml(html: string): string {
|
|
|
146
167
|
*/
|
|
147
168
|
export function sanitizeMermaidSvg(svg: string): string {
|
|
148
169
|
if (!svg) return svg;
|
|
149
|
-
|
|
170
|
+
const purifier = purifierForCurrentWindow();
|
|
171
|
+
if (!purifier) return svg;
|
|
150
172
|
|
|
151
173
|
const hasUri = /href/.test(svg);
|
|
152
174
|
try {
|
|
153
|
-
return
|
|
175
|
+
return purifier.sanitize(svg, buildMermaidConfig(hasUri));
|
|
154
176
|
} catch {
|
|
155
177
|
return svg;
|
|
156
178
|
}
|
|
@@ -170,7 +192,8 @@ export function sanitizeMermaidSvg(svg: string): string {
|
|
|
170
192
|
*/
|
|
171
193
|
export function sanitizeKatexHtml(html: string): string {
|
|
172
194
|
if (!html) return html;
|
|
173
|
-
|
|
195
|
+
const purifier = purifierForCurrentWindow();
|
|
196
|
+
if (!purifier) return html;
|
|
174
197
|
|
|
175
198
|
// DOMPurify drops a bare root-level <span>, which would strip KaTeX's outer
|
|
176
199
|
// `.katex` wrapper — the element every layout rule in katex.css hangs off.
|
|
@@ -178,7 +201,7 @@ export function sanitizeKatexHtml(html: string): string {
|
|
|
178
201
|
// removed again afterwards so only the KaTeX markup is injected.
|
|
179
202
|
const wrapped = `<div data-katex-wrap>${html}</div>`;
|
|
180
203
|
try {
|
|
181
|
-
const clean =
|
|
204
|
+
const clean = purifier.sanitize(wrapped, {
|
|
182
205
|
USE_PROFILES: { html: true, mathMl: true },
|
|
183
206
|
ADD_ATTR: ['class', 'aria-hidden', 'encoding', 'style', 'data-katex-wrap'],
|
|
184
207
|
} as Config);
|