@myrialabs/clopen 0.4.47 → 0.4.49
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 +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/message-pages.test.ts +163 -0
- package/backend/chat/message-pages.ts +233 -0
- package/backend/chat/stream-manager.ts +91 -67
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/blob-line-stats-queries.ts +48 -0
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +15 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/env/diff.ts +9 -33
- package/backend/db-client/env/env.test.ts +8 -8
- package/backend/db-client/env/service.ts +1 -1
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/file-watcher.ts +19 -0
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/contributors.test.ts +35 -0
- package/backend/git/contributors.ts +46 -0
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/http/static-assets.test.ts +78 -0
- package/backend/http/static-assets.ts +104 -0
- package/backend/index.ts +32 -16
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +383 -29
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/blob-store.ts +9 -1
- package/backend/snapshot/helpers.ts +3 -11
- package/backend/snapshot/line-stats.test.ts +80 -0
- package/backend/snapshot/line-stats.ts +64 -0
- package/backend/snapshot/restore.ts +252 -0
- package/backend/snapshot/snapshot-service.ts +14 -27
- package/backend/snapshot/turn-changes.test.ts +10 -5
- package/backend/snapshot/turn-changes.ts +78 -40
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +10 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws-wire.test.ts +87 -0
- package/backend/utils/ws-wire.ts +189 -0
- package/backend/utils/ws.ts +101 -192
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +105 -57
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +45 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/log.ts +52 -0
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +78 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +29 -0
- package/backend/ws/preview/watchers.ts +84 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +42 -57
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +12 -13
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/terminal/tunnel.ts +2 -2
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +46 -41
- package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
- package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
- package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/{index-CwuKQelV.js → index-CrVWZH_D.js} +1 -1
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/{index-BTcR1byF.js → index-DD0-3EWg.js} +1 -1
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +1240 -0
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +1 -0
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
- package/dist/fonts/dm-sans.css.br +0 -0
- package/dist/fonts/dm-sans.css.gz +0 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/sw.js.br +0 -0
- package/dist/sw.js.gz +0 -0
- package/package.json +3 -3
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +13 -5
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/diff-calculator.test.ts +178 -41
- package/shared/utils/diff-calculator.ts +383 -100
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/process-supervisor.test.ts +172 -0
- package/shared/utils/process-supervisor.ts +251 -0
- package/shared/utils/ws-chunk.test.ts +33 -0
- package/shared/utils/ws-chunk.ts +73 -0
- package/shared/utils/ws-client-chunks.test.ts +45 -0
- package/shared/utils/ws-client.ts +43 -0
- package/shared/utils/ws-server.ts +49 -21
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
package/backend/memory/redact.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* keys, an `.env` a tool printed, an Authorization header inside a failed
|
|
6
6
|
* request. Memory is the worst possible place for those to land, because unlike
|
|
7
7
|
* a chat message a memory is durable, is re-injected into EVERY future turn on
|
|
8
|
-
* EVERY engine, and is readable
|
|
8
|
+
* EVERY engine, and is readable from every device. A secret that
|
|
9
9
|
* reaches a message is exposed once; a secret that reaches the graph is exposed
|
|
10
10
|
* continuously.
|
|
11
11
|
*
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Tests for the note collection access rule.
|
|
3
3
|
*
|
|
4
4
|
* This one function decides who can read notes and who can read the image bytes
|
|
5
|
-
* behind them
|
|
6
|
-
* stay deliberate: it grants every signed-in account, so a regression that
|
|
7
|
-
* quietly widened the project case into it would be invisible in the UI.
|
|
5
|
+
* behind them, so both answers have to stay in step.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
|
|
@@ -16,47 +14,51 @@ import { noteCollectionQueries } from '../database/queries/note-queries';
|
|
|
16
14
|
import { canAccessCollection } from './access';
|
|
17
15
|
import type { NoteCollection } from '$shared/types/database/schema';
|
|
18
16
|
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let projectId: string;
|
|
17
|
+
let listedId: string;
|
|
18
|
+
let removedId: string;
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
outsiderId = randomUUID();
|
|
27
|
-
projectId = projectQueries.create({
|
|
28
|
-
name: 'notes-access-test',
|
|
20
|
+
function createProject(name: string): string {
|
|
21
|
+
return projectQueries.create({
|
|
22
|
+
name,
|
|
29
23
|
// `projects.path` is unique, so a fixed path collides with whatever an
|
|
30
24
|
// earlier run left behind in the test data dir.
|
|
31
|
-
path: `/tmp
|
|
25
|
+
path: `/tmp/${name}-${randomUUID()}`,
|
|
32
26
|
created_at: new Date().toISOString(),
|
|
33
27
|
last_opened_at: new Date().toISOString()
|
|
34
28
|
}).id;
|
|
35
|
-
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
await initializeDatabase();
|
|
33
|
+
listedId = createProject('notes-access-listed');
|
|
34
|
+
projectQueries.list(listedId);
|
|
35
|
+
// Removed from the list (mode 'remove'): the record stays, access does not.
|
|
36
|
+
removedId = createProject('notes-access-removed');
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
afterAll(() => {
|
|
39
|
-
projectQueries.deleteProject(
|
|
40
|
+
projectQueries.deleteProject(listedId);
|
|
41
|
+
projectQueries.deleteProject(removedId);
|
|
40
42
|
closeDatabase();
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
describe('canAccessCollection — project scope', () => {
|
|
44
|
-
it('admits a
|
|
45
|
-
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId });
|
|
46
|
-
expect(canAccessCollection(
|
|
46
|
+
it('admits a collection of a listed project', () => {
|
|
47
|
+
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId: listedId });
|
|
48
|
+
expect(canAccessCollection(collection)).toBe(true);
|
|
47
49
|
noteCollectionQueries.delete(collection.id);
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
it('refuses
|
|
51
|
-
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId });
|
|
52
|
-
expect(canAccessCollection(
|
|
52
|
+
it('refuses a collection of a removed project', () => {
|
|
53
|
+
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId: removedId });
|
|
54
|
+
expect(canAccessCollection(collection)).toBe(false);
|
|
53
55
|
noteCollectionQueries.delete(collection.id);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
it('refuses a project collection with no project rather than admitting
|
|
58
|
+
it('refuses a project collection with no project rather than admitting it', () => {
|
|
57
59
|
// The table's CHECK makes this unreachable through the queries, but a row
|
|
58
60
|
// in this shape must fail closed rather than fall through to the global
|
|
59
|
-
// branch
|
|
61
|
+
// branch.
|
|
60
62
|
const malformed = {
|
|
61
63
|
id: 'x',
|
|
62
64
|
name: 'Malformed',
|
|
@@ -66,17 +68,14 @@ describe('canAccessCollection — project scope', () => {
|
|
|
66
68
|
created_at: '',
|
|
67
69
|
updated_at: ''
|
|
68
70
|
} as NoteCollection;
|
|
69
|
-
expect(canAccessCollection(
|
|
71
|
+
expect(canAccessCollection(malformed)).toBe(false);
|
|
70
72
|
});
|
|
71
73
|
});
|
|
72
74
|
|
|
73
75
|
describe('canAccessCollection — global scope', () => {
|
|
74
|
-
it('admits
|
|
75
|
-
// Deliberate: a global collection has no per-note ACL, so everything in it
|
|
76
|
-
// is readable by every account that can sign in.
|
|
76
|
+
it('admits a global collection', () => {
|
|
77
77
|
const collection = noteCollectionQueries.create({ name: 'G', scope: 'global' });
|
|
78
|
-
expect(canAccessCollection(
|
|
79
|
-
expect(canAccessCollection(outsiderId, collection)).toBe(true);
|
|
78
|
+
expect(canAccessCollection(collection)).toBe(true);
|
|
80
79
|
noteCollectionQueries.delete(collection.id);
|
|
81
80
|
});
|
|
82
81
|
});
|
package/backend/notes/access.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Whether a note collection can be reached.
|
|
3
3
|
*
|
|
4
4
|
* The rule lives here rather than in each route because three call sites need
|
|
5
5
|
* to agree on it — the WebSocket handlers, the image upload, and the image
|
|
@@ -11,17 +11,12 @@ import type { NoteCollection } from '$shared/types/database/schema';
|
|
|
11
11
|
import { projectQueries } from '../database/queries/project-queries';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `
|
|
17
|
-
* project-scoped API uses.
|
|
18
|
-
* - `global` — every signed-in user on this instance. Global collections are
|
|
19
|
-
* deliberately instance-wide: there is no per-note ACL, so anything put in
|
|
20
|
-
* one is readable by every account that can sign in, including members of
|
|
21
|
-
* unrelated projects.
|
|
14
|
+
* - `project` — reachable while its project is in the workspace list, the same
|
|
15
|
+
* check the rest of the project-scoped API uses.
|
|
16
|
+
* - `global` — always reachable.
|
|
22
17
|
*/
|
|
23
|
-
export function canAccessCollection(
|
|
18
|
+
export function canAccessCollection(collection: NoteCollection): boolean {
|
|
24
19
|
if (collection.scope === 'global') return true;
|
|
25
20
|
if (!collection.project_id) return false;
|
|
26
|
-
return projectQueries.
|
|
21
|
+
return projectQueries.isListed(collection.project_id);
|
|
27
22
|
}
|
|
@@ -95,7 +95,7 @@ export interface PermissionInventory {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export const permissionService = {
|
|
98
|
-
/** All stored global/project permission sets for the
|
|
98
|
+
/** All stored global/project permission sets for the Settings listing. Profile
|
|
99
99
|
* overlays are excluded — they are managed in the profile editor. */
|
|
100
100
|
list(projectId?: string): PermissionSetDTO[] {
|
|
101
101
|
const rows = projectId
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workspace clipboard's one job besides holding text: telling the user's
|
|
3
|
+
* devices about copies they did not make, and never echoing theirs back.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import { WorkspaceClipboard, type ClipboardChange } from './browser-clipboard';
|
|
8
|
+
|
|
9
|
+
function watch(clipboard: WorkspaceClipboard): ClipboardChange[] {
|
|
10
|
+
const changes: ClipboardChange[] = [];
|
|
11
|
+
clipboard.on('changed', (change: ClipboardChange) => changes.push(change));
|
|
12
|
+
return changes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('WorkspaceClipboard', () => {
|
|
16
|
+
test('a page copy is held and announced to the devices', () => {
|
|
17
|
+
const clipboard = new WorkspaceClipboard();
|
|
18
|
+
const changes = watch(clipboard);
|
|
19
|
+
|
|
20
|
+
clipboard.write('TOKEN', 'page');
|
|
21
|
+
|
|
22
|
+
expect(clipboard.read()).toBe('TOKEN');
|
|
23
|
+
expect(changes.map((change) => [change.text, change.source])).toEqual([['TOKEN', 'page']]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('a copy from the device is held but not sent back to it', () => {
|
|
27
|
+
const clipboard = new WorkspaceClipboard();
|
|
28
|
+
const changes = watch(clipboard);
|
|
29
|
+
|
|
30
|
+
clipboard.write('from my laptop', 'device');
|
|
31
|
+
|
|
32
|
+
expect(clipboard.read()).toBe('from my laptop');
|
|
33
|
+
expect(changes).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('writing the same text again announces nothing', () => {
|
|
37
|
+
const clipboard = new WorkspaceClipboard();
|
|
38
|
+
const changes = watch(clipboard);
|
|
39
|
+
|
|
40
|
+
clipboard.write('same', 'agent');
|
|
41
|
+
clipboard.write('same', 'page');
|
|
42
|
+
|
|
43
|
+
expect(changes).toHaveLength(1);
|
|
44
|
+
expect(clipboard.describe().source).toBe('page');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace clipboard.
|
|
3
|
+
*
|
|
4
|
+
* One clipboard per workspace, shared by its tabs, its agent and the user's
|
|
5
|
+
* devices — the single source of truth for "what was copied last".
|
|
6
|
+
*
|
|
7
|
+
* There used to be three clipboards that never met: the headless browser's own
|
|
8
|
+
* (which a page's `execCommand('copy')` filled and nobody could read), the
|
|
9
|
+
* viewer's device (where `navigator.clipboard.writeText` was relayed, and which
|
|
10
|
+
* an agent cannot see), and none at all for the agent. So an agent clicking a
|
|
11
|
+
* page's "Copy" button and pasting the result elsewhere got nothing, and a
|
|
12
|
+
* paste chord pasted from the empty headless clipboard.
|
|
13
|
+
*
|
|
14
|
+
* Every copy now lands here — from a page (copy event, `writeText`), from the
|
|
15
|
+
* agent, from the context menu, or from the user's device — and every paste
|
|
16
|
+
* reads from here. Anything not copied *by the device* is pushed back down to
|
|
17
|
+
* the user's devices, which is what keeps the two in step.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
21
|
+
|
|
22
|
+
export type ClipboardSource = 'page' | 'agent' | 'menu' | 'device';
|
|
23
|
+
|
|
24
|
+
export interface ClipboardChange {
|
|
25
|
+
text: string;
|
|
26
|
+
source: ClipboardSource;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Above this, a copy is kept but no longer mirrored over the socket. */
|
|
31
|
+
const MAX_SYNCED_CHARS = 1_000_000;
|
|
32
|
+
|
|
33
|
+
export class WorkspaceClipboard extends EventEmitter {
|
|
34
|
+
private text = '';
|
|
35
|
+
private source: ClipboardSource | null = null;
|
|
36
|
+
private updatedAt = 0;
|
|
37
|
+
|
|
38
|
+
read(): string {
|
|
39
|
+
return this.text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Who wrote the current content and when — for the stats panel. */
|
|
43
|
+
describe(): { length: number; source: ClipboardSource | null; updatedAt: number } {
|
|
44
|
+
return { length: this.text.length, source: this.source, updatedAt: this.updatedAt };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Replace the content. Emits `changed` when the text actually differs, so a
|
|
49
|
+
* device echoing back what it was just sent does not ping-pong.
|
|
50
|
+
*/
|
|
51
|
+
write(text: string, source: ClipboardSource): void {
|
|
52
|
+
const value = String(text ?? '');
|
|
53
|
+
if (value === this.text) {
|
|
54
|
+
this.source = source;
|
|
55
|
+
this.updatedAt = Date.now();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.text = value;
|
|
60
|
+
this.source = source;
|
|
61
|
+
this.updatedAt = Date.now();
|
|
62
|
+
|
|
63
|
+
if (source !== 'device' && value.length <= MAX_SYNCED_CHARS) {
|
|
64
|
+
this.emit('changed', { text: value, source, timestamp: this.updatedAt } satisfies ClipboardChange);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -22,13 +22,87 @@ import { nanoid } from 'nanoid';
|
|
|
22
22
|
*/
|
|
23
23
|
const DIALOG_RESPONSE_TIMEOUT_MS = 120_000;
|
|
24
24
|
|
|
25
|
+
/** A dialog the page is blocked on, as an agent is told about it. */
|
|
26
|
+
export interface PendingDialogInfo {
|
|
27
|
+
dialogId: string;
|
|
28
|
+
type: 'alert' | 'confirm' | 'prompt' | 'beforeunload';
|
|
29
|
+
message: string;
|
|
30
|
+
defaultValue: string;
|
|
31
|
+
openedAt: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DialogHandlerDeps {
|
|
35
|
+
/**
|
|
36
|
+
* Whether an agent holds the tab. Its dialogs are the agent's to answer,
|
|
37
|
+
* exactly as a person's would be theirs, so the unattended-page timeout
|
|
38
|
+
* that dismisses them on nobody's behalf does not apply.
|
|
39
|
+
*/
|
|
40
|
+
isAgentHeld(tabId: string): boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
export class BrowserDialogHandler extends EventEmitter {
|
|
26
44
|
// Store pending dialogs waiting for response, tagged with the tab that raised
|
|
27
45
|
// them so closing one tab cannot dismiss another tab's prompt.
|
|
28
|
-
private pendingDialogs = new Map<
|
|
46
|
+
private pendingDialogs = new Map<
|
|
47
|
+
string,
|
|
48
|
+
{ sessionId: string; dialog: Dialog; timeout: NodeJS.Timeout; info: PendingDialogInfo }
|
|
49
|
+
>();
|
|
29
50
|
|
|
30
|
-
|
|
51
|
+
private deps: DialogHandlerDeps;
|
|
52
|
+
|
|
53
|
+
constructor(deps: DialogHandlerDeps = { isAgentHeld: () => false }) {
|
|
31
54
|
super();
|
|
55
|
+
this.deps = deps;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The dialog a tab is blocked on, if any.
|
|
60
|
+
*
|
|
61
|
+
* A page with an open dialog runs no script and paints nothing, so every
|
|
62
|
+
* read, screenshot or evaluate against it hangs until someone answers. An
|
|
63
|
+
* agent asks this before acting instead of finding out by waiting.
|
|
64
|
+
*/
|
|
65
|
+
getPendingDialog(tabId: string): PendingDialogInfo | null {
|
|
66
|
+
let latest: PendingDialogInfo | null = null;
|
|
67
|
+
for (const entry of this.pendingDialogs.values()) {
|
|
68
|
+
if (entry.sessionId !== tabId) continue;
|
|
69
|
+
if (!latest || entry.info.openedAt >= latest.openedAt) latest = entry.info;
|
|
70
|
+
}
|
|
71
|
+
return latest;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolve when the tab raises a dialog — for racing an action against it.
|
|
76
|
+
* `dispose` must be called once the race is decided either way.
|
|
77
|
+
*/
|
|
78
|
+
waitForDialog(tabId: string): { promise: Promise<PendingDialogInfo>; dispose: () => void } {
|
|
79
|
+
let listener: ((event: { sessionId: string; dialogId: string }) => void) | null = null;
|
|
80
|
+
const promise = new Promise<PendingDialogInfo>((resolve) => {
|
|
81
|
+
listener = (event) => {
|
|
82
|
+
if (event.sessionId !== tabId) return;
|
|
83
|
+
const info = this.pendingDialogs.get(event.dialogId)?.info;
|
|
84
|
+
if (info) resolve(info);
|
|
85
|
+
};
|
|
86
|
+
this.on('dialog', listener);
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
promise,
|
|
90
|
+
dispose: () => {
|
|
91
|
+
if (listener) this.off('dialog', listener);
|
|
92
|
+
listener = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Answer whatever dialog a tab has open — the agent's way in, which names
|
|
99
|
+
* the tab rather than a dialog id it never saw.
|
|
100
|
+
*/
|
|
101
|
+
async respondForTab(tabId: string, accept: boolean, promptText?: string): Promise<PendingDialogInfo | null> {
|
|
102
|
+
const info = this.getPendingDialog(tabId);
|
|
103
|
+
if (!info) return null;
|
|
104
|
+
const ok = await this.respondToDialog({ dialogId: info.dialogId, accept, promptText } as BrowserDialogResponse);
|
|
105
|
+
return ok ? info : null;
|
|
32
106
|
}
|
|
33
107
|
|
|
34
108
|
/**
|
|
@@ -73,17 +147,32 @@ export class BrowserDialogHandler extends EventEmitter {
|
|
|
73
147
|
debug.log('preview', `🎭 Dialog detected - Type: ${dialogType}, Session: ${sessionId}`);
|
|
74
148
|
|
|
75
149
|
// Store pending dialog for later response, with a deadline so an
|
|
76
|
-
// unattended page cannot stay blocked indefinitely.
|
|
77
|
-
|
|
150
|
+
// unattended page cannot stay blocked indefinitely. A tab an agent holds
|
|
151
|
+
// is not unattended: the deadline is pushed back for as long as it does.
|
|
152
|
+
const expire = () => {
|
|
153
|
+
const entry = this.pendingDialogs.get(dialogId);
|
|
154
|
+
if (!entry) return;
|
|
155
|
+
if (this.deps.isAgentHeld(sessionId)) {
|
|
156
|
+
entry.timeout = setTimeout(expire, DIALOG_RESPONSE_TIMEOUT_MS);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
78
159
|
this.pendingDialogs.delete(dialogId);
|
|
79
160
|
debug.warn('preview', `⏱️ Dialog ${dialogId} unanswered, auto-dismissing`);
|
|
80
161
|
// beforeunload is the one dialog where dismissing is the safe default
|
|
81
162
|
// in both directions: it cancels the navigation rather than losing work.
|
|
82
163
|
dialog.dismiss().catch(() => {});
|
|
83
164
|
this.emit('dialog-closed', { sessionId, dialogId, timestamp: Date.now() });
|
|
84
|
-
}
|
|
165
|
+
};
|
|
166
|
+
const timeout = setTimeout(expire, DIALOG_RESPONSE_TIMEOUT_MS);
|
|
85
167
|
|
|
86
|
-
|
|
168
|
+
const info: PendingDialogInfo = {
|
|
169
|
+
dialogId,
|
|
170
|
+
type: dialogType as PendingDialogInfo['type'],
|
|
171
|
+
message,
|
|
172
|
+
defaultValue,
|
|
173
|
+
openedAt: Date.now()
|
|
174
|
+
};
|
|
175
|
+
this.pendingDialogs.set(dialogId, { sessionId, dialog, timeout, info });
|
|
87
176
|
|
|
88
177
|
// Emit dialog event to frontend (sessionId will be converted to tabId by previewService)
|
|
89
178
|
const dialogEvent: any = {
|
|
@@ -34,6 +34,9 @@ export type HostRequestKind =
|
|
|
34
34
|
| 'media-devices'
|
|
35
35
|
| 'clipboard-read'
|
|
36
36
|
| 'clipboard-write'
|
|
37
|
+
// Not a capability: the page reporting what a copy event put on the
|
|
38
|
+
// clipboard, so it reaches the workspace clipboard. Answered by the service.
|
|
39
|
+
| 'clipboard-copied'
|
|
37
40
|
| 'notification-permission'
|
|
38
41
|
| 'notification-show'
|
|
39
42
|
| 'speech-start'
|
|
@@ -108,6 +111,7 @@ const REQUEST_TIMEOUT_MS: Record<HostRequestKind, number> = {
|
|
|
108
111
|
'media-devices': 15_000,
|
|
109
112
|
'clipboard-read': 30_000,
|
|
110
113
|
'clipboard-write': 15_000,
|
|
114
|
+
'clipboard-copied': 5_000,
|
|
111
115
|
'notification-permission': 60_000,
|
|
112
116
|
'notification-show': 15_000,
|
|
113
117
|
// Only the handshake is timed; results stream back as events afterwards.
|
|
@@ -304,6 +308,11 @@ export class BrowserHostBridge extends EventEmitter {
|
|
|
304
308
|
|
|
305
309
|
clearTimeout(pending.timeout);
|
|
306
310
|
this.pending.delete(requestId);
|
|
311
|
+
// A read the viewer answered is the device's clipboard as of now — the
|
|
312
|
+
// freshest copy of it the workspace will see.
|
|
313
|
+
if (pending.kind === 'clipboard-read' && response.ok && typeof response.result === 'string') {
|
|
314
|
+
this.emit('clipboard-observed', { tabId: pending.tabId, text: response.result });
|
|
315
|
+
}
|
|
307
316
|
// The page asked once, but the prompt was raised on every device watching
|
|
308
317
|
// this tab. Whoever answered first answered for all of them, so the rest
|
|
309
318
|
// are told to take their copy down.
|