@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
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move a project to another folder — renaming its folder on disk, or pointing
|
|
3
|
+
* it at a folder that was moved outside Clopen ("Locate folder").
|
|
4
|
+
*
|
|
5
|
+
* A project's name IS its folder's name, so both are one operation here and
|
|
6
|
+
* there is no separate "display name" to keep in step.
|
|
7
|
+
*
|
|
8
|
+
* The folder path is load-bearing in more places than the `projects` row:
|
|
9
|
+
* engines file chat history under it, the memory queue remembers it, and
|
|
10
|
+
* saved panel state refers to files by absolute path. Each is carried along,
|
|
11
|
+
* so chats resume, panels reopen and memory keeps extracting after the move.
|
|
12
|
+
*
|
|
13
|
+
* Work running in the folder blocks the move unless the caller asks to stop
|
|
14
|
+
* it (`force`): a running chat would keep writing into the old path, and a
|
|
15
|
+
* shell would sit in a directory that is no longer named what it says.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { existsSync, statSync } from 'fs';
|
|
19
|
+
import { rename } from 'fs/promises';
|
|
20
|
+
import { basename, dirname, join, resolve } from 'path';
|
|
21
|
+
import { getDatabase } from '$backend/database';
|
|
22
|
+
import { memoryQueueQueries, projectQueries, sessionQueries } from '$backend/database/queries';
|
|
23
|
+
import { streamManager, type StreamState } from '$backend/chat/stream-manager';
|
|
24
|
+
import { countLiveMainTreeSessions, cleanupMainTreeSessions } from '$backend/terminal/ptykit';
|
|
25
|
+
import { disposeProjectEngines } from '$backend/engine';
|
|
26
|
+
import { fileWatcher } from '$backend/files/file-watcher';
|
|
27
|
+
import { execGit } from '$backend/git/git-executor';
|
|
28
|
+
import { ws } from '$backend/utils/ws';
|
|
29
|
+
import { broadcastPresence } from '$backend/ws/projects/status';
|
|
30
|
+
import { isHomeProject } from '$shared/utils/home-project';
|
|
31
|
+
import type { Project } from '$shared/types/database/schema';
|
|
32
|
+
import { debug } from '$shared/utils/logger';
|
|
33
|
+
import { projectAtFolder, protectedFolderReason, validFolderName } from './folder-guard';
|
|
34
|
+
import { moveEngineTranscripts } from './engine-transcripts';
|
|
35
|
+
|
|
36
|
+
/** What is running in a project's main tree right now. */
|
|
37
|
+
export interface ProjectUsage {
|
|
38
|
+
chats: number;
|
|
39
|
+
terminals: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type MoveRequest = { kind: 'rename'; name: string } | { kind: 'relocate'; path: string };
|
|
43
|
+
|
|
44
|
+
export type MoveOutcome =
|
|
45
|
+
| { status: 'busy'; usage: ProjectUsage }
|
|
46
|
+
| { status: 'moved'; project: Project; previousPath: string; warnings: string[] };
|
|
47
|
+
|
|
48
|
+
/** A project as the client sees it: with whether its folder is still there. */
|
|
49
|
+
export function withFolderState(project: Project): Project {
|
|
50
|
+
return { ...project, missing: !existsSync(project.path) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Chat streams generating in the main tree. A worktree's chat runs in the
|
|
55
|
+
* worktree's own folder, which moving the project folder does not touch.
|
|
56
|
+
*/
|
|
57
|
+
function mainTreeStreams(projectId: string): StreamState[] {
|
|
58
|
+
return streamManager
|
|
59
|
+
.getProjectStreams(projectId)
|
|
60
|
+
.filter((stream) => stream.status === 'active' && !sessionQueries.getById(stream.chatSessionId)?.worktree_id);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getProjectUsage(projectId: string): ProjectUsage {
|
|
64
|
+
return { chats: mainTreeStreams(projectId).length, terminals: countLiveMainTreeSessions(projectId) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isBusy(usage: ProjectUsage): boolean {
|
|
68
|
+
return usage.chats > 0 || usage.terminals > 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Stop everything `getProjectUsage` counts, the same way the Stop button and closing a tab do. */
|
|
72
|
+
async function stopProjectUsage(projectId: string): Promise<void> {
|
|
73
|
+
for (const stream of mainTreeStreams(projectId)) {
|
|
74
|
+
await streamManager.cancelStream(stream.streamId, 'project-moved');
|
|
75
|
+
ws.emit.chatSession(stream.chatSessionId, 'chat:cancelled', {
|
|
76
|
+
chatSessionId: stream.chatSessionId,
|
|
77
|
+
status: 'cancelled',
|
|
78
|
+
processId: stream.processId
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const killed = cleanupMainTreeSessions(projectId);
|
|
82
|
+
debug.log('project', `Stopped work in ${projectId} before moving it (${killed} terminal sessions)`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `value` with every path at or under `from` re-rooted at `to`. Strings that
|
|
87
|
+
* are themselves JSON (panel state is stored as JSON inside JSON) are opened,
|
|
88
|
+
* rewritten and closed again, so nested paths move too.
|
|
89
|
+
*/
|
|
90
|
+
export function rewritePathPrefix(value: unknown, from: string, to: string): unknown {
|
|
91
|
+
if (typeof value === 'string') {
|
|
92
|
+
if (value === from) return to;
|
|
93
|
+
if (value.startsWith(`${from}/`) || value.startsWith(`${from}\\`)) return to + value.slice(from.length);
|
|
94
|
+
const head = value.trimStart()[0];
|
|
95
|
+
if (head === '{' || head === '[') {
|
|
96
|
+
try {
|
|
97
|
+
const parsed: unknown = JSON.parse(value);
|
|
98
|
+
const rewritten = rewritePathPrefix(parsed, from, to);
|
|
99
|
+
return rewritten === parsed ? value : JSON.stringify(rewritten);
|
|
100
|
+
} catch {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
let changed = false;
|
|
108
|
+
const next = value.map((item) => {
|
|
109
|
+
const rewritten = rewritePathPrefix(item, from, to);
|
|
110
|
+
if (rewritten !== item) changed = true;
|
|
111
|
+
return rewritten;
|
|
112
|
+
});
|
|
113
|
+
return changed ? next : value;
|
|
114
|
+
}
|
|
115
|
+
if (value && typeof value === 'object') {
|
|
116
|
+
let changed = false;
|
|
117
|
+
const next: Record<string, unknown> = {};
|
|
118
|
+
for (const [key, item] of Object.entries(value)) {
|
|
119
|
+
const rewritten = rewritePathPrefix(item, from, to);
|
|
120
|
+
if (rewritten !== item) changed = true;
|
|
121
|
+
next[key] = rewritten;
|
|
122
|
+
}
|
|
123
|
+
return changed ? next : value;
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function rewriteStoredJson(raw: string | null, from: string, to: string): string | null {
|
|
129
|
+
if (!raw) return raw;
|
|
130
|
+
const rewritten = rewritePathPrefix(raw, from, to);
|
|
131
|
+
return typeof rewritten === 'string' ? rewritten : raw;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Same filesystem entry — a case-only rename on a case-insensitive disk resolves to the source. */
|
|
135
|
+
function isSameEntry(a: string, b: string): boolean {
|
|
136
|
+
try {
|
|
137
|
+
const left = statSync(a);
|
|
138
|
+
const right = statSync(b);
|
|
139
|
+
return left.ino === right.ino && left.dev === right.dev;
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isDirectory(path: string): boolean {
|
|
146
|
+
try {
|
|
147
|
+
return statSync(path).isDirectory();
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Where the request sends the project, after every check that needs no side effect. */
|
|
154
|
+
function resolveTarget(project: Project, request: MoveRequest): string {
|
|
155
|
+
const current = resolve(project.path);
|
|
156
|
+
|
|
157
|
+
if (request.kind === 'rename') {
|
|
158
|
+
const name = validFolderName(request.name);
|
|
159
|
+
if (!isDirectory(current)) {
|
|
160
|
+
throw new Error('The project folder is no longer there. Use Locate folder to point the project at where it is now.');
|
|
161
|
+
}
|
|
162
|
+
const reason = protectedFolderReason(current, project.id);
|
|
163
|
+
if (reason) throw new Error(`This folder cannot be renamed: ${reason}.`);
|
|
164
|
+
const target = join(dirname(current), name);
|
|
165
|
+
if (target !== current && existsSync(target) && !isSameEntry(current, target)) {
|
|
166
|
+
throw new Error(`A folder named "${name}" already exists next to it.`);
|
|
167
|
+
}
|
|
168
|
+
return target;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const target = resolve(request.path);
|
|
172
|
+
if (!isDirectory(target)) throw new Error('There is no folder at that path.');
|
|
173
|
+
const reason = protectedFolderReason(target, project.id);
|
|
174
|
+
if (reason) throw new Error(`That folder cannot be used: ${reason}.`);
|
|
175
|
+
return target;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Repair `git worktree` links in both directions; a repository without any is left alone. */
|
|
179
|
+
async function repairGitWorktrees(folder: string): Promise<string | null> {
|
|
180
|
+
if (!existsSync(join(folder, '.git'))) return null;
|
|
181
|
+
try {
|
|
182
|
+
const result = await execGit(['worktree', 'repair'], folder, 15000);
|
|
183
|
+
if (result.exitCode === 0) return null;
|
|
184
|
+
return `Git worktrees linked to this repository could not be repaired: ${result.stderr.trim() || 'git worktree repair failed'}.`;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return `Git worktrees linked to this repository could not be repaired: ${error instanceof Error ? error.message : String(error)}.`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function friendlyRenameError(error: unknown): Error {
|
|
191
|
+
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
|
192
|
+
if (code === 'EBUSY' || code === 'EPERM' || code === 'EACCES') {
|
|
193
|
+
return new Error('The folder could not be renamed because another program is using it. Close any editor, terminal or process open in it and try again.');
|
|
194
|
+
}
|
|
195
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Rename a project's folder or point the project at another one. Returns
|
|
200
|
+
* `busy` without touching anything when work is running and `force` is off.
|
|
201
|
+
*/
|
|
202
|
+
export async function moveProject(projectId: string, request: MoveRequest, force = false): Promise<MoveOutcome> {
|
|
203
|
+
const project = projectQueries.getById(projectId);
|
|
204
|
+
if (!project) throw new Error('That project no longer exists.');
|
|
205
|
+
if (isHomeProject(project)) throw new Error('Home cannot be renamed or moved.');
|
|
206
|
+
|
|
207
|
+
const previousPath = project.path;
|
|
208
|
+
const target = resolveTarget(project, request);
|
|
209
|
+
|
|
210
|
+
const owner = projectAtFolder(target);
|
|
211
|
+
if (owner && owner.id !== project.id) throw new Error(`That folder is already the project ${owner.name}.`);
|
|
212
|
+
|
|
213
|
+
// Nothing to move: same folder, same spelling.
|
|
214
|
+
if (target === resolve(previousPath)) {
|
|
215
|
+
return { status: 'moved', project: withFolderState(project), previousPath, warnings: [] };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const usage = getProjectUsage(projectId);
|
|
219
|
+
const stopping = isBusy(usage);
|
|
220
|
+
if (stopping) {
|
|
221
|
+
if (!force) return { status: 'busy', usage };
|
|
222
|
+
await stopProjectUsage(projectId);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Idle state bound to the old path: engines cached with it as cwd (an
|
|
226
|
+
// OpenCode server, a Pi runtime) and the main tree's file watcher. Both are
|
|
227
|
+
// rebuilt on demand at the new path.
|
|
228
|
+
await disposeProjectEngines(projectId);
|
|
229
|
+
fileWatcher.releaseProject(projectId);
|
|
230
|
+
|
|
231
|
+
const renaming = request.kind === 'rename';
|
|
232
|
+
if (renaming) {
|
|
233
|
+
try {
|
|
234
|
+
await rename(previousPath, target);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
throw friendlyRenameError(error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
const commit = () => {
|
|
242
|
+
projectQueries.relocate(projectId, target, basename(target));
|
|
243
|
+
memoryQueueQueries.repointProject(projectId, previousPath, target);
|
|
244
|
+
projectQueries.setWorkspaceState(projectId, rewriteStoredJson(projectQueries.getWorkspaceState(projectId), previousPath, target));
|
|
245
|
+
projectQueries.setFilesPanelState(projectId, rewriteStoredJson(projectQueries.getFilesPanelState(projectId), previousPath, target));
|
|
246
|
+
};
|
|
247
|
+
const db = getDatabase();
|
|
248
|
+
if (db.transaction) db.transaction(commit)();
|
|
249
|
+
else commit();
|
|
250
|
+
} catch (error) {
|
|
251
|
+
// The record still names the old folder, so the folder goes back there.
|
|
252
|
+
if (renaming) {
|
|
253
|
+
await rename(target, previousPath).catch((rollbackError) => {
|
|
254
|
+
debug.error('project', `Could not move ${target} back to ${previousPath}:`, rollbackError);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const warnings = moveEngineTranscripts(previousPath, target);
|
|
261
|
+
const gitProblem = await repairGitWorktrees(target);
|
|
262
|
+
if (gitProblem) warnings.push(gitProblem);
|
|
263
|
+
|
|
264
|
+
const moved = withFolderState(projectQueries.getById(projectId)!);
|
|
265
|
+
debug.log('project', `Moved project ${projectId}: ${previousPath} -> ${target}`);
|
|
266
|
+
|
|
267
|
+
// Every device follows: the sidebar shows the new name, and a device with
|
|
268
|
+
// the project open reloads its workspace at the new path.
|
|
269
|
+
ws.emit.global('projects:updated', { project: moved, previousPath });
|
|
270
|
+
if (stopping) {
|
|
271
|
+
broadcastPresence().catch((err) => {
|
|
272
|
+
debug.warn('project', 'Presence broadcast error after project move:', err);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return { status: 'moved', project: moved, previousPath, warnings };
|
|
277
|
+
}
|
|
@@ -3,7 +3,7 @@ import { projectCleanupRegistry, runProjectCleanups } from './project-cleanup-re
|
|
|
3
3
|
|
|
4
4
|
import './project-cleanup';
|
|
5
5
|
|
|
6
|
-
const DEFAULT_CLEANUP_HANDLERS = ['engine', 'mcp-context', 'file-watcher', 'worktrees'] as const;
|
|
6
|
+
const DEFAULT_CLEANUP_HANDLERS = ['engine', 'mcp-context', 'file-watcher', 'preview-profile', 'worktrees'] as const;
|
|
7
7
|
|
|
8
8
|
describe('project cleanup integration', () => {
|
|
9
9
|
test('registers default backend handlers when project-cleanup is loaded', () => {
|
|
@@ -14,6 +14,8 @@ describe('project cleanup integration', () => {
|
|
|
14
14
|
expect(names.indexOf('engine')).toBeLessThan(names.indexOf('mcp-context'));
|
|
15
15
|
expect(names.indexOf('mcp-context')).toBeLessThan(names.indexOf('file-watcher'));
|
|
16
16
|
expect(names.indexOf('file-watcher')).toBeLessThan(names.indexOf('worktrees'));
|
|
17
|
+
// Before worktrees: the main tree's profile is named from the project id alone.
|
|
18
|
+
expect(names.indexOf('preview-profile')).toBeLessThan(names.indexOf('worktrees'));
|
|
17
19
|
});
|
|
18
20
|
|
|
19
21
|
test('runProjectCleanups runs default handlers without throwing', async () => {
|
|
@@ -7,6 +7,7 @@ import { fileWatcher } from '../files/file-watcher';
|
|
|
7
7
|
import { registerProjectCleanup } from './project-cleanup-registry';
|
|
8
8
|
import { removeProjectWorktrees } from '../worktrees';
|
|
9
9
|
import { removeProjectNotes } from '../notes/storage';
|
|
10
|
+
import { wipeWorkspaceProfile } from '../storage/preview-profiles';
|
|
10
11
|
|
|
11
12
|
registerProjectCleanup({
|
|
12
13
|
name: 'engine',
|
|
@@ -25,6 +26,15 @@ registerProjectCleanup({
|
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
28
|
|
|
29
|
+
// The main tree's Preview Browser profile. Each worktree's profile goes with
|
|
30
|
+
// the worktree (see `releaseWorkspaceScope`).
|
|
31
|
+
registerProjectCleanup({
|
|
32
|
+
name: 'preview-profile',
|
|
33
|
+
run: async (projectId) => {
|
|
34
|
+
await wipeWorkspaceProfile(projectId);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
28
38
|
registerProjectCleanup({
|
|
29
39
|
name: 'worktrees',
|
|
30
40
|
run: (projectId) => removeProjectWorktrees(projectId)
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleanup actions. Each one re-reads what it is about to delete at the moment it
|
|
3
|
+
* runs — a report is only an estimate, and the files may have changed since —
|
|
4
|
+
* and every action applies the same protections as the scan that priced it:
|
|
5
|
+
* nothing a running stream uses, nothing touched within the grace period,
|
|
6
|
+
* nothing a chat or workspace still refers to.
|
|
7
|
+
*
|
|
8
|
+
* One cleanup runs at a time.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
CleanupActionId, CleanupActionMeta, CleanupEstimate, CleanupRequest, CleanupResult
|
|
13
|
+
} from '$shared/types/storage';
|
|
14
|
+
import { debug } from '$shared/utils/logger';
|
|
15
|
+
import { selectOldChats, slimSession, estimateSlimBytes } from './chats';
|
|
16
|
+
import { compactDatabase, databaseStats, releaseFreePagesIfCheap } from './database';
|
|
17
|
+
import { legacyEnginePaths, removePaths, staleLogFiles, toolCachePaths } from './engine-homes';
|
|
18
|
+
import { ws } from '$backend/utils/ws';
|
|
19
|
+
import { recordCleanupRun } from './history';
|
|
20
|
+
import { clearProfileCaches, listProfileDirs, orphanProfiles, removeProfileDirs, wipeProjectProfiles } from './preview-profiles';
|
|
21
|
+
import { activeChatIds, purgeSessions } from './purge';
|
|
22
|
+
import { currentTranscriptUsage, getLastStorageReport, scanStorage } from './scanner';
|
|
23
|
+
import { refreshSessionIndex } from './session-index';
|
|
24
|
+
import { blobSizes, deleteBlobs, orphanBlobs } from './snapshots';
|
|
25
|
+
import { applyDedupe, listAllTranscripts, removeOrphans, selectOrphans, selectRedundant } from './transcripts';
|
|
26
|
+
import { listWorktreeDirs, orphanWorktreeDirs, removeWorktreeDirs, removeWorktrees, staleWorktrees } from './worktrees';
|
|
27
|
+
import { getDatabase } from '$backend/database';
|
|
28
|
+
import { measurePath } from './fs-size';
|
|
29
|
+
import { profileDirName, profilesRoot } from '$backend/preview/browser/browser-pool';
|
|
30
|
+
import { makeScopeKey } from '$shared/utils/workspace-scope';
|
|
31
|
+
import { worktreeQueries } from '$backend/database/queries';
|
|
32
|
+
import { join } from 'node:path';
|
|
33
|
+
|
|
34
|
+
export const CLEANUP_ACTIONS: CleanupActionMeta[] = [
|
|
35
|
+
{ id: 'orphan-transcripts', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
36
|
+
{ id: 'dedupe-transcripts', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
37
|
+
{ id: 'orphan-snapshots', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
38
|
+
{ id: 'orphan-profiles', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
39
|
+
{ id: 'orphan-worktree-dirs', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
40
|
+
{ id: 'legacy-engine-data', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
41
|
+
{ id: 'engine-logs', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
42
|
+
{ id: 'browser-cache', tier: 'safe', usesAge: false, projectScoped: false, automatable: true },
|
|
43
|
+
{ id: 'tool-caches', tier: 'caution', usesAge: false, projectScoped: false, automatable: true },
|
|
44
|
+
{ id: 'compact-database', tier: 'caution', usesAge: false, projectScoped: false, automatable: true },
|
|
45
|
+
{ id: 'stale-worktrees', tier: 'caution', usesAge: true, projectScoped: true, automatable: true },
|
|
46
|
+
{ id: 'project-profiles', tier: 'caution', usesAge: false, projectScoped: true, automatable: false },
|
|
47
|
+
{ id: 'slim-old-chats', tier: 'destructive', usesAge: true, projectScoped: true, automatable: true },
|
|
48
|
+
{ id: 'delete-old-chats', tier: 'destructive', usesAge: true, projectScoped: true, automatable: true }
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
export function cleanupMeta(action: CleanupActionId): CleanupActionMeta {
|
|
52
|
+
const meta = CLEANUP_ACTIONS.find(item => item.id === action);
|
|
53
|
+
if (!meta) throw new Error(`Unknown cleanup action: ${action}`);
|
|
54
|
+
return meta;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const DEFAULT_AGE_DAYS = 90;
|
|
58
|
+
const isStreaming = () => activeChatIds().size > 0;
|
|
59
|
+
|
|
60
|
+
function activeWorktreeIds(): Set<string> {
|
|
61
|
+
const active = activeChatIds();
|
|
62
|
+
const ids = new Set<string>();
|
|
63
|
+
if (active.size === 0) return ids;
|
|
64
|
+
const rows = getDatabase().prepare('SELECT id, worktree_id FROM chat_sessions WHERE worktree_id IS NOT NULL')
|
|
65
|
+
.all() as { id: string; worktree_id: string }[];
|
|
66
|
+
for (const row of rows) if (active.has(row.id)) ids.add(row.worktree_id);
|
|
67
|
+
return ids;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Price an action. Parameterless actions answer from the last report when there is one. */
|
|
71
|
+
export async function estimateCleanup(request: CleanupRequest): Promise<CleanupEstimate> {
|
|
72
|
+
const { action } = request;
|
|
73
|
+
const days = request.olderThanDays ?? DEFAULT_AGE_DAYS;
|
|
74
|
+
const meta = cleanupMeta(action);
|
|
75
|
+
|
|
76
|
+
if (!meta.usesAge && !meta.projectScoped) {
|
|
77
|
+
const cached = getLastStorageReport()?.estimates.find(estimate => estimate.action === action);
|
|
78
|
+
if (cached) return cached;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
switch (action) {
|
|
82
|
+
case 'slim-old-chats':
|
|
83
|
+
case 'delete-old-chats': {
|
|
84
|
+
await refreshSessionIndex();
|
|
85
|
+
const chats = selectOldChats({
|
|
86
|
+
olderThanDays: days,
|
|
87
|
+
projectId: request.projectId,
|
|
88
|
+
excludeSlimmed: action === 'slim-old-chats',
|
|
89
|
+
active: activeChatIds()
|
|
90
|
+
});
|
|
91
|
+
const bytes = chats.reduce((total, chat) => total + chat.bytes, 0);
|
|
92
|
+
return { action, bytes: action === 'slim-old-chats' ? estimateSlimBytes(bytes) : bytes, items: chats.length };
|
|
93
|
+
}
|
|
94
|
+
case 'stale-worktrees': {
|
|
95
|
+
const stale = await staleWorktrees(await listWorktreeDirs(), {
|
|
96
|
+
olderThanDays: days, projectId: request.projectId, activeChatWorktrees: activeWorktreeIds()
|
|
97
|
+
});
|
|
98
|
+
return { action, bytes: stale.reduce((total, dir) => total + dir.bytes, 0), items: stale.length };
|
|
99
|
+
}
|
|
100
|
+
case 'project-profiles': {
|
|
101
|
+
if (!request.projectId) return { action, bytes: 0, items: 0 };
|
|
102
|
+
const keys = [makeScopeKey(request.projectId), ...worktreeQueries.getByProjectId(request.projectId).map(w => makeScopeKey(request.projectId!, w.id))];
|
|
103
|
+
let bytes = 0;
|
|
104
|
+
let items = 0;
|
|
105
|
+
for (const key of keys) {
|
|
106
|
+
const size = (await measurePath(join(profilesRoot(), profileDirName(key)))).bytes;
|
|
107
|
+
if (size > 0) items++;
|
|
108
|
+
bytes += size;
|
|
109
|
+
}
|
|
110
|
+
return { action, bytes, items };
|
|
111
|
+
}
|
|
112
|
+
default: {
|
|
113
|
+
const report = await scanStorage();
|
|
114
|
+
return report.estimates.find(estimate => estimate.action === action) ?? { action, bytes: 0, items: 0 };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let running: CleanupActionId | null = null;
|
|
120
|
+
|
|
121
|
+
export function runningCleanup(): CleanupActionId | null {
|
|
122
|
+
return running;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Run one action now. Records the outcome in the cleanup history. */
|
|
126
|
+
export async function runCleanup(request: CleanupRequest, trigger: 'manual' | 'auto'): Promise<CleanupResult> {
|
|
127
|
+
if (running) throw new Error('Another cleanup is running. Try again when it finishes.');
|
|
128
|
+
running = request.action;
|
|
129
|
+
const startedAt = new Date().toISOString();
|
|
130
|
+
let result: CleanupResult = { action: request.action, freedBytes: 0, items: 0, errors: [] };
|
|
131
|
+
try {
|
|
132
|
+
result = await perform(request);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
result.errors.push(error instanceof Error ? error.message : String(error));
|
|
135
|
+
} finally {
|
|
136
|
+
running = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
recordCleanupRun({
|
|
140
|
+
action: request.action,
|
|
141
|
+
trigger,
|
|
142
|
+
startedAt,
|
|
143
|
+
finishedAt: new Date().toISOString(),
|
|
144
|
+
freedBytes: result.freedBytes,
|
|
145
|
+
items: result.items,
|
|
146
|
+
error: result.errors.length > 0 ? result.errors.slice(0, 3).join('; ') : (result.skippedReason ?? null)
|
|
147
|
+
});
|
|
148
|
+
debug.log('storage', `Cleanup ${request.action} (${trigger}): ${result.items} item(s), ${result.freedBytes} bytes`);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function perform(request: CleanupRequest): Promise<CleanupResult> {
|
|
153
|
+
const { action } = request;
|
|
154
|
+
const days = request.olderThanDays ?? DEFAULT_AGE_DAYS;
|
|
155
|
+
const done = (freedBytes: number, items: number, errors: string[] = []): CleanupResult => ({ action, freedBytes, items, errors });
|
|
156
|
+
const skipped = (reason: string): CleanupResult => ({ action, freedBytes: 0, items: 0, errors: [], skippedReason: reason });
|
|
157
|
+
|
|
158
|
+
switch (action) {
|
|
159
|
+
case 'orphan-transcripts': {
|
|
160
|
+
const usage = await currentTranscriptUsage({ strict: true });
|
|
161
|
+
const orphans = selectOrphans(await listAllTranscripts(), usage);
|
|
162
|
+
const result = await removeOrphans(orphans, usage);
|
|
163
|
+
return done(result.freedBytes, result.removed, result.errors);
|
|
164
|
+
}
|
|
165
|
+
case 'dedupe-transcripts': {
|
|
166
|
+
const usage = await currentTranscriptUsage({ strict: true });
|
|
167
|
+
const redundant = await selectRedundant(await listAllTranscripts(), usage);
|
|
168
|
+
const result = await applyDedupe(redundant);
|
|
169
|
+
return done(result.freedBytes, result.removed, result.errors);
|
|
170
|
+
}
|
|
171
|
+
case 'orphan-snapshots': {
|
|
172
|
+
if (isStreaming()) return skipped('A chat is running; checkpoints are left alone until it finishes.');
|
|
173
|
+
const { hashes, bytes } = orphanBlobs(await blobSizes());
|
|
174
|
+
// Re-checked between batches: a turn that starts mid-sweep writes and
|
|
175
|
+
// reuses blobs, and a blob it reuses must not be deleted under it.
|
|
176
|
+
let deleted = 0;
|
|
177
|
+
for (let i = 0; i < hashes.length; i += 500) {
|
|
178
|
+
if (isStreaming()) break;
|
|
179
|
+
deleted += await deleteBlobs(hashes.slice(i, i + 500));
|
|
180
|
+
}
|
|
181
|
+
return done(deleted === hashes.length ? bytes : Math.round(bytes * (deleted / Math.max(1, hashes.length))), deleted);
|
|
182
|
+
}
|
|
183
|
+
case 'orphan-profiles': {
|
|
184
|
+
const result = await removeProfileDirs(orphanProfiles(await listProfileDirs()));
|
|
185
|
+
return done(result.freedBytes, result.removed);
|
|
186
|
+
}
|
|
187
|
+
case 'orphan-worktree-dirs': {
|
|
188
|
+
const result = await removeWorktreeDirs(orphanWorktreeDirs(await listWorktreeDirs()));
|
|
189
|
+
return done(result.freedBytes, result.removed);
|
|
190
|
+
}
|
|
191
|
+
case 'legacy-engine-data': {
|
|
192
|
+
const result = await removePaths(await legacyEnginePaths());
|
|
193
|
+
return done(result.freedBytes, result.removed, result.errors);
|
|
194
|
+
}
|
|
195
|
+
case 'engine-logs': {
|
|
196
|
+
const result = await removePaths((await staleLogFiles()).map(file => file.path));
|
|
197
|
+
return done(result.freedBytes, result.removed, result.errors);
|
|
198
|
+
}
|
|
199
|
+
case 'browser-cache': {
|
|
200
|
+
const result = await clearProfileCaches((await listProfileDirs()).filter(dir => dir.scope));
|
|
201
|
+
return {
|
|
202
|
+
...done(result.freedBytes, result.cleared),
|
|
203
|
+
...(result.skipped > 0 && { skippedReason: `${result.skipped} profile(s) in use were left alone.` })
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
case 'tool-caches': {
|
|
207
|
+
if (isStreaming()) return skipped('A chat is running and may be using these caches.');
|
|
208
|
+
const paths = await toolCachePaths();
|
|
209
|
+
const result = await removePaths(paths);
|
|
210
|
+
return done(result.freedBytes, result.removed, result.errors);
|
|
211
|
+
}
|
|
212
|
+
case 'compact-database': {
|
|
213
|
+
if (databaseStats().freeBytes === 0) return done(0, 0);
|
|
214
|
+
const result = await compactDatabase(isStreaming);
|
|
215
|
+
return done(result.freedBytes, 1);
|
|
216
|
+
}
|
|
217
|
+
case 'stale-worktrees': {
|
|
218
|
+
const stale = await staleWorktrees(await listWorktreeDirs(), {
|
|
219
|
+
olderThanDays: days, projectId: request.projectId, activeChatWorktrees: activeWorktreeIds()
|
|
220
|
+
});
|
|
221
|
+
const result = await removeWorktrees(stale);
|
|
222
|
+
return done(result.freedBytes, result.removed);
|
|
223
|
+
}
|
|
224
|
+
case 'project-profiles': {
|
|
225
|
+
if (!request.projectId) return skipped('No project given.');
|
|
226
|
+
return done(await wipeProjectProfiles(request.projectId), 1);
|
|
227
|
+
}
|
|
228
|
+
case 'slim-old-chats': {
|
|
229
|
+
await refreshSessionIndex();
|
|
230
|
+
const chats = selectOldChats({ olderThanDays: days, projectId: request.projectId, excludeSlimmed: true, active: activeChatIds() });
|
|
231
|
+
let freed = 0;
|
|
232
|
+
let items = 0;
|
|
233
|
+
const errors: string[] = [];
|
|
234
|
+
for (const chat of chats) {
|
|
235
|
+
if (activeChatIds().has(chat.id)) continue;
|
|
236
|
+
try {
|
|
237
|
+
freed += (await slimSession(chat.id)).freedBytes;
|
|
238
|
+
items++;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
errors.push(`${chat.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
freed = Math.max(freed, await releaseFreePagesIfCheap(isStreaming));
|
|
244
|
+
return done(freed, items, errors);
|
|
245
|
+
}
|
|
246
|
+
case 'delete-old-chats': {
|
|
247
|
+
await refreshSessionIndex();
|
|
248
|
+
const chats = selectOldChats({ olderThanDays: days, projectId: request.projectId, active: activeChatIds() });
|
|
249
|
+
const bytes = chats.reduce((total, chat) => total + chat.bytes, 0);
|
|
250
|
+
const { deletedIds } = await purgeSessions(chats.map(chat => chat.id));
|
|
251
|
+
const projectOf = new Map(chats.map(chat => [chat.id, chat.projectId]));
|
|
252
|
+
for (const sessionId of deletedIds) {
|
|
253
|
+
const projectId = projectOf.get(sessionId);
|
|
254
|
+
if (projectId) ws.emit.project(projectId, 'sessions:session-deleted', { sessionId, projectId });
|
|
255
|
+
}
|
|
256
|
+
await releaseFreePagesIfCheap(isStreaming);
|
|
257
|
+
return done(bytes, deletedIds.length);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slimming keeps every message and its words, and cuts only what is heavy.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from 'bun:test';
|
|
6
|
+
import type { UnifiedMessage } from '$shared/types/unified';
|
|
7
|
+
import { SLIM_KEEP_CHARS, slimMessage } from './chats';
|
|
8
|
+
|
|
9
|
+
const base = {
|
|
10
|
+
createdAt: '',
|
|
11
|
+
messageId: 'm',
|
|
12
|
+
sessionId: 's',
|
|
13
|
+
parent: { messageId: null, sessionId: null, toolUseId: null },
|
|
14
|
+
engine: { type: 'claude-code', provider: '', model: { id: '', name: '' }, account: { id: 0, name: '' } }
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const long = 'x'.repeat(20_000);
|
|
18
|
+
|
|
19
|
+
describe('slimMessage', () => {
|
|
20
|
+
it('leaves a message with nothing heavy untouched', () => {
|
|
21
|
+
const message = { ...base, type: 'user', synthetic: false, content: [{ type: 'text', text: long }] } as unknown as UnifiedMessage;
|
|
22
|
+
expect(slimMessage(message)).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('cuts long tool results to their head and says how much went', () => {
|
|
26
|
+
const message = {
|
|
27
|
+
...base, type: 'user', synthetic: false,
|
|
28
|
+
content: [{ type: 'tool_result', toolUseId: 't', content: long, isError: false }, { type: 'text', text: 'keep me' }]
|
|
29
|
+
} as unknown as UnifiedMessage;
|
|
30
|
+
const slim = slimMessage(message) as Extract<UnifiedMessage, { type: 'user' }>;
|
|
31
|
+
const result = slim.content[0] as { content: string };
|
|
32
|
+
expect(result.content.startsWith('x'.repeat(SLIM_KEEP_CHARS))).toBe(true);
|
|
33
|
+
expect(result.content).toContain('removed by Storage cleanup');
|
|
34
|
+
expect(result.content.length).toBeLessThan(SLIM_KEEP_CHARS + 100);
|
|
35
|
+
expect(slim.content[1]).toEqual({ type: 'text', text: 'keep me' });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('turns attachments into a note naming them', () => {
|
|
39
|
+
const message = {
|
|
40
|
+
...base, type: 'user', synthetic: false,
|
|
41
|
+
content: [{ type: 'image', mediaType: 'image/png', data: long, title: 'shot.png' }]
|
|
42
|
+
} as unknown as UnifiedMessage;
|
|
43
|
+
const slim = slimMessage(message) as Extract<UnifiedMessage, { type: 'user' }>;
|
|
44
|
+
expect(slim.content[0]).toEqual({ type: 'text', text: '[Image "shot.png" removed by Storage cleanup]' });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('cuts long strings inside a tool input and keeps its shape', () => {
|
|
48
|
+
const message = {
|
|
49
|
+
...base, type: 'assistant', stopReason: null, usage: null,
|
|
50
|
+
content: [{ type: 'tool_use', id: 't', name: 'Write', input: { file_path: '/a.ts', content: long } }]
|
|
51
|
+
} as unknown as UnifiedMessage;
|
|
52
|
+
const slim = slimMessage(message) as Extract<UnifiedMessage, { type: 'assistant' }>;
|
|
53
|
+
const input = (slim.content[0] as unknown as { input: { file_path: string; content: string } }).input;
|
|
54
|
+
expect(input.file_path).toBe('/a.ts');
|
|
55
|
+
expect(input.content.length).toBeLessThan(SLIM_KEEP_CHARS + 100);
|
|
56
|
+
});
|
|
57
|
+
});
|