@polka-codes/cli-shared 0.9.92 → 0.9.94

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.
Files changed (2) hide show
  1. package/dist/index.js +64 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -35106,7 +35106,7 @@ var require_mimeScore = __commonJS((exports, module) => {
35106
35106
 
35107
35107
  // ../../node_modules/sql.js/dist/sql-wasm.js
35108
35108
  var require_sql_wasm = __commonJS((exports, module) => {
35109
- var __dirname = "/home/ubuntu/polka-codes/node_modules/sql.js/dist";
35109
+ var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
35110
35110
  var initSqlJsPromise = undefined;
35111
35111
  var initSqlJs = function(moduleConfig) {
35112
35112
  if (initSqlJsPromise) {
@@ -52477,6 +52477,9 @@ class UsageMeter {
52477
52477
  let requestsWithCache = 0;
52478
52478
  for (const entry of entries) {
52479
52479
  const metadata = entry.metadata;
52480
+ if (typeof metadata !== "object" || metadata === null) {
52481
+ continue;
52482
+ }
52480
52483
  const cachedTokens = metadata.cachedPromptTokens ?? metadata.cacheReadTokens ?? metadata.prompt_cache_hit_tokens ?? 0;
52481
52484
  if (cachedTokens > 0) {
52482
52485
  totalCachedTokens += cachedTokens;
@@ -63433,9 +63436,11 @@ ${error48}`);
63433
63436
  const config3 = readConfig(path);
63434
63437
  configs.push(config3);
63435
63438
  } catch (error48) {
63436
- console.error(`Error loading config file: ${path}
63439
+ if (error48 instanceof ZodError) {
63440
+ console.error(`Error in config file: ${path}
63437
63441
  ${error48}`);
63438
- throw error48;
63442
+ throw error48;
63443
+ }
63439
63444
  }
63440
63445
  }
63441
63446
  } else {
@@ -67474,17 +67479,65 @@ ${content}`;
67474
67479
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
67475
67480
  import { randomUUID } from "node:crypto";
67476
67481
  import { existsSync as existsSync3 } from "node:fs";
67477
- import { mkdir as mkdir2, readFile as readFile3, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
67478
- import { dirname as dirname3, resolve as resolve5 } from "node:path";
67482
+ import { mkdir as mkdir2, readdir, readFile as readFile3, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
67483
+ import { basename as basename2, dirname as dirname3, resolve as resolve5 } from "node:path";
67479
67484
  import { fileURLToPath } from "node:url";
67480
67485
  var import_sql = __toESM(require_sql_wasm(), 1);
67481
67486
 
67482
67487
  class FileLock {
67483
67488
  lockfilePath;
67484
67489
  static LOCK_TIMEOUT = 30000;
67490
+ static CLEANUP_AGE = 600000;
67491
+ static lastCleanupTime = 0;
67492
+ static CLEANUP_THROTTLE = 60000;
67485
67493
  constructor(dbPath) {
67486
67494
  this.lockfilePath = `${dbPath}.lock`;
67487
67495
  }
67496
+ static resetCleanupThrottle() {
67497
+ FileLock.lastCleanupTime = 0;
67498
+ }
67499
+ static async cleanupOldLockFiles(dbPath, maxAge = FileLock.CLEANUP_AGE, force = false) {
67500
+ const now = Date.now();
67501
+ if (!force && now - FileLock.lastCleanupTime < FileLock.CLEANUP_THROTTLE) {
67502
+ return;
67503
+ }
67504
+ FileLock.lastCleanupTime = now;
67505
+ try {
67506
+ const lockDir = dirname3(dbPath);
67507
+ const dbBaseName = basename2(dbPath);
67508
+ const files = await readdir(lockDir);
67509
+ const now2 = Date.now();
67510
+ let cleanedCount = 0;
67511
+ for (const file2 of files) {
67512
+ if (!file2.startsWith(`${dbBaseName}.lock.`)) {
67513
+ continue;
67514
+ }
67515
+ const match = file2.match(/\.lock\.(released|stale|invalid|corrupt)\.(\d+)$/);
67516
+ if (!match) {
67517
+ continue;
67518
+ }
67519
+ const filePath = resolve5(lockDir, file2);
67520
+ const timestamp = Number.parseInt(match[2], 10);
67521
+ const age = now2 - timestamp;
67522
+ if (age > maxAge) {
67523
+ try {
67524
+ await unlink2(filePath);
67525
+ cleanedCount++;
67526
+ } catch (error48) {
67527
+ const errorCode = error48?.code;
67528
+ if (errorCode !== "ENOENT") {
67529
+ console.warn(`[FileLock] Failed to delete old lock file ${file2}: ${error48 instanceof Error ? error48.message : String(error48)}`);
67530
+ }
67531
+ }
67532
+ }
67533
+ }
67534
+ if (cleanedCount > 0) {
67535
+ console.log(`[FileLock] Cleaned up ${cleanedCount} old lock file(s) (older than ${maxAge}ms)`);
67536
+ }
67537
+ } catch (error48) {
67538
+ console.debug(`[FileLock] Cleanup encountered an error: ${error48 instanceof Error ? error48.message : String(error48)}`);
67539
+ }
67540
+ }
67488
67541
  async acquire(retries = 10, delay2 = 100) {
67489
67542
  for (let i2 = 0;i2 < retries; i2++) {
67490
67543
  try {
@@ -67535,6 +67588,8 @@ class FileLock {
67535
67588
  async release() {
67536
67589
  try {
67537
67590
  await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
67591
+ const dbPath = this.lockfilePath.slice(0, -5);
67592
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
67538
67593
  } catch (error48) {
67539
67594
  const errorCode = error48.code;
67540
67595
  if (errorCode !== "ENOENT") {
@@ -67617,6 +67672,9 @@ class SQLiteMemoryStore {
67617
67672
  inTransaction = false;
67618
67673
  transactionMutex = new ReentrantMutex;
67619
67674
  fileLock;
67675
+ static resetCleanupThrottle() {
67676
+ FileLock.resetCleanupThrottle();
67677
+ }
67620
67678
  getDbPath() {
67621
67679
  return this.config.path || DEFAULT_MEMORY_CONFIG.path;
67622
67680
  }
@@ -67653,6 +67711,7 @@ class SQLiteMemoryStore {
67653
67711
  if (!existsSync3(dir)) {
67654
67712
  await mkdir2(dir, { recursive: true, mode: 448 });
67655
67713
  }
67714
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
67656
67715
  let dbData;
67657
67716
  if (existsSync3(dbPath)) {
67658
67717
  const lock = this.getFileLock();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.92",
3
+ "version": "0.9.94",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",