@kabmo-labs/kabmo 0.8.0 → 0.10.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 +52 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +336 -336
- package/dist/client/static/js/index-18xe7655.css +1 -0
- package/dist/client/static/js/{index-qwpvd9fv.js → index-nxpe7835.js} +933 -898
- package/package.json +11 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
- package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
- package/src/client/components/common/code-surface/documents.test.ts +122 -0
- package/src/client/components/common/code-surface/documents.ts +286 -0
- package/src/client/components/common/code-surface/extensions.test.ts +115 -0
- package/src/client/components/common/code-surface/extensions.ts +295 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
- package/src/client/components/common/code-surface/fold.test.ts +148 -0
- package/src/client/components/common/code-surface/fold.ts +118 -0
- package/src/client/components/common/code-surface/handle.ts +102 -0
- package/src/client/components/common/code-surface/indent-guide.ts +104 -0
- package/src/client/components/common/code-surface/indent.test.ts +239 -0
- package/src/client/components/common/code-surface/indent.ts +124 -0
- package/src/client/components/common/code-surface/index.tsx +283 -314
- package/src/client/components/common/code-surface/keymap.test.ts +133 -0
- package/src/client/components/common/code-surface/keymap.ts +256 -0
- package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
- package/src/client/components/common/code-surface/line-commands.ts +103 -0
- package/src/client/components/common/code-surface/marks.ts +74 -0
- package/src/client/components/common/code-surface/props.ts +87 -0
- package/src/client/components/common/code-surface/shiki.ts +234 -0
- package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
- package/src/client/components/common/code-surface/stream-language.ts +123 -0
- package/src/client/components/common/code-surface/sync.test.ts +185 -0
- package/src/client/components/common/code-surface/sync.ts +58 -0
- package/src/client/components/common/code-surface/theme.test.ts +237 -0
- package/src/client/components/common/code-surface/theme.ts +224 -0
- package/src/client/components/common/code-surface/typing.test.ts +97 -0
- package/src/client/components/common/code-surface/typing.ts +111 -0
- package/src/client/components/common/editor-view-buttons/index.test.tsx +148 -0
- package/src/client/components/common/editor-view-buttons/index.tsx +109 -0
- package/src/client/components/common/shell-update-button/Modal.tsx +163 -0
- package/src/client/components/common/shell-update-button/index.test.tsx +251 -0
- package/src/client/components/common/shell-update-button/index.tsx +125 -0
- package/src/client/components/common/toolbar-row/index.test.tsx +215 -0
- package/src/client/components/common/toolbar-row/index.tsx +260 -0
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +58 -78
- package/src/client/components/layout/desktop-layout/index.tsx +65 -67
- package/src/client/components/layout/desktop-layout/resizer/index.tsx +6 -3
- package/src/client/components/layout/session-sidebar/Footer.tsx +8 -15
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +98 -71
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.test.tsx +137 -0
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.tsx +14 -3
- package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/Footer.tsx +9 -21
- package/src/client/components/settings/Modal.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +9 -0
- package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +167 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +184 -0
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +8 -2
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +16 -8
- package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +9 -4
- package/src/client/components/workspace/chat-timeline/TaskResultContent.tsx +9 -7
- package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
- package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +132 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.test.tsx +319 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +285 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/hashline-patch/index.tsx +34 -29
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AstEdit.tsx +11 -9
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +10 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +25 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.tsx +8 -11
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.test.ts +114 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +7 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/SearchTool.tsx +9 -59
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactBody.tsx +2 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +43 -30
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +49 -32
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ExcerptCode.tsx +8 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/HighlightedCode.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock.tsx +4 -4
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +179 -0
- package/src/client/components/workspace/diff-panel/ThemedMergeDiffView.tsx +24 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +224 -186
- package/src/client/components/workspace/diff-panel/ToolbarSegments.tsx +98 -0
- package/src/client/components/workspace/diff-panel/index.tsx +76 -145
- package/src/client/components/workspace/diff-panel/merge.ts +315 -0
- package/src/client/components/workspace/editor/Body.tsx +28 -7
- package/src/client/components/workspace/editor/CommandPalette.tsx +6 -6
- package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
- package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
- package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
- package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +146 -63
- package/src/client/components/workspace/editor/FilePane.tsx +47 -7
- package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
- package/src/client/components/workspace/editor/FindWidget.tsx +36 -2
- package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
- package/src/client/components/workspace/editor/Notices.tsx +71 -0
- package/src/client/components/workspace/editor/Pane.tsx +118 -0
- package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
- package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
- package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
- package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
- package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
- package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
- package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
- package/src/client/components/workspace/editor/Tabs.tsx +195 -18
- package/src/client/components/workspace/editor/Toolbar.tsx +110 -140
- package/src/client/components/workspace/editor/index.tsx +201 -193
- package/src/client/components/workspace/editor/props.ts +64 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
- package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
- package/src/client/components/workspace/file-explorer/OutlineSection.test.tsx +18 -0
- package/src/client/components/workspace/file-explorer/OutlineSection.tsx +10 -3
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
- package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -48
- package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
- package/src/client/components/workspace/search-panel/Body.tsx +7 -2
- package/src/client/components/workspace/worktree-modal/index.test.tsx +118 -0
- package/src/client/hooks/chat/composer/file-drop.ts +22 -37
- package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
- package/src/client/hooks/chat/composer/pipeline.ts +12 -1
- package/src/client/hooks/chat/omp/reconnect.test.ts +338 -0
- package/src/client/hooks/chat/omp/reconnect.ts +187 -0
- package/src/client/hooks/chat/omp/run-liveness.test.ts +71 -0
- package/src/client/hooks/chat/omp/run-liveness.ts +65 -0
- package/src/client/hooks/chat/omp/session-list.activity.test.ts +114 -0
- package/src/client/hooks/chat/omp/session-list.test-util.ts +164 -0
- package/src/client/hooks/chat/omp/session-list.test.ts +30 -150
- package/src/client/hooks/chat/omp/session-list.tsx +69 -9
- package/src/client/hooks/chat/timeline/generating.ts +19 -2
- package/src/client/hooks/chat/timeline/index.ts +19 -24
- package/src/client/hooks/chat/timeline/lost-run.test.ts +329 -0
- package/src/client/hooks/chat/timeline/lost-run.ts +177 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +205 -0
- package/src/client/hooks/chat/timeline/session-load.test.ts +61 -162
- package/src/client/hooks/chat/timeline/session-load.ts +69 -37
- package/src/client/hooks/chat/timeline/session-switch.test.ts +65 -0
- package/src/client/hooks/chat/timeline/session-switch.ts +63 -0
- package/src/client/hooks/code/deferred-highlight.test.ts +182 -0
- package/src/client/hooks/code/deferred-highlight.ts +129 -0
- package/src/client/hooks/editor/caret-position.test.ts +58 -0
- package/src/client/hooks/editor/caret-position.ts +48 -0
- package/src/client/hooks/editor/file-editor-types.ts +200 -0
- package/src/client/hooks/editor/find-history.test.ts +132 -0
- package/src/client/hooks/editor/find-history.ts +46 -0
- package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
- package/src/client/hooks/editor/find-selection-range.ts +49 -0
- package/src/client/hooks/editor/find-state.ts +14 -1
- package/src/client/hooks/editor/font.test.ts +0 -93
- package/src/client/hooks/editor/indent-settings.test.ts +104 -0
- package/src/client/hooks/editor/indent-settings.ts +88 -0
- package/src/client/hooks/editor/quick-open.test.ts +141 -0
- package/src/client/hooks/editor/quick-open.ts +127 -0
- package/src/client/hooks/editor/save-as.test.ts +156 -0
- package/src/client/hooks/editor/save-as.ts +122 -0
- package/src/client/hooks/editor/save-file.test.ts +179 -0
- package/src/client/hooks/editor/save-file.ts +73 -28
- package/src/client/hooks/editor/theme.test.ts +206 -0
- package/src/client/hooks/editor/theme.ts +82 -0
- package/src/client/hooks/editor/typing-settings.test.ts +73 -0
- package/src/client/hooks/editor/typing-settings.ts +65 -0
- package/src/client/hooks/editor/use-close-guard.ts +98 -0
- package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
- package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +101 -0
- package/src/client/hooks/editor/use-editor-drop.ts +120 -77
- package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
- package/src/client/hooks/editor/use-editor-find.ts +45 -10
- package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
- package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
- package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
- package/src/client/hooks/editor/use-external-change.test.ts +88 -0
- package/src/client/hooks/editor/use-external-change.ts +146 -0
- package/src/client/hooks/editor/use-file-editor.ts +83 -116
- package/src/client/hooks/editor/use-file-read.ts +16 -8
- package/src/client/hooks/editor/use-file-writes.ts +28 -3
- package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
- package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
- package/src/client/hooks/editor/use-outline-view.test.ts +182 -0
- package/src/client/hooks/editor/use-outline-view.ts +94 -7
- package/src/client/hooks/editor/use-scroll-restore.test.ts +55 -2
- package/src/client/hooks/editor/use-scroll-restore.ts +124 -4
- package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
- package/src/client/hooks/editor/use-search-reveal.ts +1 -1
- package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
- package/src/client/hooks/editor/use-split-editor.ts +91 -0
- package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
- package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
- package/src/client/hooks/editor/use-write-conflict.ts +152 -0
- package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
- package/src/client/hooks/editor/wheel-zoom.ts +96 -0
- package/src/client/hooks/ui/drag-presence.test.ts +193 -0
- package/src/client/hooks/ui/drag-presence.ts +108 -0
- package/src/client/hooks/ui/settings-modal.test.ts +115 -0
- package/src/client/hooks/ui/settings-modal.ts +56 -0
- package/src/client/hooks/ui/updates/shell-download.test.ts +2 -0
- package/src/client/hooks/ui/updates/shell-download.ts +55 -14
- package/src/client/hooks/ui/updates/shell-offer.test.ts +26 -0
- package/src/client/hooks/ui/updates/shell-update.test.ts +140 -0
- package/src/client/hooks/ui/updates/shell-update.ts +119 -0
- package/src/client/hooks/workspace/diff-file.ts +29 -10
- package/src/client/hooks/workspace/diff-git-actions.ts +147 -0
- package/src/client/hooks/workspace/editor-view.ts +61 -0
- package/src/client/hooks/workspace/file-listing.ts +36 -24
- package/src/client/hooks/workspace/file-tabs.test.ts +152 -5
- package/src/client/hooks/workspace/file-tabs.ts +70 -11
- package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
- package/src/client/hooks/workspace/navbar-session-actions.ts +72 -0
- package/src/client/hooks/workspace/worktree/index.ts +20 -5
- package/src/client/lib/desktop/bridge.ts +45 -0
- package/src/client/lib/desktop/dropped-paths.ts +83 -0
- package/src/client/lib/editor/tab-menu.test.ts +127 -0
- package/src/client/lib/editor/tab-menu.ts +127 -0
- package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
- package/src/client/lib/editor-dirty-tabs.ts +103 -0
- package/src/client/lib/native/resume.test.ts +66 -0
- package/src/client/lib/native/resume.ts +42 -0
- package/src/client/lib/search-reveal.ts +1 -1
- package/src/client/main.tsx +13 -1
- package/src/client/tailwind.css +75 -8
- package/src/server/lib/auth/guard.test.ts +28 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/bundler/css.test.ts +31 -0
- package/src/server/lib/fs/listing.test.ts +81 -16
- package/src/server/lib/fs/listing.ts +72 -5
- package/src/server/lib/fs/worktree/create.ts +2 -3
- package/src/server/lib/fs/worktree/list.ts +13 -0
- package/src/server/lib/fs/worktree/remove.ts +3 -3
- package/src/server/lib/fs/write-conflict.test.ts +68 -0
- package/src/server/lib/fs/write-conflict.ts +84 -0
- package/src/server/lib/lifecycle/claim-port.test.ts +156 -0
- package/src/server/lib/lifecycle/port-guard.test.ts +20 -164
- package/src/server/lib/lifecycle/port-guard.ts +39 -7
- package/src/server/lib/lifecycle/probe-health.test.ts +166 -0
- package/src/server/lib/lifecycle/probe.test.ts +77 -164
- package/src/server/lib/lifecycle/probe.ts +121 -13
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +112 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +10 -5
- package/src/server/lib/omp/session/sidebar-activity.server.test.ts +162 -0
- package/src/server/lib/omp/session/sidebar-activity.server.ts +70 -0
- package/src/server/lib/omp/session/telemetry/compute.ts +13 -1
- package/src/server/lib/omp/session/telemetry.test.ts +33 -0
- package/src/server/lib/realtime/signals.server.ts +10 -0
- package/src/server/lib/realtime/topics/catalog.server.ts +4 -1
- package/src/server/lib/realtime/topics.server.ts +16 -0
- package/src/server/lib/updates/shell-assets.ts +94 -3
- package/src/server/lib/updates/shell-cache.ts +105 -0
- package/src/server/lib/updates/shell-pages.test.ts +33 -2
- package/src/server/lib/updates/shell-pages.ts +17 -5
- package/src/server/lib/updates/shell-release-desktop.test.ts +166 -0
- package/src/server/lib/updates/shell-release.test.ts +10 -27
- package/src/server/lib/updates/shell-release.ts +107 -111
- package/src/server/routes/fs/action-save-as.test.ts +82 -0
- package/src/server/routes/fs/action.test.ts +82 -0
- package/src/server/routes/fs/action.ts +54 -1
- package/src/server/routes/fs/exists.ts +11 -1
- package/src/server/routes/fs/git-merge.test.ts +11 -1
- package/src/server/routes/fs/read.test.ts +24 -7
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/fs/scope.test.ts +15 -10
- package/src/server/routes/fs/scope.ts +3 -14
- package/src/server/routes/updates/android.ts +6 -1
- package/src/server/routes/updates/desktop.ts +29 -7
- package/src/server/routes/updates/ios.ts +5 -1
- package/src/server/routes/worktrees/list.ts +11 -1
- package/src/server/routes/worktrees/routes.test.ts +17 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +36 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +18 -0
- package/src/shared/lib/chat/timeline/run-signals.test.ts +2 -0
- package/src/shared/lib/code/editor/comment-syntax.test.ts +37 -0
- package/src/shared/lib/code/editor/comment-syntax.ts +55 -0
- package/src/shared/lib/code/editor/find-replace.test.ts +134 -0
- package/src/shared/lib/code/editor/{find.ts → find-replace.ts} +23 -107
- package/src/shared/lib/code/editor/{find.test.ts → find-scan.test.ts} +20 -74
- package/src/shared/lib/code/editor/find-scan.ts +198 -0
- package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
- package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
- package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
- package/src/shared/lib/code/editor/indent-rules.ts +198 -0
- package/src/shared/lib/code/editor/keymap.test.ts +23 -0
- package/src/shared/lib/code/editor/keymap.ts +43 -6
- package/src/shared/lib/code/editor/lines.test.ts +7 -55
- package/src/shared/lib/code/editor/lines.ts +8 -48
- package/src/shared/lib/code/editor/marks.test.ts +4 -5
- package/src/shared/lib/code/editor/marks.ts +13 -25
- package/src/shared/lib/code/editor/palette.test.ts +25 -2
- package/src/shared/lib/code/editor/palette.ts +10 -0
- package/src/shared/lib/code/editor/stream-modes.ts +225 -0
- package/src/shared/lib/code/editor/theme-loader.ts +97 -0
- package/src/shared/lib/code/editor/themes.generated.ts +156 -0
- package/src/shared/lib/code/editor/themes.test.ts +165 -0
- package/src/shared/lib/code/editor/themes.ts +165 -0
- package/src/shared/lib/code/highlight-memo.test.ts +103 -0
- package/src/shared/lib/code/highlight-memo.ts +149 -0
- package/src/shared/lib/code/highlighter-warmup.ts +112 -0
- package/src/shared/lib/code/highlighter.ts +3 -1
- package/src/shared/lib/code/idle.ts +37 -0
- package/src/shared/lib/code/outline/rows.test.ts +96 -0
- package/src/shared/lib/code/outline/rows.ts +94 -0
- package/src/shared/lib/code/syntax-highlight.test.ts +2 -80
- package/src/shared/lib/code/syntax-highlight.ts +2 -3
- package/src/shared/lib/fs/file-kind-classify.test.ts +25 -11
- package/src/shared/lib/fs/file-kind.ts +47 -13
- package/src/shared/lib/fs/file-tree.test.ts +41 -0
- package/src/shared/lib/fs/file-tree.ts +126 -34
- package/src/shared/lib/fs/file-url.test.ts +52 -0
- package/src/shared/lib/fs/file-url.ts +37 -0
- package/src/shared/lib/fs/folder-chain.test.ts +87 -0
- package/src/shared/lib/fs/folder-chain.ts +91 -0
- package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
- package/src/shared/lib/fs/patch-sides.test.ts +114 -0
- package/src/shared/lib/fs/patch-sides.ts +139 -0
- package/src/shared/lib/realtime/connection.test.ts +5 -1
- package/src/shared/lib/realtime/connection.ts +25 -119
- package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
- package/src/shared/lib/realtime/protocol.ts +16 -0
- package/src/shared/lib/realtime/resume.ts +223 -0
- package/src/shared/lib/realtime/state.ts +22 -0
- package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
- package/src/shared/lib/realtime/watchdog.test.ts +99 -0
- package/src/shared/lib/realtime/watchdog.ts +72 -0
- package/src/shared/lib/ui/toolbar-overflow.test.ts +83 -0
- package/src/shared/lib/ui/toolbar-overflow.ts +86 -0
- package/src/shared/lib/updates/shell-arch.ts +54 -0
- package/src/shared/lib/updates/shell-ua.ts +4 -4
- package/src/shared/lib/workspace/editor-view-mode.test.ts +70 -0
- package/src/shared/lib/workspace/editor-view-mode.ts +48 -0
- package/src/shared/lib/workspace/panel-widths.test.ts +30 -0
- package/src/shared/lib/workspace/panel-widths.ts +25 -5
- package/src/shared/lib/workspace/session-state/cache.ts +159 -0
- package/src/shared/lib/workspace/session-state/harness.test-util.ts +55 -0
- package/src/shared/lib/workspace/session-state/merge.ts +100 -0
- package/src/shared/lib/workspace/session-state/store-load.test.ts +206 -0
- package/src/shared/lib/workspace/session-state/store.test.ts +17 -139
- package/src/shared/lib/workspace/session-state/store.ts +92 -130
- package/src/shared/lib/workspace/split-editor.test.ts +104 -0
- package/src/shared/lib/workspace/split-editor.ts +129 -0
- package/src/shared/lib/workspace/workspace-panel-widths.ts +124 -0
- package/src/shared/types/realtime.ts +29 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/test-support/file-explorer-disk.test-util.ts +30 -3
- package/src/test-support/loopback.ts +183 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-gtbpewr7.css +0 -1
- package/src/client/components/common/code-editor/handler.test.ts +0 -274
- package/src/client/components/common/code-editor/handler.ts +0 -175
- package/src/client/components/common/code-editor/index.tsx +0 -314
- package/src/client/components/common/code-surface/measure.ts +0 -148
- package/src/client/components/workspace/chat-timeline/target-picker/index.test.tsx +0 -227
- package/src/client/components/workspace/chat-timeline/target-picker/index.tsx +0 -260
- package/src/client/components/workspace/diff-panel/SplitView.tsx +0 -209
- package/src/client/components/workspace/diff-panel/UnifiedView.tsx +0 -150
- package/src/client/hooks/editor/scroll-container.test.ts +0 -102
- package/src/client/hooks/editor/scroll-container.ts +0 -26
- package/src/client/hooks/editor/use-code-window.ts +0 -100
- package/src/client/hooks/editor/use-editor-history.test.ts +0 -216
- package/src/client/hooks/editor/use-editor-history.ts +0 -134
- package/src/client/hooks/editor/use-occurrences.test.ts +0 -236
- package/src/client/hooks/editor/use-occurrences.ts +0 -98
- package/src/shared/lib/code/editor/commands.test.ts +0 -155
- package/src/shared/lib/code/editor/commands.ts +0 -260
- package/src/shared/lib/code/editor/edits.test.ts +0 -100
- package/src/shared/lib/code/editor/edits.ts +0 -122
- package/src/shared/lib/code/editor/history.test.ts +0 -118
- package/src/shared/lib/code/editor/history.ts +0 -101
- package/src/shared/lib/code/editor/layers.test.ts +0 -77
- package/src/shared/lib/code/editor/layers.ts +0 -67
- package/src/shared/lib/code/editor/line-edits.test.ts +0 -131
- package/src/shared/lib/code/editor/line-edits.ts +0 -159
- package/src/shared/lib/code/editor/occurrences.test.ts +0 -117
- package/src/shared/lib/code/editor/occurrences.ts +0 -111
- package/src/shared/lib/code/editor/reset-css.test.ts +0 -35
- package/src/shared/lib/code/editor/reset-css.ts +0 -32
- package/src/shared/lib/code/editor/text-commands.test.ts +0 -178
- package/src/shared/lib/code/editor/text-commands.ts +0 -154
- package/src/shared/lib/code/lazy-window.test.ts +0 -161
- package/src/shared/lib/code/lazy-window.ts +0 -156
- package/src/shared/lib/code/windowed-highlight.ts +0 -114
- package/src/shared/lib/fs/diff-parser.test.ts +0 -116
- package/src/shared/lib/fs/diff-parser.ts +0 -213
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The indentation setting.
|
|
8
|
+
*
|
|
9
|
+
* Two things are pinned here. The stored value is GUARDED on read — a width outside
|
|
10
|
+
* the offered set is a downgrade or a hand-edited row, and configuring the surface
|
|
11
|
+
* with a value the picker cannot show is a setting the user cannot change back. And
|
|
12
|
+
* a tab-indented unit is `'\t'`, the only spelling `indentUnit` accepts for a tab: the
|
|
13
|
+
* facet is documented as "a string consisting entirely of the same whitespace
|
|
14
|
+
* character", so a mixture would be a facet that silently does nothing.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_EDITOR_INDENT,
|
|
22
|
+
EDITOR_INDENT_CHANGED_EVENT,
|
|
23
|
+
currentEditorIndent,
|
|
24
|
+
indentUnitFor,
|
|
25
|
+
} from '@/client/hooks/editor/indent-settings';
|
|
26
|
+
import { primeKabmoSettings, writeKabmoSettings } from '@/shared/lib/settings/client';
|
|
27
|
+
|
|
28
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Event', 'CustomEvent'] as const;
|
|
29
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
30
|
+
const win = new Window({ url: 'http://localhost' });
|
|
31
|
+
for (const key of DOM_GLOBALS) {
|
|
32
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
33
|
+
native[key] = target[key];
|
|
34
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
afterAll(() => {
|
|
38
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
39
|
+
for (const key of DOM_GLOBALS) target[key] = native[key];
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
// The blob is module-level in the settings client, so every case primes it.
|
|
44
|
+
primeKabmoSettings({});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('currentEditorIndent', () => {
|
|
48
|
+
test('an unset value reads as the shipped default', () => {
|
|
49
|
+
expect(currentEditorIndent()).toEqual(DEFAULT_EDITOR_INDENT);
|
|
50
|
+
expect(DEFAULT_EDITOR_INDENT).toEqual({ width: 2, insertSpaces: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a stored width and spaces flag are adopted', () => {
|
|
54
|
+
primeKabmoSettings({ kabmo_settings: { editorIndentWidth: 4, editorInsertSpaces: true } });
|
|
55
|
+
expect(currentEditorIndent()).toEqual({ width: 4, insertSpaces: true });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a width outside the offered set falls back, so the picker can still show it', () => {
|
|
59
|
+
// A downgrade or a hand-edited row must not configure the surface with a value
|
|
60
|
+
// the picker cannot represent — that would be a setting with no way back.
|
|
61
|
+
primeKabmoSettings({ kabmo_settings: { editorIndentWidth: 3 } });
|
|
62
|
+
expect(currentEditorIndent().width).toBe(2);
|
|
63
|
+
primeKabmoSettings({ kabmo_settings: { editorIndentWidth: '4' } });
|
|
64
|
+
expect(currentEditorIndent().width).toBe(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('a non-boolean spaces flag falls back', () => {
|
|
68
|
+
primeKabmoSettings({ kabmo_settings: { editorInsertSpaces: 'no' } });
|
|
69
|
+
expect(currentEditorIndent().insertSpaces).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a tab-indented setting is preserved', () => {
|
|
73
|
+
primeKabmoSettings({ kabmo_settings: { editorIndentWidth: 4, editorInsertSpaces: false } });
|
|
74
|
+
expect(currentEditorIndent()).toEqual({ width: 4, insertSpaces: false });
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('indentUnitFor', () => {
|
|
79
|
+
test('spaces become a run of that many spaces', () => {
|
|
80
|
+
expect(indentUnitFor({ width: 2, insertSpaces: true })).toBe(' ');
|
|
81
|
+
expect(indentUnitFor({ width: 4, insertSpaces: true })).toBe(' ');
|
|
82
|
+
expect(indentUnitFor({ width: 8, insertSpaces: true })).toBe(' ');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('a tab-indented setting is ONE tab, whatever the width says', () => {
|
|
86
|
+
// `indentUnit` requires a string of one repeated whitespace character, so a
|
|
87
|
+
// width is meaningless here — mixing them would be a facet that does nothing.
|
|
88
|
+
expect(indentUnitFor({ width: 4, insertSpaces: false })).toBe('\t');
|
|
89
|
+
expect(indentUnitFor({ width: 2, insertSpaces: false })).toBe('\t');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('the live event', () => {
|
|
94
|
+
test('the event name is the one the editor subscribes to', () => {
|
|
95
|
+
// Both ends state this string, so a rename on one side would silently stop
|
|
96
|
+
// reaching an open editor.
|
|
97
|
+
expect(EDITOR_INDENT_CHANGED_EVENT).toBe('omp:editor-indent-changed');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a write lands in the blob the readers resolve', () => {
|
|
101
|
+
writeKabmoSettings({ editorIndentWidth: 8 });
|
|
102
|
+
expect(currentEditorIndent().width).toBe(8);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's indentation SETTING: how wide a level is, and what a Tab inserts.
|
|
8
|
+
*
|
|
9
|
+
* The surface has always hardcoded two spaces (`extensions.ts`' `INDENT`), which is
|
|
10
|
+
* wrong for every 4-space repository — and now that the auto-indent rules emit
|
|
11
|
+
* `indentUnit`, the setting propagates through them for free (the service reads
|
|
12
|
+
* `ctx.unit`, which is `getIndentUnit(state)`).
|
|
13
|
+
*
|
|
14
|
+
* ## The setting reaches an open editor through an EVENT
|
|
15
|
+
*
|
|
16
|
+
* Same reason the font and the theme do: `appSettings` is a boot-time prop, so a
|
|
17
|
+
* value read once would not reach the editor already on screen. The picker writes
|
|
18
|
+
* the setting AND announces it; the editor subscribes. The event fires only when the
|
|
19
|
+
* value actually moved, or every unrelated settings toggle would churn every
|
|
20
|
+
* editor's configuration — and a reconfigure re-creates the editor's plugins,
|
|
21
|
+
* including the tokenizer.
|
|
22
|
+
*
|
|
23
|
+
* ## Two facets, because they answer different questions
|
|
24
|
+
*
|
|
25
|
+
* `EditorState.tabSize` is what a literal TAB character counts as. `indentUnit` is
|
|
26
|
+
* what one indentation LEVEL is, and it is what `indentMore`/`indentLess` and the
|
|
27
|
+
* indent service emit. A tab-indented repository wants both to be 1 tab; a
|
|
28
|
+
* space-indented one wants a width and `insertSpaces`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
32
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
33
|
+
|
|
34
|
+
/** Broadcast on every indentation-setting write. Detail is the new value. */
|
|
35
|
+
export const EDITOR_INDENT_CHANGED_EVENT = 'omp:editor-indent-changed';
|
|
36
|
+
|
|
37
|
+
/** The widths the picker offers. */
|
|
38
|
+
export const EDITOR_INDENT_WIDTHS: readonly number[] = [2, 4, 8];
|
|
39
|
+
|
|
40
|
+
/** What the editor's indentation resolves to. */
|
|
41
|
+
export interface EditorIndentSettings {
|
|
42
|
+
/** Columns in one level. */
|
|
43
|
+
width: number;
|
|
44
|
+
/** `false` means a level is one TAB character. */
|
|
45
|
+
insertSpaces: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_EDITOR_INDENT: EditorIndentSettings = { width: 2, insertSpaces: true };
|
|
49
|
+
|
|
50
|
+
/** The stored indentation, falling back to the shipped default. */
|
|
51
|
+
export function currentEditorIndent(): EditorIndentSettings {
|
|
52
|
+
if (typeof window === 'undefined') return DEFAULT_EDITOR_INDENT;
|
|
53
|
+
const width = readKabmoSetting<number>('editorIndentWidth');
|
|
54
|
+
const spaces = readKabmoSetting<boolean>('editorInsertSpaces');
|
|
55
|
+
return {
|
|
56
|
+
// A stored width outside the offered set is a downgrade or a hand-edited row;
|
|
57
|
+
// the surface must not be configured with a value the picker cannot show.
|
|
58
|
+
width: typeof width === 'number' && EDITOR_INDENT_WIDTHS.includes(width) ? width : DEFAULT_EDITOR_INDENT.width,
|
|
59
|
+
insertSpaces: typeof spaces === 'boolean' ? spaces : DEFAULT_EDITOR_INDENT.insertSpaces,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The indentation unit as a string — what `indentUnit.of` takes.
|
|
65
|
+
*
|
|
66
|
+
* `'\t'` for a tab-indented setting, which is the ONE way `indentUnit` accepts a
|
|
67
|
+
* tab: the facet is documented as "a string consisting entirely of the same
|
|
68
|
+
* whitespace character".
|
|
69
|
+
*/
|
|
70
|
+
export function indentUnitFor(settings: EditorIndentSettings): string {
|
|
71
|
+
return settings.insertSpaces ? ' '.repeat(settings.width) : '\t';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The stored indentation, kept in step with writes from the settings modal. */
|
|
75
|
+
export function useEditorIndent(): EditorIndentSettings {
|
|
76
|
+
const [settings, setSettings] = useState<EditorIndentSettings>(currentEditorIndent);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const onChange = (event: Event) => {
|
|
80
|
+
const detail = (event as CustomEvent<EditorIndentSettings>).detail;
|
|
81
|
+
setSettings(detail ?? currentEditorIndent());
|
|
82
|
+
};
|
|
83
|
+
window.addEventListener(EDITOR_INDENT_CHANGED_EVENT, onChange);
|
|
84
|
+
return () => window.removeEventListener(EDITOR_INDENT_CHANGED_EVENT, onChange);
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
return settings;
|
|
88
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The quick-open ranking, and the index reader.
|
|
8
|
+
*
|
|
9
|
+
* The ranking is the feature: a picker that lists every file whose path contains the
|
|
10
|
+
* query is not a picker, it is a filtered tree. The cases below are the ones that
|
|
11
|
+
* distinguish a useful order from an alphabetical one.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
fetchQuickOpenIndex,
|
|
18
|
+
isSubsequence,
|
|
19
|
+
quickOpenEntry,
|
|
20
|
+
rankQuickOpen,
|
|
21
|
+
scoreQuickOpen,
|
|
22
|
+
type QuickOpenEntry,
|
|
23
|
+
} from '@/client/hooks/editor/quick-open';
|
|
24
|
+
|
|
25
|
+
const nativeFetch = Bun.fetch;
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
globalThis.fetch = nativeFetch;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const ENTRIES: QuickOpenEntry[] = [
|
|
32
|
+
'src/client/hooks/editor/use-file-tabs.ts',
|
|
33
|
+
'src/client/components/workspace/editor/Tabs.tsx',
|
|
34
|
+
'src/shared/lib/code/editor/keymap.ts',
|
|
35
|
+
'src/client/hooks/editor/quick-open.ts',
|
|
36
|
+
'README.md',
|
|
37
|
+
].map(quickOpenEntry);
|
|
38
|
+
|
|
39
|
+
describe('quickOpenEntry', () => {
|
|
40
|
+
test('splits the path into the name and the directory a row prints', () => {
|
|
41
|
+
expect(quickOpenEntry('src/a/b.ts')).toEqual({ path: 'src/a/b.ts', name: 'b.ts', directory: 'src/a' });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('a root-level file has no directory', () => {
|
|
45
|
+
expect(quickOpenEntry('README.md')).toEqual({ path: 'README.md', name: 'README.md', directory: '' });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('scoreQuickOpen', () => {
|
|
50
|
+
test('an exact basename beats a prefix, which beats a substring', () => {
|
|
51
|
+
const exact = scoreQuickOpen(quickOpenEntry('a/quick-open.ts'), 'quick-open.ts')!;
|
|
52
|
+
const prefix = scoreQuickOpen(quickOpenEntry('a/quick-open.tsx'), 'quick-open')!;
|
|
53
|
+
const inside = scoreQuickOpen(quickOpenEntry('a/xquick-open.ts'), 'quick-open')!;
|
|
54
|
+
expect(exact).toBeGreaterThan(prefix);
|
|
55
|
+
expect(prefix).toBeGreaterThan(inside);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a basename hit always beats a directory-only hit', () => {
|
|
59
|
+
// Typing a file's name must find the FILE, not every sibling in a folder named
|
|
60
|
+
// after it — which is the failure a plain `path.includes` produces.
|
|
61
|
+
const nameHit = scoreQuickOpen(quickOpenEntry('deep/nested/editor.ts'), 'editor')!;
|
|
62
|
+
const dirHit = scoreQuickOpen(quickOpenEntry('editor/other.ts'), 'editor')!;
|
|
63
|
+
expect(nameHit).toBeGreaterThan(dirHit);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('shorter paths win ties, because the file you want is usually nearer the root', () => {
|
|
67
|
+
const near = scoreQuickOpen(quickOpenEntry('a/keymap.ts'), 'keymap')!;
|
|
68
|
+
const far = scoreQuickOpen(quickOpenEntry('a/b/c/d/e/keymap.ts'), 'keymap')!;
|
|
69
|
+
expect(near).toBeGreaterThan(far);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('an empty query matches everything with the same score', () => {
|
|
73
|
+
expect(scoreQuickOpen(quickOpenEntry('a.ts'), '')).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('a non-match is null, and a subsequence is the last resort', () => {
|
|
77
|
+
expect(scoreQuickOpen(quickOpenEntry('src/a.ts'), 'zzz')).toBeNull();
|
|
78
|
+
// `uft` is a subsequence of `use-file-tabs`, and it must still be found — that
|
|
79
|
+
// is how people type an acronym for a long name.
|
|
80
|
+
expect(scoreQuickOpen(quickOpenEntry('a/use-file-tabs.ts'), 'uft')).not.toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('isSubsequence', () => {
|
|
85
|
+
test('matches characters in order, not contiguously', () => {
|
|
86
|
+
expect(isSubsequence('uft', 'use-file-tabs')).toBe(true);
|
|
87
|
+
expect(isSubsequence('tabs', 'use-file-tabs')).toBe(true);
|
|
88
|
+
expect(isSubsequence('ftu', 'use-file-tabs')).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('an empty needle matches', () => {
|
|
92
|
+
expect(isSubsequence('', 'anything')).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('rankQuickOpen', () => {
|
|
97
|
+
test('returns the best matches first and respects the limit', () => {
|
|
98
|
+
const ranked = rankQuickOpen(ENTRIES, 'tabs');
|
|
99
|
+
expect(ranked[0].name).toBe('Tabs.tsx');
|
|
100
|
+
expect(ranked.map((entry) => entry.path)).toContain('src/client/hooks/editor/use-file-tabs.ts');
|
|
101
|
+
expect(rankQuickOpen(ENTRIES, 'tabs', 1)).toHaveLength(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('an empty query lists the index in path order', () => {
|
|
105
|
+
const ranked = rankQuickOpen(ENTRIES, '');
|
|
106
|
+
expect(ranked).toHaveLength(ENTRIES.length);
|
|
107
|
+
expect(ranked.map((entry) => entry.path)).toEqual([...ranked.map((entry) => entry.path)].sort());
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('a query that matches nothing answers an empty list', () => {
|
|
111
|
+
expect(rankQuickOpen(ENTRIES, 'zzzz')).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('fetchQuickOpenIndex', () => {
|
|
116
|
+
test('reads the flat index and shapes every row', async () => {
|
|
117
|
+
globalThis.fetch = (async () => ({
|
|
118
|
+
ok: true,
|
|
119
|
+
json: async () => ({ files: [{ path: 'src/a.ts' }, { path: 'b/c.ts' }] }),
|
|
120
|
+
})) as unknown as typeof fetch;
|
|
121
|
+
expect(await fetchQuickOpenIndex('/repo')).toEqual([
|
|
122
|
+
{ path: 'src/a.ts', name: 'a.ts', directory: 'src' },
|
|
123
|
+
{ path: 'b/c.ts', name: 'c.ts', directory: 'b' },
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a refusal or a malformed row answers an empty list, never a throw', async () => {
|
|
128
|
+
globalThis.fetch = (async () => ({ ok: false, json: async () => ({}) })) as unknown as typeof fetch;
|
|
129
|
+
expect(await fetchQuickOpenIndex('/repo')).toEqual([]);
|
|
130
|
+
|
|
131
|
+
globalThis.fetch = (async () => ({
|
|
132
|
+
ok: true,
|
|
133
|
+
json: async () => ({ files: [{ path: 42 }, null, { path: 'ok.ts' }] }),
|
|
134
|
+
})) as unknown as typeof fetch;
|
|
135
|
+
// A row without a string path is dropped rather than rendered as `undefined`.
|
|
136
|
+
expect((await fetchQuickOpenIndex('/repo')).map((entry) => entry.path)).toEqual(['ok.ts']);
|
|
137
|
+
|
|
138
|
+
globalThis.fetch = (async () => { throw new Error('offline'); }) as unknown as typeof fetch;
|
|
139
|
+
expect(await fetchQuickOpenIndex('/repo')).toEqual([]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Quick open: reach a file by NAME, without expanding the tree.
|
|
8
|
+
*
|
|
9
|
+
* `⌘P` is the fastest route to a file the reader has not opened — the tree needs
|
|
10
|
+
* every folder on the path expanded, and a search panel needs a query about the
|
|
11
|
+
* file's CONTENT. The index is `/api/fs/list`, which already exists for the
|
|
12
|
+
* composer's `@` picker: a flat walk, capped at 3 000 files, skipping the
|
|
13
|
+
* dependency trees (`node_modules`, `dist`, …). That budget is exactly what a picker
|
|
14
|
+
* wants, so this reuses the route rather than growing a second one.
|
|
15
|
+
*
|
|
16
|
+
* ## Matching is per-SEGMENT, not a substring of the whole path
|
|
17
|
+
*
|
|
18
|
+
* `useTabs` finds `use-file-tabs.ts`; so does `uft`; and so does `tabs`. What a
|
|
19
|
+
* user types is usually the tail of a path, and a plain `path.includes(query)` ranks
|
|
20
|
+
* `src/client/hooks/editor/use-file-tabs.ts` no better than a file whose directory
|
|
21
|
+
* happens to contain the same letters. Scoring prefers, in order: an exact basename
|
|
22
|
+
* match, a basename prefix, a basename substring, then the same three against the
|
|
23
|
+
* whole path — and shorter paths win ties, because the file you want is usually the
|
|
24
|
+
* one closest to the root of what you typed.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** One file the picker can offer. */
|
|
28
|
+
export interface QuickOpenEntry {
|
|
29
|
+
/** Workspace-relative path — what `handleOpenFile` takes. */
|
|
30
|
+
path: string;
|
|
31
|
+
/** The last segment, for the row's title. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Everything before the last segment, for the row's subtitle. */
|
|
34
|
+
directory: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The shape `/api/fs/list` answers. */
|
|
38
|
+
interface FileListResponse {
|
|
39
|
+
files?: unknown;
|
|
40
|
+
truncated?: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A row from `/api/fs/list`, narrowed rather than asserted. */
|
|
44
|
+
function isFileRow(value: unknown): value is { path: string } {
|
|
45
|
+
return typeof value === 'object' && value !== null && 'path' in value && typeof value.path === 'string';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Split a workspace-relative path into the two parts a row prints. */
|
|
49
|
+
export function quickOpenEntry(path: string): QuickOpenEntry {
|
|
50
|
+
const cut = path.lastIndexOf('/');
|
|
51
|
+
return cut === -1
|
|
52
|
+
? { path, name: path, directory: '' }
|
|
53
|
+
: { path, name: path.slice(cut + 1), directory: path.slice(0, cut) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A score for one entry against a query, or `null` when it does not match.
|
|
58
|
+
*
|
|
59
|
+
* Higher is better. The tiers are ordered so that a basename hit ALWAYS beats a
|
|
60
|
+
* directory-only hit, which is what makes typing a file's name find the file rather
|
|
61
|
+
* than every sibling in a folder named after it.
|
|
62
|
+
*/
|
|
63
|
+
export function scoreQuickOpen(entry: QuickOpenEntry, query: string): number | null {
|
|
64
|
+
const needle = query.trim().toLowerCase();
|
|
65
|
+
if (!needle) return 0;
|
|
66
|
+
const name = entry.name.toLowerCase();
|
|
67
|
+
const path = entry.path.toLowerCase();
|
|
68
|
+
|
|
69
|
+
const tier = (haystack: string, weight: number): number | null => {
|
|
70
|
+
if (haystack === needle) return weight + 300;
|
|
71
|
+
if (haystack.startsWith(needle)) return weight + 200;
|
|
72
|
+
if (haystack.includes(needle)) return weight + 100;
|
|
73
|
+
return null;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const nameScore = tier(name, 1000);
|
|
77
|
+
if (nameScore !== null) return nameScore - entry.path.length / 100;
|
|
78
|
+
const pathScore = tier(path, 0);
|
|
79
|
+
if (pathScore !== null) return pathScore - entry.path.length / 100;
|
|
80
|
+
// A subsequence match (`uft` → use-file-tabs) is the last resort, and only on the
|
|
81
|
+
// basename: a subsequence over a whole path matches almost everything.
|
|
82
|
+
if (isSubsequence(needle, name)) return 50 - entry.path.length / 100;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Whether every character of `needle` appears in `haystack`, in order. */
|
|
87
|
+
export function isSubsequence(needle: string, haystack: string): boolean {
|
|
88
|
+
let index = 0;
|
|
89
|
+
for (const character of haystack) {
|
|
90
|
+
if (character === needle[index]) index += 1;
|
|
91
|
+
if (index === needle.length) return true;
|
|
92
|
+
}
|
|
93
|
+
return needle.length === 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The ranked matches for `query`, best first, capped at `limit`. */
|
|
97
|
+
export function rankQuickOpen(
|
|
98
|
+
entries: readonly QuickOpenEntry[],
|
|
99
|
+
query: string,
|
|
100
|
+
limit = 50,
|
|
101
|
+
): QuickOpenEntry[] {
|
|
102
|
+
const scored: Array<{ entry: QuickOpenEntry; score: number }> = [];
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const score = scoreQuickOpen(entry, query);
|
|
105
|
+
if (score !== null) scored.push({ entry, score });
|
|
106
|
+
}
|
|
107
|
+
scored.sort((a, b) => b.score - a.score || a.entry.path.localeCompare(b.entry.path));
|
|
108
|
+
return scored.slice(0, limit).map((row) => row.entry);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Read the index for one scope. A refusal answers an empty list, never a throw. */
|
|
112
|
+
export async function fetchQuickOpenIndex(root?: string | null, repo?: string | null): Promise<QuickOpenEntry[]> {
|
|
113
|
+
const params = new URLSearchParams();
|
|
114
|
+
if (root) params.set('root', root);
|
|
115
|
+
if (repo && repo !== '.') params.set('repo', repo);
|
|
116
|
+
try {
|
|
117
|
+
const res = await fetch(`/api/fs/list?${params.toString()}`);
|
|
118
|
+
const data = (await res.json().catch(() => null)) as FileListResponse | null;
|
|
119
|
+
if (!res.ok || !data || !Array.isArray(data.files)) return [];
|
|
120
|
+
return data.files.flatMap((row) => {
|
|
121
|
+
if (!isFileRow(row)) return [];
|
|
122
|
+
return row.path ? [quickOpenEntry(row.path)] : [];
|
|
123
|
+
});
|
|
124
|
+
} catch {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Save As: the name it suggests, the name it accepts, and what each answer means.
|
|
8
|
+
*
|
|
9
|
+
* The suggestion keeps the EXTENSION: a destination that lost it would be saved as a file
|
|
10
|
+
* the surface no longer recognises, so the language would change under the user. A `409`
|
|
11
|
+
* is a REFUSAL rather than a failure — the user picked a name that is taken — and the
|
|
12
|
+
* dialog has to be able to say so without closing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { Window } from 'happy-dom';
|
|
17
|
+
|
|
18
|
+
import { isSingleSegmentName, saveAsSuggestedName, saveFileAs } from '@/client/hooks/editor/save-as';
|
|
19
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The DOM globals come from the shared helper, and the `File`/`Blob` it installs are
|
|
23
|
+
* RESTORED at the end.
|
|
24
|
+
*
|
|
25
|
+
* A local save-and-restore loop is what broke a suite two directories away: this file
|
|
26
|
+
* swapped `File` and `Blob` for happy-dom's and never put them back, so a later file's
|
|
27
|
+
* `carriesBytes` read a happy-dom `File` whose `slice().arrayBuffer()` answered empty and
|
|
28
|
+
* reported that a real file held no bytes — a failure in a suite this file does not name.
|
|
29
|
+
* `installDomGlobals`/`restoreDomGlobals` capture the runner's own values at their first
|
|
30
|
+
* install and put them back, which is the only ordering-safe way to do it in a directory
|
|
31
|
+
* run (Bun imports every file before any test executes).
|
|
32
|
+
*/
|
|
33
|
+
const nativeFetch = Bun.fetch;
|
|
34
|
+
|
|
35
|
+
beforeAll(() => {
|
|
36
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
restoreDomGlobals();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
globalThis.fetch = nativeFetch;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function stub(answer: { ok: boolean; status?: number; body?: unknown }): FormData[] {
|
|
48
|
+
const forms: FormData[] = [];
|
|
49
|
+
globalThis.fetch = (async (_input: unknown, init?: RequestInit) => {
|
|
50
|
+
forms.push(init?.body as FormData);
|
|
51
|
+
return {
|
|
52
|
+
ok: answer.ok,
|
|
53
|
+
status: answer.status ?? (answer.ok ? 200 : 500),
|
|
54
|
+
json: async () => answer.body ?? null,
|
|
55
|
+
};
|
|
56
|
+
}) as unknown as typeof fetch;
|
|
57
|
+
return forms;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('saveAsSuggestedName', () => {
|
|
61
|
+
test('keeps the extension', () => {
|
|
62
|
+
expect(saveAsSuggestedName('notes.ts')).toBe('notes copy.ts');
|
|
63
|
+
expect(saveAsSuggestedName('README.md')).toBe('README copy.md');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('a name with several dots keeps only the last as the extension', () => {
|
|
67
|
+
expect(saveAsSuggestedName('a.test.ts')).toBe('a.test copy.ts');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a name with no extension gains none', () => {
|
|
71
|
+
expect(saveAsSuggestedName('Makefile')).toBe('Makefile copy');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a dotfile is not treated as an extension', () => {
|
|
75
|
+
// `.gitignore` has no stem to keep, so appending is the only sensible answer.
|
|
76
|
+
expect(saveAsSuggestedName('.gitignore')).toBe('.gitignore copy');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('isSingleSegmentName', () => {
|
|
81
|
+
test('accepts a plain name', () => {
|
|
82
|
+
expect(isSingleSegmentName('notes.ts')).toBe(true);
|
|
83
|
+
expect(isSingleSegmentName(' notes.ts ')).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('refuses a separator, an empty name, and the two dot segments', () => {
|
|
87
|
+
expect(isSingleSegmentName('a/b.ts')).toBe(false);
|
|
88
|
+
expect(isSingleSegmentName('a\\b.ts')).toBe(false);
|
|
89
|
+
expect(isSingleSegmentName('')).toBe(false);
|
|
90
|
+
expect(isSingleSegmentName(' ')).toBe(false);
|
|
91
|
+
expect(isSingleSegmentName('.')).toBe(false);
|
|
92
|
+
expect(isSingleSegmentName('..')).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('saveFileAs', () => {
|
|
97
|
+
test('posts the directory, the name and the buffer, and answers the new path', async () => {
|
|
98
|
+
const forms = stub({ ok: true, body: { success: true, path: 'src/notes copy.ts' } });
|
|
99
|
+
const outcome = await saveFileAs({
|
|
100
|
+
parent: 'src',
|
|
101
|
+
name: 'notes copy.ts',
|
|
102
|
+
content: 'const a = 1;\n',
|
|
103
|
+
eol: 'lf',
|
|
104
|
+
root: '/ws',
|
|
105
|
+
});
|
|
106
|
+
expect(outcome).toEqual({ status: 'written', path: 'src/notes copy.ts' });
|
|
107
|
+
expect(forms[0].get('actionType')).toBe('saveAs');
|
|
108
|
+
expect(forms[0].get('path')).toBe('src');
|
|
109
|
+
expect(forms[0].get('name')).toBe('notes copy.ts');
|
|
110
|
+
expect(forms[0].get('content')).toBe('const a = 1;\n');
|
|
111
|
+
expect(forms[0].get('eol')).toBe('lf');
|
|
112
|
+
expect(forms[0].get('root')).toBe('/ws');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('no baseMtime is sent — a new file has nothing to compare against', async () => {
|
|
116
|
+
const forms = stub({ ok: true, body: { success: true, path: 'a.ts' } });
|
|
117
|
+
await saveFileAs({ parent: '', name: 'a.ts', content: 'x', eol: 'lf' });
|
|
118
|
+
expect(forms[0].get('baseMtime')).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('an empty name is refused before the request', async () => {
|
|
122
|
+
const forms = stub({ ok: true, body: { success: true, path: 'x' } });
|
|
123
|
+
expect(await saveFileAs({ parent: '', name: ' ', content: 'x', eol: 'lf' })).toEqual({
|
|
124
|
+
status: 'failed',
|
|
125
|
+
reason: 'Enter a file name.',
|
|
126
|
+
});
|
|
127
|
+
expect(forms).toHaveLength(0);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('a 409 is an EXISTS refusal carrying the server sentence, not a failure', async () => {
|
|
131
|
+
stub({ ok: false, status: 409, body: { error: 'notes.ts already exists' } });
|
|
132
|
+
expect(await saveFileAs({ parent: 'src', name: 'notes.ts', content: 'x', eol: 'lf' })).toEqual({
|
|
133
|
+
status: 'exists',
|
|
134
|
+
reason: 'notes.ts already exists',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('a 409 with no body still names the name it collided with', async () => {
|
|
139
|
+
stub({ ok: false, status: 409, body: null });
|
|
140
|
+
const outcome = await saveFileAs({ parent: '', name: 'a.ts', content: 'x', eol: 'lf' });
|
|
141
|
+
expect(outcome.status).toBe('exists');
|
|
142
|
+
expect(outcome.status === 'exists' && outcome.reason).toContain('a.ts');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('any other refusal is a failure with the server reason', async () => {
|
|
146
|
+
stub({ ok: false, status: 403, body: { error: 'Invalid path' } });
|
|
147
|
+
expect(await saveFileAs({ parent: '../x', name: 'a.ts', content: 'x', eol: 'lf' })).toEqual({
|
|
148
|
+
status: 'failed',
|
|
149
|
+
reason: 'Invalid path',
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
globalThis.fetch = (async () => { throw new Error('offline'); }) as unknown as typeof fetch;
|
|
153
|
+
const dropped = await saveFileAs({ parent: '', name: 'a.ts', content: 'x', eol: 'lf' });
|
|
154
|
+
expect(dropped.status).toBe('failed');
|
|
155
|
+
});
|
|
156
|
+
});
|