@polka-codes/cli 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 +73 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25661,6 +25661,9 @@ class UsageMeter {
25661
25661
  let requestsWithCache = 0;
25662
25662
  for (const entry of entries) {
25663
25663
  const metadata = entry.metadata;
25664
+ if (typeof metadata !== "object" || metadata === null) {
25665
+ continue;
25666
+ }
25664
25667
  const cachedTokens = metadata.cachedPromptTokens ?? metadata.cacheReadTokens ?? metadata.prompt_cache_hit_tokens ?? 0;
25665
25668
  if (cachedTokens > 0) {
25666
25669
  totalCachedTokens += cachedTokens;
@@ -42706,9 +42709,11 @@ ${error48}`);
42706
42709
  const config3 = readConfig(path);
42707
42710
  configs.push(config3);
42708
42711
  } catch (error48) {
42709
- console.error(`Error loading config file: ${path}
42712
+ if (error48 instanceof ZodError) {
42713
+ console.error(`Error in config file: ${path}
42710
42714
  ${error48}`);
42711
- throw error48;
42715
+ throw error48;
42716
+ }
42712
42717
  }
42713
42718
  }
42714
42719
  } else {
@@ -73524,7 +73529,7 @@ var init_provider = __esm(() => {
73524
73529
 
73525
73530
  // ../../node_modules/sql.js/dist/sql-wasm.js
73526
73531
  var require_sql_wasm = __commonJS((exports, module) => {
73527
- var __dirname = "/home/ubuntu/polka-codes/node_modules/sql.js/dist";
73532
+ var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
73528
73533
  var initSqlJsPromise = undefined;
73529
73534
  var initSqlJs = function(moduleConfig) {
73530
73535
  if (initSqlJsPromise) {
@@ -75810,16 +75815,64 @@ var require_sql_wasm = __commonJS((exports, module) => {
75810
75815
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
75811
75816
  import { randomUUID } from "node:crypto";
75812
75817
  import { existsSync as existsSync4 } from "node:fs";
75813
- import { mkdir as mkdir2, readFile as readFile4, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
75814
- import { dirname as dirname3, resolve as resolve5 } from "node:path";
75818
+ import { mkdir as mkdir2, readdir as readdir2, readFile as readFile4, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
75819
+ import { basename as basename2, dirname as dirname3, resolve as resolve5 } from "node:path";
75815
75820
  import { fileURLToPath } from "node:url";
75816
75821
 
75817
75822
  class FileLock {
75818
75823
  lockfilePath;
75819
75824
  static LOCK_TIMEOUT = 30000;
75825
+ static CLEANUP_AGE = 600000;
75826
+ static lastCleanupTime = 0;
75827
+ static CLEANUP_THROTTLE = 60000;
75820
75828
  constructor(dbPath) {
75821
75829
  this.lockfilePath = `${dbPath}.lock`;
75822
75830
  }
75831
+ static resetCleanupThrottle() {
75832
+ FileLock.lastCleanupTime = 0;
75833
+ }
75834
+ static async cleanupOldLockFiles(dbPath, maxAge = FileLock.CLEANUP_AGE, force = false) {
75835
+ const now2 = Date.now();
75836
+ if (!force && now2 - FileLock.lastCleanupTime < FileLock.CLEANUP_THROTTLE) {
75837
+ return;
75838
+ }
75839
+ FileLock.lastCleanupTime = now2;
75840
+ try {
75841
+ const lockDir = dirname3(dbPath);
75842
+ const dbBaseName = basename2(dbPath);
75843
+ const files = await readdir2(lockDir);
75844
+ const now3 = Date.now();
75845
+ let cleanedCount = 0;
75846
+ for (const file2 of files) {
75847
+ if (!file2.startsWith(`${dbBaseName}.lock.`)) {
75848
+ continue;
75849
+ }
75850
+ const match = file2.match(/\.lock\.(released|stale|invalid|corrupt)\.(\d+)$/);
75851
+ if (!match) {
75852
+ continue;
75853
+ }
75854
+ const filePath = resolve5(lockDir, file2);
75855
+ const timestamp = Number.parseInt(match[2], 10);
75856
+ const age = now3 - timestamp;
75857
+ if (age > maxAge) {
75858
+ try {
75859
+ await unlink2(filePath);
75860
+ cleanedCount++;
75861
+ } catch (error48) {
75862
+ const errorCode = error48?.code;
75863
+ if (errorCode !== "ENOENT") {
75864
+ console.warn(`[FileLock] Failed to delete old lock file ${file2}: ${error48 instanceof Error ? error48.message : String(error48)}`);
75865
+ }
75866
+ }
75867
+ }
75868
+ }
75869
+ if (cleanedCount > 0) {
75870
+ console.log(`[FileLock] Cleaned up ${cleanedCount} old lock file(s) (older than ${maxAge}ms)`);
75871
+ }
75872
+ } catch (error48) {
75873
+ console.debug(`[FileLock] Cleanup encountered an error: ${error48 instanceof Error ? error48.message : String(error48)}`);
75874
+ }
75875
+ }
75823
75876
  async acquire(retries = 10, delay2 = 100) {
75824
75877
  for (let i2 = 0;i2 < retries; i2++) {
75825
75878
  try {
@@ -75870,6 +75923,8 @@ class FileLock {
75870
75923
  async release() {
75871
75924
  try {
75872
75925
  await rename2(this.lockfilePath, `${this.lockfilePath}.released.${Date.now()}`);
75926
+ const dbPath = this.lockfilePath.slice(0, -5);
75927
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
75873
75928
  } catch (error48) {
75874
75929
  const errorCode = error48.code;
75875
75930
  if (errorCode !== "ENOENT") {
@@ -75953,6 +76008,9 @@ var init_sqlite_memory_store = __esm(() => {
75953
76008
  inTransaction = false;
75954
76009
  transactionMutex = new ReentrantMutex;
75955
76010
  fileLock;
76011
+ static resetCleanupThrottle() {
76012
+ FileLock.resetCleanupThrottle();
76013
+ }
75956
76014
  getDbPath() {
75957
76015
  return this.config.path || DEFAULT_MEMORY_CONFIG.path;
75958
76016
  }
@@ -75989,6 +76047,7 @@ var init_sqlite_memory_store = __esm(() => {
75989
76047
  if (!existsSync4(dir)) {
75990
76048
  await mkdir2(dir, { recursive: true, mode: 448 });
75991
76049
  }
76050
+ FileLock.cleanupOldLockFiles(dbPath).catch(() => {});
75992
76051
  let dbData;
75993
76052
  if (existsSync4(dbPath)) {
75994
76053
  const lock = this.getFileLock();
@@ -94068,9 +94127,11 @@ function createGitReadBinaryFile(commit2) {
94068
94127
  }
94069
94128
  };
94070
94129
  }
94071
- const result = await provider3.executeCommand(`git show ${quotedCommit}:${quotedUrl}`, false);
94130
+ const isWindows2 = process.platform === "win32";
94131
+ const command = isWindows2 ? `cmd /c "git show ${quotedCommit}:${quotedUrl} | base64 -w 0 2>&1"` : `sh -c "git show ${quotedCommit}:${quotedUrl} | base64 2>&1"`;
94132
+ const result = await provider3.executeCommand(command, false);
94072
94133
  if (result.exitCode === 0) {
94073
- const base64Data = Buffer.from(result.stdout, "binary").toString("base64");
94134
+ const base64Data = result.stdout.replace(/\n/g, "");
94074
94135
  return {
94075
94136
  success: true,
94076
94137
  message: {
@@ -94086,11 +94147,13 @@ function createGitReadBinaryFile(commit2) {
94086
94147
  }
94087
94148
  };
94088
94149
  } else {
94150
+ const isBase64Error = result.stderr.includes("not recognized") || result.stderr.includes("command not found") || result.stderr.includes("base64");
94151
+ const errorMessage = isBase64Error ? `Failed to read binary file: base64 command not found. On Windows, ensure Git Bash or Unix tools are installed and in PATH.` : `Failed to read binary file: ${result.stderr}`;
94089
94152
  return {
94090
94153
  success: false,
94091
94154
  message: {
94092
94155
  type: "error-text",
94093
- value: `Failed to read binary file: ${result.stderr}`
94156
+ value: errorMessage
94094
94157
  }
94095
94158
  };
94096
94159
  }
@@ -112279,7 +112342,7 @@ var {
112279
112342
  Help
112280
112343
  } = import__.default;
112281
112344
  // package.json
112282
- var version = "0.9.92";
112345
+ var version = "0.9.94";
112283
112346
 
112284
112347
  // src/commands/agent.ts
112285
112348
  init_src();
@@ -121396,6 +121459,7 @@ var reviewCommand = new Command("review").description("Review a GitHub pull requ
121396
121459
  const workflowOpts = getBaseWorkflowOptions(command);
121397
121460
  if (json2) {
121398
121461
  workflowOpts.interactive = false;
121462
+ workflowOpts.silent = true;
121399
121463
  }
121400
121464
  const { verbose } = workflowOpts;
121401
121465
  const logger = createLogger({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
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",