@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,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Write feedback for a settings pane: whether the last save/delete is still in
|
|
8
|
+
* flight, whether it landed, and the server's own sentence when it did not.
|
|
9
|
+
*
|
|
10
|
+
* The panes used to show "Saved successfully" the instant the button was
|
|
11
|
+
* pressed, before the request had answered — so a refused write (a duplicate
|
|
12
|
+
* agent name, a read-only native file, a validator rejecting the draft) showed
|
|
13
|
+
* a success badge over a row that had not changed. The outcome of the write is
|
|
14
|
+
* now the only thing that sets the badge.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useRef, useState } from 'preact/hooks';
|
|
18
|
+
import type { WriteOutcome } from '@/shared/types';
|
|
19
|
+
|
|
20
|
+
export interface WriteFeedback {
|
|
21
|
+
saving: boolean;
|
|
22
|
+
saved: boolean;
|
|
23
|
+
/** The last refusal's sentence; stays until the next write or dismissal. */
|
|
24
|
+
error: string | null;
|
|
25
|
+
dismissError: () => void;
|
|
26
|
+
/** Run one write and report its real outcome. Resolves `true` when it landed. */
|
|
27
|
+
run: (action: () => Promise<WriteOutcome>) => Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SAVED_FLASH_MS = 2000;
|
|
31
|
+
|
|
32
|
+
export function useWriteFeedback(): WriteFeedback {
|
|
33
|
+
const [saving, setSaving] = useState(false);
|
|
34
|
+
const [saved, setSaved] = useState(false);
|
|
35
|
+
const [error, setError] = useState<string | null>(null);
|
|
36
|
+
const flash = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
37
|
+
|
|
38
|
+
const dismissError = useCallback(() => setError(null), []);
|
|
39
|
+
|
|
40
|
+
const run = useCallback(async (action: () => Promise<WriteOutcome>): Promise<boolean> => {
|
|
41
|
+
setSaving(true);
|
|
42
|
+
setError(null);
|
|
43
|
+
clearTimeout(flash.current);
|
|
44
|
+
setSaved(false);
|
|
45
|
+
try {
|
|
46
|
+
const outcome = await action();
|
|
47
|
+
if (!outcome.ok) {
|
|
48
|
+
setError(outcome.error ?? 'The server refused the write.');
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
setSaved(true);
|
|
52
|
+
flash.current = setTimeout(() => setSaved(false), SAVED_FLASH_MS);
|
|
53
|
+
return true;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
56
|
+
return false;
|
|
57
|
+
} finally {
|
|
58
|
+
setSaving(false);
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return { saving, saved, error, dismissError, run };
|
|
63
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The live answers to "can this engine draw the glass material", subscribed.
|
|
8
|
+
*
|
|
9
|
+
* `glassLimits` states the rule; this hook is the only place that ASKS the
|
|
10
|
+
* platform, so the settings control never touches `window` itself.
|
|
11
|
+
*
|
|
12
|
+
* Three facts about the asking:
|
|
13
|
+
*
|
|
14
|
+
* - **Both spellings are tested.** Chromium shipped `backdrop-filter`
|
|
15
|
+
* unprefixed only in 76, and the Android shell's floor is `minSdk 24`; the
|
|
16
|
+
* stylesheets always write the `-webkit-` pair, so the probe tests the pair
|
|
17
|
+
* too. Testing one and not the other reports "unsupported" on a device that
|
|
18
|
+
* renders the frost correctly.
|
|
19
|
+
* - **Computed ONCE.** `CSS.supports` is a parse check on a constant string; it
|
|
20
|
+
* cannot change while the document lives, and calling it per render would be a
|
|
21
|
+
* style recalc for a constant.
|
|
22
|
+
* - **`matchMedia` is SUBSCRIBED.** The OS setting can be toggled while the
|
|
23
|
+
* window is open (System Settings → Accessibility, next to the app), and the
|
|
24
|
+
* media query then flips without a reload — a stale `false` would leave the
|
|
25
|
+
* notice hidden on a window that had just gone opaque.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
29
|
+
import { glassLimits, type GlassLimit } from '@/shared/lib/theme/glass-support';
|
|
30
|
+
|
|
31
|
+
const REDUCED_TRANSPARENCY = '(prefers-reduced-transparency: reduce)';
|
|
32
|
+
|
|
33
|
+
function supportsBackdropFilter(): boolean {
|
|
34
|
+
if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function') return false;
|
|
35
|
+
return (
|
|
36
|
+
CSS.supports('backdrop-filter', 'blur(1px)') ||
|
|
37
|
+
CSS.supports('-webkit-backdrop-filter', 'blur(1px)')
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useGlassLimits(): GlassLimit[] {
|
|
42
|
+
const [reduced, setReduced] = useState(() =>
|
|
43
|
+
typeof window === 'undefined' ? false : window.matchMedia(REDUCED_TRANSPARENCY).matches,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const media = window.matchMedia(REDUCED_TRANSPARENCY);
|
|
48
|
+
const update = () => setReduced(media.matches);
|
|
49
|
+
// The query can change between the initial render and this effect, so read it
|
|
50
|
+
// once on the way in — the same reason `useViewportAtLeast` does.
|
|
51
|
+
update();
|
|
52
|
+
media.addEventListener('change', update);
|
|
53
|
+
return () => media.removeEventListener('change', update);
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
return glassLimits({ backdropFilter: supportsBackdropFilter(), reducedTransparency: reduced });
|
|
57
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The single writer for the brand-mark paint style.
|
|
8
|
+
*
|
|
9
|
+
* Same contract as `surface-style.ts`: an attribute on `<html>`, read by CSS
|
|
10
|
+
* only, because `ProviderIconPlate` is drawn in 26 places across five surfaces
|
|
11
|
+
* and a prop would be 26 chances to miss one. The rules live in
|
|
12
|
+
* `src/client/tailwind.css` (`[data-icon-style]`) and read the brand table in
|
|
13
|
+
* `provider-icon/brand-colors.ts` — never a colour written at a call site.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_ICON_STYLE,
|
|
19
|
+
ICON_STYLE_ATTRIBUTE,
|
|
20
|
+
ICON_STYLE_SETTING_KEY,
|
|
21
|
+
resolveIconStyle,
|
|
22
|
+
} from '@/shared/lib/theme/icon-style';
|
|
23
|
+
import {
|
|
24
|
+
ICON_PAINT_STYLE_ELEMENT_ID,
|
|
25
|
+
iconPaintStyleSheet,
|
|
26
|
+
} from '@/shared/lib/icons/icon-paint-css';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Point the document at `style`.
|
|
30
|
+
*
|
|
31
|
+
* The default is REMOVED rather than written, so the ink rule in CSS is the
|
|
32
|
+
* single statement of what "no attribute" means.
|
|
33
|
+
*/
|
|
34
|
+
export function applyIconStyle(style: unknown): void {
|
|
35
|
+
if (typeof document === 'undefined') return;
|
|
36
|
+
const root = document.documentElement;
|
|
37
|
+
const resolved = resolveIconStyle(style);
|
|
38
|
+
if (resolved === DEFAULT_ICON_STYLE) root.removeAttribute(ICON_STYLE_ATTRIBUTE);
|
|
39
|
+
else root.setAttribute(ICON_STYLE_ATTRIBUTE, resolved);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Apply the stored style before the first render, and make sure the generated
|
|
44
|
+
* icon-paint stylesheet is in the document.
|
|
45
|
+
*
|
|
46
|
+
* The stylesheet is written by the server shell (it is generated from a TS
|
|
47
|
+
* table, so the bundler cannot carry it — the same split `themeStyleSheet` uses).
|
|
48
|
+
* This only repairs a document served by a build that predates it; without the
|
|
49
|
+
* repair, `color` mode would set the attribute and paint nothing.
|
|
50
|
+
*/
|
|
51
|
+
export function initIconStyle(): void {
|
|
52
|
+
if (typeof document !== 'undefined' && !document.getElementById(ICON_PAINT_STYLE_ELEMENT_ID)) {
|
|
53
|
+
const style = document.createElement('style');
|
|
54
|
+
style.id = ICON_PAINT_STYLE_ELEMENT_ID;
|
|
55
|
+
style.textContent = iconPaintStyleSheet();
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
}
|
|
58
|
+
applyIconStyle(readKabmoSetting<unknown>(ICON_STYLE_SETTING_KEY));
|
|
59
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The two post-mount hydration passes a rendered markdown document needs.
|
|
8
|
+
*
|
|
9
|
+
* Extracted from `MarkdownRenderer` for the per-file ceiling, and they belong in
|
|
10
|
+
* a hook because they are not rendering: both observe the container and swap
|
|
11
|
+
* placeholders for real content after the HTML string landed.
|
|
12
|
+
*
|
|
13
|
+
* ## Why an observer, in both cases
|
|
14
|
+
*
|
|
15
|
+
* The container's `innerHTML` can be replaced with an IDENTICAL string — the
|
|
16
|
+
* chat timeline re-renders a message, a preview re-renders after a save — and
|
|
17
|
+
* the effect does not re-run for an unchanged dependency. New placeholders would
|
|
18
|
+
* then sit unhydrated forever. Each hydrator writes only inside the placeholder
|
|
19
|
+
* elements it found, so it never re-triggers its own observer.
|
|
20
|
+
*
|
|
21
|
+
* ## KaTeX is lazy, mermaid is not
|
|
22
|
+
*
|
|
23
|
+
* `marked.ts` emits a `math-pending` span and `katex.ts` swaps it once ~522 kB
|
|
24
|
+
* of JS arrives; a message with no math must never pay for that fetch. Mermaid
|
|
25
|
+
* bakes the palette into its SVG, so every theme write has to re-render it — the
|
|
26
|
+
* trigger is the `data-theme` ATTRIBUTE rather than the `omp:theme-changed`
|
|
27
|
+
* event, because the navbar toggle and the settings modal are both writers and
|
|
28
|
+
* observing the attribute catches all of them.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import type { RefObject } from 'preact';
|
|
32
|
+
import { useEffect, useLayoutEffect } from 'preact/hooks';
|
|
33
|
+
|
|
34
|
+
import { hydrateMathBlocks } from '@/shared/lib/markdown/katex';
|
|
35
|
+
import { hydrateMermaidBlocks } from '@/shared/lib/markdown/mermaid';
|
|
36
|
+
|
|
37
|
+
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
38
|
+
|
|
39
|
+
/** Replace `math-pending` placeholders for real KaTeX markup, when there are any. */
|
|
40
|
+
export function useMathHydration(container: RefObject<HTMLElement>, html: string, active: boolean): void {
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!active || typeof window === 'undefined') return;
|
|
43
|
+
const element = container.current;
|
|
44
|
+
if (!element) return;
|
|
45
|
+
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
const hydrate = async () => {
|
|
48
|
+
if (!element.isConnected) return;
|
|
49
|
+
await hydrateMathBlocks(element);
|
|
50
|
+
if (cancelled) return;
|
|
51
|
+
};
|
|
52
|
+
void hydrate();
|
|
53
|
+
const observer = new MutationObserver(() => {
|
|
54
|
+
if (element.isConnected) void hydrateMathBlocks(element);
|
|
55
|
+
});
|
|
56
|
+
observer.observe(element, { childList: true });
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
cancelled = true;
|
|
60
|
+
observer.disconnect();
|
|
61
|
+
};
|
|
62
|
+
}, [container, active, html]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface MermaidHydrationOptions {
|
|
66
|
+
container: RefObject<HTMLElement>;
|
|
67
|
+
html: string;
|
|
68
|
+
active: boolean;
|
|
69
|
+
/** The block the open diagram viewer was read from, so a theme write can re-read it. */
|
|
70
|
+
diagramBlock: RefObject<HTMLElement | null>;
|
|
71
|
+
/**
|
|
72
|
+
* The block the viewer is showing, re-rendered for the new palette.
|
|
73
|
+
*
|
|
74
|
+
* The caller reads it (`readDiagramBlock`) because the snapshot type belongs
|
|
75
|
+
* to the viewer, not to hydration — this module never needs to know what a
|
|
76
|
+
* diagram IS.
|
|
77
|
+
*/
|
|
78
|
+
onDiagramBlock: (block: HTMLElement) => void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Draw every `mermaid-block` placeholder, and re-draw on a palette change. */
|
|
82
|
+
export function useMermaidHydration({
|
|
83
|
+
container,
|
|
84
|
+
html,
|
|
85
|
+
active,
|
|
86
|
+
diagramBlock,
|
|
87
|
+
onDiagramBlock,
|
|
88
|
+
}: MermaidHydrationOptions): void {
|
|
89
|
+
useIsomorphicLayoutEffect(() => {
|
|
90
|
+
if (!active || typeof window === 'undefined') return;
|
|
91
|
+
const element = container.current;
|
|
92
|
+
if (!element) return;
|
|
93
|
+
|
|
94
|
+
let timer: number | undefined;
|
|
95
|
+
const hydrate = async () => {
|
|
96
|
+
if (!element.isConnected) return;
|
|
97
|
+
await hydrateMermaidBlocks(element);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
void hydrate();
|
|
101
|
+
const observer = new MutationObserver(() => {
|
|
102
|
+
if (element.isConnected) void hydrateMermaidBlocks(element, { cachedOnly: true });
|
|
103
|
+
window.clearTimeout(timer);
|
|
104
|
+
timer = window.setTimeout(() => void hydrate(), 120);
|
|
105
|
+
});
|
|
106
|
+
observer.observe(element, { childList: true });
|
|
107
|
+
|
|
108
|
+
const rehydrateForTheme = async () => {
|
|
109
|
+
await hydrate();
|
|
110
|
+
const block = diagramBlock.current;
|
|
111
|
+
// A timeline re-render can replace the block under an open viewer; keep
|
|
112
|
+
// the last snapshot then rather than closing the viewer on the user.
|
|
113
|
+
if (!block?.isConnected) return;
|
|
114
|
+
onDiagramBlock(block);
|
|
115
|
+
};
|
|
116
|
+
const themeObserver = new MutationObserver(() => void rehydrateForTheme());
|
|
117
|
+
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
|
|
118
|
+
|
|
119
|
+
return () => {
|
|
120
|
+
window.clearTimeout(timer);
|
|
121
|
+
observer.disconnect();
|
|
122
|
+
themeObserver.disconnect();
|
|
123
|
+
};
|
|
124
|
+
}, [container, html, active, diagramBlock, onDiagramBlock]);
|
|
125
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `useStuckHeader`: a sticky element's PINNED state.
|
|
8
|
+
*
|
|
9
|
+
* The rule this pins is the one the sidebar depends on: a sticky header paints a
|
|
10
|
+
* surface only while it is overlapping content. Measured with happy-dom's scroll
|
|
11
|
+
* geometry, because the alternative — trusting the CSS — is what shipped a band
|
|
12
|
+
* across a uniform sidebar twice.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { Window } from 'happy-dom';
|
|
17
|
+
import { h, render } from 'preact';
|
|
18
|
+
import { act } from 'preact/test-utils';
|
|
19
|
+
import { useRef } from 'preact/hooks';
|
|
20
|
+
import { useStuckHeader } from '@/client/hooks/ui/stuck-header';
|
|
21
|
+
|
|
22
|
+
// `requestAnimationFrame` is in the list because the HOOK schedules through it
|
|
23
|
+
// and happy-dom keeps it on its window, not on the runner's global.
|
|
24
|
+
const DOM_GLOBALS = [
|
|
25
|
+
'window',
|
|
26
|
+
'document',
|
|
27
|
+
'navigator',
|
|
28
|
+
'Node',
|
|
29
|
+
'Element',
|
|
30
|
+
'HTMLElement',
|
|
31
|
+
'Event',
|
|
32
|
+
'requestAnimationFrame',
|
|
33
|
+
'cancelAnimationFrame',
|
|
34
|
+
// `preact/test-utils`' `act` reads this one to flush effects.
|
|
35
|
+
'getComputedStyle',
|
|
36
|
+
] as const;
|
|
37
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
38
|
+
|
|
39
|
+
let container: HTMLElement;
|
|
40
|
+
let scroller: HTMLElement;
|
|
41
|
+
/** The header's current top, in container coordinates. Mutated per assertion. */
|
|
42
|
+
let headerTop = 0;
|
|
43
|
+
/** The container's scroll offset. Zero is "at rest" — nothing overlapping. */
|
|
44
|
+
let scrollTop = 0;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
const win = new Window({ url: 'http://localhost' });
|
|
48
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
49
|
+
for (const key of DOM_GLOBALS) {
|
|
50
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = win[key as keyof Window];
|
|
51
|
+
target[key] = win[key as keyof Window];
|
|
52
|
+
}
|
|
53
|
+
// A SYNCHRONOUS frame: the hook coalesces scroll events through
|
|
54
|
+
// `requestAnimationFrame`, and a real one is a timer this suite would have to
|
|
55
|
+
// wait on. Running the callback inline measures the same logic with no clock.
|
|
56
|
+
target.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
|
57
|
+
callback(0);
|
|
58
|
+
return 1;
|
|
59
|
+
}) as typeof requestAnimationFrame;
|
|
60
|
+
target.cancelAnimationFrame = (() => {}) as typeof cancelAnimationFrame;
|
|
61
|
+
|
|
62
|
+
container = document.createElement('div');
|
|
63
|
+
document.body.appendChild(container);
|
|
64
|
+
headerTop = 0;
|
|
65
|
+
scrollTop = 0;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
render(null, container);
|
|
70
|
+
container.remove();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
75
|
+
for (const key of DOM_GLOBALS) {
|
|
76
|
+
if (key in nativeGlobals) target[key] = nativeGlobals[key];
|
|
77
|
+
else delete target[key];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A scroll container with a sticky header inside it.
|
|
83
|
+
*
|
|
84
|
+
* happy-dom has no layout engine, so the geometry is supplied: the container's
|
|
85
|
+
* `getBoundingClientRect().top` and the header's are both overridden, which is
|
|
86
|
+
* exactly what `useStuckHeader` reads. The header's rect is a LIVE getter over
|
|
87
|
+
* `headerTop`, so a test scrolls by changing one number.
|
|
88
|
+
*/
|
|
89
|
+
function mountHarness(): HTMLElement {
|
|
90
|
+
function Probe() {
|
|
91
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
92
|
+
const stuck = useStuckHeader(ref);
|
|
93
|
+
return h('div', { ref, 'data-stuck': stuck ? '' : undefined, 'data-testid': 'header' });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
scroller = document.createElement('div');
|
|
97
|
+
scroller.style.overflowY = 'auto';
|
|
98
|
+
Object.defineProperty(scroller, 'scrollHeight', { value: 1000, configurable: true });
|
|
99
|
+
Object.defineProperty(scroller, 'clientHeight', { value: 300, configurable: true });
|
|
100
|
+
Object.defineProperty(scroller, 'scrollTop', {
|
|
101
|
+
get: () => scrollTop,
|
|
102
|
+
set: (value: number) => {
|
|
103
|
+
scrollTop = value;
|
|
104
|
+
},
|
|
105
|
+
configurable: true,
|
|
106
|
+
});
|
|
107
|
+
scroller.getBoundingClientRect = () => ({ top: 0 }) as DOMRect;
|
|
108
|
+
container.appendChild(scroller);
|
|
109
|
+
|
|
110
|
+
// `act` so the effect runs (and attaches its listener) before the geometry is
|
|
111
|
+
// supplied; without it the mount measurement reads happy-dom's zero rect and
|
|
112
|
+
// no later scroll would be heard.
|
|
113
|
+
act(() => {
|
|
114
|
+
render(h(Probe, null), scroller);
|
|
115
|
+
});
|
|
116
|
+
const header = scroller.querySelector('[data-testid="header"]') as HTMLElement;
|
|
117
|
+
header.getBoundingClientRect = () => ({ top: headerTop, bottom: headerTop + 26 }) as DOMRect;
|
|
118
|
+
return header;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Scroll the harness and wait for the hook's OWN measurement.
|
|
123
|
+
*
|
|
124
|
+
* The hook coalesces scroll events into a `requestAnimationFrame`, so the signal
|
|
125
|
+
* to await is that frame — awaited directly rather than guessed at with a sleep,
|
|
126
|
+
* which would pay real latency per run and still flake under load.
|
|
127
|
+
*/
|
|
128
|
+
/** Move the list: `top` is where the header now sits, `offset` how far it scrolled. */
|
|
129
|
+
function scrollTo(top: number, offset: number) {
|
|
130
|
+
headerTop = top;
|
|
131
|
+
scrollTop = offset;
|
|
132
|
+
act(() => {
|
|
133
|
+
scroller.dispatchEvent(new Event('scroll'));
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
describe('useStuckHeader', () => {
|
|
138
|
+
test('a header below the container top is at rest', () => {
|
|
139
|
+
const header = mountHarness();
|
|
140
|
+
scrollTo(120, 0);
|
|
141
|
+
|
|
142
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('a header at the container top is NOT stuck before the list scrolls', () => {
|
|
146
|
+
// The regression this guards: the geometric test alone is true at
|
|
147
|
+
// `scrollTop: 0` for a header that starts at the top edge, so the surface
|
|
148
|
+
// appeared before anything overlapped it.
|
|
149
|
+
const header = mountHarness();
|
|
150
|
+
headerTop = 0;
|
|
151
|
+
scrollTop = 0;
|
|
152
|
+
act(() => {
|
|
153
|
+
scroller.dispatchEvent(new Event('scroll'));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('a header level with the container top is stuck', () => {
|
|
160
|
+
const header = mountHarness();
|
|
161
|
+
scrollTo(0, 120);
|
|
162
|
+
|
|
163
|
+
expect(header.hasAttribute('data-stuck')).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('a header whose section scrolled past is not painted', () => {
|
|
167
|
+
// It sits entirely above the container: sticky keeps it out of sight, so a
|
|
168
|
+
// fill there is work for a surface nobody can see.
|
|
169
|
+
const header = mountHarness();
|
|
170
|
+
scrollTo(-60, 400);
|
|
171
|
+
|
|
172
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('scrolling re-measures, in both directions', () => {
|
|
176
|
+
const header = mountHarness();
|
|
177
|
+
scrollTo(120, 0);
|
|
178
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
179
|
+
|
|
180
|
+
// The user scrolls the list: the sticky header is now pinned.
|
|
181
|
+
scrollTo(0, 120);
|
|
182
|
+
expect(header.hasAttribute('data-stuck')).toBe(true);
|
|
183
|
+
|
|
184
|
+
// …and scrolls back to the top: it is the first line of the list again.
|
|
185
|
+
scrollTo(40, 0);
|
|
186
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether a `position: sticky` element is currently PINNED.
|
|
8
|
+
*
|
|
9
|
+
* A sticky header needs a surface only while it is overlapping content — that is
|
|
10
|
+
* the moment its text sits on top of a row and needs a field of its own. When it
|
|
11
|
+
* is at rest it is just the first line of the list, and painting it there is what
|
|
12
|
+
* draws a band across a surface that is otherwise uniform.
|
|
13
|
+
*
|
|
14
|
+
* The test is geometric and needs no sentinel: a stuck element's own top edge is
|
|
15
|
+
* at (or above) its scroll container's content top, because that is what sticky
|
|
16
|
+
* positioning does. A sentinel would have to be a second element in the DOM, and
|
|
17
|
+
* every caller would have to place it in the same flow — one more thing that can
|
|
18
|
+
* be forgotten.
|
|
19
|
+
*
|
|
20
|
+
* `root: null`-style viewport maths is deliberately NOT used: the sidebar is an
|
|
21
|
+
* inner scroll container, so the comparison has to be against THAT box.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
25
|
+
import type { RefObject } from 'preact';
|
|
26
|
+
|
|
27
|
+
/** The nearest ancestor that actually scrolls, or null for the document. */
|
|
28
|
+
function scrollParent(element: HTMLElement): HTMLElement | null {
|
|
29
|
+
let node = element.parentElement;
|
|
30
|
+
while (node) {
|
|
31
|
+
const style = getComputedStyle(node);
|
|
32
|
+
if (/(auto|scroll|overlay)/.test(style.overflowY) && node.scrollHeight > node.clientHeight) return node;
|
|
33
|
+
node = node.parentElement;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* True while `ref`'s element is pinned against the top of its scroll container.
|
|
40
|
+
*
|
|
41
|
+
* Re-measured on the container's `scroll`, on resize, and once after mount
|
|
42
|
+
* (layout settles a frame later). A rAF coalesces the scroll events, so a fast
|
|
43
|
+
* scroll costs one measurement per frame rather than one per event.
|
|
44
|
+
*/
|
|
45
|
+
export function useStuckHeader(ref: RefObject<HTMLElement | null>): boolean {
|
|
46
|
+
const [stuck, setStuck] = useState(false);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const element = ref.current;
|
|
50
|
+
if (!element) return;
|
|
51
|
+
const container = scrollParent(element);
|
|
52
|
+
// A boolean rather than the frame handle: the handle is assigned AFTER the
|
|
53
|
+
// callback runs, so a synchronous `requestAnimationFrame` (a test seam, a
|
|
54
|
+
// polyfill) would leave it set and block every later measurement.
|
|
55
|
+
let pending = false;
|
|
56
|
+
|
|
57
|
+
const measure = () => {
|
|
58
|
+
pending = false;
|
|
59
|
+
const box = container ? container.getBoundingClientRect() : { top: 0 };
|
|
60
|
+
// The scroll offset is part of the test, not a detail: an element that
|
|
61
|
+
// starts at the container's top edge satisfies the geometric comparison at
|
|
62
|
+
// `scrollTop: 0` too, so without this the header would paint its stuck
|
|
63
|
+
// surface BEFORE anything scrolled under it — the band, restored by the
|
|
64
|
+
// very fix meant to remove it. "Stuck" means overlapping, and nothing is
|
|
65
|
+
// overlapping at offset zero.
|
|
66
|
+
const scrolled = container ? container.scrollTop > 0 : window.scrollY > 0;
|
|
67
|
+
// 0.5px of slack: sub-pixel scroll offsets otherwise flip the state on
|
|
68
|
+
// every frame while the user scrolls slowly. The lower bound matters too:
|
|
69
|
+
// a header whose section has scrolled past sits entirely above the
|
|
70
|
+
// container, and painting it would be work nobody can see.
|
|
71
|
+
const rect = element.getBoundingClientRect();
|
|
72
|
+
setStuck(scrolled && rect.top <= box.top + 0.5 && rect.bottom > box.top);
|
|
73
|
+
};
|
|
74
|
+
const schedule = () => {
|
|
75
|
+
if (pending) return;
|
|
76
|
+
pending = true;
|
|
77
|
+
requestAnimationFrame(measure);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
measure();
|
|
81
|
+
(container ?? window).addEventListener('scroll', schedule, { passive: true });
|
|
82
|
+
window.addEventListener('resize', schedule);
|
|
83
|
+
return () => {
|
|
84
|
+
pending = false;
|
|
85
|
+
(container ?? window).removeEventListener('scroll', schedule);
|
|
86
|
+
window.removeEventListener('resize', schedule);
|
|
87
|
+
};
|
|
88
|
+
}, [ref]);
|
|
89
|
+
|
|
90
|
+
return stuck;
|
|
91
|
+
}
|