@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
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Owns the query, the option toggles, which match is "current", and the two
|
|
10
10
|
* write paths (replace one, replace all). Every rule it applies lives in
|
|
11
|
-
* `shared/lib/code/editor/find
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* that
|
|
11
|
+
* `shared/lib/code/editor/find-scan` (the match list) and `find-replace` (what
|
|
12
|
+
* one match becomes), so the count in the widget, the marks painted on the
|
|
13
|
+
* surface and the bytes written back are the same list — the failure this shape
|
|
14
|
+
* exists to prevent is a widget that says "3 of 7" over highlights that
|
|
15
|
+
* disagree.
|
|
15
16
|
*
|
|
16
17
|
* The query and the toggles persist per session; whether the bar is OPEN does
|
|
17
18
|
* not. A reload that reopened a find bar over the file would be noise the user
|
|
@@ -21,16 +22,17 @@
|
|
|
21
22
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
22
23
|
|
|
23
24
|
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
25
|
+
import { useFindHistory } from '@/client/hooks/editor/find-history';
|
|
26
|
+
import { useSelectionRange } from '@/client/hooks/editor/find-selection-range';
|
|
24
27
|
import {
|
|
25
28
|
DEFAULT_FIND_OPTIONS,
|
|
26
29
|
findMatches,
|
|
27
30
|
lineStartOffset,
|
|
28
31
|
matchIndexAtOrAfter,
|
|
29
|
-
replaceAllMatches,
|
|
30
|
-
replaceMatch,
|
|
31
32
|
stepMatchIndex,
|
|
32
33
|
type FindOptions,
|
|
33
|
-
} from '@/shared/lib/code/editor/find';
|
|
34
|
+
} from '@/shared/lib/code/editor/find-scan';
|
|
35
|
+
import { replaceAllMatches, replaceMatch } from '@/shared/lib/code/editor/find-replace';
|
|
34
36
|
import type { EditorCommand } from '@/shared/lib/code/editor/keymap';
|
|
35
37
|
import type { EditorFindState, UseEditorFindOptions } from '@/client/hooks/editor/find-state';
|
|
36
38
|
|
|
@@ -59,6 +61,10 @@ export function useEditorFind({
|
|
|
59
61
|
// A blob written before an option existed carries only the keys it had, so
|
|
60
62
|
// the read is merged over the defaults rather than trusted wholesale.
|
|
61
63
|
const options = useMemo<FindOptions>(() => ({ ...DEFAULT_FIND_OPTIONS, ...storedOptions }), [storedOptions]);
|
|
64
|
+
// The range an "in selection" search is restricted to, captured when it is armed.
|
|
65
|
+
const selection = useSelectionRange();
|
|
66
|
+
// Recent queries, remembered when a search was actually USED — see `find-history.ts`.
|
|
67
|
+
const findHistory = useFindHistory();
|
|
62
68
|
const [open, setOpen] = useState(false);
|
|
63
69
|
const [replaceOpen, setReplaceOpen] = useState(false);
|
|
64
70
|
const [currentIndex, setCurrentIndex] = useState(-1);
|
|
@@ -76,7 +82,12 @@ export function useEditorFind({
|
|
|
76
82
|
const openRef = useRef(false);
|
|
77
83
|
openRef.current = open;
|
|
78
84
|
|
|
79
|
-
const result = useMemo(
|
|
85
|
+
const result = useMemo(
|
|
86
|
+
// The range travels beside the options: the flag says WHETHER to restrict, the range
|
|
87
|
+
// says to what, and the two are captured at different moments.
|
|
88
|
+
() => findMatches(text, query, options, options.inSelection ? selection.range : null),
|
|
89
|
+
[text, query, options, selection.range],
|
|
90
|
+
);
|
|
80
91
|
|
|
81
92
|
/**
|
|
82
93
|
* Where the current match is resolved FROM: the caret/anchor a reseed uses.
|
|
@@ -166,6 +177,9 @@ export function useEditorFind({
|
|
|
166
177
|
const toggleReplace = useCallback(() => setReplaceOpen((prev) => !prev), []);
|
|
167
178
|
|
|
168
179
|
const close = useCallback(() => {
|
|
180
|
+
// A query that was actually searched is worth remembering; one typed and abandoned
|
|
181
|
+
// is not, which is why this is here rather than in `setQuery`.
|
|
182
|
+
findHistory.remember(query);
|
|
169
183
|
setOpen(false);
|
|
170
184
|
setReplaceOpen(false);
|
|
171
185
|
// Focus returns to the match, which is where the user was looking.
|
|
@@ -190,10 +204,28 @@ export function useEditorFind({
|
|
|
190
204
|
|
|
191
205
|
const toggleOption = useCallback(
|
|
192
206
|
(key: keyof FindOptions) => {
|
|
193
|
-
|
|
207
|
+
const next = { ...options, [key]: !options[key] };
|
|
208
|
+
if (key === 'inSelection' && !selection.arm(readSelection)) {
|
|
209
|
+
// Nothing selected: the toggle cannot mean anything, so it does not arm.
|
|
210
|
+
setOptions({ ...options, inSelection: false });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (key === 'inSelection' && !next.inSelection) selection.disarm();
|
|
214
|
+
setOptions(next);
|
|
194
215
|
reseed(anchorRef.current);
|
|
195
216
|
},
|
|
196
|
-
[options, setOptions, reseed],
|
|
217
|
+
[options, setOptions, reseed, readSelection, selection],
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
/** Re-run a query from the history, and remember it as the most recent again. */
|
|
221
|
+
const useHistoryEntry = useCallback(
|
|
222
|
+
(value: string) => {
|
|
223
|
+
setQueryState(value);
|
|
224
|
+
findHistory.remember(value);
|
|
225
|
+
reseed(anchorRef.current);
|
|
226
|
+
setResolveRequest((previous) => previous + 1);
|
|
227
|
+
},
|
|
228
|
+
[findHistory, reseed],
|
|
197
229
|
);
|
|
198
230
|
|
|
199
231
|
/**
|
|
@@ -300,6 +332,9 @@ export function useEditorFind({
|
|
|
300
332
|
runCommand,
|
|
301
333
|
revealMatch,
|
|
302
334
|
toggleOption,
|
|
335
|
+
selectionRange: options.inSelection ? selection.range : null,
|
|
336
|
+
history: findHistory.entries,
|
|
337
|
+
useHistoryEntry,
|
|
303
338
|
step,
|
|
304
339
|
replaceCurrent,
|
|
305
340
|
replaceAll,
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor panel's keyboard surface, as one hook.
|
|
8
|
+
*
|
|
9
|
+
* Three things live here because they are one decision: what the panel CONSUMES
|
|
10
|
+
* before the document sees it. The panel is the scope, not the window — another
|
|
11
|
+
* panel's text field keeps its own ⌘F and the composer is untouched — and only the
|
|
12
|
+
* commands the PANEL owns are consumed here, because the editor's own keymap runs
|
|
13
|
+
* inside the document where it has the buffer and the caret in hand.
|
|
14
|
+
*
|
|
15
|
+
* ## Capture is the mechanism
|
|
16
|
+
*
|
|
17
|
+
* The contenteditable has CodeMirror's handlers (the generated keymap, and
|
|
18
|
+
* `defaultKeymap` behind it) and would see these chords first otherwise. Capture
|
|
19
|
+
* on the panel's own root is what puts them in front, and it is also why the
|
|
20
|
+
* panel is the scope: the listener is on a container, not on `window`.
|
|
21
|
+
*
|
|
22
|
+
* ## ⌘S is the one chord handled on the WINDOW
|
|
23
|
+
*
|
|
24
|
+
* It has to work while focus is anywhere in the panel — including a field the
|
|
25
|
+
* panel does not own — and a browser's own Save dialog is the alternative. It is
|
|
26
|
+
* registered once and reads the save callback through a ref, so a re-render does
|
|
27
|
+
* not detach and reattach it.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { useCallback, useEffect, useRef } from 'preact/hooks';
|
|
31
|
+
import type { TargetedKeyboardEvent } from 'preact';
|
|
32
|
+
|
|
33
|
+
import { EDITOR_KEY_BINDINGS, isFindBarCommand, type EditorCommand } from '@/shared/lib/code/editor/keymap';
|
|
34
|
+
import { resolveBinding } from '@/shared/lib/ui/key-binding';
|
|
35
|
+
|
|
36
|
+
interface UseEditorPanelKeysOptions {
|
|
37
|
+
find: {
|
|
38
|
+
open: boolean;
|
|
39
|
+
close: () => void;
|
|
40
|
+
runCommand: (command: EditorCommand) => void;
|
|
41
|
+
};
|
|
42
|
+
paletteOpen: boolean;
|
|
43
|
+
setPaletteOpen: (open: boolean) => void;
|
|
44
|
+
runCommand: (command: EditorCommand) => void;
|
|
45
|
+
saveNow: () => void;
|
|
46
|
+
/** Open the file picker. `⌘P` is about the WORKSPACE, not the buffer. */
|
|
47
|
+
openQuickOpen: () => void;
|
|
48
|
+
/** Restore the most recently closed tab; returns false with an empty stack. */
|
|
49
|
+
reopenClosed?: () => boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface EditorPanelKeys {
|
|
53
|
+
/** Spread on the panel's root: the capture-phase dispatch. */
|
|
54
|
+
onKeyDownCapture: (event: TargetedKeyboardEvent<HTMLDivElement>) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function useEditorPanelKeys({
|
|
58
|
+
find,
|
|
59
|
+
paletteOpen,
|
|
60
|
+
setPaletteOpen,
|
|
61
|
+
runCommand,
|
|
62
|
+
saveNow,
|
|
63
|
+
openQuickOpen,
|
|
64
|
+
reopenClosed,
|
|
65
|
+
}: UseEditorPanelKeysOptions): EditorPanelKeys {
|
|
66
|
+
// The handler is rebuilt every render (it reads live find state), so the ref is
|
|
67
|
+
// what keeps the window listener attached once.
|
|
68
|
+
const findRef = useRef(find);
|
|
69
|
+
findRef.current = find;
|
|
70
|
+
const paletteRef = useRef({ paletteOpen, setPaletteOpen });
|
|
71
|
+
paletteRef.current = { paletteOpen, setPaletteOpen };
|
|
72
|
+
const runRef = useRef(runCommand);
|
|
73
|
+
runRef.current = runCommand;
|
|
74
|
+
|
|
75
|
+
const saveRef = useRef(saveNow);
|
|
76
|
+
saveRef.current = saveNow;
|
|
77
|
+
const quickOpenRef = useRef(openQuickOpen);
|
|
78
|
+
quickOpenRef.current = openQuickOpen;
|
|
79
|
+
const reopenRef = useRef(reopenClosed);
|
|
80
|
+
reopenRef.current = reopenClosed;
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const handler = (event: globalThis.KeyboardEvent) => {
|
|
84
|
+
if (!(event.ctrlKey || event.metaKey) || event.key !== 's') return;
|
|
85
|
+
// The browser's Save dialog is never what the user meant.
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
saveRef.current();
|
|
88
|
+
};
|
|
89
|
+
window.addEventListener('keydown', handler);
|
|
90
|
+
return () => window.removeEventListener('keydown', handler);
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
const onKeyDownCapture = useCallback((event: TargetedKeyboardEvent<HTMLDivElement>) => {
|
|
94
|
+
const current = findRef.current;
|
|
95
|
+
const palette = paletteRef.current;
|
|
96
|
+
|
|
97
|
+
if (event.key === 'Escape') {
|
|
98
|
+
if (palette.paletteOpen) {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
event.stopPropagation();
|
|
101
|
+
palette.setPaletteOpen(false);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!current.open) return;
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
current.close();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ⌘⇧T restores the last closed tab. Checked BEFORE ⌘⇧P for the same reason: a
|
|
112
|
+
// chord pair that differs only by its letter must not both match.
|
|
113
|
+
if ((event.metaKey || event.ctrlKey) && event.shiftKey && event.code === 'KeyT') {
|
|
114
|
+
// Only consumed when there IS something to restore, so an empty stack leaves the
|
|
115
|
+
// key to the browser rather than swallowing it.
|
|
116
|
+
if (reopenRef.current?.()) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
event.stopPropagation();
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ⌘P opens the file picker, and it is checked BEFORE ⌘⇧P: the shift test below
|
|
124
|
+
// excludes it, so the two cannot both fire, but the reader should see the pair
|
|
125
|
+
// together.
|
|
126
|
+
if ((event.metaKey || event.ctrlKey) && !event.shiftKey && event.code === 'KeyP') {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
event.stopPropagation();
|
|
129
|
+
quickOpenRef.current();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ⌘⇧P opens the palette — the one chord that is not an editor command.
|
|
134
|
+
if ((event.metaKey || event.ctrlKey) && event.shiftKey && event.code === 'KeyP') {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
event.stopPropagation();
|
|
137
|
+
palette.setPaletteOpen(true);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// While the bar is open, an unmodified key in one of ITS fields belongs to the
|
|
142
|
+
// field — but F3 and the ⌘-chords below still dispatch, so stepping to the
|
|
143
|
+
// next match from inside the find field works.
|
|
144
|
+
const command = resolveBinding(EDITOR_KEY_BINDINGS, event);
|
|
145
|
+
if (!command || !isFindBarCommand(command)) return;
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
runRef.current(command);
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
return { onKeyDownCapture };
|
|
152
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor panel's tab-level bookkeeping, as one hook.
|
|
8
|
+
*
|
|
9
|
+
* Two effects that both answer "what does the TAB STRIP need to know", and both are
|
|
10
|
+
* easy to get wrong on their own:
|
|
11
|
+
*
|
|
12
|
+
* - **Which tabs hold unsaved edits.** The editor is the only component that caches
|
|
13
|
+
* the buffers, so it is the only one that can answer; the strip draws the dot, the
|
|
14
|
+
* close guard asks before closing, and the unload prompt arms itself. Only FILE
|
|
15
|
+
* tabs are published — a diff tab and an attachment chip have no file behind them,
|
|
16
|
+
* so "unsaved" means nothing there.
|
|
17
|
+
* - **The default preview mode for a rendered file.** A markdown page, a CSV grid and
|
|
18
|
+
* an SVG open in their RENDERED form, because that is what the user opened them to
|
|
19
|
+
* read. The default is seeded only when nothing was stored, so a user who switched
|
|
20
|
+
* to source keeps that choice.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { useEffect } from 'preact/hooks';
|
|
24
|
+
|
|
25
|
+
import { RENDERED_VIEWERS, viewerKindFor } from '@/shared/lib/fs/document-kind';
|
|
26
|
+
import { getSessionValue } from '@/shared/lib/workspace/session-state/store';
|
|
27
|
+
import { setDirtyTabs } from '@/client/lib/editor-dirty-tabs';
|
|
28
|
+
import type { OpenedFile } from '@/shared/types/fs';
|
|
29
|
+
|
|
30
|
+
interface UseEditorTabStateOptions {
|
|
31
|
+
openedFiles: OpenedFile[];
|
|
32
|
+
/** Buffer keys holding edits that are not on disk (from `useFileEditor`). */
|
|
33
|
+
dirtyKeys: ReadonlySet<string>;
|
|
34
|
+
activeFile: OpenedFile | undefined;
|
|
35
|
+
/** The session store has loaded, so a stored choice can be read. */
|
|
36
|
+
previewReady: boolean;
|
|
37
|
+
setPreviewMode: (update: (previous: Record<string | number, boolean>) => Record<string | number, boolean>) => void;
|
|
38
|
+
sessionId: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useEditorTabState({
|
|
42
|
+
openedFiles,
|
|
43
|
+
dirtyKeys,
|
|
44
|
+
activeFile,
|
|
45
|
+
previewReady,
|
|
46
|
+
setPreviewMode,
|
|
47
|
+
sessionId,
|
|
48
|
+
}: UseEditorTabStateOptions): void {
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const ids = new Set(
|
|
51
|
+
openedFiles.filter((file) => !file.isDiff && file.content === undefined).map((file) => file.id),
|
|
52
|
+
);
|
|
53
|
+
setDirtyTabs([...dirtyKeys].filter((key) => ids.has(key)));
|
|
54
|
+
}, [dirtyKeys, openedFiles]);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!previewReady) return;
|
|
58
|
+
const id = activeFile?.id;
|
|
59
|
+
if (!activeFile || id === undefined || id === null) return;
|
|
60
|
+
// Only a file with a RENDERED view has a default worth setting; a code file has
|
|
61
|
+
// no preview to open.
|
|
62
|
+
if (!RENDERED_VIEWERS[viewerKindFor(activeFile.name)]) return;
|
|
63
|
+
const stored = getSessionValue<Record<string | number, boolean>>(sessionId, 'editor.previewMode');
|
|
64
|
+
if (stored && stored[id] !== undefined) return;
|
|
65
|
+
setPreviewMode((previous) => (previous[id] === undefined ? { ...previous, [id]: true } : previous));
|
|
66
|
+
// `previewMode` is deliberately absent: the effect seeds a MISSING entry, and
|
|
67
|
+
// re-running it because the map moved would re-seed the file the user just
|
|
68
|
+
// switched to source.
|
|
69
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
}, [previewReady, activeFile]);
|
|
71
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The external-change strip AND its "Keep mine" answer, as one call.
|
|
8
|
+
*
|
|
9
|
+
* They are one concern: the strip exists so the user can choose between two answers, and
|
|
10
|
+
* the answer needs the mtime the probe found. Wiring them separately in the panel meant the
|
|
11
|
+
* answer read `externalChange?.mtimeMs` from a value the same component held — a second
|
|
12
|
+
* place for the two to disagree about which change is being answered.
|
|
13
|
+
*
|
|
14
|
+
* "Keep mine" ADOPTS the disk mtime and writes nothing: the buffer stays dirty and the
|
|
15
|
+
* autosave owns the write. That is the difference between this and the CONFLICT strip's
|
|
16
|
+
* Keep mine, which writes immediately — a conflict is a save the server refused, so the
|
|
17
|
+
* user's answer is "try again with the new base".
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { DiskChange } from '@/client/hooks/editor/use-external-change';
|
|
21
|
+
import { useExternalChange } from '@/client/hooks/editor/use-external-change';
|
|
22
|
+
|
|
23
|
+
interface ExternalFile {
|
|
24
|
+
path?: string;
|
|
25
|
+
root?: string;
|
|
26
|
+
repo?: string;
|
|
27
|
+
isDiff?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface UseExternalChangeNoticeOptions {
|
|
31
|
+
file: ExternalFile | undefined;
|
|
32
|
+
/** The mtime the buffer was read at. */
|
|
33
|
+
baseMtimeMs: number | null;
|
|
34
|
+
dirty: boolean;
|
|
35
|
+
/** Bumped whenever something may have written the tree. */
|
|
36
|
+
revision: number;
|
|
37
|
+
/** Take the disk mtime as this buffer's base, writing nothing. */
|
|
38
|
+
adoptDiskMtime: (diskMtimeMs: number) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ExternalChangeNotice {
|
|
42
|
+
externalChange: DiskChange | null;
|
|
43
|
+
/** Adopt the disk mtime so the next save is not refused. */
|
|
44
|
+
keepMine: () => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useExternalChangeNotice({
|
|
48
|
+
file,
|
|
49
|
+
baseMtimeMs,
|
|
50
|
+
dirty,
|
|
51
|
+
revision,
|
|
52
|
+
adoptDiskMtime,
|
|
53
|
+
}: UseExternalChangeNoticeOptions): ExternalChangeNotice {
|
|
54
|
+
const externalChange = useExternalChange({
|
|
55
|
+
// A diff tab's path names a CHANGE, not a document: there is no file behind it to
|
|
56
|
+
// compare an mtime against.
|
|
57
|
+
path: file && !file.isDiff ? file.path ?? null : null,
|
|
58
|
+
root: file?.root,
|
|
59
|
+
repo: file?.repo,
|
|
60
|
+
baseMtimeMs,
|
|
61
|
+
dirty,
|
|
62
|
+
revision,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const keepMine = () => {
|
|
66
|
+
const mtime = externalChange?.mtimeMs;
|
|
67
|
+
if (mtime != null) adoptDiskMtime(mtime);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return { externalChange, keepMine };
|
|
71
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The external-change probe.
|
|
8
|
+
*
|
|
9
|
+
* Three rules, and each is a silent failure if broken:
|
|
10
|
+
*
|
|
11
|
+
* - a REFUSED probe is not a verdict — offering a Reload over a dropped request is
|
|
12
|
+
* worse than saying nothing;
|
|
13
|
+
* - a file that is GONE is the tab strip's strike-through, not a change strip;
|
|
14
|
+
* - a MATCHING mtime is no change at all, which is what keeps the strip off a file
|
|
15
|
+
* nobody touched.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
19
|
+
|
|
20
|
+
import { probeExternalChange } from '@/client/hooks/editor/use-external-change';
|
|
21
|
+
|
|
22
|
+
const nativeFetch = Bun.fetch;
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
globalThis.fetch = nativeFetch;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Answer the probe with `body`, or refuse it. */
|
|
29
|
+
function stub(body: unknown, ok = true): void {
|
|
30
|
+
globalThis.fetch = (async () => ({
|
|
31
|
+
ok,
|
|
32
|
+
json: async () => body,
|
|
33
|
+
})) as unknown as typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('probeExternalChange', () => {
|
|
37
|
+
test('a matching mtime is no change', async () => {
|
|
38
|
+
stub({ exists: true, mtimeMs: 100 });
|
|
39
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unchanged' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('a moved mtime is a change, carrying both sides', async () => {
|
|
43
|
+
stub({ exists: true, mtimeMs: 200 });
|
|
44
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({
|
|
45
|
+
kind: 'changed',
|
|
46
|
+
mtimeMs: 200,
|
|
47
|
+
baseMtimeMs: 100,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('a missing file is not a change — the tab strip owns that fact', async () => {
|
|
52
|
+
stub({ exists: false, mtimeMs: null });
|
|
53
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'gone' });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a refused probe is NO VERDICT, never a change', async () => {
|
|
57
|
+
stub({}, false);
|
|
58
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unknown' });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a malformed body is no verdict', async () => {
|
|
62
|
+
stub({ exists: 'yes' });
|
|
63
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unknown' });
|
|
64
|
+
stub(null);
|
|
65
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unknown' });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('a dropped connection is no verdict', async () => {
|
|
69
|
+
globalThis.fetch = (async () => { throw new Error('offline'); }) as unknown as typeof fetch;
|
|
70
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unknown' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a file that exists with no mtime to report is no verdict', async () => {
|
|
74
|
+
stub({ exists: true });
|
|
75
|
+
expect(await probeExternalChange('/a.ts', null, null, 100)).toEqual({ kind: 'unknown' });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('the scope travels with the probe, so a nested repo is read from its own tree', async () => {
|
|
79
|
+
const seen: string[] = [];
|
|
80
|
+
globalThis.fetch = (async (input: unknown) => {
|
|
81
|
+
seen.push(String(input));
|
|
82
|
+
return { ok: true, json: async () => ({ exists: true, mtimeMs: 100 }) };
|
|
83
|
+
}) as unknown as typeof fetch;
|
|
84
|
+
await probeExternalChange('a.ts', '/repo', 'nested', 100);
|
|
85
|
+
expect(seen[0]).toContain('root=%2Frepo');
|
|
86
|
+
expect(seen[0]).toContain('repo=nested');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* "This file changed on disk while you were editing it."
|
|
8
|
+
*
|
|
9
|
+
* The editor never noticed: it subscribed to no realtime topic, and the only re-read
|
|
10
|
+
* was a manual Refresh. With the 800 ms autosave that is a data-loss path — an agent
|
|
11
|
+
* (or another tab, or `git checkout`) writes a file the user has open, and the next
|
|
12
|
+
* keystroke writes the stale buffer over it.
|
|
13
|
+
*
|
|
14
|
+
* ## Why the `fs:` topic's own revision and not a file watcher
|
|
15
|
+
*
|
|
16
|
+
* `workspace-dirty` already republishes every watched `fs:`/`git:` topic after each
|
|
17
|
+
* tool call and each run end, and the panel's `refreshKey` carries the same signal
|
|
18
|
+
* for its own writes. A server-side `fs.watch` per open file would be a new
|
|
19
|
+
* process-wide resource for one strip.
|
|
20
|
+
*
|
|
21
|
+
* ## The probe asks ONE question, and a refusal is not a verdict
|
|
22
|
+
*
|
|
23
|
+
* The topic payload is a directory listing; what this needs is one file's mtime.
|
|
24
|
+
* `/api/fs/exists` already answers the scope question with the same allow-list and
|
|
25
|
+
* the same containment, so it grew an `mtimeMs`. A refused or dropped probe says
|
|
26
|
+
* nothing about the file, and reporting it as "changed" would offer a Reload over a
|
|
27
|
+
* perfectly current buffer — so only a real answer counts, and `unknown` is its own
|
|
28
|
+
* outcome rather than a silent "fine".
|
|
29
|
+
*
|
|
30
|
+
* ## Only a DIRTY buffer asks
|
|
31
|
+
*
|
|
32
|
+
* A clean buffer has nothing to lose: re-reading it silently is what the read effect
|
|
33
|
+
* already does on a refresh. The strip exists for the case where the user's edits and
|
|
34
|
+
* the disk's bytes disagree, which is precisely `isDirty`.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
38
|
+
|
|
39
|
+
/** What a probe learned. */
|
|
40
|
+
export type ExternalChangeVerdict =
|
|
41
|
+
/** The disk still holds the bytes this buffer was built from. */
|
|
42
|
+
| { kind: 'unchanged' }
|
|
43
|
+
/** The disk moved: both sides, so the strip can say when. */
|
|
44
|
+
| { kind: 'changed'; mtimeMs: number; baseMtimeMs: number }
|
|
45
|
+
/** The file is gone; the tab strip's strike-through owns that fact. */
|
|
46
|
+
| { kind: 'gone' }
|
|
47
|
+
/** No answer — a refused request, a malformed body, a file with no mtime. */
|
|
48
|
+
| { kind: 'unknown' };
|
|
49
|
+
|
|
50
|
+
/** The change a buffer has to be told about, or null. */
|
|
51
|
+
export interface DiskChange {
|
|
52
|
+
mtimeMs: number;
|
|
53
|
+
baseMtimeMs: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Ask the server whether `path` still has the mtime the buffer was built from.
|
|
58
|
+
*
|
|
59
|
+
* Exported because the three "no verdict" branches are the whole rule, and they are
|
|
60
|
+
* only testable without a mounted component.
|
|
61
|
+
*/
|
|
62
|
+
export async function probeExternalChange(
|
|
63
|
+
path: string,
|
|
64
|
+
root: string | null,
|
|
65
|
+
repo: string | null,
|
|
66
|
+
baseMtimeMs: number,
|
|
67
|
+
): Promise<ExternalChangeVerdict> {
|
|
68
|
+
const params = new URLSearchParams({ path });
|
|
69
|
+
if (root) params.set('root', root);
|
|
70
|
+
if (repo && repo !== '.') params.set('repo', repo);
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch(`/api/fs/exists?${params.toString()}`);
|
|
73
|
+
const data = (await res.json().catch(() => null)) as { exists?: unknown; mtimeMs?: unknown } | null;
|
|
74
|
+
if (!res.ok || !data || typeof data.exists !== 'boolean') return { kind: 'unknown' };
|
|
75
|
+
if (data.exists === false) return { kind: 'gone' };
|
|
76
|
+
if (typeof data.mtimeMs !== 'number') return { kind: 'unknown' };
|
|
77
|
+
return data.mtimeMs === baseMtimeMs
|
|
78
|
+
? { kind: 'unchanged' }
|
|
79
|
+
: { kind: 'changed', mtimeMs: data.mtimeMs, baseMtimeMs };
|
|
80
|
+
} catch {
|
|
81
|
+
return { kind: 'unknown' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface UseExternalChangeOptions {
|
|
86
|
+
/** The file the buffer came from; `null` for an inline attachment or a handle. */
|
|
87
|
+
path: string | null;
|
|
88
|
+
root?: string | null;
|
|
89
|
+
repo?: string | null;
|
|
90
|
+
/** The mtime the buffer was read at — the value the save path would send. */
|
|
91
|
+
baseMtimeMs: number | null;
|
|
92
|
+
/** Only a dirty buffer has anything to lose. */
|
|
93
|
+
dirty: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Bumped whenever something may have written the tree.
|
|
96
|
+
*
|
|
97
|
+
* The panel's `refreshKey` already carries this (a save, a Files-panel delete, a
|
|
98
|
+
* workspace refresh), and the realtime topic adds the agent's own writes.
|
|
99
|
+
*/
|
|
100
|
+
revision: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The disk change this buffer has to be told about, or null.
|
|
105
|
+
*
|
|
106
|
+
* The probe runs on `revision` (a write somewhere) and on the base moving (a save
|
|
107
|
+
* that landed). A save updates `baseMtimeMs` to what the server wrote, and
|
|
108
|
+
* re-probing with the NEW base is what clears the strip — comparing against a base
|
|
109
|
+
* the probe never saw would leave it up over a file the user just saved.
|
|
110
|
+
*/
|
|
111
|
+
export function useExternalChange({
|
|
112
|
+
path,
|
|
113
|
+
root = null,
|
|
114
|
+
repo = null,
|
|
115
|
+
baseMtimeMs,
|
|
116
|
+
dirty,
|
|
117
|
+
revision,
|
|
118
|
+
}: UseExternalChangeOptions): DiskChange | null {
|
|
119
|
+
const [change, setChange] = useState<DiskChange | null>(null);
|
|
120
|
+
/** The base the last probe asked about, so a re-render does not re-probe. */
|
|
121
|
+
const askedRef = useRef<number | null>(null);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!path || !dirty || baseMtimeMs === null) {
|
|
125
|
+
setChange(null);
|
|
126
|
+
askedRef.current = null;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (askedRef.current === baseMtimeMs) return;
|
|
130
|
+
let cancelled = false;
|
|
131
|
+
void probeExternalChange(path, root, repo, baseMtimeMs).then((verdict) => {
|
|
132
|
+
if (cancelled) return;
|
|
133
|
+
askedRef.current = baseMtimeMs;
|
|
134
|
+
// `unknown` deliberately leaves the previous answer alone: a dropped probe
|
|
135
|
+
// must not raise a strip, and it must not clear one the user is reading
|
|
136
|
+
// either — the next revision asks again.
|
|
137
|
+
if (verdict.kind === 'unknown') return;
|
|
138
|
+
setChange(verdict.kind === 'changed' ? { mtimeMs: verdict.mtimeMs, baseMtimeMs: verdict.baseMtimeMs } : null);
|
|
139
|
+
});
|
|
140
|
+
return () => {
|
|
141
|
+
cancelled = true;
|
|
142
|
+
};
|
|
143
|
+
}, [path, root, repo, baseMtimeMs, dirty, revision]);
|
|
144
|
+
|
|
145
|
+
return change;
|
|
146
|
+
}
|