@koreanhole/opencodex 3.2.34 → 3.2.35
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,221 @@ 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
|
+
|
|
399
|
+
const unique: ClineCredentialCandidate[] = [];
|
|
400
|
+
const seen = new Set<string>();
|
|
401
|
+
for (const candidate of raw) {
|
|
402
|
+
const key = `${candidate.providerSettingsPath}\u0000${candidate.dataDir}`;
|
|
403
|
+
if (seen.has(key)) continue;
|
|
404
|
+
seen.add(key);
|
|
405
|
+
unique.push(candidate);
|
|
406
|
+
}
|
|
407
|
+
const probed = unique.map(candidate => {
|
|
408
|
+
const files = collectCredentialFiles(candidate);
|
|
409
|
+
return { candidate, files };
|
|
410
|
+
});
|
|
411
|
+
const selected = probed.find(entry => entry.files.length > 0) ?? probed[0]!;
|
|
412
|
+
return {
|
|
413
|
+
candidate: selected.candidate,
|
|
414
|
+
usableFiles: selected.files,
|
|
415
|
+
probes: probed.map(entry => ({ ...entry.candidate, usableCount: entry.files.length })),
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Cline's provider store follows its documented env overrides and authenticated home defaults. */
|
|
420
|
+
export function resolveClineProviderSettingsPath(env: Record<string, string | undefined> = process.env): string {
|
|
421
|
+
return resolveClineCredentialSource(env).candidate.providerSettingsPath;
|
|
214
422
|
}
|
|
215
423
|
|
|
216
424
|
function isLoopbackUrl(value: string): boolean {
|
|
@@ -324,17 +532,30 @@ function legacyClineSafetyState(value: unknown): Record<string, unknown> {
|
|
|
324
532
|
};
|
|
325
533
|
}
|
|
326
534
|
|
|
535
|
+
async function readOptionalFile(paths: readonly string[]): Promise<Buffer | undefined> {
|
|
536
|
+
for (const path of paths) {
|
|
537
|
+
try {
|
|
538
|
+
return await readFile(path);
|
|
539
|
+
} catch (error) {
|
|
540
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return undefined;
|
|
544
|
+
}
|
|
545
|
+
|
|
327
546
|
async function stageLegacyClineState(
|
|
328
|
-
|
|
547
|
+
candidate: ClineCredentialCandidate,
|
|
329
548
|
dataDir: string,
|
|
330
549
|
): Promise<{ globalStatePath: string; secretsPath?: string }> {
|
|
331
|
-
const settingsDir = dirname(providerSettingsPath);
|
|
332
|
-
const sourceDataDir = basename(settingsDir) === "settings" ? dirname(settingsDir) : undefined;
|
|
333
550
|
const globalStatePath = join(dataDir, "globalState.json");
|
|
551
|
+
const rawState = await readOptionalFile([
|
|
552
|
+
join(candidate.dataDir, "globalState.json"),
|
|
553
|
+
join(candidate.configDir, "globalState.json"),
|
|
554
|
+
]);
|
|
334
555
|
let sourceState: unknown;
|
|
335
|
-
if (
|
|
556
|
+
if (rawState) {
|
|
336
557
|
try {
|
|
337
|
-
sourceState = JSON.parse(
|
|
558
|
+
sourceState = JSON.parse(rawState.toString("utf8"));
|
|
338
559
|
} catch {
|
|
339
560
|
sourceState = undefined;
|
|
340
561
|
}
|
|
@@ -346,14 +567,13 @@ async function stageLegacyClineState(
|
|
|
346
567
|
});
|
|
347
568
|
|
|
348
569
|
let secretsPath: string | undefined;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
570
|
+
const secretsBytes = await readOptionalFile([
|
|
571
|
+
join(candidate.dataDir, "secrets.json"),
|
|
572
|
+
join(candidate.configDir, "secrets.json"),
|
|
573
|
+
]);
|
|
574
|
+
if (secretsBytes) {
|
|
575
|
+
secretsPath = join(dataDir, "secrets.json");
|
|
576
|
+
await writeFile(secretsPath, secretsBytes, { mode: 0o600, flag: "wx" });
|
|
357
577
|
}
|
|
358
578
|
return { globalStatePath, ...(secretsPath ? { secretsPath } : {}) };
|
|
359
579
|
}
|
|
@@ -384,35 +604,67 @@ function clineMcpSettings(launch: ClineMcpLaunch | undefined, catalogPath: strin
|
|
|
384
604
|
};
|
|
385
605
|
}
|
|
386
606
|
|
|
387
|
-
|
|
388
|
-
async function linkClineFile(target: string, path: string): Promise<void> {
|
|
607
|
+
async function isStagedRegularFile(path: string): Promise<boolean> {
|
|
389
608
|
try {
|
|
390
|
-
await
|
|
609
|
+
return (await stat(path)).isFile();
|
|
391
610
|
} catch {
|
|
392
|
-
|
|
393
|
-
await link(resolve(target), path);
|
|
394
|
-
} catch {
|
|
395
|
-
// Best-effort: the CLINE_* path environment remains the primary contract.
|
|
396
|
-
}
|
|
611
|
+
return false;
|
|
397
612
|
}
|
|
398
613
|
}
|
|
399
614
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
615
|
+
export interface StageClineFileDeps {
|
|
616
|
+
symlink?: typeof symlink;
|
|
617
|
+
link?: typeof link;
|
|
618
|
+
copyFile?: typeof copyFile;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** Expose a staged file via symlink, hardlink, or private 0600 copy fallback. */
|
|
622
|
+
export async function stageClineFile(
|
|
623
|
+
sourcePath: string,
|
|
624
|
+
targetPath: string,
|
|
625
|
+
deps: StageClineFileDeps = {},
|
|
626
|
+
): Promise<"symlink" | "hardlink" | "copy" | undefined> {
|
|
627
|
+
if (resolve(sourcePath) === resolve(targetPath)) return "copy";
|
|
628
|
+
const symlinkFn = deps.symlink ?? symlink;
|
|
629
|
+
const linkFn = deps.link ?? link;
|
|
630
|
+
const copyFileFn = deps.copyFile ?? copyFile;
|
|
631
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
403
632
|
try {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
633
|
+
await symlinkFn(resolve(sourcePath), targetPath);
|
|
634
|
+
if (await isStagedRegularFile(targetPath)) return "symlink";
|
|
635
|
+
} catch {
|
|
636
|
+
// Fall through to hardlink.
|
|
637
|
+
}
|
|
638
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
639
|
+
try {
|
|
640
|
+
await linkFn(resolve(sourcePath), targetPath);
|
|
641
|
+
if (await isStagedRegularFile(targetPath)) return "hardlink";
|
|
642
|
+
} catch {
|
|
643
|
+
// Fall through to private copy.
|
|
408
644
|
}
|
|
645
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
646
|
+
try {
|
|
647
|
+
await copyFileFn(sourcePath, targetPath, constants.COPYFILE_EXCL);
|
|
648
|
+
await chmod(targetPath, 0o600).catch(() => undefined);
|
|
649
|
+
if (await isStagedRegularFile(targetPath)) return "copy";
|
|
650
|
+
} catch {
|
|
651
|
+
// Best-effort: the CLINE_* path environment remains the primary contract.
|
|
652
|
+
}
|
|
653
|
+
await rm(targetPath, { recursive: true, force: true }).catch(() => undefined);
|
|
654
|
+
return undefined;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** Copy the auth source into the private turn root so vendor refreshes cannot mutate it. */
|
|
658
|
+
async function copyClineProviderSettings(sources: readonly string[], target: string): Promise<boolean> {
|
|
659
|
+
const bytes = await readOptionalFile(sources);
|
|
660
|
+
if (!bytes) return false;
|
|
409
661
|
await writeFile(target, bytes, { mode: 0o600, flag: "wx" });
|
|
410
662
|
return true;
|
|
411
663
|
}
|
|
412
664
|
|
|
413
665
|
/**
|
|
414
666
|
* A fork that ignores CLINE_PROVIDER_SETTINGS_PATH still looks at ~/.cline or
|
|
415
|
-
* CLINE_DIR/data/settings.
|
|
667
|
+
* CLINE_DIR/data/settings. Stage the private copies and settings there.
|
|
416
668
|
*/
|
|
417
669
|
async function linkClineSettings(input: {
|
|
418
670
|
dataDir: string;
|
|
@@ -423,7 +675,11 @@ async function linkClineSettings(input: {
|
|
|
423
675
|
legacySecretsPath?: string;
|
|
424
676
|
globalSettingsPath: string;
|
|
425
677
|
mcpSettingsPath: string;
|
|
426
|
-
}): Promise<
|
|
678
|
+
}): Promise<string | undefined> {
|
|
679
|
+
let method: "symlink" | "hardlink" | "copy" | undefined;
|
|
680
|
+
const record = (used: typeof method): void => {
|
|
681
|
+
method ??= used;
|
|
682
|
+
};
|
|
427
683
|
const targets = [
|
|
428
684
|
{ dir: join(input.dataDir, "settings"), settings: false },
|
|
429
685
|
{ dir: join(input.configDir, "data", "settings"), settings: true },
|
|
@@ -431,31 +687,95 @@ async function linkClineSettings(input: {
|
|
|
431
687
|
];
|
|
432
688
|
for (const target of targets) {
|
|
433
689
|
if (input.providerSettingsPath) {
|
|
434
|
-
await
|
|
690
|
+
record(await stageClineFile(input.providerSettingsPath, join(target.dir, "providers.json")));
|
|
435
691
|
}
|
|
436
692
|
if (!target.settings) continue;
|
|
437
|
-
await
|
|
438
|
-
await
|
|
693
|
+
await stageClineFile(input.globalSettingsPath, join(target.dir, "global-settings.json"));
|
|
694
|
+
await stageClineFile(input.mcpSettingsPath, join(target.dir, "cline_mcp_settings.json"));
|
|
439
695
|
}
|
|
440
696
|
const legacyDirs = [input.dataDir, join(input.homeDir, ".cline", "data")];
|
|
441
697
|
for (const dir of legacyDirs) {
|
|
442
698
|
if (input.legacyGlobalStatePath) {
|
|
443
|
-
await
|
|
699
|
+
record(await stageClineFile(input.legacyGlobalStatePath, join(dir, "globalState.json")));
|
|
444
700
|
}
|
|
445
701
|
if (input.legacySecretsPath) {
|
|
446
|
-
await
|
|
702
|
+
record(await stageClineFile(input.legacySecretsPath, join(dir, "secrets.json")));
|
|
447
703
|
}
|
|
448
704
|
}
|
|
705
|
+
return method;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
async function stageExtraCredentialFiles(
|
|
709
|
+
source: ClineCredentialSource,
|
|
710
|
+
dirs: { configDir: string; dataDir: string; homeDir: string },
|
|
711
|
+
skip: ReadonlySet<string>,
|
|
712
|
+
perTurnPaths: string[],
|
|
713
|
+
): Promise<string[]> {
|
|
714
|
+
const stagedNames: string[] = [];
|
|
715
|
+
for (const file of source.usableFiles) {
|
|
716
|
+
if (skip.has(file.sourcePath)) continue;
|
|
717
|
+
if (file.relArea === "settings" && file.name === "providers.json") continue;
|
|
718
|
+
if ((file.relArea === "data" || file.relArea === "config") && (file.name === "globalState.json" || file.name === "secrets.json")) {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
const bytes = await readOptionalFile([file.sourcePath]);
|
|
722
|
+
if (!bytes) continue;
|
|
723
|
+
if (file.relArea === "settings") {
|
|
724
|
+
const privateCopy = join(dirs.configDir, "data", "settings", file.name);
|
|
725
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
726
|
+
await stageClineFile(privateCopy, join(dirs.dataDir, "settings", file.name));
|
|
727
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", "data", "settings", file.name));
|
|
728
|
+
stagedNames.push(`settings/${file.name}`);
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
if (file.relArea === "data") {
|
|
732
|
+
const privateCopy = join(dirs.configDir, "data", file.name);
|
|
733
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
734
|
+
const dataTarget = join(dirs.dataDir, file.name);
|
|
735
|
+
perTurnPaths.push(dataTarget);
|
|
736
|
+
await stageClineFile(privateCopy, dataTarget);
|
|
737
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", "data", file.name));
|
|
738
|
+
stagedNames.push(`data/${file.name}`);
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
const privateCopy = join(dirs.configDir, file.name);
|
|
742
|
+
await writeFile(privateCopy, bytes, { mode: 0o600, flag: "wx" });
|
|
743
|
+
await stageClineFile(privateCopy, join(dirs.homeDir, ".cline", file.name));
|
|
744
|
+
if (file.name !== "providers.json") {
|
|
745
|
+
const dataTarget = join(dirs.dataDir, file.name);
|
|
746
|
+
perTurnPaths.push(dataTarget);
|
|
747
|
+
await stageClineFile(privateCopy, dataTarget);
|
|
748
|
+
}
|
|
749
|
+
stagedNames.push(file.name);
|
|
750
|
+
}
|
|
751
|
+
return stagedNames;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function clineCredentialDiagnostic(
|
|
755
|
+
source: ClineCredentialSource,
|
|
756
|
+
stagedItems: readonly string[],
|
|
757
|
+
method: string | undefined,
|
|
758
|
+
): string {
|
|
759
|
+
const probed = source.probes
|
|
760
|
+
.map(probe => `${probe.label} ${probe.configDir} (${probe.key}; ${probe.usableCount > 0 ? `${probe.usableCount} file(s)` : "empty"})`)
|
|
761
|
+
.join("; ");
|
|
762
|
+
const staged = stagedItems.length > 0
|
|
763
|
+
? `staged ${stagedItems.join(", ")}${method ? ` (${method})` : ""}`
|
|
764
|
+
: "no credential files staged";
|
|
765
|
+
return `Cline credentials: using ${source.candidate.label} ${source.candidate.configDir} (${source.candidate.key}); ${staged}; probed ${probed}`;
|
|
449
766
|
}
|
|
450
767
|
|
|
451
768
|
/** Stage all Cline paths the proxy controls; the vendor provider store remains the auth source. */
|
|
452
769
|
export async function stageClineTurn(options: {
|
|
453
770
|
providerSettingsPath: string;
|
|
771
|
+
sourceEnv?: NodeJS.ProcessEnv;
|
|
454
772
|
catalog: readonly Record<string, unknown>[];
|
|
455
773
|
mcpLaunch?: ClineMcpLaunch;
|
|
456
774
|
/** Persistent conversation root. When set, per-turn state is recreated and vendor data survives. */
|
|
457
775
|
root?: string;
|
|
458
776
|
}): Promise<ClineStagedTurn> {
|
|
777
|
+
const credentialSource = resolveClineCredentialSource(options.sourceEnv ?? process.env, options.providerSettingsPath);
|
|
778
|
+
const sourceCandidate = credentialSource.candidate;
|
|
459
779
|
const persistent = Boolean(options.root);
|
|
460
780
|
const root = options.root ?? await mkdtemp(join(tmpdir(), "ocx-cline-cli-"));
|
|
461
781
|
const configDir = join(root, "config");
|
|
@@ -475,13 +795,12 @@ export async function stageClineTurn(options: {
|
|
|
475
795
|
hooksDir,
|
|
476
796
|
logDir,
|
|
477
797
|
join(dataDir, "settings"),
|
|
478
|
-
join(dataDir,
|
|
479
|
-
join(dataDir, "secrets.json"),
|
|
798
|
+
...CLINE_DATA_AUTH_FILES.map(name => join(dataDir, name)),
|
|
480
799
|
catalogPath,
|
|
481
800
|
];
|
|
482
801
|
const perTurnPaths = [...recreatedPaths, join(root, "prompt.txt")];
|
|
483
802
|
const cleanup = async (): Promise<void> => {
|
|
484
|
-
const targets = persistent ? perTurnPaths : [root];
|
|
803
|
+
const targets = persistent ? [...new Set(perTurnPaths)] : [root];
|
|
485
804
|
await Promise.all(targets.map(path => rm(path, { recursive: true, force: true }).catch(() => undefined)));
|
|
486
805
|
};
|
|
487
806
|
|
|
@@ -507,9 +826,13 @@ export async function stageClineTurn(options: {
|
|
|
507
826
|
writeFile(mcpSettingsPath, `${JSON.stringify(clineMcpSettings(options.mcpLaunch, catalogPath), null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" }),
|
|
508
827
|
writeFile(catalogPath, JSON.stringify(options.catalog), { encoding: "utf8", mode: 0o600, flag: "wx" }),
|
|
509
828
|
]);
|
|
510
|
-
const legacyState = await stageLegacyClineState(
|
|
511
|
-
const
|
|
512
|
-
|
|
829
|
+
const legacyState = await stageLegacyClineState(sourceCandidate, join(configDir, "data"));
|
|
830
|
+
const providerSources = [
|
|
831
|
+
sourceCandidate.providerSettingsPath,
|
|
832
|
+
join(sourceCandidate.configDir, "providers.json"),
|
|
833
|
+
];
|
|
834
|
+
const copiedProviderStore = await copyClineProviderSettings(providerSources, providerSettingsPath);
|
|
835
|
+
const linkMethod = await linkClineSettings({
|
|
513
836
|
dataDir,
|
|
514
837
|
configDir,
|
|
515
838
|
homeDir,
|
|
@@ -519,6 +842,25 @@ export async function stageClineTurn(options: {
|
|
|
519
842
|
globalSettingsPath,
|
|
520
843
|
mcpSettingsPath,
|
|
521
844
|
});
|
|
845
|
+
const handledPaths = new Set([
|
|
846
|
+
...providerSources.map(path => resolve(path)),
|
|
847
|
+
resolve(join(sourceCandidate.dataDir, "globalState.json")),
|
|
848
|
+
resolve(join(sourceCandidate.configDir, "globalState.json")),
|
|
849
|
+
resolve(join(sourceCandidate.dataDir, "secrets.json")),
|
|
850
|
+
resolve(join(sourceCandidate.configDir, "secrets.json")),
|
|
851
|
+
]);
|
|
852
|
+
const extraStaged = await stageExtraCredentialFiles(
|
|
853
|
+
credentialSource,
|
|
854
|
+
{ configDir, dataDir, homeDir },
|
|
855
|
+
handledPaths,
|
|
856
|
+
perTurnPaths,
|
|
857
|
+
);
|
|
858
|
+
const stagedItems = [
|
|
859
|
+
...(copiedProviderStore ? ["providers.json"] : []),
|
|
860
|
+
...(legacyState.secretsPath ? ["secrets.json"] : []),
|
|
861
|
+
"globalState.json",
|
|
862
|
+
...extraStaged,
|
|
863
|
+
];
|
|
522
864
|
return {
|
|
523
865
|
root,
|
|
524
866
|
configDir,
|
|
@@ -527,11 +869,13 @@ export async function stageClineTurn(options: {
|
|
|
527
869
|
workspaceDir,
|
|
528
870
|
hooksDir,
|
|
529
871
|
providerSettingsPath,
|
|
872
|
+
hasProviderSettings: copiedProviderStore,
|
|
530
873
|
legacyGlobalStatePath: legacyState.globalStatePath,
|
|
531
874
|
...(legacyState.secretsPath ? { legacySecretsPath: legacyState.secretsPath } : {}),
|
|
532
875
|
globalSettingsPath,
|
|
533
876
|
mcpSettingsPath,
|
|
534
877
|
catalogPath,
|
|
878
|
+
diagnostics: [clineCredentialDiagnostic(credentialSource, stagedItems, linkMethod)],
|
|
535
879
|
cleanup,
|
|
536
880
|
};
|
|
537
881
|
} catch (error) {
|
|
@@ -588,10 +932,20 @@ export function buildClineChildEnv(staged: ClineStagedTurn, sourceEnv: NodeJS.Pr
|
|
|
588
932
|
"XDG_RUNTIME_DIR",
|
|
589
933
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
590
934
|
"GNOME_KEYRING_CONTROL",
|
|
935
|
+
...CLINE_FORWARDED_PROXY_KEYS,
|
|
936
|
+
...CLINE_FORWARDED_AUTH_KEYS,
|
|
591
937
|
]) {
|
|
592
938
|
const value = nonEmpty(sourceEnv[key]);
|
|
593
939
|
if (value) env[key] = value;
|
|
594
940
|
}
|
|
941
|
+
for (const key of CLINE_CA_FILE_KEYS) {
|
|
942
|
+
const value = nonEmpty(sourceEnv[key]);
|
|
943
|
+
if (value && readablePath(value, "file")) env[key] = value;
|
|
944
|
+
}
|
|
945
|
+
for (const key of CLINE_CA_DIR_KEYS) {
|
|
946
|
+
const value = nonEmpty(sourceEnv[key]);
|
|
947
|
+
if (value && readablePath(value, "directory")) env[key] = value;
|
|
948
|
+
}
|
|
595
949
|
const user = sourceEnv.USER ?? sourceEnv.LOGNAME;
|
|
596
950
|
if (user) env.USER = user;
|
|
597
951
|
if (sourceEnv.LOGNAME) env.LOGNAME = sourceEnv.LOGNAME;
|
|
@@ -602,7 +956,7 @@ export function buildClineChildEnv(staged: ClineStagedTurn, sourceEnv: NodeJS.Pr
|
|
|
602
956
|
CLINE_SESSION_DATA_DIR: join(staged.dataDir, "sessions"),
|
|
603
957
|
CLINE_TEAM_DATA_DIR: join(staged.dataDir, "teams"),
|
|
604
958
|
CLINE_SANDBOX_DATA_DIR: staged.dataDir,
|
|
605
|
-
CLINE_PROVIDER_SETTINGS_PATH: staged.providerSettingsPath,
|
|
959
|
+
...(staged.hasProviderSettings !== false ? { CLINE_PROVIDER_SETTINGS_PATH: staged.providerSettingsPath } : {}),
|
|
606
960
|
CLINE_GLOBAL_SETTINGS_PATH: staged.globalSettingsPath,
|
|
607
961
|
CLINE_HOOKS_DIR: staged.hooksDir,
|
|
608
962
|
CLINE_MCP_SETTINGS_PATH: staged.mcpSettingsPath,
|