tokenusage-cli 0.5.2 → 0.5.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/CHANGELOG.md CHANGED
@@ -6,6 +6,25 @@
6
6
  > 0.4.x 之前的条目为压缩摘要;细节与当时的验收记录见 `docs/cli-release.md`
7
7
  > 与 `docs/archive/`。
8
8
 
9
+ ## 0.5.3
10
+
11
+ 2026-11-09。同步锁稳健性 + 上游命令名残留清理。零契约变更,服务端无需同步升级;对账基线
12
+ (`queue.jsonl` last-wins)与队列文件格式不变。
13
+
14
+ - **sync.lock 瞬时创建被拒不再裸崩**:Windows 上过滤驱动或上一轮释放的收尾窗口,会让锁文件
15
+ 名的创建偶发返回 `EPERM`(或共享冲突的 `EBUSY`)——此前只把「名字已存在」(`EEXIST`)当作
16
+ 被占用,其余错误码直接抛出,桌面端「立即同步」会以一行裸 errno 中断。现在这两个错误码先
17
+ 做一轮短重试(3 × 150 ms,多数瞬时态自愈),仍未拿到锁则归入既有的「锁不可得」语义:写
18
+ `sync.skip.json` 标记(`lock_busy` + 可读 detail)、正常退出,采集不被打断,持久性损坏也
19
+ 保持可观测。活锁持有者仍然只走 `EEXIST` 路径,行为不变。
20
+ - **上游 `tracker` 命令名残留清理**:`device-login` 的配对码过期提示此前让用户 re-run
21
+ `tracker device-login`,而本 fork 的二进制叫 `tokenusage`——照着敲会得到「命令不存在」;
22
+ 源码内同类残留(注释里的 `tracker sync` / `tracker status` 等)一并改正,branding 守卫
23
+ 测试锁死回潮。
24
+
25
+ 升级说明:无需任何动作,随下次计划任务自动生效;修复对桌面端「立即同步」立竿见影
26
+ (下一版桌面端随附的 CLI 同理)。
27
+
9
28
  ## 0.5.2
10
29
 
11
30
  2026-11-08。上传队列防线:彻底消除「毒批/超大批次导致队头永久卡死」类故障。零契约变更,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenusage-cli",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Self-hosted AI coding token usage collector for the Token Usage dashboard.",
