@myrialabs/clopen 0.4.41 → 0.4.43
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/backend/chat/stream-manager.ts +8 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/index.ts +18 -0
- package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
- package/backend/database/migrations/082_create_git_identities.ts +122 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/git-identity-queries.ts +290 -0
- package/backend/database/queries/index.ts +2 -0
- package/backend/db-client/env/detect.ts +2 -1
- package/backend/engine/adapters/claude/environment.ts +11 -1
- package/backend/engine/adapters/claude/models.ts +147 -18
- package/backend/engine/adapters/claude/stream.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +13 -9
- package/backend/engine/adapters/codex/stream.ts +35 -3
- package/backend/engine/adapters/opencode/server.ts +26 -2
- package/backend/engine/adapters/opencode/stream.ts +4 -1
- package/backend/engine/adapters/qwen/stream.ts +3 -1
- package/backend/engine/types.ts +10 -0
- package/backend/env-files/discovery.ts +2 -1
- package/backend/files/file-reading.ts +4 -3
- package/backend/files/path-browsing.ts +2 -1
- package/backend/git/git-executor.ts +28 -2
- package/backend/git/git-service.ts +61 -41
- package/backend/git/identity/cli.test.ts +58 -0
- package/backend/git/identity/cli.ts +201 -0
- package/backend/git/identity/credential-helper.test.ts +242 -0
- package/backend/git/identity/env.test.ts +214 -0
- package/backend/git/identity/env.ts +193 -0
- package/backend/git/identity/import-local.test.ts +199 -0
- package/backend/git/identity/import-local.ts +141 -0
- package/backend/git/identity/index.ts +78 -0
- package/backend/git/identity/keys.ts +183 -0
- package/backend/git/identity/resolve.ts +140 -0
- package/backend/git/identity/scope-config.test.ts +145 -0
- package/backend/git/identity/scope-config.ts +175 -0
- package/backend/git/identity/service.ts +297 -0
- package/backend/index.ts +16 -0
- package/backend/preview/browser/browser-console-manager.ts +214 -34
- package/backend/preview/browser/browser-pool.ts +526 -123
- package/backend/preview/browser/browser-preview-service.ts +192 -8
- package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
- package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
- package/backend/preview/browser/browser-tab-manager.ts +291 -65
- package/backend/preview/browser/capture-profile.ts +15 -1
- package/backend/preview/browser/types.ts +26 -1
- package/backend/snapshot/turn-changes.ts +3 -2
- package/backend/ssh/sftp.ts +2 -1
- package/backend/terminal/ptykit.ts +24 -0
- package/backend/worktrees/merge.ts +2 -1
- package/backend/ws/git/branch.ts +17 -6
- package/backend/ws/git/commit.ts +6 -5
- package/backend/ws/git/conflict.ts +3 -2
- package/backend/ws/git/identity-context.ts +91 -0
- package/backend/ws/git/identity.ts +200 -0
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/remote.ts +57 -11
- package/backend/ws/preview/browser/data.ts +60 -0
- package/backend/ws/preview/browser/interact.ts +6 -0
- package/backend/ws/preview/browser/tab-info.ts +9 -1
- package/backend/ws/preview/browser/tab.ts +64 -8
- package/backend/ws/preview/index.ts +21 -0
- package/bin/clopen.ts +9 -0
- package/dist/assets/{index-CeNKKSDR.js → index-B6u8cait.js} +1 -1
- package/dist/assets/{index-DW89566K.js → index-BeUKiRiY.js} +1 -1
- package/dist/assets/{main-Cy5DXWPT.js → main-CMRXlv2f.js} +604 -596
- package/dist/assets/main-DzCY0n-j.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +2 -2
- package/shared/types/git-identity.ts +112 -0
- package/shared/utils/compare.test.ts +46 -0
- package/shared/utils/compare.ts +21 -0
- package/dist/assets/main-DJKj_4By.css +0 -1
|
@@ -42,6 +42,7 @@ import type {
|
|
|
42
42
|
DbEnvRole,
|
|
43
43
|
DbEnvShape
|
|
44
44
|
} from '$shared/types/db-client';
|
|
45
|
+
import { naturalCompare } from '$shared/utils/compare';
|
|
45
46
|
import { debug } from '$shared/utils/logger';
|
|
46
47
|
|
|
47
48
|
/** A value that is unmistakably a database connection string. */
|
|
@@ -396,7 +397,7 @@ export async function detectEnvUsage(input: {
|
|
|
396
397
|
|
|
397
398
|
const keys = [...draft.keys.keys()].sort();
|
|
398
399
|
const orderedFiles = [...draft.files].sort(
|
|
399
|
-
(a, b) => envFilePrecedence(a) - envFilePrecedence(b) || a
|
|
400
|
+
(a, b) => envFilePrecedence(a) - envFilePrecedence(b) || naturalCompare(a, b)
|
|
400
401
|
);
|
|
401
402
|
const isTemplateOnly = draft.liveFiles.length === 0;
|
|
402
403
|
const where = orderedFiles[0] ?? [...draft.sources][0] ?? 'this project';
|
|
@@ -57,8 +57,16 @@ export async function setupEnvironmentOnce(): Promise<void> {
|
|
|
57
57
|
*
|
|
58
58
|
* When accountId is provided, overrides the OAuth token with that
|
|
59
59
|
* specific account's token instead of the globally active account.
|
|
60
|
+
*
|
|
61
|
+
* `extraEnv` is applied last and carries per-turn values the caller resolved —
|
|
62
|
+
* in practice the requester's git identity, so a `git commit` the agent runs
|
|
63
|
+
* through its shell tool is authored by the same person the Git panel would
|
|
64
|
+
* attribute it to.
|
|
60
65
|
*/
|
|
61
|
-
export function getEngineEnv(
|
|
66
|
+
export function getEngineEnv(
|
|
67
|
+
accountId?: number,
|
|
68
|
+
extraEnv?: Record<string, string>
|
|
69
|
+
): Record<string, string> {
|
|
62
70
|
// Start from clean env (no Bun/npm/Vite pollution)
|
|
63
71
|
const env = getCleanSpawnEnv();
|
|
64
72
|
// Apply our overrides
|
|
@@ -77,6 +85,8 @@ export function getEngineEnv(accountId?: number): Record<string, string> {
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
if (extraEnv) Object.assign(env, extraEnv);
|
|
89
|
+
|
|
80
90
|
return env;
|
|
81
91
|
}
|
|
82
92
|
|
|
@@ -32,8 +32,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
32
32
|
type: 'claude-code',
|
|
33
33
|
provider: 'anthropic',
|
|
34
34
|
model: {
|
|
35
|
-
id: 'claude-fable-5',
|
|
36
|
-
name: 'Claude Fable 5',
|
|
35
|
+
id: 'claude-fable-5-1',
|
|
36
|
+
name: 'Claude Fable 5.1',
|
|
37
37
|
},
|
|
38
38
|
account: {
|
|
39
39
|
id: 0,
|
|
@@ -75,8 +75,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
75
75
|
type: 'claude-code',
|
|
76
76
|
provider: 'anthropic',
|
|
77
77
|
model: {
|
|
78
|
-
id: 'claude-opus-5',
|
|
79
|
-
name: 'Claude Opus 5',
|
|
78
|
+
id: 'claude-opus-5-5',
|
|
79
|
+
name: 'Claude Opus 5.5',
|
|
80
80
|
},
|
|
81
81
|
account: {
|
|
82
82
|
id: 0,
|
|
@@ -109,8 +109,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
109
109
|
structuredOutput: true,
|
|
110
110
|
},
|
|
111
111
|
cost: {
|
|
112
|
-
input:
|
|
113
|
-
output:
|
|
112
|
+
input: 4,
|
|
113
|
+
output: 20,
|
|
114
114
|
},
|
|
115
115
|
},
|
|
116
116
|
{
|
|
@@ -118,8 +118,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
118
118
|
type: 'claude-code',
|
|
119
119
|
provider: 'anthropic',
|
|
120
120
|
model: {
|
|
121
|
-
id: 'claude-sonnet-5',
|
|
122
|
-
name: 'Claude Sonnet 5',
|
|
121
|
+
id: 'claude-sonnet-5-5',
|
|
122
|
+
name: 'Claude Sonnet 5.5',
|
|
123
123
|
},
|
|
124
124
|
account: {
|
|
125
125
|
id: 0,
|
|
@@ -152,8 +152,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
152
152
|
structuredOutput: true,
|
|
153
153
|
},
|
|
154
154
|
cost: {
|
|
155
|
-
input:
|
|
156
|
-
output:
|
|
155
|
+
input: 2,
|
|
156
|
+
output: 10,
|
|
157
157
|
},
|
|
158
158
|
},
|
|
159
159
|
{
|
|
@@ -199,6 +199,135 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
199
199
|
output: 5,
|
|
200
200
|
},
|
|
201
201
|
},
|
|
202
|
+
{
|
|
203
|
+
engine: {
|
|
204
|
+
type: 'claude-code',
|
|
205
|
+
provider: 'anthropic',
|
|
206
|
+
model: {
|
|
207
|
+
id: 'claude-fable-5',
|
|
208
|
+
name: 'Claude Fable 5',
|
|
209
|
+
},
|
|
210
|
+
account: {
|
|
211
|
+
id: 0,
|
|
212
|
+
name: '',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
limit: {
|
|
216
|
+
input: 1_000_000,
|
|
217
|
+
output: 128_000,
|
|
218
|
+
},
|
|
219
|
+
modalities: {
|
|
220
|
+
input: {
|
|
221
|
+
text: true,
|
|
222
|
+
image: true,
|
|
223
|
+
audio: false,
|
|
224
|
+
video: false,
|
|
225
|
+
pdf: true,
|
|
226
|
+
},
|
|
227
|
+
output: {
|
|
228
|
+
text: true,
|
|
229
|
+
image: false,
|
|
230
|
+
audio: false,
|
|
231
|
+
video: false,
|
|
232
|
+
pdf: false,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
capabilities: {
|
|
236
|
+
reasoning: true,
|
|
237
|
+
tools: true,
|
|
238
|
+
structuredOutput: true,
|
|
239
|
+
},
|
|
240
|
+
cost: {
|
|
241
|
+
input: 10,
|
|
242
|
+
output: 50,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
engine: {
|
|
247
|
+
type: 'claude-code',
|
|
248
|
+
provider: 'anthropic',
|
|
249
|
+
model: {
|
|
250
|
+
id: 'claude-opus-5',
|
|
251
|
+
name: 'Claude Opus 5',
|
|
252
|
+
},
|
|
253
|
+
account: {
|
|
254
|
+
id: 0,
|
|
255
|
+
name: '',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
limit: {
|
|
259
|
+
input: 1_000_000,
|
|
260
|
+
output: 128_000,
|
|
261
|
+
},
|
|
262
|
+
modalities: {
|
|
263
|
+
input: {
|
|
264
|
+
text: true,
|
|
265
|
+
image: true,
|
|
266
|
+
audio: false,
|
|
267
|
+
video: false,
|
|
268
|
+
pdf: true,
|
|
269
|
+
},
|
|
270
|
+
output: {
|
|
271
|
+
text: true,
|
|
272
|
+
image: false,
|
|
273
|
+
audio: false,
|
|
274
|
+
video: false,
|
|
275
|
+
pdf: false,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
capabilities: {
|
|
279
|
+
reasoning: true,
|
|
280
|
+
tools: true,
|
|
281
|
+
structuredOutput: true,
|
|
282
|
+
},
|
|
283
|
+
cost: {
|
|
284
|
+
input: 5,
|
|
285
|
+
output: 25,
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
engine: {
|
|
290
|
+
type: 'claude-code',
|
|
291
|
+
provider: 'anthropic',
|
|
292
|
+
model: {
|
|
293
|
+
id: 'claude-sonnet-5',
|
|
294
|
+
name: 'Claude Sonnet 5',
|
|
295
|
+
},
|
|
296
|
+
account: {
|
|
297
|
+
id: 0,
|
|
298
|
+
name: '',
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
limit: {
|
|
302
|
+
input: 1_000_000,
|
|
303
|
+
output: 128_000,
|
|
304
|
+
},
|
|
305
|
+
modalities: {
|
|
306
|
+
input: {
|
|
307
|
+
text: true,
|
|
308
|
+
image: true,
|
|
309
|
+
audio: false,
|
|
310
|
+
video: false,
|
|
311
|
+
pdf: true,
|
|
312
|
+
},
|
|
313
|
+
output: {
|
|
314
|
+
text: true,
|
|
315
|
+
image: false,
|
|
316
|
+
audio: false,
|
|
317
|
+
video: false,
|
|
318
|
+
pdf: false,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
capabilities: {
|
|
322
|
+
reasoning: true,
|
|
323
|
+
tools: true,
|
|
324
|
+
structuredOutput: true,
|
|
325
|
+
},
|
|
326
|
+
cost: {
|
|
327
|
+
input: 3,
|
|
328
|
+
output: 15,
|
|
329
|
+
},
|
|
330
|
+
},
|
|
202
331
|
{
|
|
203
332
|
engine: {
|
|
204
333
|
type: 'claude-code',
|
|
@@ -376,8 +505,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
376
505
|
type: 'claude-code',
|
|
377
506
|
provider: 'anthropic',
|
|
378
507
|
model: {
|
|
379
|
-
id: 'claude-
|
|
380
|
-
name: 'Claude
|
|
508
|
+
id: 'claude-opus-4-5',
|
|
509
|
+
name: 'Claude Opus 4.5',
|
|
381
510
|
},
|
|
382
511
|
account: {
|
|
383
512
|
id: 0,
|
|
@@ -410,8 +539,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
410
539
|
structuredOutput: true,
|
|
411
540
|
},
|
|
412
541
|
cost: {
|
|
413
|
-
input:
|
|
414
|
-
output:
|
|
542
|
+
input: 5,
|
|
543
|
+
output: 25,
|
|
415
544
|
},
|
|
416
545
|
},
|
|
417
546
|
{
|
|
@@ -419,8 +548,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
419
548
|
type: 'claude-code',
|
|
420
549
|
provider: 'anthropic',
|
|
421
550
|
model: {
|
|
422
|
-
id: 'claude-
|
|
423
|
-
name: 'Claude
|
|
551
|
+
id: 'claude-sonnet-4-5',
|
|
552
|
+
name: 'Claude Sonnet 4.5',
|
|
424
553
|
},
|
|
425
554
|
account: {
|
|
426
555
|
id: 0,
|
|
@@ -453,8 +582,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
|
453
582
|
structuredOutput: true,
|
|
454
583
|
},
|
|
455
584
|
cost: {
|
|
456
|
-
input:
|
|
457
|
-
output:
|
|
585
|
+
input: 3,
|
|
586
|
+
output: 15,
|
|
458
587
|
},
|
|
459
588
|
},
|
|
460
589
|
];
|
|
@@ -226,7 +226,7 @@ export class ClaudeCodeEngine implements AIEngine {
|
|
|
226
226
|
permissionMode: 'bypassPermissions' as PermissionMode,
|
|
227
227
|
allowDangerouslySkipPermissions: true,
|
|
228
228
|
cwd: resolvedProjectPath,
|
|
229
|
-
env: getEngineEnv(accountId),
|
|
229
|
+
env: getEngineEnv(accountId, options.gitIdentityEnv),
|
|
230
230
|
systemPrompt: { type: "preset", preset: "claude_code" },
|
|
231
231
|
settingSources: ["user", "project", "local"],
|
|
232
232
|
forkSession: true,
|
|
@@ -9,10 +9,16 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Presence in that table decides membership here: `gpt-5.3-codex`, `gpt-5.4`
|
|
11
11
|
* and `gpt-5.4-mini` left it in the 0.147 bump and are dropped (the 5.4 pair
|
|
12
|
-
* retires 2026-08-31). `gpt-5.3-codex-spark`
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* retires 2026-08-31). `gpt-5.2` and `gpt-5.3-codex-spark` are dropped too —
|
|
13
|
+
* both are gone from the shipped table and learn.chatgpt.com/docs/models no
|
|
14
|
+
* longer mentions either (the docs used to carve `-spark` out as a ChatGPT
|
|
15
|
+
* Pro-only exception, but that's no longer true).
|
|
16
|
+
*
|
|
17
|
+
* `gpt-daybreak-blue-latest`/`gpt-daybreak-red-latest` (specialized
|
|
18
|
+
* defensive/offensive cybersecurity-research variants) and
|
|
19
|
+
* `codex-auto-review` (an internal approval-review model) are in the shipped
|
|
20
|
+
* table but marked `visibility: "hide"` there, so they're deliberately left
|
|
21
|
+
* out of this picker too.
|
|
16
22
|
*
|
|
17
23
|
* Models tagged `requiresAuthMode` are filtered by the chat-input account
|
|
18
24
|
* picker so the user can't pick a ChatGPT-only model while signed in with an
|
|
@@ -72,15 +78,13 @@ function codexModel(
|
|
|
72
78
|
|
|
73
79
|
/** Ordered by the CLI's own `priority` field, so the picker matches Codex's. */
|
|
74
80
|
export const CODEX_MODELS: EngineModel[] = [
|
|
81
|
+
codexModel('gpt-6-astra', 'GPT-6-Astra', codexReasoning(EFFORTS_TO_ULTRA, 'low')),
|
|
82
|
+
codexModel('gpt-6-sol', 'GPT-6-Sol', codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
|
|
83
|
+
codexModel('gpt-6-luna', 'GPT-6-Luna', codexReasoning(EFFORTS_TO_MAX, 'medium')),
|
|
75
84
|
codexModel('gpt-5.6-sol', 'GPT-5.6-Sol', codexReasoning(EFFORTS_TO_ULTRA, 'low')),
|
|
76
85
|
codexModel('gpt-5.6-terra', 'GPT-5.6-Terra', codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
|
|
77
86
|
codexModel('gpt-5.6-luna', 'GPT-5.6-Luna', codexReasoning(EFFORTS_TO_MAX, 'medium')),
|
|
78
87
|
codexModel('gpt-5.5', 'GPT-5.5', codexReasoning(EFFORTS_TO_XHIGH, 'medium')),
|
|
79
|
-
codexModel('gpt-5.2', 'GPT-5.2', codexReasoning(EFFORTS_TO_XHIGH, 'medium')),
|
|
80
|
-
codexModel('gpt-5.3-codex-spark', 'GPT-5.3 Codex Spark (ChatGPT Pro)', null, {
|
|
81
|
-
image: false,
|
|
82
|
-
requiresAuthMode: 'chatgpt',
|
|
83
|
-
}),
|
|
84
88
|
];
|
|
85
89
|
|
|
86
90
|
/**
|
|
@@ -64,6 +64,17 @@ interface CodexRun {
|
|
|
64
64
|
thread: Thread | null;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* A stable key for an identity environment, so "same identity?" is a string
|
|
69
|
+
* compare rather than a deep object compare. Sorted because the builder's key
|
|
70
|
+
* order is an implementation detail, not a difference.
|
|
71
|
+
*/
|
|
72
|
+
function gitIdentityKey(env: Record<string, string>): string {
|
|
73
|
+
const keys = Object.keys(env).sort();
|
|
74
|
+
if (keys.length === 0) return '';
|
|
75
|
+
return keys.map((k) => `${k}=${env[k]}`).join('\u0000');
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
export class CodexEngine implements AIEngine {
|
|
68
79
|
readonly name = 'codex' as const;
|
|
69
80
|
|
|
@@ -104,6 +115,17 @@ export class CodexEngine implements AIEngine {
|
|
|
104
115
|
* satisfying that type.
|
|
105
116
|
*/
|
|
106
117
|
private pendingProjectId: string | null = null;
|
|
118
|
+
/**
|
|
119
|
+
* Git identity baked into the current client, as a comparable key.
|
|
120
|
+
*
|
|
121
|
+
* The SDK takes `env` at construction and does not re-read it, so the
|
|
122
|
+
* identity is part of what the client IS — exactly like the account and the
|
|
123
|
+
* MCP set. Stored as a stable string so a turn can ask "is this still the
|
|
124
|
+
* right client" without deep-comparing the environment.
|
|
125
|
+
*/
|
|
126
|
+
private currentGitIdentityKey: string | null = null;
|
|
127
|
+
/** Identity for the client `initialize()` is about to build. */
|
|
128
|
+
private pendingGitIdentityEnv: Record<string, string> = {};
|
|
107
129
|
|
|
108
130
|
get isInitialized(): boolean {
|
|
109
131
|
return this._isInitialized;
|
|
@@ -161,7 +183,7 @@ export class CodexEngine implements AIEngine {
|
|
|
161
183
|
this.codex = new Codex({
|
|
162
184
|
apiKey: credential.kind === 'api_key' ? credential.apiKey : undefined,
|
|
163
185
|
...(codexCli ? { codexPathOverride: codexCli.path } : {}),
|
|
164
|
-
env: { ...getCleanSpawnEnv(), CODEX_HOME: getCodexHomeDir() },
|
|
186
|
+
env: { ...getCleanSpawnEnv(), CODEX_HOME: getCodexHomeDir(), ...this.pendingGitIdentityEnv },
|
|
165
187
|
config: {
|
|
166
188
|
show_raw_agent_reasoning: true,
|
|
167
189
|
...(Object.keys(mcpConfig).length > 0 ? { mcp_servers: mcpConfig } : {}),
|
|
@@ -170,6 +192,7 @@ export class CodexEngine implements AIEngine {
|
|
|
170
192
|
this.currentAccountId = account.id;
|
|
171
193
|
this.currentMcpFilterKey = mcpKey;
|
|
172
194
|
this.currentProjectId = projectId;
|
|
195
|
+
this.currentGitIdentityKey = gitIdentityKey(this.pendingGitIdentityEnv);
|
|
173
196
|
this._isInitialized = true;
|
|
174
197
|
debug.log('engine', `Codex engine initialized (account ${account.id}, mode=${credential.kind}, mcpFilter=${mcpKey}, project=${projectId ?? 'none'})`);
|
|
175
198
|
}
|
|
@@ -180,6 +203,7 @@ export class CodexEngine implements AIEngine {
|
|
|
180
203
|
this.currentAccountId = null;
|
|
181
204
|
this.currentMcpFilterKey = null;
|
|
182
205
|
this.currentProjectId = null;
|
|
206
|
+
this.currentGitIdentityKey = null;
|
|
183
207
|
this._isInitialized = false;
|
|
184
208
|
debug.log('engine', 'Codex engine disposed');
|
|
185
209
|
}
|
|
@@ -219,11 +243,19 @@ export class CodexEngine implements AIEngine {
|
|
|
219
243
|
// ended up opening tabs in another.
|
|
220
244
|
const streamProjectId = options.mcpContext?.projectId ?? null;
|
|
221
245
|
const projectChanged = this._isInitialized && streamProjectId !== null && streamProjectId !== this.currentProjectId;
|
|
222
|
-
|
|
223
|
-
|
|
246
|
+
// One client serves every turn, so a turn requested by a different user —
|
|
247
|
+
// or in a project bound to a different identity — must not inherit the
|
|
248
|
+
// previous requester's git identity. Re-creating the client is the only
|
|
249
|
+
// way to change an env the SDK already baked.
|
|
250
|
+
const streamGitIdentityEnv = options.gitIdentityEnv ?? {};
|
|
251
|
+
const identityChanged =
|
|
252
|
+
this._isInitialized && gitIdentityKey(streamGitIdentityEnv) !== this.currentGitIdentityKey;
|
|
253
|
+
if (accountChanged || mcpChanged || projectChanged || identityChanged) {
|
|
254
|
+
debug.log('engine', `Codex re-initialising (accountChanged=${accountChanged}, mcpChanged=${mcpChanged}, projectChanged=${projectChanged}, identityChanged=${identityChanged})`);
|
|
224
255
|
await this.dispose();
|
|
225
256
|
}
|
|
226
257
|
this.pendingProjectId = streamProjectId;
|
|
258
|
+
this.pendingGitIdentityEnv = streamGitIdentityEnv;
|
|
227
259
|
if (!this._isInitialized || !this.codex) {
|
|
228
260
|
await this.initialize(accountId, mcpProfileFilter);
|
|
229
261
|
}
|
|
@@ -142,6 +142,19 @@ export interface ServerConfigSpec {
|
|
|
142
142
|
subagentFilter?: Set<string>;
|
|
143
143
|
/** Inline agent definitions (undefined/empty = the engine's default set). */
|
|
144
144
|
inlineAgents?: Record<string, OpenCodeInlineAgent>;
|
|
145
|
+
/**
|
|
146
|
+
* Git identity of whoever asked for this turn, as a `GIT_CONFIG_*` block.
|
|
147
|
+
*
|
|
148
|
+
* Folded into the signature for the same reason the connector set and the
|
|
149
|
+
* provider credentials are: the server process is spawned with it and cannot
|
|
150
|
+
* re-read it. One server serves every turn routed to it, so without this a
|
|
151
|
+
* second user's turn would reuse a server carrying the FIRST user's identity
|
|
152
|
+
* and commit under their name.
|
|
153
|
+
*
|
|
154
|
+
* In the ordinary case — one person, one identity — the block is identical
|
|
155
|
+
* every turn and the signature does not move, so no extra server is spawned.
|
|
156
|
+
*/
|
|
157
|
+
gitIdentityEnv?: Record<string, string>;
|
|
145
158
|
}
|
|
146
159
|
|
|
147
160
|
/** Everything needed to spawn a server, plus the key derived from it. */
|
|
@@ -150,6 +163,7 @@ interface SpawnPlan {
|
|
|
150
163
|
scopeKey: string;
|
|
151
164
|
configContent: string;
|
|
152
165
|
envVars: Record<string, string>;
|
|
166
|
+
gitIdentityEnv: Record<string, string>;
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
/**
|
|
@@ -653,13 +667,20 @@ async function resolvePlan(spec: ServerConfigSpec): Promise<SpawnPlan> {
|
|
|
653
667
|
// models.dev catalog it reads lives in `settings`, which bumps no revision.
|
|
654
668
|
const providerConfig = generateOpenCodeProviderConfig();
|
|
655
669
|
const configContent = assembleConfigContent(config, providerConfig.enabledProviders, spec.inlineAgents);
|
|
670
|
+
// Sorted so the key order the builder happens to emit is not mistaken for a
|
|
671
|
+
// different identity.
|
|
672
|
+
const gitIdentityEnv = spec.gitIdentityEnv ?? {};
|
|
673
|
+
const gitIdentityKey = Object.keys(gitIdentityEnv)
|
|
674
|
+
.sort()
|
|
675
|
+
.map((k) => `${k}=${gitIdentityEnv[k]}`)
|
|
676
|
+
.join('\u0000');
|
|
656
677
|
const signature = hashConfig(
|
|
657
|
-
`${configContent}‖${JSON.stringify(providerConfig.envVars)}‖${fingerprint}‖${internalBridgeExposure()}`
|
|
678
|
+
`${configContent}‖${JSON.stringify(providerConfig.envVars)}‖${fingerprint}‖${internalBridgeExposure()}‖${gitIdentityKey}`
|
|
658
679
|
);
|
|
659
680
|
const key = `${scopeKey}#${signature}`;
|
|
660
681
|
|
|
661
682
|
currentKeyByScope.set(scopeKey, key);
|
|
662
|
-
return { key, scopeKey, configContent, envVars: providerConfig.envVars };
|
|
683
|
+
return { key, scopeKey, configContent, envVars: providerConfig.envVars, gitIdentityEnv };
|
|
663
684
|
}
|
|
664
685
|
|
|
665
686
|
// ============================================================================
|
|
@@ -955,6 +976,9 @@ async function spawnServerOnce(
|
|
|
955
976
|
env: {
|
|
956
977
|
...process.env,
|
|
957
978
|
...plan.envVars,
|
|
979
|
+
// The identity this server was keyed on, so a `git commit` the agent
|
|
980
|
+
// runs is authored by the person whose turn spawned it.
|
|
981
|
+
...plan.gitIdentityEnv,
|
|
958
982
|
XDG_CONFIG_HOME: configDir,
|
|
959
983
|
XDG_DATA_HOME: dataDir,
|
|
960
984
|
XDG_STATE_HOME: dataDir,
|
|
@@ -228,7 +228,10 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
228
228
|
// stream keeps running until that stream is done. Holding the server by
|
|
229
229
|
// stream id is what makes that safe: a held server is never reaped.
|
|
230
230
|
const holderId = options.mcpContext?.streamId;
|
|
231
|
-
const server = await acquireServer(
|
|
231
|
+
const server = await acquireServer(
|
|
232
|
+
{ mcpProfileFilter, subagentFilter, inlineAgents, gitIdentityEnv: options.gitIdentityEnv },
|
|
233
|
+
holderId
|
|
234
|
+
);
|
|
232
235
|
run.server = server;
|
|
233
236
|
run.holder = holderId ? { key: server.key, holderId } : null;
|
|
234
237
|
const client = server.client;
|
|
@@ -150,7 +150,9 @@ export class QwenEngine implements AIEngine {
|
|
|
150
150
|
if (!resolution) {
|
|
151
151
|
throw new Error('Qwen Code is not configured. Add an API key in Settings → Engines → Qwen Code.');
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
// Layered here rather than inside `getEngineEnv` because the identity is a
|
|
154
|
+
// property of the turn, while that function answers "which account".
|
|
155
|
+
const env = { ...resolution.env, ...(options.gitIdentityEnv ?? {}) };
|
|
154
156
|
|
|
155
157
|
const controller = abortController || new AbortController();
|
|
156
158
|
const run: QwenRun = { controller, query: null, converter: null, pendingAskUserQuestion: null };
|
package/backend/engine/types.ts
CHANGED
|
@@ -46,6 +46,16 @@ export interface EngineQueryOptions {
|
|
|
46
46
|
accountId?: number;
|
|
47
47
|
/** Context bound to MCP tool handlers for project isolation */
|
|
48
48
|
mcpContext?: McpExecutionContext;
|
|
49
|
+
/**
|
|
50
|
+
* `GIT_CONFIG_*` block for the git identity of whoever asked for this turn
|
|
51
|
+
* (see `backend/git/identity`). Adapters merge it into the environment of
|
|
52
|
+
* the process they spawn, so a `git commit` the agent runs through its shell
|
|
53
|
+
* tool is authored by the same identity as one made from the Git panel.
|
|
54
|
+
*
|
|
55
|
+
* Resolved once per turn by the stream manager rather than by each adapter:
|
|
56
|
+
* the adapter knows how to spawn its engine, not who is driving it.
|
|
57
|
+
*/
|
|
58
|
+
gitIdentityEnv?: Record<string, string>;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
/** Options for one-shot structured generation (no tools, no streaming) */
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import fs from 'fs/promises';
|
|
11
|
+
import { naturalCompare } from '$shared/utils/compare';
|
|
11
12
|
import { envFilePrecedence, isDotenvFileName, isTemplateEnvFile } from './keys';
|
|
12
13
|
|
|
13
14
|
export interface DotenvFileEntry {
|
|
@@ -32,7 +33,7 @@ export async function listEnvFileEntries(projectRoot: string): Promise<DotenvFil
|
|
|
32
33
|
(a, b) =>
|
|
33
34
|
Number(a.isTemplate) - Number(b.isTemplate) ||
|
|
34
35
|
envFilePrecedence(a.name) - envFilePrecedence(b.name) ||
|
|
35
|
-
a.name
|
|
36
|
+
naturalCompare(a.name, b.name)
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -2,6 +2,7 @@ import { join, extname } from 'path';
|
|
|
2
2
|
import { readdir } from 'node:fs/promises';
|
|
3
3
|
import { readFileWithEncoding, isTextFile } from '$shared/utils/file-type-detection';
|
|
4
4
|
|
|
5
|
+
import { naturalCompare } from '$shared/utils/compare';
|
|
5
6
|
import { debug } from '$shared/utils/logger';
|
|
6
7
|
|
|
7
8
|
// Return types
|
|
@@ -100,7 +101,7 @@ export async function buildFileTree(
|
|
|
100
101
|
if (a.type !== b.type) {
|
|
101
102
|
return a.type === 'directory' ? -1 : 1;
|
|
102
103
|
}
|
|
103
|
-
return a.name
|
|
104
|
+
return naturalCompare(a.name, b.name);
|
|
104
105
|
});
|
|
105
106
|
|
|
106
107
|
return {
|
|
@@ -180,7 +181,7 @@ export async function listDirectoryContents(dirPath: string): Promise<FileTreeNo
|
|
|
180
181
|
if (a.type !== b.type) {
|
|
181
182
|
return a.type === 'directory' ? -1 : 1;
|
|
182
183
|
}
|
|
183
|
-
return a.name
|
|
184
|
+
return naturalCompare(a.name, b.name);
|
|
184
185
|
});
|
|
185
186
|
|
|
186
187
|
return children;
|
|
@@ -288,7 +289,7 @@ export async function searchFiles(rootPath: string, query: string): Promise<File
|
|
|
288
289
|
if (a.type !== b.type) {
|
|
289
290
|
return a.type === 'directory' ? -1 : 1;
|
|
290
291
|
}
|
|
291
|
-
return a.name
|
|
292
|
+
return naturalCompare(a.name, b.name);
|
|
292
293
|
});
|
|
293
294
|
|
|
294
295
|
// Limit results to prevent overwhelming the UI
|
|
@@ -2,6 +2,7 @@ import { join, extname } from 'path';
|
|
|
2
2
|
import { readdir as fsReaddir } from 'node:fs/promises';
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
|
+
import { naturalCompare } from '$shared/utils/compare';
|
|
5
6
|
import { debug } from '$shared/utils/logger';
|
|
6
7
|
|
|
7
8
|
// Cross-platform readdir using fs.promises
|
|
@@ -170,7 +171,7 @@ export async function handlePathBrowsing(path: string): Promise<PathBrowseData>
|
|
|
170
171
|
if (a.type !== b.type) {
|
|
171
172
|
return a.type === 'directory' ? -1 : 1;
|
|
172
173
|
}
|
|
173
|
-
return a.name
|
|
174
|
+
return naturalCompare(a.name, b.name);
|
|
174
175
|
});
|
|
175
176
|
|
|
176
177
|
return {
|
|
@@ -7,6 +7,15 @@ import { debug } from '$shared/utils/logger';
|
|
|
7
7
|
import { getCleanSpawnEnv } from '../utils/env';
|
|
8
8
|
import { resolveBinary } from '../utils/cli';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The environment fragment carrying a caller's git identity.
|
|
12
|
+
*
|
|
13
|
+
* An alias rather than a bare `Record<string, string>` so the operations that
|
|
14
|
+
* accept one say so in their signature — which is how a reader tells the
|
|
15
|
+
* commands that care who is running them from the ones that do not.
|
|
16
|
+
*/
|
|
17
|
+
export type GitIdentityEnv = Record<string, string>;
|
|
18
|
+
|
|
10
19
|
export interface GitExecResult {
|
|
11
20
|
stdout: string;
|
|
12
21
|
stderr: string;
|
|
@@ -23,6 +32,21 @@ export interface GitExecOptions {
|
|
|
23
32
|
* not logged as one — `check-ignore` exits 1 to say "nothing matched".
|
|
24
33
|
*/
|
|
25
34
|
okExitCodes?: number[];
|
|
35
|
+
/**
|
|
36
|
+
* Extra environment for this invocation — in practice the `GIT_CONFIG_*`
|
|
37
|
+
* block that carries the caller's git identity (see
|
|
38
|
+
* `backend/git/identity/env.ts`).
|
|
39
|
+
*
|
|
40
|
+
* Passed per command rather than resolved here because resolving an identity
|
|
41
|
+
* costs a database read, and `git status` runs many times a second. Commands
|
|
42
|
+
* that create an object or talk to a remote ask for it; the read-only ones
|
|
43
|
+
* never pay for it.
|
|
44
|
+
*
|
|
45
|
+
* Applied last, so an identity can override the fixed variables below. That
|
|
46
|
+
* ordering matters for `core.sshCommand`, which nothing else here sets but a
|
|
47
|
+
* future variable might.
|
|
48
|
+
*/
|
|
49
|
+
env?: Record<string, string>;
|
|
26
50
|
}
|
|
27
51
|
|
|
28
52
|
/**
|
|
@@ -36,7 +60,7 @@ export async function execGit(
|
|
|
36
60
|
): Promise<GitExecResult> {
|
|
37
61
|
const options: GitExecOptions =
|
|
38
62
|
typeof timeoutOrOptions === 'number' ? { timeout: timeoutOrOptions } : timeoutOrOptions;
|
|
39
|
-
const { timeout = 30000, stdin, okExitCodes = [] } = options;
|
|
63
|
+
const { timeout = 30000, stdin, okExitCodes = [], env: extraEnv } = options;
|
|
40
64
|
debug.log('git', `Executing: git ${args.join(' ')} in ${cwd}`);
|
|
41
65
|
|
|
42
66
|
const gitPath = resolveBinary('git');
|
|
@@ -70,7 +94,9 @@ export async function execGit(
|
|
|
70
94
|
GIT_SEQUENCE_EDITOR: 'true',
|
|
71
95
|
// Use English output for consistent parsing
|
|
72
96
|
LANG: 'en_US.UTF-8',
|
|
73
|
-
LC_ALL: 'en_US.UTF-8'
|
|
97
|
+
LC_ALL: 'en_US.UTF-8',
|
|
98
|
+
// The caller's git identity, last so it wins.
|
|
99
|
+
...extraEnv
|
|
74
100
|
}
|
|
75
101
|
});
|
|
76
102
|
|