@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,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preview browser: a tab (its address, what it shows, what went wrong in
|
|
3
|
+
* it), a tab's console, and one element of a page.
|
|
4
|
+
*
|
|
5
|
+
* A tab is captured with a picture of what is on screen beside the document —
|
|
6
|
+
* the model can see the page the user is talking about. The tab's id is in
|
|
7
|
+
* the document too, so an agent with the browser tool can act on that tab.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ws } from '$backend/utils/ws';
|
|
11
|
+
import { browserPreviewServiceManager } from '$backend/preview/index';
|
|
12
|
+
import { makeScopeKey } from '$shared/utils/workspace-scope';
|
|
13
|
+
import type { CapturedAttachment, MentionCandidate } from '$shared/types/mentions';
|
|
14
|
+
import type { BrowserConsoleMessage } from '$backend/preview/browser/types';
|
|
15
|
+
import { buildContextDocument, contextFileSlug, countLines } from '$shared/utils/context-document';
|
|
16
|
+
import { rank, wants } from '../shared';
|
|
17
|
+
import { refString, type MentionContext, type MentionSource } from '../types';
|
|
18
|
+
|
|
19
|
+
const CATEGORY = 'preview';
|
|
20
|
+
|
|
21
|
+
/** The preview of the workspace on screen, without starting one. */
|
|
22
|
+
function previewService(ctx: MentionContext) {
|
|
23
|
+
const scope = makeScopeKey(ctx.projectId, ws.getWorktreeId(ctx.conn));
|
|
24
|
+
return browserPreviewServiceManager.hasService(scope) ? browserPreviewServiceManager.getService(scope) : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function consoleLine(message: BrowserConsoleMessage): string {
|
|
28
|
+
const where = message.location?.url ? ` (${message.location.url}:${message.location.lineNumber})` : '';
|
|
29
|
+
const repeat = message.count && message.count > 1 ? ` ×${message.count}` : '';
|
|
30
|
+
return `[${message.type}] ${message.text}${where}${repeat}${message.stackTrace ? `\n${message.stackTrace}` : ''}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function base64(bytes: Uint8Array): string {
|
|
34
|
+
return Buffer.from(bytes).toString('base64');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const previewSource: MentionSource = {
|
|
38
|
+
kinds: ['preview-tab', 'preview-console', 'preview-element'],
|
|
39
|
+
|
|
40
|
+
categories(ctx) {
|
|
41
|
+
const service = previewService(ctx);
|
|
42
|
+
if (!service || service.getTabCount() === 0) return [];
|
|
43
|
+
return [{ id: CATEGORY, label: 'Preview tabs', detail: `${service.getTabCount()} open`, icon: 'lucide:app-window', group: 'Preview' }];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async list(ctx, request) {
|
|
47
|
+
const mode = wants(request.category, CATEGORY);
|
|
48
|
+
if (!mode) return [];
|
|
49
|
+
const service = previewService(ctx);
|
|
50
|
+
if (!service) return [];
|
|
51
|
+
const tabs = service.getAllTabsInfo();
|
|
52
|
+
const rows: MentionCandidate[] = [];
|
|
53
|
+
for (const tab of tabs) {
|
|
54
|
+
rows.push({
|
|
55
|
+
key: `preview-tab:${tab.id}`, kind: 'preview-tab', group: 'Preview', label: tab.title || tab.url || 'Untitled tab',
|
|
56
|
+
detail: `${tab.isActive ? 'Active · ' : ''}${tab.url}`, icon: 'lucide:app-window', ref: { tabId: tab.id }
|
|
57
|
+
});
|
|
58
|
+
if (mode === 'own') {
|
|
59
|
+
const count = service.getConsoleLogs(tab.id).length;
|
|
60
|
+
rows.push({
|
|
61
|
+
key: `preview-console:${tab.id}`, kind: 'preview-console', group: 'Console', label: `Console · ${tab.title || tab.url}`,
|
|
62
|
+
detail: `${count} ${count === 1 ? 'message' : 'messages'}`, icon: 'lucide:scroll-text', ref: { tabId: tab.id }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// At the root with nothing typed, only the tab on screen is suggested.
|
|
67
|
+
if (mode === 'root' && !request.query.trim()) return rows.filter((row) => tabs.find((tab) => tab.isActive && row.ref.tabId === tab.id)).slice(0, 1);
|
|
68
|
+
return rank(rows, request.query, (row) => [row.label, row.detail, 'preview browser'], mode === 'root' ? 3 : request.limit);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
async capture(ctx, kind, ref) {
|
|
72
|
+
const service = previewService(ctx);
|
|
73
|
+
if (!service) throw new Error('The preview is not running');
|
|
74
|
+
const tabId = refString(ref, 'tabId');
|
|
75
|
+
const tab = service.getTabInfo(tabId);
|
|
76
|
+
if (!tab) throw new Error('That tab is no longer open');
|
|
77
|
+
const logs = service.getConsoleLogs(tabId).filter((message) => message.type !== 'clear');
|
|
78
|
+
const tabFacts: Array<[string, string]> = [
|
|
79
|
+
['URL', tab.url],
|
|
80
|
+
['Title', tab.title],
|
|
81
|
+
['Tab id', tab.id],
|
|
82
|
+
['Device', `${tab.deviceSize}${tab.deviceModel ? ` (${tab.deviceModel})` : ''}, ${tab.width}×${tab.height}`]
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
if (kind === 'preview-console') {
|
|
86
|
+
const body = logs.map(consoleLine).join('\n');
|
|
87
|
+
return {
|
|
88
|
+
documents: [buildContextDocument({
|
|
89
|
+
kind, label: tab.title || tab.url, detail: `${logs.length} messages`, facts: tabFacts,
|
|
90
|
+
sections: [{ title: 'Console', body, fence: 'text' }]
|
|
91
|
+
})]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (kind === 'preview-tab') {
|
|
96
|
+
const problems = logs.filter((message) => message.type === 'error' || message.type === 'warn').slice(-50);
|
|
97
|
+
const images: CapturedAttachment[] = [];
|
|
98
|
+
try {
|
|
99
|
+
const shot = await service.takeScreenshot(tabId, { kind: 'viewport' }, { format: 'jpeg', quality: 80 }, 'user');
|
|
100
|
+
images.push({ fileName: `preview-${contextFileSlug(tab.title || 'tab')}.jpg`, mediaType: shot.mimeType, data: base64(shot.data) });
|
|
101
|
+
} catch {
|
|
102
|
+
// The page and its errors still say what is going on.
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
documents: [buildContextDocument({
|
|
106
|
+
kind, label: tab.title || tab.url, detail: tab.url, facts: tabFacts,
|
|
107
|
+
sections: [{
|
|
108
|
+
title: 'Recent errors and warnings',
|
|
109
|
+
body: problems.length ? problems.map(consoleLine).join('\n') : 'None.',
|
|
110
|
+
fence: problems.length ? 'text' : undefined
|
|
111
|
+
}]
|
|
112
|
+
})],
|
|
113
|
+
images
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// preview-element
|
|
118
|
+
const x = Number(ref.x);
|
|
119
|
+
const y = Number(ref.y);
|
|
120
|
+
const depth = Number(ref.depth) || 0;
|
|
121
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error('No point on the page was given');
|
|
122
|
+
const element = await service.describeElementAt(tabId, x, y, depth);
|
|
123
|
+
if (!element) throw new Error('There is no element at that point');
|
|
124
|
+
const images: CapturedAttachment[] = [];
|
|
125
|
+
try {
|
|
126
|
+
const shot = await service.takeScreenshot(tabId, { kind: 'element', x, y, depth }, { format: 'png' }, 'user');
|
|
127
|
+
images.push({ fileName: `element-${contextFileSlug(element.selector)}.png`, mediaType: shot.mimeType, data: base64(shot.data) });
|
|
128
|
+
} catch {
|
|
129
|
+
// An element with no visible box still has its markup.
|
|
130
|
+
}
|
|
131
|
+
const attributes = Object.entries(element.attributes).map(([name, value]) => `${name}="${value}"`).join('\n');
|
|
132
|
+
const styles = Object.entries(element.styles).map(([name, value]) => `${name}: ${value};`).join('\n');
|
|
133
|
+
return {
|
|
134
|
+
documents: [buildContextDocument({
|
|
135
|
+
kind, label: element.selector, detail: `<${element.tag}> on ${element.title || element.url}`,
|
|
136
|
+
facts: [
|
|
137
|
+
['Page', element.url],
|
|
138
|
+
['Tab id', tab.id],
|
|
139
|
+
['Selector', element.selector],
|
|
140
|
+
['Box', `${element.rect.width}×${element.rect.height} at (${element.rect.x}, ${element.rect.y}) in a ${tab.width}×${tab.height} viewport`],
|
|
141
|
+
['Inside', element.ancestors.slice(-6).join(' > ') || '(document)']
|
|
142
|
+
],
|
|
143
|
+
sections: [
|
|
144
|
+
...(element.text ? [{ title: 'Visible text', body: element.text, fence: 'text' }] : []),
|
|
145
|
+
...(attributes ? [{ title: 'Attributes', body: attributes, fence: '' }] : []),
|
|
146
|
+
{ title: 'Computed style', body: styles, fence: 'css' },
|
|
147
|
+
{ title: `HTML${element.htmlTruncated ? ' (cut short)' : ''} · ${countLines(element.html)}`, body: element.html, fence: 'html' }
|
|
148
|
+
]
|
|
149
|
+
})],
|
|
150
|
+
images
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Another project: where it is and what it is.
|
|
3
|
+
*
|
|
4
|
+
* The overview is what someone opening the project would read first — its
|
|
5
|
+
* readme and agent instructions, the top of its tree, its git state — plus its
|
|
6
|
+
* path, so an engine that can reach it can read on from there.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readdir, readFile } from 'fs/promises';
|
|
10
|
+
import { join } from 'path';
|
|
11
|
+
import type { Project } from '$shared/types/database/schema';
|
|
12
|
+
import type { MentionCandidate } from '$shared/types/mentions';
|
|
13
|
+
import { buildContextDocument, type ContextSection } from '$shared/utils/context-document';
|
|
14
|
+
import { projectQueries } from '$backend/database/queries';
|
|
15
|
+
import { SKIP_DIRS } from '$backend/ws/files/search';
|
|
16
|
+
import { ago, gitText, rank, wants } from '../shared';
|
|
17
|
+
import { refString, type MentionSource } from '../types';
|
|
18
|
+
|
|
19
|
+
const CATEGORY = 'projects';
|
|
20
|
+
|
|
21
|
+
/** Files that describe a project, in the order they are worth reading. */
|
|
22
|
+
const DESCRIBING_FILES = ['README.md', 'readme.md', 'README', 'AGENTS.md', 'CLAUDE.md', 'package.json', 'pyproject.toml', 'Cargo.toml', 'go.mod'];
|
|
23
|
+
const MAX_DESCRIBING_BYTES = 60_000;
|
|
24
|
+
|
|
25
|
+
function projectRow(project: Project): MentionCandidate {
|
|
26
|
+
return {
|
|
27
|
+
key: `project:${project.id}`,
|
|
28
|
+
kind: 'project',
|
|
29
|
+
group: 'Projects',
|
|
30
|
+
label: project.name,
|
|
31
|
+
detail: `${project.path} · opened ${ago(project.last_opened_at)}`,
|
|
32
|
+
icon: 'lucide:folder-kanban',
|
|
33
|
+
ref: { projectId: project.id }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function topOfTree(root: string): Promise<string> {
|
|
38
|
+
const lines: string[] = [];
|
|
39
|
+
const visit = async (dir: string, prefix: string, depth: number) => {
|
|
40
|
+
let entries;
|
|
41
|
+
try {
|
|
42
|
+
entries = (await readdir(dir, { withFileTypes: true })).filter((entry) => !SKIP_DIRS.has(entry.name) && entry.name !== '.git');
|
|
43
|
+
} catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
entries.sort((a, b) => Number(b.isDirectory()) - Number(a.isDirectory()) || a.name.localeCompare(b.name));
|
|
47
|
+
for (const entry of entries.slice(0, 60)) {
|
|
48
|
+
lines.push(`${prefix}${entry.name}${entry.isDirectory() ? '/' : ''}`);
|
|
49
|
+
if (entry.isDirectory() && depth < 1) await visit(join(dir, entry.name), `${prefix} `, depth + 1);
|
|
50
|
+
}
|
|
51
|
+
if (entries.length > 60) lines.push(`${prefix}… ${entries.length - 60} more`);
|
|
52
|
+
};
|
|
53
|
+
await visit(root, '', 0);
|
|
54
|
+
return lines.join('\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const projectsSource: MentionSource = {
|
|
58
|
+
kinds: ['project'],
|
|
59
|
+
|
|
60
|
+
categories: () => [{ id: CATEGORY, label: 'Projects', detail: 'Other projects in Clopen', icon: 'lucide:folder-kanban', group: 'Projects' }],
|
|
61
|
+
|
|
62
|
+
async list(ctx, request) {
|
|
63
|
+
const mode = wants(request.category, CATEGORY);
|
|
64
|
+
if (!mode || (mode === 'root' && !request.query.trim())) return [];
|
|
65
|
+
const projects = projectQueries
|
|
66
|
+
.getListed()
|
|
67
|
+
.filter((project) => project.id !== ctx.projectId && project.kind !== 'home')
|
|
68
|
+
.sort((a, b) => (b.last_opened_at ?? '').localeCompare(a.last_opened_at ?? ''));
|
|
69
|
+
return rank(projects, request.query, (project) => [project.name, project.path], mode === 'root' ? 3 : request.limit).map(projectRow);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async capture(_ctx, _kind, ref) {
|
|
73
|
+
const project = projectQueries.getById(refString(ref, 'projectId'));
|
|
74
|
+
if (!project || !projectQueries.isListed(project.id)) throw new Error('That project is gone');
|
|
75
|
+
|
|
76
|
+
const sections: ContextSection[] = [];
|
|
77
|
+
const tree = await topOfTree(project.path);
|
|
78
|
+
sections.push({ title: 'Top of the tree', body: tree || '(empty or unreadable)', fence: '' });
|
|
79
|
+
|
|
80
|
+
const branch = (await gitText(['rev-parse', '--abbrev-ref', 'HEAD'], project.path))?.trim();
|
|
81
|
+
if (branch) {
|
|
82
|
+
const status = await gitText(['status', '--short'], project.path);
|
|
83
|
+
const log = await gitText(['log', '--oneline', '-n', '10'], project.path);
|
|
84
|
+
sections.push({ title: `Git · ${branch}`, body: `${status?.trim() || 'Clean working tree.'}\n\nRecent commits:\n${log?.trim() ?? ''}`, fence: '' });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let budget = MAX_DESCRIBING_BYTES;
|
|
88
|
+
// A case-insensitive disk answers README.md and readme.md with one file.
|
|
89
|
+
const read = new Set<string>();
|
|
90
|
+
for (const name of DESCRIBING_FILES) {
|
|
91
|
+
if (budget <= 0) break;
|
|
92
|
+
if (read.has(name.toLowerCase())) continue;
|
|
93
|
+
try {
|
|
94
|
+
const text = await readFile(join(project.path, name), 'utf8');
|
|
95
|
+
read.add(name.toLowerCase());
|
|
96
|
+
const body = text.length > budget ? `${text.slice(0, budget)}\n… (cut short)` : text;
|
|
97
|
+
budget -= body.length;
|
|
98
|
+
sections.push({ title: name, body, fence: name.endsWith('.md') || name === 'README' ? undefined : '' });
|
|
99
|
+
} catch {
|
|
100
|
+
// Not every project has every file.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
documents: [buildContextDocument({
|
|
106
|
+
kind: 'project',
|
|
107
|
+
label: project.name,
|
|
108
|
+
detail: project.path,
|
|
109
|
+
facts: [['Path', project.path], ['Branch', branch ?? null]],
|
|
110
|
+
sections
|
|
111
|
+
})]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The machine around the project: which ports are listening (and who holds
|
|
3
|
+
* them), and the project's environment files.
|
|
4
|
+
*
|
|
5
|
+
* A port is the usual question when a dev server will not start ("address
|
|
6
|
+
* already in use") or a request goes nowhere. An environment file is attached
|
|
7
|
+
* by its variable names; the values are masked — they are usually secrets,
|
|
8
|
+
* and what the model needs is which ones exist — except in templates like
|
|
9
|
+
* `.env.example`, which exist to be read.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFile } from 'fs/promises';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import type { MentionCandidate } from '$shared/types/mentions';
|
|
15
|
+
import type { PortEntry } from '$shared/types/ports';
|
|
16
|
+
import { LOCAL_PORT_HOST } from '$shared/types/ports';
|
|
17
|
+
import { buildContextDocument } from '$shared/utils/context-document';
|
|
18
|
+
import { portMonitor } from '$backend/ports/monitor';
|
|
19
|
+
import { listEnvFileEntries, parseDotenv } from '$backend/env-files';
|
|
20
|
+
import { ago, rank, within } from '../shared';
|
|
21
|
+
import { refOptional, refString, type MentionContext, type MentionSource } from '../types';
|
|
22
|
+
|
|
23
|
+
const PORTS = 'ports';
|
|
24
|
+
const ENV = 'env';
|
|
25
|
+
|
|
26
|
+
function portLabel(entry: PortEntry): string {
|
|
27
|
+
return `:${entry.port}${entry.origin.label ? ` · ${entry.origin.label}` : ''}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function processLine(entry: PortEntry): string {
|
|
31
|
+
return entry.process?.command ? entry.process.command.split(/\s+/).slice(0, 4).join(' ') : entry.pid ? `pid ${entry.pid}` : 'unknown process';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function describePort(entry: PortEntry): string[] {
|
|
35
|
+
return [
|
|
36
|
+
`Port ${entry.port}/${entry.protocol} on ${entry.addresses.join(', ') || '*'}`,
|
|
37
|
+
` Owner: ${entry.origin.label}${entry.origin.detail ? ` — ${entry.origin.detail}` : ''} (${entry.origin.kind}, ${entry.origin.confidence})`,
|
|
38
|
+
` Process: ${entry.process?.command ?? 'unknown'}${entry.pid ? ` (pid ${entry.pid})` : ''}`,
|
|
39
|
+
...(entry.process?.cwd ? [` Working directory: ${entry.process.cwd}`] : []),
|
|
40
|
+
...(entry.process?.startedAt ? [` Started: ${entry.process.startedAt} (${ago(entry.process.startedAt)})`] : []),
|
|
41
|
+
...(entry.workerPids.length > 1 ? [` Workers: ${entry.workerPids.join(', ')}`] : []),
|
|
42
|
+
` Connections: ${entry.peerCount}`,
|
|
43
|
+
...(entry.publicUrl ? [` Public URL: ${entry.publicUrl}`] : [])
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function scanPorts(): Promise<PortEntry[]> {
|
|
48
|
+
const scan = await within(portMonitor.scanOnce(LOCAL_PORT_HOST), 15_000, null);
|
|
49
|
+
return [...(scan?.entries ?? [])].sort((a, b) => a.port - b.port);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `KEY=value` with the value masked, unless the file is a template. */
|
|
53
|
+
function maskedLine(key: string, value: string, template: boolean): string {
|
|
54
|
+
if (template) return `${key}=${value}`;
|
|
55
|
+
if (!value) return `${key}= (empty)`;
|
|
56
|
+
return `${key}=•••• (set, ${value.length} chars)`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const systemSource: MentionSource = {
|
|
60
|
+
kinds: ['port', 'env-file'],
|
|
61
|
+
|
|
62
|
+
categories: () => [
|
|
63
|
+
{ id: PORTS, label: 'Ports', detail: 'What is listening on this machine', icon: 'lucide:ethernet-port', group: 'Ops' },
|
|
64
|
+
{ id: ENV, label: 'Environment files', detail: 'Variable names from .env files', icon: 'lucide:key-round', group: 'Workspace' }
|
|
65
|
+
],
|
|
66
|
+
|
|
67
|
+
async list(ctx: MentionContext, request) {
|
|
68
|
+
if (request.category === PORTS) {
|
|
69
|
+
const entries = await scanPorts();
|
|
70
|
+
const all: MentionCandidate = {
|
|
71
|
+
key: 'port:all', kind: 'port', group: 'Ports', label: 'All listening ports',
|
|
72
|
+
detail: `${entries.length} ${entries.length === 1 ? 'port' : 'ports'} on this machine`, icon: 'lucide:ethernet-port', ref: { all: true }
|
|
73
|
+
};
|
|
74
|
+
const rows = entries.map((entry): MentionCandidate => ({
|
|
75
|
+
key: `port:${entry.key}`, kind: 'port', group: 'Ports', label: portLabel(entry), detail: processLine(entry),
|
|
76
|
+
icon: 'lucide:ethernet-port', ref: { port: entry.port }
|
|
77
|
+
}));
|
|
78
|
+
return [...(request.query.trim() ? [] : [all]), ...rank(rows, request.query, (row) => [row.label, row.detail, String(row.ref.port)], request.limit)];
|
|
79
|
+
}
|
|
80
|
+
if (request.category === ENV) {
|
|
81
|
+
const files = await listEnvFileEntries(ctx.root);
|
|
82
|
+
const rows = files.map((file): MentionCandidate => ({
|
|
83
|
+
key: `env-file:${file.name}`, kind: 'env-file', group: 'Environment files', label: file.name,
|
|
84
|
+
detail: file.isTemplate ? 'Template · values included' : 'Values masked', icon: 'lucide:key-round', ref: { name: file.name }
|
|
85
|
+
}));
|
|
86
|
+
return rank(rows, request.query, (row) => [row.label], request.limit);
|
|
87
|
+
}
|
|
88
|
+
// Typing ":3000" at the root finds what holds that port. The colon is
|
|
89
|
+
// required: "@3" names an attachment, and scanning on it would be waste.
|
|
90
|
+
const typed = /^:(\d{2,5})$/.exec(request.query.trim());
|
|
91
|
+
if (!request.category && typed) {
|
|
92
|
+
const entry = (await scanPorts()).find((candidate) => candidate.port === Number(typed[1]));
|
|
93
|
+
if (entry) {
|
|
94
|
+
return [{ key: `port:${entry.key}`, kind: 'port', group: 'Ports', label: portLabel(entry), detail: processLine(entry), icon: 'lucide:ethernet-port', ref: { port: entry.port } }];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
async capture(ctx, kind, ref) {
|
|
101
|
+
if (kind === 'env-file') {
|
|
102
|
+
const name = refString(ref, 'name');
|
|
103
|
+
const entry = (await listEnvFileEntries(ctx.root)).find((file) => file.name === name);
|
|
104
|
+
if (!entry) throw new Error(`${name} is not an environment file of this project`);
|
|
105
|
+
const assignments = parseDotenv(await readFile(join(ctx.root, entry.name), 'utf8')).filter((assignment) => !assignment.commented);
|
|
106
|
+
const body = assignments.map((assignment) => maskedLine(assignment.key, assignment.value, entry.isTemplate)).join('\n');
|
|
107
|
+
return {
|
|
108
|
+
documents: [buildContextDocument({
|
|
109
|
+
kind, label: entry.name, detail: `${assignments.length} variables${entry.isTemplate ? '' : ', values masked'}`,
|
|
110
|
+
facts: [['File', entry.name], ['Values', entry.isTemplate ? 'included (template)' : 'masked: they are usually secrets']],
|
|
111
|
+
sections: [{ title: 'Variables', body: body || '(none)', fence: 'dotenv' }]
|
|
112
|
+
})]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const entries = await scanPorts();
|
|
117
|
+
if (ref.all) {
|
|
118
|
+
return {
|
|
119
|
+
documents: [buildContextDocument({
|
|
120
|
+
kind, label: 'All listening ports', detail: `${entries.length} ports`,
|
|
121
|
+
sections: [{ title: 'Ports', body: entries.map((entry) => describePort(entry).join('\n')).join('\n\n') || 'Nothing is listening.', fence: 'text' }]
|
|
122
|
+
})]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const port = Number(ref.port ?? refOptional(ref, 'port'));
|
|
126
|
+
const held = entries.filter((entry) => entry.port === port);
|
|
127
|
+
if (held.length === 0) throw new Error(`Nothing is listening on port ${port} any more`);
|
|
128
|
+
return {
|
|
129
|
+
documents: [buildContextDocument({
|
|
130
|
+
kind, label: `:${port}`, detail: held.map((entry) => entry.origin.label).join(', '),
|
|
131
|
+
sections: [{ title: 'Listener', body: held.map((entry) => describePort(entry).join('\n')).join('\n\n'), fence: 'text' }]
|
|
132
|
+
})]
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A terminal tab's output.
|
|
3
|
+
*
|
|
4
|
+
* The tabs are listed by the composer, which knows their names; the output is
|
|
5
|
+
* read here, from the scrollback PtyKit keeps for every session — so a tab
|
|
6
|
+
* whose panel is closed can still be mentioned.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ptyKitManager } from '$backend/terminal/ptykit';
|
|
10
|
+
import { scopeProjectId } from '$shared/utils/workspace-scope';
|
|
11
|
+
import { buildContextDocument, countLines } from '$shared/utils/context-document';
|
|
12
|
+
import { stripAnsi } from '../shared';
|
|
13
|
+
import { refOptional, refString, type MentionSource } from '../types';
|
|
14
|
+
|
|
15
|
+
/** The scrollback as plain lines, without the blank screen below the prompt. */
|
|
16
|
+
export function terminalText(serialized: string): string {
|
|
17
|
+
const text = stripAnsi(serialized).replace(/\r\n?/g, '\n');
|
|
18
|
+
return text.replace(/[ \t]+$/gm, '').replace(/\n{3,}/g, '\n\n').replace(/\s+$/, '');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const terminalSource: MentionSource = {
|
|
22
|
+
kinds: ['terminal'],
|
|
23
|
+
categories: () => [],
|
|
24
|
+
list: async () => [],
|
|
25
|
+
|
|
26
|
+
async capture(ctx, _kind, ref) {
|
|
27
|
+
const sessionId = refString(ref, 'sessionId');
|
|
28
|
+
const session = ptyKitManager.getSession(sessionId);
|
|
29
|
+
if (!session || scopeProjectId(session.namespace) !== ctx.projectId) {
|
|
30
|
+
throw new Error('That terminal is no longer open');
|
|
31
|
+
}
|
|
32
|
+
const name = refOptional(ref, 'name') ?? 'Terminal';
|
|
33
|
+
const output = terminalText(ptyKitManager.getSerializedState(sessionId));
|
|
34
|
+
return {
|
|
35
|
+
documents: [
|
|
36
|
+
buildContextDocument({
|
|
37
|
+
kind: 'terminal',
|
|
38
|
+
label: name,
|
|
39
|
+
detail: countLines(output),
|
|
40
|
+
facts: [
|
|
41
|
+
['Working directory', session.cwd],
|
|
42
|
+
['Status', session.status === 'exited' ? `exited (${session.exitCode ?? '?'})` : 'running'],
|
|
43
|
+
['Size', `${session.cols}×${session.rows}`]
|
|
44
|
+
],
|
|
45
|
+
sections: [{ title: 'Output', body: output, fence: 'text' }]
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every `@` mention source provides.
|
|
3
|
+
*
|
|
4
|
+
* A source lists what it can mention and takes the snapshot of what was
|
|
5
|
+
* picked. Sources never touch the composer or the prompt: what they return is
|
|
6
|
+
* a context document (shared/utils/context-document.ts), and from there it is
|
|
7
|
+
* an attachment like any other.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
11
|
+
import type { IconName } from '$shared/types/ui/icons';
|
|
12
|
+
import type { CapturedAttachment, ContextKind, MentionCandidate, MentionRef } from '$shared/types/mentions';
|
|
13
|
+
import type { ContextDocument } from '$shared/utils/context-document';
|
|
14
|
+
|
|
15
|
+
export interface MentionContext {
|
|
16
|
+
conn: WSConnection;
|
|
17
|
+
projectId: string;
|
|
18
|
+
/** The project's own directory. */
|
|
19
|
+
projectPath: string;
|
|
20
|
+
/** Root of the workspace on screen — the project, or one of its worktrees. */
|
|
21
|
+
root: string;
|
|
22
|
+
/** The chat the composer belongs to, when there is one. */
|
|
23
|
+
chatSessionId: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A list the picker can open: "Terminals", "Commits", one database. */
|
|
27
|
+
export interface MentionCategory {
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
/** Every row has one, so the list reads evenly. */
|
|
31
|
+
detail: string;
|
|
32
|
+
icon: IconName;
|
|
33
|
+
group: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ListRequest {
|
|
37
|
+
/** The category asked for; absent at the picker's root. */
|
|
38
|
+
category?: string;
|
|
39
|
+
/** What was typed after `@`; may be empty. */
|
|
40
|
+
query: string;
|
|
41
|
+
limit: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A snapshot: one or more documents, and the pictures that go with them. */
|
|
45
|
+
export interface MentionCapture {
|
|
46
|
+
documents: ContextDocument[];
|
|
47
|
+
images?: CapturedAttachment[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface MentionSource {
|
|
51
|
+
/** Kinds this source captures. */
|
|
52
|
+
kinds: ContextKind[];
|
|
53
|
+
/** The lists it offers at the picker's root. */
|
|
54
|
+
categories(ctx: MentionContext): MentionCategory[] | Promise<MentionCategory[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Rows for a request. At the root (no category) only cheap, local lookups
|
|
57
|
+
* belong here — every source answers each keystroke. A category this source
|
|
58
|
+
* does not own answers nothing.
|
|
59
|
+
*/
|
|
60
|
+
list(ctx: MentionContext, request: ListRequest): Promise<MentionCandidate[]>;
|
|
61
|
+
capture(ctx: MentionContext, kind: ContextKind, ref: MentionRef): Promise<MentionCapture>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A ref field as a string, or an error naming it. */
|
|
65
|
+
export function refString(ref: MentionRef, key: string): string {
|
|
66
|
+
const value = ref[key];
|
|
67
|
+
if (typeof value !== 'string' || !value) throw new Error(`Missing ${key}`);
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A ref field as a string when it is one. */
|
|
72
|
+
export function refOptional(ref: MentionRef, key: string): string | undefined {
|
|
73
|
+
const value = ref[key];
|
|
74
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
75
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { outsideBotChecks } from './bot-check-frames';
|
|
3
|
+
|
|
4
|
+
/** Run the generated source the way a frame would, and report whether the script ran. */
|
|
5
|
+
function runsIn(href: string, ancestors: string[] = []): boolean {
|
|
6
|
+
const url = new URL(href);
|
|
7
|
+
const location = {
|
|
8
|
+
hostname: url.hostname,
|
|
9
|
+
pathname: url.pathname,
|
|
10
|
+
ancestorOrigins: ancestors
|
|
11
|
+
};
|
|
12
|
+
const source = outsideBotChecks(function (flag: string) {
|
|
13
|
+
(globalThis as unknown as Record<string, boolean>)[flag] = true;
|
|
14
|
+
}, '__botCheckProbe');
|
|
15
|
+
const globals = globalThis as unknown as Record<string, boolean>;
|
|
16
|
+
delete globals.__botCheckProbe;
|
|
17
|
+
new Function('location', source)(location);
|
|
18
|
+
const ran = globals.__botCheckProbe === true;
|
|
19
|
+
delete globals.__botCheckProbe;
|
|
20
|
+
return ran;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('outsideBotChecks', () => {
|
|
24
|
+
test('runs in ordinary pages and embeds', () => {
|
|
25
|
+
expect(runsIn('https://example.com/')).toBe(true);
|
|
26
|
+
expect(runsIn('https://www.youtube.com/embed/x', ['https://example.com'])).toBe(true);
|
|
27
|
+
expect(runsIn('https://www.google.com/maps/embed?pb=1', ['https://example.com'])).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('skips a challenge widget frame', () => {
|
|
31
|
+
expect(runsIn('https://challenges.cloudflare.com/cdn-cgi/challenge-platform/h/b/turnstile/if/ov2')).toBe(false);
|
|
32
|
+
expect(runsIn('https://newassets.hcaptcha.com/captcha/v1/static/hcaptcha.html')).toBe(false);
|
|
33
|
+
expect(runsIn('https://www.google.com/recaptcha/api2/anchor?k=1')).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('skips frames nested inside a challenge widget', () => {
|
|
37
|
+
expect(runsIn('https://example.com/', ['https://challenges.cloudflare.com', 'https://example.com'])).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('a path-scoped host does not make its whole origin a bot check', () => {
|
|
41
|
+
// An ancestor only exposes its origin, and www.google.com serves far more than reCAPTCHA.
|
|
42
|
+
expect(runsIn('https://example.com/', ['https://www.google.com'])).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('passes the script its arguments', () => {
|
|
46
|
+
const source = outsideBotChecks((a: number, b: { c: string }) => a + b.c.length, 1, { c: 'xy' });
|
|
47
|
+
expect(source).toContain('(1, {"c":"xy"})');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frames that belong to a bot check, and keeping Clopen's scripts out of them.
|
|
3
|
+
*
|
|
4
|
+
* The preview injects scripts into every frame on each new document: the host
|
|
5
|
+
* bridge (device APIs answered by the viewer) and the audio tap. A challenge
|
|
6
|
+
* widget — Cloudflare's "Verify you are human", hCaptcha, reCAPTCHA — runs in
|
|
7
|
+
* its own iframe and inspects that frame's APIs. Finding them replaced, it
|
|
8
|
+
* fails the check, and on a challenge page the user ticks the box only to land
|
|
9
|
+
* back on the same page, forever. Nobody needs a camera or an audio tap inside
|
|
10
|
+
* a captcha, so those frames are simply left alone.
|
|
11
|
+
*
|
|
12
|
+
* A frame counts when it, or any frame above it, is served from one of these
|
|
13
|
+
* hosts: challenge widgets nest `about:blank` frames of their own, which take
|
|
14
|
+
* the widget's origin as an ancestor rather than as their own.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface BotCheckFrame {
|
|
18
|
+
host: string;
|
|
19
|
+
/** Only frames under this path, for hosts that serve more than the check. */
|
|
20
|
+
path?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BOT_CHECK_FRAMES: BotCheckFrame[] = [
|
|
24
|
+
{ host: 'challenges.cloudflare.com' },
|
|
25
|
+
{ host: 'hcaptcha.com' },
|
|
26
|
+
{ host: 'www.google.com', path: '/recaptcha/' },
|
|
27
|
+
{ host: 'www.recaptcha.net', path: '/recaptcha/' },
|
|
28
|
+
{ host: 'arkoselabs.com' },
|
|
29
|
+
{ host: 'captcha-delivery.com' }
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/** Runs in the page, so it carries everything it needs. */
|
|
33
|
+
function insideBotCheck(frames: BotCheckFrame[]): boolean {
|
|
34
|
+
const matches = (host: string, path: string | null) =>
|
|
35
|
+
frames.some((frame) => {
|
|
36
|
+
const hostMatches = host === frame.host || host.endsWith(`.${frame.host}`);
|
|
37
|
+
if (!hostMatches) return false;
|
|
38
|
+
// An ancestor only gives its origin; a path-scoped host counts for the frame itself only.
|
|
39
|
+
return !frame.path || (path !== null && path.startsWith(frame.path));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (matches(location.hostname, location.pathname)) return true;
|
|
43
|
+
|
|
44
|
+
const ancestors = Array.from(location.ancestorOrigins ?? []);
|
|
45
|
+
return ancestors.some((origin) => {
|
|
46
|
+
try {
|
|
47
|
+
return matches(new URL(origin).hostname, null);
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Source for `evaluateOnNewDocument` that runs `script(...args)` in every frame
|
|
56
|
+
* except those of a bot check.
|
|
57
|
+
*/
|
|
58
|
+
export function outsideBotChecks<Args extends unknown[]>(
|
|
59
|
+
script: (...args: Args) => unknown,
|
|
60
|
+
...args: Args
|
|
61
|
+
): string {
|
|
62
|
+
const serializedArgs = args.map((arg) => JSON.stringify(arg) ?? 'undefined').join(', ');
|
|
63
|
+
return `if (!(${insideBotCheck.toString()})(${JSON.stringify(BOT_CHECK_FRAMES)})) {
|
|
64
|
+
(${script.toString()})(${serializedArgs});
|
|
65
|
+
}`;
|
|
66
|
+
}
|