@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
|
@@ -64,14 +64,9 @@ async function runInSandbox(
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const PRELUDE = `
|
|
67
|
-
import { initializeDatabase
|
|
67
|
+
import { initializeDatabase } from '$backend/database';
|
|
68
68
|
import { gitIdentityService } from '$backend/git/identity';
|
|
69
69
|
await initializeDatabase();
|
|
70
|
-
const now = new Date().toISOString();
|
|
71
|
-
getDatabase().prepare(
|
|
72
|
-
\`INSERT INTO users (id, name, color, avatar, role, created_at, updated_at)
|
|
73
|
-
VALUES ('u1', 'User', '#fff', 'a', 'admin', ?, ?)\`
|
|
74
|
-
).run(now, now);
|
|
75
70
|
`;
|
|
76
71
|
|
|
77
72
|
describe('mirroring the machine git identity', () => {
|
|
@@ -85,7 +80,7 @@ describe('mirroring the machine git identity', () => {
|
|
|
85
80
|
|
|
86
81
|
const result = await runInSandbox(
|
|
87
82
|
`${PRELUDE}
|
|
88
|
-
const list = await gitIdentityService.list(
|
|
83
|
+
const list = await gitIdentityService.list();
|
|
89
84
|
console.log(JSON.stringify(list.map((i) => ({
|
|
90
85
|
label: i.label, name: i.name, email: i.email,
|
|
91
86
|
isDefault: i.isDefault, source: i.source, canDelete: i.canDelete
|
|
@@ -117,9 +112,9 @@ describe('mirroring the machine git identity', () => {
|
|
|
117
112
|
|
|
118
113
|
const result = await runInSandbox(
|
|
119
114
|
`${PRELUDE}
|
|
120
|
-
await gitIdentityService.list(
|
|
121
|
-
await gitIdentityService.list(
|
|
122
|
-
const list = await gitIdentityService.list(
|
|
115
|
+
await gitIdentityService.list();
|
|
116
|
+
await gitIdentityService.list();
|
|
117
|
+
const list = await gitIdentityService.list();
|
|
123
118
|
console.log(JSON.stringify({ count: list.length }));`,
|
|
124
119
|
{ home, dataDir }
|
|
125
120
|
);
|
|
@@ -137,11 +132,11 @@ describe('mirroring the machine git identity', () => {
|
|
|
137
132
|
|
|
138
133
|
const result = await runInSandbox(
|
|
139
134
|
`${PRELUDE}
|
|
140
|
-
const [mirrored] = await gitIdentityService.list(
|
|
135
|
+
const [mirrored] = await gitIdentityService.list();
|
|
141
136
|
let error = null;
|
|
142
|
-
try { await gitIdentityService.remove(
|
|
137
|
+
try { await gitIdentityService.remove(mirrored.id); }
|
|
143
138
|
catch (e) { error = e instanceof Error ? e.message : String(e); }
|
|
144
|
-
const after = await gitIdentityService.list(
|
|
139
|
+
const after = await gitIdentityService.list();
|
|
145
140
|
console.log(JSON.stringify({ error, stillThere: after.length }));`,
|
|
146
141
|
{ home, dataDir }
|
|
147
142
|
);
|
|
@@ -162,8 +157,8 @@ describe('mirroring the machine git identity', () => {
|
|
|
162
157
|
|
|
163
158
|
const result = await runInSandbox(
|
|
164
159
|
`${PRELUDE}
|
|
165
|
-
const [mirrored] = await gitIdentityService.list(
|
|
166
|
-
const updated = await gitIdentityService.update(
|
|
160
|
+
const [mirrored] = await gitIdentityService.list();
|
|
161
|
+
const updated = await gitIdentityService.update(mirrored.id, {
|
|
167
162
|
label: 'Renamed', name: 'Edited Name', email: 'edited@example.com',
|
|
168
163
|
authMethod: 'none', hosts: []
|
|
169
164
|
});
|
|
@@ -189,7 +184,7 @@ describe('mirroring the machine git identity', () => {
|
|
|
189
184
|
|
|
190
185
|
const result = await runInSandbox(
|
|
191
186
|
`${PRELUDE}
|
|
192
|
-
const list = await gitIdentityService.list(
|
|
187
|
+
const list = await gitIdentityService.list();
|
|
193
188
|
console.log(JSON.stringify({ count: list.length }));`,
|
|
194
189
|
{ home, dataDir }
|
|
195
190
|
);
|
|
@@ -77,10 +77,10 @@ export async function readMachineIdentity(): Promise<MachineIdentity | null> {
|
|
|
77
77
|
/**
|
|
78
78
|
* A label that says where the row came from without pretending to be a choice.
|
|
79
79
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
80
|
+
* Labels are unique, so a collision with a manual identity called "This
|
|
81
|
+
* machine" has to be resolved rather than thrown.
|
|
82
82
|
*/
|
|
83
|
-
function machineLabel(
|
|
83
|
+
function machineLabel(taken: (label: string) => boolean): string {
|
|
84
84
|
const base = 'This machine';
|
|
85
85
|
if (!taken(base)) return base;
|
|
86
86
|
for (let i = 2; i < 50; i++) {
|
|
@@ -88,20 +88,20 @@ function machineLabel(userId: string, taken: (label: string) => boolean): string
|
|
|
88
88
|
if (!taken(candidate)) return candidate;
|
|
89
89
|
}
|
|
90
90
|
// Practically unreachable; a unique suffix beats failing the whole list read.
|
|
91
|
-
return `${base} ${
|
|
91
|
+
return `${base} ${randomUUID().slice(0, 6)}`;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Ensure the
|
|
95
|
+
* Ensure the identity list reflects the machine's git config.
|
|
96
96
|
*
|
|
97
97
|
* Returns the mirrored row, or null when the machine has nothing to mirror.
|
|
98
98
|
* Never throws: this runs on the read path for Settings, and a failure to mirror
|
|
99
99
|
* must not take the whole list with it.
|
|
100
100
|
*/
|
|
101
|
-
export async function syncLocalMachineIdentity(
|
|
101
|
+
export async function syncLocalMachineIdentity(): Promise<GitIdentityRow | null> {
|
|
102
102
|
try {
|
|
103
103
|
const machine = await readMachineIdentity();
|
|
104
|
-
const existing = gitIdentityQueries.getLocalMachine(
|
|
104
|
+
const existing = gitIdentityQueries.getLocalMachine();
|
|
105
105
|
|
|
106
106
|
if (!machine) {
|
|
107
107
|
// Nothing to mirror. An existing row is left alone rather than deleted —
|
|
@@ -111,8 +111,8 @@ export async function syncLocalMachineIdentity(userId: string): Promise<GitIdent
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (!existing) {
|
|
114
|
-
const label = machineLabel(
|
|
115
|
-
const row = gitIdentityQueries.create(randomUUID(),
|
|
114
|
+
const label = machineLabel((l) => gitIdentityQueries.labelTaken(l));
|
|
115
|
+
const row = gitIdentityQueries.create(randomUUID(), {
|
|
116
116
|
label,
|
|
117
117
|
name: machine.name,
|
|
118
118
|
email: machine.email,
|
|
@@ -124,10 +124,10 @@ export async function syncLocalMachineIdentity(userId: string): Promise<GitIdent
|
|
|
124
124
|
});
|
|
125
125
|
// Becoming the default is the point: a fresh install then commits as the
|
|
126
126
|
// person the machine already says it is, with nothing to configure.
|
|
127
|
-
if (!gitIdentityQueries.
|
|
128
|
-
gitIdentityQueries.setDefault(
|
|
127
|
+
if (!gitIdentityQueries.getDefault()) {
|
|
128
|
+
gitIdentityQueries.setDefault(row.id);
|
|
129
129
|
}
|
|
130
|
-
debug.log('git',
|
|
130
|
+
debug.log('git', "Imported the machine's git identity");
|
|
131
131
|
return gitIdentityQueries.getById(row.id);
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
* Three seams the rest of Clopen uses:
|
|
5
5
|
* - `gitIdentityService` — CRUD for the Settings surface.
|
|
6
6
|
* - `resolveGitEnv` — the one call every git-running surface makes to get the
|
|
7
|
-
* environment fragment for a
|
|
7
|
+
* environment fragment for a project. Panel, engine, and terminal all
|
|
8
8
|
* go through it so they cannot drift apart.
|
|
9
9
|
* - `buildGitIdentityEnv` / `remoteHost` — the primitives, for tests and the
|
|
10
10
|
* credential helper.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { gitIdentityQueries } from '$backend/database/queries';
|
|
14
13
|
import { buildGitIdentityEnv, remoteHost } from './env';
|
|
15
14
|
import { helperCommand, pickCredentialIdentity, resolveIdentity, toEnvIdentity } from './resolve';
|
|
16
15
|
import { toDTO } from './service';
|
|
@@ -21,30 +20,26 @@ export { buildGitIdentityEnv, buildGitConfigPairs, remoteHost } from './env';
|
|
|
21
20
|
export type { GitEnvIdentity, HelperCommand } from './env';
|
|
22
21
|
export { resolveIdentity, pickCredentialIdentity, toEnvIdentity, helperCommand } from './resolve';
|
|
23
22
|
export { identityKeyPath, removeKeyFiles, writeKeyFile } from './keys';
|
|
24
|
-
export { writeScopeConfig, removeScopeConfig,
|
|
23
|
+
export { writeScopeConfig, removeScopeConfig, refreshScopeConfigs, scopeConfigPath } from './scope-config';
|
|
25
24
|
export { readMachineIdentity, syncLocalMachineIdentity } from './import-local';
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
* The environment fragment for a
|
|
27
|
+
* The environment fragment for a project, optionally scoped to a remote.
|
|
29
28
|
*
|
|
30
29
|
* `remoteUrl` is what lets a fork workflow work: the host it points at decides
|
|
31
30
|
* which identity's credential answers, while attribution always comes from the
|
|
32
31
|
* project's own identity. Callers that are not talking to a remote (a commit, a
|
|
33
32
|
* rebase) leave it out and get attribution only.
|
|
34
33
|
*
|
|
35
|
-
* Returns `{}` when
|
|
34
|
+
* Returns `{}` when there is no identity, so every call site can merge the
|
|
36
35
|
* result unconditionally.
|
|
37
36
|
*/
|
|
38
|
-
export function resolveGitEnv(
|
|
39
|
-
projectId
|
|
40
|
-
userId: string,
|
|
41
|
-
remoteUrl?: string | null
|
|
42
|
-
): Record<string, string> {
|
|
43
|
-
const { row } = resolveIdentity(projectId, userId);
|
|
37
|
+
export function resolveGitEnv(projectId: string, remoteUrl?: string | null): Record<string, string> {
|
|
38
|
+
const { row } = resolveIdentity(projectId);
|
|
44
39
|
if (!row) return {};
|
|
45
40
|
|
|
46
41
|
const host = remoteUrl ? remoteHost(remoteUrl) : null;
|
|
47
|
-
const credential = pickCredentialIdentity(
|
|
42
|
+
const credential = pickCredentialIdentity(host, row);
|
|
48
43
|
return buildGitIdentityEnv(toEnvIdentity(row, credential), helperCommand());
|
|
49
44
|
}
|
|
50
45
|
|
|
@@ -52,16 +47,12 @@ export function resolveGitEnv(
|
|
|
52
47
|
* What the UI shows above the commit box: who this will be committed as, and
|
|
53
48
|
* whether that was chosen for this project or inherited.
|
|
54
49
|
*/
|
|
55
|
-
export function describeIdentity(
|
|
56
|
-
|
|
57
|
-
userId: string,
|
|
58
|
-
remoteUrl?: string | null
|
|
59
|
-
): ResolvedGitIdentity {
|
|
60
|
-
const { row, source } = resolveIdentity(projectId, userId);
|
|
50
|
+
export function describeIdentity(projectId: string, remoteUrl?: string | null): ResolvedGitIdentity {
|
|
51
|
+
const { row, source } = resolveIdentity(projectId);
|
|
61
52
|
if (!row) return { identity: null, source: 'none', credentialIdentity: null };
|
|
62
53
|
|
|
63
54
|
const host = remoteUrl ? remoteHost(remoteUrl) : null;
|
|
64
|
-
const credential = pickCredentialIdentity(
|
|
55
|
+
const credential = pickCredentialIdentity(host, row);
|
|
65
56
|
|
|
66
57
|
return {
|
|
67
58
|
identity: toDTO(row),
|
|
@@ -71,8 +62,3 @@ export function describeIdentity(
|
|
|
71
62
|
credentialIdentity: credential && credential.id !== row.id ? toDTO(credential) : null
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
|
-
|
|
75
|
-
/** Every identity a user owns, as rows — for the credential helper. */
|
|
76
|
-
export function identitiesOf(userId: string) {
|
|
77
|
-
return gitIdentityQueries.listByUser(userId);
|
|
78
|
-
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Which identity a git command runs as.
|
|
3
3
|
*
|
|
4
4
|
* ── The chain ──
|
|
5
|
-
* binding (project
|
|
5
|
+
* binding (project) → the default identity → nothing
|
|
6
6
|
* "Nothing" is a real answer, not a failure: Clopen then runs git exactly as it
|
|
7
7
|
* did before this feature existed, deferring to `.git/config` and the machine.
|
|
8
8
|
* That is what keeps the feature opt-in for people who already have git set up.
|
|
9
9
|
*
|
|
10
10
|
* ── Why the credential can come from a different identity ──
|
|
11
|
-
* Attribution is a property of the
|
|
11
|
+
* Attribution is a property of the author; a credential is a property of the
|
|
12
12
|
* host. A fork workflow has `origin` on a personal account and `upstream` on a
|
|
13
13
|
* work one, and the commits belong to the same human either way. So the
|
|
14
14
|
* project's identity always decides `user.name`/`user.email`, while the
|
|
@@ -28,7 +28,7 @@ import type { GitEnvIdentity, HelperCommand } from './env';
|
|
|
28
28
|
import { identityKeyPath } from './keys';
|
|
29
29
|
|
|
30
30
|
/** Where the identity came from, for the "committing as…" line in the UI. */
|
|
31
|
-
export type IdentitySource = 'project' | '
|
|
31
|
+
export type IdentitySource = 'project' | 'default' | 'none';
|
|
32
32
|
|
|
33
33
|
export interface IdentityResolution {
|
|
34
34
|
row: GitIdentityRow | null;
|
|
@@ -36,22 +36,22 @@ export interface IdentityResolution {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* The identity for a project
|
|
39
|
+
* The identity for a project.
|
|
40
40
|
*
|
|
41
|
-
* A binding pointing at a deleted identity resolves to the
|
|
42
|
-
*
|
|
41
|
+
* A binding pointing at a deleted identity resolves to the default rather than
|
|
42
|
+
* to nothing — `ON DELETE CASCADE` removes such bindings, so this
|
|
43
43
|
* only guards against a row that outlived its target.
|
|
44
44
|
*/
|
|
45
|
-
export function resolveIdentity(projectId: string
|
|
46
|
-
const binding = gitIdentityBindingQueries.get(projectId
|
|
45
|
+
export function resolveIdentity(projectId: string): IdentityResolution {
|
|
46
|
+
const binding = gitIdentityBindingQueries.get(projectId);
|
|
47
47
|
if (binding) {
|
|
48
48
|
const row = gitIdentityQueries.getById(binding.identity_id);
|
|
49
|
-
if (row
|
|
49
|
+
if (row) return { row, source: 'project' };
|
|
50
50
|
debug.warn('git', `Identity binding for project ${projectId} points at a missing identity`);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const fallback = gitIdentityQueries.
|
|
54
|
-
return fallback ? { row: fallback, source: '
|
|
53
|
+
const fallback = gitIdentityQueries.getDefault();
|
|
54
|
+
return fallback ? { row: fallback, source: 'default' } : { row: null, source: 'none' };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** True when this identity can authenticate to `host`. */
|
|
@@ -64,7 +64,7 @@ function claimsHost(row: GitIdentityRow, host: string): boolean {
|
|
|
64
64
|
* The identity whose credential should answer for `host`.
|
|
65
65
|
*
|
|
66
66
|
* Prefers the one already chosen for the project, so the common case never
|
|
67
|
-
* looks past it. Otherwise the
|
|
67
|
+
* looks past it. Otherwise the other identities are searched, and a
|
|
68
68
|
* single match wins. AMBIGUITY IS RESOLVED AS "NO CREDENTIAL": if two
|
|
69
69
|
* identities claim the same host, picking one arbitrarily would authenticate
|
|
70
70
|
* as an account the user did not choose, and a push that fails asking for a
|
|
@@ -72,7 +72,6 @@ function claimsHost(row: GitIdentityRow, host: string): boolean {
|
|
|
72
72
|
* wrong name.
|
|
73
73
|
*/
|
|
74
74
|
export function pickCredentialIdentity(
|
|
75
|
-
userId: string,
|
|
76
75
|
host: string | null,
|
|
77
76
|
primary: GitIdentityRow | null
|
|
78
77
|
): GitIdentityRow | null {
|
|
@@ -80,7 +79,7 @@ export function pickCredentialIdentity(
|
|
|
80
79
|
if (primary && claimsHost(primary, host)) return primary;
|
|
81
80
|
|
|
82
81
|
const candidates = gitIdentityQueries
|
|
83
|
-
.
|
|
82
|
+
.list()
|
|
84
83
|
.filter((row) => claimsHost(row, host));
|
|
85
84
|
|
|
86
85
|
if (candidates.length === 1) return candidates[0]!;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A git config file per
|
|
3
|
-
*
|
|
2
|
+
* A git config file per project, for the one surface that outlives a single
|
|
3
|
+
* command: the terminal.
|
|
4
4
|
*
|
|
5
5
|
* ── The problem this solves ──
|
|
6
6
|
* `GIT_CONFIG_*` is read from the environment, and a process's environment is
|
|
@@ -40,19 +40,26 @@ import { debug } from '$shared/utils/logger';
|
|
|
40
40
|
import { buildGitConfigPairs } from './env';
|
|
41
41
|
import { helperCommand, pickCredentialIdentity, resolveIdentity, toEnvIdentity } from './resolve';
|
|
42
42
|
|
|
43
|
-
/** Where the generated per-
|
|
43
|
+
/** Where the generated per-project config files live. */
|
|
44
44
|
function scopeConfigDir(): string {
|
|
45
|
-
return join(getClopenDir(), 'git-identities', '
|
|
45
|
+
return join(getClopenDir(), 'git-identities', 'projects');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* in one project must not share a file.
|
|
49
|
+
* Files from when an identity was chosen per (user, project) lived in a sibling
|
|
50
|
+
* directory under a name no longer read. Dropped once per process, before the
|
|
51
|
+
* first write, so they do not linger next to the files that replaced them.
|
|
53
52
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
let legacyScopesRemoved = false;
|
|
54
|
+
async function removeLegacyScopes(): Promise<void> {
|
|
55
|
+
if (legacyScopesRemoved) return;
|
|
56
|
+
legacyScopesRemoved = true;
|
|
57
|
+
await rm(join(getClopenDir(), 'git-identities', 'scopes'), { recursive: true, force: true }).catch(() => {});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Path of the config file for one project. */
|
|
61
|
+
export function scopeConfigPath(projectId: string): string {
|
|
62
|
+
return join(scopeConfigDir(), `${projectId}.gitconfig`);
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
/** The config files git would normally read as "global", in the order it does. */
|
|
@@ -82,7 +89,7 @@ function configValue(value: string): string {
|
|
|
82
89
|
export function renderScopeConfig(pairs: Array<[string, string]>): string {
|
|
83
90
|
const lines = [
|
|
84
91
|
'# Generated by Clopen — do not edit.',
|
|
85
|
-
'# Identity for one
|
|
92
|
+
'# Identity for one project; regenerated whenever it changes.',
|
|
86
93
|
''
|
|
87
94
|
];
|
|
88
95
|
|
|
@@ -112,20 +119,18 @@ export function renderScopeConfig(pairs: Array<[string, string]>): string {
|
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
/**
|
|
115
|
-
* Write (or remove) the config file for one
|
|
122
|
+
* Write (or remove) the config file for one project.
|
|
116
123
|
*
|
|
117
124
|
* Returns the path when a file now exists, and `null` when there is nothing to
|
|
118
125
|
* write. The caller must only set `GIT_CONFIG_GLOBAL` on a non-null result:
|
|
119
126
|
* pointing it at a missing file would make git ignore the user's real global
|
|
120
127
|
* config entirely, which is a far worse outcome than having no identity.
|
|
121
128
|
*/
|
|
122
|
-
export async function writeScopeConfig(
|
|
123
|
-
userId: string,
|
|
124
|
-
projectId: string
|
|
125
|
-
): Promise<string | null> {
|
|
129
|
+
export async function writeScopeConfig(projectId: string): Promise<string | null> {
|
|
126
130
|
try {
|
|
127
|
-
|
|
128
|
-
const
|
|
131
|
+
await removeLegacyScopes();
|
|
132
|
+
const { row } = resolveIdentity(projectId);
|
|
133
|
+
const path = scopeConfigPath(projectId);
|
|
129
134
|
|
|
130
135
|
if (!row) {
|
|
131
136
|
// No identity — remove any file from a previous one, so a cleared
|
|
@@ -136,12 +141,12 @@ export async function writeScopeConfig(
|
|
|
136
141
|
|
|
137
142
|
// No remote URL here: a terminal is not one command against one remote, so
|
|
138
143
|
// the credential comes from the identity's own host claims.
|
|
139
|
-
const credential = pickCredentialIdentity(
|
|
144
|
+
const credential = pickCredentialIdentity(null, row);
|
|
140
145
|
const pairs = buildGitConfigPairs(toEnvIdentity(row, credential), helperCommand());
|
|
141
146
|
|
|
142
147
|
await mkdir(scopeConfigDir(), { recursive: true, mode: 0o700 });
|
|
143
148
|
await writeFile(path, renderScopeConfig(pairs), { mode: 0o600 });
|
|
144
|
-
debug.log('git', `Wrote git scope config for
|
|
149
|
+
debug.log('git', `Wrote git scope config for project ${projectId}`);
|
|
145
150
|
return path;
|
|
146
151
|
} catch (error) {
|
|
147
152
|
// A terminal with the machine's identity is a working terminal; failing to
|
|
@@ -151,9 +156,9 @@ export async function writeScopeConfig(
|
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
|
|
154
|
-
/** Drop the file for one
|
|
155
|
-
export async function removeScopeConfig(
|
|
156
|
-
await rm(scopeConfigPath(
|
|
159
|
+
/** Drop the file for one project. */
|
|
160
|
+
export async function removeScopeConfig(projectId: string): Promise<void> {
|
|
161
|
+
await rm(scopeConfigPath(projectId), { force: true }).catch(() => {});
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
/**
|
|
@@ -161,14 +166,14 @@ export async function removeScopeConfig(userId: string, projectId: string): Prom
|
|
|
161
166
|
*
|
|
162
167
|
* Called after a create/update/delete/default change, so a shell that is already
|
|
163
168
|
* open picks the new identity up on its next git command. Bindings naming the
|
|
164
|
-
* identity are refreshed, and so is every project the
|
|
165
|
-
*
|
|
169
|
+
* identity are refreshed, and so is every project the default reaches — which
|
|
170
|
+
* is why the project list is consulted rather than only the bindings.
|
|
166
171
|
*/
|
|
167
|
-
export async function
|
|
172
|
+
export async function refreshScopeConfigs(): Promise<void> {
|
|
168
173
|
try {
|
|
169
174
|
const { projectQueries } = await import('$backend/database/queries');
|
|
170
|
-
const projects = projectQueries.
|
|
171
|
-
await Promise.all(projects.map((project) => writeScopeConfig(
|
|
175
|
+
const projects = projectQueries.getListed();
|
|
176
|
+
await Promise.all(projects.map((project) => writeScopeConfig(project.id)));
|
|
172
177
|
} catch (error) {
|
|
173
178
|
debug.warn('git', 'Could not refresh git scope configs:', error);
|
|
174
179
|
}
|
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
} from '$shared/types/git-identity';
|
|
27
27
|
import { derivePublicKey, generateKeyPair, identityKeyPath, removeKeyFiles, writeKeyFile } from './keys';
|
|
28
28
|
import { syncLocalMachineIdentity } from './import-local';
|
|
29
|
-
import {
|
|
29
|
+
import { refreshScopeConfigs, writeScopeConfig } from './scope-config';
|
|
30
30
|
|
|
31
31
|
/** Strip a row down to what a client may see. */
|
|
32
32
|
export function toDTO(row: GitIdentityRow): GitIdentityDTO {
|
|
@@ -111,31 +111,29 @@ async function syncKeyFile(row: GitIdentityRow): Promise<GitIdentityRow> {
|
|
|
111
111
|
|
|
112
112
|
export const gitIdentityService = {
|
|
113
113
|
/**
|
|
114
|
-
* Every identity
|
|
114
|
+
* Every identity, mirroring the machine's git config first.
|
|
115
115
|
*
|
|
116
|
-
* Done on the read rather than at startup
|
|
117
|
-
*
|
|
118
|
-
* shown. It is idempotent and only writes on the first call per user.
|
|
116
|
+
* Done on the read rather than at startup because it is the moment the result
|
|
117
|
+
* is actually about to be shown. It is idempotent and only writes once.
|
|
119
118
|
*/
|
|
120
|
-
async list(
|
|
121
|
-
await syncLocalMachineIdentity(
|
|
122
|
-
return gitIdentityQueries.
|
|
119
|
+
async list(): Promise<GitIdentityDTO[]> {
|
|
120
|
+
await syncLocalMachineIdentity();
|
|
121
|
+
return gitIdentityQueries.list().map(toDTO);
|
|
123
122
|
},
|
|
124
123
|
|
|
125
|
-
get(
|
|
124
|
+
get(id: string): GitIdentityDTO | null {
|
|
126
125
|
const row = gitIdentityQueries.getById(id);
|
|
127
|
-
|
|
128
|
-
return toDTO(row);
|
|
126
|
+
return row ? toDTO(row) : null;
|
|
129
127
|
},
|
|
130
128
|
|
|
131
|
-
async create(
|
|
129
|
+
async create(input: GitIdentityInput): Promise<GitIdentityDTO> {
|
|
132
130
|
assertValid(input);
|
|
133
|
-
if (gitIdentityQueries.labelTaken(
|
|
131
|
+
if (gitIdentityQueries.labelTaken(input.label.trim())) {
|
|
134
132
|
throw new Error(`You already have an identity called "${input.label.trim()}"`);
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
const id = randomUUID();
|
|
138
|
-
let row = gitIdentityQueries.create(id,
|
|
136
|
+
let row = gitIdentityQueries.create(id, {
|
|
139
137
|
label: input.label.trim(),
|
|
140
138
|
name: input.name.trim(),
|
|
141
139
|
email: input.email.trim(),
|
|
@@ -151,28 +149,28 @@ export const gitIdentityService = {
|
|
|
151
149
|
|
|
152
150
|
row = await syncKeyFile(row);
|
|
153
151
|
|
|
154
|
-
// The first identity
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
if (input.isDefault || gitIdentityQueries.
|
|
158
|
-
gitIdentityQueries.setDefault(
|
|
152
|
+
// The first identity created becomes the default — otherwise it would sit
|
|
153
|
+
// there doing nothing until someone found the toggle, which reads as the
|
|
154
|
+
// feature being broken.
|
|
155
|
+
if (input.isDefault || gitIdentityQueries.list().length === 1) {
|
|
156
|
+
gitIdentityQueries.setDefault(id);
|
|
159
157
|
row = gitIdentityQueries.getById(id)!;
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
// Terminals that are already open read their identity from a file, so it is
|
|
163
161
|
// rewritten here — otherwise the new account would only reach tabs opened
|
|
164
162
|
// after this point.
|
|
165
|
-
await
|
|
163
|
+
await refreshScopeConfigs();
|
|
166
164
|
|
|
167
|
-
debug.log('git', `Created git identity "${row.label}"
|
|
165
|
+
debug.log('git', `Created git identity "${row.label}"`);
|
|
168
166
|
return toDTO(row);
|
|
169
167
|
},
|
|
170
168
|
|
|
171
|
-
async update(
|
|
169
|
+
async update(id: string, input: GitIdentityInput): Promise<GitIdentityDTO> {
|
|
172
170
|
assertValid(input);
|
|
173
171
|
const existing = gitIdentityQueries.getById(id);
|
|
174
|
-
if (!existing
|
|
175
|
-
if (gitIdentityQueries.labelTaken(
|
|
172
|
+
if (!existing) throw new Error('Identity not found');
|
|
173
|
+
if (gitIdentityQueries.labelTaken(input.label.trim(), id)) {
|
|
176
174
|
throw new Error(`You already have an identity called "${input.label.trim()}"`);
|
|
177
175
|
}
|
|
178
176
|
|
|
@@ -199,19 +197,19 @@ export const gitIdentityService = {
|
|
|
199
197
|
row = await syncKeyFile(row);
|
|
200
198
|
|
|
201
199
|
if (input.isDefault && row.is_default !== 1) {
|
|
202
|
-
gitIdentityQueries.setDefault(
|
|
200
|
+
gitIdentityQueries.setDefault(id);
|
|
203
201
|
row = gitIdentityQueries.getById(id)!;
|
|
204
202
|
}
|
|
205
203
|
|
|
206
|
-
await
|
|
204
|
+
await refreshScopeConfigs();
|
|
207
205
|
|
|
208
206
|
debug.log('git', `Updated git identity "${row.label}"`);
|
|
209
207
|
return toDTO(row);
|
|
210
208
|
},
|
|
211
209
|
|
|
212
|
-
async remove(
|
|
210
|
+
async remove(id: string): Promise<void> {
|
|
213
211
|
const row = gitIdentityQueries.getById(id);
|
|
214
|
-
if (!row
|
|
212
|
+
if (!row) throw new Error('Identity not found');
|
|
215
213
|
if (row.source === 'local-machine') {
|
|
216
214
|
throw new Error(
|
|
217
215
|
"This account mirrors the machine's own git config, so it cannot be deleted. Edit it instead."
|
|
@@ -221,24 +219,24 @@ export const gitIdentityService = {
|
|
|
221
219
|
gitIdentityQueries.remove(id);
|
|
222
220
|
await removeKeyFiles(id);
|
|
223
221
|
|
|
224
|
-
// Deleting the default leaves
|
|
225
|
-
//
|
|
222
|
+
// Deleting the default leaves none, so the next one in the list takes over
|
|
223
|
+
// rather than every project silently losing its identity.
|
|
226
224
|
if (row.is_default === 1) {
|
|
227
|
-
const remaining = gitIdentityQueries.
|
|
228
|
-
if (remaining.length > 0) gitIdentityQueries.setDefault(
|
|
225
|
+
const remaining = gitIdentityQueries.list();
|
|
226
|
+
if (remaining.length > 0) gitIdentityQueries.setDefault(remaining[0]!.id);
|
|
229
227
|
}
|
|
230
228
|
|
|
231
|
-
await
|
|
229
|
+
await refreshScopeConfigs();
|
|
232
230
|
|
|
233
231
|
debug.log('git', `Removed git identity "${row.label}"`);
|
|
234
232
|
},
|
|
235
233
|
|
|
236
|
-
async setDefault(
|
|
234
|
+
async setDefault(id: string): Promise<GitIdentityDTO> {
|
|
237
235
|
const row = gitIdentityQueries.getById(id);
|
|
238
|
-
if (!row
|
|
239
|
-
gitIdentityQueries.setDefault(
|
|
236
|
+
if (!row) throw new Error('Identity not found');
|
|
237
|
+
gitIdentityQueries.setDefault(id);
|
|
240
238
|
// Every project that inherits the default is affected, not just one.
|
|
241
|
-
await
|
|
239
|
+
await refreshScopeConfigs();
|
|
242
240
|
return toDTO(gitIdentityQueries.getById(id)!);
|
|
243
241
|
},
|
|
244
242
|
|
|
@@ -248,9 +246,9 @@ export const gitIdentityService = {
|
|
|
248
246
|
* Returns only the public key and its fingerprint; the private key goes
|
|
249
247
|
* straight into the sealed column and the 0600 file.
|
|
250
248
|
*/
|
|
251
|
-
async generateKey(
|
|
249
|
+
async generateKey(id: string): Promise<GeneratedSshKey> {
|
|
252
250
|
const row = gitIdentityQueries.getById(id);
|
|
253
|
-
if (!row
|
|
251
|
+
if (!row) throw new Error('Identity not found');
|
|
254
252
|
|
|
255
253
|
const { privateKey, publicKey, fingerprint } = await generateKeyPair(
|
|
256
254
|
id,
|
|
@@ -271,23 +269,22 @@ export const gitIdentityService = {
|
|
|
271
269
|
integrationAccountId: row.integration_account_id
|
|
272
270
|
});
|
|
273
271
|
|
|
274
|
-
await
|
|
272
|
+
await refreshScopeConfigs();
|
|
275
273
|
|
|
276
274
|
debug.log('git', `Generated SSH key for identity "${row.label}"`);
|
|
277
275
|
return { publicKey, fingerprint };
|
|
278
276
|
},
|
|
279
277
|
|
|
280
|
-
/** Bind a project to an identity
|
|
281
|
-
async bind(
|
|
278
|
+
/** Bind a project to an identity. */
|
|
279
|
+
async bind(projectId: string, identityId: string | null): Promise<void> {
|
|
282
280
|
if (identityId === null) {
|
|
283
|
-
gitIdentityBindingQueries.clear(projectId
|
|
281
|
+
gitIdentityBindingQueries.clear(projectId);
|
|
284
282
|
} else {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
gitIdentityBindingQueries.set(projectId, userId, identityId);
|
|
283
|
+
if (!gitIdentityQueries.getById(identityId)) throw new Error('Identity not found');
|
|
284
|
+
gitIdentityBindingQueries.set(projectId, identityId);
|
|
288
285
|
}
|
|
289
286
|
// Only this project's file can have changed, so only it is rewritten.
|
|
290
|
-
await writeScopeConfig(
|
|
287
|
+
await writeScopeConfig(projectId);
|
|
291
288
|
},
|
|
292
289
|
|
|
293
290
|
/** How many projects would lose their binding if this identity went away. */
|