@aiusage/cli 1.7.5 → 1.7.7

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
@@ -5,7 +5,7 @@
5
5
  - discovering and managing projects across AI tools
6
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
 
@@ -29,9 +29,10 @@ differ, rather than treating every local record as billable token usage.
29
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
30
  | Qwen Code | Current `~/.qwen/projects/` and legacy `~/.qwen/tmp/` chat JSONL, with session/position deduplication and cache-aware input accounting. |
31
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`. |
32
+ | OpenCode | All XDG `opencode*.db` channel databases, including v1 `message` and v2 `session_message`, plus legacy `storage/message/*.json`; deduplicates dual writes/forks and preserves provider-reported cost. Node 22.13+ uses built-in read-only SQLite, with system `sqlite3` as the older-Node fallback. |
33
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. |
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. |
35
36
 
36
37
  Only token counters and session metadata are aggregated or uploaded. Conversation
37
38
  content and local credentials are never uploaded.
@@ -80,7 +81,11 @@ Local usage report. No cloud upload required.
80
81
  aiusage report # default: last 7 days + today, English, compact
81
82
  aiusage report --range 1m # last 30 days
82
83
  aiusage report --range 3m # last 90 days
84
+ aiusage report --range 6m # last 180 days
83
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
84
89
  aiusage report --detail # show all columns, top models, pricing notes
85
90
  aiusage report --lang zh # Chinese output
86
91
  aiusage report --no-emoji # disable emoji in title
@@ -93,16 +98,23 @@ Reads data from local tool data directories including `~/.claude/projects` (Clau
93
98
 
94
99
  ### trae sync
95
100
 
96
- Sync Trae CN's local historical token counters before running a regular report or dashboard upload:
101
+ Sync either Trae edition before running a regular report or dashboard upload:
97
102
 
98
103
  ```bash
99
- aiusage trae sync
100
- aiusage report --range all
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
101
111
  ```
102
112
 
103
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.
104
114
 
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.
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.
106
118
 
107
119
  ### Shared date options
108
120
 
@@ -112,11 +124,12 @@ Only session identifiers, workspace paths, timestamps, model labels, and numeric
112
124
  aiusage scan --today # today only
113
125
  aiusage report --date 2026-03-31 # specific date
114
126
  aiusage sync --range 1m # last 30 days
127
+ aiusage report --range 6m # last 180 days
115
128
  aiusage sync --lookback 14 # last 14 days + today
116
129
  aiusage scan --from 2025-01-01 --to 2026-04-05
117
130
  ```
118
131
 
119
- 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.
120
133
 
121
134
  ### scan
122
135
 
@@ -126,6 +139,7 @@ Scan local usage and print detailed breakdowns.
126
139
  aiusage scan # yesterday
127
140
  aiusage scan --date 2026-03-31 # specific date
128
141
  aiusage scan --range 1m # last 30 days
142
+ aiusage scan --tool trae-cn --range 6m # Trae CN only, last 180 days
129
143
  aiusage scan --date 2026-03-31 --json # JSON output
130
144
  ```
131
145
 
@@ -225,6 +239,7 @@ aiusage config set emoji false # disable emoji in repor
225
239
  aiusage config set device.alias "MacBook Pro 工作机" # device display name on dashboard
226
240
  aiusage config set privacy.projectVisibility masked # hidden | masked | plain
227
241
  aiusage config set project.alias MyApp "我的应用" # prefer: aiusage project alias
242
+ aiusage config set scanner.opencodeDbPaths "/custom/opencode-next.db" # extra OpenCode DB
228
243
  aiusage config set anthropic-admin-key sk-ant-admin... # for aiusage import
229
244
  ```
230
245
 
package/README.zh-CN.md CHANGED
@@ -5,7 +5,7 @@
5
5
  - 发现和管理本机 AI 工具项目
6
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,9 +14,22 @@ 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` 生成的缓存。
17
+ OpenCode 同时读取 XDG 数据目录中的全部 `opencode*.db`:兼容 v1 `message`
18
+ 与 v2 `session_message`,并保留旧版 `storage/message/*.json` 兜底。扫描器会对
19
+ 多渠道数据库、迁移期双写和 fork 副本去重,采用消息内的供应商费用。支持
20
+ `XDG_DATA_HOME` 与 `OPENCODE_DB`。Node 22.13+ 使用内置只读 SQLite;更早的
21
+ 受支持 Node 版本回退系统 `sqlite3`。数据库位于其他自定义目录时可配置:
22
+
23
+ ```bash
24
+ aiusage config set scanner.opencodeDbPaths "/custom/opencode-next.db" "/custom/opencode-stable.db"
25
+ aiusage config set scanner.opencodeDbPaths default # 清除自定义路径
26
+ ```
27
+
28
+ Trae CN 通过 `aiusage trae sync --edition cn` 调用 Trae 自己的本地 `ai-agent`
29
+ 接口读取历史 Token 计数,缓存到 `~/.aiusage/trae-cache/sessions/`;不会直接破解
30
+ 加密数据库。国际版通过 `--edition intl` 在本机读取 Trae IDE 或 Trae Solo 的登录
31
+ 信息(旧版直接读取、新版在本机解密),并调用官方账号用量 API;实现和缓存解析均与
32
+ [tokscale](https://github.com/junhoyeo/tokscale) 的 MIT 开源实现交叉校验。
20
33
 
21
34
  ## 安装
22
35
 
@@ -62,7 +75,11 @@ aiusage project alias --remove myapp # 移除别名
62
75
  aiusage report # 默认: 最近 7 天 + 今天,英文,紧凑模式
63
76
  aiusage report --range 1m # 最近 30 天
64
77
  aiusage report --range 3m # 最近 90 天
78
+ aiusage report --range 6m # 最近 180 天
65
79
  aiusage report --range all # 全部历史
80
+ aiusage report --tool trae-cn --range all # 仅 Trae CN
81
+ aiusage report --tool trae-intl --range 6m # 仅 Trae 国际版
82
+ aiusage report --tool trae --range all # 两个版本合计
66
83
  aiusage report --detail # 展示全部列、热门模型、定价说明
67
84
  aiusage report --lang zh # 中文输出
68
85
  aiusage report --no-emoji # 禁用标题 emoji
@@ -73,19 +90,31 @@ aiusage report --json # JSON 输出
73
90
 
74
91
  ### trae sync
75
92
 
76
- 先同步 Trae CN 的本地历史用量,再运行常规报告或看板上传:
93
+ 按版本同步 Trae 历史用量,再运行常规报告或看板上传:
77
94
 
78
95
  ```bash
79
- aiusage trae sync
80
- aiusage report --range all
96
+ aiusage trae sync --edition cn # 默认值;Trae CN 本地历史
97
+ aiusage trae sync --edition intl --since 180 # 国际版账号最近 180 天
98
+ aiusage trae sync --edition all --since 180 # 两边都尝试,任一成功即可
99
+
100
+ aiusage report --tool trae-cn --range all
101
+ aiusage report --tool trae-intl --range 6m
102
+ aiusage report --tool trae --range all # CN + 国际版 + 兼容旧数据
81
103
  ```
82
104
 
83
105
  如果 Trae CN 未运行,AIUsage 会用仅限本机的调试端口临时启动它,读取官方
84
106
  `ai-agent` 会话接口,完成后自动退出。如果 Trae 已经在运行但没有开启该端口,
85
107
  请先退出 Trae 再重试。也可以通过 `--port 9230 --no-launch` 连接自行启动的实例。
86
108
 
87
- 缓存只包含会话标识、项目路径、时间、模型名和 Token 数字,不包含对话正文或登录凭据。
88
- 国际版用户可先执行 `tokscale trae sync`,AIUsage 会自动读取兼容缓存。
109
+ Trae 国际版 IDE 与 Trae Solo 共用账号级用量,只会通过第一个可用凭据请求一次,不会
110
+ 重复统计。AIUsage 会在本机读取或解密 `storage.json` 中的登录信息,并以 `0600` 权限保存到
111
+ `~/.aiusage/trae-cache/intl/credentials-{ide,solo}.json`;凭据和对话正文都不会上传。
112
+ 官方 API 返回的会话级 Token/费用缓存位于
113
+ `~/.aiusage/trae-cache/intl/sessions/usage.json`。现有
114
+ `~/.config/tokscale/trae-cache/sessions/*.json` 仍会读取,并按会话保留最新快照,避免双算。
115
+
116
+ 报告筛选值为 `trae-cn`、`trae-intl`;`trae` 是两者合计的稳定别名。常规 `sync`
117
+ 始终按完整日期汇总上传,因此不接受 `--tool`,避免把局部结果当成整日统计。
89
118
 
90
119
  ### 统一日期参数
91
120
 
@@ -95,11 +124,12 @@ aiusage report --range all
95
124
  aiusage scan --today # 仅今天
96
125
  aiusage report --date 2026-03-31 # 指定日期
97
126
  aiusage sync --range 1m # 最近 30 天
127
+ aiusage report --range 6m # 最近 180 天
98
128
  aiusage sync --lookback 14 # 最近 14 天 + 今天
99
129
  aiusage scan --from 2025-01-01 --to 2026-04-05
100
130
  ```
101
131
 
102
- 使用 `--range 1m`,不要写成 `range -1m`。`report` 额外支持 `--range all`;`scan` 和 `sync` 如需很长历史范围,请明确使用 `--from/--to`。
132
+ 使用 `--range 1m`,不要写成 `range -1m`。`scan`、`report`、`sync` 支持 `--range 6m`;`report` 额外支持 `--range all`。`scan` 和 `sync` 如需更长历史范围,请明确使用 `--from/--to`。
103
133
 
104
134
  ### scan
105
135
 
@@ -109,6 +139,7 @@ aiusage scan --from 2025-01-01 --to 2026-04-05
109
139
  aiusage scan # 昨天
110
140
  aiusage scan --date 2026-03-31 # 指定日期
111
141
  aiusage scan --range 1m # 最近 30 天
142
+ aiusage scan --tool trae-cn --range 6m # 仅 Trae CN 最近 180 天
112
143
  aiusage scan --date 2026-03-31 --json # JSON 输出
113
144
  ```
114
145
 
@@ -207,6 +238,7 @@ aiusage config set emoji false # 禁用报告标题 emo
207
238
  aiusage config set device.alias "MacBook Pro 工作机" # Dashboard 上显示的设备名称
208
239
  aiusage config set privacy.projectVisibility masked # hidden | masked | plain
209
240
  aiusage config set project.alias MyApp "我的应用" # 推荐用 aiusage project alias
241
+ aiusage config set scanner.opencodeDbPaths "/custom/opencode-next.db" # 额外 OpenCode 数据库
210
242
  aiusage config set anthropic-admin-key sk-ant-admin... # 用于 aiusage import
211
243
  ```
212
244
 
@@ -0,0 +1,29 @@
1
+ # Third-Party Notices
2
+
3
+ ## tokscale
4
+
5
+ Portions of the Kimi, Trae, and OpenCode local usage parsers, Trae credential
6
+ decryption, 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.