tokenusage-cli 0.4.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
3
3
  本包(`tokenusage-cli`)的用户可见变更记录。发版时在顶部新增一节,
4
4
  `## <版本号>` 行会被 release workflow 取作 GitHub Release 正文。
5
5
 
6
+ ## 0.4.2
7
+
8
+ 2026-11-01。`init` 的调度摘要不再只写 `degraded: xml_rejected`:现在把被拒的第一行原因
9
+ (如 `ERROR: Access is denied.`,超过 100 字符截断)一并打印,用户能据此判断是「需要
10
+ 管理员权限」还是「任务定义本身有问题」。
11
+
12
+ - Windows:非提升 shell 下 `schtasks /Create /XML` 必然 `Access is denied`,降级路径照旧
13
+ 每小时采集(隐藏窗口);要启用 catch-up / retry / 无执行时限,需以管理员身份重跑
14
+ `tokenusage init`。
15
+ - 单测覆盖:原因可见、超长命令输出截断(`test/scheduled-task.test.js`)。
16
+
17
+ ## 0.4.1
18
+
19
+ 2026-11-01。修复 `tokenusage reconcile` 在真实队列上的误报:队列行写的是
20
+ `conversation_count`(`docs/cli-contract.md` §2.4 的线名),小时表列名是
21
+ `conversations`,按字段名直接比较会把每一行都报成 `conversations local 0 → cloud N`
22
+ (本机首跑 41/43 行误报)。现在按别名归一后比较,真实差异仍照常报出。
23
+
24
+ - 会话数比较读 `conversations`,缺失时回退 `conversation_count`(两者都没有按 0)。
25
+ - 单测按真实队列形态(只带 `conversation_count`)覆盖,并断言真差异仍落在 `conversations` 字段。
26
+
6
27
  ## 0.4.0
7
28
 
8
29
  2026-11-01。错误提示更友好(一行 `Error:` + `Hint:` 且不再刷堆栈),帮助信息改为
package/README.md CHANGED
@@ -8,7 +8,8 @@
8
8
 
9
9
  ```bash
10
10
  # 1) 初始化:扫描根配置、各工具用量 hook、并注册每小时自动采集的计划任务
11
- # (Windows 经 VBS 隐藏窗口运行,不弹黑框;--no-task 可跳过任务注册)
11
+ # (Windows 经 VBS 隐藏窗口运行,不弹黑框;--no-task 可跳过任务注册。增强任务定义
12
+ # 需要管理员权限,非提升 shell 下会自动降级为普通每小时触发并提示 degraded)
12
13
  tokenusage init
13
14
 
14
15
  # 2) 配对:输出一个 user_code,浏览器打开提示的链接批准
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenusage-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Self-hosted AI coding token usage collector for the Token Usage dashboard.",
5
5
  "keywords": [
6
6
  "token-usage",
@@ -296,12 +296,23 @@ function round6(value) {
296
296
 
297
297
  const COMPARED_COLUMNS = [...TOKEN_COLUMNS, "billable_total_tokens", "conversations", "credits"];
298
298
 
299
+ // Queue rows use the `conversation_count` wire alias (§2.4) while the hourly
300
+ // table stores `conversations`; read either name so a row that only carries the
301
+ // legacy one is not compared as 0.
302
+ function columnValue(row, column) {
303
+ if (column === "conversations" && row?.conversations === undefined) {
304
+ return row?.conversation_count;
305
+ }
306
+ return row?.[column];
307
+ }
308
+
299
309
  function describeRow(row) {
300
310
  const out = {};
301
311
  for (const column of COMPARED_COLUMNS) {
302
- if (column === "billable_total_tokens" && row?.[column] == null) out[column] = null;
303
- else if (column === "credits") out[column] = round6(Number(row?.[column] ?? 0));
304
- else out[column] = Number(row?.[column] ?? 0);
312
+ const value = columnValue(row, column);
313
+ if (column === "billable_total_tokens" && value == null) out[column] = null;
314
+ else if (column === "credits") out[column] = round6(Number(value ?? 0));
315
+ else out[column] = Number(value ?? 0);
305
316
  }
306
317
  return out;
307
318
  }
@@ -320,7 +331,7 @@ function compareBuckets({ local, server }) {
320
331
  continue;
321
332
  }
322
333
  const fields = COMPARED_COLUMNS.filter((column) =>
323
- valuesDiffer(localRow?.[column], serverRow?.[column], column),
334
+ valuesDiffer(columnValue(localRow, column), serverRow?.[column], column),
324
335
  );
325
336
  if (fields.length > 0) {
326
337
  mismatches.push({
@@ -637,12 +637,28 @@ function deleteAutoSyncSchedule({ home = os.homedir(), binDir, platform = proces
637
637
  }
638
638
 
639
639
  // One place for the init summary copy so Windows/macOS/Linux cannot drift.
640
+ //
641
+ // Degraded registrations carry the raw rejection in `detail`. On a normal
642
+ // (non-elevated) Windows install `schtasks /Create /XML` always fails with
643
+ // "Access is denied", so showing that first line lets the user tell "re-run as
644
+ // administrator" apart from a genuinely malformed definition. Clip it to one
645
+ // short line so the summary table stays readable.
646
+ function scheduleDetailLine(value, max = 100) {
647
+ const line =
648
+ String(value ?? "")
649
+ .split(/\r?\n/)
650
+ .map((part) => part.trim())
651
+ .find(Boolean) ?? "";
652
+ return line.length > max ? `${line.slice(0, max - 1)}…` : line;
653
+ }
654
+
640
655
  function formatScheduleRegistration(outcome) {
641
656
  if (!outcome) return "not registered";
642
657
  if (outcome.registered) {
643
658
  const when = "hourly, hidden window";
644
659
  if (outcome.degraded) {
645
- return `${outcome.label}: ${when} (degraded: ${outcome.reason}; no catch-up/retry settings)`;
660
+ const why = scheduleDetailLine(outcome.detail);
661
+ return `${outcome.label}: ${when} (degraded: ${outcome.reason}${why ? ` — ${why}` : ""}; no catch-up/retry settings)`;
646
662
  }
647
663
  return `${outcome.label}: ${when} (pause/resume toggles it)`;
648
664
  }