@myrialabs/clopen 0.4.41 → 0.4.42

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.
Files changed (61) hide show
  1. package/backend/chat/stream-manager.ts +8 -0
  2. package/backend/database/crypto/secret-columns.ts +5 -1
  3. package/backend/database/index.ts +18 -0
  4. package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
  5. package/backend/database/migrations/082_create_git_identities.ts +122 -0
  6. package/backend/database/migrations/index.ts +7 -0
  7. package/backend/database/queries/git-identity-queries.ts +290 -0
  8. package/backend/database/queries/index.ts +2 -0
  9. package/backend/engine/adapters/claude/environment.ts +11 -1
  10. package/backend/engine/adapters/claude/stream.ts +1 -1
  11. package/backend/engine/adapters/codex/stream.ts +35 -3
  12. package/backend/engine/adapters/opencode/server.ts +26 -2
  13. package/backend/engine/adapters/opencode/stream.ts +4 -1
  14. package/backend/engine/adapters/qwen/stream.ts +3 -1
  15. package/backend/engine/types.ts +10 -0
  16. package/backend/git/git-executor.ts +28 -2
  17. package/backend/git/git-service.ts +59 -40
  18. package/backend/git/identity/cli.test.ts +58 -0
  19. package/backend/git/identity/cli.ts +201 -0
  20. package/backend/git/identity/credential-helper.test.ts +242 -0
  21. package/backend/git/identity/env.test.ts +214 -0
  22. package/backend/git/identity/env.ts +193 -0
  23. package/backend/git/identity/import-local.test.ts +199 -0
  24. package/backend/git/identity/import-local.ts +141 -0
  25. package/backend/git/identity/index.ts +78 -0
  26. package/backend/git/identity/keys.ts +183 -0
  27. package/backend/git/identity/resolve.ts +140 -0
  28. package/backend/git/identity/scope-config.test.ts +145 -0
  29. package/backend/git/identity/scope-config.ts +175 -0
  30. package/backend/git/identity/service.ts +297 -0
  31. package/backend/index.ts +16 -0
  32. package/backend/preview/browser/browser-console-manager.ts +214 -34
  33. package/backend/preview/browser/browser-pool.ts +526 -123
  34. package/backend/preview/browser/browser-preview-service.ts +192 -8
  35. package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
  36. package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
  37. package/backend/preview/browser/browser-tab-manager.ts +291 -65
  38. package/backend/preview/browser/capture-profile.ts +15 -1
  39. package/backend/preview/browser/types.ts +26 -1
  40. package/backend/terminal/ptykit.ts +24 -0
  41. package/backend/ws/git/branch.ts +17 -6
  42. package/backend/ws/git/commit.ts +6 -5
  43. package/backend/ws/git/conflict.ts +3 -2
  44. package/backend/ws/git/identity-context.ts +91 -0
  45. package/backend/ws/git/identity.ts +200 -0
  46. package/backend/ws/git/index.ts +3 -1
  47. package/backend/ws/git/remote.ts +57 -11
  48. package/backend/ws/preview/browser/data.ts +60 -0
  49. package/backend/ws/preview/browser/interact.ts +6 -0
  50. package/backend/ws/preview/browser/tab-info.ts +9 -1
  51. package/backend/ws/preview/browser/tab.ts +64 -8
  52. package/backend/ws/preview/index.ts +21 -0
  53. package/bin/clopen.ts +9 -0
  54. package/dist/assets/{index-CeNKKSDR.js → index-BynqyvF4.js} +1 -1
  55. package/dist/assets/{index-DW89566K.js → index-DLoJsmNQ.js} +1 -1
  56. package/dist/assets/{main-Cy5DXWPT.js → main-CUyZAmqt.js} +591 -584
  57. package/dist/assets/main-DVCW3cfr.css +1 -0
  58. package/dist/index.html +2 -2
  59. package/package.json +2 -2
  60. package/shared/types/git-identity.ts +112 -0
  61. package/dist/assets/main-DJKj_4By.css +0 -1
@@ -7,6 +7,7 @@ import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { requireProjectWorkspace } from '../access';
10
+ import { identityEnvFor } from './identity-context';
10
11
  import { debug } from '$shared/utils/logger';
11
12
 
