@winston.wan/burn-your-money 3.0.0 → 3.0.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.
package/README.md CHANGED
@@ -90,6 +90,18 @@ npm install -g "@winston.wan/burn-your-money"
90
90
  - **历史统计**:从 `~/.claude/stats-cache.json` 读取
91
91
  - **本地计算**:零网络请求,纯本地处理
92
92
 
93
+ ### 💰 价格说明
94
+
95
+ 费用计算基于 **Claude 模型官方定价**(截至 2025 年):
96
+
97
+ | Token 类型 | 价格 |
98
+ |-----------|------|
99
+ | Input Tokens | $3 / 百万 tokens |
100
+ | Output Tokens | $15 / 百万 tokens |
101
+ | Cache Read Tokens | $0.30 / 百万 tokens (90% 折扣) |
102
+
103
+ > **注意**:如果你使用的是其他兼容模型(如本地部署的模型),实际费用可能不同。本插件仅按 Claude 官方价格估算,不代表实际账单。
104
+
93
105
  ---
94
106
 
95
107
  ## 📋 常见问题
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@winston.wan/burn-your-money",
3
- "version": "3.0.0",
4
- "description": "💸 Burn Your Money - 实时显示 Claude Code 的 token 消耗,看着你的钱包燃烧!",
5
- "main": "src/statusline.js",
6
- "scripts": {
7
- "postinstall": "node install.js",
8
- "postuninstall": "node uninstall.js"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/winston-wwzhen/burn-your-money.git"
13
- },
14
- "keywords": [
15
- "claude-code",
16
- "token-monitor",
17
- "statusline",
18
- "claude",
19
- "ai",
20
- "cost-tracker",
21
- "burn-money"
22
- ],
23
- "author": "winston-wwzhen",
24
- "license": "MIT",
25
- "bugs": {
26
- "url": "https://github.com/winston-wwzhen/burn-your-money/issues"
27
- },
28
- "homepage": "https://github.com/winston-wwzhen/burn-your-money#readme"
29
- }
1
+ {
2
+ "name": "@winston.wan/burn-your-money",
3
+ "version": "3.0.2",
4
+ "description": "💸 Burn Your Money - 实时显示 Claude Code 的 token 消耗,看着你的钱包燃烧!",
5
+ "main": "src/statusline.js",
6
+ "scripts": {
7
+ "postinstall": "node install.js",
8
+ "postuninstall": "node uninstall.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/winston-wwzhen/burn-your-money.git"
13
+ },
14
+ "keywords": [
15
+ "claude-code",
16
+ "token-monitor",
17
+ "statusline",
18
+ "claude",
19
+ "ai",
20
+ "cost-tracker",
21
+ "burn-money"
22
+ ],
23
+ "author": "winston-wwzhen",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://github.com/winston-wwzhen/burn-your-money/issues"
27
+ },
28
+ "homepage": "https://github.com/winston-wwzhen/burn-your-money#readme"
29
+ }
package/src/statusline.js CHANGED
@@ -166,9 +166,69 @@ function main() {
166
166
  const now = Math.floor(Date.now() / 1000);
167
167
  let historyData = readJsonFile(HISTORY_CACHE, {});
168
168
 
169
+ // 如果缓存过期(超过 5 分钟),重新获取
170
+ const CACHE_EXPIRY = 300; // 5 分钟
171
+ if (!historyData._cache_time || (now - historyData._cache_time) > CACHE_EXPIRY) {
172
+ try {
173
+ const { execSync } = require('child_process');
174
+ const scriptPath = path.join(__dirname, 'token-history.js');
175
+ // 使用更兼容的方式执行脚本
176
+ const freshData = execSync(`node "${scriptPath}" summary`, {
177
+ encoding: 'utf8',
178
+ stdio: ['ignore', 'pipe', 'ignore']
179
+ });
180
+ historyData = JSON.parse(freshData);
181
+ historyData._cache_time = now;
182
+ writeJsonFile(HISTORY_CACHE, historyData);
183
+ } catch (e) {
184
+ // 如果获取失败,尝试直接读取 stats-cache.json 作为降级方案
185
+ try {
186
+ const statsCache = path.join(os.homedir(), '.claude', 'stats-cache.json');
187
+ const stats = JSON.parse(fs.readFileSync(statsCache, 'utf8'));
188
+
189
+ // 从 stats-cache.json 构建基本数据
190
+ const totalInput = Object.values(stats.modelUsage || {}).reduce((sum, m) => sum + (m.inputTokens || 0), 0);
191
+ const totalOutput = Object.values(stats.modelUsage || {}).reduce((sum, m) => sum + (m.outputTokens || 0), 0);
192
+ const totalCache = Object.values(stats.modelUsage || {}).reduce((sum, m) => sum + (m.cacheReadInputTokens || 0), 0);
193
+ const totalTokens = totalInput + totalOutput + totalCache;
194
+ const totalCost = (totalInput / 1000000 * 3) + (totalOutput / 1000000 * 15) + (totalCache / 1000000 * 0.3);
195
+
196
+ historyData = {
197
+ total_tokens_all: totalTokens,
198
+ total_cost: totalCost.toFixed(2),
199
+ today_tokens: 0,
200
+ today_cost: '0.00',
201
+ week_tokens: 0,
202
+ week_cost: '0.00',
203
+ month_tokens: 0,
204
+ month_cost: '0.00',
205
+ _cache_time: now
206
+ };
207
+ writeJsonFile(HISTORY_CACHE, historyData);
208
+ } catch (e2) {
209
+ // 如果降级方案也失败,使用旧缓存或默认值
210
+ if (!historyData || !historyData.total_tokens_all) {
211
+ historyData = {
212
+ total_tokens_all: 0,
213
+ total_cost: '0.00',
214
+ today_tokens: 0,
215
+ today_cost: '0.00',
216
+ _cache_time: now
217
+ };
218
+ }
219
+ }
220
+ }
221
+ }
222
+
169
223
  // 如果缓存不存在或无效,使用默认值(但保留已有数据)
170
224
  if (!historyData || typeof historyData !== 'object') {
171
- historyData = {};
225
+ historyData = {
226
+ total_tokens_all: 0,
227
+ total_cost: '0.00',
228
+ today_tokens: 0,
229
+ today_cost: '0.00',
230
+ _cache_time: now
231
+ };
172
232
  }
173
233
 
174
234
  // 确保 _cache_time 存在(如果是旧缓存,添加时间戳)
@@ -176,34 +236,42 @@ function main() {
176
236
  historyData._cache_time = now;
177
237
  }
178
238
 
179
- // 今日数据持久化
239
+ // 使用历史数据的今日统计(包含缓存 tokens)
240
+ const historyTodayTokens = historyData.today_tokens || 0;
241
+ const historyTodayCost = parseFloat(historyData.today_cost || 0);
242
+
243
+ // 今日数据持久化(用于当前会话增量)
180
244
  const todayDate = new Date().toISOString().split('T')[0];
181
245
  ensureDir(TODAY_STATE);
182
246
  const todayState = readJsonFile(TODAY_STATE, {
183
247
  date: todayDate,
184
- tokens: 0,
185
- cost: 0,
248
+ tokens: historyTodayTokens,
249
+ cost: historyTodayCost,
186
250
  last_session_tokens: 0,
187
251
  last_session_cost: 0
188
252
  });
189
253
 
190
- // 如果是新的一天,重置
254
+ // 如果是新的一天,重置为历史数据
191
255
  if (todayState.date !== todayDate) {
192
256
  todayState.date = todayDate;
193
- todayState.tokens = 0;
194
- todayState.cost = 0;
257
+ todayState.tokens = historyTodayTokens;
258
+ todayState.cost = historyTodayCost;
195
259
  todayState.last_session_tokens = 0;
196
260
  todayState.last_session_cost = 0;
197
261
  }
198
262
 
199
- // 计算增量
263
+ // 计算增量(当前会话相对于历史数据的增量)
200
264
  let tokenIncrement = currentSessionTokens - (todayState.last_session_tokens || 0);
201
- if (tokenIncrement < 0) tokenIncrement = 0;
265
+ if (tokenIncrement < 0) {
266
+ tokenIncrement = currentSessionTokens;
267
+ }
202
268
 
203
269
  let costIncrement = currentCost - (todayState.last_session_cost || 0);
204
- if (costIncrement < 0) costIncrement = 0;
270
+ if (costIncrement < 0 || todayState.last_session_tokens === 0) {
271
+ costIncrement = currentCost;
272
+ }
205
273
 
206
- // 更新今日数据
274
+ // 新的今日数据 = 历史基础 + 当前增量
207
275
  const newTodayTokens = (todayState.tokens || 0) + tokenIncrement;
208
276
  const newTodayCost = (todayState.cost || 0) + costIncrement;
209
277
 
@@ -215,9 +283,9 @@ function main() {
215
283
  last_session_cost: currentCost
216
284
  });
