@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,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* XML section wrappers in omp's `xd://` docs (`<instruction>`, `<examples>`,
|
|
8
|
+
* `<critical>`) became headings before the markdown parse. Without that, the
|
|
9
|
+
* prose path escaped the tags — the reader saw `<instruction>` as a literal
|
|
10
|
+
* line and every section ran together as one block.
|
|
11
|
+
*
|
|
12
|
+
* The gates are what the tests pin: a paired, whole-line wrapper is rewritten,
|
|
13
|
+
* and nothing else is (a code fence showing the tags as an example, an
|
|
14
|
+
* attribute-carrying wrapper, an unpaired tag, a tag inside a sentence).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expect, test } from 'bun:test';
|
|
18
|
+
import { xmlSectionsToHeadings } from '@/shared/lib/markdown/xml-sections';
|
|
19
|
+
|
|
20
|
+
describe('xmlSectionsToHeadings', () => {
|
|
21
|
+
test('paired wrappers become headings and their closing lines disappear', () => {
|
|
22
|
+
const source = [
|
|
23
|
+
'Intro line.',
|
|
24
|
+
'',
|
|
25
|
+
'<instruction>',
|
|
26
|
+
'- Static content? Use `read`.',
|
|
27
|
+
'</instruction>',
|
|
28
|
+
'',
|
|
29
|
+
'<critical>',
|
|
30
|
+
'- MUST open a tab before direct use.',
|
|
31
|
+
'</critical>',
|
|
32
|
+
].join('\n');
|
|
33
|
+
|
|
34
|
+
expect(xmlSectionsToHeadings(source)).toBe([
|
|
35
|
+
'Intro line.',
|
|
36
|
+
'',
|
|
37
|
+
'## Instruction',
|
|
38
|
+
'- Static content? Use `read`.',
|
|
39
|
+
'',
|
|
40
|
+
'',
|
|
41
|
+
'## Critical',
|
|
42
|
+
'- MUST open a tab before direct use.',
|
|
43
|
+
'',
|
|
44
|
+
].join('\n'));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('nesting steps the heading level down, capped at h6', () => {
|
|
48
|
+
const source = [
|
|
49
|
+
'<outer>',
|
|
50
|
+
'<inner>',
|
|
51
|
+
'text',
|
|
52
|
+
'</inner>',
|
|
53
|
+
'</outer>',
|
|
54
|
+
'<a>',
|
|
55
|
+
'<b>',
|
|
56
|
+
'<c>',
|
|
57
|
+
'<d>',
|
|
58
|
+
'<e>',
|
|
59
|
+
'deep',
|
|
60
|
+
'</e>',
|
|
61
|
+
'</d>',
|
|
62
|
+
'</c>',
|
|
63
|
+
'</b>',
|
|
64
|
+
'</a>',
|
|
65
|
+
].join('\n');
|
|
66
|
+
|
|
67
|
+
expect(xmlSectionsToHeadings(source)).toBe([
|
|
68
|
+
'## Outer',
|
|
69
|
+
'### Inner',
|
|
70
|
+
'text',
|
|
71
|
+
'',
|
|
72
|
+
'',
|
|
73
|
+
'## A',
|
|
74
|
+
'### B',
|
|
75
|
+
'#### C',
|
|
76
|
+
'##### D',
|
|
77
|
+
'###### E',
|
|
78
|
+
'deep',
|
|
79
|
+
'',
|
|
80
|
+
'',
|
|
81
|
+
'',
|
|
82
|
+
'',
|
|
83
|
+
'',
|
|
84
|
+
].join('\n'));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('a crossed pair leaves the unmatched lines literal', () => {
|
|
88
|
+
// Valid = open + matching close, properly nested. `<a>` never gets its own
|
|
89
|
+
// close where the stack expects it, so only the well-formed `<b>` pair is
|
|
90
|
+
// a section.
|
|
91
|
+
const source = ['<a>', 'text', '<b>', 'inner', '</a>', '</b>'].join('\n');
|
|
92
|
+
|
|
93
|
+
expect(xmlSectionsToHeadings(source)).toBe(
|
|
94
|
+
['<a>', 'text', '## B', 'inner', '</a>', ''].join('\n'),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('a fenced block that shows the wrappers keeps them verbatim', () => {
|
|
99
|
+
const source = [
|
|
100
|
+
'<instruction>',
|
|
101
|
+
'Outer section.',
|
|
102
|
+
'```xml',
|
|
103
|
+
'<instruction>',
|
|
104
|
+
'literal',
|
|
105
|
+
'</instruction>',
|
|
106
|
+
'```',
|
|
107
|
+
'</instruction>',
|
|
108
|
+
].join('\n');
|
|
109
|
+
|
|
110
|
+
expect(xmlSectionsToHeadings(source)).toBe([
|
|
111
|
+
'## Instruction',
|
|
112
|
+
'Outer section.',
|
|
113
|
+
'```xml',
|
|
114
|
+
'<instruction>',
|
|
115
|
+
'literal',
|
|
116
|
+
'</instruction>',
|
|
117
|
+
'```',
|
|
118
|
+
'',
|
|
119
|
+
].join('\n'));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('an unpaired or inline tag is left exactly as written', () => {
|
|
123
|
+
const source = [
|
|
124
|
+
'<summary>',
|
|
125
|
+
'no closing partner',
|
|
126
|
+
'use <slug> here',
|
|
127
|
+
'<system-reminder reason="a rule fired">',
|
|
128
|
+
'wrapped with attributes',
|
|
129
|
+
'</system-reminder>',
|
|
130
|
+
'closing without an opener: </notes>',
|
|
131
|
+
].join('\n');
|
|
132
|
+
|
|
133
|
+
expect(xmlSectionsToHeadings(source)).toBe(source);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('a source with no tags is returned untouched', () => {
|
|
137
|
+
const source = '# Title\n\n- a < b';
|
|
138
|
+
expect(xmlSectionsToHeadings(source)).toBe(source);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* XML section wrappers → markdown headings.
|
|
8
|
+
*
|
|
9
|
+
* omp's `xd://` device docs are markdown, but several sections are marked with
|
|
10
|
+
* an XML-ish wrapper instead of a heading: `<instruction>…</instruction>`,
|
|
11
|
+
* `<examples>…</examples>`, `<critical>…</critical>`. The markdown pipeline
|
|
12
|
+
* escapes source HTML (agent output renders markup as data), so the read panel
|
|
13
|
+
* showed `<instruction>` and `</instruction>` as literal lines and the sections
|
|
14
|
+
* ran together as ordinary prose — the wrap did no visual work at all.
|
|
15
|
+
*
|
|
16
|
+
* Converting them before the markdown parse is the only place both halves can
|
|
17
|
+
* be dropped: marked would otherwise treat a bare tag line as an HTML block,
|
|
18
|
+
* and DOMPurify's profile strips it only after the paragraph boundaries are
|
|
19
|
+
* already decided.
|
|
20
|
+
*
|
|
21
|
+
* Deliberately narrow, because the same text path renders real markdown files:
|
|
22
|
+
*
|
|
23
|
+
* - A wrapper must occupy a WHOLE line AND be valid: an opening line closed by
|
|
24
|
+
* the same name, properly nested. `<slug>` inside a sentence, a lone
|
|
25
|
+
* `<summary>`, a stray `</tag>`, and a tag carrying attributes
|
|
26
|
+
* (`<system-reminder reason="…">`, which the output envelope already reads)
|
|
27
|
+
* are left byte-for-byte as they were.
|
|
28
|
+
* - Nothing inside a fenced code block is touched: a doc that shows the tags
|
|
29
|
+
* as an example must keep showing them as text.
|
|
30
|
+
* - Nesting moves the heading level down one, capped at `h6`; the first level
|
|
31
|
+
* is `h2`, since the document's own `#` title is `h1`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** A wrapper line: `<name>` / `</name>`, nothing else on the line. */
|
|
35
|
+
const OPEN_RE = /^<([A-Za-z][\w-]*)>$/;
|
|
36
|
+
const CLOSE_RE = /^<\/([A-Za-z][\w-]*)>$/;
|
|
37
|
+
|
|
38
|
+
/** One wrapper line, and the pair it forms when a matching close arrives. */
|
|
39
|
+
interface Section {
|
|
40
|
+
name: string;
|
|
41
|
+
openIndex: number;
|
|
42
|
+
/** The wrapper this one sits inside — matched or not; the level check sorts
|
|
43
|
+
* that out once the whole source has been scanned. */
|
|
44
|
+
parent?: Section;
|
|
45
|
+
/** Line index of the closing wrapper, once the pair was matched. */
|
|
46
|
+
closeIndex?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A fence opener or closer, indented no more than markdown allows. */
|
|
50
|
+
function fenceAt(line: string): { char: string; length: number } | undefined {
|
|
51
|
+
const body = line.trimStart();
|
|
52
|
+
if (line.length - body.length > 3) return undefined;
|
|
53
|
+
const match = /^(`{3,}|~{3,})/.exec(body);
|
|
54
|
+
return match ? { char: match[1][0], length: match[1].length } : undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `security-scan` → `Security Scan`; an already-capitalized name is kept. */
|
|
58
|
+
function sectionLabel(name: string): string {
|
|
59
|
+
return name
|
|
60
|
+
.split(/[-_]+/)
|
|
61
|
+
.filter(Boolean)
|
|
62
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
63
|
+
.join(' ');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Rewrite standalone XML wrapper pairs into `##`-level headings, and drop the
|
|
68
|
+
* closing wrapper lines.
|
|
69
|
+
*
|
|
70
|
+
* A wrapper only counts when it is VALID: an opening line and a closing line
|
|
71
|
+
* with the same name, properly nested against every other wrapper around it. A
|
|
72
|
+
* stray `<tag>`, a stray `</tag>`, and a crossed pair (`<a><b></a></b>`) stay
|
|
73
|
+
* literal — they are text about markup, not a section of the document.
|
|
74
|
+
*/
|
|
75
|
+
export function xmlSectionsToHeadings(source: string): string {
|
|
76
|
+
if (!source.includes('<')) return source;
|
|
77
|
+
|
|
78
|
+
const lines = source.split('\n');
|
|
79
|
+
|
|
80
|
+
// Which lines sit inside a fenced code block, so the scan below can skip
|
|
81
|
+
// them. A fence is closed by a run of the same character that is at least as
|
|
82
|
+
// long as the one that opened it.
|
|
83
|
+
const inFence: boolean[] = [];
|
|
84
|
+
let fence: { char: string; length: number } | undefined;
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
const candidate = fenceAt(line);
|
|
87
|
+
if (fence) {
|
|
88
|
+
inFence.push(true);
|
|
89
|
+
if (candidate && candidate.char === fence.char && candidate.length >= fence.length) fence = undefined;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (candidate) fence = candidate;
|
|
93
|
+
inFence.push(candidate !== undefined);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const stack: Section[] = [];
|
|
97
|
+
/** The opening line index of every valid pair, and where its close sits. */
|
|
98
|
+
const headings = new Map<number, Section>();
|
|
99
|
+
const closes = new Set<number>();
|
|
100
|
+
|
|
101
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
102
|
+
if (inFence[index]) continue;
|
|
103
|
+
const text = lines[index].trim();
|
|
104
|
+
|
|
105
|
+
const closed = CLOSE_RE.exec(text);
|
|
106
|
+
if (closed) {
|
|
107
|
+
// Strict nesting: only the wrapper that is actually open can be closed.
|
|
108
|
+
const opener = stack[stack.length - 1];
|
|
109
|
+
if (!opener || opener.name !== closed[1]) continue;
|
|
110
|
+
stack.pop();
|
|
111
|
+
opener.closeIndex = index;
|
|
112
|
+
headings.set(opener.openIndex, opener);
|
|
113
|
+
closes.add(index);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const opened = OPEN_RE.exec(text);
|
|
118
|
+
if (opened) stack.push({ name: opened[1], openIndex: index, parent: stack[stack.length - 1] });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (headings.size === 0) return source;
|
|
122
|
+
|
|
123
|
+
/** Heading level from the nesting of VALID ancestors only: an unmatched
|
|
124
|
+
* wrapper stays literal text and therefore contributes no level. */
|
|
125
|
+
const level = (section: Section): number => {
|
|
126
|
+
const parent = section.parent;
|
|
127
|
+
if (!parent || parent.closeIndex === undefined) return 2;
|
|
128
|
+
return Math.min(6, level(parent) + 1);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return lines
|
|
132
|
+
.map((line, index) => {
|
|
133
|
+
const section = headings.get(index);
|
|
134
|
+
if (section) return `${'#'.repeat(level(section))} ${sectionLabel(section.name)}`;
|
|
135
|
+
if (closes.has(index)) return '';
|
|
136
|
+
return line;
|
|
137
|
+
})
|
|
138
|
+
.join('\n');
|
|
139
|
+
}
|
|
@@ -29,6 +29,63 @@ export function providerLabel(slug: string, names: Record<string, string> = {}):
|
|
|
29
29
|
return known?.trim() ? known : titleCaseProviderSlug(slug);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Slug aliases omp uses interchangeably, folded onto one identity.
|
|
34
|
+
*
|
|
35
|
+
* Both the quota surfaces (`usage/providers.server.ts`) and the token/cost
|
|
36
|
+
* rollup attribute rows by provider, and the two must agree or the same
|
|
37
|
+
* account is two rows on one panel and one on the other.
|
|
38
|
+
*/
|
|
39
|
+
const SLUG_ALIASES: Record<string, string> = {
|
|
40
|
+
'command-code': 'commandcode',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** The canonical spelling of a provider slug: lowercased, alias folded. */
|
|
44
|
+
export function canonicalProviderSlug(slug: string): string {
|
|
45
|
+
const lower = slug.trim().toLowerCase();
|
|
46
|
+
return SLUG_ALIASES[lower] ?? lower;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Brand spellings a title-case pass cannot produce. Kept small on purpose: the
|
|
51
|
+
* slug is the identity, this is only how it is printed.
|
|
52
|
+
*/
|
|
53
|
+
const BRAND_NAMES: Record<string, string> = {
|
|
54
|
+
openai: 'OpenAI',
|
|
55
|
+
kenari: 'Kenari.id',
|
|
56
|
+
deepseek: 'DeepSeek',
|
|
57
|
+
'openai-codex': 'OpenAI Codex',
|
|
58
|
+
'google-gemini-cli': 'Google Gemini CLI',
|
|
59
|
+
'google-antigravity': 'Google Antigravity',
|
|
60
|
+
'github-copilot': 'GitHub Copilot',
|
|
61
|
+
zai: 'Z.AI',
|
|
62
|
+
'zai-coding-plan': 'Z.AI Coding Plan',
|
|
63
|
+
xai: 'xAI',
|
|
64
|
+
'xai-oauth': 'xAI (OAuth)',
|
|
65
|
+
'kimi-code': 'Kimi Code',
|
|
66
|
+
'qwen-portal': 'Qwen Portal',
|
|
67
|
+
'minimax-code': 'MiniMax Code',
|
|
68
|
+
'minimax-code-cn': 'MiniMax Code (CN)',
|
|
69
|
+
'alibaba-token-plan': 'Alibaba Token Plan',
|
|
70
|
+
'alibaba-coding-plan': 'Alibaba Coding Plan',
|
|
71
|
+
'zhipu-coding-plan': 'Zhipu Coding Plan',
|
|
72
|
+
'gitlab-duo': 'GitLab Duo',
|
|
73
|
+
'gitlab-duo-agent': 'GitLab Duo Agent',
|
|
74
|
+
'charm-hyper': 'Charm Hyper',
|
|
75
|
+
'cline-pass': 'Cline Pass',
|
|
76
|
+
'opencode-go': 'OpenCode Go',
|
|
77
|
+
'xiaomi-token-plan-sgp': 'Xiaomi Token Plan (SGP)',
|
|
78
|
+
'xiaomi-token-plan-ams': 'Xiaomi Token Plan (AMS)',
|
|
79
|
+
'xiaomi-token-plan-cn': 'Xiaomi Token Plan (CN)',
|
|
80
|
+
'openai-codex-device': 'OpenAI Codex (Device)',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Human-readable provider name: brand spelling when known, title case otherwise. */
|
|
84
|
+
export function providerDisplayName(slug: string): string {
|
|
85
|
+
const canonical = canonicalProviderSlug(slug);
|
|
86
|
+
return BRAND_NAMES[canonical] ?? titleCaseProviderSlug(canonical);
|
|
87
|
+
}
|
|
88
|
+
|
|
32
89
|
/** Build a slug → display-name map from `/api/models` `connectedProviders`. */
|
|
33
90
|
export function providerNamesFromConnected(
|
|
34
91
|
connectedProviders: readonly ProviderNameInfo[] | undefined,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Agent file naming, enforced on both sides of the wire.
|
|
8
|
+
*
|
|
9
|
+
* The route refuses an unsafe base name and the pane refuses the same name
|
|
10
|
+
* before it sends one. Pinned here so the two cannot drift: a name the pane
|
|
11
|
+
* accepted and the route rejected would surface as a 400 under a form that
|
|
12
|
+
* looked valid.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { agentFileBaseName, agentFileNameError } from '@/shared/lib/omp/config/agent-file';
|
|
17
|
+
|
|
18
|
+
describe('agentFileNameError', () => {
|
|
19
|
+
test('accepts a normal agent name', () => {
|
|
20
|
+
expect(agentFileNameError('reviewer')).toBeNull();
|
|
21
|
+
expect(agentFileNameError('code-reviewer.v2')).toBeNull();
|
|
22
|
+
expect(agentFileNameError(' helper_1 ')).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('refuses an empty name with a sentence that says what it becomes', () => {
|
|
26
|
+
expect(agentFileNameError(' ')).toContain('becomes the definition');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('refuses a path or a space instead of letting the route answer 400', () => {
|
|
30
|
+
expect(agentFileNameError('a/b')).toContain('letters, numbers');
|
|
31
|
+
expect(agentFileNameError('../escape')).toContain('letters, numbers');
|
|
32
|
+
expect(agentFileNameError('bad name')).toContain('letters, numbers');
|
|
33
|
+
expect(agentFileNameError('-leading')).toContain('letters, numbers');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('agentFileBaseName', () => {
|
|
38
|
+
test('strips the directory and the extension', () => {
|
|
39
|
+
expect(agentFileBaseName('/home/u/.omp/agent/agents/reviewer.md')).toBe('reviewer');
|
|
40
|
+
expect(agentFileBaseName('C:/agents/helper.MD')).toBe('helper');
|
|
41
|
+
expect(agentFileBaseName('plain')).toBe('plain');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('strips a BACKSLASH path, which is what a Windows host reports', () => {
|
|
45
|
+
// The pane sends this value straight back as `fileName` on the next rename
|
|
46
|
+
// or delete, so returning the whole path made every write land at a path
|
|
47
|
+
// named after itself and no delete find its file — measured on the Windows
|
|
48
|
+
// gate, where the list answered
|
|
49
|
+
// `fileName: "C:\Users\RUNNER~1\AppData\Local\Temp\…\agents\reviewer"`
|
|
50
|
+
// and three cases failed.
|
|
51
|
+
expect(agentFileBaseName('C:\\Users\\u\\.omp\\agent\\agents\\reviewer.md')).toBe('reviewer');
|
|
52
|
+
expect(agentFileBaseName('D:\\agents\\helper.MD')).toBe('helper');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The file-name rules for a native omp agent definition.
|
|
8
|
+
*
|
|
9
|
+
* One module because two sides enforce the same rule: the route refuses a file
|
|
10
|
+
* name that is not a safe base name (path traversal, spaces, dots-only), and
|
|
11
|
+
* the pane refuses the same name before it sends it — a save that travels and
|
|
12
|
+
* returns a 500 for a name the form could have rejected reads as a server bug
|
|
13
|
+
* rather than as a typo.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** A file base name (no extension) an agent can be written to. */
|
|
17
|
+
export const AGENT_FILE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
18
|
+
|
|
19
|
+
/** Why a name cannot be used as an agent file, or null when it can. */
|
|
20
|
+
export function agentFileNameError(name: string): string | null {
|
|
21
|
+
const trimmed = name.trim();
|
|
22
|
+
if (!trimmed) return 'An agent needs a name — it becomes the definition’s file name.';
|
|
23
|
+
if (!AGENT_FILE_NAME_PATTERN.test(trimmed)) {
|
|
24
|
+
return 'Use letters, numbers, dots, dashes or underscores, starting with a letter or number.';
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The base name (no `.md`) of an agent definition file path. */
|
|
30
|
+
export function agentFileBaseName(filePath: string): string {
|
|
31
|
+
// BOTH separators, because `filePath` is whatever the host produced: a
|
|
32
|
+
// Windows runner reports `C:\Users\…\agents\reviewer.md`, and splitting on
|
|
33
|
+
// `/` alone returned that entire path as the "file name". The pane then sent
|
|
34
|
+
// it back as `fileName`, the route wrote a file named after the full path,
|
|
35
|
+
// and every later rename/delete missed the file it meant — measured on the
|
|
36
|
+
// Windows gate, where `fileName` came back as
|
|
37
|
+
// `C:\Users\RUNNER~1\AppData\Local\Temp\…\agents\reviewer` and three cases
|
|
38
|
+
// failed. `node:path` is not usable here: this module is shared with the
|
|
39
|
+
// browser, where it has no implementation.
|
|
40
|
+
const cut = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
|
|
41
|
+
const file = filePath.slice(cut + 1);
|
|
42
|
+
return file.replace(/\.md$/i, '');
|
|
43
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The OMP config row's text → value conversion.
|
|
8
|
+
*
|
|
9
|
+
* Pinned because a bad draft used to revert SILENTLY: a trailing comma in a
|
|
10
|
+
* JSON array or a half-typed number simply did not save, with nothing on screen
|
|
11
|
+
* to say why. Each case here is a draft a user can produce with one keystroke
|
|
12
|
+
* too many.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import {
|
|
17
|
+
parseDraft,
|
|
18
|
+
parseFiniteNumber,
|
|
19
|
+
parseJsonArray,
|
|
20
|
+
parseJsonRecord,
|
|
21
|
+
valueToText,
|
|
22
|
+
valuesEqual,
|
|
23
|
+
} from '@/shared/lib/omp/config/row-value';
|
|
24
|
+
|
|
25
|
+
describe('valueToText', () => {
|
|
26
|
+
test('scalars print themselves and containers print JSON', () => {
|
|
27
|
+
expect(valueToText('titanium')).toBe('titanium');
|
|
28
|
+
expect(valueToText(42)).toBe('42');
|
|
29
|
+
expect(valueToText(false)).toBe('false');
|
|
30
|
+
expect(valueToText(['anthropic', 'openai'])).toBe('["anthropic","openai"]');
|
|
31
|
+
expect(valueToText({ bash: 'prompt' })).toBe('{"bash":"prompt"}');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('an unset value is an empty field, not the text "undefined"', () => {
|
|
35
|
+
expect(valueToText(undefined)).toBe('');
|
|
36
|
+
expect(valueToText(null)).toBe('');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('parseFiniteNumber', () => {
|
|
41
|
+
test('a partial entry is not a number', () => {
|
|
42
|
+
expect(parseFiniteNumber('')).toBeNull();
|
|
43
|
+
expect(parseFiniteNumber('-')).toBeNull();
|
|
44
|
+
expect(parseFiniteNumber('+')).toBeNull();
|
|
45
|
+
expect(parseFiniteNumber('.')).toBeNull();
|
|
46
|
+
expect(parseFiniteNumber('abc')).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a finite number survives surrounding whitespace', () => {
|
|
50
|
+
expect(parseFiniteNumber(' 1200 ')).toBe(1200);
|
|
51
|
+
expect(parseFiniteNumber('-0.5')).toBe(-0.5);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('parseDraft', () => {
|
|
56
|
+
test('a number row names what it wants instead of reverting', () => {
|
|
57
|
+
expect(parseDraft('number', '12')).toEqual({ ok: true, value: 12 });
|
|
58
|
+
expect(parseDraft('number', '')).toMatchObject({ ok: false });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a string row keeps an empty value — clearing a credential is a write', () => {
|
|
62
|
+
expect(parseDraft('string', ' ')).toEqual({ ok: true, value: '' });
|
|
63
|
+
expect(parseDraft('string', ' sk-live ')).toEqual({ ok: true, value: 'sk-live' });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('an array row accepts a JSON array and rejects anything else', () => {
|
|
67
|
+
expect(parseDraft('array', '["a"]')).toEqual({ ok: true, value: ['a'] });
|
|
68
|
+
expect(parseDraft('array', '')).toEqual({ ok: true, value: [] });
|
|
69
|
+
expect(parseDraft('array', '["a",]')).toMatchObject({ ok: false });
|
|
70
|
+
expect(parseDraft('array', '{"a":1}')).toMatchObject({ ok: false });
|
|
71
|
+
expect(parseDraft('array', 'nope')).toMatchObject({ ok: false });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a record row accepts a JSON object and rejects an array', () => {
|
|
75
|
+
expect(parseDraft('record', '{"bash":"prompt"}')).toEqual({ ok: true, value: { bash: 'prompt' } });
|
|
76
|
+
expect(parseDraft('record', '')).toEqual({ ok: true, value: {} });
|
|
77
|
+
expect(parseDraft('record', '[]')).toMatchObject({ ok: false });
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('json helpers', () => {
|
|
82
|
+
test('a non-array and a non-object parse to null', () => {
|
|
83
|
+
expect(parseJsonArray('7')).toBeNull();
|
|
84
|
+
expect(parseJsonRecord('"x"')).toBeNull();
|
|
85
|
+
expect(parseJsonArray('[1,2]')).toEqual([1, 2]);
|
|
86
|
+
expect(parseJsonRecord('{"a":1}')).toEqual({ a: 1 });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('valuesEqual compares depth-first, ignoring key-independent order', () => {
|
|
90
|
+
expect(valuesEqual(['a'], ['a'])).toBe(true);
|
|
91
|
+
expect(valuesEqual(['a', 'b'], ['b', 'a'])).toBe(false);
|
|
92
|
+
expect(valuesEqual({ a: 1 }, { a: 1 })).toBe(true);
|
|
93
|
+
expect(valuesEqual(1, '1')).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Text ↔ value conversion for one omp config row.
|
|
8
|
+
*
|
|
9
|
+
* `omp config set` accepts a string, number, boolean, array or record, and the
|
|
10
|
+
* schema decides which one a row holds. The panel edits everything as text, so
|
|
11
|
+
* this module is where a keystroke becomes a typed value — and where invalid
|
|
12
|
+
* text is REJECTED instead of being silently dropped. The old editor reverted
|
|
13
|
+
* on a parse failure with no message, so a trailing comma in a JSON array
|
|
14
|
+
* looked like the field had simply refused to save.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SchemaEntry } from '@/shared/lib/omp/config/schema-types';
|
|
18
|
+
|
|
19
|
+
/** A row's draft parsed back into the value to write, or a reason it cannot be. */
|
|
20
|
+
export type ParsedValue =
|
|
21
|
+
| { ok: true; value: string | number | boolean | unknown[] | Record<string, unknown> }
|
|
22
|
+
| { ok: false; error: string };
|
|
23
|
+
|
|
24
|
+
/** Deep equality for JSON-safe values (arrays, records, scalars). */
|
|
25
|
+
export function valuesEqual(a: unknown, b: unknown): boolean {
|
|
26
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Render a stored value as the text its editor shows. */
|
|
30
|
+
export function valueToText(value: unknown): string {
|
|
31
|
+
if (value === undefined || value === null) return '';
|
|
32
|
+
if (Array.isArray(value) || typeof value === 'object') return JSON.stringify(value);
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Number-editor conversion: an incomplete or non-finite entry is not a value. */
|
|
37
|
+
export function parseFiniteNumber(raw: string): number | null {
|
|
38
|
+
const trimmed = raw.trim();
|
|
39
|
+
if (trimmed === '' || trimmed === '-' || trimmed === '+' || trimmed === '.') return null;
|
|
40
|
+
const parsed = Number(trimmed);
|
|
41
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Parse a JSON array; `null` when the text is not one. */
|
|
45
|
+
export function parseJsonArray(raw: string): unknown[] | null {
|
|
46
|
+
const trimmed = raw.trim();
|
|
47
|
+
if (trimmed === '') return [];
|
|
48
|
+
try {
|
|
49
|
+
const parsed: unknown = JSON.parse(trimmed);
|
|
50
|
+
return Array.isArray(parsed) ? parsed : null;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parse a JSON record; `null` when the text is not one. */
|
|
57
|
+
export function parseJsonRecord(raw: string): Record<string, unknown> | null {
|
|
58
|
+
const trimmed = raw.trim();
|
|
59
|
+
if (trimmed === '') return {};
|
|
60
|
+
try {
|
|
61
|
+
const parsed: unknown = JSON.parse(trimmed);
|
|
62
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
|
|
63
|
+
? (parsed as Record<string, unknown>)
|
|
64
|
+
: null;
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Interpret a draft for a text-editable row type.
|
|
72
|
+
*
|
|
73
|
+
* An empty number is "no value" rather than `NaN`; an empty string is a value
|
|
74
|
+
* (clearing a credential field is a real write); JSON text must parse to the
|
|
75
|
+
* shape the schema names.
|
|
76
|
+
*/
|
|
77
|
+
export function parseDraft(type: SchemaEntry['type'], raw: string): ParsedValue {
|
|
78
|
+
if (type === 'number') {
|
|
79
|
+
const parsed = parseFiniteNumber(raw);
|
|
80
|
+
return parsed === null
|
|
81
|
+
? { ok: false, error: 'A number is required, e.g. 1200.' }
|
|
82
|
+
: { ok: true, value: parsed };
|
|
83
|
+
}
|
|
84
|
+
if (type === 'array') {
|
|
85
|
+
const parsed = parseJsonArray(raw);
|
|
86
|
+
return parsed === null
|
|
87
|
+
? { ok: false, error: 'This key is a JSON array, e.g. ["anthropic","openai"].' }
|
|
88
|
+
: { ok: true, value: parsed };
|
|
89
|
+
}
|
|
90
|
+
if (type === 'record') {
|
|
91
|
+
const parsed = parseJsonRecord(raw);
|
|
92
|
+
return parsed === null
|
|
93
|
+
? { ok: false, error: 'This key is a JSON object, e.g. {"bash":"prompt"}.' }
|
|
94
|
+
: { ok: true, value: parsed };
|
|
95
|
+
}
|
|
96
|
+
return { ok: true, value: raw.trim() };
|
|
97
|
+
}
|