12
13
  const BranchSchema = t.Object({
@@ -171,11 +172,16 @@ export const branchHandler = createRouter()
171
172
  }, async ({ data, conn }) => {
172
173
  const { root } = requireProjectWorkspace(conn, data.projectId);
173
174
  const cwd = resolveRepoCwd(root, data.repoPath);
174
- return await gitService.mergeBranch(cwd, data.branchName, {
175
- noFastForward: data.noFastForward ?? false,
176
- squash: data.squash ?? false,
177
- ffOnly: data.ffOnly ?? false
178
- });
175
+ return await gitService.mergeBranch(
176
+ cwd,
177
+ data.branchName,
178
+ {
179
+ noFastForward: data.noFastForward ?? false,
180
+ squash: data.squash ?? false,
181
+ ffOnly: data.ffOnly ?? false
182
+ },
183
+ identityEnvFor(conn, data.projectId)
184
+ );
179
185
  })
180
186
 
181
187
  .http('git:rebase', {
@@ -194,7 +200,12 @@ export const branchHandler = createRouter()
194
200
  }, async ({ data, conn }) => {
195
201
  const { root } = requireProjectWorkspace(conn, data.projectId);
196
202
  const cwd = resolveRepoCwd(root, data.repoPath);
197
- return await gitService.rebaseOnto(cwd, data.upstream, data.autostash ?? true);
203
+ return await gitService.rebaseOnto(
204
+ cwd,
205
+ data.upstream,
206
+ data.autostash ?? true,
207
+ identityEnvFor(conn, data.projectId)
208
+ );
198
209
  })
199
210
 
