@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
package/README.md
CHANGED
|
@@ -221,7 +221,8 @@ If Clopen is useful to you, consider supporting its development:
|
|
|
221
221
|
| Solana (SOL) | `Ev3P4KLF1PNC5C9rZYP8M3DdssyBQAQAiNJkvNmPQPVs` |
|
|
222
222
|
| Ethereum (ERC-20) | `0x61D826e5b666AA5345302EEEd485Acca39b1AFCF` |
|
|
223
223
|
| USDT (TRC-20) | `TLH49i3EoVKhFyLb6u2JUXZWScK7uzksdC` |
|
|
224
|
-
|
|
|
224
|
+
| USDC (BNB Smart Chain, BEP-20) | `0x61D826e5b666AA5345302EEEd485Acca39b1AFCF` |
|
|
225
|
+
| Saweria (Indonesia) | [saweria.co/myrialabs](https://saweria.co/myrialabs) |
|
|
225
226
|
|
|
226
227
|
---
|
|
227
228
|
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
|
7
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
|
|
7
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
8
8
|
import { tmpdir } from 'os';
|
|
9
9
|
import { join } from 'path';
|
|
10
10
|
import type { StreamRequest } from '$shared/types/unified';
|
|
11
11
|
import { registerModels } from '$shared/constants/engines';
|
|
12
|
-
import { base64Size, isNative, normalizeAttachments } from './attachments';
|
|
12
|
+
import { base64Size, CONTEXT_NOTE, isNative, labelAttachments, normalizeAttachments } from './attachments';
|
|
13
|
+
import { buildContextDocument, fileReferenceDocument } from '$shared/utils/context-document';
|
|
14
|
+
import type { FileBlock } from '$shared/types/unified';
|
|
13
15
|
|
|
14
16
|
const VISION = { text: true, image: true, pdf: true, audio: false, video: false };
|
|
15
17
|
const TEXT_ONLY = { text: true, image: false, pdf: false, audio: false, video: false };
|
|
@@ -54,12 +56,25 @@ describe('attachments', () => {
|
|
|
54
56
|
expect(base64Size(b64('hello'))).toBe(5);
|
|
55
57
|
});
|
|
56
58
|
|
|
57
|
-
it('leaves a prompt
|
|
58
|
-
const input = request('vision', [{ type: '
|
|
59
|
+
it('leaves a prompt without attachments alone', async () => {
|
|
60
|
+
const input = request('vision', [{ type: 'text', text: 'hello' }]);
|
|
59
61
|
expect(await normalizeAttachments(input, root)).toBe(input);
|
|
60
62
|
});
|
|
61
63
|
|
|
62
|
-
it('
|
|
64
|
+
it('keeps native files inline and numbers every attachment in order', async () => {
|
|
65
|
+
const result = await normalizeAttachments(
|
|
66
|
+
request('vision', [
|
|
67
|
+
{ type: 'image', mediaType: 'image/png', data: b64('png'), title: 'a.png' },
|
|
68
|
+
{ type: 'document', mediaType: 'text/csv', data: b64('a,b'), title: 'b.csv' },
|
|
69
|
+
{ type: 'text', text: 'what is this' }
|
|
70
|
+
]),
|
|
71
|
+
root
|
|
72
|
+
);
|
|
73
|
+
const content = result.prompt.content as Array<{ type: string; index?: number }>;
|
|
74
|
+
expect(content.map((block) => [block.type, block.index])).toEqual([['image', 1], ['file', 2], ['text', undefined]]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('saves any other file into the session folder, ignored by git, and keeps where it went', async () => {
|
|
63
78
|
const result = await normalizeAttachments(
|
|
64
79
|
request('vision', [
|
|
65
80
|
{ type: 'document', mediaType: 'text/csv', data: b64('a,b\n1,2'), title: 'data.csv' },
|
|
@@ -67,22 +82,96 @@ describe('attachments', () => {
|
|
|
67
82
|
]),
|
|
68
83
|
root
|
|
69
84
|
);
|
|
70
|
-
const content = result.prompt.content as Array<{ type: string; text?: string }>;
|
|
71
|
-
expect(content).
|
|
72
|
-
expect(content[0].
|
|
73
|
-
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
76
|
-
expect(content[
|
|
77
|
-
expect(content[0].text!.endsWith('summarise it')).toBe(true);
|
|
85
|
+
const content = result.prompt.content as Array<{ type: string; path?: string; title?: string; size?: number; text?: string }>;
|
|
86
|
+
expect(content.map((block) => block.type)).toEqual(['file', 'text']);
|
|
87
|
+
expect(content[0].path!.startsWith(join(root, '.clopen', 'attachments'))).toBe(true);
|
|
88
|
+
expect(readFileSync(content[0].path!, 'utf8')).toBe('a,b\n1,2');
|
|
89
|
+
expect(content[0].title).toBe('data.csv');
|
|
90
|
+
expect(content[0].size).toBe(7);
|
|
91
|
+
expect(content[1].text).toBe('summarise it');
|
|
78
92
|
expect(readFileSync(join(root, '.clopen', '.gitignore'), 'utf8')).toBe('*\n');
|
|
79
93
|
});
|
|
80
94
|
|
|
81
|
-
it('saves an image for a model that cannot see
|
|
95
|
+
it('saves an image for a model that cannot see', async () => {
|
|
82
96
|
const result = await normalizeAttachments(request('text', [{ type: 'image', mediaType: 'image/png', data: b64('png'), title: 'shot.png' }]), root);
|
|
83
|
-
const content = result.prompt.content as Array<{ type: string;
|
|
84
|
-
expect(content.map((block) => block.type)).toEqual(['
|
|
85
|
-
expect(content[0].
|
|
97
|
+
const content = result.prompt.content as Array<{ type: string; title?: string }>;
|
|
98
|
+
expect(content.map((block) => block.type)).toEqual(['file']);
|
|
99
|
+
expect(content[0].title).toBe('shot.png');
|
|
86
100
|
expect(existsSync(join(root, '.clopen', 'attachments'))).toBe(true);
|
|
87
101
|
});
|
|
102
|
+
|
|
103
|
+
it('labels every attachment with its number for the engine', () => {
|
|
104
|
+
const labelled = labelAttachments(
|
|
105
|
+
[
|
|
106
|
+
{ type: 'image', mediaType: 'image/png', data: b64('png'), title: 'a.png', index: 1 },
|
|
107
|
+
{ type: 'file', mediaType: 'text/csv', title: 'b.csv', size: 3, path: join(root, '.clopen', 'attachments', 'b.csv'), index: 2 },
|
|
108
|
+
{ type: 'text', text: 'compare @1 with @2' }
|
|
109
|
+
],
|
|
110
|
+
root
|
|
111
|
+
);
|
|
112
|
+
expect(labelled.map((block) => block.type)).toEqual(['text', 'image', 'text', 'text']);
|
|
113
|
+
expect((labelled[0] as { text: string }).text).toBe('[Attachment @1: "a.png" (image/png, 3 B)]');
|
|
114
|
+
expect((labelled[2] as { text: string }).text).toBe('[Attachment @2: "b.csv" (text/csv, 3 B), saved at ./.clopen/attachments/b.csv]');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('leaves messages from before numbering as they were', () => {
|
|
118
|
+
const content = [{ type: 'image' as const, mediaType: 'image/png', data: b64('png') }, { type: 'text' as const, text: 'hi' }];
|
|
119
|
+
expect(labelAttachments(content, root)).toBe(content);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('saves a mention snapshot and names what it is', async () => {
|
|
123
|
+
const snapshot = buildContextDocument({
|
|
124
|
+
kind: 'terminal',
|
|
125
|
+
label: 'dev server',
|
|
126
|
+
detail: '2 lines',
|
|
127
|
+
capturedAt: '2026-11-27T10:00:00.000Z',
|
|
128
|
+
sections: [{ title: 'Output', body: 'ready\nerror: port in use', fence: 'text' }]
|
|
129
|
+
});
|
|
130
|
+
const result = await normalizeAttachments(
|
|
131
|
+
request('vision', [
|
|
132
|
+
{ type: 'document', mediaType: 'text/markdown', data: b64(snapshot.text), title: snapshot.fileName },
|
|
133
|
+
{ type: 'text', text: 'why does @1 fail' }
|
|
134
|
+
]),
|
|
135
|
+
root
|
|
136
|
+
);
|
|
137
|
+
const [file] = result.prompt.content as FileBlock[];
|
|
138
|
+
expect(file.type).toBe('file');
|
|
139
|
+
expect(file.index).toBe(1);
|
|
140
|
+
expect(file.source).toEqual({ kind: 'terminal', label: 'dev server', detail: '2 lines', capturedAt: '2026-11-27T10:00:00.000Z' });
|
|
141
|
+
expect(readFileSync(file.path, 'utf8')).toBe(snapshot.text);
|
|
142
|
+
|
|
143
|
+
const labelled = labelAttachments(result.prompt.content as FileBlock[], root);
|
|
144
|
+
expect((labelled[0] as { text: string }).text).toBe(CONTEXT_NOTE);
|
|
145
|
+
expect((labelled[1] as { text: string }).text).toMatch(
|
|
146
|
+
/^\[Attachment @1: terminal output "dev server" \(2 lines, captured 2026-11-27T10:00:00\.000Z\), saved at \.\/\.clopen\/attachments\/.+\.md\]$/
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('points the engine at a mentioned project file rather than a copy', async () => {
|
|
151
|
+
mkdirSync(join(root, 'src'), { recursive: true });
|
|
152
|
+
writeFileSync(join(root, 'src', 'app.ts'), 'export {};\n');
|
|
153
|
+
const reference = fileReferenceDocument('src/app.ts');
|
|
154
|
+
const result = await normalizeAttachments(
|
|
155
|
+
request('vision', [{ type: 'document', mediaType: 'text/markdown', data: b64(reference.text), title: reference.fileName }]),
|
|
156
|
+
root
|
|
157
|
+
);
|
|
158
|
+
const [file] = result.prompt.content as FileBlock[];
|
|
159
|
+
expect(file.path).toBe(join(root, 'src', 'app.ts'));
|
|
160
|
+
expect(file.source?.kind).toBe('file');
|
|
161
|
+
expect(existsSync(join(root, '.clopen', 'attachments'))).toBe(false);
|
|
162
|
+
|
|
163
|
+
const labelled = labelAttachments([file], root);
|
|
164
|
+
expect(labelled).toEqual([{ type: 'text', text: '[Attachment @1: project file "src/app.ts", at ./src/app.ts]' }]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('says so when a mentioned file is gone or outside the project', async () => {
|
|
168
|
+
for (const path of ['src/missing.ts', '../outside.ts']) {
|
|
169
|
+
const reference = fileReferenceDocument(path);
|
|
170
|
+
const result = await normalizeAttachments(
|
|
171
|
+
request('vision', [{ type: 'document', mediaType: 'text/markdown', data: b64(reference.text), title: reference.fileName }]),
|
|
172
|
+
root
|
|
173
|
+
);
|
|
174
|
+
expect(result.prompt.content).toEqual([{ type: 'text', text: `[Attachment @1 "${path}" is no longer in the project.]` }]);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
88
177
|
});
|
|
@@ -9,14 +9,25 @@
|
|
|
9
9
|
* working tree and the prompt names it, which every engine can act on with its
|
|
10
10
|
* own file tools.
|
|
11
11
|
*
|
|
12
|
+
* Every attachment is numbered within its message (`@1`, `@2`, …) and the
|
|
13
|
+
* engine prompt labels each one with its number — see `labelAttachments`.
|
|
14
|
+
*
|
|
15
|
+
* An `@` mention arrives as a context document (see
|
|
16
|
+
* shared/utils/context-document.ts): it is always saved, and its header
|
|
17
|
+
* becomes the attachment's `source`, so the engine is told what the snapshot
|
|
18
|
+
* is. A mentioned project file is not copied at all — the engine is pointed at
|
|
19
|
+
* the file itself.
|
|
20
|
+
*
|
|
12
21
|
* Files land in `.clopen/attachments/` under the session's working root. The
|
|
13
22
|
* folder ignores itself (`.clopen/.gitignore` is `*`), so an attachment never
|
|
14
23
|
* shows up in git or in a turn's snapshot as a change the agent made.
|
|
15
24
|
*/
|
|
16
25
|
|
|
17
|
-
import { mkdirSync, writeFileSync, existsSync } from 'fs';
|
|
18
|
-
import { join, extname, basename } from 'path';
|
|
19
|
-
import type { EngineModel, EngineType, StreamRequest } from '$shared/types/unified';
|
|
26
|
+
import { mkdirSync, writeFileSync, existsSync, statSync } from 'fs';
|
|
27
|
+
import { join, extname, basename, relative, isAbsolute, resolve, sep } from 'path';
|
|
28
|
+
import type { EngineModel, EngineType, FileBlock, StreamRequest, UserContentBlock } from '$shared/types/unified';
|
|
29
|
+
import type { ContextSource } from '$shared/types/mentions';
|
|
30
|
+
import { CONTEXT_MEDIA_TYPE, CONTEXT_NOUNS, isReferenceKind, readContextHeaderFromBase64 } from '$shared/utils/context-document';
|
|
20
31
|
import { getModelsByEngine, registerModels } from '$shared/constants/engines';
|
|
21
32
|
import { debug } from '$shared/utils/logger';
|
|
22
33
|
import { MAX_ATTACHMENT_BYTES, MAX_INLINE_ATTACHMENT_BYTES } from '$shared/constants/attachments';
|
|
@@ -103,57 +114,143 @@ export function saveAttachment(root: string, input: { data: Uint8Array; mediaTyp
|
|
|
103
114
|
return join(ATTACHMENTS_DIR, file);
|
|
104
115
|
}
|
|
105
116
|
|
|
106
|
-
/** The line a prompt carries for a file it does not hold inline. */
|
|
107
|
-
export function attachmentMention(relativePath: string, input: { mediaType: string; size: number; name?: string | null }): string {
|
|
108
|
-
const label = input.name?.trim() ? `"${input.name.trim()}"` : 'a file';
|
|
109
|
-
return `[Attached ${label} (${input.mediaType || 'unknown type'}, ${formatBytes(input.size)}), saved at ./${relativePath.split('\\').join('/')}]`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
117
|
/**
|
|
113
|
-
* Keep what the model reads inline; save the rest under `root` and
|
|
114
|
-
*
|
|
118
|
+
* Keep what the model reads inline; save the rest under `root` and keep a
|
|
119
|
+
* `file` block saying where it went. Every attachment is numbered in the
|
|
120
|
+
* order it was attached — the `@N` the user writes about it.
|
|
115
121
|
*/
|
|
116
122
|
export async function normalizeAttachments(request: StreamRequest, root: string): Promise<StreamRequest> {
|
|
117
123
|
const content = (request.prompt as { content?: unknown })?.content;
|
|
118
124
|
if (!Array.isArray(content)) return request;
|
|
119
|
-
|
|
120
|
-
if (files.length === 0) return request;
|
|
125
|
+
if (!content.some(isAttachment)) return request;
|
|
121
126
|
|
|
122
127
|
const modalities = await inputModalities(request.engine.type, request.engine.model.id);
|
|
123
|
-
const
|
|
124
|
-
|
|
128
|
+
const normalized: unknown[] = [];
|
|
129
|
+
let index = 0;
|
|
125
130
|
for (const block of content) {
|
|
126
|
-
if ((block
|
|
127
|
-
|
|
131
|
+
if (!isAttachment(block)) {
|
|
132
|
+
normalized.push(block);
|
|
128
133
|
continue;
|
|
129
134
|
}
|
|
130
|
-
|
|
135
|
+
index++;
|
|
136
|
+
if (block.type === 'file') {
|
|
137
|
+
normalized.push({ ...block, index });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (typeof block.data !== 'string') {
|
|
141
|
+
normalized.push({ ...block, index });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const mediaType = typeof block.mediaType === 'string' && block.mediaType ? block.mediaType : 'application/octet-stream';
|
|
145
|
+
const title = typeof block.title === 'string' && block.title.trim() ? block.title.trim() : null;
|
|
131
146
|
const size = base64Size(block.data);
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
const source = mediaType === CONTEXT_MEDIA_TYPE ? readContextHeaderFromBase64(block.data, mediaType) : null;
|
|
148
|
+
if (source && isReferenceKind(source.kind)) {
|
|
149
|
+
normalized.push(referenceBlock(root, source, index));
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (!source && isNative(mediaType, modalities) && size <= MAX_INLINE_ATTACHMENT_BYTES) {
|
|
153
|
+
normalized.push({ ...block, index });
|
|
134
154
|
continue;
|
|
135
155
|
}
|
|
136
156
|
if (size > MAX_ATTACHMENT_BYTES) {
|
|
137
|
-
|
|
157
|
+
normalized.push({ type: 'text', text: `[Attachment @${index} "${title ?? 'attachment'}" (${formatBytes(size)}) was too large to keep. The limit is ${formatBytes(MAX_ATTACHMENT_BYTES)}.]` });
|
|
138
158
|
continue;
|
|
139
159
|
}
|
|
140
160
|
try {
|
|
141
|
-
const path = saveAttachment(root, { data: Buffer.from(block.data, 'base64'), mediaType, name:
|
|
142
|
-
|
|
161
|
+
const path = saveAttachment(root, { data: Buffer.from(block.data, 'base64'), mediaType, name: title });
|
|
162
|
+
normalized.push({ type: 'file', mediaType, title, size, path: join(root, path), index, ...(source && { source }) } satisfies FileBlock);
|
|
143
163
|
} catch (error) {
|
|
144
164
|
debug.warn('chat', 'Saving an attachment failed:', error);
|
|
145
|
-
|
|
165
|
+
normalized.push({ type: 'text', text: `[Attachment @${index} "${title ?? 'attachment'}" could not be saved.]` });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { ...request, prompt: { ...request.prompt, content: normalized } as StreamRequest['prompt'] };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* A mentioned project file: the engine reads the file itself. One that has
|
|
173
|
+
* gone since it was mentioned is said to be gone rather than silently dropped.
|
|
174
|
+
*/
|
|
175
|
+
function referenceBlock(root: string, source: ContextSource, index: number): UserContentBlock {
|
|
176
|
+
const absolute = source.path ? resolve(root, source.path) : null;
|
|
177
|
+
const inside = !!absolute && (absolute === resolve(root) || absolute.startsWith(resolve(root) + sep));
|
|
178
|
+
if (absolute && inside && existsSync(absolute)) {
|
|
179
|
+
let size = 0;
|
|
180
|
+
try {
|
|
181
|
+
size = statSync(absolute).size;
|
|
182
|
+
} catch {
|
|
183
|
+
// The size is only for the card.
|
|
146
184
|
}
|
|
185
|
+
return { type: 'file', mediaType: 'text/plain', title: basename(absolute), size, path: absolute, index, source };
|
|
147
186
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
187
|
+
return { type: 'text', text: `[Attachment @${index} "${source.label}" is no longer in the project.]` };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type AttachmentLike = { type: 'image' | 'document' | 'file'; data?: unknown; mediaType?: unknown; title?: unknown };
|
|
191
|
+
|
|
192
|
+
function isAttachment(block: unknown): block is AttachmentLike {
|
|
193
|
+
const type = (block as { type?: unknown } | null)?.type;
|
|
194
|
+
return type === 'image' || type === 'document' || type === 'file';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** How the prompt names a file: its number, name, type and size. */
|
|
198
|
+
export function attachmentLabel(input: { index: number; title?: string | null; mediaType: string; size: number }): string {
|
|
199
|
+
const name = input.title?.trim() ? `"${input.title.trim()}"` : 'a file';
|
|
200
|
+
return `Attachment @${input.index}: ${name} (${input.mediaType || 'unknown type'}, ${formatBytes(input.size)})`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A path as the engine, working in `root`, would write it. */
|
|
204
|
+
function displayPath(path: string, root: string): string {
|
|
205
|
+
const inside = relative(root, path);
|
|
206
|
+
if (!inside || inside.startsWith('..') || isAbsolute(inside)) return path;
|
|
207
|
+
return `./${inside.split('\\').join('/')}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** How the prompt names a mention: what it is a snapshot of, and when it was taken. */
|
|
211
|
+
export function contextLabel(input: { index: number; source: ContextSource }): string {
|
|
212
|
+
const { source } = input;
|
|
213
|
+
if (isReferenceKind(source.kind)) return `Attachment @${input.index}: ${CONTEXT_NOUNS[source.kind]} "${source.label}"`;
|
|
214
|
+
const extra = [source.detail, source.capturedAt && `captured ${source.capturedAt}`].filter(Boolean).join(', ');
|
|
215
|
+
return `Attachment @${input.index}: ${CONTEXT_NOUNS[source.kind]} "${source.label}"${extra ? ` (${extra})` : ''}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Said once, before the first mention: the snapshots are part of the request. */
|
|
219
|
+
export const CONTEXT_NOTE =
|
|
220
|
+
'[The user attached snapshots of their workspace to this message, saved as files. Read the ones the message refers to before acting on it — they show what the user was looking at.]';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* What the engine is given for a user message. Every numbered attachment is
|
|
224
|
+
* preceded by its label, and a saved file becomes a label saying where it is —
|
|
225
|
+
* so `@3` in the text points at the same file for the model as for the user.
|
|
226
|
+
* Engines that pull images out of the content keep the labels in the text, in
|
|
227
|
+
* the same order. The saved message is left as it is: labels are for the
|
|
228
|
+
* model, the timeline draws its own numbers.
|
|
229
|
+
*/
|
|
230
|
+
export function labelAttachments(content: UserContentBlock[], root: string): UserContentBlock[] {
|
|
231
|
+
const labelled = content.some((block) => block.type === 'file' || ((block.type === 'image' || block.type === 'document') && block.index));
|
|
232
|
+
if (!labelled) return content;
|
|
233
|
+
|
|
234
|
+
const result: UserContentBlock[] = [];
|
|
235
|
+
let noted = false;
|
|
236
|
+
for (const block of content) {
|
|
237
|
+
if (block.type === 'file' && block.source) {
|
|
238
|
+
if (!noted && !isReferenceKind(block.source.kind)) {
|
|
239
|
+
result.push({ type: 'text', text: CONTEXT_NOTE });
|
|
240
|
+
noted = true;
|
|
241
|
+
}
|
|
242
|
+
const label = contextLabel({ index: block.index ?? 0, source: block.source });
|
|
243
|
+
const where = isReferenceKind(block.source.kind) ? 'at' : 'saved at';
|
|
244
|
+
result.push({ type: 'text', text: `[${label}, ${where} ${displayPath(block.path, root)}]` });
|
|
245
|
+
} else if (block.type === 'file') {
|
|
246
|
+
const label = attachmentLabel({ index: block.index ?? 0, title: block.title, mediaType: block.mediaType, size: block.size });
|
|
247
|
+
result.push({ type: 'text', text: `[${label}, saved at ${displayPath(block.path, root)}]` });
|
|
248
|
+
} else if ((block.type === 'image' || block.type === 'document') && block.index) {
|
|
249
|
+
const label = attachmentLabel({ index: block.index, title: block.title, mediaType: block.mediaType, size: base64Size(block.data) });
|
|
250
|
+
result.push({ type: 'text', text: `[${label}]` }, block);
|
|
251
|
+
} else {
|
|
252
|
+
result.push(block);
|
|
253
|
+
}
|
|
157
254
|
}
|
|
158
|
-
return
|
|
255
|
+
return result;
|
|
159
256
|
}
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
import { messageQueries, sessionQueries } from '../database/queries';
|
|
35
35
|
import { getModelsByEngine } from '$shared/constants/engines';
|
|
36
|
+
import { CONTEXT_NOUNS } from '$shared/utils/context-document';
|
|
36
37
|
import { debug } from '$shared/utils/logger';
|
|
37
38
|
import type {
|
|
38
39
|
EngineType,
|
|
@@ -43,6 +44,7 @@ import type {
|
|
|
43
44
|
UserContentBlock,
|
|
44
45
|
ImageBlock,
|
|
45
46
|
DocumentBlock,
|
|
47
|
+
FileBlock,
|
|
46
48
|
} from '$shared/types/unified';
|
|
47
49
|
|
|
48
50
|
// ============================================================================
|
|
@@ -63,7 +65,7 @@ const CHARS_PER_TOKEN = 4;
|
|
|
63
65
|
// ============================================================================
|
|
64
66
|
|
|
65
67
|
type Entry =
|
|
66
|
-
| { kind: 'user'; text: string; attachments: Array<ImageBlock | DocumentBlock> }
|
|
68
|
+
| { kind: 'user'; text: string; attachments: Array<ImageBlock | DocumentBlock | FileBlock> }
|
|
67
69
|
| { kind: 'assistant'; text: string }
|
|
68
70
|
| { kind: 'reasoning'; text: string }
|
|
69
71
|
| { kind: 'tool_use'; id: string; name: string; input: unknown }
|
|
@@ -194,13 +196,13 @@ function collect(messages: UnifiedMessage[]): Entry[] {
|
|
|
194
196
|
case 'user': {
|
|
195
197
|
const user = msg as UserMessage;
|
|
196
198
|
const texts: string[] = [];
|
|
197
|
-
const attachments: Array<ImageBlock | DocumentBlock> = [];
|
|
199
|
+
const attachments: Array<ImageBlock | DocumentBlock | FileBlock> = [];
|
|
198
200
|
let emittedResult = false;
|
|
199
201
|
|
|
200
202
|
for (const block of user.content) {
|
|
201
203
|
if (block.type === 'text') {
|
|
202
204
|
if (block.text.trim()) texts.push(block.text);
|
|
203
|
-
} else if (block.type === 'image' || block.type === 'document') {
|
|
205
|
+
} else if (block.type === 'image' || block.type === 'document' || block.type === 'file') {
|
|
204
206
|
attachments.push(block);
|
|
205
207
|
} else if (block.type === 'tool_result') {
|
|
206
208
|
entries.push({
|
|
@@ -278,6 +280,11 @@ function renderEntries(entries: Entry[], clearedToolUseIds: Set<string>, support
|
|
|
278
280
|
case 'user': {
|
|
279
281
|
if (entry.text) lines.push(`[user]\n${entry.text}`);
|
|
280
282
|
for (const att of entry.attachments) {
|
|
283
|
+
// A saved file was never inline: the copy on disk is still there to read.
|
|
284
|
+
if (att.type === 'file') {
|
|
285
|
+
lines.push(`[user attachment: ${describeAttachment(att)}, saved at ${att.path}]`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
281
288
|
const supported = att.type === 'image' ? support.image : support.document;
|
|
282
289
|
if (supported) {
|
|
283
290
|
attachments.push(att);
|
|
@@ -317,9 +324,12 @@ function renderEntries(entries: Entry[], clearedToolUseIds: Set<string>, support
|
|
|
317
324
|
return { lines, attachments, droppedAttachments };
|
|
318
325
|
}
|
|
319
326
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
/** Its number first, so `@2` in the replayed text still points at it. */
|
|
328
|
+
function describeAttachment(att: ImageBlock | DocumentBlock | FileBlock): string {
|
|
329
|
+
const number = att.index ? `@${att.index} ` : '';
|
|
330
|
+
if (att.type === 'file' && att.source) return `${number}${CONTEXT_NOUNS[att.source.kind]} "${att.source.label}"`;
|
|
331
|
+
if (att.title) return `${number}${att.title} (${att.mediaType})`;
|
|
332
|
+
return `${number}${att.mediaType}`;
|
|
323
333
|
}
|
|
324
334
|
|
|
325
335
|
function estimateTokens(lines: string[]): number {
|
|
@@ -437,3 +447,29 @@ export function buildEngineHandoff(
|
|
|
437
447
|
export function withHandoff(prompt: UserMessage, blocks: UserContentBlock[]): UserMessage {
|
|
438
448
|
return { ...prompt, content: [...blocks, ...prompt.content] };
|
|
439
449
|
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* A chat's active branch as plain text — what `@` mentioning that chat in
|
|
453
|
+
* another one attaches. The same rendering the handoff uses, uncleared: it is
|
|
454
|
+
* read from a file, so its size costs a read rather than context.
|
|
455
|
+
*/
|
|
456
|
+
export function renderBranchTranscript(chatSessionId: string): { text: string; turns: number } | null {
|
|
457
|
+
let messages: UnifiedMessage[];
|
|
458
|
+
try {
|
|
459
|
+
const head = sessionQueries.getHead(chatSessionId);
|
|
460
|
+
if (!head) return null;
|
|
461
|
+
messages = messageQueries
|
|
462
|
+
.getPathToRoot(head)
|
|
463
|
+
.map(row => parse(row.data))
|
|
464
|
+
.filter((msg): msg is UnifiedMessage => msg !== null);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
debug.error('chat', 'Transcript: failed to read branch:', error);
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
const entries = collect(messages);
|
|
470
|
+
if (!entries.length) return null;
|
|
471
|
+
// Attachments are named, not carried: the transcript is text.
|
|
472
|
+
const render = renderEntries(entries, new Set(), { image: true, document: true });
|
|
473
|
+
const turns = entries.filter(e => e.kind === 'user' || e.kind === 'assistant').length;
|
|
474
|
+
return { text: render.lines.join('\n\n'), turns };
|
|
475
|
+
}
|
|
@@ -47,6 +47,8 @@ import { extractMessageText } from '../snapshot/helpers';
|
|
|
47
47
|
import { deferEpisodicIngest, ingestTurn } from '../memory/extract';
|
|
48
48
|
import { buildMemoryContext, withMemoryContext } from '../memory/context';
|
|
49
49
|
import { buildEngineHandoff, resolveBranchEngine, withHandoff } from './engine-handoff';
|
|
50
|
+
import { labelAttachments } from './attachments';
|
|
51
|
+
import { resolveTranscriptAlias, transcriptExists } from '../storage/transcripts';
|
|
50
52
|
import { resolveGitEnv } from '$backend/git/identity';
|
|
51
53
|
import { debug } from '$shared/utils/logger';
|
|
52
54
|
import { attachSubmittedAnswers } from '$shared/utils/ask-user-question';
|
|
@@ -106,6 +108,8 @@ export interface StreamState {
|
|
|
106
108
|
engineInstance?: AIEngine;
|
|
107
109
|
sdkSessionId?: string;
|
|
108
110
|
preStreamSessionId?: string | null;
|
|
111
|
+
/** The transcript actually resumed — differs from `preStreamSessionId` when it was deduplicated. */
|
|
112
|
+
resumeTargetSessionId?: string | null;
|
|
109
113
|
hasCompactBoundary?: boolean;
|
|
110
114
|
eventSeq: number;
|
|
111
115
|
/**
|
|
@@ -695,6 +699,31 @@ class StreamManager extends EventEmitter {
|
|
|
695
699
|
}
|
|
696
700
|
streamState.preStreamSessionId = resumeSessionId ?? null;
|
|
697
701
|
|
|
702
|
+
// Where that session lives now, and whether it still exists at all.
|
|
703
|
+
// Settings → Storage deduplicates Claude forks (an earlier fork becomes
|
|
704
|
+
// "the later one, cut at this entry") and may delete the transcripts of
|
|
705
|
+
// a slimmed chat. A target that is gone is not resumed — the branch is
|
|
706
|
+
// replayed as prompt content instead, exactly as for an engine switch,
|
|
707
|
+
// so the conversation carries on with its context rather than failing
|
|
708
|
+
// or silently starting blank.
|
|
709
|
+
let engineResume: string | undefined = resumeSessionId;
|
|
710
|
+
let engineResumeAt: string | undefined;
|
|
711
|
+
let resumeLost = false;
|
|
712
|
+
if (resumeSessionId) {
|
|
713
|
+
const alias = resolveTranscriptAlias(requestEngine.type, resumeSessionId);
|
|
714
|
+
if (alias) {
|
|
715
|
+
engineResume = alias.targetSessionId;
|
|
716
|
+
engineResumeAt = alias.resumeAt;
|
|
717
|
+
}
|
|
718
|
+
if (!(await transcriptExists(requestEngine.type, engineResume!, projectPath))) {
|
|
719
|
+
debug.log('chat', `Resume target ${engineResume} is gone; replaying the branch instead`);
|
|
720
|
+
resumeLost = true;
|
|
721
|
+
engineResume = undefined;
|
|
722
|
+
engineResumeAt = undefined;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
streamState.resumeTargetSessionId = engineResume ?? null;
|
|
726
|
+
|
|
698
727
|
// Convert raw SDK prompt → UserMessage (unified)
|
|
699
728
|
const userMessage = convertRawPromptToUserMessage(rawPrompt);
|
|
700
729
|
|
|
@@ -798,17 +827,23 @@ class StreamManager extends EventEmitter {
|
|
|
798
827
|
debug.warn('chat', 'Slash skill expansion failed, sending the message as typed:', error);
|
|
799
828
|
}
|
|
800
829
|
|
|
801
|
-
|
|
830
|
+
// Every attachment is labelled with its `@N` (saved ones with where
|
|
831
|
+
// they are), so the numbers the user writes mean the same files to the
|
|
832
|
+
// engine. After the slash expansion, which reads the first text block.
|
|
833
|
+
enginePrompt = { ...enginePrompt, content: labelAttachments(enginePrompt.content, projectPath) };
|
|
834
|
+
|
|
835
|
+
if ((engineSwitched || resumeLost) && chatSessionId) {
|
|
802
836
|
try {
|
|
803
837
|
const handoff = buildEngineHandoff(
|
|
804
838
|
chatSessionId,
|
|
805
839
|
requestEngine.type,
|
|
806
840
|
requestEngine.model.id || '',
|
|
807
|
-
|
|
841
|
+
// Same engine, lost transcript: not a takeover from another engine.
|
|
842
|
+
engineSwitched ? branchEngine : null,
|
|
808
843
|
userMessageId
|
|
809
844
|
);
|
|
810
845
|
if (handoff) {
|
|
811
|
-
enginePrompt = withHandoff(
|
|
846
|
+
enginePrompt = withHandoff(enginePrompt, handoff.blocks);
|
|
812
847
|
const { turns, clearedToolResults, droppedAttachments, estimatedTokens } = handoff.stats;
|
|
813
848
|
debug.log(
|
|
814
849
|
'chat',
|
|
@@ -866,7 +901,7 @@ class StreamManager extends EventEmitter {
|
|
|
866
901
|
// Detect orphaned user messages and prepend context (claude-code only).
|
|
867
902
|
// Same idea as the handoff above but for the in-engine case: messages the
|
|
868
903
|
// engine's own session never saw because an earlier turn was cancelled.
|
|
869
|
-
if (!engineSwitched && requestEngine.type === 'claude-code' && chatSessionId) {
|
|
904
|
+
if (!engineSwitched && !resumeLost && requestEngine.type === 'claude-code' && chatSessionId) {
|
|
870
905
|
try {
|
|
871
906
|
const head = sessionQueries.getHead(chatSessionId);
|
|
872
907
|
if (head) {
|
|
@@ -947,7 +982,8 @@ class StreamManager extends EventEmitter {
|
|
|
947
982
|
const streamIterable = engine.streamQuery({
|
|
948
983
|
projectPath,
|
|
949
984
|
prompt: enginePrompt,
|
|
950
|
-
resume:
|
|
985
|
+
resume: engineResume,
|
|
986
|
+
...(engineResumeAt && { resumeAt: engineResumeAt }),
|
|
951
987
|
providerSlug: requestEngine.provider,
|
|
952
988
|
modelId: requestEngine.model.id,
|
|
953
989
|
...(streamState.reasoningEffort && { reasoningEffort: streamState.reasoningEffort }),
|
|
@@ -291,6 +291,28 @@ export async function readStats(hostId: string, containerId: string): Promise<Co
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
/** Everything `inspect` knows, read only when a detail pane asks for it. */
|
|
294
|
+
/**
|
|
295
|
+
* The last lines a container wrote, read once — what a chat mention attaches.
|
|
296
|
+
* Following a log is logs.ts; this is a snapshot of it.
|
|
297
|
+
*/
|
|
298
|
+
export async function readRecentLogs(hostId: string, containerId: string, lines = 2000): Promise<string | null> {
|
|
299
|
+
assertContainerId(containerId);
|
|
300
|
+
|
|
301
|
+
return containerMonitor.withHost(hostId, async (runner, platform) => {
|
|
302
|
+
const info = await detectRuntime(hostId, runner, platform);
|
|
303
|
+
if (info.problem !== 'none' || !info.runtime) return null;
|
|
304
|
+
|
|
305
|
+
const result = await tryRun(
|
|
306
|
+
runner,
|
|
307
|
+
containerArgv(info.runtime, platform, ['logs', '--tail', String(Math.max(1, Math.floor(lines))), '--timestamps', containerId]),
|
|
308
|
+
CONTAINER_TIMEOUTS.inspect
|
|
309
|
+
);
|
|
310
|
+
if (result.code !== 0) return null;
|
|
311
|
+
// The runtime writes the container's stderr to its own; both are the log.
|
|
312
|
+
return [result.stdout, result.stderr].filter((part) => part.trim()).join('\n');
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
294
316
|
export async function inspectContainer(
|
|
295
317
|
hostId: string,
|
|
296
318
|
containerId: string
|