@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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Old chats: slim them, or delete them.
|
|
3
|
+
*
|
|
4
|
+
* Most of a chat's weight is not the conversation. Measured on a real instance,
|
|
5
|
+
* 2.5 GB of a 3.4 GB message table was tool output carried on user-type rows
|
|
6
|
+
* (file reads, command output, screenshots), against well under a gigabyte of
|
|
7
|
+
* everything people and models actually wrote. Slimming keeps every message and
|
|
8
|
+
* every word of the conversation and removes the rest:
|
|
9
|
+
*
|
|
10
|
+
* - tool results and tool inputs longer than SLIM_KEEP_CHARS are cut to their
|
|
11
|
+
* head, with a note saying how much went
|
|
12
|
+
* - image and document attachments become a one-line note
|
|
13
|
+
* - file checkpoints go (the chat can no longer restore files)
|
|
14
|
+
* - the engine's transcripts go (the chat can no longer be resumed natively;
|
|
15
|
+
* continuing it replays the conversation to the engine, as switching engine
|
|
16
|
+
* does)
|
|
17
|
+
*
|
|
18
|
+
* A slimmed chat is marked `slimmed_at`, which also tells the transcript cleanup
|
|
19
|
+
* that its old engine sessions are no longer protected. Writing a new message
|
|
20
|
+
* clears the mark (see sessionQueries.updateOnMessage), so a chat that is picked
|
|
21
|
+
* up again protects its new transcripts as usual.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { getDatabase } from '$backend/database';
|
|
25
|
+
import { snapshotQueries } from '$backend/database/queries';
|
|
26
|
+
import type { UnifiedMessage } from '$shared/types/unified';
|
|
27
|
+
import { debug } from '$shared/utils/logger';
|
|
28
|
+
import { yieldToEventLoop } from './fs-size';
|
|
29
|
+
import { collectOrphanBlobs, releaseTranscripts } from './purge';
|
|
30
|
+
import { measureSession, reindexSession, type EngineRef } from './session-index';
|
|
31
|
+
|
|
32
|
+
/** Characters of a long tool result or input kept when slimming. */
|
|
33
|
+
export const SLIM_KEEP_CHARS = 2_000;
|
|
34
|
+
/** Strings at or below this length are left alone. */
|
|
35
|
+
const SLIM_THRESHOLD_CHARS = 4_096;
|
|
36
|
+
|
|
37
|
+
const DAY_MS = 24 * 60 * 60_000;
|
|
38
|
+
|
|
39
|
+
function trimmed(text: string): string {
|
|
40
|
+
if (text.length <= SLIM_THRESHOLD_CHARS) return text;
|
|
41
|
+
const removedKb = Math.max(1, Math.round((text.length - SLIM_KEEP_CHARS) / 1024));
|
|
42
|
+
return `${text.slice(0, SLIM_KEEP_CHARS)}\n\n[… ${removedKb} KB removed by Storage cleanup]`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Cut every long string inside a tool input, keeping its shape. */
|
|
46
|
+
function trimDeep(value: unknown): unknown {
|
|
47
|
+
if (typeof value === 'string') return trimmed(value);
|
|
48
|
+
if (Array.isArray(value)) return value.map(trimDeep);
|
|
49
|
+
if (value && typeof value === 'object') {
|
|
50
|
+
return Object.fromEntries(Object.entries(value as Record<string, unknown>).map(([key, inner]) => [key, trimDeep(inner)]));
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The slimmed form of a message, or null when nothing in it is heavy. */
|
|
56
|
+
export function slimMessage(message: UnifiedMessage): UnifiedMessage | null {
|
|
57
|
+
if (message.type === 'user') {
|
|
58
|
+
let changed = false;
|
|
59
|
+
const content = message.content.map(block => {
|
|
60
|
+
if (block.type === 'tool_result' && block.content.length > SLIM_THRESHOLD_CHARS) {
|
|
61
|
+
changed = true;
|
|
62
|
+
return { ...block, content: trimmed(block.content) };
|
|
63
|
+
}
|
|
64
|
+
if (block.type === 'image' || block.type === 'document') {
|
|
65
|
+
changed = true;
|
|
66
|
+
const label = block.type === 'image' ? 'Image' : 'Document';
|
|
67
|
+
const number = block.index ? ` @${block.index}` : '';
|
|
68
|
+
return { type: 'text' as const, text: `[${label}${number}${block.title ? ` "${block.title}"` : ''} removed by Storage cleanup]` };
|
|
69
|
+
}
|
|
70
|
+
return block;
|
|
71
|
+
});
|
|
72
|
+
return changed ? { ...message, content } : null;
|
|
73
|
+
}
|
|
74
|
+
if (message.type === 'assistant') {
|
|
75
|
+
let changed = false;
|
|
76
|
+
const content = message.content.map(block => {
|
|
77
|
+
if (block.type !== 'tool_use') return block;
|
|
78
|
+
const before = JSON.stringify(block.input ?? null);
|
|
79
|
+
if (before.length <= SLIM_THRESHOLD_CHARS) return block;
|
|
80
|
+
changed = true;
|
|
81
|
+
return { ...block, input: trimDeep(block.input) } as typeof block;
|
|
82
|
+
});
|
|
83
|
+
return changed ? { ...message, content } : null;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SlimResult {
|
|
89
|
+
freedBytes: number;
|
|
90
|
+
messages: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Slim one chat. Its rows are rewritten one at a time, yielding between batches. */
|
|
94
|
+
export async function slimSession(sessionId: string): Promise<SlimResult> {
|
|
95
|
+
const db = getDatabase();
|
|
96
|
+
const before = measureSession(sessionId);
|
|
97
|
+
const rows = db.prepare('SELECT id, data FROM messages WHERE session_id = ?').all(sessionId) as { id: string; data: string }[];
|
|
98
|
+
const update = db.prepare('UPDATE messages SET data = ? WHERE id = ?');
|
|
99
|
+
|
|
100
|
+
let messages = 0;
|
|
101
|
+
for (let i = 0; i < rows.length; i++) {
|
|
102
|
+
let parsed: UnifiedMessage;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(rows[i].data) as UnifiedMessage;
|
|
105
|
+
} catch {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const slim = slimMessage(parsed);
|
|
109
|
+
if (slim) {
|
|
110
|
+
update.run(JSON.stringify(slim), rows[i].id);
|
|
111
|
+
messages++;
|
|
112
|
+
}
|
|
113
|
+
if (i % 200 === 199) await yieldToEventLoop();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const snapshots = snapshotQueries.deleteBySessionId(sessionId);
|
|
117
|
+
await collectOrphanBlobs(snapshotQueries.collectBlobHashes(snapshots));
|
|
118
|
+
|
|
119
|
+
db.prepare('UPDATE chat_sessions SET slimmed_at = ? WHERE id = ?').run(new Date().toISOString(), sessionId);
|
|
120
|
+
reindexSession(sessionId);
|
|
121
|
+
const after = measureSession(sessionId);
|
|
122
|
+
if (before.refs.length > 0) await releaseTranscripts(before.refs as EngineRef[]);
|
|
123
|
+
|
|
124
|
+
return { freedBytes: Math.max(0, before.bytes - after.bytes), messages };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Chats a "delete/slim old chats" action may touch: no activity for
|
|
129
|
+
* `olderThanDays`, not streaming, and none of the chats something else points
|
|
130
|
+
* at — a project's open chat, a chat app's current conversation, a chat linked
|
|
131
|
+
* to an issue or pull request.
|
|
132
|
+
*/
|
|
133
|
+
export function selectOldChats(options: {
|
|
134
|
+
olderThanDays: number;
|
|
135
|
+
projectId?: string | null;
|
|
136
|
+
excludeSlimmed?: boolean;
|
|
137
|
+
active: Set<string>;
|
|
138
|
+
}): { id: string; projectId: string; bytes: number }[] {
|
|
139
|
+
const cutoff = new Date(Date.now() - options.olderThanDays * DAY_MS).toISOString();
|
|
140
|
+
const db = getDatabase();
|
|
141
|
+
const rows = db.prepare(`
|
|
142
|
+
SELECT cs.id, cs.project_id, COALESCE(i.bytes, 0) AS bytes
|
|
143
|
+
FROM chat_sessions cs
|
|
144
|
+
LEFT JOIN storage_session_index i ON i.session_id = cs.id
|
|
145
|
+
WHERE COALESCE(cs.last_message_at, cs.started_at) < ?
|
|
146
|
+
AND (? IS NULL OR cs.project_id = ?)
|
|
147
|
+
AND (? = 0 OR cs.slimmed_at IS NULL)
|
|
148
|
+
AND cs.id NOT IN (SELECT current_session_id FROM workspace_projects WHERE current_session_id IS NOT NULL)
|
|
149
|
+
AND cs.id NOT IN (SELECT active_session_id FROM channel_links WHERE active_session_id IS NOT NULL)
|
|
150
|
+
AND cs.id NOT IN (SELECT session_id FROM work_links WHERE session_id IS NOT NULL)
|
|
151
|
+
`).all(
|
|
152
|
+
cutoff,
|
|
153
|
+
options.projectId ?? null, options.projectId ?? null,
|
|
154
|
+
options.excludeSlimmed ? 1 : 0
|
|
155
|
+
) as { id: string; project_id: string; bytes: number }[];
|
|
156
|
+
return rows
|
|
157
|
+
.filter(row => !options.active.has(row.id))
|
|
158
|
+
.map(row => ({ id: row.id, projectId: row.project_id, bytes: row.bytes }));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** What slimming a chat would free, estimated from its size without rewriting it. */
|
|
162
|
+
export function estimateSlimBytes(bytes: number): number {
|
|
163
|
+
// Measured ratio of heavy payload to message bytes (2.5 of 3.4 GB). An
|
|
164
|
+
// estimate only; the result reports what was actually freed.
|
|
165
|
+
return Math.round(bytes * 0.7);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function logSlimmed(sessionId: string, result: SlimResult): void {
|
|
169
|
+
debug.log('storage', `Slimmed chat ${sessionId}: ${result.messages} message(s), ${result.freedBytes} bytes`);
|
|
170
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returning the database's free pages to the disk.
|
|
3
|
+
*
|
|
4
|
+
* SQLite never shrinks its file on its own: deleting or slimming chats leaves
|
|
5
|
+
* the freed pages inside `app.db` for reuse. Two ways to give them back:
|
|
6
|
+
*
|
|
7
|
+
* - VACUUM rebuilds the whole file. It holds the database for as long as that
|
|
8
|
+
* takes (about a minute per few gigabytes) and needs free disk space about the
|
|
9
|
+
* size of the database while it runs. Clopen answers nothing that touches the
|
|
10
|
+
* database in the meantime.
|
|
11
|
+
* - With `auto_vacuum = INCREMENTAL`, `PRAGMA incremental_vacuum(N)` releases N
|
|
12
|
+
* free pages at a time — milliseconds per batch, so it can run between other
|
|
13
|
+
* work. The mode can only be switched on by a VACUUM.
|
|
14
|
+
*
|
|
15
|
+
* So the first compaction is a VACUUM that also switches the mode on, and every
|
|
16
|
+
* later one is incremental. Both refuse to start while a chat is streaming.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { statSync } from 'node:fs';
|
|
20
|
+
import { statfs } from 'node:fs/promises';
|
|
21
|
+
import { dirname } from 'node:path';
|
|
22
|
+
import { getDatabase } from '$backend/database';
|
|
23
|
+
import { DatabaseManager } from '$backend/database/utils/connection';
|
|
24
|
+
import { debug } from '$shared/utils/logger';
|
|
25
|
+
import { yieldToEventLoop } from './fs-size';
|
|
26
|
+
|
|
27
|
+
const INCREMENTAL = 2;
|
|
28
|
+
const PAGES_PER_STEP = 2_000;
|
|
29
|
+
|
|
30
|
+
function pragma(name: string): number {
|
|
31
|
+
const row = getDatabase().prepare(`PRAGMA ${name}`).get() as Record<string, number> | null;
|
|
32
|
+
return row ? Number(Object.values(row)[0]) : 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function databasePath(): string {
|
|
36
|
+
return DatabaseManager.getInstance().getPath();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function databaseStats(): { fileBytes: number; freeBytes: number; incrementalVacuum: boolean } {
|
|
40
|
+
const path = databasePath();
|
|
41
|
+
let fileBytes = 0;
|
|
42
|
+
for (const suffix of ['', '-wal', '-shm']) {
|
|
43
|
+
try {
|
|
44
|
+
fileBytes += statSync(path + suffix).size;
|
|
45
|
+
} catch { /* absent */ }
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
fileBytes,
|
|
49
|
+
freeBytes: pragma('freelist_count') * pragma('page_size'),
|
|
50
|
+
incrementalVacuum: pragma('auto_vacuum') === INCREMENTAL
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function freeDiskBytes(path: string): Promise<number | null> {
|
|
55
|
+
try {
|
|
56
|
+
const stats = await statfs(dirname(path));
|
|
57
|
+
return Number(stats.bavail) * Number(stats.bsize);
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface CompactResult {
|
|
64
|
+
freedBytes: number;
|
|
65
|
+
mode: 'vacuum' | 'incremental';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Give free pages back. Throws with a readable reason when it cannot run. */
|
|
69
|
+
export async function compactDatabase(isBusy: () => boolean): Promise<CompactResult> {
|
|
70
|
+
if (isBusy()) throw new Error('A chat is running. Compacting waits until nothing is streaming.');
|
|
71
|
+
const db = getDatabase();
|
|
72
|
+
const before = databaseStats();
|
|
73
|
+
|
|
74
|
+
if (!before.incrementalVacuum) {
|
|
75
|
+
const free = await freeDiskBytes(databasePath());
|
|
76
|
+
if (free !== null && free < before.fileBytes * 1.1) {
|
|
77
|
+
throw new Error('Not enough free disk space to rebuild the database (it needs about its own size).');
|
|
78
|
+
}
|
|
79
|
+
debug.log('storage', 'Rebuilding the database and switching on incremental vacuum');
|
|
80
|
+
db.exec(`PRAGMA auto_vacuum = INCREMENTAL`);
|
|
81
|
+
db.exec('VACUUM');
|
|
82
|
+
db.exec('PRAGMA wal_checkpoint(TRUNCATE)');
|
|
83
|
+
const after = databaseStats();
|
|
84
|
+
return { freedBytes: Math.max(0, before.fileBytes - after.fileBytes), mode: 'vacuum' };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
while (pragma('freelist_count') > 0) {
|
|
88
|
+
if (isBusy()) break;
|
|
89
|
+
db.exec(`PRAGMA incremental_vacuum(${PAGES_PER_STEP})`);
|
|
90
|
+
await yieldToEventLoop();
|
|
91
|
+
}
|
|
92
|
+
db.exec('PRAGMA wal_checkpoint(TRUNCATE)');
|
|
93
|
+
const after = databaseStats();
|
|
94
|
+
return { freedBytes: Math.max(0, before.fileBytes - after.fileBytes), mode: 'incremental' };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Release free pages when that is cheap (incremental mode). A no-op otherwise. */
|
|
98
|
+
export async function releaseFreePagesIfCheap(isBusy: () => boolean): Promise<number> {
|
|
99
|
+
if (!databaseStats().incrementalVacuum) return 0;
|
|
100
|
+
try {
|
|
101
|
+
return (await compactDatabase(isBusy)).freedBytes;
|
|
102
|
+
} catch {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What else lives in an engine's isolated home besides its transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Each engine runs with its home redirected under `{clopenDir}/engine/<name>/user`
|
|
5
|
+
* (§10.19), and the agents it runs inherit that: Open Code points every XDG dir
|
|
6
|
+
* at its scope folder, so a model download, a `uv` environment or a package
|
|
7
|
+
* cache a tool creates mid-task lands there. Those are caches by the tool's own
|
|
8
|
+
* definition and come back on demand. They are named explicitly here — never
|
|
9
|
+
* "everything that is not a transcript" — because the same folders also hold
|
|
10
|
+
* the tools' CONFIG (`gh` keeps its sign-in in `$XDG_CONFIG_HOME/gh`).
|
|
11
|
+
*
|
|
12
|
+
* Legacy data: before the Open Code server pool, its data and cache dirs were
|
|
13
|
+
* the engine home itself. Sessions now live under `pool/<scope>/`, and nothing
|
|
14
|
+
* opens the old `opencode/opencode.db` (or its snapshots and logs) again. The
|
|
15
|
+
* config files beside them — agents, commands, plugins — are still read and are
|
|
16
|
+
* not touched.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import fs from 'node:fs/promises';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { getEngineUserConfigDir } from '$backend/utils/paths';
|
|
22
|
+
import { measurePath, removePath } from './fs-size';
|
|
23
|
+
|
|
24
|
+
/** Folder names tools create under `$XDG_CACHE_HOME` (and `$XDG_DATA_HOME` for uv). */
|
|
25
|
+
const TOOL_CACHE_DIRS = [
|
|
26
|
+
'huggingface', 'uv', 'pip', 'pypoetry', 'bun', 'swiftpm', 'prisma', 'node-gyp', 'pnpm', 'yarn',
|
|
27
|
+
'go-build', 'ms-playwright', 'puppeteer', 'typescript', 'deno', 'esbuild', 'electron', 'torch',
|
|
28
|
+
'matplotlib', 'fontconfig', 'mesa_shader_cache', 'turbo', 'next', 'sccache', 'ccache', 'cypress',
|
|
29
|
+
'selenium', 'jedi', 'black', 'ruff', 'mypy', 'pre-commit', 'vscode-ripgrep'
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/** Open Code's pre-pool data inside its config folder. */
|
|
33
|
+
const OPENCODE_LEGACY = [
|
|
34
|
+
'opencode.db', 'opencode.db-shm', 'opencode.db-wal', 'snapshot', 'log', 'tool-output', 'repos',
|
|
35
|
+
'storage', 'project', 'bin', 'locks', 'models.json'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** Log and scratch folders, per engine, relative to its home. Only files older than LOG_AGE_MS go. */
|
|
39
|
+
const LOG_DIRS: Record<string, string[]> = {
|
|
40
|
+
claude: ['debug', 'telemetry', 'shell-snapshots'],
|
|
41
|
+
codex: ['log', '.tmp', 'tmp', 'shell_snapshots'],
|
|
42
|
+
copilot: ['logs'],
|
|
43
|
+
qwen: ['debug', 'tmp'],
|
|
44
|
+
opencode: [],
|
|
45
|
+
pi: [],
|
|
46
|
+
cursor: []
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const LOG_AGE_MS = 7 * 24 * 60 * 60_000;
|
|
50
|
+
|
|
51
|
+
export const ENGINE_HOME_NAMES = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi', 'cursor'] as const;
|
|
52
|
+
|
|
53
|
+
async function existing(paths: string[]): Promise<string[]> {
|
|
54
|
+
const found: string[] = [];
|
|
55
|
+
for (const path of paths) {
|
|
56
|
+
try {
|
|
57
|
+
await fs.lstat(path);
|
|
58
|
+
found.push(path);
|
|
59
|
+
} catch { /* absent */ }
|
|
60
|
+
}
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Folders `$XDG_CACHE_HOME` has pointed at: the Open Code home and every pool scope. */
|
|
65
|
+
async function openCodeCacheHomes(): Promise<string[]> {
|
|
66
|
+
const home = getEngineUserConfigDir('opencode');
|
|
67
|
+
const homes = [home];
|
|
68
|
+
try {
|
|
69
|
+
for (const scope of await fs.readdir(join(home, 'pool'))) homes.push(join(home, 'pool', scope));
|
|
70
|
+
} catch { /* no pool yet */ }
|
|
71
|
+
return homes;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Caches an engine keeps for itself in its home, rebuilt on demand. */
|
|
75
|
+
const ENGINE_CACHE_DIRS: Record<string, string[]> = {
|
|
76
|
+
codex: ['cache']
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export async function toolCachePaths(): Promise<string[]> {
|
|
80
|
+
const candidates: string[] = [];
|
|
81
|
+
for (const home of await openCodeCacheHomes()) {
|
|
82
|
+
for (const name of TOOL_CACHE_DIRS) candidates.push(join(home, name));
|
|
83
|
+
}
|
|
84
|
+
for (const [engine, names] of Object.entries(ENGINE_CACHE_DIRS)) {
|
|
85
|
+
for (const name of names) candidates.push(join(getEngineUserConfigDir(engine), name));
|
|
86
|
+
}
|
|
87
|
+
return existing(candidates);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function legacyEnginePaths(): Promise<string[]> {
|
|
91
|
+
const dir = join(getEngineUserConfigDir('opencode'), 'opencode');
|
|
92
|
+
return existing(OPENCODE_LEGACY.map(name => join(dir, name)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Log files old enough to go, across every engine (including each Open Code scope's log dir). */
|
|
96
|
+
export async function staleLogFiles(now = Date.now()): Promise<{ path: string; bytes: number }[]> {
|
|
97
|
+
const dirs: string[] = [];
|
|
98
|
+
for (const [engine, names] of Object.entries(LOG_DIRS)) {
|
|
99
|
+
for (const name of names) dirs.push(join(getEngineUserConfigDir(engine), name));
|
|
100
|
+
}
|
|
101
|
+
for (const home of (await openCodeCacheHomes()).slice(1)) dirs.push(join(home, 'opencode', 'log'));
|
|
102
|
+
|
|
103
|
+
const files: { path: string; bytes: number }[] = [];
|
|
104
|
+
for (const dir of dirs) {
|
|
105
|
+
const stack = [dir];
|
|
106
|
+
while (stack.length > 0) {
|
|
107
|
+
const current = stack.pop()!;
|
|
108
|
+
let entries: import('node:fs').Dirent[];
|
|
109
|
+
try {
|
|
110
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
111
|
+
} catch {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const full = join(current, entry.name);
|
|
116
|
+
if (entry.isDirectory()) {
|
|
117
|
+
stack.push(full);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const stat = await fs.lstat(full).catch(() => null);
|
|
121
|
+
if (stat && now - stat.mtimeMs >= LOG_AGE_MS) files.push({ path: full, bytes: (await measurePath(full)).bytes });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return files;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function measurePaths(paths: string[]): Promise<number> {
|
|
129
|
+
let bytes = 0;
|
|
130
|
+
for (const path of paths) bytes += (await measurePath(path)).bytes;
|
|
131
|
+
return bytes;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function removePaths(paths: string[]): Promise<{ freedBytes: number; removed: number; errors: string[] }> {
|
|
135
|
+
const result = { freedBytes: 0, removed: 0, errors: [] as string[] };
|
|
136
|
+
for (const path of paths) {
|
|
137
|
+
try {
|
|
138
|
+
result.freedBytes += await removePath(path);
|
|
139
|
+
result.removed++;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
result.errors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disk usage of a path, measured the way a deletion would free it.
|
|
3
|
+
*
|
|
4
|
+
* Allocated blocks rather than apparent size where the platform reports them: a
|
|
5
|
+
* sparse Chrome cache file or a reflinked worktree occupies far less than its
|
|
6
|
+
* length, and promising the length back would overstate every cleanup. Windows
|
|
7
|
+
* reports no block count, so the size is the best figure there.
|
|
8
|
+
*
|
|
9
|
+
* Everything is asynchronous and yields between directories, so measuring
|
|
10
|
+
* forty gigabytes never holds the event loop the server answers on.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import type { Stats } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
|
|
17
|
+
export interface TreeSize {
|
|
18
|
+
bytes: number;
|
|
19
|
+
files: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function allocatedBytes(stat: Stats): number {
|
|
23
|
+
const blocks = (stat as Stats & { blocks?: number }).blocks;
|
|
24
|
+
return typeof blocks === 'number' && blocks > 0 ? blocks * 512 : stat.size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Size of a file or directory tree. Missing paths measure 0. Symlinks are not followed. */
|
|
28
|
+
export async function measurePath(target: string, signal?: AbortSignal): Promise<TreeSize> {
|
|
29
|
+
let stat: Stats;
|
|
30
|
+
try {
|
|
31
|
+
stat = await fs.lstat(target);
|
|
32
|
+
} catch {
|
|
33
|
+
return { bytes: 0, files: 0 };
|
|
34
|
+
}
|
|
35
|
+
if (!stat.isDirectory()) return { bytes: allocatedBytes(stat), files: 1 };
|
|
36
|
+
|
|
37
|
+
const total: TreeSize = { bytes: allocatedBytes(stat), files: 0 };
|
|
38
|
+
const stack: string[] = [target];
|
|
39
|
+
while (stack.length > 0) {
|
|
40
|
+
if (signal?.aborted) break;
|
|
41
|
+
const dir = stack.pop()!;
|
|
42
|
+
let entries: import('node:fs').Dirent[];
|
|
43
|
+
try {
|
|
44
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
45
|
+
} catch {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const stats = await Promise.all(entries.map(entry =>
|
|
49
|
+
fs.lstat(join(dir, entry.name)).then(s => ({ entry, s }), () => null)
|
|
50
|
+
));
|
|
51
|
+
for (const item of stats) {
|
|
52
|
+
if (!item) continue;
|
|
53
|
+
total.bytes += allocatedBytes(item.s);
|
|
54
|
+
if (item.s.isDirectory()) stack.push(join(dir, item.entry.name));
|
|
55
|
+
else total.files++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return total;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Sizes of each direct child of a directory, keyed by name. */
|
|
62
|
+
export async function measureChildren(dir: string, signal?: AbortSignal): Promise<Map<string, TreeSize>> {
|
|
63
|
+
const sizes = new Map<string, TreeSize>();
|
|
64
|
+
let names: string[];
|
|
65
|
+
try {
|
|
66
|
+
names = await fs.readdir(dir);
|
|
67
|
+
} catch {
|
|
68
|
+
return sizes;
|
|
69
|
+
}
|
|
70
|
+
for (const name of names) {
|
|
71
|
+
if (signal?.aborted) break;
|
|
72
|
+
sizes.set(name, await measurePath(join(dir, name), signal));
|
|
73
|
+
}
|
|
74
|
+
return sizes;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Remove a path and report what it occupied. Never throws for a missing path. */
|
|
78
|
+
export async function removePath(target: string): Promise<number> {
|
|
79
|
+
const { bytes } = await measurePath(target);
|
|
80
|
+
await fs.rm(target, { recursive: true, force: true });
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function pathExists(target: string): Promise<boolean> {
|
|
85
|
+
try {
|
|
86
|
+
await fs.lstat(target);
|
|
87
|
+
return true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Let other work run. Used between units of a long synchronous loop. */
|
|
94
|
+
export function yieldToEventLoop(): Promise<void> {
|
|
95
|
+
return new Promise(resolve => setImmediate(resolve));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A file's bytes, chunk by chunk, without holding the whole file in memory. */
|
|
99
|
+
export async function* readFileChunks(file: string): AsyncGenerator<Uint8Array> {
|
|
100
|
+
const reader = Bun.file(file).stream().getReader();
|
|
101
|
+
try {
|
|
102
|
+
while (true) {
|
|
103
|
+
const { done, value } = await reader.read();
|
|
104
|
+
if (done) return;
|
|
105
|
+
yield value;
|
|
106
|
+
}
|
|
107
|
+
} finally {
|
|
108
|
+
// Also reached when the caller stops early; cancel closes the file.
|
|
109
|
+
await reader.cancel().catch(() => {});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** What each cleanup removed, for the history list in Settings → Storage. */
|
|
2
|
+
|
|
3
|
+
import { getDatabase } from '$backend/database';
|
|
4
|
+
import type { CleanupActionId, StorageCleanupRun } from '$shared/types/storage';
|
|
5
|
+
|
|
6
|
+
/** Older runs are dropped; the list is a recent-activity view, not an audit log. */
|
|
7
|
+
const KEEP_RUNS = 200;
|
|
8
|
+
|
|
9
|
+
export function recordCleanupRun(run: Omit<StorageCleanupRun, 'id'>): void {
|
|
10
|
+
const db = getDatabase();
|
|
11
|
+
db.prepare(`
|
|
12
|
+
INSERT INTO storage_cleanup_runs (action, trigger, started_at, finished_at, freed_bytes, items, error)
|
|
13
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
14
|
+
`).run(run.action, run.trigger, run.startedAt, run.finishedAt, run.freedBytes, run.items, run.error);
|
|
15
|
+
db.prepare(`
|
|
16
|
+
DELETE FROM storage_cleanup_runs
|
|
17
|
+
WHERE id NOT IN (SELECT id FROM storage_cleanup_runs ORDER BY id DESC LIMIT ?)
|
|
18
|
+
`).run(KEEP_RUNS);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function listCleanupRuns(limit = 50): StorageCleanupRun[] {
|
|
22
|
+
const rows = getDatabase().prepare(`
|
|
23
|
+
SELECT id, action, trigger, started_at, finished_at, freed_bytes, items, error
|
|
24
|
+
FROM storage_cleanup_runs ORDER BY id DESC LIMIT ?
|
|
25
|
+
`).all(limit) as {
|
|
26
|
+
id: number; action: string; trigger: string; started_at: string; finished_at: string | null;
|
|
27
|
+
freed_bytes: number; items: number; error: string | null;
|
|
28
|
+
}[];
|
|
29
|
+
return rows.map(row => ({
|
|
30
|
+
id: row.id,
|
|
31
|
+
action: row.action as CleanupActionId,
|
|
32
|
+
trigger: row.trigger as StorageCleanupRun['trigger'],
|
|
33
|
+
startedAt: row.started_at,
|
|
34
|
+
finishedAt: row.finished_at,
|
|
35
|
+
freedBytes: row.freed_bytes,
|
|
36
|
+
items: row.items,
|
|
37
|
+
error: row.error
|
|
38
|
+
}));
|
|
39
|
+
}
|