tokenforbes-cli 0.1.1 → 0.1.2

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.
Files changed (3) hide show
  1. package/bin.js +1 -1
  2. package/ccusage.js +11 -2
  3. package/package.json +1 -1
package/bin.js CHANGED
@@ -96,7 +96,7 @@ async function report() {
96
96
  const days = readUsage();
97
97
  if (!days.length) return console.log('没读到用量数据。');
98
98
  const device = detectDevice();
99
- const total = days.reduce((s, d) => s + d.input + d.output, 0);
99
+ const total = days.reduce((s, d) => s + d.input + d.output + (d.cacheCreation || 0) + (d.cacheRead || 0), 0);
100
100
  console.log(`设备:${device}`);
101
101
  console.log(`共 ${days.length} 天,合计约 ${Math.round(total / 1e4).toLocaleString()} 万 token,上报中…`);
102
102
  const j = await post(server + '/api/report', { key: c.key, device, days });
package/ccusage.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // 读本地 AI 编码用量。只用 ccusage 的统计数字,绝不碰你的项目内容。
2
- // 榜单口径:每天 input + output(不含缓存)。
2
+ // 榜单口径:每天 input + output + 缓存(读+写)一起算;成本用 ccusage 的真实分档价($)
3
3
  import { execSync } from 'node:child_process';
4
4
 
5
5
  const num = (x) => Math.max(0, Math.round(Number(x) || 0));
6
+ const money = (x) => Math.max(0, Number(x) || 0); // 成本是美元小数,别取整
6
7
 
7
8
  export function readUsage() {
8
9
  let out;
@@ -25,10 +26,14 @@ export function readUsage() {
25
26
  return data.daily
26
27
  .map((d) => {
27
28
  const input = num(d.inputTokens), output = num(d.outputTokens);
29
+ const cacheCreation = num(d.cacheCreationTokens), cacheRead = num(d.cacheReadTokens);
28
30
  return {
29
31
  date: d.period,
30
32
  input,
31
33
  output,
34
+ cacheCreation, // 缓存写(建缓存)
35
+ cacheRead, // 缓存读(命中缓存,最便宜)
36
+ cost: money(d.totalCost), // ccusage 按各模型真实分档价算出的当天美元成本(已含缓存)
32
37
  models: d.modelsUsed || [],
33
38
  tools: d.metadata?.agents || [], // 用了哪些工具:claude / codex …
34
39
  breakdown: Array.isArray(d.modelBreakdowns)
@@ -36,9 +41,13 @@ export function readUsage() {
36
41
  model: m.modelName,
37
42
  input: num(m.inputTokens),
38
43
  output: num(m.outputTokens),
44
+ cacheCreation: num(m.cacheCreationTokens),
45
+ cacheRead: num(m.cacheReadTokens),
46
+ cost: money(m.cost),
39
47
  }))
40
48
  : [],
41
49
  };
42
50
  })
43
- .filter((d) => d.date && d.input + d.output > 0);
51
+ // 放宽:只要四类 token 有一个 >0 就留下(纯缓存的天也算数)
52
+ .filter((d) => d.date && (d.input + d.output + d.cacheCreation + d.cacheRead) > 0);
44
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenforbes-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "上报本地 AI 编程工具(Claude Code / Codex 等)的 token 用量到 Token 福布斯排行榜(ceorank.cn)。只读用量数字和设备型号,绝不碰你的代码内容。",
5
5
  "type": "module",
6
6
  "bin": {