@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,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The skills route's catalog-source and git-import contract.
|
|
8
|
+
*
|
|
9
|
+
* Every case here pins a request shape the client depends on and that the server
|
|
10
|
+
* used to get wrong:
|
|
11
|
+
*
|
|
12
|
+
* - **`catalogSources` used to be a write nobody read.** The client sent
|
|
13
|
+
* `{ catalogSources: [...] }`, which matched no branch and came back `400
|
|
14
|
+
* Unsupported skill action` behind a `.catch(console.error)` — so "Add your own
|
|
15
|
+
* source" reported success and changed nothing. Adding a source now has its own
|
|
16
|
+
* `type`, refuses a duplicate repository, and answers the stored list.
|
|
17
|
+
* - **A source carries no invented metadata.** `skillCount` is `null` until a
|
|
18
|
+
* scan reports a real one, and the old `stars`/`updatedAt` literals are dropped
|
|
19
|
+
* on read instead of being passed through a narrower type.
|
|
20
|
+
* - **With no query, the scope is the app root, and a project install needs a
|
|
21
|
+
* workspace.** `install_git_skills` therefore refuses rather than falling back
|
|
22
|
+
* to the user root behind the user's back.
|
|
23
|
+
* - **MOCK answers 409 for every operation that would spawn a process.** A demo
|
|
24
|
+
* install that reports success while nothing is cloned is worse than a refusal.
|
|
25
|
+
*
|
|
26
|
+
* The DB is a temp file and the agent dir a temp tree, so nothing reaches the
|
|
27
|
+
* developer's real `~/.kabmo` or `~/.omp`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
31
|
+
import fs from 'fs';
|
|
32
|
+
import { tmpdir } from 'os';
|
|
33
|
+
import { join } from 'path';
|
|
34
|
+
import { getDb } from '@/server/db.server';
|
|
35
|
+
import { action as skillsAction, loader as skillsLoader } from '@/server/routes/settings/skills';
|
|
36
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
37
|
+
|
|
38
|
+
const API = 'http://localhost/api/settings/skills';
|
|
39
|
+
const ROOT = join(tmpdir(), 'kabmo-skill-routes-test');
|
|
40
|
+
const AGENT_DIR = join(ROOT, 'agent');
|
|
41
|
+
const WORKSPACE = join(ROOT, 'workspace');
|
|
42
|
+
const REPO = join(ROOT, 'repo');
|
|
43
|
+
|
|
44
|
+
type Handler = (args: never) => unknown;
|
|
45
|
+
|
|
46
|
+
function call(handler: Handler, request: Request): Promise<Response> {
|
|
47
|
+
return handler({ request, params: {} } as never) as Promise<Response>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function send(body: unknown): Request {
|
|
51
|
+
return new Request(API, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: JSON.stringify(body),
|
|
54
|
+
headers: { 'content-type': 'application/json' },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function writeSkill(dir: string, frontmatter: string): void {
|
|
59
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
+
fs.writeFileSync(join(dir, 'SKILL.md'), `---\n${frontmatter}\n---\n\nbody\n`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
beforeAll(async () => {
|
|
64
|
+
removeDir(ROOT);
|
|
65
|
+
fs.mkdirSync(AGENT_DIR, { recursive: true });
|
|
66
|
+
fs.mkdirSync(WORKSPACE, { recursive: true });
|
|
67
|
+
writeSkill(join(REPO, 'skills', 'alpha'), 'name: alpha\ndescription: First skill');
|
|
68
|
+
writeSkill(join(REPO, 'skills', 'beta'), 'name: beta\ndescription: Second skill');
|
|
69
|
+
// A real repository: the installer clones, and a plain directory is not clonable.
|
|
70
|
+
Bun.spawnSync({ cmd: ['git', 'init', '--quiet'], cwd: REPO });
|
|
71
|
+
Bun.spawnSync({ cmd: ['git', 'add', '.'], cwd: REPO });
|
|
72
|
+
Bun.spawnSync({
|
|
73
|
+
cmd: ['git', '-c', 'user.email=t@example.com', '-c', 'user.name=t', 'commit', '-qm', 'init'],
|
|
74
|
+
cwd: REPO,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Bun.env.PI_CODING_AGENT_DIR = AGENT_DIR;
|
|
78
|
+
Bun.env.KABMO_DB_PATH = join(ROOT, 'db.sqlite');
|
|
79
|
+
Bun.env.SYNC_WORKSPACE = 'false';
|
|
80
|
+
delete Bun.env.MOCK;
|
|
81
|
+
globalThis.__kabmoDb = undefined;
|
|
82
|
+
await getDb();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
afterAll(() => {
|
|
86
|
+
globalThis.__kabmoDb?.resolved?.raw.close();
|
|
87
|
+
globalThis.__kabmoDb = undefined;
|
|
88
|
+
delete Bun.env.PI_CODING_AGENT_DIR;
|
|
89
|
+
delete Bun.env.KABMO_DB_PATH;
|
|
90
|
+
delete Bun.env.SYNC_WORKSPACE;
|
|
91
|
+
delete Bun.env.MOCK;
|
|
92
|
+
removeDir(ROOT);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('catalog sources', () => {
|
|
96
|
+
test('the defaults report an unscanned count rather than a number', async () => {
|
|
97
|
+
const body = await (await call(skillsLoader, new Request(API))).json();
|
|
98
|
+
expect(Array.isArray(body.catalogSources)).toBe(true);
|
|
99
|
+
expect(body.catalogSources.every((source: { skillCount: unknown }) => source.skillCount === null)).toBe(true);
|
|
100
|
+
expect(body.catalogSources.some((source: { stars?: unknown }) => source.stars !== undefined)).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('adding a source stores a normalised repo slug and answers the list', async () => {
|
|
104
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'https://github.com/acme/skills', name: 'Acme' }));
|
|
105
|
+
expect(res.status).toBe(200);
|
|
106
|
+
const body = await res.json();
|
|
107
|
+
expect(body.source).toMatchObject({ name: 'Acme', repo: 'acme/skills', skillCount: null, isCustom: true });
|
|
108
|
+
expect(body.catalogSources.at(-1).repo).toBe('acme/skills');
|
|
109
|
+
|
|
110
|
+
const reloaded = await (await call(skillsLoader, new Request(API))).json();
|
|
111
|
+
expect(reloaded.catalogSources.at(-1).repo).toBe('acme/skills');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('the same repository twice is a 409, not a second card', async () => {
|
|
115
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'acme/skills' }));
|
|
116
|
+
expect(res.status).toBe(409);
|
|
117
|
+
expect((await res.json()).error).toContain('already a source');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('an unusable repo is a 400', async () => {
|
|
121
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'not a repo' }));
|
|
122
|
+
expect(res.status).toBe(400);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('removing a source drops it, and an unknown id is a 404', async () => {
|
|
126
|
+
const list = await (await call(skillsLoader, new Request(API))).json();
|
|
127
|
+
const id = list.catalogSources.at(-1).id;
|
|
128
|
+
const removed = await call(skillsAction, send({ type: 'remove_source', id }));
|
|
129
|
+
expect(removed.status).toBe(200);
|
|
130
|
+
expect((await removed.json()).catalogSources.some((source: { id: string }) => source.id === id)).toBe(false);
|
|
131
|
+
|
|
132
|
+
expect((await call(skillsAction, send({ type: 'remove_source', id }))).status).toBe(404);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('git inspection and install', () => {
|
|
137
|
+
test('an inspect on MOCK is refused instead of inventing a repository', async () => {
|
|
138
|
+
Bun.env.MOCK = 'true';
|
|
139
|
+
try {
|
|
140
|
+
const res = await call(skillsAction, send({ type: 'inspect_git_repo', url: REPO }));
|
|
141
|
+
expect(res.status).toBe(409);
|
|
142
|
+
} finally {
|
|
143
|
+
delete Bun.env.MOCK;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('install with no selection is a 400', async () => {
|
|
148
|
+
const res = await call(skillsAction, send({ type: 'install_git_skills', url: REPO, paths: [] }));
|
|
149
|
+
expect(res.status).toBe(400);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a project install with no workspace is refused, not redirected to another root', async () => {
|
|
153
|
+
// `?scope=user` is the request with no workspace. A create made there while
|
|
154
|
+
// the draft says `project` must be refused: writing it to the user root
|
|
155
|
+
// instead is how a skill "vanishes" from the list the user was looking at,
|
|
156
|
+
// and writing it under the server's cwd is how a test leaked a real
|
|
157
|
+
// `<repo>/.omp/skills/alpha` once.
|
|
158
|
+
const res = await call(
|
|
159
|
+
skillsAction,
|
|
160
|
+
new Request(`${API}?scope=user`, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
body: JSON.stringify({
|
|
163
|
+
type: 'install_git_skills',
|
|
164
|
+
url: REPO,
|
|
165
|
+
paths: ['skills/alpha'],
|
|
166
|
+
mode: 'managed_copy',
|
|
167
|
+
location: 'project',
|
|
168
|
+
}),
|
|
169
|
+
headers: { 'content-type': 'application/json' },
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
expect(res.status).toBe(400);
|
|
173
|
+
expect((await res.json()).error).toContain('workspace');
|
|
174
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'alpha'))).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('a user-scope install lands in the agent dir', async () => {
|
|
178
|
+
const res = await call(
|
|
179
|
+
skillsAction,
|
|
180
|
+
new Request(`${API}?scope=user`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/alpha'], mode: 'managed_copy', location: 'user' }),
|
|
183
|
+
headers: { 'content-type': 'application/json' },
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
const body = await res.json();
|
|
187
|
+
expect(body.installed).toEqual(['alpha']);
|
|
188
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'alpha', 'SKILL.md'))).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('a request that names no location installs into the USER root, not the server cwd', async () => {
|
|
192
|
+
// Measured: the catalog pane sends no root and no location, and a `project`
|
|
193
|
+
// default wrote the copy into `<server cwd>/.omp/skills` — the repository
|
|
194
|
+
// Kabmo was started from — while the user was looking at a user-scope list.
|
|
195
|
+
const before = fs.existsSync(join(process.cwd(), '.omp', 'skills', 'beta'));
|
|
196
|
+
const res = await call(
|
|
197
|
+
skillsAction,
|
|
198
|
+
new Request(API, {
|
|
199
|
+
method: 'POST',
|
|
200
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/beta'], mode: 'managed_copy' }),
|
|
201
|
+
headers: { 'content-type': 'application/json' },
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
expect(res.status).toBe(200);
|
|
205
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'beta', 'SKILL.md'))).toBe(true);
|
|
206
|
+
expect(fs.existsSync(join(process.cwd(), '.omp', 'skills', 'beta'))).toBe(before);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('installing the same skill again is skipped with the reason', async () => {
|
|
210
|
+
const request = () =>
|
|
211
|
+
new Request(`${API}?scope=user`, {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/alpha'], mode: 'managed_copy', location: 'user' }),
|
|
214
|
+
headers: { 'content-type': 'application/json' },
|
|
215
|
+
});
|
|
216
|
+
const body = await (await call(skillsAction, request())).json();
|
|
217
|
+
expect(body.installed).toEqual([]);
|
|
218
|
+
expect(body.skipped[0].reason).toContain('already installed');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('catalog search with an empty query answers nothing and spawns nothing', async () => {
|
|
222
|
+
const body = await (await call(skillsAction, send({ type: 'search_catalog', q: ' ' }))).json();
|
|
223
|
+
expect(body.catalogSkills).toEqual([]);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -5,7 +5,7 @@ import { getDb } from '@/server/db.server';
|
|
|
5
5
|
import { DEFAULT_CATALOG_SKILLS, DEFAULT_CATALOG_SOURCES, DEFAULT_SKILLS } from '@/client/data/settings/skill';
|
|
6
6
|
import { isMockMode } from '@/server/mock.server';
|
|
7
7
|
import type { SkillItem } from '@/shared/types';
|
|
8
|
-
import {
|
|
8
|
+
import { readCatalogSources } from '@/server/lib/omp/config/skill-sources';
|
|
9
9
|
import {
|
|
10
10
|
deleteSkillDir,
|
|
11
11
|
discoverSkills,
|
|
@@ -20,11 +20,10 @@ import {
|
|
|
20
20
|
toCatalogSkills,
|
|
21
21
|
uninstallCatalogSkill,
|
|
22
22
|
} from '@/server/lib/omp/config/skills-catalog';
|
|
23
|
+
import { runCatalogAction } from '@/server/routes/settings/skills-catalog-actions';
|
|
23
24
|
import { resolveDiscoveryScope, type DiscoveryScope } from '@/server/lib/omp/config/scope';
|
|
24
25
|
import { reloadLiveSessions } from '@/server/lib/omp/session/reload.server';
|
|
25
26
|
|
|
26
|
-
const SOURCES_KEY = 'omp_catalog_sources';
|
|
27
|
-
|
|
28
27
|
/** Human label for an omp discovery source. */
|
|
29
28
|
const SOURCE_LABELS: Record<string, string> = {
|
|
30
29
|
'native:user': 'User / omp agent',
|
|
@@ -83,10 +82,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
83
82
|
try {
|
|
84
83
|
if (mock) {
|
|
85
84
|
const db = await getDb();
|
|
86
|
-
const storedSources = await readSettingsJson<typeof DEFAULT_CATALOG_SOURCES>(db, SOURCES_KEY, DEFAULT_CATALOG_SOURCES);
|
|
87
85
|
return json({
|
|
88
86
|
skills: DEFAULT_SKILLS,
|
|
89
|
-
catalogSources:
|
|
87
|
+
catalogSources: await readCatalogSources(db),
|
|
90
88
|
catalogSkills: DEFAULT_CATALOG_SKILLS,
|
|
91
89
|
root: null,
|
|
92
90
|
isMock: true,
|
|
@@ -96,9 +94,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
96
94
|
const db = await getDb();
|
|
97
95
|
const url = new URL(request.url);
|
|
98
96
|
const scope = await resolveDiscoveryScope(url.searchParams.get('root'), url.searchParams.get('scope'));
|
|
99
|
-
|
|
100
|
-
const storedSources = await readSettingsJson<typeof DEFAULT_CATALOG_SOURCES>(db, SOURCES_KEY, DEFAULT_CATALOG_SOURCES);
|
|
101
|
-
const catalogSources = Array.isArray(storedSources) && storedSources.length > 0 ? storedSources : DEFAULT_CATALOG_SOURCES;
|
|
97
|
+
const catalogSources = await readCatalogSources(db);
|
|
102
98
|
|
|
103
99
|
const [skills, popular, curated] = await Promise.all([
|
|
104
100
|
listSkills(scope),
|
|
@@ -106,8 +102,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
106
102
|
searchSkillCatalog('code review', 8),
|
|
107
103
|
]);
|
|
108
104
|
|
|
105
|
+
// skills.sh entries are their own source: their install runs the CLI against
|
|
106
|
+
// a registry package, which is a different path from a local source card.
|
|
109
107
|
const seen = new Set<string>();
|
|
110
|
-
const catalogSkills = toCatalogSkills([...popular, ...curated],
|
|
108
|
+
const catalogSkills = toCatalogSkills([...popular, ...curated], 'skills-sh')
|
|
111
109
|
.filter((item) => (seen.has(item.repoTag) ? false : (seen.add(item.repoTag), true)));
|
|
112
110
|
|
|
113
111
|
return json({ skills, catalogSources, catalogSkills, root: scope.workspace, isMock: false });
|
|
@@ -170,12 +168,17 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
170
168
|
return json({ success: true, reloaded });
|
|
171
169
|
}
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
const catalogResponse = await runCatalogAction(body as Record<string, unknown>, {
|
|
172
|
+
db,
|
|
173
|
+
scope,
|
|
174
|
+
// A request that names no root is scoped to the app root for READING, but
|
|
175
|
+
// that is not a workspace a write may land in.
|
|
176
|
+
hasWorkspace:
|
|
177
|
+
Boolean(url.searchParams.get('root') ?? (typeof body.root === 'string' ? body.root : null)) &&
|
|
178
|
+
(url.searchParams.get('scope') ?? body.scope) !== 'user',
|
|
179
|
+
listSkills: async (target) => listSkills(target),
|
|
180
|
+
});
|
|
181
|
+
if (catalogResponse) return catalogResponse;
|
|
179
182
|
|
|
180
183
|
// Catalog install/uninstall goes through the real skills CLI, which is what
|
|
181
184
|
// actually puts the skill where omp reads it.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `GET|POST /api/telemetry/tokens` — the contract the Token Usage panel reads.
|
|
8
|
+
*
|
|
9
|
+
* The route is small on purpose, so the cases that matter are the ones a user
|
|
10
|
+
* can see: an unknown period must not 400 (the picker's own state can outrun a
|
|
11
|
+
* deploy), the body must carry the provider split the breakdown draws, and a
|
|
12
|
+
* demo run must answer the SAME shape as a real one — a field present in only
|
|
13
|
+
* one mode is how the panel renders in dev and crashes in production.
|
|
14
|
+
*
|
|
15
|
+
* The sessions root is a temp tree and the DB a temp file, so nothing here can
|
|
16
|
+
* read the developer's own usage.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
|
|
24
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
25
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
26
|
+
import { action, loader } from '@/server/routes/telemetry/tokens';
|
|
27
|
+
import type { TokenUsagePayload } from '@/shared/types';
|
|
28
|
+
|
|
29
|
+
const dirs: string[] = [];
|
|
30
|
+
let savedAgentDir: string | undefined;
|
|
31
|
+
let sessionsRoot = '';
|
|
32
|
+
|
|
33
|
+
function tempDir(): string {
|
|
34
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-tokens-'));
|
|
35
|
+
dirs.push(dir);
|
|
36
|
+
return dir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function read(response: Response): Promise<TokenUsagePayload> {
|
|
40
|
+
return (await response.json()) as TokenUsagePayload;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The route modules answer `unknown` (Remix's loader contract); this names it. */
|
|
44
|
+
async function call(
|
|
45
|
+
handler: (args: never) => unknown,
|
|
46
|
+
request: Request,
|
|
47
|
+
): Promise<Response> {
|
|
48
|
+
return (await handler({ request } as never)) as Response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const line = (provider: string, model: string, cost: number, timestamp: Date) =>
|
|
52
|
+
JSON.stringify({
|
|
53
|
+
type: 'message',
|
|
54
|
+
timestamp: timestamp.toISOString(),
|
|
55
|
+
message: {
|
|
56
|
+
role: 'assistant',
|
|
57
|
+
provider,
|
|
58
|
+
model,
|
|
59
|
+
usage: { input: 10, output: 5, cacheRead: 100, totalTokens: 115, cost: { total: cost } },
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
beforeAll(async () => {
|
|
64
|
+
await isolateDb();
|
|
65
|
+
savedAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
66
|
+
const agent = path.join(tempDir(), 'agent');
|
|
67
|
+
Bun.env.PI_CODING_AGENT_DIR = agent;
|
|
68
|
+
sessionsRoot = path.join(agent, 'sessions', 'kabmo');
|
|
69
|
+
fs.mkdirSync(sessionsRoot, { recursive: true });
|
|
70
|
+
delete Bun.env.MOCK;
|
|
71
|
+
|
|
72
|
+
const now = new Date();
|
|
73
|
+
fs.writeFileSync(
|
|
74
|
+
path.join(sessionsRoot, 'a.jsonl'),
|
|
75
|
+
[
|
|
76
|
+
line('kenari-jatis', 'deepseek-v4-1-flash', 9, now),
|
|
77
|
+
line('kenari', 'deepseek-v4-1-flash', 1, now),
|
|
78
|
+
].join('\n') + '\n',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterAll(async () => {
|
|
83
|
+
if (savedAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
84
|
+
else Bun.env.PI_CODING_AGENT_DIR = savedAgentDir;
|
|
85
|
+
await releaseDb();
|
|
86
|
+
for (const dir of dirs.splice(0)) removeDir(dir);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('GET /api/telemetry/tokens', () => {
|
|
90
|
+
test('answers the provider split of the requested period', async () => {
|
|
91
|
+
const response = await call(loader, new Request('http://kabmo.test/api/telemetry/tokens?range=30d'));
|
|
92
|
+
expect(response.status).toBe(200);
|
|
93
|
+
const payload = await read(response);
|
|
94
|
+
expect(payload.providers.map((provider) => provider.id).sort()).toEqual(['kenari', 'kenari-jatis']);
|
|
95
|
+
expect(payload.providers.find((provider) => provider.id === 'kenari-jatis')?.cost).toBeCloseTo(9, 10);
|
|
96
|
+
expect(payload.days).toHaveLength(1);
|
|
97
|
+
expect(payload.days[0].providers['kenari']?.cost).toBeCloseTo(1, 10);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('the body is raw counters plus an index state — no formatted strings', async () => {
|
|
101
|
+
const payload = await read(await call(loader, new Request('http://kabmo.test/api/telemetry/tokens')));
|
|
102
|
+
expect(typeof payload.totals.cost).toBe('number');
|
|
103
|
+
expect(payload.index.state).toBe('ready');
|
|
104
|
+
expect(payload.index.transcripts).toBe(1);
|
|
105
|
+
expect(payload.periodLabel.length).toBeGreaterThan(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('an unknown range falls back to the default instead of failing', async () => {
|
|
109
|
+
const payload = await read(await call(loader, new Request('http://kabmo.test/api/telemetry/tokens?range=forever')));
|
|
110
|
+
expect(payload.range).toBe('30d');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a custom period is honoured end to end', async () => {
|
|
114
|
+
const today = new Date();
|
|
115
|
+
const day = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
|
|
116
|
+
const payload = await read(
|
|
117
|
+
await call(loader, new Request(`http://kabmo.test/api/telemetry/tokens?range=custom&customFrom=${day}&customTo=${day}`)),
|
|
118
|
+
);
|
|
119
|
+
expect(payload.range).toBe('custom');
|
|
120
|
+
expect(payload.totals.records).toBe(2);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('a non-GET request is refused rather than answered', async () => {
|
|
124
|
+
const response = await call(loader, new Request('http://kabmo.test/api/telemetry/tokens', { method: 'POST' }));
|
|
125
|
+
expect(response.status).toBe(405);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('POST /api/telemetry/tokens', () => {
|
|
130
|
+
test('refresh re-reads the tree and answers the same shape', async () => {
|
|
131
|
+
fs.appendFileSync(
|
|
132
|
+
path.join(sessionsRoot, 'a.jsonl'),
|
|
133
|
+
`${line('kenari-jatis', 'deepseek-v4-1-flash', 2, new Date())}\n`,
|
|
134
|
+
);
|
|
135
|
+
const response = await call(action, new Request('http://kabmo.test/api/telemetry/tokens?range=30d', { method: 'POST' }));
|
|
136
|
+
expect(response.status).toBe(200);
|
|
137
|
+
const payload = await read(response);
|
|
138
|
+
expect(payload.providers.find((provider) => provider.id === 'kenari-jatis')?.cost).toBeCloseTo(11, 10);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('a non-POST request is refused', async () => {
|
|
142
|
+
const response = await call(action, new Request('http://kabmo.test/api/telemetry/tokens', { method: 'GET' }));
|
|
143
|
+
expect(response.status).toBe(405);
|
|
144
|
+
});
|
|
145
|
+
});
|