@kenkaiiii/gg-core 5.87.1 → 5.87.3
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/dist/{chunk-HMJZM62P.js → chunk-5ZYOOESD.js} +192 -300
- package/dist/chunk-5ZYOOESD.js.map +1 -0
- package/dist/index.cjs +197 -309
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -13
- package/dist/index.d.ts +2 -13
- package/dist/index.js +1 -1
- package/dist/model-registry.cjs +14 -18
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-HMJZM62P.js.map +0 -1
|
@@ -230,7 +230,7 @@ async function refreshKimiToken(refreshToken) {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
// src/auth-storage.ts
|
|
233
|
-
import
|
|
233
|
+
import fs3 from "fs/promises";
|
|
234
234
|
import { readFileSync as readFileSync2 } from "fs";
|
|
235
235
|
import crypto5 from "crypto";
|
|
236
236
|
|
|
@@ -256,283 +256,11 @@ async function generatePKCE() {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// src/claude-code-version.ts
|
|
259
|
-
import
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
import path2 from "path";
|
|
265
|
-
import { randomBytes } from "crypto";
|
|
266
|
-
import { environmentSecrets, redactText, redactValue } from "@kenkaiiii/gg-ai";
|
|
267
|
-
var MAX_BYTES = 10 * 1024 * 1024;
|
|
268
|
-
var MIN_HEADROOM_BYTES = 64 * 1024;
|
|
269
|
-
var fd = null;
|
|
270
|
-
var logPath = null;
|
|
271
|
-
var fileBytes = 0;
|
|
272
|
-
var processBytes = 0;
|
|
273
|
-
var rotationFailed = false;
|
|
274
|
-
var capped = false;
|
|
275
|
-
var sessionId = "";
|
|
276
|
-
var appName = "app";
|
|
277
|
-
var cleanups = [];
|
|
278
|
-
var exactSecrets = [];
|
|
279
|
-
function rotateIfNeeded(filePath, force = false) {
|
|
280
|
-
try {
|
|
281
|
-
const st = fs.statSync(filePath);
|
|
282
|
-
if (!force && st.size <= MAX_BYTES - MIN_HEADROOM_BYTES) return;
|
|
283
|
-
const rotated = `${filePath}.1`;
|
|
284
|
-
try {
|
|
285
|
-
fs.unlinkSync(rotated);
|
|
286
|
-
} catch {
|
|
287
|
-
}
|
|
288
|
-
fs.renameSync(filePath, rotated);
|
|
289
|
-
} catch {
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function rotateOpenLog() {
|
|
293
|
-
if (fd === null || logPath === null) return false;
|
|
294
|
-
const sizeBefore = fileBytes;
|
|
295
|
-
try {
|
|
296
|
-
fs.closeSync(fd);
|
|
297
|
-
} catch {
|
|
298
|
-
}
|
|
299
|
-
fd = null;
|
|
300
|
-
rotateIfNeeded(logPath, true);
|
|
301
|
-
try {
|
|
302
|
-
fd = fs.openSync(logPath, "a");
|
|
303
|
-
fileBytes = fs.fstatSync(fd).size;
|
|
304
|
-
} catch {
|
|
305
|
-
if (fd !== null) {
|
|
306
|
-
try {
|
|
307
|
-
fs.closeSync(fd);
|
|
308
|
-
} catch {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
fd = null;
|
|
312
|
-
capped = true;
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
if (fileBytes >= sizeBefore) rotationFailed = true;
|
|
316
|
-
return true;
|
|
317
|
-
}
|
|
318
|
-
function openLog(filePath, name) {
|
|
319
|
-
if (fd !== null || capped) return false;
|
|
320
|
-
appName = name;
|
|
321
|
-
exactSecrets = environmentSecrets(process.env);
|
|
322
|
-
try {
|
|
323
|
-
fs.mkdirSync(path2.dirname(filePath), { recursive: true, mode: 448 });
|
|
324
|
-
} catch {
|
|
325
|
-
}
|
|
326
|
-
rotateIfNeeded(filePath);
|
|
327
|
-
try {
|
|
328
|
-
fd = fs.openSync(filePath, "a");
|
|
329
|
-
} catch {
|
|
330
|
-
fd = null;
|
|
331
|
-
fileBytes = 0;
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
fileBytes = fs.fstatSync(fd).size;
|
|
336
|
-
} catch {
|
|
337
|
-
try {
|
|
338
|
-
fs.closeSync(fd);
|
|
339
|
-
} catch {
|
|
340
|
-
}
|
|
341
|
-
fd = null;
|
|
342
|
-
fileBytes = 0;
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
logPath = filePath;
|
|
346
|
-
processBytes = 0;
|
|
347
|
-
rotationFailed = false;
|
|
348
|
-
sessionId = randomBytes(4).toString("hex");
|
|
349
|
-
try {
|
|
350
|
-
if (fileBytes < MAX_BYTES) {
|
|
351
|
-
const written = fs.writeSync(fd, "\n");
|
|
352
|
-
fileBytes += written;
|
|
353
|
-
processBytes += written;
|
|
354
|
-
}
|
|
355
|
-
} catch {
|
|
356
|
-
}
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
function getSessionId() {
|
|
360
|
-
return sessionId;
|
|
361
|
-
}
|
|
362
|
-
function isLoggerOpen() {
|
|
363
|
-
return fd !== null;
|
|
364
|
-
}
|
|
365
|
-
function log(level, category, message, data) {
|
|
366
|
-
if (fd === null) return;
|
|
367
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
368
|
-
const safeMessage = redactText(message, { secrets: exactSecrets });
|
|
369
|
-
let line = `[${ts}] [sid=${sessionId}] [${level}] [${category}] ${safeMessage}`;
|
|
370
|
-
if (data) {
|
|
371
|
-
const safeData = redactValue(data, { secrets: exactSecrets });
|
|
372
|
-
const pairs = Object.entries(safeData).map(([k, v]) => {
|
|
373
|
-
if (typeof v === "string") return `${k}=${v}`;
|
|
374
|
-
if (typeof v === "bigint") return `${k}=${String(v)}`;
|
|
375
|
-
return `${k}=${JSON.stringify(v)}`;
|
|
376
|
-
}).join(" ");
|
|
377
|
-
if (pairs) line += ` ${pairs}`;
|
|
378
|
-
}
|
|
379
|
-
line += "\n";
|
|
380
|
-
const lineBytes = Buffer.byteLength(line);
|
|
381
|
-
if (processBytes + lineBytes > MAX_BYTES) {
|
|
382
|
-
const capLine = `[${ts}] [sid=${sessionId}] [WARN] [logger] Log cap reached; file logging disabled until restart
|
|
383
|
-
`;
|
|
384
|
-
try {
|
|
385
|
-
if (fileBytes + Buffer.byteLength(capLine) <= MAX_BYTES) {
|
|
386
|
-
fileBytes += fs.writeSync(fd, capLine);
|
|
387
|
-
}
|
|
388
|
-
fs.closeSync(fd);
|
|
389
|
-
} catch {
|
|
390
|
-
}
|
|
391
|
-
fd = null;
|
|
392
|
-
capped = true;
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (fileBytes + lineBytes > MAX_BYTES && !rotationFailed && !rotateOpenLog()) return;
|
|
396
|
-
if (fd === null) return;
|
|
397
|
-
try {
|
|
398
|
-
const written = fs.writeSync(fd, line);
|
|
399
|
-
fileBytes += written;
|
|
400
|
-
processBytes += written;
|
|
401
|
-
} catch {
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
function registerLogCleanup(fn) {
|
|
405
|
-
cleanups.push(fn);
|
|
406
|
-
}
|
|
407
|
-
function closeLogger(opts) {
|
|
408
|
-
if (fd !== null) {
|
|
409
|
-
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${appName} shutting down`);
|
|
410
|
-
try {
|
|
411
|
-
if (fd !== null) fs.closeSync(fd);
|
|
412
|
-
} catch {
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
fd = null;
|
|
416
|
-
logPath = null;
|
|
417
|
-
fileBytes = 0;
|
|
418
|
-
processBytes = 0;
|
|
419
|
-
rotationFailed = false;
|
|
420
|
-
capped = false;
|
|
421
|
-
exactSecrets = [];
|
|
422
|
-
for (const unsub of cleanups) unsub();
|
|
423
|
-
cleanups = [];
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// src/claude-code-version.ts
|
|
427
|
-
var NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
428
|
-
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
429
|
-
var FETCH_TIMEOUT_MS = 3e3;
|
|
430
|
-
var FALLBACK_VERSION = "2.1.88";
|
|
431
|
-
var memoryCache = null;
|
|
432
|
-
var inflight = null;
|
|
433
|
-
function cachePath() {
|
|
434
|
-
return path3.join(getAppPaths().agentDir, "claude-code-version.json");
|
|
435
|
-
}
|
|
436
|
-
async function readDiskCache() {
|
|
437
|
-
try {
|
|
438
|
-
const raw = await fs2.readFile(cachePath(), "utf-8");
|
|
439
|
-
const parsed = JSON.parse(raw);
|
|
440
|
-
if (typeof parsed.version === "string" && typeof parsed.fetchedAt === "number") {
|
|
441
|
-
return parsed;
|
|
442
|
-
}
|
|
443
|
-
return null;
|
|
444
|
-
} catch {
|
|
445
|
-
return null;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
async function writeDiskCache(data) {
|
|
449
|
-
try {
|
|
450
|
-
await fs2.mkdir(getAppPaths().agentDir, { recursive: true, mode: 448 });
|
|
451
|
-
await fs2.writeFile(cachePath(), JSON.stringify(data), { mode: 384 });
|
|
452
|
-
} catch (err) {
|
|
453
|
-
log(
|
|
454
|
-
"WARN",
|
|
455
|
-
"claude-code-version",
|
|
456
|
-
`Failed to write cache: ${err instanceof Error ? err.message : String(err)}`
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
async function fetchLatest() {
|
|
461
|
-
const controller = new AbortController();
|
|
462
|
-
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
463
|
-
try {
|
|
464
|
-
const response = await fetch(NPM_LATEST_URL, { signal: controller.signal });
|
|
465
|
-
if (!response.ok) return null;
|
|
466
|
-
const data = await response.json();
|
|
467
|
-
if (typeof data.version === "string" && /^\d/.test(data.version)) {
|
|
468
|
-
return data.version;
|
|
469
|
-
}
|
|
470
|
-
return null;
|
|
471
|
-
} catch {
|
|
472
|
-
return null;
|
|
473
|
-
} finally {
|
|
474
|
-
clearTimeout(timer);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
var refreshing = null;
|
|
478
|
-
function refreshInBackground() {
|
|
479
|
-
refreshing ??= (async () => {
|
|
480
|
-
try {
|
|
481
|
-
const fetched = await fetchLatest();
|
|
482
|
-
if (!fetched) return;
|
|
483
|
-
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
484
|
-
memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
485
|
-
} finally {
|
|
486
|
-
refreshing = null;
|
|
487
|
-
}
|
|
488
|
-
})();
|
|
489
|
-
return refreshing;
|
|
490
|
-
}
|
|
491
|
-
function pendingClaudeCodeVersionRefresh() {
|
|
492
|
-
return refreshing;
|
|
493
|
-
}
|
|
494
|
-
async function getClaudeCodeVersion() {
|
|
495
|
-
if (memoryCache && Date.now() < memoryCache.expiresAt) {
|
|
496
|
-
return memoryCache.version;
|
|
497
|
-
}
|
|
498
|
-
if (inflight) return inflight;
|
|
499
|
-
inflight = (async () => {
|
|
500
|
-
const disk = await readDiskCache();
|
|
501
|
-
const diskFresh = disk && Date.now() - disk.fetchedAt < CACHE_TTL_MS;
|
|
502
|
-
if (disk && diskFresh) {
|
|
503
|
-
memoryCache = { version: disk.version, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
504
|
-
return disk.version;
|
|
505
|
-
}
|
|
506
|
-
if (disk) {
|
|
507
|
-
memoryCache = { version: disk.version, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
508
|
-
void refreshInBackground();
|
|
509
|
-
return disk.version;
|
|
510
|
-
}
|
|
511
|
-
const fetched = await fetchLatest();
|
|
512
|
-
if (fetched) {
|
|
513
|
-
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
514
|
-
memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
515
|
-
return fetched;
|
|
516
|
-
}
|
|
517
|
-
const resolved = FALLBACK_VERSION;
|
|
518
|
-
memoryCache = { version: resolved, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
519
|
-
log(
|
|
520
|
-
"WARN",
|
|
521
|
-
"claude-code-version",
|
|
522
|
-
`Failed to fetch latest Claude Code version; using ${resolved}`
|
|
523
|
-
);
|
|
524
|
-
return resolved;
|
|
525
|
-
})();
|
|
526
|
-
try {
|
|
527
|
-
return await inflight;
|
|
528
|
-
} finally {
|
|
529
|
-
inflight = null;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
async function getClaudeCliUserAgent() {
|
|
533
|
-
const version = await getClaudeCodeVersion();
|
|
534
|
-
return `claude-cli/${version} (external, cli)`;
|
|
535
|
-
}
|
|
259
|
+
import {
|
|
260
|
+
getClaudeCodeVersion,
|
|
261
|
+
getClaudeCliUserAgent,
|
|
262
|
+
pendingClaudeCodeVersionRefresh
|
|
263
|
+
} from "@kenkaiiii/gg-ai";
|
|
536
264
|
|
|
537
265
|
// src/oauth/anthropic.ts
|
|
538
266
|
var CLIENT_ID2 = atob("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
|
|
@@ -1415,7 +1143,7 @@ async function refreshXaiToken(refreshToken) {
|
|
|
1415
1143
|
}
|
|
1416
1144
|
|
|
1417
1145
|
// src/file-lock.ts
|
|
1418
|
-
import
|
|
1146
|
+
import fs from "fs/promises";
|
|
1419
1147
|
import { setTimeout as setTimeout2 } from "timers/promises";
|
|
1420
1148
|
var STALE_TIMEOUT_MS = 1e4;
|
|
1421
1149
|
var RETRY_INTERVAL_MS = 50;
|
|
@@ -1434,27 +1162,27 @@ async function acquireLock(lockPath) {
|
|
|
1434
1162
|
while (true) {
|
|
1435
1163
|
try {
|
|
1436
1164
|
const info = { pid: process.pid, timestamp: Date.now() };
|
|
1437
|
-
await
|
|
1165
|
+
await fs.writeFile(lockPath, JSON.stringify(info), { flag: "wx" });
|
|
1438
1166
|
return;
|
|
1439
1167
|
} catch (err) {
|
|
1440
1168
|
if (err.code !== "EEXIST") throw err;
|
|
1441
1169
|
try {
|
|
1442
|
-
const content = await
|
|
1170
|
+
const content = await fs.readFile(lockPath, "utf-8");
|
|
1443
1171
|
const info = JSON.parse(content);
|
|
1444
1172
|
const isProcessAlive = isAlive(info.pid);
|
|
1445
1173
|
const isStale = Date.now() - info.timestamp > STALE_TIMEOUT_MS;
|
|
1446
1174
|
if (!isProcessAlive || isStale) {
|
|
1447
|
-
await
|
|
1175
|
+
await fs.unlink(lockPath).catch(() => {
|
|
1448
1176
|
});
|
|
1449
1177
|
continue;
|
|
1450
1178
|
}
|
|
1451
1179
|
} catch {
|
|
1452
|
-
await
|
|
1180
|
+
await fs.unlink(lockPath).catch(() => {
|
|
1453
1181
|
});
|
|
1454
1182
|
continue;
|
|
1455
1183
|
}
|
|
1456
1184
|
if (Date.now() - startTime > MAX_WAIT_MS) {
|
|
1457
|
-
await
|
|
1185
|
+
await fs.unlink(lockPath).catch(() => {
|
|
1458
1186
|
});
|
|
1459
1187
|
continue;
|
|
1460
1188
|
}
|
|
@@ -1463,7 +1191,7 @@ async function acquireLock(lockPath) {
|
|
|
1463
1191
|
}
|
|
1464
1192
|
}
|
|
1465
1193
|
async function releaseLock(lockPath) {
|
|
1466
|
-
await
|
|
1194
|
+
await fs.unlink(lockPath).catch(() => {
|
|
1467
1195
|
});
|
|
1468
1196
|
}
|
|
1469
1197
|
function isAlive(pid) {
|
|
@@ -1476,6 +1204,170 @@ function isAlive(pid) {
|
|
|
1476
1204
|
}
|
|
1477
1205
|
}
|
|
1478
1206
|
|
|
1207
|
+
// src/logger.ts
|
|
1208
|
+
import fs2 from "fs";
|
|
1209
|
+
import path2 from "path";
|
|
1210
|
+
import { randomBytes } from "crypto";
|
|
1211
|
+
import { environmentSecrets, redactText, redactValue } from "@kenkaiiii/gg-ai";
|
|
1212
|
+
var MAX_BYTES = 10 * 1024 * 1024;
|
|
1213
|
+
var MIN_HEADROOM_BYTES = 64 * 1024;
|
|
1214
|
+
var fd = null;
|
|
1215
|
+
var logPath = null;
|
|
1216
|
+
var fileBytes = 0;
|
|
1217
|
+
var processBytes = 0;
|
|
1218
|
+
var rotationFailed = false;
|
|
1219
|
+
var capped = false;
|
|
1220
|
+
var sessionId = "";
|
|
1221
|
+
var appName = "app";
|
|
1222
|
+
var cleanups = [];
|
|
1223
|
+
var exactSecrets = [];
|
|
1224
|
+
function rotateIfNeeded(filePath, force = false) {
|
|
1225
|
+
try {
|
|
1226
|
+
const st = fs2.statSync(filePath);
|
|
1227
|
+
if (!force && st.size <= MAX_BYTES - MIN_HEADROOM_BYTES) return;
|
|
1228
|
+
const rotated = `${filePath}.1`;
|
|
1229
|
+
try {
|
|
1230
|
+
fs2.unlinkSync(rotated);
|
|
1231
|
+
} catch {
|
|
1232
|
+
}
|
|
1233
|
+
fs2.renameSync(filePath, rotated);
|
|
1234
|
+
} catch {
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function rotateOpenLog() {
|
|
1238
|
+
if (fd === null || logPath === null) return false;
|
|
1239
|
+
const sizeBefore = fileBytes;
|
|
1240
|
+
try {
|
|
1241
|
+
fs2.closeSync(fd);
|
|
1242
|
+
} catch {
|
|
1243
|
+
}
|
|
1244
|
+
fd = null;
|
|
1245
|
+
rotateIfNeeded(logPath, true);
|
|
1246
|
+
try {
|
|
1247
|
+
fd = fs2.openSync(logPath, "a");
|
|
1248
|
+
fileBytes = fs2.fstatSync(fd).size;
|
|
1249
|
+
} catch {
|
|
1250
|
+
if (fd !== null) {
|
|
1251
|
+
try {
|
|
1252
|
+
fs2.closeSync(fd);
|
|
1253
|
+
} catch {
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
fd = null;
|
|
1257
|
+
capped = true;
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1260
|
+
if (fileBytes >= sizeBefore) rotationFailed = true;
|
|
1261
|
+
return true;
|
|
1262
|
+
}
|
|
1263
|
+
function openLog(filePath, name) {
|
|
1264
|
+
if (fd !== null || capped) return false;
|
|
1265
|
+
appName = name;
|
|
1266
|
+
exactSecrets = environmentSecrets(process.env);
|
|
1267
|
+
try {
|
|
1268
|
+
fs2.mkdirSync(path2.dirname(filePath), { recursive: true, mode: 448 });
|
|
1269
|
+
} catch {
|
|
1270
|
+
}
|
|
1271
|
+
rotateIfNeeded(filePath);
|
|
1272
|
+
try {
|
|
1273
|
+
fd = fs2.openSync(filePath, "a");
|
|
1274
|
+
} catch {
|
|
1275
|
+
fd = null;
|
|
1276
|
+
fileBytes = 0;
|
|
1277
|
+
return false;
|
|
1278
|
+
}
|
|
1279
|
+
try {
|
|
1280
|
+
fileBytes = fs2.fstatSync(fd).size;
|
|
1281
|
+
} catch {
|
|
1282
|
+
try {
|
|
1283
|
+
fs2.closeSync(fd);
|
|
1284
|
+
} catch {
|
|
1285
|
+
}
|
|
1286
|
+
fd = null;
|
|
1287
|
+
fileBytes = 0;
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
logPath = filePath;
|
|
1291
|
+
processBytes = 0;
|
|
1292
|
+
rotationFailed = false;
|
|
1293
|
+
sessionId = randomBytes(4).toString("hex");
|
|
1294
|
+
try {
|
|
1295
|
+
if (fileBytes < MAX_BYTES) {
|
|
1296
|
+
const written = fs2.writeSync(fd, "\n");
|
|
1297
|
+
fileBytes += written;
|
|
1298
|
+
processBytes += written;
|
|
1299
|
+
}
|
|
1300
|
+
} catch {
|
|
1301
|
+
}
|
|
1302
|
+
return true;
|
|
1303
|
+
}
|
|
1304
|
+
function getSessionId() {
|
|
1305
|
+
return sessionId;
|
|
1306
|
+
}
|
|
1307
|
+
function isLoggerOpen() {
|
|
1308
|
+
return fd !== null;
|
|
1309
|
+
}
|
|
1310
|
+
function log(level, category, message, data) {
|
|
1311
|
+
if (fd === null) return;
|
|
1312
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
1313
|
+
const safeMessage = redactText(message, { secrets: exactSecrets });
|
|
1314
|
+
let line = `[${ts}] [sid=${sessionId}] [${level}] [${category}] ${safeMessage}`;
|
|
1315
|
+
if (data) {
|
|
1316
|
+
const safeData = redactValue(data, { secrets: exactSecrets });
|
|
1317
|
+
const pairs = Object.entries(safeData).map(([k, v]) => {
|
|
1318
|
+
if (typeof v === "string") return `${k}=${v}`;
|
|
1319
|
+
if (typeof v === "bigint") return `${k}=${String(v)}`;
|
|
1320
|
+
return `${k}=${JSON.stringify(v)}`;
|
|
1321
|
+
}).join(" ");
|
|
1322
|
+
if (pairs) line += ` ${pairs}`;
|
|
1323
|
+
}
|
|
1324
|
+
line += "\n";
|
|
1325
|
+
const lineBytes = Buffer.byteLength(line);
|
|
1326
|
+
if (processBytes + lineBytes > MAX_BYTES) {
|
|
1327
|
+
const capLine = `[${ts}] [sid=${sessionId}] [WARN] [logger] Log cap reached; file logging disabled until restart
|
|
1328
|
+
`;
|
|
1329
|
+
try {
|
|
1330
|
+
if (fileBytes + Buffer.byteLength(capLine) <= MAX_BYTES) {
|
|
1331
|
+
fileBytes += fs2.writeSync(fd, capLine);
|
|
1332
|
+
}
|
|
1333
|
+
fs2.closeSync(fd);
|
|
1334
|
+
} catch {
|
|
1335
|
+
}
|
|
1336
|
+
fd = null;
|
|
1337
|
+
capped = true;
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
if (fileBytes + lineBytes > MAX_BYTES && !rotationFailed && !rotateOpenLog()) return;
|
|
1341
|
+
if (fd === null) return;
|
|
1342
|
+
try {
|
|
1343
|
+
const written = fs2.writeSync(fd, line);
|
|
1344
|
+
fileBytes += written;
|
|
1345
|
+
processBytes += written;
|
|
1346
|
+
} catch {
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function registerLogCleanup(fn) {
|
|
1350
|
+
cleanups.push(fn);
|
|
1351
|
+
}
|
|
1352
|
+
function closeLogger(opts) {
|
|
1353
|
+
if (fd !== null) {
|
|
1354
|
+
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${appName} shutting down`);
|
|
1355
|
+
try {
|
|
1356
|
+
if (fd !== null) fs2.closeSync(fd);
|
|
1357
|
+
} catch {
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
fd = null;
|
|
1361
|
+
logPath = null;
|
|
1362
|
+
fileBytes = 0;
|
|
1363
|
+
processBytes = 0;
|
|
1364
|
+
rotationFailed = false;
|
|
1365
|
+
capped = false;
|
|
1366
|
+
exactSecrets = [];
|
|
1367
|
+
for (const unsub of cleanups) unsub();
|
|
1368
|
+
cleanups = [];
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1479
1371
|
// src/hidden-providers.ts
|
|
1480
1372
|
var HIDDEN_PROVIDERS = ["gemini"];
|
|
1481
1373
|
function isHiddenProvider(provider) {
|
|
@@ -1682,7 +1574,7 @@ var AuthStorage = class {
|
|
|
1682
1574
|
const first = !this.loaded;
|
|
1683
1575
|
await withFileLock(this.filePath, async () => {
|
|
1684
1576
|
try {
|
|
1685
|
-
const content = await
|
|
1577
|
+
const content = await fs3.readFile(this.filePath, "utf-8");
|
|
1686
1578
|
this.data = JSON.parse(content);
|
|
1687
1579
|
if (first) {
|
|
1688
1580
|
log("INFO", "auth", `Loaded credentials from ${this.filePath}`, {
|
|
@@ -1728,7 +1620,7 @@ var AuthStorage = class {
|
|
|
1728
1620
|
}
|
|
1729
1621
|
let changed;
|
|
1730
1622
|
try {
|
|
1731
|
-
const stat = await
|
|
1623
|
+
const stat = await fs3.stat(this.filePath);
|
|
1732
1624
|
changed = stat.ino !== this.snapshotIno || stat.mtimeMs !== this.snapshotMtimeMs || stat.size !== this.snapshotSize;
|
|
1733
1625
|
} catch {
|
|
1734
1626
|
changed = this.snapshotSize !== -1;
|
|
@@ -1741,7 +1633,7 @@ var AuthStorage = class {
|
|
|
1741
1633
|
*/
|
|
1742
1634
|
async rememberSnapshot() {
|
|
1743
1635
|
try {
|
|
1744
|
-
const stat = await
|
|
1636
|
+
const stat = await fs3.stat(this.filePath);
|
|
1745
1637
|
this.snapshotMtimeMs = stat.mtimeMs;
|
|
1746
1638
|
this.snapshotSize = stat.size;
|
|
1747
1639
|
this.snapshotIno = stat.ino;
|
|
@@ -1982,7 +1874,7 @@ var AuthStorage = class {
|
|
|
1982
1874
|
};
|
|
1983
1875
|
async function readAuthData(filePath) {
|
|
1984
1876
|
try {
|
|
1985
|
-
const content = await
|
|
1877
|
+
const content = await fs3.readFile(filePath, "utf-8");
|
|
1986
1878
|
return JSON.parse(content);
|
|
1987
1879
|
} catch (error) {
|
|
1988
1880
|
if (error.code === "ENOENT") return {};
|
|
@@ -1992,10 +1884,10 @@ async function readAuthData(filePath) {
|
|
|
1992
1884
|
async function atomicWriteFile(filePath, content) {
|
|
1993
1885
|
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${crypto5.randomUUID().slice(0, 8)}.tmp`;
|
|
1994
1886
|
try {
|
|
1995
|
-
await
|
|
1996
|
-
await
|
|
1887
|
+
await fs3.writeFile(tmpPath, content, { encoding: "utf-8", mode: 384 });
|
|
1888
|
+
await fs3.rename(tmpPath, filePath);
|
|
1997
1889
|
} catch (err) {
|
|
1998
|
-
await
|
|
1890
|
+
await fs3.unlink(tmpPath).catch(() => {
|
|
1999
1891
|
});
|
|
2000
1892
|
throw err;
|
|
2001
1893
|
}
|
|
@@ -2869,15 +2761,9 @@ export {
|
|
|
2869
2761
|
loginKimi,
|
|
2870
2762
|
refreshKimiToken,
|
|
2871
2763
|
generatePKCE,
|
|
2872
|
-
openLog,
|
|
2873
|
-
getSessionId,
|
|
2874
|
-
isLoggerOpen,
|
|
2875
|
-
log,
|
|
2876
|
-
registerLogCleanup,
|
|
2877
|
-
closeLogger,
|
|
2878
|
-
pendingClaudeCodeVersionRefresh,
|
|
2879
2764
|
getClaudeCodeVersion,
|
|
2880
2765
|
getClaudeCliUserAgent,
|
|
2766
|
+
pendingClaudeCodeVersionRefresh,
|
|
2881
2767
|
loginAnthropic,
|
|
2882
2768
|
refreshAnthropicToken,
|
|
2883
2769
|
loginOpenAI,
|
|
@@ -2890,6 +2776,12 @@ export {
|
|
|
2890
2776
|
loginXai,
|
|
2891
2777
|
refreshXaiToken,
|
|
2892
2778
|
withFileLock,
|
|
2779
|
+
openLog,
|
|
2780
|
+
getSessionId,
|
|
2781
|
+
isLoggerOpen,
|
|
2782
|
+
log,
|
|
2783
|
+
registerLogCleanup,
|
|
2784
|
+
closeLogger,
|
|
2893
2785
|
HIDDEN_PROVIDERS,
|
|
2894
2786
|
isHiddenProvider,
|
|
2895
2787
|
MOONSHOT_OAUTH_KEY,
|
|
@@ -2926,4 +2818,4 @@ export {
|
|
|
2926
2818
|
getDefaultThinkingLevel,
|
|
2927
2819
|
getSummaryModel
|
|
2928
2820
|
};
|
|
2929
|
-
//# sourceMappingURL=chunk-
|
|
2821
|
+
//# sourceMappingURL=chunk-5ZYOOESD.js.map
|