@koreanhole/opencodex 3.2.34 → 3.2.36
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/package.json
CHANGED
|
@@ -317,6 +317,7 @@ export async function runClineTurn(
|
|
|
317
317
|
try {
|
|
318
318
|
staged = await (deps.stageTurn ?? stageClineTurn)({
|
|
319
319
|
providerSettingsPath,
|
|
320
|
+
sourceEnv,
|
|
320
321
|
catalog: catalog.tools,
|
|
321
322
|
...(catalog.emittedNameMap.size > 0 ? { mcpLaunch: mcpLaunch() } : {}),
|
|
322
323
|
...(sessionRoot ? { root: sessionRoot } : {}),
|
|
@@ -381,6 +382,7 @@ export async function runClineTurn(
|
|
|
381
382
|
maxToolCalls: 16,
|
|
382
383
|
requireToolCall: catalog.requireToolCall,
|
|
383
384
|
incoming,
|
|
385
|
+
...(staged.diagnostics?.length ? { diagnostics: staged.diagnostics } : {}),
|
|
384
386
|
onVendorSession: sessionId => { vendorSessionId ??= sessionId; },
|
|
385
387
|
}, event => {
|
|
386
388
|
if ((event.type === "done" || event.type === "error" || event.type === "incomplete") && !terminal) terminal = event;
|
|
@@ -60,6 +60,7 @@ export interface ClineJsonTurnInput {
|
|
|
60
60
|
maxToolCalls: number;
|
|
61
61
|
requireToolCall: boolean;
|
|
62
62
|
incoming: IncomingMeta;
|
|
63
|
+
diagnostics?: readonly string[];
|
|
63
64
|
/** First vendor session id reported by the turn; enables continuation storage. */
|
|
64
65
|
onVendorSession?: (sessionId: string) => void;
|
|
65
66
|
}
|
|
@@ -428,8 +429,18 @@ export async function runClineJsonTurn(
|
|
|
428
429
|
let timeoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
429
430
|
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
430
431
|
|
|
432
|
+
const withDiagnostics = (event: Extract<AdapterEvent, { type: "error" }>): Extract<AdapterEvent, { type: "error" }> => {
|
|
433
|
+
const notes = input.diagnostics?.filter(Boolean) ?? [];
|
|
434
|
+
if (notes.length === 0) return event;
|
|
435
|
+
if (event.code !== "cline_cli_not_logged_in" && event.message !== "Cline JSON ended without a terminal result.") {
|
|
436
|
+
return event;
|
|
437
|
+
}
|
|
438
|
+
const detail = redactSecretString(notes.join("; ")).slice(0, 768);
|
|
439
|
+
return { ...event, message: `${event.message} (${detail})` };
|
|
440
|
+
};
|
|
441
|
+
|
|
431
442
|
const deliver = (event: AdapterEvent): void => {
|
|
432
|
-
const
|
|
443
|
+
const candidate = event.type === "done" && input.requireToolCall && state.toolCalls === 0
|
|
433
444
|
? {
|
|
434
445
|
type: "error" as const,
|
|
435
446
|
message: "Cline returned no tool call for a request that requires one.",
|
|
@@ -439,6 +450,7 @@ export async function runClineJsonTurn(
|
|
|
439
450
|
retryable: false,
|
|
440
451
|
}
|
|
441
452
|
: event;
|
|
453
|
+
const terminal = candidate.type === "error" ? withDiagnostics(candidate) : candidate;
|
|
442
454
|
if (terminal.type === "done" || terminal.type === "error" || terminal.type === "incomplete") {
|
|
443
455
|
if (terminalEmitted) return;
|
|
444
456
|
terminalEmitted = true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { accessSync, constants, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { chmod, copyFile, link, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
2
3
|
import { homedir, tmpdir } from "node:os";
|
|
3
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
5
|
import { baseScopedEnv } from "../env";
|
|
@@ -59,11 +60,13 @@ export interface ClineStagedTurn {
|
|
|
59
60
|
workspaceDir: string;
|
|
60
61
|
hooksDir: string;
|
|
61
62
|
providerSettingsPath: string;
|
|
63
|
+
hasProviderSettings?: boolean;
|
|
62
64
|
legacyGlobalStatePath: string;
|
|
63
65
|
legacySecretsPath?: string;
|
|
64
66
|
globalSettingsPath: string;
|
|
65
67
|
mcpSettingsPath: string;
|
|
66
68
|
catalogPath: string;
|
|
69
|
+
diagnostics?: string[];
|
|
67
70
|
cleanup: () => Promise<void>;
|
|
68
71
|
}
|
|
69
72
|
|
|
@@ -201,16 +204,224 @@ function parseClineSelectionDocument(parsed: unknown): ClineSelectionCandidate {
|
|
|
201
204
|
);
|
|
202
205
|
}
|
|
203
206
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
const CLINE_DATA_AUTH_FILES = [
|
|
208
|
+
"secrets.json",
|
|
209
|
+
"globalState.json",
|
|
210
|
+
"auth.json",
|
|
211
|
+
"credentials.json",
|
|
212
|
+
"accounts.json",
|
|
213
|
+
"oauth.json",
|
|
214
|
+
"oauth_creds.json",
|
|
215
|
+
"tokens.json",
|
|
216
|
+
".env",
|
|
217
|
+
] as const;
|
|
218
|
+
const CLINE_CONFIG_AUTH_FILES = ["providers.json", ...CLINE_DATA_AUTH_FILES] as const;
|
|
219
|
+
const CLINE_OWNED_SETTINGS_FILES = new Set(["providers.json", "global-settings.json", "cline_mcp_settings.json"]);
|
|
220
|
+
|
|
221
|
+
const CLINE_FORWARDED_PROXY_KEYS = [
|
|
222
|
+
"HTTP_PROXY",
|
|
223
|
+
"HTTPS_PROXY",
|
|
224
|
+
"ALL_PROXY",
|
|
225
|
+
"NO_PROXY",
|
|
226
|
+
"http_proxy",
|
|
227
|
+
"https_proxy",
|
|
228
|
+
"no_proxy",
|
|
229
|
+
] as const;
|
|
230
|
+
|
|
231
|
+
const CLINE_FORWARDED_AUTH_KEYS = [
|
|
232
|
+
"CLINE_API_KEY",
|
|
233
|
+
"CLINE_PROVIDER",
|
|
234
|
+
"CLINE_MODEL",
|
|
235
|
+
"CLINE_MODEL_ID",
|
|
236
|
+
"CLINE_BASE_URL",
|
|
237
|
+
"ANTHROPIC_API_KEY",
|
|
238
|
+
"ANTHROPIC_BASE_URL",
|
|
239
|
+
"OPENAI_API_KEY",
|
|
240
|
+
"OPENAI_BASE_URL",
|
|
241
|
+
"OPENAI_ORG_ID",
|
|
242
|
+
"OPENROUTER_API_KEY",
|
|
243
|
+
"OPENROUTER_BASE_URL",
|
|
244
|
+
"GEMINI_API_KEY",
|
|
245
|
+
"GOOGLE_API_KEY",
|
|
246
|
+
"GOOGLE_GEMINI_BASE_URL",
|
|
247
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
248
|
+
"GOOGLE_CLOUD_PROJECT",
|
|
249
|
+
"GOOGLE_CLOUD_LOCATION",
|
|
250
|
+
"GOOGLE_GENAI_USE_VERTEXAI",
|
|
251
|
+
"GOOGLE_GENAI_USE_GCA",
|
|
252
|
+
"DEEPSEEK_API_KEY",
|
|
253
|
+
"MISTRAL_API_KEY",
|
|
254
|
+
"XAI_API_KEY",
|
|
255
|
+
"GROQ_API_KEY",
|
|
256
|
+
"TOGETHER_API_KEY",
|
|
257
|
+
"FIREWORKS_API_KEY",
|
|
258
|
+
"CEREBRAS_API_KEY",
|
|
259
|
+
"SAMBANOVA_API_KEY",
|
|
260
|
+
"MOONSHOT_API_KEY",
|
|
261
|
+
"DASHSCOPE_API_KEY",
|
|
262
|
+
"ZHIPU_API_KEY",
|
|
263
|
+
"AWS_ACCESS_KEY_ID",
|
|
264
|
+
"AWS_SECRET_ACCESS_KEY",
|
|
265
|
+
"AWS_SESSION_TOKEN",
|
|
266
|
+
"AWS_REGION",
|
|
267
|
+
"AWS_DEFAULT_REGION",
|
|
268
|
+
"AWS_PROFILE",
|
|
269
|
+
"AWS_BEARER_TOKEN_BEDROCK",
|
|
270
|
+
"AZURE_OPENAI_API_KEY",
|
|
271
|
+
"AZURE_OPENAI_ENDPOINT",
|
|
272
|
+
"AZURE_OPENAI_API_VERSION",
|
|
273
|
+
"OLLAMA_HOST",
|
|
274
|
+
"OLLAMA_API_KEY",
|
|
275
|
+
"LMSTUDIO_BASE_URL",
|
|
276
|
+
] as const;
|
|
277
|
+
|
|
278
|
+
const CLINE_CA_FILE_KEYS = ["NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE"] as const;
|
|
279
|
+
const CLINE_CA_DIR_KEYS = ["SSL_CERT_DIR"] as const;
|
|
280
|
+
|
|
281
|
+
export interface ClineCredentialCandidate {
|
|
282
|
+
label: string;
|
|
283
|
+
key: string;
|
|
284
|
+
configDir: string;
|
|
285
|
+
dataDir: string;
|
|
286
|
+
settingsDir: string;
|
|
287
|
+
providerSettingsPath: string;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface ClineCredentialFile {
|
|
291
|
+
relArea: "settings" | "data" | "config";
|
|
292
|
+
name: string;
|
|
293
|
+
sourcePath: string;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface ClineCredentialSource {
|
|
297
|
+
candidate: ClineCredentialCandidate;
|
|
298
|
+
usableFiles: ClineCredentialFile[];
|
|
299
|
+
probes: Array<ClineCredentialCandidate & { usableCount: number }>;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function readablePath(path: string, kind: "file" | "directory"): boolean {
|
|
303
|
+
try {
|
|
304
|
+
accessSync(path, constants.R_OK);
|
|
305
|
+
const info = statSync(path);
|
|
306
|
+
return kind === "file" ? info.isFile() : info.isDirectory();
|
|
307
|
+
} catch {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function isUsableAuthFile(path: string): boolean {
|
|
313
|
+
try {
|
|
314
|
+
accessSync(path, constants.R_OK);
|
|
315
|
+
const info = statSync(path);
|
|
316
|
+
return info.isFile() && info.size > 0;
|
|
317
|
+
} catch {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function candidateFromProviderPath(label: string, key: string, providerPath: string): ClineCredentialCandidate {
|
|
323
|
+
const resolved = resolve(providerPath);
|
|
324
|
+
const settingsDir = dirname(resolved);
|
|
325
|
+
const dataDir = basename(settingsDir) === "settings" ? dirname(settingsDir) : settingsDir;
|
|
326
|
+
const configDir = basename(dataDir) === "data" ? dirname(dataDir) : dataDir;
|
|
327
|
+
return { label, key, configDir, dataDir, settingsDir, providerSettingsPath: resolved };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function candidateFromDataDir(label: string, key: string, dataDir: string): ClineCredentialCandidate {
|
|
331
|
+
const resolved = resolve(dataDir);
|
|
332
|
+
const configDir = basename(resolved) === "data" ? dirname(resolved) : resolved;
|
|
333
|
+
const settingsDir = join(resolved, "settings");
|
|
334
|
+
return { label, key, configDir, dataDir: resolved, settingsDir, providerSettingsPath: join(settingsDir, "providers.json") };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function candidateFromConfigDir(label: string, key: string, configDir: string): ClineCredentialCandidate {
|
|
338
|
+
const resolved = resolve(configDir);
|
|
339
|
+
const dataDir = join(resolved, "data");
|
|
340
|
+
const settingsDir = join(dataDir, "settings");
|
|
341
|
+
return { label, key, configDir: resolved, dataDir, settingsDir, providerSettingsPath: join(settingsDir, "providers.json") };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function collectCredentialFiles(candidate: ClineCredentialCandidate): ClineCredentialFile[] {
|
|
345
|
+
const found: ClineCredentialFile[] = [];
|
|
346
|
+
const seen = new Set<string>();
|
|
347
|
+
const add = (relArea: ClineCredentialFile["relArea"], name: string, sourcePath: string): void => {
|
|
348
|
+
const resolved = resolve(sourcePath);
|
|
349
|
+
if (seen.has(resolved) || !isUsableAuthFile(resolved)) return;
|
|
350
|
+
seen.add(resolved);
|
|
351
|
+
found.push({ relArea, name, sourcePath: resolved });
|
|
352
|
+
};
|
|
353
|
+
add("settings", "providers.json", candidate.providerSettingsPath);
|
|
354
|
+
try {
|
|
355
|
+
for (const entry of readdirSync(candidate.settingsDir, { withFileTypes: true })) {
|
|
356
|
+
if (!entry.name.endsWith(".json") || CLINE_OWNED_SETTINGS_FILES.has(entry.name)) continue;
|
|
357
|
+
if (entry.isFile() || entry.isSymbolicLink()) {
|
|
358
|
+
add("settings", entry.name, join(candidate.settingsDir, entry.name));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
} catch {
|
|
362
|
+
// Missing or unreadable settings dir.
|
|
363
|
+
}
|
|
364
|
+
for (const name of CLINE_DATA_AUTH_FILES) {
|
|
365
|
+
add("data", name, join(candidate.dataDir, name));
|
|
366
|
+
}
|
|
367
|
+
for (const name of CLINE_CONFIG_AUTH_FILES) {
|
|
368
|
+
add("config", name, join(candidate.configDir, name));
|
|
369
|
+
}
|
|
370
|
+
return found;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Probe env-configured and standard Cline homes, preferring the first location with usable credentials. */
|
|
374
|
+
export function resolveClineCredentialSource(
|
|
375
|
+
env: Record<string, string | undefined> = process.env,
|
|
376
|
+
explicitProviderPath?: string,
|
|
377
|
+
): ClineCredentialSource {
|
|
378
|
+
const raw: ClineCredentialCandidate[] = [];
|
|
379
|
+
const explicitArg = nonEmpty(explicitProviderPath);
|
|
380
|
+
if (explicitArg) raw.push(candidateFromProviderPath("explicit provider", "providerSettingsPath", explicitArg));
|
|
381
|
+
const explicitEnv = nonEmpty(env.CLINE_PROVIDER_SETTINGS_PATH);
|
|
382
|
+
if (explicitEnv) raw.push(candidateFromProviderPath("env provider", "CLINE_PROVIDER_SETTINGS_PATH", explicitEnv));
|
|
208
383
|
const dataDir = nonEmpty(env.CLINE_DATA_DIR);
|
|
209
|
-
if (dataDir)
|
|
384
|
+
if (dataDir) raw.push(candidateFromDataDir("env data", "CLINE_DATA_DIR", dataDir));
|
|
210
385
|
const clineDir = nonEmpty(env.CLINE_DIR);
|
|
211
|
-
if (clineDir)
|
|
212
|
-
const home = nonEmpty(env.HOME)
|
|
213
|
-
|
|
386
|
+
if (clineDir) raw.push(candidateFromConfigDir("env dir", "CLINE_DIR", clineDir));
|
|
387
|
+
const home = nonEmpty(env.HOME);
|
|
388
|
+
if (home) raw.push(candidateFromConfigDir("HOME", "HOME", join(home, ".cline")));
|
|
389
|
+
const userProfile = nonEmpty(env.USERPROFILE);
|
|
390
|
+
if (userProfile) raw.push(candidateFromConfigDir("USERPROFILE", "USERPROFILE", join(userProfile, ".cline")));
|
|
391
|
+
if (!home && !userProfile) raw.push(candidateFromConfigDir("homedir", "homedir()", join(homedir(), ".cline")));
|
|
392
|
+
const xdgConfig = nonEmpty(env.XDG_CONFIG_HOME);
|
|
393
|
+
if (xdgConfig) raw.push(candidateFromConfigDir("XDG_CONFIG_HOME", "XDG_CONFIG_HOME", join(xdgConfig, "cline")));
|
|
394
|
+
const appData = nonEmpty(env.APPDATA);
|
|
395
|
+
if (appData) raw.push(candidateFromConfigDir("APPDATA", "APPDATA", join(appData, "cline")));
|
|
396
|
+
const localAppData = nonEmpty(env.LOCALAPPDATA);
|
|
397
|
+
if (localAppData) raw.push(candidateFromConfigDir("LOCALAPPDATA", "LOCALAPPDATA", join(localAppData, "cline")));
|
|
398
|
+
if (home) raw.push(candidateFromConfigDir("HOME SR", "HOME", join(home, ".cline-sr")));
|
|
399
|
+
if (userProfile) raw.push(candidateFromConfigDir("USERPROFILE SR", "USERPROFILE", join(userProfile, ".cline-sr")));
|
|
400
|
+
if (!home && !userProfile) raw.push(candidateFromConfigDir("homedir SR", "homedir()", join(homedir(), ".cline-sr")));
|
|
401
|
+
|
|
402
|
+
const unique: ClineCredentialCandidate[] = [];
|
|
403
|
+
const seen = new Set<string>();
|
|
404
|
+
for (const candidate of raw) {
|
|
405
|
+
const key = `${candidate.providerSettingsPath}\u0000${candidate.dataDir}`;
|
|
406
|
+
if (seen.has(key)) continue;
|
|
407
|
+
seen.add(key);
|
|
408
|
+
unique.push(candidate);
|
|
409
|
+
}
|
|
410
|
+
const probed = unique.map(candidate => {
|
|
411
|
+
const files = collectCredentialFiles(candidate);
|
|
412
|
+
return { candidate, files };
|
|
413
|
+
});
|
|
414
|
+
const selected = probed.find(entry => entry.files.length > 0) ?? probed[0]!;
|
|
415
|
+
return {
|
|
416
|
+
candidate: selected.candidate,
|
|
417
|
+
usableFiles: selected.files,
|
|
418
|
+
probes: probed.map(entry => ({ ...entry.candidate, usableCount: entry.files.length })),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Cline's provider store follows its documented env overrides and authenticated home defaults. */
|
|
423
|
+
export function resolveClineProviderSettingsPath(env: Record<string, string | undefined> = process.env): string {
|
|
424
|
+
return resolveClineCredentialSource(env).candidate.providerSettingsPath;
|
|
214
425
|
}
|
|
215
426
|
|
|
216
427
|
function isLoopbackUrl(value: string): boolean {
|
|
@@ -324,17 +535,30 @@ function legacyClineSafetyState(value: unknown): Record<string, unknown> {
|
|
|
324
535
|
};
|
|
325
536
|
}
|
|
326
537
|
|
|
538
|
+
async function readOptionalFile(paths: readonly string[]): Promise<Buffer | undefined> {
|
|
539
|
+
for (const path of paths) {
|
|
540
|
+
try {
|
|
541
|
+
return await readFile(path);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
|
|
327
549
|
async function stageLegacyClineState(
|
|
328
|
-
|
|
550
|
+
candidate: ClineCredentialCandidate,
|
|
329
551
|
dataDir: string,
|
|
330
552
|
): Promise<{ globalStatePath: string; secretsPath?: string }> {
|
|
331
|
-
const settingsDir = dirname(providerSettingsPath);
|
|
332
|
-
const sourceDataDir = basename(settingsDir) === "settings" ? dirname(settingsDir) : undefined;
|
|
333
553
|
const globalStatePath = join(dataDir, "globalState.json");
|
|
554
|
+
const rawState = await readOptionalFile([
|
|
555
|
+
join(candidate.dataDir, "globalState.json"),
|
|
556
|
+
join(candidate.configDir, "globalState.json"),
|
|
557
|
+
]);
|
|
334
558
|
let sourceState: unknown;
|
|
335
|
-
if (
|
|
559
|
+
if (rawState) {
|
|
336
560
|
try {
|
|
337
|
-
sourceState = JSON.parse(
|
|
561
|
+
sourceState = JSON.parse(rawState.toString("utf8"));
|
|
338
562
|
} catch {
|
|
339
563
|
sourceState = undefined;
|
|
340
564
|
}
|
|
@@ -346,14 +570,13 @@ async function stageLegacyClineState(
|
|
|
346
570
|
});
|
|
347
571
|
|
|
348
572
|
let secretsPath: string | undefined;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
573
|
+
const secretsBytes = await readOptionalFile([
|
|
574
|
+
join(candidate.dataDir, "secrets.json"),
|
|
575
|
+
join(candidate.configDir, "secrets.json"),
|
|
576
|
+
]);
|
|
577
|
+
if (secretsBytes) {
|
|
578
|
+
secretsPath = join(dataDir, "secrets.json");
|
|
579
|
+
await writeFile(secretsPath, secretsBytes, { mode: 0o600, flag: "wx" });
|
|
357
580
|
}
|
|
358
581
|
return { globalStatePath, ...(secretsPath ? { secretsPath } : {}) };
|
|
359
582
|
}
|
|
@@ -384,35 +607,67 @@ function clineMcpSettings(launch: ClineMcpLaunch | undefined, catalogPath: strin
|
|
|
384
607
|
};
|
|
385
608
|
}
|
|
386
609
|
|
|
387
|
-
|
|
388
|
-
async function linkClineFile(target: string, path: string): Promise<void> {
|
|
610
|
+
async function isStagedRegularFile(path: string): Promise<boolean> {
|
|
389
611
|
try {
|
|
390
|
-
await
|
|
612
|
+
return (await stat(path)).isFile();
|
|
391
613
|
} catch {
|
|
392
|
-
|
|
393
|
-
await link(resolve(target), path);
|
|
394
|
-
} catch {
|
|
395
|
-
// Best-effort: the CLINE_* path environment remains the primary contract.
|
|
396
|
-
}
|
|
614
|
+
return false;
|
|
397
615
|
}
|
|
398
616
|
}
|
|
399
617
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
618
|
+
export interface StageClineFileDeps {
|
|
619
|
+
symlink?: typeof symlink;
|
|
620
|
+
link?: typeof link;
|
|
621
|
+
copyFile?: typeof copyFile;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** Expose a staged file via symlink, hardlink, or private 0600 copy fallback. */
|
|
625
|
+
export async function stageClineFile(
|
|
626
|
+
sourcePath: string,
|
|
627
|
+
targetPath: string,
|
|
628
|
+
deps: StageClineFileDeps = {},
|
|
629
|
+
): Promise<"symlink" | "hardlink" | "copy" | undefined> {
|
|
630
|
+
if (resolve(sourcePath) === resolve(targetPath)) return "copy";
|
|
631
|
+
const symlinkFn = deps.symlink ?? symlink;
|
|
632
|
+
const linkFn = deps.link ?? link;
|
|
633
|
+
const copyFileFn = deps.copyFile ?? copyFile;
|
|
634
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
403
635
|
try {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
636
|
+
await symlinkFn(resolve(sourcePath), targetPath);
|
|
637
|
+
if (await isStagedRegularFile(targetPath)) return "symlink";
|
|
638
|
+
} catch {
|
|
639
|
+
// Fall through to hardlink.
|
|
640
|
+
}
|
|
641
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
642
|
+
try {
|
|
643
|
+
await linkFn(resolve(sourcePath), targetPath);
|
|
644
|
+
if (await isStagedRegularFile(targetPath)) return "hardlink";
|
|
645
|
+
} catch {
|
|
646
|
+
// Fall through to private copy.
|
|
408
647
|
}
|
|
648
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
649
|
+
try {
|
|
650
|
+
await copyFileFn(sourcePath, targetPath, constants.COPYFILE_EXCL);
|
|
651
|
+
await chmod(targetPath, 0o600).catch(() => undefined);
|
|
652
|
+
if (await isStagedRegularFile(targetPath)) return "copy";
|
|
653
|
+
} catch {
|
|
654
|
+
// Best-effort: the CLINE_* path environment remains the primary contract.
|
|
655
|
+
}
|
|
656
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
657
|
+
return undefined;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/** Copy the auth source into the private turn root so vendor refreshes cannot mutate it. */
|
|
661
|
+
async function copyClineProviderSettings(sources: readonly string[], target: string): Promise<boolean> {
|
|
662
|
+
const bytes = await readOptionalFile(sources);
|
|
663
|
+
if (!bytes) return false;
|
|
409
664
|
await writeFile(target, bytes, { mode: 0o600, flag: "wx" });
|
|
410
665
|
return true;
|
|
411
666
|
}
|
|
412
667
|
|
|
413
668
|
/**
|
|
414
669
|
* A fork that ignores CLINE_PROVIDER_SETTINGS_PATH still looks at ~/.cline or
|
|
415
|
-
* CLINE_DIR/data/settings.
|
|
670
|
+
* CLINE_DIR/data/settings. Stage the private copies and settings there.
|
|
416
671
|
*/
|
|
417
672
|
async function linkClineSettings(input: {
|
|
418
673
|
dataDir: string;
|
|
@@ -423,7 +678,11 @@ async function linkClineSettings(input: {
|
|
|
423
678
|
legacySecretsPath?: string;
|
|
424
679
|
globalSettingsPath: string;
|
|
425
680
|
mcpSettingsPath: string;
|
|
426
|
-
}): Promise<
|
|
681
|
+
}): Promise<string | undefined> {
|
|
682
|
+
let method: "symlink" | "hardlink" | "copy" | undefined;
|
|
683
|
+
const record = (used: typeof method): void => {
|
|
684
|
+
method ??= used;
|
|
685
|
+
};
|
|
427
686
|
const targets = [
|
|
428
687
|
{ dir: join(input.dataDir, "settings"), settings: false },
|
|
429
688
|
{ dir: join(input.configDir, "data", "settings"), settings: true },
|
|
@@ -431,31 +690,95 @@ async function linkClineSettings(input: {
|
|
|
431
690
|
];
|
|
432
691
|
for (const target of targets) {
|
|
433
692
|
if (input.providerSettingsPath) {
|
|
434
|
-
await
|
|
693
|
+
record(await stageClineFile(input.providerSettingsPath, join(target.dir, "providers.json")));
|
|
435
694
|
}
|
|
436
695
|
if (!target.settings) continue;
|
|
437
|
-
await
|
|
438
|
-
await
|
|
696
|
+
await stageClineFile(input.globalSettingsPath, join(target.dir, "global-settings.json"));
|
|
697
|
+
await stageClineFile(input.mcpSettingsPath, join(target.dir, "cline_mcp_settings.json"));
|
|
439
698
|
}
|
|
440
699
|
const legacyDirs = [input.dataDir, join(input.homeDir, ".cline", "data")];
|
|
441
700
|
for (const dir of legacyDirs) {
|
|
442
701
|
if (input.legacyGlobalStatePath) {
|
|
443
|
-
await
|
|
702
|
+
record(await stageClineFile(input.legacyGlobalStatePath, join(dir, "globalState.json")));
|
|
444
703
|
}
|
|
445
704
|
if (input.legacySecretsPath) {
|
|
446
|
-
await
|
|
705
|
+
record(await stageClineFile(input.legacySecretsPath, join(dir, "secrets.json")));
|
|
447
706
|
}
|
|
448
707
|
}
|
|
708
|
+
return method;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
async function stageExtraCredentialFiles(
|
|
712
|
+
source: ClineCredentialSource,
|
|
713
|
+
dirs: { configDir: string; dataDir: string; homeDir: string },
|
|
714
|
+
skip: ReadonlySet<string>,
|
|
715
|
+
perTurnPaths: string[],
|
|
716
|
+
): Promise<string[]> {
|
|
717
|
+
const stagedNames: string[] = [];
|
|
718
|
+
for (const file of source.usableFiles) {
|
|
719
|
+
if (skip.has(file.sourcePath)) continue;
|
|
720
|
+
if (file.relArea === "settings" && file.name === "providers.json") continue;
|
|
721
|
+
if ((file.relArea === "data" || file.relArea === "config") && (file.name === "globalState.json" || file.name === "secrets.json")) {
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
const bytes = await readOptionalFile([file.sourcePath]);
|
|
725
|
+
if (!bytes) continue;
|
|
726
|
+
if (file.relArea === "settings") {
|
|
727
|
+
const privateCopy = join(dirs.configDir, "data", "settings", file.name);
|
|
728
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
729
|
+
await stageClineFile(privateCopy, join(dirs.dataDir, "settings", file.name));
|
|
730
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", "data", "settings", file.name));
|
|
731
|
+
stagedNames.push(`settings/${file.name}`);
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
if (file.relArea === "data") {
|
|
735
|
+
const privateCopy = join(dirs.configDir, "data", file.name);
|
|
736
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
737
|
+
const dataTarget = join(dirs.dataDir, file.name);
|
|
738
|
+
perTurnPaths.push(dataTarget);
|
|
739
|
+
await stageClineFile(privateCopy, dataTarget);
|
|
740
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", "data", file.name));
|
|
741
|
+
stagedNames.push(`data/${file.name}`);
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const privateCopy = join(dirs.configDir, file.name);
|
|
745
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
746
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", file.name));
|
|
747
|
+
if (file.name !== "providers.json") {
|
|
748
|
+
const dataTarget = join(dirs.dataDir, file.name);
|
|
749
|
+
perTurnPaths.push(dataTarget);
|
|
750
|
+
await stageClineFile(privateCopy, dataTarget);
|
|
751
|
+
}
|
|
752
|
+
stagedNames.push(file.name);
|
|
753
|
+
}
|
|
754
|
+
return stagedNames;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function clineCredentialDiagnostic(
|
|
758
|
+
source: ClineCredentialSource,
|
|
759
|
+
stagedItems: readonly string[],
|
|
760
|
+
method: string | undefined,
|
|
761
|
+
): string {
|
|
762
|
+
const probed = source.probes
|
|
763
|
+
.map(probe => `${probe.label} ${probe.configDir} (${probe.key}; ${probe.usableCount > 0 ? `${probe.usableCount} file(s)` : "empty"})`)
|
|
764
|
+
.join("; ");
|
|
765
|
+
const staged = stagedItems.length > 0
|
|
766
|
+
? `staged ${stagedItems.join(", ")}${method ? ` (${method})` : ""}`
|
|
767
|
+
: "no credential files staged";
|
|
768
|
+
return `Cline credentials: using ${source.candidate.label} ${source.candidate.configDir} (${source.candidate.key}); ${staged}; probed ${probed}`;
|
|
449
769
|
}
|
|
450
770
|
|
|
451
771
|
/** Stage all Cline paths the proxy controls; the vendor provider store remains the auth source. */
|
|
452
772
|
export async function stageClineTurn(options: {
|
|
453
773
|
providerSettingsPath: string;
|
|
774
|
+
sourceEnv?: NodeJS.ProcessEnv;
|
|
454
775
|
catalog: readonly Record<string, unknown>[];
|
|
455
776
|
mcpLaunch?: ClineMcpLaunch;
|
|
456
777
|
/** Persistent conversation root. When set, per-turn state is recreated and vendor data survives. */
|
|
457
778
|
root?: string;
|
|
458
779
|
}): Promise<ClineStagedTurn> {
|
|
780
|
+
const credentialSource = resolveClineCredentialSource(options.sourceEnv ?? process.env, options.providerSettingsPath);
|
|
781
|
+
const sourceCandidate = credentialSource.candidate;
|
|
459
782
|
const persistent = Boolean(options.root);
|
|
460
783
|
const root = options.root ?? await mkdtemp(join(tmpdir(), "ocx-cline-cli-"));
|
|
461
784
|
const configDir = join(root, "config");
|
|
@@ -475,13 +798,12 @@ export async function stageClineTurn(options: {
|
|
|
475
798
|
hooksDir,
|
|
476
799
|
logDir,
|
|
477
800
|
join(dataDir, "settings"),
|
|
478
|
-
join(dataDir,
|
|
479
|
-
join(dataDir, "secrets.json"),
|
|
801
|
+
...CLINE_DATA_AUTH_FILES.map(name => join(dataDir, name)),
|
|
480
802
|
catalogPath,
|
|
481
803
|
];
|
|
482
804
|
const perTurnPaths = [...recreatedPaths, join(root, "prompt.txt")];
|
|
483
805
|
const cleanup = async (): Promise<void> => {
|
|
484
|
-
const targets = persistent ? perTurnPaths : [root];
|
|
806
|
+
const targets = persistent ? [...new Set(perTurnPaths)] : [root];
|
|
485
807
|
await Promise.all(targets.map(path => rm(path, { recursive: true, force: true }).catch(() => undefined)));
|
|
486
808
|
};
|
|
487
809
|
|
|
@@ -507,9 +829,13 @@ export async function stageClineTurn(options: {
|
|
|
507
829
|
writeFile(mcpSettingsPath, `${JSON.stringify(clineMcpSettings(options.mcpLaunch, catalogPath), null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" }),
|
|
508
830
|
writeFile(catalogPath, JSON.stringify(options.catalog), { encoding: "utf8", mode: 0o600, flag: "wx" }),
|
|
509
831
|
]);
|
|
510
|
-
const legacyState = await stageLegacyClineState(
|
|
511
|
-
const
|
|
512
|
-
|
|
832
|
+
const legacyState = await stageLegacyClineState(sourceCandidate, join(configDir, "data"));
|
|
833
|
+
const providerSources = [
|
|
834
|
+
sourceCandidate.providerSettingsPath,
|
|
835
|
+
join(sourceCandidate.configDir, "providers.json"),
|
|
836
|
+
];
|
|
837
|
+
const copiedProviderStore = await copyClineProviderSettings(providerSources, providerSettingsPath);
|
|
838
|
+
const linkMethod = await linkClineSettings({
|
|
513
839
|
dataDir,
|
|
514
840
|
configDir,
|
|
515
841
|
homeDir,
|
|
@@ -519,6 +845,25 @@ export async function stageClineTurn(options: {
|
|
|
519
845
|
globalSettingsPath,
|
|
520
846
|
mcpSettingsPath,
|
|
521
847
|
});
|
|
848
|
+
const handledPaths = new Set([
|
|
849
|
+
...providerSources.map(path => resolve(path)),
|
|
850
|
+
resolve(join(sourceCandidate.dataDir, "globalState.json")),
|
|
851
|
+
resolve(join(sourceCandidate.configDir, "globalState.json")),
|
|
852
|
+
resolve(join(sourceCandidate.dataDir, "secrets.json")),
|
|
853
|
+
resolve(join(sourceCandidate.configDir, "secrets.json")),
|
|
854
|
+
]);
|
|
855
|
+
const extraStaged = await stageExtraCredentialFiles(
|
|
856
|
+
credentialSource,
|
|
857
|
+
{ configDir, dataDir, homeDir },
|
|
858
|
+
handledPaths,
|
|
859
|
+
perTurnPaths,
|
|
860
|
+
);
|
|
861
|
+
const stagedItems = [
|
|
862
|
+
...(copiedProviderStore ? ["providers.json"] : []),
|
|
863
|
+
...(legacyState.secretsPath ? ["secrets.json"] : []),
|
|
864
|
+
"globalState.json",
|
|
865
|
+
...extraStaged,
|
|
866
|
+
];
|
|
522
867
|
return {
|
|
523
868
|
root,
|
|
524
869
|
configDir,
|
|
@@ -527,11 +872,13 @@ export async function stageClineTurn(options: {
|
|
|
527
872
|
workspaceDir,
|
|
528
873
|
hooksDir,
|
|
529
874
|
providerSettingsPath,
|
|
875
|
+
hasProviderSettings: copiedProviderStore,
|
|
530
876
|
legacyGlobalStatePath: legacyState.globalStatePath,
|
|
531
877
|
...(legacyState.secretsPath ? { legacySecretsPath: legacyState.secretsPath } : {}),
|
|
532
878
|
globalSettingsPath,
|
|
533
879
|
mcpSettingsPath,
|
|
534
880
|
catalogPath,
|
|
881
|
+
diagnostics: [clineCredentialDiagnostic(credentialSource, stagedItems, linkMethod)],
|
|
535
882
|
cleanup,
|
|
536
883
|
};
|
|
537
884
|
} catch (error) {
|
|
@@ -588,10 +935,20 @@ export function buildClineChildEnv(staged: ClineStagedTurn, sourceEnv: NodeJS.Pr
|
|
|
588
935
|
"XDG_RUNTIME_DIR",
|
|
589
936
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
590
937
|
"GNOME_KEYRING_CONTROL",
|
|
938
|
+
...CLINE_FORWARDED_PROXY_KEYS,
|
|
939
|
+
...CLINE_FORWARDED_AUTH_KEYS,
|
|
591
940
|
]) {
|
|
592
941
|
const value = nonEmpty(sourceEnv[key]);
|
|
593
942
|
if (value) env[key] = value;
|
|
594
943
|
}
|
|
944
|
+
for (const key of CLINE_CA_FILE_KEYS) {
|
|
945
|
+
const value = nonEmpty(sourceEnv[key]);
|
|
946
|
+
if (value && readablePath(value, "file")) env[key] = value;
|
|
947
|
+
}
|
|
948
|
+
for (const key of CLINE_CA_DIR_KEYS) {
|
|
949
|
+
const value = nonEmpty(sourceEnv[key]);
|
|
950
|
+
if (value && readablePath(value, "directory")) env[key] = value;
|
|
951
|
+
}
|
|
595
952
|
const user = sourceEnv.USER ?? sourceEnv.LOGNAME;
|
|
596
953
|
if (user) env.USER = user;
|
|
597
954
|
if (sourceEnv.LOGNAME) env.LOGNAME = sourceEnv.LOGNAME;
|
|
@@ -602,7 +959,7 @@ export function buildClineChildEnv(staged: ClineStagedTurn, sourceEnv: NodeJS.Pr
|
|
|
602
959
|
CLINE_SESSION_DATA_DIR: join(staged.dataDir, "sessions"),
|
|
603
960
|
CLINE_TEAM_DATA_DIR: join(staged.dataDir, "teams"),
|
|
604
961
|
CLINE_SANDBOX_DATA_DIR: staged.dataDir,
|
|
605
|
-
CLINE_PROVIDER_SETTINGS_PATH: staged.providerSettingsPath,
|
|
962
|
+
...(staged.hasProviderSettings !== false ? { CLINE_PROVIDER_SETTINGS_PATH: staged.providerSettingsPath } : {}),
|
|
606
963
|
CLINE_GLOBAL_SETTINGS_PATH: staged.globalSettingsPath,
|
|
607
964
|
CLINE_HOOKS_DIR: staged.hooksDir,
|
|
608
965
|
CLINE_MCP_SETTINGS_PATH: staged.mcpSettingsPath,
|