@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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Files Panel State Handlers
|
|
3
3
|
*
|
|
4
|
-
* Persist per-
|
|
4
|
+
* Persist per-workspace files panel state (expanded folders, open
|
|
5
5
|
* tabs, scroll positions, view mode). Single source of truth in DB so that the
|
|
6
6
|
* state survives browser refresh and follows the user across devices.
|
|
7
7
|
*
|
|
8
|
-
* The row is per
|
|
8
|
+
* The row is per project, but the state inside it is per workspace: a
|
|
9
9
|
* project and each of its worktrees keep separate entries. Sharing one entry
|
|
10
10
|
* carried open tabs — including unsaved buffers — from the main tree into a
|
|
11
11
|
* worktree, which read as the edit having crossed between them.
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
import { t } from 'elysia';
|
|
15
15
|
import { createRouter } from '$shared/utils/ws-server';
|
|
16
16
|
import { projectQueries } from '../../database/queries/project-queries';
|
|
17
|
-
import { ws as wsServer } from '../../utils/ws';
|
|
18
17
|
import { requireProjectAccess } from '../access';
|
|
19
18
|
|
|
20
19
|
/** Stored shape: opaque per-scope state strings under one version marker. */
|
|
@@ -65,10 +64,9 @@ export const filesStateHandler = createRouter()
|
|
|
65
64
|
response: t.Object({
|
|
66
65
|
state: t.Union([t.String(), t.Null()])
|
|
67
66
|
})
|
|
68
|
-
}, async ({ data
|
|
69
|
-
requireProjectAccess(
|
|
70
|
-
const
|
|
71
|
-
const raw = projectQueries.getFilesPanelState(userId, data.projectId);
|
|
67
|
+
}, async ({ data }) => {
|
|
68
|
+
requireProjectAccess(data.projectId);
|
|
69
|
+
const raw = projectQueries.getFilesPanelState(data.projectId);
|
|
72
70
|
|
|
73
71
|
const scopeKey = data.scopeKey || data.projectId;
|
|
74
72
|
if (isLegacyState(raw)) {
|
|
@@ -85,11 +83,10 @@ export const filesStateHandler = createRouter()
|
|
|
85
83
|
state: t.Union([t.String(), t.Null()])
|
|
86
84
|
}),
|
|
87
85
|
response: t.Object({ ok: t.Boolean() })
|
|
88
|
-
}, async ({ data
|
|
89
|
-
requireProjectAccess(
|
|
90
|
-
const userId = wsServer.getUserId(conn);
|
|
86
|
+
}, async ({ data }) => {
|
|
87
|
+
requireProjectAccess(data.projectId);
|
|
91
88
|
|
|
92
|
-
const raw = projectQueries.getFilesPanelState(
|
|
89
|
+
const raw = projectQueries.getFilesPanelState(data.projectId);
|
|
93
90
|
const scopeKey = data.scopeKey || data.projectId;
|
|
94
91
|
|
|
95
92
|
// Read-modify-write so writing one workspace never drops another's entry.
|
|
@@ -99,6 +96,6 @@ export const filesStateHandler = createRouter()
|
|
|
99
96
|
if (data.state === null) delete stored.scopes[scopeKey];
|
|
100
97
|
else stored.scopes[scopeKey] = data.state;
|
|
101
98
|
|
|
102
|
-
projectQueries.setFilesPanelState(
|
|
99
|
+
projectQueries.setFilesPanelState(data.projectId, JSON.stringify(stored));
|
|
103
100
|
return { ok: true };
|
|
104
101
|
});
|
|
@@ -13,7 +13,7 @@ import { fileWatcher } from '$backend/files/file-watcher';
|
|
|
13
13
|
import { debug } from '$shared/utils/logger';
|
|
14
14
|
import { ws } from '$backend/utils/ws';
|
|
15
15
|
import { makeScopeKey } from '$shared/utils/workspace-scope';
|
|
16
|
-
import {
|
|
16
|
+
import { requireWorkspaceRoot } from './path-access';
|
|
17
17
|
import { requireProjectAccess } from '../access';
|
|
18
18
|
|
|
19
19
|
// Connection ids that already have a disconnect cleanup registered, so we
|
|
@@ -31,7 +31,7 @@ export const watchHandler = createRouter()
|
|
|
31
31
|
|
|
32
32
|
// The root may be the project or one of its worktrees; watchers are keyed
|
|
33
33
|
// per workspace so two trees of one project never share a watcher.
|
|
34
|
-
const { project, worktreeId } =
|
|
34
|
+
const { project, worktreeId } = requireWorkspaceRoot(projectPath);
|
|
35
35
|
const projectId = makeScopeKey(project.id, worktreeId);
|
|
36
36
|
|
|
37
37
|
try {
|
|
@@ -91,7 +91,7 @@ export const watchHandler = createRouter()
|
|
|
91
91
|
let projectId: string;
|
|
92
92
|
let roomProjectId: string;
|
|
93
93
|
if (data.projectPath) {
|
|
94
|
-
const { project, worktreeId } =
|
|
94
|
+
const { project, worktreeId } = requireWorkspaceRoot(data.projectPath);
|
|
95
95
|
roomProjectId = project.id;
|
|
96
96
|
projectId = makeScopeKey(project.id, worktreeId);
|
|
97
97
|
} else {
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
} from '../../files/file-operations';
|
|
25
25
|
import { createArchiveOperation, extractArchiveOperation } from '../../files/file-archive';
|
|
26
26
|
import { stat as fsStat, readdir as fsReaddir, rename as fsRename } from 'node:fs/promises';
|
|
27
|
-
import {
|
|
27
|
+
import { resolveFilePath } from './path-access';
|
|
28
28
|
|
|
29
29
|
export const writeHandler = createRouter()
|
|
30
30
|
// Write file operation
|
|
@@ -42,8 +42,8 @@ export const writeHandler = createRouter()
|
|
|
42
42
|
size: t.Number(),
|
|
43
43
|
modified: t.String()
|
|
44
44
|
})
|
|
45
|
-
}, async ({ data
|
|
46
|
-
const filePath = await
|
|
45
|
+
}, async ({ data }) => {
|
|
46
|
+
const filePath = await resolveFilePath(data.filePath);
|
|
47
47
|
debug.log('file', 'Write file operation:', {
|
|
48
48
|
filePath,
|
|
49
49
|
contentLength: data.content.length
|
|
@@ -63,8 +63,8 @@ export const writeHandler = createRouter()
|
|
|
63
63
|
size: t.Number(),
|
|
64
64
|
modified: t.String()
|
|
65
65
|
})
|
|
66
|
-
}, async ({ data
|
|
67
|
-
const filePath = await
|
|
66
|
+
}, async ({ data }) => {
|
|
67
|
+
const filePath = await resolveFilePath(data.filePath);
|
|
68
68
|
return await createFileOperation(filePath, data.content);
|
|
69
69
|
})
|
|
70
70
|
|
|
@@ -78,11 +78,10 @@ export const writeHandler = createRouter()
|
|
|
78
78
|
path: t.String(),
|
|
79
79
|
modified: t.String()
|
|
80
80
|
})
|
|
81
|
-
}, async ({ data
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
const dirPath = await requireSharedFilePathAccess(conn, data.dirPath);
|
|
81
|
+
}, async ({ data }) => {
|
|
82
|
+
// FolderBrowser creates candidate project folders here, inside or
|
|
83
|
+
// outside any existing project.
|
|
84
|
+
const dirPath = await resolveFilePath(data.dirPath);
|
|
86
85
|
return await createDirectoryOperation(dirPath);
|
|
87
86
|
})
|
|
88
87
|
|
|
@@ -98,9 +97,9 @@ export const writeHandler = createRouter()
|
|
|
98
97
|
newPath: t.String(),
|
|
99
98
|
modified: t.String()
|
|
100
99
|
})
|
|
101
|
-
}, async ({ data
|
|
102
|
-
const oldPath = await
|
|
103
|
-
const newPath = await
|
|
100
|
+
}, async ({ data }) => {
|
|
101
|
+
const oldPath = await resolveFilePath(data.oldPath);
|
|
102
|
+
const newPath = await resolveFilePath(data.newPath);
|
|
104
103
|
return await renameOperation(oldPath, newPath);
|
|
105
104
|
})
|
|
106
105
|
|
|
@@ -117,9 +116,9 @@ export const writeHandler = createRouter()
|
|
|
117
116
|
size: t.Number(),
|
|
118
117
|
modified: t.String()
|
|
119
118
|
})
|
|
120
|
-
}, async ({ data
|
|
121
|
-
const sourcePath = await
|
|
122
|
-
const targetPath = await
|
|
119
|
+
}, async ({ data }) => {
|
|
120
|
+
const sourcePath = await resolveFilePath(data.sourcePath);
|
|
121
|
+
const targetPath = await resolveFilePath(data.targetPath);
|
|
123
122
|
return await duplicateOperation(sourcePath, targetPath);
|
|
124
123
|
})
|
|
125
124
|
|
|
@@ -149,15 +148,15 @@ export const writeHandler = createRouter()
|
|
|
149
148
|
size: t.Number(),
|
|
150
149
|
modified: t.String()
|
|
151
150
|
})
|
|
152
|
-
}, async ({ data
|
|
151
|
+
}, async ({ data }) => {
|
|
153
152
|
if (data.sourcePaths.length === 0) {
|
|
154
153
|
throw new Error('At least one source path is required');
|
|
155
154
|
}
|
|
156
155
|
const resolvedSources: string[] = [];
|
|
157
156
|
for (const p of data.sourcePaths) {
|
|
158
|
-
resolvedSources.push(await
|
|
157
|
+
resolvedSources.push(await resolveFilePath(p));
|
|
159
158
|
}
|
|
160
|
-
const resolvedTarget = await
|
|
159
|
+
const resolvedTarget = await resolveFilePath(data.targetPath);
|
|
161
160
|
return await createArchiveOperation(resolvedSources, resolvedTarget, {
|
|
162
161
|
format: data.format,
|
|
163
162
|
method: data.method,
|
|
@@ -179,9 +178,9 @@ export const writeHandler = createRouter()
|
|
|
179
178
|
entries: t.Number(),
|
|
180
179
|
modified: t.String()
|
|
181
180
|
})
|
|
182
|
-
}, async ({ data
|
|
183
|
-
const archivePath = await
|
|
184
|
-
const targetDir = await
|
|
181
|
+
}, async ({ data }) => {
|
|
182
|
+
const archivePath = await resolveFilePath(data.archivePath);
|
|
183
|
+
const targetDir = await resolveFilePath(data.targetDir);
|
|
185
184
|
return await extractArchiveOperation(archivePath, targetDir, data.password);
|
|
186
185
|
})
|
|
187
186
|
|
|
@@ -195,8 +194,8 @@ export const writeHandler = createRouter()
|
|
|
195
194
|
message: t.String(),
|
|
196
195
|
path: t.String()
|
|
197
196
|
})
|
|
198
|
-
}, async ({ data
|
|
199
|
-
const filePath = await
|
|
197
|
+
}, async ({ data }) => {
|
|
198
|
+
const filePath = await resolveFilePath(data.filePath);
|
|
200
199
|
return await deleteOperation(filePath, data.force);
|
|
201
200
|
})
|
|
202
201
|
|
|
@@ -212,8 +211,8 @@ export const writeHandler = createRouter()
|
|
|
212
211
|
message: t.String(),
|
|
213
212
|
path: t.String()
|
|
214
213
|
})
|
|
215
|
-
}, async ({ data
|
|
216
|
-
const dirPath = await
|
|
214
|
+
}, async ({ data }) => {
|
|
215
|
+
const dirPath = await resolveFilePath(data.dirPath);
|
|
217
216
|
|
|
218
217
|
const stats = await fsStat(dirPath);
|
|
219
218
|
if (!stats.isDirectory()) {
|
|
@@ -228,8 +227,8 @@ export const writeHandler = createRouter()
|
|
|
228
227
|
})
|
|
229
228
|
|
|
230
229
|
// Rename a directory from FolderBrowser (e.g. fix typo on a candidate
|
|
231
|
-
// project folder). Restricted to real directories on both sides
|
|
232
|
-
//
|
|
230
|
+
// project folder). Restricted to real directories on both sides. Uses
|
|
231
|
+
// fs.rename directly
|
|
233
232
|
// because Bun.file(...).exists() returns false for directories, which
|
|
234
233
|
// makes the generic renameOperation unusable here.
|
|
235
234
|
.http('files:rename-directory', {
|
|
@@ -243,9 +242,9 @@ export const writeHandler = createRouter()
|
|
|
243
242
|
newPath: t.String(),
|
|
244
243
|
modified: t.String()
|
|
245
244
|
})
|
|
246
|
-
}, async ({ data
|
|
247
|
-
const oldPath = await
|
|
248
|
-
const newPath = await
|
|
245
|
+
}, async ({ data }) => {
|
|
246
|
+
const oldPath = await resolveFilePath(data.oldPath);
|
|
247
|
+
const newPath = await resolveFilePath(data.newPath);
|
|
249
248
|
|
|
250
249
|
let oldStats;
|
|
251
250
|
try {
|
package/backend/ws/git/branch.ts
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
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 { requireProjectWorkspace } from '../access';
|
|
10
9
|
import { identityEnvFor } from './identity-context';
|
|
11
|
-
import {
|
|
10
|
+
import { gitRepoContext, withRepoLock } from './repo-context';
|
|
12
11
|
|
|
13
12
|
const BranchSchema = t.Object({
|
|
14
13
|
name: t.String(),
|
|
@@ -32,30 +31,13 @@ const NestedRepoInfoSchema = t.Object({
|
|
|
32
31
|
ahead: t.Number(),
|
|
33
32
|
behind: t.Number(),
|
|
34
33
|
detached: t.Optional(t.Boolean()),
|
|
35
|
-
operation: t.Optional(t.Union([t.String(), t.Null()]))
|
|
34
|
+
operation: t.Optional(t.Union([t.String(), t.Null()])),
|
|
35
|
+
hasSubmodules: t.Optional(t.Boolean()),
|
|
36
|
+
hasPackageJson: t.Optional(t.Boolean())
|
|
36
37
|
}),
|
|
37
38
|
error: t.Optional(t.String())
|
|
38
39
|
});
|
|
39
40
|
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the working directory for a git operation. Defaults to the project
|
|
42
|
-
* root; when `repoPath` is provided it must already be inside the project
|
|
43
|
-
* (these paths come from the backend's own `getBranches` response, but we
|
|
44
|
-
* re-validate to defend against a tampered/mismatched client).
|
|
45
|
-
*/
|
|
46
|
-
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
47
|
-
if (!repoPath) return projectPath;
|
|
48
|
-
const resolved = path.resolve(repoPath);
|
|
49
|
-
const projectRoot = path.resolve(projectPath);
|
|
50
|
-
const sep = path.sep;
|
|
51
|
-
// Must equal project root or live strictly inside it — no `..` escape.
|
|
52
|
-
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
53
|
-
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
54
|
-
return projectPath;
|
|
55
|
-
}
|
|
56
|
-
return resolved;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
41
|
export const branchHandler = createRouter()
|
|
60
42
|
.http('git:branches', {
|
|
61
43
|
data: t.Object({
|
|
@@ -70,7 +52,9 @@ export const branchHandler = createRouter()
|
|
|
70
52
|
behind: t.Number(),
|
|
71
53
|
detached: t.Optional(t.Boolean()),
|
|
72
54
|
operation: t.Optional(t.Union([t.String(), t.Null()])),
|
|
73
|
-
nested: t.Optional(t.Array(NestedRepoInfoSchema))
|
|
55
|
+
nested: t.Optional(t.Array(NestedRepoInfoSchema)),
|
|
56
|
+
hasSubmodules: t.Optional(t.Boolean()),
|
|
57
|
+
hasPackageJson: t.Optional(t.Boolean())
|
|
74
58
|
})
|
|
75
59
|
}, async ({ data, conn }) => {
|
|
76
60
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
@@ -88,9 +72,10 @@ export const branchHandler = createRouter()
|
|
|
88
72
|
}),
|
|
89
73
|
response: t.Object({ ok: t.Boolean() })
|
|
90
74
|
}, async ({ data, conn }) => {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
76
|
+
await withRepoLock(ctx, { category: 'branch', label: 'Create branch', target: data.name }, () =>
|
|
77
|
+
gitService.createBranch(ctx.cwd, data.name, data.startPoint)
|
|
78
|
+
);
|
|
94
79
|
return { ok: true };
|
|
95
80
|
})
|
|
96
81
|
|
|
@@ -103,9 +88,10 @@ export const branchHandler = createRouter()
|
|
|
103
88
|
}),
|
|
104
89
|
response: t.Object({ ok: t.Boolean() })
|
|
105
90
|
}, async ({ data, conn }) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
92
|
+
await withRepoLock(ctx, { category: 'branch', label: 'Switch branch', target: data.name }, () =>
|
|
93
|
+
gitService.switchBranch(ctx.cwd, data.name)
|
|
94
|
+
);
|
|
109
95
|
return { ok: true };
|
|
110
96
|
})
|
|
111
97
|
|
|
@@ -117,9 +103,10 @@ export const branchHandler = createRouter()
|
|
|
117
103
|
}),
|
|
118
104
|
response: t.Object({ ok: t.Boolean() })
|
|
119
105
|
}, async ({ data, conn }) => {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
107
|
+
await withRepoLock(ctx, { category: 'branch', label: 'Checkout commit', target: data.commitHash.slice(0, 7) }, () =>
|
|
108
|
+
gitService.checkoutCommit(ctx.cwd, data.commitHash)
|
|
109
|
+
);
|
|
123
110
|
return { ok: true };
|
|
124
111
|
})
|
|
125
112
|
|
|
@@ -133,9 +120,10 @@ export const branchHandler = createRouter()
|
|
|
133
120
|
}),
|
|
134
121
|
response: t.Object({ ok: t.Boolean() })
|
|
135
122
|
}, async ({ data, conn }) => {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
123
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
124
|
+
await withRepoLock(ctx, { category: 'branch', label: 'Delete branch', target: data.name }, () =>
|
|
125
|
+
gitService.deleteBranch(ctx.cwd, data.name, data.force)
|
|
126
|
+
);
|
|
139
127
|
return { ok: true };
|
|
140
128
|
})
|
|
141
129
|
|
|
@@ -148,9 +136,10 @@ export const branchHandler = createRouter()
|
|
|
148
136
|
}),
|
|
149
137
|
response: t.Object({ ok: t.Boolean() })
|
|
150
138
|
}, async ({ data, conn }) => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
139
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
140
|
+
await withRepoLock(ctx, { category: 'branch', label: 'Rename branch', target: data.oldName }, () =>
|
|
141
|
+
gitService.renameBranch(ctx.cwd, data.oldName, data.newName)
|
|
142
|
+
);
|
|
154
143
|
return { ok: true };
|
|
155
144
|
})
|
|
156
145
|
|
|
@@ -170,17 +159,18 @@ export const branchHandler = createRouter()
|
|
|
170
159
|
message: t.String()
|
|
171
160
|
})
|
|
172
161
|
}, async ({ data, conn }) => {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
162
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
163
|
+
return await withRepoLock(ctx, { category: 'more', label: 'Merge', target: data.branchName }, () =>
|
|
164
|
+
gitService.mergeBranch(
|
|
165
|
+
ctx.cwd,
|
|
166
|
+
data.branchName,
|
|
167
|
+
{
|
|
168
|
+
noFastForward: data.noFastForward ?? false,
|
|
169
|
+
squash: data.squash ?? false,
|
|
170
|
+
ffOnly: data.ffOnly ?? false
|
|
171
|
+
},
|
|
172
|
+
identityEnvFor(data.projectId)
|
|
173
|
+
)
|
|
184
174
|
);
|
|
185
175
|
})
|
|
186
176
|
|
|
@@ -198,13 +188,9 @@ export const branchHandler = createRouter()
|
|
|
198
188
|
message: t.String()
|
|
199
189
|
})
|
|
200
190
|
}, async ({ data, conn }) => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
cwd,
|
|
205
|
-
data.upstream,
|
|
206
|
-
data.autostash ?? true,
|
|
207
|
-
identityEnvFor(conn, data.projectId)
|
|
191
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
192
|
+
return await withRepoLock(ctx, { category: 'more', label: 'Rebase', target: data.upstream }, () =>
|
|
193
|
+
gitService.rebaseOnto(ctx.cwd, data.upstream, data.autostash ?? true, identityEnvFor(data.projectId))
|
|
208
194
|
);
|
|
209
195
|
})
|
|
210
196
|
|
|
@@ -217,8 +203,43 @@ export const branchHandler = createRouter()
|
|
|
217
203
|
}),
|
|
218
204
|
response: t.Object({ ok: t.Boolean() })
|
|
219
205
|
}, async ({ data, conn }) => {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
206
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
207
|
+
await withRepoLock(ctx, { category: 'more', label: 'Return to branch' }, () =>
|
|
208
|
+
gitService.returnToBranch(ctx.cwd, data.branch)
|
|
209
|
+
);
|
|
223
210
|
return { ok: true };
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// Branches a prune would delete, for the confirmation list.
|
|
214
|
+
.http('git:prune-candidates', {
|
|
215
|
+
data: t.Object({
|
|
216
|
+
projectId: t.String(),
|
|
217
|
+
mode: t.Union([t.Literal('merged'), t.Literal('gone')]),
|
|
218
|
+
remote: t.Optional(t.String()),
|
|
219
|
+
repoPath: t.Optional(t.String())
|
|
220
|
+
}),
|
|
221
|
+
response: t.Object({
|
|
222
|
+
defaultBranch: t.Union([t.String(), t.Null()]),
|
|
223
|
+
candidates: t.Array(t.Object({ name: t.String(), merged: t.Boolean() }))
|
|
224
|
+
})
|
|
225
|
+
}, async ({ data, conn }) => {
|
|
226
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
227
|
+
return await gitService.getPruneCandidates(ctx.cwd, data.mode, data.remote);
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
.http('git:delete-branches', {
|
|
231
|
+
data: t.Object({
|
|
232
|
+
projectId: t.String(),
|
|
233
|
+
names: t.Array(t.String(), { minItems: 1 }),
|
|
234
|
+
repoPath: t.Optional(t.String())
|
|
235
|
+
}),
|
|
236
|
+
response: t.Object({
|
|
237
|
+
deleted: t.Array(t.String()),
|
|
238
|
+
failed: t.Array(t.Object({ name: t.String(), message: t.String() }))
|
|
239
|
+
})
|
|
240
|
+
}, async ({ data, conn }) => {
|
|
241
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
242
|
+
return await withRepoLock(ctx, { category: 'branch', label: 'Prune branches' }, () =>
|
|
243
|
+
gitService.deleteBranches(ctx.cwd, data.names)
|
|
244
|
+
);
|
|
224
245
|
});
|
package/backend/ws/git/commit.ts
CHANGED
|
@@ -3,28 +3,10 @@
|
|
|
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
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { debug } from '$shared/utils/logger';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the working directory for a git operation. Defaults to the project
|
|
15
|
-
* root; when `repoPath` is provided it must already be inside the project.
|
|
16
|
-
*/
|
|
17
|
-
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
18
|
-
if (!repoPath) return projectPath;
|
|
19
|
-
const resolved = path.resolve(repoPath);
|
|
20
|
-
const projectRoot = path.resolve(projectPath);
|
|
21
|
-
const sep = path.sep;
|
|
22
|
-
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
23
|
-
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
24
|
-
return projectPath;
|
|
25
|
-
}
|
|
26
|
-
return resolved;
|
|
27
|
-
}
|
|
8
|
+
import { identityEnvFor, identityEnvForRemote } from './identity-context';
|
|
9
|
+
import { gitRepoContext, withRepoLock } from './repo-context';
|
|
28
10
|
|
|
29
11
|
export const commitHandler = createRouter()
|
|
30
12
|
.http('git:commit', {
|
|
@@ -37,9 +19,10 @@ export const commitHandler = createRouter()
|
|
|
37
19
|
hash: t.String()
|
|
38
20
|
})
|
|
39
21
|
}, async ({ data, conn }) => {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
22
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
23
|
+
const hash = await withRepoLock(ctx, { category: 'commit', label: 'Commit' }, () =>
|
|
24
|
+
gitService.commit(ctx.cwd, data.message, identityEnvFor(data.projectId))
|
|
25
|
+
);
|
|
43
26
|
return { hash };
|
|
44
27
|
})
|
|
45
28
|
|
|
@@ -53,9 +36,10 @@ export const commitHandler = createRouter()
|
|
|
53
36
|
hash: t.String()
|
|
54
37
|
})
|
|
55
38
|
}, async ({ data, conn }) => {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
39
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
40
|
+
const hash = await withRepoLock(ctx, { category: 'commit', label: 'Amend' }, () =>
|
|
41
|
+
gitService.amendCommit(ctx.cwd, data.message, identityEnvFor(data.projectId))
|
|
42
|
+
);
|
|
59
43
|
return { hash };
|
|
60
44
|
})
|
|
61
45
|
|
|
@@ -67,9 +51,10 @@ export const commitHandler = createRouter()
|
|
|
67
51
|
}),
|
|
68
52
|
response: t.Object({ ok: t.Boolean() })
|
|
69
53
|
}, async ({ data, conn }) => {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
55
|
+
await withRepoLock(ctx, { category: 'more', label: 'Undo commit' }, () =>
|
|
56
|
+
gitService.undoLastCommit(ctx.cwd, data.mode)
|
|
57
|
+
);
|
|
73
58
|
return { ok: true };
|
|
74
59
|
})
|
|
75
60
|
|
|
@@ -84,9 +69,10 @@ export const commitHandler = createRouter()
|
|
|
84
69
|
message: t.String()
|
|
85
70
|
})
|
|
86
71
|
}, async ({ data, conn }) => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
73
|
+
return await withRepoLock(ctx, { category: 'more', label: 'Revert' }, () =>
|
|
74
|
+
gitService.revertCommit(ctx.cwd, data.ref, identityEnvFor(data.projectId))
|
|
75
|
+
);
|
|
90
76
|
})
|
|
91
77
|
|
|
92
78
|
.http('git:cherry-pick', {
|
|
@@ -100,21 +86,25 @@ export const commitHandler = createRouter()
|
|
|
100
86
|
message: t.String()
|
|
101
87
|
})
|
|
102
88
|
}, async ({ data, conn }) => {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
89
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
90
|
+
return await withRepoLock(ctx, { category: 'more', label: 'Cherry-pick' }, () =>
|
|
91
|
+
gitService.cherryPick(ctx.cwd, data.hashes, identityEnvFor(data.projectId))
|
|
92
|
+
);
|
|
106
93
|
})
|
|
107
94
|
|
|
108
95
|
.http('git:clean', {
|
|
109
96
|
data: t.Object({
|
|
110
97
|
projectId: t.String(),
|
|
98
|
+
/** Also delete ignored files (`-x`) — node_modules, build output, .env. */
|
|
99
|
+
includeIgnored: t.Optional(t.Boolean()),
|
|
111
100
|
repoPath: t.Optional(t.String())
|
|
112
101
|
}),
|
|
113
102
|
response: t.Object({ message: t.String() })
|
|
114
103
|
}, async ({ data, conn }) => {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
104
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
105
|
+
const message = await withRepoLock(ctx, { category: 'more', label: 'Clean' }, () =>
|
|
106
|
+
gitService.cleanUntracked(ctx.cwd, data.includeIgnored)
|
|
107
|
+
);
|
|
118
108
|
return { message };
|
|
119
109
|
})
|
|
120
110
|
|
|
@@ -125,9 +115,10 @@ export const commitHandler = createRouter()
|
|
|
125
115
|
}),
|
|
126
116
|
response: t.Object({ message: t.String() })
|
|
127
117
|
}, async ({ data, conn }) => {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
118
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
119
|
+
const message = await withRepoLock(ctx, { category: 'more', label: 'Optimize repository' }, () =>
|
|
120
|
+
gitService.optimize(ctx.cwd)
|
|
121
|
+
);
|
|
131
122
|
return { message };
|
|
132
123
|
})
|
|
133
124
|
|
|
@@ -143,7 +134,35 @@ export const commitHandler = createRouter()
|
|
|
143
134
|
message: t.String()
|
|
144
135
|
})
|
|
145
136
|
}, async ({ data, conn }) => {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
138
|
+
return await withRepoLock(ctx, { category: 'more', label: `npm version ${data.bump}` }, () =>
|
|
139
|
+
gitService.npmVersion(ctx.cwd, data.bump, identityEnvFor(data.projectId))
|
|
140
|
+
);
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Dry run of `git:clean`, so the confirmation can name what will be deleted.
|
|
144
|
+
.http('git:clean-preview', {
|
|
145
|
+
data: t.Object({
|
|
146
|
+
projectId: t.String(),
|
|
147
|
+
includeIgnored: t.Optional(t.Boolean()),
|
|
148
|
+
repoPath: t.Optional(t.String())
|
|
149
|
+
}),
|
|
150
|
+
response: t.Object({ paths: t.Array(t.String()) })
|
|
151
|
+
}, async ({ data, conn }) => {
|
|
152
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
153
|
+
return { paths: await gitService.cleanPreview(ctx.cwd, data.includeIgnored) };
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
.http('git:submodule-update', {
|
|
157
|
+
data: t.Object({
|
|
158
|
+
projectId: t.String(),
|
|
159
|
+
repoPath: t.Optional(t.String())
|
|
160
|
+
}),
|
|
161
|
+
response: t.Object({ message: t.String() })
|
|
162
|
+
}, async ({ data, conn }) => {
|
|
163
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
164
|
+
const message = await withRepoLock(ctx, { category: 'more', label: 'Update submodules' }, async () =>
|
|
165
|
+
gitService.updateSubmodules(ctx.cwd, await identityEnvForRemote(data.projectId, ctx.cwd))
|
|
166
|
+
);
|
|
167
|
+
return { message };
|
|
149
168
|
});
|