@myrialabs/clopen 0.4.46 → 0.4.48
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/stream-manager.ts +62 -62
- 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.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- 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 +13 -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/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/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -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/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- 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/index.ts +21 -7
- 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 +361 -25
- 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/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- 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 +64 -47
- 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/opencode/providers.ts +2 -1
- 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 +15 -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/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 +29 -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 +27 -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 +34 -45
- 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 +7 -7
- 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/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 +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- 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 +2 -4
- 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/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- 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
|
@@ -9,6 +9,7 @@ import { gitService } from '../../git/git-service';
|
|
|
9
9
|
import { findNestedRepoPaths, findRepoForFile } from '../../git/nested-repos';
|
|
10
10
|
import { requireProjectWorkspace } from '../access';
|
|
11
11
|
import { identityEnvFor } from './identity-context';
|
|
12
|
+
import { gitRepoContext, withRepoLock } from './repo-context';
|
|
12
13
|
import { debug } from '$shared/utils/logger';
|
|
13
14
|
|
|
14
15
|
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
|
|
@@ -130,13 +131,10 @@ export const conflictHandler = createRouter()
|
|
|
130
131
|
}, async ({ data, conn }) => {
|
|
131
132
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
132
133
|
const repo = await findRepoForFile(root, data.filePath);
|
|
133
|
-
const
|
|
134
|
+
const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
|
|
134
135
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
135
|
-
await
|
|
136
|
-
cwd,
|
|
137
|
-
filePath,
|
|
138
|
-
data.resolution,
|
|
139
|
-
data.customContent
|
|
136
|
+
await withRepoLock(ctx, { category: 'resolve', label: 'Resolve conflict', target: data.filePath, queue: true }, () =>
|
|
137
|
+
gitService.resolveConflict(ctx.cwd, filePath, data.resolution, data.customContent)
|
|
140
138
|
);
|
|
141
139
|
return { ok: true };
|
|
142
140
|
})
|
|
@@ -166,9 +164,10 @@ export const conflictHandler = createRouter()
|
|
|
166
164
|
}),
|
|
167
165
|
response: t.Object({ success: t.Boolean(), message: t.String() })
|
|
168
166
|
}, async ({ data, conn }) => {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
168
|
+
return await withRepoLock(ctx, { category: 'resolve', label: 'Continue' }, () =>
|
|
169
|
+
gitService.continueOperation(ctx.cwd, identityEnvFor(data.projectId))
|
|
170
|
+
);
|
|
172
171
|
})
|
|
173
172
|
|
|
174
173
|
.http('git:skip-operation', {
|
|
@@ -178,9 +177,10 @@ export const conflictHandler = createRouter()
|
|
|
178
177
|
}),
|
|
179
178
|
response: t.Object({ success: t.Boolean(), message: t.String() })
|
|
180
179
|
}, async ({ data, conn }) => {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
181
|
+
return await withRepoLock(ctx, { category: 'resolve', label: 'Skip' }, () =>
|
|
182
|
+
gitService.skipOperation(ctx.cwd, identityEnvFor(data.projectId))
|
|
183
|
+
);
|
|
184
184
|
})
|
|
185
185
|
|
|
186
186
|
.http('git:abort-operation', {
|
|
@@ -190,9 +190,8 @@ export const conflictHandler = createRouter()
|
|
|
190
190
|
}),
|
|
191
191
|
response: t.Object({ ok: t.Boolean() })
|
|
192
192
|
}, async ({ data, conn }) => {
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
await gitService.abortOperation(cwd);
|
|
193
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
194
|
+
await withRepoLock(ctx, { category: 'resolve', label: 'Abort' }, () => gitService.abortOperation(ctx.cwd));
|
|
196
195
|
return { ok: true };
|
|
197
196
|
})
|
|
198
197
|
|
|
@@ -204,8 +203,7 @@ export const conflictHandler = createRouter()
|
|
|
204
203
|
}),
|
|
205
204
|
response: t.Object({ ok: t.Boolean() })
|
|
206
205
|
}, async ({ data, conn }) => {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
await gitService.abortOperation(cwd);
|
|
206
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
207
|
+
await withRepoLock(ctx, { category: 'resolve', label: 'Abort' }, () => gitService.abortOperation(ctx.cwd));
|
|
210
208
|
return { ok: true };
|
|
211
209
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The bridge from a
|
|
2
|
+
* The bridge from a git route to the project's git identity.
|
|
3
3
|
*
|
|
4
|
-
* Handlers already know the project (`data.projectId`);
|
|
5
|
-
*
|
|
6
|
-
* owned by a person and chosen per project, so neither alone identifies one.
|
|
4
|
+
* Handlers already know the project (`data.projectId`); the identity is chosen
|
|
5
|
+
* per project, falling back to the default.
|
|
7
6
|
*
|
|
8
|
-
* Every helper here degrades to `{}` rather than throwing.
|
|
9
|
-
*
|
|
7
|
+
* Every helper here degrades to `{}` rather than throwing. No identity, an
|
|
8
|
+
* unreadable row, a project that was never bound — all of them
|
|
10
9
|
* mean "run git the way Clopen always did", which is a working commit, not an
|
|
11
10
|
* error dialog.
|
|
12
11
|
*/
|
|
@@ -14,8 +13,6 @@
|
|
|
14
13
|
import { resolveGitEnv } from '$backend/git/identity';
|
|
15
14
|
import { gitService } from '$backend/git/git-service';
|
|
16
15
|
import type { GitIdentityEnv } from '$backend/git/git-executor';
|
|
17
|
-
import { ws } from '$backend/utils/ws';
|
|
18
|
-
import type { WSConnection } from '$shared/utils/ws-server';
|
|
19
16
|
import { debug } from '$shared/utils/logger';
|
|
20
17
|
|
|
21
18
|
/**
|
|
@@ -24,11 +21,9 @@ import { debug } from '$shared/utils/logger';
|
|
|
24
21
|
* For commits, merges, stashes, tags — anything that writes a git object
|
|
25
22
|
* without reaching the network.
|
|
26
23
|
*/
|
|
27
|
-
export function identityEnvFor(
|
|
24
|
+
export function identityEnvFor(projectId: string): GitIdentityEnv {
|
|
28
25
|
try {
|
|
29
|
-
|
|
30
|
-
if (!userId) return {};
|
|
31
|
-
return resolveGitEnv(projectId, userId);
|
|
26
|
+
return resolveGitEnv(projectId);
|
|
32
27
|
} catch (error) {
|
|
33
28
|
debug.warn('git', 'Could not resolve a git identity for this connection:', error);
|
|
34
29
|
return {};
|
|
@@ -48,17 +43,13 @@ export function identityEnvFor(conn: WSConnection, projectId: string): GitIdenti
|
|
|
48
43
|
* behaviour as before this feature.
|
|
49
44
|
*/
|
|
50
45
|
export async function identityEnvForRemote(
|
|
51
|
-
conn: WSConnection,
|
|
52
46
|
projectId: string,
|
|
53
47
|
cwd: string,
|
|
54
48
|
remoteName?: string
|
|
55
49
|
): Promise<GitIdentityEnv> {
|
|
56
50
|
try {
|
|
57
|
-
const userId = ws.getUserId(conn);
|
|
58
|
-
if (!userId) return {};
|
|
59
|
-
|
|
60
51
|
const url = await remoteUrl(cwd, remoteName);
|
|
61
|
-
return resolveGitEnv(projectId,
|
|
52
|
+
return resolveGitEnv(projectId, url);
|
|
62
53
|
} catch (error) {
|
|
63
54
|
debug.warn('git', 'Could not resolve a git identity for this remote:', error);
|
|
64
55
|
return {};
|
|
@@ -15,7 +15,6 @@ import { t } from 'elysia';
|
|
|
15
15
|
import { createRouter } from '$shared/utils/ws-server';
|
|
16
16
|
import { gitIdentityService, describeIdentity } from '$backend/git/identity';
|
|
17
17
|
import { requireProjectWorkspace } from '../access';
|
|
18
|
-
import { ws } from '$backend/utils/ws';
|
|
19
18
|
import { gitService } from '$backend/git/git-service';
|
|
20
19
|
import { debug } from '$shared/utils/logger';
|
|
21
20
|
import type { GitIdentityAuthMethod } from '$shared/types/git-identity';
|
|
@@ -71,26 +70,19 @@ const INPUT = t.Object({
|
|
|
71
70
|
isDefault: t.Optional(t.Boolean())
|
|
72
71
|
});
|
|
73
72
|
|
|
74
|
-
/** The owner of this connection. Throws when unauthenticated. */
|
|
75
|
-
function requireUserId(conn: Parameters<typeof ws.getUserId>[0]): string {
|
|
76
|
-
const userId = ws.getUserId(conn);
|
|
77
|
-
if (!userId) throw new Error('Authentication required');
|
|
78
|
-
return userId;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
73
|
export const gitIdentityHandler = createRouter()
|
|
82
74
|
.http('git:identities', {
|
|
83
75
|
data: t.Object({}),
|
|
84
76
|
response: t.Object({ identities: t.Array(IDENTITY) })
|
|
85
|
-
}, async (
|
|
86
|
-
return { identities: await gitIdentityService.list(
|
|
77
|
+
}, async () => {
|
|
78
|
+
return { identities: await gitIdentityService.list() };
|
|
87
79
|
})
|
|
88
80
|
|
|
89
81
|
.http('git:identity-create', {
|
|
90
82
|
data: INPUT,
|
|
91
83
|
response: t.Object({ identity: IDENTITY })
|
|
92
|
-
}, async ({ data
|
|
93
|
-
const identity = await gitIdentityService.create(
|
|
84
|
+
}, async ({ data }) => {
|
|
85
|
+
const identity = await gitIdentityService.create({
|
|
94
86
|
...data,
|
|
95
87
|
authMethod: data.authMethod as GitIdentityAuthMethod
|
|
96
88
|
});
|
|
@@ -100,9 +92,9 @@ export const gitIdentityHandler = createRouter()
|
|
|
100
92
|
.http('git:identity-update', {
|
|
101
93
|
data: t.Intersect([INPUT, t.Object({ id: t.String() })]),
|
|
102
94
|
response: t.Object({ identity: IDENTITY })
|
|
103
|
-
}, async ({ data
|
|
95
|
+
}, async ({ data }) => {
|
|
104
96
|
const { id, ...input } = data;
|
|
105
|
-
const identity = await gitIdentityService.update(
|
|
97
|
+
const identity = await gitIdentityService.update(id, {
|
|
106
98
|
...input,
|
|
107
99
|
authMethod: input.authMethod as GitIdentityAuthMethod
|
|
108
100
|
});
|
|
@@ -112,16 +104,16 @@ export const gitIdentityHandler = createRouter()
|
|
|
112
104
|
.http('git:identity-delete', {
|
|
113
105
|
data: t.Object({ id: t.String() }),
|
|
114
106
|
response: t.Object({ ok: t.Boolean() })
|
|
115
|
-
}, async ({ data
|
|
116
|
-
await gitIdentityService.remove(
|
|
107
|
+
}, async ({ data }) => {
|
|
108
|
+
await gitIdentityService.remove(data.id);
|
|
117
109
|
return { ok: true };
|
|
118
110
|
})
|
|
119
111
|
|
|
120
112
|
.http('git:identity-set-default', {
|
|
121
113
|
data: t.Object({ id: t.String() }),
|
|
122
114
|
response: t.Object({ identity: IDENTITY })
|
|
123
|
-
}, async ({ data
|
|
124
|
-
return { identity: await gitIdentityService.setDefault(
|
|
115
|
+
}, async ({ data }) => {
|
|
116
|
+
return { identity: await gitIdentityService.setDefault(data.id) };
|
|
125
117
|
})
|
|
126
118
|
|
|
127
119
|
/**
|
|
@@ -133,16 +125,15 @@ export const gitIdentityHandler = createRouter()
|
|
|
133
125
|
.http('git:identity-generate-key', {
|
|
134
126
|
data: t.Object({ id: t.String() }),
|
|
135
127
|
response: t.Object({ publicKey: t.String(), fingerprint: t.String() })
|
|
136
|
-
}, async ({ data
|
|
137
|
-
return await gitIdentityService.generateKey(
|
|
128
|
+
}, async ({ data }) => {
|
|
129
|
+
return await gitIdentityService.generateKey(data.id);
|
|
138
130
|
})
|
|
139
131
|
|
|
140
132
|
/** How many projects would lose their binding if this identity went away. */
|
|
141
133
|
.http('git:identity-usage', {
|
|
142
134
|
data: t.Object({ id: t.String() }),
|
|
143
135
|
response: t.Object({ projectCount: t.Number() })
|
|
144
|
-
}, async ({ data
|
|
145
|
-
requireUserId(conn);
|
|
136
|
+
}, async ({ data }) => {
|
|
146
137
|
return { projectCount: gitIdentityService.bindingCount(data.id) };
|
|
147
138
|
})
|
|
148
139
|
|
|
@@ -156,7 +147,7 @@ export const gitIdentityHandler = createRouter()
|
|
|
156
147
|
}, async ({ data, conn }) => {
|
|
157
148
|
// Access is the project's call, exactly as for every other git operation.
|
|
158
149
|
requireProjectWorkspace(conn, data.projectId);
|
|
159
|
-
await gitIdentityService.bind(
|
|
150
|
+
await gitIdentityService.bind(data.projectId, data.identityId);
|
|
160
151
|
return { ok: true };
|
|
161
152
|
})
|
|
162
153
|
|
|
@@ -164,7 +155,7 @@ export const gitIdentityHandler = createRouter()
|
|
|
164
155
|
* Who the next commit in this project will be attributed to.
|
|
165
156
|
*
|
|
166
157
|
* Drives the line above the commit box. `source` distinguishes an identity
|
|
167
|
-
* chosen for this project from one inherited as the
|
|
158
|
+
* chosen for this project from one inherited as the default, which is
|
|
168
159
|
* the difference between "this is right" and "check this before you push".
|
|
169
160
|
*/
|
|
170
161
|
.http('git:identity-resolved', {
|
|
@@ -175,12 +166,11 @@ export const gitIdentityHandler = createRouter()
|
|
|
175
166
|
}),
|
|
176
167
|
response: t.Object({
|
|
177
168
|
identity: t.Union([IDENTITY, t.Null()]),
|
|
178
|
-
source: t.Union([t.Literal('project'), t.Literal('
|
|
169
|
+
source: t.Union([t.Literal('project'), t.Literal('default'), t.Literal('none')]),
|
|
179
170
|
credentialIdentity: t.Union([IDENTITY, t.Null()])
|
|
180
171
|
})
|
|
181
172
|
}, async ({ data, conn }) => {
|
|
182
173
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
183
|
-
const userId = requireUserId(conn);
|
|
184
174
|
|
|
185
175
|
// The remote URL decides which identity's credential answers, so it is
|
|
186
176
|
// resolved here too — a fork whose origin and upstream sit on different
|
|
@@ -196,5 +186,5 @@ export const gitIdentityHandler = createRouter()
|
|
|
196
186
|
debug.log('git', 'No remotes to resolve an identity credential against:', error);
|
|
197
187
|
}
|
|
198
188
|
|
|
199
|
-
return describeIdentity(data.projectId,
|
|
189
|
+
return describeIdentity(data.projectId, remoteUrl);
|
|
200
190
|
});
|
package/backend/ws/git/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { commitMessageHandler } from './commit-message';
|
|
|
16
16
|
import { branchNameHandler } from './branch-name';
|
|
17
17
|
import { ignoredHandler } from './ignored';
|
|
18
18
|
import { gitIdentityHandler } from './identity';
|
|
19
|
+
import { opStateHandler } from './op-state';
|
|
19
20
|
|
|
20
21
|
export const gitRouter = createRouter()
|
|
21
22
|
.merge(statusHandler)
|
|
@@ -29,4 +30,5 @@ export const gitRouter = createRouter()
|
|
|
29
30
|
.merge(commitMessageHandler)
|
|
30
31
|
.merge(branchNameHandler)
|
|
31
32
|
.merge(ignoredHandler)
|
|
32
|
-
.merge(gitIdentityHandler)
|
|
33
|
+
.merge(gitIdentityHandler)
|
|
34
|
+
.merge(opStateHandler);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Operation State Handler
|
|
3
|
+
*
|
|
4
|
+
* Publishes the per-repository operation lock (`backend/git/op-lock.ts`) so
|
|
5
|
+
* every client renders the same busy state, and handles the one recovery the
|
|
6
|
+
* lock cannot prevent: a lockfile left behind by a git process that died.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { t } from 'elysia';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { stat, unlink } from 'node:fs/promises';
|
|
12
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
13
|
+
import { scopeProjectId } from '$shared/utils/workspace-scope';
|
|
14
|
+
import { debug } from '$shared/utils/logger';
|
|
15
|
+
import { ws } from '$backend/utils/ws';
|
|
16
|
+
import { getScopeOpStates, hasProjectOps, onGitOpChange } from '../../git/op-lock';
|
|
17
|
+
import { gitRepoContext } from './repo-context';
|
|
18
|
+
import type { GitLockStatus } from '$shared/types/git';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A lockfile younger than this probably belongs to a live git process — a
|
|
22
|
+
* terminal, an agent, an IDE — that will release it on its own.
|
|
23
|
+
*/
|
|
24
|
+
const STALE_LOCK_AGE_MS = 10_000;
|
|
25
|
+
|
|
26
|
+
const ActiveOpSchema = t.Object({
|
|
27
|
+
id: t.String(),
|
|
28
|
+
category: t.Union([
|
|
29
|
+
t.Literal('commit'),
|
|
30
|
+
t.Literal('staging'),
|
|
31
|
+
t.Literal('push'),
|
|
32
|
+
t.Literal('pull'),
|
|
33
|
+
t.Literal('fetch'),
|
|
34
|
+
t.Literal('more'),
|
|
35
|
+
t.Literal('stash'),
|
|
36
|
+
t.Literal('tag'),
|
|
37
|
+
t.Literal('branch'),
|
|
38
|
+
t.Literal('resolve'),
|
|
39
|
+
t.Literal('configure')
|
|
40
|
+
]),
|
|
41
|
+
cls: t.Union([t.Literal('exclusive'), t.Literal('network'), t.Literal('index')]),
|
|
42
|
+
label: t.String(),
|
|
43
|
+
target: t.Optional(t.String()),
|
|
44
|
+
startedAt: t.Number()
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const RepoOpStateSchema = t.Object({
|
|
48
|
+
scope: t.String(),
|
|
49
|
+
repoPath: t.Optional(t.String()),
|
|
50
|
+
ops: t.Array(ActiveOpSchema)
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
onGitOpChange((state) => {
|
|
54
|
+
ws.emit.project(scopeProjectId(state.scope), 'git:op-state', state);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The lock path from a git error, validated to be a `.lock` file inside a git
|
|
59
|
+
* directory of this project. Everything else is refused: this endpoint deletes
|
|
60
|
+
* files, so it must never accept an arbitrary path.
|
|
61
|
+
*/
|
|
62
|
+
function validateLockPath(lockPath: string, roots: string[]): string {
|
|
63
|
+
const resolved = path.resolve(lockPath);
|
|
64
|
+
const segments = resolved.split(path.sep);
|
|
65
|
+
if (!resolved.endsWith('.lock') || !segments.includes('.git')) {
|
|
66
|
+
throw new Error('Not a git lock file.');
|
|
67
|
+
}
|
|
68
|
+
const inside = roots.some(root => {
|
|
69
|
+
const base = path.resolve(root);
|
|
70
|
+
return resolved.startsWith(base + path.sep);
|
|
71
|
+
});
|
|
72
|
+
if (!inside) throw new Error('The lock file is outside this project.');
|
|
73
|
+
return resolved;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function inspectLock(projectId: string, lockPath: string): Promise<GitLockStatus> {
|
|
77
|
+
const clopenOpRunning = hasProjectOps(projectId);
|
|
78
|
+
try {
|
|
79
|
+
const info = await stat(lockPath);
|
|
80
|
+
const ageMs = Math.max(0, Date.now() - info.mtimeMs);
|
|
81
|
+
return {
|
|
82
|
+
exists: true,
|
|
83
|
+
ageMs,
|
|
84
|
+
clopenOpRunning,
|
|
85
|
+
removable: !clopenOpRunning && ageMs >= STALE_LOCK_AGE_MS
|
|
86
|
+
};
|
|
87
|
+
} catch {
|
|
88
|
+
return { exists: false, ageMs: 0, clopenOpRunning, removable: false };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const LockStatusSchema = t.Object({
|
|
93
|
+
exists: t.Boolean(),
|
|
94
|
+
ageMs: t.Number(),
|
|
95
|
+
clopenOpRunning: t.Boolean(),
|
|
96
|
+
removable: t.Boolean()
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const opStateHandler = createRouter()
|
|
100
|
+
// Every operation running in the connection's workspace — read on mount,
|
|
101
|
+
// on workspace switch and after a reconnect, when events may have been missed.
|
|
102
|
+
.http('git:op-states', {
|
|
103
|
+
data: t.Object({ projectId: t.String() }),
|
|
104
|
+
response: t.Array(RepoOpStateSchema)
|
|
105
|
+
}, async ({ data, conn }) => {
|
|
106
|
+
const ctx = gitRepoContext(conn, data.projectId);
|
|
107
|
+
return getScopeOpStates(ctx.scope);
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
.http('git:lock-status', {
|
|
111
|
+
data: t.Object({ projectId: t.String(), lockPath: t.String({ minLength: 1 }) }),
|
|
112
|
+
response: LockStatusSchema
|
|
113
|
+
}, async ({ data, conn }) => {
|
|
114
|
+
const ctx = gitRepoContext(conn, data.projectId);
|
|
115
|
+
const lockPath = validateLockPath(data.lockPath, [ctx.root, ctx.projectRoot]);
|
|
116
|
+
return inspectLock(ctx.projectId, lockPath);
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
.http('git:remove-stale-lock', {
|
|
120
|
+
data: t.Object({ projectId: t.String(), lockPath: t.String({ minLength: 1 }) }),
|
|
121
|
+
response: t.Object({ ok: t.Boolean() })
|
|
122
|
+
}, async ({ data, conn }) => {
|
|
123
|
+
const ctx = gitRepoContext(conn, data.projectId);
|
|
124
|
+
const lockPath = validateLockPath(data.lockPath, [ctx.root, ctx.projectRoot]);
|
|
125
|
+
// Re-check at the moment of deletion: the status the client saw may be old.
|
|
126
|
+
const status = await inspectLock(ctx.projectId, lockPath);
|
|
127
|
+
if (!status.exists) return { ok: true };
|
|
128
|
+
if (status.clopenOpRunning) {
|
|
129
|
+
throw new Error('A git operation started by Clopen is still running — wait for it to finish.');
|
|
130
|
+
}
|
|
131
|
+
if (!status.removable) {
|
|
132
|
+
throw new Error('The lock was written moments ago, so another git process is probably still using it. Try again shortly.');
|
|
133
|
+
}
|
|
134
|
+
await unlink(lockPath);
|
|
135
|
+
debug.warn('git', `Removed stale git lock file: ${lockPath}`);
|
|
136
|
+
return { ok: true };
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
.emit('git:op-state', RepoOpStateSchema);
|