@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
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Which published native-shell artifact a browser or an installed shell should
|
|
3
8
|
* download, and whether the installed one is behind.
|
|
@@ -19,11 +24,12 @@
|
|
|
19
24
|
*
|
|
20
25
|
* - `url` is what to download. For the mobile pair it is the artifact itself (an
|
|
21
26
|
* APK the shell installs, an IPA the release page explains). For the DESKTOP
|
|
22
|
-
* trio it is the
|
|
23
|
-
* per-architecture
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
+
* trio it is the artifact when the caller reported its ARCHITECTURE, and the
|
|
28
|
+
* release page otherwise: every desktop artifact is per-architecture, and a
|
|
29
|
+
* console served to another machine cannot guess. Naming the wrong arch's file
|
|
30
|
+
* would hand half the readers a build that will not launch.
|
|
31
|
+
* - `direct` says which of the two `url` is, so the client knows whether the
|
|
32
|
+
* offer can be installed from inside the shell.
|
|
27
33
|
* - `latest` is the version that asset ships, read from the asset NAME (see
|
|
28
34
|
* `shell-assets`). The release TAG cannot be used: the artifact is attached to
|
|
29
35
|
* the app's release, whose tag names the SERVER version.
|
|
@@ -34,10 +40,25 @@
|
|
|
34
40
|
*/
|
|
35
41
|
|
|
36
42
|
import { REPO } from '@/server/lib/updates/release-url';
|
|
37
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
cacheSlot,
|
|
45
|
+
CACHE_MS,
|
|
46
|
+
githubApiBase,
|
|
47
|
+
gitHubHeaders,
|
|
48
|
+
shellCacheKey,
|
|
49
|
+
} from '@/server/lib/updates/shell-cache';
|
|
50
|
+
import { SHELL_ASSETS, selfUpdateArtifact, versionFromAssetName } from '@/server/lib/updates/shell-assets';
|
|
38
51
|
import { findAssetInPages } from '@/server/lib/updates/shell-pages';
|
|
52
|
+
import type { ShellArch } from '@/shared/lib/updates/shell-arch';
|
|
39
53
|
import type { ShellKind } from '@/shared/lib/updates/shell-ua';
|
|
40
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The test seam for the process-wide answer cache, re-exported here because this
|
|
57
|
+
* module is what owns the answers. The cache itself lives next door (`shell-cache`)
|
|
58
|
+
* so its key — shell AND architecture — is stated in one place.
|
|
59
|
+
*/
|
|
60
|
+
export { resetShellReleaseCache } from '@/server/lib/updates/shell-cache';
|
|
61
|
+
|
|
41
62
|
/** One published shell artifact, as the console needs it. */
|
|
42
63
|
export interface ShellRelease {
|
|
43
64
|
/** Asset download URL, or the release page for a per-arch desktop build. */
|
|
@@ -46,8 +67,21 @@ export interface ShellRelease {
|
|
|
46
67
|
latest: string | null;
|
|
47
68
|
/** The release page, for a "what changed" link. */
|
|
48
69
|
releaseUrl: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* True when `url` names the artifact itself rather than the release page.
|
|
72
|
+
*
|
|
73
|
+
* This is what tells the console whether the offer can be INSTALLED from
|
|
74
|
+
* inside the shell. It is true for the mobile pair (one file for every
|
|
75
|
+
* device) and for a desktop shell that reported its architecture — and false
|
|
76
|
+
* for a desktop probe without one, which still gets the page that lists every
|
|
77
|
+
* architecture.
|
|
78
|
+
*/
|
|
79
|
+
direct: boolean;
|
|
49
80
|
}
|
|
50
81
|
|
|
82
|
+
/** The answer a probe gives when it found nothing: a valid result, not an error. */
|
|
83
|
+
const EMPTY_RELEASE: ShellRelease = { url: null, latest: null, releaseUrl: null, direct: false };
|
|
84
|
+
|
|
51
85
|
/**
|
|
52
86
|
* The newest release that actually carries this shell's artifact.
|
|
53
87
|
*
|
|
@@ -57,25 +91,32 @@ export interface ShellRelease {
|
|
|
57
91
|
* `release.yml`), so their `kabmo-sdk/v*` / `kabmo-ui/v*` releases are newer
|
|
58
92
|
* than the app release that carries the shells. `@semantic-release/github` runs
|
|
59
93
|
* in both pipelines, so those are real releases — measured against a stub that
|
|
60
|
-
* answered a package release: `/releases/latest` produced
|
|
61
|
-
*
|
|
62
|
-
*
|
|
94
|
+
* answered a package release: `/releases/latest` produced `{url: null, …}` and
|
|
95
|
+
* the sidebar's button disappeared even though the APK sat on the release
|
|
96
|
+
* directly below.
|
|
97
|
+
*
|
|
98
|
+
* `arch` is what a DESKTOP shell reports about its own machine, and it is the
|
|
99
|
+
* difference between "here is the page, pick your build" and "here is your
|
|
100
|
+
* installer". It is the THIRD parameter so every existing caller — including
|
|
101
|
+
* every test, which passes `fetchImpl` — keeps its shape.
|
|
63
102
|
*
|
|
64
|
-
* Cached for five minutes on `globalThis` for the same
|
|
65
|
-
* handle is anchored there: `bun --hot` re-evaluates this
|
|
66
|
-
* it would otherwise hold lives on.
|
|
103
|
+
* Cached for five minutes on `globalThis` (see `shell-cache`) for the same
|
|
104
|
+
* reason the database handle is anchored there: `bun --hot` re-evaluates this
|
|
105
|
+
* module while the cache it would otherwise hold lives on.
|
|
67
106
|
*/
|
|
68
107
|
export async function fetchShellRelease(
|
|
69
108
|
kind: ShellKind,
|
|
70
109
|
fetchImpl: typeof fetch = fetch,
|
|
110
|
+
arch: ShellArch | null = null,
|
|
71
111
|
): Promise<ShellRelease | null> {
|
|
72
|
-
const cache = cacheSlot(kind);
|
|
112
|
+
const cache = cacheSlot<ShellRelease>(shellCacheKey(kind, arch));
|
|
73
113
|
const now = Date.now();
|
|
74
114
|
if (cache.entry && now - cache.at < CACHE_MS) return cache.entry;
|
|
75
115
|
|
|
76
116
|
const headers = gitHubHeaders();
|
|
77
117
|
const resolved =
|
|
78
|
-
(await readFromApi(kind, fetchImpl, headers)) ??
|
|
118
|
+
(await readFromApi(kind, arch, fetchImpl, headers)) ??
|
|
119
|
+
(await readFromPages(kind, arch, fetchImpl, headers));
|
|
79
120
|
if (!resolved) return cache.entry ?? null;
|
|
80
121
|
|
|
81
122
|
cache.entry = resolved;
|
|
@@ -94,6 +135,7 @@ const RELEASE_SCAN = 20;
|
|
|
94
135
|
*/
|
|
95
136
|
async function readFromApi(
|
|
96
137
|
kind: ShellKind,
|
|
138
|
+
arch: ShellArch | null,
|
|
97
139
|
fetchImpl: typeof fetch,
|
|
98
140
|
headers: Record<string, string>,
|
|
99
141
|
): Promise<ShellRelease | null> {
|
|
@@ -105,8 +147,8 @@ async function readFromApi(
|
|
|
105
147
|
|
|
106
148
|
const body = (await response.json()) as unknown;
|
|
107
149
|
// A body that is not the release list is a failed probe, not an empty
|
|
108
|
-
// repository: answering `{url: null,
|
|
109
|
-
//
|
|
150
|
+
// repository: answering `{url: null, …}` here would be indistinguishable
|
|
151
|
+
// from "no release carries an artifact".
|
|
110
152
|
if (!Array.isArray(body)) return null;
|
|
111
153
|
|
|
112
154
|
// Drafts are not published and prereleases are not what a console offers an
|
|
@@ -117,12 +159,12 @@ async function readFromApi(
|
|
|
117
159
|
);
|
|
118
160
|
|
|
119
161
|
const release = published
|
|
120
|
-
.map((entry) => ({ entry, asset: shellAsset(kind, entry.assets) }))
|
|
162
|
+
.map((entry) => ({ entry, asset: shellAsset(kind, arch, entry.assets) }))
|
|
121
163
|
.find((candidate) => candidate.asset !== null);
|
|
122
164
|
|
|
123
|
-
if (!release?.asset) return
|
|
165
|
+
if (!release?.asset) return EMPTY_RELEASE;
|
|
124
166
|
|
|
125
|
-
return resolvedRelease(kind, {
|
|
167
|
+
return resolvedRelease(kind, arch, {
|
|
126
168
|
name: String(release.asset.name),
|
|
127
169
|
downloadUrl:
|
|
128
170
|
typeof release.asset.browser_download_url === 'string' ? release.asset.browser_download_url : null,
|
|
@@ -136,14 +178,15 @@ async function readFromApi(
|
|
|
136
178
|
/** The public-pages read, wrapped so a failure is the caller's `null`. */
|
|
137
179
|
async function readFromPages(
|
|
138
180
|
kind: ShellKind,
|
|
181
|
+
arch: ShellArch | null,
|
|
139
182
|
fetchImpl: typeof fetch,
|
|
140
183
|
headers: Record<string, string>,
|
|
141
184
|
): Promise<ShellRelease | null> {
|
|
142
185
|
try {
|
|
143
|
-
const found = await findAssetInPages(kind, fetchImpl, headers);
|
|
186
|
+
const found = await findAssetInPages(kind, fetchImpl, headers, arch);
|
|
144
187
|
if (found.kind === 'unreachable') return null;
|
|
145
|
-
if (found.kind === 'none') return
|
|
146
|
-
return resolvedRelease(kind, { ...found.asset, releaseUrl: found.releaseUrl });
|
|
188
|
+
if (found.kind === 'none') return EMPTY_RELEASE;
|
|
189
|
+
return resolvedRelease(kind, arch, { ...found.asset, releaseUrl: found.releaseUrl });
|
|
147
190
|
} catch {
|
|
148
191
|
return null;
|
|
149
192
|
}
|
|
@@ -152,16 +195,26 @@ async function readFromPages(
|
|
|
152
195
|
/**
|
|
153
196
|
* The asset of a release that names this shell's artifact, or null.
|
|
154
197
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
198
|
+
* Two questions, in this order:
|
|
199
|
+
*
|
|
200
|
+
* 1. **Does an architecture match?** When the caller named one, the only
|
|
201
|
+
* acceptable asset is the file that machine installs (`selfUpdateArtifact`).
|
|
202
|
+
* Everything else in the release — the other architecture, the `.dmg`, a
|
|
203
|
+
* `.deb` — is skipped, and the next release is tried.
|
|
204
|
+
* 2. **Which spelling?** The CURRENT scheme wins over the legacy one, and that
|
|
205
|
+
* is not cosmetic. A release that carries both — which happens the moment a
|
|
206
|
+
* rename lands and `--clobber` has not yet replaced the old asset, or a
|
|
207
|
+
* hand-upload adds one beside the other — would otherwise resolve to
|
|
208
|
+
* whichever the asset list happened to order first. Measured: a release
|
|
209
|
+
* holding both `kabmo-android-v0.4.0.apk` and `Kabmo-0.6.0-android.apk`
|
|
210
|
+
* answered `0.4.0`, i.e. the console offered an update to a version it
|
|
211
|
+
* already had and hid the newer one.
|
|
163
212
|
*/
|
|
164
|
-
function shellAsset(
|
|
213
|
+
function shellAsset(
|
|
214
|
+
kind: ShellKind,
|
|
215
|
+
arch: ShellArch | null,
|
|
216
|
+
assets: unknown,
|
|
217
|
+
): Record<string, unknown> | null {
|
|
165
218
|
if (!Array.isArray(assets)) return null;
|
|
166
219
|
|
|
167
220
|
const named = assets.filter(
|
|
@@ -172,95 +225,38 @@ function shellAsset(kind: ShellKind, assets: unknown): Record<string, unknown> |
|
|
|
172
225
|
versionFromAssetName(kind, String((entry as Record<string, unknown>).name)) !== null,
|
|
173
226
|
);
|
|
174
227
|
|
|
228
|
+
if (arch) {
|
|
229
|
+
const exact = named.find(
|
|
230
|
+
(asset) => selfUpdateArtifact(kind, arch, String(asset.name)) !== null,
|
|
231
|
+
);
|
|
232
|
+
if (exact) return exact;
|
|
233
|
+
}
|
|
234
|
+
|
|
175
235
|
return named.find((asset) => SHELL_ASSETS[kind].current.test(String(asset.name))) ?? named[0] ?? null;
|
|
176
236
|
}
|
|
177
237
|
|
|
178
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* Turn one resolved asset into the payload.
|
|
240
|
+
*
|
|
241
|
+
* `direct` is derived from the SAME decision that chose the asset: an arch was
|
|
242
|
+
* named and the asset is that arch's self-update file. Deriving it separately —
|
|
243
|
+
* from `directDownload`, or from the platform — is how the client ends up
|
|
244
|
+
* offering an install for a release page.
|
|
245
|
+
*/
|
|
179
246
|
function resolvedRelease(
|
|
180
247
|
kind: ShellKind,
|
|
248
|
+
arch: ShellArch | null,
|
|
181
249
|
asset: { name: string; downloadUrl: string | null; releaseUrl: string | null },
|
|
182
250
|
): ShellRelease {
|
|
251
|
+
const installable = arch !== null && selfUpdateArtifact(kind, arch, asset.name) !== null;
|
|
252
|
+
const direct = SHELL_ASSETS[kind].directDownload || installable;
|
|
253
|
+
|
|
183
254
|
return {
|
|
184
|
-
// A per-arch desktop build cannot be named
|
|
185
|
-
// comment — so the link is the page that lists every
|
|
186
|
-
url:
|
|
255
|
+
// A per-arch desktop build cannot be named without an architecture — see
|
|
256
|
+
// the module comment — so the link is the page that lists every one.
|
|
257
|
+
url: direct ? asset.downloadUrl : asset.releaseUrl,
|
|
187
258
|
latest: versionFromAssetName(kind, asset.name),
|
|
188
259
|
releaseUrl: asset.releaseUrl,
|
|
260
|
+
direct: direct && asset.downloadUrl !== null,
|
|
189
261
|
};
|
|
190
262
|
}
|
|
191
|
-
|
|
192
|
-
const CACHE_MS = 5 * 60_000;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Where the release read goes.
|
|
196
|
-
*
|
|
197
|
-
* Overridable for the same reason the npm probe honours `NPM_CONFIG_REGISTRY`: a
|
|
198
|
-
* test and a rehearsal need to exercise the real parsing against a stub instead
|
|
199
|
-
* of a live GitHub call, and hardcoding the host makes that impossible without
|
|
200
|
-
* intercepting `fetch` globally.
|
|
201
|
-
*/
|
|
202
|
-
function githubApiBase(): string {
|
|
203
|
-
const configured = Bun.env.KABMO_GITHUB_API ?? '';
|
|
204
|
-
return configured.trim().replace(/\/+$/, '') || 'https://api.github.com';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* A token, when the operator has one, which lifts the API quota from 60 an hour
|
|
209
|
-
* to 5000 — the difference between the precise read working on a shared address
|
|
210
|
-
* and falling through to the pages every time.
|
|
211
|
-
*
|
|
212
|
-
* Read from the environment rather than a setting: it is a deployment fact, it
|
|
213
|
-
* must never reach the browser, and `kabmo serve` already passes its own
|
|
214
|
-
* environment through.
|
|
215
|
-
*/
|
|
216
|
-
function gitHubHeaders(): Record<string, string> {
|
|
217
|
-
const token = (Bun.env.KABMO_GITHUB_TOKEN ?? Bun.env.GITHUB_TOKEN ?? '').trim();
|
|
218
|
-
const headers: Record<string, string> = {
|
|
219
|
-
// GitHub rejects a request with no User-Agent.
|
|
220
|
-
'user-agent': 'kabmo-console',
|
|
221
|
-
};
|
|
222
|
-
if (token) headers.authorization = `Bearer ${token}`;
|
|
223
|
-
return headers;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
interface CacheSlot {
|
|
227
|
-
entry: ShellRelease | null;
|
|
228
|
-
at: number;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
type ShellCacheHost = typeof globalThis & {
|
|
232
|
-
__kabmoShellRelease?: Partial<Record<ShellKind, CacheSlot>>;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* The cache slot for one shell.
|
|
237
|
-
*
|
|
238
|
-
* PER SHELL, not one shared slot: both probes read the same release list but
|
|
239
|
-
* resolve different assets, so one slot would make the second shell answer with
|
|
240
|
-
* the first one's artifact.
|
|
241
|
-
*/
|
|
242
|
-
function cacheSlot(kind: ShellKind): CacheSlot {
|
|
243
|
-
const host = globalThis as ShellCacheHost;
|
|
244
|
-
host.__kabmoShellRelease ??= {};
|
|
245
|
-
host.__kabmoShellRelease[kind] ??= { entry: null, at: 0 };
|
|
246
|
-
return host.__kabmoShellRelease[kind] as CacheSlot;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Drop the cached answer for one shell (or every shell, with no argument).
|
|
251
|
-
*
|
|
252
|
-
* The cache lives on `globalThis` so `bun --hot` cannot orphan it, which also
|
|
253
|
-
* means it outlives a test file: without this seam the second case in a suite
|
|
254
|
-
* reads the first case's answer and passes for the wrong reason (measured — the
|
|
255
|
-
* "malformed body" case returned the previous test's release). Production has
|
|
256
|
-
* no caller; it exists because the cache is process-wide by design.
|
|
257
|
-
*/
|
|
258
|
-
export function resetShellReleaseCache(kind?: ShellKind): void {
|
|
259
|
-
const host = globalThis as ShellCacheHost;
|
|
260
|
-
if (!kind) {
|
|
261
|
-
host.__kabmoShellRelease = {};
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
host.__kabmoShellRelease ??= {};
|
|
265
|
-
host.__kabmoShellRelease[kind] = { entry: null, at: 0 };
|
|
266
|
-
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Save As, against the real handler.
|
|
8
|
+
*
|
|
9
|
+
* Three rules, each of which a careless implementation gets wrong: an existing destination
|
|
10
|
+
* is REFUSED (overwriting is what `save` is for), the name must be ONE segment (a
|
|
11
|
+
* separator would reach outside the directory the dialog named), and the new file is
|
|
12
|
+
* written with the requested line ending — the same rebuild `save` does, because a
|
|
13
|
+
* multipart body normalizes bare LF.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import fs from 'fs';
|
|
18
|
+
import path from 'path';
|
|
19
|
+
|
|
20
|
+
import { action } from '@/server/routes/fs/action';
|
|
21
|
+
|
|
22
|
+
/** Probe files live in the repo root — the one directory the root allow-list always accepts. */
|
|
23
|
+
const ROOT = process.cwd();
|
|
24
|
+
const PROBE = path.join(ROOT, 'tmp-save-as-probe.ts');
|
|
25
|
+
const COPY = path.join(ROOT, 'tmp-save-as-probe copy.ts');
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
fs.rmSync(PROBE, { force: true });
|
|
29
|
+
fs.rmSync(COPY, { force: true });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function saveAs(fields: { path?: string; name: string; content?: string; eol?: string }) {
|
|
33
|
+
const form = new FormData();
|
|
34
|
+
form.append('actionType', 'saveAs');
|
|
35
|
+
form.append('root', ROOT);
|
|
36
|
+
form.append('path', fields.path ?? '.');
|
|
37
|
+
form.append('name', fields.name);
|
|
38
|
+
form.append('content', fields.content ?? 'a\nb\n');
|
|
39
|
+
if (fields.eol) form.append('eol', fields.eol);
|
|
40
|
+
return action({ request: new Request('http://localhost/api/fs/action', { method: 'POST', body: form }) } as never);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('fs saveAs', () => {
|
|
44
|
+
test('writes a new file and answers its workspace-relative path', async () => {
|
|
45
|
+
const res = await saveAs({ name: 'tmp-save-as-probe.ts', content: 'const a = 1;\n', eol: 'lf' });
|
|
46
|
+
expect(res.status).toBe(200);
|
|
47
|
+
const body = (await res.json()) as { success?: boolean; path?: string };
|
|
48
|
+
expect(body.success).toBe(true);
|
|
49
|
+
expect(body.path).toBe('tmp-save-as-probe.ts');
|
|
50
|
+
expect(fs.readFileSync(PROBE, 'utf8')).toBe('const a = 1;\n');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('an existing destination is a 409 and its bytes are untouched', async () => {
|
|
54
|
+
fs.writeFileSync(PROBE, 'original\n');
|
|
55
|
+
const res = await saveAs({ name: 'tmp-save-as-probe.ts', content: 'replacement\n', eol: 'lf' });
|
|
56
|
+
expect(res.status).toBe(409);
|
|
57
|
+
expect(((await res.json()) as { error?: string }).error).toContain('already exists');
|
|
58
|
+
// The refusal is the point: an overwrite is what `save` is for.
|
|
59
|
+
expect(fs.readFileSync(PROBE, 'utf8')).toBe('original\n');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('a name carrying a separator is refused before anything is written', async () => {
|
|
63
|
+
for (const name of ['nested/probe.ts', '..', '.', '']) {
|
|
64
|
+
const res = await saveAs({ name, content: 'x' });
|
|
65
|
+
expect(res.status).toBe(400);
|
|
66
|
+
}
|
|
67
|
+
expect(fs.existsSync(PROBE)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('the requested line ending is what lands on disk', async () => {
|
|
71
|
+
await saveAs({ name: 'tmp-save-as-probe.ts', content: 'a\nb\n', eol: 'crlf' });
|
|
72
|
+
expect([...fs.readFileSync(PROBE)]).toEqual([0x61, 0x0d, 0x0a, 0x62, 0x0d, 0x0a]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a subdirectory destination is created when it does not exist', async () => {
|
|
76
|
+
const res = await saveAs({ name: 'tmp-save-as-probe.ts', path: 'tmp-save-as-dir', content: 'x', eol: 'lf' });
|
|
77
|
+
expect(res.status).toBe(200);
|
|
78
|
+
const written = path.join(ROOT, 'tmp-save-as-dir', 'tmp-save-as-probe.ts');
|
|
79
|
+
expect(fs.readFileSync(written, 'utf8')).toBe('x');
|
|
80
|
+
fs.rmSync(path.join(ROOT, 'tmp-save-as-dir'), { recursive: true, force: true });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -62,3 +62,85 @@ describe('fs save line endings', () => {
|
|
|
62
62
|
expect([...bytes]).toEqual([0x61, 0x0d, 0x0a, 0x62, 0x0d, 0x0a]);
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The conflict contract, against the real handler.
|
|
68
|
+
*
|
|
69
|
+
* A save that names the mtime it was built from must be REFUSED when the disk has
|
|
70
|
+
* moved — that is the whole point, and it is the branch a unit test on
|
|
71
|
+
* `checkWriteConflict` cannot prove because it never reaches the route. The three
|
|
72
|
+
* "must still write" branches matter just as much: a guard that refuses a legitimate
|
|
73
|
+
* save is worse than no guard.
|
|
74
|
+
*/
|
|
75
|
+
describe('fs save conflict', () => {
|
|
76
|
+
const CONFLICT = path.join(process.cwd(), 'tmp-conflict-probe.ts');
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
fs.rmSync(CONFLICT, { force: true });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
async function saveWith(baseMtime: number | undefined, content: string) {
|
|
83
|
+
const form = new FormData();
|
|
84
|
+
form.append('actionType', 'save');
|
|
85
|
+
form.append('root', process.cwd());
|
|
86
|
+
form.append('path', 'tmp-conflict-probe.ts');
|
|
87
|
+
form.append('content', content);
|
|
88
|
+
form.append('eol', 'lf');
|
|
89
|
+
if (baseMtime !== undefined) form.append('baseMtime', String(baseMtime));
|
|
90
|
+
return action({ request: new Request('http://localhost/api/fs/action', { method: 'POST', body: form }) } as never);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
test('a matching base writes and answers the mtime it wrote', async () => {
|
|
94
|
+
fs.writeFileSync(CONFLICT, 'first\n');
|
|
95
|
+
const base = Math.round(fs.statSync(CONFLICT).mtimeMs);
|
|
96
|
+
const res = await saveWith(base, 'mine\n');
|
|
97
|
+
expect(res.status).toBe(200);
|
|
98
|
+
const body = (await res.json()) as { success?: boolean; mtimeMs?: number };
|
|
99
|
+
expect(body.success).toBe(true);
|
|
100
|
+
expect(typeof body.mtimeMs).toBe('number');
|
|
101
|
+
expect(fs.readFileSync(CONFLICT, 'utf8')).toBe('mine\n');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('a base the disk moved past is a 409, and NOTHING is written', async () => {
|
|
105
|
+
fs.writeFileSync(CONFLICT, 'first\n');
|
|
106
|
+
const base = Math.round(fs.statSync(CONFLICT).mtimeMs);
|
|
107
|
+
// Another writer — an agent, another tab — moves the file. The mtime is set
|
|
108
|
+
// explicitly rather than by writing again: two writes inside one millisecond
|
|
109
|
+
// leave `mtimeMs` identical, which is the documented limit of this guard (see
|
|
110
|
+
// `write-conflict.ts`) rather than something a test should paper over.
|
|
111
|
+
fs.writeFileSync(CONFLICT, 'theirs\n');
|
|
112
|
+
const moved = new Date(base + 5_000);
|
|
113
|
+
fs.utimesSync(CONFLICT, moved, moved);
|
|
114
|
+
const res = await saveWith(base, 'mine again\n');
|
|
115
|
+
expect(res.status).toBe(409);
|
|
116
|
+
const body = (await res.json()) as { conflict?: boolean; mtimeMs?: number };
|
|
117
|
+
expect(body.conflict).toBe(true);
|
|
118
|
+
expect(typeof body.mtimeMs).toBe('number');
|
|
119
|
+
// The refusal is the point: the other writer's bytes survive.
|
|
120
|
+
expect(fs.readFileSync(CONFLICT, 'utf8')).toBe('theirs\n');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('no base writes unconditionally — a handle-backed file and an older client', async () => {
|
|
124
|
+
fs.writeFileSync(CONFLICT, 'first\n');
|
|
125
|
+
expect((await saveWith(undefined, 'no base\n')).status).toBe(200);
|
|
126
|
+
expect(fs.readFileSync(CONFLICT, 'utf8')).toBe('no base\n');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('a base the disk agrees with after adoption writes — the "Keep mine" retry', async () => {
|
|
130
|
+
fs.writeFileSync(CONFLICT, 'first\n');
|
|
131
|
+
fs.writeFileSync(CONFLICT, 'theirs\n');
|
|
132
|
+
const moved = new Date(Date.now() + 5_000);
|
|
133
|
+
fs.utimesSync(CONFLICT, moved, moved);
|
|
134
|
+
const adopted = Math.round(fs.statSync(CONFLICT).mtimeMs);
|
|
135
|
+
expect((await saveWith(adopted, 'adopted\n')).status).toBe(200);
|
|
136
|
+
expect(fs.readFileSync(CONFLICT, 'utf8')).toBe('adopted\n');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('a base with the file DELETED recreates it — recreating is the user’s decision', async () => {
|
|
140
|
+
fs.writeFileSync(CONFLICT, 'first\n');
|
|
141
|
+
const base = Math.round(fs.statSync(CONFLICT).mtimeMs);
|
|
142
|
+
fs.rmSync(CONFLICT, { force: true });
|
|
143
|
+
expect((await saveWith(base, 'recreated\n')).status).toBe(200);
|
|
144
|
+
expect(fs.readFileSync(CONFLICT, 'utf8')).toBe('recreated\n');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -8,6 +8,8 @@ import { runShell } from '@/server/lib/fs/shell';
|
|
|
8
8
|
import { revealInFileManager } from '@/server/lib/fs/reveal';
|
|
9
9
|
import { duplicateEntry, nextDuplicateName, pasteEntry, toRelPath } from '@/server/lib/fs/transfer';
|
|
10
10
|
import { normalizeRelativePath } from '@/server/lib/fs/relative-path';
|
|
11
|
+
import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
|
|
12
|
+
import { checkWriteConflict, parseBaseMtime, stableMtime } from '@/server/lib/fs/write-conflict';
|
|
11
13
|
import { transferRefusal } from '@/shared/lib/fs/clipboard';
|
|
12
14
|
import { toDiskText } from '@/shared/lib/code/line-endings';
|
|
13
15
|
|
|
@@ -101,9 +103,60 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
101
103
|
// CRLF and show up as a full-file diff. `eol` is the ending the client
|
|
102
104
|
// read the file with; without it the payload is written untouched.
|
|
103
105
|
const content = eol === 'crlf' || eol === 'lf' ? toDiskText(raw, eol) : raw;
|
|
106
|
+
// The buffer names the mtime it was read from. A file that moved since then
|
|
107
|
+
// is a CONFLICT, not a failure: the verdict carries the current value so the
|
|
108
|
+
// panel can offer Reload/Keep. A save with no base — a handle-backed file, an
|
|
109
|
+
// older client — writes unconditionally, which is the pre-existing contract.
|
|
110
|
+
const verdict = await checkWriteConflict(
|
|
111
|
+
fullPath,
|
|
112
|
+
parseBaseMtime(formData.get('baseMtime')),
|
|
113
|
+
async (target) => {
|
|
114
|
+
const stat = await Bun.file(target).stat().catch(() => null);
|
|
115
|
+
return stat && !stat.isDirectory() ? { mtimeMs: stat.mtimeMs } : null;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
if (!verdict.write) {
|
|
119
|
+
return json(
|
|
120
|
+
{
|
|
121
|
+
error: 'This file changed on disk since it was opened.',
|
|
122
|
+
conflict: true,
|
|
123
|
+
mtimeMs: verdict.diskMtimeMs,
|
|
124
|
+
},
|
|
125
|
+
{ status: 409 },
|
|
126
|
+
);
|
|
127
|
+
}
|
|
104
128
|
await fs.promises.mkdir(path.dirname(fullPath), { recursive: true });
|
|
105
129
|
await Bun.write(fullPath, content);
|
|
106
|
-
|
|
130
|
+
const written = await Bun.file(fullPath).stat().catch(() => null);
|
|
131
|
+
return json({ success: true, mtimeMs: written ? stableMtime(written.mtimeMs) : null });
|
|
132
|
+
} else if (actionType === 'saveAs') {
|
|
133
|
+
// Write the buffer to a NEW path. The destination is `path` (a directory) plus
|
|
134
|
+
// `name` (ONE segment), both resolved against this route's own scope — a
|
|
135
|
+
// client-supplied absolute path is exactly the shape that would write outside the
|
|
136
|
+
// workspace, so it is never trusted.
|
|
137
|
+
//
|
|
138
|
+
// No `baseMtime`: a file that did not exist a moment ago has nothing to compare
|
|
139
|
+
// against, and sending the ORIGINAL's mtime would refuse every Save As.
|
|
140
|
+
const directory = (formData.get('path') as string) ?? '';
|
|
141
|
+
const name = ((formData.get('name') as string) ?? '').trim();
|
|
142
|
+
if (!isSinglePathSegment(name)) {
|
|
143
|
+
return json({ error: 'Enter a file name without a path separator' }, { status: 400 });
|
|
144
|
+
}
|
|
145
|
+
const destination = resolveWithinRoot(scopedRoot, path.join(directory || '.', name));
|
|
146
|
+
if (!destination) return json({ error: 'Invalid path' }, { status: 403 });
|
|
147
|
+
// An existing destination is REFUSED, not overwritten: overwriting is what `save`
|
|
148
|
+
// is for, and a dialog that silently replaced a file the user did not name is the
|
|
149
|
+
// worst outcome of a mis-click. The same rule `create` applies.
|
|
150
|
+
if ((await Bun.file(destination).stat().catch(() => null)) !== null) {
|
|
151
|
+
return json({ error: `${name} already exists` }, { status: 409 });
|
|
152
|
+
}
|
|
153
|
+
const raw = (formData.get('content') as string) ?? '';
|
|
154
|
+
const eol = formData.get('eol');
|
|
155
|
+
const content = eol === 'crlf' || eol === 'lf' ? toDiskText(raw, eol) : raw;
|
|
156
|
+
await fs.promises.mkdir(path.dirname(destination), { recursive: true });
|
|
157
|
+
await Bun.write(destination, content);
|
|
158
|
+
// Relative to the LISTED root, which is the identity a tab needs.
|
|
159
|
+
return json({ success: true, path: toRelPath(scopedRoot, destination) });
|
|
107
160
|
} else if (actionType === 'create') {
|
|
108
161
|
// The Files panel's "New file"/"New folder": an empty entry beside the
|
|
109
162
|
// folder that was right-clicked. The NAME may carry segments
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { json, type LoaderFunctionArgs } from '@/server/lib/remix-compat';
|
|
23
23
|
import { isMockMode } from '@/server/mock.server';
|
|
24
24
|
import { getDefaultFsRoot, resolveRoot, resolveWithinRoot } from '@/server/lib/fs/root';
|
|
25
|
+
import { stableMtime } from '@/server/lib/fs/write-conflict';
|
|
25
26
|
|
|
26
27
|
export async function fileExists({ request }: LoaderFunctionArgs) {
|
|
27
28
|
const url = new URL(request.url);
|
|
@@ -48,6 +49,15 @@ export async function fileExists({ request }: LoaderFunctionArgs) {
|
|
|
48
49
|
// about a folder only by accident. The question here is whether the FILE the
|
|
49
50
|
// tab names is still there, so a folder standing in its place is a "no" —
|
|
50
51
|
// the file was deleted and something else took its path.
|
|
52
|
+
//
|
|
53
|
+
// The mtime travels beside the answer because the editor's change detection asks
|
|
54
|
+
// this exact question — "does the file the buffer came from still look like the
|
|
55
|
+
// one it read?" — and a second route for one `stat` would be a second scope
|
|
56
|
+
// check to keep in step. `null` when there is no file to report on.
|
|
51
57
|
const stat = await Bun.file(fullPath).stat().catch(() => null);
|
|
52
|
-
|
|
58
|
+
const exists = stat !== null && !stat.isDirectory();
|
|
59
|
+
// Rounded to a whole millisecond: `node:fs` and `Bun.file()` disagree on the
|
|
60
|
+
// fractional part, and the editor compares this value against the one the read
|
|
61
|
+
// route reported. See `stableMtime`.
|
|
62
|
+
return json({ exists, mtimeMs: exists ? stableMtime(stat.mtimeMs) : null });
|
|
53
63
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* answers "no <op> in progress" and only `reset --merge HEAD` clears it.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { afterAll, describe, expect, test } from 'bun:test';
|
|
22
|
+
import { afterAll, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
|
23
23
|
import fs from 'node:fs';
|
|
24
24
|
import path from 'node:path';
|
|
25
25
|
import { action } from '@/server/routes/fs/git';
|
|
@@ -36,6 +36,16 @@ import { removeDir } from '@/test-support/remove-dir';
|
|
|
36
36
|
* action ran against THE Kabmo REPOSITORY.
|
|
37
37
|
*/
|
|
38
38
|
const FIXTURE_ROOT = path.join(process.cwd(), 'tmp-test-git-merge');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Every case here builds a real repository and drives several `git` processes
|
|
42
|
+
* through it, so Bun's 5s per-test default is a budget for the RUNNER rather
|
|
43
|
+
* than for the code. Measured on a loaded CI runner: the cherry-pick case alone
|
|
44
|
+
* spent 5.0s and timed out, while the same commit passed the `Checks` job and
|
|
45
|
+
* failed the `Release` one minutes later — the same suite, two machines, one
|
|
46
|
+
* answer each. `git-actions-sync.test.ts` sets the same 30s for the same reason.
|
|
47
|
+
*/
|
|
48
|
+
setDefaultTimeout(30_000);
|
|
39
49
|
const repos: string[] = [];
|
|
40
50
|
|
|
41
51
|
function git(cwd: string, ...args: string[]): string {
|