codexuse-cli 3.1.1 → 3.1.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/index.js +36 -10
- package/dist/index.js.map +1 -1
- package/dist/server/index.mjs +99 -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);
|
|
@@ -8624,7 +8650,7 @@ async function ensureCliStorageReady() {
|
|
|
8624
8650
|
}
|
|
8625
8651
|
|
|
8626
8652
|
// src/app/main.ts
|
|
8627
|
-
var VERSION = true ? "3.
|
|
8653
|
+
var VERSION = true ? "3.1.3" : "0.0.0";
|
|
8628
8654
|
async function runCli() {
|
|
8629
8655
|
const args = process.argv.slice(2);
|
|
8630
8656
|
if (args.length === 0) {
|