ai-token-usage-lite 0.1.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/LICENSE +24 -0
- package/README.md +106 -0
- package/bin/ai-token-usage-lite.js +8 -0
- package/package.json +40 -0
- package/public/index.html +1003 -0
- package/src/aggregate.js +100 -0
- package/src/cli.js +115 -0
- package/src/doctor.js +30 -0
- package/src/export.js +32 -0
- package/src/fs-utils.js +65 -0
- package/src/paths.js +16 -0
- package/src/providers/claude.js +69 -0
- package/src/providers/codex.js +127 -0
- package/src/server.js +117 -0
- package/src/status.js +40 -0
- package/src/sync.js +33 -0
- package/src/turns/aggregate-turns.js +68 -0
- package/src/turns/claude-turns.js +120 -0
- package/src/turns/codex-turns.js +117 -0
- package/src/turns/common.js +42 -0
- package/src/turns/index.js +15 -0
- package/src/turns/skill-detect.js +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
This project includes parser and integration design derived from Token Tracker
|
|
16
|
+
(https://github.com/mm7894215/TokenTracker), MIT licensed.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# AI Token Usage Lite
|
|
2
|
+
|
|
3
|
+
本地版 AI 对话 Token 用量看板。当前支持 Codex、Claude Code 的用量统计,并提供按轮次的 Skills、耗时和 Token 明细。
|
|
4
|
+
|
|
5
|
+
要求:
|
|
6
|
+
|
|
7
|
+
- Node.js `>= 20`
|
|
8
|
+
- 本机已安装并使用过 Codex 或 Claude Code
|
|
9
|
+
- 仅扫描本地日志,不请求外部用量 API
|
|
10
|
+
|
|
11
|
+
## 通过 npx 使用
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx ai-token-usage-lite@latest serve --port 7790
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
打开看板:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
http://127.0.0.1:7790
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
常用命令:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx ai-token-usage-lite@latest sync
|
|
27
|
+
npx ai-token-usage-lite@latest serve --port 7790
|
|
28
|
+
npx ai-token-usage-lite@latest status --json
|
|
29
|
+
npx ai-token-usage-lite@latest doctor
|
|
30
|
+
npx ai-token-usage-lite@latest export --format csv
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
默认数据来源:
|
|
34
|
+
|
|
35
|
+
- Claude Code:`~/.claude/projects`
|
|
36
|
+
- Codex:`~/.codex/sessions`
|
|
37
|
+
- 聚合结果:`~/.ai-token-usage-lite/usage.json`
|
|
38
|
+
|
|
39
|
+
## 团队内推荐用法
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx ai-token-usage-lite@latest serve --port 7790
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
如果需要只刷新本地聚合结果:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx ai-token-usage-lite@latest sync
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
如果需要排查为什么没有统计到数据:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx ai-token-usage-lite@latest doctor
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 本地开发与发布检查
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm test
|
|
61
|
+
npm run pack:check
|
|
62
|
+
npm run smoke:npx
|
|
63
|
+
npm run release:check
|
|
64
|
+
node bin/ai-token-usage-lite.js sync
|
|
65
|
+
node bin/ai-token-usage-lite.js serve --port 7790
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
发布到公开 npm:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm login
|
|
72
|
+
npm run release:check
|
|
73
|
+
npm run publish:public
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
说明:
|
|
77
|
+
|
|
78
|
+
- 仓库内已固定 npm cache 到 `./.npm-cache`,避免受全局 `~/.npm` 权限问题影响。
|
|
79
|
+
- `smoke:npx` 会先打 tarball,再用 `npm exec --package=<tgz>` 验证公开安装路径对应的 CLI 入口。
|
|
80
|
+
|
|
81
|
+
## 统计内容
|
|
82
|
+
|
|
83
|
+
- 总览:消耗总 Token、输入 Token、输出 Token、缓存输入 Token、对话次数。
|
|
84
|
+
- 按来源:Codex、Claude Code 的用量分布。
|
|
85
|
+
- 按模型:不同模型的 Token 和对话次数。
|
|
86
|
+
- 按日期:每日用量趋势。
|
|
87
|
+
- 按项目:从本地日志里能识别到的项目引用。
|
|
88
|
+
- 按 Skills:每个 skill 的调用轮次、总耗时、总 Token、平均 Token、平均耗时。
|
|
89
|
+
- 最近对话轮次:每轮对话的来源、模型、耗时、Skills、输入/输出/缓存/消耗总 Token。
|
|
90
|
+
|
|
91
|
+
## Token 口径
|
|
92
|
+
|
|
93
|
+
- 输入 Token:发送给模型的上下文消耗,通常包括你的请求、历史上下文、工具结果、系统提示等。
|
|
94
|
+
- 输出 Token:模型生成回答、工具调用参数、推理输出等产生的消耗。
|
|
95
|
+
- 缓存输入 Token:命中上下文缓存的输入 Token。它仍然属于模型上下文规模,但计费口径通常会和普通输入不同,具体以各工具或模型服务商为准。
|
|
96
|
+
- 消耗总 Token:当前看板主口径,按 `输入 - 缓存输入 + 输出 + cache creation` 计算,更接近实际消耗。
|
|
97
|
+
|
|
98
|
+
## Skills 识别说明
|
|
99
|
+
|
|
100
|
+
- Skill 识别分为:
|
|
101
|
+
- `explicit`:对话文本中明确出现正在使用某个 skill。
|
|
102
|
+
- `inferred`:从读取 `SKILL.md` 等本地 skill 文件路径推断。
|
|
103
|
+
|
|
104
|
+
## 隐私边界
|
|
105
|
+
|
|
106
|
+
工具只落地聚合后的统计信息:来源、模型、时间桶、项目引用、Token 数、轮次耗时和 Skill 名称。不会保存 prompt、assistant response、工具调用参数、工具结果或文件内容,也不会请求外部用量 API。
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-token-usage-lite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-only token usage dashboard for Codex and Claude Code.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"author": "lingaibo",
|
|
7
|
+
"homepage": "https://www.npmjs.com/package/ai-token-usage-lite",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ai-token-usage-lite": "bin/ai-token-usage-lite.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"src/",
|
|
14
|
+
"public/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test",
|
|
20
|
+
"pack:check": "npm pack --dry-run --cache ./.npm-cache",
|
|
21
|
+
"smoke:npx": "node scripts/release-smoke.js",
|
|
22
|
+
"release:check": "npm test && npm run pack:check && npm run smoke:npx",
|
|
23
|
+
"publish:public": "npm publish --access public --cache ./.npm-cache"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"ai",
|
|
30
|
+
"token",
|
|
31
|
+
"usage",
|
|
32
|
+
"dashboard",
|
|
33
|
+
"codex",
|
|
34
|
+
"claude-code"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|