@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,109 @@
|
|
|
1
|
+
import { MessageSquareOff, PanelLeftClose } from 'lucide-preact';
|
|
2
|
+
import type { LucideIcon } from 'lucide-preact';
|
|
3
|
+
import { useSharedSessionState } from '@/client/hooks/workspace/session-state';
|
|
4
|
+
import type { ToolbarOverflowAction } from '@/client/components/common/toolbar-row';
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_EDITOR_VIEW_MODE,
|
|
7
|
+
EDITOR_VIEW_MODE_KEY,
|
|
8
|
+
isEditorViewMode,
|
|
9
|
+
toggledEditorViewMode,
|
|
10
|
+
type EditorViewMode,
|
|
11
|
+
type EditorViewModeTarget,
|
|
12
|
+
} from '@/shared/lib/workspace/editor-view-mode';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The two width modes, as data.
|
|
16
|
+
*
|
|
17
|
+
* Each is a row so the buttons, their labels and their icons cannot drift
|
|
18
|
+
* apart: the label states exactly which columns disappear, because "Compact"
|
|
19
|
+
* and "Full" are words that could mean anything, and the icons are DIFFERENT
|
|
20
|
+
* SHAPES rather than two spellings of the same one — the third width control
|
|
21
|
+
* beside them (full SCREEN, which covers the right panel too) keeps its own
|
|
22
|
+
* `Maximize` glyph.
|
|
23
|
+
*/
|
|
24
|
+
export const EDITOR_VIEW_MODES: Array<{
|
|
25
|
+
target: EditorViewModeTarget;
|
|
26
|
+
label: string;
|
|
27
|
+
hint: string;
|
|
28
|
+
Icon: LucideIcon;
|
|
29
|
+
}> = [
|
|
30
|
+
{
|
|
31
|
+
target: 'compact',
|
|
32
|
+
label: 'Compact view',
|
|
33
|
+
hint: 'Editor takes the chat width — chat hidden, sidebar and right panel kept',
|
|
34
|
+
Icon: MessageSquareOff,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
target: 'full',
|
|
38
|
+
label: 'Full view',
|
|
39
|
+
hint: 'Editor takes the chat and sidebar width — chat and sidebar hidden, right panel kept',
|
|
40
|
+
Icon: PanelLeftClose,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/** The mode in force, and the setter the buttons share. */
|
|
45
|
+
export function useEditorViewMode(): { mode: EditorViewMode; setMode: (next: EditorViewMode) => void } {
|
|
46
|
+
const [stored, setMode] = useSharedSessionState<EditorViewMode>(EDITOR_VIEW_MODE_KEY, DEFAULT_EDITOR_VIEW_MODE);
|
|
47
|
+
return { mode: isEditorViewMode(stored) ? stored : DEFAULT_EDITOR_VIEW_MODE, setMode };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The same two modes as `⋯` menu rows, for a toolbar too narrow to draw them.
|
|
52
|
+
*
|
|
53
|
+
* A hook rather than a plain function because the menu row has to CLICK the same
|
|
54
|
+
* slot the buttons write, and a row built from a stale mode would enter the mode
|
|
55
|
+
* already in force (which the toggle reads as "leave it").
|
|
56
|
+
*/
|
|
57
|
+
export function useEditorViewActions(): ToolbarOverflowAction[] {
|
|
58
|
+
const { mode, setMode } = useEditorViewMode();
|
|
59
|
+
return EDITOR_VIEW_MODES.map(({ target, label, Icon }) => ({
|
|
60
|
+
// A menu row has no hover title, so the sentence that explains the mode is
|
|
61
|
+
// part of what the row says rather than lost with the button's tooltip.
|
|
62
|
+
label,
|
|
63
|
+
icon: Icon,
|
|
64
|
+
active: mode === target,
|
|
65
|
+
onSelect: () => setMode(toggledEditorViewMode(mode, target)),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface EditorViewButtonsProps {
|
|
70
|
+
/** Glyph size: the editor toolbar draws 14px, the diff toolbar 13px. */
|
|
71
|
+
size?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The two width-mode buttons, drawn by BOTH the editor and the diff toolbar.
|
|
76
|
+
*
|
|
77
|
+
* One component because the two toolbars are the same surface on two tab kinds:
|
|
78
|
+
* a mode entered from the diff and a mode entered from a file must be the same
|
|
79
|
+
* mode, and a second copy of these rules is how the diff ends up offering a
|
|
80
|
+
* width the layout does not implement. The state is the shared session slot
|
|
81
|
+
* (see `useEditorViewLayout`) so the layout collapses the columns on the same
|
|
82
|
+
* render.
|
|
83
|
+
*/
|
|
84
|
+
export function EditorViewButtons({ size = 14 }: EditorViewButtonsProps) {
|
|
85
|
+
const { mode, setMode } = useEditorViewMode();
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<>
|
|
89
|
+
{EDITOR_VIEW_MODES.map(({ target, label, hint, Icon }) => {
|
|
90
|
+
const active = mode === target;
|
|
91
|
+
return (
|
|
92
|
+
<button
|
|
93
|
+
key={target}
|
|
94
|
+
type="button"
|
|
95
|
+
onClick={() => setMode(toggledEditorViewMode(mode, target))}
|
|
96
|
+
className={`flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer flex-shrink-0 ${
|
|
97
|
+
active ? 'bg-ink/10 text-ink' : 'text-ink/50 hover:text-ink hover:bg-ink/5'
|
|
98
|
+
}`}
|
|
99
|
+
title={hint}
|
|
100
|
+
aria-label={label}
|
|
101
|
+
aria-pressed={active}
|
|
102
|
+
>
|
|
103
|
+
<Icon size={size} />
|
|
104
|
+
</button>
|
|
105
|
+
);
|
|
106
|
+
})}
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shell update's dialog: confirm, install, report.
|
|
8
|
+
*
|
|
9
|
+
* ## Why the message lives HERE and not in the footer
|
|
10
|
+
*
|
|
11
|
+
* The footer is a row of controls, one of them 24px wide. A sentence like "Kabmo
|
|
12
|
+
* 0.3.2 installed — restarting" pushed into that row pushed the controls around
|
|
13
|
+
* and read as a status line for the SIDEBAR rather than for the update the user
|
|
14
|
+
* just asked for. The control therefore stays a control, and everything a run has
|
|
15
|
+
* to say — the confirmation before it, the progress during it, the shell's own
|
|
16
|
+
* refusal after it — is a dialog.
|
|
17
|
+
*
|
|
18
|
+
* ## The confirmation is not ceremony
|
|
19
|
+
*
|
|
20
|
+
* The click replaces the app the user is looking at and restarts it. That is not
|
|
21
|
+
* something a 24px glyph should do on a single press with no words, which is why
|
|
22
|
+
* the first thing the dialog says is what will happen and what will be lost
|
|
23
|
+
* (nothing but the window: the servers and the session are the console's own
|
|
24
|
+
* state, and they survive).
|
|
25
|
+
*
|
|
26
|
+
* ## Every phase reports the shell's own words
|
|
27
|
+
*
|
|
28
|
+
* `done` and `error` print the sentence the SHELL sent. Nothing here invents
|
|
29
|
+
* "Update failed": a shell that verified the download and declined knows why, and
|
|
30
|
+
* that reason is the only thing a user can act on.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { AlertCircle, Check, Download, Loader2 } from 'lucide-preact';
|
|
34
|
+
import { Modal } from '@/client/components/common/Modal';
|
|
35
|
+
import {
|
|
36
|
+
shellDownloadLabel,
|
|
37
|
+
type ShellDownload,
|
|
38
|
+
} from '@/client/hooks/ui/updates/shell-download';
|
|
39
|
+
import type { ShellUpdatePhase } from '@/client/hooks/ui/updates/shell-update';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What the dialog is showing.
|
|
43
|
+
*
|
|
44
|
+
* `confirm` is the dialog's own phase, not the hook's: the hook's `idle` means "no
|
|
45
|
+
* run has happened", and the dialog is only ever open on a run the user is about to
|
|
46
|
+
* start or one that already ran.
|
|
47
|
+
*/
|
|
48
|
+
export type ShellUpdateModalPhase = ShellUpdatePhase | 'confirm';
|
|
49
|
+
|
|
50
|
+
interface ShellUpdateModalProps {
|
|
51
|
+
download: ShellDownload;
|
|
52
|
+
phase: ShellUpdateModalPhase;
|
|
53
|
+
message: string | null;
|
|
54
|
+
onConfirm: () => void;
|
|
55
|
+
onClose: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What this platform actually does with the artifact, in the platform's terms. */
|
|
59
|
+
function installNote(download: ShellDownload): string {
|
|
60
|
+
switch (download.platform) {
|
|
61
|
+
case 'macos':
|
|
62
|
+
return 'Kabmo downloads the new build, checks its signature and replaces itself. The window reopens on the new version.';
|
|
63
|
+
case 'windows':
|
|
64
|
+
return 'Kabmo downloads the new installer and runs it silently. The window closes and reopens on the new version.';
|
|
65
|
+
case 'linux':
|
|
66
|
+
return 'Kabmo downloads the new AppImage over the one it is running from and restarts. A package install (.deb / .rpm) cannot replace itself — that build is offered the release page instead.';
|
|
67
|
+
default:
|
|
68
|
+
return 'Kabmo installs the new build and restarts.';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const SECONDARY =
|
|
73
|
+
'rounded-md border border-ink/20 px-3 py-1.5 text-[11px] font-medium text-ink transition-colors hover:border-ink/40 cursor-pointer';
|
|
74
|
+
const PRIMARY =
|
|
75
|
+
'inline-flex items-center gap-1.5 rounded-md bg-ink px-3 py-1.5 text-[11px] font-medium text-paper transition-opacity hover:opacity-90 disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer';
|
|
76
|
+
|
|
77
|
+
export function ShellUpdateModal({ download, phase, message, onConfirm, onClose }: ShellUpdateModalProps) {
|
|
78
|
+
const label = shellDownloadLabel(download);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Modal
|
|
82
|
+
onClose={onClose}
|
|
83
|
+
maxWidthClass="max-w-sm"
|
|
84
|
+
header={<h2 className="text-sm font-semibold text-ink">{label}</h2>}
|
|
85
|
+
footer={
|
|
86
|
+
<div className="flex items-center justify-end gap-2 px-5 pb-4">
|
|
87
|
+
{phase === 'confirm' && (
|
|
88
|
+
<>
|
|
89
|
+
<button type="button" className={SECONDARY} onClick={onClose}>
|
|
90
|
+
Cancel
|
|
91
|
+
</button>
|
|
92
|
+
<button type="button" className={PRIMARY} onClick={onConfirm}>
|
|
93
|
+
<Download size={13} />
|
|
94
|
+
<span>Install update</span>
|
|
95
|
+
</button>
|
|
96
|
+
</>
|
|
97
|
+
)}
|
|
98
|
+
|
|
99
|
+
{phase === 'working' && (
|
|
100
|
+
<button type="button" className={PRIMARY} disabled>
|
|
101
|
+
<Loader2 size={13} className="animate-spin motion-reduce:animate-none" />
|
|
102
|
+
<span>Installing…</span>
|
|
103
|
+
</button>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
{phase === 'done' && (
|
|
107
|
+
<button type="button" className={PRIMARY} onClick={onClose}>
|
|
108
|
+
<Check size={13} />
|
|
109
|
+
<span>Close</span>
|
|
110
|
+
</button>
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
{phase === 'error' && (
|
|
114
|
+
<>
|
|
115
|
+
<button type="button" className={SECONDARY} onClick={onClose}>
|
|
116
|
+
Close
|
|
117
|
+
</button>
|
|
118
|
+
{/* Retry re-runs the SAME offer: the release is still the one the
|
|
119
|
+
console read, and a failure here is the shell's download or its
|
|
120
|
+
verification, not a stale version. */}
|
|
121
|
+
<button type="button" className={PRIMARY} onClick={onConfirm}>
|
|
122
|
+
<Download size={13} />
|
|
123
|
+
<span>Try again</span>
|
|
124
|
+
</button>
|
|
125
|
+
</>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
}
|
|
129
|
+
>
|
|
130
|
+
<div className="px-5 py-4 space-y-3 text-[11px] leading-5 text-ink/70">
|
|
131
|
+
{phase === 'confirm' && (
|
|
132
|
+
<>
|
|
133
|
+
<p>{installNote(download)}</p>
|
|
134
|
+
<p className="text-ink/50">
|
|
135
|
+
Version {download.latest} · the console keeps running; only this window restarts.
|
|
136
|
+
</p>
|
|
137
|
+
</>
|
|
138
|
+
)}
|
|
139
|
+
|
|
140
|
+
{phase === 'working' && (
|
|
141
|
+
<p className="flex items-center gap-2 text-ink">
|
|
142
|
+
<Loader2 size={14} className="animate-spin motion-reduce:animate-none" />
|
|
143
|
+
<span>Downloading and verifying the new build…</span>
|
|
144
|
+
</p>
|
|
145
|
+
)}
|
|
146
|
+
|
|
147
|
+
{(phase === 'done' || phase === 'error') && (
|
|
148
|
+
<p
|
|
149
|
+
role="status"
|
|
150
|
+
className={`flex items-start gap-2 ${phase === 'error' ? 'text-error' : 'text-ink'}`}
|
|
151
|
+
>
|
|
152
|
+
{phase === 'error' ? (
|
|
153
|
+
<AlertCircle size={14} className="mt-0.5 shrink-0" />
|
|
154
|
+
) : (
|
|
155
|
+
<Check size={14} className="mt-0.5 shrink-0" />
|
|
156
|
+
)}
|
|
157
|
+
<span>{message ?? (phase === 'error' ? 'The update failed.' : 'Update installed.')}</span>
|
|
158
|
+
</p>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
</Modal>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The footer control is a CONTROL; every word a run says is in the dialog.
|
|
8
|
+
*
|
|
9
|
+
* That split is the whole point of this suite. The footer is a 24px row of glyphs,
|
|
10
|
+
* and a status sentence pushed into it moved the neighbouring controls and read as
|
|
11
|
+
* a status line for the SIDEBAR rather than for the update the user just asked for.
|
|
12
|
+
* So the cases below assert the RENDERED tree in both states, not the module's
|
|
13
|
+
* constants: a table in a module would pass while the footer rendered something
|
|
14
|
+
* else.
|
|
15
|
+
*
|
|
16
|
+
* Three behaviours are load-bearing and each was a decision:
|
|
17
|
+
*
|
|
18
|
+
* 1. **A confirmation comes FIRST.** The click replaces the app and restarts it, so
|
|
19
|
+
* a 24px glyph must not do that on a single press with no words.
|
|
20
|
+
* 2. **`done` and `error` print the SHELL's sentence**, inside the dialog. Nothing
|
|
21
|
+
* here invents "Update failed": a shell that verified the download and declined
|
|
22
|
+
* knows why, and that reason is the only thing a user can act on.
|
|
23
|
+
* 3. **A shell that cannot install it gets a LINK**, and the dialog never opens.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
27
|
+
import { Window } from 'happy-dom';
|
|
28
|
+
import { h, render } from 'preact';
|
|
29
|
+
import { act } from 'preact/test-utils';
|
|
30
|
+
import { ShellUpdateButton } from '@/client/components/common/shell-update-button';
|
|
31
|
+
import type { ShellDownload } from '@/client/hooks/ui/updates/shell-download';
|
|
32
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
33
|
+
|
|
34
|
+
const DESKTOP: ShellDownload = {
|
|
35
|
+
url: 'https://github.com/kabmo-labs/kabmo/releases/download/v0.3.2/Kabmo-0.3.2-mac-arm64.zip',
|
|
36
|
+
latest: '0.3.2',
|
|
37
|
+
releaseUrl: 'https://github.com/kabmo-labs/kabmo/releases/tag/v0.8.0',
|
|
38
|
+
direct: true,
|
|
39
|
+
kind: 'update',
|
|
40
|
+
platform: 'macos',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const PAGE: ShellDownload = { ...DESKTOP, url: 'https://github.com/kabmo-labs/kabmo/releases/tag/v0.8.0', direct: false };
|
|
44
|
+
|
|
45
|
+
let container: HTMLElement;
|
|
46
|
+
|
|
47
|
+
/** Install (or remove) a bridge on the page. */
|
|
48
|
+
function bridge(call: ((method: string, params?: Record<string, unknown>) => Promise<unknown>) | null): void {
|
|
49
|
+
const page = globalThis as unknown as { window: { __kabmoCall?: unknown } };
|
|
50
|
+
if (call) page.window.__kabmoCall = call;
|
|
51
|
+
else delete page.window.__kabmoCall;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function mount(download: ShellDownload): Promise<void> {
|
|
55
|
+
await act(async () => {
|
|
56
|
+
render(h(ShellUpdateButton, { download, variant: 'icon' }), container);
|
|
57
|
+
});
|
|
58
|
+
for (let i = 0; i < 5; i += 1) await act(async () => {});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The dialog, by its role — the same locator a browser spec would use.
|
|
63
|
+
*
|
|
64
|
+
* Queried on `document.body`, not on the render container: the dialog is a PORTAL
|
|
65
|
+
* (see the component), which is what keeps it out of the footer row's own text.
|
|
66
|
+
*/
|
|
67
|
+
function dialog(): HTMLElement | null {
|
|
68
|
+
return document.body.querySelector('[role="dialog"]');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Both helpers search the whole body, because the dialog is a PORTAL: its controls
|
|
73
|
+
* live beside the render container, not inside it. The footer control is inside the
|
|
74
|
+
* container, which is itself in the body, so one query covers both.
|
|
75
|
+
*/
|
|
76
|
+
function byName(name: string): HTMLElement | null {
|
|
77
|
+
return document.body.querySelector(`[aria-label="${name}"]`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function buttonByText(text: string): HTMLElement | null {
|
|
81
|
+
const buttons = [...document.body.querySelectorAll('button')];
|
|
82
|
+
return (buttons.find((button) => button.textContent?.trim() === text) as HTMLElement | undefined) ?? null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function click(element: HTMLElement | null): Promise<void> {
|
|
86
|
+
if (!element) throw new Error('nothing to click');
|
|
87
|
+
await act(async () => {
|
|
88
|
+
element.click();
|
|
89
|
+
});
|
|
90
|
+
for (let i = 0; i < 10; i += 1) await act(async () => {});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeAll(() => {
|
|
94
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
95
|
+
container = document.createElement('div');
|
|
96
|
+
document.body.appendChild(container);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(() => {
|
|
100
|
+
act(() => render(null, container));
|
|
101
|
+
bridge(null);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
afterAll(() => {
|
|
105
|
+
container.remove();
|
|
106
|
+
restoreDomGlobals();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('a shell that can install its own update', () => {
|
|
110
|
+
test('the dialog is OUTSIDE the footer row, so the row says nothing about a run', async () => {
|
|
111
|
+
// A dialog rendered inside the footer would put its sentence into the row's own
|
|
112
|
+
// text content (measured in the browser before the portal: the row read as the
|
|
113
|
+
// dialog's body). It also has to be a portal for a second reason — the row is a
|
|
114
|
+
// 24px flex strip, and any `overflow`/`transform` added to it would clip a
|
|
115
|
+
// `fixed` overlay.
|
|
116
|
+
bridge(async () => ({ success: true, message: 'ok' }));
|
|
117
|
+
await mount(DESKTOP);
|
|
118
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
119
|
+
|
|
120
|
+
const modal = document.body.querySelector('[role="dialog"]');
|
|
121
|
+
expect(modal).not.toBeNull();
|
|
122
|
+
expect(container.contains(modal)).toBe(false);
|
|
123
|
+
// The control itself carries no status text in any phase.
|
|
124
|
+
expect(byName('Update Kabmo 0.3.2 for macOS')?.textContent?.trim()).toBe('');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('draws a button, and opens a CONFIRMATION rather than installing on the press', async () => {
|
|
128
|
+
const calls: string[] = [];
|
|
129
|
+
bridge(async (method) => {
|
|
130
|
+
calls.push(method);
|
|
131
|
+
return { success: true, version: '0.3.2', message: 'Kabmo 0.3.2 installed — restarting.', relaunching: true };
|
|
132
|
+
});
|
|
133
|
+
await mount(DESKTOP);
|
|
134
|
+
|
|
135
|
+
const control = byName('Update Kabmo 0.3.2 for macOS');
|
|
136
|
+
expect(control?.tagName).toBe('BUTTON');
|
|
137
|
+
// Nothing has been asked of the shell yet — that is the confirmation's job.
|
|
138
|
+
expect(calls).toEqual([]);
|
|
139
|
+
|
|
140
|
+
await click(control);
|
|
141
|
+
expect(dialog()).not.toBeNull();
|
|
142
|
+
expect(dialog()?.textContent).toContain('Version 0.3.2');
|
|
143
|
+
expect(dialog()?.textContent).toContain('replaces itself');
|
|
144
|
+
// Still nothing: the press opened a dialog, it did not install.
|
|
145
|
+
expect(calls).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('installing happens on the dialog’s own button, and the report stays IN the dialog', async () => {
|
|
149
|
+
const calls: { method: string; params?: Record<string, unknown> }[] = [];
|
|
150
|
+
bridge(async (method, params) => {
|
|
151
|
+
calls.push({ method, params });
|
|
152
|
+
return { success: true, version: '0.3.2', message: 'Kabmo 0.3.2 installed — restarting.', relaunching: true };
|
|
153
|
+
});
|
|
154
|
+
await mount(DESKTOP);
|
|
155
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
156
|
+
await click(buttonByText('Install update'));
|
|
157
|
+
|
|
158
|
+
expect(calls).toEqual([
|
|
159
|
+
{ method: 'update_apply', params: { url: DESKTOP.url, version: '0.3.2' } },
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
// The sentence is the SHELL's, and it is inside the dialog.
|
|
163
|
+
expect(dialog()?.textContent).toContain('Kabmo 0.3.2 installed — restarting.');
|
|
164
|
+
// …and the footer carries no status line of its own: the control is still a
|
|
165
|
+
// control, with its own label.
|
|
166
|
+
expect(byName('Update Kabmo 0.3.2 for macOS')).not.toBeNull();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('a refusal keeps the shell’s reason in the dialog, and offers another try', async () => {
|
|
170
|
+
bridge(async () => ({ success: false, message: 'The downloaded file is not a signed Kabmo build.' }));
|
|
171
|
+
await mount(DESKTOP);
|
|
172
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
173
|
+
await click(buttonByText('Install update'));
|
|
174
|
+
|
|
175
|
+
expect(dialog()?.textContent).toContain('The downloaded file is not a signed Kabmo build.');
|
|
176
|
+
expect(buttonByText('Try again')).not.toBeNull();
|
|
177
|
+
expect(buttonByText('Close')).not.toBeNull();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('closing after a failure, then reopening, starts at the confirmation again', async () => {
|
|
181
|
+
// A dismissed run is not a run: the next press must not greet the user with the
|
|
182
|
+
// previous attempt's refusal.
|
|
183
|
+
bridge(async () => ({ success: false, message: 'The download could not be downloaded.' }));
|
|
184
|
+
await mount(DESKTOP);
|
|
185
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
186
|
+
await click(buttonByText('Install update'));
|
|
187
|
+
await click(buttonByText('Close'));
|
|
188
|
+
expect(dialog()).toBeNull();
|
|
189
|
+
|
|
190
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
191
|
+
expect(dialog()?.textContent).toContain('Version 0.3.2');
|
|
192
|
+
expect(dialog()?.textContent).not.toContain('could not be downloaded');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('Cancel closes without asking the shell anything', async () => {
|
|
196
|
+
const calls: string[] = [];
|
|
197
|
+
bridge(async (method) => {
|
|
198
|
+
calls.push(method);
|
|
199
|
+
return { success: true, message: 'ok' };
|
|
200
|
+
});
|
|
201
|
+
await mount(DESKTOP);
|
|
202
|
+
await click(byName('Update Kabmo 0.3.2 for macOS'));
|
|
203
|
+
await click(buttonByText('Cancel'));
|
|
204
|
+
|
|
205
|
+
expect(dialog()).toBeNull();
|
|
206
|
+
expect(calls).toEqual([]);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('the phone footer’s variant', () => {
|
|
211
|
+
test('draws the short label on the same button, and opens the same dialog', async () => {
|
|
212
|
+
// The two layouts pass different `variant`s because a 24px glyph and a word are
|
|
213
|
+
// different rows — but they must be the same CONTROL: a link on one layout and a
|
|
214
|
+
// button on the other is the drift this component exists to prevent.
|
|
215
|
+
bridge(async () => ({ success: true, version: '0.3.2', message: 'Kabmo 0.3.2 installed — restarting.' }));
|
|
216
|
+
await act(async () => {
|
|
217
|
+
render(h(ShellUpdateButton, { download: DESKTOP, variant: 'label' }), container);
|
|
218
|
+
});
|
|
219
|
+
for (let i = 0; i < 5; i += 1) await act(async () => {});
|
|
220
|
+
|
|
221
|
+
const control = byName('Update Kabmo 0.3.2 for macOS');
|
|
222
|
+
expect(control?.tagName).toBe('BUTTON');
|
|
223
|
+
expect(control?.textContent?.trim()).toBe('Update macOS');
|
|
224
|
+
|
|
225
|
+
await click(control);
|
|
226
|
+
expect(dialog()?.textContent).toContain('Version 0.3.2');
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('a shell that cannot install it', () => {
|
|
231
|
+
test('draws a link to the release page, and no dialog', async () => {
|
|
232
|
+
bridge(async () => null);
|
|
233
|
+
await mount(PAGE);
|
|
234
|
+
|
|
235
|
+
const control = byName('Update Kabmo 0.3.2 for macOS');
|
|
236
|
+
expect(control?.tagName).toBe('A');
|
|
237
|
+
expect(control?.getAttribute('href')).toBe(PAGE.url);
|
|
238
|
+
expect(control?.getAttribute('target')).toBe('_blank');
|
|
239
|
+
|
|
240
|
+
await click(control);
|
|
241
|
+
expect(dialog()).toBeNull();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('a browser draws the link too, because there is no shell to ask', async () => {
|
|
245
|
+
bridge(null);
|
|
246
|
+
await mount(DESKTOP);
|
|
247
|
+
|
|
248
|
+
expect(byName('Update Kabmo 0.3.2 for macOS')?.tagName).toBe('A');
|
|
249
|
+
expect(dialog()).toBeNull();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The native shell's update/install control, shared by both sidebar layouts.
|
|
8
|
+
*
|
|
9
|
+
* ## Two controls, because there are two different jobs
|
|
10
|
+
*
|
|
11
|
+
* - **A link** when the console cannot name a file: a desktop shell that did not
|
|
12
|
+
* report its architecture, or any offer whose artifact is not installable from
|
|
13
|
+
* inside. Following it is the browser's (or the WebView's) job.
|
|
14
|
+
* - **A button** when the shell CAN install it: the click opens a CONFIRMATION, and
|
|
15
|
+
* the confirmation asks the shell to download, verify and replace itself. That is
|
|
16
|
+
* the desktop self-update, and it is the whole reason this component exists.
|
|
17
|
+
*
|
|
18
|
+
* The decision is `canSelfUpdate`, never a check on the platform at the call site:
|
|
19
|
+
* Android installs through `PackageInstaller` (its own path, unchanged), iOS cannot
|
|
20
|
+
* install at all, and a browser has no shell to ask.
|
|
21
|
+
*
|
|
22
|
+
* ## The control is ONLY a control
|
|
23
|
+
*
|
|
24
|
+
* Every word a run has to say — the confirmation, the progress, the shell's own
|
|
25
|
+
* refusal — is in `Modal.tsx`. The footer is a 24px row of glyphs, and a status
|
|
26
|
+
* sentence pushed into it moved the neighbouring controls and read as a status
|
|
27
|
+
* line for the SIDEBAR rather than for the update.
|
|
28
|
+
*
|
|
29
|
+
* ## The state lives here, not in either footer
|
|
30
|
+
*
|
|
31
|
+
* Both layouts draw this control and each unmounts at a different moment (a phone
|
|
32
|
+
* closes its drawer, a desktop swaps sessions). One hook, one vocabulary of
|
|
33
|
+
* phases, so the two cannot report the same run differently.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { useState } from 'preact/hooks';
|
|
37
|
+
import { createPortal } from 'preact/compat';
|
|
38
|
+
import { Download, Loader2 } from 'lucide-preact';
|
|
39
|
+
import {
|
|
40
|
+
shellDownloadLabel,
|
|
41
|
+
shellDownloadShortLabel,
|
|
42
|
+
type ShellDownload,
|
|
43
|
+
} from '@/client/hooks/ui/updates/shell-download';
|
|
44
|
+
import { canSelfUpdate, useShellUpdate } from '@/client/hooks/ui/updates/shell-update';
|
|
45
|
+
import { ShellUpdateModal } from '@/client/components/common/shell-update-button/Modal';
|
|
46
|
+
|
|
47
|
+
interface ShellUpdateButtonProps {
|
|
48
|
+
download: ShellDownload;
|
|
49
|
+
/** `icon` for the desktop footer's glyph row, `label` for the phone's. */
|
|
50
|
+
variant: 'icon' | 'label';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const ICON_CLASS = 'p-1 rounded hover:text-ink hover:bg-ink/5 cursor-pointer transition-colors';
|
|
54
|
+
|
|
55
|
+
export function ShellUpdateButton({ download, variant }: ShellUpdateButtonProps) {
|
|
56
|
+
const { phase, message, apply, reset, working } = useShellUpdate();
|
|
57
|
+
// The dialog is open from the CLICK until it is dismissed, and the run's phases
|
|
58
|
+
// are drawn inside it. A closed dialog whose run is still `working` is not a
|
|
59
|
+
// state this component can be in: `confirm` is what opens it.
|
|
60
|
+
const [open, setOpen] = useState(false);
|
|
61
|
+
const label = shellDownloadLabel(download);
|
|
62
|
+
|
|
63
|
+
if (!canSelfUpdate(download)) {
|
|
64
|
+
// A link, and `target="_blank"` hands it to the system browser so the console
|
|
65
|
+
// is not replaced by a file download.
|
|
66
|
+
return (
|
|
67
|
+
<a
|
|
68
|
+
href={download.url}
|
|
69
|
+
target="_blank"
|
|
70
|
+
rel="noopener noreferrer"
|
|
71
|
+
title={label}
|
|
72
|
+
aria-label={label}
|
|
73
|
+
className={ICON_CLASS}
|
|
74
|
+
>
|
|
75
|
+
{variant === 'icon' ? <Download size={16} /> : <span>{shellDownloadShortLabel(download)}</span>}
|
|
76
|
+
</a>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
// A dismissed run is not a run: reopening starts from the confirmation, not
|
|
85
|
+
// from the previous attempt's refusal.
|
|
86
|
+
onClick={() => {
|
|
87
|
+
reset();
|
|
88
|
+
setOpen(true);
|
|
89
|
+
}}
|
|
90
|
+
disabled={working}
|
|
91
|
+
title={label}
|
|
92
|
+
aria-label={label}
|
|
93
|
+
className={`${ICON_CLASS} disabled:cursor-not-allowed disabled:opacity-60 inline-flex items-center gap-1`}
|
|
94
|
+
>
|
|
95
|
+
{working ? (
|
|
96
|
+
<Loader2 size={variant === 'icon' ? 16 : 13} className="animate-spin motion-reduce:animate-none" />
|
|
97
|
+
) : (
|
|
98
|
+
<Download size={variant === 'icon' ? 16 : 13} />
|
|
99
|
+
)}
|
|
100
|
+
{variant === 'label' && <span>{shellDownloadShortLabel(download)}</span>}
|
|
101
|
+
</button>
|
|
102
|
+
|
|
103
|
+
{open &&
|
|
104
|
+
// A PORTAL, not a child of this row. The footer is a 24px flex row of
|
|
105
|
+
// glyphs, so a dialog rendered inside it is nested in a control strip: its
|
|
106
|
+
// text joins the row's own text content (measured in the browser — the row
|
|
107
|
+
// read as the dialog's body), and any `overflow`/`transform` added to that
|
|
108
|
+
// row later would clip a `fixed` overlay. The portal is what makes "the
|
|
109
|
+
// footer says nothing about a run" true rather than merely visually true.
|
|
110
|
+
createPortal(
|
|
111
|
+
<ShellUpdateModal
|
|
112
|
+
download={download}
|
|
113
|
+
phase={phase === 'idle' ? 'confirm' : phase}
|
|
114
|
+
message={message}
|
|
115
|
+
onConfirm={() => void apply(download)}
|
|
116
|
+
// Closing mid-run hides the dialog but does not cancel the shell: it is
|
|
117
|
+
// already replacing itself, and a Cancel that could not stop it would be
|
|
118
|
+
// a button that lies. The control stays disabled until the run answers.
|
|
119
|
+
onClose={() => setOpen(false)}
|
|
120
|
+
/>,
|
|
121
|
+
document.body,
|
|
122
|
+
)}
|
|
123
|
+
</>
|
|
124
|
+
);
|
|
125
|
+
}
|