@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,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WRITE half of skill import: copying the skills a user picked out of a
|
|
8
|
+
* cloned repository into a root Kabmo owns.
|
|
9
|
+
*
|
|
10
|
+
* The clone and the SKILL.md scan live in `skills-git-repo.ts`, because the
|
|
11
|
+
* inspector and the installer must agree on what a repository contains — a
|
|
12
|
+
* second scan here is how an installer copies a skill the list never showed.
|
|
13
|
+
*
|
|
14
|
+
* Every refusal is per skill, never per batch: one name that collides with an
|
|
15
|
+
* installed skill (or one directory past the size cap) is reported in `skipped`
|
|
16
|
+
* while the rest install, because a repository of twenty skills must not fail as
|
|
17
|
+
* a whole over one collision.
|
|
18
|
+
*
|
|
19
|
+
* Two properties are load-bearing:
|
|
20
|
+
*
|
|
21
|
+
* - **The destination is always `<managed root>/<validated name>`.** Nothing is
|
|
22
|
+
* copied to a path the repository supplied: `safeSkillDirName` refuses a
|
|
23
|
+
* separator, and the source directory itself is re-derived from the scan and
|
|
24
|
+
* checked with `withinRoot` before it is read.
|
|
25
|
+
* - **The source directory is copied WHOLE** (scripts, references, assets), not
|
|
26
|
+
* just its SKILL.md — a skill whose instructions point at `scripts/build.sh`
|
|
27
|
+
* is broken the moment only the markdown survives.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import fs from 'fs';
|
|
31
|
+
import { tmpdir } from 'os';
|
|
32
|
+
import { join } from 'path';
|
|
33
|
+
import { invalidateSkillCache, managedSkillRoots } from '@/server/lib/omp/config/skills';
|
|
34
|
+
import { MAX_SKILL_DIR_BYTES } from '@/server/lib/omp/config/skills-git-repo';
|
|
35
|
+
import {
|
|
36
|
+
scanSkillRepository,
|
|
37
|
+
stageClone,
|
|
38
|
+
toSkillRepoRef,
|
|
39
|
+
withinRoot,
|
|
40
|
+
} from '@/server/lib/omp/config/skills-git-repo';
|
|
41
|
+
|
|
42
|
+
/** The directory a skill's name sanitises to, or a refusal. */
|
|
43
|
+
function safeSkillDirName(name: string): string {
|
|
44
|
+
const trimmed = name.trim();
|
|
45
|
+
if (!trimmed) throw new Error('A skill has no name');
|
|
46
|
+
if (/[\\/]/.test(trimmed) || trimmed === '.' || trimmed === '..') {
|
|
47
|
+
throw new Error(`Skill name refuses a path separator: ${trimmed}`);
|
|
48
|
+
}
|
|
49
|
+
return trimmed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function dirSize(dir: string): Promise<number> {
|
|
53
|
+
let total = 0;
|
|
54
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const full = join(dir, entry.name);
|
|
57
|
+
if (entry.isDirectory()) total += await dirSize(full);
|
|
58
|
+
else if (entry.isFile()) total += await fs.promises.stat(full).then((s) => s.size).catch(() => 0);
|
|
59
|
+
if (total > MAX_SKILL_DIR_BYTES) return total;
|
|
60
|
+
}
|
|
61
|
+
return total;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface InstallFromRepoOptions {
|
|
65
|
+
scope: 'user' | 'project';
|
|
66
|
+
projectDir?: string | null;
|
|
67
|
+
/** A skill whose directory already exists is replaced, not skipped. */
|
|
68
|
+
overwrite?: boolean;
|
|
69
|
+
stagingParent?: string;
|
|
70
|
+
/** Test seam: read from an existing directory instead of cloning. */
|
|
71
|
+
sourceDir?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface InstallFromRepoOutcome {
|
|
75
|
+
installed: string[];
|
|
76
|
+
skipped: Array<{ name: string; reason: string }>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Copy the picked skills out of `rawUrl` into a managed root. `wantedPaths` are
|
|
81
|
+
* repo-relative paths exactly as the inspector reported them.
|
|
82
|
+
*/
|
|
83
|
+
export async function installSkillCopies(
|
|
84
|
+
rawUrl: string,
|
|
85
|
+
wantedPaths: string[],
|
|
86
|
+
options: InstallFromRepoOptions,
|
|
87
|
+
): Promise<InstallFromRepoOutcome> {
|
|
88
|
+
const ref = toSkillRepoRef(rawUrl);
|
|
89
|
+
if (!ref) throw new Error('Expected a git URL or an owner/repo pair');
|
|
90
|
+
if (options.scope === 'project' && !options.projectDir) {
|
|
91
|
+
throw new Error('A workspace root is required to install a project skill');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const stagingParent = options.stagingParent ?? tmpdir();
|
|
95
|
+
const staged = options.sourceDir
|
|
96
|
+
? { dir: options.sourceDir, cleanup: async () => {} }
|
|
97
|
+
: await stageClone(ref.url, stagingParent);
|
|
98
|
+
|
|
99
|
+
const installed: string[] = [];
|
|
100
|
+
const skipped: Array<{ name: string; reason: string }> = [];
|
|
101
|
+
const wanted = new Set(wantedPaths);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const entries = (await scanSkillRepository(staged.dir)).filter((entry) => wanted.has(entry.path));
|
|
105
|
+
if (entries.length === 0) throw new Error('None of the selected skills are in that repository');
|
|
106
|
+
|
|
107
|
+
const roots = managedSkillRoots(options.projectDir ?? null);
|
|
108
|
+
const root = options.scope === 'project' ? roots[1] : roots[0];
|
|
109
|
+
if (!root) throw new Error('A workspace root is required to install a project skill');
|
|
110
|
+
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
const sourceDir = join(staged.dir, ...entry.path.split('/'));
|
|
113
|
+
if (!withinRoot(staged.dir, sourceDir)) {
|
|
114
|
+
skipped.push({ name: entry.name, reason: 'path is outside the repository' });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let dirName: string;
|
|
118
|
+
try {
|
|
119
|
+
dirName = safeSkillDirName(entry.name);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
skipped.push({ name: entry.name, reason: error instanceof Error ? error.message : String(error) });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!entry.loadable) {
|
|
125
|
+
skipped.push({ name: entry.name, reason: 'SKILL.md has no description, so omp will not load it' });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const target = join(root, dirName);
|
|
130
|
+
const exists = await fs.promises.stat(target).then((s) => s.isDirectory()).catch(() => false);
|
|
131
|
+
if (exists && !options.overwrite) {
|
|
132
|
+
skipped.push({ name: entry.name, reason: 'already installed — enable overwrite to replace it' });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const size = await dirSize(sourceDir);
|
|
136
|
+
if (size > MAX_SKILL_DIR_BYTES) {
|
|
137
|
+
skipped.push({
|
|
138
|
+
name: entry.name,
|
|
139
|
+
reason: `skill directory is ${Math.round(size / 1024)} KB (limit ${MAX_SKILL_DIR_BYTES / 1024} KB)`,
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (exists) await fs.promises.rm(target, { recursive: true, force: true });
|
|
145
|
+
await fs.promises.mkdir(root, { recursive: true });
|
|
146
|
+
await fs.promises.cp(sourceDir, target, { recursive: true, force: true });
|
|
147
|
+
installed.push(entry.name);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (installed.length > 0) invalidateSkillCache();
|
|
151
|
+
return { installed, skipped };
|
|
152
|
+
} finally {
|
|
153
|
+
await staged.cleanup();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Skill import from an arbitrary git repository.
|
|
8
|
+
*
|
|
9
|
+
* The catalog's other install path is `bunx skills add <package>`, which works
|
|
10
|
+
* for a repository the skills.sh registry knows and tells the user nothing about
|
|
11
|
+
* what is inside. A URL a user pastes is neither: it may hold one SKILL.md at the
|
|
12
|
+
* root, twenty under `skills/`, or a plugin layout, and the user has to see the
|
|
13
|
+
* list before anything lands on disk. So this module clones the repository into
|
|
14
|
+
* a staging directory, reads the SKILL.md frontmatter itself, and installs the
|
|
15
|
+
* entries the user picked.
|
|
16
|
+
*
|
|
17
|
+
* Three properties are load-bearing:
|
|
18
|
+
*
|
|
19
|
+
* - **`bunx skills add <repo> --list` is NOT the inspector.** It prints a
|
|
20
|
+
* human-oriented tree (measured: 60+ wrapped lines for one repository), has no
|
|
21
|
+
* `--json` form (`--json` is refused together with `--list`), and no exit code
|
|
22
|
+
* or machine shape to parse. Reading SKILL.md from a clone is the only shape
|
|
23
|
+
* that survives a CLI rewrite.
|
|
24
|
+
* - **Everything is quoted as argv and path-joined through `join()`.** A skill
|
|
25
|
+
* name is author-chosen, so nothing here builds a shell string, and nothing
|
|
26
|
+
* copies a path the frontmatter supplied: a copy target is always
|
|
27
|
+
* `<root>/<validated name>`.
|
|
28
|
+
* - **The clone is always removed.** A failed clone, a repository with no
|
|
29
|
+
* SKILL.md and a successful install all `rm -rf` the staging directory in a
|
|
30
|
+
* `finally`, because a leftover clone is a directory the next scan would have
|
|
31
|
+
* to reason about.
|
|
32
|
+
*
|
|
33
|
+
* This half CLONES and SCANS; `skills-git-install.ts` is the half that writes
|
|
34
|
+
* into a managed root, and it imports the scanner rather than repeating it.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import fs from 'fs';
|
|
38
|
+
import { tmpdir } from 'os';
|
|
39
|
+
import { dirname, join, relative, resolve, sep } from 'path';
|
|
40
|
+
import { gitRun, firstLine } from '@/server/lib/wiki/git';
|
|
41
|
+
import { parseFrontmatter } from '@/server/lib/omp/config/yaml';
|
|
42
|
+
import { repoSlug } from '@/shared/lib/git/url';
|
|
43
|
+
import type { GitSkillEntry } from '@/shared/types';
|
|
44
|
+
|
|
45
|
+
export const CLONE_TIMEOUT_MS = 120_000;
|
|
46
|
+
export const MAX_SKILL_ENTRIES = 60;
|
|
47
|
+
/** A skill directory is instructions plus optional scripts/assets. Past this it
|
|
48
|
+
* is not a skill Kabmo should silently copy. */
|
|
49
|
+
export const MAX_SKILL_DIR_BYTES = 5 * 1024 * 1024;
|
|
50
|
+
const MAX_SCAN_DEPTH = 4;
|
|
51
|
+
const MAX_SKILL_MD_BYTES = 512 * 1024;
|
|
52
|
+
|
|
53
|
+
/** A repo reference Kabmo is willing to hand to `git clone`. */
|
|
54
|
+
export interface SkillRepoRef {
|
|
55
|
+
/** The URL exactly as git should receive it. */
|
|
56
|
+
url: string;
|
|
57
|
+
/** `owner/repo` for a GitHub URL, else the repo slug. Display and dedupe. */
|
|
58
|
+
slug: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalise what a user pasted into a clone URL.
|
|
63
|
+
*
|
|
64
|
+
* Accepts an https/ssh URL, the `git@host:owner/repo` form, a `github.com/owner/repo`
|
|
65
|
+
* shorthand with no scheme, and a bare `owner/repo` pair — the last two are what
|
|
66
|
+
* a catalog source card holds, and refusing them would mean the same repository
|
|
67
|
+
* had to be written two different ways in two panes.
|
|
68
|
+
*/
|
|
69
|
+
export function toSkillRepoRef(raw: string): SkillRepoRef | null {
|
|
70
|
+
const value = raw.trim().replace(/\/+$/, '');
|
|
71
|
+
if (!value || /\s/.test(value)) return null;
|
|
72
|
+
|
|
73
|
+
if (/^(https?|ssh|file):\/\/\S+$/i.test(value) || /^git@[^:/\s]+:\S+$/.test(value)) {
|
|
74
|
+
return { url: value, slug: displaySlug(value) };
|
|
75
|
+
}
|
|
76
|
+
if (value.startsWith('/') || value.startsWith('~') || /^[a-z]:[\\/]/i.test(value)) {
|
|
77
|
+
// A local path: git clones it, and a test fixtures directory is a real use
|
|
78
|
+
// (an offline clone is the only way to exercise this offline). The key IS the
|
|
79
|
+
// path — its last segment would make two different checkouts both named
|
|
80
|
+
// "repo" one source, and the stored value is fed back to `git clone`, which
|
|
81
|
+
// cannot resolve a bare directory name.
|
|
82
|
+
return { url: value, slug: value };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const shorthand = value.replace(/^github\.com\//i, '');
|
|
86
|
+
if (/^[\w.-]+\/[\w.-]+$/.test(shorthand)) {
|
|
87
|
+
return { url: `https://github.com/${shorthand}.git`, slug: shorthand.replace(/\.git$/i, '') };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* `owner/repo` for a URL that has an owner, the last path segment otherwise.
|
|
94
|
+
*
|
|
95
|
+
* `repoSlug` answers the DIRECTORY name a clone takes, which is the repository
|
|
96
|
+
* only — a catalog card that showed `skills` for `anthropics/skills` would name
|
|
97
|
+
* a repository that does not exist.
|
|
98
|
+
*/
|
|
99
|
+
function displaySlug(url: string): string {
|
|
100
|
+
const withoutScheme = url.replace(/^[a-z]+:\/\//i, '').replace(/^git@[^:]+:/i, '');
|
|
101
|
+
const segments = withoutScheme.split('/').filter(Boolean);
|
|
102
|
+
const tail = segments.slice(-2).map((part) => part.replace(/\.git$/i, ''));
|
|
103
|
+
if (tail.length === 2 && !tail[0].includes(':')) return `${tail[0]}/${tail[1]}`;
|
|
104
|
+
return repoSlug(url) || url;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function withinRoot(root: string, candidate: string): boolean {
|
|
108
|
+
const rel = relative(resolve(root), resolve(candidate));
|
|
109
|
+
return rel !== '' && !rel.startsWith('..') && !rel.startsWith(sep) && !rel.startsWith('/');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Directories a scan never descends into. A clone of a real repository is
|
|
113
|
+
* mostly these, and walking them costs seconds per inspection. */
|
|
114
|
+
const SKIP_DIRS: Record<string, true> = {
|
|
115
|
+
node_modules: true,
|
|
116
|
+
'.git': true,
|
|
117
|
+
dist: true,
|
|
118
|
+
build: true,
|
|
119
|
+
out: true,
|
|
120
|
+
coverage: true,
|
|
121
|
+
vendor: true,
|
|
122
|
+
'.next': true,
|
|
123
|
+
target: true,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
async function readSkillEntry(stagingDir: string, skillMdPath: string): Promise<GitSkillEntry | null> {
|
|
127
|
+
const dir = dirname(skillMdPath);
|
|
128
|
+
if (!withinRoot(stagingDir, dir)) return null;
|
|
129
|
+
let stat: fs.Stats;
|
|
130
|
+
try {
|
|
131
|
+
stat = await fs.promises.stat(skillMdPath);
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (!stat.isFile() || stat.size > MAX_SKILL_MD_BYTES) return null;
|
|
136
|
+
|
|
137
|
+
let text: string;
|
|
138
|
+
try {
|
|
139
|
+
text = await fs.promises.readFile(skillMdPath, 'utf8');
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const { data } = parseFrontmatter(text);
|
|
144
|
+
const name = (data.name || dir.split(sep).pop() || '').trim();
|
|
145
|
+
if (!name) return null;
|
|
146
|
+
const description = (data.description || '').replace(/\s+/g, ' ').trim();
|
|
147
|
+
return {
|
|
148
|
+
path: relative(stagingDir, dir).split(sep).join('/'),
|
|
149
|
+
name,
|
|
150
|
+
description,
|
|
151
|
+
// omp skips a SKILL.md with no description outright. Reporting such an entry
|
|
152
|
+
// as installable would promise a skill that cannot run.
|
|
153
|
+
loadable: description.length > 0,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Collect `SKILL.md` files, `skills/*` first. A repository that keeps its
|
|
158
|
+
* skills at the top level (one SKILL.md at the root) and one that keeps them
|
|
159
|
+
* under `skills/` both resolve, and a nested plugin layout is reached by the
|
|
160
|
+
* bounded walk. */
|
|
161
|
+
async function scanSkillDirs(stagingDir: string): Promise<string[]> {
|
|
162
|
+
const found: string[] = [];
|
|
163
|
+
const seen = new Set<string>();
|
|
164
|
+
const push = (file: string) => {
|
|
165
|
+
const dir = dirname(file);
|
|
166
|
+
if (seen.has(dir) || found.length >= MAX_SKILL_ENTRIES * 3) return;
|
|
167
|
+
seen.add(dir);
|
|
168
|
+
found.push(file);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const readdir = async (dir: string): Promise<fs.Dirent[]> => {
|
|
172
|
+
try {
|
|
173
|
+
return await fs.promises.readdir(dir, { withFileTypes: true });
|
|
174
|
+
} catch {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const rootEntries = await readdir(stagingDir);
|
|
180
|
+
for (const entry of rootEntries) {
|
|
181
|
+
if (entry.isFile() && entry.name === 'SKILL.md') push(join(stagingDir, entry.name));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
for (const preferred of ['skills', 'plugins', 'agents']) {
|
|
185
|
+
const dir = join(stagingDir, preferred);
|
|
186
|
+
if (!(await fs.promises.stat(dir).then((s) => s.isDirectory()).catch(() => false))) continue;
|
|
187
|
+
for (const child of await readdir(dir)) {
|
|
188
|
+
if (!child.isDirectory()) continue;
|
|
189
|
+
const candidate = join(dir, child.name, 'SKILL.md');
|
|
190
|
+
if (await fs.promises.stat(candidate).then((s) => s.isFile()).catch(() => false)) push(candidate);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Bounded walk for anything the conventional layouts did not cover.
|
|
195
|
+
const walk = async (dir: string, depth: number): Promise<void> => {
|
|
196
|
+
if (depth > MAX_SCAN_DEPTH || found.length >= MAX_SKILL_ENTRIES * 3) return;
|
|
197
|
+
for (const child of await readdir(dir)) {
|
|
198
|
+
if (found.length >= MAX_SKILL_ENTRIES * 3) return;
|
|
199
|
+
if (!child.isDirectory() || child.name.startsWith('.') || Object.hasOwn(SKIP_DIRS, child.name)) continue;
|
|
200
|
+
const next = join(dir, child.name);
|
|
201
|
+
const candidate = join(next, 'SKILL.md');
|
|
202
|
+
if (await fs.promises.stat(candidate).then((s) => s.isFile()).catch(() => false)) push(candidate);
|
|
203
|
+
await walk(next, depth + 1);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
await walk(stagingDir, 1);
|
|
207
|
+
return found;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Every skill a repository holds, in listing order. */
|
|
211
|
+
export async function scanSkillRepository(stagingDir: string): Promise<GitSkillEntry[]> {
|
|
212
|
+
const files = await scanSkillDirs(stagingDir);
|
|
213
|
+
const entries: GitSkillEntry[] = [];
|
|
214
|
+
const names = new Set<string>();
|
|
215
|
+
for (const file of files) {
|
|
216
|
+
const entry = await readSkillEntry(stagingDir, file);
|
|
217
|
+
if (!entry) continue;
|
|
218
|
+
const key = `${entry.path}::${entry.name}`;
|
|
219
|
+
if (names.has(key)) continue;
|
|
220
|
+
names.add(key);
|
|
221
|
+
entries.push(entry);
|
|
222
|
+
if (entries.length >= MAX_SKILL_ENTRIES) break;
|
|
223
|
+
}
|
|
224
|
+
// Loadable entries first: a repository with three broken SKILL.md files and
|
|
225
|
+
// one real skill should not lead with the broken ones.
|
|
226
|
+
return entries.sort((a, b) => Number(b.loadable) - Number(a.loadable));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface InspectOptions {
|
|
230
|
+
/** Where the repository is cloned. Defaults to the OS temp dir. */
|
|
231
|
+
stagingParent?: string;
|
|
232
|
+
/** Test seam: clone a directory that already exists instead of running git. */
|
|
233
|
+
sourceDir?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function stageClone(url: string, stagingParent: string): Promise<{ dir: string; cleanup: () => Promise<void> }> {
|
|
237
|
+
const slug = repoSlug(url) || 'repo';
|
|
238
|
+
const dir = join(stagingParent, `kabmo-skill-stage-${slug}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
|
|
239
|
+
await fs.promises.rm(dir, { recursive: true, force: true });
|
|
240
|
+
await fs.promises.mkdir(dirname(dir), { recursive: true });
|
|
241
|
+
const clone = await gitRun(['clone', '--depth', '1', '--quiet', url, dir], { timeoutMs: CLONE_TIMEOUT_MS });
|
|
242
|
+
const cleanup = async () => {
|
|
243
|
+
await fs.promises.rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
244
|
+
};
|
|
245
|
+
if (clone.failed || clone.exitCode !== 0) {
|
|
246
|
+
await cleanup();
|
|
247
|
+
const detail = firstLine(clone.stderr);
|
|
248
|
+
if (/could not read Username|authentication failed|Permission denied/i.test(clone.stderr)) {
|
|
249
|
+
throw new Error(`${detail || 'git clone failed'} — the repository needs credentials Kabmo cannot supply`);
|
|
250
|
+
}
|
|
251
|
+
throw new Error(detail || 'git clone failed');
|
|
252
|
+
}
|
|
253
|
+
return { dir, cleanup };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Clone `url` into a staging directory, list its skills, and remove the clone.
|
|
258
|
+
*
|
|
259
|
+
* Errors are thrown with git's own first line, because "clone failed" tells the
|
|
260
|
+
* user nothing about a typo in the owner name or a private repository.
|
|
261
|
+
*/
|
|
262
|
+
export async function inspectSkillRepo(
|
|
263
|
+
rawUrl: string,
|
|
264
|
+
options: InspectOptions = {},
|
|
265
|
+
): Promise<{ repo: string; skills: GitSkillEntry[]; notes: string[] }> {
|
|
266
|
+
const ref = toSkillRepoRef(rawUrl);
|
|
267
|
+
if (!ref) throw new Error('Expected a git URL or an owner/repo pair');
|
|
268
|
+
|
|
269
|
+
if (options.sourceDir) {
|
|
270
|
+
const skills = await scanSkillRepository(options.sourceDir);
|
|
271
|
+
return { repo: ref.slug, skills, notes: [...(skills.length >= MAX_SKILL_ENTRIES ? [`Only the first ${MAX_SKILL_ENTRIES} skills are listed.`] : [])] };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const stagingParent = options.stagingParent ?? tmpdir();
|
|
275
|
+
const staged = await stageClone(ref.url, stagingParent);
|
|
276
|
+
try {
|
|
277
|
+
const skills = await scanSkillRepository(staged.dir);
|
|
278
|
+
const notes: string[] = [];
|
|
279
|
+
if (skills.length === 0) notes.push('No SKILL.md found in this repository.');
|
|
280
|
+
if (skills.length >= MAX_SKILL_ENTRIES) notes.push(`Only the first ${MAX_SKILL_ENTRIES} skills are listed.`);
|
|
281
|
+
const unloadable = skills.filter((skill) => !skill.loadable).length;
|
|
282
|
+
if (unloadable > 0) notes.push(`${unloadable} SKILL.md file(s) have no description, so omp would not load them.`);
|
|
283
|
+
return { repo: ref.slug, skills, notes };
|
|
284
|
+
} finally {
|
|
285
|
+
await staged.cleanup();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Skill import from a git repository: what the inspector is willing to list and
|
|
8
|
+
* what the managed-copy installer will and will not write.
|
|
9
|
+
*
|
|
10
|
+
* The cases pinned here are the ones that quietly corrupt a skill tree:
|
|
11
|
+
*
|
|
12
|
+
* - a skill whose frontmatter has no `description` is NOT loadable (omp skips
|
|
13
|
+
* the file outright), so offering it as installable would promise a skill that
|
|
14
|
+
* never appears in the agent;
|
|
15
|
+
* - a name carrying a path separator is refused rather than joined, which is the
|
|
16
|
+
* only thing standing between a repository and `join(root, '../../x')`;
|
|
17
|
+
* - an existing directory is a SKIP unless `overwrite` is set, so importing a
|
|
18
|
+
* repository twice cannot silently replace the user's edits to a skill;
|
|
19
|
+
* - every refusal is per skill: one collision must not abort the batch.
|
|
20
|
+
*
|
|
21
|
+
* Fixtures are plain directories on disk (`sourceDir`), so no case needs a
|
|
22
|
+
* network or a git binary. The one clone case points `git` at a local repository
|
|
23
|
+
* it creates itself, which is the only way to prove the staging directory is
|
|
24
|
+
* removed afterwards.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
28
|
+
import fs from 'fs';
|
|
29
|
+
import { tmpdir } from 'os';
|
|
30
|
+
import { join } from 'path';
|
|
31
|
+
import { scanSkillRepository, toSkillRepoRef, inspectSkillRepo } from '@/server/lib/omp/config/skills-git-repo';
|
|
32
|
+
import { installSkillCopies } from '@/server/lib/omp/config/skills-git-install';
|
|
33
|
+
import { invalidateSkillCache } from '@/server/lib/omp/config/skills';
|
|
34
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
35
|
+
|
|
36
|
+
const ROOT = join(tmpdir(), 'kabmo-skills-git-test');
|
|
37
|
+
const REPO = join(ROOT, 'repo');
|
|
38
|
+
const AGENT_DIR = join(ROOT, 'agent');
|
|
39
|
+
let realAgentDir: string | undefined;
|
|
40
|
+
|
|
41
|
+
function writeSkill(dir: string, frontmatter: string, body = 'do the thing'): void {
|
|
42
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
43
|
+
fs.writeFileSync(join(dir, 'SKILL.md'), `---\n${frontmatter}\n---\n\n${body}\n`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
beforeAll(() => {
|
|
47
|
+
removeDir(ROOT);
|
|
48
|
+
realAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
49
|
+
Bun.env.PI_CODING_AGENT_DIR = AGENT_DIR;
|
|
50
|
+
fs.mkdirSync(AGENT_DIR, { recursive: true });
|
|
51
|
+
|
|
52
|
+
writeSkill(join(REPO, 'skills', 'review-pr'), 'name: review-pr\ndescription: Review pull requests');
|
|
53
|
+
writeSkill(join(REPO, 'skills', 'diagnose'), 'name: diagnose\ndescription: Diagnose a bug');
|
|
54
|
+
writeSkill(join(REPO, 'skills', 'no-description'), 'name: no-description');
|
|
55
|
+
writeSkill(join(REPO, 'plugins', 'nested-skill'), 'name: nested-skill\ndescription: Lives under plugins/');
|
|
56
|
+
// A directory with an unrelated README is not a skill.
|
|
57
|
+
fs.mkdirSync(join(REPO, 'docs'), { recursive: true });
|
|
58
|
+
fs.writeFileSync(join(REPO, 'docs', 'README.md'), '# docs\n');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterAll(() => {
|
|
62
|
+
if (realAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
63
|
+
else Bun.env.PI_CODING_AGENT_DIR = realAgentDir;
|
|
64
|
+
removeDir(ROOT);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('toSkillRepoRef', () => {
|
|
68
|
+
test('accepts a URL, the scp form, a github shorthand and an owner/repo pair', () => {
|
|
69
|
+
expect(toSkillRepoRef('https://github.com/anthropics/skills')?.url).toBe('https://github.com/anthropics/skills');
|
|
70
|
+
expect(toSkillRepoRef('https://github.com/anthropics/skills')?.slug).toBe('anthropics/skills');
|
|
71
|
+
expect(toSkillRepoRef('git@github.com:anthropics/skills.git')?.slug).toBe('anthropics/skills');
|
|
72
|
+
expect(toSkillRepoRef('github.com/anthropics/skills')?.url).toBe('https://github.com/anthropics/skills.git');
|
|
73
|
+
expect(toSkillRepoRef('anthropics/skills')?.slug).toBe('anthropics/skills');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('a shorthand slug is owner/repo, not the clone directory name', () => {
|
|
77
|
+
// `repoSlug` answers the DIRECTORY a clone takes ("skills"); a card showing
|
|
78
|
+
// that would name a repository that does not exist.
|
|
79
|
+
expect(toSkillRepoRef('https://github.com/anthropics/skills')?.slug).not.toBe('skills');
|
|
80
|
+
expect(toSkillRepoRef('https://gitlab.com/team/tools/skills')?.slug).toBe('tools/skills');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('refuses an empty value and anything with whitespace', () => {
|
|
84
|
+
expect(toSkillRepoRef('')).toBeNull();
|
|
85
|
+
expect(toSkillRepoRef(' ')).toBeNull();
|
|
86
|
+
expect(toSkillRepoRef('not a repo')).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('scanSkillRepository', () => {
|
|
91
|
+
test('lists skills/ and plugins/ entries and marks the unloadable one', async () => {
|
|
92
|
+
const skills = await scanSkillRepository(REPO);
|
|
93
|
+
const byName = new Map(skills.map((skill) => [skill.name, skill]));
|
|
94
|
+
expect(byName.get('review-pr')?.path).toBe('skills/review-pr');
|
|
95
|
+
expect(byName.get('diagnose')?.loadable).toBe(true);
|
|
96
|
+
expect(byName.get('nested-skill')?.path).toBe('plugins/nested-skill');
|
|
97
|
+
expect(byName.get('no-description')?.loadable).toBe(false);
|
|
98
|
+
expect(byName.has('README')).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('loadable entries come first', async () => {
|
|
102
|
+
const skills = await scanSkillRepository(REPO);
|
|
103
|
+
const firstBlocked = skills.findIndex((skill) => !skill.loadable);
|
|
104
|
+
if (firstBlocked !== -1) {
|
|
105
|
+
expect(skills.slice(firstBlocked).every((skill) => !skill.loadable)).toBe(true);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('a repository with no SKILL.md reports nothing and says so', async () => {
|
|
110
|
+
const empty = join(ROOT, 'empty-repo');
|
|
111
|
+
fs.mkdirSync(empty, { recursive: true });
|
|
112
|
+
fs.writeFileSync(join(empty, 'package.json'), '{}');
|
|
113
|
+
const inspection = await inspectSkillRepo(empty, { sourceDir: empty });
|
|
114
|
+
expect(inspection.skills).toEqual([]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('installSkillCopies', () => {
|
|
119
|
+
test('copies a skill directory whole into the managed user root', async () => {
|
|
120
|
+
invalidateSkillCache();
|
|
121
|
+
const outcome = await installSkillCopies('owner/repo', ['skills/review-pr'], {
|
|
122
|
+
scope: 'user',
|
|
123
|
+
sourceDir: REPO,
|
|
124
|
+
});
|
|
125
|
+
expect(outcome.installed).toEqual(['review-pr']);
|
|
126
|
+
expect(outcome.skipped).toEqual([]);
|
|
127
|
+
const target = join(AGENT_DIR, 'skills', 'review-pr');
|
|
128
|
+
expect(fs.existsSync(join(target, 'SKILL.md'))).toBe(true);
|
|
129
|
+
expect(fs.readFileSync(join(target, 'SKILL.md'), 'utf8')).toContain('description: Review pull requests');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('an existing skill is skipped, not overwritten, and the batch continues', async () => {
|
|
133
|
+
const outcome = await installSkillCopies('owner/repo', ['skills/review-pr', 'skills/diagnose'], {
|
|
134
|
+
scope: 'user',
|
|
135
|
+
sourceDir: REPO,
|
|
136
|
+
});
|
|
137
|
+
expect(outcome.installed).toEqual(['diagnose']);
|
|
138
|
+
expect(outcome.skipped).toEqual([
|
|
139
|
+
{ name: 'review-pr', reason: 'already installed — enable overwrite to replace it' },
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('overwrite replaces the directory', async () => {
|
|
144
|
+
fs.writeFileSync(join(AGENT_DIR, 'skills', 'review-pr', 'SKILL.md'), 'local edit');
|
|
145
|
+
const outcome = await installSkillCopies('owner/repo', ['skills/review-pr'], {
|
|
146
|
+
scope: 'user',
|
|
147
|
+
sourceDir: REPO,
|
|
148
|
+
overwrite: true,
|
|
149
|
+
});
|
|
150
|
+
expect(outcome.installed).toEqual(['review-pr']);
|
|
151
|
+
expect(fs.readFileSync(join(AGENT_DIR, 'skills', 'review-pr', 'SKILL.md'), 'utf8')).toContain('Review pull requests');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('a SKILL.md with no description is refused by name', async () => {
|
|
155
|
+
const outcome = await installSkillCopies('owner/repo', ['skills/no-description'], {
|
|
156
|
+
scope: 'user',
|
|
157
|
+
sourceDir: REPO,
|
|
158
|
+
});
|
|
159
|
+
expect(outcome.installed).toEqual([]);
|
|
160
|
+
expect(outcome.skipped[0]?.name).toBe('no-description');
|
|
161
|
+
expect(outcome.skipped[0]?.reason).toContain('no description');
|
|
162
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'no-description'))).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('a name carrying a path separator cannot escape the managed root', async () => {
|
|
166
|
+
const evil = join(ROOT, 'evil-repo');
|
|
167
|
+
writeSkill(join(evil, 'skills', 'escape'), 'name: ../../escaped\ndescription: tries to escape');
|
|
168
|
+
const outcome = await installSkillCopies('owner/repo', ['skills/escape'], {
|
|
169
|
+
scope: 'user',
|
|
170
|
+
sourceDir: evil,
|
|
171
|
+
});
|
|
172
|
+
expect(outcome.installed).toEqual([]);
|
|
173
|
+
expect(outcome.skipped[0]?.reason).toContain('path separator');
|
|
174
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'escaped'))).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('a project install with no workspace is refused, never redirected', async () => {
|
|
178
|
+
await expect(
|
|
179
|
+
installSkillCopies('owner/repo', ['skills/diagnose'], { scope: 'project', sourceDir: REPO }),
|
|
180
|
+
).rejects.toThrow(/workspace root/);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('selecting nothing from the repository is an error, not an empty success', async () => {
|
|
184
|
+
await expect(
|
|
185
|
+
installSkillCopies('owner/repo', ['skills/does-not-exist'], { scope: 'user', sourceDir: REPO }),
|
|
186
|
+
).rejects.toThrow(/None of the selected skills/);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('inspectSkillRepo over a real clone', () => {
|
|
191
|
+
test('clones a local repository, lists its skills, and removes the staging directory', async () => {
|
|
192
|
+
const origin = join(ROOT, 'origin');
|
|
193
|
+
writeSkill(join(origin, 'skills', 'cloned'), 'name: cloned\ndescription: Came from a clone');
|
|
194
|
+
const stagingParent = join(ROOT, 'staging');
|
|
195
|
+
fs.mkdirSync(stagingParent, { recursive: true });
|
|
196
|
+
|
|
197
|
+
const init = Bun.spawnSync({ cmd: ['git', 'init', '--quiet'], cwd: origin });
|
|
198
|
+
expect(init.exitCode).toBe(0);
|
|
199
|
+
Bun.spawnSync({ cmd: ['git', 'add', '.'], cwd: origin });
|
|
200
|
+
Bun.spawnSync({
|
|
201
|
+
cmd: ['git', '-c', 'user.email=t@example.com', '-c', 'user.name=t', 'commit', '-qm', 'init'],
|
|
202
|
+
cwd: origin,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const inspection = await inspectSkillRepo(origin, { stagingParent });
|
|
206
|
+
expect(inspection.skills.map((skill) => skill.name)).toEqual(['cloned']);
|
|
207
|
+
const leftovers = fs.readdirSync(stagingParent).filter((entry) => entry.startsWith('kabmo-skill-stage-'));
|
|
208
|
+
expect(leftovers).toEqual([]);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('a clone of a path that is not a repository reports git’s own line', async () => {
|
|
212
|
+
const notARepo = join(ROOT, 'not-a-repo');
|
|
213
|
+
fs.mkdirSync(notARepo, { recursive: true });
|
|
214
|
+
await expect(inspectSkillRepo(notARepo, { stagingParent: join(ROOT, 'staging2') })).rejects.toThrow();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('an unusable URL is refused before any process starts', async () => {
|
|
218
|
+
await expect(inspectSkillRepo('not a repo')).rejects.toThrow(/Expected a git URL/);
|
|
219
|
+
});
|
|
220
|
+
});
|