@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,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
|
+
}
|
|
@@ -32,7 +32,10 @@ import { codeSafeAutolink } from '@/shared/lib/markdown/autolink';
|
|
|
32
32
|
import remend from 'remend';
|
|
33
33
|
import { highlightCode } from '@/shared/lib/code/syntax-highlight';
|
|
34
34
|
import { directiveBlockHtml, isDirectiveLanguage, parseDirectiveAttributes } from '@/shared/lib/markdown/directives';
|
|
35
|
-
import {
|
|
35
|
+
import { mathExtensions, setProseEscaped } from '@/shared/lib/markdown/math-extensions';
|
|
36
|
+
import { registerBlockMapper } from '@/shared/lib/markdown/blocks/renderer';
|
|
37
|
+
import { mapBlocks } from '@/shared/lib/markdown/blocks/scan';
|
|
38
|
+
import type { MdBlock } from '@/shared/lib/markdown/blocks/types';
|
|
36
39
|
|
|
37
40
|
/** Escape HTML for safe interpolation inside highlighted output. */
|
|
38
41
|
function escapeHtml(value: string): string {
|
|
@@ -44,56 +47,6 @@ function escapeHtml(value: string): string {
|
|
|
44
47
|
.replace(/'/g, ''');
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
/**
|
|
48
|
-
* True while `renderMarkdown` parses prose it escaped itself. Set around the
|
|
49
|
-
* `marked.parse` call, read by `renderMathPlaceholder`. Synchronous by
|
|
50
|
-
* construction: `marked.parse` never awaits, so no nested `renderMarkdown`
|
|
51
|
-
* can observe the flag mid-parse.
|
|
52
|
-
*/
|
|
53
|
-
let proseEscaped = false;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Emit a math placeholder instead of rendering KaTeX inline.
|
|
57
|
-
*
|
|
58
|
-
* `katex` is ~522 kB of JS worth loading only when a message contains math, so
|
|
59
|
-
* it is not imported here. The placeholder carries the TeX source and the
|
|
60
|
-
* display flag; `katex.ts` swaps it for real markup once the library lands
|
|
61
|
-
* (see `hydrateMathBlocks`).
|
|
62
|
-
*
|
|
63
|
-
* Two things happen to the captured source here, and both exist because this
|
|
64
|
-
* renderer is the one place all four math extensions funnel through:
|
|
65
|
-
*
|
|
66
|
-
* 1. **Entities are reversed** when `renderMarkdown` escaped the prose itself
|
|
67
|
-
* (`proseEscaped`). `escapeHtmlOutsideCode` rewrites the source BEFORE
|
|
68
|
-
* marked sees it, so a tokenizer captures `x < y` rather than `x < y` and
|
|
69
|
-
* KaTeX reports a syntax error for a perfectly good formula. Only the three
|
|
70
|
-
* entities that escaper emits are reversed, and only when it ran — a
|
|
71
|
-
* document (`allowHtml`) whose own text legitimately holds `&` is left
|
|
72
|
-
* alone.
|
|
73
|
-
* 2. **The result is percent-encoded**, the way a mermaid block carries its
|
|
74
|
-
* source. HTML-escaping the payload instead re-escapes what step 1 just
|
|
75
|
-
* restored, and the attribute round-trip hides the extra layer from both
|
|
76
|
-
* ends. An encoded payload holds no HTML-special character, so nothing
|
|
77
|
-
* between here and `renderPlaceholder` can alter it.
|
|
78
|
-
*/
|
|
79
|
-
function renderMathPlaceholder(tex: string, displayMode: boolean): string {
|
|
80
|
-
const restored = proseEscaped
|
|
81
|
-
? tex.replace(/&(amp|lt|gt);/g, (_, name: string) => (name === 'amp' ? '&' : name === 'lt' ? '<' : '>'))
|
|
82
|
-
: tex;
|
|
83
|
-
const display = displayMode ? ' data-math-display="1"' : '';
|
|
84
|
-
const span = `<span class="${MATH_PENDING_CLASS}" data-math="${encodeURIComponent(restored)}"${display}></span>`;
|
|
85
|
-
// Block math must stay inside a block element: DOMPurify drops a bare
|
|
86
|
-
// `<span>` that sits at the top level of the fragment, which silently deleted
|
|
87
|
-
// every `$$…$$` formula. KaTeX's own output is inline-level too, so the old
|
|
88
|
-
// synchronous renderer relied on the same wrapper being present.
|
|
89
|
-
return displayMode ? `<p>${span}</p>` : span;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
interface TokenLike {
|
|
93
|
-
type: string;
|
|
94
|
-
text?: string;
|
|
95
|
-
raw?: string;
|
|
96
|
-
}
|
|
97
50
|
|
|
98
51
|
const marked = new Marked({
|
|
99
52
|
gfm: true,
|
|
@@ -190,97 +143,15 @@ marked.use({
|
|
|
190
143
|
},
|
|
191
144
|
});
|
|
192
145
|
|
|
193
|
-
marked.use({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
tokenizer(src: string) {
|
|
203
|
-
const match = /^\\\(([\s\S]+?)\\\)/.exec(src);
|
|
204
|
-
return match
|
|
205
|
-
? { type: 'inlineMath', raw: match[0], text: match[1] }
|
|
206
|
-
: undefined;
|
|
207
|
-
},
|
|
208
|
-
renderer(token: TokenLike) {
|
|
209
|
-
return renderMathPlaceholder(token.text ?? '', false);
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
// \[ ... \] block math
|
|
213
|
-
{
|
|
214
|
-
name: 'blockMath',
|
|
215
|
-
level: 'block',
|
|
216
|
-
start(src: string) {
|
|
217
|
-
return src.match(/^\\\[/)?.index;
|
|
218
|
-
},
|
|
219
|
-
tokenizer(src: string) {
|
|
220
|
-
const match = /^\\\[([\s\S]+?)\\\]/.exec(src);
|
|
221
|
-
return match
|
|
222
|
-
? { type: 'blockMath', raw: match[0], text: match[1] }
|
|
223
|
-
: undefined;
|
|
224
|
-
},
|
|
225
|
-
renderer(token: TokenLike) {
|
|
226
|
-
return renderMathPlaceholder(token.text ?? '', true);
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
// $$ ... $$ display math (block-level, must be its own line)
|
|
230
|
-
{
|
|
231
|
-
name: 'blockMathDisplay',
|
|
232
|
-
level: 'block',
|
|
233
|
-
start(src: string) {
|
|
234
|
-
return src.match(/^\$\$/)?.index;
|
|
235
|
-
},
|
|
236
|
-
tokenizer(src: string) {
|
|
237
|
-
const match = /^\$\$([\s\S]+?)\$\$(?:\n|$)/.exec(src);
|
|
238
|
-
return match
|
|
239
|
-
? { type: 'blockMathDisplay', raw: match[0], text: match[1] }
|
|
240
|
-
: undefined;
|
|
241
|
-
},
|
|
242
|
-
renderer(token: TokenLike) {
|
|
243
|
-
return renderMathPlaceholder(token.text ?? '', true);
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
// $ ... $ inline math. The flanking rules are the whole defence: a single
|
|
247
|
-
// `$` is the one delimiter that collides with ordinary text, and this
|
|
248
|
-
// pipeline renders shell output, currency, SQL and awk programs all day.
|
|
249
|
-
//
|
|
250
|
-
// opening $ — not preceded by a word char (checked in `start`, the only
|
|
251
|
-
// place the preceding character is visible), and not
|
|
252
|
-
// followed by a digit, `$` or `{`. The digit guard is what
|
|
253
|
-
// makes `$5`, `$1` and `$10` text; `{` keeps `${HOME}` out.
|
|
254
|
-
// closing $ — not preceded by whitespace, and not followed by a WORD
|
|
255
|
-
// char or `$`. That trailing guard is load-bearing twice
|
|
256
|
-
// over: it rejects `PATH=$PATH:$HOME` (closer followed by
|
|
257
|
-
// `H`) and `a$b$c` (followed by `c`), and it is the reason
|
|
258
|
-
// the rule no longer depends on where `start` happened to
|
|
259
|
-
// land — the tokenizer is anchored at `^` and cannot see
|
|
260
|
-
// the preceding character, so `a$b$c` was math while
|
|
261
|
-
// `ax$b$c` was text on the identical rule.
|
|
262
|
-
//
|
|
263
|
-
// `$n$ = 3` and `$x^2$ benar` still parse: a space after the closer is not
|
|
264
|
-
// a word char.
|
|
265
|
-
{
|
|
266
|
-
name: 'inlineMathDollar',
|
|
267
|
-
level: 'inline',
|
|
268
|
-
start(src: string) {
|
|
269
|
-
const match = /(^|[^\w$])\$(?!\$)(?!\s)/.exec(src);
|
|
270
|
-
return match ? match.index + (match[1]?.length ?? 0) : undefined;
|
|
271
|
-
},
|
|
272
|
-
tokenizer(src: string) {
|
|
273
|
-
const match = /^\$(?![\d${])((?:\\\$|[^$])*?)(?<!\s)\$(?![\w$])/.exec(src);
|
|
274
|
-
return match
|
|
275
|
-
? { type: 'inlineMathDollar', raw: match[0], text: match[1] }
|
|
276
|
-
: undefined;
|
|
277
|
-
},
|
|
278
|
-
renderer(token: TokenLike) {
|
|
279
|
-
return renderMathPlaceholder(token.text ?? '', false);
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
});
|
|
146
|
+
marked.use({ extensions: mathExtensions() });
|
|
147
|
+
|
|
148
|
+
// LAST, and the order is the contract: the mapper captures these renderers as
|
|
149
|
+
// they stand, so registering it before the overrides above would capture the
|
|
150
|
+
// un-wrapped `code`/`table` and every previewed document would lose its copy
|
|
151
|
+
// buttons and its table scroller. A math block's token is not in this table at
|
|
152
|
+
// all (it belongs to the extension), which is why the mapper also wraps
|
|
153
|
+
// `defaults.extensions.renderers` — see `blocks/renderer.ts`.
|
|
154
|
+
registerBlockMapper(marked);
|
|
284
155
|
|
|
285
156
|
/** Escape HTML special chars in text, leaving backtick-delimited code intact
|
|
286
157
|
* (inline `code` and fenced ``` blocks) so code like `a < b` is not mangled
|
|
@@ -313,23 +184,63 @@ export interface RenderMarkdownOptions {
|
|
|
313
184
|
allowHtml?: boolean;
|
|
314
185
|
}
|
|
315
186
|
|
|
187
|
+
/**
|
|
188
|
+
* The healed source both entry points parse — one spelling of the pipeline, so
|
|
189
|
+
* the preview and the mapped preview can never disagree about what a document
|
|
190
|
+
* says.
|
|
191
|
+
*/
|
|
192
|
+
function heal(markdown: string, allowHtml: boolean): string {
|
|
193
|
+
const source = allowHtml ? markdown : escapeHtmlOutsideCode(markdown);
|
|
194
|
+
return remend(source, { katex: true, inlineKatex: false })
|
|
195
|
+
.replace(INCOMPLETE_LINK_RE, (_, text: string) => `<span class="md-incomplete-link">${text}</span>`);
|
|
196
|
+
}
|
|
197
|
+
|
|
316
198
|
/**
|
|
317
199
|
* Heal streaming markdown (remend) then parse to HTML via marked.
|
|
318
200
|
* Synchronous and side-effect free — safe in both server loaders and the
|
|
319
201
|
* browser. The output must be sanitized with DOMPurify before injection.
|
|
320
202
|
*/
|
|
321
203
|
export function renderMarkdown(markdown: string, options: RenderMarkdownOptions = {}): string {
|
|
322
|
-
const
|
|
323
|
-
const healed = remend(source, { katex: true, inlineKatex: false })
|
|
324
|
-
.replace(INCOMPLETE_LINK_RE, (_, text: string) => `<span class="md-incomplete-link">${text}</span>`);
|
|
204
|
+
const healed = heal(markdown, options.allowHtml === true);
|
|
325
205
|
// The math renderers need to know the prose was escaped, so they can hand
|
|
326
206
|
// KaTeX the source the author wrote instead of `x < y`. `marked.parse`
|
|
327
207
|
// never awaits, so no nested render can observe this mid-parse.
|
|
328
|
-
|
|
208
|
+
setProseEscaped(options.allowHtml !== true);
|
|
329
209
|
try {
|
|
330
210
|
return (marked.parse(healed) as string).trim();
|
|
331
211
|
} finally {
|
|
332
|
-
|
|
212
|
+
setProseEscaped(false);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The mapped render: the same HTML, plus the block each element came from. */
|
|
217
|
+
export interface MappedMarkdown {
|
|
218
|
+
html: string;
|
|
219
|
+
blocks: MdBlock[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Render a document AND say which source block each rendered element is.
|
|
224
|
+
*
|
|
225
|
+
* The preview needs the second half: a reviewer points at a paragraph, and a
|
|
226
|
+
* line number cannot express that (the render has no lines). The identity rides
|
|
227
|
+
* on `data-md-block`, a content-derived anchor, so it survives an edit above the
|
|
228
|
+
* block — see `blocks/anchor.ts`.
|
|
229
|
+
*
|
|
230
|
+
* Deliberately NOT `marked.parse(healed)`: that lexes a second time and the
|
|
231
|
+
* fresh tokens carry no tag. One lexer pass, then `parser(tokens)` on those
|
|
232
|
+
* objects. The attributes are a strict no-op for an untagged token, so the
|
|
233
|
+
* chat path (`renderMarkdown`) stays byte-identical.
|
|
234
|
+
*/
|
|
235
|
+
export function renderMappedMarkdown(markdown: string, options: RenderMarkdownOptions = {}): MappedMarkdown {
|
|
236
|
+
const healed = heal(markdown, options.allowHtml === true);
|
|
237
|
+
const { tokens, blocks } = mapBlocks(marked, healed);
|
|
238
|
+
setProseEscaped(options.allowHtml !== true);
|
|
239
|
+
try {
|
|
240
|
+
const html = (marked.parser(tokens) as string).trim();
|
|
241
|
+
return { html, blocks };
|
|
242
|
+
} finally {
|
|
243
|
+
setProseEscaped(false);
|
|
333
244
|
}
|
|
334
245
|
}
|
|
335
246
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The four math extensions, split out of `marked.ts` for the per-file ceiling —
|
|
8
|
+
* and because they are the one part of the pipeline with rules that do not fit
|
|
9
|
+
* in a renderer override: each is a tokenizer plus a renderer, registered
|
|
10
|
+
* through `marked.use({ extensions })`.
|
|
11
|
+
*
|
|
12
|
+
* ## The placeholder is never the formula
|
|
13
|
+
*
|
|
14
|
+
* KaTeX is ~522 kB of JS worth fetching only when a message contains math, so
|
|
15
|
+
* this module emits a span carrying the source and the display flag; `katex.ts`
|
|
16
|
+
* swaps it for real markup once the library lands.
|
|
17
|
+
*
|
|
18
|
+
* ## The prose-escape flag is shared state, and that is deliberate
|
|
19
|
+
*
|
|
20
|
+
* `renderMarkdown` escapes HTML in prose before marked sees it, so a tokenizer
|
|
21
|
+
* captures `x < y` rather than `x < y` — and KaTeX would report a syntax
|
|
22
|
+
* error for a perfectly good formula. The flag is set for the duration of one
|
|
23
|
+
* synchronous `parse`, which is why `setProseEscaped` exists instead of a
|
|
24
|
+
* parameter threaded through four renderers. `marked.parse` never awaits, so no
|
|
25
|
+
* nested render can observe it mid-parse.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { TokenizerAndRendererExtension } from 'marked';
|
|
29
|
+
|
|
30
|
+
import { MATH_PENDING_CLASS } from '@/shared/lib/markdown/katex';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* True while `renderMarkdown` parses prose it escaped itself, read by the math
|
|
34
|
+
* renderers below.
|
|
35
|
+
*/
|
|
36
|
+
let proseEscaped = false;
|
|
37
|
+
|
|
38
|
+
/** Set for the duration of one parse; always paired with `false`. */
|
|
39
|
+
export function setProseEscaped(value: boolean): void {
|
|
40
|
+
proseEscaped = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface TokenLike {
|
|
44
|
+
type: string;
|
|
45
|
+
text?: string;
|
|
46
|
+
raw?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Emit a math placeholder instead of rendering KaTeX inline.
|
|
51
|
+
*
|
|
52
|
+
* Two things happen to the captured source, and both exist because this is the
|
|
53
|
+
* one place all four math extensions funnel through:
|
|
54
|
+
*
|
|
55
|
+
* 1. **Entities are reversed** when the prose was escaped. Only the three
|
|
56
|
+
* entities that escaper emits are reversed, and only when it ran — a document
|
|
57
|
+
* (`allowHtml`) whose own text legitimately holds `&` is left alone.
|
|
58
|
+
* 2. **The result is percent-encoded**, the way a mermaid block carries its
|
|
59
|
+
* source. HTML-escaping the payload instead re-escapes what step 1 just
|
|
60
|
+
* restored, and the attribute round-trip hides the extra layer from both
|
|
61
|
+
* ends. An encoded payload holds no HTML-special character, so nothing
|
|
62
|
+
* between here and injection can alter it.
|
|
63
|
+
*/
|
|
64
|
+
export function renderMathPlaceholder(tex: string, displayMode: boolean): string {
|
|
65
|
+
const restored = proseEscaped
|
|
66
|
+
? tex.replace(/&(amp|lt|gt);/g, (_, name: string) => (name === 'amp' ? '&' : name === 'lt' ? '<' : '>'))
|
|
67
|
+
: tex;
|
|
68
|
+
const display = displayMode ? ' data-math-display="1"' : '';
|
|
69
|
+
const span = `<span class="${MATH_PENDING_CLASS}" data-math="${encodeURIComponent(restored)}"${display}></span>`;
|
|
70
|
+
// Block math must stay inside a block element: DOMPurify drops a bare
|
|
71
|
+
// `<span>` that sits at the top level of the fragment, which silently deleted
|
|
72
|
+
// every `$$…$$` formula. KaTeX's own output is inline-level too, so the old
|
|
73
|
+
// synchronous renderer relied on the same wrapper being present.
|
|
74
|
+
return displayMode ? `<p>${span}</p>` : span;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The four extensions, in the order `marked.ts` registers them. */
|
|
78
|
+
export function mathExtensions(): TokenizerAndRendererExtension[] {
|
|
79
|
+
return [
|
|
80
|
+
// \( ... \) inline math
|
|
81
|
+
{
|
|
82
|
+
name: 'inlineMath',
|
|
83
|
+
level: 'inline',
|
|
84
|
+
start(src: string) {
|
|
85
|
+
return src.match(/\\\(/)?.index;
|
|
86
|
+
},
|
|
87
|
+
tokenizer(src: string) {
|
|
88
|
+
const match = /^\\\(([\s\S]+?)\\\)/.exec(src);
|
|
89
|
+
return match
|
|
90
|
+
? { type: 'inlineMath', raw: match[0], text: match[1] }
|
|
91
|
+
: undefined;
|
|
92
|
+
},
|
|
93
|
+
renderer(token: TokenLike) {
|
|
94
|
+
return renderMathPlaceholder(token.text ?? '', false);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
// \[ ... \] block math
|
|
98
|
+
{
|
|
99
|
+
name: 'blockMath',
|
|
100
|
+
level: 'block',
|
|
101
|
+
start(src: string) {
|
|
102
|
+
return src.match(/^\\\[/)?.index;
|
|
103
|
+
},
|
|
104
|
+
tokenizer(src: string) {
|
|
105
|
+
const match = /^\\\[([\s\S]+?)\\\]/.exec(src);
|
|
106
|
+
return match
|
|
107
|
+
? { type: 'blockMath', raw: match[0], text: match[1] }
|
|
108
|
+
: undefined;
|
|
109
|
+
},
|
|
110
|
+
renderer(token: TokenLike) {
|
|
111
|
+
return renderMathPlaceholder(token.text ?? '', true);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
// $$ ... $$ display math (block-level, must be its own line)
|
|
115
|
+
{
|
|
116
|
+
name: 'blockMathDisplay',
|
|
117
|
+
level: 'block',
|
|
118
|
+
start(src: string) {
|
|
119
|
+
return src.match(/^\$\$/)?.index;
|
|
120
|
+
},
|
|
121
|
+
tokenizer(src: string) {
|
|
122
|
+
const match = /^\$\$([\s\S]+?)\$\$(?:\n|$)/.exec(src);
|
|
123
|
+
return match
|
|
124
|
+
? { type: 'blockMathDisplay', raw: match[0], text: match[1] }
|
|
125
|
+
: undefined;
|
|
126
|
+
},
|
|
127
|
+
renderer(token: TokenLike) {
|
|
128
|
+
return renderMathPlaceholder(token.text ?? '', true);
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
// $ ... $ inline math. The flanking rules are the whole defence: a single
|
|
132
|
+
// `$` is the one delimiter that collides with ordinary text, and this
|
|
133
|
+
// pipeline renders shell output, currency, SQL and awk programs all day.
|
|
134
|
+
//
|
|
135
|
+
// opening $ — not preceded by a word char (checked in `start`, the only
|
|
136
|
+
// place the preceding character is visible), and not
|
|
137
|
+
// followed by a digit, `$` or `{`. The digit guard is what
|
|
138
|
+
// makes `$5`, `$1` and `$10` text; `{` keeps `${HOME}` out.
|
|
139
|
+
// closing $ — not preceded by whitespace, and not followed by a WORD
|
|
140
|
+
// char or `$`. That trailing guard is load-bearing twice
|
|
141
|
+
// over: it rejects `PATH=$PATH:$HOME` (closer followed by
|
|
142
|
+
// `H`) and `a$b$c` (followed by `c`), and it is the reason
|
|
143
|
+
// the rule no longer depends on where `start` happened to
|
|
144
|
+
// land — the tokenizer is anchored at `^` and cannot see
|
|
145
|
+
// the preceding character, so `a$b$c` was math while
|
|
146
|
+
// `ax$b$c` was text on the identical rule.
|
|
147
|
+
//
|
|
148
|
+
// `$n$ = 3` and `$x^2$ benar` still parse: a space after the closer is not
|
|
149
|
+
// a word char.
|
|
150
|
+
{
|
|
151
|
+
name: 'inlineMathDollar',
|
|
152
|
+
level: 'inline',
|
|
153
|
+
start(src: string) {
|
|
154
|
+
const match = /(^|[^\w$])\$(?!\$)(?!\s)/.exec(src);
|
|
155
|
+
return match ? match.index + (match[1]?.length ?? 0) : undefined;
|
|
156
|
+
},
|
|
157
|
+
tokenizer(src: string) {
|
|
158
|
+
const match = /^\$(?![\d${])((?:\\\$|[^$])*?)(?<!\s)\$(?![\w$])/.exec(src);
|
|
159
|
+
return match
|
|
160
|
+
? { type: 'inlineMathDollar', raw: match[0], text: match[1] }
|
|
161
|
+
: undefined;
|
|
162
|
+
},
|
|
163
|
+
renderer(token: TokenLike) {
|
|
164
|
+
return renderMathPlaceholder(token.text ?? '', false);
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A document review as the text the agent receives.
|
|
8
|
+
*
|
|
9
|
+
* The same shape the browser panel's page context uses: the judgements become
|
|
10
|
+
* PROMPT TEXT in the composer draft, never a second store the agent has to be
|
|
11
|
+
* taught to read. Each line names the block by its line range and quotes it, so
|
|
12
|
+
* the agent can find the paragraph without counting, and each mark says which
|
|
13
|
+
* answer was chosen in words (`good`, `needs work`) rather than a glyph alone.
|
|
14
|
+
*
|
|
15
|
+
* The closing instruction is load-bearing: without it, a list of verdicts reads
|
|
16
|
+
* as a description of the document instead of a decision about it — and a
|
|
17
|
+
* `good` block is exactly the instruction "leave this alone".
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { BlockVerdict, DocumentAnnotation } from '@/shared/lib/markdown/blocks/types';
|
|
21
|
+
|
|
22
|
+
/** One `scope\0repo` pair as the prompt spells it: a path a reader can act on. */
|
|
23
|
+
export interface ReviewPromptDocument {
|
|
24
|
+
/** The document's path, relative to the workspace (or nested repo). */
|
|
25
|
+
path: string;
|
|
26
|
+
annotations: readonly Pick<DocumentAnnotation, 'lineStart' | 'lineEnd' | 'verdict' | 'note' | 'quote'>[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const VERDICT_LABEL: Record<BlockVerdict, string> = {
|
|
30
|
+
good: 'good — leave it as it is',
|
|
31
|
+
'needs-work': 'needs work',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function rangeOf(annotation: ReviewPromptDocument['annotations'][number]): string {
|
|
35
|
+
return annotation.lineStart === annotation.lineEnd
|
|
36
|
+
? `L${annotation.lineStart}`
|
|
37
|
+
: `L${annotation.lineStart}-${annotation.lineEnd}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The block this review adds to the draft; empty when nothing was judged.
|
|
42
|
+
*
|
|
43
|
+
* An empty review produces NO text rather than a header claiming zero marks: the
|
|
44
|
+
* button that sends it is disabled in that state, and a stray header would be
|
|
45
|
+
* something the user has to delete before typing.
|
|
46
|
+
*/
|
|
47
|
+
export function formatReviewBlock(document: ReviewPromptDocument): string {
|
|
48
|
+
const marks = document.annotations.filter((annotation) => annotation.verdict === 'good' || annotation.verdict === 'needs-work');
|
|
49
|
+
if (marks.length === 0) return '';
|
|
50
|
+
const lines = marks.map((annotation) => {
|
|
51
|
+
const quote = annotation.quote ? ` «${annotation.quote}»` : '';
|
|
52
|
+
const note = annotation.note.trim();
|
|
53
|
+
return `- ${rangeOf(annotation)}${quote} — ${VERDICT_LABEL[annotation.verdict]}${note ? `: ${note}` : ''}`;
|
|
54
|
+
});
|
|
55
|
+
return [
|
|
56
|
+
`[Review dokumen] ${document.path}`,
|
|
57
|
+
...lines,
|
|
58
|
+
'Ini keputusan user atas blok-blok di atas: blok bertanda "needs work" perlu diperbaiki sesuai catatannya, blok bertanda "good" jangan diubah.',
|
|
59
|
+
].join('\n');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A blank draft gets the block alone; otherwise one blank line separates them. */
|
|
63
|
+
export function appendReviewBlock(previous: string, block: string): string {
|
|
64
|
+
if (!block) return previous;
|
|
65
|
+
if (!previous) return block;
|
|
66
|
+
const separator = previous.endsWith('\n\n') ? '' : previous.endsWith('\n') ? '\n' : '\n\n';
|
|
67
|
+
return `${previous}${separator}${block}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** DOM event a document review dispatches to append its block to the draft. */
|
|
71
|
+
export const REVIEW_INCLUDE_EVENT = 'omp:review-include';
|
|
72
|
+
|
|
73
|
+
/** Hand a finished review to the composer, whichever tree is listening. */
|
|
74
|
+
export function emitReviewBlock(block: string): void {
|
|
75
|
+
if (typeof window === 'undefined' || !block) return;
|
|
76
|
+
window.dispatchEvent(new CustomEvent<string>(REVIEW_INCLUDE_EVENT, { detail: block }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which stored marks still describe a block on screen, and which do not.
|
|
8
|
+
*
|
|
9
|
+
* A mark names its block by content (`type:hash#n`), so editing a block detaches
|
|
10
|
+
* its mark: the stored quote no longer matches anything rendered. That is a
|
|
11
|
+
* real state the reader must SEE — the note is still what they wrote, and the
|
|
12
|
+
* only copy of it — so it is reported as `outdated` with its quote intact and a
|
|
13
|
+
* way to remove it, never deleted behind their back.
|
|
14
|
+
*
|
|
15
|
+
* A mark that matches nothing because the DOCUMENT was not rendered at all (a
|
|
16
|
+
* refused read, an unsupported kind) is a different fact and is not this
|
|
17
|
+
* module's business: the caller only reconciles against a real block list.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { DocumentAnnotation, MdBlock } from '@/shared/lib/markdown/blocks/types';
|
|
21
|
+
|
|
22
|
+
export interface ReconcileResult<T extends DocumentAnnotation> {
|
|
23
|
+
/** Marks whose block is on screen, keyed by block key. */
|
|
24
|
+
attached: Map<string, T>;
|
|
25
|
+
/** Marks whose block is no longer rendered, newest first. */
|
|
26
|
+
outdated: T[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Attach stored marks to the blocks the render produced. */
|
|
30
|
+
export function reconcileAnnotations<T extends DocumentAnnotation>(
|
|
31
|
+
blocks: readonly MdBlock[],
|
|
32
|
+
annotations: readonly T[],
|
|
33
|
+
): ReconcileResult<T> {
|
|
34
|
+
const byKey = new Map(blocks.map((block) => [block.key, block]));
|
|
35
|
+
const attached = new Map<string, T>();
|
|
36
|
+
const outdated: T[] = [];
|
|
37
|
+
|
|
38
|
+
for (const annotation of annotations) {
|
|
39
|
+
if (byKey.has(annotation.blockKey)) attached.set(annotation.blockKey, annotation);
|
|
40
|
+
else outdated.push(annotation);
|
|
41
|
+
}
|
|
42
|
+
outdated.sort((left, right) => right.updatedAt - left.updatedAt);
|
|
43
|
+
return { attached, outdated };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The verdict counts the summary chip prints. */
|
|
47
|
+
export function tallyAnnotations<T extends DocumentAnnotation>(attached: ReadonlyMap<string, T>): { good: number; needsWork: number } {
|
|
48
|
+
let good = 0;
|
|
49
|
+
let needsWork = 0;
|
|
50
|
+
for (const annotation of attached.values()) {
|
|
51
|
+
if (annotation.verdict === 'good') good += 1;
|
|
52
|
+
else needsWork += 1;
|
|
53
|
+
}
|
|
54
|
+
return { good, needsWork };
|
|
55
|
+
}
|