tokenusage-cli 0.5.4 → 0.6.0
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 +52 -0
- package/README.md +7 -6
- package/package.json +1 -1
- package/src/cli.js +44 -5
- package/src/commands/device-login.js +16 -17
- package/src/commands/diagnostics.js +16 -16
- package/src/commands/doctor.js +14 -11
- package/src/commands/pause.js +34 -3
- package/src/commands/project-profiles.js +97 -0
- package/src/commands/sessions.js +18 -30
- package/src/commands/status.js +22 -16
- package/src/commands/sync.js +117 -3614
- package/src/commands/uninstall.js +10 -9
- package/src/commands/upload.js +18 -12
- package/src/lib/ark-agent-plan-limits.js +4 -13
- package/src/lib/ark-coding-plan-limits.js +4 -13
- package/src/lib/cli-flags.js +109 -0
- package/src/lib/commandcode-limits.js +11 -38
- package/src/lib/doctor.js +91 -1
- package/src/lib/fs.js +10 -0
- package/src/lib/grok-limits.js +5 -18
- package/src/lib/limits-core.js +64 -0
- package/src/lib/qoder-limits.js +4 -13
- package/src/lib/queue-backup.js +24 -0
- package/src/lib/queue-drain.js +388 -0
- package/src/lib/usage-limits.js +22 -29
- package/src/lib/workbuddy-ipc.js +191 -0
- package/src/lib/workbuddy-limits.js +656 -0
- package/src/lib/zcode-limits.js +5 -18
- package/src/repairs/claude.js +442 -0
- package/src/repairs/codebuddy.js +246 -0
- package/src/repairs/codex.js +1023 -0
- package/src/repairs/droid.js +266 -0
- package/src/repairs/grok.js +352 -0
- package/src/repairs/legacy-migrations.js +135 -0
- package/src/repairs/mimo.js +161 -0
- package/src/repairs/workbuddy.js +209 -0
- package/src/repairs/zcode.js +647 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,58 @@
|
|
|
6
6
|
> 0.4.x 之前的条目为压缩摘要;细节与当时的验收记录见 `docs/cli-release.md`
|
|
7
7
|
> 与 `docs/archive/`。
|
|
8
8
|
|
|
9
|
+
## 0.6.0
|
|
10
|
+
|
|
11
|
+
2026-11-15。来源覆盖面的补齐 + 采集可诊断性。零契约变更(`docs/cli-contract.md` 未动),
|
|
12
|
+
服务端无需同步升级;对账基线(`queue.jsonl` last-wins)与队列文件格式不变。
|
|
13
|
+
|
|
14
|
+
- **`doctor` 新增 `sources.coverage`**:按 30 天窗口列出每个来源的最新小时桶、桶数与 token
|
|
15
|
+
数,并把超过 7 天没有新行的源单列为 `silent`;只有整条队列都超过 7 天才降为 warn——闲置
|
|
16
|
+
工具正常停写,与解析器坏掉外观一致,必须由人判断。此前回答「这个来源到底采到没有」只能
|
|
17
|
+
临时扫队列。
|
|
18
|
+
- **WorkBuddy 限额接入 `status --limits`**(`workbuddy` / `workbuddyAi` 两个键):国内版与
|
|
19
|
+
AI 国际版各走自己桌面端的本地计费代理(wbipc),互不借用对方的 socket;订阅窗口取自配额
|
|
20
|
+
汇总,奖励 credits 不算配额窗口;provider 预算耗尽时 abort 会拆掉 IPC socket。plan 标签
|
|
21
|
+
原样透传(`Ultimate` / `Advanced` / `STANDARD` / `Free`),共享的 Title-Case 归一化会把
|
|
22
|
+
`Free` 吞掉,因此与 grok / commandCode 同路跳过。
|
|
23
|
+
- **prime-agent 进入源注册表**:解析器早已存在但 id 没注册,`--source prime-agent` 直接报未知
|
|
24
|
+
id,auto / background 同步也整源跳过,只有不带筛选的手动 `sync` 才采得到。同时补
|
|
25
|
+
`astudio → acode` 别名——CLI 里集成叫 AStudio,`acode` 只是采集器 id。
|
|
26
|
+
- **修复 `sync --source <id>` 实际未限制扫描**:手动单源同步此前只校验了 id,随后仍然遍历全部来源
|
|
27
|
+
(`--json` 里恒定 ~32,000 parsed files、固定 ~1.8s 底噪);真正的源筛选只对带 `--auto` 的 hook/
|
|
28
|
+
重试生效。现在 `--source` 也收窄扫描范围(本机实测 `--source kiro` / `--source zed` 从 31,785 个
|
|
29
|
+
文件 / 1.8s 降到 0 个 / 0.4s),且单源运行不再跑跨源修复——这些修复会用解析到的文件集重建
|
|
30
|
+
队列行,只喂一个来源可能把其它来源的桶当成过期数据。全量 `sync` 行为不变。
|
|
31
|
+
- **`sync --timing`**:打印扫描 / 上传 / 会话三段的耗时,长会话机器的慢环节不再靠猜。
|
|
32
|
+
- **旗标解析收敛为声明式 spec**:未知旗标统一走 `UsageError`(退出码 2),`--json` 下错误
|
|
33
|
+
面与成功面同构;`project-profiles` 的请求补超时,避免桌面端调用挂死。
|
|
34
|
+
- **内部重构(无行为变化)**:八套 limits 的重复原语收敛到 `lib/limits-core`;队列抽排与
|
|
35
|
+
批次读取、Codex / Grok / Zcode / Mimo / Droid / legacy 修复族各自拆成独立模块;`fs` 调用
|
|
36
|
+
统一到 promises 版。
|
|
37
|
+
|
|
38
|
+
升级说明:无需任何动作,随下次计划任务自动生效。想让运行时副本也拿到本版,跑一次
|
|
39
|
+
`tokenusage init --yes --no-integrations --no-open`,随后 `tokenusage doctor` 应全 OK。
|
|
40
|
+
|
|
41
|
+
## 0.5.5
|
|
42
|
+
|
|
43
|
+
2026-11-11。新增只读子命令 `tokenusage project-profiles`(契约 §2.13),供桌面端伴生工具
|
|
44
|
+
读取 web 上编辑的项目显示名 / logo / 仓库。零破坏性变更:现有子命令行为、对账基线与队列
|
|
45
|
+
格式均不变,服务端只需部署含该 series 的版本(否则 CLI 报 `Unknown account series`,
|
|
46
|
+
桌面端静默降级)。
|
|
47
|
+
|
|
48
|
+
- **新增 `tokenusage project-profiles`**:不带参数,凭证解析与 `sync` 同一条路径(运行时
|
|
49
|
+
配置 → `cloud-device-token` 文件,自定义 base 需配 anon key),把账号的项目档案以**单行
|
|
50
|
+
JSON** 打到 stdout(`{"profiles":[{project_key, display_name, repo_url, repo_source,
|
|
51
|
+
detected_repo_url, manual_repo_url, repo_hidden, logo_url, logo_upload_url}]}`)。诊断信息
|
|
52
|
+
一律走 stderr + `UsageError`(退出码 2),stdout 始终保持可解析。
|
|
53
|
+
- **桌面端消费方式**:桌面经 `run_cli` 捕获该行并解析,挂载时与每 5 分钟刷新一次,用于把
|
|
54
|
+
项目列表 / 项目详情的显示名、logo、仓库链接对齐 web;未配对、HTTP 失败或旧 CLI 均静默
|
|
55
|
+
降级为队列 key + 字母方块,界面不空。
|
|
56
|
+
|
|
57
|
+
升级说明:装完即生效(无迁移动作)。Volta 托管的机器升级要跑 `volta install
|
|
58
|
+
tokenusage-cli@0.5.5`(`npm i -g` 只更新 image-dir 副本,`volta run` 仍解析 packages
|
|
59
|
+
副本,见 `docs/cli-release.md` §十三/§十四)。
|
|
60
|
+
|
|
9
61
|
## 0.5.4
|
|
10
62
|
|
|
11
63
|
2026-11-09。tracker 目录写入被拒时的可诊断性与降级。零契约变更,服务端无需同步升级;对账
|
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ tokenusage sync --drain # 首次/积压补传(更大的批处理预算)
|
|
|
67
67
|
| `--dry-run` | 只预览不落盘 |
|
|
68
68
|
| `--no-open` | 不自动打开浏览器 |
|
|
69
69
|
|
|
70
|
-
已移除:`--email` / `--password` / `--device-name` / `--link-code` / `--no-auth
|
|
70
|
+
已移除:`--email` / `--password` / `--device-name` / `--link-code` / `--no-auth`(配对只走 `device-login`)。
|
|
71
71
|
</details>
|
|
72
72
|
|
|
73
73
|
<details>
|
|
@@ -87,6 +87,7 @@ tokenusage sync --drain # 首次/积压补传(更大的批处理预算)
|
|
|
87
87
|
| `--wait-for-lock` | 遇并发 sync 等待而不是跳过 |
|
|
88
88
|
| `--background` / `--lightweight` | 精简扫描档 |
|
|
89
89
|
| `--repair-grok` | 从会话快照重建 Grok 行 |
|
|
90
|
+
| `--timing` | 在交互式汇总里打印分阶段耗时(扫描 / 上传 / 会话) |
|
|
90
91
|
|
|
91
92
|
可用 `--source` id 见 `tokenusage sync --help` 的来源清单。
|
|
92
93
|
</details>
|
|
@@ -100,9 +101,9 @@ tokenusage sync --drain # 首次/积压补传(更大的批处理预算)
|
|
|
100
101
|
| `reconcile` | `--days <n>`(默认 7,上限 366)、`--from` / `--to`(UTC 日历日,裸日期含当天整天)、`--limit <n>`(1–2000)、`--json` |
|
|
101
102
|
| `status` | `--diagnostics`(含路径 / 光标 / WSL·Kiro 探针)、`--json`、`--light`(无 ANSI 的 ASCII 表)、`--limits`(各家配额面板,会读本机凭据并访问厂商 API)、`--no-spinner`、`--probe-keychain` / `--probe-keychain-details`(macOS) |
|
|
102
103
|
| `doctor` | `--json`、`--out <file>`、`--base-url <url>` |
|
|
103
|
-
| `diagnostics` | `--out <file
|
|
104
|
+
| `diagnostics` | `--out <file>`、`--compact` / `--pretty`(单行 / 缩进 JSON,默认缩进) |
|
|
104
105
|
| `sessions` | `--from` / `--to`、`--format json\|csv`(或 `--csv`)、`--out <file>`(原子写,0600)、`--refresh`、`--no-git` |
|
|
105
|
-
| `device-login` | `--json`、`--base-url <url>` |
|
|
106
|
+
| `device-login` | `--json`、`--base-url <url>`、`--dashboard-url <url>`、`--anon-key <key>` / `--anon-key-file <path>` |
|
|
106
107
|
</details>
|
|
107
108
|
|
|
108
109
|
### 只补传积压、不重扫本地日志
|
|
@@ -200,7 +201,7 @@ CLI 未配对也能正常用,只是**降级为“只采集、不上报”**:
|
|
|
200
201
|
|
|
201
202
|
**永不上传**:prompt / 助手正文 / 工具参数 / 命令输出 / diff / 会话标题 / 本地绝对路径 / resume 命令。测试(`test/session-upload.test.js`)用字段白名单锁定该边界。
|
|
202
203
|
|
|
203
|
-
CLI 不发送匿名安装心跳,也不做任何第三方错误上报:上游的 `tokenusage-telemetry`
|
|
204
|
+
CLI 不发送匿名安装心跳,也不做任何第三方错误上报:上游的 `tokenusage-telemetry` 端点与 Sentry SDK 均已移除。除你自己配对的实例外,CLI 不向任何第三方发送数据。
|
|
204
205
|
|
|
205
206
|
## 数据目录
|
|
206
207
|
|
|
@@ -217,9 +218,9 @@ CLI 不发送匿名安装心跳,也不做任何第三方错误上报:上游
|
|
|
217
218
|
| `tracker/upload.throttle.json` | 上传节流状态 |
|
|
218
219
|
| `tracker/logs/sync.log` | 自动采集滚动日志(JSONL) |
|
|
219
220
|
|
|
220
|
-
暂停标志另存。与旧版
|
|
221
|
+
暂停标志另存。与旧版 CLI 的 `~/.tokentracker/` 互不干扰,两套 CLI 可在同一台机器共存。
|
|
221
222
|
|
|
222
|
-
##
|
|
223
|
+
## 自包含运行时副本
|
|
223
224
|
|
|
224
225
|
init 会把当前 CLI 及其依赖闭包复制到 `~/.tokenusage/tracker/app`,并写入
|
|
225
226
|
`.runtime-ready`(版本 + 安装时间)。计划任务 / notify / hook 优先启动已安装包;
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -21,6 +21,7 @@ const { cmdDoctor } = require("./commands/doctor");
|
|
|
21
21
|
const { cmdUninstall } = require("./commands/uninstall");
|
|
22
22
|
const { cmdDeviceLogin } = require("./commands/device-login");
|
|
23
23
|
const { cmdSessions } = require("./commands/sessions");
|
|
24
|
+
const { cmdProjectProfiles } = require("./commands/project-profiles");
|
|
24
25
|
const { cmdPause, cmdResume } = require("./commands/pause");
|
|
25
26
|
|
|
26
27
|
const DEFAULT_WATCH_INTERVAL_MS = 15 * 60_000;
|
|
@@ -89,6 +90,7 @@ const COMMANDS = [
|
|
|
89
90
|
" --drain Upload the whole backlog (higher batch ceiling)",
|
|
90
91
|
" --no-sessions Skip the session metadata upload (hourly buckets only)",
|
|
91
92
|
" --publish-account Publish account-level sources (cursor / trae-cn) locally",
|
|
93
|
+
" --timing Print per-phase durations (scan / upload / sessions)",
|
|
92
94
|
" --all-local-sources Scan every local source, including background-only ones",
|
|
93
95
|
" --auto Auto flavor (honors pause + cloud-sync preference)",
|
|
94
96
|
" --from-notify|--from-openclaw|--from-retry|--from-scheduled",
|
|
@@ -143,14 +145,28 @@ const COMMANDS = [
|
|
|
143
145
|
{
|
|
144
146
|
name: "pause",
|
|
145
147
|
summary: "Stop automatic collection (manual sync still works)",
|
|
146
|
-
run: () => cmdPause(),
|
|
147
|
-
usage: [
|
|
148
|
+
run: (argv) => cmdPause(argv),
|
|
149
|
+
usage: [
|
|
150
|
+
"tokenusage pause [options]",
|
|
151
|
+
"",
|
|
152
|
+
"Writes the pause flag and stops the registered auto-sync schedule.",
|
|
153
|
+
"",
|
|
154
|
+
"Options:",
|
|
155
|
+
" --json Machine-readable summary",
|
|
156
|
+
],
|
|
148
157
|
},
|
|
149
158
|
{
|
|
150
159
|
name: "resume",
|
|
151
160
|
summary: "Restart automatic collection",
|
|
152
|
-
run: () => cmdResume(),
|
|
153
|
-
usage: [
|
|
161
|
+
run: (argv) => cmdResume(argv),
|
|
162
|
+
usage: [
|
|
163
|
+
"tokenusage resume [options]",
|
|
164
|
+
"",
|
|
165
|
+
"Clears the pause flag and re-enables the registered auto-sync schedule.",
|
|
166
|
+
"",
|
|
167
|
+
"Options:",
|
|
168
|
+
" --json Machine-readable summary",
|
|
169
|
+
],
|
|
154
170
|
},
|
|
155
171
|
{
|
|
156
172
|
name: "status",
|
|
@@ -173,7 +189,16 @@ const COMMANDS = [
|
|
|
173
189
|
name: "diagnostics",
|
|
174
190
|
summary: "Dump a redacted environment report",
|
|
175
191
|
run: (argv) => cmdDiagnostics(argv),
|
|
176
|
-
usage: [
|
|
192
|
+
usage: [
|
|
193
|
+
"tokenusage diagnostics [options]",
|
|
194
|
+
"",
|
|
195
|
+
"Options:",
|
|
196
|
+
" --out <file> Also write the report to a file",
|
|
197
|
+
" --compact Single-line JSON (default is pretty-printed)",
|
|
198
|
+
" --pretty Pretty-printed JSON (the default)",
|
|
199
|
+
"",
|
|
200
|
+
"Home paths are redacted to `~` before being printed.",
|
|
201
|
+
],
|
|
177
202
|
},
|
|
178
203
|
{
|
|
179
204
|
name: "doctor",
|
|
@@ -204,6 +229,9 @@ const COMMANDS = [
|
|
|
204
229
|
"Options:",
|
|
205
230
|
" --json Machine-readable output",
|
|
206
231
|
" --base-url <url> Backend to pair against",
|
|
232
|
+
" --dashboard-url <url> Browser dashboard the code is approved on",
|
|
233
|
+
" --anon-key <key> Publishable key of your self-hosted instance",
|
|
234
|
+
" --anon-key-file <path> Read the publishable key from a file",
|
|
207
235
|
],
|
|
208
236
|
},
|
|
209
237
|
{
|
|
@@ -223,6 +251,17 @@ const COMMANDS = [
|
|
|
223
251
|
" --no-git Skip git outcome attribution",
|
|
224
252
|
],
|
|
225
253
|
},
|
|
254
|
+
{
|
|
255
|
+
name: "project-profiles",
|
|
256
|
+
summary: "Print the web-edited project profiles (display name, logo, repo)",
|
|
257
|
+
run: (argv) => cmdProjectProfiles(argv),
|
|
258
|
+
usage: [
|
|
259
|
+
"tokenusage project-profiles",
|
|
260
|
+
"",
|
|
261
|
+
"Prints the account's project profiles as a single JSON line (contract",
|
|
262
|
+
"docs/cli-contract.md §2.13). No options.",
|
|
263
|
+
],
|
|
264
|
+
},
|
|
226
265
|
];
|
|
227
266
|
|
|
228
267
|
function findCommand(name) {
|
|
@@ -8,6 +8,7 @@ const { readJson, updateJsonLocked } = require("../lib/fs");
|
|
|
8
8
|
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
9
9
|
const { resolveRuntimeConfig, assertInsforgeRuntime, normalizeInstanceBaseUrl, clearDeviceIdentity, resetInstanceState } = require("../lib/runtime-config");
|
|
10
10
|
const { functionUrlFor, fetchFunctionResponse } = require("../lib/function-url");
|
|
11
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
11
12
|
|
|
12
13
|
const POLL_INTERVAL_MS = 5_000;
|
|
13
14
|
const ABSOLUTE_TIMEOUT_MS = 16 * 60 * 1000; // matches the 15-min server window with a small buffer
|
|
@@ -184,22 +185,20 @@ async function cmdDeviceLogin(argv = [], options = {}) {
|
|
|
184
185
|
throw new Error("device-login timed out without approval");
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
return out;
|
|
188
|
+
const DEVICE_LOGIN_FLAGS = {
|
|
189
|
+
command: "device-login",
|
|
190
|
+
defaults: { json: false, baseUrl: null, anonKey: null, anonKeyFile: null, dashboardUrl: null },
|
|
191
|
+
flags: [
|
|
192
|
+
{ flag: "--json", key: "json" },
|
|
193
|
+
{ flag: "--base-url", key: "baseUrl", kind: "value" },
|
|
194
|
+
{ flag: "--anon-key", key: "anonKey", kind: "value" },
|
|
195
|
+
{ flag: "--anon-key-file", key: "anonKeyFile", kind: "value" },
|
|
196
|
+
{ flag: "--dashboard-url", key: "dashboardUrl", kind: "value" },
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
function parseArgs(argv = []) {
|
|
201
|
+
return parseFlags(argv, DEVICE_LOGIN_FLAGS);
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
module.exports = { cmdDeviceLogin, authorize, pollOnce };
|
|
204
|
+
module.exports = { cmdDeviceLogin, authorize, pollOnce, parseArgs, flagSpec: DEVICE_LOGIN_FLAGS };
|
|
@@ -2,6 +2,7 @@ const path = require("node:path");
|
|
|
2
2
|
|
|
3
3
|
const { writeFileAtomic, chmod600IfPossible } = require("../lib/fs");
|
|
4
4
|
const { collectTrackerDiagnostics } = require("../lib/diagnostics");
|
|
5
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
5
6
|
|
|
6
7
|
async function cmdDiagnostics(argv = []) {
|
|
7
8
|
const opts = parseArgs(argv);
|
|
@@ -18,21 +19,20 @@ async function cmdDiagnostics(argv = []) {
|
|
|
18
19
|
process.stdout.write(json);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return out;
|
|
22
|
+
// `--compact` / `--pretty` were accepted but undocumented; the spec below is
|
|
23
|
+
// the single source `tokenusage diagnostics --help` and the surface test read.
|
|
24
|
+
const DIAGNOSTICS_FLAGS = {
|
|
25
|
+
command: "diagnostics",
|
|
26
|
+
defaults: { out: null, compact: false },
|
|
27
|
+
flags: [
|
|
28
|
+
{ flag: "--out", key: "out", kind: "value" },
|
|
29
|
+
{ flag: "--compact", key: "compact" },
|
|
30
|
+
{ flag: "--pretty", key: "compact", const: false },
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function parseArgs(argv = []) {
|
|
35
|
+
return parseFlags(argv, DIAGNOSTICS_FLAGS);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
module.exports = { cmdDiagnostics };
|
|
38
|
+
module.exports = { cmdDiagnostics, parseArgs, flagSpec: DIAGNOSTICS_FLAGS };
|
package/src/commands/doctor.js
CHANGED
|
@@ -9,6 +9,7 @@ const { resolveDeviceTokenPresence } = require("../lib/cloud-device-token");
|
|
|
9
9
|
const { resolveLocalDeviceIdentity } = require("../lib/device-identity");
|
|
10
10
|
const { buildDoctorReport } = require("../lib/doctor");
|
|
11
11
|
const { inspectAutoSyncSchedule } = require("../lib/scheduled-task");
|
|
12
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
12
13
|
|
|
13
14
|
async function cmdDoctor(argv = []) {
|
|
14
15
|
const opts = parseArgs(argv);
|
|
@@ -88,16 +89,18 @@ async function cmdDoctor(argv = []) {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
const DOCTOR_FLAGS = {
|
|
93
|
+
command: "doctor",
|
|
94
|
+
defaults: { json: false, out: null, baseUrl: null },
|
|
95
|
+
flags: [
|
|
96
|
+
{ flag: "--json", key: "json" },
|
|
97
|
+
{ flag: "--out", key: "out", kind: "value" },
|
|
98
|
+
{ flag: "--base-url", key: "baseUrl", kind: "value" },
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function parseArgs(argv = []) {
|
|
103
|
+
return parseFlags(argv, DOCTOR_FLAGS);
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
function renderHumanReport(report) {
|
|
@@ -125,4 +128,4 @@ function isPlainObject(value) {
|
|
|
125
128
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
module.exports = { cmdDoctor };
|
|
131
|
+
module.exports = { cmdDoctor, parseArgs, flagSpec: DOCTOR_FLAGS };
|
package/src/commands/pause.js
CHANGED
|
@@ -20,14 +20,37 @@ const {
|
|
|
20
20
|
setAutoSyncEnabled,
|
|
21
21
|
formatScheduleToggle,
|
|
22
22
|
} = require("../lib/scheduled-task");
|
|
23
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
// pause/resume used to receive no argv at all, so `tokenusage pause --json`
|
|
26
|
+
// (or any typo) silently paused collection and exited 0 — the one command
|
|
27
|
+
// where a surprise state change is worst. `--json` is the only accepted flag;
|
|
28
|
+
// every other command already offers it for script consumption.
|
|
29
|
+
const PAUSE_FLAGS = {
|
|
30
|
+
command: "pause",
|
|
31
|
+
defaults: { json: false },
|
|
32
|
+
flags: [{ flag: "--json", key: "json" }],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function parseArgs(argv = [], command = "pause") {
|
|
36
|
+
return parseFlags(argv, { ...PAUSE_FLAGS, command });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function cmdPause(argv = []) {
|
|
40
|
+
const opts = parseArgs(argv, "pause");
|
|
25
41
|
const { trackerDir } = await resolveTrackerPaths({ home: os.homedir() });
|
|
26
42
|
const alreadyPaused = isCollectionPaused(trackerDir);
|
|
27
43
|
|
|
28
44
|
await setCollectionPaused(trackerDir, true);
|
|
29
45
|
const schedule = setAutoSyncEnabled(false);
|
|
30
46
|
|
|
47
|
+
if (opts.json) {
|
|
48
|
+
process.stdout.write(
|
|
49
|
+
`${JSON.stringify({ ok: true, paused: true, already_paused: alreadyPaused, schedule })}\n`,
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
31
54
|
process.stdout.write(
|
|
32
55
|
[
|
|
33
56
|
"Collection paused.",
|
|
@@ -42,13 +65,21 @@ async function cmdPause() {
|
|
|
42
65
|
);
|
|
43
66
|
}
|
|
44
67
|
|
|
45
|
-
async function cmdResume() {
|
|
68
|
+
async function cmdResume(argv = []) {
|
|
69
|
+
const opts = parseArgs(argv, "resume");
|
|
46
70
|
const { trackerDir } = await resolveTrackerPaths({ home: os.homedir() });
|
|
47
71
|
const wasPaused = isCollectionPaused(trackerDir);
|
|
48
72
|
|
|
49
73
|
await setCollectionPaused(trackerDir, false);
|
|
50
74
|
const schedule = setAutoSyncEnabled(true);
|
|
51
75
|
|
|
76
|
+
if (opts.json) {
|
|
77
|
+
process.stdout.write(
|
|
78
|
+
`${JSON.stringify({ ok: true, paused: false, was_paused: wasPaused, schedule })}\n`,
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
52
83
|
process.stdout.write(
|
|
53
84
|
[
|
|
54
85
|
"Collection resumed.",
|
|
@@ -62,4 +93,4 @@ async function cmdResume() {
|
|
|
62
93
|
);
|
|
63
94
|
}
|
|
64
95
|
|
|
65
|
-
module.exports = { cmdPause, cmdResume };
|
|
96
|
+
module.exports = { cmdPause, cmdResume, parseArgs, flagSpec: PAUSE_FLAGS };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// `tokenusage project-profiles` — read-only mirror of the web-edited project
|
|
4
|
+
// profiles (docs/cli-contract.md §2.13), for the desktop companion: the
|
|
5
|
+
// desktop never reads the device token file (desktop-plan §3 boundary 1), so
|
|
6
|
+
// the CLI — which already holds the pairing credential — fetches the account
|
|
7
|
+
// payload and prints it as a single JSON line on stdout. Diagnostics travel
|
|
8
|
+
// through UsageError (stderr + exit 2) so stdout stays parseable.
|
|
9
|
+
|
|
10
|
+
const os = require("node:os");
|
|
11
|
+
const path = require("node:path");
|
|
12
|
+
|
|
13
|
+
const { readJson } = require("../lib/fs");
|
|
14
|
+
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
15
|
+
const { normalizeInstanceBaseUrl, resolveRuntimeConfig } = require("../lib/runtime-config");
|
|
16
|
+
const { readCloudDeviceTokenEntry } = require("../lib/cloud-device-token");
|
|
17
|
+
const { functionUrlFor, fetchFunctionResponse } = require("../lib/function-url");
|
|
18
|
+
const { UsageError, unknownOptionError } = require("../lib/cli-errors");
|
|
19
|
+
|
|
20
|
+
// Contract §2.13: the desktop parses this exact payload shape.
|
|
21
|
+
const SLUG = "token-usage-account-project-profiles";
|
|
22
|
+
|
|
23
|
+
function parseArgs(args = []) {
|
|
24
|
+
for (const a of args) throw unknownOptionError(a, "project-profiles");
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Same resolution order as `resolveDeviceTokenPresence`: runtime config
|
|
30
|
+
* (env / config.json) first, then the cloud-device-token file — but this
|
|
31
|
+
* returns the VALUE, which the desktop's `run_cli` capture turns into data.
|
|
32
|
+
* The cloud file is only trusted when its recorded instance matches the
|
|
33
|
+
* configured one (same guard as the presence check).
|
|
34
|
+
*/
|
|
35
|
+
async function resolveCredentials({ home }) {
|
|
36
|
+
const { trackerDir } = await resolveTrackerPaths({ home });
|
|
37
|
+
const config = (await readJson(path.join(trackerDir, "config.json"))) || {};
|
|
38
|
+
const runtime = resolveRuntimeConfig({ config, env: process.env });
|
|
39
|
+
const baseUrl =
|
|
40
|
+
typeof runtime.baseUrl === "string" ? runtime.baseUrl.trim() : "";
|
|
41
|
+
let deviceToken =
|
|
42
|
+
typeof runtime.deviceToken === "string" ? runtime.deviceToken.trim() : "";
|
|
43
|
+
|
|
44
|
+
if (!deviceToken) {
|
|
45
|
+
const entry = readCloudDeviceTokenEntry(
|
|
46
|
+
path.join(trackerDir, "cloud-device-token.json"),
|
|
47
|
+
);
|
|
48
|
+
// The cache entry stores the credential as `token` (bound to userId /
|
|
49
|
+
// baseUrl / machineId), unlike config.json's `deviceToken`.
|
|
50
|
+
const entryToken =
|
|
51
|
+
entry && typeof entry.token === "string" ? entry.token.trim() : "";
|
|
52
|
+
const entryBase = normalizeInstanceBaseUrl(
|
|
53
|
+
(entry && entry.baseUrl) || "",
|
|
54
|
+
);
|
|
55
|
+
const configuredBase = normalizeInstanceBaseUrl(baseUrl);
|
|
56
|
+
|
|
57
|
+
if (entryToken && (!configuredBase || entryBase === configuredBase)) {
|
|
58
|
+
deviceToken = entryToken;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { baseUrl, deviceToken, httpTimeoutMs: runtime.httpTimeoutMs };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function cmdProjectProfiles(argv = [], context = {}) {
|
|
66
|
+
parseArgs(argv);
|
|
67
|
+
const home = context.home || os.homedir();
|
|
68
|
+
const { baseUrl, deviceToken, httpTimeoutMs } = await resolveCredentials({ home });
|
|
69
|
+
|
|
70
|
+
if (!baseUrl || !deviceToken) {
|
|
71
|
+
throw new UsageError("This machine is not paired yet.", {
|
|
72
|
+
code: "NOT_PAIRED",
|
|
73
|
+
hint: "Run `tokenusage device-login` first, then try again.",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const res = await fetchFunctionResponse(functionUrlFor(baseUrl, SLUG), {
|
|
78
|
+
// The desktop blocks on this call: without a timeout a half-open network
|
|
79
|
+
// would hang the panel until the process is killed.
|
|
80
|
+
...(httpTimeoutMs > 0 ? { signal: AbortSignal.timeout(httpTimeoutMs) } : {}),
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: "application/json",
|
|
83
|
+
Authorization: `Bearer ${deviceToken}`,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
const body = (await res.text().catch(() => "")).replace(/\s+/g, " ").slice(0, 200);
|
|
88
|
+
throw new UsageError(`Request failed with HTTP ${res.status}.`, {
|
|
89
|
+
code: "HTTP_ERROR",
|
|
90
|
+
hint: body || "Check your instance URL and try again.",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const payload = await res.json();
|
|
94
|
+
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = { cmdProjectProfiles };
|
package/src/commands/sessions.js
CHANGED
|
@@ -8,41 +8,29 @@
|
|
|
8
8
|
// exporting the wrong shape to the wrong file.
|
|
9
9
|
|
|
10
10
|
const { writeFileAtomic } = require("../lib/fs");
|
|
11
|
-
const { UsageError
|
|
11
|
+
const { UsageError } = require("../lib/cli-errors");
|
|
12
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
12
13
|
const { buildSessionAnalytics, summarizeSessions, sessionsToCsv } = require("../lib/session-analytics");
|
|
13
14
|
const { buildGitOutcomes } = require("../lib/git-outcomes");
|
|
14
15
|
|
|
15
16
|
const FORMATS = new Set(["json", "csv"]);
|
|
16
|
-
|
|
17
|
-
const
|
|
17
|
+
|
|
18
|
+
const SESSIONS_FLAGS = {
|
|
19
|
+
command: "sessions",
|
|
20
|
+
defaults: { format: null, out: null, from: null, to: null, refresh: false, git: true },
|
|
21
|
+
flags: [
|
|
22
|
+
{ flag: "--format", key: "format", kind: "value", parse: (raw) => String(raw).trim().toLowerCase() },
|
|
23
|
+
{ flag: "--out", key: "out", kind: "value" },
|
|
24
|
+
{ flag: "--from", key: "from", kind: "value" },
|
|
25
|
+
{ flag: "--to", key: "to", kind: "value" },
|
|
26
|
+
{ flag: "--csv", key: "format", const: "csv" },
|
|
27
|
+
{ flag: "--refresh", key: "refresh" },
|
|
28
|
+
{ flag: "--no-git", key: "git", const: false },
|
|
29
|
+
],
|
|
30
|
+
};
|
|
18
31
|
|
|
19
32
|
function parseArgs(args = []) {
|
|
20
|
-
const out =
|
|
21
|
-
for (let i = 0; i < args.length; i++) {
|
|
22
|
-
const a = args[i];
|
|
23
|
-
if (VALUE_FLAGS.has(a)) {
|
|
24
|
-
const value = args[i + 1];
|
|
25
|
-
if (value == null || value === "" || value.startsWith("--")) {
|
|
26
|
-
throw new UsageError(`${a} requires a value`, {
|
|
27
|
-
code: "MISSING_VALUE",
|
|
28
|
-
hint: "Run `tokenusage sessions --help` for supported options.",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
i += 1;
|
|
32
|
-
if (a === "--format") out.format = value.trim().toLowerCase();
|
|
33
|
-
else if (a === "--out") out.out = value;
|
|
34
|
-
else if (a === "--from") out.from = value;
|
|
35
|
-
else out.to = value;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (BOOLEAN_FLAGS.has(a)) {
|
|
39
|
-
if (a === "--csv") out.format = "csv";
|
|
40
|
-
else if (a === "--refresh") out.refresh = true;
|
|
41
|
-
else out.git = false;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
throw unknownOptionError(a, "sessions");
|
|
45
|
-
}
|
|
33
|
+
const out = parseFlags(args, SESSIONS_FLAGS);
|
|
46
34
|
if (out.format == null) out.format = "json";
|
|
47
35
|
if (!FORMATS.has(out.format)) {
|
|
48
36
|
throw new UsageError(`Unknown --format: ${out.format}`, {
|
|
@@ -69,4 +57,4 @@ async function cmdSessions(args = []) {
|
|
|
69
57
|
}
|
|
70
58
|
}
|
|
71
59
|
|
|
72
|
-
module.exports = { cmdSessions, parseArgs };
|
|
60
|
+
module.exports = { cmdSessions, parseArgs, flagSpec: SESSIONS_FLAGS };
|
package/src/commands/status.js
CHANGED
|
@@ -6,6 +6,7 @@ const pkg = require("../../package.json");
|
|
|
6
6
|
const { resolveDumateDbPaths } = require("../lib/dumate");
|
|
7
7
|
|
|
8
8
|
const { readJson } = require("../lib/fs");
|
|
9
|
+
const { parseFlags } = require("../lib/cli-flags");
|
|
9
10
|
const { readCursorStateSummary } = require("../lib/cursor-store");
|
|
10
11
|
const {
|
|
11
12
|
readCodexNotify,
|
|
@@ -1640,6 +1641,8 @@ const USAGE_LIMIT_PROVIDERS = [
|
|
|
1640
1641
|
["opencodeGo", "OpenCode Go"],
|
|
1641
1642
|
["commandCode", "CommandCode"],
|
|
1642
1643
|
["devin", "Devin"],
|
|
1644
|
+
["workbuddy", "WorkBuddy"],
|
|
1645
|
+
["workbuddyAi", "WorkBuddy AI"],
|
|
1643
1646
|
["qoder", "Qoder"],
|
|
1644
1647
|
["qoderCn", "Qoder CN"],
|
|
1645
1648
|
["codingPlan", "Ark Coding Plan"],
|
|
@@ -1725,8 +1728,9 @@ function formatUsageLimitRows(limits) {
|
|
|
1725
1728
|
return rows;
|
|
1726
1729
|
}
|
|
1727
1730
|
|
|
1728
|
-
|
|
1729
|
-
|
|
1731
|
+
const STATUS_FLAGS = {
|
|
1732
|
+
command: "status",
|
|
1733
|
+
defaults: {
|
|
1730
1734
|
diagnostics: false,
|
|
1731
1735
|
json: false,
|
|
1732
1736
|
light: false,
|
|
@@ -1734,21 +1738,22 @@ function parseArgs(argv) {
|
|
|
1734
1738
|
noSpinner: false,
|
|
1735
1739
|
probeKeychain: false,
|
|
1736
1740
|
probeKeychainDetails: false,
|
|
1737
|
-
}
|
|
1741
|
+
},
|
|
1742
|
+
flags: [
|
|
1743
|
+
{ flag: "--diagnostics", key: "diagnostics" },
|
|
1744
|
+
{ flag: "--json", key: "json" },
|
|
1745
|
+
{ flag: "--light", key: "light" },
|
|
1746
|
+
{ flag: "--limits", key: "limits" },
|
|
1747
|
+
{ flag: "--no-spinner", key: "noSpinner" },
|
|
1748
|
+
{ flag: "--probe-keychain", key: "probeKeychain" },
|
|
1749
|
+
{ flag: "--probe-keychain-details", key: "probeKeychainDetails" },
|
|
1750
|
+
],
|
|
1751
|
+
};
|
|
1738
1752
|
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
else if (a === "--light") out.light = true;
|
|
1744
|
-
else if (a === "--limits") out.limits = true;
|
|
1745
|
-
else if (a === "--no-spinner") out.noSpinner = true;
|
|
1746
|
-
else if (a === "--probe-keychain") out.probeKeychain = true;
|
|
1747
|
-
else if (a === "--probe-keychain-details") {
|
|
1748
|
-
out.probeKeychainDetails = true;
|
|
1749
|
-
out.probeKeychain = true;
|
|
1750
|
-
} else throw new Error(`Unknown option: ${a}`);
|
|
1751
|
-
}
|
|
1753
|
+
function parseArgs(argv = []) {
|
|
1754
|
+
const out = parseFlags(argv, STATUS_FLAGS);
|
|
1755
|
+
// `--probe-keychain-details` implies the base probe (unchanged behavior).
|
|
1756
|
+
if (out.probeKeychainDetails) out.probeKeychain = true;
|
|
1752
1757
|
|
|
1753
1758
|
return out;
|
|
1754
1759
|
}
|
|
@@ -1900,6 +1905,7 @@ function parseEpochMsToIso(v) {
|
|
|
1900
1905
|
|
|
1901
1906
|
module.exports = {
|
|
1902
1907
|
cmdStatus,
|
|
1908
|
+
flagSpec: STATUS_FLAGS,
|
|
1903
1909
|
formatUsageLimitRows,
|
|
1904
1910
|
parseArgs,
|
|
1905
1911
|
renderLightTable,
|