@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
|
@@ -26,58 +26,9 @@ import { buildKenariReport } from '@/server/lib/usage/kenari';
|
|
|
26
26
|
import { fetchOmpUsageSnapshot, type OmpUsageSnapshot } from '@/server/lib/usage/omp-usage.server';
|
|
27
27
|
import { fetchVendorBalance, type VendorBalance } from '@/server/lib/usage/vendor-balance.server';
|
|
28
28
|
import { kenariProviderSlugs, listCredentialedProviders, type CredentialedProvider } from '@/server/lib/usage/provider-key';
|
|
29
|
-
import {
|
|
29
|
+
import { canonicalProviderSlug, providerDisplayName } from '@/shared/lib/models/provider/label';
|
|
30
30
|
import type { KenariUsageReport, UsageProviderSummary } from '@/shared/types';
|
|
31
31
|
|
|
32
|
-
/** Slug aliases omp uses interchangeably, folded onto one display entry. */
|
|
33
|
-
const SLUG_ALIASES: Record<string, string> = {
|
|
34
|
-
'command-code': 'commandcode',
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Brand spellings a title-case pass cannot produce. Kept small on purpose: the
|
|
39
|
-
* slug is the identity, this is only how it is printed.
|
|
40
|
-
*/
|
|
41
|
-
const BRAND_NAMES: Record<string, string> = {
|
|
42
|
-
openai: 'OpenAI',
|
|
43
|
-
kenari: 'Kenari.id',
|
|
44
|
-
deepseek: 'DeepSeek',
|
|
45
|
-
'openai-codex': 'OpenAI Codex',
|
|
46
|
-
'google-gemini-cli': 'Google Gemini CLI',
|
|
47
|
-
'google-antigravity': 'Google Antigravity',
|
|
48
|
-
'github-copilot': 'GitHub Copilot',
|
|
49
|
-
zai: 'Z.AI',
|
|
50
|
-
'zai-coding-plan': 'Z.AI Coding Plan',
|
|
51
|
-
xai: 'xAI',
|
|
52
|
-
'xai-oauth': 'xAI (OAuth)',
|
|
53
|
-
'kimi-code': 'Kimi Code',
|
|
54
|
-
'qwen-portal': 'Qwen Portal',
|
|
55
|
-
'minimax-code': 'MiniMax Code',
|
|
56
|
-
'minimax-code-cn': 'MiniMax Code (CN)',
|
|
57
|
-
'alibaba-token-plan': 'Alibaba Token Plan',
|
|
58
|
-
'alibaba-coding-plan': 'Alibaba Coding Plan',
|
|
59
|
-
'zhipu-coding-plan': 'Zhipu Coding Plan',
|
|
60
|
-
'gitlab-duo': 'GitLab Duo',
|
|
61
|
-
'gitlab-duo-agent': 'GitLab Duo Agent',
|
|
62
|
-
'charm-hyper': 'Charm Hyper',
|
|
63
|
-
'cline-pass': 'Cline Pass',
|
|
64
|
-
'opencode-go': 'OpenCode Go',
|
|
65
|
-
'xiaomi-token-plan-sgp': 'Xiaomi Token Plan (SGP)',
|
|
66
|
-
'xiaomi-token-plan-ams': 'Xiaomi Token Plan (AMS)',
|
|
67
|
-
'xiaomi-token-plan-cn': 'Xiaomi Token Plan (CN)',
|
|
68
|
-
'openai-codex-device': 'OpenAI Codex (Device)',
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
function canonicalSlug(slug: string): string {
|
|
72
|
-
const lower = slug.trim().toLowerCase();
|
|
73
|
-
return SLUG_ALIASES[lower] ?? lower;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Human-readable provider name: brand spelling when known, title case otherwise. */
|
|
77
|
-
function displayName(slug: string): string {
|
|
78
|
-
return BRAND_NAMES[slug] ?? titleCaseProviderSlug(slug);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
32
|
/**
|
|
82
33
|
* omp's own display names for the providers it knows (slug → name), e.g.
|
|
83
34
|
* `commandcode` → "Command Code". Best-effort: a cold or busy omp degrades to
|
|
@@ -88,7 +39,7 @@ async function loadProviderNames(): Promise<Record<string, string>> {
|
|
|
88
39
|
const { providers } = await fetchOmpRegistrySnapshot();
|
|
89
40
|
const names: Record<string, string> = {};
|
|
90
41
|
for (const provider of providers) {
|
|
91
|
-
const slug =
|
|
42
|
+
const slug = canonicalProviderSlug(provider.id);
|
|
92
43
|
const name = provider.name.trim();
|
|
93
44
|
if (slug && name) names[slug] = name;
|
|
94
45
|
}
|
|
@@ -118,7 +69,7 @@ async function loadVendorBalances(slugs: string[]): Promise<Map<string, VendorBa
|
|
|
118
69
|
function mergeCredentials(entries: CredentialedProvider[]): Map<string, string[]> {
|
|
119
70
|
const bySlug = new Map<string, string[]>();
|
|
120
71
|
for (const entry of entries) {
|
|
121
|
-
const slug =
|
|
72
|
+
const slug = canonicalProviderSlug(entry.slug);
|
|
122
73
|
if (!slug) continue;
|
|
123
74
|
const sources = bySlug.get(slug) ?? [];
|
|
124
75
|
for (const source of entry.sources) {
|
|
@@ -189,7 +140,7 @@ export async function buildUsageProviders(options: { force?: boolean } = {}): Pr
|
|
|
189
140
|
const { tracked, limitsUnavailable } = resolveUsageTracking(slug, snapshot);
|
|
190
141
|
const summary: UsageProviderSummary = {
|
|
191
142
|
id: slug,
|
|
192
|
-
name: names[slug] ??
|
|
143
|
+
name: names[slug] ?? providerDisplayName(slug),
|
|
193
144
|
...(iconUrls.get(slug) ? { iconUrl: iconUrls.get(slug) } : {}),
|
|
194
145
|
credentialSources: sources,
|
|
195
146
|
// A vendor balance is real quota data even when omp has no adapter for it.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The project default model reaching a new chat.
|
|
8
|
+
*
|
|
9
|
+
* "Defaults for new chats" is only a setting if the spawn reads it: the column
|
|
10
|
+
* rendered in two panes while `POST /api/agent/new` fell back to Kabmo's global
|
|
11
|
+
* pick, so every chat started on the global model regardless. These cases pin
|
|
12
|
+
* the resolution — exact root, a worktree/nested cwd under the root, a folder
|
|
13
|
+
* with no model (inherit), and a legacy display name that cannot name a model.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { mkdtempSync } from 'node:fs';
|
|
18
|
+
import * as os from 'node:os';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
|
|
21
|
+
import { createDb, type DbClient } from '@/server/lib/db/client';
|
|
22
|
+
import { projectModelForCwd } from '@/server/lib/workspace/project-model.server';
|
|
23
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
24
|
+
|
|
25
|
+
const ROOT = `${os.tmpdir()}/kabmo-project-model-${process.pid}`;
|
|
26
|
+
|
|
27
|
+
let workRoot = '';
|
|
28
|
+
let db: DbClient;
|
|
29
|
+
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
workRoot = mkdtempSync(path.join(os.tmpdir(), 'kabmo-project-model-'));
|
|
32
|
+
db = createDb(path.join(workRoot, 'db.sqlite'));
|
|
33
|
+
await db.exec(`
|
|
34
|
+
CREATE TABLE workspace_folders (
|
|
35
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
36
|
+
name TEXT NOT NULL,
|
|
37
|
+
project_path TEXT,
|
|
38
|
+
model TEXT
|
|
39
|
+
);
|
|
40
|
+
`);
|
|
41
|
+
await db.run('INSERT INTO workspace_folders (name, project_path, model) VALUES (?, ?, ?)', [
|
|
42
|
+
'kenari-project',
|
|
43
|
+
ROOT,
|
|
44
|
+
'kenari:deepseek-v4-flash',
|
|
45
|
+
]);
|
|
46
|
+
await db.run('INSERT INTO workspace_folders (name, project_path, model) VALUES (?, ?, ?)', [
|
|
47
|
+
'legacy',
|
|
48
|
+
`${ROOT}-legacy`,
|
|
49
|
+
'GPT-4o',
|
|
50
|
+
]);
|
|
51
|
+
await db.run('INSERT INTO workspace_folders (name, project_path, model) VALUES (?, ?, ?)', [
|
|
52
|
+
'unset',
|
|
53
|
+
`${ROOT}-unset`,
|
|
54
|
+
'Not selected',
|
|
55
|
+
]);
|
|
56
|
+
await db.run('INSERT INTO workspace_folders (name, project_path, model) VALUES (?, ?, ?)', [
|
|
57
|
+
'nested',
|
|
58
|
+
`${ROOT}/nested`,
|
|
59
|
+
'openai:gpt-5',
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterAll(() => {
|
|
64
|
+
db.raw.close();
|
|
65
|
+
removeDir(workRoot);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('projectModelForCwd', () => {
|
|
69
|
+
test('resolves the bound root to the composite model the picker stored', async () => {
|
|
70
|
+
expect(await projectModelForCwd(db, ROOT)).toEqual({
|
|
71
|
+
provider: 'kenari',
|
|
72
|
+
modelId: 'deepseek-v4-flash',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('a cwd nested under the root (a worktree) resolves to the same project', async () => {
|
|
77
|
+
expect(await projectModelForCwd(db, `${ROOT}/.worktrees/feature-x`)).toEqual({
|
|
78
|
+
provider: 'kenari',
|
|
79
|
+
modelId: 'deepseek-v4-flash',
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('the schema default and a legacy display name both yield no override', async () => {
|
|
84
|
+
expect(await projectModelForCwd(db, `${ROOT}-unset`)).toBeNull();
|
|
85
|
+
// A display name cannot name a model: falling back to Kabmo's pick is
|
|
86
|
+
// honest, and inventing a provider would start the chat on the wrong model.
|
|
87
|
+
expect(await projectModelForCwd(db, `${ROOT}-legacy`)).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a nested workspace wins over the root that contains it', async () => {
|
|
91
|
+
expect(await projectModelForCwd(db, `${ROOT}/nested/crate`)).toEqual({
|
|
92
|
+
provider: 'openai',
|
|
93
|
+
modelId: 'gpt-5',
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('an unregistered cwd and an empty one yield no override', async () => {
|
|
98
|
+
expect(await projectModelForCwd(db, '/nowhere/at/all')).toBeNull();
|
|
99
|
+
expect(await projectModelForCwd(db, '')).toBeNull();
|
|
100
|
+
expect(await projectModelForCwd(db, null)).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The default model a NEW chat inherits from the workspace it starts in.
|
|
8
|
+
*
|
|
9
|
+
* "Defaults for new chats" on a project is only a setting if the spawn reads
|
|
10
|
+
* it. The spawn used to fall back to Kabmo's global persisted pick and nothing
|
|
11
|
+
* else, so the project's model column rendered in the settings pane and in the
|
|
12
|
+
* sidebar payload while every chat actually started on the global pick — a
|
|
13
|
+
* control that promised something it never decided.
|
|
14
|
+
*
|
|
15
|
+
* Resolution is by the spawn's cwd, compared the way the sidebar compares
|
|
16
|
+
* folders: the row holds the spelling the user registered, while the composer
|
|
17
|
+
* may hand over a worktree or a symlinked path of the same project.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
21
|
+
import { projectPathKey } from '@/server/lib/omp/core/paths';
|
|
22
|
+
import { parseProjectModel } from '@/shared/lib/workspace/project-model';
|
|
23
|
+
import type { SelectedModel } from '@/shared/types';
|
|
24
|
+
|
|
25
|
+
export async function projectModelForCwd(db: DbClient, cwd: string | null | undefined): Promise<SelectedModel | null> {
|
|
26
|
+
if (!cwd || !cwd.trim()) return null;
|
|
27
|
+
|
|
28
|
+
const rows = await db.all<{ model: string | null; project_path: string | null }>(
|
|
29
|
+
'SELECT model, project_path FROM workspace_folders WHERE project_path IS NOT NULL ORDER BY length(project_path) DESC',
|
|
30
|
+
);
|
|
31
|
+
if (rows.length === 0) return null;
|
|
32
|
+
|
|
33
|
+
const target = projectPathKey(cwd);
|
|
34
|
+
const exact = rows.find((row) => row.project_path && projectPathKey(row.project_path) === target);
|
|
35
|
+
if (exact) return parseProjectModel(exact.model);
|
|
36
|
+
|
|
37
|
+
// A linked checkout runs outside its project root, and its own path is not
|
|
38
|
+
// registered — so the nearest bound root that CONTAINS it is the folder the
|
|
39
|
+
// chat belongs to. Longest first, so a project nested inside another
|
|
40
|
+
// workspace resolves to the more specific one.
|
|
41
|
+
const nested = rows.find((row) => {
|
|
42
|
+
if (!row.project_path) return false;
|
|
43
|
+
const root = projectPathKey(row.project_path);
|
|
44
|
+
return target.startsWith(`${root}/`);
|
|
45
|
+
});
|
|
46
|
+
return nested ? parseProjectModel(nested.model) : null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Turn a settings PATCH body for one workspace into a row patch the store can
|
|
8
|
+
* apply, or a refusal that names what is wrong.
|
|
9
|
+
*
|
|
10
|
+
* The pane edits facts that decide where chats run and which sessions appear in
|
|
11
|
+
* the sidebar, so a value that cannot be honoured must be refused HERE rather
|
|
12
|
+
* than written and quietly ignored:
|
|
13
|
+
*
|
|
14
|
+
* - **A project needs a name.** The store skips an empty name on purpose (so a
|
|
15
|
+
* partial update cannot blank a row), which meant the field could be cleared
|
|
16
|
+
* on screen while the old name stayed on the server — a rename that silently
|
|
17
|
+
* did nothing.
|
|
18
|
+
* - **Names are unique case-insensitively**, the same rule the creation path
|
|
19
|
+
* enforces (`registerWorkspaceFolder`), because the sidebar identifies a
|
|
20
|
+
* workspace by its name.
|
|
21
|
+
* - **A project path must be a real directory**, expanded from `~` exactly like
|
|
22
|
+
* the creation path. Binding a typo produced a folder that listed no sessions
|
|
23
|
+
* forever with nothing on screen saying why.
|
|
24
|
+
* - **An accent must be a hex colour.** The sidebar paints it into a CSS
|
|
25
|
+
* `color`, so a free-form string is a style injection, not a preference.
|
|
26
|
+
* - **One directory, one workspace.** Two rows bound to the same root list the
|
|
27
|
+
* same sessions twice and fight over the discovery tombstones.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { getDb } from '@/server/db.server';
|
|
31
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
32
|
+
import { projectPathKey } from '@/server/lib/omp/core/paths';
|
|
33
|
+
import { expandHome } from '@/server/routes/folders/create';
|
|
34
|
+
import { normalizeHexAccent } from '@/shared/lib/workspace/project-accent';
|
|
35
|
+
import { parseFolderSettingsPatch, type FolderSettingsPatch } from '@/shared/lib/workspace/project-settings';
|
|
36
|
+
|
|
37
|
+
export type PreparedProjectPatch =
|
|
38
|
+
| { ok: true; patch: FolderSettingsPatch }
|
|
39
|
+
| { ok: false; status: number; error: string; code?: string };
|
|
40
|
+
|
|
41
|
+
/** An icon may be an uploaded raster (data URL) or a fetched absolute URL. */
|
|
42
|
+
const MAX_ICON_CHARS = 700_000; // ~512 KiB of bytes, base64-inflated
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* True when the value is something an `<img src>` can render and the store may
|
|
46
|
+
* keep. The field is written from the client, and without this a whole
|
|
47
|
+
* megabyte image, a `javascript:` URI or a relative path could be persisted as
|
|
48
|
+
* a project icon and then rendered in every sidebar row.
|
|
49
|
+
*/
|
|
50
|
+
function isIconUrl(value: string): boolean {
|
|
51
|
+
if (value.length > MAX_ICON_CHARS) return false;
|
|
52
|
+
if (/^data:image\/(png|jpeg|jpg|svg\+xml|webp|gif);base64,[A-Za-z0-9+/=]+$/.test(value)) return true;
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(value);
|
|
55
|
+
return url.protocol === 'https:' || url.protocol === 'http:';
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** True when the path is an existing directory (symlinks followed). */
|
|
62
|
+
async function isDirectory(target: string): Promise<boolean> {
|
|
63
|
+
try {
|
|
64
|
+
return (await Bun.file(target).stat()).isDirectory();
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function prepareProjectPatch(
|
|
71
|
+
db: DbClient,
|
|
72
|
+
folderId: string,
|
|
73
|
+
raw: unknown,
|
|
74
|
+
): Promise<PreparedProjectPatch> {
|
|
75
|
+
const patch = parseFolderSettingsPatch(raw);
|
|
76
|
+
|
|
77
|
+
if (patch.name !== undefined && patch.name === '') {
|
|
78
|
+
return { ok: false, status: 400, error: 'A project needs a name', code: 'name_required' };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (patch.name !== undefined) {
|
|
82
|
+
const clash = await db.get<{ id: number }>(
|
|
83
|
+
'SELECT id FROM workspace_folders WHERE lower(name) = lower(?) AND id != ?',
|
|
84
|
+
[patch.name, folderId],
|
|
85
|
+
);
|
|
86
|
+
if (clash) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
status: 409,
|
|
90
|
+
error: `A workspace named "${patch.name}" already exists`,
|
|
91
|
+
code: 'duplicate_name',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (patch.accentColor !== undefined && patch.accentColor !== '') {
|
|
97
|
+
const normalized = normalizeHexAccent(patch.accentColor);
|
|
98
|
+
if (normalized === null) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
status: 400,
|
|
102
|
+
error: 'An accent must be a hex colour like #7c3aed',
|
|
103
|
+
code: 'invalid_accent',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Stored in ONE form — the sidebar paints this straight into a style, and two
|
|
107
|
+
// spellings of the same colour would defeat the "is this a preset?" check.
|
|
108
|
+
patch.accentColor = normalized;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (patch.customIconUrl !== undefined && patch.customIconUrl !== null && !isIconUrl(patch.customIconUrl)) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
status: 400,
|
|
115
|
+
error: 'An icon must be an uploaded image or an http(s) URL under 512 KiB',
|
|
116
|
+
code: 'invalid_icon',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (patch.projectPath) {
|
|
121
|
+
const resolved = expandHome(patch.projectPath);
|
|
122
|
+
if (!(await isDirectory(resolved))) {
|
|
123
|
+
return {
|
|
124
|
+
ok: false,
|
|
125
|
+
status: 400,
|
|
126
|
+
error: `Directory does not exist: ${patch.projectPath}`,
|
|
127
|
+
code: 'directory_not_found',
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const target = projectPathKey(resolved);
|
|
131
|
+
const bound = await db.all<{ id: number; project_path: string | null }>(
|
|
132
|
+
'SELECT id, project_path FROM workspace_folders WHERE project_path IS NOT NULL AND id != ?',
|
|
133
|
+
[folderId],
|
|
134
|
+
);
|
|
135
|
+
const duplicate = bound.find((row) => row.project_path && projectPathKey(row.project_path) === target);
|
|
136
|
+
if (duplicate) {
|
|
137
|
+
// A worktree of a bound project canonicalizes elsewhere, so this only
|
|
138
|
+
// refuses the same project root twice.
|
|
139
|
+
const other = await db.get<{ name: string }>('SELECT name FROM workspace_folders WHERE id = ?', [duplicate.id]);
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
status: 409,
|
|
143
|
+
error: `${other?.name ?? 'Another workspace'} is already bound to ${resolved}`,
|
|
144
|
+
code: 'duplicate_path',
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
patch.projectPath = resolved;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { ok: true, patch };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Convenience for route handlers: prepare against the process database. */
|
|
154
|
+
export async function prepareProjectPatchForStore(folderId: string, raw: unknown): Promise<PreparedProjectPatch> {
|
|
155
|
+
return prepareProjectPatch(await getDb(), folderId, raw);
|
|
156
|
+
}
|
|
@@ -7,6 +7,7 @@ import { loadPersistedAccessMode } from '@/shared/lib/omp/config/access-mode.ser
|
|
|
7
7
|
import { rpcErrorResponse } from '@/server/lib/omp/rpc/errors';
|
|
8
8
|
import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
|
|
9
9
|
import { parseModeSelection } from '@/server/lib/omp/mode/request';
|
|
10
|
+
import { projectModelForCwd } from '@/server/lib/workspace/project-model.server';
|
|
10
11
|
|
|
11
12
|
/** The model-dropdown persists its selection here (actionType 'selectModel');
|
|
12
13
|
* a spawn that arrives without an explicit provider/modelId falls back to it. */
|
|
@@ -79,7 +80,13 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
79
80
|
thinkingLevel?: string;
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
// The workspace's own default is the FIRST fallback: "Defaults for new
|
|
84
|
+
// chats" exists to decide the model a chat starts on, so a project pick
|
|
85
|
+
// outranks Kabmo's global one for a chat born in that project.
|
|
86
|
+
const projectModel = await projectModelForCwd(await getDb(), cwd);
|
|
87
|
+
const effectiveModel = provider && modelId
|
|
88
|
+
? { provider, modelId }
|
|
89
|
+
: projectModel ?? await loadPersistedModel();
|
|
83
90
|
if (effectiveModel) {
|
|
84
91
|
await session.send({ type: 'set_model', ...effectiveModel }).catch(() => {});
|
|
85
92
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
|
|
2
2
|
import * as browserStream from '@/server/routes/browser/stream';
|
|
3
|
+
import * as browserTabs from '@/server/routes/browser/tabs';
|
|
3
4
|
|
|
4
5
|
export const browserBindings: HandlerBinding[] = [
|
|
5
6
|
...bindingsFor(browserStream, '/api/browser/:sessionId/stream'),
|
|
7
|
+
// Mutating route: `bindingsFor` adds the 405 GET fallback on its own.
|
|
8
|
+
...bindingsFor(browserTabs, '/api/browser/:sessionId/tabs/close'),
|
|
6
9
|
];
|
|
@@ -37,6 +37,9 @@ import { BROWSER_POLL_MS, STREAM_HEARTBEAT_MS } from '@/shared/lib/workspace/ref
|
|
|
37
37
|
|
|
38
38
|
const BROWSER_OFFLINE: BrowserViewState = { status: 'browser-offline', tabs: [] };
|
|
39
39
|
|
|
40
|
+
/** How soon a frame held under backpressure is offered to the stream again. */
|
|
41
|
+
const FRAME_FLUSH_RETRY_MS = 120;
|
|
42
|
+
|
|
40
43
|
export async function loader({ params, request }: LoaderFunctionArgs) {
|
|
41
44
|
const sessionId = params.sessionId ?? '';
|
|
42
45
|
const preferTargetId = new URL(request.url).searchParams.get('target') ?? undefined;
|
|
@@ -81,6 +84,11 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
|
|
|
81
84
|
const cleanup = (): void => {
|
|
82
85
|
if (closed) return;
|
|
83
86
|
closed = true;
|
|
87
|
+
pendingFrame = null;
|
|
88
|
+
if (frameTimer !== null) {
|
|
89
|
+
clearTimeout(frameTimer);
|
|
90
|
+
frameTimer = null;
|
|
91
|
+
}
|
|
84
92
|
detachViewer();
|
|
85
93
|
dropWatcher();
|
|
86
94
|
unsubscribeAgent?.();
|
|
@@ -104,12 +112,33 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
|
|
|
104
112
|
handlers.send('action', payload);
|
|
105
113
|
};
|
|
106
114
|
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
let pendingFrame: BrowserViewFrame | null = null;
|
|
116
|
+
let frameTimer: ReturnType<typeof setTimeout> | null = null;
|
|
117
|
+
|
|
118
|
+
const flushFrame = (): void => {
|
|
119
|
+
if (closed || !pendingFrame) return;
|
|
109
120
|
if (handlers.isBackpressured()) return;
|
|
121
|
+
const frame = pendingFrame;
|
|
122
|
+
pendingFrame = null;
|
|
110
123
|
handlers.send('frame', frame);
|
|
111
124
|
};
|
|
112
125
|
|
|
126
|
+
const emitFrame = (frame: BrowserViewFrame): void => {
|
|
127
|
+
// Backpressure: hold the NEWEST frame instead of dropping it. A drop is
|
|
128
|
+
// only harmless while the page keeps painting; an idle tab (the normal
|
|
129
|
+
// state of a tab the agent finished with) produces exactly one frame —
|
|
130
|
+
// the seeding snapshot — so dropping it is what put the panel back on
|
|
131
|
+
// "waiting for the first frame".
|
|
132
|
+
pendingFrame = frame;
|
|
133
|
+
flushFrame();
|
|
134
|
+
if (!pendingFrame || frameTimer !== null) return;
|
|
135
|
+
frameTimer = setTimeout(() => {
|
|
136
|
+
frameTimer = null;
|
|
137
|
+
flushFrame();
|
|
138
|
+
if (pendingFrame) emitFrame(pendingFrame);
|
|
139
|
+
}, FRAME_FLUSH_RETRY_MS);
|
|
140
|
+
};
|
|
141
|
+
|
|
113
142
|
const tick = async (): Promise<void> => {
|
|
114
143
|
if (closed || tickInFlight) return;
|
|
115
144
|
tickInFlight = true;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `POST /api/browser/:sessionId/tabs/close` — the refusals, which are the whole
|
|
8
|
+
* contract reachable without a real Chromium.
|
|
9
|
+
*
|
|
10
|
+
* A close request is an ACT of the user on someone else's browser, so every
|
|
11
|
+
* path that does not close must say why: no session, no shared browser, a tab
|
|
12
|
+
* that belongs to another session, a malformed id. The happy path itself is a
|
|
13
|
+
* single CDP call whose behaviour is measured in `shared/lib/browser/tab-close.ts`
|
|
14
|
+
* (Chromium 1248: `{"success":true}`, the socket survives, the attached session
|
|
15
|
+
* dies on its own), and its policy — which ids may be closed at all — is pinned
|
|
16
|
+
* in `tab-close.test.ts`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
|
|
22
|
+
import { action } from '@/server/routes/browser/tabs';
|
|
23
|
+
|
|
24
|
+
const originalMock = Bun.env.MOCK;
|
|
25
|
+
const globals = globalThis as unknown as { __ompSessions?: Map<string, unknown> };
|
|
26
|
+
const SESSION = 'tabs-close-test-session';
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
delete Bun.env.MOCK;
|
|
30
|
+
if (!globals.__ompSessions) globals.__ompSessions = new Map();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
globals.__ompSessions?.delete(SESSION);
|
|
35
|
+
if (originalMock === undefined) delete Bun.env.MOCK;
|
|
36
|
+
else Bun.env.MOCK = originalMock;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function post(body: unknown, sessionId = SESSION): Promise<Response> {
|
|
40
|
+
return action({
|
|
41
|
+
params: { sessionId },
|
|
42
|
+
request: new Request(`http://localhost/api/browser/${sessionId}/tabs/close`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: { 'content-type': 'application/json' },
|
|
45
|
+
body: typeof body === 'string' ? body : JSON.stringify(body),
|
|
46
|
+
}),
|
|
47
|
+
} as never) as Promise<Response>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('browser tab close route', () => {
|
|
51
|
+
test('a session this process does not run owns no tabs to close', async () => {
|
|
52
|
+
const res = await post({ targetId: 'abc' });
|
|
53
|
+
expect(res.status).toBe(404);
|
|
54
|
+
expect(((await res.json()) as { error: string }).error).toContain('not running');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('a malformed target id is refused before any browser is touched', async () => {
|
|
58
|
+
globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
|
|
59
|
+
for (const targetId of [undefined, '', 'a b', '../x', 7]) {
|
|
60
|
+
const res = await post({ targetId });
|
|
61
|
+
expect(res.status).toBe(400);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a body that is not JSON is refused with 400, not a crash', async () => {
|
|
66
|
+
globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
|
|
67
|
+
const res = await post('{not json');
|
|
68
|
+
expect(res.status).toBe(400);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('a project with no running shared browser reports 503', async () => {
|
|
72
|
+
globals.__ompSessions?.set(SESSION, {
|
|
73
|
+
pid: process.pid,
|
|
74
|
+
// A directory with no scope.json: discovery finds no runtime for it.
|
|
75
|
+
cwd: path.join(process.cwd(), 'tmp-no-browser-here'),
|
|
76
|
+
isAlive: () => true,
|
|
77
|
+
});
|
|
78
|
+
const res = await post({ targetId: 'abc' });
|
|
79
|
+
expect(res.status).toBe(503);
|
|
80
|
+
expect(((await res.json()) as { error: string }).error).toContain('No shared browser');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('MOCK mode never reaches a daemon', async () => {
|
|
84
|
+
Bun.env.MOCK = '1';
|
|
85
|
+
globals.__ompSessions?.set(SESSION, { pid: process.pid, cwd: process.cwd(), isAlive: () => true });
|
|
86
|
+
const res = await post({ targetId: 'abc' });
|
|
87
|
+
expect(res.status).toBe(503);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a missing sessionId is a client error, not a silent no-op', async () => {
|
|
91
|
+
const res = await post({ targetId: 'abc' }, '');
|
|
92
|
+
expect(res.status).toBe(400);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* POST /api/browser/:sessionId/tabs/close — close one page this session's omp
|
|
8
|
+
* agent opened in the project-shared Chromium.
|
|
9
|
+
*
|
|
10
|
+
* Why the panel needs it: an agent that visits several pages leaves them all
|
|
11
|
+
* open in the shared daemon. The panel attaches to the newest owned target, so
|
|
12
|
+
* a pile of stale tabs is one more reason it shows the wrong page, and each one
|
|
13
|
+
* keeps a renderer alive.
|
|
14
|
+
*
|
|
15
|
+
* The ownership rule and the CDP behaviour are `shared/lib/browser/tab-close.ts`
|
|
16
|
+
* (one copy, so the panel and this route cannot disagree). This module only
|
|
17
|
+
* turns them into status codes:
|
|
18
|
+
*
|
|
19
|
+
* - 404 the session is not running here — there is no agent whose tab to close
|
|
20
|
+
* - 503 no shared browser for the session's project (nothing to connect to)
|
|
21
|
+
* - 403 the target is not one of THIS session's tabs
|
|
22
|
+
* - 200 closed, with the surviving tabs and the neighbour to select next
|
|
23
|
+
*
|
|
24
|
+
* A target the browser no longer knows is reported as `alreadyClosed: true`
|
|
25
|
+
* rather than an error: the caller asked for a tab to be gone, and it is.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { json, type ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
29
|
+
import { parseJsonBody, requireParam } from '@/server/lib/route-adapter';
|
|
30
|
+
import { isMockMode } from '@/server/mock.server';
|
|
31
|
+
import { getRpcSession } from '@/server/lib/omp/rpc/session-registry';
|
|
32
|
+
import { findProjectRuntimeDir, readOwnedTargetIds } from '@/server/lib/browser/runtime';
|
|
33
|
+
import { acquireConnection, releaseConnection } from '@/shared/lib/browser/connection';
|
|
34
|
+
import { closeVerdict, neighbourTargetId, readCloseTarget } from '@/shared/lib/browser/tab-close';
|
|
35
|
+
|
|
36
|
+
interface CloseBody {
|
|
37
|
+
targetId?: unknown;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function action({ request, params }: ActionFunctionArgs) {
|
|
41
|
+
const sessionId = requireParam(params, 'sessionId');
|
|
42
|
+
if (!sessionId) return json({ error: 'Missing session id' }, { status: 400 });
|
|
43
|
+
if (isMockMode()) {
|
|
44
|
+
return json({ error: 'The shared browser is not available in MOCK mode' }, { status: 503 });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const parsed = await parseJsonBody<CloseBody>(request);
|
|
48
|
+
if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
49
|
+
const targetId = readCloseTarget(parsed.body.targetId);
|
|
50
|
+
if (!targetId) return json({ error: 'Missing or malformed targetId' }, { status: 400 });
|
|
51
|
+
|
|
52
|
+
const session = getRpcSession(sessionId);
|
|
53
|
+
if (!session || !session.isAlive() || session.pid === undefined) {
|
|
54
|
+
return json({ error: 'This session is not running, so it owns no browser tabs' }, { status: 404 });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const runtime = await findProjectRuntimeDir(session.cwd);
|
|
58
|
+
if (!runtime) return json({ error: 'No shared browser is running for this project' }, { status: 503 });
|
|
59
|
+
|
|
60
|
+
// Ownership is decided against the on-disk registry, the same source the
|
|
61
|
+
// viewer scopes its tab list to: the daemon hosts every session's pages, so
|
|
62
|
+
// a target id from another one must be refused rather than attempted.
|
|
63
|
+
const owned = await readOwnedTargetIds(runtime.runtimeDir, runtime.daemonName, session.pid);
|
|
64
|
+
const verdict = closeVerdict(targetId, owned);
|
|
65
|
+
if (!verdict.ok) {
|
|
66
|
+
return json({ error: verdict.reason, remaining: verdict.remaining }, { status: 403 });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const conn = await acquireConnection(runtime.wsUrl).catch(() => null);
|
|
70
|
+
if (!conn) return json({ error: 'Could not reach the shared browser' }, { status: 503 });
|
|
71
|
+
try {
|
|
72
|
+
const reply = await conn.send('Target.closeTarget', { targetId }).catch((error: unknown) => error);
|
|
73
|
+
if (reply instanceof Error) {
|
|
74
|
+
// "No target found for targetId" is the page having gone away already:
|
|
75
|
+
// the outcome the caller asked for, not a failure of this request.
|
|
76
|
+
if (reply.message.includes('No target found')) {
|
|
77
|
+
return json({ ok: true, alreadyClosed: true, remaining: verdict.remaining, next: neighbourTargetId(owned, targetId) });
|
|
78
|
+
}
|
|
79
|
+
return json({ error: reply.message }, { status: 502 });
|
|
80
|
+
}
|
|
81
|
+
return json({ ok: true, alreadyClosed: false, remaining: verdict.remaining, next: neighbourTargetId(owned, targetId) });
|
|
82
|
+
} finally {
|
|
83
|
+
releaseConnection(runtime.wsUrl, conn);
|
|
84
|
+
}
|
|
85
|
+
}
|