codexuse-cli 3.1.2 → 3.1.4
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/index.js +104 -10
- package/dist/index.js.map +1 -1
- package/dist/server/index.mjs +178 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2402,6 +2402,9 @@ var import_node_path3 = __toESM(require("path"), 1);
|
|
|
2402
2402
|
var APP_STORAGE_TABLE = "app_storage_documents";
|
|
2403
2403
|
var APP_STORAGE_DB_DIR = "t3-projects";
|
|
2404
2404
|
var APP_STORAGE_DB_NAME = "state.sqlite";
|
|
2405
|
+
var SQLITE_BUSY_TIMEOUT_MS = 5e3;
|
|
2406
|
+
var SQLITE_BUSY_MAX_ATTEMPTS = 3;
|
|
2407
|
+
var SQLITE_BUSY_RETRY_DELAY_MS = 100;
|
|
2405
2408
|
var initializedDbPaths = /* @__PURE__ */ new Set();
|
|
2406
2409
|
function isRecord(value) {
|
|
2407
2410
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -2419,6 +2422,17 @@ function safeParseJson(raw) {
|
|
|
2419
2422
|
return null;
|
|
2420
2423
|
}
|
|
2421
2424
|
}
|
|
2425
|
+
function sleep(ms) {
|
|
2426
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2427
|
+
}
|
|
2428
|
+
function isSqliteBusyError(error) {
|
|
2429
|
+
if (!error || typeof error !== "object") {
|
|
2430
|
+
return false;
|
|
2431
|
+
}
|
|
2432
|
+
const sqliteError = error;
|
|
2433
|
+
const message = typeof sqliteError.message === "string" ? sqliteError.message.toLowerCase() : "";
|
|
2434
|
+
return sqliteError.code === "SQLITE_BUSY" || sqliteError.errno === 5 || message.includes("sqlite_busy") || message.includes("database is locked");
|
|
2435
|
+
}
|
|
2422
2436
|
function beginImmediate(db) {
|
|
2423
2437
|
db.exec("BEGIN IMMEDIATE");
|
|
2424
2438
|
}
|
|
@@ -2431,12 +2445,15 @@ function rollback(db) {
|
|
|
2431
2445
|
} catch {
|
|
2432
2446
|
}
|
|
2433
2447
|
}
|
|
2448
|
+
function applyConnectionPragmas(db) {
|
|
2449
|
+
db.exec(`PRAGMA busy_timeout = ${SQLITE_BUSY_TIMEOUT_MS};`);
|
|
2450
|
+
db.exec("PRAGMA journal_mode = WAL;");
|
|
2451
|
+
db.exec("PRAGMA foreign_keys = ON;");
|
|
2452
|
+
}
|
|
2434
2453
|
function ensureSchema(db, dbPath) {
|
|
2435
2454
|
if (initializedDbPaths.has(dbPath)) {
|
|
2436
2455
|
return;
|
|
2437
2456
|
}
|
|
2438
|
-
db.exec("PRAGMA journal_mode = WAL;");
|
|
2439
|
-
db.exec("PRAGMA foreign_keys = ON;");
|
|
2440
2457
|
db.exec(`
|
|
2441
2458
|
CREATE TABLE IF NOT EXISTS ${APP_STORAGE_TABLE} (
|
|
2442
2459
|
namespace TEXT PRIMARY KEY,
|
|
@@ -2457,7 +2474,7 @@ async function openDatabase(dbPath) {
|
|
|
2457
2474
|
close: database2.close.bind(database2)
|
|
2458
2475
|
};
|
|
2459
2476
|
}
|
|
2460
|
-
const sqlite = await import(
|
|
2477
|
+
const sqlite = await Function("return import('node:sqlite')")();
|
|
2461
2478
|
const database = new sqlite.DatabaseSync(dbPath);
|
|
2462
2479
|
return {
|
|
2463
2480
|
exec: database.exec.bind(database),
|
|
@@ -2466,13 +2483,22 @@ async function openDatabase(dbPath) {
|
|
|
2466
2483
|
};
|
|
2467
2484
|
}
|
|
2468
2485
|
async function withDatabase(dbPath, task) {
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2486
|
+
for (let attempt = 1; attempt <= SQLITE_BUSY_MAX_ATTEMPTS; attempt += 1) {
|
|
2487
|
+
const db = await openDatabase(dbPath);
|
|
2488
|
+
try {
|
|
2489
|
+
applyConnectionPragmas(db);
|
|
2490
|
+
ensureSchema(db, dbPath);
|
|
2491
|
+
return task(db);
|
|
2492
|
+
} catch (error) {
|
|
2493
|
+
if (!isSqliteBusyError(error) || attempt >= SQLITE_BUSY_MAX_ATTEMPTS) {
|
|
2494
|
+
throw error;
|
|
2495
|
+
}
|
|
2496
|
+
} finally {
|
|
2497
|
+
db.close();
|
|
2498
|
+
}
|
|
2499
|
+
await sleep(SQLITE_BUSY_RETRY_DELAY_MS * attempt);
|
|
2475
2500
|
}
|
|
2501
|
+
throw new Error("App storage database remained busy after retrying.");
|
|
2476
2502
|
}
|
|
2477
2503
|
function resolveAppStorageDbPath(userDataDir) {
|
|
2478
2504
|
return import_node_path3.default.join(userDataDir, APP_STORAGE_DB_DIR, APP_STORAGE_DB_NAME);
|
|
@@ -3773,6 +3799,7 @@ async function handleLicense(args, version) {
|
|
|
3773
3799
|
}
|
|
3774
3800
|
|
|
3775
3801
|
// ../../packages/runtime-profiles/src/profiles/profile-manager.ts
|
|
3802
|
+
var import_node_crypto4 = require("crypto");
|
|
3776
3803
|
var import_fs = require("fs");
|
|
3777
3804
|
var import_path = __toESM(require("path"), 1);
|
|
3778
3805
|
var import_path2 = require("path");
|
|
@@ -4398,6 +4425,73 @@ var ProfileManager = class {
|
|
|
4398
4425
|
return null;
|
|
4399
4426
|
}
|
|
4400
4427
|
}
|
|
4428
|
+
async captureActiveAuthSnapshot() {
|
|
4429
|
+
await this.initialize();
|
|
4430
|
+
let raw;
|
|
4431
|
+
try {
|
|
4432
|
+
raw = await import_fs.promises.readFile(this.activeAuth, "utf8");
|
|
4433
|
+
} catch (error) {
|
|
4434
|
+
if (this.isNotFoundError(error)) {
|
|
4435
|
+
return {
|
|
4436
|
+
fingerprint: null,
|
|
4437
|
+
email: null,
|
|
4438
|
+
accountId: null,
|
|
4439
|
+
userId: null,
|
|
4440
|
+
chatgptUserId: null,
|
|
4441
|
+
workspaceId: null
|
|
4442
|
+
};
|
|
4443
|
+
}
|
|
4444
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
4445
|
+
const signature = typeof message === "string" ? `${message}:${this.activeAuth}` : this.activeAuth;
|
|
4446
|
+
if (this.lastActiveAuthErrorSignature !== signature) {
|
|
4447
|
+
logWarn("Failed to snapshot active auth file:", error);
|
|
4448
|
+
this.lastActiveAuthErrorSignature = signature;
|
|
4449
|
+
}
|
|
4450
|
+
return {
|
|
4451
|
+
fingerprint: null,
|
|
4452
|
+
email: null,
|
|
4453
|
+
accountId: null,
|
|
4454
|
+
userId: null,
|
|
4455
|
+
chatgptUserId: null,
|
|
4456
|
+
workspaceId: null
|
|
4457
|
+
};
|
|
4458
|
+
}
|
|
4459
|
+
const trimmed = raw.trim();
|
|
4460
|
+
if (!trimmed) {
|
|
4461
|
+
return {
|
|
4462
|
+
fingerprint: null,
|
|
4463
|
+
email: null,
|
|
4464
|
+
accountId: null,
|
|
4465
|
+
userId: null,
|
|
4466
|
+
chatgptUserId: null,
|
|
4467
|
+
workspaceId: null
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
4470
|
+
const fingerprint = (0, import_node_crypto4.createHash)("sha256").update(trimmed).digest("hex");
|
|
4471
|
+
try {
|
|
4472
|
+
const parsed = JSON.parse(trimmed);
|
|
4473
|
+
const normalized = this.normalizeProfileData(parsed);
|
|
4474
|
+
const metadata = this.extractProfileMetadata(normalized);
|
|
4475
|
+
const workspace = this.resolveWorkspaceIdentity(normalized, metadata);
|
|
4476
|
+
return {
|
|
4477
|
+
fingerprint,
|
|
4478
|
+
email: this.resolveProfileEmail(normalized, metadata) ?? null,
|
|
4479
|
+
accountId: this.getAccountIdFromData(normalized) ?? null,
|
|
4480
|
+
userId: metadata?.userId ?? null,
|
|
4481
|
+
chatgptUserId: metadata?.chatgptUserId ?? null,
|
|
4482
|
+
workspaceId: workspace.id ?? null
|
|
4483
|
+
};
|
|
4484
|
+
} catch {
|
|
4485
|
+
return {
|
|
4486
|
+
fingerprint,
|
|
4487
|
+
email: null,
|
|
4488
|
+
accountId: null,
|
|
4489
|
+
userId: null,
|
|
4490
|
+
chatgptUserId: null,
|
|
4491
|
+
workspaceId: null
|
|
4492
|
+
};
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4401
4495
|
/**
|
|
4402
4496
|
* Decode a JWT payload into an object without validating the signature.
|
|
4403
4497
|
*/
|
|
@@ -8624,7 +8718,7 @@ async function ensureCliStorageReady() {
|
|
|
8624
8718
|
}
|
|
8625
8719
|
|
|
8626
8720
|
// src/app/main.ts
|
|
8627
|
-
var VERSION = true ? "3.
|
|
8721
|
+
var VERSION = true ? "3.1.4" : "0.0.0";
|
|
8628
8722
|
async function runCli() {
|
|
8629
8723
|
const args = process.argv.slice(2);
|
|
8630
8724
|
if (args.length === 0) {
|