@kabmo-labs/kabmo 0.17.0 → 0.19.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 +10 -7
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +523 -441
- package/dist/client/static/js/{index-rerjq5th.js → index-fcee4c13.js} +828 -818
- package/dist/client/static/js/index-sxdw908m.css +1 -0
- package/marketplace/plugins/command-runner/package.json +3 -2
- package/marketplace/plugins/git-forge/package.json +3 -2
- package/marketplace/plugins/session-info/package.json +3 -2
- package/marketplace/plugins/stats/package.json +3 -2
- package/package.json +3 -1
- package/src/client/components/auth/login-screen/index.tsx +2 -1
- package/src/client/components/common/ComposerPicker.tsx +1 -1
- package/src/client/components/common/FolderPicker.tsx +2 -2
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/Modal.tsx +2 -2
- package/src/client/components/common/PWAInstallButton.tsx +2 -2
- package/src/client/components/common/ViewportSelector.tsx +1 -1
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +147 -0
- package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
- package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
- package/src/client/components/common/brand-wordmark/index.tsx +13 -2
- package/src/client/components/common/checkbox/style.test.ts +139 -0
- package/src/client/components/common/checkbox/style.ts +51 -0
- package/src/client/components/common/context-usage-button/index.tsx +2 -2
- package/src/client/components/common/file-icon/index.tsx +23 -9
- package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
- 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/panel-mark/index.tsx +97 -0
- package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
- package/src/client/components/common/provider-icon/index.test.ts +14 -0
- package/src/client/components/common/provider-icon/index.tsx +4 -0
- package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
- package/src/client/components/common/provider-icon/resolve.ts +16 -3
- package/src/client/components/common/server-control/Panel.tsx +33 -23
- package/src/client/components/common/server-control/index.test.tsx +11 -5
- package/src/client/components/common/server-control/index.tsx +10 -8
- package/src/client/components/common/session-actions-menu/index.tsx +1 -1
- package/src/client/components/common/toolbar-row/index.tsx +1 -1
- package/src/client/components/layout/ActivityBar.tsx +22 -3
- package/src/client/components/layout/LeftDock.tsx +9 -2
- package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
- package/src/client/components/layout/WindowAura.tsx +27 -0
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
- package/src/client/components/layout/desktop-layout/index.tsx +3 -1
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +44 -23
- 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/Header.tsx +1 -1
- package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
- package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
- 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/ActionRow.tsx +1 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +40 -14
- 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/session-sidebar/new-workspace-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
- 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/LayoutWrapper.tsx +3 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
- 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 +1 -1
- 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/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/mobile/panel-chips.tsx +10 -2
- package/src/client/components/settings/Modal.tsx +4 -4
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/apply-side-effects.test.ts +30 -0
- package/src/client/components/settings/apply-side-effects.ts +14 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
- package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
- 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/SkillSettings.tsx +2 -2
- 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 +9 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -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 +93 -77
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +28 -15
- 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/panel-plugins/AvailableList.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +51 -2
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +43 -10
- package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +37 -8
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
- 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/btw-panel/TopicMenu.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
- 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/UndoConfirmModal.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
- 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/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/shared/ArtifactChip.tsx +7 -6
- 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/context-panel/CostBreakdownPopover.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/index.tsx +2 -2
- 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/PluginRail.tsx +1 -1
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
- package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
- package/src/client/components/workspace/editor/Tabs.tsx +1 -1
- 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/file-explorer/ContextMenu.tsx +1 -1
- package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
- package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
- package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
- package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
- package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
- package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
- package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/git-panel/index.tsx +7 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
- package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
- package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
- package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
- package/src/client/components/workspace/search-panel/Body.tsx +1 -1
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
- 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 +33 -1
- package/src/client/glass.css +785 -0
- package/src/client/glass.test.ts +346 -0
- 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/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/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/ui/glass-support.ts +57 -0
- package/src/client/hooks/ui/icon-style.ts +59 -0
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/stuck-header.test.ts +188 -0
- package/src/client/hooks/ui/stuck-header.ts +91 -0
- package/src/client/hooks/ui/style-attributes.test.ts +120 -0
- package/src/client/hooks/ui/surface-style.ts +56 -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/workspace/panel-hues.ts +23 -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/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/main.tsx +10 -0
- package/src/client/tailwind.css +329 -11
- package/src/server/lib/assets/shell-attributes.server.ts +80 -0
- package/src/server/lib/assets/shell-attributes.test.ts +86 -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/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/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
- package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
- package/src/server/lib/omp/rpc/manager.ts +2 -2
- package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
- package/src/server/lib/omp/rpc/process.test.ts +106 -0
- package/src/server/lib/omp/rpc/process.ts +39 -18
- package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
- package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
- package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
- package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
- package/src/server/lib/omp/rpc/session-commands.ts +17 -3
- package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
- 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/panels/bundled-catalog.server.ts +1 -0
- package/src/server/lib/panels/manifest.test.ts +20 -0
- package/src/server/lib/panels/manifest.ts +12 -0
- package/src/server/lib/panels/scan.server.ts +4 -0
- package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
- package/src/server/lib/queue/delivery-harness.ts +8 -4
- package/src/server/lib/queue/delivery.server.test.ts +29 -0
- package/src/server/lib/queue/delivery.server.ts +39 -0
- package/src/server/lib/queue/store.server.test.ts +22 -2
- package/src/server/lib/queue/store.server.ts +33 -11
- 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/plugins/ssr.ts +22 -5
- 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 +95 -102
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
- 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/icons/file-brand-color.ts +38 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +234 -0
- package/src/shared/lib/icons/icon-paint-css.ts +284 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +100 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +230 -0
- package/src/shared/lib/icons/tint.test.ts +273 -0
- package/src/shared/lib/icons/tint.ts +219 -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/brand-color.test.ts +116 -0
- package/src/shared/lib/models/provider/brand-color.ts +103 -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 +31 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +113 -47
- package/src/shared/lib/omp/rpc/frame.ts +107 -43
- package/src/shared/lib/settings/defaults.ts +4 -0
- package/src/shared/lib/theme/catalog.test.ts +5 -4
- package/src/shared/lib/theme/catalog.ts +18 -3
- package/src/shared/lib/theme/glass-support.test.ts +38 -0
- package/src/shared/lib/theme/glass-support.ts +73 -0
- package/src/shared/lib/theme/icon-style.test.ts +74 -0
- package/src/shared/lib/theme/icon-style.ts +90 -0
- package/src/shared/lib/theme/legibility.ts +91 -0
- package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
- package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
- package/src/shared/lib/theme/surface-style.test.ts +68 -0
- package/src/shared/lib/theme/surface-style.ts +91 -0
- package/src/shared/lib/theme/theme.test.ts +11 -7
- 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/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/panel-hues.test.ts +68 -0
- package/src/shared/lib/workspace/panel-hues.ts +57 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/panels-registry.ts +6 -0
- package/src/shared/types/panels.ts +14 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/state.ts +30 -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/fake-omp-frames.ts +163 -0
- package/dist/client/static/js/index-3ve31rzx.css +0 -1
- 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/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The colour every FUNCTIONAL glyph is painted in, in `color` mode.
|
|
8
|
+
*
|
|
9
|
+
* Lucide draws each icon as a stroke in `currentColor`, so "full colour" for a
|
|
10
|
+
* functional glyph can only mean a TINT — there is no second artwork to swap in.
|
|
11
|
+
* Two rules decide which tint, and they answer different questions:
|
|
12
|
+
*
|
|
13
|
+
* - **A signal icon means something, so it takes the palette's signal colour**
|
|
14
|
+
* ({@link ICON_TINTS}): a trash can is destructive, a check is a confirmation,
|
|
15
|
+
* a clock is waiting, an info dot is information. Those colours already exist
|
|
16
|
+
* in every palette, and a themed `--theme-error` follows the user's theme the
|
|
17
|
+
* way a literal red cannot.
|
|
18
|
+
* - **Every other icon gets its OWN hue** ({@link ICON_HUES}, generated). One
|
|
19
|
+
* shared accent for the remaining two hundred glyphs is the failure mode this
|
|
20
|
+
* avoids: a mode that colours a dozen icons and leaves the rest identical is
|
|
21
|
+
* not "full colour", it is one colour. The hue comes from a stable hash of the
|
|
22
|
+
* name, quantised to a 36-step wheel, so two neighbouring icons differ without
|
|
23
|
+
* the table being 250 hand-picked decisions.
|
|
24
|
+
*
|
|
25
|
+
* Both are DEFAULT paint, never an override: the stylesheet wraps every selector
|
|
26
|
+
* in `:where()`, so a `text-*` class a caller wrote on the element still wins
|
|
27
|
+
* (see `icon-paint-css.ts`).
|
|
28
|
+
*
|
|
29
|
+
* Keys are the names the code IMPORTS (`Trash2`), not the emitted class, so a
|
|
30
|
+
* row is checkable against the call site it describes; {@link lucideClassName}
|
|
31
|
+
* is the single translation to `lucide-trash-2`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { ICON_HUES } from '@/shared/lib/icons/tint-hues.generated';
|
|
35
|
+
|
|
36
|
+
export type IconTintRole = 'error' | 'success' | 'warning' | 'info';
|
|
37
|
+
|
|
38
|
+
/** The CSS value each role paints. Tokens only — never a hex. */
|
|
39
|
+
export const ICON_TINT_TOKENS: Readonly<Record<IconTintRole, string>> = {
|
|
40
|
+
error: 'var(--theme-error)',
|
|
41
|
+
success: 'var(--theme-success)',
|
|
42
|
+
warning: 'var(--theme-warning)',
|
|
43
|
+
info: 'var(--theme-info)',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Saturation and lightness the generated hues are painted with, per variant.
|
|
48
|
+
*
|
|
49
|
+
* These two pairs are the whole legibility budget: measured against every light
|
|
50
|
+
* palette, `60% 30%` keeps its worst hue at 3.46:1 (the floor is 3:1 for a
|
|
51
|
+
* graphic) even on `tokyonight-light`'s `#dee0ee` paper, and `65% 70%` keeps the
|
|
52
|
+
* worst dark hue at 4.07:1 on `jetbrains-dark`'s `#2B2D30`. A lighter light
|
|
53
|
+
* value (34%) drops two hues below the floor, which is why it is not "prettier".
|
|
54
|
+
*/
|
|
55
|
+
export const ICON_HUE_PAINT = {
|
|
56
|
+
light: { saturation: 60, lightness: 30 },
|
|
57
|
+
dark: { saturation: 65, lightness: 70 },
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
/** The hue an icon with no row keeps — a neutral blue, never a sixth signal. */
|
|
61
|
+
export const DEFAULT_ICON_HUE = 210;
|
|
62
|
+
|
|
63
|
+
/** One hue as a paintable `hsl()`. The single place the numbers become CSS. */
|
|
64
|
+
export function iconHueColor(hue: number, variant: 'light' | 'dark'): string {
|
|
65
|
+
const { saturation, lightness } = ICON_HUE_PAINT[variant];
|
|
66
|
+
return `hsl(${hue} ${saturation}% ${lightness}%)`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The paint rule's value: the hue left to the custom property the class sets. */
|
|
70
|
+
export function iconHuePaint(variant: 'light' | 'dark'): string {
|
|
71
|
+
const { saturation, lightness } = ICON_HUE_PAINT[variant];
|
|
72
|
+
return `hsl(var(--icon-hue, ${DEFAULT_ICON_HUE}) ${saturation}% ${lightness}%)`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Glyph name → the signal it stands for. Everything else gets a generated hue. */
|
|
76
|
+
export const ICON_TINTS: Readonly<Record<string, IconTintRole>> = {
|
|
77
|
+
// Failures, destructive actions, and things that are broken.
|
|
78
|
+
AlertCircle: 'error',
|
|
79
|
+
AlertTriangle: 'error',
|
|
80
|
+
Ban: 'error',
|
|
81
|
+
Bug: 'error',
|
|
82
|
+
BugOff: 'error',
|
|
83
|
+
CircleAlert: 'error',
|
|
84
|
+
CircleSlash: 'error',
|
|
85
|
+
FileWarning: 'error',
|
|
86
|
+
FileX: 'error',
|
|
87
|
+
OctagonAlert: 'error',
|
|
88
|
+
OctagonX: 'error',
|
|
89
|
+
PackageX: 'error',
|
|
90
|
+
ShieldAlert: 'error',
|
|
91
|
+
Trash2: 'error',
|
|
92
|
+
XCircle: 'error',
|
|
93
|
+
|
|
94
|
+
// Confirmations and healthy state.
|
|
95
|
+
Check: 'success',
|
|
96
|
+
CheckCheck: 'success',
|
|
97
|
+
CheckCircle2: 'success',
|
|
98
|
+
CheckSquare: 'success',
|
|
99
|
+
PackageCheck: 'success',
|
|
100
|
+
ShieldCheck: 'success',
|
|
101
|
+
|
|
102
|
+
// A file whose VIEWER is the point: the hue is what tells a reader at a
|
|
103
|
+
// glance that the document opens as something other than source text. These
|
|
104
|
+
// carried fixed hexes before the mode existed, which made them the only icons
|
|
105
|
+
// that ignored it.
|
|
106
|
+
Braces: 'warning',
|
|
107
|
+
FileArchive: 'warning',
|
|
108
|
+
FileSpreadsheet: 'success',
|
|
109
|
+
FileType: 'warning',
|
|
110
|
+
|
|
111
|
+
// Attention: something is pending, scheduled or in flight.
|
|
112
|
+
Bell: 'warning',
|
|
113
|
+
Calendar: 'warning',
|
|
114
|
+
CalendarRange: 'warning',
|
|
115
|
+
Clock: 'warning',
|
|
116
|
+
Clock3: 'warning',
|
|
117
|
+
Hourglass: 'warning',
|
|
118
|
+
|
|
119
|
+
// Information, help and reading.
|
|
120
|
+
BookOpen: 'info',
|
|
121
|
+
CircleQuestionMark: 'info',
|
|
122
|
+
Compass: 'info',
|
|
123
|
+
HelpCircle: 'info',
|
|
124
|
+
Info: 'info',
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* `Trash2` -> `trash-2`: the class Lucide emits for that component.
|
|
129
|
+
*
|
|
130
|
+
* Lucide names the class from the icon's own canonical name and adds one per
|
|
131
|
+
* alias, so a legacy import name (`Trash2`, `AlertTriangle`) still matches its
|
|
132
|
+
* own class — which is why this conversion is enough and the table can stay in
|
|
133
|
+
* the vocabulary of the call sites.
|
|
134
|
+
*/
|
|
135
|
+
export function kebabIconName(name: string): string {
|
|
136
|
+
return name
|
|
137
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
138
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
139
|
+
.replace(/([a-zA-Z])([0-9])/g, '$1-$2')
|
|
140
|
+
.toLowerCase();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The class Lucide puts on the `<svg>` for an imported icon name. */
|
|
144
|
+
export function lucideClassName(name: string): string {
|
|
145
|
+
return `lucide-${kebabIconName(name)}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The signal role for an imported icon name, or `null` when it has none. */
|
|
149
|
+
export function iconTintRole(name: string): IconTintRole | null {
|
|
150
|
+
return ICON_TINTS[name] ?? null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The generated hue for an imported icon name. */
|
|
154
|
+
export function iconHue(name: string): number {
|
|
155
|
+
return ICON_HUES[name] ?? DEFAULT_ICON_HUE;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The wheel the hashes land on: 36 hues, 10° apart. */
|
|
159
|
+
export const HUE_STEPS = 36;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The hue of anything that is not in the generated table — a plugin's mark.
|
|
163
|
+
*
|
|
164
|
+
* Plugin names arrive at RUNTIME, so they cannot be baked into a table: the
|
|
165
|
+
* manifest is read from disk and a marketplace install adds rows no build could
|
|
166
|
+
* have seen. The hue is therefore computed here, with the SAME function that
|
|
167
|
+
* produced every generated row (`scripts/icon-tints.mjs`, asserted equal in
|
|
168
|
+
* `tint.test.ts`), so a plugin's colour sits on the same wheel as the glyphs
|
|
169
|
+
* around it instead of inventing a second palette.
|
|
170
|
+
*
|
|
171
|
+
* FNV-1a, 36 steps of 10°: stable across runs and platforms, which a colour for
|
|
172
|
+
* stored data has to be.
|
|
173
|
+
*/
|
|
174
|
+
export function hashHue(name: string): number {
|
|
175
|
+
let hash = 2166136261 >>> 0;
|
|
176
|
+
for (const char of name) {
|
|
177
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
178
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
179
|
+
}
|
|
180
|
+
return (hash % HUE_STEPS) * (360 / HUE_STEPS);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* One hue per PANEL, with collisions resolved.
|
|
185
|
+
*
|
|
186
|
+
* A rail draws ~14 marks and the wheel has 36 slots, so a plain hash collides
|
|
187
|
+
* about nine times in ten (birthday bound) — measured on the right rail: three
|
|
188
|
+
* of its fourteen icons landed on the same blue, which is the opposite of "each
|
|
189
|
+
* icon has its own colour". Panels are a KNOWN, stable set per rail, so the
|
|
190
|
+
* collision can be resolved deterministically: sort the ids, take each hash, and
|
|
191
|
+
* probe forward 10° at a time until the slot is free. Sorting makes the answer
|
|
192
|
+
* independent of the catalog's order, so reordering a rail never recolours it.
|
|
193
|
+
*
|
|
194
|
+
* A plugin and a built-in compete in the same space on purpose: they sit in one
|
|
195
|
+
* bar, and two neighbours in the same hue is the defect this avoids.
|
|
196
|
+
*/
|
|
197
|
+
export function assignPanelHues(ids: readonly string[]): Map<string, number> {
|
|
198
|
+
const hues = new Map<string, number>();
|
|
199
|
+
const taken = new Set<number>();
|
|
200
|
+
for (const id of [...ids].sort()) {
|
|
201
|
+
let hue = hashHue(id);
|
|
202
|
+
for (let step = 0; step < HUE_STEPS && taken.has(hue); step += 1) {
|
|
203
|
+
hue = (hue + 360 / HUE_STEPS) % 360;
|
|
204
|
+
}
|
|
205
|
+
taken.add(hue);
|
|
206
|
+
hues.set(id, hue);
|
|
207
|
+
}
|
|
208
|
+
return hues;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Signal rows, as `{ className, role }`, for the stylesheet generator. */
|
|
212
|
+
export const ICON_TINT_ROWS: ReadonlyArray<{ className: string; role: IconTintRole }> = Object.entries(
|
|
213
|
+
ICON_TINTS,
|
|
214
|
+
).map(([name, role]) => ({ className: lucideClassName(name), role }));
|
|
215
|
+
|
|
216
|
+
/** Generated-hue rows, as `{ className, hue }`, for the stylesheet generator. */
|
|
217
|
+
export const ICON_HUE_ROWS: ReadonlyArray<{ className: string; hue: number }> = Object.entries(ICON_HUES).map(
|
|
218
|
+
([name, hue]) => ({ className: lucideClassName(name), hue }),
|
|
219
|
+
);
|
|
@@ -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
|
+
}
|