@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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which connections are looking at a Preview right now.
|
|
3
|
+
*
|
|
4
|
+
* Most preview events describe state every device must stay in step with (tabs
|
|
5
|
+
* opened or closed, an agent taking control, a dialog) and still go to the
|
|
6
|
+
* whole project. A few are a panel's live detail and are frequent: every line
|
|
7
|
+
* the previewed page logs, and every step of the agent's cursor. Those only go
|
|
8
|
+
* to connections with a Preview mounted. A panel that mounts later loses
|
|
9
|
+
* nothing: the console is seeded from its history (`preview:browser-console-get`)
|
|
10
|
+
* and the agent's last cursor position is replayed on `preview:watch`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { t } from 'elysia';
|
|
14
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
15
|
+
import { ws } from '$backend/utils/ws';
|
|
16
|
+
import type { WSAPI } from '$backend/ws';
|
|
17
|
+
import { scopeProjectId } from '$shared/utils/workspace-scope';
|
|
18
|
+
|
|
19
|
+
const watching = new Set<string>();
|
|
20
|
+
|
|
21
|
+
/** Last known agent cursor per project and tab, replayed to a new watcher. */
|
|
22
|
+
const lastCursor = new Map<string, Map<string, WSAPI['server']['preview:browser-mcp-cursor-position']>>();
|
|
23
|
+
|
|
24
|
+
/** Send a Preview-detail event to the project's connections that have a Preview open. */
|
|
25
|
+
export function emitToPreviewWatchers<K extends keyof WSAPI['server']>(
|
|
26
|
+
projectId: string,
|
|
27
|
+
event: K,
|
|
28
|
+
payload: WSAPI['server'][K]
|
|
29
|
+
): void {
|
|
30
|
+
ws.emit.projectWhere(projectId, (connectionId) => watching.has(connectionId), event, payload);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Remember where the agent's cursor came to rest on a tab. */
|
|
34
|
+
export function rememberAgentCursor(
|
|
35
|
+
projectId: string,
|
|
36
|
+
cursor: WSAPI['server']['preview:browser-mcp-cursor-position']
|
|
37
|
+
): void {
|
|
38
|
+
let tabs = lastCursor.get(projectId);
|
|
39
|
+
if (!tabs) {
|
|
40
|
+
tabs = new Map();
|
|
41
|
+
lastCursor.set(projectId, tabs);
|
|
42
|
+
}
|
|
43
|
+
tabs.set(cursor.sessionId, cursor);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The agent let go of a tab: there is no cursor to show on it any more. */
|
|
47
|
+
export function forgetAgentCursor(projectId: string, tabId: string): void {
|
|
48
|
+
lastCursor.get(projectId)?.delete(tabId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const previewWatchHandler = createRouter()
|
|
52
|
+
/**
|
|
53
|
+
* A Preview was mounted (`watching: true`) or the last one went away
|
|
54
|
+
* (`false`). Clients send it again after a reconnect.
|
|
55
|
+
*/
|
|
56
|
+
.on('preview:watch', {
|
|
57
|
+
data: t.Object({
|
|
58
|
+
watching: t.Boolean()
|
|
59
|
+
})
|
|
60
|
+
}, ({ conn, data }) => {
|
|
61
|
+
const connectionId = ws.getConnectionId(conn);
|
|
62
|
+
if (!connectionId) return;
|
|
63
|
+
if (!data.watching) {
|
|
64
|
+
watching.delete(connectionId);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!watching.has(connectionId)) {
|
|
68
|
+
watching.add(connectionId);
|
|
69
|
+
ws.addCleanup(conn, () => watching.delete(connectionId));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let projectId: string;
|
|
73
|
+
try {
|
|
74
|
+
projectId = scopeProjectId(ws.getProjectId(conn));
|
|
75
|
+
} catch {
|
|
76
|
+
return; // No project yet — nothing to replay.
|
|
77
|
+
}
|
|
78
|
+
for (const cursor of lastCursor.get(projectId)?.values() ?? []) {
|
|
79
|
+
ws.sendToConnectionId(
|
|
80
|
+
connectionId,
|
|
81
|
+
JSON.stringify({ action: 'preview:browser-mcp-cursor-position', payload: cursor })
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Profiles Handlers (Settings → Profiles) + per-session picker + project default.
|
|
3
3
|
*
|
|
4
|
-
* - profiles:list / get / inventory / create / update / delete
|
|
5
|
-
* - profiles:get-permissions / save-permissions
|
|
6
|
-
* - profiles:set-project-default
|
|
7
|
-
* - profiles:available / project-default
|
|
4
|
+
* - profiles:list / get / inventory / create / update / delete
|
|
5
|
+
* - profiles:get-permissions / save-permissions
|
|
6
|
+
* - profiles:set-project-default
|
|
7
|
+
* - profiles:available / project-default
|
|
8
8
|
*
|
|
9
9
|
* A Profile bundles references to existing artifacts (Skills, Commands,
|
|
10
10
|
* Subagents, Integrations) by slug plus an optional per-engine allow/deny
|
|
11
|
-
* overlay. Nothing is duplicated — see `backend/profiles`.
|
|
12
|
-
* `backend/auth/permissions.ts`; the picker/default-read routes stay non-admin
|
|
13
|
-
* (choosing a profile for a session is a run choice like the model).
|
|
11
|
+
* overlay. Nothing is duplicated — see `backend/profiles`.
|
|
14
12
|
*/
|
|
15
13
|
|
|
16
14
|
import { t } from 'elysia';
|
|
@@ -129,7 +127,7 @@ export const profilesCrudHandler = createRouter()
|
|
|
129
127
|
return { success: true };
|
|
130
128
|
})
|
|
131
129
|
|
|
132
|
-
// ──
|
|
130
|
+
// ── Per-session picker + default read ──────────────────────────────────────
|
|
133
131
|
.http('profiles:available', {
|
|
134
132
|
data: t.Object({}),
|
|
135
133
|
response: t.Object({
|
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
* a client path) and reads the MAIN project checkout — worktrees follow it once
|
|
8
8
|
* the change is committed and merged. Writes go only to `.agents/` and the
|
|
9
9
|
* managed block of `AGENTS.md` (see `backend/artifacts/project/edit.ts`).
|
|
10
|
-
* Admin-only: see ADMIN_ONLY_ROUTES.
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
12
|
import { t } from 'elysia';
|
|
14
13
|
import { createRouter } from '$shared/utils/ws-server';
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
import { debug } from '$shared/utils/logger';
|
|
17
16
|
import { ws } from '$backend/utils/ws';
|
|
18
17
|
import { requireProjectAccess } from '../access';
|
|
@@ -86,15 +85,15 @@ const SAVED = t.Object({ slug: t.String(), path: t.String() });
|
|
|
86
85
|
|
|
87
86
|
const AGENTS_MD = t.Object({ exists: t.Boolean(), content: t.String() });
|
|
88
87
|
|
|
89
|
-
/** Project row + repository root for a request, with the
|
|
90
|
-
function projectRoot(
|
|
91
|
-
const project = requireProjectAccess(
|
|
88
|
+
/** Project row + repository root for a request, with the project checked. */
|
|
89
|
+
function projectRoot(projectId: string): { root: string; projectId: string } {
|
|
90
|
+
const project = requireProjectAccess(projectId);
|
|
92
91
|
if (!project.path) throw new Error('Project has no path on disk');
|
|
93
92
|
return { root: project.path, projectId };
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
async function scanFor(
|
|
97
|
-
const { root } = projectRoot(
|
|
95
|
+
async function scanFor(projectId: string) {
|
|
96
|
+
const { root } = projectRoot(projectId);
|
|
98
97
|
const scan = await scanProject(root, hash => projectMcpTrustQueries.isTrusted(projectId, hash));
|
|
99
98
|
const trust = projectMcpTrustQueries.get(projectId);
|
|
100
99
|
return {
|
|
@@ -107,16 +106,16 @@ export const projectArtifactsRouter = createRouter()
|
|
|
107
106
|
.http('project-artifacts:scan', {
|
|
108
107
|
data: t.Object({ projectId: t.String() }),
|
|
109
108
|
response: SCAN
|
|
110
|
-
}, async ({ data
|
|
109
|
+
}, async ({ data }) => {
|
|
111
110
|
debug.log('path', `project-artifacts:scan ${data.projectId}`);
|
|
112
|
-
return scanFor(
|
|
111
|
+
return scanFor(data.projectId);
|
|
113
112
|
})
|
|
114
113
|
|
|
115
114
|
.http('project-artifacts:read', {
|
|
116
115
|
data: t.Object({ projectId: t.String(), path: t.String() }),
|
|
117
116
|
response: t.Object({ content: t.String() })
|
|
118
|
-
}, async ({ data
|
|
119
|
-
const { root } = projectRoot(
|
|
117
|
+
}, async ({ data }) => {
|
|
118
|
+
const { root } = projectRoot(data.projectId);
|
|
120
119
|
return { content: await readProjectFile(root, data.path) };
|
|
121
120
|
})
|
|
122
121
|
|
|
@@ -130,17 +129,17 @@ export const projectArtifactsRouter = createRouter()
|
|
|
130
129
|
body: t.String()
|
|
131
130
|
}),
|
|
132
131
|
response: SAVED
|
|
133
|
-
}, async ({ data
|
|
132
|
+
}, async ({ data }) => {
|
|
134
133
|
debug.log('path', `project-artifacts:save-skill ${data.projectId} ${data.name}`);
|
|
135
|
-
const { root } = projectRoot(
|
|
134
|
+
const { root } = projectRoot(data.projectId);
|
|
136
135
|
return saveProjectSkill(root, data);
|
|
137
136
|
})
|
|
138
137
|
.http('project-artifacts:delete-skill', {
|
|
139
138
|
data: t.Object({ projectId: t.String(), slug: t.String() }),
|
|
140
139
|
response: t.Object({ success: t.Boolean() })
|
|
141
|
-
}, async ({ data
|
|
140
|
+
}, async ({ data }) => {
|
|
142
141
|
debug.log('path', `project-artifacts:delete-skill ${data.projectId} ${data.slug}`);
|
|
143
|
-
const { root } = projectRoot(
|
|
142
|
+
const { root } = projectRoot(data.projectId);
|
|
144
143
|
await deleteProjectSkill(root, data.slug);
|
|
145
144
|
return { success: true };
|
|
146
145
|
})
|
|
@@ -157,17 +156,17 @@ export const projectArtifactsRouter = createRouter()
|
|
|
157
156
|
body: t.String()
|
|
158
157
|
}),
|
|
159
158
|
response: SAVED
|
|
160
|
-
}, async ({ data
|
|
159
|
+
}, async ({ data }) => {
|
|
161
160
|
debug.log('path', `project-artifacts:save-subagent ${data.projectId} ${data.name}`);
|
|
162
|
-
const { root } = projectRoot(
|
|
161
|
+
const { root } = projectRoot(data.projectId);
|
|
163
162
|
return saveProjectSubagent(root, data);
|
|
164
163
|
})
|
|
165
164
|
.http('project-artifacts:delete-subagent', {
|
|
166
165
|
data: t.Object({ projectId: t.String(), slug: t.String() }),
|
|
167
166
|
response: t.Object({ success: t.Boolean() })
|
|
168
|
-
}, async ({ data
|
|
167
|
+
}, async ({ data }) => {
|
|
169
168
|
debug.log('path', `project-artifacts:delete-subagent ${data.projectId} ${data.slug}`);
|
|
170
|
-
const { root } = projectRoot(
|
|
169
|
+
const { root } = projectRoot(data.projectId);
|
|
171
170
|
await deleteProjectSubagent(root, data.slug);
|
|
172
171
|
return { success: true };
|
|
173
172
|
})
|
|
@@ -175,9 +174,9 @@ export const projectArtifactsRouter = createRouter()
|
|
|
175
174
|
.http('project-artifacts:copy-to-agents', {
|
|
176
175
|
data: t.Object({ projectId: t.String(), kind: t.Union([t.Literal('skill'), t.Literal('subagent')]), path: t.String() }),
|
|
177
176
|
response: SAVED
|
|
178
|
-
}, async ({ data
|
|
177
|
+
}, async ({ data }) => {
|
|
179
178
|
debug.log('path', `project-artifacts:copy-to-agents ${data.projectId} ${data.path}`);
|
|
180
|
-
const { root } = projectRoot(
|
|
179
|
+
const { root } = projectRoot(data.projectId);
|
|
181
180
|
return copyToAgents(root, data.kind, data.path);
|
|
182
181
|
})
|
|
183
182
|
|
|
@@ -185,16 +184,16 @@ export const projectArtifactsRouter = createRouter()
|
|
|
185
184
|
.http('project-artifacts:get-agents-md', {
|
|
186
185
|
data: t.Object({ projectId: t.String() }),
|
|
187
186
|
response: AGENTS_MD
|
|
188
|
-
}, async ({ data
|
|
189
|
-
const { root } = projectRoot(
|
|
187
|
+
}, async ({ data }) => {
|
|
188
|
+
const { root } = projectRoot(data.projectId);
|
|
190
189
|
return readAgentsMd(root);
|
|
191
190
|
})
|
|
192
191
|
.http('project-artifacts:save-agents-md', {
|
|
193
192
|
data: t.Object({ projectId: t.String(), content: t.String() }),
|
|
194
193
|
response: AGENTS_MD
|
|
195
|
-
}, async ({ data
|
|
194
|
+
}, async ({ data }) => {
|
|
196
195
|
debug.log('path', `project-artifacts:save-agents-md ${data.projectId}`);
|
|
197
|
-
const { root } = projectRoot(
|
|
196
|
+
const { root } = projectRoot(data.projectId);
|
|
198
197
|
return saveAgentsMd(root, data.content);
|
|
199
198
|
})
|
|
200
199
|
|
|
@@ -202,8 +201,8 @@ export const projectArtifactsRouter = createRouter()
|
|
|
202
201
|
.http('project-artifacts:get-mcp', {
|
|
203
202
|
data: t.Object({ projectId: t.String() }),
|
|
204
203
|
response: t.Object({ path: t.String(), content: t.String() })
|
|
205
|
-
}, async ({ data
|
|
206
|
-
const { root } = projectRoot(
|
|
204
|
+
}, async ({ data }) => {
|
|
205
|
+
const { root } = projectRoot(data.projectId);
|
|
207
206
|
return { path: PROJECT_WRITE_PATHS.mcp, content: readProjectMcpFile(root) ?? '' };
|
|
208
207
|
})
|
|
209
208
|
.http('project-artifacts:save-mcp', {
|
|
@@ -211,9 +210,9 @@ export const projectArtifactsRouter = createRouter()
|
|
|
211
210
|
response: t.Object({ hash: t.String() })
|
|
212
211
|
}, async ({ data, conn }) => {
|
|
213
212
|
debug.log('path', `project-artifacts:save-mcp ${data.projectId}`);
|
|
214
|
-
const { root, projectId } = projectRoot(
|
|
213
|
+
const { root, projectId } = projectRoot(data.projectId);
|
|
215
214
|
const hash = await saveProjectMcp(root, data.content);
|
|
216
|
-
//
|
|
215
|
+
// Writing the file from Settings IS the approval: the owner authored
|
|
217
216
|
// exactly this content. Edits from anywhere else still need approving.
|
|
218
217
|
if (hash) projectMcpTrustQueries.approve(projectId, hash, ws.getUserId(conn));
|
|
219
218
|
else projectMcpTrustQueries.revoke(projectId);
|
|
@@ -224,9 +223,9 @@ export const projectArtifactsRouter = createRouter()
|
|
|
224
223
|
response: t.Object({ success: t.Boolean() })
|
|
225
224
|
}, async ({ data, conn }) => {
|
|
226
225
|
debug.log('path', `project-artifacts:approve-mcp ${data.projectId}`);
|
|
227
|
-
const { root, projectId } = projectRoot(
|
|
226
|
+
const { root, projectId } = projectRoot(data.projectId);
|
|
228
227
|
const raw = readProjectMcpFile(root);
|
|
229
|
-
// Approve only what
|
|
228
|
+
// Approve only what was actually reviewed: the hash shown must
|
|
230
229
|
// still be the file on disk.
|
|
231
230
|
if (raw == null || hashContent(raw) !== data.hash) {
|
|
232
231
|
throw new Error('.agents/mcp.json changed since it was shown — review it again before approving');
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Projects CRUD Operations
|
|
3
3
|
*
|
|
4
4
|
* HTTP endpoints for project management:
|
|
5
|
-
* - List
|
|
6
|
-
* - Create new project (or
|
|
5
|
+
* - List projects in the workspace
|
|
6
|
+
* - Create new project (or re-list an existing one at the same path)
|
|
7
7
|
* - Get project by ID
|
|
8
8
|
* - Update project info
|
|
9
|
-
* - Delete project (remove
|
|
9
|
+
* - Delete project (remove from the list, or delete it with its chats)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { t } from 'elysia';
|
|
@@ -23,40 +23,43 @@ import { debug } from '$shared/utils/logger';
|
|
|
23
23
|
import { requireProjectAccess } from '../access';
|
|
24
24
|
import { runProjectCleanups } from '../../projects/project-cleanup-registry';
|
|
25
25
|
import '../../projects/project-cleanup';
|
|
26
|
+
import { ensureHomeProject } from '../../projects/home';
|
|
27
|
+
import { homeFirst, isHomeProject } from '$shared/utils/home-project';
|
|
26
28
|
|
|
27
29
|
export const crudHandler = createRouter()
|
|
28
|
-
// List
|
|
30
|
+
// List projects in the workspace
|
|
29
31
|
.http('projects:list', {
|
|
30
32
|
data: t.Object({}),
|
|
31
33
|
response: t.Array(t.Any())
|
|
32
|
-
}, async (
|
|
34
|
+
}, async () => {
|
|
33
35
|
await initializeDatabase();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// Home is always there, listed first — the place a chat with no project
|
|
37
|
+
// selected lives, and where a fresh install lands.
|
|
38
|
+
ensureHomeProject();
|
|
39
|
+
return homeFirst(projectQueries.getListed());
|
|
37
40
|
})
|
|
38
41
|
|
|
39
|
-
// Create new project (or
|
|
42
|
+
// Create new project (or re-list an existing project at the same path)
|
|
40
43
|
.http('projects:create', {
|
|
41
44
|
data: t.Object({
|
|
42
45
|
name: t.String({ minLength: 1 }),
|
|
43
46
|
path: t.String({ minLength: 1 })
|
|
44
47
|
}),
|
|
45
48
|
response: t.Any()
|
|
46
|
-
}, async ({ data
|
|
49
|
+
}, async ({ data }) => {
|
|
47
50
|
await initializeDatabase();
|
|
48
|
-
const userId = ws.getUserId(conn);
|
|
49
51
|
const { name, path } = data;
|
|
50
52
|
|
|
51
|
-
// Check if project with this path already exists. If so,
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
53
|
+
// Check if project with this path already exists. If so, put it back in
|
|
54
|
+
// the list and return the existing record. This covers re-adding a
|
|
55
|
+
// project that was previously removed (mode='remove'), which preserves
|
|
56
|
+
// the project row for session restoration.
|
|
55
57
|
const existing = projectQueries.getByPath(path);
|
|
58
|
+
// Home is already listed, as Home; a second entry for its folder would
|
|
59
|
+
// be the same workspace twice.
|
|
60
|
+
if (existing && isHomeProject(existing)) throw new Error('That folder is the Home workspace and cannot be added as a project');
|
|
56
61
|
if (existing) {
|
|
57
|
-
|
|
58
|
-
projectQueries.addUserProject(userId, existing.id);
|
|
59
|
-
}
|
|
62
|
+
projectQueries.list(existing.id);
|
|
60
63
|
return existing;
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -68,8 +71,7 @@ export const crudHandler = createRouter()
|
|
|
68
71
|
last_opened_at: now
|
|
69
72
|
});
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
projectQueries.addUserProject(userId, project.id);
|
|
74
|
+
projectQueries.list(project.id);
|
|
73
75
|
|
|
74
76
|
return project;
|
|
75
77
|
})
|
|
@@ -80,8 +82,8 @@ export const crudHandler = createRouter()
|
|
|
80
82
|
id: t.String({ minLength: 1 })
|
|
81
83
|
}),
|
|
82
84
|
response: t.Any()
|
|
83
|
-
}, async ({ data
|
|
84
|
-
requireProjectAccess(
|
|
85
|
+
}, async ({ data }) => {
|
|
86
|
+
requireProjectAccess(data.id);
|
|
85
87
|
|
|
86
88
|
// Update last_opened_at when getting project
|
|
87
89
|
projectQueries.updateLastOpened(data.id);
|
|
@@ -100,9 +102,9 @@ export const crudHandler = createRouter()
|
|
|
100
102
|
id: t.String(),
|
|
101
103
|
deleted: t.Boolean()
|
|
102
104
|
})
|
|
103
|
-
}, async ({ data
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
}, async ({ data }) => {
|
|
106
|
+
const target = requireProjectAccess(data.id);
|
|
107
|
+
if (isHomeProject(target)) throw new Error('Home cannot be removed');
|
|
106
108
|
|
|
107
109
|
const mode = data.mode ?? 'remove';
|
|
108
110
|
|
|
@@ -159,17 +161,13 @@ export const crudHandler = createRouter()
|
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// In full mode, delete the project record if no users remain
|
|
166
|
-
// In remove mode, keep the project record so sessions can be restored
|
|
164
|
+
// In full mode, delete the project record.
|
|
165
|
+
// In remove mode, keep the project record so sessions can be restored.
|
|
167
166
|
if (mode === 'full') {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
167
|
+
await runProjectCleanups(data.id);
|
|
168
|
+
projectQueries.deleteProject(data.id);
|
|
169
|
+
} else {
|
|
170
|
+
projectQueries.unlist(data.id);
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
broadcastPresence().catch((err) => {
|
|
@@ -5,15 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Structure:
|
|
7
7
|
* - crud.ts: HTTP endpoints for CRUD operations (list, create, get, update, delete)
|
|
8
|
-
* - status.ts:
|
|
9
|
-
* - presence.ts: User presence management (update-presence with broadcast)
|
|
8
|
+
* - status.ts: Live chat-stream status of every project (get-status, join, broadcast)
|
|
10
9
|
* - overview.ts: Per-project resource usage for every project (projects:overview)
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
12
|
import { createRouter } from '$shared/utils/ws-server';
|
|
14
13
|
import { crudHandler } from './crud';
|
|
15
14
|
import { statusHandler } from './status';
|
|
16
|
-
import { presenceHandler } from './presence';
|
|
17
15
|
import { infoHandler } from './info';
|
|
18
16
|
import { overviewHandler } from './overview';
|
|
19
17
|
|
|
@@ -21,14 +19,11 @@ export const projectsRouter = createRouter()
|
|
|
21
19
|
// CRUD Operations (HTTP)
|
|
22
20
|
.merge(crudHandler)
|
|
23
21
|
|
|
24
|
-
//
|
|
22
|
+
// Live stream status (HTTP + Events)
|
|
25
23
|
.merge(statusHandler)
|
|
26
24
|
|
|
27
|
-
// Presence Management (HTTP + Broadcast)
|
|
28
|
-
.merge(presenceHandler)
|
|
29
|
-
|
|
30
25
|
// Per-project resource info (storage + process-isolated CPU/RAM)
|
|
31
26
|
.merge(infoHandler)
|
|
32
27
|
|
|
33
|
-
// Per-project resource usage across every project
|
|
28
|
+
// Per-project resource usage across every project
|
|
34
29
|
.merge(overviewHandler);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Storage is a bounded walk of the project folder, nothing excluded. CPU and
|
|
5
5
|
* RAM come from the shared host probe in `backend/host/metrics.ts`, narrowed to
|
|
6
6
|
* the project's PTY shells and their descendants, so they sit on the same basis
|
|
7
|
-
* Settings →
|
|
7
|
+
* Settings → Machine reports for the whole machine. Engine processes Clopen runs
|
|
8
8
|
* outside a terminal are not shells and do not appear here.
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -431,8 +431,8 @@ export const infoHandler = createRouter().http(
|
|
|
431
431
|
})
|
|
432
432
|
})
|
|
433
433
|
},
|
|
434
|
-
async ({ data
|
|
435
|
-
requireProjectAccess(
|
|
434
|
+
async ({ data }) => {
|
|
435
|
+
requireProjectAccess(data.id);
|
|
436
436
|
const project = projectQueries.getById(data.id);
|
|
437
437
|
if (!project) {
|
|
438
438
|
throw new Error('Project not found');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Projects Overview — per-project resource usage for every project at once.
|
|
3
3
|
*
|
|
4
4
|
* Settings -> Device already describes the machine; this is the same question
|
|
5
|
-
* asked per project, so
|
|
5
|
+
* asked per project, so it is clear where the machine's CPU, RAM and disk
|
|
6
6
|
* actually went without opening Project Info once per project.
|
|
7
7
|
*
|
|
8
8
|
* Separate from `system:device-info` (host hardware) and from `projects:info`
|
|
@@ -15,23 +15,18 @@
|
|
|
15
15
|
* - idle = `projectShellPids(projectId).length === 0` (no active PTY shell)
|
|
16
16
|
* - running = at least one active shell
|
|
17
17
|
*
|
|
18
|
-
* Access: scoped to the caller. Admins see every project, everyone else sees
|
|
19
|
-
* only the projects they are assigned to — the same rule `projects:info`
|
|
20
|
-
* enforces per project through `requireProjectAccess`.
|
|
21
|
-
*
|
|
22
18
|
* Cost control:
|
|
23
19
|
* - no port scan and no per-process list here, only the summed CPU/RAM
|
|
24
20
|
* - storage is read from cache and never awaited: a cold folder reports
|
|
25
21
|
* `measuring` and fills in on a later poll, so this handler's latency is
|
|
26
22
|
* the process-table probe, not a filesystem walk
|
|
27
|
-
* - one snapshot
|
|
23
|
+
* - one snapshot is cached for `OVERVIEW_CACHE_TTL_MS` and
|
|
28
24
|
* single-flighted, and the process table underneath has its own 2s cache,
|
|
29
25
|
* so a fast poll costs at most one probe every couple of seconds
|
|
30
26
|
*/
|
|
31
27
|
|
|
32
28
|
import { t } from 'elysia';
|
|
33
29
|
import { createRouter } from '$shared/utils/ws-server';
|
|
34
|
-
import { ws } from '$backend/utils/ws';
|
|
35
30
|
import { projectQueries } from '../../database/queries';
|
|
36
31
|
import { projectShellPids } from '../../projects/shell-ownership';
|
|
37
32
|
import { getHostFacts } from '../../host/metrics';
|
|
@@ -217,34 +212,32 @@ async function buildOverview(projects: Project[]): Promise<ProjectsOverview> {
|
|
|
217
212
|
};
|
|
218
213
|
}
|
|
219
214
|
|
|
220
|
-
/** One snapshot
|
|
221
|
-
*
|
|
222
|
-
*
|
|
215
|
+
/** One snapshot, kept below the frontend heartbeat so a poll is never
|
|
216
|
+
* answered with the payload it already has, while burst opens and rapid tab
|
|
217
|
+
* switches still collapse onto a single build. */
|
|
223
218
|
const OVERVIEW_CACHE_TTL_MS = 1_500;
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
let cachedOverview: { payload: ProjectsOverview; at: number } | null = null;
|
|
220
|
+
let inFlightOverview: Promise<ProjectsOverview> | null = null;
|
|
226
221
|
|
|
227
|
-
function getOverview(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return Promise.resolve(cached.payload);
|
|
222
|
+
function getOverview(projects: Project[]): Promise<ProjectsOverview> {
|
|
223
|
+
if (cachedOverview && Date.now() - cachedOverview.at < OVERVIEW_CACHE_TTL_MS) {
|
|
224
|
+
return Promise.resolve(cachedOverview.payload);
|
|
231
225
|
}
|
|
232
226
|
|
|
233
|
-
|
|
234
|
-
if (inFlight) return inFlight;
|
|
227
|
+
if (inFlightOverview) return inFlightOverview;
|
|
235
228
|
|
|
236
229
|
const build = buildOverview(projects).then((payload) => {
|
|
237
|
-
|
|
238
|
-
|
|
230
|
+
cachedOverview = { payload, at: Date.now() };
|
|
231
|
+
inFlightOverview = null;
|
|
239
232
|
return payload;
|
|
240
233
|
});
|
|
241
234
|
// A failed build must not pin the single-flight slot: storage failures are
|
|
242
235
|
// already folded into `unavailable`, so a rejection here is unexpected
|
|
243
236
|
// (e.g. the process table is unreadable) and the next poll should retry.
|
|
244
237
|
build.catch(() => {
|
|
245
|
-
|
|
238
|
+
inFlightOverview = null;
|
|
246
239
|
});
|
|
247
|
-
|
|
240
|
+
inFlightOverview = build;
|
|
248
241
|
return build;
|
|
249
242
|
}
|
|
250
243
|
|
|
@@ -288,13 +281,9 @@ export const overviewHandler = createRouter().http(
|
|
|
288
281
|
generatedAt: t.String()
|
|
289
282
|
})
|
|
290
283
|
},
|
|
291
|
-
async (
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
const userId = ws.getUserId(conn);
|
|
296
|
-
const isAdmin = ws.getRole(conn) === 'admin';
|
|
297
|
-
const projects = isAdmin ? projectQueries.getAll() : projectQueries.getAllForUser(userId);
|
|
298
|
-
return getOverview(isAdmin ? 'admin' : `user:${userId}`, projects);
|
|
284
|
+
async () => {
|
|
285
|
+
// Every project on disk, including one removed from the list: it still
|
|
286
|
+
// takes up storage and can still run processes.
|
|
287
|
+
return getOverview(projectQueries.getAll());
|
|
299
288
|
}
|
|
300
289
|
);
|