tokenusage-cli 0.2.2 → 0.2.4

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,70 @@
3
3
  本包(`tokenusage-cli`)的用户可见变更记录。发版时在顶部新增一节,
4
4
  `## <版本号>` 行会被 release workflow 取作 GitHub Release 正文。
5
5
 
6
+ ## 0.2.4
7
+
8
+ 计划任务抗 Node 版本切换 + 自检一次性收口的采集可靠性修复(发 0.2.3 后立即补;
9
+ 家里机实测发现)。
10
+
11
+ - 0.2.3 的隐藏 VBS 把 npm 全局前缀里的包路径写死,而 nvm-windows 的全局前缀
12
+ 按 Node 版本分目录(如 `E:\nvm\nvm\v24.4.1\node_modules\tokenusage-cli`)。
13
+ `nvm use` 之后该路径消失,任务每小时以 "file not found" 失败
14
+ (`LastTaskResult` 非 0、日志停更),而任务本身看起来仍"已注册"。
15
+ - VBS 现在先 `FileExists` 探测包路径,缺失时回落到 init 复制到数据目录的自包含
16
+ 运行时 `~/.tokenusage/tracker/app/bin/tracker.js`,采集不中断。
17
+ - VBS 的引号改用 `Chr(34)` 拼接(不再依赖转义写法),行为不变:wscript 直接起
18
+ node、隐藏窗口、用退出码回填 `LastTaskResult`。
19
+ - 运行时副本改为"依赖闭包"复制:旧实现整目录 `fs.cp`,在 pnpm 安装下只复制到
20
+ junction 链接(副本里 `node_modules` 只有 1 项),副本一跑就是
21
+ `Cannot find module`;现在按依赖图逐个复制真实目录,npm / pnpm 两种布局都能
22
+ 得到自包含副本。
23
+ - 副本先复制到 `app.new` 暂存目录,**实际启动一遍**(`require` 全部直接依赖 +
24
+ `--version`)通过后才替换 `app` 并写 `.runtime-ready` 标记。没有标记的副本
25
+ 一律不使用——半成品副本在忽略输出的后台进程里静默死掉,表现与"采集正常"
26
+ 完全一样,这是最难排查的一类失败。
27
+ - notify / OpenClaw hook / OpenClaw session plugin / sync 自动重试脚本统一按
28
+ "带标记的副本 → 已安装包入口 → npx" 三级选择启动器。
29
+ - `tokenusage doctor` 新增 `runtime.copy` 检查:缺标记、版本落后都会给出
30
+ warn 与重跑 `init` 的建议(升级 CLI 后重跑之前先能看见)。
31
+ - `init` 复制失败不再静默:报告里列一行(stderr 同时提示),并说明会自动回退。
32
+ - `uninstall` 一并清理暂存目录 `app.new`。
33
+ - 后台 spawn 全部加 `windowsHide`(notify 之外的 hook / 自动重试 / 本地 API),
34
+ 避免 GUI 宿主(如 oh-my-pi)每轮闪一个控制台窗口。
35
+ - `sync --watch --interval=<毫秒>` 等号写法不再泄漏进 sync 参数(此前会被当成
36
+ 未知参数导致每一轮失败);低于 1 分钟仍按 15 分钟处理。
37
+ - 仍然建议升级或切换 Node 版本后重跑一次
38
+ `tokenusage init --yes --no-integrations --no-open`:回落副本是上次 init 的
39
+ 快照,重跑才会同步到最新版本。
40
+
41
+ ## 0.2.3
42
+
43
+ 修复 0.2.x 计划任务的两个隐藏缺陷(0.2.2 升级验收时实测发现)。
44
+
45
+ - 计划任务指向错误入口:init 注册的隐藏 VBS 调用的是 `src/cli.js`——那是只
46
+ 导出 `run()` 的库文件、没有命令行入口,任务 0.1 秒内以退出码 0 结束,
47
+ 既不采集也不写日志,`LastTaskResult` 永远是 0(看起来永远成功)。VBS 现
48
+ 固定指向包内 `bin/tokenusage.js`,并有回归测试锁定(禁止再指向 `src/cli.js`)。
49
+ - 定时运行不落日志:`sync --from-scheduled` 只打印到 stdout,隐藏窗口下没有
50
+ 任何 trail,与 0.2.2 发布说明不符。现在所有自动风味运行(scheduled / hook /
51
+ retry / watch)统一追加到滚动日志 `~/.tokenusage/tracker/logs/sync.log`。
52
+ - 已注册过任务的机器:升级后重跑一次
53
+ `tokenusage init --yes --no-integrations --no-open` 即可修正任务入口。
54
+ - 品牌残留:init 启动横幅的 ASCII 与大标题仍是上游的 TOKEN TRACKER,
55
+ local-api 的兜底设备名也写 Token Tracker;按 AGENTS 命名约束统一为
56
+ Token Usage,并加回归测试防回潮。
57
+ - 移除上游遗留的匿名安装心跳(`POST /api/functions/tokenusage-telemetry`):
58
+ 本仓库契约与 Web 端都没有该路由,每次 sync 只会拿到 404 并进退避,还与启动屏
59
+ "只有 token 计数离开本机"的口径冲突。要统计安装量,先补服务端路由再恢复。
60
+ - 修正 local-api 遗留的本地服务 spawn 路径(`bin/tracker.js` 自 fork 起就不
61
+ 存在),并新增发包自检测试:bin 入口存在、spawn 路径可解析、无孤儿端点。
62
+ - `--help` 补齐 `init --no-integrations/--no-task` 与 `sync --interval`。
63
+ - 修正 `sync --watch --interval <ms>` 的非法值处理:README 承诺低于 1 分钟回退
64
+ 15 分钟,但此前参数会漏进 cmdSync,导致每轮以 `Unknown option: --interval`
65
+ 失败;现在该参数始终被剥离,并有单测覆盖。
66
+ - 署名与包元数据收敛:`description` 去掉 fork 字样;`THIRD_PARTY_NOTICES.md`
67
+ 只保留上游 TokenTracker 一节(其余条目是 Web 端资产,本仓库已不存在也不随包);
68
+ README 的来源说明收为一句,指向 `LICENSE` / `THIRD_PARTY_NOTICES.md`。
69
+
6
70
  ## 0.2.2
