@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
|
@@ -4,15 +4,13 @@ import type { ParsedTaskNotice } from '@/shared/lib/chat/task-result-parser';
|
|
|
4
4
|
import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
|
|
5
5
|
import { CopyButton } from '@/client/components/common/CopyButton';
|
|
6
6
|
import { isCodeLike } from '@/shared/lib/code/language';
|
|
7
|
-
import {
|
|
8
|
-
import { useSyntaxReady } from '@/client/hooks/ui/syntax-ready';
|
|
7
|
+
import { useDeferredHighlight } from '@/client/hooks/code/deferred-highlight';
|
|
9
8
|
|
|
10
9
|
interface TaskResultContentProps {
|
|
11
10
|
task: ParsedTaskNotice;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export function TaskResultContent({ task }: TaskResultContentProps) {
|
|
15
|
-
useSyntaxReady();
|
|
16
14
|
const structured = task.structuredOutput;
|
|
17
15
|
const isRawCode = !task.formattedJson && isCodeLike(task.rawOutput);
|
|
18
16
|
|
|
@@ -20,6 +18,13 @@ export function TaskResultContent({ task }: TaskResultContentProps) {
|
|
|
20
18
|
structured || !isRawCode ? 'formatted' : 'raw'
|
|
21
19
|
);
|
|
22
20
|
|
|
21
|
+
// Gated on the tab that draws it: the raw view is one of two, and tokenizing
|
|
22
|
+
// it while the formatted view is on screen is work nobody sees.
|
|
23
|
+
const rawHtml = useDeferredHighlight(
|
|
24
|
+
activeTab === 'raw' ? task.formattedJson || task.rawOutput : '',
|
|
25
|
+
task.formattedJson ? 'json' : isRawCode ? 'javascript' : 'markdown',
|
|
26
|
+
);
|
|
27
|
+
|
|
23
28
|
return (
|
|
24
29
|
<div className="space-y-3">
|
|
25
30
|
{/* Top action toolbar / tab toggles */}
|
|
@@ -151,10 +156,7 @@ export function TaskResultContent({ task }: TaskResultContentProps) {
|
|
|
151
156
|
<pre
|
|
152
157
|
className="max-h-64 overflow-auto rounded-lg border border-ink/8 bg-paper p-3 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words text-ink/80 scrollbar-overlay-container"
|
|
153
158
|
dangerouslySetInnerHTML={{
|
|
154
|
-
__html:
|
|
155
|
-
task.formattedJson || task.rawOutput,
|
|
156
|
-
task.formattedJson ? 'json' : isRawCode ? 'javascript' : 'markdown'
|
|
157
|
-
),
|
|
159
|
+
__html: rawHtml,
|
|
158
160
|
}}
|
|
159
161
|
/>
|
|
160
162
|
)}
|
|
@@ -38,10 +38,15 @@
|
|
|
38
38
|
* is the panel's own overlap with the visible area (`useKeyboardInset`),
|
|
39
39
|
* applied as padding; with no keyboard the padding is the home indicator's
|
|
40
40
|
* inset instead.
|
|
41
|
-
* - **A send collapses the
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
41
|
+
* - **A send collapses the stretch, on BOTH layouts, and only a DISPATCHED
|
|
42
|
+
* send does.** The stretched composer covers the transcript on a phone and
|
|
43
|
+
* covers a third of the conversation on a desktop, so it returns to the dock
|
|
44
|
+
* once the prompt is on its way — but the collapse is driven by the send
|
|
45
|
+
* pipeline's own `onSent`, never by the click: a Send press that dispatched
|
|
46
|
+
* nothing (an empty draft, an attachment whose read produced no body) must
|
|
47
|
+
* leave the box exactly where the user put it, or a refused send would look
|
|
48
|
+
* like a successful one. Escape collapses either layout too, from a document
|
|
49
|
+
* listener, so the popup's own Escape handling cannot trap the user.
|
|
45
50
|
*/
|
|
46
51
|
|
|
47
52
|
import type { CSSProperties } from 'preact';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
2
2
|
import type { ClipboardEvent, SetStateAction } from 'preact/compat';
|
|
3
3
|
import { AlertTriangle, X } from 'lucide-preact';
|
|
4
4
|
import type { Attachment } from '@/shared/types';
|
|
@@ -106,6 +106,17 @@ export function ChatInput({
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
+
// A DISPATCHED send returns the composer to its docked size, on BOTH layouts.
|
|
110
|
+
// Hooked into the pipeline rather than the click handler so every way in —
|
|
111
|
+
// the Send button, Enter, Cmd+Enter steering, a queued follow-up — collapses
|
|
112
|
+
// it, while a click that dispatched nothing (an empty draft, an unreadable
|
|
113
|
+
// attachment) leaves the stretched box exactly where the user put it. Staying
|
|
114
|
+
// stretched hides the answer being streamed on a phone, and on a desktop it
|
|
115
|
+
// keeps a 38vh box over the conversation the prompt was written against.
|
|
116
|
+
// Stable identity: the pipeline's `submit` closes over it, and a fresh arrow
|
|
117
|
+
// per render would rebuild `submit` on every keystroke.
|
|
118
|
+
const collapseOnSend = useCallback(() => setExpanded(false), []);
|
|
119
|
+
|
|
109
120
|
// Attach-and-send pipeline: drop handling, the inline notice, and the send
|
|
110
121
|
// guard all live in the hook, because a drop registers files before this
|
|
111
122
|
// component re-renders and the send decision cannot read a stale prop.
|
|
@@ -116,6 +127,7 @@ export function ChatInput({
|
|
|
116
127
|
disabled,
|
|
117
128
|
rootPath,
|
|
118
129
|
onSend,
|
|
130
|
+
onSent: collapseOnSend,
|
|
119
131
|
});
|
|
120
132
|
|
|
121
133
|
// Publishes this composer's state to the plugin kit, and gives the kit a way
|
|
@@ -167,14 +179,6 @@ export function ChatInput({
|
|
|
167
179
|
return () => document.removeEventListener('keydown', onKey);
|
|
168
180
|
}, [expanded]);
|
|
169
181
|
|
|
170
|
-
// A send on a phone collapses the stretch: it covers the transcript, so
|
|
171
|
-
// staying stretched would hide the answer being streamed. On a desktop the
|
|
172
|
-
// chat is visible either way and the box stays where the user put it.
|
|
173
|
-
const handleSubmit = (options?: { steering?: boolean }) => {
|
|
174
|
-
if (isMobile) setExpanded(false);
|
|
175
|
-
submit(options);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
182
|
// Browser dictation, delegated to omp's own local STT worker. The hook owns
|
|
179
183
|
// capture + the socket; this component owns where the text lands and the
|
|
180
184
|
// status line while a first-run model download is still going.
|
|
@@ -275,7 +279,7 @@ export function ChatInput({
|
|
|
275
279
|
<ComposerTextarea
|
|
276
280
|
value={value}
|
|
277
281
|
onChange={onChange}
|
|
278
|
-
onSend={
|
|
282
|
+
onSend={submit}
|
|
279
283
|
disabled={disabled}
|
|
280
284
|
appSettings={appSettings}
|
|
281
285
|
rootPath={rootPath}
|
|
@@ -308,7 +312,7 @@ export function ChatInput({
|
|
|
308
312
|
isGenerating={isGenerating}
|
|
309
313
|
chatRunning={chatRunning}
|
|
310
314
|
onStop={onStop}
|
|
311
|
-
onSend={() =>
|
|
315
|
+
onSend={() => submit()}
|
|
312
316
|
sendDisabled={disabled || (!value.trim() && attachments.length === 0)}
|
|
313
317
|
accessMode={accessMode}
|
|
314
318
|
onSelectAccess={onAccessModeChange}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A DISPATCHED send returns the composer to its docked size, on BOTH layouts.
|
|
8
|
+
*
|
|
9
|
+
* This is the rule the click handler used to own as `if (isMobile)
|
|
10
|
+
* setExpanded(false)`, which was wrong twice over. A desktop kept its 38vh box
|
|
11
|
+
* over the conversation the prompt was written against, and on EITHER layout a
|
|
12
|
+
* press that dispatched nothing (an empty draft, an attachment whose read
|
|
13
|
+
* produced no body) collapsed a box whose content had never been sent — a
|
|
14
|
+
* refusal that read as success.
|
|
15
|
+
*
|
|
16
|
+
* The collapse therefore lives in the send pipeline's `onSent`, after every
|
|
17
|
+
* guard. These cases pin both directions from the component the user actually
|
|
18
|
+
* presses: the Maximize control, then a send, then the frame it is in.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
22
|
+
import { Window } from 'happy-dom';
|
|
23
|
+
import { h, render } from 'preact';
|
|
24
|
+
import { act } from 'preact/test-utils';
|
|
25
|
+
import type { Attachment } from '@/shared/types';
|
|
26
|
+
import { ChatInput } from '@/client/components/workspace/chat-timeline/chat-input';
|
|
27
|
+
import { delay } from '@/client/hooks/chat/composer/file-reads';
|
|
28
|
+
import { restoreRealtime, silenceRealtime } from '@/test-support/silent-socket';
|
|
29
|
+
|
|
30
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'HTMLTextAreaElement', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'PointerEvent'] as const;
|
|
31
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
32
|
+
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
const win = new Window({ url: 'http://localhost' });
|
|
35
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
36
|
+
for (const key of DOM_GLOBALS) {
|
|
37
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
|
|
38
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
44
|
+
for (const key of DOM_GLOBALS) {
|
|
45
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
46
|
+
else target[key] = nativeGlobals[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let container: HTMLElement | null = null;
|
|
51
|
+
/** Every dispatch the composer made, so a case can assert what was NOT sent. */
|
|
52
|
+
const sent: Attachment[][] = [];
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
silenceRealtime();
|
|
56
|
+
sent.length = 0;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(async () => {
|
|
60
|
+
// Unmount inside `act`, then drain AFTER the realtime reset and WHILE this
|
|
61
|
+
// window still exists. A stretched composer runs `useKeyboardInset` — a
|
|
62
|
+
// `ResizeObserver`, four window listeners and a deferred
|
|
63
|
+
// `requestAnimationFrame` — and the send pipeline resolves on a zero-delay
|
|
64
|
+
// read-back, so a case can leave work queued on this window; Preact's own
|
|
65
|
+
// effect flush is deferred too, so an unmount outside `act` lets a render land
|
|
66
|
+
// after `afterAll` deletes the globals. Measured as `document is not defined`
|
|
67
|
+
// inside whichever file bun runs next: 9 of 12 folder runs without this
|
|
68
|
+
// drain, 0 of 10 with it. The drain must be a BARE timer — wrapping it in
|
|
69
|
+
// `act` queues another flush and reintroduces the leak.
|
|
70
|
+
const host = container;
|
|
71
|
+
if (host) {
|
|
72
|
+
// The local binding is the narrowing: a closure cannot carry it.
|
|
73
|
+
await act(async () => { render(null, host); });
|
|
74
|
+
host.remove();
|
|
75
|
+
}
|
|
76
|
+
container = null;
|
|
77
|
+
restoreRealtime();
|
|
78
|
+
await delay(50);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
interface MountOptions {
|
|
83
|
+
value?: string;
|
|
84
|
+
variant?: 'desktop' | 'mobile';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function mount({ value = '', variant = 'desktop' }: MountOptions = {}): Promise<HTMLElement> {
|
|
88
|
+
const host = document.createElement('div');
|
|
89
|
+
document.body.appendChild(host);
|
|
90
|
+
await act(async () => {
|
|
91
|
+
render(
|
|
92
|
+
h(ChatInput, {
|
|
93
|
+
value,
|
|
94
|
+
onChange: () => {},
|
|
95
|
+
onSend: (attachments: Attachment[]) => { sent.push(attachments); },
|
|
96
|
+
isGenerating: false,
|
|
97
|
+
composerModelRef: { current: null },
|
|
98
|
+
variant,
|
|
99
|
+
expandable: true,
|
|
100
|
+
sessionId: 'composer-stretch-test',
|
|
101
|
+
}),
|
|
102
|
+
host,
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
container = host;
|
|
106
|
+
return host;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const byLabel = (el: HTMLElement, label: string) =>
|
|
110
|
+
el.querySelector(`[aria-label="${label}"]`) as HTMLButtonElement | null;
|
|
111
|
+
const isExpanded = (el: HTMLElement) => byLabel(el, 'Restore composer') !== null;
|
|
112
|
+
|
|
113
|
+
/** Clicks the Maximize control, the way the user starts a stretched draft. */
|
|
114
|
+
async function stretch(el: HTMLElement) {
|
|
115
|
+
const maximize = byLabel(el, 'Maximize composer');
|
|
116
|
+
expect(maximize).not.toBeNull();
|
|
117
|
+
await act(async () => { maximize!.click(); });
|
|
118
|
+
expect(isExpanded(el)).toBe(true);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Drains the pipeline's own zero-delay wait plus the renders it lands. */
|
|
122
|
+
async function settle(rounds = 6) {
|
|
123
|
+
for (let i = 0; i < rounds; i += 1) {
|
|
124
|
+
await act(async () => { await delay(0); });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
describe('a send collapses the stretch', () => {
|
|
129
|
+
for (const variant of ['desktop', 'mobile'] as const) {
|
|
130
|
+
test(`a ${variant} send returns the composer to the dock`, async () => {
|
|
131
|
+
const el = await mount({ value: 'collapse me', variant });
|
|
132
|
+
await stretch(el);
|
|
133
|
+
|
|
134
|
+
const send = byLabel(el, 'Send message');
|
|
135
|
+
expect(send).not.toBeNull();
|
|
136
|
+
await act(async () => { send!.click(); });
|
|
137
|
+
await settle();
|
|
138
|
+
|
|
139
|
+
expect(sent.length).toBe(1);
|
|
140
|
+
// Back to the docked frame: the control offers Maximize again.
|
|
141
|
+
expect(isExpanded(el)).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
test('a send that dispatched nothing leaves the stretched box alone', async () => {
|
|
146
|
+
const el = await mount({ variant: 'desktop' });
|
|
147
|
+
await stretch(el);
|
|
148
|
+
|
|
149
|
+
// Enter with an empty draft: the pipeline returns before it dispatches, so
|
|
150
|
+
// the box the user stretched stays exactly as they left it.
|
|
151
|
+
const textarea = el.querySelector('textarea')!;
|
|
152
|
+
await act(async () => {
|
|
153
|
+
textarea.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
154
|
+
});
|
|
155
|
+
await settle();
|
|
156
|
+
|
|
157
|
+
expect(sent).toEqual([]);
|
|
158
|
+
expect(isExpanded(el)).toBe(true);
|
|
159
|
+
|
|
160
|
+
// Collapse before teardown: a stretched composer keeps `useKeyboardInset`
|
|
161
|
+
// live (a `ResizeObserver` plus a deferred frame), and leaving one mounted
|
|
162
|
+
// past `afterAll` lets its work run after the DOM globals are gone.
|
|
163
|
+
await act(async () => { byLabel(el, 'Restore composer')!.click(); });
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer's WORKSPACE picker, rendered.
|
|
8
|
+
*
|
|
9
|
+
* The cases a reader would otherwise find only in a browser:
|
|
10
|
+
*
|
|
11
|
+
* - the trigger names the selected folder, and says what it is waiting for
|
|
12
|
+
* when nothing is selected;
|
|
13
|
+
* - the menu lists folders and NOTHING about worktrees — the split is the
|
|
14
|
+
* point of this control, and a worktree row here is the regression;
|
|
15
|
+
* - choosing another folder clears the worktree pick, because a checkout of
|
|
16
|
+
* the previous project names a path the new one cannot resolve.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
20
|
+
import { Window } from 'happy-dom';
|
|
21
|
+
import { h, render } from 'preact';
|
|
22
|
+
import { act } from 'preact/test-utils';
|
|
23
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
24
|
+
import { WorkspacePicker, workspaceLabel } from '@/client/components/workspace/chat-timeline/target-picker/WorkspacePicker';
|
|
25
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
26
|
+
|
|
27
|
+
const folder = (id: number, name: string): WorkspaceFolderData => ({
|
|
28
|
+
id,
|
|
29
|
+
name,
|
|
30
|
+
project_path: `/repo/${name}`,
|
|
31
|
+
isExpanded: true,
|
|
32
|
+
hasMore: false,
|
|
33
|
+
totalSessions: 0,
|
|
34
|
+
sessions: [],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const mounted: HTMLElement[] = [];
|
|
38
|
+
|
|
39
|
+
beforeAll(() => {
|
|
40
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
for (const host of mounted.splice(0)) {
|
|
45
|
+
render(null, host);
|
|
46
|
+
host.remove();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
restoreDomGlobals();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function mount(node: h.JSX.Element): Promise<HTMLElement> {
|
|
55
|
+
const host = document.createElement('div');
|
|
56
|
+
document.body.appendChild(host);
|
|
57
|
+
await act(async () => {
|
|
58
|
+
render(node, host);
|
|
59
|
+
});
|
|
60
|
+
mounted.push(host);
|
|
61
|
+
return host;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function textOf(host: HTMLElement): string {
|
|
65
|
+
return (host.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('workspaceLabel', () => {
|
|
69
|
+
test('the selected folder', () => {
|
|
70
|
+
expect(workspaceLabel([folder(1, 'kabmo')], 1)).toBe('kabmo');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('what it is waiting for, with nothing selected', () => {
|
|
74
|
+
expect(workspaceLabel([], null)).toBe('Select Workspace Context');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('WorkspacePicker', () => {
|
|
79
|
+
test('the menu lists the workspaces and nothing about worktrees', async () => {
|
|
80
|
+
const host = await mount(
|
|
81
|
+
h(WorkspacePicker, {
|
|
82
|
+
folders: [folder(1, 'kabmo'), folder(2, 'notes')],
|
|
83
|
+
selectedFolderId: 1,
|
|
84
|
+
setSelectedFolderId: () => {},
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
await act(async () => {
|
|
89
|
+
(host.querySelector('button') as HTMLButtonElement).click();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const text = textOf(host);
|
|
93
|
+
expect(text).toContain('Target Workspace');
|
|
94
|
+
expect(text).toContain('kabmo');
|
|
95
|
+
expect(text).toContain('notes');
|
|
96
|
+
// The split: a worktree row here would be the merged menu coming back.
|
|
97
|
+
expect(text).not.toContain('Quick worktree');
|
|
98
|
+
expect(text).not.toContain('New worktree');
|
|
99
|
+
expect(text).not.toContain('Worktrees');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('choosing a folder clears the worktree pick', async () => {
|
|
103
|
+
// A record rather than two locals: a value assigned inside a callback is
|
|
104
|
+
// still narrowed to its initializer by control-flow analysis, so `picked`
|
|
105
|
+
// would be `null` at the assertion.
|
|
106
|
+
const seen: { picked: number | null; cleared: number } = { picked: null, cleared: 0 };
|
|
107
|
+
const host = await mount(
|
|
108
|
+
h(WorkspacePicker, {
|
|
109
|
+
folders: [folder(1, 'kabmo'), folder(2, 'notes')],
|
|
110
|
+
selectedFolderId: 1,
|
|
111
|
+
setSelectedFolderId: (id) => {
|
|
112
|
+
seen.picked = id;
|
|
113
|
+
},
|
|
114
|
+
onClearWorktree: () => {
|
|
115
|
+
seen.cleared += 1;
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
await act(async () => {
|
|
121
|
+
(host.querySelector('button') as HTMLButtonElement).click();
|
|
122
|
+
});
|
|
123
|
+
const rows = [...host.querySelectorAll('[role="menuitemradio"]')] as HTMLButtonElement[];
|
|
124
|
+
expect(rows.length).toBe(2);
|
|
125
|
+
await act(async () => {
|
|
126
|
+
rows[1]?.click();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(seen.picked).toBe(2);
|
|
130
|
+
expect(seen.cleared).toBe(1);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WHERE the chat runs: the workspace folder.
|
|
8
|
+
*
|
|
9
|
+
* One control of the composer's draft-target pair, and the pair exists because
|
|
10
|
+
* the two questions are different: the folder is the project, and the worktree
|
|
11
|
+
* is the checkout inside it (`WorktreePicker`). They were merged into one menu
|
|
12
|
+
* once, and the result read as a workspace picker with worktree rows buried in
|
|
13
|
+
* it — a user looking for another project scrolled past branch names, and a
|
|
14
|
+
* user looking for a worktree could not tell the control was the place to look.
|
|
15
|
+
* OpenChamber draws them as two controls for the same reason.
|
|
16
|
+
*
|
|
17
|
+
* Picking a folder CLEARS the worktree pick: a checkout of the previous project
|
|
18
|
+
* names a path that does not exist under the new one.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { useRef, useState } from 'preact/hooks';
|
|
22
|
+
import { Check, ChevronDown, Folder } from 'lucide-preact';
|
|
23
|
+
import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
|
|
24
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
25
|
+
|
|
26
|
+
export interface WorkspacePickerProps {
|
|
27
|
+
folders: WorkspaceFolderData[];
|
|
28
|
+
selectedFolderId: number | null;
|
|
29
|
+
setSelectedFolderId: (id: number | null) => void;
|
|
30
|
+
/** Called with `null` when the user moves to another project. */
|
|
31
|
+
onClearWorktree?: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The trigger's words, exported so a test asserts them without the markup. */
|
|
35
|
+
export function workspaceLabel(folders: WorkspaceFolderData[], selectedFolderId: number | null): string {
|
|
36
|
+
const folder = folders.find((candidate) => String(candidate.id) === String(selectedFolderId));
|
|
37
|
+
return folder?.name ?? 'Select Workspace Context';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function WorkspacePicker({
|
|
41
|
+
folders,
|
|
42
|
+
selectedFolderId,
|
|
43
|
+
setSelectedFolderId,
|
|
44
|
+
onClearWorktree,
|
|
45
|
+
}: WorkspacePickerProps) {
|
|
46
|
+
const [open, setOpen] = useState(false);
|
|
47
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
useOnClickOutside(containerRef, () => setOpen(false));
|
|
49
|
+
|
|
50
|
+
const pick = (folder: WorkspaceFolderData) => {
|
|
51
|
+
setSelectedFolderId(folder.id);
|
|
52
|
+
// A worktree belongs to the project it was made from; keeping the pick
|
|
53
|
+
// across a project change would spawn the chat in a path this project
|
|
54
|
+
// cannot resolve.
|
|
55
|
+
onClearWorktree?.();
|
|
56
|
+
setOpen(false);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const label = workspaceLabel(folders, selectedFolderId);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div className="relative shrink-0" ref={containerRef}>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
// Two triggers sit side by side, so each needs a name that says which
|
|
66
|
+
// question it answers: "kabmo" and "main" alone are both ambiguous.
|
|
67
|
+
aria-label={`Workspace: ${label}`}
|
|
68
|
+
aria-haspopup="menu"
|
|
69
|
+
aria-expanded={open}
|
|
70
|
+
onClick={() => setOpen((value) => !value)}
|
|
71
|
+
className="group flex items-center space-x-1.5 px-1.5 py-1 rounded-md text-xs font-medium text-ink/75 hover:text-ink hover:bg-ink/5 focus-visible:bg-ink/5 transition-all outline-none cursor-pointer select-none"
|
|
72
|
+
>
|
|
73
|
+
<Folder size={13} className="text-ink/50 group-hover:text-ink/80 transition-colors flex-shrink-0" />
|
|
74
|
+
<span className="max-w-[260px] truncate tracking-tight">{label}</span>
|
|
75
|
+
<ChevronDown
|
|
76
|
+
size={13}
|
|
77
|
+
className={`text-ink/40 group-hover:text-ink/70 flex-shrink-0 transition-transform duration-150 ${open ? 'rotate-180 text-ink/70' : ''}`}
|
|
78
|
+
/>
|
|
79
|
+
</button>
|
|
80
|
+
|
|
81
|
+
{open && (
|
|
82
|
+
<div
|
|
83
|
+
role="menu"
|
|
84
|
+
className="absolute bottom-full left-0 mb-1.5 w-64 bg-paper border border-ink/10 rounded-lg shadow-lg z-50 flex flex-col overflow-hidden text-xs py-1"
|
|
85
|
+
>
|
|
86
|
+
<div className="px-3 py-1.5 text-[10px] uppercase tracking-wider text-ink/40 font-semibold border-b border-ink/5">
|
|
87
|
+
Target Workspace
|
|
88
|
+
</div>
|
|
89
|
+
<div className="max-h-56 scrollbar-overlay-container py-1">
|
|
90
|
+
{folders.length === 0 ? (
|
|
91
|
+
<div className="px-3 py-2 text-ink/40 italic">No workspaces available</div>
|
|
92
|
+
) : (
|
|
93
|
+
folders.map((folder) => {
|
|
94
|
+
const active = String(selectedFolderId) === String(folder.id);
|
|
95
|
+
return (
|
|
96
|
+
<button
|
|
97
|
+
key={folder.id}
|
|
98
|
+
type="button"
|
|
99
|
+
role="menuitemradio"
|
|
100
|
+
aria-checked={active}
|
|
101
|
+
onClick={() => pick(folder)}
|
|
102
|
+
className={`w-full text-left px-3 py-1.5 flex items-center justify-between transition-colors cursor-pointer ${
|
|
103
|
+
active ? 'bg-ink/10 text-ink font-semibold' : 'text-ink/80 hover:bg-ink/5 hover:text-ink'
|
|
104
|
+
}`}
|
|
105
|
+
>
|
|
106
|
+
<span className="flex items-center space-x-2 truncate pr-2">
|
|
107
|
+
<Folder size={12} className={active ? 'text-ink flex-shrink-0' : 'text-ink/50 flex-shrink-0'} />
|
|
108
|
+
<span className="truncate font-medium">{folder.name}</span>
|
|
109
|
+
</span>
|
|
110
|
+
{active && <Check size={12} className="text-ink flex-shrink-0" />}
|
|
111
|
+
</button>
|
|
112
|
+
);
|
|
113
|
+
})
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|