@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,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Save As: write the buffer to a NEW path.
|
|
8
|
+
*
|
|
9
|
+
* ## What the server does, and what it deliberately does not
|
|
10
|
+
*
|
|
11
|
+
* One `POST /api/fs/action` with `actionType: 'saveAs'`: create the destination and
|
|
12
|
+
* write the bytes. It does NOT delete the original, does not copy its permissions or
|
|
13
|
+
* mtime, and does not ask the Files panel to refresh — those are three different
|
|
14
|
+
* decisions and only the first is "save as".
|
|
15
|
+
*
|
|
16
|
+
* **A destination that already exists is refused, not overwritten.** The same rule the
|
|
17
|
+
* Files panel's `create` applies: an overwrite is what `save` is for, and a dialog whose
|
|
18
|
+
* "Save" silently replaced a file the user did not name is the worst possible outcome of
|
|
19
|
+
* a mis-click. The refusal is a `409` carrying the reason, so the dialog can stay open
|
|
20
|
+
* with the name still in it.
|
|
21
|
+
*
|
|
22
|
+
* **The write is a new file, so there is no `baseMtime`.** A conflict guard compares a
|
|
23
|
+
* buffer against the bytes it was read from; a file that did not exist a moment ago has
|
|
24
|
+
* nothing to compare, and sending the ORIGINAL's mtime would refuse every Save As.
|
|
25
|
+
*
|
|
26
|
+
* ## The destination is a path plus a name, and the path is validated on the server
|
|
27
|
+
*
|
|
28
|
+
* The dialog builds `parent/name`, but the server re-resolves both against its own root
|
|
29
|
+
* allow-list: a client-supplied absolute path is exactly the shape that would let a
|
|
30
|
+
* crafted request write outside the workspace.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** What a Save As attempt answers. */
|
|
34
|
+
export type SaveAsOutcome =
|
|
35
|
+
/** Written; `path` is workspace-relative, which is what a tab needs. */
|
|
36
|
+
| { status: 'written'; path: string }
|
|
37
|
+
/** The destination exists. `reason` is the server's own sentence. */
|
|
38
|
+
| { status: 'exists'; reason: string }
|
|
39
|
+
/** Anything else: a bad name, a scope refusal, a dropped request. */
|
|
40
|
+
| { status: 'failed'; reason: string };
|
|
41
|
+
|
|
42
|
+
interface SaveAsOptions {
|
|
43
|
+
/** Workspace-relative directory the new file lands in. `''` means the scope root. */
|
|
44
|
+
parent: string;
|
|
45
|
+
/** One path segment — the server refuses a name carrying a separator. */
|
|
46
|
+
name: string;
|
|
47
|
+
/** The buffer, LF-only. The server rebuilds the bytes with `eol`. */
|
|
48
|
+
content: string;
|
|
49
|
+
eol: 'lf' | 'crlf';
|
|
50
|
+
root?: string;
|
|
51
|
+
repo?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What `/api/fs/action` answers for a saveAs. */
|
|
55
|
+
interface SaveAsResponse {
|
|
56
|
+
success?: unknown;
|
|
57
|
+
path?: unknown;
|
|
58
|
+
error?: unknown;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Write `content` to `parent/name`.
|
|
63
|
+
*
|
|
64
|
+
* The name is trimmed and refused when empty HERE as well as on the server: a dialog
|
|
65
|
+
* that posted an empty name would get a `400` and could only report a failure, while the
|
|
66
|
+
* user's actual mistake ("you did not type a name") is one the caller can show inline.
|
|
67
|
+
*/
|
|
68
|
+
export async function saveFileAs(options: SaveAsOptions): Promise<SaveAsOutcome> {
|
|
69
|
+
const name = options.name.trim();
|
|
70
|
+
if (!name) return { status: 'failed', reason: 'Enter a file name.' };
|
|
71
|
+
|
|
72
|
+
const formData = new FormData();
|
|
73
|
+
formData.append('actionType', 'saveAs');
|
|
74
|
+
formData.append('path', options.parent);
|
|
75
|
+
formData.append('name', name);
|
|
76
|
+
formData.append('content', options.content);
|
|
77
|
+
formData.append('eol', options.eol);
|
|
78
|
+
if (options.root) formData.append('root', options.root);
|
|
79
|
+
if (options.repo && options.repo !== '.') formData.append('repo', options.repo);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch('/api/fs/action', { method: 'POST', body: formData });
|
|
83
|
+
const data = (await res.json().catch(() => null)) as SaveAsResponse | null;
|
|
84
|
+
const reason = typeof data?.error === 'string' ? data.error : null;
|
|
85
|
+
if (res.status === 409) {
|
|
86
|
+
return { status: 'exists', reason: reason ?? `${name} already exists.` };
|
|
87
|
+
}
|
|
88
|
+
if (res.ok && data?.success && typeof data.path === 'string') {
|
|
89
|
+
return { status: 'written', path: data.path };
|
|
90
|
+
}
|
|
91
|
+
return { status: 'failed', reason: reason ?? 'The file could not be written.' };
|
|
92
|
+
} catch {
|
|
93
|
+
return { status: 'failed', reason: 'The file could not be written.' };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The name a Save As dialog starts with.
|
|
99
|
+
*
|
|
100
|
+
* `notes.ts` → `notes copy.ts`, not `notes copy` — a destination that loses the
|
|
101
|
+
* extension would be saved as a file the editor no longer recognises, and the language
|
|
102
|
+
* the surface resolved would change under the user.
|
|
103
|
+
*/
|
|
104
|
+
export function saveAsSuggestedName(fileName: string): string {
|
|
105
|
+
const dot = fileName.lastIndexOf('.');
|
|
106
|
+
if (dot <= 0) return `${fileName} copy`;
|
|
107
|
+
return `${fileName.slice(0, dot)} copy${fileName.slice(dot)}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether a typed name is one path segment, as the DIALOG checks it before posting.
|
|
112
|
+
*
|
|
113
|
+
* The server's own `isSinglePathSegment` is the authority (it also normalizes and refuses
|
|
114
|
+
* a NUL byte); this is the same shape minus the syscall-level cases, so the dialog can
|
|
115
|
+
* name the problem inline instead of posting a request it knows will be refused.
|
|
116
|
+
*/
|
|
117
|
+
export function isSingleSegmentName(name: string): boolean {
|
|
118
|
+
const trimmed = name.trim();
|
|
119
|
+
if (!trimmed) return false;
|
|
120
|
+
if (trimmed === '.' || trimmed === '..') return false;
|
|
121
|
+
return !trimmed.includes('/') && !trimmed.includes('\\');
|
|
122
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The write half of the file-editing contract.
|
|
8
|
+
*
|
|
9
|
+
* Two things are pinned here. The multipart shape the server rebuilds the file
|
|
10
|
+
* from — including the line ending that travels as its own field, because a
|
|
11
|
+
* multipart body normalizes bare LF — and the CONFLICT verdict, which is the only
|
|
12
|
+
* answer that must not be reported as a failure: a `409` carries the disk's own
|
|
13
|
+
* mtime so the panel can offer Reload/Keep instead of "save failed".
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
|
|
19
|
+
import { retainKeys, saveEditorFile } from '@/client/hooks/editor/save-file';
|
|
20
|
+
|
|
21
|
+
/** Globals happy-dom provides and the save path reads. */
|
|
22
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'FormData', 'File', 'Blob'] as const;
|
|
23
|
+
|
|
24
|
+
/** The runner's own `fetch`, reached through `Bun` so a leaked stub cannot be mistaken for it. */
|
|
25
|
+
const nativeFetch = Bun.fetch;
|
|
26
|
+
/** The runner's own globals, put back once this file's DOM work is done. */
|
|
27
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
28
|
+
|
|
29
|
+
beforeAll(() => {
|
|
30
|
+
const win = new Window({ url: 'http://localhost' });
|
|
31
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
32
|
+
const source = win as unknown as Record<string, unknown>;
|
|
33
|
+
for (const key of DOM_GLOBALS) {
|
|
34
|
+
native[key] = target[key];
|
|
35
|
+
target[key] = source[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
41
|
+
for (const key of DOM_GLOBALS) target[key] = native[key];
|
|
42
|
+
globalThis.fetch = nativeFetch;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
globalThis.fetch = nativeFetch;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
interface Write {
|
|
50
|
+
url: string;
|
|
51
|
+
method: string;
|
|
52
|
+
form: FormData;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Captures the write request and answers it with `answer`. */
|
|
56
|
+
function stubWrite(answer: { ok: boolean; status?: number; body?: unknown; throwOnJson?: boolean }): Write[] {
|
|
57
|
+
const writes: Write[] = [];
|
|
58
|
+
globalThis.fetch = (async (input: unknown, init?: RequestInit) => {
|
|
59
|
+
writes.push({ url: String(input), method: init?.method ?? 'GET', form: init?.body as FormData });
|
|
60
|
+
return {
|
|
61
|
+
ok: answer.ok,
|
|
62
|
+
status: answer.status ?? (answer.ok ? 200 : 500),
|
|
63
|
+
json: async () => {
|
|
64
|
+
if (answer.throwOnJson) throw new Error('not json');
|
|
65
|
+
return answer.body ?? null;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}) as unknown as typeof fetch;
|
|
69
|
+
return writes;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('saveEditorFile — the request it builds', () => {
|
|
73
|
+
test('posts the buffer with the path and the ending as its own field', async () => {
|
|
74
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
75
|
+
const outcome = await saveEditorFile({ path: 'src/a.ts', root: '/repo' }, 'const a = 1;\n', 'lf', { interactive: false });
|
|
76
|
+
|
|
77
|
+
expect(outcome).toEqual({ status: 'written' });
|
|
78
|
+
expect(writes.length).toBe(1);
|
|
79
|
+
expect(writes[0].url).toBe('/api/fs/action');
|
|
80
|
+
expect(writes[0].method).toBe('POST');
|
|
81
|
+
// A multipart body normalizes bare LF, so the ending cannot travel in it.
|
|
82
|
+
expect(writes[0].form.get('actionType')).toBe('save');
|
|
83
|
+
expect(writes[0].form.get('path')).toBe('src/a.ts');
|
|
84
|
+
expect(writes[0].form.get('content')).toBe('const a = 1;\n');
|
|
85
|
+
expect(writes[0].form.get('eol')).toBe('lf');
|
|
86
|
+
expect(writes[0].form.get('root')).toBe('/repo');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('omits the root when the file has none and the repo when it is the cwd marker', async () => {
|
|
90
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
91
|
+
await saveEditorFile({ path: 'a.ts', repo: '.' }, 'x', 'crlf', { interactive: false });
|
|
92
|
+
expect(writes[0].form.get('root')).toBeNull();
|
|
93
|
+
expect(writes[0].form.get('repo')).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a named repo travels with the write', async () => {
|
|
97
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
98
|
+
await saveEditorFile({ path: 'a.ts', repo: 'other' }, 'x', 'crlf', { interactive: false });
|
|
99
|
+
expect(writes[0].form.get('repo')).toBe('other');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('a file with no path is refused without touching the network', async () => {
|
|
103
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
104
|
+
expect(await saveEditorFile({}, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
105
|
+
expect(writes).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('saveEditorFile — the conflict contract', () => {
|
|
110
|
+
test('the base mtime travels with the write when the caller has one', async () => {
|
|
111
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
112
|
+
await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false, baseMtimeMs: 1_700_000_000_123 });
|
|
113
|
+
expect(writes[0].form.get('baseMtime')).toBe('1700000000123');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('no base mtime sends no field — a handle write and an older client must still save', async () => {
|
|
117
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
118
|
+
await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false });
|
|
119
|
+
expect(writes[0].form.get('baseMtime')).toBeNull();
|
|
120
|
+
|
|
121
|
+
const again = stubWrite({ ok: true, body: { success: true } });
|
|
122
|
+
await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false, baseMtimeMs: null });
|
|
123
|
+
// `null` must not become the string "null", which the server would parse and
|
|
124
|
+
// then compare against a real mtime — failing every save.
|
|
125
|
+
expect(again[0].form.get('baseMtime')).toBeNull();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('a 409 is a CONFLICT with the disk mtime, never a failure', async () => {
|
|
129
|
+
stubWrite({
|
|
130
|
+
ok: false,
|
|
131
|
+
status: 409,
|
|
132
|
+
body: { error: 'This file changed on disk since it was opened.', conflict: true, mtimeMs: 1_700_000_000_999 },
|
|
133
|
+
});
|
|
134
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false, baseMtimeMs: 1 })).toEqual({
|
|
135
|
+
status: 'conflict',
|
|
136
|
+
diskMtimeMs: 1_700_000_000_999,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('a 409 whose body names no mtime still reports a conflict, with null', async () => {
|
|
141
|
+
stubWrite({ ok: false, status: 409, body: null });
|
|
142
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false, baseMtimeMs: 1 })).toEqual({
|
|
143
|
+
status: 'conflict',
|
|
144
|
+
diskMtimeMs: null,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('saveEditorFile — every other refusal is a failure', () => {
|
|
150
|
+
test('non-2xx, an error body, a non-JSON body, a dropped connection', async () => {
|
|
151
|
+
stubWrite({ ok: false, body: { success: true } });
|
|
152
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
153
|
+
|
|
154
|
+
stubWrite({ ok: true, body: { success: false } });
|
|
155
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
156
|
+
|
|
157
|
+
stubWrite({ ok: true, body: null });
|
|
158
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
159
|
+
|
|
160
|
+
stubWrite({ ok: true, throwOnJson: true });
|
|
161
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
162
|
+
|
|
163
|
+
globalThis.fetch = (async () => { throw new Error('offline'); }) as unknown as typeof fetch;
|
|
164
|
+
expect(await saveEditorFile({ path: 'a.ts' }, 'x', 'lf', { interactive: false })).toEqual({ status: 'failed' });
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('retainKeys', () => {
|
|
169
|
+
test('keeps the same object when nothing was dropped, so children keep their identity', () => {
|
|
170
|
+
const record = { a: 1, b: 2 };
|
|
171
|
+
expect(retainKeys(record, new Set(['a', 'b']))).toBe(record);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('drops the keys that left the tab set and keeps the rest', () => {
|
|
175
|
+
const record = { a: 1, b: 2, c: 3 };
|
|
176
|
+
expect(retainKeys(record, new Set(['a', 'c']))).toEqual({ a: 1, c: 3 });
|
|
177
|
+
expect(retainKeys(record, new Set())).toEqual({});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -4,12 +4,24 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The write
|
|
8
|
-
* `/api/fs/action` and report whether the server took it.
|
|
7
|
+
* The write-conflict verdict: "the file on disk moved since you read it".
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the
|
|
9
|
+
* The save path wrote unconditionally, so two tabs on one file — or one tab and a
|
|
10
|
+
* tool call — silently last-writer-wins. The read route now reports the file's
|
|
11
|
+
* `mtimeMs`, the save sends it back as `baseMtime`, and the server refuses with
|
|
12
|
+
* `409` when the bytes on disk are not the ones the buffer was built from.
|
|
13
|
+
*
|
|
14
|
+
* Three rules make this safe rather than annoying:
|
|
15
|
+
*
|
|
16
|
+
* - **A save with no `baseMtime` keeps the old behaviour.** A handle-backed file
|
|
17
|
+
* (a PWA launch) has no server path and no mtime to send, and an older client
|
|
18
|
+
* sends none; neither may be turned into a refusal.
|
|
19
|
+
* - **A file that does not exist yet is not a conflict.** Creating the file the
|
|
20
|
+
* tab names is what `confirmSaveMissing` exists to allow, and `mtimeMs` is
|
|
21
|
+
* `null` there.
|
|
22
|
+
* - **A refusal is a VERDICT, not a failure.** It carries the current mtime, so
|
|
23
|
+
* the panel can offer "Reload" (discard mine) or "Keep mine" (write anyway,
|
|
24
|
+
* passing the new mtime) instead of reporting that the save failed.
|
|
13
25
|
*/
|
|
14
26
|
|
|
15
27
|
import type { LineEnding } from '@/shared/lib/code/line-endings';
|
|
@@ -22,10 +34,27 @@ interface SavableFile {
|
|
|
22
34
|
handleId?: string;
|
|
23
35
|
}
|
|
24
36
|
|
|
37
|
+
/** What a save attempt answers. */
|
|
38
|
+
export type SaveOutcome =
|
|
39
|
+
| { status: 'written' }
|
|
40
|
+
/** The buffer is behind the disk copy: `diskMtimeMs` is what is there now. */
|
|
41
|
+
| { status: 'conflict'; diskMtimeMs: number | null }
|
|
42
|
+
/** The write was refused for a reason that is not a conflict (a 4xx/5xx, a drop). */
|
|
43
|
+
| { status: 'failed' }
|
|
44
|
+
/** A handle-backed file needs a user gesture to grant write access. */
|
|
45
|
+
| { status: 'needs-permission' };
|
|
46
|
+
|
|
47
|
+
/** The shape `/api/fs/action` answers for a save. */
|
|
48
|
+
interface SaveResponse {
|
|
49
|
+
success?: unknown;
|
|
50
|
+
error?: unknown;
|
|
51
|
+
/** Present on a `409`: the mtime the file holds now. */
|
|
52
|
+
mtimeMs?: unknown;
|
|
53
|
+
conflict?: unknown;
|
|
54
|
+
}
|
|
55
|
+
|
|
25
56
|
/**
|
|
26
|
-
* Writes `lfText` to `file.path` in the file's own `eol`.
|
|
27
|
-
* refusal — a non-2xx response, an `error` body, or a dropped connection —
|
|
28
|
-
* because the caller's only decision is whether to mark the buffer clean.
|
|
57
|
+
* Writes `lfText` to `file.path` in the file's own `eol`.
|
|
29
58
|
*
|
|
30
59
|
* The ending travels as its own field and the server rebuilds the bytes: a
|
|
31
60
|
* multipart body normalizes bare LF to CRLF, so the payload cannot carry the
|
|
@@ -33,30 +62,37 @@ interface SavableFile {
|
|
|
33
62
|
*
|
|
34
63
|
* A file a PWA launch (or a Finder drop) handed over has NO server-reachable
|
|
35
64
|
* path — its `path` is only a display name — so the write goes through the live
|
|
36
|
-
* handle instead. Sending it to `/api/fs/action` would resolve that name
|
|
37
|
-
*
|
|
38
|
-
*
|
|
65
|
+
* handle instead. Sending it to `/api/fs/action` would resolve that name against
|
|
66
|
+
* the default root and write an unrelated file, which is why the branch comes
|
|
67
|
+
* first and a missing handle is a REFUSAL rather than a fallback.
|
|
39
68
|
*
|
|
40
69
|
* `interactive` says whether a user gesture is behind this call (a click, a
|
|
41
70
|
* Ctrl+S) or a timer (the autosave). It is passed straight through because the
|
|
42
|
-
* handle write needs the distinction to decide between asking for permission
|
|
43
|
-
*
|
|
71
|
+
* handle write needs the distinction to decide between asking for permission and
|
|
72
|
+
* reporting that a click is required.
|
|
73
|
+
*
|
|
74
|
+
* `baseMtimeMs` is the mtime the buffer was read from. Omit it for a handle write
|
|
75
|
+
* and for a caller that has none; the server then writes unconditionally, which
|
|
76
|
+
* is the pre-existing contract.
|
|
44
77
|
*/
|
|
45
78
|
export async function saveEditorFile(
|
|
46
79
|
file: SavableFile,
|
|
47
80
|
lfText: string,
|
|
48
81
|
eol: LineEnding,
|
|
49
|
-
options: { interactive: boolean
|
|
50
|
-
): Promise<
|
|
82
|
+
options: { interactive: boolean; baseMtimeMs?: number | null },
|
|
83
|
+
): Promise<SaveOutcome> {
|
|
51
84
|
if (file.handleId) {
|
|
52
|
-
|
|
53
|
-
return writeThroughHandle(
|
|
85
|
+
const result: HandleWriteResult = await writeThroughHandle(
|
|
54
86
|
file.handleId,
|
|
55
87
|
eol === 'crlf' ? lfText.replace(/\n/g, '\r\n') : lfText,
|
|
56
88
|
{ interactive: options.interactive },
|
|
57
89
|
);
|
|
90
|
+
if (result === 'written') return { status: 'written' };
|
|
91
|
+
if (result === 'needs-permission') return { status: 'needs-permission' };
|
|
92
|
+
return { status: 'failed' };
|
|
58
93
|
}
|
|
59
|
-
if (!file.path) return 'failed';
|
|
94
|
+
if (!file.path) return { status: 'failed' };
|
|
95
|
+
|
|
60
96
|
const formData = new FormData();
|
|
61
97
|
formData.append('actionType', 'save');
|
|
62
98
|
formData.append('path', file.path);
|
|
@@ -64,25 +100,34 @@ export async function saveEditorFile(
|
|
|
64
100
|
formData.append('eol', eol);
|
|
65
101
|
if (file.root) formData.append('root', file.root);
|
|
66
102
|
if (file.repo && file.repo !== '.') formData.append('repo', file.repo);
|
|
103
|
+
// `null`/absent is deliberately NOT sent: the server treats a missing field as
|
|
104
|
+
// "no expectation", and sending the string "null" would fail every save.
|
|
105
|
+
if (typeof options.baseMtimeMs === 'number') formData.append('baseMtime', String(options.baseMtimeMs));
|
|
106
|
+
|
|
67
107
|
try {
|
|
68
108
|
const res = await fetch('/api/fs/action', { method: 'POST', body: formData });
|
|
69
|
-
const data = await res.json().catch(() => null);
|
|
70
|
-
|
|
109
|
+
const data = (await res.json().catch(() => null)) as SaveResponse | null;
|
|
110
|
+
if (res.status === 409) {
|
|
111
|
+
const diskMtimeMs = typeof data?.mtimeMs === 'number' ? data.mtimeMs : null;
|
|
112
|
+
return { status: 'conflict', diskMtimeMs };
|
|
113
|
+
}
|
|
114
|
+
if (res.ok && data?.success) return { status: 'written' };
|
|
115
|
+
return { status: 'failed' };
|
|
71
116
|
} catch {
|
|
72
|
-
return 'failed';
|
|
117
|
+
return { status: 'failed' };
|
|
73
118
|
}
|
|
74
119
|
}
|
|
75
120
|
|
|
76
121
|
/**
|
|
77
|
-
* Keeps only `keep`'s keys, returning the same object when nothing was
|
|
78
|
-
*
|
|
122
|
+
* Keeps only `keep`'s keys, returning the same object when nothing was dropped so
|
|
123
|
+
* a render whose tab set is unchanged does not re-key its children.
|
|
79
124
|
*/
|
|
80
125
|
export function retainKeys<T>(record: Record<string, T>, keep: Set<string>): Record<string, T> {
|
|
81
|
-
const keys = Object.keys(record);
|
|
82
|
-
if (keys.every((key) => keep.has(key))) return record;
|
|
83
126
|
const next: Record<string, T> = {};
|
|
84
|
-
|
|
85
|
-
|
|
127
|
+
let dropped = false;
|
|
128
|
+
for (const [key, value] of Object.entries(record)) {
|
|
129
|
+
if (keep.has(key)) next[key] = value;
|
|
130
|
+
else dropped = true;
|
|
86
131
|
}
|
|
87
|
-
return next;
|
|
132
|
+
return dropped ? next : record;
|
|
88
133
|
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor-theme setting, and the two rules that make it safe to offer.
|
|
8
|
+
*
|
|
9
|
+
* A theme is a MODULE that is fetched on selection, so there are two failure
|
|
10
|
+
* modes a unit test can pin without a browser:
|
|
11
|
+
*
|
|
12
|
+
* 1. **The module has to be registered before Shiki can tokenize with it.**
|
|
13
|
+
* `loadTheme` is idempotent, and a second surface selecting the same theme
|
|
14
|
+
* must share the first fetch rather than start a second one.
|
|
15
|
+
* 2. **`auto` must not register anything**, and an id this build does not ship
|
|
16
|
+
* must resolve to no theme rather than leave the editor half-painted.
|
|
17
|
+
*
|
|
18
|
+
* Driven through happy-dom because the hook subscribes to a window event — the
|
|
19
|
+
* same shape the editor FONT uses, and the reason an already-open editor hears
|
|
20
|
+
* about a change at all (`appSettings` is a boot-time prop).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
24
|
+
import { Window } from 'happy-dom';
|
|
25
|
+
import { h, render } from 'preact';
|
|
26
|
+
import { act } from 'preact/test-utils';
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
EDITOR_THEME_CHANGED_EVENT,
|
|
30
|
+
currentEditorThemeId,
|
|
31
|
+
useEditorTheme,
|
|
32
|
+
} from '@/client/hooks/editor/theme';
|
|
33
|
+
import {
|
|
34
|
+
isEditorThemeReady,
|
|
35
|
+
loadEditorTheme,
|
|
36
|
+
onEditorThemeReady,
|
|
37
|
+
resetEditorThemeLoader,
|
|
38
|
+
} from '@/shared/lib/code/editor/theme-loader';
|
|
39
|
+
import { EDITOR_AUTO_THEME_ID, resolveEditorTheme } from '@/shared/lib/code/editor/themes';
|
|
40
|
+
import { bootSyntax, onLanguageReady, requestLanguage } from '@/shared/lib/code/highlighter';
|
|
41
|
+
import { primeKabmoSettings } from '@/shared/lib/settings/client';
|
|
42
|
+
|
|
43
|
+
const DOM_GLOBALS = [
|
|
44
|
+
'window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'CustomEvent',
|
|
45
|
+
'getComputedStyle', 'MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame',
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
/** The runner's own globals, put back once this file's DOM work is done. */
|
|
49
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
50
|
+
|
|
51
|
+
/** happy-dom's `CustomEvent`, so a dispatch is an instance its EventTarget accepts. */
|
|
52
|
+
let Custom: typeof CustomEvent;
|
|
53
|
+
|
|
54
|
+
async function bootTokenizer(): Promise<void> {
|
|
55
|
+
// The highlighter only boots where `window` exists, and the Bun runner has
|
|
56
|
+
// none. Stub it for the boot alone, then hand the global to happy-dom — a
|
|
57
|
+
// `window` left pointing at `globalThis` would make the hook's
|
|
58
|
+
// `dispatchEvent` the runner's, which rejects a happy-dom CustomEvent.
|
|
59
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
60
|
+
const had = 'window' in target ? target.window : undefined;
|
|
61
|
+
target.window = globalThis;
|
|
62
|
+
await bootSyntax();
|
|
63
|
+
if (had === undefined) delete target.window;
|
|
64
|
+
else target.window = had;
|
|
65
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
66
|
+
const settle = () => {
|
|
67
|
+
if (requestLanguage('typescript')) {
|
|
68
|
+
off();
|
|
69
|
+
resolve();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const off = onLanguageReady(settle);
|
|
73
|
+
settle();
|
|
74
|
+
await promise;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
beforeAll(async () => {
|
|
78
|
+
const win = new Window({ url: 'http://localhost' });
|
|
79
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
80
|
+
for (const key of DOM_GLOBALS) {
|
|
81
|
+
if (!(key in native)) native[key] = target[key];
|
|
82
|
+
const value = (win as unknown as Record<string, unknown>)[key];
|
|
83
|
+
if (value !== undefined) target[key] = value;
|
|
84
|
+
}
|
|
85
|
+
Custom = win.CustomEvent as unknown as typeof CustomEvent;
|
|
86
|
+
await bootTokenizer();
|
|
87
|
+
resetEditorThemeLoader();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
afterEach(() => {
|
|
91
|
+
primeKabmoSettings({});
|
|
92
|
+
document.body.innerHTML = '';
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterAll(() => {
|
|
96
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
97
|
+
for (const key of DOM_GLOBALS) {
|
|
98
|
+
if (native[key] === undefined) delete target[key];
|
|
99
|
+
else target[key] = native[key];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
/** A probe that renders exactly what the hook says the surface should paint. */
|
|
104
|
+
function ThemeProbe() {
|
|
105
|
+
const theme = useEditorTheme();
|
|
106
|
+
return h(
|
|
107
|
+
'div',
|
|
108
|
+
{ id: 'probe' },
|
|
109
|
+
`${theme.theme?.id ?? 'auto'}|${theme.vars['--editor-bg'] ?? 'none'}|${theme.themes.light}`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function mountProbe(): Promise<HTMLElement> {
|
|
114
|
+
const host = document.createElement('div');
|
|
115
|
+
document.body.appendChild(host);
|
|
116
|
+
await act(async () => {
|
|
117
|
+
render(h(ThemeProbe, {}), host);
|
|
118
|
+
});
|
|
119
|
+
return host.querySelector('#probe') as HTMLElement;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
describe('currentEditorThemeId', () => {
|
|
123
|
+
test('reads the stored value and falls back to auto', () => {
|
|
124
|
+
primeKabmoSettings({});
|
|
125
|
+
expect(currentEditorThemeId()).toBe(EDITOR_AUTO_THEME_ID);
|
|
126
|
+
|
|
127
|
+
primeKabmoSettings({ kabmo_settings: { editorTheme: 'nord' } });
|
|
128
|
+
expect(currentEditorThemeId()).toBe('nord');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('theme module loading', () => {
|
|
133
|
+
test('auto needs no module, and an unknown id is a no-op', async () => {
|
|
134
|
+
resetEditorThemeLoader();
|
|
135
|
+
await loadEditorTheme(EDITOR_AUTO_THEME_ID);
|
|
136
|
+
expect(isEditorThemeReady(EDITOR_AUTO_THEME_ID)).toBe(true);
|
|
137
|
+
|
|
138
|
+
await loadEditorTheme('no-such-theme');
|
|
139
|
+
expect(isEditorThemeReady('no-such-theme')).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('a shipped theme registers with the highlighter and announces itself', async () => {
|
|
143
|
+
resetEditorThemeLoader();
|
|
144
|
+
const seen: string[] = [];
|
|
145
|
+
const off = onEditorThemeReady((id) => seen.push(id));
|
|
146
|
+
try {
|
|
147
|
+
expect(isEditorThemeReady('nord')).toBe(false);
|
|
148
|
+
await loadEditorTheme('nord');
|
|
149
|
+
expect(isEditorThemeReady('nord')).toBe(true);
|
|
150
|
+
expect(seen).toEqual(['nord']);
|
|
151
|
+
} finally {
|
|
152
|
+
off();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('two requests for one theme share a single registration', async () => {
|
|
157
|
+
resetEditorThemeLoader();
|
|
158
|
+
let announcements = 0;
|
|
159
|
+
const off = onEditorThemeReady(() => announcements++);
|
|
160
|
+
try {
|
|
161
|
+
await Promise.all([loadEditorTheme('dracula'), loadEditorTheme('dracula')]);
|
|
162
|
+
expect(announcements).toBe(1);
|
|
163
|
+
// Already registered: a third call resolves without announcing again.
|
|
164
|
+
await loadEditorTheme('dracula');
|
|
165
|
+
expect(announcements).toBe(1);
|
|
166
|
+
} finally {
|
|
167
|
+
off();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('useEditorTheme', () => {
|
|
173
|
+
test('auto renders no variables and the app’s dual pair', async () => {
|
|
174
|
+
primeKabmoSettings({});
|
|
175
|
+
const probe = await mountProbe();
|
|
176
|
+
expect(probe.textContent).toBe('auto|none|one-light');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('an explicit theme renders its own surface and names itself in both slots', async () => {
|
|
180
|
+
primeKabmoSettings({ kabmo_settings: { editorTheme: 'dracula' } });
|
|
181
|
+
const probe = await mountProbe();
|
|
182
|
+
const theme = resolveEditorTheme('dracula');
|
|
183
|
+
expect(theme).not.toBeNull();
|
|
184
|
+
expect(probe.textContent).toBe(`dracula|${theme!.bg}|dracula`);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('a write reaches an ALREADY-MOUNTED editor without a reload', async () => {
|
|
188
|
+
primeKabmoSettings({});
|
|
189
|
+
const probe = await mountProbe();
|
|
190
|
+
expect(probe.textContent).toBe('auto|none|one-light');
|
|
191
|
+
|
|
192
|
+
// Exactly what the settings modal dispatches on a change.
|
|
193
|
+
await act(async () => {
|
|
194
|
+
window.dispatchEvent(new Custom(EDITOR_THEME_CHANGED_EVENT, { detail: 'nord' }));
|
|
195
|
+
});
|
|
196
|
+
const nord = resolveEditorTheme('nord');
|
|
197
|
+
expect(probe.textContent).toBe(`nord|${nord!.bg}|nord`);
|
|
198
|
+
|
|
199
|
+
// And back to auto, which must clear the variables again rather than leave
|
|
200
|
+
// the previous theme's surface behind.
|
|
201
|
+
await act(async () => {
|
|
202
|
+
window.dispatchEvent(new Custom(EDITOR_THEME_CHANGED_EVENT, { detail: EDITOR_AUTO_THEME_ID }));
|
|
203
|
+
});
|
|
204
|
+
expect(probe.textContent).toBe('auto|none|one-light');
|
|
205
|
+
});
|
|
206
|
+
});
|