@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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Files panel's COLLAPSED folder chains.
|
|
8
|
+
*
|
|
9
|
+
* A folder that holds exactly one folder and nothing else is drawn as a single
|
|
10
|
+
* row naming the whole chain (`com/java/app/package`), because a row per
|
|
11
|
+
* directory level spends four rows to reach the files inside and every editor
|
|
12
|
+
* folds that. The server collapses the same chains when it lists a directory
|
|
13
|
+
* (`folderChain`, `lib/fs/listing.ts`); this half exists for the trees the
|
|
14
|
+
* CLIENT builds — a create or a rename inserts a chain the server has not
|
|
15
|
+
* listed yet — and it is applied by `rehydrateTree`, which is the one function
|
|
16
|
+
* that builds a rendered tree.
|
|
17
|
+
*
|
|
18
|
+
* Split from `file-tree.ts` (which owns the edits) because the two rules are
|
|
19
|
+
* read by different callers: the panel's listing hook needs the fold and the
|
|
20
|
+
* reveal, while the create/rename paths need the placement.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { FsNode } from '@/shared/types';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collapse a folder that holds exactly one FOLDER and nothing else into that
|
|
27
|
+
* child, so one row names the whole chain.
|
|
28
|
+
*
|
|
29
|
+
* The folded row's IDENTITY is the deepest directory — that is what its
|
|
30
|
+
* children are, what an expand reads, and what a rename, delete or drag acts
|
|
31
|
+
* on. Only its `name` carries the chain, so the label says where the row is.
|
|
32
|
+
*
|
|
33
|
+
* A folder whose children are NOT loaded cannot fold: the client does not know
|
|
34
|
+
* whether it holds one folder or forty files, and guessing would hide a listing
|
|
35
|
+
* the server never produced.
|
|
36
|
+
*/
|
|
37
|
+
export function foldSingleChildFolders(nodes: FsNode[]): FsNode[] {
|
|
38
|
+
const next = nodes.map(foldNode);
|
|
39
|
+
// Identity is what the row components diff on, so an unchanged list keeps its
|
|
40
|
+
// own array rather than re-rendering every row on every commit.
|
|
41
|
+
return next.some((node, index) => node !== nodes[index]) ? next : nodes;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function foldNode(node: FsNode): FsNode {
|
|
45
|
+
if (node.type !== 'folder' || !Array.isArray(node.children)) return node;
|
|
46
|
+
const children = foldSingleChildFolders(node.children);
|
|
47
|
+
let current: FsNode = children === node.children ? node : { ...node, children };
|
|
48
|
+
while (Array.isArray(current.children) && current.children.length === 1) {
|
|
49
|
+
const only = current.children[0];
|
|
50
|
+
if (only.type !== 'folder') break;
|
|
51
|
+
current = {
|
|
52
|
+
...current,
|
|
53
|
+
name: `${current.name}/${only.name}`,
|
|
54
|
+
path: only.path,
|
|
55
|
+
children: only.children,
|
|
56
|
+
// The row names the deepest directory now, so that is the one whose
|
|
57
|
+
// git-ignore answer it wears (a rule matching an outer level matches it
|
|
58
|
+
// too — verified against `git check-ignore`).
|
|
59
|
+
ignored: only.ignored ?? current.ignored,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return current;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The paths of the DRAWN rows that contain `path`, outermost first.
|
|
67
|
+
*
|
|
68
|
+
* This is what a reveal expands. It cannot be the path's own segments: a
|
|
69
|
+
* collapsed chain is one row whose path is the deepest directory, so `lib` and
|
|
70
|
+
* `lib/deep` are not rows at all — expanding them would leave the expansion set
|
|
71
|
+
* holding paths nothing draws, which the next refresh then re-reads from disk
|
|
72
|
+
* for nothing.
|
|
73
|
+
*/
|
|
74
|
+
export function drawnAncestors(nodes: FsNode[], path: string): string[] {
|
|
75
|
+
const folders = new Set<string>();
|
|
76
|
+
const walk = (list: FsNode[]) => {
|
|
77
|
+
for (const node of list) {
|
|
78
|
+
if (node.type !== 'folder') continue;
|
|
79
|
+
folders.add(node.path);
|
|
80
|
+
if (Array.isArray(node.children)) walk(node.children);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
walk(nodes);
|
|
84
|
+
const segments = path.split('/').slice(0, -1);
|
|
85
|
+
const ancestors: string[] = [];
|
|
86
|
+
for (let i = 0; i < segments.length; i += 1) {
|
|
87
|
+
const prefix = segments.slice(0, i + 1).join('/');
|
|
88
|
+
if (folders.has(prefix)) ancestors.push(prefix);
|
|
89
|
+
}
|
|
90
|
+
return ancestors;
|
|
91
|
+
}
|
|
@@ -22,7 +22,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
22
22
|
import type { FsNode } from '@/shared/types';
|
|
23
23
|
import { COMMIT_PAGE_SIZE } from '@/shared/lib/fs/commit-page';
|
|
24
24
|
import { normalizeCommits } from '@/shared/lib/fs/commit-row';
|
|
25
|
-
import { rehydrateTree
|
|
25
|
+
import { rehydrateTree } from '@/shared/lib/fs/file-tree';
|
|
26
26
|
import { buildFsRawUrl, toAbsolutePath } from '@/shared/lib/fs/paths';
|
|
27
27
|
|
|
28
28
|
const file = (path: string): FsNode => ({ name: path.split('/').pop() ?? path, path, type: 'file' });
|
|
@@ -111,53 +111,6 @@ describe('toAbsolutePath', () => {
|
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
describe('setChildrenAt', () => {
|
|
115
|
-
test('the matching node receives the new children', () => {
|
|
116
|
-
const tree = [folder('a', [file('a/x.ts')]), file('b.ts')];
|
|
117
|
-
const result = setChildrenAt(tree, 'a', [file('a/y.ts')]);
|
|
118
|
-
expect(result[0].children?.map(c => c.path)).toEqual(['a/y.ts']);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('a nested folder is patched at any depth', () => {
|
|
122
|
-
const tree = [folder('a', [folder('a/b', [file('a/b/c.ts')])])];
|
|
123
|
-
const result = setChildrenAt(tree, 'a/b', [file('a/b/d.ts')]);
|
|
124
|
-
expect(result[0].children?.[0].children?.map(c => c.path)).toEqual(['a/b/d.ts']);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('the original tree is never mutated', () => {
|
|
128
|
-
const tree = [folder('a', [file('a/x.ts')])];
|
|
129
|
-
setChildrenAt(tree, 'a', [file('a/y.ts')]);
|
|
130
|
-
expect(tree[0].children?.map(c => c.path)).toEqual(['a/x.ts']);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('unrelated file nodes keep their identity', () => {
|
|
134
|
-
const tree = [folder('a', [file('a/x.ts')]), file('b.ts')];
|
|
135
|
-
const result = setChildrenAt(tree, 'a/x.ts', []);
|
|
136
|
-
expect(result[1]).toBe(tree[1]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test('a path that does not exist leaves the shape unchanged', () => {
|
|
140
|
-
const tree = [folder('a', [file('a/x.ts')]), file('b.ts')];
|
|
141
|
-
const result = setChildrenAt(tree, 'missing', []);
|
|
142
|
-
expect(result[0].children?.[0]).toBe(tree[0].children?.[0]);
|
|
143
|
-
expect(result[1]).toBe(tree[1]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('a folder without a children array is left alone on a miss', () => {
|
|
147
|
-
const childless: FsNode = { name: 'a', path: 'a', type: 'folder' };
|
|
148
|
-
const result = setChildrenAt([childless], 'other', []);
|
|
149
|
-
expect(result[0]).toBe(childless);
|
|
150
|
-
expect(result[0].children).toBeUndefined();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('a folder without a children array can still be given children', () => {
|
|
154
|
-
const childless: FsNode = { name: 'a', path: 'a', type: 'folder' };
|
|
155
|
-
const result = setChildrenAt([childless], 'a', [file('a/x.ts')]);
|
|
156
|
-
expect(result[0].children?.map(c => c.path)).toEqual(['a/x.ts']);
|
|
157
|
-
expect(childless.children).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
114
|
describe('rehydrateTree', () => {
|
|
162
115
|
test('a cached folder gets its children back', () => {
|
|
163
116
|
const cache = { a: [file('a/x.ts')] };
|
|
@@ -166,9 +119,10 @@ describe('rehydrateTree', () => {
|
|
|
166
119
|
});
|
|
167
120
|
|
|
168
121
|
test('nested cached folders are rehydrated recursively', () => {
|
|
169
|
-
const cache = { a: [folder('a/b', [])], 'a/b': [file('a/b/c.ts')] };
|
|
122
|
+
const cache = { a: [folder('a/b', []), file('a/y.ts')], 'a/b': [file('a/b/c.ts')] };
|
|
170
123
|
const result = rehydrateTree([folder('a', [])], cache);
|
|
171
|
-
|
|
124
|
+
const nested = result[0].children?.find((child) => child.path === 'a/b');
|
|
125
|
+
expect(nested?.children?.map(c => c.path)).toEqual(['a/b/c.ts']);
|
|
172
126
|
});
|
|
173
127
|
|
|
174
128
|
test('an uncached folder keeps its own children untouched', () => {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A unified patch → the two documents it compares.
|
|
8
|
+
*
|
|
9
|
+
* What this pins is the shape a chat tool card depends on: a card has a PATCH
|
|
10
|
+
* and no files, and it draws the same merge surface the diff panel does — so the
|
|
11
|
+
* sides it hands over must be exactly what the patch says they were. A context
|
|
12
|
+
* row belongs to both, a `-` row only to the original, a `+` row only to the new
|
|
13
|
+
* one; everything else (the `diff --git` header, `index`, `---`/`+++`, mode and
|
|
14
|
+
* rename lines, the "No newline" marker) is metadata and must not appear in
|
|
15
|
+
* either document.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, expect, test } from 'bun:test';
|
|
19
|
+
|
|
20
|
+
import { patchSides } from '@/shared/lib/fs/patch-sides';
|
|
21
|
+
|
|
22
|
+
const GIT_DIFF = [
|
|
23
|
+
'diff --git a/src/a.ts b/src/a.ts',
|
|
24
|
+
'index 1111111..2222222 100644',
|
|
25
|
+
'--- a/src/a.ts',
|
|
26
|
+
'+++ b/src/a.ts',
|
|
27
|
+
'@@ -1,3 +1,3 @@',
|
|
28
|
+
' const one = 1;',
|
|
29
|
+
'-const two = 2;',
|
|
30
|
+
'+const two = 22;',
|
|
31
|
+
' const three = 3;',
|
|
32
|
+
'',
|
|
33
|
+
].join('\n');
|
|
34
|
+
|
|
35
|
+
describe('patchSides', () => {
|
|
36
|
+
test('splits a git diff into the documents it compares', () => {
|
|
37
|
+
const sides = patchSides(GIT_DIFF);
|
|
38
|
+
|
|
39
|
+
expect(sides.original).toBe('const one = 1;\nconst two = 2;\nconst three = 3;');
|
|
40
|
+
expect(sides.next).toBe('const one = 1;\nconst two = 22;\nconst three = 3;');
|
|
41
|
+
expect(sides.additions).toBe(1);
|
|
42
|
+
expect(sides.deletions).toBe(1);
|
|
43
|
+
expect(sides.hasHunk).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('keeps the header lines out of both documents', () => {
|
|
47
|
+
// A `--- a/x` header would otherwise land in the original as `-- a/x`, and
|
|
48
|
+
// the merge view would draw a chunk that is not a change.
|
|
49
|
+
const sides = patchSides(GIT_DIFF);
|
|
50
|
+
for (const line of ['diff --git', 'index ', '--- a/', '+++ b/']) {
|
|
51
|
+
expect(sides.original.includes(line)).toBe(false);
|
|
52
|
+
expect(sides.next.includes(line)).toBe(false);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a new file has an empty original and the whole new document', () => {
|
|
57
|
+
const sides = patchSides(['@@ -0,0 +1,2 @@', '+alpha', '+beta'].join('\n'));
|
|
58
|
+
|
|
59
|
+
expect(sides.original).toBe('');
|
|
60
|
+
expect(sides.next).toBe('alpha\nbeta');
|
|
61
|
+
expect(sides.additions).toBe(2);
|
|
62
|
+
expect(sides.deletions).toBe(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a deleted file is the mirror image', () => {
|
|
66
|
+
const sides = patchSides(['@@ -1,1 +0,0 @@', '-gone'].join('\n'));
|
|
67
|
+
|
|
68
|
+
expect(sides.original).toBe('gone');
|
|
69
|
+
expect(sides.next).toBe('');
|
|
70
|
+
expect(sides.deletions).toBe(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a header-only patch has no rows, so the caller can fall back to text', () => {
|
|
74
|
+
const sides = patchSides('--- a/x\n+++ b/x\n');
|
|
75
|
+
|
|
76
|
+
expect(sides.rows).toBe(0);
|
|
77
|
+
expect(sides.hasHunk).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('an empty patch is the empty answer, not a one-line document', () => {
|
|
81
|
+
expect(patchSides('')).toEqual({ original: '', next: '', additions: 0, deletions: 0, rows: 0, hasHunk: false });
|
|
82
|
+
expect(patchSides(' \n')).toEqual({ original: '', next: '', additions: 0, deletions: 0, rows: 0, hasHunk: false });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('counts rows without the blank line a trailing newline leaves behind', () => {
|
|
86
|
+
const sides = patchSides(['@@ -1 +1 @@', '-a', '+b'].join('\n'));
|
|
87
|
+
|
|
88
|
+
expect(sides.rows).toBe(2);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('a hunk starting mid-file keeps its real line numbers', () => {
|
|
92
|
+
// Without the padding the change would be line 1 of the rebuilt document,
|
|
93
|
+
// and the card's gutter would name a line the file does not have it on.
|
|
94
|
+
const sides = patchSides(['@@ -43,2 +43,2 @@', ' context', '-old', '+new'].join('\n'));
|
|
95
|
+
|
|
96
|
+
expect(sides.original.split('\n')).toHaveLength(44);
|
|
97
|
+
expect(sides.original.split('\n')[42]).toBe('context');
|
|
98
|
+
expect(sides.original.split('\n')[43]).toBe('old');
|
|
99
|
+
expect(sides.next.split('\n')[43]).toBe('new');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('the gap between two hunks is restored from their own headers', () => {
|
|
103
|
+
const sides = patchSides(
|
|
104
|
+
['@@ -2,1 +2,1 @@', '-a', '+b', '@@ -10,1 +10,1 @@', '-c', '+d'].join('\n'),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// Line 2 is the first change, line 10 the second, and everything between is
|
|
108
|
+
// unchanged content the patch did not carry.
|
|
109
|
+
const original = sides.original.split('\n');
|
|
110
|
+
expect(original[1]).toBe('a');
|
|
111
|
+
expect(original[9]).toBe('c');
|
|
112
|
+
expect(original).toHaveLength(10);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A unified patch as its two DOCUMENTS.
|
|
8
|
+
*
|
|
9
|
+
* This replaced a table parser (`diff-parser.ts`) that produced per-row line
|
|
10
|
+
* numbers and paired split-view rows. Both of those are now the merge view's
|
|
11
|
+
* job — `@codemirror/merge` computes the alignment itself from two documents —
|
|
12
|
+
* so the only thing still needed from a patch is what the two sides were.
|
|
13
|
+
*
|
|
14
|
+
* That matters in one place: a chat tool card has a PATCH and no documents, and
|
|
15
|
+
* the card draws the same merge surface the diff panel does. Reconstructing the
|
|
16
|
+
* sides here keeps one renderer for both, instead of the card growing a second
|
|
17
|
+
* diff implementation that drifts.
|
|
18
|
+
*
|
|
19
|
+
* **The gap between hunks is restored as blank lines, and that is what keeps the
|
|
20
|
+
* gutter honest.** A hunk header names the line it starts on (`@@ -43,7 +43,8`),
|
|
21
|
+
* and a document rebuilt by concatenating hunks would number the change from 1.
|
|
22
|
+
* Padding each side up to the header's own counters puts the change back on the
|
|
23
|
+
* line the file has it on — and because the padding is unchanged content, the
|
|
24
|
+
* merge view collapses it into one marker (`contentMode: 'diff'`).
|
|
25
|
+
*
|
|
26
|
+
* The counters are the patch's own (`+`/`-` rows, hunk headers excluded), which
|
|
27
|
+
* is what the card's header prints. The diff panel deliberately does NOT use
|
|
28
|
+
* them: it has the real documents, and its counts must describe the rows the
|
|
29
|
+
* merge view actually draws (a collapsed or whitespace-folded change is not a
|
|
30
|
+
* changed row on screen).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** One side's text, and what the patch said about it. */
|
|
34
|
+
export interface PatchSides {
|
|
35
|
+
/** The document before the change, with the hunk gaps as blank lines. */
|
|
36
|
+
original: string;
|
|
37
|
+
/** The document after it, the same way. */
|
|
38
|
+
next: string;
|
|
39
|
+
additions: number;
|
|
40
|
+
deletions: number;
|
|
41
|
+
/** Content rows the patch produced — zero for a header-only or empty patch. */
|
|
42
|
+
rows: number;
|
|
43
|
+
/** The patch named at least one hunk (`@@`), so it is a real diff. */
|
|
44
|
+
hasHunk: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const EMPTY: PatchSides = { original: '', next: '', additions: 0, deletions: 0, rows: 0, hasHunk: false };
|
|
48
|
+
|
|
49
|
+
/** Header lines that describe the patch rather than its content. */
|
|
50
|
+
const HEADER_PREFIXES = [
|
|
51
|
+
'diff --git',
|
|
52
|
+
'index ',
|
|
53
|
+
'---',
|
|
54
|
+
'+++',
|
|
55
|
+
'new file mode',
|
|
56
|
+
'deleted file mode',
|
|
57
|
+
'similarity index',
|
|
58
|
+
'dissimilarity index',
|
|
59
|
+
'rename from',
|
|
60
|
+
'rename to',
|
|
61
|
+
'copy from',
|
|
62
|
+
'copy to',
|
|
63
|
+
'old mode',
|
|
64
|
+
'new mode',
|
|
65
|
+
'\\ No newline',
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/** `@@ -43,7 +43,8 @@` → the two starting lines; anything else → null. */
|
|
69
|
+
function hunkStarts(line: string): { old: number; next: number } | null {
|
|
70
|
+
const match = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
71
|
+
if (!match) return null;
|
|
72
|
+
return { old: Number(match[1]), next: Number(match[2]) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Pad `lines` with blanks until it holds `count` lines. */
|
|
76
|
+
function padTo(lines: string[], count: number): void {
|
|
77
|
+
while (lines.length < count) lines.push('');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function patchSides(patch: string): PatchSides {
|
|
81
|
+
if (!patch.trim()) return EMPTY;
|
|
82
|
+
|
|
83
|
+
const before: string[] = [];
|
|
84
|
+
const after: string[] = [];
|
|
85
|
+
let additions = 0;
|
|
86
|
+
let deletions = 0;
|
|
87
|
+
let rows = 0;
|
|
88
|
+
let hasHunk = false;
|
|
89
|
+
|
|
90
|
+
const lines = patch.split(/\r?\n/);
|
|
91
|
+
// A patch ends with a newline, and `split` turns that into a final empty
|
|
92
|
+
// string. It is the terminator, not a blank row: keeping it put an empty line
|
|
93
|
+
// at the end of BOTH documents, which the merge view drew as a chunk.
|
|
94
|
+
if (lines[lines.length - 1] === '') lines.pop();
|
|
95
|
+
|
|
96
|
+
for (const raw of lines) {
|
|
97
|
+
if (HEADER_PREFIXES.some((prefix) => raw.startsWith(prefix))) continue;
|
|
98
|
+
|
|
99
|
+
if (raw.startsWith('@@')) {
|
|
100
|
+
hasHunk = true;
|
|
101
|
+
const starts = hunkStarts(raw);
|
|
102
|
+
// `-0,0` (a new file) has no original line to reach, and `padTo` is a
|
|
103
|
+
// no-op for it because the count is below what is already there.
|
|
104
|
+
if (starts) {
|
|
105
|
+
padTo(before, starts.old - 1);
|
|
106
|
+
padTo(after, starts.next - 1);
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (raw.startsWith('+')) {
|
|
112
|
+
additions++;
|
|
113
|
+
rows++;
|
|
114
|
+
after.push(raw.slice(1));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (raw.startsWith('-')) {
|
|
118
|
+
deletions++;
|
|
119
|
+
rows++;
|
|
120
|
+
before.push(raw.slice(1));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// A context row (` ` prefix) is on BOTH sides; a bare line is what a
|
|
124
|
+
// header-less patch carries, and it is context too.
|
|
125
|
+
const text = raw.startsWith(' ') ? raw.slice(1) : raw;
|
|
126
|
+
rows++;
|
|
127
|
+
before.push(text);
|
|
128
|
+
after.push(text);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
original: before.join('\n'),
|
|
133
|
+
next: after.join('\n'),
|
|
134
|
+
additions,
|
|
135
|
+
deletions,
|
|
136
|
+
rows,
|
|
137
|
+
hasHunk,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -212,7 +212,10 @@ describe('realtime channel retry lifecycle', () => {
|
|
|
212
212
|
expect(ping).toBeDefined();
|
|
213
213
|
socket.onmessage?.({ data: JSON.stringify({ t: 'pong', id: ping!.id }) });
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
// Short of the idle-probe window: an answered probe must not cause a
|
|
216
|
+
// reconnect of its own. (Past `IDLE_PROBE_AFTER_MS` the watchdog probes
|
|
217
|
+
// again by design — see the idle case below.)
|
|
218
|
+
vi.advanceTimersByTime(20_000);
|
|
216
219
|
expect(FakeSocket.instances).toHaveLength(1);
|
|
217
220
|
expect(currentStatus()).toBe('open');
|
|
218
221
|
});
|
|
@@ -299,3 +302,4 @@ describe('realtime channel retry lifecycle', () => {
|
|
|
299
302
|
expect(() => resetRealtimeClient()).not.toThrow();
|
|
300
303
|
});
|
|
301
304
|
});
|
|
305
|
+
|
|
@@ -39,9 +39,8 @@
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
import { realtimeSocketUrl } from '@/shared/lib/realtime/protocol';
|
|
42
|
+
import { createResumeWatch } from '@/shared/lib/realtime/resume';
|
|
42
43
|
import {
|
|
43
|
-
WS_CONNECTING,
|
|
44
|
-
WS_OPEN,
|
|
45
44
|
deliverFrame,
|
|
46
45
|
liveTopics,
|
|
47
46
|
notifyClosed,
|
|
@@ -63,12 +62,17 @@ const MAX_FAILED_DIALS = 4;
|
|
|
63
62
|
const SLOW_RETRY_MS = 30_000;
|
|
64
63
|
/** How long a dial may sit in CONNECTING before it is abandoned and retried. */
|
|
65
64
|
const CONNECT_TIMEOUT_MS = 10_000;
|
|
65
|
+
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
* Resume, watchdog and liveness probe live in `resume.ts`: they are the
|
|
68
|
+
* mechanism that repairs a connection the browser never reported dead, and they
|
|
69
|
+
* need `dial` — which this module owns — so the dependency is injected rather
|
|
70
|
+
* than imported back.
|
|
70
71
|
*/
|
|
71
|
-
const
|
|
72
|
+
const resumeWatch = createResumeWatch(() => dial());
|
|
73
|
+
|
|
74
|
+
/** The tab (or the app, or the radio) is back. See `resume.ts`. */
|
|
75
|
+
export const wake = resumeWatch.wake;
|
|
72
76
|
|
|
73
77
|
/**
|
|
74
78
|
* The server answered a resume probe: the socket really is alive. Called from
|
|
@@ -81,6 +85,7 @@ export function notePong(id: number): void {
|
|
|
81
85
|
host.probeId = undefined;
|
|
82
86
|
clearTimeout(host.probeTimer);
|
|
83
87
|
host.probeTimer = undefined;
|
|
88
|
+
host.lastInboundAt = Date.now();
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
function scheduleReconnect(): void {
|
|
@@ -97,111 +102,6 @@ function scheduleReconnect(): void {
|
|
|
97
102
|
dial();
|
|
98
103
|
}, delay);
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Ask a socket that LOOKS open whether it still is.
|
|
103
|
-
*
|
|
104
|
-
* A frozen tab keeps `readyState === OPEN` for a connection the server's
|
|
105
|
-
* heartbeat already tore down, and no `close` is delivered until the browser
|
|
106
|
-
* notices. Without this probe the resume path would trust a corpse and the
|
|
107
|
-
* indicator would stay green over a stream that never resumes.
|
|
108
|
-
*/
|
|
109
|
-
function probeLiveness(socket: WebSocket): void {
|
|
110
|
-
const host = state();
|
|
111
|
-
if (host.probeId !== undefined) return;
|
|
112
|
-
const id = (host.probeSeq += 1);
|
|
113
|
-
host.probeId = id;
|
|
114
|
-
const abandon = (): void => {
|
|
115
|
-
// A late answer from a socket that has since been replaced must not close
|
|
116
|
-
// the live one: the deadline is only ever about THIS socket.
|
|
117
|
-
if (host.probeId !== id) return;
|
|
118
|
-
host.probeId = undefined;
|
|
119
|
-
host.probeTimer = undefined;
|
|
120
|
-
if (host.socket !== socket) return;
|
|
121
|
-
try {
|
|
122
|
-
socket.close();
|
|
123
|
-
} catch {
|
|
124
|
-
// Already gone.
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
host.probeTimer = window.setTimeout(abandon, WAKE_PROBE_MS);
|
|
128
|
-
if (!send({ t: 'ping', id })) abandon();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* The tab is back: a background freeze stopped our timers and the server's
|
|
133
|
-
* heartbeat dropped the socket, so the failure count describes a window in
|
|
134
|
-
* which nothing could run. Reset it and dial now if the socket is gone.
|
|
135
|
-
*
|
|
136
|
-
* Fires from `visibilitychange`, `pageshow` (bfcache) and `online` (the radio
|
|
137
|
-
* can come back before the page is visible again). `online` also covers a
|
|
138
|
-
* network that dropped without the tab ever hiding.
|
|
139
|
-
*/
|
|
140
|
-
function wake(): void {
|
|
141
|
-
const host = state();
|
|
142
|
-
if (!host.wanted) return;
|
|
143
|
-
host.failures = 0;
|
|
144
|
-
const socket = host.socket;
|
|
145
|
-
if (socket && socket.readyState === WS_CONNECTING) return;
|
|
146
|
-
if (socket && socket.readyState === WS_OPEN) {
|
|
147
|
-
probeLiveness(socket);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (host.retryTimer !== undefined) {
|
|
151
|
-
clearTimeout(host.retryTimer);
|
|
152
|
-
host.retryTimer = undefined;
|
|
153
|
-
}
|
|
154
|
-
if (socket) {
|
|
155
|
-
// Nulled FIRST: `close()` delivers `onclose` synchronously in some engines,
|
|
156
|
-
// and that handler owns the retry decision for a socket it still believes
|
|
157
|
-
// in. This socket is being abandoned on purpose, so its late close must
|
|
158
|
-
// report nothing.
|
|
159
|
-
host.socket = null;
|
|
160
|
-
try {
|
|
161
|
-
socket.close();
|
|
162
|
-
} catch {
|
|
163
|
-
// Already gone.
|
|
164
|
-
}
|
|
165
|
-
// The server tore this connection down while the tab was frozen, so every
|
|
166
|
-
// value on screen is of unknown age even though no `close` arrived.
|
|
167
|
-
notifyClosed();
|
|
168
|
-
}
|
|
169
|
-
dial();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Install the resume listeners once. A no-op outside a document.
|
|
174
|
-
*
|
|
175
|
-
* The cleanup closes over the `document`/`window` it REGISTERED on rather than
|
|
176
|
-
* reading the globals again when it runs. Those are not necessarily the same
|
|
177
|
-
* objects: a test suite replaces them per case and deletes them when it is
|
|
178
|
-
* done, and `resetConnection` (the teardown seam) would then dereference an
|
|
179
|
-
* absent `document` and throw — measured on CI, where a suite that reset the
|
|
180
|
-
* client after its own `restoreDomGlobals` failed the NEXT file with
|
|
181
|
-
* `ReferenceError: document is not defined`. In a browser the two are always
|
|
182
|
-
* the same object, so this changes nothing there.
|
|
183
|
-
*/
|
|
184
|
-
function ensureWakeListeners(): void {
|
|
185
|
-
const host = state();
|
|
186
|
-
if (host.wakeCleanup) return;
|
|
187
|
-
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
188
|
-
const doc = document;
|
|
189
|
-
const win = window;
|
|
190
|
-
const onVisible = (): void => {
|
|
191
|
-
if (!doc.hidden) wake();
|
|
192
|
-
};
|
|
193
|
-
const onOnline = (): void => wake();
|
|
194
|
-
const onPageShow = (): void => wake();
|
|
195
|
-
doc.addEventListener('visibilitychange', onVisible);
|
|
196
|
-
win.addEventListener('online', onOnline);
|
|
197
|
-
win.addEventListener('pageshow', onPageShow);
|
|
198
|
-
host.wakeCleanup = () => {
|
|
199
|
-
doc.removeEventListener('visibilitychange', onVisible);
|
|
200
|
-
win.removeEventListener('online', onOnline);
|
|
201
|
-
win.removeEventListener('pageshow', onPageShow);
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
105
|
function dial(): void {
|
|
206
106
|
const host = state();
|
|
207
107
|
// A retry scheduled before the last subscriber left must not open a socket
|
|
@@ -239,6 +139,9 @@ function dial(): void {
|
|
|
239
139
|
opened = true;
|
|
240
140
|
clearTimeout(connectTimer);
|
|
241
141
|
host.failures = 0;
|
|
142
|
+
// The socket just proved it is alive; the idle clock starts here so the
|
|
143
|
+
// watchdog does not probe a connection opened a moment ago.
|
|
144
|
+
host.lastInboundAt = Date.now();
|
|
242
145
|
if (host.probeId !== undefined) {
|
|
243
146
|
host.probeId = undefined;
|
|
244
147
|
clearTimeout(host.probeTimer);
|
|
@@ -252,7 +155,11 @@ function dial(): void {
|
|
|
252
155
|
};
|
|
253
156
|
|
|
254
157
|
socket.onmessage = (event) => {
|
|
255
|
-
if (typeof event.data
|
|
158
|
+
if (typeof event.data !== 'string') return;
|
|
159
|
+
// The idle clock the watchdog reads: every inbound frame — a delta, a
|
|
160
|
+
// snapshot, a pong — proves the socket is alive.
|
|
161
|
+
host.lastInboundAt = Date.now();
|
|
162
|
+
deliverFrame(event.data);
|
|
256
163
|
};
|
|
257
164
|
|
|
258
165
|
socket.onclose = () => {
|
|
@@ -286,7 +193,8 @@ export function connectIfNeeded(): void {
|
|
|
286
193
|
const host = state();
|
|
287
194
|
setWanted(liveTopics().length > 0);
|
|
288
195
|
if (!host.wanted) return;
|
|
289
|
-
|
|
196
|
+
resumeWatch.ensureListeners();
|
|
197
|
+
resumeWatch.start();
|
|
290
198
|
if (host.socket) return;
|
|
291
199
|
if (host.retryTimer !== undefined) return;
|
|
292
200
|
dial();
|
|
@@ -295,12 +203,10 @@ export function connectIfNeeded(): void {
|
|
|
295
203
|
/** Test seam: close the socket and forget the connection state. */
|
|
296
204
|
export function resetConnection(): void {
|
|
297
205
|
const host = state();
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
host.wakeCleanup = null;
|
|
303
|
-
cleanup?.();
|
|
206
|
+
// Removes the resume listeners AND stops the watchdog. The watch nulls its own
|
|
207
|
+
// slots before running the cleanup, so a throwing listener target cannot leave
|
|
208
|
+
// them set and make the next reset retry the same throw.
|
|
209
|
+
resumeWatch.stop();
|
|
304
210
|
clearTimeout(host.retryTimer);
|
|
305
211
|
clearTimeout(host.probeTimer);
|
|
306
212
|
const socket = host.socket;
|