@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
|
@@ -3,24 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
-
import path from 'node:path';
|
|
7
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
8
7
|
import { gitService } from '../../git/git-service';
|
|
9
8
|
import { findRepoForFile } from '../../git/nested-repos';
|
|
10
9
|
import { requireProjectWorkspace } from '../access';
|
|
11
|
-
import {
|
|
10
|
+
import { gitRepoContext, withRepoLock } from './repo-context';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
19
|
-
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
20
|
-
return projectRoot;
|
|
21
|
-
}
|
|
22
|
-
return resolved;
|
|
23
|
-
}
|
|
12
|
+
// Index writes queue behind each other rather than refusing: three files staged
|
|
13
|
+
// in quick succession are three requests the user meant.
|
|
14
|
+
const STAGE = { category: 'staging', label: 'Staging', queue: true } as const;
|
|
15
|
+
const UNSTAGE = { category: 'staging', label: 'Unstaging', queue: true } as const;
|
|
16
|
+
const DISCARD = { category: 'staging', label: 'Discarding changes', queue: true } as const;
|
|
24
17
|
|
|
25
18
|
export const stagingHandler = createRouter()
|
|
26
19
|
.http('git:stage', {
|
|
@@ -32,9 +25,9 @@ export const stagingHandler = createRouter()
|
|
|
32
25
|
}, async ({ data, conn }) => {
|
|
33
26
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
34
27
|
const repo = await findRepoForFile(root, data.filePath);
|
|
35
|
-
const
|
|
28
|
+
const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
|
|
36
29
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
37
|
-
await gitService.stageFile(cwd, filePath);
|
|
30
|
+
await withRepoLock(ctx, STAGE, () => gitService.stageFile(ctx.cwd, filePath));
|
|
38
31
|
return { ok: true };
|
|
39
32
|
})
|
|
40
33
|
|
|
@@ -45,9 +38,8 @@ export const stagingHandler = createRouter()
|
|
|
45
38
|
}),
|
|
46
39
|
response: t.Object({ ok: t.Boolean() })
|
|
47
40
|
}, async ({ data, conn }) => {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
await gitService.stageAll(cwd);
|
|
41
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
42
|
+
await withRepoLock(ctx, STAGE, () => gitService.stageAll(ctx.cwd));
|
|
51
43
|
return { ok: true };
|
|
52
44
|
})
|
|
53
45
|
|
|
@@ -60,9 +52,9 @@ export const stagingHandler = createRouter()
|
|
|
60
52
|
}, async ({ data, conn }) => {
|
|
61
53
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
62
54
|
const repo = await findRepoForFile(root, data.filePath);
|
|
63
|
-
const
|
|
55
|
+
const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
|
|
64
56
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
65
|
-
await gitService.unstageFile(cwd, filePath);
|
|
57
|
+
await withRepoLock(ctx, UNSTAGE, () => gitService.unstageFile(ctx.cwd, filePath));
|
|
66
58
|
return { ok: true };
|
|
67
59
|
})
|
|
68
60
|
|
|
@@ -73,9 +65,8 @@ export const stagingHandler = createRouter()
|
|
|
73
65
|
}),
|
|
74
66
|
response: t.Object({ ok: t.Boolean() })
|
|
75
67
|
}, async ({ data, conn }) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
await gitService.unstageAll(cwd);
|
|
68
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
69
|
+
await withRepoLock(ctx, UNSTAGE, () => gitService.unstageAll(ctx.cwd));
|
|
79
70
|
return { ok: true };
|
|
80
71
|
})
|
|
81
72
|
|
|
@@ -88,9 +79,9 @@ export const stagingHandler = createRouter()
|
|
|
88
79
|
}, async ({ data, conn }) => {
|
|
89
80
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
90
81
|
const repo = await findRepoForFile(root, data.filePath);
|
|
91
|
-
const
|
|
82
|
+
const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
|
|
92
83
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
93
|
-
await gitService.discardFile(cwd, filePath);
|
|
84
|
+
await withRepoLock(ctx, DISCARD, () => gitService.discardFile(ctx.cwd, filePath));
|
|
94
85
|
return { ok: true };
|
|
95
86
|
})
|
|
96
87
|
|
|
@@ -101,8 +92,7 @@ export const stagingHandler = createRouter()
|
|
|
101
92
|
}),
|
|
102
93
|
response: t.Object({ ok: t.Boolean() })
|
|
103
94
|
}, async ({ data, conn }) => {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
await gitService.discardAll(cwd);
|
|
95
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
96
|
+
await withRepoLock(ctx, DISCARD, () => gitService.discardAll(ctx.cwd));
|
|
107
97
|
return { ok: true };
|
|
108
98
|
});
|
package/backend/ws/git/status.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { t } from 'elysia';
|
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
8
|
import { findNestedRepoPaths } from '../../git/nested-repos';
|
|
9
|
+
import { gitRepoContext, withRepoLock } from './repo-context';
|
|
9
10
|
import { requireProjectWorkspace } from '../access';
|
|
10
11
|
import { relative as pathRelative } from 'path';
|
|
11
12
|
|
|
@@ -126,8 +127,10 @@ export const statusHandler = createRouter()
|
|
|
126
127
|
}),
|
|
127
128
|
response: t.Object({ ok: t.Boolean() })
|
|
128
129
|
}, async ({ data, conn }) => {
|
|
129
|
-
const
|
|
130
|
-
await
|
|
130
|
+
const ctx = gitRepoContext(conn, data.projectId);
|
|
131
|
+
await withRepoLock(ctx, { category: 'configure', label: 'Initialize repository' }, () =>
|
|
132
|
+
gitService.init(ctx.root, data.defaultBranch)
|
|
133
|
+
);
|
|
131
134
|
return { ok: true };
|
|
132
135
|
})
|
|
133
136
|
|
package/backend/ws/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ import { worktreesRouter } from './worktrees';
|
|
|
48
48
|
import { notesRouter } from './notes';
|
|
49
49
|
import { workRouter } from './work';
|
|
50
50
|
import { deploymentsRouter } from './deployments';
|
|
51
|
+
import { chatAppsRouter } from './chat-apps';
|
|
51
52
|
|
|
52
53
|
// ============================================
|
|
53
54
|
// Main App Router - Merge All Module Routers
|
|
@@ -130,7 +131,10 @@ export const wsRouter = createRouter()
|
|
|
130
131
|
.merge(workRouter)
|
|
131
132
|
|
|
132
133
|
// Deployments surface — builds, logs and what is live, for the current project
|
|
133
|
-
.merge(deploymentsRouter)
|
|
134
|
+
.merge(deploymentsRouter)
|
|
135
|
+
|
|
136
|
+
// Notification channels — pairing a chat with a connected bot, per user
|
|
137
|
+
.merge(chatAppsRouter);
|
|
134
138
|
|
|
135
139
|
// Export API type for frontend type-safe access
|
|
136
140
|
export type WSAPI = typeof wsRouter['$api'];
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - instructions:get-project / save-project
|
|
6
6
|
*
|
|
7
7
|
* The managed block is injected into each engine's memory file as a
|
|
8
|
-
* marker-region; hand-written content is preserved.
|
|
8
|
+
* marker-region; hand-written content is preserved.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { t } from 'elysia';
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
* integrations:health — probe one account
|
|
10
10
|
* integrations:secrets-health — state of secrets at rest, for the hub banner
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* absorbs: connecting an account changes what every engine and every project
|
|
14
|
-
* can reach.
|
|
12
|
+
* Connecting an account changes what every engine and every project can reach.
|
|
15
13
|
*/
|
|
16
14
|
|
|
17
15
|
import { t } from 'elysia';
|
package/backend/ws/mcp/crud.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
* - mcp:toggle — enable / disable
|
|
8
8
|
* - mcp:uninstall — remove
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* effect on the next chat stream (engines read MCP config when a stream starts).
|
|
10
|
+
* Changes take effect on the next chat stream (engines read MCP config when a stream starts).
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
import { t } from 'elysia';
|
|
@@ -52,9 +51,8 @@ const INSTALLED_SERVER_SCHEMA = t.Object({
|
|
|
52
51
|
transport: TRANSPORT_SCHEMA,
|
|
53
52
|
command: t.Union([t.String(), t.Null()]),
|
|
54
53
|
args: t.Array(t.String()),
|
|
55
|
-
// Full values are returned (not redacted): the
|
|
56
|
-
//
|
|
57
|
-
// admins can review and edit what each engine receives.
|
|
54
|
+
// Full values are returned (not redacted): the Settings UI shows values so
|
|
55
|
+
// the owner can review and edit what each engine receives.
|
|
58
56
|
env: t.Record(t.String(), t.String()),
|
|
59
57
|
headers: t.Record(t.String(), t.String()),
|
|
60
58
|
configSchema: t.Array(CONFIG_FIELD_SCHEMA),
|
package/backend/ws/mcp/tools.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* All three go through the SAME upstream introspection path the bridge uses
|
|
10
10
|
* (`backend/mcp/external/proxy.ts`), so what Settings shows matches what the
|
|
11
|
-
* engines receive.
|
|
11
|
+
* engines receive.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { t } from 'elysia';
|
|
@@ -12,16 +12,12 @@
|
|
|
12
12
|
* - memory:status / memory:retry-failed
|
|
13
13
|
* - memory:config / memory:save-config
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `backend/auth/permissions.ts`, matching skills / mcp_servers / subagents:
|
|
18
|
-
* memory is instance-global, so one member editing it changes what every agent
|
|
19
|
-
* is told on every future turn.
|
|
15
|
+
* Memory is instance-global, so an edit changes what every agent is told on
|
|
16
|
+
* every future turn.
|
|
20
17
|
*/
|
|
21
18
|
|
|
22
19
|
import { t } from 'elysia';
|
|
23
|
-
import { createRouter
|
|
24
|
-
import { ws } from '$backend/utils/ws';
|
|
20
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
25
21
|
import { projectContextService } from '$backend/mcp/internal/project-context';
|
|
26
22
|
import { debug } from '$shared/utils/logger';
|
|
27
23
|
import { graphQueries, graphLayoutQueries } from '$backend/database/queries/graph-queries';
|
|
@@ -133,39 +129,12 @@ const READINESS = t.Object({
|
|
|
133
129
|
})
|
|
134
130
|
});
|
|
135
131
|
|
|
136
|
-
/**
|
|
137
|
-
* How the modal's project multi-select reaches a query.
|
|
138
|
-
*
|
|
139
|
-
* `projectIds` is tri-state on the wire and each state means something
|
|
140
|
-
* different: ABSENT is "every project" (the cross-project view), an EMPTY array
|
|
141
|
-
* is "global only" — nothing selected is a narrowing, not the absence of one —
|
|
142
|
-
* and a non-empty array is those projects plus the globals that apply inside
|
|
143
|
-
* every one of them.
|
|
144
|
-
*
|
|
145
|
-
* Cross-project is admin-only. Reads are otherwise open, because the graph is
|
|
146
|
-
* what explains a project to whoever is working on it and withholding that would
|
|
147
|
-
* defeat the feature. But "every project at once" is a different request: memory
|
|
148
|
-
* is instance-global, so it would show a member everything every other team has
|
|
149
|
-
* ever worked on, including repositories they have no access to. Narrowing to
|
|
150
|
-
* the caller's current project is the honest degradation — they still see
|
|
151
|
-
* everything that applies where they are, plus the globals.
|
|
152
|
-
*
|
|
153
|
-
* Mutations are gated separately, in `backend/auth/permissions.ts`.
|
|
154
|
-
*/
|
|
155
|
-
function scopeForRole(conn: WSConnection, requested: string[] | undefined): string[] | undefined {
|
|
156
|
-
if (requested !== undefined) return requested;
|
|
157
|
-
if (ws.getRole(conn) === 'admin') return undefined;
|
|
158
|
-
|
|
159
|
-
const current = projectContextService.getCurrentProjectId();
|
|
160
|
-
debug.log('path', 'memory: cross-project read narrowed to current project (not admin)');
|
|
161
|
-
// No project selected and not an admin: global-scope memories only, which an
|
|
162
|
-
// empty selection already means.
|
|
163
|
-
return current ? [current] : [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
132
|
export const memoryCrudHandler = createRouter()
|
|
167
133
|
.http('memory:graph', {
|
|
168
134
|
data: t.Object({
|
|
135
|
+
// Tri-state, and each state means something different: ABSENT is every
|
|
136
|
+
// project, an EMPTY array is global only, and a non-empty array is those
|
|
137
|
+
// projects plus the globals that apply inside every one of them.
|
|
169
138
|
projectIds: t.Optional(t.Array(t.String())),
|
|
170
139
|
subkinds: t.Optional(t.Array(t.String())),
|
|
171
140
|
scopes: t.Optional(t.Array(SCOPE)),
|
|
@@ -238,10 +207,10 @@ export const memoryCrudHandler = createRouter()
|
|
|
238
207
|
totalNodes: t.Number(),
|
|
239
208
|
truncated: t.Boolean()
|
|
240
209
|
})
|
|
241
|
-
}, async ({
|
|
210
|
+
}, async ({ data }) => {
|
|
242
211
|
debug.log('path', 'memory:graph');
|
|
243
212
|
return buildGraphView({
|
|
244
|
-
projectIds:
|
|
213
|
+
projectIds: data.projectIds,
|
|
245
214
|
subkinds: data.subkinds,
|
|
246
215
|
scopes: data.scopes as GraphScope[] | undefined,
|
|
247
216
|
sources: data.sources as GraphSource[] | undefined,
|
|
@@ -290,11 +259,11 @@ export const memoryCrudHandler = createRouter()
|
|
|
290
259
|
vectorWeight: t.Number()
|
|
291
260
|
})
|
|
292
261
|
})
|
|
293
|
-
}, async ({
|
|
262
|
+
}, async ({ data }) => {
|
|
294
263
|
debug.log('path', 'memory:search');
|
|
295
264
|
const result = retrieve({
|
|
296
265
|
query: data.query,
|
|
297
|
-
projectIds:
|
|
266
|
+
projectIds: data.projectIds,
|
|
298
267
|
subkinds: data.subkinds,
|
|
299
268
|
sources: data.sources as GraphSource[] | undefined,
|
|
300
269
|
limit: data.limit ?? 20,
|
|
@@ -493,9 +462,8 @@ export const memoryCrudHandler = createRouter()
|
|
|
493
462
|
/**
|
|
494
463
|
* What the extraction queue is doing.
|
|
495
464
|
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
* can change the setting that fixes it.
|
|
465
|
+
* It answers "is memory working right now" for someone watching the graph
|
|
466
|
+
* fail to grow.
|
|
499
467
|
*/
|
|
500
468
|
.http('memory:status', {
|
|
501
469
|
data: t.Object({}),
|
|
@@ -576,9 +544,9 @@ export const memoryCrudHandler = createRouter()
|
|
|
576
544
|
nodes: t.Array(NODE),
|
|
577
545
|
total: t.Number()
|
|
578
546
|
})
|
|
579
|
-
}, async ({
|
|
547
|
+
}, async ({ data }) => {
|
|
580
548
|
debug.log('path', 'memory:forgotten');
|
|
581
|
-
const projectIds =
|
|
549
|
+
const projectIds = data.projectIds;
|
|
582
550
|
return {
|
|
583
551
|
nodes: graphQueries.listArchived({
|
|
584
552
|
projectIds,
|
|
@@ -9,8 +9,8 @@ import { memoryCrudHandler } from './crud';
|
|
|
9
9
|
export const memoryRouter = createRouter()
|
|
10
10
|
/**
|
|
11
11
|
* The graph changed. Broadcast globally rather than per session, because the
|
|
12
|
-
* memory graph is instance-wide: a memory written by one
|
|
13
|
-
*
|
|
12
|
+
* memory graph is instance-wide: a memory written by one chat is immediately
|
|
13
|
+
* part of what every device's Memory view is showing.
|
|
14
14
|
*
|
|
15
15
|
* The payload deliberately carries no data, only a reason. Diffing the graph
|
|
16
16
|
* over the wire would mean a second serialization format to keep in step with
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* HTTP endpoints for message management:
|
|
5
5
|
* - List messages (with optional include_all for history view)
|
|
6
|
+
* - Page through the active branch, its prompt index and older task tools
|
|
6
7
|
* - Get message by ID
|
|
8
|
+
* - Resolve which of a session's message ids are saved
|
|
7
9
|
* - Delete message
|
|
8
10
|
*/
|
|
9
11
|
|
|
@@ -12,6 +14,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
12
14
|
import { messageQueries } from '../../database/queries';
|
|
13
15
|
import { loadMessage } from '$shared/utils/message-formatter';
|
|
14
16
|
import { requireMessageAccess, requireSessionAccess } from '../access';
|
|
17
|
+
import { getMessagePage, getPromptIndex, getTaskHistory } from '../../chat/message-pages';
|
|
15
18
|
|
|
16
19
|
export const crudHandler = createRouter()
|
|
17
20
|
// List messages
|
|
@@ -21,8 +24,8 @@ export const crudHandler = createRouter()
|
|
|
21
24
|
include_all: t.Optional(t.Boolean())
|
|
22
25
|
}),
|
|
23
26
|
response: t.Array(t.Any())
|
|
24
|
-
}, async ({ data
|
|
25
|
-
requireSessionAccess(
|
|
27
|
+
}, async ({ data }) => {
|
|
28
|
+
requireSessionAccess(data.session_id);
|
|
26
29
|
if (data.include_all) {
|
|
27
30
|
// Return all messages including those in other branches (for History view)
|
|
28
31
|
const allMessages = messageQueries.getAllBySessionId(data.session_id);
|
|
@@ -33,17 +36,84 @@ export const crudHandler = createRouter()
|
|
|
33
36
|
}
|
|
34
37
|
})
|
|
35
38
|
|
|
39
|
+
// One page of the active branch — the chat loads its latest turns and pages
|
|
40
|
+
// back as the user scrolls up (see backend/chat/message-pages.ts).
|
|
41
|
+
.http('messages:list-page', {
|
|
42
|
+
data: t.Object({
|
|
43
|
+
session_id: t.String({ minLength: 1 }),
|
|
44
|
+
/** Return the page that ends just before this message; omit for the latest. */
|
|
45
|
+
before_id: t.Optional(t.String()),
|
|
46
|
+
/** Minimum page size; the page is extended back to the start of a turn. */
|
|
47
|
+
limit: t.Optional(t.Number({ minimum: 1, maximum: 500 }))
|
|
48
|
+
}),
|
|
49
|
+
response: t.Object({
|
|
50
|
+
messages: t.Array(t.Any()),
|
|
51
|
+
hasMore: t.Boolean()
|
|
52
|
+
})
|
|
53
|
+
}, async ({ data }) => {
|
|
54
|
+
requireSessionAccess(data.session_id);
|
|
55
|
+
return getMessagePage(data.session_id, { beforeId: data.before_id, minCount: data.limit });
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Every user prompt on the active branch — the chat's navigation rail.
|
|
59
|
+
.http('messages:list-prompts', {
|
|
60
|
+
data: t.Object({
|
|
61
|
+
session_id: t.String({ minLength: 1 })
|
|
62
|
+
}),
|
|
63
|
+
response: t.Array(t.Object({
|
|
64
|
+
messageId: t.String(),
|
|
65
|
+
text: t.String(),
|
|
66
|
+
createdAt: t.String()
|
|
67
|
+
}))
|
|
68
|
+
}, async ({ data }) => {
|
|
69
|
+
requireSessionAccess(data.session_id);
|
|
70
|
+
return getPromptIndex(data.session_id);
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// Task-tool calls and results older than a message — the task widget replays
|
|
74
|
+
// them together with the loaded messages.
|
|
75
|
+
.http('messages:list-task-history', {
|
|
76
|
+
data: t.Object({
|
|
77
|
+
session_id: t.String({ minLength: 1 }),
|
|
78
|
+
before_id: t.String({ minLength: 1 })
|
|
79
|
+
}),
|
|
80
|
+
response: t.Array(t.Any())
|
|
81
|
+
}, async ({ data }) => {
|
|
82
|
+
requireSessionAccess(data.session_id);
|
|
83
|
+
return getTaskHistory(data.session_id, data.before_id);
|
|
84
|
+
})
|
|
85
|
+
|
|
36
86
|
// Get message by ID
|
|
37
87
|
.http('messages:get', {
|
|
38
88
|
data: t.Object({
|
|
39
89
|
messageId: t.String({ minLength: 1 })
|
|
40
90
|
}),
|
|
41
91
|
response: t.Any()
|
|
42
|
-
}, async ({ data
|
|
43
|
-
const message = requireMessageAccess(
|
|
92
|
+
}, async ({ data }) => {
|
|
93
|
+
const message = requireMessageAccess(data.messageId);
|
|
44
94
|
return loadMessage(message);
|
|
45
95
|
})
|
|
46
96
|
|
|
97
|
+
// Which of these ids are saved messages of the session, and what they hold.
|
|
98
|
+
// A sender checks the bubbles it is still showing optimistically: a send
|
|
99
|
+
// whose echo never arrived (socket dropped, stopped early) may still have
|
|
100
|
+
// been saved, or may never have reached the server at all.
|
|
101
|
+
.http('messages:resolve', {
|
|
102
|
+
data: t.Object({
|
|
103
|
+
session_id: t.String({ minLength: 1 }),
|
|
104
|
+
ids: t.Array(t.String({ minLength: 1 }), { maxItems: 100 })
|
|
105
|
+
}),
|
|
106
|
+
response: t.Array(t.Any())
|
|
107
|
+
}, async ({ data }) => {
|
|
108
|
+
requireSessionAccess(data.session_id);
|
|
109
|
+
const found: ReturnType<typeof loadMessage>[] = [];
|
|
110
|
+
for (const id of new Set(data.ids)) {
|
|
111
|
+
const row = messageQueries.getById(id);
|
|
112
|
+
if (row && row.session_id === data.session_id) found.push(loadMessage(row));
|
|
113
|
+
}
|
|
114
|
+
return found;
|
|
115
|
+
})
|
|
116
|
+
|
|
47
117
|
// Get full (untrimmed) sub-agent messages nested under a message.
|
|
48
118
|
// Used by the Debug modal to show complete data despite the wire trimming
|
|
49
119
|
// sub-agent noise from the normal chat payload.
|
|
@@ -52,8 +122,8 @@ export const crudHandler = createRouter()
|
|
|
52
122
|
messageId: t.String({ minLength: 1 })
|
|
53
123
|
}),
|
|
54
124
|
response: t.Array(t.Any())
|
|
55
|
-
}, async ({ data
|
|
56
|
-
requireMessageAccess(
|
|
125
|
+
}, async ({ data }) => {
|
|
126
|
+
requireMessageAccess(data.messageId);
|
|
57
127
|
return messageQueries.getSubAgentMessages(data.messageId);
|
|
58
128
|
})
|
|
59
129
|
|
|
@@ -65,9 +135,9 @@ export const crudHandler = createRouter()
|
|
|
65
135
|
response: t.Object({
|
|
66
136
|
message: t.String()
|
|
67
137
|
})
|
|
68
|
-
}, async ({ data
|
|
138
|
+
}, async ({ data }) => {
|
|
69
139
|
// Check if message exists first
|
|
70
|
-
requireMessageAccess(
|
|
140
|
+
requireMessageAccess(data.messageId);
|
|
71
141
|
|
|
72
142
|
// Delete the message
|
|
73
143
|
messageQueries.delete(data.messageId);
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* Notes Router
|
|
3
3
|
*
|
|
4
4
|
* Notes live in collections, and a collection carries the scope: `project`
|
|
5
|
-
* (
|
|
5
|
+
* (inside one project) or `global` (shown in every project). Access is
|
|
6
6
|
* resolved through the collection on every route — a note id is never treated
|
|
7
7
|
* as a capability on its own.
|
|
8
8
|
*
|
|
9
|
-
* Writes broadcast `notes:changed` to
|
|
10
|
-
* way worktrees do: a note
|
|
11
|
-
* next reload without it. The event carries ids only — a note holds up to
|
|
9
|
+
* Writes broadcast `notes:changed` to every device showing the collection, the
|
|
10
|
+
* same way worktrees do: a note just created on another device is invisible
|
|
11
|
+
* until the next reload without it. The event carries ids only — a note holds up to
|
|
12
12
|
* 200 KB, so fanning the list out on every autosave would put megabytes on the
|
|
13
13
|
* socket per keystroke of a long note.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { t } from 'elysia';
|
|
17
17
|
import { createRouter } from '$shared/utils/ws-server';
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
import type { NoteCollection } from '$shared/types/database/schema';
|
|
20
20
|
import { ws as wsServer } from '../../utils/ws';
|
|
21
21
|
import { requireProjectAccess } from '../access';
|
|
@@ -61,45 +61,39 @@ const noteSchema = t.Object({
|
|
|
61
61
|
)
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
/** Resolve a collection and refuse the call unless
|
|
65
|
-
function requireCollection(
|
|
64
|
+
/** Resolve a collection and refuse the call unless it can be reached. */
|
|
65
|
+
function requireCollection(collectionId: string): NoteCollection {
|
|
66
66
|
const collection = noteCollectionQueries.getById(collectionId);
|
|
67
|
-
// Same answer for "does not exist" and "not yours", so the id space cannot be
|
|
68
|
-
// probed for which collections are real.
|
|
69
67
|
if (!collection) throw new Error('Access denied');
|
|
70
|
-
if (!canAccessCollection(
|
|
68
|
+
if (!canAccessCollection(collection)) {
|
|
71
69
|
throw new Error('Access denied');
|
|
72
70
|
}
|
|
73
71
|
return collection;
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
/** Resolve the collection a note belongs to, subject to the same check. */
|
|
77
|
-
function requireNoteCollection(
|
|
75
|
+
function requireNoteCollection(noteId: string): NoteCollection {
|
|
78
76
|
const collection = noteCollectionQueries.getForNote(noteId);
|
|
79
77
|
if (!collection) throw new Error('Access denied');
|
|
80
|
-
if (!canAccessCollection(
|
|
78
|
+
if (!canAccessCollection(collection)) {
|
|
81
79
|
throw new Error('Access denied');
|
|
82
80
|
}
|
|
83
81
|
return collection;
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
/** Check
|
|
87
|
-
function requireScope(
|
|
84
|
+
/** Check `scope` can be written into before anything is created there. */
|
|
85
|
+
function requireScope(scope: 'project' | 'global', projectId: string | null): void {
|
|
88
86
|
if (scope === 'project') {
|
|
89
87
|
if (!projectId) throw new Error('projectId is required for the project scope');
|
|
90
|
-
requireProjectAccess(
|
|
91
|
-
return;
|
|
88
|
+
requireProjectAccess(projectId);
|
|
92
89
|
}
|
|
93
|
-
// Global is instance-wide; the only requirement is a signed-in connection,
|
|
94
|
-
// which getUserId asserts.
|
|
95
|
-
wsServer.getUserId(conn);
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
/**
|
|
99
|
-
* Tell
|
|
93
|
+
* Tell every device showing this collection that its contents moved.
|
|
100
94
|
*
|
|
101
95
|
* A project collection reaches the project room; a global one reaches every
|
|
102
|
-
* connection
|
|
96
|
+
* connection.
|
|
103
97
|
*/
|
|
104
98
|
function broadcast(collection: NoteCollection): void {
|
|
105
99
|
const payload = {
|
|
@@ -126,9 +120,9 @@ export const notesRouter = createRouter()
|
|
|
126
120
|
collections: t.Array(collectionSchema),
|
|
127
121
|
notes: t.Array(noteSchema)
|
|
128
122
|
})
|
|
129
|
-
}, async ({ data
|
|
123
|
+
}, async ({ data }) => {
|
|
130
124
|
const projectId = data.projectId ?? null;
|
|
131
|
-
requireScope(
|
|
125
|
+
requireScope(data.scope, projectId);
|
|
132
126
|
const collections = noteCollectionQueries.listByScope(data.scope, projectId);
|
|
133
127
|
return {
|
|
134
128
|
collections,
|
|
@@ -145,7 +139,7 @@ export const notesRouter = createRouter()
|
|
|
145
139
|
response: t.Object({ collection: collectionSchema })
|
|
146
140
|
}, async ({ data, conn }) => {
|
|
147
141
|
const projectId = data.scope === 'project' ? (data.projectId ?? null) : null;
|
|
148
|
-
requireScope(
|
|
142
|
+
requireScope(data.scope, projectId);
|
|
149
143
|
const collection = noteCollectionQueries.create({
|
|
150
144
|
name: data.name,
|
|
151
145
|
scope: data.scope,
|
|
@@ -159,8 +153,8 @@ export const notesRouter = createRouter()
|
|
|
159
153
|
.http('notes:rename-collection', {
|
|
160
154
|
data: t.Object({ id: t.String({ minLength: 1 }), name: t.String({ minLength: 1 }) }),
|
|
161
155
|
response: t.Object({ collection: t.Union([collectionSchema, t.Null()]) })
|
|
162
|
-
}, async ({ data
|
|
163
|
-
const collection = requireCollection(
|
|
156
|
+
}, async ({ data }) => {
|
|
157
|
+
const collection = requireCollection(data.id);
|
|
164
158
|
const renamed = noteCollectionQueries.rename(collection.id, data.name);
|
|
165
159
|
if (renamed) broadcast(renamed);
|
|
166
160
|
return { collection: renamed };
|
|
@@ -169,8 +163,8 @@ export const notesRouter = createRouter()
|
|
|
169
163
|
.http('notes:delete-collection', {
|
|
170
164
|
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
171
165
|
response: t.Object({ ok: t.Boolean() })
|
|
172
|
-
}, async ({ data
|
|
173
|
-
const collection = requireCollection(
|
|
166
|
+
}, async ({ data }) => {
|
|
167
|
+
const collection = requireCollection(data.id);
|
|
174
168
|
// Notes and image rows cascade with the collection; the files they point
|
|
175
169
|
// at do not, so the whole collection directory goes with them.
|
|
176
170
|
noteCollectionQueries.delete(collection.id);
|
|
@@ -184,8 +178,8 @@ export const notesRouter = createRouter()
|
|
|
184
178
|
.http('notes:get', {
|
|
185
179
|
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
186
180
|
response: t.Object({ note: t.Union([noteSchema, t.Null()]) })
|
|
187
|
-
}, async ({ data
|
|
188
|
-
requireNoteCollection(
|
|
181
|
+
}, async ({ data }) => {
|
|
182
|
+
requireNoteCollection(data.id);
|
|
189
183
|
return { note: noteQueries.getById(data.id) };
|
|
190
184
|
})
|
|
191
185
|
|
|
@@ -204,11 +198,11 @@ export const notesRouter = createRouter()
|
|
|
204
198
|
const userId = wsServer.getUserId(conn);
|
|
205
199
|
let collection: NoteCollection;
|
|
206
200
|
if (data.collectionId) {
|
|
207
|
-
collection = requireCollection(
|
|
201
|
+
collection = requireCollection(data.collectionId);
|
|
208
202
|
} else {
|
|
209
203
|
const scope = data.scope ?? 'project';
|
|
210
204
|
const projectId = scope === 'project' ? (data.projectId ?? null) : null;
|
|
211
|
-
requireScope(
|
|
205
|
+
requireScope(scope, projectId);
|
|
212
206
|
collection = noteCollectionQueries.ensureDefault(scope, projectId, userId);
|
|
213
207
|
}
|
|
214
208
|
const note = noteQueries.create({
|
|
@@ -229,11 +223,11 @@ export const notesRouter = createRouter()
|
|
|
229
223
|
collectionId: t.Optional(t.String())
|
|
230
224
|
}),
|
|
231
225
|
response: t.Object({ note: t.Union([noteSchema, t.Null()]) })
|
|
232
|
-
}, async ({ data
|
|
233
|
-
const from = requireNoteCollection(
|
|
226
|
+
}, async ({ data }) => {
|
|
227
|
+
const from = requireNoteCollection(data.id);
|
|
234
228
|
// Moving a note is only allowed between collections the caller can already
|
|
235
229
|
// see, otherwise a move would be a way to read or plant one they cannot.
|
|
236
|
-
const to = data.collectionId ? requireCollection(
|
|
230
|
+
const to = data.collectionId ? requireCollection(data.collectionId) : from;
|
|
237
231
|
const updated = noteQueries.update(data.id, {
|
|
238
232
|
title: data.title,
|
|
239
233
|
content: data.content,
|
|
@@ -248,8 +242,8 @@ export const notesRouter = createRouter()
|
|
|
248
242
|
.http('notes:delete', {
|
|
249
243
|
data: t.Object({ id: t.String({ minLength: 1 }) }),
|
|
250
244
|
response: t.Object({ ok: t.Boolean() })
|
|
251
|
-
}, async ({ data
|
|
252
|
-
const collection = requireNoteCollection(
|
|
245
|
+
}, async ({ data }) => {
|
|
246
|
+
const collection = requireNoteCollection(data.id);
|
|
253
247
|
noteQueries.delete(data.id);
|
|
254
248
|
await removeNoteFiles(collection.id, data.id);
|
|
255
249
|
broadcast(collection);
|
|
@@ -259,10 +253,10 @@ export const notesRouter = createRouter()
|
|
|
259
253
|
.http('notes:delete-image', {
|
|
260
254
|
data: t.Object({ imageId: t.String({ minLength: 1 }) }),
|
|
261
255
|
response: t.Object({ ok: t.Boolean() })
|
|
262
|
-
}, async ({ data
|
|
256
|
+
}, async ({ data }) => {
|
|
263
257
|
const img = noteImageQueries.getById(data.imageId);
|
|
264
258
|
if (!img) return { ok: true };
|
|
265
|
-
const collection = requireNoteCollection(
|
|
259
|
+
const collection = requireNoteCollection(img.note_id);
|
|
266
260
|
const absolute = resolveNoteImagePath(img.storage_path);
|
|
267
261
|
if (absolute) await unlink(absolute).catch(() => {});
|
|
268
262
|
noteImageQueries.delete(data.imageId);
|