200
211
  .http('git:return-to-branch', {
@@ -7,6 +7,7 @@ import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { requireProjectWorkspace } from '../access';
10
+ import { identityEnvFor } from './identity-context';
10
11
  import { debug } from '$shared/utils/logger';
11
12
 
12
13
  /**
@@ -38,7 +39,7 @@ export const commitHandler = createRouter()
38
39
  }, async ({ data, conn }) => {
39
40
  const { root } = requireProjectWorkspace(conn, data.projectId);
40
41
  const cwd = resolveRepoCwd(root, data.repoPath);
41
- const hash = await gitService.commit(cwd, data.message);
42
+ const hash = await gitService.commit(cwd, data.message, identityEnvFor(conn, data.projectId));
42
43
  return { hash };
43
44
  })
44
45
 
@@ -54,7 +55,7 @@ export const commitHandler = createRouter()
54
55
  }, async ({ data, conn }) => {
55
56
  const { root } = requireProjectWorkspace(conn, data.projectId);
56
57
  const cwd = resolveRepoCwd(root, data.repoPath);
57
- const hash = await gitService.amendCommit(cwd, data.message);
58
+ const hash = await gitService.amendCommit(cwd, data.message, identityEnvFor(conn, data.projectId));
58
59
  return { hash };
59
60
  })
60
61
 
@@ -85,7 +86,7 @@ export const commitHandler = createRouter()
85
86
  }, async ({ data, conn }) => {
86
87
  const { root } = requireProjectWorkspace(conn, data.projectId);
87
88
  const cwd = resolveRepoCwd(root, data.repoPath);
88
- return await gitService.revertCommit(cwd, data.ref);
89
+ return await gitService.revertCommit(cwd, data.ref, identityEnvFor(conn, data.projectId));
89
90
  })
90
91
 
91
92
  .http('git:cherry-pick', {
@@ -101,7 +102,7 @@ export const commitHandler = createRouter()
101
102
  }, async ({ data, conn }) => {
102
103
  const { root } = requireProjectWorkspace(conn, data.projectId);
103
104
  const cwd = resolveRepoCwd(root, data.repoPath);
104
- return await gitService.cherryPick(cwd, data.hashes);
105
+ return await gitService.cherryPick(cwd, data.hashes, identityEnvFor(conn, data.projectId));
105
106
  })
106
107
 
107
108
  .http('git:clean', {
@@ -144,5 +145,5 @@ export const commitHandler = createRouter()
144
145
  }, async ({ data, conn }) => {
145
146
  const { root } = requireProjectWorkspace(conn, data.projectId);
146
147
  const cwd = resolveRepoCwd(root, data.repoPath);
147
- return await gitService.npmVersion(cwd, data.bump);
148
+ return await gitService.npmVersion(cwd, data.bump, identityEnvFor(conn, data.projectId));
148
149
  });
@@ -8,6 +8,7 @@ import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { findNestedRepoPaths, findRepoForFile } from '../../git/nested-repos';
10
10
  import { requireProjectWorkspace } from '../access';
11
+ import { identityEnvFor } from './identity-context';
11
12
  import { debug } from '$shared/utils/logger';
12
13
 
13
14
  function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
@@ -167,7 +168,7 @@ export const conflictHandler = createRouter()
167
168
  }, async ({ data, conn }) => {
168
169
  const { root } = requireProjectWorkspace(conn, data.projectId);
169
170
  const cwd = resolveRepoCwd(root, data.repoPath) ?? root;
170
- return await gitService.continueOperation(cwd);
171
+ return await gitService.continueOperation(cwd, identityEnvFor(conn, data.projectId));
171
172
  })
172
173
 
173
174
  .http('git:skip-operation', {
@@ -179,7 +180,7 @@ export const conflictHandler = createRouter()
179
180
  }, async ({ data, conn }) => {
180
181
  const { root } = requireProjectWorkspace(conn, data.projectId);
181
182
  const cwd = resolveRepoCwd(root, data.repoPath) ?? root;
182
- return await gitService.skipOperation(cwd);
183
+ return await gitService.skipOperation(cwd, identityEnvFor(conn, data.projectId));
183
184
  })
184
185
 
185
186
  .http('git:abort-operation', {
@@ -0,0 +1,91 @@
1
+ /**
2
+ * The bridge from a WebSocket connection to a git identity.
3
+ *
4
+ * Handlers already know the project (`data.projectId`); this adds the other
5
+ * half, the user, from the connection. Both are needed because an identity is
6
+ * owned by a person and chosen per project, so neither alone identifies one.
7
+ *
8
+ * Every helper here degrades to `{}` rather than throwing. A user with no
9
+ * identity, an unreadable row, a project that was never bound — all of them
10
+ * mean "run git the way Clopen always did", which is a working commit, not an
11
+ * error dialog.
12
+ */
13
+
14
+ import { resolveGitEnv } from '$backend/git/identity';
15
+ import { gitService } from '$backend/git/git-service';
16
+ 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
+ import { debug } from '$shared/utils/logger';
20
+
21
+ /**
22
+ * Attribution-only environment: who authors what this command creates.
23
+ *
24
+ * For commits, merges, stashes, tags — anything that writes a git object
25
+ * without reaching the network.
26
+ */
27
+ export function identityEnvFor(conn: WSConnection, projectId: string): GitIdentityEnv {
28
+ try {
29
+ const userId = ws.getUserId(conn);
30
+ if (!userId) return {};
31
+ return resolveGitEnv(projectId, userId);
32
+ } catch (error) {
33
+ debug.warn('git', 'Could not resolve a git identity for this connection:', error);
34
+ return {};
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Attribution plus the credential that reaches `remote`.
40
+ *
41
+ * The remote's URL — not its name — decides which identity authenticates, so
42
+ * the name is resolved to a URL first. `origin` on one account and `upstream`
43
+ * on another is the case this exists for.
44
+ *
45
+ * When the name cannot be resolved to a URL the result is attribution only:
46
+ * that is what happens for a branch pushing to an upstream Clopen did not
47
+ * name, and falling back to the machine's credentials there is the same
48
+ * behaviour as before this feature.
49
+ */
50
+ export async function identityEnvForRemote(
51
+ conn: WSConnection,
52
+ projectId: string,
53
+ cwd: string,
54
+ remoteName?: string
55
+ ): Promise<GitIdentityEnv> {
56
+ try {
57
+ const userId = ws.getUserId(conn);
58
+ if (!userId) return {};
59
+
60
+ const url = await remoteUrl(cwd, remoteName);
61
+ return resolveGitEnv(projectId, userId, url);
62
+ } catch (error) {
63
+ debug.warn('git', 'Could not resolve a git identity for this remote:', error);
64
+ return {};
65
+ }
66
+ }
67
+
68
+ /**
69
+ * The URL behind a remote name.
70
+ *
71
+ * Falls back to `origin` when no name is given, because that is what git itself
72
+ * does for a branch with no upstream — and a branch WITH an upstream is
73
+ * overwhelmingly tracking origin too.
74
+ */
75
+ async function remoteUrl(cwd: string, remoteName?: string): Promise<string | null> {
76
+ try {
77
+ const remotes = await gitService.getRemotes(cwd);
78
+ if (remotes.length === 0) return null;
79
+ const wanted = remoteName ?? 'origin';
80
+ const match = remotes.find((r) => r.name === wanted);
81
+ // A repo with exactly one remote under a different name is unambiguous, so
82
+ // using it beats declining to pick a credential at all.
83
+ const chosen = match ?? (remotes.length === 1 ? remotes[0] : undefined);
84
+ if (!chosen) return null;
85
+ // Push URL first: it is the one that needs a credential, and a remote
86
+ // configured with separate fetch/push URLs is doing so deliberately.
87
+ return chosen.pushUrl || chosen.fetchUrl || null;
88
+ } catch {
89
+ return null;
90
+ }
91
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Git identity handlers — CRUD for Settings, binding for a project, and the
3
+ * "who will this be committed as" read the Git panel shows.
4
+ *
5
+ * Every response is a DTO from `backend/git/identity/service`, so no private
6
+ * key, passphrase or token can reach a client from here. The public key is the
7
+ * one piece of key material that crosses, and it is public by definition.
8
+ *
9
+ * Identities are owned per user, and every handler resolves the owner from the
10
+ * connection rather than from the payload. A client cannot name whose
11
+ * identities it wants to read or change.
12
+ */
13
+
14
+ import { t } from 'elysia';
15
+ import { createRouter } from '$shared/utils/ws-server';
16
+ import { gitIdentityService, describeIdentity } from '$backend/git/identity';
17
+ import { requireProjectWorkspace } from '../access';
18
+ import { ws } from '$backend/utils/ws';
19
+ import { gitService } from '$backend/git/git-service';
20
+ import { debug } from '$shared/utils/logger';
21
+ import type { GitIdentityAuthMethod } from '$shared/types/git-identity';
22
+
23
+ const AUTH_METHOD = t.Union([
24
+ t.Literal('none'),
25
+ t.Literal('ssh-key'),
26
+ t.Literal('https-token'),
27
+ t.Literal('https-account')
28
+ ]);
29
+
30
+ /** The DTO shape, mirrored for the wire schema. */
31
+ const IDENTITY = t.Object({
32
+ id: t.String(),
33
+ label: t.String(),
34
+ name: t.String(),
35
+ email: t.String(),
36
+ authMethod: AUTH_METHOD,
37
+ hosts: t.Array(t.String()),
38
+ sshPublicKey: t.Union([t.String(), t.Null()]),
39
+ hasSshKey: t.Boolean(),
40
+ hasSshPassphrase: t.Boolean(),
41
+ hasHttpsToken: t.Boolean(),
42
+ httpsUsername: t.Union([t.String(), t.Null()]),
43
+ integrationAccountId: t.Union([t.String(), t.Null()]),
44
+ isDefault: t.Boolean(),
45
+ source: t.Union([t.Literal('manual'), t.Literal('local-machine')]),
46
+ canDelete: t.Boolean(),
47
+ createdAt: t.String(),
48
+ updatedAt: t.String()
49
+ });
50
+
51
+ /**
52
+ * Write fields.
53
+ *
54
+ * Secrets are `Optional` AND nullable on purpose, and the distinction is
55
+ * load-bearing: absent means "keep what is stored", explicit `null` means
56
+ * "clear it". Anything else would force the browser to hold a private key just
57
+ * to rename an identity.
58
+ */
59
+ const INPUT = t.Object({
60
+ label: t.String({ minLength: 1 }),
61
+ name: t.String({ minLength: 1 }),
62
+ email: t.String({ minLength: 1 }),
63
+ authMethod: AUTH_METHOD,
64
+ hosts: t.Array(t.String()),
65
+ sshPrivateKey: t.Optional(t.Union([t.String(), t.Null()])),
66
+ sshPublicKey: t.Optional(t.Union([t.String(), t.Null()])),
67
+ sshPassphrase: t.Optional(t.Union([t.String(), t.Null()])),
68
+ httpsUsername: t.Optional(t.Union([t.String(), t.Null()])),
69
+ httpsToken: t.Optional(t.Union([t.String(), t.Null()])),
70
+ integrationAccountId: t.Optional(t.Union([t.String(), t.Null()])),
71
+ isDefault: t.Optional(t.Boolean())
72
+ });
73
+
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
+ export const gitIdentityHandler = createRouter()
82
+ .http('git:identities', {
83
+ data: t.Object({}),
84
+ response: t.Object({ identities: t.Array(IDENTITY) })
85
+ }, async ({ conn }) => {
86
+ return { identities: await gitIdentityService.list(requireUserId(conn)) };
87
+ })
88
+
89
+ .http('git:identity-create', {
90
+ data: INPUT,
91
+ response: t.Object({ identity: IDENTITY })
92
+ }, async ({ data, conn }) => {
93
+ const identity = await gitIdentityService.create(requireUserId(conn), {
94
+ ...data,
95
+ authMethod: data.authMethod as GitIdentityAuthMethod
96
+ });
97
+ return { identity };
98
+ })
99
+
100
+ .http('git:identity-update', {
101
+ data: t.Intersect([INPUT, t.Object({ id: t.String() })]),
102
+ response: t.Object({ identity: IDENTITY })
103
+ }, async ({ data, conn }) => {
104
+ const { id, ...input } = data;
105
+ const identity = await gitIdentityService.update(requireUserId(conn), id, {
106
+ ...input,
107
+ authMethod: input.authMethod as GitIdentityAuthMethod
108
+ });
109
+ return { identity };
110
+ })
111
+
112
+ .http('git:identity-delete', {
113
+ data: t.Object({ id: t.String() }),
114
+ response: t.Object({ ok: t.Boolean() })
115
+ }, async ({ data, conn }) => {
116
+ await gitIdentityService.remove(requireUserId(conn), data.id);
117
+ return { ok: true };
118
+ })
119
+
120
+ .http('git:identity-set-default', {
121
+ data: t.Object({ id: t.String() }),
122
+ response: t.Object({ identity: IDENTITY })
123
+ }, async ({ data, conn }) => {
124
+ return { identity: await gitIdentityService.setDefault(requireUserId(conn), data.id) };
125
+ })
126
+
127
+ /**
128
+ * Generate a keypair for an identity.
129
+ *
130
+ * Returns the public half and its fingerprint. The private key never leaves
131
+ * the server — it goes straight into the sealed column and the 0600 file.
132
+ */
133
+ .http('git:identity-generate-key', {
134
+ data: t.Object({ id: t.String() }),
135
+ response: t.Object({ publicKey: t.String(), fingerprint: t.String() })
136
+ }, async ({ data, conn }) => {
137
+ return await gitIdentityService.generateKey(requireUserId(conn), data.id);
138
+ })
139
+
140
+ /** How many projects would lose their binding if this identity went away. */
141
+ .http('git:identity-usage', {
142
+ data: t.Object({ id: t.String() }),
143
+ response: t.Object({ projectCount: t.Number() })
144
+ }, async ({ data, conn }) => {
145
+ requireUserId(conn);
146
+ return { projectCount: gitIdentityService.bindingCount(data.id) };
147
+ })
148
+
149
+ /** Bind this project to an identity, or clear the binding with `null`. */
150
+ .http('git:identity-bind', {
151
+ data: t.Object({
152
+ projectId: t.String(),
153
+ identityId: t.Union([t.String(), t.Null()])
154
+ }),
155
+ response: t.Object({ ok: t.Boolean() })
156
+ }, async ({ data, conn }) => {
157
+ // Access is the project's call, exactly as for every other git operation.
158
+ requireProjectWorkspace(conn, data.projectId);
159
+ await gitIdentityService.bind(requireUserId(conn), data.projectId, data.identityId);
160
+ return { ok: true };
161
+ })
162
+
163
+ /**
164
+ * Who the next commit in this project will be attributed to.
165
+ *
166
+ * Drives the line above the commit box. `source` distinguishes an identity
167
+ * chosen for this project from one inherited as the user's default, which is
168
+ * the difference between "this is right" and "check this before you push".
169
+ */
170
+ .http('git:identity-resolved', {
171
+ data: t.Object({
172
+ projectId: t.String(),
173
+ /** Remote to resolve the credential against. Defaults to origin. */
174
+ remote: t.Optional(t.String())
175
+ }),
176
+ response: t.Object({
177
+ identity: t.Union([IDENTITY, t.Null()]),
178
+ source: t.Union([t.Literal('project'), t.Literal('user-default'), t.Literal('none')]),
179
+ credentialIdentity: t.Union([IDENTITY, t.Null()])
180
+ })
181
+ }, async ({ data, conn }) => {
182
+ const { root } = requireProjectWorkspace(conn, data.projectId);
183
+ const userId = requireUserId(conn);
184
+
185
+ // The remote URL decides which identity's credential answers, so it is
186
+ // resolved here too — a fork whose origin and upstream sit on different
187
+ // accounts is exactly what the panel needs to be able to show.
188
+ let remoteUrl: string | null = null;
189
+ try {
190
+ const remotes = await gitService.getRemotes(root);
191
+ const wanted = data.remote ?? 'origin';
192
+ const match = remotes.find((r) => r.name === wanted) ?? (remotes.length === 1 ? remotes[0] : undefined);
193
+ remoteUrl = match ? match.pushUrl || match.fetchUrl : null;
194
+ } catch (error) {
195
+ // A project that is not a repo yet still has an identity to report.
196
+ debug.log('git', 'No remotes to resolve an identity credential against:', error);
197
+ }
198
+
199
+ return describeIdentity(data.projectId, userId, remoteUrl);
200
+ });
@@ -15,6 +15,7 @@ import { conflictHandler } from './conflict';
15
15
  import { commitMessageHandler } from './commit-message';
16
16
  import { branchNameHandler } from './branch-name';
17
17
  import { ignoredHandler } from './ignored';
18
+ import { gitIdentityHandler } from './identity';
18
19
 
19
20
  export const gitRouter = createRouter()
20
21
  .merge(statusHandler)
@@ -27,4 +28,5 @@ export const gitRouter = createRouter()
27
28
  .merge(conflictHandler)
28
29
  .merge(commitMessageHandler)
29
30
  .merge(branchNameHandler)
30
- .merge(ignoredHandler);
31
+ .merge(ignoredHandler)
32
+ .merge(gitIdentityHandler);
@@ -7,6 +7,7 @@ import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { requireProjectWorkspace } from '../access';
10
+ import { identityEnvFor, identityEnvForRemote } from './identity-context';
10
11
  import { debug } from '$shared/utils/logger';
11
12
 
12
13
  /**
@@ -54,7 +55,11 @@ export const remoteHandler = createRouter()
54
55
  }, async ({ data, conn }) => {
55
56
  const { root } = requireProjectWorkspace(conn, data.projectId);
56
57
  const cwd = resolveRepoCwd(root, data.repoPath);
57
- const message = await gitService.fetch(cwd, data.remote);
58
+ const message = await gitService.fetch(
59
+ cwd,
60
+ data.remote,
61
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
62
+ );
58
63
  return { message };
59
64
  })
60
65
 
@@ -73,7 +78,13 @@ export const remoteHandler = createRouter()
73
78
  }, async ({ data, conn }) => {
74
79
  const { root } = requireProjectWorkspace(conn, data.projectId);
75
80
  const cwd = resolveRepoCwd(root, data.repoPath);
76
- return await gitService.pull(cwd, data.remote, data.branch, data.rebase);
81
+ return await gitService.pull(
82
+ cwd,
83
+ data.remote,
84
+ data.branch,
85
+ data.rebase,
86
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
87
+ );
77
88
  })
78
89
 
79
90
  .http('git:push-advanced', {
@@ -96,7 +107,13 @@ export const remoteHandler = createRouter()
96
107
  }, async ({ data, conn }) => {
97
108
  const { root } = requireProjectWorkspace(conn, data.projectId);
98
109
  const cwd = resolveRepoCwd(root, data.repoPath);
99
- return await gitService.pushAdvanced(cwd, data.mode, data.remote, data.branch);
110
+ return await gitService.pushAdvanced(
111
+ cwd,
112
+ data.mode,
113
+ data.remote,
114
+ data.branch,
115
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
116
+ );
100
117
  })
101
118
 
102
119
  .http('git:fetch-all', {
@@ -110,7 +127,10 @@ export const remoteHandler = createRouter()
110
127
  }, async ({ data, conn }) => {
111
128
  const { root } = requireProjectWorkspace(conn, data.projectId);
112
129
  const cwd = resolveRepoCwd(root, data.repoPath);
113
- const message = await gitService.fetchAll(cwd);
130
+ const message = await gitService.fetchAll(
131
+ cwd,
132
+ await identityEnvForRemote(conn, data.projectId, cwd)
133
+ );
114
134
  return { message };
115
135
  })
116
136
 
@@ -134,9 +154,14 @@ export const remoteHandler = createRouter()
134
154
  }, async ({ data, conn }) => {
135
155
  const { root } = requireProjectWorkspace(conn, data.projectId);
136
156
  const cwd = resolveRepoCwd(root, data.repoPath);
137
- return await gitService.push(cwd, data.remote, data.branch, data.force, {
138
- useUpstream: data.useUpstream ?? true
139
- });
157
+ return await gitService.push(
158
+ cwd,
159
+ data.remote,
160
+ data.branch,
161
+ data.force,
162
+ { useUpstream: data.useUpstream ?? true },
163
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
164
+ );
140
165
  })
141
166
 
142
167
  /** Where a push would actually land — drives the Push button's label. */
@@ -278,7 +303,12 @@ export const remoteHandler = createRouter()
278
303
  }, async ({ data, conn }) => {
279
304
  const { root } = requireProjectWorkspace(conn, data.projectId);
280
305
  const cwd = resolveRepoCwd(root, data.repoPath);
281
- await gitService.deleteRemoteBranch(cwd, data.remote, data.branch);
306
+ await gitService.deleteRemoteBranch(
307
+ cwd,
308
+ data.remote,
309
+ data.branch,
310
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
311
+ );
282
312
  return { ok: true };
283
313
  })
284
314
 
@@ -309,7 +339,12 @@ export const remoteHandler = createRouter()
309
339
  }, async ({ data, conn }) => {
310
340
  const { root } = requireProjectWorkspace(conn, data.projectId);
311
341
  const cwd = resolveRepoCwd(root, data.repoPath);
312
- await gitService.stashSave(cwd, data.message, data.staged);
342
+ await gitService.stashSave(
343
+ cwd,
344
+ data.message,
345
+ data.staged,
346
+ identityEnvFor(conn, data.projectId)
347
+ );
313
348
  return { ok: true };
314
349
  })
315
350
 
@@ -422,7 +457,13 @@ export const remoteHandler = createRouter()
422
457
  }, async ({ data, conn }) => {
423
458
  const { root } = requireProjectWorkspace(conn, data.projectId);
424
459
  const cwd = resolveRepoCwd(root, data.repoPath);
425
- await gitService.createTag(cwd, data.name, data.message, data.commitHash);
460
+ await gitService.createTag(
461
+ cwd,
462
+ data.name,
463
+ data.message,
464
+ data.commitHash,
465
+ identityEnvFor(conn, data.projectId)
466
+ );
426
467
  return { ok: true };
427
468
  })
