@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
|
@@ -214,15 +214,40 @@ export function surfaceTheme(): Extension {
|
|
|
214
214
|
backgroundColor: 'var(--editor-active-line, color-mix(in srgb, var(--theme-ink) 4%, transparent))',
|
|
215
215
|
color: 'var(--editor-fg, var(--theme-ink))',
|
|
216
216
|
},
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
217
|
+
// Whitespace marks (`whitespace.ts`): a dot per space and an arrow per tab,
|
|
218
|
+
// drawn only for characters the reader has SELECTED — VS Code's
|
|
219
|
+
// `renderWhitespace: 'selection'`. Nothing is painted for a bare caret.
|
|
220
|
+
//
|
|
221
|
+
// The ink is read from `--editor-fg`, NOT from `currentColor`: a mark that lands
|
|
222
|
+
// inside a Shiki token inherits that token's colour, so the dots in one line
|
|
223
|
+
// would come out in as many colours as the highlighting uses.
|
|
224
|
+
//
|
|
225
|
+
// The dot geometry is the package's own (`.4em`, centred at 55%): a dot wide
|
|
226
|
+
// enough to read at 8px would touch its neighbours at 24px. The tab draws an
|
|
227
|
+
// ARROW rather than a second dot, because one tab and a run of spaces are the
|
|
228
|
+
// same width and must not look alike. The arrow is a MASK, not a background
|
|
229
|
+
// image: an SVG in `url()` is its own document, so `currentColor` inside it
|
|
230
|
+
// resolves to black and the arrow would vanish in a dark theme.
|
|
231
|
+
'.cm-whitespace-space': {
|
|
232
|
+
background:
|
|
233
|
+
'radial-gradient(circle at 50% 55%, var(--editor-fg, var(--theme-ink)) 20%, transparent 0) no-repeat',
|
|
234
|
+
backgroundSize: '.4em',
|
|
235
|
+
backgroundPosition: 'calc(min(50%, 0px)) center',
|
|
236
|
+
opacity: '0.45',
|
|
237
|
+
},
|
|
238
|
+
'.cm-whitespace-tab': {
|
|
239
|
+
backgroundColor: 'var(--editor-fg, var(--theme-ink))',
|
|
240
|
+
maskImage:
|
|
241
|
+
"url('data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"200\" height=\"20\"><path stroke=\"%23000\" stroke-width=\"1\" fill=\"none\" d=\"M1 10H196L190 5M190 15L196 10M197 4L197 16\"/></svg>')",
|
|
242
|
+
WebkitMaskImage:
|
|
243
|
+
"url('data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"200\" height=\"20\"><path stroke=\"%23000\" stroke-width=\"1\" fill=\"none\" d=\"M1 10H196L190 5M190 15L196 10M197 4L197 16\"/></svg>')",
|
|
244
|
+
maskSize: 'auto 100%',
|
|
245
|
+
WebkitMaskSize: 'auto 100%',
|
|
246
|
+
maskPosition: 'right 90%',
|
|
247
|
+
WebkitMaskPosition: 'right 90%',
|
|
248
|
+
maskRepeat: 'no-repeat',
|
|
249
|
+
WebkitMaskRepeat: 'no-repeat',
|
|
250
|
+
opacity: '0.45',
|
|
226
251
|
},
|
|
227
252
|
// The line-blame label at the end of a run's first line.
|
|
228
253
|
//
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whitespace marks, through the REAL surface stack.
|
|
8
|
+
*
|
|
9
|
+
* Pins what makes this feature different from both alternatives, and each case
|
|
10
|
+
* is one a naive version gets wrong:
|
|
11
|
+
*
|
|
12
|
+
* - **A bare caret paints nothing.** The package's `highlightWhitespace()` marks
|
|
13
|
+
* every space in the viewport and a leading-run version marks every block's
|
|
14
|
+
* indentation; both look identical to this one as soon as text is selected,
|
|
15
|
+
* so the CARET case is the only one that tells them apart.
|
|
16
|
+
* - **Only the selected characters are marked**, so a selection that stops
|
|
17
|
+
* mid-line marks the part it covers and nothing past it.
|
|
18
|
+
* - **Collapsing the selection clears the marks.** They are a function of the
|
|
19
|
+
* selection, so a missing rebuild leaves the last painted set on screen.
|
|
20
|
+
*
|
|
21
|
+
* The marks exist only once a view mounts (a `ViewPlugin`), which is why every
|
|
22
|
+
* case here mounts one; `whitespaceDecorations` is also driven directly, so the
|
|
23
|
+
* rules are asserted without depending on the DOM.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
27
|
+
import { Window } from 'happy-dom';
|
|
28
|
+
import { Compartment, EditorState } from '@codemirror/state';
|
|
29
|
+
import { EditorView } from '@codemirror/view';
|
|
30
|
+
|
|
31
|
+
import { surfaceExtensions } from '@/client/components/common/code-surface/extensions';
|
|
32
|
+
import { whitespaceDecorations } from '@/client/components/common/code-surface/whitespace';
|
|
33
|
+
import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
|
|
34
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
35
|
+
|
|
36
|
+
const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame'] as const;
|
|
37
|
+
const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
|
|
38
|
+
|
|
39
|
+
let host: HTMLElement;
|
|
40
|
+
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
const win = new Window({ url: 'http://localhost' });
|
|
43
|
+
installDomGlobals(win);
|
|
44
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
45
|
+
for (const key of EXTRA_GLOBALS) {
|
|
46
|
+
native[key] = target[key];
|
|
47
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
48
|
+
}
|
|
49
|
+
host = document.body.appendChild(document.createElement('div'));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterAll(() => {
|
|
53
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
54
|
+
for (const key of EXTRA_GLOBALS) {
|
|
55
|
+
if (native[key] === undefined) delete target[key];
|
|
56
|
+
else target[key] = native[key];
|
|
57
|
+
}
|
|
58
|
+
restoreDomGlobals();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** The component's own stack, mounted at `selection` (offsets into `doc`). */
|
|
62
|
+
function mount(doc: string, selection?: { anchor: number; head: number }): EditorView {
|
|
63
|
+
return new EditorView({
|
|
64
|
+
parent: host,
|
|
65
|
+
state: EditorState.create({
|
|
66
|
+
doc,
|
|
67
|
+
selection,
|
|
68
|
+
extensions: surfaceExtensions({
|
|
69
|
+
language: 'typescript',
|
|
70
|
+
wordWrapCompartment: new Compartment(),
|
|
71
|
+
readOnlyCompartment: new Compartment(),
|
|
72
|
+
themeCompartment: new Compartment(),
|
|
73
|
+
languageCompartment: new Compartment(),
|
|
74
|
+
indentCompartment: new Compartment(),
|
|
75
|
+
typingCompartment: new Compartment(),
|
|
76
|
+
blameCompartment: new Compartment(),
|
|
77
|
+
blame: null,
|
|
78
|
+
indentUnitText: ' ',
|
|
79
|
+
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
80
|
+
wordWrap: false,
|
|
81
|
+
readOnly: false,
|
|
82
|
+
themes: SHIKI_THEMES,
|
|
83
|
+
onDocChange: () => {},
|
|
84
|
+
onState: () => {},
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The mark classes on each rendered line, in document order. */
|
|
91
|
+
function marksByLine(view: EditorView): Array<{ text: string; marks: string[] }> {
|
|
92
|
+
return Array.from(view.contentDOM.querySelectorAll('.cm-line')).map((line) => ({
|
|
93
|
+
text: line.textContent ?? '',
|
|
94
|
+
marks: Array.from(line.querySelectorAll('.cm-whitespace-space, .cm-whitespace-tab')).map((mark) => mark.className),
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Every marked range of a document, without mounting a view. */
|
|
99
|
+
function ranges(doc: string, selection?: { anchor: number; head: number }): Array<[number, number]> {
|
|
100
|
+
const state = EditorState.create({ doc, selection });
|
|
101
|
+
const out: Array<[number, number]> = [];
|
|
102
|
+
whitespaceDecorations(state).between(0, state.doc.length, (from, to) => {
|
|
103
|
+
out.push([from, to]);
|
|
104
|
+
});
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
describe('whitespace marks', () => {
|
|
109
|
+
test('a caret paints nothing, however much whitespace the file holds', () => {
|
|
110
|
+
const doc = 'function f() {\n const a = 1;\n}\n';
|
|
111
|
+
const view = mount(doc, { anchor: 0, head: 0 });
|
|
112
|
+
expect(marksByLine(view).flatMap((line) => line.marks)).toEqual([]);
|
|
113
|
+
// And the rule agrees without a view.
|
|
114
|
+
expect(ranges(doc)).toEqual([]);
|
|
115
|
+
view.destroy();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a selection marks every space it covers, indent and between tokens alike', () => {
|
|
119
|
+
const doc = 'function f() {\n const a = 1;\n}\n';
|
|
120
|
+
const lineFrom = doc.indexOf(' const');
|
|
121
|
+
const view = mount(doc, { anchor: lineFrom, head: lineFrom + ' const a = 1;'.length });
|
|
122
|
+
const block = marksByLine(view).find((line) => line.text === ' const a = 1;');
|
|
123
|
+
view.destroy();
|
|
124
|
+
|
|
125
|
+
// Four of indent plus the three between `const`, `a`, `=` and `1`: inside a
|
|
126
|
+
// selection, EVERY space is the point — that is what the reader is counting.
|
|
127
|
+
expect(block?.marks).toEqual(Array(7).fill('cm-whitespace-space'));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('a selection that stops mid-line marks only the part it covers', () => {
|
|
131
|
+
expect(ranges(' x\n', { anchor: 0, head: 2 })).toEqual([
|
|
132
|
+
[0, 1],
|
|
133
|
+
[1, 2],
|
|
134
|
+
]);
|
|
135
|
+
expect(ranges(' x\n', { anchor: 1, head: 3 })).toEqual([
|
|
136
|
+
[1, 2],
|
|
137
|
+
[2, 3],
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('a tab in the selection is one arrow, not the columns it measures', () => {
|
|
142
|
+
const view = mount('\tif (a) {\n', { anchor: 0, head: 6 });
|
|
143
|
+
expect(marksByLine(view)[0].marks).toEqual(['cm-whitespace-tab', 'cm-whitespace-space']);
|
|
144
|
+
view.destroy();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('a selection spanning several lines marks each covered line', () => {
|
|
148
|
+
const doc = ' a\n b\nc\n';
|
|
149
|
+
expect(ranges(doc, { anchor: 0, head: doc.length })).toEqual([
|
|
150
|
+
[0, 1],
|
|
151
|
+
[1, 2],
|
|
152
|
+
[4, 5],
|
|
153
|
+
[5, 6],
|
|
154
|
+
[6, 7],
|
|
155
|
+
[7, 8],
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('a selection ending in a line break does not reach the next line', () => {
|
|
160
|
+
// ` b` is fully covered; `c` starts at offset 9 and must not be touched.
|
|
161
|
+
const doc = ' a\n b\nc\n';
|
|
162
|
+
expect(ranges(doc, { anchor: 4, head: 9 })).toEqual([
|
|
163
|
+
[4, 5],
|
|
164
|
+
[5, 6],
|
|
165
|
+
[6, 7],
|
|
166
|
+
[7, 8],
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('collapsing the selection clears the marks instead of leaving them painted', () => {
|
|
171
|
+
const doc = ' a\n b\n';
|
|
172
|
+
const view = mount(doc, { anchor: 0, head: doc.length });
|
|
173
|
+
expect(marksByLine(view).flatMap((line) => line.marks).length).toBe(6);
|
|
174
|
+
|
|
175
|
+
view.dispatch({ selection: { anchor: 3, head: 3 } });
|
|
176
|
+
expect(marksByLine(view).flatMap((line) => line.marks)).toEqual([]);
|
|
177
|
+
view.destroy();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('the mark holds the character it replaces, so a copy keeps its whitespace', () => {
|
|
181
|
+
const view = mount(' x\n', { anchor: 0, head: 4 });
|
|
182
|
+
const mark = view.contentDOM.querySelector('.cm-whitespace-space');
|
|
183
|
+
expect(mark?.textContent).toBe(' ');
|
|
184
|
+
expect(view.contentDOM.querySelector('.cm-line')?.textContent).toBe(' x');
|
|
185
|
+
view.destroy();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('the window bounds the walk, so a whole-document selection is still cheap', () => {
|
|
189
|
+
// The window is the viewport in the plugin; here it stands in for one, and the
|
|
190
|
+
// answer must be the selection INTERSECTED with it — not the whole document.
|
|
191
|
+
const doc = ' a\n b\n c\n';
|
|
192
|
+
const state = EditorState.create({ doc, selection: { anchor: 0, head: doc.length } });
|
|
193
|
+
const out: Array<[number, number]> = [];
|
|
194
|
+
whitespaceDecorations(state, state.selection.ranges, { from: 4, to: 8 }).between(0, state.doc.length, (from, to) => {
|
|
195
|
+
out.push([from, to]);
|
|
196
|
+
});
|
|
197
|
+
// Line 2's two spaces; the newline at 7 and line 3 (from offset 8) are outside
|
|
198
|
+
// the window, so they cost nothing.
|
|
199
|
+
expect(out).toEqual([
|
|
200
|
+
[4, 5],
|
|
201
|
+
[5, 6],
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('whitespace theme', () => {
|
|
207
|
+
test('both marks paint from the surface ink, and no indent guide survives', () => {
|
|
208
|
+
const view = mount(' a\n', { anchor: 0, head: 3 });
|
|
209
|
+
const css = Array.from(document.head.querySelectorAll('style'))
|
|
210
|
+
.map((node) => node.textContent ?? '')
|
|
211
|
+
.join('\n');
|
|
212
|
+
view.destroy();
|
|
213
|
+
|
|
214
|
+
// The package's own `#aaa`/`#888` are chroma the palette does not own, and
|
|
215
|
+
// they disappear against a dark editor theme, so both marks restate the ink.
|
|
216
|
+
expect(css).toMatch(/\.cm-whitespace-space \{[^}]*var\(--editor-fg, var\(--theme-ink\)\)/);
|
|
217
|
+
expect(css).toMatch(/\.cm-whitespace-tab \{[^}]*var\(--editor-fg, var\(--theme-ink\)\)/);
|
|
218
|
+
// One dot per character box, which is what `.4em` with `no-repeat` gives.
|
|
219
|
+
expect(css).toMatch(/\.cm-whitespace-space \{[^}]*background-size: \.4em/);
|
|
220
|
+
// The per-level vertical rule is gone; the marks replaced it.
|
|
221
|
+
expect(css).not.toContain('.cm-indent-guide');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whitespace marks, drawn only where the text is SELECTED — VS Code's
|
|
8
|
+
* `editor.renderWhitespace: 'selection'`, its default.
|
|
9
|
+
*
|
|
10
|
+
* ## Why the selection, and not the document
|
|
11
|
+
*
|
|
12
|
+
* An always-on mark is a permanent dotted layer over every block in a file: it
|
|
13
|
+
* competes with the code it was meant to explain, and it answers a question
|
|
14
|
+
* nobody asked until they started caring about the bytes. Painting the marks on
|
|
15
|
+
* the selection answers it at the moment it is asked — a drag across a block, or
|
|
16
|
+
* `⇧⌘→` over a line — and leaves the rest of the document as code. The package's
|
|
17
|
+
* own `highlightWhitespace()` marks every space in the viewport; a leading-run
|
|
18
|
+
* version marks every block's indentation. Both were tried and both are noise.
|
|
19
|
+
*
|
|
20
|
+
* ## Two bounds keep it cheap
|
|
21
|
+
*
|
|
22
|
+
* - Only SELECTED characters are considered, so a caret (`empty` range) paints
|
|
23
|
+
* nothing — which is also what makes thousands of `⌘D` cursors free.
|
|
24
|
+
* - Only the selection's intersection with the VIEWPORT is walked, so `⌘A` on a
|
|
25
|
+
* 20 MB file costs the lines on screen rather than the document.
|
|
26
|
+
*
|
|
27
|
+
* ## It is NOT an indent guide
|
|
28
|
+
*
|
|
29
|
+
* Nothing here draws a vertical rule per nesting level — that feature was
|
|
30
|
+
* removed, because a column of rules read as structure the file does not have.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { EditorState, SelectionRange } from '@codemirror/state';
|
|
34
|
+
import { RangeSetBuilder } from '@codemirror/state';
|
|
35
|
+
import { Decoration, EditorView, ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
|
|
36
|
+
|
|
37
|
+
/** The two characters a mark is drawn for; a line break is not one of them. */
|
|
38
|
+
const KINDS = {
|
|
39
|
+
' ': Decoration.mark({ class: 'cm-whitespace-space' }),
|
|
40
|
+
'\t': Decoration.mark({ class: 'cm-whitespace-tab' }),
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
type WhitespaceChar = keyof typeof KINDS;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Marks every space and tab in `[from, to)`.
|
|
47
|
+
*
|
|
48
|
+
* One mark per CHARACTER, not per run: a mark's box is what the CSS paints, and
|
|
49
|
+
* a single span over four spaces can hold only one dot (`no-repeat` at `.4em`).
|
|
50
|
+
* Per-character ranges are what make four spaces draw four dots.
|
|
51
|
+
*/
|
|
52
|
+
function addSlice(state: EditorState, from: number, to: number, builder: RangeSetBuilder<Decoration>): void {
|
|
53
|
+
let line = state.doc.lineAt(from);
|
|
54
|
+
for (;;) {
|
|
55
|
+
const start = Math.max(from, line.from);
|
|
56
|
+
const end = Math.min(to, line.to);
|
|
57
|
+
for (let offset = start; offset < end; offset++) {
|
|
58
|
+
const kind = line.text[offset - line.from] as WhitespaceChar;
|
|
59
|
+
// Anything else — a newline, or the file's content — is not a mark.
|
|
60
|
+
if (kind === ' ' || kind === '\t') builder.add(offset, offset + 1, KINDS[kind]);
|
|
61
|
+
}
|
|
62
|
+
if (line.to >= to || line.to >= state.doc.length) break;
|
|
63
|
+
line = state.doc.lineAt(line.to + 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The marks for one selection range, clipped to the window `[windowFrom, windowTo)`.
|
|
69
|
+
*
|
|
70
|
+
* The clip is the viewport, which is the bound that makes a whole-document
|
|
71
|
+
* selection cheap: a mark outside the rendered lines could not be seen.
|
|
72
|
+
*/
|
|
73
|
+
function addRange(
|
|
74
|
+
state: EditorState,
|
|
75
|
+
range: SelectionRange,
|
|
76
|
+
windowFrom: number,
|
|
77
|
+
windowTo: number,
|
|
78
|
+
builder: RangeSetBuilder<Decoration>,
|
|
79
|
+
): void {
|
|
80
|
+
const from = Math.max(range.from, windowFrom);
|
|
81
|
+
const to = Math.min(range.to, windowTo);
|
|
82
|
+
// A caret, or a selection entirely outside the window: nothing to paint.
|
|
83
|
+
if (from >= to) return;
|
|
84
|
+
addSlice(state, from, to, builder);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The whitespace marks for `ranges`, in document order.
|
|
89
|
+
*
|
|
90
|
+
* `window` defaults to the whole document, which is what a caller that has no
|
|
91
|
+
* view (a test) wants; the plugin passes its viewport, because that is the only
|
|
92
|
+
* part of a selection that can be seen.
|
|
93
|
+
*/
|
|
94
|
+
export function whitespaceDecorations(
|
|
95
|
+
state: EditorState,
|
|
96
|
+
ranges: readonly SelectionRange[] = state.selection.ranges,
|
|
97
|
+
window: { from: number; to: number } = { from: 0, to: state.doc.length },
|
|
98
|
+
): DecorationSet {
|
|
99
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
100
|
+
for (const range of ranges) {
|
|
101
|
+
// CodeMirror keeps selection ranges ascending, and the window is one span,
|
|
102
|
+
// so appending as we go yields a sorted set.
|
|
103
|
+
addRange(state, range, window.from, window.to, builder);
|
|
104
|
+
}
|
|
105
|
+
return builder.finish();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The whitespace marks, as a view plugin.
|
|
110
|
+
*
|
|
111
|
+
* Rebuilt on a SELECTION change as well as on an edit or a scroll: the marks are
|
|
112
|
+
* a function of the selection AND of what is rendered, so collapsing the
|
|
113
|
+
* selection is what removes them and scrolling is what produces them elsewhere.
|
|
114
|
+
*/
|
|
115
|
+
export const whitespaceMarks = ViewPlugin.fromClass(
|
|
116
|
+
class {
|
|
117
|
+
decorations: DecorationSet;
|
|
118
|
+
|
|
119
|
+
constructor(view: EditorView) {
|
|
120
|
+
this.decorations = this.build(view);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
update(update: ViewUpdate) {
|
|
124
|
+
if (update.docChanged || update.selectionSet || update.viewportChanged) {
|
|
125
|
+
this.decorations = this.build(update.view);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private build(view: EditorView): DecorationSet {
|
|
130
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
131
|
+
for (const { from, to } of view.visibleRanges) {
|
|
132
|
+
for (const range of view.state.selection.ranges) {
|
|
133
|
+
if (!range.empty) addRange(view.state, range, from, to, builder);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return builder.finish();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{ decorations: (plugin) => plugin.decorations },
|
|
140
|
+
);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The judge panel: two answers, one note.
|
|
8
|
+
*
|
|
9
|
+
* Fixed at the rectangle the click reported rather than tracking its block. A
|
|
10
|
+
* rendered document rehydrates (mermaid, math, directives) and every hydrate
|
|
11
|
+
* moves blocks, so anything that measured once and followed would drift away
|
|
12
|
+
* from what it describes; a scroll closes it instead, which is also the moment
|
|
13
|
+
* the block under it is no longer where the user is looking.
|
|
14
|
+
*
|
|
15
|
+
* The two answers are `aria-pressed` buttons, not a radio or a checkbox: the
|
|
16
|
+
* pressed state IS the judgement, and a screen reader has to hear which one it
|
|
17
|
+
* is without counting options.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
21
|
+
import { Check, X } from 'lucide-preact';
|
|
22
|
+
|
|
23
|
+
import type { BlockVerdict, MdBlock } from '@/shared/lib/markdown/blocks/types';
|
|
24
|
+
import { ACTION_CLASS } from '@/client/components/workspace/editor/toolbar-toggle';
|
|
25
|
+
|
|
26
|
+
interface ReviewPopoverProps {
|
|
27
|
+
block: MdBlock;
|
|
28
|
+
verdict: BlockVerdict | null;
|
|
29
|
+
note: string;
|
|
30
|
+
anchor: { top: number; left: number };
|
|
31
|
+
onSave: (verdict: BlockVerdict, note: string) => void;
|
|
32
|
+
onRemove: () => void;
|
|
33
|
+
onClose: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function rangeOf(block: MdBlock): string {
|
|
37
|
+
return block.lineStart === block.lineEnd ? `L${block.lineStart}` : `L${block.lineStart}-${block.lineEnd}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function ReviewPopover({ block, verdict, note, anchor, onSave, onRemove, onClose }: ReviewPopoverProps) {
|
|
41
|
+
// The whole panel is one form, so the draft lives in the DOM rather than in
|
|
42
|
+
// state: two saves of the same block would otherwise need a re-seed effect,
|
|
43
|
+
// and the `key` on this element already re-mounts it per block.
|
|
44
|
+
const form = useRef<HTMLDivElement | null>(null);
|
|
45
|
+
const field = useRef<HTMLTextAreaElement | null>(null);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
field.current?.focus();
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const onKey = (event: KeyboardEvent) => {
|
|
53
|
+
if (event.key !== 'Escape') return;
|
|
54
|
+
// `stopPropagation`, not `preventDefault`: Escape is also the panel's own
|
|
55
|
+
// chord for closing the find bar, and the innermost scope must win.
|
|
56
|
+
event.stopPropagation();
|
|
57
|
+
onClose();
|
|
58
|
+
};
|
|
59
|
+
// Capture, so the panel's own keydown handler cannot consume it first.
|
|
60
|
+
window.addEventListener('keydown', onKey, true);
|
|
61
|
+
return () => window.removeEventListener('keydown', onKey, true);
|
|
62
|
+
}, [onClose]);
|
|
63
|
+
|
|
64
|
+
const submit = (chosen: BlockVerdict) => onSave(chosen, field.current?.value ?? note);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div
|
|
68
|
+
ref={form}
|
|
69
|
+
role="dialog"
|
|
70
|
+
aria-label={`Review block ${rangeOf(block)}`}
|
|
71
|
+
// `fixed`, from the click's own rectangle — see the module note.
|
|
72
|
+
style={{ top: `${anchor.top}px`, left: `${anchor.left}px` }}
|
|
73
|
+
className="fixed z-[65] w-[min(24rem,calc(100vw-2rem))] rounded-md border border-ink/15 bg-paper shadow-lg p-2 font-sans text-[11.5px] text-ink"
|
|
74
|
+
onClick={(event) => event.stopPropagation()}
|
|
75
|
+
>
|
|
76
|
+
<div className="flex items-center gap-1.5 text-[10.5px] font-mono text-ink/50">
|
|
77
|
+
<span>{rangeOf(block)}</span>
|
|
78
|
+
<span className="truncate">«{block.quote}»</span>
|
|
79
|
+
<button
|
|
80
|
+
type="button"
|
|
81
|
+
onClick={onClose}
|
|
82
|
+
className="ml-auto cursor-pointer text-ink/50 hover:text-ink"
|
|
83
|
+
aria-label="Close review"
|
|
84
|
+
>
|
|
85
|
+
<X size={12} />
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<div className="mt-1.5 flex items-center gap-1.5">
|
|
90
|
+
<button
|
|
91
|
+
type="button"
|
|
92
|
+
aria-pressed={verdict === 'good'}
|
|
93
|
+
title="This block is good — do not change it"
|
|
94
|
+
onClick={() => submit('good')}
|
|
95
|
+
className={`${ACTION_CLASS} border px-2 text-[11px] ${
|
|
96
|
+
verdict === 'good' ? 'border-ink bg-ink/10 text-ink' : 'border-ink/15 text-ink/70 hover:border-ink/40'
|
|
97
|
+
}`}
|
|
98
|
+
>
|
|
99
|
+
<Check size={11} /> Good
|
|
100
|
+
</button>
|
|
101
|
+
<button
|
|
102
|
+
type="button"
|
|
103
|
+
aria-pressed={verdict === 'needs-work'}
|
|
104
|
+
title="This block needs work"
|
|
105
|
+
onClick={() => submit('needs-work')}
|
|
106
|
+
className={`${ACTION_CLASS} border px-2 text-[11px] ${
|
|
107
|
+
verdict === 'needs-work' ? 'border-error bg-error/10 text-error' : 'border-ink/15 text-ink/70 hover:border-ink/40'
|
|
108
|
+
}`}
|
|
109
|
+
>
|
|
110
|
+
<X size={11} /> Needs work
|
|
111
|
+
</button>
|
|
112
|
+
{verdict && (
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
onClick={onRemove}
|
|
116
|
+
className={`${ACTION_CLASS} ml-auto border border-ink/15 px-2 text-[11px] text-ink/60 hover:text-error`}
|
|
117
|
+
>
|
|
118
|
+
Remove
|
|
119
|
+
</button>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<textarea
|
|
124
|
+
ref={field}
|
|
125
|
+
defaultValue={note}
|
|
126
|
+
rows={3}
|
|
127
|
+
placeholder="What is wrong — or what is right — with this block…"
|
|
128
|
+
onKeyDown={(event) => {
|
|
129
|
+
// ⌘↵ saves the CURRENT verdict; a block with none is not saved by a
|
|
130
|
+
// keystroke that cannot say which answer it means.
|
|
131
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && verdict) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
submit(verdict);
|
|
134
|
+
}
|
|
135
|
+
}}
|
|
136
|
+
className="mt-1.5 w-full resize-y rounded border border-ink/15 bg-canvas/40 px-2 py-1 text-[11px] font-sans outline-none focus:border-ink"
|
|
137
|
+
/>
|
|
138
|
+
|
|
139
|
+
<div className="mt-1 flex items-center gap-1.5 text-[10.5px] text-ink/45">
|
|
140
|
+
<span>Click an answer to save · ⌘↵ keeps the note with it</span>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The review's totals, the way out, and the marks that no longer fit.
|
|
8
|
+
*
|
|
9
|
+
* Two rules this bar exists to keep:
|
|
10
|
+
*
|
|
11
|
+
* - **An outdated mark is SHOWN.** Its block was edited, so it matches nothing
|
|
12
|
+
* rendered — but the note is still the user's and the only copy of it.
|
|
13
|
+
* Dropping it silently is the one thing a review tool must never do, so it is
|
|
14
|
+
* listed with its stored quote and a Remove of its own.
|
|
15
|
+
* - **Sending is a prefill.** The button says "to the chat box": it writes the
|
|
16
|
+
* draft and focuses the composer. A review the user never read before it
|
|
17
|
+
* reached the agent is how a wrong note becomes an instruction.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Send, X } from 'lucide-preact';
|
|
21
|
+
|
|
22
|
+
import type { DocumentAnnotation } from '@/shared/lib/markdown/blocks/types';
|
|
23
|
+
|
|
24
|
+
interface ReviewSummaryProps {
|
|
25
|
+
counts: { good: number; needsWork: number };
|
|
26
|
+
outdated: readonly DocumentAnnotation[];
|
|
27
|
+
error: string | null;
|
|
28
|
+
/** True once the block reached the composer, so the bar can say so. */
|
|
29
|
+
sent: boolean;
|
|
30
|
+
onSend: () => void;
|
|
31
|
+
onRemoveOutdated: (id: string) => void;
|
|
32
|
+
onExit: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function rangeOf(annotation: DocumentAnnotation): string {
|
|
36
|
+
return annotation.lineStart === annotation.lineEnd
|
|
37
|
+
? `L${annotation.lineStart}`
|
|
38
|
+
: `L${annotation.lineStart}-${annotation.lineEnd}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ReviewSummary({ counts, outdated, error, sent, onSend, onRemoveOutdated, onExit }: ReviewSummaryProps) {
|
|
42
|
+
const total = counts.good + counts.needsWork;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="sticky bottom-0 z-40 mt-2 border-t border-ink/10 bg-paper/95 px-1 py-2 backdrop-blur">
|
|
46
|
+
{outdated.length > 0 && (
|
|
47
|
+
<div className="mb-1.5 space-y-1">
|
|
48
|
+
<div className="text-[10px] uppercase font-mono text-ink/40">
|
|
49
|
+
{outdated.length} outdated — the block was edited or is no longer rendered
|
|
50
|
+
</div>
|
|
51
|
+
{outdated.map((annotation) => (
|
|
52
|
+
<div key={annotation.id} className="flex items-start gap-1.5 text-[11px] text-ink/60">
|
|
53
|
+
<span className="font-mono text-[10.5px] text-ink/40">{rangeOf(annotation)}</span>
|
|
54
|
+
{/* Both halves, because they say different things: the QUOTE is
|
|
55
|
+
the block this note was written about, the NOTE is what the
|
|
56
|
+
user said about it — and the note is the reason the row is
|
|
57
|
+
worth keeping at all. */}
|
|
58
|
+
<span className="min-w-0 flex-1">
|
|
59
|
+
<span className="block truncate text-ink/45">{annotation.quote || '(block text unavailable)'}</span>
|
|
60
|
+
{annotation.note.trim() && <span className="block truncate text-ink/70">{annotation.note}</span>}
|
|
61
|
+
</span>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
onClick={() => onRemoveOutdated(annotation.id)}
|
|
65
|
+
className="cursor-pointer text-ink/40 hover:text-error"
|
|
66
|
+
aria-label={`Remove outdated annotation at ${rangeOf(annotation)}`}
|
|
67
|
+
>
|
|
68
|
+
<X size={11} />
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
))}
|
|
72
|
+
</div>
|
|
73
|
+
)}
|
|
74
|
+
|
|
75
|
+
{error && (
|
|
76
|
+
<div role="alert" className="mb-1.5 text-[11px] text-error">
|
|
77
|
+
{error}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
|
|
81
|
+
<div className="flex items-center gap-2 font-sans text-[11px]">
|
|
82
|
+
<span className="text-ink/70">
|
|
83
|
+
<span className="text-ink">{counts.good}</span> good ·{' '}
|
|
84
|
+
<span className="text-error">{counts.needsWork}</span> needs work
|
|
85
|
+
</span>
|
|
86
|
+
{sent && <span className="text-ink/50">Added to the chat box</span>}
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
onClick={onExit}
|
|
90
|
+
className="ml-auto cursor-pointer p-1 text-ink/50 hover:text-ink"
|
|
91
|
+
title="Exit review mode"
|
|
92
|
+
aria-label="Exit review mode"
|
|
93
|
+
>
|
|
94
|
+
<X size={13} />
|
|
95
|
+
</button>
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
disabled={total === 0}
|
|
99
|
+
onClick={onSend}
|
|
100
|
+
title="Put this review into the chat box — you still choose to send it"
|
|
101
|
+
className="flex items-center gap-1 rounded border border-ink bg-ink px-2 py-1 text-canvas transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"
|
|
102
|
+
>
|
|
103
|
+
<Send size={11} /> Send to chat
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|