@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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The frame pipeline between the CDP reader and the SSE stream: one place that
|
|
8
|
+
* decides WHICH picture the panel gets, and one that decides how often.
|
|
9
|
+
*
|
|
10
|
+
* Both halves exist because a screencast alone cannot be trusted to produce a
|
|
11
|
+
* first frame. Chromium only pushes `Page.screencastFrame` when the page paints,
|
|
12
|
+
* so an idle tab — the normal state of a tab an agent finished with — sends
|
|
13
|
+
* nothing and the panel sits on "Menunggu frame pertama dari browser…" forever.
|
|
14
|
+
* Measured on Chromium 1248: a static page attached to and left alone delivered
|
|
15
|
+
* zero frames at any `everyNthFrame`, while `Page.captureScreenshot` answered in
|
|
16
|
+
* 8–40 ms with the page's real pixels, background tab or not (`snapshot.ts`).
|
|
17
|
+
*
|
|
18
|
+
* So the pipeline is: a snapshot seeds the view while the page has painted
|
|
19
|
+
* nothing for us, a live frame always beats a snapshot that is still in flight,
|
|
20
|
+
* and the rate gate defers — never discards — the newest frame.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { CdpConnection } from '@/shared/lib/browser/cdp';
|
|
24
|
+
import { FRAME_MIN_INTERVAL_MS } from '@/shared/lib/browser/frame-params';
|
|
25
|
+
import { createFrameGate } from '@/shared/lib/browser/frame-gate';
|
|
26
|
+
import { createFrameSeeder } from '@/shared/lib/browser/snapshot';
|
|
27
|
+
import type { BrowserViewFrame } from '@/shared/types';
|
|
28
|
+
|
|
29
|
+
export interface FramePipeline {
|
|
30
|
+
/** The attached tab changed: forget the pixels and the clock. */
|
|
31
|
+
reset: () => void;
|
|
32
|
+
/** A `Page.screencastFrame` arrived for the attached tab. */
|
|
33
|
+
pushLive: (frame: BrowserViewFrame) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Take a snapshot unless a picture has already crossed downstream. Safe to
|
|
36
|
+
* call from the poll loop: a capture already in flight is not stacked.
|
|
37
|
+
*/
|
|
38
|
+
seed: () => void;
|
|
39
|
+
/** A load settled: the new page counts as unpainted, so seed again. */
|
|
40
|
+
seedAfterLoad: () => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** `readAttached` is null while nothing is attached (no snapshot possible). */
|
|
44
|
+
export function createFramePipeline(
|
|
45
|
+
conn: CdpConnection,
|
|
46
|
+
readAttached: () => { sessionId: string; targetId: string } | null,
|
|
47
|
+
emit: (frame: BrowserViewFrame) => void,
|
|
48
|
+
): FramePipeline {
|
|
49
|
+
// Whether any picture (snapshot or live) has crossed downstream for the
|
|
50
|
+
// attached page. Only the downstream sink sets it, so a frame the rate gate
|
|
51
|
+
// is still holding counts as delivered — it will land within a frame budget.
|
|
52
|
+
let painted = false;
|
|
53
|
+
const deliver = (frame: BrowserViewFrame): void => {
|
|
54
|
+
painted = true;
|
|
55
|
+
emit(frame);
|
|
56
|
+
};
|
|
57
|
+
const gate = createFrameGate(deliver, FRAME_MIN_INTERVAL_MS);
|
|
58
|
+
const seeder = createFrameSeeder(conn, readAttached, deliver);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
reset: () => {
|
|
62
|
+
painted = false;
|
|
63
|
+
gate.reset();
|
|
64
|
+
seeder.invalidate();
|
|
65
|
+
},
|
|
66
|
+
pushLive: (frame) => {
|
|
67
|
+
// A live frame is newer than any snapshot still in flight: cancel it.
|
|
68
|
+
seeder.invalidate();
|
|
69
|
+
gate.push(frame);
|
|
70
|
+
},
|
|
71
|
+
seed: () => {
|
|
72
|
+
if (painted) return;
|
|
73
|
+
seeder.seed();
|
|
74
|
+
},
|
|
75
|
+
seedAfterLoad: () => {
|
|
76
|
+
painted = false;
|
|
77
|
+
seeder.seed();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -4,17 +4,73 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Sibling-panel bridge that hands
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Sibling-panel bridge that hands a browser panel's page to the chat composer.
|
|
8
|
+
*
|
|
9
|
+
* The panel and the chat timeline are separate trees, so the page travels as a
|
|
10
|
+
* DOM event rather than shared React state. This module owns BOTH halves of
|
|
11
|
+
* that contract: the event, and the exact text a page context becomes in the
|
|
12
|
+
* draft (`formatPageContextBlock`). The formatter lives here rather than in the
|
|
13
|
+
* listener because the same block is read back by tests and by anyone
|
|
14
|
+
* re-dispatching the event; two spellings of it is how the shared page and the
|
|
15
|
+
* annotated page start saying different things.
|
|
10
16
|
*/
|
|
11
17
|
|
|
12
18
|
import type { BrowserPageContext } from '@/shared/types';
|
|
19
|
+
import { describeAnnotations } from '@/shared/lib/browser/annotate';
|
|
13
20
|
|
|
14
|
-
/** DOM event the
|
|
21
|
+
/** DOM event the browser panels dispatch to append page context to the draft. */
|
|
15
22
|
export const BROWSER_INCLUDE_PAGE_EVENT = 'omp:browser-include-page';
|
|
16
23
|
|
|
17
24
|
export function emitBrowserPageContext(detail: BrowserPageContext): void {
|
|
18
25
|
if (typeof window === 'undefined') return;
|
|
19
26
|
window.dispatchEvent(new CustomEvent<BrowserPageContext>(BROWSER_INCLUDE_PAGE_EVENT, { detail }));
|
|
20
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The block a page context adds to the composer draft.
|
|
31
|
+
*
|
|
32
|
+
* The trailing instruction is what makes a bare URL useful: the agent's browser
|
|
33
|
+
* is its own, so "continue from this page" would otherwise be a claim about a
|
|
34
|
+
* page the agent never loaded. With marks attached the block also states that
|
|
35
|
+
* only the user can see the page — the marks are coordinates, not a picture —
|
|
36
|
+
* so the agent knows to open the URL itself before acting.
|
|
37
|
+
*/
|
|
38
|
+
export function formatPageContextBlock(detail: BrowserPageContext): string {
|
|
39
|
+
const lines = ['[Konteks halaman browser]', `URL: ${detail.url}`];
|
|
40
|
+
if (detail.title) lines.push(`Judul: ${detail.title}`);
|
|
41
|
+
|
|
42
|
+
const panel = detail.panel;
|
|
43
|
+
const description = detail.annotations && panel
|
|
44
|
+
? describeAnnotations(detail.annotations, panel)
|
|
45
|
+
: [];
|
|
46
|
+
if (panel && detail.annotations) {
|
|
47
|
+
lines.push(`Panel: ${panel.viewportMode} ${Math.round(panel.width)}×${Math.round(panel.height)} px @${panel.zoom}%`);
|
|
48
|
+
}
|
|
49
|
+
if (description.length > 0 && panel) {
|
|
50
|
+
lines.push(`Anotasi (${description.length}):`, ...description);
|
|
51
|
+
lines.push('Halaman ini hanya terlihat oleh user — buka URL di atas sendiri sebelum mengubah apa pun.');
|
|
52
|
+
// The coordinates are fractions of the panel the user was looking at, not
|
|
53
|
+
// of whatever viewport the agent opens. Saying so is what lets the agent
|
|
54
|
+
// resolve them (`elementFromPoint` at the same box, or scaled) instead of
|
|
55
|
+
// treating a percentage as an absolute position.
|
|
56
|
+
lines.push(
|
|
57
|
+
`Koordinat relatif ke viewport ${Math.round(panel.width)}×${Math.round(panel.height)} px; pakai ukuran yang sama saat membuka halaman ini, lalu cari elemennya di titik itu.`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
lines.push('(Lanjutkan dari halaman ini.)');
|
|
61
|
+
return lines.join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Append one page-context block to an existing draft.
|
|
66
|
+
*
|
|
67
|
+
* A blank draft gets the block alone; otherwise it is separated by one blank
|
|
68
|
+
* line, so two "include page" clicks read as two blocks instead of one run-on
|
|
69
|
+
* paragraph.
|
|
70
|
+
*/
|
|
71
|
+
export function appendPageContext(previous: string, detail: BrowserPageContext): string {
|
|
72
|
+
const block = formatPageContextBlock(detail);
|
|
73
|
+
if (!previous) return block;
|
|
74
|
+
const separator = previous.endsWith('\n\n') ? '' : previous.endsWith('\n') ? '\n' : '\n\n';
|
|
75
|
+
return `${previous}${separator}${block}`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The snapshot that seeds the panel.
|
|
8
|
+
*
|
|
9
|
+
* `Page.startScreencast` pushes a frame only when the page PAINTS, so an idle
|
|
10
|
+
* tab sends nothing and the panel waited on "Menunggu frame pertama dari
|
|
11
|
+
* browser…" indefinitely (measured on Chromium 1248 for a static page, and for
|
|
12
|
+
* a page that changed once and went idle — see `frame-pipeline.ts`). The
|
|
13
|
+
* snapshot is the fix, and these pin its two contracts: it is boxed like the
|
|
14
|
+
* screencast, and a live frame that lands first wins.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from 'bun:test';
|
|
18
|
+
|
|
19
|
+
import type { CdpConnection } from '@/shared/lib/browser/cdp';
|
|
20
|
+
import type { FrameSeeder } from '@/shared/lib/browser/snapshot';
|
|
21
|
+
import { createFrameSeeder } from '@/shared/lib/browser/snapshot';
|
|
22
|
+
import type { BrowserViewFrame } from '@/shared/types';
|
|
23
|
+
|
|
24
|
+
type Reply = unknown | Error;
|
|
25
|
+
|
|
26
|
+
/** Minimal CDP connection: answers from a table, records what was asked. */
|
|
27
|
+
function fakeConnection(replies: Record<string, Reply>) {
|
|
28
|
+
const sent: Array<{ method: string; params: Record<string, unknown>; sessionId?: string }> = [];
|
|
29
|
+
const conn = {
|
|
30
|
+
send: (method: string, params: Record<string, unknown> = {}, sessionId?: string) => {
|
|
31
|
+
sent.push({ method, params, sessionId });
|
|
32
|
+
const reply = replies[method];
|
|
33
|
+
return reply instanceof Error ? Promise.reject(reply) : Promise.resolve(reply);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return { conn: conn as unknown as CdpConnection, sent };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ATTACHED = { sessionId: 'S1', targetId: 'T1' };
|
|
40
|
+
|
|
41
|
+
async function settle(): Promise<void> {
|
|
42
|
+
for (let i = 0; i < 8; i += 1) await Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('createFrameSeeder', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.useFakeTimers();
|
|
48
|
+
jest.setSystemTime(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
jest.useRealTimers();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function seeder(conn: CdpConnection, frames: BrowserViewFrame[], attached: typeof ATTACHED | null = ATTACHED): FrameSeeder {
|
|
56
|
+
return createFrameSeeder(conn, () => attached, (frame) => frames.push(frame));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test('captures the attached page clipped and scaled into the frame box', async () => {
|
|
60
|
+
const { conn, sent } = fakeConnection({
|
|
61
|
+
'Page.getLayoutMetrics': { cssVisualViewport: { clientWidth: 1600, clientHeight: 1000 } },
|
|
62
|
+
'Page.captureScreenshot': { data: 'SNAP' },
|
|
63
|
+
});
|
|
64
|
+
const frames: BrowserViewFrame[] = [];
|
|
65
|
+
seeder(conn, frames).seed();
|
|
66
|
+
await settle();
|
|
67
|
+
const capture = sent.find((entry) => entry.method === 'Page.captureScreenshot');
|
|
68
|
+
expect(capture?.params).toEqual({
|
|
69
|
+
format: 'jpeg',
|
|
70
|
+
quality: 60,
|
|
71
|
+
clip: { x: 0, y: 0, width: 1600, height: 1000, scale: 0.8 },
|
|
72
|
+
captureBeyondViewport: false,
|
|
73
|
+
});
|
|
74
|
+
expect(capture?.sessionId).toBe('S1');
|
|
75
|
+
expect(frames).toEqual([{ data: 'SNAP', mimeType: 'image/jpeg', targetId: 'T1' }]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('captures without a clip when the page will not report a viewport', async () => {
|
|
79
|
+
const { conn, sent } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
|
|
80
|
+
const frames: BrowserViewFrame[] = [];
|
|
81
|
+
seeder(conn, frames).seed();
|
|
82
|
+
await settle();
|
|
83
|
+
const capture = sent.find((entry) => entry.method === 'Page.captureScreenshot');
|
|
84
|
+
expect(capture?.params).toEqual({ format: 'jpeg', quality: 60, captureBeyondViewport: false });
|
|
85
|
+
expect(frames).toHaveLength(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a refused capture emits nothing and keeps the previous pixels', async () => {
|
|
89
|
+
const { conn } = fakeConnection({ 'Page.captureScreenshot': new Error('no compositor') });
|
|
90
|
+
const frames: BrowserViewFrame[] = [];
|
|
91
|
+
seeder(conn, frames).seed();
|
|
92
|
+
await settle();
|
|
93
|
+
expect(frames).toEqual([]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a live frame that landed first wins over the late snapshot', async () => {
|
|
97
|
+
const { conn } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
|
|
98
|
+
const frames: BrowserViewFrame[] = [];
|
|
99
|
+
const target = seeder(conn, frames);
|
|
100
|
+
target.seed();
|
|
101
|
+
// The page painted while the capture was in flight.
|
|
102
|
+
target.invalidate();
|
|
103
|
+
await settle();
|
|
104
|
+
expect(frames).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('nothing is captured while no tab is attached', async () => {
|
|
108
|
+
const { conn, sent } = fakeConnection({ 'Page.captureScreenshot': { data: 'SNAP' } });
|
|
109
|
+
const frames: BrowserViewFrame[] = [];
|
|
110
|
+
seeder(conn, frames, null).seed();
|
|
111
|
+
await settle();
|
|
112
|
+
expect(sent).toEqual([]);
|
|
113
|
+
expect(frames).toEqual([]);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one-off snapshot that seeds the panel before the screencast can paint.
|
|
8
|
+
*
|
|
9
|
+
* `Page.startScreencast` only pushes frames when the page PRODUCES a new one.
|
|
10
|
+
* A tab the agent finished with is static, and Chromium measures a burst: a
|
|
11
|
+
* page that is attached to and left alone delivers **zero** `Page.screencastFrame`
|
|
12
|
+
* events no matter which `everyNthFrame` is asked for (Chromium 1248, both
|
|
13
|
+
* `chrome-headless-shell` and `--headless=new`; a page that changed once and
|
|
14
|
+
* went idle likewise stayed on the previous pixels at `everyNthFrame: 2`).
|
|
15
|
+
* So the panel sat on "Menunggu frame pertama dari browser…" for a live tab
|
|
16
|
+
* that simply had nothing to redraw.
|
|
17
|
+
*
|
|
18
|
+
* `Page.captureScreenshot` is unaffected: measured on the same build it
|
|
19
|
+
* answers for a BACKGROUND tab (a neighbouring page focused, so the surface is
|
|
20
|
+
* no longer composited on screen), for a just-navigated tab, and in 8–40 ms.
|
|
21
|
+
* Decoded with ffmpeg, the pixels are the page's own — yellow `#ffff00` for a
|
|
22
|
+
* background tab painted yellow, magenta after it navigated to magenta — not a
|
|
23
|
+
* blank surface. This module is that call, boxed to the screencast's size so
|
|
24
|
+
* the snapshot and the first live frame line up instead of popping.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { CdpConnection } from '@/shared/lib/browser/cdp';
|
|
28
|
+
import { FRAME_QUALITY, frameScale } from '@/shared/lib/browser/frame-params';
|
|
29
|
+
import { readNumber, readString } from '@/shared/lib/browser/util';
|
|
30
|
+
import { isRecord } from '@/shared/lib/util/guards';
|
|
31
|
+
import type { BrowserViewFrame } from '@/shared/types';
|
|
32
|
+
|
|
33
|
+
/** CSS viewport size of the attached page, or null when the page will not say. */
|
|
34
|
+
async function readViewport(conn: CdpConnection, sessionId: string): Promise<{ width: number; height: number } | null> {
|
|
35
|
+
const metrics = await conn.send('Page.getLayoutMetrics', {}, sessionId).catch(() => null);
|
|
36
|
+
if (!isRecord(metrics)) return null;
|
|
37
|
+
const viewport = isRecord(metrics.cssVisualViewport) ? metrics.cssVisualViewport : metrics;
|
|
38
|
+
const width = readNumber(viewport, 'clientWidth');
|
|
39
|
+
const height = readNumber(viewport, 'clientHeight');
|
|
40
|
+
if (!width || !height) return null;
|
|
41
|
+
return { width, height };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Capture one JPEG of the attached page, scaled into the frame box.
|
|
46
|
+
*
|
|
47
|
+
* Best-effort by contract: a page that refuses (crash, no compositor) yields
|
|
48
|
+
* null and the caller falls back to waiting for a live frame. The clip is the
|
|
49
|
+
* whole viewport at `frameScale`, which is the only knob that makes a snapshot
|
|
50
|
+
* honour `maxWidth`/`maxHeight` — `captureScreenshot` has no such parameter.
|
|
51
|
+
*/
|
|
52
|
+
export async function captureFrame(
|
|
53
|
+
conn: CdpConnection,
|
|
54
|
+
sessionId: string,
|
|
55
|
+
targetId: string,
|
|
56
|
+
): Promise<BrowserViewFrame | null> {
|
|
57
|
+
const viewport = await readViewport(conn, sessionId);
|
|
58
|
+
const clip = viewport
|
|
59
|
+
? { x: 0, y: 0, width: viewport.width, height: viewport.height, scale: frameScale(viewport.width, viewport.height) }
|
|
60
|
+
: undefined;
|
|
61
|
+
const captured = await conn
|
|
62
|
+
.send('Page.captureScreenshot', { format: 'jpeg', quality: FRAME_QUALITY, ...(clip ? { clip } : {}), captureBeyondViewport: false }, sessionId)
|
|
63
|
+
.catch(() => null);
|
|
64
|
+
const data = isRecord(captured) ? readString(captured, 'data') : undefined;
|
|
65
|
+
if (!data) return null;
|
|
66
|
+
return { data, mimeType: 'image/jpeg', targetId };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface FrameSeeder {
|
|
70
|
+
/** Snapshot the attached page now; a live frame landing first wins. */
|
|
71
|
+
seed: () => void;
|
|
72
|
+
/** A live frame arrived (or the tab changed): drop any snapshot in flight. */
|
|
73
|
+
invalidate: () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Snapshot scheduling for one viewer.
|
|
78
|
+
*
|
|
79
|
+
* `seed()` is what removes the "waiting for the first frame" hang: it is called
|
|
80
|
+
* on attach and after a load, the two moments the page will not push a frame
|
|
81
|
+
* of its own. A snapshot that was overtaken by a live frame is DISCARDED —
|
|
82
|
+
* those pixels are newer, and repainting them would show the older page.
|
|
83
|
+
*/
|
|
84
|
+
export function createFrameSeeder(
|
|
85
|
+
conn: CdpConnection,
|
|
86
|
+
readAttached: () => { sessionId: string; targetId: string } | null,
|
|
87
|
+
emit: (frame: BrowserViewFrame) => void,
|
|
88
|
+
): FrameSeeder {
|
|
89
|
+
let generation = 0;
|
|
90
|
+
let inFlight = false;
|
|
91
|
+
return {
|
|
92
|
+
seed: () => {
|
|
93
|
+
const attached = readAttached();
|
|
94
|
+
// A retry loop (the viewer asks again each tick until a picture lands)
|
|
95
|
+
// must not stack captures: one is in flight, the next one starts after.
|
|
96
|
+
if (!attached || inFlight) return;
|
|
97
|
+
generation += 1;
|
|
98
|
+
const mine = generation;
|
|
99
|
+
inFlight = true;
|
|
100
|
+
void captureFrame(conn, attached.sessionId, attached.targetId)
|
|
101
|
+
.then((frame) => {
|
|
102
|
+
if (frame && mine === generation) emit(frame);
|
|
103
|
+
})
|
|
104
|
+
.finally(() => {
|
|
105
|
+
inFlight = false;
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
invalidate: () => {
|
|
109
|
+
generation += 1;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What "close this tab" means for the agent's browser.
|
|
8
|
+
*
|
|
9
|
+
* The rules are shared by the route and the panel, and both halves matter:
|
|
10
|
+
* a target id from ANOTHER session must be refused (the daemon is
|
|
11
|
+
* project-shared), and the tab the panel watches after a close must be the
|
|
12
|
+
* neighbour, not whichever page happens to be newest.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import { closeVerdict, neighbourTargetId, readCloseTarget } from '@/shared/lib/browser/tab-close';
|
|
18
|
+
|
|
19
|
+
describe('readCloseTarget', () => {
|
|
20
|
+
test('accepts an opaque target id', () => {
|
|
21
|
+
expect(readCloseTarget('3A863DE80D88040BA983CA1949531524')).toBe('3A863DE80D88040BA983CA1949531524');
|
|
22
|
+
expect(readCloseTarget(' ABC123 ')).toBe('ABC123');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('rejects anything that is not a bare id', () => {
|
|
26
|
+
expect(readCloseTarget(undefined)).toBeNull();
|
|
27
|
+
expect(readCloseTarget(null)).toBeNull();
|
|
28
|
+
expect(readCloseTarget('')).toBeNull();
|
|
29
|
+
expect(readCloseTarget(42)).toBeNull();
|
|
30
|
+
expect(readCloseTarget({ targetId: 'x' })).toBeNull();
|
|
31
|
+
expect(readCloseTarget('a b')).toBeNull();
|
|
32
|
+
expect(readCloseTarget('../escape')).toBeNull();
|
|
33
|
+
expect(readCloseTarget('a:b')).toBeNull();
|
|
34
|
+
expect(readCloseTarget('x'.repeat(129))).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('closeVerdict', () => {
|
|
39
|
+
test('closes a tab this session owns and reports the survivors', () => {
|
|
40
|
+
expect(closeVerdict('mine-2', ['mine-1', 'mine-2', 'mine-3'])).toEqual({
|
|
41
|
+
ok: true,
|
|
42
|
+
remaining: ['mine-1', 'mine-3'],
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('refuses a tab another session owns, and keeps the list intact', () => {
|
|
47
|
+
const verdict = closeVerdict('other-1', ['mine-1']);
|
|
48
|
+
expect(verdict.ok).toBe(false);
|
|
49
|
+
expect(verdict.reason).toContain('does not belong to this session');
|
|
50
|
+
expect(verdict.remaining).toEqual(['mine-1']);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a session with no tabs refuses everything', () => {
|
|
54
|
+
expect(closeVerdict('mine-1', []).ok).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('neighbourTargetId', () => {
|
|
59
|
+
test('prefers the tab to the right, in registry (creation) order', () => {
|
|
60
|
+
expect(neighbourTargetId(['a', 'b', 'c'], 'b')).toBe('c');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('falls back to the left when the closed tab was the newest', () => {
|
|
64
|
+
expect(neighbourTargetId(['a', 'b', 'c'], 'c')).toBe('b');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('nothing left to select when the last tab closes', () => {
|
|
68
|
+
expect(neighbourTargetId(['only'], 'only')).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('an id outside the list names no neighbour', () => {
|
|
72
|
+
expect(neighbourTargetId(['a'], 'nope')).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What "close this tab" MEANS for the agent's browser, decided once.
|
|
8
|
+
*
|
|
9
|
+
* A session's omp agent routinely opens several pages in the project-shared
|
|
10
|
+
* Chromium, and a finished tab keeps costing the panel: the viewer attaches to
|
|
11
|
+
* the newest owned target, so every stale tab is one more reason the panel
|
|
12
|
+
* shows the wrong page, and it keeps its renderer alive in the daemon.
|
|
13
|
+
*
|
|
14
|
+
* Two rules live here because both the route and the panel need them and a
|
|
15
|
+
* second copy would drift:
|
|
16
|
+
*
|
|
17
|
+
* - **Only the session's OWN tabs are closable.** The daemon is project-shared,
|
|
18
|
+
* so a target id from another session must be refused by name rather than
|
|
19
|
+
* attempted (`pickTargetId`/`ownedPages` already scope the view this way).
|
|
20
|
+
* - **`Target.closeTarget` is the whole close.** Measured on Chromium 1248
|
|
21
|
+
* against a tab that is mid-screencast: it answers `{"success":true}`, the
|
|
22
|
+
* browser socket STAYS OPEN, the attached session dies on its own
|
|
23
|
+
* (`Page.stopScreencast` then answers "Session with given id not found" and
|
|
24
|
+
* `Target.detachedFromTarget` arrives browser-level), and the remaining tabs
|
|
25
|
+
* are still attachable. So the viewer needs no special teardown — but it does
|
|
26
|
+
* need to know the page it was watching is gone, which the 1s target poll
|
|
27
|
+
* already covers.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** The tab id the client asks to close, or null when it is not a usable id. */
|
|
31
|
+
export function readCloseTarget(value: unknown): string | null {
|
|
32
|
+
if (typeof value !== 'string') return null;
|
|
33
|
+
const targetId = value.trim();
|
|
34
|
+
// A CDP target id is an opaque hex string; anything with whitespace or a
|
|
35
|
+
// path separator is a caller bug, not a tab.
|
|
36
|
+
if (!targetId || targetId.length > 128) return null;
|
|
37
|
+
if (/[\s/\\:]/.test(targetId)) return null;
|
|
38
|
+
return targetId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CloseVerdict {
|
|
42
|
+
ok: boolean;
|
|
43
|
+
/** Present when `ok` is false: why the tab was not closed. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
/** Tabs that survive the close, in registry order. */
|
|
46
|
+
remaining: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Decide whether `targetId` may be closed, given what this session owns.
|
|
51
|
+
*
|
|
52
|
+
* `ownedIds` is the on-disk registry read, so a tab another session opened is
|
|
53
|
+
* not merely "not listed here" — it is refused, and the refusal names the
|
|
54
|
+
* ownership rule so a client bug does not look like a browser failure.
|
|
55
|
+
*/
|
|
56
|
+
export function closeVerdict(targetId: string, ownedIds: readonly string[]): CloseVerdict {
|
|
57
|
+
const remaining = ownedIds.filter((id) => id !== targetId);
|
|
58
|
+
if (!ownedIds.includes(targetId)) {
|
|
59
|
+
return { ok: false, reason: 'That tab does not belong to this session', remaining: [...ownedIds] };
|
|
60
|
+
}
|
|
61
|
+
return { ok: true, remaining };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Which tab the panel should watch after `closed` is gone: the neighbour to its
|
|
66
|
+
* RIGHT in registry order (the newest remaining owned tab), else the one to its
|
|
67
|
+
* left, else nothing.
|
|
68
|
+
*
|
|
69
|
+
* Deliberately not "always the newest": the registry is in creation order, so
|
|
70
|
+
* after closing one of several tabs the user is looking at, staying put in that
|
|
71
|
+
* region is what keeps the panel on the page they were watching.
|
|
72
|
+
*/
|
|
73
|
+
export function neighbourTargetId(ownedIds: readonly string[], closed: string): string | null {
|
|
74
|
+
const index = ownedIds.indexOf(closed);
|
|
75
|
+
if (index === -1) return null;
|
|
76
|
+
return ownedIds[index + 1] ?? ownedIds[index - 1] ?? null;
|
|
77
|
+
}
|
|
@@ -26,31 +26,12 @@ import { CdpConnection } from '@/shared/lib/browser/cdp';
|
|
|
26
26
|
import { acquireConnection, releaseConnection } from '@/shared/lib/browser/connection';
|
|
27
27
|
import { OBSERVER_BINDING, installObserver, parseObserverPayload, type ObserverHandle } from '@/shared/lib/browser/observer';
|
|
28
28
|
import { ownedPages, parsePageTargets, pickTargetId, readTargetInfoPatch, type PageTarget } from '@/shared/lib/browser/targets';
|
|
29
|
+
import { SCREENCAST_PARAMS } from '@/shared/lib/browser/frame-params';
|
|
30
|
+
import { createFramePipeline, type FramePipeline } from '@/shared/lib/browser/frame-pipeline';
|
|
29
31
|
import { readNumber, readString } from '@/shared/lib/browser/util';
|
|
30
32
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
31
33
|
import { BROWSER_POLL_MS } from '@/shared/lib/workspace/refresh-cadence';
|
|
32
34
|
|
|
33
|
-
/**
|
|
34
|
-
* What the stream asks the page for.
|
|
35
|
-
*
|
|
36
|
-
* `everyNthFrame: 1` (every frame) is what the panel used to request, and it is
|
|
37
|
-
* the wrong default for a viewer that is watched, not sampled: a 30 fps page
|
|
38
|
-
* produced 30 decodes a second, each one a full RGBA surface the renderer has to
|
|
39
|
-
* allocate and free. Measured in WebKit with the canvas sink in place, 1 760
|
|
40
|
-
* frames at 16 fps still cost ~8 KB of WebContent footprint per frame, so the
|
|
41
|
-
* frame RATE is a real lever on top of the sink (`client/lib/browser/frame-canvas.ts`).
|
|
42
|
-
* Every second frame keeps the motion readable at half the decodes, and the
|
|
43
|
-
* size is the panel's own display width — 1 600 px was above every panel width
|
|
44
|
-
* the app renders, so it was only ever downscaled.
|
|
45
|
-
*/
|
|
46
|
-
const SCREENCAST_PARAMS = {
|
|
47
|
-
format: 'jpeg',
|
|
48
|
-
quality: 60,
|
|
49
|
-
maxWidth: 1280,
|
|
50
|
-
maxHeight: 800,
|
|
51
|
-
everyNthFrame: 2,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
35
|
interface ScreencastOptions {
|
|
55
36
|
/** Caller's preferred tab id; honored while it is still a live, owned page. */
|
|
56
37
|
preferTargetId?: string;
|
|
@@ -102,10 +83,16 @@ class ScreencastSession {
|
|
|
102
83
|
private unsubscribeClose: (() => void) | null = null;
|
|
103
84
|
private ticking = false;
|
|
104
85
|
private _closed = false;
|
|
86
|
+
private readonly frames: FramePipeline;
|
|
105
87
|
|
|
106
88
|
constructor(conn: CdpConnection, opts: ScreencastOptions) {
|
|
107
89
|
this.conn = conn;
|
|
108
90
|
this.opts = opts;
|
|
91
|
+
this.frames = createFramePipeline(
|
|
92
|
+
conn,
|
|
93
|
+
() => (this.currentSessionId && this.currentTargetId ? { sessionId: this.currentSessionId, targetId: this.currentTargetId } : null),
|
|
94
|
+
(frame) => this.emitFrame(frame),
|
|
95
|
+
);
|
|
109
96
|
}
|
|
110
97
|
|
|
111
98
|
get closed(): boolean {
|
|
@@ -148,6 +135,7 @@ class ScreencastSession {
|
|
|
148
135
|
this.targets = targets;
|
|
149
136
|
const nextTargetId = pickTargetId(targets, ownedIds, this.opts.preferTargetId);
|
|
150
137
|
if (nextTargetId !== this.currentTargetId) await this.switchTarget(nextTargetId);
|
|
138
|
+
else this.frames.seed();
|
|
151
139
|
this.emitCurrent();
|
|
152
140
|
} catch {
|
|
153
141
|
this.fail();
|
|
@@ -168,13 +156,32 @@ class ScreencastSession {
|
|
|
168
156
|
if (!sessionId) throw new Error('CDP attachToTarget returned no session id');
|
|
169
157
|
this.currentTargetId = nextTargetId;
|
|
170
158
|
this.currentSessionId = sessionId;
|
|
159
|
+
this.frames.reset();
|
|
171
160
|
this.observer = await installObserver(this.conn, sessionId).catch(() => null);
|
|
172
161
|
try {
|
|
162
|
+
// Page.loadEventFired is only delivered once the domain is enabled; the
|
|
163
|
+
// observer enables it too, but that install is best-effort and must not
|
|
164
|
+
// be what the snapshot depends on.
|
|
165
|
+
await this.conn.send('Page.enable', {}, sessionId).catch(() => {});
|
|
173
166
|
await this.conn.send('Page.startScreencast', SCREENCAST_PARAMS, sessionId);
|
|
174
167
|
} catch (error) {
|
|
175
168
|
await this.detach();
|
|
176
169
|
throw error;
|
|
177
170
|
}
|
|
171
|
+
// The page has nothing to redraw right now — it may never push a frame
|
|
172
|
+
// until the agent touches it — so take a snapshot instead of spinning on
|
|
173
|
+
// "waiting for the first frame" (`frame-pipeline.ts` measures why).
|
|
174
|
+
this.frames.seed();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** What actually crosses to the SSE stream. */
|
|
178
|
+
private emitFrame(frame: BrowserViewFrame): void {
|
|
179
|
+
if (this._closed) return;
|
|
180
|
+
try {
|
|
181
|
+
this.opts.onFrame(frame);
|
|
182
|
+
} catch {
|
|
183
|
+
// Subscriber bugs (SSE encode failure) must not break frame acking.
|
|
184
|
+
}
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
private async detach(): Promise<void> {
|
|
@@ -204,6 +211,10 @@ class ScreencastSession {
|
|
|
204
211
|
this.handleFrameNavigated(params, sessionId);
|
|
205
212
|
return;
|
|
206
213
|
}
|
|
214
|
+
if (method === 'Page.loadEventFired') {
|
|
215
|
+
this.handleLoadEvent(sessionId);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
207
218
|
if (method === 'Target.targetInfoChanged') {
|
|
208
219
|
const patch = readTargetInfoPatch(params);
|
|
209
220
|
if (!patch) return;
|
|
@@ -231,6 +242,18 @@ class ScreencastSession {
|
|
|
231
242
|
this.emitAction({ kind: 'loaded', label: `Halaman dimuat: ${shortUrl(url)}` });
|
|
232
243
|
}
|
|
233
244
|
|
|
245
|
+
/**
|
|
246
|
+
* A load settled: the page is idle now and may push nothing until the agent
|
|
247
|
+
* touches it, so take the picture. `Page.loadEventFired` is the signal a
|
|
248
|
+
* viewer session actually receives — measured on Chromium 1248, a
|
|
249
|
+
* background navigation delivers it (plus `domContentEventFired`) even
|
|
250
|
+
* though the screencast stays silent, and a 1.2s wait is enough.
|
|
251
|
+
*/
|
|
252
|
+
private handleLoadEvent(sessionId?: string): void {
|
|
253
|
+
if (!sessionId || sessionId !== this.currentSessionId) return;
|
|
254
|
+
this.frames.seedAfterLoad();
|
|
255
|
+
}
|
|
256
|
+
|
|
234
257
|
private emitAction(action: BrowserActionDraft): void {
|
|
235
258
|
try {
|
|
236
259
|
this.opts.onAction?.(action);
|
|
@@ -253,11 +276,7 @@ class ScreencastSession {
|
|
|
253
276
|
mimeType: 'image/jpeg',
|
|
254
277
|
targetId: this.currentTargetId ?? '',
|
|
255
278
|
};
|
|
256
|
-
|
|
257
|
-
this.opts.onFrame(frame);
|
|
258
|
-
} catch {
|
|
259
|
-
// Subscriber bugs (SSE encode failure) must not break frame acking.
|
|
260
|
-
}
|
|
279
|
+
this.frames.pushLive(frame);
|
|
261
280
|
}
|
|
262
281
|
|
|
263
282
|
private emitCurrent(): void {
|