428
469
 
@@ -454,5 +495,10 @@ export const remoteHandler = createRouter()
454
495
  }, async ({ data, conn }) => {
455
496
  const { root } = requireProjectWorkspace(conn, data.projectId);
456
497
  const cwd = resolveRepoCwd(root, data.repoPath);
457
- return await gitService.pushTag(cwd, data.name, data.remote);
498
+ return await gitService.pushTag(
499
+ cwd,
500
+ data.name,
501
+ data.remote,
502
+ await identityEnvForRemote(conn, data.projectId, cwd, data.remote)
503
+ );
458
504
  });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Browsing Data WebSocket Handler
3
+ *
4
+ * The preview keeps a Chrome profile per workspace, so a login made in a
5
+ * preview tab outlives the tab, the panel and the server. That is the point —
6
+ * and it is also why there has to be a way to take it back. These are the
7
+ * preview's equivalent of a browser's "clear browsing data": one site, or all
8
+ * of them.
9
+ *
10
+ * **PROJECT ISOLATION**: the profile is the project's, and so is the clear.
11
+ */
12
+
13
+ import { t } from 'elysia';
14
+ import { createRouter } from '$shared/utils/ws-server';
15
+ import { requireBrowserPreviewAccess } from '../access';
16
+
17
+ export const browsingDataPreviewHandler = createRouter()
18
+ // Sites this workspace's preview browser holds data for
19
+ .http(
20
+ 'preview:browser-data-list',
21
+ {
22
+ data: t.Object({}),
23
+ response: t.Object({
24
+ sites: t.Array(
25
+ t.Object({
26
+ domain: t.String(),
27
+ origin: t.String(),
28
+ cookies: t.Number(),
29
+ open: t.Boolean()
30
+ })
31
+ )
32
+ })
33
+ },
34
+ async ({ conn }) => {
35
+ const { previewService } = requireBrowserPreviewAccess(conn);
36
+ return { sites: await previewService.listBrowsingData() };
37
+ }
38
+ )
39
+
40
+ // Forget one site, or everything
41
+ .http(
42
+ 'preview:browser-data-clear',
43
+ {
44
+ data: t.Object({
45
+ /**
46
+ * Origin to clear. Omitted means every site — including ones
47
+ * whose tab has long been closed, which is the case the
48
+ * per-origin call cannot reach.
49
+ */
50
+ origin: t.Optional(t.String())
51
+ }),
52
+ response: t.Object({
53
+ success: t.Boolean()
54
+ })
55
+ },
56
+ async ({ data, conn }) => {
57
+ const { previewService } = requireBrowserPreviewAccess(conn);
58
+ return { success: await previewService.clearBrowsingData(data.origin) };
59
+ }
60
+ );
@@ -116,6 +116,12 @@ export const interactPreviewHandler = createRouter()
116
116
  // Mark tab activity to prevent automatic cleanup
