@yishiguji/tokenarena 0.14.0 → 0.14.2

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 CHANGED
@@ -969,7 +969,55 @@ import { dirname, join as join6 } from "path";
969
969
 
970
970
  // src/infrastructure/sqlite.ts
971
971
  import { execFileSync } from "child_process";
972
+ import { statSync } from "fs";
972
973
  import { pathToFileURL } from "url";
974
+
975
+ // src/utils/logger.ts
976
+ var LOG_LEVELS = {
977
+ debug: 0,
978
+ info: 1,
979
+ warn: 2,
980
+ error: 3
981
+ };
982
+ var Logger = class {
983
+ level;
984
+ constructor(level = "info") {
985
+ this.level = level;
986
+ }
987
+ setLevel(level) {
988
+ this.level = level;
989
+ }
990
+ debug(msg) {
991
+ if (LOG_LEVELS[this.level] <= LOG_LEVELS.debug) {
992
+ process.stderr.write(`[debug] ${msg}
993
+ `);
994
+ }
995
+ }
996
+ info(msg) {
997
+ if (LOG_LEVELS[this.level] <= LOG_LEVELS.info) {
998
+ process.stdout.write(`${msg}
999
+ `);
1000
+ }
1001
+ }
1002
+ warn(msg) {
1003
+ if (LOG_LEVELS[this.level] <= LOG_LEVELS.warn) {
1004
+ process.stderr.write(`warn: ${msg}
1005
+ `);
1006
+ }
1007
+ }
1008
+ error(msg) {
1009
+ if (LOG_LEVELS[this.level] <= LOG_LEVELS.error) {
1010
+ process.stderr.write(`error: ${msg}
1011
+ `);
1012
+ }
1013
+ }
1014
+ log(msg) {
1015
+ this.info(msg);
1016
+ }
1017
+ };
1018
+ var logger = new Logger();
1019
+
1020
+ // src/infrastructure/sqlite.ts
973
1021
  function withSuppressedSqliteWarning(fn) {
974
1022
  const originalEmitWarning = process.emitWarning;
975
1023
  process.emitWarning = ((warning, ...args) => {
@@ -984,21 +1032,34 @@ function withSuppressedSqliteWarning(fn) {
984
1032
  process.emitWarning = originalEmitWarning;
985
1033
  });
986
1034
  }
1035
+ function warnWhenWalSkipped(dbPath) {
1036
+ try {
1037
+ const pendingBytes = statSync(`${dbPath}-wal`).size;
1038
+ if (pendingBytes > 0) {
1039
+ logger.warn(
1040
+ `${dbPath} was read without its write-ahead log (${pendingBytes} bytes pending), so the newest records may be missing. This happens when the database directory is not writable.`
1041
+ );
1042
+ }
1043
+ } catch {
1044
+ }
1045
+ }
987
1046
  async function readSqliteRowsWithBuiltin(dbPath, query) {
988
1047
  try {
989
1048
  return await withSuppressedSqliteWarning(async () => {
990
1049
  const sqliteModuleId = "node:sqlite";
991
1050
  const sqlite = await import(sqliteModuleId);
992
- const locations = [
993
- dbPath,
994
- `${pathToFileURL(dbPath).href}?mode=ro&immutable=1`
995
- ];
1051
+ const immutableLocation = `${pathToFileURL(dbPath).href}?mode=ro&immutable=1`;
1052
+ const locations = [dbPath, immutableLocation];
996
1053
  let lastError = null;
997
1054
  for (const location of locations) {
998
1055
  let db = null;
999
1056
  try {
1000
1057
  db = new sqlite.DatabaseSync(location);
1001
- return db.prepare(query).all();
1058
+ const rows = db.prepare(query).all();
1059
+ if (location === immutableLocation) {
1060
+ warnWhenWalSkipped(dbPath);
1061
+ }
1062
+ return rows;
1002
1063
  } catch (err) {
1003
1064
  lastError = err;
1004
1065
  const error = err;
@@ -2420,6 +2481,9 @@ function getPathLeaf6(value) {
2420
2481
  const leaf = normalized.split("/").filter(Boolean).pop();
2421
2482
  return leaf || "unknown";
2422
2483
  }
2484
+ function isModelPlaceholder(value) {
2485
+ return !value || /^__[^_]+(?:_[^_]+)*__$/.test(value);
2486
+ }
2423
2487
  function findWireFiles(baseDir) {
2424
2488
  const results = [];
2425
2489
  if (!existsSync14(baseDir)) return results;
@@ -2534,6 +2598,12 @@ var KimiCodeParser = class {
2534
2598
  } catch {
2535
2599
  continue;
2536
2600
  }
2601
+ if (obj.type === "llm.request" || obj.type === "model.bind") {
2602
+ if (obj.model && !isModelPlaceholder(obj.model)) {
2603
+ currentModel = obj.model;
2604
+ }
2605
+ continue;
2606
+ }
2537
2607
  if (obj.type === "usage.record") {
2538
2608
  const timestampValue2 = obj.time;
2539
2609
  const timestamp2 = timestampValue2 ? new Date(timestampValue2) : null;
@@ -2557,10 +2627,11 @@ var KimiCodeParser = class {
2557
2627
  timestamp: timestamp2,
2558
2628
  role: "assistant"
2559
2629
  });
2630
+ const model = obj.model && !isModelPlaceholder(obj.model) ? obj.model : currentModel;
2560
2631
  entries.push({
2561
2632
  sessionId,
2562
2633
  source: TOOL_ID9,
2563
- model: obj.model || currentModel,
2634
+ model,
2564
2635
  project,
2565
2636
  timestamp: timestamp2,
2566
2637
  inputTokens: inputTokens2,
@@ -3331,7 +3402,7 @@ var QwenPawParser = class {
3331
3402
  registerParser(new QwenPawParser());
3332
3403
 
3333
3404
  // src/parsers/cline.ts
3334
- import { readFileSync as readFileSync6, statSync } from "fs";
3405
+ import { readFileSync as readFileSync6, statSync as statSync2 } from "fs";
3335
3406
  import { homedir as homedir18 } from "os";
3336
3407
  import { basename as basename7, join as join19 } from "path";
3337
3408
  var EXTENSION_ID = "saoudrizwan.claude-dev";
@@ -3368,7 +3439,7 @@ function findClineExtensionDirs() {
3368
3439
  for (const root of getHostRoots()) {
3369
3440
  const ext = join19(root, "User", "globalStorage", EXTENSION_ID);
3370
3441
  try {
3371
- if (statSync(ext).isDirectory()) dirs.push(ext);
3442
+ if (statSync2(ext).isDirectory()) dirs.push(ext);
3372
3443
  } catch {
3373
3444
  }
3374
3445
  }
@@ -3485,7 +3556,7 @@ import {
3485
3556
  readdirSync as readdirSync10,
3486
3557
  readFileSync as readFileSync7,
3487
3558
  rmSync,
3488
- statSync as statSync2
3559
+ statSync as statSync3
3489
3560
  } from "fs";
3490
3561
  import { homedir as homedir19, tmpdir } from "os";
3491
3562
  import { join as join20, resolve } from "path";
@@ -3566,7 +3637,7 @@ function readJsonl(jsonlPath) {
3566
3637
  if (lines.length === 0) return [];
3567
3638
  let mtime;
3568
3639
  try {
3569
- mtime = statSync2(jsonlPath).mtime;
3640
+ mtime = statSync3(jsonlPath).mtime;
3570
3641
  } catch {
3571
3642
  mtime = /* @__PURE__ */ new Date();
3572
3643
  }
@@ -3711,7 +3782,7 @@ var KiroParser = class {
3711
3782
  registerParser(new KiroParser());
3712
3783
 
3713
3784
  // src/parsers/roo-code.ts
3714
- import { readdirSync as readdirSync11, readFileSync as readFileSync8, statSync as statSync3 } from "fs";
3785
+ import { readdirSync as readdirSync11, readFileSync as readFileSync8, statSync as statSync4 } from "fs";
3715
3786
  import { homedir as homedir20 } from "os";
3716
3787
  import { basename as basename8, join as join21 } from "path";
3717
3788
  var EXTENSION_ID2 = "rooveterinaryinc.roo-cline";
@@ -3748,7 +3819,7 @@ function findExtensionDirs() {
3748
3819
  for (const root of getHostRoots2()) {
3749
3820
  const ext = join21(root, "User", "globalStorage", EXTENSION_ID2);
3750
3821
  try {
3751
- if (statSync3(ext).isDirectory()) dirs.push(ext);
3822
+ if (statSync4(ext).isDirectory()) dirs.push(ext);
3752
3823
  } catch {
3753
3824
  }
3754
3825
  }
@@ -5718,51 +5789,6 @@ async function promptSelect(options) {
5718
5789
  });
5719
5790
  }
5720
5791
 
5721
- // src/utils/logger.ts
5722
- var LOG_LEVELS = {
5723
- debug: 0,
5724
- info: 1,
5725
- warn: 2,
5726
- error: 3
5727
- };
5728
- var Logger = class {
5729
- level;
5730
- constructor(level = "info") {
5731
- this.level = level;
5732
- }
5733
- setLevel(level) {
5734
- this.level = level;
5735
- }
5736
- debug(msg) {
5737
- if (LOG_LEVELS[this.level] <= LOG_LEVELS.debug) {
5738
- process.stderr.write(`[debug] ${msg}
5739
- `);
5740
- }
5741
- }
5742
- info(msg) {
5743
- if (LOG_LEVELS[this.level] <= LOG_LEVELS.info) {
5744
- process.stdout.write(`${msg}
5745
- `);
5746
- }
5747
- }
5748
- warn(msg) {
5749
- if (LOG_LEVELS[this.level] <= LOG_LEVELS.warn) {
5750
- process.stderr.write(`warn: ${msg}
5751
- `);
5752
- }
5753
- }
5754
- error(msg) {
5755
- if (LOG_LEVELS[this.level] <= LOG_LEVELS.error) {
5756
- process.stderr.write(`error: ${msg}
5757
- `);
5758
- }
5759
- }
5760
- log(msg) {
5761
- this.info(msg);
5762
- }
5763
- };
5764
- var logger = new Logger();
5765
-
5766
5792
  // src/commands/config.ts
5767
5793
  var VALID_KEYS = ["apiKey", "apiUrl", "syncInterval", "logLevel"];
5768
5794
  function isConfigKey(value) {