@aiusage/cli 1.7.3 → 1.7.5

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/README.md CHANGED
@@ -3,18 +3,38 @@
3
3
  `@aiusage/cli` is the AIUsage command-line tool for:
4
4
 
5
5
  - discovering and managing projects across AI tools
6
- - scanning local Claude Code, Codex, Cursor, Copilot CLI, Copilot for VS Code, Gemini CLI, Antigravity, Amp, Kimi Code, Qwen Code, Droid, OpenCode, and Pi usage
6
+ - scanning local Claude Code, Codex, Cursor, Copilot CLI, Copilot for VS Code, Gemini CLI, Antigravity, Amp, Kimi Code, Qwen Code, Droid, OpenCode, Pi, and Trae usage
7
7
  - importing historical usage from Anthropic Admin API
8
8
  - printing local usage summaries for the last 7 days, 30 days, 90 days, or all history
9
9
  - scheduling automatic sync to an AIUsage Worker
10
10
  - diagnosing configuration and connectivity issues
11
11
 
12
- Kimi scanning supports both legacy Kimi CLI data in `~/.kimi/sessions/` and
13
- new Kimi Code data in `$KIMI_CODE_HOME/sessions/` (default:
14
- `~/.kimi-code/sessions/`). It reads only token counters and session metadata
15
- from `wire.jsonl`; conversation content is not uploaded. The new wire-format
16
- parser references the MIT-licensed [tokscale](https://github.com/junhoyeo/tokscale)
17
- implementation.
12
+ The local scanners have been compatibility-audited against the overlapping
13
+ parsers in the MIT-licensed [tokscale](https://github.com/junhoyeo/tokscale)
14
+ project. AIUsage keeps tool-specific safeguards where the source semantics
15
+ differ, rather than treating every local record as billable token usage.
16
+
17
+ ## Local scanner coverage
18
+
19
+ | Tool | Sources and compatibility behavior |
20
+ |------|------------------------------------|
21
+ | Claude Code | `~/.config/claude/projects/` and `~/.claude/projects/` JSONL; deduplicates parent/sidechain replays, merges streaming snapshots per token field, and honors wrapper providers. Aggregate `stats-cache.json` is intentionally not converted into guessed per-message usage. |
22
+ | Codex CLI | Active and archived `~/.codex` sessions; fork-aware replay boundaries, inherited baselines, `last_token_usage`, and total-delta fallback. |
23
+ | Cursor | Reads the local `state.vscdb` credential and requests Cursor's token-strategy usage CSV; the database is snapshotted when locked. |
24
+ | Copilot CLI | OpenTelemetry JSONL under `~/.copilot/otel/` plus `session-state` shutdown totals; granular inference spans supersede same-trace aggregates. |
25
+ | Copilot for VS Code | Chat logs, legacy session JSON, and modern CRDT `workspaceStorage/**/chatSessions/*.jsonl`; modern sessions contribute real token fields, while legacy records remain interaction-only. |
26
+ | Gemini CLI | Session JSON/JSONL, headless stats, and `$set.messages` updates under `~/.gemini/tmp/`, with last-write-wins request deduplication. |
27
+ | Antigravity | `~/.gemini/antigravity/brain` and browser-recording metadata; currently reports interaction counts because those artifacts do not expose reliable token counters. |
28
+ | Amp | `~/.local/share/amp/threads/`; reconciles the usage ledger with message usage so partial ledgers are completed without double-counting. |
29
+ | Kimi CLI / Kimi Code | Legacy `~/.kimi/sessions/` and `$KIMI_CODE_HOME/sessions/` (default `~/.kimi-code/sessions/`) `wire.jsonl`; handles progressive status snapshots and nested agent sessions. |
30
+ | Qwen Code | Current `~/.qwen/projects/` and legacy `~/.qwen/tmp/` chat JSONL, with session/position deduplication and cache-aware input accounting. |
31
+ | Droid | `~/.factory/sessions/*.settings.json`; uses persisted token totals first and the transcript only as a model fallback. |
32
+ | OpenCode | OpenCode 1.2+ `opencode.db` through read-only `sqlite3`, plus legacy `storage/message/*.json`. |
33
+ | Pi / Oh My Pi | `~/.pi/agent/sessions/` and `~/.omp/agent/sessions/` JSONL, including provider, cache-write, and session metadata. |
34
+ | Trae / Trae CN | `aiusage trae sync` reads Trae CN history through Trae's official local `ai-agent` RPC and writes a privacy-minimized cache under `~/.aiusage/trae-cache/sessions/`. The scanner also accepts international Trae caches produced by `tokscale trae sync` under `~/.config/tokscale/trae-cache/sessions/`. The encrypted SQLCipher database is never opened directly. |
35
+
36
+ Only token counters and session metadata are aggregated or uploaded. Conversation
37
+ content and local credentials are never uploaded.
18
38
 
19
39
  ## Install
20
40
 
@@ -48,7 +68,7 @@ aiusage project alias # list all configured aliases
48
68
  aiusage project alias --remove myapp # remove alias
49
69
  ```
50
70
 
51
- Scans data directories for all supported tools, including Kimi Code session metadata, listing discovered projects with their aliases and sources.
71
+ Scans data directories for all supported tools, including Kimi Code session metadata and the Trae CN sync cache, listing discovered projects with their aliases and sources.
52
72
 
53
73
  Project aliases are applied locally before upload. If two devices set the same alias for their respective project directories, the server merges them into one project.
54
74
 
@@ -71,6 +91,19 @@ Reads data from local tool data directories including `~/.claude/projects` (Clau
71
91
 
72
92
  **Compact mode** (default) shows Sources and Daily tables with merged Cache column and 2-decimal cost. **Detail mode** (`--detail`) expands all columns (CacheRead, CacheWrite, Reasoning), adds Top Models and Pricing Notes sections, and shows 4-decimal cost.
73
93
 
94
+ ### trae sync
95
+
96
+ Sync Trae CN's local historical token counters before running a regular report or dashboard upload:
97
+
98
+ ```bash
99
+ aiusage trae sync
100
+ aiusage report --range all
101
+ ```
102
+
103
+ If Trae CN is closed, AIUsage temporarily launches it with a local-only debugging port, reads the official `ai-agent` session API, then closes the temporary instance. If Trae is already running without that port, quit Trae and rerun the command. Use `--port 9230 --no-launch` to connect to an instance you started yourself.
104
+
105
+ Only session identifiers, workspace paths, timestamps, model labels, and numeric token counters are cached. Conversation content and login credentials are neither cached nor uploaded. International Trae users can run `tokscale trae sync`; AIUsage reads that compatible cache automatically.
106
+
74
107
  ### Shared date options
75
108
 
76
109
  `scan`, `report`, and `sync` use the same date options:
package/README.zh-CN.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `@aiusage/cli` 是 AIUsage 命令行工具,用于:
4
4
 
5
5
  - 发现和管理本机 AI 工具项目
6
- - 扫描本地 AI 编程工具的 Token 用量(Claude Code、Codex、Cursor、Copilot CLI、Copilot VS Code、Gemini CLI、Antigravity、Amp、Kimi Code、Qwen Code、Droid、OpenCode、Pi)
6
+ - 扫描本地 AI 编程工具的 Token 用量(Claude Code、Codex、Cursor、Copilot CLI、Copilot VS Code、Gemini CLI、Antigravity、Amp、Kimi Code、Qwen Code、Droid、OpenCode、Pi、Trae)
7
7
  - 通过 Anthropic Admin API 导入历史用量
8
8
  - 生成本地用量报告(最近 7 天、30 天、90 天或全部历史)
9
9
  - 定时自动同步数据到 AIUsage Worker
@@ -14,6 +14,10 @@ Kimi 同时支持旧版 Kimi CLI 的 `~/.kimi/sessions/` 与新版 Kimi Code 的
14
14
  `wire.jsonl` 中的 Token 计数与会话元数据,不上传对话正文;新版格式参考了
15
15
  [tokscale](https://github.com/junhoyeo/tokscale) 的 MIT 开源实现。
16
16
 
17
+ Trae CN 通过 `aiusage trae sync` 调用 Trae 自己的本地 `ai-agent` 接口读取历史
18
+ Token 计数,缓存到 `~/.aiusage/trae-cache/sessions/`;不会直接破解加密数据库。
19
+ 国际版 Trae 也兼容 `tokscale trae sync` 生成的缓存。
20
+
17
21
  ## 安装
18
22
 
19
23
  ```bash
@@ -67,6 +71,22 @@ aiusage report --json # JSON 输出
67
71
 
68
72
  **紧凑模式**(默认)显示来源和每日汇总表,合并缓存列,保留 2 位小数成本。**详细模式**(`--detail`)展开所有列(CacheRead、CacheWrite、Reasoning),增加热门模型和定价说明,显示 4 位小数成本。
69
73
 
74
+ ### trae sync
75
+
76
+ 先同步 Trae CN 的本地历史用量,再运行常规报告或看板上传:
77
+
78
+ ```bash
79
+ aiusage trae sync
80
+ aiusage report --range all
81
+ ```
82
+
83
+ 如果 Trae CN 未运行,AIUsage 会用仅限本机的调试端口临时启动它,读取官方
84
+ `ai-agent` 会话接口,完成后自动退出。如果 Trae 已经在运行但没有开启该端口,
85
+ 请先退出 Trae 再重试。也可以通过 `--port 9230 --no-launch` 连接自行启动的实例。
86
+
87
+ 缓存只包含会话标识、项目路径、时间、模型名和 Token 数字,不包含对话正文或登录凭据。
88
+ 国际版用户可先执行 `tokscale trae sync`,AIUsage 会自动读取兼容缓存。
89
+
70
90
  ### 统一日期参数
71
91
 
72
92
  `scan`、`report`、`sync` 使用同一套日期参数: