@anthonyhan/token-pilot 0.0.0-stage → 0.2.3
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/.github/FUNDING.yml +3 -0
- package/.github/workflows/build-desktop.yml +68 -0
- package/.idea/go.imports.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/sonarlint/vulnerabilitystore/default/index.pb +0 -0
- package/.idea/thriftCompilerAssist.xml +6 -0
- package/.idea/token-pilot.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/README-en.md +127 -0
- package/README.md +146 -2
- package/bin/token-pilot.js +15 -0
- package/docs/assets/dashboard.png +0 -0
- package/docs/assets/icon.png +0 -0
- package/docs/assets/menubar-panel.png +0 -0
- package/docs/assets/sponsor-alipay.png +0 -0
- package/docs/assets/sponsor-wechat.png +0 -0
- package/llms.txt +40 -0
- package/menubar/package-lock.json +248 -0
- package/menubar/package.json +16 -0
- package/menubar/src/dashboard.html +1266 -0
- package/menubar/src/index.html +674 -0
- package/menubar/src-tauri/Cargo.lock +4963 -0
- package/menubar/src-tauri/Cargo.toml +15 -0
- package/menubar/src-tauri/build.rs +3 -0
- package/menubar/src-tauri/gen/schemas/acl-manifests.json +1 -0
- package/menubar/src-tauri/gen/schemas/capabilities.json +1 -0
- package/menubar/src-tauri/gen/schemas/desktop-schema.json +2526 -0
- package/menubar/src-tauri/gen/schemas/macOS-schema.json +2526 -0
- package/menubar/src-tauri/icons/128x128.png +0 -0
- package/menubar/src-tauri/icons/128x128@2x.png +0 -0
- package/menubar/src-tauri/icons/32x32.png +0 -0
- package/menubar/src-tauri/icons/64x64.png +0 -0
- package/menubar/src-tauri/icons/Square107x107Logo.png +0 -0
- package/menubar/src-tauri/icons/Square142x142Logo.png +0 -0
- package/menubar/src-tauri/icons/Square150x150Logo.png +0 -0
- package/menubar/src-tauri/icons/Square284x284Logo.png +0 -0
- package/menubar/src-tauri/icons/Square30x30Logo.png +0 -0
- package/menubar/src-tauri/icons/Square310x310Logo.png +0 -0
- package/menubar/src-tauri/icons/Square44x44Logo.png +0 -0
- package/menubar/src-tauri/icons/Square71x71Logo.png +0 -0
- package/menubar/src-tauri/icons/Square89x89Logo.png +0 -0
- package/menubar/src-tauri/icons/StoreLogo.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml +5 -0
- package/menubar/src-tauri/icons/android/mipmap-hdpi/ic_launcher.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-hdpi/ic_launcher_foreground.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-mdpi/ic_launcher.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-mdpi/ic_launcher_foreground.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xhdpi/ic_launcher.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/menubar/src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/menubar/src-tauri/icons/android/values/ic_launcher_background.xml +4 -0
- package/menubar/src-tauri/icons/icon.icns +0 -0
- package/menubar/src-tauri/icons/icon.ico +0 -0
- package/menubar/src-tauri/icons/icon.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-20x20@1x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-20x20@2x-1.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-20x20@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-20x20@3x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-29x29@1x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-29x29@2x-1.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-29x29@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-29x29@3x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-40x40@1x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-40x40@2x-1.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-40x40@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-40x40@3x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-512@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-60x60@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-60x60@3x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-76x76@1x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-76x76@2x.png +0 -0
- package/menubar/src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png +0 -0
- package/menubar/src-tauri/icons/tray-win.png +0 -0
- package/menubar/src-tauri/icons/tray.png +0 -0
- package/menubar/src-tauri/src/main.rs +486 -0
- package/menubar/src-tauri/tauri.conf.json +56 -0
- package/package.json +20 -3
- package/pricing/models.json +311 -0
- package/scripts/gen-icons.py +153 -0
- package/scripts/reconcile.py +162 -0
- package/scripts/verify-dashboard.py +101 -0
- package/src/adapters/claude-code.ts +246 -0
- package/src/adapters/codex.ts +166 -0
- package/src/adapters/dsh.ts +156 -0
- package/src/adapters/kimi-code.ts +164 -0
- package/src/adapters/opencode.ts +120 -0
- package/src/adapters/pi.ts +99 -0
- package/src/adapters/qoder.ts +43 -0
- package/src/adapters/types.ts +39 -0
- package/src/adapters/volc-ark.ts +102 -0
- package/src/adapters/workbuddy.ts +135 -0
- package/src/cli/index.ts +294 -0
- package/src/cli/serve.ts +209 -0
- package/src/core/aggregate.ts +821 -0
- package/src/core/alert.ts +33 -0
- package/src/core/autocompact.ts +46 -0
- package/src/core/budget.ts +42 -0
- package/src/core/collector.ts +209 -0
- package/src/core/compression.ts +163 -0
- package/src/core/config.ts +71 -0
- package/src/core/contract.ts +181 -0
- package/src/core/metrics.ts +72 -0
- package/src/core/price-fetch.ts +112 -0
- package/src/core/pricing.ts +182 -0
- package/src/core/registry.ts +141 -0
- package/src/core/retry-detector.ts +64 -0
- package/src/core/rtk.ts +58 -0
- package/src/core/savings.ts +55 -0
- package/src/core/schema.ts +66 -0
- package/src/core/unknown-models.ts +64 -0
- package/tests/adapters-dsh.test.ts +35 -0
- package/tests/adapters-opencode.test.ts +39 -0
- package/tests/adapters-pi.test.ts +33 -0
- package/tests/adapters-workbuddy.test.ts +34 -0
- package/tests/adapters.test.ts +45 -0
- package/tests/aggregate.test.ts +153 -0
- package/tests/compression.test.ts +71 -0
- package/tests/fixtures/claude-session.jsonl +9 -0
- package/tests/fixtures/codex-rollout.jsonl +5 -0
- package/tests/fixtures/kimi-wire.jsonl +6 -0
- package/tests/pricing-timebased.test.ts +51 -0
- package/tests/pricing.test.ts +73 -0
- package/tests/serve.test.ts +29 -0
- package/tsconfig.json +19 -0
- package/web/dashboard.html +1266 -0
- package/web/panel.html +674 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# token-pilot 状态栏应用 — Windows / macOS 构建
|
|
2
|
+
# 触发:打 v* tag 或手动 dispatch。产出 .msi(Windows x64)与 .dmg(macOS arm64 + Intel)。
|
|
3
|
+
|
|
4
|
+
name: build-desktop
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
push:
|
|
9
|
+
tags: ["v*"]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
include:
|
|
16
|
+
- os: windows-latest
|
|
17
|
+
target: x86_64-pc-windows-msvc
|
|
18
|
+
- os: macos-latest
|
|
19
|
+
target: aarch64-apple-darwin
|
|
20
|
+
- os: macos-15-intel
|
|
21
|
+
target: x86_64-apple-darwin
|
|
22
|
+
runs-on: ${{ matrix.os }}
|
|
23
|
+
defaults:
|
|
24
|
+
run:
|
|
25
|
+
working-directory: menubar
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
|
|
29
|
+
- uses: actions/setup-node@v4
|
|
30
|
+
with:
|
|
31
|
+
node-version: 22
|
|
32
|
+
|
|
33
|
+
# Windows 交叉/本机构建 token-pilot CLI 依赖 node 全局安装由用户侧 npm link 提供;
|
|
34
|
+
# 桌面应用本身只依赖 Rust 工具链。
|
|
35
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
36
|
+
with:
|
|
37
|
+
targets: ${{ matrix.target }}
|
|
38
|
+
|
|
39
|
+
- name: Cache cargo
|
|
40
|
+
uses: actions/cache@v4
|
|
41
|
+
with:
|
|
42
|
+
path: |
|
|
43
|
+
~/.cargo/registry
|
|
44
|
+
~/.cargo/git
|
|
45
|
+
menubar/src-tauri/target
|
|
46
|
+
key: ${{ matrix.os }}-${{ matrix.target }}-cargo-${{ hashFiles('menubar/src-tauri/Cargo.lock') }}
|
|
47
|
+
|
|
48
|
+
- name: Install tauri-cli
|
|
49
|
+
run: cargo install tauri-cli --version "^2" --locked
|
|
50
|
+
|
|
51
|
+
- name: Clean stale bundle artifacts(防缓存带旧版本包)
|
|
52
|
+
shell: bash
|
|
53
|
+
run: rm -rf src-tauri/target/*/release/bundle src-tauri/target/release/bundle
|
|
54
|
+
working-directory: menubar
|
|
55
|
+
|
|
56
|
+
- name: Build bundles
|
|
57
|
+
run: cargo tauri build --target ${{ matrix.target }}
|
|
58
|
+
working-directory: menubar
|
|
59
|
+
|
|
60
|
+
- name: Upload artifacts
|
|
61
|
+
uses: actions/upload-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
name: token-pilot-${{ matrix.target }}
|
|
64
|
+
path: |
|
|
65
|
+
menubar/src-tauri/target/${{ matrix.target }}/release/bundle/msi/*.msi
|
|
66
|
+
menubar/src-tauri/target/${{ matrix.target }}/release/bundle/dmg/*.dmg
|
|
67
|
+
menubar/src-tauri/target/${{ matrix.target }}/release/bundle/macos/*.app
|
|
68
|
+
if-no-files-found: ignore
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/token-pilot.iml" filepath="$PROJECT_DIR$/.idea/token-pilot.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="Go" enabled="true" />
|
|
4
|
+
<component name="NewModuleRootManager">
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/README-en.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="docs/assets/icon.png" width="96" alt="token-pilot — local billing for all your AI tools">
|
|
4
|
+
|
|
5
|
+
# token-pilot ⚡
|
|
6
|
+
|
|
7
|
+
### Local billing for all your AI tools, always one glance away
|
|
8
|
+
|
|
9
|
+
For anyone running Claude Code / Codex / Kimi Code with Chinese models (DeepSeek, GLM…) and can't answer "how much did I burn on AI this month" — reads local logs only, nothing leaves your machine.
|
|
10
|
+
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](#-menubar-app)
|
|
13
|
+
[](tests/)
|
|
14
|
+
[](#-data-accuracy)
|
|
15
|
+
|
|
16
|
+
[Quickstart](#-quickstart) · [Menubar App](#-menubar-app) · [Data Accuracy](#-data-accuracy) · [When NOT to use](#-when-not-to-use-it) · [中文](README.md) · [llms.txt](llms.txt)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
> Lives in your menubar as `⚡ ¥today · budget%`. Left-click for the panel, "Open dashboard" for the full picture. My real October: **810M tokens · ¥2,546 · 12,685 calls** ([how we know](#-data-accuracy)).
|
|
25
|
+
|
|
26
|
+
> ⚠️ **注意**:npm 上的 \`token-pilot\` 是别人的同名包(MCP 代码导航工具,会往 Claude Code 写 hooks)。**我们的包叫 \`@anthonyhan/token-pilot\`**,别装错:
|
|
27
|
+
|
|
28
|
+
## 🚀 Quickstart
|
|
29
|
+
|
|
30
|
+
**For Humans:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install -g @anthonyhan/token-pilot
|
|
34
|
+
token-pilot month # month bill + forecast + retry-loop detection + savings advice
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**For AI Agents:** (paste this to your agent)
|
|
38
|
+
|
|
39
|
+
> Install token-pilot for me: `npm install -g @anthonyhan/token-pilot`, then run `token-pilot month` and tell me how much I spent on AI this month and where I'm wasting it.
|
|
40
|
+
|
|
41
|
+
### Menubar App
|
|
42
|
+
|
|
43
|
+
Grab `.dmg` (macOS Apple Silicon) or `.msi` (Windows x64) from [Releases](../../releases). After install it lives **only in the menubar** — no Dock icon, no startup window. Left-click opens the panel, right-click opens the menu.
|
|
44
|
+
|
|
45
|
+
> Unsigned: on macOS right-click → Open; on Windows SmartScreen → "Run anyway". Build it yourself: `cd menubar && npm install && npx tauri build`
|
|
46
|
+
|
|
47
|
+
## ✨ What it does
|
|
48
|
+
|
|
49
|
+
| You want | You say | It does |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| The bill | `token-pilot month` | Per-host & per-model month bill + month-end forecast |
|
|
52
|
+
| Budget guardrails | set a monthly budget | progress bar + system notification + menubar `¥today · budget%` |
|
|
53
|
+
| Catch runaway agents | nothing | flags sessions with ≥30 calls stuck in retry loops, computes the waste |
|
|
54
|
+
| Save money | see "savings" cards | expensive-model-for-light-tasks migration advice with $/month saved; low cache-hit sessions; how much cache saved you this month |
|
|
55
|
+
| Who's burning | see host/model/project ranks | which tool, which model, which project costs most |
|
|
56
|
+
| Chinese models | nothing to configure | DeepSeek/GLM/Kimi/Qwen auto-normalized via host-log `model` field |
|
|
57
|
+
|
|
58
|
+
**Works with your toolchain:** Claude Code ✅ · Codex ✅ · Kimi Code ✅ · OpenCode ✅ · pi ✅ · DeepSeek Harness ✅ · WorkBuddy ✅ · Doubao cloud ✅ · DeepSeek/GLM/Kimi/Qwen/MiniMax/Hunyuan/MiMo/LongCat/Doubao ✅ (model normalization) · 12 more detected-only · desktop subscription apps tracked as fixed monthly fees
|
|
59
|
+
|
|
60
|
+
## 📈 Data accuracy
|
|
61
|
+
|
|
62
|
+
A billing tool that's wrong is worse than none. Accuracy here is **verifiable**:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python3 scripts/reconcile.py month # independent third-party recount of raw logs vs CLI
|
|
66
|
+
python3 scripts/verify-dashboard.py # 36 dashboard algorithm invariants
|
|
67
|
+
npm test # 23 unit tests (pricing / collection / aggregation)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Real accounting bugs fixed (2026-10-21, 4,787 log files on my machine):
|
|
71
|
+
|
|
72
|
+
| Bug | Impact | Fix |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| Claude streaming snapshot duplicates | one session: 169 usage lines = 79 actual calls | dedupe by `message.id`, keep max |
|
|
75
|
+
| Codex `input` includes `cached` subset | cache billed at full price AND cache price | split `input − cached` |
|
|
76
|
+
| Kimi `inputOther` is the real fresh input | same double-billing | only `usage.record`, no cache merging |
|
|
77
|
+
|
|
78
|
+
## 📊 Why trust me
|
|
79
|
+
|
|
80
|
+
- It runs my own AI bill: **¥2,546 / 810M tokens** this month (2026-10-21, screenshots above are my live data)
|
|
81
|
+
- 36 dashboard invariants + 23 unit tests + an independent reconciliation script — all runnable out of the box
|
|
82
|
+
- Honest about rate accounting: logs book tokens at call-completion time; in-flight generations aren't counted until they finish (noted in the dashboard)
|
|
83
|
+
|
|
84
|
+
## ⚠️ When NOT to use it
|
|
85
|
+
|
|
86
|
+
- **Your tool doesn't write local usage logs** (Antigravity / Copilot / Cursor and 9 more) — we detect presence, but there's no token data to read
|
|
87
|
+
- **Desktop subscription apps** (Kimi.app / ChatGPT.app) — not per-token billed; tracked as fixed monthly fees only
|
|
88
|
+
- **You want to throttle requests before they happen** — it's after-the-fact analysis, not a proxy (a routing layer is on the roadmap)
|
|
89
|
+
|
|
90
|
+
## 💰 Support
|
|
91
|
+
|
|
92
|
+
Free & MIT. If it saved you money on AI bills, buy me a coffee (Alipay / WeChat codes in the [Chinese README](README.md#-支持这个项目)) — or just say hi on [X @AnthonyHan_](https://x.com/AnthonyHan_).
|
|
93
|
+
|
|
94
|
+
⭐ Star = vote for your host: the next adapter gets built for the most-nominated tool.
|
|
95
|
+
|
|
96
|
+
## 🙋 About me
|
|
97
|
+
|
|
98
|
+
A solo dev + a few AI agents running product experiments (remote, Xi'an). token-pilot is what I actually use daily — it first caught a kimi-code session stuck in a 120-call retry loop, then told me caching saved me ¥3,048 this month.
|
|
99
|
+
|
|
100
|
+
## 📝 Changelog
|
|
101
|
+
|
|
102
|
+
- **2026-10-21** v0.1.0: first release — CLI bill + local dashboard + macOS/Windows menubar app
|
|
103
|
+
|
|
104
|
+
## ✅ TODO
|
|
105
|
+
|
|
106
|
+
**Coverage**
|
|
107
|
+
- [x] OpenCode adapter (SQLite) · Qoder (session counts) · pi · Cursor spike
|
|
108
|
+
- [x] Cloud usage API: Doubao Volcano (arkcli, daily granularity)
|
|
109
|
+
- [ ] Cloud usage APIs: OpenAI / Moonshot (user-provided API key)
|
|
110
|
+
|
|
111
|
+
**Throttling (step 2)**
|
|
112
|
+
- [x] 2A Compression potential measurement
|
|
113
|
+
- [x] 2B layer 1: auto-compact alerts + Claude autoCompact + one-click RTK install
|
|
114
|
+
- [ ] 2B layer 2: proxy gateway (LiteLLM/self-built)
|
|
115
|
+
- [ ] 2B Compression execution (integrate Gobstopper-style proxy first)
|
|
116
|
+
- [ ] Cheap-model routing (optional local proxy — never touches your config by default)
|
|
117
|
+
- [ ] Proactive retry-loop breaker notifications
|
|
118
|
+
|
|
119
|
+
**Platform & engineering**
|
|
120
|
+
- [x] macOS menubar app (arm64 .app/.dmg)
|
|
121
|
+
- [x] Windows audit + platform icons + CI
|
|
122
|
+
- [ ] Windows .msi on-device validation (Actions artifact)
|
|
123
|
+
- [ ] Intel Mac build (universal2) · auto-update (tauri-updater) · signing & notarization
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT © anthonyhann
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="docs/assets/icon.png" width="96" alt="token-pilot —— 所有 AI 工具的本地账单,本月实测 ¥2,546 / 810M tokens">
|
|
4
|
+
|
|
5
|
+
# token-pilot ⚡
|
|
6
|
+
|
|
7
|
+
### 所有 AI 工具的本地账单,一抬头就看见
|
|
8
|
+
|
|
9
|
+
同时用 Claude Code / Codex / Kimi Code 跑国产模型的人,终于能答上「这个月给 AI 烧了多少钱」——只读本地日志,数据不出本机。
|
|
10
|
+
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](#-状态栏应用)
|
|
13
|
+
[](tests/)
|
|
14
|
+
[](#-数据准确性)
|
|
15
|
+
|
|
16
|
+
[快速开始](#-快速开始) · [状态栏应用](#-状态栏应用) · [数据准确性](#-数据准确性) · [什么时候别用它](#-什么时候别用它) · [TODO](#-todo-list) · [English](README-en.md) · [llms.txt](llms.txt)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
> 状态栏常驻 `⚡ ¥今日 · 预算%`。左键弹面板,「打开完整看板」看全部。我的真实 10 月:**810M tokens · ¥2,546 · 12,685 次调用**([怎么算的](#-数据准确性))。
|
|
25
|
+
|
|
26
|
+
> ⚠️ **注意**:npm 上的 \`token-pilot\` 是别人的同名包(MCP 代码导航工具,会往 Claude Code 写 hooks)。**我们的包叫 \`@anthonyhan/token-pilot\`**,别装错:
|
|
27
|
+
|
|
28
|
+
## 🚀 快速开始
|
|
29
|
+
|
|
30
|
+
**For Humans:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install -g @anthonyhan/token-pilot
|
|
34
|
+
token-pilot month # 本月账单 + 月底预测 + 打转检测 + 省钱建议
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**For AI Agents:**(把这句粘贴给你的 Agent)
|
|
38
|
+
|
|
39
|
+
> 帮我安装 token-pilot:`npm install -g @anthonyhan/token-pilot`,然后跑 `token-pilot month` 告诉我这个月 AI 花了多少钱、哪里在浪费。
|
|
40
|
+
|
|
41
|
+
### 状态栏应用
|
|
42
|
+
|
|
43
|
+
[Releases](../../releases) 下载 `.dmg`(macOS Apple Silicon)/ `.msi`(Windows x64)。安装启动后**只在状态栏显示一个闪电图标**——无 Dock 图标、无启动窗口;左键弹面板,右键出菜单。
|
|
44
|
+
|
|
45
|
+
> 未签名:macOS 首次打开需右键 → 打开;Windows SmartScreen 选「仍要运行」。自己构建:`cd menubar && npm install && npx tauri build`
|
|
46
|
+
|
|
47
|
+
## ✨ 它能做什么
|
|
48
|
+
|
|
49
|
+
| 场景 | 你说 | 它做 |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| 看账单 | `token-pilot month` | 按宿主/按模型双维度月账单 + 月底预测 |
|
|
52
|
+
| 怕超支 | 设个月度预算 | 进度条 + 超支系统通知 + 托盘常驻 `¥今日 · 预算%` |
|
|
53
|
+
| Agent 打转 | 不用说话 | 自动揪出「单会话 ≥30 次调用」的死循环,算出浪费金额 |
|
|
54
|
+
| 想省钱 | 看「省钱建议」卡 | 贵模型干轻活 → 迁移建议+每月省多少;低缓存命中 → 优化空间;本月缓存帮你省了多少 |
|
|
55
|
+
| 上下文太长 | 自动提醒 / 点徽标 | 会话超 100K 上下文标记「该压缩」,可写 Claude Code autoCompact / 一键装 RTK 输出压缩层 |
|
|
56
|
+
| 核对价格 | `token-pilot prices` | 每个在用模型的单价来源(目录价/人工覆写/自动补价待核对) |
|
|
57
|
+
| 谁在烧 | 看「宿主/模型/项目榜」 | 哪个工具、哪个模型、哪个项目花最多,一目了然 |
|
|
58
|
+
| 国产模型 | 不用配置 | DeepSeek/GLM/Kimi/Qwen 走宿主日志 model 字段自动归一 |
|
|
59
|
+
|
|
60
|
+
**兼容你的工具链:** Claude Code ✅ · Codex ✅ · Kimi Code ✅ · OpenCode ✅(全量 token)· DeepSeek/GLM/Kimi/Qwen/MiniMax/混元/MiMo/LongCat/Doubao ✅(模型归一)· 其余 12 款仅检测 · 桌面订阅端记固定月费
|
|
61
|
+
|
|
62
|
+
## 📈 数据准确性
|
|
63
|
+
|
|
64
|
+
账单工具不准就是误导。所以准确性**可验证**:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python3 scripts/reconcile.py month # 第三方视角独立重算原始日志,与 CLI 逐项对账
|
|
68
|
+
python3 scripts/verify-dashboard.py # 看板 36 项算法不变量校验
|
|
69
|
+
npm test # 40 个单元测试(定价/采集口径/聚合/注入)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
实测修过的口径坑(2026-10-21,本机 4787 个日志文件):
|
|
73
|
+
|
|
74
|
+
| 坑 | 影响 | 修复 |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| Claude 流式快照重复行 | 某会话 169 行 usage 实为 79 次调用 | 按 `message.id` 去重取最大 |
|
|
77
|
+
| Codex `input` 含 `cached` 子集 | 缓存被按全价+缓存价计两次 | 拆分 `input − cached` |
|
|
78
|
+
| Kimi `inputOther` 才是新输入 | 同上 | 只认 `usage.record` 且不并入缓存 |
|
|
79
|
+
|
|
80
|
+
## 📊 凭什么信我
|
|
81
|
+
|
|
82
|
+
- 我自己的 AI 账单就是它管的:本月 **¥2,546 / 810M tokens**(2026-10-21,上方截图即本机实时数据)
|
|
83
|
+
- 36 项看板算法不变量 + 22 个单测 + 独立对账脚本,全部开箱可跑
|
|
84
|
+
- 诚实披露速率口径:日志按「调用完成时刻」记账,生成中的调用完成前不计入(看板内有注明)
|
|
85
|
+
|
|
86
|
+
## ⚠️ 什么时候别用它
|
|
87
|
+
|
|
88
|
+
- **你想管的工具不写本地用量日志**(Antigravity / Copilot / Cursor 等 12 款)——只能检测到装没装,读不到 token
|
|
89
|
+
- **桌面订阅 App**(Kimi.app / ChatGPT.app)——不按 token 计费,只能登记固定月费
|
|
90
|
+
- **想拦在请求前面节流**——它是事后分析,不拦截请求(拦截需要代理层,在 Roadmap)
|
|
91
|
+
|
|
92
|
+
## 💰 支持这个项目
|
|
93
|
+
|
|
94
|
+
token-pilot 免费且 MIT。如果它帮你省下了 AI 账单,可以请我喝杯咖啡:
|
|
95
|
+
|
|
96
|
+
| 支付宝 | 微信 |
|
|
97
|
+
|---|---|
|
|
98
|
+
| <img src="docs/assets/sponsor-alipay.png" width="260" alt="支付宝赞赏码"> | <img src="docs/assets/sponsor-wechat.png" width="260" alt="微信赞赏码"> |
|
|
99
|
+
|
|
100
|
+
也想出现在这里?→ [bmomhan@gmail.com](mailto:bmomhan@gmail.com)(赞助位招租)
|
|
101
|
+
|
|
102
|
+
⭐ Star 本仓库 = 告诉我你在用哪个宿主——下一个 adapter 优先做 Star 用户提名最多的那个。
|
|
103
|
+
|
|
104
|
+
## 🙋 关于我
|
|
105
|
+
|
|
106
|
+
一个人 + 几个 AI Agent 在做产品实验(西安远程)。token-pilot 是我自己每天真在用的工具——它先抓出了我 kimi-code 里一个打了 120 次调用的打转会话,又告诉我这个月缓存帮我省了 ¥3,048。
|
|
107
|
+
|
|
108
|
+
**保持联系:** [X @AnthonyHan_](https://x.com/AnthonyHan_) · [bmomhan@gmail.com](mailto:bmomhan@gmail.com)
|
|
109
|
+
|
|
110
|
+
## 📝 更新日志
|
|
111
|
+
|
|
112
|
+
- **2026-10-21** v0.1.0:首版 → CLI 账单 + 本地看板 + macOS/Windows 状态栏应用,三形态一次给齐
|
|
113
|
+
|
|
114
|
+
## ✅ TODO LIST
|
|
115
|
+
|
|
116
|
+
**采集覆盖**
|
|
117
|
+
- [x] OpenCode adapter(SQLite)
|
|
118
|
+
- [x] Qoder adapter(仅会话数,model 全为 auto——诚实标注)
|
|
119
|
+
- [x] pi adapter
|
|
120
|
+
- [x] Cursor spike(结论:无 token 用量数据,ai-code-tracking 是代码追踪非用量 → 诚实归「仅检测」)
|
|
121
|
+
- [x] 云端用量 API:Doubao 火山(arkcli usage stats,日粒度)
|
|
122
|
+
- [ ] 云端用量 API:OpenAI / Kimi 开放平台(需用户配 API key)
|
|
123
|
+
|
|
124
|
+
**节流(Step 2)**
|
|
125
|
+
- [x] 2A 压缩潜力量化(规则引擎:陈旧输出/重复读取/超长输出 → 本月可省多少,实测 $63-95)
|
|
126
|
+
- [x] 2B 压缩执行第一层:自动压缩提醒 + Claude autoCompact 写入 + RTK 一键安装
|
|
127
|
+
- [ ] 2B 压缩执行第二层:代理网关(LiteLLM/自研,视数据再定)
|
|
128
|
+
- [ ] 低价模型路由(本地代理层,可选开启,默认不动你任何配置)
|
|
129
|
+
- [ ] 异常重试自动熔断提醒(已有检测,加主动通知策略)
|
|
130
|
+
|
|
131
|
+
**平台与工程**
|
|
132
|
+
- [x] macOS 状态栏应用(arm64 .app/.dmg)
|
|
133
|
+
- [x] Windows 核查 + 分平台图标 + CI
|
|
134
|
+
- [ ] Windows .msi 实机验证(Actions 产物)
|
|
135
|
+
- [ ] Intel Mac 包(universal2)
|
|
136
|
+
- [ ] 自动更新(tauri-updater)
|
|
137
|
+
- [ ] 签名与公证(Apple Developer $99/年,有赞助再开)
|
|
138
|
+
|
|
139
|
+
## English
|
|
140
|
+
|
|
141
|
+
**[README in English → README-en.md](README-en.md)**
|
|
142
|
+
|
|
143
|
+
*token-pilot* — local billing + budget control for all your AI coding tools. Reads local logs only (no hooks, no telemetry). CLI + local dashboard + menubar app (macOS/Windows). Chinese models (DeepSeek/GLM/Kimi…) auto-normalized via host-log `model` field.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT © anthonyhann
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// token-pilot 全局入口:用 --experimental-strip-types 直接跑 TS,无需先 build
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const entry = path.resolve(__dirname, '../src/cli/index.ts');
|
|
9
|
+
|
|
10
|
+
const r = spawnSync(
|
|
11
|
+
process.execPath,
|
|
12
|
+
['--experimental-strip-types', '--no-warnings', entry, ...process.argv.slice(2)],
|
|
13
|
+
{ stdio: 'inherit' }
|
|
14
|
+
);
|
|
15
|
+
process.exit(r.status ?? 0);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/llms.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# token-pilot
|
|
2
|
+
|
|
3
|
+
> 所有 AI 工具的本地账单 + 预算控制器。只读本地日志,零入侵,数据不出本机。
|
|
4
|
+
|
|
5
|
+
## 给 AI Agent 的安装口令
|
|
6
|
+
|
|
7
|
+
用户说「帮我装 token-pilot」时执行:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @anthonyhan/token-pilot
|
|
11
|
+
token-pilot month
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
然后把月账单、打转检测、省钱建议三条结论念给用户。
|
|
15
|
+
|
|
16
|
+
## 命令
|
|
17
|
+
|
|
18
|
+
- `token-pilot today` — 今天各宿主/模型的 tokens 与花费
|
|
19
|
+
- `token-pilot month` — 本月 + 月底预测 + 打转检测 + 省钱建议
|
|
20
|
+
- `token-pilot report` — 全量
|
|
21
|
+
- `token-pilot sync` — 刷新 ~/.token-pilot/dashboard-data.json(增量缓存,热跑 <1s)
|
|
22
|
+
- `token-pilot serve` — 本地看板 http://127.0.0.1:17895(10s 自刷新,可选)
|
|
23
|
+
- `token-pilot dash` — 静态看板 ~/.token-pilot/dashboard.html
|
|
24
|
+
|
|
25
|
+
## 数据口径
|
|
26
|
+
|
|
27
|
+
- 读取:~/.claude/projects/**/*.jsonl(按 message.id 去重)、~/.codex/sessions/**/*.jsonl(input−cached 拆分)、~/.kimi-code/sessions/**/wire.jsonl(只认 usage.record)
|
|
28
|
+
- 定价:pricing/models.json(USD/1M,含 cacheRead 目录价),展示按 config.usdToCny 折 ¥
|
|
29
|
+
- 配置:~/.token-pilot/config.json(monthlyBudgetCny / priceOverrides / cloudApis / subscriptions)
|
|
30
|
+
- 看板数据契约:src/core/contract.ts(DashboardData)
|
|
31
|
+
|
|
32
|
+
## 验证
|
|
33
|
+
|
|
34
|
+
- `python3 scripts/reconcile.py month` — 独立重算原始日志对账
|
|
35
|
+
- `python3 scripts/verify-dashboard.py` — 36 项看板算法不变量
|
|
36
|
+
- `npm test` — 22 个单元测试
|
|
37
|
+
|
|
38
|
+
## 仓库
|
|
39
|
+
|
|
40
|
+
https://github.com/anthonyhann/token-pilot
|