7
71
 
8
72
  新机初始化修复与采集口径修正。
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # tokenusage-cli
2
2
 
3
- 自托管 AI 编码 token 用量采集器,为 [token-usage](https://github.com/baiwumm/token-usage)(自托管仪表盘)上报数据。fork 自 [TokenTracker](https://github.com/xiufengsun/TokenTracker)(MIT,见 `LICENSE` 与 `THIRD_PARTY_NOTICES.md`),指向 token-usage 契约(`docs/cli-contract.md`)。
3
+ 自托管 AI 编码 token 用量采集器,为 [token-usage](https://github.com/baiwumm/token-usage)(自托管仪表盘)上报数据,指向其契约(`docs/cli-contract.md`)。代码来源与许可见 `LICENSE` 与 `THIRD_PARTY_NOTICES.md`。
4
4
 
5
5
  > 运行要求:Node ≥ 22.19(由上传依赖 undici 8 的引擎下限决定)。
6
6
 
@@ -103,6 +103,8 @@ CLI 未配对也能正常用,只是**降级为“只采集、不上报”**:
103
103
 
104
104
  **永不上传**:prompt / 助手正文 / 工具参数 / 命令输出 / diff / 会话标题 / 本地绝对路径 / resume 命令。测试(`test/session-upload.test.js`)用字段白名单锁定该边界。
105
105
 
106
+ CLI 也不发送匿名安装心跳:上游的 `tokenusage-telemetry` 端点在自托管后端从未实现,0.2.3 起已移除。可选的 Sentry 错误上报必须显式配置 DSN,并受 `TOKENUSAGE_NO_TELEMETRY` / `DO_NOT_TRACK` 约束。
107
+
106
108
  ## 数据目录
107
109
 
108
110
  `~/.tokenusage/`(`0700` 目录 + `0600` 文件):`tracker/config.json`(配对与运行配置)、上传队列(`queue.jsonl` + offset)、会话分析 sidecar、`session-upload-watermarks.json`(增量水位)、`tracker/logs/sync.log`(自动采集滚动日志)、暂停标志。与旧版 tokentracker CLI 的 `~/.tokentracker/` 互不干扰,迁移期两套 CLI 可在同一台机器共存。
@@ -1,6 +1,6 @@
1
1
  # Third-Party Notices
2
2
 
3
- This project includes third-party assets and code. The following notices apply.
3
+ `tokenusage-cli` 以 MIT 发布,许可正文与版权行见本包 [`LICENSE`](./LICENSE)。
4
4
 
5
5
  ## TokenTracker (upstream)
6
6
 
@@ -11,130 +11,6 @@ upstream repository and were then modified for the token-usage contract
11
11
  (`docs/cli-contract.md` in the repository root). The upstream MIT license text
12
12
  and copyright notice are preserved in this package's `LICENSE` file.
13
13
 
14
- ## RunCat menu bar cat frames
15
-
16
- The running-cat animation frames used by the macOS menu bar icon
17
- (`TokenTrackerBar/TokenTrackerBar/Assets.xcassets/RunnerCat0…4.imageset`)
18
- are from [menubar_runcat](https://github.com/Kyome22/menubar_runcat)
19
- by Takuto Nakamura (Kyome22).
20
-
21
- Copyright © 2019 Takuto Nakamura
22
-
23
- Licensed under the Apache License, Version 2.0 (the "License");
24
- you may not use these files except in compliance with the License.
25
- You may obtain a copy of the License at
26
-
27
- http://www.apache.org/licenses/LICENSE-2.0
28
-
29
- Unless required by applicable law or agreed to in writing, software
30
- distributed under the License is distributed on an "AS IS" BASIS,
31
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- See the License for the specific language governing permissions and
33
- limitations under the License.
34
-
35
- ## Bot companion morphing engine
36
-
37
- The vector morphing engine behind the `bot` pet character and its menu bar icon
38
- (`dashboard/src/lib/bot/`, and the frame data generated from it by
39
- `scripts/gen-bot-frames.cjs`) is from [bloub](https://github.com/jeremy-prt/bloub)
40
- by Jérémy Perret, vendored unmodified at commit
41
- [`b4bb3c1b5f93`](https://github.com/jeremy-prt/bloub/tree/b4bb3c1b5f93c7b87a2e8d620f667c4093d97749).
42
-
43
- Note when re-vendoring: `dashboard/src/lib/bot/README.md` is ours, not upstream's, and
44
- `decor.ts` / `skins.ts` are listed in `scripts/ops/ui-hardcode-baseline.json`, so a
45
- refresh needs that file re-copied and the baseline regenerated.
46
-
47
- Copyright © 2026 Jérémy Perret
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining a copy
50
- of this software and associated documentation files (the "Software"), to deal
51
- in the Software without restriction, including without limitation the rights
52
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- copies of the Software, and to permit persons to whom the Software is
54
- furnished to do so, subject to the following conditions:
55
-
56
- The above copyright notice and this permission notice shall be included in all
57
- copies or substantial portions of the Software.
58
-
59
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- SOFTWARE.
66
-
67
- ## Devin brand mark
68
-
69
- `dashboard/public/brand-logos/devin.svg` is a monochrome vector trace of the
70
- official Devin "nodes" mark published by Cognition at
71
- `https://app.devin.ai/assets/pwa/apple-touch-icon.png` (also
72
- `https://app.devin.ai/assets/pwa/pwa-icon-192.png`). The Devin name and logo
73
- are trademarks of Cognition; the mark is bundled solely to identify the Devin
74
- CLI source and subscription quota in the dashboard, recoloured to `currentColor` like the
75
- other provider marks.
76
-
77
- ## Hairline line figures
78
-
79
- The Cloud plan page uses [Hairline](https://github.com/lucasmarkes/hairline) v0.5.0 by Lucas Marques.
80
-
81
- MIT License
82
-
83
- Copyright (c) 2026 Lucas Marques
84
-
85
- Permission is hereby granted, free of charge, to any person obtaining a copy
86
- of this software and associated documentation files (the "Software"), to deal
87
- in the Software without restriction, including without limitation the rights
88
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89
- copies of the Software, and to permit persons to whom the Software is
90
- furnished to do so, subject to the following conditions:
91
-
92
- The above copyright notice and this permission notice shall be included in all
93
- copies or substantial portions of the Software.
94
-
95
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
96
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
97
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
98
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
99
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
100
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
101
- SOFTWARE.
102
-
103
- ## React Bits ElectricLogo
104
-
105
- The dark Cloud plan artwork adapts the user-provided React Bits ElectricLogo by David Haz.
106
- Source: https://reactbits.dev/animations/electric-logo
107
- Vendored integration: dashboard/vendor/react-bits/.
108
-
109
- MIT + Commons Clause License Condition v1.0
110
-
111
- Copyright (c) 2026 David Haz
112
-
113
- Permission is hereby granted, free of charge, to any person obtaining a copy
114
- of this software and associated documentation files (the "Software"), to deal
115
- in the Software without restriction, including without limitation the rights
116
- to use, copy, modify, merge, publish, and distribute the Software **as part of an application, website, or product**, subject to the following conditions:
117
-
118
- The above copyright notice and this permission notice shall be included in all
119
- copies or substantial portions of the Software.
120
-
121
- ## Commons Clause Restriction
122
-
123
- You may use this Software, including for any commercial purpose, **so long as you do not sell, sublicense, or redistribute the components themselves-whether alone, in a bundle, or as a ported version.**
124
-
125
- ## No Warranty
126
-
127
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
128
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
129
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
130
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
131
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
132
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
133
- SOFTWARE.
134
-
135
-
136
- ## OGL
137
-
138
- The ElectricLogo renderer uses OGL 1.0.11 by Nathan Gordon.
139
- Source: https://github.com/oframe/ogl
140
- License: Unlicense (public domain dedication), as declared in the OGL package metadata.
14
+ 本包不含其他第三方资产:运行时依赖(`undici`、`@sentry/node` 等)的许可随
15
+ `node_modules` 一同分发;品牌图标、字体与定价快照属于 Web 端,登记在仓库根目录的
16
+ `THIRD_PARTY_NOTICES.md`。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokenusage-cli",
3
- "version": "0.2.2",
4
- "description": "Self-hosted AI coding token usage collector for token-usage (forked from TokenTracker, MIT).",
3
+ "version": "0.2.4",
4
+ "description": "Self-hosted AI coding token usage collector for the Token Usage dashboard.",
5
5
  "keywords": [
6
6
  "token-usage",
7
7
  "token",
package/src/cli.js CHANGED
@@ -79,22 +79,35 @@ async function run(argv) {
79
79
  }
80
80
  }
81
81
 
82
+ // Split `--interval <ms>` (or `--interval=<ms>`) off the sync args. Values
83
+ // below the 1-minute floor (or a missing value) fall back to 15 min, but the
84
+ // flag must ALWAYS be removed: leaving it behind made cmdSync reject every
85
+ // pass with "Unknown option: --interval" instead of the documented fallback.
86
+ function resolveWatchInterval(rest) {
87
+ const args = rest.filter((arg) => arg !== "--watch");
88
+ let intervalMs = 15 * 60_000;
89
+ let value;
90
+ const spacedIndex = args.indexOf("--interval");
91
+ const equalsIndex = args.findIndex((arg) => arg.startsWith("--interval="));
92
+ if (spacedIndex >= 0) {
93
+ value = args[spacedIndex + 1];
94
+ args.splice(spacedIndex, 2);
95
+ } else if (equalsIndex >= 0) {
96
+ value = args[equalsIndex].slice("--interval=".length);
97
+ args.splice(equalsIndex, 1);
98
+ }
99
+ const parsed = Number(value);
100
+ if (Number.isFinite(parsed) && parsed >= 60_000) intervalMs = parsed;
101
+ return { args, intervalMs };
102
+ }
103
+
82
104
  // --watch: keep the process alive and re-run sync on an interval. Each pass
83
105
  // reuses the session-analytics sidecar cache and the upload watermarks, so a
84
106
  // pass with nothing new is cheap (a directory signature stat + a no-op).
85
107
  // The trigger tag rides context into cmdSync so run telemetry can report
86
108
  // `watch` runs distinctly from scheduled/manual/notify ones (§2.11).
87
109
  async function watchSync(rest) {
88
- const args = rest.filter((arg) => arg !== "--watch");
89
- const intervalIndex = args.indexOf("--interval");
90
- let intervalMs = 15 * 60_000;
91
- if (intervalIndex >= 0) {
92
- const value = Number(args[intervalIndex + 1]);
93
- if (Number.isFinite(value) && value >= 60_000) {
94
- intervalMs = value;
95
- args.splice(intervalIndex, 2);
96
- }
97
- }
110
+ const { args, intervalMs } = resolveWatchInterval(rest);
98
111
 
99
112
  process.stdout.write(`tokenusage sync --watch: every ${Math.round(intervalMs / 60_000)} min (Ctrl+C to stop)\n`);
100
113
  for (;;) {
@@ -118,7 +131,8 @@ function printHelp() {
118
131
  "Usage:",
119
132
  " tokenusage -v, --version Show version info",
120
133
  " tokenusage [--debug] init [--yes] [--dry-run] [--no-open] [--link-code <code>] [--run-report=on|off]",
121
- " tokenusage [--debug] sync [--auto] [--drain] [--no-sessions] [--watch]",
134
+ " [--no-integrations] [--no-task]",
135
+ " tokenusage [--debug] sync [--auto] [--drain] [--no-sessions] [--watch] [--interval <ms>]",
122
136
  " tokenusage [--debug] status [--probe-keychain] [--probe-keychain-details]",
123
137
  " tokenusage [--debug] pause | resume",
124
138
  " tokenusage [--debug] diagnostics [--out diagnostics.json]",
@@ -143,4 +157,4 @@ function printHelp() {
143
157
  );
144
158
  }
145
159
 
146
- module.exports = { run };
160
+ module.exports = { run, resolveWatchInterval };