@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
|
@@ -62,6 +62,90 @@ function foldNode(node: FsNode): FsNode {
|
|
|
62
62
|
return current;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Whether this row is a folded chain — one row standing for several directories.
|
|
67
|
+
*
|
|
68
|
+
* Decided by the LABEL alone, and that is load-bearing in both directions: a
|
|
69
|
+
* directory name cannot contain a separator, so a `/` in a folder's `name` can
|
|
70
|
+
* only come from the fold. Comparing `name` with `path` does not work, because a
|
|
71
|
+
* chain folded at the listing's own root is labelled with the whole path
|
|
72
|
+
* (`name === path === 'dev/src/main/code'`) while still standing for four
|
|
73
|
+
* directories — every surface that asks "does this row hide levels?" (drop
|
|
74
|
+
* targets, the rename and delete dialogs, the unfold menu row) reads this one
|
|
75
|
+
* answer, so they cannot disagree about the same row.
|
|
76
|
+
*/
|
|
77
|
+
export function isChainRow(node: { type: 'file' | 'folder'; name: string }): boolean {
|
|
78
|
+
return node.type === 'folder' && node.name.includes('/');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The paths of the directories a collapsed row STANDS FOR, outermost first —
|
|
83
|
+
* or null when the row's label does not name a chain.
|
|
84
|
+
*
|
|
85
|
+
* The fold is a RENDERING decision, not a filesystem fact, and it hides
|
|
86
|
+
* destinations: `dev/src/main` is not a row, so it cannot be dropped on,
|
|
87
|
+
* renamed, or created inside — a drop on the one row lands in the deepest
|
|
88
|
+
* directory (`code`) instead. The panel keeps a set of chains the user asked to
|
|
89
|
+
* unfold and projects it onto the tree the listing hands over
|
|
90
|
+
* (`unfoldChains`), and this is the one place that turns the row's LABEL
|
|
91
|
+
* (`dev/src/main/code`) plus its `path` (the deepest directory) back into the
|
|
92
|
+
* levels between them.
|
|
93
|
+
*/
|
|
94
|
+
export function chainLevelPaths(path: string, label: string): string[] | null {
|
|
95
|
+
const names = label.split('/');
|
|
96
|
+
const segments = path.split('/');
|
|
97
|
+
if (names.length < 2 || names.length > segments.length || names.some((name) => !name)) return null;
|
|
98
|
+
const outer = segments.slice(0, segments.length - names.length);
|
|
99
|
+
return names.map((_, index) => [...outer, ...names.slice(0, index + 1)].join('/'));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Drawn rows with the chains named in `unfolded` split back into one row per
|
|
104
|
+
* directory, so every level of a folded chain becomes a real drop target, a
|
|
105
|
+
* real rename target and a real place to create something.
|
|
106
|
+
*
|
|
107
|
+
* The deepest row keeps its own `children` — and therefore its own read — so
|
|
108
|
+
* unfolding a chain never costs a request. Whether the intermediate rows are
|
|
109
|
+
* DRAWN open is the panel's business, not this projection's: they are ordinary
|
|
110
|
+
* rows, opened through the panel's expansion set like any other folder.
|
|
111
|
+
*/
|
|
112
|
+
export function unfoldChains(nodes: FsNode[], unfolded: ReadonlySet<string>): {
|
|
113
|
+
nodes: FsNode[];
|
|
114
|
+
/** The outermost level of each chain that was actually unfolded → its deepest path. */
|
|
115
|
+
roots: Map<string, string>;
|
|
116
|
+
} {
|
|
117
|
+
const roots = new Map<string, string>();
|
|
118
|
+
if (unfolded.size === 0) return { nodes, roots };
|
|
119
|
+
let changed = false;
|
|
120
|
+
const walk = (list: FsNode[]): FsNode[] => list.flatMap((node) => {
|
|
121
|
+
if (node.type !== 'folder') return [node];
|
|
122
|
+
const children = Array.isArray(node.children) ? walk(node.children) : node.children;
|
|
123
|
+
const row: FsNode = children === node.children ? node : { ...node, children };
|
|
124
|
+
const levels = unfolded.has(node.path) ? chainLevelPaths(node.path, node.name) : null;
|
|
125
|
+
if (!levels) return [row];
|
|
126
|
+
changed = true;
|
|
127
|
+
roots.set(levels[0]!, node.path);
|
|
128
|
+
// Rebuilt from the outside in, so the deepest row is the original one —
|
|
129
|
+
// its children, its expansion state and its git answer all stay attached.
|
|
130
|
+
let deepest: FsNode = { ...row, name: levels[levels.length - 1]!.split('/').pop()! };
|
|
131
|
+
for (let depth = levels.length - 1; depth > 0; depth -= 1) {
|
|
132
|
+
const path = levels[depth - 1]!;
|
|
133
|
+
deepest = {
|
|
134
|
+
name: path.split('/').pop()!,
|
|
135
|
+
path,
|
|
136
|
+
type: 'folder',
|
|
137
|
+
// A rule matching any level of the chain answers for the deepest too
|
|
138
|
+
// (see `foldNode`), so every level wears the row's own answer.
|
|
139
|
+
ignored: row.ignored,
|
|
140
|
+
children: [deepest],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return [deepest];
|
|
144
|
+
});
|
|
145
|
+
const next = walk(nodes);
|
|
146
|
+
return { nodes: changed ? next : nodes, roots };
|
|
147
|
+
}
|
|
148
|
+
|
|
65
149
|
/**
|
|
66
150
|
* The paths of the DRAWN rows that contain `path`, outermost first.
|
|
67
151
|
*
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The identity of a block: its type, a digest of its text, and an ordinal.
|
|
8
|
+
*
|
|
9
|
+
* ## Why not a line number
|
|
10
|
+
*
|
|
11
|
+
* A line is where a block HAPPENS to be. Inserting one paragraph above it moves
|
|
12
|
+
* every block below, and a note keyed by line would then describe the wrong
|
|
13
|
+
* text — the failure that makes reviews untrustworthy.
|
|
14
|
+
*
|
|
15
|
+
* ## Why not a cryptographic digest
|
|
16
|
+
*
|
|
17
|
+
* This module is imported by `src/shared/**`, which also runs in the browser,
|
|
18
|
+
* so `Bun.CryptoHasher` is unavailable and `crypto.subtle` is async (a render
|
|
19
|
+
* path cannot await). FNV-1a over UTF-16 code units is synchronous, allocation
|
|
20
|
+
* free, and more than strong enough: the ordinal below settles the only
|
|
21
|
+
* collisions that matter.
|
|
22
|
+
*
|
|
23
|
+
* ## What the ordinal settles
|
|
24
|
+
*
|
|
25
|
+
* Two identical blocks (a repeated `## Notes`, two identical list items) hash
|
|
26
|
+
* the same, so the Nth occurrence is part of the key. Reordering them swaps
|
|
27
|
+
* their identities, which is correct — they are indistinguishable.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Whitespace is not content: a reflow is not an edit. */
|
|
31
|
+
export function normalizeBlockText(text: string): string {
|
|
32
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** FNV-1a, 32-bit, hex. Deterministic and dependency-free. */
|
|
36
|
+
export function hashBlockText(text: string): string {
|
|
37
|
+
let hash = 0x811c9dc5;
|
|
38
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
39
|
+
hash ^= text.charCodeAt(index);
|
|
40
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
41
|
+
}
|
|
42
|
+
return hash.toString(16).padStart(8, '0');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The key for one block, given the blocks already emitted for the document.
|
|
47
|
+
*
|
|
48
|
+
* `seen` is mutated (the occurrence count moves), because the caller walks the
|
|
49
|
+
* document once and each duplicate needs the next ordinal.
|
|
50
|
+
*/
|
|
51
|
+
export function blockKeyOf(type: string, raw: string, seen: Map<string, number>): string {
|
|
52
|
+
const base = `${type}:${hashBlockText(normalizeBlockText(raw))}`;
|
|
53
|
+
const occurrence = (seen.get(base) ?? 0) + 1;
|
|
54
|
+
seen.set(base, occurrence);
|
|
55
|
+
return `${base}#${occurrence}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The block text a reviewer (and the prompt) sees: one line, bounded. */
|
|
59
|
+
export function quoteOf(raw: string, limit = 160): string {
|
|
60
|
+
const collapsed = normalizeBlockText(raw);
|
|
61
|
+
if (collapsed.length <= limit) return collapsed;
|
|
62
|
+
return `${collapsed.slice(0, Math.max(0, limit - 1))}…`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The block map: what a rendered document says its blocks ARE.
|
|
8
|
+
*
|
|
9
|
+
* The properties here are the ones the review feature rests on, and each was
|
|
10
|
+
* measured before it was written down:
|
|
11
|
+
*
|
|
12
|
+
* - `raw` partitions the source exactly, so accumulating line counts names the
|
|
13
|
+
* real line of every block (a leading blank line, front-matter, a document
|
|
14
|
+
* with no trailing newline and one with `$$…$$` were all checked).
|
|
15
|
+
* - The identity is content-derived, so inserting a paragraph above every block
|
|
16
|
+
* leaves every key untouched, and editing a block's own text is the ONLY thing
|
|
17
|
+
* that changes one.
|
|
18
|
+
* - The mapped render adds attributes and nothing else: strip them and the HTML
|
|
19
|
+
* is byte-identical to `renderMarkdown`, including the copy button, the table
|
|
20
|
+
* scroller and the directive/mermaid placeholders.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { describe, expect, test } from 'bun:test';
|
|
24
|
+
|
|
25
|
+
import { renderMarkdown, renderMappedMarkdown } from '@/shared/lib/markdown/marked';
|
|
26
|
+
import { blockKeyOf, hashBlockText, normalizeBlockText, quoteOf } from '@/shared/lib/markdown/blocks/anchor';
|
|
27
|
+
|
|
28
|
+
const stripAttributes = (html: string): string => html.replace(/ data-md-(?:block|start|end)="[^"]*"/g, '');
|
|
29
|
+
|
|
30
|
+
const CORPUS = [
|
|
31
|
+
'# Heading',
|
|
32
|
+
'',
|
|
33
|
+
'Paragraph with **bold**, `code` and a [link](a.md).',
|
|
34
|
+
'',
|
|
35
|
+
'> quote line',
|
|
36
|
+
'> second',
|
|
37
|
+
'',
|
|
38
|
+
'- one',
|
|
39
|
+
'- two',
|
|
40
|
+
'',
|
|
41
|
+
'```ts',
|
|
42
|
+
'const a = 1;',
|
|
43
|
+
'```',
|
|
44
|
+
'',
|
|
45
|
+
'| a | b |',
|
|
46
|
+
'| - | - |',
|
|
47
|
+
'| 1 | 2 |',
|
|
48
|
+
'',
|
|
49
|
+
'---',
|
|
50
|
+
'',
|
|
51
|
+
'$$y = 1$$',
|
|
52
|
+
'',
|
|
53
|
+
'End.',
|
|
54
|
+
].join('\n');
|
|
55
|
+
|
|
56
|
+
describe('the block map', () => {
|
|
57
|
+
test('every top-level block carries its identity and its source lines', () => {
|
|
58
|
+
const { blocks } = renderMappedMarkdown(CORPUS, { allowHtml: true });
|
|
59
|
+
expect(blocks.map((block) => block.type)).toEqual([
|
|
60
|
+
'heading',
|
|
61
|
+
'paragraph',
|
|
62
|
+
'blockquote',
|
|
63
|
+
'list',
|
|
64
|
+
'code',
|
|
65
|
+
'table',
|
|
66
|
+
'hr',
|
|
67
|
+
'blockMathDisplay',
|
|
68
|
+
'paragraph',
|
|
69
|
+
]);
|
|
70
|
+
// The heading is line 1; the paragraph that follows the blank line is line 3.
|
|
71
|
+
expect(blocks[0]).toMatchObject({ lineStart: 1, lineEnd: 1 });
|
|
72
|
+
expect(blocks[1]).toMatchObject({ lineStart: 3, lineEnd: 3 });
|
|
73
|
+
// A fenced block spans its fence and body, and its trailing newline is the
|
|
74
|
+
// separator rather than a line of its own.
|
|
75
|
+
expect(blocks[4]).toMatchObject({ lineStart: 11, lineEnd: 13 });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a block map that misses a rendered block would be a silent hole', () => {
|
|
79
|
+
const { html, blocks } = renderMappedMarkdown(CORPUS, { allowHtml: true });
|
|
80
|
+
// Every block the map names must exist in the DOM, and vice versa. This is
|
|
81
|
+
// the test that fails when a new block kind (or a `marked` rename) slips past
|
|
82
|
+
// `BLOCK_RENDERERS`.
|
|
83
|
+
const rendered = (html.match(/data-md-block=/g) ?? []).length;
|
|
84
|
+
expect(rendered).toBe(blocks.length);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('the mapped render changes nothing but the attributes', () => {
|
|
88
|
+
const plain = renderMarkdown(CORPUS, { allowHtml: true });
|
|
89
|
+
const mapped = renderMappedMarkdown(CORPUS, { allowHtml: true });
|
|
90
|
+
expect(stripAttributes(mapped.html)).toBe(plain);
|
|
91
|
+
// The overrides `marked.ts` installs must survive the mapper: it captures the
|
|
92
|
+
// renderer table at registration, so wrapping too early would drop them.
|
|
93
|
+
expect(mapped.html).toContain('code-copy-float');
|
|
94
|
+
expect(mapped.html).toContain('md-table-scroll');
|
|
95
|
+
expect(mapped.html).toContain('math-pending');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('the chat path stays byte-identical while the mapper is registered', () => {
|
|
99
|
+
const first = renderMarkdown('# T\n\npara\n');
|
|
100
|
+
const again = renderMarkdown('# T\n\npara\n');
|
|
101
|
+
expect(again).toBe(first);
|
|
102
|
+
expect(first).not.toContain('data-md-block');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('block identity', () => {
|
|
107
|
+
test('an edit above a block does not change its key; its own text does', () => {
|
|
108
|
+
const before = renderMappedMarkdown('# A\n\nfirst\n\nsecond\n', { allowHtml: true }).blocks;
|
|
109
|
+
const after = renderMappedMarkdown('# A\n\ninserted\n\nfirst\n\nsecond\n', { allowHtml: true }).blocks;
|
|
110
|
+
const keysBefore = new Set(before.map((block) => block.key));
|
|
111
|
+
// Every original block is still matched by its own key, except the one whose
|
|
112
|
+
// position the new paragraph took: its text is the same, so its key is the
|
|
113
|
+
// same too. Insertion is not an edit.
|
|
114
|
+
for (const key of keysBefore) expect(after.some((block) => block.key === key)).toBe(true);
|
|
115
|
+
|
|
116
|
+
const edited = renderMappedMarkdown('# A\n\nfirst\n\nsecond changed\n', { allowHtml: true }).blocks;
|
|
117
|
+
const lost = before.filter((block) => !edited.some((next) => next.key === block.key));
|
|
118
|
+
expect(lost.map((block) => block.quote)).toEqual(['second']);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('a reflow is not an edit, because whitespace is normalized', () => {
|
|
122
|
+
const one = renderMappedMarkdown('a single line\n', { allowHtml: true }).blocks[0];
|
|
123
|
+
const two = renderMappedMarkdown('a single\nline\n', { allowHtml: true }).blocks[0];
|
|
124
|
+
expect(two.key).toBe(one.key);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('two identical blocks are told apart by their ordinal', () => {
|
|
128
|
+
const seen = new Map<string, number>();
|
|
129
|
+
expect(blockKeyOf('paragraph', 'same', seen)).toBe('paragraph:' + hashBlockText('same') + '#1');
|
|
130
|
+
expect(blockKeyOf('paragraph', 'same', seen)).toBe('paragraph:' + hashBlockText('same') + '#2');
|
|
131
|
+
// A different TYPE with the same text is a different block.
|
|
132
|
+
expect(blockKeyOf('heading', 'same', seen).endsWith('#1')).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('the quote is one line and bounded', () => {
|
|
136
|
+
expect(normalizeBlockText(' a\n\n b ')).toBe('a b');
|
|
137
|
+
const long = quoteOf('x'.repeat(400));
|
|
138
|
+
expect(long.length).toBe(160);
|
|
139
|
+
expect(long.endsWith('…')).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Put the block identity on the rendered markup, and nowhere else.
|
|
8
|
+
*
|
|
9
|
+
* The attributes go on the OUTERMOST element of each block, which is what makes
|
|
10
|
+
* this compose with the wrappers `marked.ts` already emits for code blocks,
|
|
11
|
+
* tables and math placeholders: the hydrators (`hydrateMermaidBlocks`,
|
|
12
|
+
* `hydrateMathBlocks`, `hydrateDirectiveBlocks`) rewrite grandchildren, so a
|
|
13
|
+
* reviewer's attributes on the wrapper survive every hydrate and every theme
|
|
14
|
+
* repaint.
|
|
15
|
+
*
|
|
16
|
+
* ## Registration order is part of the contract
|
|
17
|
+
*
|
|
18
|
+
* `registerBlockMapper` captures the renderer as it stands. It MUST run after
|
|
19
|
+
* every `marked.use({ renderer })` in `marked.ts`, or it captures the
|
|
20
|
+
* un-overridden `code`/`table` and every previewed document silently loses its
|
|
21
|
+
* copy buttons and its table scroller. The capture is also what keeps the
|
|
22
|
+
* chat path byte-identical: a token with no tag renders exactly as before.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { Token } from 'marked';
|
|
26
|
+
|
|
27
|
+
import { BLOCK_ATTRIBUTE, type BlockToken } from '@/shared/lib/markdown/blocks/scan';
|
|
28
|
+
import type { MdBlock } from '@/shared/lib/markdown/blocks/types';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The block-level renderers that own a top-level token.
|
|
32
|
+
*
|
|
33
|
+
* A name missing here is a block nobody can annotate, so `registerBlockMapper`
|
|
34
|
+
* refuses to register instead of skipping it: a `marked` upgrade that renames
|
|
35
|
+
* one must fail loudly.
|
|
36
|
+
*/
|
|
37
|
+
export const BLOCK_RENDERERS = [
|
|
38
|
+
'heading',
|
|
39
|
+
'paragraph',
|
|
40
|
+
'blockquote',
|
|
41
|
+
'list',
|
|
42
|
+
'code',
|
|
43
|
+
'table',
|
|
44
|
+
'html',
|
|
45
|
+
'hr',
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The BLOCK-level math extension renderers.
|
|
50
|
+
*
|
|
51
|
+
* `$$…$$` and `\[…\]` are blocks of the document; `$…$` and `\(…\)` are
|
|
52
|
+
* inline and live inside a block that is already tagged. They are in their own
|
|
53
|
+
* table because that is where marked keeps them — and because the core table
|
|
54
|
+
* cannot name them at all (measured: registering `blockMathDisplay` through
|
|
55
|
+
* `marked.use({ renderer })` throws "renderer does not exist").
|
|
56
|
+
*/
|
|
57
|
+
export const EXTENSION_BLOCK_RENDERERS = ['blockMath', 'blockMathDisplay'] as const;
|
|
58
|
+
|
|
59
|
+
/** The first start tag of a rendered block, after any leading whitespace. */
|
|
60
|
+
const LEADING_TAG = /^(\s*)<([a-zA-Z][\w-]*)/;
|
|
61
|
+
|
|
62
|
+
/** The identity attributes, or the html untouched when the token has no block. */
|
|
63
|
+
export function annotateBlockHtml(html: string, token: unknown): string {
|
|
64
|
+
const block = (token as BlockToken | undefined)?.[BLOCK_ATTRIBUTE] as MdBlock | undefined;
|
|
65
|
+
if (!block) return html;
|
|
66
|
+
const attributes = `data-md-block="${block.key}" data-md-start="${block.lineStart}" data-md-end="${block.lineEnd}"`;
|
|
67
|
+
return html.replace(LEADING_TAG, `$1<$2 ${attributes}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What `registerBlockMapper` needs of the `Marked` instance.
|
|
72
|
+
*
|
|
73
|
+
* Deliberately structural and loosely typed: `marked`'s own `defaults.renderer`
|
|
74
|
+
* is `_Renderer | null | undefined`, and the extension table is untyped in the
|
|
75
|
+
* public surface. Every slot is checked at runtime before it is wrapped, so the
|
|
76
|
+
* cast is the honest place to put the looseness — one module, not a `any` at
|
|
77
|
+
* each call site.
|
|
78
|
+
*/
|
|
79
|
+
interface MapperHost {
|
|
80
|
+
defaults: {
|
|
81
|
+
renderer?: unknown;
|
|
82
|
+
extensions?: { renderers?: unknown } | null;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** One renderer slot, already bound to the object it was read from. */
|
|
87
|
+
type RendererSlot = (...args: unknown[]) => string;
|
|
88
|
+
|
|
89
|
+
/** Replace a renderer slot with one that prints the block identity. */
|
|
90
|
+
function wrap(owner: Record<string, unknown>, name: string): void {
|
|
91
|
+
const original = owner[name];
|
|
92
|
+
if (typeof original !== 'function') {
|
|
93
|
+
throw new Error(`marked renderer "${name}" is missing — the block map cannot be built`);
|
|
94
|
+
}
|
|
95
|
+
owner[name] = function blockMapper(this: unknown, token: Token, ...rest: unknown[]): string {
|
|
96
|
+
const html = (original as RendererSlot).call(this, token, ...rest);
|
|
97
|
+
return annotateBlockHtml(html, token);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Wrap every block renderer so a tagged token prints its identity.
|
|
103
|
+
*
|
|
104
|
+
* Mutates the instance's renderer table rather than calling `marked.use`: the
|
|
105
|
+
* options form of `marked.parser` bypasses the extension renderers entirely
|
|
106
|
+
* (measured — it throws on `$x^2$`), so the only safe place for this wrapper is
|
|
107
|
+
* the instance's own chain.
|
|
108
|
+
*/
|
|
109
|
+
export function registerBlockMapper(instance: MapperHost): void {
|
|
110
|
+
const renderer = instance.defaults.renderer as Record<string, unknown> | null | undefined;
|
|
111
|
+
if (!renderer) throw new Error('marked has no renderer table — the block map cannot be built');
|
|
112
|
+
for (const name of BLOCK_RENDERERS) wrap(renderer, name);
|
|
113
|
+
|
|
114
|
+
const extensions = instance.defaults.extensions?.renderers as Record<string, unknown> | null | undefined;
|
|
115
|
+
for (const name of EXTENSION_BLOCK_RENDERERS) {
|
|
116
|
+
// Absent means this instance has no math extensions; skipping is correct
|
|
117
|
+
// there, and the block-map test fails loudly if the names ever change.
|
|
118
|
+
if (extensions && typeof extensions[name] === 'function') wrap(extensions, name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Turn a markdown source into the blocks a rendered preview will contain, and
|
|
8
|
+
* tag each token so the renderer can put that identity on the markup.
|
|
9
|
+
*
|
|
10
|
+
* The line ranges come from `raw`, and that is exact rather than approximate:
|
|
11
|
+
* `marked`'s top-level tokens partition the source verbatim, so accumulating
|
|
12
|
+
* `raw.split('\n').length - 1` per token — including the `space` tokens — names
|
|
13
|
+
* the real line every block starts on (measured on this repo's own documents;
|
|
14
|
+
* see the block-map tests).
|
|
15
|
+
*
|
|
16
|
+
* ## The tokens are returned because they ARE the render input
|
|
17
|
+
*
|
|
18
|
+
* Annotating the token objects and then calling `marked.parse(source)` does
|
|
19
|
+
* nothing: `parse` lexes again, and the fresh tokens carry no tag. The only
|
|
20
|
+
* shape that works is one lexer pass, then `parser(tokens)` on those objects.
|
|
21
|
+
*
|
|
22
|
+
* ## `space` and `def` are not blocks
|
|
23
|
+
*
|
|
24
|
+
* `space` is the gap between blocks (it carries lines, never content), and a
|
|
25
|
+
* definition token renders nothing at all. Both are walked for their lines and
|
|
26
|
+
* dropped from the result, so a review can never be attached to whitespace.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { Token } from 'marked';
|
|
30
|
+
|
|
31
|
+
import { blockKeyOf, quoteOf } from '@/shared/lib/markdown/blocks/anchor';
|
|
32
|
+
import type { MdBlock } from '@/shared/lib/markdown/blocks/types';
|
|
33
|
+
|
|
34
|
+
/** Where the map is written onto the token, read by `renderer.ts`. */
|
|
35
|
+
export const BLOCK_ATTRIBUTE = '__mdBlock';
|
|
36
|
+
|
|
37
|
+
/** A token carrying its block, once `mapBlocks` has run. */
|
|
38
|
+
export type BlockToken = Token & { [BLOCK_ATTRIBUTE]?: MdBlock };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The lexer surface `mapBlocks` needs — the `Marked` instance satisfies it.
|
|
42
|
+
*
|
|
43
|
+
* Called as a METHOD, never destructured: `marked.lexer` reads `this.defaults`,
|
|
44
|
+
* so `const { lexer } = marked; lexer(source)` throws `this.defaults` undefined.
|
|
45
|
+
*/
|
|
46
|
+
export interface BlockLexer {
|
|
47
|
+
lexer(source: string): Token[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface BlockScan {
|
|
51
|
+
/** The same tokens, each block-level one tagged with its {@link MdBlock}. */
|
|
52
|
+
tokens: Token[];
|
|
53
|
+
blocks: MdBlock[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Token types that occupy lines but render no block of their own. */
|
|
57
|
+
const NOT_A_BLOCK: Record<string, true> = { space: true, def: true };
|
|
58
|
+
|
|
59
|
+
function linesIn(raw: string): number {
|
|
60
|
+
return raw.split('\n').length - 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Lex `source` and tag every block token with its key and line range.
|
|
65
|
+
*
|
|
66
|
+
* The returned tokens MUST be handed to `marked.parser`. Rendering the source
|
|
67
|
+
* again would lex a second time and lose every tag.
|
|
68
|
+
*/
|
|
69
|
+
export function mapBlocks(instance: BlockLexer, source: string): BlockScan {
|
|
70
|
+
const tokens = instance.lexer(source);
|
|
71
|
+
const blocks: MdBlock[] = [];
|
|
72
|
+
const seen = new Map<string, number>();
|
|
73
|
+
let line = 1;
|
|
74
|
+
|
|
75
|
+
for (const token of tokens) {
|
|
76
|
+
const raw = typeof token.raw === 'string' ? token.raw : '';
|
|
77
|
+
if (NOT_A_BLOCK[token.type] === true) {
|
|
78
|
+
line += linesIn(raw);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
// A trailing newline is the SEPARATOR between blocks, not part of the last
|
|
82
|
+
// line of this one — counting it would report a block as one line longer
|
|
83
|
+
// than the text it renders.
|
|
84
|
+
const body = raw.replace(/\n+$/, '');
|
|
85
|
+
const lineStart = line;
|
|
86
|
+
const lineEnd = lineStart + linesIn(body);
|
|
87
|
+
const block: MdBlock = {
|
|
88
|
+
key: blockKeyOf(token.type, raw, seen),
|
|
89
|
+
type: token.type,
|
|
90
|
+
lineStart,
|
|
91
|
+
lineEnd,
|
|
92
|
+
quote: quoteOf(body),
|
|
93
|
+
};
|
|
94
|
+
blocks.push(block);
|
|
95
|
+
(token as BlockToken)[BLOCK_ATTRIBUTE] = block;
|
|
96
|
+
line += linesIn(raw);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return { tokens, blocks };
|
|
100
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One renderable block of a markdown document, as the RENDER produced it.
|
|
8
|
+
*
|
|
9
|
+
* The rendered preview has no lines and no identity: it is one HTML string.
|
|
10
|
+
* A reviewer, though, points at a paragraph — so every top-level block carries
|
|
11
|
+
* a key derived from its own text, and the source line range it came from.
|
|
12
|
+
*
|
|
13
|
+
* The key is content-derived on purpose: a line number would re-attach a note
|
|
14
|
+
* to whatever moved into that line after the next edit, while an anchor that
|
|
15
|
+
* names the block follows the block when text above it is inserted, deleted or
|
|
16
|
+
* reflowed (see `anchor.ts`).
|
|
17
|
+
*/
|
|
18
|
+
export interface MdBlock {
|
|
19
|
+
/** `type:hash#occurrence` — stable across edits above the block. */
|
|
20
|
+
key: string;
|
|
21
|
+
/** The marked token type (`heading`, `paragraph`, `code`, …). */
|
|
22
|
+
type: string;
|
|
23
|
+
/** 1-based first source line of the block. Display data, never identity. */
|
|
24
|
+
lineStart: number;
|
|
25
|
+
/** 1-based last source line of the block. */
|
|
26
|
+
lineEnd: number;
|
|
27
|
+
/** The block's text, whitespace-collapsed, truncated for display and prompt. */
|
|
28
|
+
quote: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A judgement on one block. Two answers, because a review is a decision. */
|
|
32
|
+
export type BlockVerdict = 'good' | 'needs-work';
|
|
33
|
+
|
|
34
|
+
/** A stored judgement, as the server holds it and the preview paints it. */
|
|
35
|
+
export interface DocumentAnnotation {
|
|
36
|
+
id: string;
|
|
37
|
+
/** `<resolvedRoot>\0<repo>` — what makes two workspaces two documents. */
|
|
38
|
+
scope: string;
|
|
39
|
+
/** Workspace-relative path of the document. */
|
|
40
|
+
path: string;
|
|
41
|
+
/** The block this judgement belongs to (see {@link MdBlock.key}). */
|
|
42
|
+
blockKey: string;
|
|
43
|
+
/** The block's line range when it was judged; updated on re-save. */
|
|
44
|
+
lineStart: number;
|
|
45
|
+
lineEnd: number;
|
|
46
|
+
verdict: BlockVerdict;
|
|
47
|
+
note: string;
|
|
48
|
+
/** The block's text when it was judged — what an outdated mark still shows. */
|
|
49
|
+
quote: string;
|
|
50
|
+
createdAt: number;
|
|
51
|
+
updatedAt: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What a save sends: everything but the id and the timestamps. */
|
|
55
|
+
export type AnnotationDraft = Omit<DocumentAnnotation, 'id' | 'createdAt' | 'updatedAt'>;
|
|
56
|
+
|
|
57
|
+
/** The document a review belongs to, as the client asks for it. */
|
|
58
|
+
export interface ReviewTarget {
|
|
59
|
+
path: string;
|
|
60
|
+
root?: string | null;
|
|
61
|
+
repo?: string | null;
|
|
62
|
+
}
|