@aiusage/cli 1.7.4 → 1.7.6

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,9 +3,9 @@
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
- - printing local usage summaries for the last 7 days, 30 days, 90 days, or all history
8
+ - printing local usage summaries for the last 7, 30, 90, or 180 days, or all history
9
9
  - scheduling automatic sync to an AIUsage Worker
10
10
  - diagnosing configuration and connectivity issues
11
11
 
@@ -31,6 +31,8 @@ differ, rather than treating every local record as billable token usage.
31
31
  | Droid | `~/.factory/sessions/*.settings.json`; uses persisted token totals first and the transcript only as a model fallback. |
32
32
  | OpenCode | OpenCode 1.2+ `opencode.db` through read-only `sqlite3`, plus legacy `storage/message/*.json`. |
33
33
  | Pi / Oh My Pi | `~/.pi/agent/sessions/` and `~/.omp/agent/sessions/` JSONL, including provider, cache-write, and session metadata. |
34
+ | Trae CN | `aiusage trae sync --edition cn` reads local history through Trae's official `ai-agent` RPC and writes a privacy-minimized cache under `~/.aiusage/trae-cache/sessions/`. The encrypted SQLCipher database is never opened directly. |
35
+ | Trae / Trae Solo (international) | `aiusage trae sync --edition intl` reads the older plain-JSON or decrypts the newer desktop credential format, then queries Trae's official account usage API once; IDE and Solo share the same account-level data. Numeric session data is cached under `~/.aiusage/trae-cache/intl/sessions/`. Existing tokscale caches under `~/.config/tokscale/trae-cache/sessions/` remain compatible and are deduplicated by session. |
34
36
 
35
37
  Only token counters and session metadata are aggregated or uploaded. Conversation
36
38
  content and local credentials are never uploaded.
@@ -67,7 +69,7 @@ aiusage project alias # list all configured aliases
67
69
  aiusage project alias --remove myapp # remove alias
68
70
  ```
69
71
 
70
- Scans data directories for all supported tools, including Kimi Code session metadata, listing discovered projects with their aliases and sources.
72
+ 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.
71
73
 
72
74
  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.
73
75
 
@@ -79,7 +81,11 @@ Local usage report. No cloud upload required.
79
81
  aiusage report # default: last 7 days + today, English, compact
80
82
  aiusage report --range 1m # last 30 days
81
83
  aiusage report --range 3m # last 90 days
84
+ aiusage report --range 6m # last 180 days
82
85
  aiusage report --range all # all history
86
+ aiusage report --tool trae-cn --range all # Trae CN only
87
+ aiusage report --tool trae-intl --range 6m # international only
88
+ aiusage report --tool trae --range all # both editions
83
89
  aiusage report --detail # show all columns, top models, pricing notes
84
90
  aiusage report --lang zh # Chinese output
85
91
  aiusage report --no-emoji # disable emoji in title
@@ -90,6 +96,26 @@ Reads data from local tool data directories including `~/.claude/projects` (Clau
90
96
 
91
97
  **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.
92
98
 
99
+ ### trae sync
100
+
101
+ Sync either Trae edition before running a regular report or dashboard upload:
102
+
103
+ ```bash
104
+ aiusage trae sync --edition cn
105
+ aiusage trae sync --edition intl --since 180
106
+ aiusage trae sync --edition all --since 180
107
+
108
+ aiusage report --tool trae-cn --range all
109
+ aiusage report --tool trae-intl --range 6m
110
+ aiusage report --tool trae --range all
111
+ ```
112
+
113
+ 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.
114
+
115
+ Trae IDE and Trae Solo share account-level international usage, so AIUsage stops after the first working credential and does not double-count the account. It reads or decrypts `storage.json` locally and stores credentials with `0600` permissions under `~/.aiusage/trae-cache/intl/credentials-{ide,solo}.json`; credentials and conversation content are never uploaded. The numeric API cache is written to `~/.aiusage/trae-cache/intl/sessions/usage.json`. Existing tokscale session caches are still read, with the newest snapshot retained per session.
116
+
117
+ Use `--tool trae-cn` or `--tool trae-intl` to isolate one edition. `--tool trae` is the stable combined alias and includes compatible legacy rows. Regular `sync` deliberately rejects `--tool` because it uploads authoritative full-day snapshots.
118
+
93
119
  ### Shared date options
94
120
 
95
121
  `scan`, `report`, and `sync` use the same date options:
@@ -98,11 +124,12 @@ Reads data from local tool data directories including `~/.claude/projects` (Clau
98
124
  aiusage scan --today # today only
99
125
  aiusage report --date 2026-03-31 # specific date
100
126
  aiusage sync --range 1m # last 30 days
127
+ aiusage report --range 6m # last 180 days
101
128
  aiusage sync --lookback 14 # last 14 days + today
102
129
  aiusage scan --from 2025-01-01 --to 2026-04-05
103
130
  ```
