@kabmo-labs/kabmo 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +552 -471
- package/dist/client/static/js/index-hp75vsv9.css +1 -0
- package/dist/client/static/js/{index-cpydmygd.js → index-tc09dtca.js} +897 -886
- package/package.json +1 -1
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +143 -0
- package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
- package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
- package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
- package/src/client/components/common/code-surface/extensions.ts +7 -4
- package/src/client/components/common/code-surface/theme.ts +34 -9
- package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
- package/src/client/components/common/code-surface/whitespace.ts +140 -0
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
- package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
- package/src/client/components/common/markdown-review/index.tsx +129 -0
- package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +92 -44
- package/src/client/components/common/server-control/index.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +120 -0
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
- package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
- package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
- package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
- package/src/client/components/layout/update-popup/index.tsx +5 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
- package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
- package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
- package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
- package/src/client/components/settings/Modal.tsx +9 -3
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +38 -44
- package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
- package/src/client/components/settings/categories/McpSettings.tsx +4 -21
- package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
- package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
- package/src/client/components/settings/categories/SkillSettings.tsx +8 -5
- package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
- package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +14 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
- package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
- package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
- package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
- package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
- package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
- package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
- package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
- package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
- package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
- package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
- package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
- package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
- package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
- package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
- package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
- package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
- package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
- package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
- package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
- package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +236 -0
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +164 -239
- package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +144 -87
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +188 -0
- package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
- package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
- package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
- package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
- package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
- package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
- package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
- package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
- package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
- package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
- package/src/client/components/workspace/browser-panel/index.tsx +50 -4
- package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
- package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
- package/src/client/components/workspace/diff-panel/changes.ts +28 -12
- package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
- package/src/client/components/workspace/diff-panel/merge.ts +21 -1
- package/src/client/components/workspace/editor/Body.tsx +7 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
- package/src/client/components/workspace/editor/FilePane.tsx +12 -0
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
- package/src/client/components/workspace/editor/index.tsx +25 -22
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
- package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
- package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
- package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
- package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
- package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
- package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
- package/src/client/components/workspace/file-explorer/index.tsx +21 -20
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
- package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
- package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
- package/src/client/data/agent-data/builtin.ts +0 -10
- package/src/client/data/agent-data/orchestrator.ts +0 -45
- package/src/client/data/agent-data/specialist.ts +0 -100
- package/src/client/data/mock/token-usage.ts +170 -120
- package/src/client/data/settings/omp-schema.json +123 -4
- package/src/client/data/settings/project.ts +9 -28
- package/src/client/data/settings/skill.ts +6 -32
- package/src/client/hooks/browser/use-annotate.test.ts +143 -0
- package/src/client/hooks/browser/use-annotate.ts +98 -0
- package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
- package/src/client/hooks/browser/use-close-tab.ts +67 -0
- package/src/client/hooks/browser/use-screencast.ts +13 -1
- package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
- package/src/client/hooks/chat/composer/browser-context.ts +40 -16
- package/src/client/hooks/chat/composer/items.test.ts +1 -1
- package/src/client/hooks/chat/composer/review-context.ts +38 -0
- package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
- package/src/client/hooks/chat/composer/use-draft.ts +31 -2
- package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
- package/src/client/hooks/editor/use-document-annotations.ts +124 -0
- package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
- package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
- package/src/client/hooks/editor/use-preview-review.ts +148 -0
- package/src/client/hooks/settings/agents.ts +149 -0
- package/src/client/hooks/settings/crud-list.test.ts +28 -6
- package/src/client/hooks/settings/crud-list.ts +96 -57
- package/src/client/hooks/settings/omp-config.ts +164 -0
- package/src/client/hooks/settings/projects/index.ts +294 -0
- package/src/client/hooks/settings/projects.test.ts +237 -0
- package/src/client/hooks/settings/skill-catalog.ts +101 -9
- package/src/client/hooks/settings/skill-git-import.ts +153 -0
- package/src/client/hooks/settings/useTokenUsage.ts +125 -0
- package/src/client/hooks/settings/write-feedback.test.ts +104 -0
- package/src/client/hooks/settings/write-feedback.ts +63 -0
- package/src/client/hooks/shell/servers.test.ts +166 -0
- package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/updates/index.test.ts +100 -1
- package/src/client/hooks/ui/updates/index.ts +50 -0
- package/src/client/hooks/ui/updates/notes.test.ts +138 -0
- package/src/client/hooks/ui/updates/notes.ts +57 -0
- package/src/client/hooks/ui/updates/shell-download.ts +1 -1
- package/src/client/hooks/ui/updates/shell-update.ts +2 -6
- package/src/client/hooks/workspace/file-row-drag.ts +41 -0
- package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
- package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
- package/src/client/hooks/workspace/root-drop-target.ts +77 -0
- package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
- package/src/client/lib/browser/element-at.test.ts +229 -0
- package/src/client/lib/browser/element-at.ts +139 -0
- package/src/client/lib/desktop/dropped-paths.ts +1 -1
- package/src/client/lib/desktop/titlebar.test.ts +12 -3
- package/src/client/lib/desktop/titlebar.ts +1 -1
- package/src/client/lib/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/lib/shell/desktop.ts +117 -0
- package/src/client/lib/shell/servers.ts +75 -0
- package/src/client/lib/shell/transport.ts +216 -0
- package/src/client/main.tsx +9 -0
- package/src/client/tailwind.css +65 -0
- package/src/server/lib/btw/lifecycle.server.ts +2 -2
- package/src/server/lib/db/schema.ts +7 -0
- package/src/server/lib/db/seed-terminal.test.ts +4 -0
- package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
- package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
- package/src/server/lib/omp/config/agents.ts +231 -61
- package/src/server/lib/omp/config/definitions.test.ts +9 -105
- package/src/server/lib/omp/config/extensions.ts +16 -7
- package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
- package/src/server/lib/omp/config/skill-sources.ts +49 -0
- package/src/server/lib/omp/config/skills-git-install.ts +155 -0
- package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
- package/src/server/lib/omp/config/skills-git.test.ts +220 -0
- package/src/server/lib/omp/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/process.ts +11 -14
- package/src/server/lib/omp/rpc/session-commands.ts +6 -3
- package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
- package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
- package/src/server/lib/omp/rpc/utility.ts +12 -0
- package/src/server/lib/review/schema.server.ts +45 -0
- package/src/server/lib/review/store.server.ts +138 -0
- package/src/server/lib/terminal/attach-replay.test.ts +132 -0
- package/src/server/lib/terminal/output.test.ts +166 -0
- package/src/server/lib/terminal/output.ts +104 -0
- package/src/server/lib/terminal/runtime.server.ts +5 -0
- package/src/server/lib/terminal/send-result.test.ts +33 -0
- package/src/server/lib/terminal/send-result.ts +32 -0
- package/src/server/lib/terminal/session.server.ts +45 -11
- package/src/server/lib/terminal/store-liveness.test.ts +4 -0
- package/src/server/lib/updates/active-notes.test.ts +149 -0
- package/src/server/lib/updates/active-notes.ts +75 -0
- package/src/server/lib/updates/changelog-file.ts +42 -11
- package/src/server/lib/updates/changelog.test.ts +15 -1
- package/src/server/lib/updates/omp.ts +42 -15
- package/src/server/lib/updates/release-url.ts +27 -1
- package/src/server/lib/usage/index-parse.test.ts +200 -0
- package/src/server/lib/usage/index-parse.ts +178 -0
- package/src/server/lib/usage/index-query.server.ts +248 -0
- package/src/server/lib/usage/index-scan.server.ts +343 -0
- package/src/server/lib/usage/index-schema.server.ts +82 -0
- package/src/server/lib/usage/index.test.ts +234 -0
- package/src/server/lib/usage/providers.server.ts +4 -53
- package/src/server/lib/workspace/project-model.server.test.ts +102 -0
- package/src/server/lib/workspace/project-model.server.ts +47 -0
- package/src/server/lib/workspace/project-patch.server.ts +156 -0
- package/src/server/routes/agent/new.ts +8 -1
- package/src/server/routes/browser/index.ts +3 -0
- package/src/server/routes/browser/stream.ts +31 -2
- package/src/server/routes/browser/tabs.test.ts +94 -0
- package/src/server/routes/browser/tabs.ts +85 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/review/bindings.ts +11 -0
- package/src/server/routes/review/index.ts +127 -0
- package/src/server/routes/review/routes.test.ts +191 -0
- package/src/server/routes/settings/agents.test.ts +180 -0
- package/src/server/routes/settings/agents.ts +99 -94
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/projects.ts +53 -19
- package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
- package/src/server/routes/settings/settings-store-routes.test.ts +11 -115
- package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
- package/src/server/routes/settings/skills.test.ts +225 -0
- package/src/server/routes/settings/skills.ts +18 -15
- package/src/server/routes/telemetry/tokens.test.ts +145 -0
- package/src/server/routes/telemetry/tokens.ts +70 -149
- package/src/server/routes/terminal/ws.ts +6 -5
- package/src/server/routes/updates/index.ts +2 -0
- package/src/server/routes/updates/notes.ts +34 -0
- package/src/server/routes/updates/routes.test.ts +49 -0
- package/src/shared/lib/browser/annotate.test.ts +283 -0
- package/src/shared/lib/browser/annotate.ts +231 -0
- package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
- package/src/shared/lib/browser/frame-gate.test.ts +91 -0
- package/src/shared/lib/browser/frame-gate.ts +69 -0
- package/src/shared/lib/browser/frame-params.test.ts +43 -0
- package/src/shared/lib/browser/frame-params.ts +60 -0
- package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
- package/src/shared/lib/browser/frame-pipeline.ts +80 -0
- package/src/shared/lib/browser/page-context.ts +60 -4
- package/src/shared/lib/browser/snapshot.test.ts +115 -0
- package/src/shared/lib/browser/snapshot.ts +112 -0
- package/src/shared/lib/browser/tab-close.test.ts +74 -0
- package/src/shared/lib/browser/tab-close.ts +77 -0
- package/src/shared/lib/browser/viewer.ts +45 -26
- package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
- package/src/shared/lib/chat/tool/artifact.ts +55 -20
- package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
- package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
- package/src/shared/lib/chat/tool/minimized.ts +64 -0
- package/src/shared/lib/chat/tool/summary.test.ts +28 -8
- package/src/shared/lib/chat/tool/summary.ts +3 -32
- package/src/shared/lib/fs/folder-chain.test.ts +81 -1
- package/src/shared/lib/fs/folder-chain.ts +84 -0
- package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
- package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
- package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
- package/src/shared/lib/markdown/blocks/scan.ts +100 -0
- package/src/shared/lib/markdown/blocks/types.ts +62 -0
- package/src/shared/lib/markdown/marked.ts +58 -147
- package/src/shared/lib/markdown/math-extensions.ts +168 -0
- package/src/shared/lib/markdown/review/prompt.ts +77 -0
- package/src/shared/lib/markdown/review/reconcile.ts +55 -0
- package/src/shared/lib/markdown/review/review.test.ts +96 -0
- package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
- package/src/shared/lib/markdown/xml-sections.ts +139 -0
- package/src/shared/lib/models/provider/label.ts +57 -0
- package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
- package/src/shared/lib/omp/config/agent-file.ts +43 -0
- package/src/shared/lib/omp/config/row-value.test.ts +95 -0
- package/src/shared/lib/omp/config/row-value.ts +97 -0
- package/src/shared/lib/omp/config/schema.test.ts +66 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
- package/src/shared/lib/omp/rpc/frame.ts +49 -40
- package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
- package/src/shared/lib/omp/session/job-progress.ts +31 -0
- package/src/shared/lib/omp/session/proc.ts +5 -0
- package/src/shared/lib/omp/session/wait.ts +5 -0
- package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
- package/src/shared/lib/ui/menu-anchor.ts +89 -0
- package/src/shared/lib/ui/mobile-overlay.ts +61 -0
- package/src/shared/lib/ui/svg-scope.test.ts +97 -0
- package/src/shared/lib/ui/svg-scope.ts +134 -0
- package/src/shared/lib/usage/breakdown.test.ts +197 -0
- package/src/shared/lib/usage/breakdown.ts +241 -0
- package/src/shared/lib/usage/range.test.ts +204 -0
- package/src/shared/lib/usage/range.ts +240 -0
- package/src/shared/lib/usage/view.test.ts +85 -0
- package/src/shared/lib/usage/view.ts +74 -0
- package/src/shared/lib/workspace/project-accent.test.ts +69 -0
- package/src/shared/lib/workspace/project-accent.ts +63 -0
- package/src/shared/lib/workspace/project-icon.ts +40 -0
- package/src/shared/lib/workspace/project-model.test.ts +79 -0
- package/src/shared/lib/workspace/project-model.ts +64 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/skill.ts +53 -3
- package/src/shared/types/settings/state.ts +4 -3
- package/src/shared/types/settings/write.ts +6 -0
- package/src/shared/types/tokenUsage.ts +128 -21
- package/src/shared/types/updates.ts +20 -0
- package/src/test-support/file-explorer-disk.test-util.ts +25 -1
- package/src/test-support/file-explorer-drag.test-util.ts +88 -0
- package/src/test-support/file-explorer.test-util.ts +47 -47
- package/dist/client/static/js/index-fjnq2z2d.css +0 -1
- package/src/client/components/common/code-surface/indent-guide.ts +0 -104
- package/src/client/components/common/server-switcher/index.test.tsx +0 -150
- package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
- package/src/client/hooks/desktop/servers.test.ts +0 -73
- package/src/client/lib/desktop/bridge.ts +0 -203
- package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
- package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
- package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
- package/src/server/lib/omp/session/usage/shaping.ts +0 -130
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
- package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
|
@@ -35,6 +35,14 @@ export interface FileTreeEditDeps {
|
|
|
35
35
|
* the only honest way to learn where the row went.
|
|
36
36
|
*/
|
|
37
37
|
reload: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* A rename landed, in the panel's own coordinates.
|
|
40
|
+
*
|
|
41
|
+
* The listing re-keys its expansion set itself; this is for the OTHER
|
|
42
|
+
* per-path state a rename has to move with the row — the panel's unfolded
|
|
43
|
+
* chains. Absent means "nothing else remembers a path".
|
|
44
|
+
*/
|
|
45
|
+
onMoved?: (fromPath: string, toPath: string) => void;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
export interface FileTreeEdits {
|
|
@@ -49,6 +57,7 @@ export function useFileTreeEdits({
|
|
|
49
57
|
setExpandedPaths,
|
|
50
58
|
setStoredExpandedPaths,
|
|
51
59
|
reload,
|
|
60
|
+
onMoved,
|
|
52
61
|
}: FileTreeEditDeps): FileTreeEdits {
|
|
53
62
|
/**
|
|
54
63
|
* Open every folder row that leads to `path`.
|
|
@@ -82,22 +91,30 @@ export function useFileTreeEdits({
|
|
|
82
91
|
* A folder's descendants and every open branch beneath it carry its path as a
|
|
83
92
|
* prefix, so the expansion set is rekeyed in the same step — an open `src`
|
|
84
93
|
* renamed to `lib` must stay open as `lib`, not collapse.
|
|
94
|
+
*
|
|
95
|
+
* The re-key runs BEFORE the local placement is attempted and whatever it
|
|
96
|
+
* answers: an unfolded chain row's inner levels are not in the tree's own
|
|
97
|
+
* coordinates, so a rename of one of them answers "not in this tree" and
|
|
98
|
+
* falls back to a reload — and the paths every other holder of this state
|
|
99
|
+
* remembers (the expansion set, the panel's unfolded chains) have still
|
|
100
|
+
* moved.
|
|
85
101
|
*/
|
|
86
102
|
const moveRenamed = useCallback((fromPath: string, toPath: string) => {
|
|
87
|
-
|
|
88
|
-
if (!tree) {
|
|
89
|
-
reload();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
103
|
+
onMoved?.(fromPath, toPath);
|
|
92
104
|
setExpandedPaths((prev) => {
|
|
93
105
|
const next = rekeyExpansion(prev, fromPath, toPath);
|
|
94
106
|
setStoredExpandedPaths(Array.from(next));
|
|
95
107
|
return next;
|
|
96
108
|
});
|
|
109
|
+
const tree = listing.moveEntry(fromPath, toPath);
|
|
110
|
+
if (!tree) {
|
|
111
|
+
reload();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
97
114
|
// A rename INTO a new folder (`a.ts` → `nested/a.ts`) has the same problem a
|
|
98
115
|
// nested create does: the destination folder is one nobody has opened.
|
|
99
116
|
reveal(toPath, tree);
|
|
100
|
-
}, [listing, reload, reveal, setExpandedPaths, setStoredExpandedPaths]);
|
|
117
|
+
}, [listing, reload, reveal, setExpandedPaths, setStoredExpandedPaths, onMoved]);
|
|
101
118
|
|
|
102
119
|
return { insertCreated, moveRenamed };
|
|
103
120
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Files panel's BACKGROUND as a drop target — the listing root.
|
|
8
|
+
*
|
|
9
|
+
* It is a target like any other row: it is the only way to move an entry back
|
|
10
|
+
* out of a folder, since a drop on a file lands in that file's own directory
|
|
11
|
+
* instead. Two facts decide its shape:
|
|
12
|
+
*
|
|
13
|
+
* - **The tint is the POINTER, not the capability.** `accepts` is true from the
|
|
14
|
+
* instant a drag starts, so tinting on it painted the whole tree blue for the
|
|
15
|
+
* entire gesture and read as "every row is selected". The tint follows the
|
|
16
|
+
* pointer being on the background's own drop area.
|
|
17
|
+
* - **A row between two gaps claims `dragover` with `stopPropagation`**, so the
|
|
18
|
+
* reach that matters here is `dragenter`: it fires whenever the pointer moves
|
|
19
|
+
* off a row and back onto bare background. `dragleave` therefore ignores a
|
|
20
|
+
* move onto a CHILD — the pointer is still inside the scroller, and it is
|
|
21
|
+
* about to be claimed by the row it landed on.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
25
|
+
import type { TargetedDragEvent } from 'preact';
|
|
26
|
+
import type { ClipboardTarget, FileClipboard } from '@/client/hooks/workspace/file-clipboard';
|
|
27
|
+
|
|
28
|
+
export interface RootDropTargetOptions {
|
|
29
|
+
/** The row the tree is currently dragging, or null. */
|
|
30
|
+
dragging: ClipboardTarget | null;
|
|
31
|
+
clipboard: FileClipboard;
|
|
32
|
+
/** The listing root's own identity — `.` and a folder. */
|
|
33
|
+
target: ClipboardTarget;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RootDropTarget {
|
|
37
|
+
/** Whether the background would accept the drag in flight. */
|
|
38
|
+
accepts: boolean;
|
|
39
|
+
/** Whether the pointer is on the background AND it would accept the drag. */
|
|
40
|
+
highlighted: boolean;
|
|
41
|
+
onDragEnter: () => void;
|
|
42
|
+
onDragLeave: (e: TargetedDragEvent<HTMLElement>) => void;
|
|
43
|
+
onDragOver: (e: TargetedDragEvent<HTMLElement>) => void;
|
|
44
|
+
onDrop: (e: TargetedDragEvent<HTMLElement>) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useRootDropTarget({ dragging, clipboard, target }: RootDropTargetOptions): RootDropTarget {
|
|
48
|
+
const accepts = Boolean(dragging) && clipboard.moveRefusalFor(dragging!, target) === null;
|
|
49
|
+
const [hovered, setHovered] = useState(false);
|
|
50
|
+
// A drag that ended (dropped, cancelled, or left the window) leaves nothing
|
|
51
|
+
// hovering, and `dragleave` is not guaranteed for the element it ended on.
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!dragging) setHovered(false);
|
|
54
|
+
}, [dragging]);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
accepts,
|
|
58
|
+
highlighted: hovered && accepts,
|
|
59
|
+
onDragEnter: () => {
|
|
60
|
+
if (dragging) setHovered(true);
|
|
61
|
+
},
|
|
62
|
+
onDragLeave: (e) => {
|
|
63
|
+
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setHovered(false);
|
|
64
|
+
},
|
|
65
|
+
onDragOver: (e) => {
|
|
66
|
+
if (!accepts) return;
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';
|
|
69
|
+
},
|
|
70
|
+
onDrop: (e) => {
|
|
71
|
+
if (!accepts) return;
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
setHovered(false);
|
|
74
|
+
clipboard.move(dragging!, target);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The collapsed folder chains the reader has UNFOLDED, and the expansion that
|
|
8
|
+
* makes the levels they expose visible.
|
|
9
|
+
*
|
|
10
|
+
* A chain row (`dev/src/main/code`) stands for four directories but is one row,
|
|
11
|
+
* so the three levels inside its label have no row: they cannot be dropped on,
|
|
12
|
+
* renamed, or created inside, and a drop on the one row lands in the deepest
|
|
13
|
+
* directory instead. Unfolding turns each level back into a row of its own
|
|
14
|
+
* (`unfoldChains` renders that projection), and this hook owns the set the
|
|
15
|
+
* projection reads plus the three halves that make it usable:
|
|
16
|
+
*
|
|
17
|
+
* - **The levels are OPENED**, because a row that hid the level below it would
|
|
18
|
+
* hide the destination one step further down. They are ordinary folders whose
|
|
19
|
+
* children are already projected, so opening them reads nothing.
|
|
20
|
+
* - **It is an explicit decision, reversed by Fold.** A hover that unfolded
|
|
21
|
+
* does not refold on its own — folding is what CLOSES the levels, so doing it
|
|
22
|
+
* silently would take a branch away from someone midway through a drag.
|
|
23
|
+
* - **It is keyed by the chain's DEEPEST path**, the identity the listing gives
|
|
24
|
+
* the row. A rename re-points that key and every level with it, so an
|
|
25
|
+
* unfolded chain stays unfolded across the rename instead of drawing rows at
|
|
26
|
+
* addresses that no longer exist.
|
|
27
|
+
*
|
|
28
|
+
* The set is tagged with the listing scope it was made in, the way every other
|
|
29
|
+
* path this panel caches is: paths are relative to the listed root, so a chain
|
|
30
|
+
* unfolded in one repository must not unfold a same-named row in the next.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
34
|
+
import { chainLevelPaths } from '@/shared/lib/fs/folder-chain';
|
|
35
|
+
import type { ClipboardTarget } from '@/client/hooks/workspace/file-clipboard';
|
|
36
|
+
|
|
37
|
+
/** The unfolded chains of one listing: deepest path → every level of the chain. */
|
|
38
|
+
interface UnfoldedChainsState {
|
|
39
|
+
scope: string;
|
|
40
|
+
chains: Map<string, string[]>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A chain nothing has unfolded — the answer for every scope not yet touched. */
|
|
44
|
+
const NO_CHAINS: ReadonlySet<string> = new Set();
|
|
45
|
+
|
|
46
|
+
export interface UnfoldedChainsDeps {
|
|
47
|
+
/** The listing scope (`root\0repo`) this set belongs to. */
|
|
48
|
+
scope: string;
|
|
49
|
+
setExpandedPaths: (updater: (prev: Set<string>) => Set<string>) => void;
|
|
50
|
+
setStoredExpandedPaths: (value: string[]) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface UnfoldedChains {
|
|
54
|
+
/** The chain rows (by their deepest path) drawn as one row per directory. */
|
|
55
|
+
unfolded: ReadonlySet<string>;
|
|
56
|
+
/** Unfold the chain `target` names; a plain folder is left alone. */
|
|
57
|
+
unfold: (target: ClipboardTarget) => void;
|
|
58
|
+
/** Fold the chain identified by its deepest path back into the one row it is listed as. */
|
|
59
|
+
fold: (deepestPath: string) => void;
|
|
60
|
+
/** Re-point an unfolded chain at a renamed row, so it stays unfolded. */
|
|
61
|
+
rekey: (fromPath: string, toPath: string) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useUnfoldedChains({ scope, setExpandedPaths, setStoredExpandedPaths }: UnfoldedChainsDeps): UnfoldedChains {
|
|
65
|
+
const [state, setState] = useState<UnfoldedChainsState>({ scope, chains: new Map() });
|
|
66
|
+
|
|
67
|
+
const unfold = useCallback((target: ClipboardTarget) => {
|
|
68
|
+
const levels = chainLevelPaths(target.path, target.name);
|
|
69
|
+
if (!levels) return;
|
|
70
|
+
setState((prev) => {
|
|
71
|
+
const chains = prev.scope === scope ? prev.chains : new Map<string, string[]>();
|
|
72
|
+
// `dragover` fires on every pointer move, so the repeat has to cost
|
|
73
|
+
// nothing at all — not a new Map, not a render.
|
|
74
|
+
const known = chains.get(target.path);
|
|
75
|
+
if (known?.length === levels.length) return prev;
|
|
76
|
+
const next = new Map(chains);
|
|
77
|
+
next.set(target.path, levels);
|
|
78
|
+
return { scope, chains: next };
|
|
79
|
+
});
|
|
80
|
+
const exposed = levels.slice(0, -1);
|
|
81
|
+
setExpandedPaths((prev) => {
|
|
82
|
+
if (exposed.every((folder) => prev.has(folder))) return prev;
|
|
83
|
+
const next = new Set(prev);
|
|
84
|
+
for (const folder of exposed) next.add(folder);
|
|
85
|
+
setStoredExpandedPaths(Array.from(next));
|
|
86
|
+
return next;
|
|
87
|
+
});
|
|
88
|
+
}, [scope, setExpandedPaths, setStoredExpandedPaths]);
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Folding also CLOSES the levels it exposed: the chain row hides them again,
|
|
92
|
+
* so leaving them in the expansion set would have the next refresh read each
|
|
93
|
+
* of them from disk to fill in rows nothing draws.
|
|
94
|
+
*/
|
|
95
|
+
const fold = useCallback((deepestPath: string) => {
|
|
96
|
+
const levels = state.scope === scope ? state.chains.get(deepestPath) : undefined;
|
|
97
|
+
if (!levels) return;
|
|
98
|
+
const exposed = levels.slice(0, -1);
|
|
99
|
+
setState((prev) => {
|
|
100
|
+
if (prev.scope !== scope) return prev;
|
|
101
|
+
const next = new Map(prev.chains);
|
|
102
|
+
next.delete(deepestPath);
|
|
103
|
+
return { scope, chains: next };
|
|
104
|
+
});
|
|
105
|
+
setExpandedPaths((prev) => {
|
|
106
|
+
if (!exposed.some((folder) => prev.has(folder))) return prev;
|
|
107
|
+
const next = new Set(prev);
|
|
108
|
+
for (const folder of exposed) next.delete(folder);
|
|
109
|
+
setStoredExpandedPaths(Array.from(next));
|
|
110
|
+
return next;
|
|
111
|
+
});
|
|
112
|
+
}, [scope, state, setExpandedPaths, setStoredExpandedPaths]);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A chain whose row was renamed keeps its unfold — unless the rename split the
|
|
116
|
+
* chain apart.
|
|
117
|
+
*
|
|
118
|
+
* A chain is a run of contiguous single-child directories, so only two renames
|
|
119
|
+
* preserve it: one of a level ABOVE the chain (every level shifts by the same
|
|
120
|
+
* prefix) and one of its DEEPEST directory (only the last level moves). A
|
|
121
|
+
* rename of a level in BETWEEN leaves `dev/` holding nothing and
|
|
122
|
+
* `dev2/src/main/` holding the rest, which is no longer one row — the entry is
|
|
123
|
+
* dropped rather than re-pointed at a chain that does not exist. The exposed
|
|
124
|
+
* levels are re-opened by name, because the expansion set is keyed by path and
|
|
125
|
+
* the rows that were open just moved.
|
|
126
|
+
*/
|
|
127
|
+
const rekey = useCallback((fromPath: string, toPath: string) => {
|
|
128
|
+
const chains = state.scope === scope ? state.chains : null;
|
|
129
|
+
if (!chains) return;
|
|
130
|
+
const next = new Map<string, string[]>();
|
|
131
|
+
const exposed: string[] = [];
|
|
132
|
+
let changed = false;
|
|
133
|
+
for (const [deepest, levels] of chains) {
|
|
134
|
+
const interior = levels.findIndex((path, index) => path === fromPath && index > 0 && index < levels.length - 1);
|
|
135
|
+
if (interior !== -1) {
|
|
136
|
+
changed = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const moved = levels.map((path) => path === fromPath
|
|
140
|
+
? toPath
|
|
141
|
+
: path.startsWith(`${fromPath}/`) ? `${toPath}${path.slice(fromPath.length)}`
|
|
142
|
+
: path);
|
|
143
|
+
const nextDeepest = moved[moved.length - 1]!;
|
|
144
|
+
if (nextDeepest !== deepest || moved.some((path, index) => path !== levels[index])) changed = true;
|
|
145
|
+
next.set(nextDeepest, moved);
|
|
146
|
+
exposed.push(...moved.slice(0, -1));
|
|
147
|
+
}
|
|
148
|
+
if (!changed) return;
|
|
149
|
+
setState({ scope, chains: next });
|
|
150
|
+
setExpandedPaths((prev) => {
|
|
151
|
+
if (exposed.every((folder) => prev.has(folder))) return prev;
|
|
152
|
+
const nextExpanded = new Set(prev);
|
|
153
|
+
for (const folder of exposed) nextExpanded.add(folder);
|
|
154
|
+
setStoredExpandedPaths(Array.from(nextExpanded));
|
|
155
|
+
return nextExpanded;
|
|
156
|
+
});
|
|
157
|
+
}, [scope, state, setExpandedPaths, setStoredExpandedPaths]);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
unfolded: state.scope === scope && state.chains.size > 0 ? new Set(state.chains.keys()) : NO_CHAINS,
|
|
161
|
+
unfold,
|
|
162
|
+
fold,
|
|
163
|
+
rekey,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reading the element under a mark.
|
|
8
|
+
*
|
|
9
|
+
* Two rules are pinned here, and they are the ones that keep the panel honest:
|
|
10
|
+
*
|
|
11
|
+
* - A cross-origin frame answers a REASON, never an element and never a blank.
|
|
12
|
+
* Measured in Chromium, `127.0.0.1:7101` embedding `127.0.0.1:7102` reports
|
|
13
|
+
* `contentDocument === null`; the same origin reports a live document.
|
|
14
|
+
* - A `<select>` reports its CHOSEN VALUE and option count. That is the fact a
|
|
15
|
+
* screenshot cannot give an agent and a user would have to type out — and it
|
|
16
|
+
* is why the user-browser panel asks for elements at all.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
20
|
+
import { Window } from 'happy-dom';
|
|
21
|
+
|
|
22
|
+
import { describeElement, elementAtPoint, elementPath, frameReadability } from '@/client/lib/browser/element-at';
|
|
23
|
+
|
|
24
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLSelectElement'] as const;
|
|
25
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
26
|
+
|
|
27
|
+
let win: Window;
|
|
28
|
+
/**
|
|
29
|
+
* The fixture document, typed as the runner's `lib.dom` `Document`.
|
|
30
|
+
*
|
|
31
|
+
* The cast is the whole point of the harness: happy-dom's `Document` is a
|
|
32
|
+
* different type from `lib.dom`'s (it lacks `currentCSSZoom`, `part` and the
|
|
33
|
+
* rest), while at runtime it is the object `highlight` reads. Typing it as
|
|
34
|
+
* happy-dom's own class would force every `createElement` result through a
|
|
35
|
+
* second cast.
|
|
36
|
+
*/
|
|
37
|
+
let doc: Document;
|
|
38
|
+
|
|
39
|
+
beforeAll(() => {
|
|
40
|
+
win = new Window({ url: 'http://localhost' });
|
|
41
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
42
|
+
for (const key of DOM_GLOBALS) {
|
|
43
|
+
if (!(key in native)) native[key] = target[key];
|
|
44
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterAll(() => {
|
|
49
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
50
|
+
for (const key of DOM_GLOBALS) {
|
|
51
|
+
if (native[key] === undefined) delete target[key];
|
|
52
|
+
else target[key] = native[key];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** A readable iframe: its `contentDocument` IS the fixture document. */
|
|
57
|
+
function readableFrame(): HTMLIFrameElement {
|
|
58
|
+
return { contentDocument: doc, contentWindow: win } as unknown as HTMLIFrameElement;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A frame whose document this origin cannot touch — the real production case. */
|
|
62
|
+
function crossOriginFrame(): HTMLIFrameElement {
|
|
63
|
+
return { contentDocument: null, contentWindow: null } as unknown as HTMLIFrameElement;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
doc = win.document as unknown as Document;
|
|
68
|
+
doc.body.innerHTML = '';
|
|
69
|
+
// happy-dom has no layout, so the frame's viewport is stated and
|
|
70
|
+
// `elementFromPoint` is answered from the point these cases aim at.
|
|
71
|
+
Object.defineProperty(win, 'innerWidth', { value: 1000, configurable: true });
|
|
72
|
+
Object.defineProperty(win, 'innerHeight', { value: 500, configurable: true });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/** Make `elementFromPoint` answer whatever sits at the given fractions. */
|
|
76
|
+
function hitAt(fractions: { x: number; y: number }, element: Element | null): { asked: string[] } {
|
|
77
|
+
const asked: string[] = [];
|
|
78
|
+
(doc as unknown as Record<string, unknown>).elementFromPoint = (x: number, y: number) => {
|
|
79
|
+
asked.push(`${x},${y}`);
|
|
80
|
+
const matchesX = Math.abs(x - fractions.x * 1000) < 1;
|
|
81
|
+
const matchesY = Math.abs(y - fractions.y * 500) < 1;
|
|
82
|
+
return matchesX && matchesY ? element : null;
|
|
83
|
+
};
|
|
84
|
+
return { asked };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe('frameReadability', () => {
|
|
88
|
+
test('a live document is readable', () => {
|
|
89
|
+
expect(frameReadability(readableFrame())).toBe('readable');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a null document is cross-origin, not an error', () => {
|
|
93
|
+
expect(frameReadability(crossOriginFrame())).toBe('cross-origin');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a frame that throws while being read is treated as cross-origin', () => {
|
|
97
|
+
const trap = Object.defineProperty({}, 'contentDocument', {
|
|
98
|
+
get() {
|
|
99
|
+
throw new Error('SecurityError');
|
|
100
|
+
},
|
|
101
|
+
}) as unknown as HTMLIFrameElement;
|
|
102
|
+
expect(frameReadability(trap)).toBe('cross-origin');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('no frame at all is its own reason', () => {
|
|
106
|
+
expect(frameReadability(null)).toBe('no-frame');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('elementAtPoint', () => {
|
|
111
|
+
test('a cross-origin frame answers a reason and never guesses an element', () => {
|
|
112
|
+
const result = elementAtPoint(crossOriginFrame(), { x: 0.5, y: 0.5 });
|
|
113
|
+
expect(result).toEqual({ ok: false, reason: 'cross-origin' });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('a mark over empty space is no-element, which is not the same fact', () => {
|
|
117
|
+
hitAt({ x: 0.5, y: 0.5 }, null);
|
|
118
|
+
expect(elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 })).toEqual({ ok: false, reason: 'no-element' });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('the marked point maps onto the FRAME viewport, not the panel box', () => {
|
|
122
|
+
const button = doc.createElement('button');
|
|
123
|
+
button.id = 'pay';
|
|
124
|
+
doc.body.appendChild(button);
|
|
125
|
+
const probe = hitAt({ x: 0.25, y: 0.4 }, button);
|
|
126
|
+
const result = elementAtPoint(readableFrame(), { x: 0.25, y: 0.4 });
|
|
127
|
+
expect(result.ok).toBe(true);
|
|
128
|
+
// 25% of a 1000px viewport, 40% of a 500px one.
|
|
129
|
+
expect(probe.asked).toEqual(['250,200']);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('a section reports its aria-label in the path', () => {
|
|
133
|
+
const section = doc.createElement('section');
|
|
134
|
+
section.setAttribute('aria-label', 'Ringkasan pesanan');
|
|
135
|
+
doc.body.appendChild(section);
|
|
136
|
+
hitAt({ x: 0.5, y: 0.5 }, section);
|
|
137
|
+
const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
|
|
138
|
+
expect(result.ok).toBe(true);
|
|
139
|
+
if (!result.ok) return;
|
|
140
|
+
expect(result.element.path).toContain('section[aria-label="Ringkasan pesanan"]');
|
|
141
|
+
expect(result.element.tag).toBe('section');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('a select reports its chosen value and option count', () => {
|
|
145
|
+
const select = doc.createElement('select');
|
|
146
|
+
select.id = 'prov';
|
|
147
|
+
for (const name of ['Aceh', 'Jawa Barat', 'Bali']) {
|
|
148
|
+
const option = doc.createElement('option');
|
|
149
|
+
option.value = name.toLowerCase();
|
|
150
|
+
option.textContent = name;
|
|
151
|
+
select.appendChild(option);
|
|
152
|
+
}
|
|
153
|
+
select.value = 'jawa barat';
|
|
154
|
+
doc.body.appendChild(select);
|
|
155
|
+
hitAt({ x: 0.3, y: 0.3 }, select);
|
|
156
|
+
const result = elementAtPoint(readableFrame(), { x: 0.3, y: 0.3 });
|
|
157
|
+
expect(result.ok).toBe(true);
|
|
158
|
+
if (!result.ok) return;
|
|
159
|
+
expect(result.element.tag).toBe('select');
|
|
160
|
+
expect(result.element.state).toContain('nilai "Jawa Barat"');
|
|
161
|
+
expect(result.element.state).toContain('3 opsi');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('a disabled control says so, which is the bug users report most', () => {
|
|
165
|
+
const button = doc.createElement('button');
|
|
166
|
+
button.textContent = 'Bayar';
|
|
167
|
+
button.setAttribute('disabled', '');
|
|
168
|
+
doc.body.appendChild(button);
|
|
169
|
+
hitAt({ x: 0.5, y: 0.5 }, button);
|
|
170
|
+
const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
|
|
171
|
+
expect(result.ok).toBe(true);
|
|
172
|
+
if (!result.ok) return;
|
|
173
|
+
expect(result.element.state).toContain('nonaktif');
|
|
174
|
+
expect(result.element.text).toBe('Bayar');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('a password input never reports its value', () => {
|
|
178
|
+
const input = doc.createElement('input');
|
|
179
|
+
input.type = 'password';
|
|
180
|
+
input.value = 'rahasia-sekali';
|
|
181
|
+
doc.body.appendChild(input);
|
|
182
|
+
hitAt({ x: 0.5, y: 0.5 }, input);
|
|
183
|
+
const result = elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 });
|
|
184
|
+
expect(result.ok).toBe(true);
|
|
185
|
+
if (!result.ok) return;
|
|
186
|
+
expect(JSON.stringify(result.element)).not.toContain('rahasia-sekali');
|
|
187
|
+
expect(result.element.state).toContain('tipe password');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('body and html are not "an element under the mark"', () => {
|
|
191
|
+
hitAt({ x: 0.5, y: 0.5 }, doc.body);
|
|
192
|
+
expect(elementAtPoint(readableFrame(), { x: 0.5, y: 0.5 })).toEqual({ ok: false, reason: 'no-element' });
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('elementPath', () => {
|
|
197
|
+
test('keeps at most four levels and stops at html', () => {
|
|
198
|
+
const outer = doc.createElement('main');
|
|
199
|
+
const middle = doc.createElement('section');
|
|
200
|
+
const inner = doc.createElement('div');
|
|
201
|
+
const leaf = doc.createElement('button');
|
|
202
|
+
inner.appendChild(leaf);
|
|
203
|
+
middle.appendChild(inner);
|
|
204
|
+
outer.appendChild(middle);
|
|
205
|
+
doc.body.appendChild(outer);
|
|
206
|
+
const path = elementPath(leaf);
|
|
207
|
+
expect(path.split(' > ')).toHaveLength(4);
|
|
208
|
+
expect(path.endsWith('button')).toBe(true);
|
|
209
|
+
expect(path).not.toContain('html');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('an id wins over a tag alone', () => {
|
|
213
|
+
const node = doc.createElement('div');
|
|
214
|
+
node.id = 'cart';
|
|
215
|
+
doc.body.appendChild(node);
|
|
216
|
+
expect(elementPath(node)).toContain('div#cart');
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('describeElement', () => {
|
|
221
|
+
test('collapses whitespace and cuts long text', () => {
|
|
222
|
+
const node = doc.createElement('p');
|
|
223
|
+
node.textContent = ` ${'kata '.repeat(40)} `;
|
|
224
|
+
doc.body.appendChild(node);
|
|
225
|
+
const info = describeElement(node);
|
|
226
|
+
expect(info.text?.length).toBeLessThanOrEqual(60);
|
|
227
|
+
expect(info.text?.startsWith('kata kata')).toBe(true);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reading what is under a mark, when the page allows it at all.
|
|
8
|
+
*
|
|
9
|
+
* The panel renders the user's page in an iframe, and a real dev server is a
|
|
10
|
+
* DIFFERENT ORIGIN from Kabmo even on the same host: measured in Chromium, a
|
|
11
|
+
* page on `127.0.0.1:7101` embedding `127.0.0.1:7102` reports
|
|
12
|
+
* `contentDocument === null` (no throw — the check is free), while the same
|
|
13
|
+
* origin reports a live document whose `elementFromPoint` answers `H2`.
|
|
14
|
+
*
|
|
15
|
+
* So this module has exactly two honest outcomes, and it never guesses:
|
|
16
|
+
* an element, or a stated reason. A mark with no element is still a complete
|
|
17
|
+
* mark — the user's label and note carry it — and the prompt says the page was
|
|
18
|
+
* not readable instead of silently looking less capable.
|
|
19
|
+
*
|
|
20
|
+
* Coordinates arrive normalized to the panel (0..1) because that is what the
|
|
21
|
+
* overlay stores. Inside the frame they map onto the frame's own viewport,
|
|
22
|
+
* which is the one box `zoom` and a viewport preset never change the meaning of.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { AnnotateElement, AnnotatePoint } from '@/shared/types';
|
|
26
|
+
|
|
27
|
+
/** Why a mark carries no element, or that it does. */
|
|
28
|
+
export type ElementAtResult =
|
|
29
|
+
| { ok: true; element: AnnotateElement }
|
|
30
|
+
| { ok: false; reason: 'no-frame' | 'cross-origin' | 'no-element' };
|
|
31
|
+
|
|
32
|
+
/** Longest visible text kept from a marked element, in UTF-16 units. */
|
|
33
|
+
const ELEMENT_TEXT_MAX_LEN = 60;
|
|
34
|
+
/** Levels of ancestry kept in a path; deeper paths stop telling the agent more. */
|
|
35
|
+
const ELEMENT_PATH_MAX_DEPTH = 4;
|
|
36
|
+
|
|
37
|
+
/** Whether the frame's document is readable at all — the whole game for this module. */
|
|
38
|
+
export function frameReadability(frame: HTMLIFrameElement | null): 'readable' | 'cross-origin' | 'no-frame' {
|
|
39
|
+
if (!frame) return 'no-frame';
|
|
40
|
+
try {
|
|
41
|
+
return frame.contentDocument ? 'readable' : 'cross-origin';
|
|
42
|
+
} catch {
|
|
43
|
+
// A frame that throws is as unreadable as one that answers null.
|
|
44
|
+
return 'cross-origin';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Collapse whitespace and cut to the stored maximum, ending with an ellipsis. */
|
|
49
|
+
function shortText(value: string): string {
|
|
50
|
+
const collapsed = value.replace(/\s+/g, ' ').trim();
|
|
51
|
+
return collapsed.length > ELEMENT_TEXT_MAX_LEN
|
|
52
|
+
? `${collapsed.slice(0, ELEMENT_TEXT_MAX_LEN - 1)}…`
|
|
53
|
+
: collapsed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One step of a path: id wins, then the one identifying attribute, then the tag. */
|
|
57
|
+
function pathStep(element: Element): string {
|
|
58
|
+
const tag = element.tagName.toLowerCase();
|
|
59
|
+
if (element.id) return `${tag}#${element.id}`;
|
|
60
|
+
for (const attribute of ['data-testid', 'data-test', 'aria-label']) {
|
|
61
|
+
const value = element.getAttribute(attribute);
|
|
62
|
+
if (value) return `${tag}[${attribute}="${shortText(value)}"]`;
|
|
63
|
+
}
|
|
64
|
+
const role = element.getAttribute('role');
|
|
65
|
+
if (role) return `${tag}[role="${role}"]`;
|
|
66
|
+
return tag;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `html > body > section … > select`, at most `ELEMENT_PATH_MAX_DEPTH` steps. */
|
|
70
|
+
export function elementPath(element: Element): string {
|
|
71
|
+
const steps: string[] = [];
|
|
72
|
+
let current: Element | null = element;
|
|
73
|
+
while (current && steps.length < ELEMENT_PATH_MAX_DEPTH) {
|
|
74
|
+
if (current.tagName.toLowerCase() === 'html') break;
|
|
75
|
+
steps.unshift(pathStep(current));
|
|
76
|
+
current = current.parentElement;
|
|
77
|
+
}
|
|
78
|
+
return steps.join(' > ');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The state a form control is in — the part a screenshot could not tell the
|
|
83
|
+
* agent and a user would have to type out by hand.
|
|
84
|
+
*/
|
|
85
|
+
function controlState(element: Element): string | undefined {
|
|
86
|
+
const parts: string[] = [];
|
|
87
|
+
if ((element as HTMLInputElement).disabled) parts.push('nonaktif');
|
|
88
|
+
if (element instanceof HTMLSelectElement || element.tagName.toLowerCase() === 'select') {
|
|
89
|
+
const select = element as HTMLSelectElement;
|
|
90
|
+
const chosen = select.selectedOptions?.[0];
|
|
91
|
+
const value = chosen?.textContent?.trim() || select.value;
|
|
92
|
+
if (value) parts.push(`nilai "${shortText(value)}"`);
|
|
93
|
+
const count = select.options?.length ?? 0;
|
|
94
|
+
if (count > 0) parts.push(`${count} opsi`);
|
|
95
|
+
} else if (element.tagName.toLowerCase() === 'input') {
|
|
96
|
+
const input = element as HTMLInputElement;
|
|
97
|
+
if (input.type) parts.push(`tipe ${input.type}`);
|
|
98
|
+
// A password's value is never read; a placeholder is what the user sees.
|
|
99
|
+
if (input.type !== 'password' && input.placeholder) parts.push(`placeholder "${shortText(input.placeholder)}"`);
|
|
100
|
+
}
|
|
101
|
+
return parts.length > 0 ? parts.join(', ') : undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The element summary, without the coordinate work. */
|
|
105
|
+
export function describeElement(element: Element): AnnotateElement {
|
|
106
|
+
const info: AnnotateElement = { path: elementPath(element), tag: element.tagName.toLowerCase() };
|
|
107
|
+
const role = element.getAttribute('role');
|
|
108
|
+
if (role) info.role = role;
|
|
109
|
+
const text = shortText((element as HTMLElement).innerText ?? element.textContent ?? '');
|
|
110
|
+
if (text) info.text = text;
|
|
111
|
+
const state = controlState(element);
|
|
112
|
+
if (state) info.state = state;
|
|
113
|
+
return info;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The element under a normalized point of the panel.
|
|
118
|
+
*
|
|
119
|
+
* `no-element` is a real answer: a mark over empty space has nothing beneath it,
|
|
120
|
+
* and that is not the same fact as an unreadable page.
|
|
121
|
+
*/
|
|
122
|
+
export function elementAtPoint(frame: HTMLIFrameElement | null, point: AnnotatePoint): ElementAtResult {
|
|
123
|
+
const readability = frameReadability(frame);
|
|
124
|
+
if (readability !== 'readable') return { ok: false, reason: readability };
|
|
125
|
+
const win = frame!.contentWindow;
|
|
126
|
+
const doc = frame!.contentDocument;
|
|
127
|
+
if (!win || !doc) return { ok: false, reason: 'cross-origin' };
|
|
128
|
+
try {
|
|
129
|
+
// The frame's own viewport is the box the normalized point is a fraction of;
|
|
130
|
+
// the panel's CSS zoom and its viewport preset never enter this mapping.
|
|
131
|
+
const x = Math.min(Math.max(point.x, 0), 1) * win.innerWidth;
|
|
132
|
+
const y = Math.min(Math.max(point.y, 0), 1) * win.innerHeight;
|
|
133
|
+
const hit = doc.elementFromPoint(x, y);
|
|
134
|
+
if (!hit || hit === doc.documentElement || hit === doc.body) return { ok: false, reason: 'no-element' };
|
|
135
|
+
return { ok: true, element: describeElement(hit) };
|
|
136
|
+
} catch {
|
|
137
|
+
return { ok: false, reason: 'cross-origin' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* wrong file later. The clock is the shell's own, and it runs on this machine.
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
|
-
import { isDesktopShell } from '@/client/lib/
|
|
41
|
+
import { isDesktopShell } from '@/client/lib/shell/transport';
|
|
42
42
|
|
|
43
43
|
/** What the shell answers with. */
|
|
44
44
|
export interface ShellDroppedPaths {
|