@kabmo-labs/kabmo 0.16.0 → 0.18.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 +2 -2
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +552 -471
- package/dist/client/static/js/index-hp75vsv9.css +1 -0
- package/dist/client/static/js/{index-cpydmygd.js → index-tc09dtca.js} +897 -886
- package/package.json +1 -1
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +143 -0
- package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
- package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
- package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
- package/src/client/components/common/code-surface/extensions.ts +7 -4
- package/src/client/components/common/code-surface/theme.ts +34 -9
- package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
- package/src/client/components/common/code-surface/whitespace.ts +140 -0
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
- package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
- package/src/client/components/common/markdown-review/index.tsx +129 -0
- package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +92 -44
- package/src/client/components/common/server-control/index.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +120 -0
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
- package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
- package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
- package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
- package/src/client/components/layout/update-popup/index.tsx +5 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
- package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
- package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
- package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
- package/src/client/components/settings/Modal.tsx +9 -3
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +38 -44
- package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
- package/src/client/components/settings/categories/McpSettings.tsx +4 -21
- package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
- package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
- package/src/client/components/settings/categories/SkillSettings.tsx +8 -5
- package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
- package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +14 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
- package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
- package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
- package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
- package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
- package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
- package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
- package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
- package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
- package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
- package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
- package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
- package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
- package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
- package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
- package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
- package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
- package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
- package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
- package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
- package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +236 -0
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +164 -239
- package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +144 -87
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +188 -0
- package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
- package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
- package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
- package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
- package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
- package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
- package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
- package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
- package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
- package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
- package/src/client/components/workspace/browser-panel/index.tsx +50 -4
- package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
- package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
- package/src/client/components/workspace/diff-panel/changes.ts +28 -12
- package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
- package/src/client/components/workspace/diff-panel/merge.ts +21 -1
- package/src/client/components/workspace/editor/Body.tsx +7 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
- package/src/client/components/workspace/editor/FilePane.tsx +12 -0
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
- package/src/client/components/workspace/editor/index.tsx +25 -22
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
- package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
- package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
- package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
- package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
- package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
- package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
- package/src/client/components/workspace/file-explorer/index.tsx +21 -20
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
- package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
- package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
- package/src/client/data/agent-data/builtin.ts +0 -10
- package/src/client/data/agent-data/orchestrator.ts +0 -45
- package/src/client/data/agent-data/specialist.ts +0 -100
- package/src/client/data/mock/token-usage.ts +170 -120
- package/src/client/data/settings/omp-schema.json +123 -4
- package/src/client/data/settings/project.ts +9 -28
- package/src/client/data/settings/skill.ts +6 -32
- package/src/client/hooks/browser/use-annotate.test.ts +143 -0
- package/src/client/hooks/browser/use-annotate.ts +98 -0
- package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
- package/src/client/hooks/browser/use-close-tab.ts +67 -0
- package/src/client/hooks/browser/use-screencast.ts +13 -1
- package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
- package/src/client/hooks/chat/composer/browser-context.ts +40 -16
- package/src/client/hooks/chat/composer/items.test.ts +1 -1
- package/src/client/hooks/chat/composer/review-context.ts +38 -0
- package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
- package/src/client/hooks/chat/composer/use-draft.ts +31 -2
- package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
- package/src/client/hooks/editor/use-document-annotations.ts +124 -0
- package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
- package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
- package/src/client/hooks/editor/use-preview-review.ts +148 -0
- package/src/client/hooks/settings/agents.ts +149 -0
- package/src/client/hooks/settings/crud-list.test.ts +28 -6
- package/src/client/hooks/settings/crud-list.ts +96 -57
- package/src/client/hooks/settings/omp-config.ts +164 -0
- package/src/client/hooks/settings/projects/index.ts +294 -0
- package/src/client/hooks/settings/projects.test.ts +237 -0
- package/src/client/hooks/settings/skill-catalog.ts +101 -9
- package/src/client/hooks/settings/skill-git-import.ts +153 -0
- package/src/client/hooks/settings/useTokenUsage.ts +125 -0
- package/src/client/hooks/settings/write-feedback.test.ts +104 -0
- package/src/client/hooks/settings/write-feedback.ts +63 -0
- package/src/client/hooks/shell/servers.test.ts +166 -0
- package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/updates/index.test.ts +100 -1
- package/src/client/hooks/ui/updates/index.ts +50 -0
- package/src/client/hooks/ui/updates/notes.test.ts +138 -0
- package/src/client/hooks/ui/updates/notes.ts +57 -0
- package/src/client/hooks/ui/updates/shell-download.ts +1 -1
- package/src/client/hooks/ui/updates/shell-update.ts +2 -6
- package/src/client/hooks/workspace/file-row-drag.ts +41 -0
- package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
- package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
- package/src/client/hooks/workspace/root-drop-target.ts +77 -0
- package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
- package/src/client/lib/browser/element-at.test.ts +229 -0
- package/src/client/lib/browser/element-at.ts +139 -0
- package/src/client/lib/desktop/dropped-paths.ts +1 -1
- package/src/client/lib/desktop/titlebar.test.ts +12 -3
- package/src/client/lib/desktop/titlebar.ts +1 -1
- package/src/client/lib/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/lib/shell/desktop.ts +117 -0
- package/src/client/lib/shell/servers.ts +75 -0
- package/src/client/lib/shell/transport.ts +216 -0
- package/src/client/main.tsx +9 -0
- package/src/client/tailwind.css +65 -0
- package/src/server/lib/btw/lifecycle.server.ts +2 -2
- package/src/server/lib/db/schema.ts +7 -0
- package/src/server/lib/db/seed-terminal.test.ts +4 -0
- package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
- package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
- package/src/server/lib/omp/config/agents.ts +231 -61
- package/src/server/lib/omp/config/definitions.test.ts +9 -105
- package/src/server/lib/omp/config/extensions.ts +16 -7
- package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
- package/src/server/lib/omp/config/skill-sources.ts +49 -0
- package/src/server/lib/omp/config/skills-git-install.ts +155 -0
- package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
- package/src/server/lib/omp/config/skills-git.test.ts +220 -0
- package/src/server/lib/omp/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/process.ts +11 -14
- package/src/server/lib/omp/rpc/session-commands.ts +6 -3
- package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
- package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
- package/src/server/lib/omp/rpc/utility.ts +12 -0
- package/src/server/lib/review/schema.server.ts +45 -0
- package/src/server/lib/review/store.server.ts +138 -0
- package/src/server/lib/terminal/attach-replay.test.ts +132 -0
- package/src/server/lib/terminal/output.test.ts +166 -0
- package/src/server/lib/terminal/output.ts +104 -0
- package/src/server/lib/terminal/runtime.server.ts +5 -0
- package/src/server/lib/terminal/send-result.test.ts +33 -0
- package/src/server/lib/terminal/send-result.ts +32 -0
- package/src/server/lib/terminal/session.server.ts +45 -11
- package/src/server/lib/terminal/store-liveness.test.ts +4 -0
- package/src/server/lib/updates/active-notes.test.ts +149 -0
- package/src/server/lib/updates/active-notes.ts +75 -0
- package/src/server/lib/updates/changelog-file.ts +42 -11
- package/src/server/lib/updates/changelog.test.ts +15 -1
- package/src/server/lib/updates/omp.ts +42 -15
- package/src/server/lib/updates/release-url.ts +27 -1
- package/src/server/lib/usage/index-parse.test.ts +200 -0
- package/src/server/lib/usage/index-parse.ts +178 -0
- package/src/server/lib/usage/index-query.server.ts +248 -0
- package/src/server/lib/usage/index-scan.server.ts +343 -0
- package/src/server/lib/usage/index-schema.server.ts +82 -0
- package/src/server/lib/usage/index.test.ts +234 -0
- package/src/server/lib/usage/providers.server.ts +4 -53
- package/src/server/lib/workspace/project-model.server.test.ts +102 -0
- package/src/server/lib/workspace/project-model.server.ts +47 -0
- package/src/server/lib/workspace/project-patch.server.ts +156 -0
- package/src/server/routes/agent/new.ts +8 -1
- package/src/server/routes/browser/index.ts +3 -0
- package/src/server/routes/browser/stream.ts +31 -2
- package/src/server/routes/browser/tabs.test.ts +94 -0
- package/src/server/routes/browser/tabs.ts +85 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/review/bindings.ts +11 -0
- package/src/server/routes/review/index.ts +127 -0
- package/src/server/routes/review/routes.test.ts +191 -0
- package/src/server/routes/settings/agents.test.ts +180 -0
- package/src/server/routes/settings/agents.ts +99 -94
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/projects.ts +53 -19
- package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
- package/src/server/routes/settings/settings-store-routes.test.ts +11 -115
- package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
- package/src/server/routes/settings/skills.test.ts +225 -0
- package/src/server/routes/settings/skills.ts +18 -15
- package/src/server/routes/telemetry/tokens.test.ts +145 -0
- package/src/server/routes/telemetry/tokens.ts +70 -149
- package/src/server/routes/terminal/ws.ts +6 -5
- package/src/server/routes/updates/index.ts +2 -0
- package/src/server/routes/updates/notes.ts +34 -0
- package/src/server/routes/updates/routes.test.ts +49 -0
- package/src/shared/lib/browser/annotate.test.ts +283 -0
- package/src/shared/lib/browser/annotate.ts +231 -0
- package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
- package/src/shared/lib/browser/frame-gate.test.ts +91 -0
- package/src/shared/lib/browser/frame-gate.ts +69 -0
- package/src/shared/lib/browser/frame-params.test.ts +43 -0
- package/src/shared/lib/browser/frame-params.ts +60 -0
- package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
- package/src/shared/lib/browser/frame-pipeline.ts +80 -0
- package/src/shared/lib/browser/page-context.ts +60 -4
- package/src/shared/lib/browser/snapshot.test.ts +115 -0
- package/src/shared/lib/browser/snapshot.ts +112 -0
- package/src/shared/lib/browser/tab-close.test.ts +74 -0
- package/src/shared/lib/browser/tab-close.ts +77 -0
- package/src/shared/lib/browser/viewer.ts +45 -26
- package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
- package/src/shared/lib/chat/tool/artifact.ts +55 -20
- package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
- package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
- package/src/shared/lib/chat/tool/minimized.ts +64 -0
- package/src/shared/lib/chat/tool/summary.test.ts +28 -8
- package/src/shared/lib/chat/tool/summary.ts +3 -32
- package/src/shared/lib/fs/folder-chain.test.ts +81 -1
- package/src/shared/lib/fs/folder-chain.ts +84 -0
- package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
- package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
- package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
- package/src/shared/lib/markdown/blocks/scan.ts +100 -0
- package/src/shared/lib/markdown/blocks/types.ts +62 -0
- package/src/shared/lib/markdown/marked.ts +58 -147
- package/src/shared/lib/markdown/math-extensions.ts +168 -0
- package/src/shared/lib/markdown/review/prompt.ts +77 -0
- package/src/shared/lib/markdown/review/reconcile.ts +55 -0
- package/src/shared/lib/markdown/review/review.test.ts +96 -0
- package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
- package/src/shared/lib/markdown/xml-sections.ts +139 -0
- package/src/shared/lib/models/provider/label.ts +57 -0
- package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
- package/src/shared/lib/omp/config/agent-file.ts +43 -0
- package/src/shared/lib/omp/config/row-value.test.ts +95 -0
- package/src/shared/lib/omp/config/row-value.ts +97 -0
- package/src/shared/lib/omp/config/schema.test.ts +66 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
- package/src/shared/lib/omp/rpc/frame.ts +49 -40
- package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
- package/src/shared/lib/omp/session/job-progress.ts +31 -0
- package/src/shared/lib/omp/session/proc.ts +5 -0
- package/src/shared/lib/omp/session/wait.ts +5 -0
- package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
- package/src/shared/lib/ui/menu-anchor.ts +89 -0
- package/src/shared/lib/ui/mobile-overlay.ts +61 -0
- package/src/shared/lib/ui/svg-scope.test.ts +97 -0
- package/src/shared/lib/ui/svg-scope.ts +134 -0
- package/src/shared/lib/usage/breakdown.test.ts +197 -0
- package/src/shared/lib/usage/breakdown.ts +241 -0
- package/src/shared/lib/usage/range.test.ts +204 -0
- package/src/shared/lib/usage/range.ts +240 -0
- package/src/shared/lib/usage/view.test.ts +85 -0
- package/src/shared/lib/usage/view.ts +74 -0
- package/src/shared/lib/workspace/project-accent.test.ts +69 -0
- package/src/shared/lib/workspace/project-accent.ts +63 -0
- package/src/shared/lib/workspace/project-icon.ts +40 -0
- package/src/shared/lib/workspace/project-model.test.ts +79 -0
- package/src/shared/lib/workspace/project-model.ts +64 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/skill.ts +53 -3
- package/src/shared/types/settings/state.ts +4 -3
- package/src/shared/types/settings/write.ts +6 -0
- package/src/shared/types/tokenUsage.ts +128 -21
- package/src/shared/types/updates.ts +20 -0
- package/src/test-support/file-explorer-disk.test-util.ts +25 -1
- package/src/test-support/file-explorer-drag.test-util.ts +88 -0
- package/src/test-support/file-explorer.test-util.ts +47 -47
- package/dist/client/static/js/index-fjnq2z2d.css +0 -1
- package/src/client/components/common/code-surface/indent-guide.ts +0 -104
- package/src/client/components/common/server-switcher/index.test.tsx +0 -150
- package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
- package/src/client/hooks/desktop/servers.test.ts +0 -73
- package/src/client/lib/desktop/bridge.ts +0 -203
- package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
- package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
- package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
- package/src/server/lib/omp/session/usage/shaping.ts +0 -130
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
- package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
2
|
+
import type { GitRepoInspection, GitSkillEntry, GitSkillInstallMode, GitSkillInstallResult } from '@/shared/types';
|
|
3
|
+
|
|
4
|
+
export interface GitImportState {
|
|
5
|
+
inspecting: boolean;
|
|
6
|
+
installing: boolean;
|
|
7
|
+
/** The repository as the last successful inspection named it. */
|
|
8
|
+
repo: string | null;
|
|
9
|
+
url: string;
|
|
10
|
+
skills: GitSkillEntry[];
|
|
11
|
+
notes: string[];
|
|
12
|
+
/** Repo-relative paths the user ticked. */
|
|
13
|
+
selected: string[];
|
|
14
|
+
mode: GitSkillInstallMode;
|
|
15
|
+
overwrite: boolean;
|
|
16
|
+
error: string | null;
|
|
17
|
+
result: GitSkillInstallResult | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GitImportController extends GitImportState {
|
|
21
|
+
inspect: (url: string) => Promise<void>;
|
|
22
|
+
toggle: (path: string) => void;
|
|
23
|
+
toggleAll: (select: boolean) => void;
|
|
24
|
+
setMode: (mode: GitSkillInstallMode) => void;
|
|
25
|
+
setOverwrite: (overwrite: boolean) => void;
|
|
26
|
+
install: () => Promise<GitSkillInstallResult | null>;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const INITIAL: GitImportState = {
|
|
31
|
+
inspecting: false,
|
|
32
|
+
installing: false,
|
|
33
|
+
repo: null,
|
|
34
|
+
url: '',
|
|
35
|
+
skills: [],
|
|
36
|
+
notes: [],
|
|
37
|
+
selected: [],
|
|
38
|
+
mode: 'managed_copy',
|
|
39
|
+
overwrite: false,
|
|
40
|
+
error: null,
|
|
41
|
+
result: null,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
async function post<T>(body: unknown): Promise<T> {
|
|
45
|
+
const response = await fetch('/api/settings/skills', {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: { 'Content-Type': 'application/json' },
|
|
48
|
+
body: JSON.stringify(body),
|
|
49
|
+
});
|
|
50
|
+
const data = (await response.json().catch(() => ({}))) as T & { error?: string };
|
|
51
|
+
if (!response.ok || data.error) throw new Error(data.error || `Request failed (${response.status})`);
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The From-Git pane's state machine: inspect a repository, pick skills, install.
|
|
57
|
+
*
|
|
58
|
+
* Every entry starts TICKED except the ones the server already reported as
|
|
59
|
+
* installed or unloadable — the common case is "install everything in this
|
|
60
|
+
* repository", and a row that would be skipped anyway is better pre-unticked than
|
|
61
|
+
* reported as a failure after the click.
|
|
62
|
+
*
|
|
63
|
+
* `install` never clears `result`: the dialog renders the outcome (installed and
|
|
64
|
+
* skipped, with the server's reason per row) instead of a toast that closes the
|
|
65
|
+
* only place the reasons could be read.
|
|
66
|
+
*/
|
|
67
|
+
export function useSkillGitImport(): GitImportController {
|
|
68
|
+
const [state, setState] = useState<GitImportState>(INITIAL);
|
|
69
|
+
|
|
70
|
+
const inspect = useCallback(async (url: string) => {
|
|
71
|
+
const trimmed = url.trim();
|
|
72
|
+
if (!trimmed) {
|
|
73
|
+
setState((prev) => ({ ...prev, error: 'Paste a repository URL first.' }));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
setState((prev) => ({ ...prev, inspecting: true, error: null, result: null, url: trimmed }));
|
|
77
|
+
try {
|
|
78
|
+
const inspection = await post<GitRepoInspection & { repo: string }>({ type: 'inspect_git_repo', url: trimmed });
|
|
79
|
+
const installable = inspection.skills.filter((skill) => skill.loadable && !skill.installed);
|
|
80
|
+
setState((prev) => ({
|
|
81
|
+
...prev,
|
|
82
|
+
inspecting: false,
|
|
83
|
+
repo: inspection.repo,
|
|
84
|
+
url: trimmed,
|
|
85
|
+
skills: inspection.skills,
|
|
86
|
+
notes: inspection.notes ?? [],
|
|
87
|
+
selected: installable.map((skill) => skill.path),
|
|
88
|
+
}));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
setState((prev) => ({
|
|
91
|
+
...prev,
|
|
92
|
+
inspecting: false,
|
|
93
|
+
skills: [],
|
|
94
|
+
selected: [],
|
|
95
|
+
repo: null,
|
|
96
|
+
error: error instanceof Error ? error.message : String(error),
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
const toggle = useCallback((path: string) => {
|
|
102
|
+
setState((prev) => ({
|
|
103
|
+
...prev,
|
|
104
|
+
selected: prev.selected.includes(path)
|
|
105
|
+
? prev.selected.filter((entry) => entry !== path)
|
|
106
|
+
: [...prev.selected, path],
|
|
107
|
+
}));
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const toggleAll = useCallback((select: boolean) => {
|
|
111
|
+
setState((prev) => ({
|
|
112
|
+
...prev,
|
|
113
|
+
selected: select
|
|
114
|
+
? prev.skills.filter((skill) => skill.loadable && !skill.installed).map((skill) => skill.path)
|
|
115
|
+
: [],
|
|
116
|
+
}));
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
const setMode = useCallback((mode: GitSkillInstallMode) => {
|
|
120
|
+
setState((prev) => ({ ...prev, mode }));
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
const setOverwrite = useCallback((overwrite: boolean) => {
|
|
124
|
+
setState((prev) => ({ ...prev, overwrite }));
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
const install = useCallback(async () => {
|
|
128
|
+
if (state.selected.length === 0 || !state.url) return null;
|
|
129
|
+
setState((prev) => ({ ...prev, installing: true, error: null, result: null }));
|
|
130
|
+
try {
|
|
131
|
+
const result = await post<GitSkillInstallResult>({
|
|
132
|
+
type: 'install_git_skills',
|
|
133
|
+
url: state.url,
|
|
134
|
+
paths: state.selected,
|
|
135
|
+
mode: state.mode,
|
|
136
|
+
overwrite: state.overwrite,
|
|
137
|
+
});
|
|
138
|
+
setState((prev) => ({ ...prev, installing: false, result }));
|
|
139
|
+
return result;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
setState((prev) => ({
|
|
142
|
+
...prev,
|
|
143
|
+
installing: false,
|
|
144
|
+
error: error instanceof Error ? error.message : String(error),
|
|
145
|
+
}));
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}, [state.selected, state.url, state.mode, state.overwrite]);
|
|
149
|
+
|
|
150
|
+
const reset = useCallback(() => setState(INITIAL), []);
|
|
151
|
+
|
|
152
|
+
return { ...state, inspect, toggle, toggleAll, setMode, setOverwrite, install, reset };
|
|
153
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Loads the Token Usage payload and keeps it fresh while the index catches up.
|
|
8
|
+
*
|
|
9
|
+
* Three behaviours the panel depends on:
|
|
10
|
+
*
|
|
11
|
+
* - **One request per period.** Cadence and breakdown tab live in the
|
|
12
|
+
* component; changing them re-folds the payload client-side.
|
|
13
|
+
* - **Stale-while-revalidate.** A range change keeps the previous numbers on
|
|
14
|
+
* screen (`refreshing`) instead of blanking the panel, and the first load is
|
|
15
|
+
* the only case that shows a skeleton.
|
|
16
|
+
* - **Abort.** A fast user clicking ranges would otherwise render whichever
|
|
17
|
+
* response happened to arrive last.
|
|
18
|
+
*
|
|
19
|
+
* While `index.state` is `building` the hook polls: the indexer answers with
|
|
20
|
+
* the data it already has, so the panel draws immediately and the footer says
|
|
21
|
+
* "indexing…" until the next poll reports `ready`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
25
|
+
import type { TimeRangeType, TokenUsagePayload } from '@/shared/types';
|
|
26
|
+
|
|
27
|
+
const POLL_MS = 1_500;
|
|
28
|
+
|
|
29
|
+
export interface TokenUsageState {
|
|
30
|
+
payload: TokenUsagePayload | null;
|
|
31
|
+
error: string | null;
|
|
32
|
+
/** True only until the first payload arrives. */
|
|
33
|
+
loading: boolean;
|
|
34
|
+
/** A request is in flight while older data is on screen. */
|
|
35
|
+
refreshing: boolean;
|
|
36
|
+
reload: (force?: boolean) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useTokenUsage(range: TimeRangeType, custom: { from: string; to: string }): TokenUsageState {
|
|
40
|
+
const [payload, setPayload] = useState<TokenUsagePayload | null>(null);
|
|
41
|
+
const [error, setError] = useState<string | null>(null);
|
|
42
|
+
const [loading, setLoading] = useState(true);
|
|
43
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
44
|
+
const abortRef = useRef<AbortController | null>(null);
|
|
45
|
+
const payloadRef = useRef<TokenUsagePayload | null>(null);
|
|
46
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
47
|
+
const forceRef = useRef(false);
|
|
48
|
+
|
|
49
|
+
const clearTimer = () => {
|
|
50
|
+
if (timerRef.current !== null) {
|
|
51
|
+
clearTimeout(timerRef.current);
|
|
52
|
+
timerRef.current = null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const request = useCallback(
|
|
57
|
+
(): string => {
|
|
58
|
+
const params = new URLSearchParams({ range });
|
|
59
|
+
if (range === 'custom') {
|
|
60
|
+
params.set('customFrom', custom.from);
|
|
61
|
+
params.set('customTo', custom.to);
|
|
62
|
+
}
|
|
63
|
+
return `/api/telemetry/tokens?${params.toString()}${forceRef.current ? '&refresh=1' : ''}`;
|
|
64
|
+
},
|
|
65
|
+
[range, custom.from, custom.to],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const load = useCallback(
|
|
69
|
+
async (force: boolean): Promise<void> => {
|
|
70
|
+
abortRef.current?.abort();
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
abortRef.current = controller;
|
|
73
|
+
forceRef.current = force;
|
|
74
|
+
setRefreshing(true);
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(request(), {
|
|
77
|
+
signal: controller.signal,
|
|
78
|
+
method: force ? 'POST' : 'GET',
|
|
79
|
+
});
|
|
80
|
+
const body = (await response.json()) as TokenUsagePayload & { error?: string };
|
|
81
|
+
if (!response.ok || body.error) throw new Error(body.error ?? `Token usage failed (${response.status})`);
|
|
82
|
+
payloadRef.current = body;
|
|
83
|
+
setPayload(body);
|
|
84
|
+
setError(null);
|
|
85
|
+
setLoading(false);
|
|
86
|
+
clearTimer();
|
|
87
|
+
if (body.index.state === 'building') {
|
|
88
|
+
timerRef.current = setTimeout(() => {
|
|
89
|
+
forceRef.current = false;
|
|
90
|
+
void load(false);
|
|
91
|
+
}, POLL_MS);
|
|
92
|
+
}
|
|
93
|
+
} catch (caught) {
|
|
94
|
+
if (controller.signal.aborted) return;
|
|
95
|
+
setError(caught instanceof Error ? caught.message : 'Failed to load token usage');
|
|
96
|
+
setLoading(false);
|
|
97
|
+
} finally {
|
|
98
|
+
if (!controller.signal.aborted) setRefreshing(false);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[request],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
// Only the FIRST load has nothing to show. A range change keeps the
|
|
106
|
+
// previous numbers on screen with an "updating…" hint instead of blanking
|
|
107
|
+
// the panel the user is reading.
|
|
108
|
+
setLoading((current) => current && payloadRef.current === null);
|
|
109
|
+
void load(false);
|
|
110
|
+
return () => {
|
|
111
|
+
abortRef.current?.abort();
|
|
112
|
+
clearTimer();
|
|
113
|
+
};
|
|
114
|
+
}, [load]);
|
|
115
|
+
|
|
116
|
+
const reload = useCallback(
|
|
117
|
+
(force = false) => {
|
|
118
|
+
clearTimer();
|
|
119
|
+
void load(force);
|
|
120
|
+
},
|
|
121
|
+
[load],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return { payload, error, loading, refreshing, reload };
|
|
125
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The write-feedback contract every settings pane now shares.
|
|
8
|
+
*
|
|
9
|
+
* This exists because the panes used to paint "Saved successfully" the moment
|
|
10
|
+
* the button was pressed — before the request answered — so a refused write (a
|
|
11
|
+
* duplicate preset name, a read-only native file, a validator rejecting the
|
|
12
|
+
* draft) showed success over a row that had not changed. The badge is now driven
|
|
13
|
+
* by the outcome and nothing else, and a refusal keeps the server's sentence.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
import { useWriteFeedback, type WriteFeedback } from '@/client/hooks/settings/write-feedback';
|
|
21
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
22
|
+
import type { WriteOutcome } from '@/shared/types';
|
|
23
|
+
|
|
24
|
+
let container: HTMLElement | null = null;
|
|
25
|
+
let feedback: WriteFeedback | null = null;
|
|
26
|
+
|
|
27
|
+
function Probe() {
|
|
28
|
+
feedback = useWriteFeedback();
|
|
29
|
+
return h('div', null, feedback.saving ? 'saving' : feedback.saved ? 'saved' : 'idle');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
beforeAll(() => {
|
|
33
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
if (container) render(null, container);
|
|
38
|
+
container = null;
|
|
39
|
+
feedback = null;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
restoreDomGlobals();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
async function mount(): Promise<void> {
|
|
47
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
48
|
+
await act(async () => { render(h(Probe, {}), container as HTMLElement); });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Run one write and drain its promise chain plus the resulting renders. */
|
|
52
|
+
async function run(action: () => Promise<WriteOutcome>): Promise<boolean> {
|
|
53
|
+
let ok = false;
|
|
54
|
+
await act(async () => {
|
|
55
|
+
const pending = feedback!.run(action);
|
|
56
|
+
ok = await pending;
|
|
57
|
+
});
|
|
58
|
+
return ok;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('useWriteFeedback', () => {
|
|
62
|
+
test('a landed write flashes saved instead of trusting the click', async () => {
|
|
63
|
+
await mount();
|
|
64
|
+
expect(await run(async () => ({ ok: true }))).toBe(true);
|
|
65
|
+
expect(feedback?.saved).toBe(true);
|
|
66
|
+
expect(feedback?.error).toBeNull();
|
|
67
|
+
expect(feedback?.saving).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a refusal keeps the server’s sentence and shows no success', async () => {
|
|
71
|
+
await mount();
|
|
72
|
+
expect(await run(async () => ({ ok: false, error: 'A preset named “cheap” already exists' }))).toBe(false);
|
|
73
|
+
expect(feedback?.saved).toBe(false);
|
|
74
|
+
expect(feedback?.error).toBe('A preset named “cheap” already exists');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('a refusal without a sentence still says something actionable', async () => {
|
|
78
|
+
await mount();
|
|
79
|
+
await run(async () => ({ ok: false }));
|
|
80
|
+
expect(feedback?.error).toBe('The server refused the write.');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('a thrown write is reported rather than escaping to the console', async () => {
|
|
84
|
+
await mount();
|
|
85
|
+
expect(await run(async () => { throw new Error('network down'); })).toBe(false);
|
|
86
|
+
expect(feedback?.error).toBe('network down');
|
|
87
|
+
expect(feedback?.saving).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a later success clears the previous refusal', async () => {
|
|
91
|
+
await mount();
|
|
92
|
+
await run(async () => ({ ok: false, error: 'first refusal' }));
|
|
93
|
+
await run(async () => ({ ok: true }));
|
|
94
|
+
expect(feedback?.error).toBeNull();
|
|
95
|
+
expect(feedback?.saved).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('dismissError clears the sentence without clearing a success', async () => {
|
|
99
|
+
await mount();
|
|
100
|
+
await run(async () => ({ ok: false, error: 'nope' }));
|
|
101
|
+
await act(async () => { feedback?.dismissError(); });
|
|
102
|
+
expect(feedback?.error).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Write feedback for a settings pane: whether the last save/delete is still in
|
|
8
|
+
* flight, whether it landed, and the server's own sentence when it did not.
|
|
9
|
+
*
|
|
10
|
+
* The panes used to show "Saved successfully" the instant the button was
|
|
11
|
+
* pressed, before the request had answered — so a refused write (a duplicate
|
|
12
|
+
* agent name, a read-only native file, a validator rejecting the draft) showed
|
|
13
|
+
* a success badge over a row that had not changed. The outcome of the write is
|
|
14
|
+
* now the only thing that sets the badge.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useRef, useState } from 'preact/hooks';
|
|
18
|
+
import type { WriteOutcome } from '@/shared/types';
|
|
19
|
+
|
|
20
|
+
export interface WriteFeedback {
|
|
21
|
+
saving: boolean;
|
|
22
|
+
saved: boolean;
|
|
23
|
+
/** The last refusal's sentence; stays until the next write or dismissal. */
|
|
24
|
+
error: string | null;
|
|
25
|
+
dismissError: () => void;
|
|
26
|
+
/** Run one write and report its real outcome. Resolves `true` when it landed. */
|
|
27
|
+
run: (action: () => Promise<WriteOutcome>) => Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SAVED_FLASH_MS = 2000;
|
|
31
|
+
|
|
32
|
+
export function useWriteFeedback(): WriteFeedback {
|
|
33
|
+
const [saving, setSaving] = useState(false);
|
|
34
|
+
const [saved, setSaved] = useState(false);
|
|
35
|
+
const [error, setError] = useState<string | null>(null);
|
|
36
|
+
const flash = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
37
|
+
|
|
38
|
+
const dismissError = useCallback(() => setError(null), []);
|
|
39
|
+
|
|
40
|
+
const run = useCallback(async (action: () => Promise<WriteOutcome>): Promise<boolean> => {
|
|
41
|
+
setSaving(true);
|
|
42
|
+
setError(null);
|
|
43
|
+
clearTimeout(flash.current);
|
|
44
|
+
setSaved(false);
|
|
45
|
+
try {
|
|
46
|
+
const outcome = await action();
|
|
47
|
+
if (!outcome.ok) {
|
|
48
|
+
setError(outcome.error ?? 'The server refused the write.');
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
setSaved(true);
|
|
52
|
+
flash.current = setTimeout(() => setSaved(false), SAVED_FLASH_MS);
|
|
53
|
+
return true;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
56
|
+
return false;
|
|
57
|
+
} finally {
|
|
58
|
+
setSaving(false);
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return { saving, saved, error, dismissError, run };
|
|
63
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shell bridge, driven through three different transports.
|
|
8
|
+
*
|
|
9
|
+
* The interesting failures are about what the page can tell apart:
|
|
10
|
+
*
|
|
11
|
+
* 1. a browser has no shell at all, and every command refuses;
|
|
12
|
+
* 2. a desktop shell installs `__kabmoCall` itself, and answers on the first
|
|
13
|
+
* paint (`__kabmoDesktop`);
|
|
14
|
+
* 3. a PHONE exposes only a host object, so the console adapts it — and that
|
|
15
|
+
* adapter must be distinguishable from a desktop, because the titlebar inset
|
|
16
|
+
* treats "a shell with no identity" as a macOS window.
|
|
17
|
+
*
|
|
18
|
+
* None of it is visible in the panel's markup: a control that never works looks
|
|
19
|
+
* exactly like one that does until it is pressed.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { beforeEach, describe, expect, test } from 'bun:test';
|
|
23
|
+
import { desktopInfo } from '@/client/lib/shell/desktop';
|
|
24
|
+
import { addRemoteServer, readServers } from '@/client/lib/shell/servers';
|
|
25
|
+
import {
|
|
26
|
+
bridgeError,
|
|
27
|
+
hasShellBridge,
|
|
28
|
+
installShellTransport,
|
|
29
|
+
isDesktopShell,
|
|
30
|
+
isMobileShell,
|
|
31
|
+
shellHost,
|
|
32
|
+
} from '@/client/lib/shell/transport';
|
|
33
|
+
|
|
34
|
+
type Reply = (id: number, ok: boolean, payload: unknown) => void;
|
|
35
|
+
|
|
36
|
+
interface ShellWindow {
|
|
37
|
+
__kabmoCall?: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
38
|
+
__kabmoDesktop?: unknown;
|
|
39
|
+
__kabmoReply?: Reply;
|
|
40
|
+
__kabmoShellHost?: 'android' | 'ios';
|
|
41
|
+
kabmoHost?: { post: (method: string, id: string, params: string) => void };
|
|
42
|
+
webkit?: { messageHandlers?: { kabmo?: { postMessage: (message: unknown) => void } } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const shell = () => globalThis as unknown as { window?: ShellWindow };
|
|
46
|
+
|
|
47
|
+
describe('shell bridge', () => {
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
delete shell().window;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('a browser has no shell, and every call refuses', async () => {
|
|
53
|
+
shell().window = {};
|
|
54
|
+
expect(shellHost()).toBeNull();
|
|
55
|
+
expect(hasShellBridge()).toBe(false);
|
|
56
|
+
expect(isDesktopShell()).toBe(false);
|
|
57
|
+
expect(isMobileShell()).toBe(false);
|
|
58
|
+
expect(await desktopInfo()).toBeNull();
|
|
59
|
+
await expect(readServers()).rejects.toThrow('Not running inside a Kabmo shell.');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('the injected identity is readable before any command runs', async () => {
|
|
63
|
+
shell().window = {
|
|
64
|
+
__kabmoCall: async () => null,
|
|
65
|
+
__kabmoDesktop: { platform: 'macos', shellVersion: '0.1.0', overlayTitlebar: true, trafficLightInset: '5rem' },
|
|
66
|
+
};
|
|
67
|
+
expect(isDesktopShell()).toBe(true);
|
|
68
|
+
expect(isMobileShell()).toBe(false);
|
|
69
|
+
const info = await desktopInfo();
|
|
70
|
+
expect(info?.overlayTitlebar).toBe(true);
|
|
71
|
+
expect(info?.trafficLightInset).toBe('5rem');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* macOS and Linux post over `window.webkit.messageHandlers.kabmo` — the same
|
|
76
|
+
* handler NAME iOS uses — so "is there a WebKit handler?" cannot decide which
|
|
77
|
+
* shell this is. When it did, `isDesktopShell()` answered false in every macOS
|
|
78
|
+
* window, `titlebarInsetLeft` stopped reserving the 5rem for the traffic
|
|
79
|
+
* lights, and the wordmark was drawn under close / minimise / maximise.
|
|
80
|
+
*/
|
|
81
|
+
test('a macOS shell is not read as an iPhone, though it posts over the same handler', () => {
|
|
82
|
+
shell().window = {
|
|
83
|
+
__kabmoCall: async () => null,
|
|
84
|
+
__kabmoDesktop: { platform: 'macos', shellVersion: '0.1.0', overlayTitlebar: true, trafficLightInset: '5rem' },
|
|
85
|
+
webkit: { messageHandlers: { kabmo: { postMessage: () => {} } } },
|
|
86
|
+
};
|
|
87
|
+
expect(shellHost()).toBe('desktop');
|
|
88
|
+
expect(isDesktopShell()).toBe(true);
|
|
89
|
+
expect(isMobileShell()).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a command answers through __kabmoCall', async () => {
|
|
93
|
+
const seen: string[] = [];
|
|
94
|
+
shell().window = {
|
|
95
|
+
__kabmoCall: async (method) => {
|
|
96
|
+
seen.push(method);
|
|
97
|
+
return { entries: [], detected: [], activeId: 'local:1' };
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const state = await readServers();
|
|
101
|
+
expect(seen).toEqual(['servers_state']);
|
|
102
|
+
expect(state.activeId).toBe('local:1');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The phone's transport is ADAPTED, not replaced: the native side gets
|
|
107
|
+
* `(method, id, params)` and answers by evaluating `__kabmoReply`, exactly as
|
|
108
|
+
* the desktop shells do. Params are form-encoded because Android's `org.json`
|
|
109
|
+
* is a stub in a JVM unit test, and state comes back as JSON text.
|
|
110
|
+
*/
|
|
111
|
+
test('an Android host becomes __kabmoCall, with form-encoded params and JSON text back', async () => {
|
|
112
|
+
const posts: Array<{ method: string; id: string; params: string }> = [];
|
|
113
|
+
shell().window = {
|
|
114
|
+
kabmoHost: {
|
|
115
|
+
post: (method, id, params) => {
|
|
116
|
+
posts.push({ method, id, params });
|
|
117
|
+
// Answer the way the native side does: a JSON TEXT payload, on the
|
|
118
|
+
// next microtask rather than a real timer.
|
|
119
|
+
queueMicrotask(() => {
|
|
120
|
+
shell().window?.__kabmoReply?.(Number(id), true, '{"entries":[],"detected":[],"activeUrl":"http://10.0.0.2:3000"}');
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
installShellTransport();
|
|
126
|
+
expect(isMobileShell()).toBe(true);
|
|
127
|
+
// The distinction that matters: a phone is NOT a desktop, or the header
|
|
128
|
+
// would reserve 5rem for traffic lights it does not have.
|
|
129
|
+
expect(isDesktopShell()).toBe(false);
|
|
130
|
+
expect(hasShellBridge()).toBe(true);
|
|
131
|
+
|
|
132
|
+
const state = await addRemoteServer('NAS', 'http://10.0.0.2:3000');
|
|
133
|
+
expect(state.activeUrl).toBe('http://10.0.0.2:3000');
|
|
134
|
+
expect(posts).toHaveLength(1);
|
|
135
|
+
expect(posts[0].method).toBe('servers_add');
|
|
136
|
+
expect(posts[0].params).toBe('label=NAS&url=http%3A%2F%2F10.0.0.2%3A3000');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('an iOS host posts to the WebKit message handler', async () => {
|
|
140
|
+
const posts: unknown[] = [];
|
|
141
|
+
shell().window = {
|
|
142
|
+
webkit: {
|
|
143
|
+
messageHandlers: {
|
|
144
|
+
kabmo: {
|
|
145
|
+
postMessage: (message) => {
|
|
146
|
+
posts.push(message);
|
|
147
|
+
const { id } = message as { id: number };
|
|
148
|
+
queueMicrotask(() => shell().window?.__kabmoReply?.(id, true, '{"entries":[],"detected":[]}'));
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
installShellTransport();
|
|
155
|
+
expect(isMobileShell()).toBe(true);
|
|
156
|
+
await readServers();
|
|
157
|
+
expect(posts).toEqual([{ id: 1, method: 'servers_state', params: '' }]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('a refusal keeps the shell’s own sentence, unstripped', async () => {
|
|
161
|
+
expect(bridgeError(new Error('Use the server’s root address — a base path is not supported.'))).toBe(
|
|
162
|
+
'Use the server’s root address — a base path is not supported.',
|
|
163
|
+
);
|
|
164
|
+
expect(bridgeError('plain')).toBe('plain');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -4,35 +4,38 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The server list the
|
|
7
|
+
* The server list the SHELL owns, as the console reads it.
|
|
8
8
|
*
|
|
9
|
-
* One store per window, not per component: the navbar
|
|
10
|
-
* anything else that asks "which server am I on" must not
|
|
11
|
-
* two copies is how a start on one side leaves the other
|
|
9
|
+
* One store per window, not per component: the navbar chip, the phone drawer's
|
|
10
|
+
* chip, the popover and anything else that asks "which server am I on" must not
|
|
11
|
+
* each hold a copy — two copies is how a start on one side leaves the other
|
|
12
|
+
* showing `Stopped`.
|
|
12
13
|
*
|
|
13
14
|
* Every mutation answers with the WHOLE state (`ServersState`), and the shell is
|
|
14
15
|
* the source of truth: it re-reads its own list, re-probes every URL and
|
|
15
16
|
* re-discovers local instances before answering. Adopting the response verbatim
|
|
16
17
|
* is what keeps the panel from inventing a running state the shell does not
|
|
17
18
|
* agree with.
|
|
19
|
+
*
|
|
20
|
+
* `available` is `hasShellBridge()` and not `isDesktopShell()`: a phone answers
|
|
21
|
+
* the same four commands the desktop shells do, so it must get the same control.
|
|
18
22
|
*/
|
|
19
23
|
|
|
20
24
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
21
25
|
import {
|
|
22
26
|
activateServer,
|
|
23
27
|
addRemoteServer,
|
|
24
|
-
bridgeError,
|
|
25
|
-
isDesktopShell,
|
|
26
28
|
readServers,
|
|
27
29
|
removeServer,
|
|
28
30
|
startLocalServer,
|
|
29
31
|
stopLocalServer,
|
|
30
|
-
type
|
|
31
|
-
} from '@/client/lib/
|
|
32
|
+
type ShellServersState,
|
|
33
|
+
} from '@/client/lib/shell/servers';
|
|
34
|
+
import { bridgeError, hasShellBridge } from '@/client/lib/shell/transport';
|
|
32
35
|
|
|
33
|
-
export interface
|
|
36
|
+
export interface ShellServersStore {
|
|
34
37
|
available: boolean;
|
|
35
|
-
state:
|
|
38
|
+
state: ShellServersState | null;
|
|
36
39
|
/** A request is in flight; the panel disables its controls rather than queueing. */
|
|
37
40
|
busy: boolean;
|
|
38
41
|
error: string | null;
|
|
@@ -55,9 +58,9 @@ export interface DesktopServersStore {
|
|
|
55
58
|
*/
|
|
56
59
|
const REFRESH_INTERVAL_MS = 4000;
|
|
57
60
|
|
|
58
|
-
export function
|
|
59
|
-
const available =
|
|
60
|
-
const [state, setState] = useState<
|
|
61
|
+
export function useShellServers(open: boolean): ShellServersStore {
|
|
62
|
+
const available = hasShellBridge();
|
|
63
|
+
const [state, setState] = useState<ShellServersState | null>(null);
|
|
61
64
|
const [busy, setBusy] = useState(false);
|
|
62
65
|
const [error, setError] = useState<string | null>(null);
|
|
63
66
|
// A mutation and a poll can overlap; the poll must not overwrite the answer
|
|
@@ -76,7 +79,7 @@ export function useDesktopServers(open: boolean): DesktopServersStore {
|
|
|
76
79
|
}, [available]);
|
|
77
80
|
|
|
78
81
|
const run = useCallback(
|
|
79
|
-
async (action: () => Promise<
|
|
82
|
+
async (action: () => Promise<ShellServersState>) => {
|
|
80
83
|
mutationsRef.current += 1;
|
|
81
84
|
setBusy(true);
|
|
82
85
|
setError(null);
|