5
5
  "keywords": [
6
6
  "token-usage",
@@ -174,7 +174,7 @@ async function cmdDeviceLogin(argv = [], options = {}) {
174
174
  return;
175
175
  }
176
176
  if (result.status === "expired") {
177
- throw new Error("device_code expired — re-run `tracker device-login`");
177
+ throw new Error("device_code expired — re-run `tokenusage device-login`");
178
178
  }
179
179
  if (result.status === "unknown") {
180
180
  throw new Error("device_code is unknown — server may have evicted it");
@@ -1233,7 +1233,7 @@ async function applyIntegrationSetup({
1233
1233
  }
1234
1234
 
1235
1235
  // CodeBuddy: Claude-Code fork. Install the SessionEnd hook so finished
1236
- // sessions trigger notify.cjs → tracker sync; passive scan still runs as a
1236
+ // sessions trigger notify.cjs → tokenusage sync; passive scan still runs as a
1237
1237
  // safety net for sessions that don't fire SessionEnd cleanly.
1238
1238
  const codebuddyDirExists = want("codebuddy") && await isDir(context.codebuddyDir);
1239
1239
  if (!want("codebuddy")) {
@@ -1249,7 +1249,7 @@ async function applyIntegrationSetup({
1249
1249
  }
1250
1250
 
1251
1251
  // WorkBuddy: sibling Claude-Code fork. Same SessionEnd hook → notify.cjs →
1252
- // tracker sync; passive scan still runs as a safety net.
1252
+ // tokenusage sync; passive scan still runs as a safety net.
1253
1253
  const workbuddyDirExists = want("workbuddy") && await isDir(context.workbuddyDir);
1254
1254
  if (!want("workbuddy")) {
1255
1255
  summary.push(notSelectedItem("workbuddy"));
@@ -162,7 +162,7 @@ async function collectTrackerDiagnostics({
162
162
  const kiroCliDbPath = resolveKiroCliDbPathInline(process.env, home);
163
163
  const kiroCliPresent = require("node:fs").existsSync(kiroCliDbPath);
164
164
 
165
- // WSL installs (win32 only) — surfaced so `tracker doctor --json` can
165
+ // WSL installs (win32 only) — surfaced so `tokenusage doctor --json` can
166
166
  // confirm dual-install discovery without running a sync.
167
167
  let kiroWslInstalls = null;
168
168
  let claudeWslProjects = null;
package/src/lib/fs.js CHANGED
@@ -72,6 +72,16 @@ const MAX_RECLAIM_DEPTH = 4;
72
72
  const MAX_RECLAIM_SWEEP_DEPTH = 64;
73
73
  const TRANSITION_GUARD_RETRY_MS = 5;
74
74
  const TRANSITION_GUARD_ATTEMPTS = 1000;
75
+ // Windows: creating the lock NAME itself can transiently fail with
76
+ // ERROR_ACCESS_DENIED (Node reports EPERM; sharing-mode conflicts surface as
77
+ // EBUSY) while a filter driver settles or the previous lease's release
78
+ // completes. A live holder can never produce these codes — an existing name
79
+ // always collides as EEXIST first. Retry briefly, then fall through to the
80
+ // held semantics so a real constant failure stays visible via sync.skip.json
81
+ // instead of crashing every run with a raw errno (issue #431's lesson: lock
82
+ // trouble must be survivable and queryable, not loud).
83
+ const LOCK_TRANSIENT_OPEN_RETRIES = 3;
84
+ const LOCK_TRANSIENT_OPEN_RETRY_MS = 150;
75
85
 
76
86
  function parseLockOwner(raw) {
77
87
  try {
@@ -290,6 +300,7 @@ async function openLock(
290
300
  reclaimDepth = 0,
291
301
  serializeRelease = true,
292
302
  sweptReclaimGuards = false,
303
+ retryTransient = true,
293
304
  } = {},
294
305
  ) {
295
306
  try {
@@ -409,6 +420,38 @@ async function openLock(
409
420
  }
410
421
  return null;
411
422
  }
423
+ if (e && (e.code === "EPERM" || e.code === "EBUSY") && retryTransient) {
424
+ // Transient create-denial on the lock name (see LOCK_TRANSIENT_OPEN_*
425
+ // above): retry briefly, then the held semantics. Nothing about a live
426
+ // holder reaches this branch — EEXIST owns that path.
427
+ for (let attempt = 0; attempt < LOCK_TRANSIENT_OPEN_RETRIES; attempt += 1) {
428
+ await new Promise((resolve) =>
429
+ setTimeout(resolve, LOCK_TRANSIENT_OPEN_RETRY_MS),
430
+ );
431
+ try {
432
+ return await openLock(lockPath, {
433
+ quietIfLocked,
434
+ beforeReclaim,
435
+ beforeReleaseUnlink,
436
+ reclaimDepth,
437
+ serializeRelease,
438
+ sweptReclaimGuards,
439
+ retryTransient: false,
440
+ });
441
+ } catch (retryError) {
442
+ if (
443
+ !retryError ||
444
+ (retryError.code !== "EPERM" && retryError.code !== "EBUSY")
445
+ ) {
446
+ throw retryError;
447
+ }
448
+ }
449
+ }
450
+ if (!quietIfLocked) {
451
+ process.stdout.write("Another sync is already running.\n");
452
+ }
453
+ return null;
454
+ }
412
455
  throw e;
413
456
  }
414
457
  }
@@ -12,13 +12,13 @@
12
12
  * session logs (`~/.claude/projects/`, `~/.gemini/sessions/`, etc.). Our
13
13
  * parsers can read those logs directly without the hook; the only loss is
14
14
  * "data is fresh within seconds" → it's now "data is fresh after the next
15
- * scheduled `tracker sync`".
15
+ * scheduled `tokenusage sync`".
16
16
  *
17
17
  * This module surfaces that fact: for each hook-driven provider, decide
18
18
  * whether the local install is in **passive mode** (no hook + log dir
19
- * present). `tracker status` reports it, and the dashboard can show a
19
+ * present). `tokenusage status` reports it, and the dashboard can show a
20
20
  * single banner asking the user whether to acknowledge & continue in
21
- * passive mode or attempt re-install (`tracker init`).
21
+ * passive mode or attempt re-install (`tokenusage init`).
22
22
  *
23
23
  * Detection is purely best-effort — we never *fail* sync because hooks are
24
24
  * missing; we just label the source so users / AI agents know latency is
@@ -250,6 +250,18 @@
250
250
  "cache_read": 0.06,
251
251
  "note": "InclusionAI Ant Ling 3.1 Flash (released 2026-09-29). Novita USD list via models.dev: $0.30/$0.90 per MTok input/output, $0.06 cache read; no published cache-write rate (retrieved 2026-11-08). Queue rows report the bare id; LiteLLM only carries ling-3.0 variants under provider-qualified keys."
252
252
  },
253
+ "ling-3.2-flash": {
254
+ "input": 0.3,
255
+ "output": 0.9,
256
+ "cache_read": 0.06,
257
+ "note": "InclusionAI Ant Ling 3.2 Flash (multimodal MoE, released 2026-11). Launch rates reported at parity with Ling 3.1 Flash ($0.30/$0.90 per MTok); the API is free on some channels during the launch window and no official pricing page has been located yet (retrieved 2026-11-08), so this entry is provisional — revisit against the official rate card. Spotted unpriced by `tokenusage doctor` pricing.coverage (dsh rows, ~20M tokens / 7d). Cache read mirrors the 3.1 pin pending a published cache-hit rate."
258
+ },
259
+ "Ling-3.2-flash": {
260
+ "input": 0.3,
261
+ "output": 0.9,
262
+ "cache_read": 0.06,
263
+ "note": "Same SKU and rates as ling-3.2-flash; the capitalized spelling is what the dsh collector actually reports (exact matching is case-sensitive, and the dot-restored form ling-3.2.flash cannot hit the dash key). Mirrors the MiniMax-M2.7-highspeed/minimax-m3 dual-registration precedent."
264
+ },
253
265
  "deepseek-v4-flash": {
254
266
  "input": 0.44,
255
267
  "output": 1.32,