117
117
  previewService.markActiveTabActivity();
118
118
 
119
+ // A tab nobody was watching is frozen: its task queues are suspended,
120
+ // so an input event dispatched now would sit unprocessed until the
121
+ // page happened to be woken by something else. Awaited rather than
122
+ // nudged — the click has to land on a running page, not the next one.
123
+ await previewService.ensureTabAwake(tabId);
124
+
119
125
  // Execute the interaction based on type with navigation-safe error handling
120
126
  try {
121
127
  switch (action.type) {
@@ -27,7 +27,8 @@ export const tabInfoPreviewHandler = createRouter()
27
27
  rotation: t.String(),
28
28
  isActive: t.Boolean(),
29
29
  canGoBack: t.Boolean(),
30
- canGoForward: t.Boolean()
30
+ canGoForward: t.Boolean(),
31
+ isSleeping: t.Optional(t.Boolean())
31
32
  })
32
33
  }, async ({ data, conn }) => {
33
34
  const { tabId } = data;
@@ -63,6 +64,12 @@ export const tabInfoPreviewHandler = createRouter()
63
64
  isActive: t.Boolean(),
64
65
  canGoBack: t.Boolean(),
65
66
  canGoForward: t.Boolean(),
67
+ /**
68
+ * Whether the page is frozen for want of an audience. Recovered
69
+ * with everything else so a reload does not paint a suspended
70
+ * page as a running one.
71
+ */
72
+ isSleeping: t.Optional(t.Boolean()),
66
73
  isMcpControlled: t.Boolean(),
67
74
  /** Whether an agent is acting on this tab right now. */
68
75
  isMcpFocused: t.Boolean(),
@@ -119,6 +126,7 @@ export const tabInfoPreviewHandler = createRouter()
119
126
  isActive: tab.isActive,
120
127
  canGoBack: tab.canGoBack,
121
128
  canGoForward: tab.canGoForward,
129
+ isSleeping: tab.isSleeping,
122
130
  isMcpControlled: browserMcpControl.isTabControlled(tab.id, projectId),
123
131
  isMcpFocused: browserMcpControl.isTabFocused(tab.id),
124
132
  mcpActivity: browserMcpControl.getActivity(tab.id) ?? undefined,