tokentracker-cli 0.5.14 → 0.5.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokentracker-cli",
3
- "version": "0.5.14",
3
+ "version": "0.5.19",
4
4
  "description": "Token usage tracker for AI agent CLIs (Claude Code, Codex, Cursor, Kiro, Gemini, OpenCode, OpenClaw)",
5
5
  "main": "src/cli.js",
6
6
  "bin": {
@@ -21,9 +21,6 @@
21
21
  "access": "public"
22
22
  },
23
23
  "scripts": {
24
- "architecture:canvas": "node scripts/ops/architecture-canvas.cjs",
25
- "architecture:canvas:focus": "node scripts/ops/architecture-canvas.cjs --focus",
26
- "architecture:canvas:list-modules": "node scripts/ops/architecture-canvas.cjs --list-modules",
27
24
  "ci:local": "npm test && npm run validate:copy && npm run validate:ui-hardcode && npm run validate:guardrails && node --test test/architecture-guardrails.test.js && npm --prefix dashboard run build",
28
25
  "copy:pull": "node scripts/copy-sync.cjs pull",
29
26
  "copy:push": "node scripts/copy-sync.cjs push",
@@ -45,7 +45,7 @@ function extractCursorSessionToken({ home } = {}) {
45
45
  try {
46
46
  jwt = cp
47
47
  .execSync(
48
- `sqlite3 -readonly "${stateDbPath}" "SELECT value FROM ItemTable WHERE key = 'cursorAuth/accessToken';"`,
48
+ `sqlite3 "${stateDbPath}" "SELECT value FROM ItemTable WHERE key = 'cursorAuth/accessToken';"`,
49
49
  { encoding: "utf8", timeout: 5000, stdio: ["pipe", "pipe", "pipe"] },
50
50
  )
51
51
  .trim();
@@ -91,6 +91,7 @@ function getModelPricing(model) {
91
91
  if (lower.includes("gemini-2.5")) return MODEL_PRICING["gemini-2.5-pro"];
92
92
  if (lower.includes("kimi")) return MODEL_PRICING["kimi-k2.5"];
93
93
  if (lower.includes("composer")) return MODEL_PRICING["composer-1"];
94
+ if (lower === "auto") return MODEL_PRICING["composer-1"];
94
95
  return ZERO_PRICING;
95
96
  }
96
97
 
@@ -459,18 +460,73 @@ function createLocalApiHandler({ queuePath }) {
459
460
 
460
461
  // Server-side cookie relay: captures auth cookies from InsForge cloud responses
461
462
  // so that both browser and WKWebView share the same login session via the proxy.
462
- const relayCookies = new Map();
463
+ // Persisted to disk so cookies survive server restarts.
464
+ let relayCookies = new Map();
465
+ const trackerDataDir = path.join(os.homedir(), ".tokentracker", "tracker");
466
+ const cookiePath = path.join(trackerDataDir, "relay-cookies.json");
467
+
468
+ // Load persisted cookies on startup
469
+ try {
470
+ if (!fs.existsSync(trackerDataDir)) fs.mkdirSync(trackerDataDir, { recursive: true });
471
+ if (fs.existsSync(cookiePath)) {
472
+ const content = fs.readFileSync(cookiePath, "utf8");
473
+ const saved = JSON.parse(content);
474
+ if (saved && typeof saved === "object") {
475
+ let count = 0;
476
+ for (const [k, v] of Object.entries(saved)) {
477
+ relayCookies.set(k, v);
478
+ count++;
479
+ }
480
+ if (count > 0) console.log(`[LocalAPI] Loaded ${count} relay cookies from ${cookiePath}`);
481
+ }
482
+ }
483
+ } catch (e) {
484
+ console.error("[LocalAPI] Failed to load relay cookies:", e.message);
485
+ }
486
+
487
+ function persistRelayCookies() {
488
+ try {
489
+ // Sticky semantics: never replace an existing on-disk session with an empty cookie map.
490
+ if (relayCookies.size === 0) return;
491
+
492
+ const json = JSON.stringify(Object.fromEntries(relayCookies));
493
+ fs.writeFileSync(cookiePath, json, { encoding: "utf8", mode: 0o600 });
494
+ } catch (e) {
495
+ console.error("[LocalAPI] Failed to persist relay cookies:", e.message);
496
+ }
497
+ }
463
498
 
464
499
  function captureSetCookies(headerValue) {
465
500
  if (!headerValue) return;
466
501
  const parts = headerValue.split(/,(?=\s*\w+=)/);
502
+ let changed = false;
467
503
  for (const raw of parts) {
468
504
  const eqIdx = raw.indexOf("=");
469
505
  if (eqIdx < 1) continue;
470
506
  const name = raw.substring(0, eqIdx).trim();
471
507
  if (!name) continue;
472
- relayCookies.set(name, raw.trim());
508
+
509
+ // Basic sticky logic: if it's a deletion cookie (Max-Age=0 or past date),
510
+ // we only remove it if we have it.
511
+ const lower = raw.toLowerCase();
512
+ const isDeletion = lower.includes("max-age=0") || lower.includes("expires=thu, 01 jan 1970");
513
+
514
+ if (isDeletion) {
515
+ if (relayCookies.has(name)) {
516
+ relayCookies.delete(name);
517
+ changed = true;
518
+ console.log(`[LocalAPI] Cookie deleted: ${name}`);
519
+ }
520
+ } else {
521
+ const oldVal = relayCookies.get(name);
522
+ if (oldVal !== raw.trim()) {
523
+ relayCookies.set(name, raw.trim());
524
+ changed = true;
525
+ console.log(`[LocalAPI] Cookie captured: ${name}`);
526
+ }
527
+ }
473
528
  }
529
+ if (changed) persistRelayCookies();
474
530
  }
475
531
 
476
532
  function buildRelayCookieHeader(clientCookieHeader) {