104
131
 
105
- Use `--range 1m`, not `range -1m`. `report` also supports `--range all`; `scan` and `sync` require explicit `--from/--to` for large historical ranges.
132
+ Use `--range 1m`, not `range -1m`. `scan`, `report`, and `sync` support `--range 6m`; `report` also supports `--range all`. Use explicit `--from/--to` for larger scan or sync ranges.
106
133
 
107
134
  ### scan
108
135
 
@@ -112,6 +139,7 @@ Scan local usage and print detailed breakdowns.
112
139
  aiusage scan # yesterday
113
140
  aiusage scan --date 2026-03-31 # specific date
114
141
  aiusage scan --range 1m # last 30 days
142
+ aiusage scan --tool trae-cn --range 6m # Trae CN only, last 180 days
115
143
  aiusage scan --date 2026-03-31 --json # JSON output
116
144
  ```
117
145
 
package/README.zh-CN.md CHANGED
@@ -3,9 +3,9 @@
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
- - 生成本地用量报告(最近 7 天、30 天、90 天或全部历史)
8
+ - 生成本地用量报告(最近 7 天、30 天、90 天、180 天或全部历史)
9
9
  - 定时自动同步数据到 AIUsage Worker
10
10
  - 诊断配置与连接问题
11
11
 
@@ -14,6 +14,12 @@ 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 --edition cn` 调用 Trae 自己的本地 `ai-agent`
18
+ 接口读取历史 Token 计数,缓存到 `~/.aiusage/trae-cache/sessions/`;不会直接破解
19
+ 加密数据库。国际版通过 `--edition intl` 在本机读取 Trae IDE 或 Trae Solo 的登录
20
+ 信息(旧版直接读取、新版在本机解密),并调用官方账号用量 API;实现和缓存解析均与
21
+ [tokscale](https://github.com/junhoyeo/tokscale) 的 MIT 开源实现交叉校验。
22
+
17
23
  ## 安装
18
24
 
19
25
  ```bash
@@ -58,7 +64,11 @@ aiusage project alias --remove myapp # 移除别名
58
64
  aiusage report # 默认: 最近 7 天 + 今天,英文,紧凑模式
59
65
  aiusage report --range 1m # 最近 30 天
60
66
  aiusage report --range 3m # 最近 90 天
67
+ aiusage report --range 6m # 最近 180 天
61
68
  aiusage report --range all # 全部历史
69
+ aiusage report --tool trae-cn --range all # 仅 Trae CN
70
+ aiusage report --tool trae-intl --range 6m # 仅 Trae 国际版
71
+ aiusage report --tool trae --range all # 两个版本合计
62
72
  aiusage report --detail # 展示全部列、热门模型、定价说明
63
73
  aiusage report --lang zh # 中文输出
64
74
  aiusage report --no-emoji # 禁用标题 emoji
@@ -67,6 +77,34 @@ aiusage report --json # JSON 输出
67
77
 
68
78
  **紧凑模式**(默认)显示来源和每日汇总表,合并缓存列,保留 2 位小数成本。**详细模式**(`--detail`)展开所有列(CacheRead、CacheWrite、Reasoning),增加热门模型和定价说明,显示 4 位小数成本。
69
79
 
80
+ ### trae sync
81
+
82
+ 按版本同步 Trae 历史用量,再运行常规报告或看板上传:
83
+
84
+ ```bash
85
+ aiusage trae sync --edition cn # 默认值;Trae CN 本地历史
86
+ aiusage trae sync --edition intl --since 180 # 国际版账号最近 180 天
87
+ aiusage trae sync --edition all --since 180 # 两边都尝试,任一成功即可
88
+
89
+ aiusage report --tool trae-cn --range all
90
+ aiusage report --tool trae-intl --range 6m
91
+ aiusage report --tool trae --range all # CN + 国际版 + 兼容旧数据
92
+ ```
93
+
94
+ 如果 Trae CN 未运行,AIUsage 会用仅限本机的调试端口临时启动它,读取官方
95
+ `ai-agent` 会话接口,完成后自动退出。如果 Trae 已经在运行但没有开启该端口,
96
+ 请先退出 Trae 再重试。也可以通过 `--port 9230 --no-launch` 连接自行启动的实例。
97
+
98
+ Trae 国际版 IDE 与 Trae Solo 共用账号级用量,只会通过第一个可用凭据请求一次,不会
99
+ 重复统计。AIUsage 会在本机读取或解密 `storage.json` 中的登录信息,并以 `0600` 权限保存到
100
+ `~/.aiusage/trae-cache/intl/credentials-{ide,solo}.json`;凭据和对话正文都不会上传。
101
+ 官方 API 返回的会话级 Token/费用缓存位于
102
+ `~/.aiusage/trae-cache/intl/sessions/usage.json`。现有
103
+ `~/.config/tokscale/trae-cache/sessions/*.json` 仍会读取,并按会话保留最新快照,避免双算。
104
+
105
+ 报告筛选值为 `trae-cn`、`trae-intl`;`trae` 是两者合计的稳定别名。常规 `sync`
106
+ 始终按完整日期汇总上传,因此不接受 `--tool`,避免把局部结果当成整日统计。
107
+
70
108
  ### 统一日期参数
71
109
 
72
110
  `scan`、`report`、`sync` 使用同一套日期参数:
@@ -75,11 +113,12 @@ aiusage report --json # JSON 输出
75
113
  aiusage scan --today # 仅今天
76
114
  aiusage report --date 2026-03-31 # 指定日期
77
115
  aiusage sync --range 1m # 最近 30 天
116
+ aiusage report --range 6m # 最近 180 天
78
117
  aiusage sync --lookback 14 # 最近 14 天 + 今天
79
118
  aiusage scan --from 2025-01-01 --to 2026-04-05
80
119
  ```
81
120
 
82
- 使用 `--range 1m`,不要写成 `range -1m`。`report` 额外支持 `--range all`;`scan` 和 `sync` 如需很长历史范围,请明确使用 `--from/--to`。
121
+ 使用 `--range 1m`,不要写成 `range -1m`。`scan`、`report`、`sync` 支持 `--range 6m`;`report` 额外支持 `--range all`。`scan` 和 `sync` 如需更长历史范围,请明确使用 `--from/--to`。
83
122
 
84
123
  ### scan
85
124
 
@@ -89,6 +128,7 @@ aiusage scan --from 2025-01-01 --to 2026-04-05
89
128
  aiusage scan # 昨天
90
129
  aiusage scan --date 2026-03-31 # 指定日期
91
130
  aiusage scan --range 1m # 最近 30 天
131
+ aiusage scan --tool trae-cn --range 6m # 仅 Trae CN 最近 180 天
92
132
  aiusage scan --date 2026-03-31 --json # JSON 输出
93
133
  ```
94
134
 
@@ -0,0 +1,29 @@
1
+ # Third-Party Notices
2
+
3
+ ## tokscale
4
+
5
+ Portions of the Kimi and Trae local usage parsers, Trae credential decryption,
6
+ and Trae account usage synchronization are adapted from
7
+ [junhoyeo/tokscale](https://github.com/junhoyeo/tokscale).
8
+
9
+ MIT License
10
+
11
+ Copyright (c) 2025 Junho Yeo
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.