@myrialabs/clopen 0.4.50 → 0.4.51
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 -1
- package/backend/chat/attachments.test.ts +106 -17
- package/backend/chat/attachments.ts +131 -34
- package/backend/chat/engine-handoff.ts +42 -6
- package/backend/chat/stream-manager.ts +41 -5
- package/backend/containers/actions.ts +22 -0
- package/backend/control/actions/projects.ts +93 -37
- package/backend/control/folders.test.ts +27 -2
- package/backend/control/index.ts +2 -1
- package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
- package/backend/database/migrations/086_single_owner.ts +66 -73
- package/backend/database/migrations/090_create_storage_tables.ts +83 -0
- package/backend/database/migrations/index.ts +11 -2
- package/backend/database/queries/integration-queries.ts +10 -0
- package/backend/database/queries/memory-queue-queries.ts +11 -0
- package/backend/database/queries/project-queries.ts +6 -0
- package/backend/database/queries/session-queries.ts +3 -0
- package/backend/database/utils/migration-runner.test.ts +196 -0
- package/backend/database/utils/migration-runner.ts +61 -16
- package/backend/database/utils/seeder-runner.ts +22 -16
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/cursor/environment.ts +1 -1
- package/backend/engine/adapters/qwen/session-store.ts +10 -1
- package/backend/engine/types.ts +7 -0
- package/backend/git/identity/cli.ts +35 -0
- package/backend/git/identity/env.test.ts +52 -1
- package/backend/git/identity/env.ts +69 -10
- package/backend/git/identity/index.ts +25 -6
- package/backend/git/identity/resolve.ts +2 -1
- package/backend/git/identity/scope-config.ts +13 -7
- package/backend/git-hosts/accounts.ts +106 -0
- package/backend/git-hosts/auth/client-ids.ts +34 -0
- package/backend/git-hosts/auth/connect.ts +110 -0
- package/backend/git-hosts/auth/endpoints.ts +130 -0
- package/backend/git-hosts/auth/flows.ts +355 -0
- package/backend/git-hosts/auth/local.ts +152 -0
- package/backend/git-hosts/ci.ts +18 -0
- package/backend/git-hosts/cli.test.ts +82 -0
- package/backend/git-hosts/cli.ts +342 -0
- package/backend/git-hosts/credentials.ts +173 -0
- package/backend/git-hosts/git-credential.ts +30 -0
- package/backend/git-hosts/health.ts +39 -0
- package/backend/git-hosts/http.ts +174 -0
- package/backend/git-hosts/index.ts +34 -0
- package/backend/git-hosts/providers/bitbucket.ts +186 -0
- package/backend/git-hosts/providers/gitea.ts +208 -0
- package/backend/git-hosts/providers/github.ts +270 -0
- package/backend/git-hosts/providers/gitlab-client.ts +70 -0
- package/backend/git-hosts/providers/gitlab.ts +285 -0
- package/backend/git-hosts/providers/locators.test.ts +68 -0
- package/backend/git-hosts/registry.ts +50 -0
- package/backend/git-hosts/service.ts +432 -0
- package/backend/git-hosts/types.ts +82 -0
- package/backend/git-hosts/urls.test.ts +42 -0
- package/backend/git-hosts/urls.ts +69 -0
- package/backend/index.ts +50 -10
- package/backend/integrations/accounts.ts +50 -3
- package/backend/integrations/registry/define.ts +9 -0
- package/backend/integrations/registry/index.ts +11 -0
- package/backend/integrations/registry/providers/bitbucket.ts +51 -0
- package/backend/integrations/registry/providers/gitea.ts +53 -0
- package/backend/integrations/registry/providers/github.ts +24 -7
- package/backend/integrations/registry/providers/gitlab.ts +57 -0
- package/backend/integrations/registry/types.ts +13 -1
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
- package/backend/mentions/diff.ts +63 -0
- package/backend/mentions/index.ts +109 -0
- package/backend/mentions/mentions.test.ts +27 -0
- package/backend/mentions/shared.ts +82 -0
- package/backend/mentions/sources/ai-changes.ts +140 -0
- package/backend/mentions/sources/chats.ts +122 -0
- package/backend/mentions/sources/database.ts +211 -0
- package/backend/mentions/sources/files.ts +240 -0
- package/backend/mentions/sources/git.ts +308 -0
- package/backend/mentions/sources/notes-memory.ts +121 -0
- package/backend/mentions/sources/ops.ts +125 -0
- package/backend/mentions/sources/preview.ts +153 -0
- package/backend/mentions/sources/projects.ts +114 -0
- package/backend/mentions/sources/system.ts +135 -0
- package/backend/mentions/sources/terminal.ts +50 -0
- package/backend/mentions/types.ts +75 -0
- package/backend/preview/browser/bot-check-frames.test.ts +49 -0
- package/backend/preview/browser/bot-check-frames.ts +66 -0
- package/backend/preview/browser/browser-dialog-handler.ts +6 -5
- package/backend/preview/browser/browser-host-bridge.ts +4 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
- package/backend/preview/browser/browser-pool.ts +26 -17
- package/backend/preview/browser/browser-preview-service.ts +164 -2
- package/backend/preview/browser/browser-screenshot.test.ts +113 -0
- package/backend/preview/browser/browser-screenshot.ts +396 -0
- package/backend/preview/browser/browser-tab-manager.ts +35 -186
- package/backend/preview/browser/browser-video-capture.ts +12 -17
- package/backend/preview/browser/element-describe.ts +125 -0
- package/backend/preview/browser/page-binding.ts +141 -0
- package/backend/preview/browser/screenshot-files.test.ts +117 -0
- package/backend/preview/browser/screenshot-files.ts +134 -0
- package/backend/preview/browser/user-agent.test.ts +25 -0
- package/backend/preview/browser/user-agent.ts +100 -0
- package/backend/projects/engine-transcripts.ts +153 -0
- package/backend/projects/folder-guard.ts +55 -0
- package/backend/projects/move.test.ts +208 -0
- package/backend/projects/move.ts +277 -0
- package/backend/projects/project-cleanup.integration.test.ts +3 -1
- package/backend/projects/project-cleanup.ts +10 -0
- package/backend/storage/actions.ts +260 -0
- package/backend/storage/chats.test.ts +57 -0
- package/backend/storage/chats.ts +170 -0
- package/backend/storage/database.ts +105 -0
- package/backend/storage/engine-homes.ts +145 -0
- package/backend/storage/fs-size.ts +111 -0
- package/backend/storage/history.ts +39 -0
- package/backend/storage/policy.ts +156 -0
- package/backend/storage/preview-profiles.ts +169 -0
- package/backend/storage/purge.ts +158 -0
- package/backend/storage/scanner.ts +339 -0
- package/backend/storage/session-index.ts +208 -0
- package/backend/storage/snapshots.ts +99 -0
- package/backend/storage/storage-flow.test.ts +137 -0
- package/backend/storage/transcripts/aliases.ts +75 -0
- package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
- package/backend/storage/transcripts/claude-dedupe.ts +152 -0
- package/backend/storage/transcripts/claude.ts +155 -0
- package/backend/storage/transcripts/cursor.ts +165 -0
- package/backend/storage/transcripts/file-stores.ts +224 -0
- package/backend/storage/transcripts/index.ts +207 -0
- package/backend/storage/transcripts/opencode.ts +124 -0
- package/backend/storage/transcripts/references.ts +42 -0
- package/backend/storage/transcripts/types.ts +58 -0
- package/backend/storage/worktrees.ts +114 -0
- package/backend/terminal/ptykit.ts +25 -0
- package/backend/update/registry.ts +24 -0
- package/backend/update/release-notes.test.ts +110 -0
- package/backend/update/release-notes.ts +132 -0
- package/backend/update/restart.ts +159 -0
- package/backend/utils/env.test.ts +64 -0
- package/backend/utils/env.ts +23 -55
- package/backend/utils/port-utils.ts +13 -0
- package/backend/work/index.ts +13 -2
- package/backend/work/providers/github/actions-logs.ts +1 -1
- package/backend/work/providers/github/adapter.ts +32 -1
- package/backend/work/providers/github/client.ts +7 -3
- package/backend/work/providers/gitlab/adapter.ts +770 -0
- package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
- package/backend/work/service.ts +60 -36
- package/backend/work/start-work.ts +1 -1
- package/backend/work/types.ts +4 -0
- package/backend/worktrees/index.ts +1 -0
- package/backend/worktrees/service.ts +23 -2
- package/backend/ws/chat/composer.ts +47 -6
- package/backend/ws/files/search.ts +1 -1
- package/backend/ws/files/write.ts +27 -0
- package/backend/ws/hosting/index.ts +231 -0
- package/backend/ws/index.ts +12 -2
- package/backend/ws/integrations/crud.ts +31 -5
- package/backend/ws/integrations/hosting-auth.ts +227 -0
- package/backend/ws/integrations/index.ts +2 -0
- package/backend/ws/mentions/index.ts +81 -0
- package/backend/ws/preview/browser/screenshot.ts +184 -0
- package/backend/ws/preview/index.ts +23 -0
- package/backend/ws/projects/crud.ts +66 -58
- package/backend/ws/sessions/crud.ts +7 -95
- package/backend/ws/snapshot/changes.ts +3 -3
- package/backend/ws/storage/index.ts +102 -0
- package/backend/ws/system/index.ts +7 -0
- package/backend/ws/system/operations.ts +125 -69
- package/backend/ws/work/context.ts +3 -4
- package/backend/ws/work/crud.ts +33 -0
- package/backend/ws/work/schemas.ts +4 -1
- package/bin/clopen.ts +15 -16
- package/dist/assets/{index-By6KdSLT.js → index-B9rHDvjg.js} +1 -1
- package/dist/assets/index-B9rHDvjg.js.br +0 -0
- package/dist/assets/index-B9rHDvjg.js.gz +0 -0
- package/dist/assets/{index-DV4TiDn1.js → index-DFlwOd7k.js} +1 -1
- package/dist/assets/index-DFlwOd7k.js.br +0 -0
- package/dist/assets/index-DFlwOd7k.js.gz +0 -0
- package/dist/assets/main-Bz_brxxS.css +1 -0
- package/dist/assets/main-Bz_brxxS.css.br +0 -0
- package/dist/assets/main-Bz_brxxS.css.gz +0 -0
- package/dist/assets/main-DRcX9SHx.js +1273 -0
- package/dist/assets/main-DRcX9SHx.js.br +0 -0
- package/dist/assets/main-DRcX9SHx.js.gz +0 -0
- package/dist/assets/pdf-DfwfQPLy.js +57 -0
- package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
- package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
- package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
- package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
- package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
- package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
- package/package.json +6 -7
- package/scripts/start.ts +21 -4
- package/shared/constants/binary-extensions.ts +20 -4
- package/shared/constants/support.test.ts +27 -0
- package/shared/constants/support.ts +79 -0
- package/shared/constants/tool-icons.ts +7 -1
- package/shared/types/database/schema.ts +6 -0
- package/shared/types/git-hosting.ts +241 -0
- package/shared/types/integrations.ts +51 -1
- package/shared/types/mentions.ts +96 -0
- package/shared/types/release-notes.ts +31 -0
- package/shared/types/storage.ts +175 -0
- package/shared/types/stores/settings.ts +16 -0
- package/shared/types/unified/index.ts +1 -0
- package/shared/types/unified/message.ts +26 -1
- package/shared/types/unified/tool.ts +4 -0
- package/shared/types/work.ts +6 -0
- package/shared/utils/attachment-mentions.test.ts +39 -0
- package/shared/utils/attachment-mentions.ts +100 -0
- package/shared/utils/context-document.test.ts +53 -0
- package/shared/utils/context-document.ts +226 -0
- package/shared/utils/device-frame.test.ts +73 -0
- package/shared/utils/device-frame.ts +320 -0
- package/shared/utils/fuzzy.ts +79 -0
- package/shared/utils/launcher-fingerprint.test.ts +73 -0
- package/shared/utils/launcher-fingerprint.ts +108 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/page-colors.test.ts +17 -0
- package/shared/utils/page-colors.ts +24 -0
- package/shared/utils/process-supervisor.test.ts +18 -1
- package/shared/utils/process-supervisor.ts +12 -23
- package/shared/utils/restart-intent.test.ts +57 -0
- package/shared/utils/restart-intent.ts +80 -0
- package/shared/utils/semver.test.ts +33 -0
- package/shared/utils/semver.ts +35 -0
- package/shared/utils/supervised-child.ts +44 -0
- package/shared/utils/supervisor-protocol.ts +20 -0
- package/.env.example +0 -9
- package/dist/assets/index-By6KdSLT.js.br +0 -0
- package/dist/assets/index-By6KdSLT.js.gz +0 -0
- package/dist/assets/index-DV4TiDn1.js.br +0 -0
- package/dist/assets/index-DV4TiDn1.js.gz +0 -0
- package/dist/assets/main-DIESTGTD.css +0 -1
- package/dist/assets/main-DIESTGTD.css.br +0 -0
- package/dist/assets/main-DIESTGTD.css.gz +0 -0
- package/dist/assets/main-Da3JKoua.js +0 -1240
- package/dist/assets/main-Da3JKoua.js.br +0 -0
- package/dist/assets/main-Da3JKoua.js.gz +0 -0
|
@@ -11,6 +11,13 @@ import type { ActionDef } from './types';
|
|
|
11
11
|
import { commonFields } from './shared';
|
|
12
12
|
import { analyzePage } from './dom-analyze';
|
|
13
13
|
import { resolveWritePath } from '../paths';
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_JPEG_QUALITY,
|
|
16
|
+
type CapturedScreenshot,
|
|
17
|
+
type ScreenshotTarget
|
|
18
|
+
} from '$backend/preview/browser/browser-screenshot';
|
|
19
|
+
import { gitIgnoreState } from '$backend/preview/browser/screenshot-files';
|
|
20
|
+
import type { FrameSpec } from '$shared/utils/device-frame';
|
|
14
21
|
|
|
15
22
|
export const find: ActionDef = {
|
|
16
23
|
type: 'find',
|
|
@@ -90,18 +97,48 @@ export const analyzeDom: ActionDef = {
|
|
|
90
97
|
}
|
|
91
98
|
};
|
|
92
99
|
|
|
100
|
+
const DEVICES = ['mobile', 'tablet', 'laptop', 'desktop'] as const;
|
|
101
|
+
|
|
102
|
+
/** `shots/home.png` → `shots/home-mobile.png`, one file per device. */
|
|
103
|
+
function perDevicePath(saveTo: string, device: string, extension: string): string {
|
|
104
|
+
const dot = saveTo.lastIndexOf('.');
|
|
105
|
+
const stem = dot > saveTo.lastIndexOf('/') ? saveTo.slice(0, dot) : saveTo;
|
|
106
|
+
return `${stem}-${device}.${extension}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
export const screenshot: ActionDef = {
|
|
94
110
|
type: 'screenshot',
|
|
95
111
|
kind: 'control',
|
|
96
112
|
activity: 'Taking a screenshot',
|
|
97
|
-
doc: `screenshot {fullPage?, selector?, format?, quality?, saveTo?, return?} — capture the page.
|
|
113
|
+
doc: `screenshot {fullPage?, selector?, point?, region?, devices?, deviceFrame?, format?, quality?, saveTo?, return?} — capture the page.
|
|
98
114
|
Needed for what the DOM cannot express: canvases, charts, iframes, captchas, and any visual check of layout or styling.
|
|
99
|
-
|
|
115
|
+
What to capture — at most one of: fullPage (whole scrollable page), selector (one element), point {x,y,depth?} (the element under a viewport point, depth ancestors up), region {x,y,width,height} (a viewport rectangle), devices (the page laid out on each listed device — mobile, tablet, laptop, desktop — in a hidden page, without touching the tab). Default: the visible viewport.
|
|
116
|
+
deviceFrame draws the device mockup around a viewport or devices capture, as the user's preview shows it.
|
|
117
|
+
saveTo writes a file under the project directory (with devices, one file per device: name-mobile.png …); with return:"file" the image is not sent back at all, which is what makes "capture twenty pages" affordable.
|
|
100
118
|
format:"jpeg" with quality is much smaller than the default PNG when only the gist matters.`,
|
|
101
119
|
schema: z.object({
|
|
102
120
|
type: z.literal('screenshot'),
|
|
103
121
|
fullPage: z.boolean().optional().describe('Capture the whole scrollable page instead of the viewport.'),
|
|
104
122
|
selector: z.string().optional().describe('Capture just this element.'),
|
|
123
|
+
point: z
|
|
124
|
+
.object({
|
|
125
|
+
x: z.number(),
|
|
126
|
+
y: z.number(),
|
|
127
|
+
depth: z.number().int().min(0).optional().describe('Ancestors to step up from the innermost element (default 0).')
|
|
128
|
+
})
|
|
129
|
+
.optional()
|
|
130
|
+
.describe('Capture the element under this viewport point.'),
|
|
131
|
+
region: z
|
|
132
|
+
.object({ x: z.number(), y: z.number(), width: z.number().positive(), height: z.number().positive() })
|
|
133
|
+
.optional()
|
|
134
|
+
.describe('Capture this rectangle of the viewport, in CSS pixels.'),
|
|
135
|
+
devices: z
|
|
136
|
+
.array(z.enum(DEVICES))
|
|
137
|
+
.min(1)
|
|
138
|
+
.max(4)
|
|
139
|
+
.optional()
|
|
140
|
+
.describe('Capture the page as laid out on each of these devices.'),
|
|
141
|
+
deviceFrame: z.boolean().optional().describe('Draw the device mockup around a viewport or devices capture.'),
|
|
105
142
|
format: z.enum(['png', 'jpeg']).optional().describe('Image format (default: png).'),
|
|
106
143
|
quality: z.number().int().min(1).max(100).optional().describe('JPEG quality (default: 80). Ignored for PNG.'),
|
|
107
144
|
saveTo: z.string().optional().describe('Project-relative path to write the image to.'),
|
|
@@ -110,36 +147,85 @@ export const screenshot: ActionDef = {
|
|
|
110
147
|
}),
|
|
111
148
|
run: async (args, ctx) => {
|
|
112
149
|
const format = args.format ?? 'png';
|
|
150
|
+
const options = { format, quality: args.quality ?? DEFAULT_JPEG_QUALITY } as const;
|
|
113
151
|
const mode = args.return ?? (args.saveTo ? 'both' : 'inline');
|
|
114
152
|
|
|
115
153
|
if (mode !== 'inline' && !args.saveTo) throw new Error('return:"file"/"both" needs saveTo');
|
|
116
154
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
155
|
+
const targets = [args.fullPage, args.selector, args.point, args.region, args.devices].filter((value) => value !== undefined && value !== false);
|
|
156
|
+
if (targets.length > 1) throw new Error('Use at most one of fullPage, selector, point, region and devices');
|
|
157
|
+
if (args.deviceFrame && (args.fullPage || args.selector || args.point || args.region)) {
|
|
158
|
+
throw new Error('deviceFrame only applies to a viewport or devices capture — the frame holds a whole screen');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Each capture with what it is called and the device it can be framed in.
|
|
162
|
+
let shots: Array<{ image: CapturedScreenshot; label: string; device?: string; spec: FrameSpec | null }>;
|
|
163
|
+
|
|
164
|
+
if (args.devices) {
|
|
165
|
+
// The tab's own colours are the best guess for how the page frames on another device.
|
|
166
|
+
const pageColors = ctx.service.screenshotFrameSpec(ctx.tab.id)?.pageColors;
|
|
167
|
+
const taken = await ctx.service.takeResponsiveScreenshots(ctx.tab.id, [...args.devices], args.deviceFrame ? { format: 'png' } : options);
|
|
168
|
+
shots = taken.map((shot) => ({
|
|
169
|
+
image: shot.image,
|
|
170
|
+
label: `${shot.deviceSize} (${shot.viewport.width}×${shot.viewport.height})`,
|
|
171
|
+
device: shot.deviceSize,
|
|
172
|
+
spec: { deviceSize: shot.deviceSize, viewport: shot.viewport, deviceModel: shot.deviceModel, pageColors }
|
|
173
|
+
}));
|
|
132
174
|
} else {
|
|
133
|
-
|
|
175
|
+
// The same capture the viewer's screenshot button uses, so every viewer
|
|
176
|
+
// of the tab sees the shutter when the agent takes one too.
|
|
177
|
+
const target: ScreenshotTarget = args.selector
|
|
178
|
+
? { kind: 'selector', selector: args.selector }
|
|
179
|
+
: args.point
|
|
180
|
+
? { kind: 'element', x: args.point.x, y: args.point.y, depth: args.point.depth }
|
|
181
|
+
: args.region
|
|
182
|
+
? { kind: 'region', ...args.region }
|
|
183
|
+
: args.fullPage
|
|
184
|
+
? { kind: 'fullPage' }
|
|
185
|
+
: { kind: 'viewport' };
|
|
186
|
+
const image = await ctx.service.takeScreenshot(ctx.tab.id, target, args.deviceFrame ? { format: 'png' } : options, 'agent');
|
|
187
|
+
const label = args.selector
|
|
188
|
+
? `screenshot of ${args.selector}`
|
|
189
|
+
: args.point
|
|
190
|
+
? 'screenshot of the element at the point'
|
|
191
|
+
: args.region
|
|
192
|
+
? 'screenshot of the region'
|
|
193
|
+
: 'screenshot';
|
|
194
|
+
shots = [{ image, label, spec: ctx.service.screenshotFrameSpec(ctx.tab.id) }];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (args.deviceFrame) {
|
|
198
|
+
// Captured lossless above; the format asked for is applied once, after framing.
|
|
199
|
+
const framed = await ctx.service.frameScreenshots(
|
|
200
|
+
shots.map((shot) => {
|
|
201
|
+
if (!shot.spec) throw new Error('That tab is no longer open');
|
|
202
|
+
return { image: shot.image, spec: shot.spec };
|
|
203
|
+
}),
|
|
204
|
+
options
|
|
205
|
+
);
|
|
206
|
+
shots = shots.map((shot, index) => ({ ...shot, image: framed[index], label: `${shot.label}, framed` }));
|
|
134
207
|
}
|
|
135
208
|
|
|
136
|
-
const parts: string[] = [
|
|
209
|
+
const parts: string[] = [];
|
|
210
|
+
const root = args.saveTo ? projectQueries.getById(ctx.projectId)?.path : undefined;
|
|
211
|
+
let tracked = 0;
|
|
137
212
|
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
213
|
+
for (const shot of shots) {
|
|
214
|
+
const { image } = shot;
|
|
215
|
+
const line = `${shot.device ? `${shot.device}: ` : ''}${format}, ${image.width}×${image.height}, ${Math.round(image.data.byteLength / 1024)}KB`;
|
|
216
|
+
if (!args.saveTo) {
|
|
217
|
+
parts.push(line);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const target = shot.device ? perDevicePath(args.saveTo, shot.device, format === 'jpeg' ? 'jpg' : 'png') : args.saveTo;
|
|
221
|
+
const absolute = await resolveWritePath(target, ctx.projectId);
|
|
222
|
+
await writeFile(absolute, image.data);
|
|
223
|
+
if (root && (await gitIgnoreState(root, absolute)) === 'not-ignored') tracked += 1;
|
|
224
|
+
parts.push(`${line} saved to ${root ? relative(root, absolute) : absolute}`);
|
|
225
|
+
}
|
|
226
|
+
if (args.fullPage) parts[0] += ', full page';
|
|
227
|
+
if (tracked > 0) {
|
|
228
|
+
parts.push(`git will track ${tracked === 1 ? 'this file' : 'these files'} — keep screenshots in an ignored folder unless they belong in the repository`);
|
|
143
229
|
}
|
|
144
230
|
|
|
145
231
|
return {
|
|
@@ -147,13 +233,11 @@ export const screenshot: ActionDef = {
|
|
|
147
233
|
images:
|
|
148
234
|
mode === 'file'
|
|
149
235
|
? undefined
|
|
150
|
-
:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
]
|
|
236
|
+
: shots.map((shot) => ({
|
|
237
|
+
data: Buffer.from(shot.image.data).toString('base64'),
|
|
238
|
+
mimeType: shot.image.mimeType,
|
|
239
|
+
label: shot.label
|
|
240
|
+
}))
|
|
157
241
|
};
|
|
158
242
|
}
|
|
159
243
|
};
|
|
@@ -39,6 +39,11 @@ Fill a form
|
|
|
39
39
|
Check a layout on mobile
|
|
40
40
|
[{set_viewport, device:"iphone-16"}, {wait_for, state:"networkIdle"}, {screenshot}]
|
|
41
41
|
Same page on Android in dark mode: [{set_viewport, device:"galaxy-s24", colorScheme:"dark"}, {screenshot}]
|
|
42
|
+
Every device at once, without changing the tab: [{screenshot, devices:["mobile","tablet","laptop","desktop"]}]
|
|
43
|
+
|
|
44
|
+
Screenshots to show the user
|
|
45
|
+
[{screenshot, deviceFrame:true, saveTo:"screenshots/home.png"}] — the page inside its device mockup.
|
|
46
|
+
One part of the page: {screenshot, selector:"#pricing"}, or what is under a point: {screenshot, point:{x:640, y:300}}.
|
|
42
47
|
|
|
43
48
|
Debug a page that misbehaves
|
|
44
49
|
[{clear_console}, {click, selector:"#save"}, {wait, ms:500}, {console_logs, level:"error"}]`;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified diffs of two texts, for snapshots that are not in git — the
|
|
3
|
+
* checkpoint blobs the AI-changes view reads.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { diffSequencesAsync, splitLines, type DiffOp } from '$shared/utils/diff-calculator';
|
|
7
|
+
|
|
8
|
+
const CONTEXT = 3;
|
|
9
|
+
|
|
10
|
+
/** A `diff -u` style diff of `before` → `after`, or '' when they are the same. */
|
|
11
|
+
export async function unifiedDiff(path: string, before: string, after: string): Promise<string> {
|
|
12
|
+
if (before === after) return '';
|
|
13
|
+
const a = splitLines(before);
|
|
14
|
+
const b = splitLines(after);
|
|
15
|
+
const ops = await diffSequencesAsync(a, b);
|
|
16
|
+
|
|
17
|
+
// Lines of the edit script, each with where it sits on either side.
|
|
18
|
+
type Line = { op: DiffOp['type']; text: string; oldLine: number; newLine: number };
|
|
19
|
+
const lines: Line[] = [];
|
|
20
|
+
let oldLine = 0;
|
|
21
|
+
let newLine = 0;
|
|
22
|
+
for (const op of ops) {
|
|
23
|
+
if (op.type === 'keep') lines.push({ op: 'keep', text: a[op.oldIndex], oldLine: ++oldLine, newLine: ++newLine });
|
|
24
|
+
else if (op.type === 'delete') lines.push({ op: 'delete', text: a[op.oldIndex], oldLine: ++oldLine, newLine });
|
|
25
|
+
else lines.push({ op: 'insert', text: b[op.newIndex], oldLine, newLine: ++newLine });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const header = [`--- ${before ? `a/${path}` : '/dev/null'}`, `+++ ${after ? `b/${path}` : '/dev/null'}`];
|
|
29
|
+
const hunks: string[] = [];
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (i < lines.length) {
|
|
32
|
+
if (lines[i].op === 'keep') {
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const start = Math.max(0, i - CONTEXT);
|
|
37
|
+
let end = i;
|
|
38
|
+
// Extend while changes are within two contexts of each other.
|
|
39
|
+
while (end < lines.length) {
|
|
40
|
+
if (lines[end].op !== 'keep') {
|
|
41
|
+
end++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let next = end;
|
|
45
|
+
while (next < lines.length && lines[next].op === 'keep') next++;
|
|
46
|
+
if (next < lines.length && next - end <= CONTEXT * 2) end = next;
|
|
47
|
+
else break;
|
|
48
|
+
}
|
|
49
|
+
const stop = Math.min(lines.length, end + CONTEXT);
|
|
50
|
+
const slice = lines.slice(start, stop);
|
|
51
|
+
const first = slice[0];
|
|
52
|
+
const oldStart = first.op === 'insert' ? first.oldLine + 1 : first.oldLine;
|
|
53
|
+
const newStart = first.op === 'delete' ? first.newLine + 1 : first.newLine;
|
|
54
|
+
const oldCount = slice.filter((line) => line.op !== 'insert').length;
|
|
55
|
+
const newCount = slice.filter((line) => line.op !== 'delete').length;
|
|
56
|
+
hunks.push(
|
|
57
|
+
`@@ -${oldCount ? oldStart : oldStart - 1},${oldCount} +${newCount ? newStart : newStart - 1},${newCount} @@`,
|
|
58
|
+
...slice.map((line) => `${line.op === 'keep' ? ' ' : line.op === 'delete' ? '-' : '+'}${line.text}`)
|
|
59
|
+
);
|
|
60
|
+
i = stop;
|
|
61
|
+
}
|
|
62
|
+
return [...header, ...hunks].join('\n');
|
|
63
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@` picker's server side: every mention source, searched together, and
|
|
3
|
+
* the snapshot of whatever is picked.
|
|
4
|
+
*
|
|
5
|
+
* Adding a source is adding it to `SOURCES` — the composer, the prompt and
|
|
6
|
+
* the timeline already know what to do with whatever it captures.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { CapturedAttachment, ContextKind, MentionCandidate, MentionRef } from '$shared/types/mentions';
|
|
10
|
+
import { CONTEXT_MEDIA_TYPE } from '$shared/utils/context-document';
|
|
11
|
+
import { MAX_ATTACHMENT_BYTES } from '$shared/constants/attachments';
|
|
12
|
+
import { debug } from '$shared/utils/logger';
|
|
13
|
+
import { bestFuzzyScore } from '$shared/utils/fuzzy';
|
|
14
|
+
import { filesSource } from './sources/files';
|
|
15
|
+
import { gitSource } from './sources/git';
|
|
16
|
+
import { terminalSource } from './sources/terminal';
|
|
17
|
+
import { previewSource } from './sources/preview';
|
|
18
|
+
import { chatsSource } from './sources/chats';
|
|
19
|
+
import { aiChangesSource } from './sources/ai-changes';
|
|
20
|
+
import { projectsSource } from './sources/projects';
|
|
21
|
+
import { notesMemorySource } from './sources/notes-memory';
|
|
22
|
+
import { databaseSource } from './sources/database';
|
|
23
|
+
import { containersSource, deploymentsSource } from './sources/ops';
|
|
24
|
+
import { systemSource } from './sources/system';
|
|
25
|
+
import { within } from './shared';
|
|
26
|
+
import type { MentionCategory, MentionContext, MentionSource } from './types';
|
|
27
|
+
|
|
28
|
+
export type { MentionContext, MentionCategory } from './types';
|
|
29
|
+
|
|
30
|
+
/** In the order their rows are listed. */
|
|
31
|
+
const SOURCES: MentionSource[] = [
|
|
32
|
+
filesSource,
|
|
33
|
+
gitSource,
|
|
34
|
+
previewSource,
|
|
35
|
+
terminalSource,
|
|
36
|
+
chatsSource,
|
|
37
|
+
aiChangesSource,
|
|
38
|
+
projectsSource,
|
|
39
|
+
notesMemorySource,
|
|
40
|
+
databaseSource,
|
|
41
|
+
deploymentsSource,
|
|
42
|
+
containersSource,
|
|
43
|
+
systemSource
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/** How long one source may take at the root before the picker answers without it. */
|
|
47
|
+
const ROOT_BUDGET_MS = 1500;
|
|
48
|
+
/** Opening a category waits longer: that list is all the picker shows. */
|
|
49
|
+
const CATEGORY_BUDGET_MS = 20_000;
|
|
50
|
+
|
|
51
|
+
export interface MentionSearch {
|
|
52
|
+
category?: string;
|
|
53
|
+
query: string;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function searchMentions(
|
|
58
|
+
ctx: MentionContext,
|
|
59
|
+
search: MentionSearch
|
|
60
|
+
): Promise<{ items: MentionCandidate[]; categories: MentionCategory[] }> {
|
|
61
|
+
const query = search.query.trim();
|
|
62
|
+
const limit = Math.min(Math.max(search.limit ?? 50, 1), 200);
|
|
63
|
+
const budget = search.category ? CATEGORY_BUDGET_MS : ROOT_BUDGET_MS;
|
|
64
|
+
|
|
65
|
+
const answer = async <T>(source: MentionSource, work: () => Promise<T> | T, fallback: T): Promise<T> => {
|
|
66
|
+
try {
|
|
67
|
+
return await within(Promise.resolve(work()), budget, fallback);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
debug.warn('chat', `A mention source failed (${source.kinds[0]}):`, error);
|
|
70
|
+
return fallback;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const lists = await Promise.all(
|
|
75
|
+
SOURCES.map((source) => answer(source, () => source.list(ctx, { category: search.category, query, limit }), [] as MentionCandidate[]))
|
|
76
|
+
);
|
|
77
|
+
const items = lists.flat();
|
|
78
|
+
|
|
79
|
+
if (search.category) return { items: items.slice(0, limit), categories: [] };
|
|
80
|
+
|
|
81
|
+
const all = (await Promise.all(SOURCES.map((source) => answer(source, () => source.categories(ctx), [] as MentionCategory[])))).flat();
|
|
82
|
+
const categories = query
|
|
83
|
+
? all.filter((category) => bestFuzzyScore(query, [category.label, category.detail]) > 0)
|
|
84
|
+
: all;
|
|
85
|
+
return { items, categories };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Take the snapshot of what was picked: its documents, then its pictures. */
|
|
89
|
+
export async function captureMention(ctx: MentionContext, kind: ContextKind, ref: MentionRef): Promise<CapturedAttachment[]> {
|
|
90
|
+
const source = SOURCES.find((entry) => entry.kinds.includes(kind));
|
|
91
|
+
if (!source) throw new Error(`Nothing can be mentioned as ${kind}`);
|
|
92
|
+
const captured = await source.capture(ctx, kind, ref);
|
|
93
|
+
return [
|
|
94
|
+
...captured.documents.map((document) => ({
|
|
95
|
+
fileName: document.fileName,
|
|
96
|
+
mediaType: CONTEXT_MEDIA_TYPE,
|
|
97
|
+
data: withinLimit(document.text).toString('base64')
|
|
98
|
+
})),
|
|
99
|
+
...(captured.images ?? [])
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The document's bytes, cut to what an attachment may hold — the header always survives. */
|
|
104
|
+
function withinLimit(text: string): Buffer {
|
|
105
|
+
const bytes = Buffer.from(text, 'utf8');
|
|
106
|
+
if (bytes.length <= MAX_ATTACHMENT_BYTES) return bytes;
|
|
107
|
+
const note = Buffer.from(`\n\n… cut here: the snapshot was larger than ${Math.round(MAX_ATTACHMENT_BYTES / (1024 * 1024))} MB.\n`, 'utf8');
|
|
108
|
+
return Buffer.concat([bytes.subarray(0, MAX_ATTACHMENT_BYTES - note.length), note]);
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { unifiedDiff } from './diff';
|
|
3
|
+
import { rank, stripAnsi } from './shared';
|
|
4
|
+
import { terminalText } from './sources/terminal';
|
|
5
|
+
|
|
6
|
+
describe('mention helpers', () => {
|
|
7
|
+
it('write a unified diff with context around each change', async () => {
|
|
8
|
+
const before = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'].join('\n');
|
|
9
|
+
const after = ['a', 'b', 'C', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'].join('\n');
|
|
10
|
+
expect(await unifiedDiff('x.txt', before, after)).toBe(
|
|
11
|
+
['--- a/x.txt', '+++ b/x.txt', '@@ -1,6 +1,6 @@', ' a', ' b', '-c', '+C', ' d', ' e', ' f', '@@ -8,3 +8,4 @@', ' h', ' i', ' j', '+k'].join('\n')
|
|
12
|
+
);
|
|
13
|
+
expect(await unifiedDiff('x.txt', 'same', 'same')).toBe('');
|
|
14
|
+
expect(await unifiedDiff('new.txt', '', 'hello')).toBe(['--- /dev/null', '+++ b/new.txt', '@@ -0,0 +1,1 @@', '+hello'].join('\n'));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('turn a terminal screen into the text a person saw', () => {
|
|
18
|
+
expect(stripAnsi('\u001b[1;31merror\u001b[0m: \u001b]0;title\u0007done')).toBe('error: done');
|
|
19
|
+
expect(terminalText('$ ls \r\nfile\r\n\r\n\r\n\r\n$ \u001b[K ')).toBe('$ ls\nfile\n\n$');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('rank by match, keeping the given order with no query', () => {
|
|
23
|
+
const items = ['readme.md', 'src/app.ts', 'src/apple.ts'];
|
|
24
|
+
expect(rank(items, '', (item) => [item], 2)).toEqual(['readme.md', 'src/app.ts']);
|
|
25
|
+
expect(rank(items, 'app', (item) => [item], 5)).toEqual(['src/app.ts', 'src/apple.ts']);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers the mention sources share.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { bestFuzzyScore } from '$shared/utils/fuzzy';
|
|
6
|
+
import { execGit } from '$backend/git/git-executor';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Keep what matches `query`, best first, at most `limit`. With no query the
|
|
10
|
+
* order given is kept — sources list most recent or most relevant first.
|
|
11
|
+
*/
|
|
12
|
+
export function rank<T>(items: T[], query: string, texts: (item: T) => Array<string | undefined | null>, limit: number): T[] {
|
|
13
|
+
if (!query.trim()) return items.slice(0, limit);
|
|
14
|
+
return items
|
|
15
|
+
.map((item, order) => ({ item, order, score: bestFuzzyScore(query, texts(item)) }))
|
|
16
|
+
.filter((entry) => entry.score > 0)
|
|
17
|
+
.sort((a, b) => b.score - a.score || a.order - b.order)
|
|
18
|
+
.slice(0, limit)
|
|
19
|
+
.map((entry) => entry.item);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Whether `category` is the one asked for, or the root is. */
|
|
23
|
+
export function wants(category: string | undefined, own: string): 'root' | 'own' | null {
|
|
24
|
+
if (!category) return 'root';
|
|
25
|
+
return category === own ? 'own' : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Resolve within `ms`, or with `fallback`. A slow source must not hold the picker. */
|
|
29
|
+
export async function within<T>(work: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
30
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
31
|
+
try {
|
|
32
|
+
return await Promise.race([
|
|
33
|
+
work,
|
|
34
|
+
new Promise<T>((resolve) => {
|
|
35
|
+
timer = setTimeout(() => resolve(fallback), ms);
|
|
36
|
+
})
|
|
37
|
+
]);
|
|
38
|
+
} finally {
|
|
39
|
+
if (timer) clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A git command's output, or null when it fails (not a repo, no git, bad ref). */
|
|
44
|
+
export async function gitText(args: string[], cwd: string, timeout = 20_000, okExitCodes: number[] = []): Promise<string | null> {
|
|
45
|
+
try {
|
|
46
|
+
const result = await execGit(args, cwd, { timeout, okExitCodes });
|
|
47
|
+
return result.stdout;
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** "3 minutes ago" for a timestamp, for a row's detail line. */
|
|
54
|
+
export function ago(value: string | number | Date | null | undefined): string {
|
|
55
|
+
if (value === null || value === undefined || value === '') return '';
|
|
56
|
+
const time = new Date(value).getTime();
|
|
57
|
+
if (!Number.isFinite(time)) return '';
|
|
58
|
+
const seconds = Math.max(0, Math.round((Date.now() - time) / 1000));
|
|
59
|
+
if (seconds < 60) return 'just now';
|
|
60
|
+
const minutes = Math.round(seconds / 60);
|
|
61
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
62
|
+
const hours = Math.round(minutes / 60);
|
|
63
|
+
if (hours < 24) return `${hours} h ago`;
|
|
64
|
+
const days = Math.round(hours / 24);
|
|
65
|
+
if (days < 30) return `${days} d ago`;
|
|
66
|
+
return new Date(time).toISOString().slice(0, 10);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Remove terminal escape sequences, leaving the text a person saw. */
|
|
70
|
+
export function stripAnsi(text: string): string {
|
|
71
|
+
return (
|
|
72
|
+
text
|
|
73
|
+
// OSC (titles, hyperlinks), ended by BEL or ST.
|
|
74
|
+
.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, '')
|
|
75
|
+
// CSI sequences: colours, cursor moves, erases.
|
|
76
|
+
.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '')
|
|
77
|
+
// Other two-character escapes.
|
|
78
|
+
.replace(/\u001b[@-Z\\-_]/g, '')
|
|
79
|
+
// Lone control characters except tab and newline.
|
|
80
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '')
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the AI changed in this chat: one turn, or the whole chat net.
|
|
3
|
+
*
|
|
4
|
+
* Read from checkpoint snapshots — the same record the AI-changes panel shows
|
|
5
|
+
* — so a change made by a shell command counts as much as one made by an edit
|
|
6
|
+
* tool. Only turns still on the active branch are offered: a restored-away
|
|
7
|
+
* turn describes nothing on disk.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { MentionCandidate } from '$shared/types/mentions';
|
|
11
|
+
import type { SessionScopedChanges } from '$shared/types/database/schema';
|
|
12
|
+
import { buildContextDocument, type ContextSection } from '$shared/utils/context-document';
|
|
13
|
+
import { loadMessage } from '$shared/utils/message-formatter';
|
|
14
|
+
import { snapshotQueries } from '$backend/database/queries';
|
|
15
|
+
import { extractMessageText } from '$backend/snapshot/helpers';
|
|
16
|
+
import { excerptPrompt, statusOf } from '$backend/snapshot/turn-changes';
|
|
17
|
+
import { activeCheckpoints, parseSessionChanges, readTextBlob } from '$backend/ws/snapshot/changes';
|
|
18
|
+
import { unifiedDiff } from '../diff';
|
|
19
|
+
import { ago, rank, wants } from '../shared';
|
|
20
|
+
import { type MentionContext, type MentionSource } from '../types';
|
|
21
|
+
|
|
22
|
+
const CATEGORY = 'ai-changes';
|
|
23
|
+
|
|
24
|
+
interface Turn {
|
|
25
|
+
checkpointId: string;
|
|
26
|
+
index: number;
|
|
27
|
+
prompt: string;
|
|
28
|
+
at: string;
|
|
29
|
+
changes: SessionScopedChanges;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** How long a chat's turn list is reused: the picker asks on every keystroke. */
|
|
33
|
+
const TURNS_TTL_MS = 10_000;
|
|
34
|
+
const turnsCache = new Map<string, { at: number; turns: Turn[] }>();
|
|
35
|
+
|
|
36
|
+
/** The turns that changed something, oldest first — read once per few keystrokes. */
|
|
37
|
+
function turnsOf(chatSessionId: string | null): Turn[] {
|
|
38
|
+
if (!chatSessionId) return [];
|
|
39
|
+
const hit = turnsCache.get(chatSessionId);
|
|
40
|
+
if (hit && Date.now() - hit.at < TURNS_TTL_MS) return hit.turns;
|
|
41
|
+
const turns = readTurns(chatSessionId);
|
|
42
|
+
turnsCache.set(chatSessionId, { at: Date.now(), turns });
|
|
43
|
+
if (turnsCache.size > 50) turnsCache.delete(turnsCache.keys().next().value!);
|
|
44
|
+
return turns;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readTurns(chatSessionId: string): Turn[] {
|
|
48
|
+
return activeCheckpoints(chatSessionId)
|
|
49
|
+
.map((checkpoint, i) => ({
|
|
50
|
+
checkpointId: checkpoint.id,
|
|
51
|
+
index: i + 1,
|
|
52
|
+
prompt: excerptPrompt(extractMessageText(loadMessage(checkpoint)).replace(/\s+/g, ' ').trim(), 120),
|
|
53
|
+
at: checkpoint.created_at,
|
|
54
|
+
changes: parseSessionChanges(snapshotQueries.getByMessageId(checkpoint.id)?.session_changes)
|
|
55
|
+
}))
|
|
56
|
+
.filter((turn) => Object.keys(turn.changes).length > 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rows(ctx: MentionContext): MentionCandidate[] {
|
|
60
|
+
const turns = turnsOf(ctx.chatSessionId);
|
|
61
|
+
if (turns.length === 0) return [];
|
|
62
|
+
const files = new Set(turns.flatMap((turn) => Object.keys(turn.changes)));
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
key: 'ai-changes:all', kind: 'ai-changes', group: 'AI changes', label: 'Everything this chat changed',
|
|
66
|
+
detail: `${files.size} ${files.size === 1 ? 'file' : 'files'} over ${turns.length} ${turns.length === 1 ? 'turn' : 'turns'}`,
|
|
67
|
+
icon: 'lucide:sparkles', ref: {}
|
|
68
|
+
},
|
|
69
|
+
...[...turns].reverse().map((turn) => {
|
|
70
|
+
const count = Object.keys(turn.changes).length;
|
|
71
|
+
return {
|
|
72
|
+
key: `ai-changes:${turn.checkpointId}`, kind: 'ai-changes' as const, group: 'AI changes',
|
|
73
|
+
label: `Turn ${turn.index}: ${turn.prompt || '(no text)'}`,
|
|
74
|
+
detail: `${count} ${count === 1 ? 'file' : 'files'} · ${ago(turn.at)}`, icon: 'lucide:sparkles' as const,
|
|
75
|
+
ref: { checkpointId: turn.checkpointId }
|
|
76
|
+
};
|
|
77
|
+
})
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const aiChangesSource: MentionSource = {
|
|
82
|
+
kinds: ['ai-changes'],
|
|
83
|
+
|
|
84
|
+
categories(ctx) {
|
|
85
|
+
const turns = turnsOf(ctx.chatSessionId);
|
|
86
|
+
if (turns.length === 0) return [];
|
|
87
|
+
return [{ id: CATEGORY, label: 'AI changes', detail: `${turns.length} ${turns.length === 1 ? 'turn' : 'turns'} in this chat`, icon: 'lucide:sparkles', group: 'Chats' }];
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async list(ctx, request) {
|
|
91
|
+
const mode = wants(request.category, CATEGORY);
|
|
92
|
+
if (!mode) return [];
|
|
93
|
+
const all = rows(ctx);
|
|
94
|
+
if (mode === 'root') return request.query.trim() ? rank(all, request.query, (row) => [row.label, 'ai changes'], 2) : [];
|
|
95
|
+
return rank(all, request.query, (row) => [row.label], request.limit);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async capture(ctx, _kind, ref) {
|
|
99
|
+
// A capture reads the chat as it is now, not as it was a few seconds ago.
|
|
100
|
+
const turns = ctx.chatSessionId ? readTurns(ctx.chatSessionId) : [];
|
|
101
|
+
const checkpointId = typeof ref.checkpointId === 'string' ? ref.checkpointId : null;
|
|
102
|
+
const chosen = checkpointId ? turns.filter((turn) => turn.checkpointId === checkpointId) : turns;
|
|
103
|
+
if (chosen.length === 0) throw new Error('Those changes are no longer on this branch');
|
|
104
|
+
|
|
105
|
+
// Net over the turns: the first "before" and the last "after" of each file.
|
|
106
|
+
const net = new Map<string, { oldHash: string; newHash: string }>();
|
|
107
|
+
for (const turn of chosen) {
|
|
108
|
+
for (const [path, change] of Object.entries(turn.changes)) {
|
|
109
|
+
const known = net.get(path);
|
|
110
|
+
net.set(path, { oldHash: known ? known.oldHash : change.oldHash, newHash: change.newHash });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const sections: ContextSection[] = [];
|
|
115
|
+
const summary: string[] = [];
|
|
116
|
+
for (const [path, change] of net) {
|
|
117
|
+
if (change.oldHash === change.newHash) continue;
|
|
118
|
+
const status = statusOf(change.oldHash, change.newHash);
|
|
119
|
+
summary.push(`${status.padEnd(8)} ${path}`);
|
|
120
|
+
const before = change.oldHash ? await readTextBlob(change.oldHash) : '';
|
|
121
|
+
const after = change.newHash ? await readTextBlob(change.newHash) : '';
|
|
122
|
+
if (before === null || after === null) {
|
|
123
|
+
sections.push({ title: path, body: `Binary file ${status}.` });
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
sections.push({ title: path, body: await unifiedDiff(path, before, after), fence: 'diff' });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const label = checkpointId ? `Turn ${chosen[0].index}: ${chosen[0].prompt || '(no text)'}` : 'Everything this chat changed';
|
|
130
|
+
return {
|
|
131
|
+
documents: [buildContextDocument({
|
|
132
|
+
kind: 'ai-changes',
|
|
133
|
+
label,
|
|
134
|
+
detail: `${summary.length} ${summary.length === 1 ? 'file' : 'files'}`,
|
|
135
|
+
facts: [['Turns', chosen.map((turn) => turn.index).join(', ')]],
|
|
136
|
+
sections: [{ title: 'Files', body: summary.join('\n') || 'Nothing left changed.', fence: '' }, ...sections]
|
|
137
|
+
})]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|