@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,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The diff panel's git writes, and the conflict-marker read behind its banner.
|
|
8
|
+
*
|
|
9
|
+
* Split out of the panel because these are the only parts of it that talk to
|
|
10
|
+
* the server: the panel used to fire and forget (`fetcher.submit` + an
|
|
11
|
+
* optimistic flip + a 300ms timer), which made a rejected action
|
|
12
|
+
* indistinguishable from a successful one — the badge flipped and the diff
|
|
13
|
+
* silently stayed put. Every write here AWAITS its answer and reports the
|
|
14
|
+
* server's own reason.
|
|
15
|
+
*
|
|
16
|
+
* `revert` is the server's name for "restore this file from the index", and it
|
|
17
|
+
* is the one that handles the untracked case (there the file is removed).
|
|
18
|
+
* Sending `discard`, which no handler matched, returned `{success: true}` for
|
|
19
|
+
* doing nothing at all.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
23
|
+
import type { ConflictMarkers } from '@/shared/lib/fs/git-unmerged';
|
|
24
|
+
|
|
25
|
+
export interface DiffGitActions {
|
|
26
|
+
/** A write is in flight; the toolbar locks its actions. */
|
|
27
|
+
isBusy: boolean;
|
|
28
|
+
/** The server's refusal, or a transport failure, as a sentence. */
|
|
29
|
+
error: string | null;
|
|
30
|
+
/** The conflict sides' labels from the file's own markers (`{}` when none). */
|
|
31
|
+
markers: ConflictMarkers;
|
|
32
|
+
dismissError: () => void;
|
|
33
|
+
/** Stage or unstage this path, then re-read the diff at the new side. */
|
|
34
|
+
stageUnstage: () => Promise<void>;
|
|
35
|
+
/** Take one side of a conflict (or only stage a resolved file with `''`). */
|
|
36
|
+
resolve: (side: 'ours' | 'theirs' | '') => Promise<void>;
|
|
37
|
+
/** Restore this file from the index — the untracked case removes it. */
|
|
38
|
+
revert: () => Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DiffGitActionsArgs {
|
|
42
|
+
filePath: string;
|
|
43
|
+
repo: string;
|
|
44
|
+
root?: string;
|
|
45
|
+
/** The status the panel currently believes (`UU`, `M`, …). */
|
|
46
|
+
status: string;
|
|
47
|
+
staged: boolean;
|
|
48
|
+
/** The panel is showing a conflicted file, so its marker labels are read. */
|
|
49
|
+
conflicted: boolean;
|
|
50
|
+
/** Adopt a state change the server confirmed. */
|
|
51
|
+
adoptState: (patch: { staged: boolean }) => void;
|
|
52
|
+
/** Re-read the diff, optionally at the other side of the index. */
|
|
53
|
+
fetchDiff: (options?: { staged: boolean }) => Promise<void>;
|
|
54
|
+
/** Something on disk changed, so the workspace panels should refresh. */
|
|
55
|
+
onFileSaved?: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function useDiffGitActions(args: DiffGitActionsArgs): DiffGitActions {
|
|
59
|
+
const { filePath, repo, root, staged, conflicted, adoptState, fetchDiff, onFileSaved } = args;
|
|
60
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
61
|
+
const [error, setError] = useState<string | null>(null);
|
|
62
|
+
const [markers, setMarkers] = useState<ConflictMarkers>({});
|
|
63
|
+
|
|
64
|
+
const run = useCallback(
|
|
65
|
+
async (fields: Record<string, string>): Promise<boolean> => {
|
|
66
|
+
const fd = new FormData();
|
|
67
|
+
for (const [key, value] of Object.entries(fields)) fd.set(key, value);
|
|
68
|
+
fd.set('repo', repo || '.');
|
|
69
|
+
if (root) fd.set('root', root);
|
|
70
|
+
try {
|
|
71
|
+
const res = await fetch('/api/fs/git', { method: 'POST', body: fd });
|
|
72
|
+
const data = (await res.json().catch(() => null)) as { success?: boolean; error?: string } | null;
|
|
73
|
+
if (!res.ok || !data?.success) {
|
|
74
|
+
setError(data?.error || `Request failed (HTTP ${res.status})`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
setError(null);
|
|
78
|
+
return true;
|
|
79
|
+
} catch (err: unknown) {
|
|
80
|
+
setError(err instanceof Error ? err.message : 'Request failed');
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
[repo, root],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/** One write, its busy flag, and the refresh every action ends with. */
|
|
88
|
+
const write = useCallback(
|
|
89
|
+
async (fields: Record<string, string>, after: () => Promise<void>): Promise<void> => {
|
|
90
|
+
setIsBusy(true);
|
|
91
|
+
try {
|
|
92
|
+
if (!(await run(fields))) return;
|
|
93
|
+
await after();
|
|
94
|
+
} finally {
|
|
95
|
+
setIsBusy(false);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[run],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// The marker labels are fetched when the file turns out to be conflicted, and
|
|
102
|
+
// re-fetched when the path changes. Keyed on the path and the status so a
|
|
103
|
+
// resolve (which changes the status away from `UU`) clears the banner.
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!conflicted) {
|
|
106
|
+
setMarkers({});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let cancelled = false;
|
|
110
|
+
const params = new URLSearchParams({ conflictMarkers: '1', file: filePath, repo: repo || '.' });
|
|
111
|
+
if (root) params.set('root', root);
|
|
112
|
+
void fetch(`/api/fs/git?${params.toString()}`)
|
|
113
|
+
.then((res) => res.json() as Promise<{ markers?: ConflictMarkers }>)
|
|
114
|
+
.then((body) => {
|
|
115
|
+
if (!cancelled) setMarkers(body.markers ?? {});
|
|
116
|
+
})
|
|
117
|
+
.catch(() => {
|
|
118
|
+
if (!cancelled) setMarkers({});
|
|
119
|
+
});
|
|
120
|
+
return () => {
|
|
121
|
+
cancelled = true;
|
|
122
|
+
};
|
|
123
|
+
}, [conflicted, filePath, repo, root]);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
isBusy,
|
|
127
|
+
error,
|
|
128
|
+
markers,
|
|
129
|
+
dismissError: () => setError(null),
|
|
130
|
+
stageUnstage: () =>
|
|
131
|
+
write({ actionType: staged ? 'unstage' : 'stage', file: filePath }, async () => {
|
|
132
|
+
adoptState({ staged: !staged });
|
|
133
|
+
onFileSaved?.();
|
|
134
|
+
await fetchDiff({ staged: !staged });
|
|
135
|
+
}),
|
|
136
|
+
resolve: (side) =>
|
|
137
|
+
write({ actionType: 'resolve_conflict', file: filePath, ...(side ? { side } : {}) }, async () => {
|
|
138
|
+
onFileSaved?.();
|
|
139
|
+
await fetchDiff();
|
|
140
|
+
}),
|
|
141
|
+
revert: () =>
|
|
142
|
+
write({ actionType: 'revert', file: filePath }, async () => {
|
|
143
|
+
onFileSaved?.();
|
|
144
|
+
await fetchDiff();
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The desktop editor column's WIDTH mode, read and written through the session
|
|
8
|
+
* slot every surface follows.
|
|
9
|
+
*
|
|
10
|
+
* Two surfaces read it — the layout (which collapses the columns) and both
|
|
11
|
+
* toolbars (which draw the mode buttons) — so it goes through
|
|
12
|
+
* `useSharedSessionState`: `useSessionState` hands each caller a private copy,
|
|
13
|
+
* and a copy would leave the diff toolbar showing `normal` after the editor
|
|
14
|
+
* toolbar entered compact view. A private copy is right for state one component
|
|
15
|
+
* owns; this one is a decision two toolbars and the layout share.
|
|
16
|
+
*
|
|
17
|
+
* The stored mode only means anything while the editor column is OPEN. With it
|
|
18
|
+
* closed the chat is the only thing on screen, and honouring the mode would
|
|
19
|
+
* leave a blank workspace; the effective mode is therefore DERIVED rather than
|
|
20
|
+
* written back, so closing and reopening the column returns the user to the
|
|
21
|
+
* width they chose.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useSharedSessionState } from '@/client/hooks/workspace/session-state';
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_EDITOR_VIEW_MODE,
|
|
27
|
+
EDITOR_VIEW_MODE_KEY,
|
|
28
|
+
editorViewHides,
|
|
29
|
+
isEditorViewMode,
|
|
30
|
+
type EditorViewMode,
|
|
31
|
+
} from '@/shared/lib/workspace/editor-view-mode';
|
|
32
|
+
|
|
33
|
+
export interface EditorViewLayout {
|
|
34
|
+
/** The mode in force, after the editor-open guard. */
|
|
35
|
+
mode: EditorViewMode;
|
|
36
|
+
/** The chat column is collapsed and the editor takes its width. */
|
|
37
|
+
chatHidden: boolean;
|
|
38
|
+
/** The session sidebar is collapsed as well (full view only). */
|
|
39
|
+
sidebarHidden: boolean;
|
|
40
|
+
/** Enter a mode, or return to `normal` — see `toggledEditorViewMode`. */
|
|
41
|
+
setMode: (next: EditorViewMode) => void;
|
|
42
|
+
/** Leave `full` for `compact`: the chat stays hidden, the sidebar returns. */
|
|
43
|
+
revealSidebar: () => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useEditorViewLayout(editorOpen: boolean): EditorViewLayout {
|
|
47
|
+
const [stored, setMode] = useSharedSessionState<EditorViewMode>(EDITOR_VIEW_MODE_KEY, DEFAULT_EDITOR_VIEW_MODE);
|
|
48
|
+
const mode: EditorViewMode = editorOpen && isEditorViewMode(stored) ? stored : DEFAULT_EDITOR_VIEW_MODE;
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
mode,
|
|
52
|
+
chatHidden: editorViewHides(mode, 'chat'),
|
|
53
|
+
sidebarHidden: editorViewHides(mode, 'sidebar'),
|
|
54
|
+
setMode,
|
|
55
|
+
// Only `full` hides the sidebar, so only `full` has anything to step back
|
|
56
|
+
// from. A caller that asks for the sidebar (the navbar's own toggle) must be
|
|
57
|
+
// able to call this unconditionally: turning `normal` into `compact` would
|
|
58
|
+
// hide the chat for a user who only wanted their sidebar back.
|
|
59
|
+
revealSidebar: () => setMode((previous) => (previous === 'full' ? 'compact' : previous)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import { useRef, useState } from 'preact/hooks';
|
|
27
27
|
import type { FsNode } from '@/shared/types';
|
|
28
|
-
import { placeEntry, rehydrateTree,
|
|
28
|
+
import { placeEntry, rehydrateTree, takeEntry, rekeyCache } from '@/shared/lib/fs/file-tree';
|
|
29
29
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -92,14 +92,21 @@ export interface FileListing {
|
|
|
92
92
|
* A create answers with the entry's path, so the tree already knows the whole
|
|
93
93
|
* result; re-reading the root plus every open folder to learn it back would
|
|
94
94
|
* be one request per open folder for an answer the caller holds.
|
|
95
|
+
*
|
|
96
|
+
* Returns the tree as committed, because the caller's next step is to reveal
|
|
97
|
+
* the row — and a reveal has to expand the rows that are DRAWN, not the path's
|
|
98
|
+
* own segments: a single-child folder is one collapsed row
|
|
99
|
+
* (`foldSingleChildFolders`), so `lib` and `lib/deep` may be a single node.
|
|
100
|
+
* `null` means the entry could not be placed — a folder whose contents are
|
|
101
|
+
* not loaded — and the caller has to re-read.
|
|
95
102
|
*/
|
|
96
|
-
insertEntry: (entry: { path: string; kind: 'file' | 'folder' }) =>
|
|
103
|
+
insertEntry: (entry: { path: string; kind: 'file' | 'folder' }) => FsNode[] | null;
|
|
97
104
|
/**
|
|
98
|
-
* Move a row the panel just renamed, without a reload.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
105
|
+
* Move a row the panel just renamed, without a reload.
|
|
106
|
+
*
|
|
107
|
+
* Returns the tree as committed, or `null` when the moved entry is not in it.
|
|
101
108
|
*/
|
|
102
|
-
moveEntry: (fromPath: string, toPath: string) =>
|
|
109
|
+
moveEntry: (fromPath: string, toPath: string) => FsNode[] | null;
|
|
103
110
|
/** Forget the root listing and every cached child (a repo switch). */
|
|
104
111
|
reset: () => void;
|
|
105
112
|
}
|
|
@@ -145,15 +152,19 @@ export function useFileListing({
|
|
|
145
152
|
return `/api/fs/dir?${params.toString()}`;
|
|
146
153
|
};
|
|
147
154
|
|
|
148
|
-
/**
|
|
149
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Render the tree from the current root listing plus the children cache.
|
|
157
|
+
*
|
|
158
|
+
* Returns what it rendered, so a caller that must act on the RESULT (a reveal
|
|
159
|
+
* after a create, an expansion rekey after a rename) reads the rows that are
|
|
160
|
+
* drawn instead of re-deriving them.
|
|
161
|
+
*/
|
|
162
|
+
const commit = (requested: string, root: string): FsNode[] => {
|
|
150
163
|
listedScopeRef.current = requested;
|
|
151
164
|
listedRootRef.current = root;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
root,
|
|
156
|
-
});
|
|
165
|
+
const files = rehydrateTree(rootFilesRef.current, childrenCacheRef.current);
|
|
166
|
+
setState({ scope: requested, files, root });
|
|
167
|
+
return files;
|
|
157
168
|
};
|
|
158
169
|
|
|
159
170
|
/**
|
|
@@ -219,9 +230,10 @@ export function useFileListing({
|
|
|
219
230
|
const read = await readDir(listUrl(path));
|
|
220
231
|
if (scopeRef.current !== requested || read.status !== 'ok') return;
|
|
221
232
|
childrenCacheRef.current[path] = read.files;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
233
|
+
// Committed through `rehydrateTree` rather than patched in place: a fresh
|
|
234
|
+
// listing can itself hold a single-child chain, and a branch set directly
|
|
235
|
+
// would draw the unfolded rows the next refresh folds away.
|
|
236
|
+
if (listedScopeRef.current === requested) commit(requested, listedRootRef.current);
|
|
225
237
|
};
|
|
226
238
|
|
|
227
239
|
const adoptRoot = (data: unknown): void => {
|
|
@@ -250,9 +262,9 @@ export function useFileListing({
|
|
|
250
262
|
* the only thing that builds what is rendered. Editing the rendered tree
|
|
251
263
|
* directly would be undone by the next commit, which rebuilds from these.
|
|
252
264
|
*/
|
|
253
|
-
const insertEntry = (entry: { path: string; kind: 'file' | 'folder' }):
|
|
265
|
+
const insertEntry = (entry: { path: string; kind: 'file' | 'folder' }): FsNode[] | null => {
|
|
254
266
|
const requested = scopeRef.current;
|
|
255
|
-
if (listedScopeRef.current !== requested) return;
|
|
267
|
+
if (listedScopeRef.current !== requested) return null;
|
|
256
268
|
const node: FsNode = {
|
|
257
269
|
name: entry.path.slice(entry.path.lastIndexOf('/') + 1),
|
|
258
270
|
path: entry.path,
|
|
@@ -260,23 +272,23 @@ export function useFileListing({
|
|
|
260
272
|
ignored: false,
|
|
261
273
|
};
|
|
262
274
|
const placed = placeEntry(rootFilesRef.current, childrenCacheRef.current, node);
|
|
263
|
-
if (placed.nodes === rootFilesRef.current) return;
|
|
275
|
+
if (placed.nodes === rootFilesRef.current) return null;
|
|
264
276
|
rootFilesRef.current = placed.nodes;
|
|
265
277
|
childrenCacheRef.current = placed.cache;
|
|
266
|
-
commit(requested, listedRootRef.current);
|
|
278
|
+
return commit(requested, listedRootRef.current);
|
|
267
279
|
};
|
|
268
280
|
|
|
269
|
-
const moveEntry = (fromPath: string, toPath: string):
|
|
281
|
+
const moveEntry = (fromPath: string, toPath: string): FsNode[] | null => {
|
|
270
282
|
const requested = scopeRef.current;
|
|
271
|
-
if (listedScopeRef.current !== requested) return;
|
|
283
|
+
if (listedScopeRef.current !== requested) return null;
|
|
272
284
|
const taken = takeEntry(rootFilesRef.current, childrenCacheRef.current, fromPath);
|
|
273
|
-
if (!taken.entry) return;
|
|
285
|
+
if (!taken.entry) return null;
|
|
274
286
|
childrenCacheRef.current = rekeyCache(taken.cache, fromPath, toPath);
|
|
275
287
|
const moved: FsNode = { ...taken.entry, path: toPath, name: toPath.slice(toPath.lastIndexOf('/') + 1) };
|
|
276
288
|
const placed = placeEntry(taken.nodes, childrenCacheRef.current, moved);
|
|
277
289
|
rootFilesRef.current = placed.nodes;
|
|
278
290
|
childrenCacheRef.current = placed.cache;
|
|
279
|
-
commit(requested, listedRootRef.current);
|
|
291
|
+
return commit(requested, listedRootRef.current);
|
|
280
292
|
};
|
|
281
293
|
|
|
282
294
|
// A listing read for another scope is not this one's to render: the panel
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
27
27
|
import { Window } from 'happy-dom';
|
|
28
28
|
import type { h as PreactH, render as PreactRender } from 'preact';
|
|
29
|
+
import type { ComponentChildren } from 'preact';
|
|
30
|
+
import type { ComponentType } from 'preact/compat';
|
|
29
31
|
import type { act as PreactAct } from 'preact/test-utils';
|
|
30
32
|
import type { useFileTabs as UseFileTabsHook } from '@/client/hooks/workspace/file-tabs';
|
|
31
33
|
import type { OpenFileInput } from '@/client/hooks/workspace/file-tabs';
|
|
@@ -44,7 +46,14 @@ const SESSION = 'new-file-tabs';
|
|
|
44
46
|
const nativeFetch = Bun.fetch;
|
|
45
47
|
|
|
46
48
|
let container: HTMLElement;
|
|
49
|
+
/** The provider component, kept so a case can re-render with a different root. */
|
|
50
|
+
let SessionStateProvider: ComponentType<{ sessionId: string; children: ComponentChildren }>;
|
|
47
51
|
let handleOpenFile: ((file: OpenFileInput) => void) | null = null;
|
|
52
|
+
let handleCloseFile: ((id: number | string) => void) | null = null;
|
|
53
|
+
let handleReopenClosed: (() => boolean) | null = null;
|
|
54
|
+
let reopenableCount: (() => number) | null = null;
|
|
55
|
+
/** The mounted probe, so a re-render can hand it another root. */
|
|
56
|
+
let Probe: ComponentType<{ rootPath: string | null }>;
|
|
48
57
|
let openedFiles: OpenedFile[] = [];
|
|
49
58
|
let activeFileId: number | string | null = null;
|
|
50
59
|
|
|
@@ -56,23 +65,38 @@ async function settle() {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
/** Re-render the mounted tree with a different workspace root. */
|
|
69
|
+
async function setRoot(rootPath: string | null): Promise<void> {
|
|
70
|
+
await act(async () => {
|
|
71
|
+
render(
|
|
72
|
+
h(SessionStateProvider, { sessionId: SESSION, children: h(Probe, { rootPath }) }),
|
|
73
|
+
container,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
await settle();
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
/** Mount the hook inside the provider, with `stored` as the session's blob. */
|
|
60
|
-
async function mount(stored: Record<string, unknown> = {}) {
|
|
80
|
+
async function mount(stored: Record<string, unknown> = {}, root: string | null = ROOT) {
|
|
61
81
|
globalThis.fetch = (async () => ({
|
|
62
82
|
ok: true,
|
|
63
83
|
json: async () => ({ sessionId: SESSION, state: stored }),
|
|
64
84
|
text: async () => JSON.stringify({ sessionId: SESSION, state: stored }),
|
|
65
85
|
})) as unknown as typeof fetch;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
const provider = await import('@/client/components/common/session-state-provider/index');
|
|
87
|
+
SessionStateProvider = provider.SessionStateProvider as typeof SessionStateProvider;
|
|
88
|
+
Probe = ({ rootPath }: { rootPath: string | null }) => {
|
|
89
|
+
const tabs = useFileTabs(rootPath, SESSION);
|
|
69
90
|
handleOpenFile = tabs.handleOpenFile;
|
|
91
|
+
handleCloseFile = tabs.handleCloseFile;
|
|
92
|
+
handleReopenClosed = tabs.handleReopenClosed;
|
|
93
|
+
reopenableCount = tabs.reopenableCount;
|
|
70
94
|
openedFiles = tabs.openedFiles;
|
|
71
95
|
activeFileId = tabs.activeFileId;
|
|
72
96
|
return null;
|
|
73
97
|
};
|
|
74
98
|
await act(async () => {
|
|
75
|
-
render(h(SessionStateProvider, { sessionId: SESSION, children: h(Probe, {}) }), container);
|
|
99
|
+
render(h(SessionStateProvider, { sessionId: SESSION, children: h(Probe, { rootPath: root }) }), container);
|
|
76
100
|
});
|
|
77
101
|
await settle();
|
|
78
102
|
}
|
|
@@ -91,6 +115,9 @@ afterAll(() => {
|
|
|
91
115
|
|
|
92
116
|
beforeEach(() => {
|
|
93
117
|
handleOpenFile = null;
|
|
118
|
+
handleCloseFile = null;
|
|
119
|
+
handleReopenClosed = null;
|
|
120
|
+
reopenableCount = null;
|
|
94
121
|
openedFiles = [];
|
|
95
122
|
activeFileId = null;
|
|
96
123
|
globalThis.fetch = (async () => ({
|
|
@@ -147,6 +174,45 @@ describe('useFileTabs open resolution', () => {
|
|
|
147
174
|
expect(activeFileId).toBe(fileTabId('src/a.ts'));
|
|
148
175
|
});
|
|
149
176
|
|
|
177
|
+
/**
|
|
178
|
+
* A root that is not known yet must not close the tabs.
|
|
179
|
+
*
|
|
180
|
+
* `activeProjectPath` is derived from the sidebar's folder list, which is empty
|
|
181
|
+
* for a beat on every load and again whenever the structure topic
|
|
182
|
+
* re-subscribes. Treating that `null` as a root CHANGE wiped the file the user
|
|
183
|
+
* had just clicked, and the editor drew "Select a file to open" over it — the
|
|
184
|
+
* rare e2e failure this pins.
|
|
185
|
+
*/
|
|
186
|
+
test('a transiently unknown root does not wipe the open tabs', async () => {
|
|
187
|
+
await mount();
|
|
188
|
+
await act(async () => {
|
|
189
|
+
handleOpenFile?.(explorerPayload('src/a.ts'));
|
|
190
|
+
});
|
|
191
|
+
await settle();
|
|
192
|
+
expect(openedFiles).toHaveLength(1);
|
|
193
|
+
|
|
194
|
+
// The folder list drops out and comes back — the same workspace.
|
|
195
|
+
await setRoot(null);
|
|
196
|
+
await setRoot(ROOT);
|
|
197
|
+
|
|
198
|
+
expect(openedFiles).toHaveLength(1);
|
|
199
|
+
expect(activeFileId).toBe('src/a.ts');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('a DIFFERENT root closes the previous workspace’s tabs', async () => {
|
|
203
|
+
await mount();
|
|
204
|
+
await act(async () => {
|
|
205
|
+
handleOpenFile?.(explorerPayload('src/a.ts'));
|
|
206
|
+
});
|
|
207
|
+
await settle();
|
|
208
|
+
expect(openedFiles).toHaveLength(1);
|
|
209
|
+
|
|
210
|
+
await setRoot('/other');
|
|
211
|
+
|
|
212
|
+
expect(openedFiles).toHaveLength(0);
|
|
213
|
+
expect(activeFileId).toBeNull();
|
|
214
|
+
});
|
|
215
|
+
|
|
150
216
|
test('reopening under the computed id activates the tab rather than adding one', async () => {
|
|
151
217
|
await mount();
|
|
152
218
|
|
|
@@ -163,3 +229,84 @@ describe('useFileTabs open resolution', () => {
|
|
|
163
229
|
expect(activeFileId).toBe(fileTabId('src/a.ts'));
|
|
164
230
|
});
|
|
165
231
|
});
|
|
232
|
+
|
|
233
|
+
describe('useFileTabs reopen', () => {
|
|
234
|
+
test('a closed tab comes back whole, and activated', async () => {
|
|
235
|
+
await mount();
|
|
236
|
+
await act(async () => handleOpenFile?.(explorerPayload('src/a.ts')));
|
|
237
|
+
await settle();
|
|
238
|
+
expect(openedFiles).toHaveLength(1);
|
|
239
|
+
|
|
240
|
+
await act(async () => handleCloseFile?.('src/a.ts'));
|
|
241
|
+
await settle();
|
|
242
|
+
expect(openedFiles).toHaveLength(0);
|
|
243
|
+
|
|
244
|
+
let restored = false;
|
|
245
|
+
await act(async () => { restored = handleReopenClosed?.() ?? false; });
|
|
246
|
+
await settle();
|
|
247
|
+
// Whole, not re-derived: the same id the explorer gave it, so the tab strip and the
|
|
248
|
+
// scroll-position map still address it.
|
|
249
|
+
expect(restored).toBe(true);
|
|
250
|
+
expect(openedFiles.map((file) => file.id)).toEqual(['src/a.ts']);
|
|
251
|
+
expect(activeFileId).toBe('src/a.ts');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('an empty stack answers false, so the chord can stay inert', async () => {
|
|
255
|
+
await mount();
|
|
256
|
+
let restored = true;
|
|
257
|
+
await act(async () => { restored = handleReopenClosed?.() ?? true; });
|
|
258
|
+
expect(restored).toBe(false);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('the stack is last-in-first-out', async () => {
|
|
262
|
+
await mount();
|
|
263
|
+
await act(async () => handleOpenFile?.(explorerPayload('src/a.ts')));
|
|
264
|
+
await act(async () => handleOpenFile?.(explorerPayload('src/b.ts')));
|
|
265
|
+
await settle();
|
|
266
|
+
await act(async () => handleCloseFile?.('src/a.ts'));
|
|
267
|
+
await act(async () => handleCloseFile?.('src/b.ts'));
|
|
268
|
+
await settle();
|
|
269
|
+
|
|
270
|
+
await act(async () => { handleReopenClosed?.(); });
|
|
271
|
+
await settle();
|
|
272
|
+
expect(openedFiles.map((file) => file.id)).toEqual(['src/b.ts']);
|
|
273
|
+
|
|
274
|
+
await act(async () => { handleReopenClosed?.(); });
|
|
275
|
+
await settle();
|
|
276
|
+
expect(openedFiles.map((file) => file.id)).toEqual(['src/b.ts', 'src/a.ts']);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test('the count follows the stack, so the menu row appears and disappears with it', async () => {
|
|
280
|
+
await mount();
|
|
281
|
+
await act(async () => handleOpenFile?.(explorerPayload('src/a.ts')));
|
|
282
|
+
await settle();
|
|
283
|
+
expect(reopenableCount?.()).toBe(0);
|
|
284
|
+
await act(async () => handleCloseFile?.('src/a.ts'));
|
|
285
|
+
await settle();
|
|
286
|
+
expect(reopenableCount?.()).toBe(1);
|
|
287
|
+
await act(async () => { handleReopenClosed?.(); });
|
|
288
|
+
await settle();
|
|
289
|
+
expect(reopenableCount?.()).toBe(0);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('a diff tab is restored as a DIFF — a path cannot derive that', async () => {
|
|
293
|
+
await mount();
|
|
294
|
+
// Opened through `handleOpenFile` with the shape only a diff has: a display name the
|
|
295
|
+
// file system does not have, plus `isDiff`. The reopen path must preserve it, because
|
|
296
|
+
// re-deriving a tab from its path would come back as a plain file tab.
|
|
297
|
+
await act(async () => handleOpenFile?.({
|
|
298
|
+
id: 'a.ts-diff',
|
|
299
|
+
name: 'a.ts (diff)',
|
|
300
|
+
path: 'a.ts',
|
|
301
|
+
root: ROOT,
|
|
302
|
+
repo: '.',
|
|
303
|
+
isDiff: true,
|
|
304
|
+
} as OpenFileInput));
|
|
305
|
+
await settle();
|
|
306
|
+
await act(async () => handleCloseFile?.('a.ts-diff'));
|
|
307
|
+
await settle();
|
|
308
|
+
await act(async () => { handleReopenClosed?.(); });
|
|
309
|
+
await settle();
|
|
310
|
+
expect(openedFiles[0]?.isDiff).toBe(true);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
@@ -22,6 +22,14 @@ export interface OpenFileInput {
|
|
|
22
22
|
handleId?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* How many closed tabs `Reopen` can restore.
|
|
27
|
+
*
|
|
28
|
+
* Ten is what a reader can still remember closing; past that the stack is a log rather
|
|
29
|
+
* than an undo.
|
|
30
|
+
*/
|
|
31
|
+
const REOPEN_STACK_LIMIT = 10;
|
|
32
|
+
|
|
25
33
|
export function useFileTabs(
|
|
26
34
|
activeProjectPath: string | null,
|
|
27
35
|
sessionId: string,
|
|
@@ -52,24 +60,37 @@ export function useFileTabs(
|
|
|
52
60
|
[sessionId],
|
|
53
61
|
);
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
/** The last root a wipe was performed FOR; `null` until one is known. */
|
|
64
|
+
const wipedRootRef = useRef<string | null>(null);
|
|
56
65
|
const { ready: layoutReady } = useSessionStateContext();
|
|
57
|
-
const wipedRootRef = useRef<string | null | undefined>(undefined);
|
|
58
66
|
|
|
59
67
|
useEffect(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
// Only a CHANGE from one known root to another closes the previous
|
|
69
|
+
// workspace's tabs.
|
|
70
|
+
//
|
|
71
|
+
// Two rules, and each was a bug first. A root that is not known yet is not a
|
|
72
|
+
// root that changed: the path is derived from the sidebar's folder list,
|
|
73
|
+
// which is empty for a beat on every load (and again whenever the structure
|
|
74
|
+
// topic re-subscribes), so treating `null` as a root wiped the tabs a user
|
|
75
|
+
// had just opened. And the FIRST known root is not a change either — it is
|
|
76
|
+
// the workspace the page was already showing, so wiping on it discarded the
|
|
77
|
+
// tabs the session blob had just restored (measured: the e2e specs had to
|
|
78
|
+
// gate every tree click on the `/state` response to survive it, and a click
|
|
79
|
+
// that lost that race left the editor reading "Select a file to open" over
|
|
80
|
+
// the file the user had opened).
|
|
81
|
+
if (!activeProjectPath || !layoutReady) return;
|
|
82
|
+
const previous = wipedRootRef.current;
|
|
63
83
|
wipedRootRef.current = activeProjectPath;
|
|
84
|
+
if (previous === null || previous === activeProjectPath) return;
|
|
64
85
|
// The tabs are dropped, but their scroll offsets deliberately are NOT: this
|
|
65
|
-
// wipe is not a user closing a tab.
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
86
|
+
// wipe is not a user closing a tab. Dropping here erased the offset the
|
|
87
|
+
// session blob had just restored — measured: the offset persisted as `900`,
|
|
88
|
+
// and came back as `{}` after a reload. The entry is keyed by the file's
|
|
89
|
+
// path hash, so it is reused when that file is opened again, which is the
|
|
90
|
+
// point.
|
|
70
91
|
setOpenedFiles([]);
|
|
71
92
|
setActiveFileId(null);
|
|
72
|
-
}, [activeProjectPath,
|
|
93
|
+
}, [activeProjectPath, layoutReady, setOpenedFiles, setActiveFileId]);
|
|
73
94
|
|
|
74
95
|
const handleOpenFile = useCallback((file: OpenFileInput) => {
|
|
75
96
|
const fileEntry: OpenedFile = {
|
|
@@ -142,9 +163,24 @@ export function useFileTabs(
|
|
|
142
163
|
onOpenTab?.();
|
|
143
164
|
}, [activeProjectPath, onOpenTab, setOpenedFiles, setActiveFileId]);
|
|
144
165
|
|
|
166
|
+
/**
|
|
167
|
+
* The tabs closed recently, newest last, so `Reopen` is a stack.
|
|
168
|
+
*
|
|
169
|
+
* A REF, not state: nothing renders the stack, and a re-render per close would be a
|
|
170
|
+
* second thing every tab interaction pays for. Bounded, because a session that closes
|
|
171
|
+
* a hundred tabs should not hold a hundred `OpenedFile`s alive.
|
|
172
|
+
*/
|
|
173
|
+
const closedRef = useRef<OpenedFile[]>([]);
|
|
174
|
+
|
|
145
175
|
const handleCloseFile = useCallback((id: number | string) => {
|
|
146
176
|
dropScrollFor([id]);
|
|
147
177
|
setOpenedFiles(prev => {
|
|
178
|
+
const closed = prev.find(f => f.id === id);
|
|
179
|
+
// Only a tab that actually existed is remembered: a close on a stale id must not
|
|
180
|
+
// put a phantom entry on the reopen stack.
|
|
181
|
+
if (closed) {
|
|
182
|
+
closedRef.current = [...closedRef.current, closed].slice(-REOPEN_STACK_LIMIT);
|
|
183
|
+
}
|
|
148
184
|
const next = prev.filter(f => f.id !== id);
|
|
149
185
|
if (activeFileId === id) {
|
|
150
186
|
setActiveFileId(next.length > 0 ? next[next.length - 1].id : null);
|
|
@@ -153,6 +189,27 @@ export function useFileTabs(
|
|
|
153
189
|
});
|
|
154
190
|
}, [activeFileId, dropScrollFor, setOpenedFiles, setActiveFileId]);
|
|
155
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Put the most recently closed tab back, activating it.
|
|
194
|
+
*
|
|
195
|
+
* The entry is restored WHOLE — name, path, scope, diff flags — because reopening
|
|
196
|
+
* reconstructs the tab rather than re-deriving it from a path (a diff tab has no file
|
|
197
|
+
* to derive from). Returns false with an empty stack so the caller can leave the chord
|
|
198
|
+
* inert rather than swallowing it.
|
|
199
|
+
*/
|
|
200
|
+
const handleReopenClosed = useCallback(() => {
|
|
201
|
+
const entry = closedRef.current[closedRef.current.length - 1];
|
|
202
|
+
if (!entry) return false;
|
|
203
|
+
closedRef.current = closedRef.current.slice(0, -1);
|
|
204
|
+
setOpenedFiles(prev => (prev.some(f => f.id === entry.id) ? prev : [...prev, entry]));
|
|
205
|
+
setActiveFileId(entry.id);
|
|
206
|
+
onOpenTab?.();
|
|
207
|
+
return true;
|
|
208
|
+
}, [onOpenTab, setOpenedFiles, setActiveFileId]);
|
|
209
|
+
|
|
210
|
+
/** How many tabs `Reopen` can still restore, for the menu's enabled state. */
|
|
211
|
+
const reopenableCount = useCallback(() => closedRef.current.length, []);
|
|
212
|
+
|
|
156
213
|
/**
|
|
157
214
|
* Turn a diff tab into the plain editor tab for the same file.
|
|
158
215
|
*
|
|
@@ -241,6 +298,8 @@ export function useFileTabs(
|
|
|
241
298
|
handleOpenFile,
|
|
242
299
|
handleOpenDiff,
|
|
243
300
|
handleCloseFile,
|
|
301
|
+
handleReopenClosed,
|
|
302
|
+
reopenableCount,
|
|
244
303
|
convertDiffToEditor,
|
|
245
304
|
};
|
|
246
305
|
}
|