@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,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Closing one of the agent's browser tabs, from the panel.
|
|
8
|
+
*
|
|
9
|
+
* The server owns the rules (ownership, what CDP does to a screencast session);
|
|
10
|
+
* this hook owns only the client's half: refuse a second close while one is in
|
|
11
|
+
* flight, surface the refusal in words, and return the tab the panel should
|
|
12
|
+
* watch next so the strip does not jump to an unrelated page.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately NOT optimistic: the tab strip is server state (the viewer's
|
|
15
|
+
* owned-target list), so removing a row before the browser confirms would show
|
|
16
|
+
* a tab that still exists — and a failed close would look like a refresh race.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
20
|
+
|
|
21
|
+
export interface CloseTabResult {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
/** The tab to select once `targetId` is gone (null when none is left). */
|
|
24
|
+
next: string | null;
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface TabsCloseReply {
|
|
29
|
+
ok?: unknown;
|
|
30
|
+
error?: unknown;
|
|
31
|
+
next?: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readNext(value: unknown): string | null {
|
|
35
|
+
return typeof value === 'string' && value ? value : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function useCloseBrowserTab(sessionId: string | undefined) {
|
|
39
|
+
const [closing, setClosing] = useState<string | null>(null);
|
|
40
|
+
|
|
41
|
+
const closeTab = useCallback(
|
|
42
|
+
async (targetId: string): Promise<CloseTabResult> => {
|
|
43
|
+
if (!sessionId || !targetId) return { ok: false, next: null, error: 'No tab to close' };
|
|
44
|
+
setClosing(targetId);
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetch(`/api/browser/${encodeURIComponent(sessionId)}/tabs/close`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: { 'content-type': 'application/json' },
|
|
49
|
+
body: JSON.stringify({ targetId }),
|
|
50
|
+
});
|
|
51
|
+
const body = (await response.json().catch(() => ({}))) as TabsCloseReply;
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const error = typeof body.error === 'string' && body.error ? body.error : `Close failed (${response.status})`;
|
|
54
|
+
return { ok: false, next: null, error };
|
|
55
|
+
}
|
|
56
|
+
return { ok: true, next: readNext(body.next) };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { ok: false, next: null, error: error instanceof Error ? error.message : String(error) };
|
|
59
|
+
} finally {
|
|
60
|
+
setClosing(null);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
[sessionId],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return { closeTab, closing };
|
|
67
|
+
}
|
|
@@ -18,6 +18,8 @@ interface UseScreencastResult {
|
|
|
18
18
|
*/
|
|
19
19
|
frame?: { data: string; mimeType: string } | null;
|
|
20
20
|
actions: BrowserPanelAction[];
|
|
21
|
+
/** The session whose tabs these are; the tab-close request needs it. */
|
|
22
|
+
sessionId: string;
|
|
21
23
|
/** Pin the viewer to one tab id; pass an empty string to follow the newest owned tab. */
|
|
22
24
|
selectTarget: (targetId: string) => void;
|
|
23
25
|
/** Drop the current SSE connection and open a fresh one. */
|
|
@@ -107,7 +109,13 @@ export function useScreencast(active = true): UseScreencastResult {
|
|
|
107
109
|
source.addEventListener('state', (event) => {
|
|
108
110
|
try {
|
|
109
111
|
const next = JSON.parse((event as MessageEvent).data) as BrowserViewState;
|
|
110
|
-
|
|
112
|
+
// Do NOT clear the frame on a target change: the viewer seeds the new
|
|
113
|
+
// tab with a snapshot, and that frame can reach this handler BEFORE
|
|
114
|
+
// the state event that names the tab (measured: 26–47 ms from attach).
|
|
115
|
+
// Clearing here threw away the first picture of an idle tab, which is
|
|
116
|
+
// exactly the picture the snapshot exists to provide. A stale tab's
|
|
117
|
+
// pixels are dropped by the target check in the `frame` handler, and
|
|
118
|
+
// a non-live state below still clears.
|
|
111
119
|
currentTargetRef.current = next.targetId;
|
|
112
120
|
setState(next);
|
|
113
121
|
if (next.status !== 'live') setFrame(null);
|
|
@@ -120,7 +128,10 @@ export function useScreencast(active = true): UseScreencastResult {
|
|
|
120
128
|
try {
|
|
121
129
|
const incoming = JSON.parse((event as MessageEvent).data) as BrowserViewFrame;
|
|
122
130
|
const current = currentTargetRef.current;
|
|
131
|
+
// Adopt the frame's tab when no state has named one yet: the seed
|
|
132
|
+
// snapshot is the first thing this stream can deliver.
|
|
123
133
|
if (current && incoming.targetId && incoming.targetId !== current) return;
|
|
134
|
+
if (!current && incoming.targetId) currentTargetRef.current = incoming.targetId;
|
|
124
135
|
setFrame({ data: incoming.data, mimeType: incoming.mimeType });
|
|
125
136
|
} catch {
|
|
126
137
|
// Ignore malformed frame payloads.
|
|
@@ -180,6 +191,7 @@ export function useScreencast(active = true): UseScreencastResult {
|
|
|
180
191
|
targetId: state.targetId,
|
|
181
192
|
frame,
|
|
182
193
|
actions,
|
|
194
|
+
sessionId,
|
|
183
195
|
selectTarget,
|
|
184
196
|
reconnect,
|
|
185
197
|
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer half of the browser-panel bridge.
|
|
8
|
+
*
|
|
9
|
+
* The failure this guards is a prompt that names a page the agent cannot place.
|
|
10
|
+
* The block is produced by `shared/lib/browser/page-context` (its own tests pin
|
|
11
|
+
* the text); what is pinned HERE is the wiring: an event appends, two events do
|
|
12
|
+
* not overwrite, and a malformed batch degrades to the plain block instead of
|
|
13
|
+
* rendering `NaN%` into the draft.
|
|
14
|
+
*
|
|
15
|
+
* An annotated page sends NO attachment — the user panel's page is a
|
|
16
|
+
* cross-origin iframe, so there are no bytes to attach.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
20
|
+
import { Window } from 'happy-dom';
|
|
21
|
+
import { h, render } from 'preact';
|
|
22
|
+
import { act } from 'preact/test-utils';
|
|
23
|
+
|
|
24
|
+
import { useBrowserPageContextInsert } from '@/client/hooks/chat/composer/browser-context';
|
|
25
|
+
import { emitBrowserPageContext } from '@/shared/lib/browser/page-context';
|
|
26
|
+
|
|
27
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
28
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
29
|
+
|
|
30
|
+
beforeAll(() => {
|
|
31
|
+
const win = new Window({ url: 'http://localhost' });
|
|
32
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
33
|
+
for (const key of DOM_GLOBALS) {
|
|
34
|
+
if (!(key in native)) native[key] = target[key];
|
|
35
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
41
|
+
for (const key of DOM_GLOBALS) {
|
|
42
|
+
if (native[key] === undefined) delete target[key];
|
|
43
|
+
else target[key] = native[key];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
let container: HTMLElement | undefined;
|
|
48
|
+
let draft = '';
|
|
49
|
+
|
|
50
|
+
/** Mount the bridge over a draft string, the way the composer wires it. */
|
|
51
|
+
function mountBridge(): void {
|
|
52
|
+
draft = '';
|
|
53
|
+
const Probe = () => {
|
|
54
|
+
useBrowserPageContextInsert((next) => {
|
|
55
|
+
draft = typeof next === 'function' ? next(draft) : next;
|
|
56
|
+
});
|
|
57
|
+
return h('div', null);
|
|
58
|
+
};
|
|
59
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
60
|
+
act(() => {
|
|
61
|
+
render(h(Probe, null), container!);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
if (container) render(null, container);
|
|
67
|
+
container?.remove();
|
|
68
|
+
container = undefined;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('useBrowserPageContextInsert', () => {
|
|
72
|
+
test('a plain page lands in the draft as the URL block', () => {
|
|
73
|
+
mountBridge();
|
|
74
|
+
act(() => emitBrowserPageContext({ url: 'https://a.test/x' }));
|
|
75
|
+
expect(draft).toBe('[Konteks halaman browser]\nURL: https://a.test/x\n(Lanjutkan dari halaman ini.)');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('an annotated page lands as the block with its numbered marks', () => {
|
|
79
|
+
mountBridge();
|
|
80
|
+
act(() => emitBrowserPageContext({
|
|
81
|
+
url: 'https://a.test/x',
|
|
82
|
+
annotations: [{ id: 'a', tool: 'box', start: { x: 0.1, y: 0.1 }, end: { x: 0.2, y: 0.2 }, label: '', note: 'mati' }],
|
|
83
|
+
panel: { width: 1000, height: 500, viewportMode: 'laptop', zoom: 100 },
|
|
84
|
+
}));
|
|
85
|
+
expect(draft).toContain('Anotasi (1):');
|
|
86
|
+
expect(draft).toContain('1. kotak kiri 10.0%, atas 10.0%');
|
|
87
|
+
expect(draft).toContain('— mati');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('two events append two blocks rather than overwriting the draft', () => {
|
|
91
|
+
mountBridge();
|
|
92
|
+
act(() => emitBrowserPageContext({ url: 'https://a.test' }));
|
|
93
|
+
act(() => emitBrowserPageContext({ url: 'https://b.test' }));
|
|
94
|
+
expect(draft.match(/\[Konteks halaman browser\]/g)).toHaveLength(2);
|
|
95
|
+
expect(draft).toContain('https://a.test');
|
|
96
|
+
expect(draft).toContain('https://b.test');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a detail with no url is ignored rather than pasting an empty block', () => {
|
|
100
|
+
mountBridge();
|
|
101
|
+
act(() => emitBrowserPageContext({ url: '' }));
|
|
102
|
+
expect(draft).toBe('');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('a malformed mark batch degrades to the plain page block, never to NaN%', () => {
|
|
106
|
+
mountBridge();
|
|
107
|
+
act(() => emitBrowserPageContext({
|
|
108
|
+
url: 'https://a.test',
|
|
109
|
+
// A shape missing `end`/`note`, as a hand-written event or an older
|
|
110
|
+
// dispatch could carry: the reader must refuse it, not format it.
|
|
111
|
+
annotations: [{ id: 'a', tool: 'box', start: { x: 1, y: 0 } } as never],
|
|
112
|
+
panel: { width: 1000, height: 500, viewportMode: 'laptop', zoom: 100 },
|
|
113
|
+
}));
|
|
114
|
+
expect(draft).not.toContain('Anotasi');
|
|
115
|
+
expect(draft).toContain('URL: https://a.test');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -4,35 +4,59 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Sibling-panel bridge: listens for
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Sibling-panel bridge: listens for a browser panel's "include page" event and
|
|
8
|
+
* appends its block to the chat draft. Lives beside the timeline hooks because
|
|
9
|
+
* they own the persisted draft (`chat.draft`).
|
|
10
|
+
*
|
|
11
|
+
* The TEXT is built by `shared/lib/browser/page-context`, not here: the same
|
|
12
|
+
* block is produced by the formatter's own tests, so a second spelling in the
|
|
13
|
+
* listener would let the annotated page and the plain page drift apart.
|
|
14
|
+
*
|
|
15
|
+
* An annotated page sends no attachment. The user panel's page is a
|
|
16
|
+
* cross-origin iframe, so there are no bytes to attach — what it sends is the
|
|
17
|
+
* region and the note, which the agent resolves by opening the URL itself.
|
|
10
18
|
*/
|
|
11
19
|
|
|
12
20
|
import { useEffect, useRef } from 'preact/hooks';
|
|
13
|
-
import { BROWSER_INCLUDE_PAGE_EVENT } from '@/shared/lib/browser/page-context';
|
|
14
|
-
import {
|
|
21
|
+
import { BROWSER_INCLUDE_PAGE_EVENT, appendPageContext } from '@/shared/lib/browser/page-context';
|
|
22
|
+
import { readAnnotatePanel, readAnnotationShapes } from '@/shared/lib/browser/annotate';
|
|
15
23
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
24
|
+
import { readString } from '@/shared/lib/browser/util';
|
|
25
|
+
import type { BrowserPageContext } from '@/shared/types';
|
|
16
26
|
|
|
17
27
|
type DraftSetter = (value: string | ((prev: string) => string)) => void;
|
|
18
28
|
|
|
19
|
-
/**
|
|
29
|
+
/** The parts of a dispatched detail this bridge trusts, from a DOM event. */
|
|
30
|
+
export function readPageContextDetail(raw: unknown): BrowserPageContext | null {
|
|
31
|
+
if (!isRecord(raw)) return null;
|
|
32
|
+
const url = readString(raw, 'url');
|
|
33
|
+
if (!url) return null;
|
|
34
|
+
const title = readString(raw, 'title');
|
|
35
|
+
const detail: BrowserPageContext = { url };
|
|
36
|
+
if (title) detail.title = title;
|
|
37
|
+
// The marks are echoed back only when BOTH halves survive validation: a shape
|
|
38
|
+
// list without its panel box cannot be turned into percentages of anything,
|
|
39
|
+
// and a malformed batch degrades to the plain page context rather than to a
|
|
40
|
+
// prompt carrying a broken annotation section.
|
|
41
|
+
const annotations = readAnnotationShapes(raw.annotations);
|
|
42
|
+
const panel = readAnnotatePanel(raw.panel);
|
|
43
|
+
if (annotations && panel) {
|
|
44
|
+
detail.annotations = annotations;
|
|
45
|
+
detail.panel = panel;
|
|
46
|
+
}
|
|
47
|
+
return detail;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Append a page-context block to the composer draft on the panel event. */
|
|
20
51
|
export function useBrowserPageContextInsert(setInputValue: DraftSetter): void {
|
|
21
52
|
const setterRef = useRef(setInputValue);
|
|
22
53
|
setterRef.current = setInputValue;
|
|
23
54
|
|
|
24
55
|
useEffect(() => {
|
|
25
56
|
const handler = (event: Event): void => {
|
|
26
|
-
const detail = event instanceof CustomEvent ? event.detail : null;
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
if (!url) return;
|
|
30
|
-
const title = readString(detail, 'title');
|
|
31
|
-
setterRef.current((prev) => {
|
|
32
|
-
const separator = prev && !prev.endsWith('\n') ? '\n\n' : prev ? '\n' : '';
|
|
33
|
-
const titleLine = title ? `\nJudul: ${title}` : '';
|
|
34
|
-
return `${prev}${separator}[Konteks halaman browser]\nURL: ${url}${titleLine}\n(Lanjutkan dari halaman ini.)`;
|
|
35
|
-
});
|
|
57
|
+
const detail = event instanceof CustomEvent ? readPageContextDetail(event.detail) : null;
|
|
58
|
+
if (!detail) return;
|
|
59
|
+
setterRef.current((prev) => appendPageContext(prev, detail));
|
|
36
60
|
};
|
|
37
61
|
window.addEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
|
|
38
62
|
return () => window.removeEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
|
|
@@ -255,7 +255,7 @@ describe('plugin commands in the popup', () => {
|
|
|
255
255
|
describe('pick item mapping', () => {
|
|
256
256
|
test('an agent becomes a bare @name token', () => {
|
|
257
257
|
const [item] = toAgentPickItems([
|
|
258
|
-
{ id: 'a1', name: 'sonic', description: 'fast', scope: 'user',
|
|
258
|
+
{ id: 'a1', name: 'sonic', description: 'fast', scope: 'user', systemPrompt: '' },
|
|
259
259
|
]);
|
|
260
260
|
expect(item).toMatchObject({ id: 'agent-sonic', name: 'sonic', kind: 'agent', source: 'agent', token: '@sonic' });
|
|
261
261
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sibling-surface bridge: the editor's document review appended to the chat
|
|
8
|
+
* draft.
|
|
9
|
+
*
|
|
10
|
+
* A DOM event rather than shared state, for the same reason the browser panel's
|
|
11
|
+
* page context is one: the editor column and the chat timeline are separate
|
|
12
|
+
* trees, and the draft belongs to the timeline's own persisted hook
|
|
13
|
+
* (`chat.draft`). `formatReviewBlock` in `shared/lib/markdown/review/prompt.ts`
|
|
14
|
+
* owns the TEXT — two spellings of it is how the annotated document and the
|
|
15
|
+
* plain one start saying different things.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
19
|
+
|
|
20
|
+
import { REVIEW_INCLUDE_EVENT, appendReviewBlock } from '@/shared/lib/markdown/review/prompt';
|
|
21
|
+
|
|
22
|
+
type DraftSetter = (value: string | ((prev: string) => string)) => void;
|
|
23
|
+
|
|
24
|
+
/** Append a review block to the composer draft on the editor's event. */
|
|
25
|
+
export function useReviewIncludeInsert(setInputValue: DraftSetter): void {
|
|
26
|
+
const setterRef = useRef(setInputValue);
|
|
27
|
+
setterRef.current = setInputValue;
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const handler = (event: Event): void => {
|
|
31
|
+
const block = event instanceof CustomEvent && typeof event.detail === 'string' ? event.detail : '';
|
|
32
|
+
if (!block) return;
|
|
33
|
+
setterRef.current((previous) => appendReviewBlock(previous, block));
|
|
34
|
+
};
|
|
35
|
+
window.addEventListener(REVIEW_INCLUDE_EVENT, handler);
|
|
36
|
+
return () => window.removeEventListener(REVIEW_INCLUDE_EVENT, handler);
|
|
37
|
+
}, []);
|
|
38
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer draft's SCOPE: a chat named in the URL, or the landing.
|
|
8
|
+
*
|
|
9
|
+
* The reported bug this pins: text appended while no session was open (an
|
|
10
|
+
* annotation sent from the browser panel) was stored on the provider's fallback
|
|
11
|
+
* id — the landing's own bucket — which is not a chat and never gets cleared,
|
|
12
|
+
* because the landing composer is disabled and nothing can send or clear it.
|
|
13
|
+
* Every later launch then opened with that text already in the box, reading as
|
|
14
|
+
* something the new chat had inherited.
|
|
15
|
+
*
|
|
16
|
+
* A landing draft is therefore memory-only. The cases below mount the real
|
|
17
|
+
* provider id the way `App` derives it (`?sessionId=` else `'1'`), so the
|
|
18
|
+
* fallback bucket is still the landing's store — it is just not WRITTEN.
|
|
19
|
+
*
|
|
20
|
+
* The hook is imported DYNAMICALLY, after the DOM exists: `useSearchParams`
|
|
21
|
+
* caches the search string and subscribes to `popstate` when its module loads,
|
|
22
|
+
* so a static import (evaluated before any `beforeAll` runs) would leave the
|
|
23
|
+
* router unable to see the URL these cases set. The module-load boundary is the
|
|
24
|
+
* subject here, which is the documented exception to static imports.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
28
|
+
import { Window } from 'happy-dom';
|
|
29
|
+
import { h, render } from 'preact';
|
|
30
|
+
import { act } from 'preact/test-utils';
|
|
31
|
+
|
|
32
|
+
import { forgetSession, getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
|
|
33
|
+
import { emitBrowserPageContext } from '@/shared/lib/browser/page-context';
|
|
34
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
35
|
+
import { CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
36
|
+
import type { Context } from 'preact';
|
|
37
|
+
import type { ComposerDraftState } from '@/client/hooks/chat/composer/use-draft';
|
|
38
|
+
import type { SessionStateContextValue } from '@/client/hooks/workspace/session-state/context';
|
|
39
|
+
|
|
40
|
+
const LANDING_ID = '1';
|
|
41
|
+
const SEEDED = '[Konteks halaman browser]\nURL: http://localhost:7801/\n(Lanjutkan dari halaman ini.)';
|
|
42
|
+
|
|
43
|
+
let container: HTMLElement | undefined;
|
|
44
|
+
let holder: { api: ComposerDraftState | null };
|
|
45
|
+
let useComposerDraft: () => ComposerDraftState;
|
|
46
|
+
let SessionStateContext: Context<SessionStateContextValue | null>;
|
|
47
|
+
const nativeFetch = globalThis.fetch;
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
installDomGlobals(new Window({ url: 'http://127.0.0.1/' }));
|
|
51
|
+
({ useComposerDraft } = await import('@/client/hooks/chat/composer/use-draft'));
|
|
52
|
+
({ SessionStateContext } = await import('@/client/hooks/workspace/session-state/context'));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
// Writes are debounced-persisted; a stray POST is not what these cases read.
|
|
57
|
+
globalThis.fetch = (async () => new Response('{"state":{}}')) as unknown as typeof fetch;
|
|
58
|
+
forgetSession(LANDING_ID);
|
|
59
|
+
holder = { api: null };
|
|
60
|
+
pointAt('');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
if (container) render(null, container);
|
|
65
|
+
container?.remove();
|
|
66
|
+
container = undefined;
|
|
67
|
+
forgetSession(LANDING_ID);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
// The router caches `location.search` in a module and subscribes to
|
|
72
|
+
// `popstate` on the window that existed when IT loaded — this suite's. Put
|
|
73
|
+
// that cache back to the bare path before the window goes away, or every
|
|
74
|
+
// later suite in the same `bun test` process reads `?sessionId=1` off a
|
|
75
|
+
// window nobody can reach any more (measured: the sidebar controller drew a
|
|
76
|
+
// stray `1` row).
|
|
77
|
+
pointAt('');
|
|
78
|
+
globalThis.fetch = nativeFetch;
|
|
79
|
+
restoreDomGlobals();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function pointAt(search: string): void {
|
|
83
|
+
window.history.replaceState(null, '', `/${search}`);
|
|
84
|
+
window.dispatchEvent(new Event('popstate'));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Mount the draft hook for one URL, with the provider id `App` derives. */
|
|
88
|
+
function mount(search: string): void {
|
|
89
|
+
pointAt(search);
|
|
90
|
+
const sessionId = new URLSearchParams(search).get('sessionId') || LANDING_ID;
|
|
91
|
+
function Probe() {
|
|
92
|
+
holder.api = useComposerDraft();
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
96
|
+
act(() => {
|
|
97
|
+
render(
|
|
98
|
+
h(SessionStateContext.Provider, { value: { sessionId, ready: true }, children: h(Probe, null) }),
|
|
99
|
+
container!,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
describe('useComposerDraft', () => {
|
|
105
|
+
test('the landing does not restore the fallback bucket\'s draft', () => {
|
|
106
|
+
setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
|
|
107
|
+
mount('');
|
|
108
|
+
expect(holder.api!.inputValue).toBe('');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('a landing draft is kept in memory and never written to a session slot', () => {
|
|
112
|
+
mount('');
|
|
113
|
+
act(() => holder.api!.setInputValue('typed at the landing'));
|
|
114
|
+
expect(holder.api!.inputValue).toBe('typed at the landing');
|
|
115
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('an annotation sent at the landing stays out of the persisted draft', () => {
|
|
119
|
+
mount('');
|
|
120
|
+
act(() => emitBrowserPageContext({ url: 'https://a.test/x' }));
|
|
121
|
+
expect(holder.api!.inputValue).toContain('[Konteks halaman browser]');
|
|
122
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('a session named in the URL still restores and persists its own draft', () => {
|
|
126
|
+
setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
|
|
127
|
+
mount(`?sessionId=${LANDING_ID}`);
|
|
128
|
+
expect(holder.api!.inputValue).toBe(SEEDED);
|
|
129
|
+
act(() => holder.api!.setInputValue('follow-up'));
|
|
130
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBe('follow-up');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -11,10 +11,23 @@
|
|
|
11
11
|
* and the browser-panel insert appends to the text beside the attachments that
|
|
12
12
|
* arrived with it. Extracted from the timeline hook, which is at the repo's
|
|
13
13
|
* per-file ceiling.
|
|
14
|
+
*
|
|
15
|
+
* A LANDING draft (no `?sessionId=` in the URL) is memory-only.
|
|
16
|
+
*
|
|
17
|
+
* The landing mounts `SessionStateProvider` on its fallback id (`'1'`), which
|
|
18
|
+
* is not a chat: the composer there is disabled until a workspace is picked, so
|
|
19
|
+
* nothing the user does can send or clear it. Persisting under that id made the
|
|
20
|
+
* slot permanent — measured: a browser-panel annotation appended once at the
|
|
21
|
+
* landing was still sitting in the composer on every later launch, looking like
|
|
22
|
+
* text a new chat had inherited. A draft belongs to the chat named in the URL;
|
|
23
|
+
* with no chat named, it is kept for this page session only.
|
|
14
24
|
*/
|
|
15
25
|
|
|
26
|
+
import { useState } from 'preact/hooks';
|
|
27
|
+
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
16
28
|
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
17
29
|
import { useBrowserPageContextInsert } from '@/client/hooks/chat/composer/browser-context';
|
|
30
|
+
import { useReviewIncludeInsert } from '@/client/hooks/chat/composer/review-context';
|
|
18
31
|
import { CHAT_DRAFT_ATTACHMENTS_KEY, CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
19
32
|
import type { Attachment } from '@/shared/types';
|
|
20
33
|
|
|
@@ -26,8 +39,24 @@ export interface ComposerDraftState {
|
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
export function useComposerDraft(): ComposerDraftState {
|
|
29
|
-
const [
|
|
42
|
+
const [searchParams] = useSearchParams();
|
|
43
|
+
const scoped = Boolean(searchParams.get('sessionId'));
|
|
44
|
+
|
|
45
|
+
// Both branches are mounted unconditionally (hook order) and the scope only
|
|
46
|
+
// picks which one this render OBSERVES: the session copy keeps following the
|
|
47
|
+
// store, and the landing copy keeps whatever was typed at the landing, so
|
|
48
|
+
// stepping into a chat and back does not destroy either.
|
|
49
|
+
const [storedText, setStoredText] = useSessionState<string>(CHAT_DRAFT_KEY, '');
|
|
50
|
+
const [storedAttachments, setStoredAttachments] = useSessionState<Attachment[]>(CHAT_DRAFT_ATTACHMENTS_KEY, []);
|
|
51
|
+
const [landingText, setLandingText] = useState('');
|
|
52
|
+
const [landingAttachments, setLandingAttachments] = useState<Attachment[]>([]);
|
|
53
|
+
|
|
54
|
+
const inputValue = scoped ? storedText : landingText;
|
|
55
|
+
const setInputValue = scoped ? setStoredText : setLandingText;
|
|
30
56
|
useBrowserPageContextInsert(setInputValue);
|
|
31
|
-
|
|
57
|
+
useReviewIncludeInsert(setInputValue);
|
|
58
|
+
|
|
59
|
+
const inputAttachments = scoped ? storedAttachments : landingAttachments;
|
|
60
|
+
const setInputAttachments = scoped ? setStoredAttachments : setLandingAttachments;
|
|
32
61
|
return { inputValue, setInputValue, inputAttachments, setInputAttachments };
|
|
33
62
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The model a PENDING chat will start on.
|
|
8
|
+
*
|
|
9
|
+
* The composer on a `new-…` chat has no session to read a model from, so its
|
|
10
|
+
* pill showed Kabmo's registry default while `POST /api/agent/new` applies the
|
|
11
|
+
* workspace's own default first. The two disagreed for exactly the project the
|
|
12
|
+
* user had configured a default for. This resolves the same value the spawn
|
|
13
|
+
* does, from the folder row the composer is bound to.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { useMemo } from 'preact/hooks';
|
|
17
|
+
import type { SelectedModel, WorkspaceFolderData } from '@/shared/types';
|
|
18
|
+
import { parseProjectModel } from '@/shared/lib/workspace/project-model';
|
|
19
|
+
|
|
20
|
+
export function usePendingProjectModel(
|
|
21
|
+
folders: WorkspaceFolderData[],
|
|
22
|
+
selectedFolderId: number | null,
|
|
23
|
+
): SelectedModel | null {
|
|
24
|
+
return useMemo(() => {
|
|
25
|
+
const folder = folders.find((row) => String(row.id) === String(selectedFolderId));
|
|
26
|
+
return parseProjectModel(folder?.model);
|
|
27
|
+
}, [folders, selectedFolderId]);
|
|
28
|
+
}
|
|
@@ -50,6 +50,9 @@ const scrollWrites: Array<{ top: number; behavior?: ScrollBehavior }> = [];
|
|
|
50
50
|
/** Frames are queued, never run by the platform, so a test drives them. */
|
|
51
51
|
let frames: Array<() => void> = [];
|
|
52
52
|
|
|
53
|
+
/** The runner's own globals, captured before this suite overwrites them. */
|
|
54
|
+
const saved: Record<string, unknown> = {};
|
|
55
|
+
|
|
53
56
|
function drainFrames(rounds = 6): void {
|
|
54
57
|
for (let i = 0; i < rounds && frames.length > 0; i += 1) {
|
|
55
58
|
const pending = frames;
|
|
@@ -119,6 +122,8 @@ beforeAll(async () => {
|
|
|
119
122
|
cancelAnimationFrame: () => {},
|
|
120
123
|
};
|
|
121
124
|
for (const [key, value] of Object.entries(globals)) {
|
|
125
|
+
// Captured BEFORE the overwrite, so the runner's own values come back.
|
|
126
|
+
saved[key] = (globalThis as Record<string, unknown>)[key];
|
|
122
127
|
(globalThis as Record<string, unknown>)[key] = value;
|
|
123
128
|
}
|
|
124
129
|
// Preact binds its environment at module evaluation, so the modules below
|
|
@@ -129,8 +134,16 @@ beforeAll(async () => {
|
|
|
129
134
|
});
|
|
130
135
|
|
|
131
136
|
afterAll(() => {
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
// RESTORED, never deleted: `requestAnimationFrame`/`cancelAnimationFrame` are
|
|
138
|
+
// in `installDomGlobals`'s list (`pristine-globals.ts`), so a later suite that
|
|
139
|
+
// installs a window keeps whatever this file left behind. Deleting them made
|
|
140
|
+
// every following Preact suite that schedules a frame die with
|
|
141
|
+
// `ReferenceError: cancelAnimationFrame is not defined` (measured:
|
|
142
|
+
// `session-pagination.test.ts`'s rail jump, and the unhandled errors that
|
|
143
|
+
// followed it through `session-switch` and `scroll-reading-back`).
|
|
144
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
145
|
+
if (value === undefined) delete (globalThis as Record<string, unknown>)[key];
|
|
146
|
+
else (globalThis as Record<string, unknown>)[key] = value;
|
|
134
147
|
}
|
|
135
148
|
});
|
|
136
149
|
|