@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
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
releasePendingSession,
|
|
32
32
|
startPendingSession,
|
|
33
33
|
} from '@/client/hooks/chat/omp/pending-sessions';
|
|
34
|
-
import { withPendingRows } from '@/client/hooks/chat/omp/pending-rows';
|
|
34
|
+
import { pendingHostFolderIds, withPendingRows } from '@/client/hooks/chat/omp/pending-rows';
|
|
35
35
|
import { formatNewSessionTitle } from '@/shared/lib/omp/session/default-title';
|
|
36
36
|
import { forgetSession, getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
|
|
37
37
|
import { CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
@@ -298,6 +298,21 @@ describe('withPendingRows', () => {
|
|
|
298
298
|
})).toBe(base);
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
+
test('the auto-expand host is the folder the row is DRAWN in', () => {
|
|
302
|
+
// The sidebar opens the folder it is about to hide a row in, so the id it
|
|
303
|
+
// opens must come from the same resolution the row is placed by — never a
|
|
304
|
+
// second guess.
|
|
305
|
+
const id = start(2);
|
|
306
|
+
const entries = listPendingSessions();
|
|
307
|
+
const placed = withPendingRows(twoFolders(), entries, { activeId: id });
|
|
308
|
+
const hosted = pendingHostFolderIds(twoFolders(), entries, { activeId: id });
|
|
309
|
+
|
|
310
|
+
expect(placed[1]?.sessions?.[0]?.id).toBe(id);
|
|
311
|
+
expect(hosted).toEqual(['2']);
|
|
312
|
+
// No entries: nothing to open, and the list is not touched.
|
|
313
|
+
expect(pendingHostFolderIds(twoFolders(), [], { activeId: id })).toEqual([]);
|
|
314
|
+
});
|
|
315
|
+
|
|
301
316
|
test('the row is named by the sent text, else by the id clock', () => {
|
|
302
317
|
const id = start(1);
|
|
303
318
|
const entry = listPendingSessions()[0];
|
|
@@ -232,3 +232,105 @@ describe('a new chat shows in the sidebar before omp writes its transcript', ()
|
|
|
232
232
|
server.stop();
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
|
+
|
|
236
|
+
describe('a folder opens when a row inside it needs to be seen', () => {
|
|
237
|
+
/** Capture the expand writes the controller issues, and answer them. */
|
|
238
|
+
function stubToggleWrites(): { toggles: string[]; restore: () => void } {
|
|
239
|
+
const toggles: string[] = [];
|
|
240
|
+
const original = globalThis.fetch;
|
|
241
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
242
|
+
const url = String(input);
|
|
243
|
+
// Only the folder toggle is under test; the sidebar's other requests
|
|
244
|
+
// (the waiting list) still have to resolve, so they are answered too.
|
|
245
|
+
if (url.includes('/api/folders/')) {
|
|
246
|
+
const body = init?.body instanceof URLSearchParams ? init.body : new URLSearchParams();
|
|
247
|
+
toggles.push(`${url} ${body.get('isExpanded')}`);
|
|
248
|
+
}
|
|
249
|
+
return new Response(JSON.stringify({ success: true }), {
|
|
250
|
+
status: 200,
|
|
251
|
+
headers: { 'content-type': 'application/json' },
|
|
252
|
+
});
|
|
253
|
+
}) as unknown as typeof fetch;
|
|
254
|
+
return { toggles, restore: () => { globalThis.fetch = original; } };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function flush(): Promise<void> {
|
|
258
|
+
await act(async () => {
|
|
259
|
+
for (let i = 0; i < 8; i += 1) await Promise.resolve();
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Publish a run over the real socket, INSIDE `act` so the render it causes
|
|
264
|
+
* flushes its effects before the assertions run. */
|
|
265
|
+
async function publishRun(harness: Harness): Promise<void> {
|
|
266
|
+
await act(async () => {
|
|
267
|
+
harness.server.publish(TOPIC_SIDEBAR_STATUS, { 'real-1': { streamStatus: 'stream' } });
|
|
268
|
+
await harness.server.waitForTopic<SidebarStatusPayload>(
|
|
269
|
+
TOPIC_SIDEBAR_STATUS,
|
|
270
|
+
(value) => value?.['real-1']?.streamStatus === 'stream',
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
await flush();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
test('a run in flight opens its collapsed folder and stores the flag', async () => {
|
|
277
|
+
const harness = await mountController('?sessionId=real-1');
|
|
278
|
+
const writes = stubToggleWrites();
|
|
279
|
+
try {
|
|
280
|
+
await publishRun(harness);
|
|
281
|
+
|
|
282
|
+
// Both halves: the list renders the folder open NOW, and the write makes
|
|
283
|
+
// it survive the run ending and a reload.
|
|
284
|
+
expect(harness.holder.api?.processedFolders[0]?.isExpanded).toBe(true);
|
|
285
|
+
expect(writes.toggles).toEqual(['/api/folders/7/toggle true']);
|
|
286
|
+
} finally {
|
|
287
|
+
writes.restore();
|
|
288
|
+
harness.server.stop();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('a run is written open ONCE, not on every structure push', async () => {
|
|
293
|
+
const harness = await mountController('?sessionId=real-1');
|
|
294
|
+
const writes = stubToggleWrites();
|
|
295
|
+
try {
|
|
296
|
+
await publishRun(harness);
|
|
297
|
+
expect(writes.toggles).toHaveLength(1);
|
|
298
|
+
|
|
299
|
+
// A tool call republishes the structure mid-run. A payload that DIFFERS
|
|
300
|
+
// (the rename) is what makes the client re-render the list, so the effect
|
|
301
|
+
// really is given a chance to write again.
|
|
302
|
+
await act(async () => {
|
|
303
|
+
harness.server.publish(TOPIC_SIDEBAR, {
|
|
304
|
+
folders: [{ ...structureBody().folders[0], name: 'ws renamed' }],
|
|
305
|
+
isMock: false,
|
|
306
|
+
});
|
|
307
|
+
await harness.server.waitForTopic<SidebarPayload>(
|
|
308
|
+
TOPIC_SIDEBAR,
|
|
309
|
+
(value) => value?.folders[0]?.name === 'ws renamed',
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
await flush();
|
|
313
|
+
|
|
314
|
+
expect(writes.toggles).toHaveLength(1);
|
|
315
|
+
} finally {
|
|
316
|
+
writes.restore();
|
|
317
|
+
harness.server.stop();
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('a new chat opens and STORES its folder', async () => {
|
|
322
|
+
const harness = await mountController('?sessionId=real-1');
|
|
323
|
+
const writes = stubToggleWrites();
|
|
324
|
+
const id = startPendingSession(7);
|
|
325
|
+
try {
|
|
326
|
+
await harness.setUrl(`?sessionId=${id}&folderId=7`);
|
|
327
|
+
await flush();
|
|
328
|
+
|
|
329
|
+
expect(writes.toggles).toEqual(['/api/folders/7/toggle true']);
|
|
330
|
+
} finally {
|
|
331
|
+
releasePendingSession(id);
|
|
332
|
+
writes.restore();
|
|
333
|
+
harness.server.stop();
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import { markPendingSessionWaiting } from '@/client/hooks/chat/omp/pending-waiting';
|
|
34
34
|
import { useWaitingPrompts } from '@/client/hooks/chat/waiting/store';
|
|
35
35
|
import { withPendingRows } from '@/client/hooks/chat/omp/pending-rows';
|
|
36
|
+
import { useFolderAutoExpand } from '@/client/hooks/chat/omp/folder-auto-expand';
|
|
36
37
|
import { writeSetting } from '@/shared/lib/settings/client';
|
|
37
38
|
import { subscribeSessionKey } from '@/shared/lib/workspace/session-state/listeners';
|
|
38
39
|
import { CHAT_DRAFT_ATTACHMENTS_KEY, CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
@@ -161,6 +162,16 @@ export function useSessionSidebarController(
|
|
|
161
162
|
() => new Set(Object.entries(sessionStatus).filter(([, status]) => status === 'stream').map(([id]) => id)),
|
|
162
163
|
[sessionStatus],
|
|
163
164
|
);
|
|
165
|
+
// A folder hosting a run in flight, or a brand-new chat's row, opens itself
|
|
166
|
+
// and stays open — see `folder-auto-expand.ts` for the edge rules.
|
|
167
|
+
const runningFolderIds = useFolderAutoExpand({
|
|
168
|
+
folders,
|
|
169
|
+
initializing,
|
|
170
|
+
runningIds,
|
|
171
|
+
pendingEntries,
|
|
172
|
+
activeId: sessionParam,
|
|
173
|
+
urlFolderId: folderIdParam,
|
|
174
|
+
});
|
|
164
175
|
|
|
165
176
|
// The URL is the other way a pending chat exists: a reload (or a second tab)
|
|
166
177
|
// re-enters `?sessionId=new-…` with an empty store. An id the structure does
|
|
@@ -284,11 +295,20 @@ export function useSessionSidebarController(
|
|
|
284
295
|
}
|
|
285
296
|
}
|
|
286
297
|
|
|
298
|
+
// A run in flight opens its folder in the SAME frame the spinner appears,
|
|
299
|
+
// and keeps it open if the toggle write is refused. The write below makes
|
|
300
|
+
// the flag durable; this makes it immediate.
|
|
301
|
+
if (runningFolderIds.size > 0) {
|
|
302
|
+
result = result.map((folder) => (
|
|
303
|
+
runningFolderIds.has(String(folder.id)) ? { ...folder, isExpanded: true } : folder
|
|
304
|
+
));
|
|
305
|
+
}
|
|
306
|
+
|
|
287
307
|
// Ordering is shared with the other sidebar so the two cannot drift.
|
|
288
308
|
result = sortFolders(result, sortOption);
|
|
289
309
|
|
|
290
310
|
return result;
|
|
291
|
-
}, [folders, pendingEntries, searchQuery, sortOption, sessionParam, folderIdParam, expandSearchMatches, titleHint]);
|
|
311
|
+
}, [folders, pendingEntries, searchQuery, sortOption, sessionParam, folderIdParam, expandSearchMatches, titleHint, runningFolderIds]);
|
|
292
312
|
|
|
293
313
|
return {
|
|
294
314
|
folders,
|
|
@@ -48,6 +48,11 @@ export interface OmpStreamRefs {
|
|
|
48
48
|
currentThinkingLevelRef: RefObject<string | undefined>;
|
|
49
49
|
/** Phrase for an open provider-retry saga, or null (see `fold-deps.ts`). */
|
|
50
50
|
providerRetryVerbRef: RefObject<string | null>;
|
|
51
|
+
/**
|
|
52
|
+
* The transcript row owning a call this fold never streamed — a run resumed
|
|
53
|
+
* after a page reload. See `ToolResultHost.resumedToolMessage`.
|
|
54
|
+
*/
|
|
55
|
+
resumedToolMessage?: (callId: string) => ChatMessageData | undefined;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
interface UseOmpAgentStreamOptions extends OmpStreamRefs {
|
|
@@ -63,6 +68,7 @@ export function useOmpAgentStream({
|
|
|
63
68
|
activityRef,
|
|
64
69
|
currentThinkingLevelRef,
|
|
65
70
|
providerRetryVerbRef,
|
|
71
|
+
resumedToolMessage,
|
|
66
72
|
}: UseOmpAgentStreamOptions) {
|
|
67
73
|
/** The session this hook is currently attached to, or null. */
|
|
68
74
|
const attachedRef = useRef<string | null>(null);
|
|
@@ -123,11 +129,12 @@ export function useOmpAgentStream({
|
|
|
123
129
|
activityRef,
|
|
124
130
|
currentThinkingLevelRef,
|
|
125
131
|
providerRetryVerbRef,
|
|
132
|
+
resumedToolMessage,
|
|
126
133
|
});
|
|
127
134
|
});
|
|
128
135
|
|
|
129
136
|
setState((prev) => ({ ...prev, connected: true }));
|
|
130
|
-
}, [disconnect, setState, callbacksRef, toolResultsRef, lastToolMessageRef, activityRef, currentThinkingLevelRef, providerRetryVerbRef]);
|
|
137
|
+
}, [disconnect, setState, callbacksRef, toolResultsRef, lastToolMessageRef, activityRef, currentThinkingLevelRef, providerRetryVerbRef, resumedToolMessage]);
|
|
131
138
|
|
|
132
139
|
// The subscription outlives a session switch only through `connect`'s own
|
|
133
140
|
// disconnect, so an unmount has to release it explicitly.
|
|
@@ -214,7 +214,7 @@ export function useChatTimeline({
|
|
|
214
214
|
withdrawExtensionDialog,
|
|
215
215
|
reloadMessages,
|
|
216
216
|
needsReloadRef,
|
|
217
|
-
}), activityRef);
|
|
217
|
+
}), activityRef, localMessagesRef);
|
|
218
218
|
const spawn = useSpawnTarget(sessionId);
|
|
219
219
|
|
|
220
220
|
const { steerOmpAgent, executeSend } = useChatTimelineSend({
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The New Chat card's open state, and the prewarm its click fires.
|
|
8
|
+
*
|
|
9
|
+
* Both live here because they are one decision: the moment the card opens is
|
|
10
|
+
* the earliest point at which the chat's cwd is known, and the first send is
|
|
11
|
+
* what pays for the omp spawn (measured 675-934 ms). The card routinely sits
|
|
12
|
+
* open while the instruction is written, so warming the child then hides that
|
|
13
|
+
* boot entirely.
|
|
14
|
+
*
|
|
15
|
+
* The folder resolution mirrors `useNewChatSubmit` — the active session's
|
|
16
|
+
* folder, else the composer's pick — because a prewarm in a different cwd is a
|
|
17
|
+
* process the send never claims, which costs a spawn AND a kill.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
21
|
+
import type { Attachment, WorkspaceFolderData } from '@/shared/types';
|
|
22
|
+
import { activeProjectForSession } from '@/shared/lib/workspace/active-project';
|
|
23
|
+
import { spawnCwdForNewSession, triggerSessionPrewarm } from '@/shared/lib/omp/session/prewarm';
|
|
24
|
+
|
|
25
|
+
export interface NewChatOpen {
|
|
26
|
+
/** The seeded content, or null while the card is closed. */
|
|
27
|
+
content: string | null;
|
|
28
|
+
/** Attachments of the row the card was opened from. */
|
|
29
|
+
attachments: Attachment[];
|
|
30
|
+
/** Open the card on `content`, warming the child for the chat it will create. */
|
|
31
|
+
open: (content: string, attachments?: Attachment[]) => void;
|
|
32
|
+
close: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface NewChatOpenDeps {
|
|
36
|
+
folders: WorkspaceFolderData[];
|
|
37
|
+
/** Session the card was opened from — the scope the prewarm inherits. */
|
|
38
|
+
sessionId: string | null;
|
|
39
|
+
selectedFolderId: number | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useNewChatOpen({ folders, sessionId, selectedFolderId }: NewChatOpenDeps): NewChatOpen {
|
|
43
|
+
const [content, setContent] = useState<string | null>(null);
|
|
44
|
+
const [attachments, setAttachments] = useState<Attachment[]>([]);
|
|
45
|
+
|
|
46
|
+
const open = useCallback((next: string, rows?: Attachment[]) => {
|
|
47
|
+
const folderId = activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId ?? undefined;
|
|
48
|
+
const cwd = spawnCwdForNewSession(folders, sessionId, folderId);
|
|
49
|
+
if (cwd) triggerSessionPrewarm(cwd);
|
|
50
|
+
setContent(next);
|
|
51
|
+
setAttachments(rows ?? []);
|
|
52
|
+
}, [folders, sessionId, selectedFolderId]);
|
|
53
|
+
|
|
54
|
+
const close = useCallback(() => {
|
|
55
|
+
setContent(null);
|
|
56
|
+
setAttachments([]);
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
return { content, attachments, open, close };
|
|
60
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The two line-blame settings: the inline label, and the whole feature.
|
|
8
|
+
*
|
|
9
|
+
* ## Off by default, and why
|
|
10
|
+
*
|
|
11
|
+
* `editorBlame` defaults ON — hovering a line to learn who wrote it is the
|
|
12
|
+
* feature, and a switch nobody finds is a feature nobody has. `editorBlameInline`
|
|
13
|
+
* defaults OFF, because the label sits at the END of every run's first line: at
|
|
14
|
+
* the panel's 320px floor it turns a long line into two and pushes the code it
|
|
15
|
+
* describes out of the reading column. The card is reachable without it (the
|
|
16
|
+
* line number in the gutter is the other hover target), so the label is the
|
|
17
|
+
* decoration and the card is the feature.
|
|
18
|
+
*
|
|
19
|
+
* ## Reaching an open editor
|
|
20
|
+
*
|
|
21
|
+
* Through `omp:editor-blame-changed`, the shape the font, theme, indent and
|
|
22
|
+
* typing settings all use: `appSettings` is a boot-time prop, so a value read
|
|
23
|
+
* once would never reach an editor already on screen. The event fires only when
|
|
24
|
+
* a value actually moved.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
28
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
29
|
+
|
|
30
|
+
/** Broadcast on every blame-setting write. Detail is the resolved pair. */
|
|
31
|
+
export const EDITOR_BLAME_CHANGED_EVENT = 'omp:editor-blame-changed';
|
|
32
|
+
|
|
33
|
+
export interface EditorBlameOptions {
|
|
34
|
+
/** The card, and the read behind it. Off means no request at all. */
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
/** The label at the end of each run's first line. */
|
|
37
|
+
inline: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const DEFAULT_EDITOR_BLAME: EditorBlameOptions = { enabled: true, inline: false };
|
|
41
|
+
|
|
42
|
+
/** The stored pair, falling back per key so one unset does not disable the other. */
|
|
43
|
+
export function currentEditorBlame(): EditorBlameOptions {
|
|
44
|
+
if (typeof window === 'undefined') return DEFAULT_EDITOR_BLAME;
|
|
45
|
+
const enabled = readKabmoSetting<boolean>('editorBlame');
|
|
46
|
+
const inline = readKabmoSetting<boolean>('editorBlameInline');
|
|
47
|
+
return {
|
|
48
|
+
enabled: typeof enabled === 'boolean' ? enabled : DEFAULT_EDITOR_BLAME.enabled,
|
|
49
|
+
inline: typeof inline === 'boolean' ? inline : DEFAULT_EDITOR_BLAME.inline,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The stored pair, kept in step with writes from the settings modal. */
|
|
54
|
+
export function useEditorBlame(): EditorBlameOptions {
|
|
55
|
+
const [blame, setBlame] = useState<EditorBlameOptions>(currentEditorBlame);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const onChange = (event: Event) => {
|
|
59
|
+
const detail = (event as CustomEvent<EditorBlameOptions>).detail;
|
|
60
|
+
setBlame(detail ?? currentEditorBlame());
|
|
61
|
+
};
|
|
62
|
+
window.addEventListener(EDITOR_BLAME_CHANGED_EVENT, onChange);
|
|
63
|
+
return () => window.removeEventListener(EDITOR_BLAME_CHANGED_EVENT, onChange);
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
return blame;
|
|
67
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The blame controller against a stubbed `fetch`, through the real hook.
|
|
8
|
+
*
|
|
9
|
+
* Three of its rules exist because the alternative was measured: a late answer
|
|
10
|
+
* for another file, a payload reported under a key it was not read for, and a
|
|
11
|
+
* payload discarded on every keystroke. Each is a case below, and each fails
|
|
12
|
+
* with the guard removed.
|
|
13
|
+
*
|
|
14
|
+
* The hook, Preact and `act` are imported inside `beforeAll` for the reason
|
|
15
|
+
* `file-editor.test-util.ts` does the same: the DOM globals have to be installed
|
|
16
|
+
* BEFORE Preact is evaluated, so a top-level import would bind the wrong
|
|
17
|
+
* `document`. `settle()` flushes microtasks rather than sleeping, because the
|
|
18
|
+
* stubbed fetch resolves on its own schedule and a real delay would only make
|
|
19
|
+
* the suite slower.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
23
|
+
import { Window } from 'happy-dom';
|
|
24
|
+
import type { FunctionComponent } from 'preact';
|
|
25
|
+
|
|
26
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
27
|
+
import type { BlamePayload } from '@/shared/lib/fs/git-blame';
|
|
28
|
+
import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
|
|
29
|
+
import type { useFileBlame as UseFileBlameHook } from '@/client/hooks/editor/blame';
|
|
30
|
+
|
|
31
|
+
const SHA = 'a'.repeat(40);
|
|
32
|
+
|
|
33
|
+
const PAYLOAD: BlamePayload = {
|
|
34
|
+
available: true,
|
|
35
|
+
head: SHA,
|
|
36
|
+
lines: 3,
|
|
37
|
+
runs: [{ from: 1, to: 3, sha: SHA }],
|
|
38
|
+
commits: { [SHA]: { sha: SHA, author: 'Ada', mail: 'ada@example.com', time: 1_700_000_000, summary: 'feat: x' } },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const TARGET: FileEditorTarget = { name: 'a.ts', path: 'src/a.ts', root: '/repo', repo: '.' };
|
|
42
|
+
const OTHER: FileEditorTarget = { name: 'b.ts', path: 'src/b.ts', root: '/repo', repo: '.' };
|
|
43
|
+
|
|
44
|
+
type BlameController = ReturnType<typeof UseFileBlameHook>;
|
|
45
|
+
|
|
46
|
+
let useFileBlame: typeof UseFileBlameHook;
|
|
47
|
+
let h: typeof import('preact').h;
|
|
48
|
+
let render: typeof import('preact').render;
|
|
49
|
+
let act: typeof import('preact/test-utils').act;
|
|
50
|
+
let container: HTMLElement;
|
|
51
|
+
|
|
52
|
+
/** The hook's latest result, re-read after every settle. */
|
|
53
|
+
let live: BlameController | null = null;
|
|
54
|
+
let props: { target: FileEditorTarget | null; enabled?: boolean; dirty?: boolean } = { target: TARGET };
|
|
55
|
+
|
|
56
|
+
/** Every URL the hook asked for, in order. */
|
|
57
|
+
let requests: string[] = [];
|
|
58
|
+
const nativeFetch = Bun.fetch;
|
|
59
|
+
|
|
60
|
+
function jsonResponse(body: unknown, status = 200): Response {
|
|
61
|
+
return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Flush every pending microtask, then let Preact's effects run. */
|
|
65
|
+
async function settle(): Promise<void> {
|
|
66
|
+
for (let i = 0; i < 20; i++) await Promise.resolve();
|
|
67
|
+
await act(async () => {
|
|
68
|
+
for (let i = 0; i < 20; i++) await Promise.resolve();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function mount(next: typeof props): Promise<void> {
|
|
73
|
+
props = next;
|
|
74
|
+
await act(async () => {
|
|
75
|
+
render(h(Probe, {}), container);
|
|
76
|
+
});
|
|
77
|
+
await settle();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const Probe: FunctionComponent = () => {
|
|
81
|
+
live = useFileBlame(props.target, { enabled: props.enabled, dirty: props.dirty });
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
beforeAll(async () => {
|
|
86
|
+
const win = new Window({ url: 'http://localhost' });
|
|
87
|
+
installDomGlobals(win);
|
|
88
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
89
|
+
({ useFileBlame } = await import('@/client/hooks/editor/blame'));
|
|
90
|
+
({ h, render } = await import('preact'));
|
|
91
|
+
({ act } = await import('preact/test-utils'));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
afterAll(() => {
|
|
95
|
+
restoreDomGlobals();
|
|
96
|
+
globalThis.fetch = nativeFetch;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(async () => {
|
|
100
|
+
// The same component type at the same position is UPDATED rather than
|
|
101
|
+
// remounted, so without this the next case inherits the previous hook state.
|
|
102
|
+
await act(async () => {
|
|
103
|
+
render(null, container);
|
|
104
|
+
});
|
|
105
|
+
requests = [];
|
|
106
|
+
live = null;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('useFileBlame', () => {
|
|
110
|
+
test('reads the file once and reports it ready', async () => {
|
|
111
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
112
|
+
requests.push(String(input));
|
|
113
|
+
return jsonResponse(PAYLOAD);
|
|
114
|
+
}) as typeof fetch;
|
|
115
|
+
|
|
116
|
+
await mount({ target: TARGET });
|
|
117
|
+
const snapshot = live!.snapshot();
|
|
118
|
+
expect(snapshot.status).toBe('ready');
|
|
119
|
+
expect(snapshot.payload?.lines).toBe(3);
|
|
120
|
+
expect(requests).toHaveLength(1);
|
|
121
|
+
expect(requests[0]).toContain('blame=1');
|
|
122
|
+
expect(requests[0]).toContain('file=src%2Fa.ts');
|
|
123
|
+
expect(requests[0]).toContain('root=%2Frepo');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('a dirty buffer issues no read at all', async () => {
|
|
127
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
128
|
+
requests.push(String(input));
|
|
129
|
+
return jsonResponse(PAYLOAD);
|
|
130
|
+
}) as typeof fetch;
|
|
131
|
+
|
|
132
|
+
await mount({ target: TARGET, dirty: true });
|
|
133
|
+
expect(requests).toHaveLength(0);
|
|
134
|
+
expect(live!.stale()).toBe(true);
|
|
135
|
+
// The previous payload is kept and marked stale rather than blanked: a
|
|
136
|
+
// skeleton on every keystroke would be worse than a label that says why.
|
|
137
|
+
expect(live!.snapshot().payload).toBeNull();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('saving re-reads, and the answer arrives without a remount', async () => {
|
|
141
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
142
|
+
requests.push(String(input));
|
|
143
|
+
return jsonResponse(PAYLOAD);
|
|
144
|
+
}) as typeof fetch;
|
|
145
|
+
|
|
146
|
+
await mount({ target: TARGET, dirty: true });
|
|
147
|
+
await mount({ target: TARGET, dirty: false });
|
|
148
|
+
expect(requests).toHaveLength(1);
|
|
149
|
+
expect(live!.snapshot().status).toBe('ready');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('an unavailable payload is reported as an answer, not an error', async () => {
|
|
153
|
+
const untracked: BlamePayload = {
|
|
154
|
+
available: false,
|
|
155
|
+
head: null,
|
|
156
|
+
lines: 0,
|
|
157
|
+
runs: [],
|
|
158
|
+
commits: {},
|
|
159
|
+
reason: 'untracked',
|
|
160
|
+
message: "fatal: no such path 'x' in HEAD",
|
|
161
|
+
};
|
|
162
|
+
globalThis.fetch = (async () => jsonResponse(untracked)) as unknown as typeof fetch;
|
|
163
|
+
|
|
164
|
+
await mount({ target: TARGET });
|
|
165
|
+
const snapshot = live!.snapshot();
|
|
166
|
+
expect(snapshot.status).toBe('unavailable');
|
|
167
|
+
expect(snapshot.payload?.reason).toBe('untracked');
|
|
168
|
+
expect(snapshot.message).toContain('no such path');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('a failed request is an error that keeps the server’s reason', async () => {
|
|
172
|
+
globalThis.fetch = (async () => jsonResponse({ error: 'Invalid path' }, 403)) as unknown as typeof fetch;
|
|
173
|
+
|
|
174
|
+
await mount({ target: TARGET });
|
|
175
|
+
const snapshot = live!.snapshot();
|
|
176
|
+
expect(snapshot.status).toBe('error');
|
|
177
|
+
expect(snapshot.message).toBe('Invalid path');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('a late answer for the PREVIOUS file never lands on the new one', async () => {
|
|
181
|
+
// The first file's read is held open; the tab switches; only then does the
|
|
182
|
+
// first answer arrive. Adopting it would label b.ts with a.ts's authors.
|
|
183
|
+
const held = Promise.withResolvers<Response>();
|
|
184
|
+
globalThis.fetch = ((input: RequestInfo | URL) => {
|
|
185
|
+
const url = String(input);
|
|
186
|
+
requests.push(url);
|
|
187
|
+
if (url.includes('a.ts')) return held.promise;
|
|
188
|
+
return Promise.resolve(jsonResponse({ ...PAYLOAD, lines: 9, runs: [{ from: 1, to: 9, sha: SHA }] }));
|
|
189
|
+
}) as typeof fetch;
|
|
190
|
+
|
|
191
|
+
await mount({ target: TARGET });
|
|
192
|
+
await mount({ target: OTHER });
|
|
193
|
+
expect(live!.snapshot().payload?.lines).toBe(9);
|
|
194
|
+
|
|
195
|
+
held.resolve(jsonResponse(PAYLOAD));
|
|
196
|
+
await settle();
|
|
197
|
+
// Still the second file's answer.
|
|
198
|
+
expect(live!.snapshot().payload?.lines).toBe(9);
|
|
199
|
+
expect(live!.snapshot().status).toBe('ready');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('the snapshot is loading for a file whose read has not landed yet', async () => {
|
|
203
|
+
const held = Promise.withResolvers<Response>();
|
|
204
|
+
globalThis.fetch = (() => held.promise) as unknown as typeof fetch;
|
|
205
|
+
|
|
206
|
+
await mount({ target: TARGET });
|
|
207
|
+
expect(live!.snapshot().status).toBe('loading');
|
|
208
|
+
|
|
209
|
+
// A switch to a file the controller has never read must not show the
|
|
210
|
+
// previous file's payload under the new key.
|
|
211
|
+
await mount({ target: OTHER });
|
|
212
|
+
expect(live!.snapshot().payload).toBeNull();
|
|
213
|
+
|
|
214
|
+
held.resolve(jsonResponse(PAYLOAD));
|
|
215
|
+
await settle();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('history is read once per line and cached', async () => {
|
|
219
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
220
|
+
const url = String(input);
|
|
221
|
+
requests.push(url);
|
|
222
|
+
if (url.includes('blameHistory=1')) {
|
|
223
|
+
return jsonResponse({ entries: [{ sha: SHA, author: 'Ada', time: 1, summary: 'feat: x' }], truncated: false });
|
|
224
|
+
}
|
|
225
|
+
return jsonResponse(PAYLOAD);
|
|
226
|
+
}) as typeof fetch;
|
|
227
|
+
|
|
228
|
+
await mount({ target: TARGET });
|
|
229
|
+
const first = await live!.history(2);
|
|
230
|
+
const second = await live!.history(2);
|
|
231
|
+
expect(first.entries).toHaveLength(1);
|
|
232
|
+
expect(second).toBe(first);
|
|
233
|
+
expect(requests.filter((url) => url.includes('blameHistory=1'))).toHaveLength(1);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('a failed history read is an empty list, not a throw', async () => {
|
|
237
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
238
|
+
if (String(input).includes('blameHistory=1')) throw new Error('offline');
|
|
239
|
+
return jsonResponse(PAYLOAD);
|
|
240
|
+
}) as unknown as typeof fetch;
|
|
241
|
+
|
|
242
|
+
await mount({ target: TARGET });
|
|
243
|
+
expect(await live!.history(3)).toEqual({ entries: [], truncated: false });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('reload drops the cached history and reads again', async () => {
|
|
247
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
248
|
+
const url = String(input);
|
|
249
|
+
requests.push(url);
|
|
250
|
+
if (url.includes('blameHistory=1')) return jsonResponse({ entries: [], truncated: false });
|
|
251
|
+
return jsonResponse(PAYLOAD);
|
|
252
|
+
}) as typeof fetch;
|
|
253
|
+
|
|
254
|
+
await mount({ target: TARGET });
|
|
255
|
+
await live!.history(1);
|
|
256
|
+
live!.reload();
|
|
257
|
+
await settle();
|
|
258
|
+
await live!.history(1);
|
|
259
|
+
expect(requests.filter((url) => url.includes('blameHistory=1'))).toHaveLength(2);
|
|
260
|
+
expect(requests.filter((url) => url.includes('blame=1'))).toHaveLength(2);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('a device-backed tab is never read: there is no path the server can reach', async () => {
|
|
264
|
+
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
265
|
+
requests.push(String(input));
|
|
266
|
+
return jsonResponse(PAYLOAD);
|
|
267
|
+
}) as unknown as typeof fetch;
|
|
268
|
+
|
|
269
|
+
await mount({ target: { name: 'x.png', path: 'x.png', deviceFile: true } });
|
|
270
|
+
expect(requests).toHaveLength(0);
|
|
271
|
+
});
|
|
272
|
+
});
|