217
285
 
218
- // 计算总计
219
- const totalTokens = (historyData.total_tokens_all || 0) + currentSessionTokens;
220
- const totalCost = (historyData.total_cost || 0) + currentCost;
286
+ // 计算总计(使用历史数据 + 当前会话)
287
+ const totalTokens = (historyData.total_tokens_all || 0);
288
+ const totalCost = parseFloat(historyData.total_cost || 0);
221
289
 
222
290
  // 检查是否超过警报阈值
223
291
  const isAlert = newTodayCost >= config.alert_daily;
package/nul DELETED
File without changes
@@ -1,23 +0,0 @@
1
- ---
2
- name: burn-your-money-uninstall
3
- description: 🗑️ 完全卸载 Burn Your Money 插件
4
- ---
5
-
6
- # 🗑️ Burn Your Money - 卸载
7
-
8
- 我将帮你完全卸载 Burn Your Money 插件,包括:
9
- - 删除所有插件文件
10
- - 移除 settings.json 中的配置
11
-
12
- 请执行以下命令:
13
-
14
- ```bash
15
- node ~/.claude/scripts/token-history.js uninstall
16
- ```
17
-
18
- 卸载完成后请重启 Claude Code。
19
-
20
- 如果你是通过 npm 全局安装的,也可以运行:
21
- ```bash
22
- npm uninstall -g @winston.wan/burn-your-money
23
- ```