@anthonyhan/token-pilot 0.2.3 → 0.3.1
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 +38 -13
- package/bin/token-pilot.js +10 -7
- package/dist/adapters/claude-code.js +251 -0
- package/dist/adapters/codex.js +163 -0
- package/dist/adapters/dsh.js +163 -0
- package/dist/adapters/kimi-code.js +165 -0
- package/dist/adapters/opencode.js +126 -0
- package/dist/adapters/pi.js +119 -0
- package/dist/adapters/qoder.js +51 -0
- package/dist/adapters/types.js +7 -0
- package/dist/adapters/volc-ark.js +92 -0
- package/dist/adapters/workbuddy.js +144 -0
- package/dist/cli/index.js +286 -0
- package/dist/cli/serve.js +211 -0
- package/dist/core/aggregate.js +813 -0
- package/dist/core/alert.js +32 -0
- package/dist/core/autocompact.js +40 -0
- package/dist/core/breaker.js +49 -0
- package/dist/core/budget.js +23 -0
- package/dist/core/collector.js +213 -0
- package/dist/core/compression.js +129 -0
- package/dist/core/config.js +44 -0
- package/dist/core/contract.js +4 -0
- package/dist/core/metrics.js +53 -0
- package/dist/core/price-fetch.js +128 -0
- package/dist/core/pricing.js +156 -0
- package/dist/core/registry.js +144 -0
- package/dist/core/retry-detector.js +41 -0
- package/dist/core/rtk.js +58 -0
- package/dist/core/savings.js +43 -0
- package/dist/core/schema.js +3 -0
- package/dist/core/unknown-models.js +50 -0
- package/package.json +18 -5
- package/web/dashboard.html +98 -4
- package/.github/FUNDING.yml +0 -3
- package/.github/workflows/build-desktop.yml +0 -68
- package/.idea/go.imports.xml +0 -10
- package/.idea/modules.xml +0 -8
- package/.idea/sonarlint/vulnerabilitystore/default/index.pb +0 -0
- package/.idea/thriftCompilerAssist.xml +0 -6
- package/.idea/token-pilot.iml +0 -9
- package/.idea/vcs.xml +0 -6
- package/README-en.md +0 -127
- 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 +0 -40
- package/menubar/package-lock.json +0 -248
- package/menubar/package.json +0 -16
- package/menubar/src/dashboard.html +0 -1266
- package/menubar/src/index.html +0 -674
- package/menubar/src-tauri/Cargo.lock +0 -4963
- package/menubar/src-tauri/Cargo.toml +0 -15
- package/menubar/src-tauri/build.rs +0 -3
- package/menubar/src-tauri/gen/schemas/acl-manifests.json +0 -1
- package/menubar/src-tauri/gen/schemas/capabilities.json +0 -1
- package/menubar/src-tauri/gen/schemas/desktop-schema.json +0 -2526
- package/menubar/src-tauri/gen/schemas/macOS-schema.json +0 -2526
- 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 +0 -5
- 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 +0 -4
- 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 +0 -486
- package/menubar/src-tauri/tauri.conf.json +0 -56
- package/scripts/gen-icons.py +0 -153
- package/scripts/reconcile.py +0 -162
- package/scripts/verify-dashboard.py +0 -101
- package/src/adapters/claude-code.ts +0 -246
- package/src/adapters/codex.ts +0 -166
- package/src/adapters/dsh.ts +0 -156
- package/src/adapters/kimi-code.ts +0 -164
- package/src/adapters/opencode.ts +0 -120
- package/src/adapters/pi.ts +0 -99
- package/src/adapters/qoder.ts +0 -43
- package/src/adapters/types.ts +0 -39
- package/src/adapters/volc-ark.ts +0 -102
- package/src/adapters/workbuddy.ts +0 -135
- package/src/cli/index.ts +0 -294
- package/src/cli/serve.ts +0 -209
- package/src/core/aggregate.ts +0 -821
- package/src/core/alert.ts +0 -33
- package/src/core/autocompact.ts +0 -46
- package/src/core/budget.ts +0 -42
- package/src/core/collector.ts +0 -209
- package/src/core/compression.ts +0 -163
- package/src/core/config.ts +0 -71
- package/src/core/contract.ts +0 -181
- package/src/core/metrics.ts +0 -72
- package/src/core/price-fetch.ts +0 -112
- package/src/core/pricing.ts +0 -182
- package/src/core/registry.ts +0 -141
- package/src/core/retry-detector.ts +0 -64
- package/src/core/rtk.ts +0 -58
- package/src/core/savings.ts +0 -55
- package/src/core/schema.ts +0 -66
- package/src/core/unknown-models.ts +0 -64
- package/tests/adapters-dsh.test.ts +0 -35
- package/tests/adapters-opencode.test.ts +0 -39
- package/tests/adapters-pi.test.ts +0 -33
- package/tests/adapters-workbuddy.test.ts +0 -34
- package/tests/adapters.test.ts +0 -45
- package/tests/aggregate.test.ts +0 -153
- package/tests/compression.test.ts +0 -71
- package/tests/fixtures/claude-session.jsonl +0 -9
- package/tests/fixtures/codex-rollout.jsonl +0 -5
- package/tests/fixtures/kimi-wire.jsonl +0 -6
- package/tests/pricing-timebased.test.ts +0 -51
- package/tests/pricing.test.ts +0 -73
- package/tests/serve.test.ts +0 -29
- package/tsconfig.json +0 -19
package/web/dashboard.html
CHANGED
|
@@ -225,7 +225,7 @@ svg{display:block}
|
|
|
225
225
|
.tier-2{color:var(--info-text);background:color-mix(in oklab, var(--info) 13%, var(--tint))}
|
|
226
226
|
.tier-0{color:oklch(0.4 0.01 275);background:oklch(0.94 0.004 85)}
|
|
227
227
|
|
|
228
|
-
.save-grid{display:grid;grid-template-columns:repeat(
|
|
228
|
+
.save-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:14px;margin-top:4px}
|
|
229
229
|
.save-card{border:1px solid var(--border);border-radius:14px;padding:15px 16px;display:flex;flex-direction:column;gap:7px;transition:box-shadow .15s var(--ease), transform .15s var(--ease)}
|
|
230
230
|
.save-card:hover{box-shadow:var(--shadow);transform:translateY(-1px)}
|
|
231
231
|
.save-top{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
@@ -235,6 +235,27 @@ svg{display:block}
|
|
|
235
235
|
.save-amt.warn{color:var(--warn);background:color-mix(in oklab, var(--warn) 10%, var(--tint))}
|
|
236
236
|
.save-amt.info{color:var(--info);background:color-mix(in oklab, var(--info) 11%, var(--tint))}
|
|
237
237
|
|
|
238
|
+
/* 压缩潜力:总额条 + 模式拆分 + 最浪费会话 */
|
|
239
|
+
.cmp-bar{display:flex;align-items:baseline;gap:12px;flex-wrap:wrap;margin-bottom:14px}
|
|
240
|
+
.cmp-big{font-size:30px;font-weight:800;letter-spacing:-.02em;color:var(--pos)}
|
|
241
|
+
.cmp-big small{font-size:15px;font-weight:700;color:var(--pos);opacity:.75}
|
|
242
|
+
.cmp-sub{color:var(--muted);font-size:12.5px}
|
|
243
|
+
.cmp-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-bottom:14px}
|
|
244
|
+
.cmp-card{border:1px solid var(--border);border-radius:12px;padding:11px 13px;background:var(--surface)}
|
|
245
|
+
.cmp-card .cmp-k{font-size:12px;color:var(--muted);display:flex;align-items:center;gap:6px}
|
|
246
|
+
.cmp-card .cmp-v{font-size:17px;font-weight:800;margin-top:5px}
|
|
247
|
+
.cmp-card .cmp-p{font-size:11.5px;color:var(--muted);margin-top:3px}
|
|
248
|
+
.cmp-track{height:6px;border-radius:999px;background:var(--border);overflow:hidden;display:flex;gap:2px;margin:0 0 16px}
|
|
249
|
+
.cmp-track i{display:block;height:100%;border-radius:999px}
|
|
250
|
+
.cmp-list{display:flex;flex-direction:column;gap:8px}
|
|
251
|
+
.cmp-row{display:flex;align-items:center;gap:10px;font-size:12.5px}
|
|
252
|
+
.cmp-row .cmp-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--mono,inherit)}
|
|
253
|
+
.cmp-row .cmp-c{font-weight:700;color:var(--warn);white-space:nowrap}
|
|
254
|
+
.cmp-row .cmp-t{color:var(--muted);white-space:nowrap;font-size:11.5px}
|
|
255
|
+
.cmp-empty{color:var(--muted);font-size:13px;padding:6px 0}
|
|
256
|
+
.cmp-note{color:var(--muted);font-size:11.5px;margin-top:12px;line-height:1.6}
|
|
257
|
+
@media (max-width:1020px){.cmp-grid{grid-template-columns:1fr}}
|
|
258
|
+
|
|
238
259
|
.filter-row{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:14px}
|
|
239
260
|
.chipbtn{border:1px solid var(--border);border-radius:999px;padding:5px 13px;font-size:12.5px;font-weight:600;color:var(--muted);background:var(--surface);transition:all .15s var(--ease)}
|
|
240
261
|
.chipbtn:hover{color:var(--fg);border-color:oklch(0.8 0.02 275)}
|
|
@@ -540,6 +561,14 @@ footer .notes{max-width:560px}
|
|
|
540
561
|
</div>
|
|
541
562
|
</section>
|
|
542
563
|
|
|
564
|
+
<section class="sec acc-green full-only" data-od-id="compression" style="margin-top:16px">
|
|
565
|
+
<div class="sec-head">
|
|
566
|
+
<h2 class="sec-title"><span class="icon-chip ic-green"><svg viewBox="0 0 24 24"><path d="M4 7h9M4 12h13M4 17h7"/><path d="M17 15l3 3 3-3" transform="translate(-1 0)"/></svg></span>压缩潜力</h2>
|
|
567
|
+
<span class="sec-note">本月 · 规则法估算,压缩后可省区间</span>
|
|
568
|
+
</div>
|
|
569
|
+
<div id="cmpBody"><div class="cmp-empty">本月暂无明显可压缩的上下文浪费。</div></div>
|
|
570
|
+
</section>
|
|
571
|
+
|
|
543
572
|
<section class="sec acc-blue full-only" data-od-id="adapters" style="margin-top:16px">
|
|
544
573
|
<div class="sec-head">
|
|
545
574
|
<h2 class="sec-title"><span class="icon-chip ic-blue"><svg viewBox="0 0 24 24"><path d="M9 3v4M15 3v4M7 7h10v4a5 5 0 0 1-10 0V7zM12 16v5"/></svg></span>适配器状态</h2>
|
|
@@ -1068,13 +1097,77 @@ var SAVEICON={
|
|
|
1068
1097
|
cache:'<span class="icon-chip ic-green"><svg viewBox="0 0 24 24"><ellipse cx="12" cy="6" rx="7" ry="3"/><path d="M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6"/></svg></span>'
|
|
1069
1098
|
};
|
|
1070
1099
|
function renderSavings(){
|
|
1071
|
-
var arr=D.savings||[];
|
|
1072
|
-
|
|
1100
|
+
var arr=(D.savings||[]).slice();
|
|
1101
|
+
// 不再按位置硬截断 3 张:可行动项(warn/info,如「该 compact 了」)优先保住,
|
|
1102
|
+
// 纯信息项(pos)排在后面。否则新增一张卡就会把它后面那张静默挤掉。
|
|
1103
|
+
var rank=function(s){return s.kind==="warn"?0:s.kind==="info"?1:2};
|
|
1104
|
+
arr=arr.map(function(s,i){return {s:s,i:i}}).sort(function(a,b){
|
|
1105
|
+
var d=rank(a.s)-rank(b.s); return d!==0?d:a.i-b.i;
|
|
1106
|
+
}).map(function(x){return x.s});
|
|
1107
|
+
document.querySelector('[data-od-id="savings"] .save-grid').innerHTML=arr.slice(0,4).map(function(s){
|
|
1073
1108
|
var cls=s.kind==="warn"?" warn":s.kind==="info"?" info":"";
|
|
1074
1109
|
return '<div class="save-card"><div class="save-top"><span class="save-title">'+(SAVEICON[s.icon]||SAVEICON.cache)+esc(s.title)+'</span><span class="save-amt'+cls+' num">'+esc(s.amount)+'</span></div><div class="save-desc num">'+esc(s.desc)+"</div></div>";
|
|
1075
1110
|
}).join("");
|
|
1076
1111
|
}
|
|
1077
1112
|
|
|
1113
|
+
/* ---------- compression ---------- */
|
|
1114
|
+
var CMPSHAPE={
|
|
1115
|
+
stale:{k:'陈旧 tool 输出',d:'早轮次的大段输出仍被后续调用反复读入'},
|
|
1116
|
+
reread:{k:'重复读取',d:'同一文件/内容被多次读入上下文'},
|
|
1117
|
+
long:{k:'超长输出',d:'单次输出体积过大,占用后续轮次上下文'}
|
|
1118
|
+
};
|
|
1119
|
+
// 压缩潜力金额:始终保留两位(大额场景下小项不能被四舍五入抹掉)
|
|
1120
|
+
function fmtCnyExact(n){
|
|
1121
|
+
n=+n||0;
|
|
1122
|
+
return "¥"+n.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2});
|
|
1123
|
+
}
|
|
1124
|
+
function renderCompression(){
|
|
1125
|
+
var box=document.getElementById('cmpBody');
|
|
1126
|
+
if(!box)return;
|
|
1127
|
+
var c=D.compression;
|
|
1128
|
+
if(!c||!c.itemCount){box.innerHTML='<div class="cmp-empty">本月暂无明显可压缩的上下文浪费。</div>';return}
|
|
1129
|
+
|
|
1130
|
+
var lo=Math.max(0,+c.potentialCny||0), hi=Math.max(lo,+c.potentialCnyMax||0);
|
|
1131
|
+
var items=+c.itemCount||0;
|
|
1132
|
+
var p=c.patterns||{stale:0,reread:0,long:0};
|
|
1133
|
+
var sum=(+p.stale||0)+(+p.reread||0)+(+p.long||0);
|
|
1134
|
+
|
|
1135
|
+
var h='<div class="cmp-bar"><div class="cmp-big num">'+fmtCny(lo)+'<small> – '+fmtCny(hi).replace('¥','¥')+'</small></div>'+
|
|
1136
|
+
'<div class="cmp-sub num">本月可节省区间 · 共 '+items.toLocaleString('zh-CN')+' 处浪费点</div></div>';
|
|
1137
|
+
|
|
1138
|
+
var pct=function(v){return sum>0?Math.round((+v||0)/sum*1000)/10:0};
|
|
1139
|
+
// 模式拆分
|
|
1140
|
+
var order=['stale','reread','long'];
|
|
1141
|
+
h+='<div class="cmp-grid">'+order.map(function(k){
|
|
1142
|
+
var v=+p[k]||0, sh=CMPSHAPE[k];
|
|
1143
|
+
var pv=pct(v);
|
|
1144
|
+
return '<div class="cmp-card"><div class="cmp-k">'+sh.k+'</div><div class="cmp-v num">'+fmtCnyExact(v)+'</div><div class="cmp-p num">'+(pv>=1?'占比 '+trim1(pv)+'% · ':'')+sh.d+'</div></div>';
|
|
1145
|
+
}).join('')+'</div>';
|
|
1146
|
+
// 占比条
|
|
1147
|
+
h+='<div class="cmp-track">'+order.map(function(k){
|
|
1148
|
+
var v=+p[k]||0;if(!v)return '';
|
|
1149
|
+
var col=k==='stale'?'var(--pos)':k==='reread'?'var(--info)':'color-mix(in oklab, var(--pos) 55%, var(--muted))';
|
|
1150
|
+
return '<i style="width:'+(sum>0?v/sum*100:0)+'%;background:'+col+'"></i>';
|
|
1151
|
+
}).join('')+'</div>';
|
|
1152
|
+
|
|
1153
|
+
// 最浪费会话
|
|
1154
|
+
var sess=(c.sessions||[]).slice(0,5);
|
|
1155
|
+
if(sess.length){
|
|
1156
|
+
h+='<div class="cmp-list">'+sess.map(function(x){
|
|
1157
|
+
var name=String(x.key||'').replace(':'+String(x.key||'').split(':').pop(),'');
|
|
1158
|
+
var short=String(x.key||'');
|
|
1159
|
+
var ci=short.indexOf(':');
|
|
1160
|
+
var host=ci>0?short.slice(0,ci):short, sid=ci>0?short.slice(ci+1):'';
|
|
1161
|
+
var label=host+(sid?' · '+sid.slice(-8):'');
|
|
1162
|
+
return '<div class="cmp-row"><span class="cmp-name" title="'+esc(short)+'">'+esc(label)+'</span>'+
|
|
1163
|
+
'<span class="cmp-t num">'+(x.items||0)+' 处 · '+esc((x.topPatterns||[]).map(function(t){return (CMPSHAPE[t]||{}).k||t}).join('/'))+'</span>'+
|
|
1164
|
+
'<span class="cmp-c num">'+fmtCnyExact(x.wasteCny)+'</span></div>';
|
|
1165
|
+
}).join('')+'</div>';
|
|
1166
|
+
}
|
|
1167
|
+
h+='<div class="cmp-note">口径:把这些浪费点压缩掉后、本月可少花的钱(区间下界=保守估算)。真正的自动压缩要在「数据设置」里显式开启,这里只做量化与提醒。</div>';
|
|
1168
|
+
box.innerHTML=h;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1078
1171
|
/* ---------- token trend ---------- */
|
|
1079
1172
|
var TW=1100,THh=220,TB=200,TT=12;
|
|
1080
1173
|
function smoothL(xs,ys){
|
|
@@ -1208,7 +1301,7 @@ function emptyData(){
|
|
|
1208
1301
|
trend:{days:days,budgetDailyCny:null,todaySplit:{cacheReadCny:0,cacheWriteCny:0,outputCny:0,newInputCny:0},sum14Cny:0,peakCny:0},
|
|
1209
1302
|
mix:{today:{model:[],tool:[],proj:[]},week:{model:[],tool:[],proj:[]},month:{model:[],tool:[],proj:[]}},
|
|
1210
1303
|
tokTrend:{days:days,top:{model:"",tool:"",proj:""}},
|
|
1211
|
-
modelRank:[],hostRank:[],savings:[],adapters:[],
|
|
1304
|
+
modelRank:[],hostRank:[],savings:[],compression:null,adapters:[],
|
|
1212
1305
|
settings:{models:[],cloudApis:[],subscriptions:[],monthlyBudgetCny:null,usdToCny:7.2}
|
|
1213
1306
|
};
|
|
1214
1307
|
}
|
|
@@ -1228,6 +1321,7 @@ function renderAll(d){
|
|
|
1228
1321
|
renderTok();
|
|
1229
1322
|
renderRanks();
|
|
1230
1323
|
renderSavings();
|
|
1324
|
+
renderCompression();
|
|
1231
1325
|
renderAdapters();
|
|
1232
1326
|
renderFooter();
|
|
1233
1327
|
}
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
package/.idea/go.imports.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
package/.idea/token-pilot.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
DELETED
package/README-en.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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
|
|
Binary file
|
package/docs/assets/icon.png
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/llms.txt
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|