myccusage 1.7.0__tar.gz → 1.7.2__tar.gz

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 (34) hide show
  1. {myccusage-1.7.0 → myccusage-1.7.2}/PKG-INFO +1 -1
  2. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage.egg-info/PKG-INFO +1 -1
  3. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/__init__.py +1 -1
  4. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/base.py +26 -10
  5. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/hermes.py +73 -30
  6. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/workbuddy.py +12 -4
  7. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/cli.py +131 -15
  8. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/core.py +38 -2
  9. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/macos/build_app.sh +2 -2
  10. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/macos/main.swift +5 -8
  11. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/web/static/app.js +12 -2
  12. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/web/static/index.html +1 -1
  13. {myccusage-1.7.0 → myccusage-1.7.2}/pyproject.toml +1 -1
  14. {myccusage-1.7.0 → myccusage-1.7.2}/LICENSE +0 -0
  15. {myccusage-1.7.0 → myccusage-1.7.2}/README.md +0 -0
  16. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage.egg-info/SOURCES.txt +0 -0
  17. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage.egg-info/dependency_links.txt +0 -0
  18. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage.egg-info/entry_points.txt +0 -0
  19. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage.egg-info/top_level.txt +0 -0
  20. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/__main__.py +0 -0
  21. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/__init__.py +0 -0
  22. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/agy.py +0 -0
  23. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/claude.py +0 -0
  24. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/codex.py +0 -0
  25. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/grok.py +0 -0
  26. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/opencode.py +0 -0
  27. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/adapters/pi.py +0 -0
  28. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/macos/AppIcon.icns +0 -0
  29. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/macos/generate_icon.py +0 -0
  30. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/sync.py +0 -0
  31. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/web/__init__.py +0 -0
  32. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/web/server.py +0 -0
  33. {myccusage-1.7.0 → myccusage-1.7.2}/myccusage_lib/web/static/style.css +0 -0
  34. {myccusage-1.7.0 → myccusage-1.7.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: myccusage
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Multi-Agent session usage analytics and DeepSeek-V4.1-Flash cost estimator
5
5
  Author-email: Richard Huang <RichardHuang0001@users.noreply.github.com>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: myccusage
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Multi-Agent session usage analytics and DeepSeek-V4.1-Flash cost estimator
5
5
  Author-email: Richard Huang <RichardHuang0001@users.noreply.github.com>
6
6
  License: MIT License
@@ -3,4 +3,4 @@ myccusage: 多 AI 编程 Agent 本地会话用量分析与 DeepSeek-V4.1-Flash
3
3
  本包提供了从命令行接口到本地数据解析、Web 服务展示的完整实现。
4
4
  """
5
5
 
6
- __version__ = "1.7.0" # 定义项目的当前版本号,方便其他模块或发布脚本引用
6
+ __version__ = "1.7.2" # 定义项目的当前版本号,方便其他模块或发布脚本引用
@@ -19,9 +19,9 @@ _CANDIDATE_HOME_DIRS: list[str] | None = None
19
19
  # 模型维度:未识别到模型时使用的占位名(统一用字符串,避免 None 作为字典键带来的歧义)
20
20
  UNKNOWN_MODEL = "unknown"
21
21
 
22
- # 文件级持久缓存的 schema 版本。records 由 7 元组扩展为 8 元组(末尾追加 model),
23
- # 旧缓存必须失效,否则会混入缺少 model 的旧数据。版本不匹配时整体丢弃并重建一次。
24
- _FILE_CACHE_SCHEMA = 2
22
+ # 文件级持久缓存的 schema 版本。records 由 8 元组扩展为 9 元组(末尾追加 credit),
23
+ # 旧缓存必须失效,否则会混入缺少 credit 的旧数据。版本不匹配时整体丢弃并重建一次。
24
+ _FILE_CACHE_SCHEMA = 3
25
25
 
26
26
  # 非真实模型的伪名(大小写不敏感),统一归入 UNKNOWN_MODEL
27
27
  _PSEUDO_MODELS = frozenset({"<synthetic>", "synthetic", "none", "null", "unknown", ""})
@@ -152,7 +152,7 @@ class BaseAgentAdapter:
152
152
  self._full_cache = (fingerprint, (daily_map, session_list))
153
153
 
154
154
  @staticmethod
155
- def _bump_model(models: dict, model: str, inp: int, cr: int, out: int, tot: int) -> None:
155
+ def _bump_model(models: dict, model: str, inp: int, cr: int, out: int, tot: int, credit: float = 0.0) -> None:
156
156
  """
157
157
  模型维度累加(含调用次数)。
158
158
 
@@ -167,25 +167,28 @@ class BaseAgentAdapter:
167
167
  m = models[model] = {
168
168
  "inputTokens": 0, "cacheReadTokens": 0,
169
169
  "outputTokens": 0, "totalTokens": 0, "calls": 0,
170
+ "credit": 0.0,
170
171
  }
171
172
  m["inputTokens"] += inp
172
173
  m["cacheReadTokens"] += cr
173
174
  m["outputTokens"] += out
174
175
  m["totalTokens"] += tot
175
176
  m["calls"] += 1
177
+ if credit:
178
+ m["credit"] = round(m.get("credit", 0.0) + credit, 4)
176
179
 
177
180
  @staticmethod
178
181
  def _accumulate_records(records) -> tuple[dict[str, list[dict]], list[dict]]:
179
182
  """
180
183
  把记录流聚合为 (daily_map, session_list):
181
- - records 元素为 8 元组:
182
- (sessionId, 日期, ISO时间, 输入Token, 缓存读Token, 输出Token, 合计Token, 模型名)
184
+ - records 元素支持 8 元组或 9 元组 (兼容 WorkBuddy credit 字段):
185
+ (sessionId, 日期, ISO时间, 输入Token, 缓存读Token, 输出Token, 合计Token, 模型名, [credit])
183
186
  第 8 位模型名一律经 normalize_model_name() 归一化,未识别时用 UNKNOWN_MODEL。
184
187
  - daily_map: { "YYYY-MM-DD": [ 当日会话切片, ... ] },同日同会话自动合并累加
185
188
  - session_list: 每个会话的全生命周期累计
186
189
 
187
190
  除既有度量字段外,两类条目都额外携带 models 子结构(纯新增,既有字段一字不改):
188
- models = { 模型名: {inputTokens, cacheReadTokens, outputTokens, totalTokens, calls} }
191
+ models = { 模型名: {inputTokens, cacheReadTokens, outputTokens, totalTokens, calls, credit} }
189
192
 
190
193
  不变式(务必守恒,改造后须逐条验证):
191
194
  sum(models[m]["totalTokens"] for m in models) == totalTokens
@@ -201,7 +204,14 @@ class BaseAgentAdapter:
201
204
  sessions: dict[str, dict] = {}
202
205
  bump = BaseAgentAdapter._bump_model
203
206
 
204
- for sid, date_str, iso_str, inp, cr, out, tot, model in records:
207
+ for rec in records:
208
+ if len(rec) >= 9:
209
+ sid, date_str, iso_str, inp, cr, out, tot, model, credit = rec[:9]
210
+ credit = float(credit or 0.0)
211
+ else:
212
+ sid, date_str, iso_str, inp, cr, out, tot, model = rec[:8]
213
+ credit = 0.0
214
+
205
215
  # 1) 每日切片累加
206
216
  day = daily.get(date_str)
207
217
  if day is None:
@@ -215,6 +225,7 @@ class BaseAgentAdapter:
215
225
  "cacheReadTokens": 0,
216
226
  "outputTokens": 0,
217
227
  "totalTokens": 0,
228
+ "credit": 0.0,
218
229
  "lastActivity": iso_str,
219
230
  "models": {},
220
231
  }
@@ -222,9 +233,11 @@ class BaseAgentAdapter:
222
233
  ds["cacheReadTokens"] += cr
223
234
  ds["outputTokens"] += out
224
235
  ds["totalTokens"] += tot
236
+ if credit:
237
+ ds["credit"] = round(ds.get("credit", 0.0) + credit, 4)
225
238
  if iso_str > ds["lastActivity"]:
226
239
  ds["lastActivity"] = iso_str
227
- bump(ds["models"], model, inp, cr, out, tot)
240
+ bump(ds["models"], model, inp, cr, out, tot, credit)
228
241
 
229
242
  # 2) 会话全生命周期累加
230
243
  ss = sessions.get(sid)
@@ -235,6 +248,7 @@ class BaseAgentAdapter:
235
248
  "cacheReadTokens": 0,
236
249
  "outputTokens": 0,
237
250
  "totalTokens": 0,
251
+ "credit": 0.0,
238
252
  "lastActivity": iso_str,
239
253
  "models": {},
240
254
  }
@@ -242,9 +256,11 @@ class BaseAgentAdapter:
242
256
  ss["cacheReadTokens"] += cr
243
257
  ss["outputTokens"] += out
244
258
  ss["totalTokens"] += tot
259
+ if credit:
260
+ ss["credit"] = round(ss.get("credit", 0.0) + credit, 4)
245
261
  if iso_str > ss["lastActivity"]:
246
262
  ss["lastActivity"] = iso_str
247
- bump(ss["models"], model, inp, cr, out, tot)
263
+ bump(ss["models"], model, inp, cr, out, tot, credit)
248
264
 
249
265
  return ({d: list(day.values()) for d, day in daily.items()}, list(sessions.values()))
250
266
 
@@ -72,13 +72,24 @@ class HermesAdapter(BaseAgentAdapter):
72
72
  uri = f"file:{db}?mode=ro"
73
73
  conn = sqlite3.connect(uri, uri=True, timeout=3.0)
74
74
  c = conn.cursor()
75
- for row in c.execute("SELECT id, started_at, ended_at, title FROM sessions"):
76
- sid, st, et, title = row
77
- last_t = et or st
78
- if last_t:
79
- times[sid] = ts_to_iso(last_t)
80
- if title and title.strip():
81
- titles[sid] = title.strip()
75
+ cols = {r[1] for r in c.execute("PRAGMA table_info(sessions)")}
76
+ has_lat = "last_activity_at" in cols
77
+ if has_lat:
78
+ for row in c.execute("SELECT id, started_at, ended_at, last_activity_at, title FROM sessions"):
79
+ sid, st, et, lat, title = row
80
+ last_t = et or lat or st
81
+ if last_t:
82
+ times[sid] = ts_to_iso(last_t)
83
+ if title and title.strip():
84
+ titles[sid] = title.strip()
85
+ else:
86
+ for row in c.execute("SELECT id, started_at, ended_at, title FROM sessions"):
87
+ sid, st, et, title = row
88
+ last_t = et or st
89
+ if last_t:
90
+ times[sid] = ts_to_iso(last_t)
91
+ if title and title.strip():
92
+ titles[sid] = title.strip()
82
93
  conn.close()
83
94
  except Exception:
84
95
  pass
@@ -89,6 +100,7 @@ class HermesAdapter(BaseAgentAdapter):
89
100
  查询 Hermes 数据库提取统计数据,按时间正序返回每日切片和汇总。
90
101
  - 支持 today_only: 仅扫描今日活跃会话 (SQL 过滤提速)
91
102
  - 模型维度取 sessions.model(会话级)。
103
+ - 优先支持 last_activity_at 字段,确保常驻长会话在跨日活跃时不会被遗漏。
92
104
 
93
105
  关于 session_model_usage 表的取舍(实测结论):
94
106
  该表粒度更细(可表达"一个会话内用了多个模型")且自带 api_call_count,
@@ -114,6 +126,9 @@ class HermesAdapter(BaseAgentAdapter):
114
126
  conn = sqlite3.connect(uri, uri=True, timeout=3.0)
115
127
  c = conn.cursor()
116
128
 
129
+ cols = {r[1] for r in c.execute("PRAGMA table_info(sessions)")}
130
+ has_lat = "last_activity_at" in cols
131
+
117
132
  where_clauses = [
118
133
  "model IS NOT NULL",
119
134
  "TRIM(model) != ''",
@@ -122,31 +137,59 @@ class HermesAdapter(BaseAgentAdapter):
122
137
  params = []
123
138
  if today_only:
124
139
  min_ts = get_today_midnight_ts()
125
- where_clauses.append("(started_at >= ? OR ended_at >= ?)")
126
- params.extend([min_ts, min_ts])
140
+ if has_lat:
141
+ where_clauses.append("(started_at >= ? OR (ended_at IS NOT NULL AND ended_at >= ?) OR (last_activity_at IS NOT NULL AND last_activity_at >= ?))")
142
+ params.extend([min_ts, min_ts, min_ts])
143
+ else:
144
+ where_clauses.append("(started_at >= ? OR (ended_at IS NOT NULL AND ended_at >= ?))")
145
+ params.extend([min_ts, min_ts])
127
146
 
128
147
  where_sql = " AND ".join(where_clauses)
129
- sql = f"""
130
- SELECT
131
- id,
132
- started_at,
133
- ended_at,
134
- input_tokens,
135
- output_tokens,
136
- cache_read_tokens,
137
- model
138
- FROM sessions
139
- WHERE {where_sql}
140
- ORDER BY started_at ASC
141
- """
142
- for row in c.execute(sql, params):
143
- sid, st, et, inp, out, cr, model = row
144
- act_time = et or st or 0
145
- date_str = ts_to_date_str(act_time) if act_time else "1970-01-01"
146
- iso_str = ts_to_iso(act_time) if act_time else ""
147
- tot = inp + cr + out
148
- records.append((sid, date_str, iso_str, inp, cr, out, tot,
149
- normalize_model_name(model)))
148
+ if has_lat:
149
+ sql = f"""
150
+ SELECT
151
+ id,
152
+ started_at,
153
+ ended_at,
154
+ last_activity_at,
155
+ input_tokens,
156
+ output_tokens,
157
+ cache_read_tokens,
158
+ model
159
+ FROM sessions
160
+ WHERE {where_sql}
161
+ ORDER BY started_at ASC
162
+ """
163
+ for row in c.execute(sql, params):
164
+ sid, st, et, lat, inp, out, cr, model = row
165
+ act_time = et or lat or st or 0
166
+ date_str = ts_to_date_str(act_time) if act_time else "1970-01-01"
167
+ iso_str = ts_to_iso(act_time) if act_time else ""
168
+ tot = inp + cr + out
169
+ records.append((sid, date_str, iso_str, inp, cr, out, tot,
170
+ normalize_model_name(model)))
171
+ else:
172
+ sql = f"""
173
+ SELECT
174
+ id,
175
+ started_at,
176
+ ended_at,
177
+ input_tokens,
178
+ output_tokens,
179
+ cache_read_tokens,
180
+ model
181
+ FROM sessions
182
+ WHERE {where_sql}
183
+ ORDER BY started_at ASC
184
+ """
185
+ for row in c.execute(sql, params):
186
+ sid, st, et, inp, out, cr, model = row
187
+ act_time = et or st or 0
188
+ date_str = ts_to_date_str(act_time) if act_time else "1970-01-01"
189
+ iso_str = ts_to_iso(act_time) if act_time else ""
190
+ tot = inp + cr + out
191
+ records.append((sid, date_str, iso_str, inp, cr, out, tot,
192
+ normalize_model_name(model)))
150
193
  conn.close()
151
194
  except Exception:
152
195
  pass
@@ -192,15 +192,23 @@ class WorkBuddyAdapter(BaseAgentAdapter):
192
192
  date_str = ms_to_date_str(ts)
193
193
  iso_str = ms_to_iso(ts)
194
194
 
195
- # 兼容 rawUsage 与 usage 两种特殊数据格式
195
+ # 兼容 rawUsage 与 usage 两种特殊数据格式并提取官方积分
196
+ credit = 0.0
196
197
  if ru:
197
198
  hit = ru.get("prompt_cache_hit_tokens", 0)
198
199
  miss = ru.get("prompt_cache_miss_tokens", 0)
199
200
  out = ru.get("completion_tokens", 0)
201
+ c_val = ru.get("credit")
202
+ if c_val is not None:
203
+ try:
204
+ credit = float(c_val)
205
+ except (ValueError, TypeError):
206
+ credit = 0.0
200
207
  else:
201
208
  if "input_tokens" in u:
202
- miss = u.get("input_tokens", 0)
203
- hit = 0
209
+ inp = u.get("input_tokens", 0)
210
+ hit = u.get("cache_read_input_tokens", 0)
211
+ miss = max(0, inp - hit)
204
212
  out = u.get("output_tokens", 0)
205
213
  else:
206
214
  inp = u.get("inputTokens", 0)
@@ -209,7 +217,7 @@ class WorkBuddyAdapter(BaseAgentAdapter):
209
217
  out = u.get("outputTokens", 0)
210
218
  tot = hit + miss + out
211
219
  model = normalize_model_name(pd.get("requestModelName") or pd.get("requestModelId") or pd.get("model"))
212
- records.append((sid, date_str, iso_str, miss, hit, out, tot, model))
220
+ records.append((sid, date_str, iso_str, miss, hit, out, tot, model, credit))
213
221
  except Exception:
214
222
  records = cached[2] if cached else []
215
223
  else:
@@ -145,6 +145,28 @@ def render_daily_table(data):
145
145
  display_name = data["displayName"]
146
146
  sort_by_tokens = data["sortByTokens"]
147
147
  sum_info = data["summary"]
148
+ is_workbuddy = (data.get("agent") == "workbuddy") or (sum_info.get("credit", 0.0) > 0)
149
+
150
+ # 预设各个数据列的固定宽度
151
+ w_rank = 5
152
+ w_time = 13
153
+ w_total = 8
154
+ w_input = 8
155
+ w_output = 8
156
+ w_cache = 8
157
+ w_hit = 7
158
+ w_credit = 10 if is_workbuddy else 0
159
+ w_cost = 10
160
+
161
+ # 计算非标题列的总宽度(包含列之间的分隔符宽度等预估常数)
162
+ extra_sep = 3 if is_workbuddy else 0
163
+ fixed_width = w_rank + w_time + w_total + w_input + w_output + w_cache + w_hit + w_credit + w_cost + 24 + extra_sep
164
+
165
+ # 将剩余空间全部分配给会话标题列,并保证最小宽度为 20
166
+ w_title = max(20, term_width - fixed_width)
167
+ total_table_width = min(term_width, fixed_width + w_title)
168
+
169
+ credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
148
170
 
149
171
  # 分支一:按 Token 消耗量排序的展示逻辑(不分层级,平铺展示)
150
172
  if sort_by_tokens:
@@ -152,6 +174,12 @@ def render_daily_table(data):
152
174
  print("=" * total_table_width)
153
175
  print(f" {display_name} 单日会话消耗排行 (共 {len(flat_records)} 条日度会话记录 - 按当日消耗排序)")
154
176
  print(" * 模式:[-d / --daily] 每日会话账本(不混淆前日用量,仅算当日实际消耗)")
177
+ if is_workbuddy:
178
+ total_credit = sum_info.get("credit", 0.0)
179
+ total_cost = sum_info.get("costCny", 0.0)
180
+ ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效价格 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
181
+ print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
182
+ print(f" * 换算:{ratio_desc}")
155
183
  print("=" * total_table_width)
156
184
 
157
185
  # 拼接表头,严格使用之前分配的各列宽度进行居中或对齐
@@ -163,6 +191,7 @@ def render_daily_table(data):
163
191
  pad_str("Output", w_output, "right") + " │ " +
164
192
  pad_str("Cache", w_cache, "right") + " │ " +
165
193
  pad_str("Hitrate", w_hit, "right") + " │ " +
194
+ credit_hdr +
166
195
  pad_str("等效价格", w_cost, "right") + " │ " +
167
196
  pad_str("会话标题", w_title, "left")
168
197
  )
@@ -171,8 +200,8 @@ def render_daily_table(data):
171
200
 
172
201
  # 遍历扁平化的记录进行单行渲染
173
202
  for r in flat_records:
174
- # 根据动态分配的标题列宽进行智能截断
175
203
  t_str = truncate_title(r["title"], w_title)
204
+ credit_col = (pad_str(f"{r.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
176
205
  print(
177
206
  pad_str(str(r["index"]), w_rank, "center") + " │ " +
178
207
  pad_str(r["time"], w_time, "center") + " │ " +
@@ -181,12 +210,17 @@ def render_daily_table(data):
181
210
  pad_str(format_tokens(r["outputTokens"]), w_output, "right") + " │ " +
182
211
  pad_str(format_tokens(r["cacheTokens"]), w_cache, "right") + " │ " +
183
212
  pad_str(format_hitrate(r["cacheTokens"], r["inputTokens"]), w_hit, "right") + " │ " +
213
+ credit_col +
184
214
  pad_str(f"¥{r['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
185
215
  pad_str(t_str, w_title, "left")
186
216
  )
187
217
  print("─" * total_table_width)
188
218
 
189
219
  # 打印全周期合计行
220
+ sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
221
+ summary_label = f"共 {len(flat_records)} 条日度会话记录 (~${sum_info['costUsd']:.2f} USD)"
222
+ if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
223
+ summary_label = f"共 {len(flat_records)} 条日度会话记录 (1 积分 ≈ ¥{sum_info['costCny'] / sum_info['credit']:.3f}, ~${sum_info['costUsd']:.2f} USD)"
190
224
  print(
191
225
  pad_str("汇总", w_rank, "center") + " │ " +
192
226
  pad_str("--", w_time, "center") + " │ " +
@@ -195,8 +229,9 @@ def render_daily_table(data):
195
229
  pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
196
230
  pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
197
231
  pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
232
+ sum_credit_col +
198
233
  pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
199
- pad_str(f"共 {len(flat_records)} 条日度会话记录 (~${sum_info['costUsd']:.2f} USD)", w_title, "left")
234
+ pad_str(summary_label, w_title, "left")
200
235
  )
201
236
  print("=" * total_table_width)
202
237
  return
@@ -205,7 +240,15 @@ def render_daily_table(data):
205
240
  print("=" * total_table_width)
206
241
  print(f" {display_name} 每日会话账本 (共 {data['activeDaysCount']} 个活动日, {data['totalRecordsCount']} 笔日度会话)")
207
242
  print(" * 模式:[-d / --daily 默认] 不混淆前日用量,精准分列“此日、此 Session”的实际发生额")
208
- print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
243
+ if is_workbuddy:
244
+ total_credit = sum_info.get("credit", 0.0)
245
+ total_cost = sum_info.get("costCny", 0.0)
246
+ ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效基准 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
247
+ print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
248
+ print(" * 计价:DeepSeek-V4.1-Flash 高峰期等效基准 (供比对官方积分与理论 API 成本换算)")
249
+ print(f" * 换算:{ratio_desc}")
250
+ else:
251
+ print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
209
252
  print("=" * total_table_width)
210
253
 
211
254
  # 渲染主表头
@@ -217,6 +260,7 @@ def render_daily_table(data):
217
260
  pad_str("Output", w_output, "right") + " │ " +
218
261
  pad_str("Cache", w_cache, "right") + " │ " +
219
262
  pad_str("Hitrate", w_hit, "right") + " │ " +
263
+ credit_hdr +
220
264
  pad_str("等效价格", w_cost, "right") + " │ " +
221
265
  pad_str("会话标题", w_title, "left")
222
266
  )
@@ -229,6 +273,7 @@ def render_daily_table(data):
229
273
  # 渲染第一级:最细粒度的单笔会话记录
230
274
  for r in day["records"]:
231
275
  t_str = truncate_title(r["title"], w_title)
276
+ credit_col = (pad_str(f"{r.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
232
277
  row = (
233
278
  pad_str(str(r["index"]), w_rank, "center") + " │ " +
234
279
  pad_str(r["time"], w_time, "center") + " │ " +
@@ -237,6 +282,7 @@ def render_daily_table(data):
237
282
  pad_str(format_tokens(r["outputTokens"]), w_output, "right") + " │ " +
238
283
  pad_str(format_tokens(r["cacheTokens"]), w_cache, "right") + " │ " +
239
284
  pad_str(format_hitrate(r["cacheTokens"], r["inputTokens"]), w_hit, "right") + " │ " +
285
+ credit_col +
240
286
  pad_str(f"¥{r['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
241
287
  pad_str(t_str, w_title, "left")
242
288
  )
@@ -245,6 +291,7 @@ def render_daily_table(data):
245
291
  # 渲染第二级:日小计(统计当日内所有会话的消耗汇总)
246
292
  day_short = day["date"][5:] if len(day["date"]) >= 10 else day["date"]
247
293
  day_time_label = f"{day_short}({day['weekday']}) 小计"
294
+ day_credit_col = (pad_str(f"{day.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
248
295
  day_subtotal_row = (
249
296
  pad_str("日计", w_rank, "center") + " │ " +
250
297
  pad_str(day_time_label, w_time, "center") + " │ " +
@@ -253,6 +300,7 @@ def render_daily_table(data):
253
300
  pad_str(format_tokens(day["outputTokens"]), w_output, "right") + " │ " +
254
301
  pad_str(format_tokens(day["cacheTokens"]), w_cache, "right") + " │ " +
255
302
  pad_str(format_hitrate(day["cacheTokens"], day["inputTokens"]), w_hit, "right") + " │ " +
303
+ day_credit_col +
256
304
  pad_str(f"¥{day['costCny']:.2f}", w_cost, "right") + " │ " +
257
305
  pad_str(f"当日净消耗 ({day['count']} 笔会话)", w_title, "left")
258
306
  )
@@ -261,6 +309,7 @@ def render_daily_table(data):
261
309
  print("·" * total_table_width)
262
310
 
263
311
  # 渲染第三级:周小计(统计当周内所有活动日的消耗汇总)
312
+ week_credit_col = (pad_str(f"{week.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
264
313
  week_subtotal_row = (
265
314
  pad_str("周计", w_rank, "center") + " │ " +
266
315
  pad_str(f"{week['weekKey']} 小计", w_time, "center") + " │ " +
@@ -269,6 +318,7 @@ def render_daily_table(data):
269
318
  pad_str(format_tokens(week["outputTokens"]), w_output, "right") + " │ " +
270
319
  pad_str(format_tokens(week["cacheTokens"]), w_cache, "right") + " │ " +
271
320
  pad_str(format_hitrate(week["cacheTokens"], week["inputTokens"]), w_hit, "right") + " │ " +
321
+ week_credit_col +
272
322
  pad_str(f"¥{week['costCny']:.2f}", w_cost, "right") + " │ " +
273
323
  pad_str(f"本周净消耗 ({week['count']} 笔会话)", w_title, "left")
274
324
  )
@@ -277,6 +327,12 @@ def render_daily_table(data):
277
327
  print("─" * total_table_width)
278
328
 
279
329
  # 渲染第四级:全周期合计(对所有历史数据的全局统计汇总)
330
+ sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
331
+ summary_label = f"全周期净消耗 (~${sum_info['costUsd']:.2f} USD)"
332
+ if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
333
+ cr = sum_info['credit']
334
+ cy = sum_info['costCny']
335
+ summary_label = f"全周期净消耗 (1 积分 ≈ ¥{cy / cr:.3f} 等效基准, ~${sum_info['costUsd']:.2f} USD)"
280
336
  grand_total_row = (
281
337
  pad_str("汇总", w_rank, "center") + " │ " +
282
338
  pad_str("全周期合计", w_time, "center") + " │ " +
@@ -285,8 +341,9 @@ def render_daily_table(data):
285
341
  pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
286
342
  pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
287
343
  pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
344
+ sum_credit_col +
288
345
  pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
289
- pad_str(f"全周期净消耗 (~${sum_info['costUsd']:.2f} USD)", w_title, "left")
346
+ pad_str(summary_label, w_title, "left")
290
347
  )
291
348
  print(grand_total_row)
292
349
  print("=" * total_table_width)
@@ -295,6 +352,8 @@ def render_session_table(data):
295
352
  """渲染项目总览模式的终端表格"""
296
353
  # 动态获取终端宽度,实现响应式排版
297
354
  term_width = shutil.get_terminal_size((118, 24)).columns
355
+ sum_info = data["summary"]
356
+ is_workbuddy = (data.get("agent") == "workbuddy") or (data.get("agentType") == "workbuddy") or (sum_info.get("credit", 0.0) > 0)
298
357
 
299
358
  # 预设固定的字段宽度
300
359
  w_rank = 5
@@ -304,23 +363,32 @@ def render_session_table(data):
304
363
  w_output = 8
305
364
  w_cache = 8
306
365
  w_hit = 7
366
+ w_credit = 10 if is_workbuddy else 0
307
367
  w_cost = 11
308
368
 
309
369
  # 计算并分配标题列所需的剩余宽度
310
- fixed_width = w_rank + w_time + w_total + w_input + w_output + w_cache + w_hit + w_cost + 24
311
- w_title = max(24, term_width - fixed_width)
370
+ extra_sep = 3 if is_workbuddy else 0
371
+ fixed_width = w_rank + w_time + w_total + w_input + w_output + w_cache + w_hit + w_credit + w_cost + 24 + extra_sep
372
+ w_title = max(20, term_width - fixed_width)
312
373
  total_table_width = min(term_width, fixed_width + w_title)
313
374
 
314
375
  display_name = data["displayName"]
315
376
  sort_by_tokens = data["sortByTokens"]
316
377
  sum_info = data["summary"]
317
378
  sessions = data["flatRecords"]
379
+ credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
318
380
 
319
381
  # 排行榜分支:按 Token 全局排序平铺展示
320
382
  if sort_by_tokens:
321
383
  print("=" * total_table_width)
322
384
  print(f" {display_name} 项目/会话总用量排行 (共 {len(sessions)} 个 Session - 按全生命周期 Token 消耗降序)")
323
385
  print(" * 模式:[-s / --session] 专注每个任务/Project 的全生命周期总耗费")
386
+ if is_workbuddy:
387
+ total_credit = sum_info.get("credit", 0.0)
388
+ total_cost = sum_info.get("costCny", 0.0)
389
+ ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效价格 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
390
+ print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
391
+ print(f" * 换算:{ratio_desc}")
324
392
  print("=" * total_table_width)
325
393
  header = (
326
394
  pad_str("序号", w_rank, "center") + " │ " +
@@ -330,6 +398,7 @@ def render_session_table(data):
330
398
  pad_str("Output", w_output, "right") + " │ " +
331
399
  pad_str("Cache", w_cache, "right") + " │ " +
332
400
  pad_str("Hitrate", w_hit, "right") + " │ " +
401
+ credit_hdr +
333
402
  pad_str("等效价格", w_cost, "right") + " │ " +
334
403
  pad_str("会话标题", w_title, "left")
335
404
  )
@@ -339,6 +408,7 @@ def render_session_table(data):
339
408
  # 遍历汇总后的会话进行展示
340
409
  for s in sessions:
341
410
  t_str = truncate_title(s["title"], w_title)
411
+ credit_col = (pad_str(f"{s.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
342
412
  print(
343
413
  pad_str(str(s["index"]), w_rank, "center") + " │ " +
344
414
  pad_str(s["time"], w_time, "center") + " │ " +
@@ -347,12 +417,17 @@ def render_session_table(data):
347
417
  pad_str(format_tokens(s["outputTokens"]), w_output, "right") + " │ " +
348
418
  pad_str(format_tokens(s["cacheTokens"]), w_cache, "right") + " │ " +
349
419
  pad_str(format_hitrate(s["cacheTokens"], s["inputTokens"]), w_hit, "right") + " │ " +
420
+ credit_col +
350
421
  pad_str(f"¥{s['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
351
422
  pad_str(t_str, w_title, "left")
352
423
  )
353
424
  print("─" * total_table_width)
354
425
 
355
426
  # 打印全周期合计行
427
+ sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
428
+ summary_label = f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)"
429
+ if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
430
+ summary_label = f"共 {len(sessions)} 个项目会话 (1 积分 ≈ ¥{sum_info['costCny'] / sum_info['credit']:.3f}, ~${sum_info['costUsd']:.2f} USD)"
356
431
  print(
357
432
  pad_str("汇总", w_rank, "center") + " │ " +
358
433
  pad_str("--", w_time, "center") + " │ " +
@@ -361,8 +436,9 @@ def render_session_table(data):
361
436
  pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
362
437
  pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
363
438
  pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
439
+ sum_credit_col +
364
440
  pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
365
- pad_str(f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)", w_title, "left")
441
+ pad_str(summary_label, w_title, "left")
366
442
  )
367
443
  print("=" * total_table_width)
368
444
  return
@@ -371,7 +447,15 @@ def render_session_table(data):
371
447
  print("=" * total_table_width)
372
448
  print(f" {display_name} 项目/会话总览 (共 {len(sessions)} 个 Session - 全生命周期累计消耗)")
373
449
  print(" * 模式:[-s / --session] 专注每个任务/Project 的全生命周期总耗费(按最新访问时间排序)")
374
- print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
450
+ if is_workbuddy:
451
+ total_credit = sum_info.get("credit", 0.0)
452
+ total_cost = sum_info.get("costCny", 0.0)
453
+ ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效基准 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
454
+ print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
455
+ print(" * 计价:DeepSeek-V4.1-Flash 高峰期等效基准 (供比对官方积分与理论 API 成本换算)")
456
+ print(f" * 换算:{ratio_desc}")
457
+ else:
458
+ print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
375
459
  print("=" * total_table_width)
376
460
 
377
461
  header = (
@@ -382,6 +466,7 @@ def render_session_table(data):
382
466
  pad_str("Output", w_output, "right") + " │ " +
383
467
  pad_str("Cache", w_cache, "right") + " │ " +
384
468
  pad_str("Hitrate", w_hit, "right") + " │ " +
469
+ credit_hdr +
385
470
  pad_str("等效价格", w_cost, "right") + " │ " +
386
471
  pad_str("会话标题", w_title, "left")
387
472
  )
@@ -397,6 +482,7 @@ def render_session_table(data):
397
482
  # 第一级:呈现单个项目的累计统计概况
398
483
  for s in day["records"]:
399
484
  t_str = truncate_title(s["title"], w_title)
485
+ credit_col = (pad_str(f"{s.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
400
486
  row = (
401
487
  pad_str(str(global_idx), w_rank, "center") + " │ " +
402
488
  pad_str(s["time"], w_time, "center") + " │ " +
@@ -405,6 +491,7 @@ def render_session_table(data):
405
491
  pad_str(format_tokens(s["outputTokens"]), w_output, "right") + " │ " +
406
492
  pad_str(format_tokens(s["cacheTokens"]), w_cache, "right") + " │ " +
407
493
  pad_str(format_hitrate(s["cacheTokens"], s["inputTokens"]), w_hit, "right") + " │ " +
494
+ credit_col +
408
495
  pad_str(f"¥{s['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
409
496
  pad_str(t_str, w_title, "left")
410
497
  )
@@ -414,6 +501,7 @@ def render_session_table(data):
414
501
  # 第二级:日小计
415
502
  day_short = day["date"][5:] if len(day["date"]) >= 10 else day["date"]
416
503
  day_time_label = f"{day_short}({day['weekday']}) 小计"
504
+ day_credit_col = (pad_str(f"{day.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
417
505
  day_subtotal_row = (
418
506
  pad_str("日计", w_rank, "center") + " │ " +
419
507
  pad_str(day_time_label, w_time, "center") + " │ " +
@@ -422,6 +510,7 @@ def render_session_table(data):
422
510
  pad_str(format_tokens(day["outputTokens"]), w_output, "right") + " │ " +
423
511
  pad_str(format_tokens(day["cacheTokens"]), w_cache, "right") + " │ " +
424
512
  pad_str(format_hitrate(day["cacheTokens"], day["inputTokens"]), w_hit, "right") + " │ " +
513
+ day_credit_col +
425
514
  pad_str(f"¥{day['costCny']:.2f}", w_cost, "right") + " │ " +
426
515
  pad_str(f"当日活跃项目 ({day['count']} 个会话)", w_title, "left")
427
516
  )
@@ -429,6 +518,7 @@ def render_session_table(data):
429
518
  print("·" * total_table_width)
430
519
 
431
520
  # 第三级:周小计
521
+ week_credit_col = (pad_str(f"{week.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
432
522
  week_subtotal_row = (
433
523
  pad_str("周计", w_rank, "center") + " │ " +
434
524
  pad_str(f"{week['weekKey']} 小计", w_time, "center") + " │ " +
@@ -437,6 +527,7 @@ def render_session_table(data):
437
527
  pad_str(format_tokens(week["outputTokens"]), w_output, "right") + " │ " +
438
528
  pad_str(format_tokens(week["cacheTokens"]), w_cache, "right") + " │ " +
439
529
  pad_str(format_hitrate(week["cacheTokens"], week["inputTokens"]), w_hit, "right") + " │ " +
530
+ week_credit_col +
440
531
  pad_str(f"¥{week['costCny']:.2f}", w_cost, "right") + " │ " +
441
532
  pad_str(f"本周活跃项目 ({week['count']} 个会话)", w_title, "left")
442
533
  )
@@ -444,6 +535,12 @@ def render_session_table(data):
444
535
  print("─" * total_table_width)
445
536
 
446
537
  # 第四级:全周期合计
538
+ sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
539
+ summary_label = f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)"
540
+ if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
541
+ cr = sum_info['credit']
542
+ cy = sum_info['costCny']
543
+ summary_label = f"共 {len(sessions)} 个项目会话 (1 积分 ≈ ¥{cy / cr:.3f} 等效基准, ~${sum_info['costUsd']:.2f} USD)"
447
544
  grand_total_row = (
448
545
  pad_str("汇总", w_rank, "center") + " │ " +
449
546
  pad_str("全周期合计", w_time, "center") + " │ " +
@@ -452,8 +549,9 @@ def render_session_table(data):
452
549
  pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
453
550
  pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
454
551
  pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
552
+ sum_credit_col +
455
553
  pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
456
- pad_str(f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)", w_title, "left")
554
+ pad_str(summary_label, w_title, "left")
457
555
  )
458
556
  print(grand_total_row)
459
557
  print("=" * total_table_width)
@@ -485,23 +583,27 @@ def render_quick_summary(summary):
485
583
  w_name = 24
486
584
  w_tok = 12
487
585
  w_hit = 10
488
- w_cost = 12
586
+ w_cost = 14
489
587
  w_sess = 10
490
588
  hdr = (
491
589
  pad_str("Agent 名称", w_name, "left") + " │ " +
492
590
  pad_str("今日Token", w_tok, "right") + " │ " +
493
591
  pad_str("缓存率", w_hit, "right") + " │ " +
494
- pad_str("等效费用", w_cost, "right") + " │ " +
592
+ pad_str("费用/积分", w_cost, "right") + " │ " +
495
593
  pad_str("会话数", w_sess, "right")
496
594
  )
497
595
  print(hdr)
498
596
  print("─" * total_table_width)
499
597
  for a in agents:
598
+ if a.get("id") == "workbuddy" and a.get("credit", 0.0) > 0:
599
+ cost_disp = f"{a['credit']:.1f}积/¥{a['costCny']:.2f}"
600
+ else:
601
+ cost_disp = f"¥{a['costCny']:.2f}"
500
602
  row = (
501
603
  pad_str(a["name"], w_name, "left") + " │ " +
502
604
  pad_str(format_tokens(a["totalTokens"]), w_tok, "right") + " │ " +
503
605
  pad_str(f"{a['hitRate']:.1f}%", w_hit, "right") + " │ " +
504
- pad_str(f"¥{a['costCny']:.2f}", w_cost, "right") + " │ " +
606
+ pad_str(cost_disp, w_cost, "right") + " │ " +
505
607
  pad_str(f"{a['sessionCount']} 笔", w_sess, "right")
506
608
  )
507
609
  print(row)
@@ -544,13 +646,24 @@ def render_model_table(data, agent_type=None):
544
646
  print("=" * term_width)
545
647
  return
546
648
 
649
+ is_workbuddy = (agent_type == "workbuddy")
547
650
  total_tok = totals.get("totalTokens", 0) or 1
548
- w_name, w_tok, w_pct, w_call, w_agent = 30, 12, 7, 10, 24
651
+ w_name = 28
652
+ w_tok = 11
653
+ w_pct = 7
654
+ w_credit = 10 if is_workbuddy else 0
655
+ w_call = 9
656
+ w_agent = 20
657
+
658
+ credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
659
+ extra_w = 13 if is_workbuddy else 0
660
+ term_width = max(term_width, 78 + extra_w)
549
661
 
550
662
  print(
551
663
  pad_str("模型名称", w_name, "left") + " │ " +
552
664
  pad_str("Token 总量", w_tok, "right") + " │ " +
553
665
  pad_str("占比", w_pct, "right") + " │ " +
666
+ credit_hdr +
554
667
  pad_str("调用次数", w_call, "right") + " │ " +
555
668
  pad_str("来源 Agent", w_agent, "left")
556
669
  )
@@ -560,17 +673,20 @@ def render_model_table(data, agent_type=None):
560
673
  agents_str = ",".join(m.get("agents", {}).keys())
561
674
  if display_len(agents_str) > w_agent:
562
675
  agents_str = agents_str[:w_agent - 2] + "…"
676
+ credit_col = (pad_str(f"{m.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
563
677
  print(
564
678
  pad_str(m.get("model", ""), w_name, "left") + " │ " +
565
679
  pad_str(format_tokens(m.get("totalTokens", 0)), w_tok, "right") + " │ " +
566
680
  pad_str(f"{m.get('totalTokens', 0) / total_tok * 100:.1f}%", w_pct, "right") + " │ " +
681
+ credit_col +
567
682
  pad_str(f"{m.get('calls', 0):,}", w_call, "right") + " │ " +
568
683
  pad_str(agents_str, w_agent, "left")
569
684
  )
570
685
 
571
686
  print("─" * term_width)
572
- print(f" 合计: {len(models)} 个模型 │ {format_tokens(totals.get('totalTokens', 0))} Tokens │ "
573
- f"{totals.get('calls', 0):,} 次调用")
687
+ credit_sum_str = f" │ {totals.get('credit', 0.0):.2f} 官方积分" if is_workbuddy else ""
688
+ print(f" 合计: {len(models)} 个模型 │ {format_tokens(totals.get('totalTokens', 0))} Tokens"
689
+ f"{credit_sum_str} │ {totals.get('calls', 0):,} 次调用")
574
690
 
575
691
  unknown_tok = totals.get("unknownTokens", 0)
576
692
  if unknown_tok:
@@ -202,6 +202,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
202
202
  grand_cache = 0
203
203
  grand_output = 0
204
204
  grand_cost = 0.0
205
+ grand_credit = 0.0
205
206
  total_records = 0
206
207
 
207
208
  daily_trend = []
@@ -227,6 +228,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
227
228
  "cacheTokens": 0,
228
229
  "outputTokens": 0,
229
230
  "costCny": 0.0,
231
+ "credit": 0.0,
230
232
  "count": 0,
231
233
  "days": []
232
234
  }
@@ -239,6 +241,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
239
241
  day_cache = 0
240
242
  day_output = 0
241
243
  day_cost = 0.0
244
+ day_credit = 0.0
242
245
  day_records = []
243
246
 
244
247
  for s in s_list:
@@ -247,6 +250,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
247
250
  ca = s.get("cacheReadTokens", 0)
248
251
  out = max(0, tot - (inp + ca))
249
252
  cost = calc_deepseek_cost(inp, ca, out)
253
+ credit = float(s.get("credit", 0.0) or 0.0)
250
254
 
251
255
  if not summary_only:
252
256
  sid = s.get("sessionId", "")
@@ -268,6 +272,8 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
268
272
  "outputTokens": out,
269
273
  "costCny": round(cost, 2),
270
274
  "costCnyRaw": cost,
275
+ "credit": round(credit, 2),
276
+ "creditRaw": credit,
271
277
  "remoteDevice": s.get("remoteDevice", ""),
272
278
  "isRemote": s.get("isRemote", False),
273
279
  }
@@ -280,6 +286,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
280
286
  day_cache += ca
281
287
  day_output += out
282
288
  day_cost += cost
289
+ day_credit += credit
283
290
 
284
291
  record_cnt = len(s_list) if summary_only else len(day_records)
285
292
 
@@ -293,6 +300,8 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
293
300
  "cacheTokens": day_cache,
294
301
  "outputTokens": day_output,
295
302
  "costCny": round(day_cost, 2),
303
+ "credit": round(day_credit, 2),
304
+ "creditRaw": day_credit,
296
305
  "records": day_records,
297
306
  "count": record_cnt
298
307
  }
@@ -302,6 +311,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
302
311
  weeks_dict[week_key]["cacheTokens"] += day_cache
303
312
  weeks_dict[week_key]["outputTokens"] += day_output
304
313
  weeks_dict[week_key]["costCny"] += day_cost
314
+ weeks_dict[week_key]["credit"] = weeks_dict[week_key].get("credit", 0.0) + day_credit
305
315
  weeks_dict[week_key]["count"] += record_cnt
306
316
 
307
317
  daily_trend.append({
@@ -312,6 +322,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
312
322
  "cacheTokens": day_cache,
313
323
  "outputTokens": day_output,
314
324
  "costCny": round(day_cost, 2),
325
+ "credit": round(day_credit, 2),
315
326
  "count": record_cnt
316
327
  })
317
328
 
@@ -320,12 +331,14 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
320
331
  grand_cache += day_cache
321
332
  grand_output += day_output
322
333
  grand_cost += day_cost
334
+ grand_credit += day_credit
323
335
  total_records += record_cnt
324
336
 
325
- # 格式化周小计的 costCny
337
+ # 格式化周小计的 costCny 与 credit
326
338
  weeks = list(weeks_dict.values())
327
339
  for w in weeks:
328
340
  w["costCny"] = round(w["costCny"], 2)
341
+ w["credit"] = round(w.get("credit", 0.0), 2)
329
342
 
330
343
  # 根据请求处理排序逻辑
331
344
  if sort_by_tokens and not summary_only:
@@ -348,6 +361,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
348
361
  "cacheTokens": t_ca,
349
362
  "outputTokens": today_entry["outputTokens"],
350
363
  "costCny": today_entry["costCny"],
364
+ "credit": today_entry.get("credit", 0.0),
351
365
  "cacheHitRate": round(t_ca / max(1, t_inp + t_ca) * 100, 1),
352
366
  "sessionCount": today_entry.get("count", 0)
353
367
  }
@@ -360,6 +374,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
360
374
  "cacheTokens": 0,
361
375
  "outputTokens": 0,
362
376
  "costCny": 0.0,
377
+ "credit": 0.0,
363
378
  "cacheHitRate": 0.0,
364
379
  "sessionCount": 0
365
380
  }
@@ -378,6 +393,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
378
393
  "outputTokens": grand_output,
379
394
  "costCny": round(grand_cost, 2),
380
395
  "costUsd": round(grand_cost / USD_CNY_RATE, 2),
396
+ "credit": round(grand_credit, 2),
381
397
  "cacheHitRate": hit_rate
382
398
  },
383
399
  "today": today_dict,
@@ -424,6 +440,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
424
440
  grand_cache = 0
425
441
  grand_output = 0
426
442
  grand_cost = 0.0
443
+ grand_credit = 0.0
427
444
 
428
445
  for s in raw_sessions:
429
446
  sid = s.get("sessionId", "")
@@ -436,6 +453,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
436
453
  ca = s.get("cacheReadTokens", 0)
437
454
  out = max(0, tot - (inp + ca))
438
455
  cost = calc_deepseek_cost(inp, ca, out)
456
+ credit = float(s.get("credit", 0.0) or 0.0)
439
457
  title = s.get("title") or resolve_title(sid, titles)
440
458
 
441
459
  grand_total += tot
@@ -443,6 +461,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
443
461
  grand_cache += ca
444
462
  grand_output += out
445
463
  grand_cost += cost
464
+ grand_credit += credit
446
465
 
447
466
  sessions.append({
448
467
  "sessionId": sid,
@@ -455,6 +474,8 @@ def get_session_data(agent_type, sort_by_tokens=False):
455
474
  "outputTokens": out,
456
475
  "costCny": round(cost, 2),
457
476
  "costCnyRaw": cost,
477
+ "credit": round(credit, 2),
478
+ "creditRaw": credit,
458
479
  "remoteDevice": s.get("remoteDevice", ""),
459
480
  "isRemote": s.get("isRemote", False),
460
481
  })
@@ -496,6 +517,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
496
517
  "cacheTokens": 0,
497
518
  "outputTokens": 0,
498
519
  "costCny": 0.0,
520
+ "credit": 0.0,
499
521
  "count": 0,
500
522
  "days_map": OrderedDict()
501
523
  }
@@ -510,6 +532,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
510
532
  "cacheTokens": 0,
511
533
  "outputTokens": 0,
512
534
  "costCny": 0.0,
535
+ "credit": 0.0,
513
536
  "records": []
514
537
  }
515
538
  d_entry = w_entry["days_map"][day_key]
@@ -519,12 +542,14 @@ def get_session_data(agent_type, sort_by_tokens=False):
519
542
  d_entry["cacheTokens"] += s["cacheTokens"]
520
543
  d_entry["outputTokens"] += s["outputTokens"]
521
544
  d_entry["costCny"] += s["costCnyRaw"]
545
+ d_entry["credit"] += s.get("creditRaw", 0.0)
522
546
 
523
547
  w_entry["totalTokens"] += s["totalTokens"]
524
548
  w_entry["inputTokens"] += s["inputTokens"]
525
549
  w_entry["cacheTokens"] += s["cacheTokens"]
526
550
  w_entry["outputTokens"] += s["outputTokens"]
527
551
  w_entry["costCny"] += s["costCnyRaw"]
552
+ w_entry["credit"] += s.get("creditRaw", 0.0)
528
553
  w_entry["count"] += 1
529
554
 
530
555
  weeks = []
@@ -532,6 +557,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
532
557
  days_list = []
533
558
  for d_k, d_v in w_v["days_map"].items():
534
559
  d_v["costCny"] = round(d_v["costCny"], 2)
560
+ d_v["credit"] = round(d_v.get("credit", 0.0), 2)
535
561
  d_v["count"] = len(d_v["records"])
536
562
  days_list.append(d_v)
537
563
  weeks.append({
@@ -541,6 +567,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
541
567
  "cacheTokens": w_v["cacheTokens"],
542
568
  "outputTokens": w_v["outputTokens"],
543
569
  "costCny": round(w_v["costCny"], 2),
570
+ "credit": round(w_v.get("credit", 0.0), 2),
544
571
  "count": w_v["count"],
545
572
  "days": days_list
546
573
  })
@@ -560,6 +587,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
560
587
  "outputTokens": grand_output,
561
588
  "costCny": round(grand_cost, 2),
562
589
  "costUsd": round(grand_cost / USD_CNY_RATE, 2),
590
+ "credit": round(grand_credit, 2),
563
591
  "cacheHitRate": hit_rate
564
592
  },
565
593
  "weeks": weeks,
@@ -862,6 +890,7 @@ def get_today_quick_summary(force_refresh=False):
862
890
  t_out = sum(s.get("outputTokens", 0) for s in slices)
863
891
  cost = calc_deepseek_cost(t_inp, t_cache, t_out)
864
892
  hit_rate = round(t_cache / max(1, t_inp + t_cache) * 100, 1)
893
+ t_credit = sum(float(s.get("credit", 0.0) or 0.0) for s in slices)
865
894
 
866
895
  latest_s = max(slices, key=lambda s: s.get("lastActivity", "") or "", default=None)
867
896
 
@@ -880,6 +909,7 @@ def get_today_quick_summary(force_refresh=False):
880
909
  "outputTokens": t_out,
881
910
  "hitRate": hit_rate,
882
911
  "costCny": round(cost, 2),
912
+ "credit": round(t_credit, 2),
883
913
  "sessionCount": len(slices),
884
914
  "latestSession": latest_s
885
915
  }
@@ -1015,12 +1045,15 @@ def get_model_breakdown(agent_type=None):
1015
1045
  "model": model,
1016
1046
  "inputTokens": 0, "cacheReadTokens": 0,
1017
1047
  "outputTokens": 0, "totalTokens": 0, "calls": 0,
1048
+ "credit": 0.0,
1018
1049
  }
1019
1050
  e["inputTokens"] += mv.get("inputTokens", 0)
1020
1051
  e["cacheReadTokens"] += mv.get("cacheReadTokens", 0)
1021
1052
  e["outputTokens"] += mv.get("outputTokens", 0)
1022
1053
  e["totalTokens"] += mv.get("totalTokens", 0)
1023
1054
  e["calls"] += mv.get("calls", 0)
1055
+ if "credit" in mv:
1056
+ e["credit"] = round(e.get("credit", 0.0) + float(mv["credit"] or 0.0), 4)
1024
1057
  return e
1025
1058
 
1026
1059
  def _bump_agent(entry: dict, aid: str, mv: dict) -> None:
@@ -1028,9 +1061,11 @@ def get_model_breakdown(agent_type=None):
1028
1061
  agents = entry.setdefault("agents", {})
1029
1062
  ag = agents.get(aid)
1030
1063
  if ag is None:
1031
- ag = agents[aid] = {"totalTokens": 0, "calls": 0}
1064
+ ag = agents[aid] = {"totalTokens": 0, "calls": 0, "credit": 0.0}
1032
1065
  ag["totalTokens"] += mv.get("totalTokens", 0)
1033
1066
  ag["calls"] += mv.get("calls", 0)
1067
+ if "credit" in mv:
1068
+ ag["credit"] = round(ag.get("credit", 0.0) + float(mv["credit"] or 0.0), 4)
1034
1069
 
1035
1070
  def _record(aid: str, d_str: str, mname: str, mv: dict) -> None:
1036
1071
  """把单个模型的用量同时记入 全局 / 按 Agent / 按日期 三个视图。"""
@@ -1090,6 +1125,7 @@ def get_model_breakdown(agent_type=None):
1090
1125
  "totals": {
1091
1126
  "models": len(models),
1092
1127
  "totalTokens": sum(x["totalTokens"] for x in models),
1128
+ "credit": round(sum(x.get("credit", 0.0) for x in models), 2),
1093
1129
  "calls": sum(x["calls"] for x in models),
1094
1130
  "unknownTokens": unknown.get("totalTokens", 0),
1095
1131
  "unknownCalls": unknown.get("calls", 0),
@@ -91,9 +91,9 @@ cat << 'EOF' > "${CONTENTS_DIR}/Info.plist"
91
91
  <key>CFBundlePackageType</key>
92
92
  <string>APPL</string>
93
93
  <key>CFBundleShortVersionString</key>
94
- <string>1.7.0</string>
94
+ <string>1.7.2</string>
95
95
  <key>CFBundleVersion</key>
96
- <string>1.7.0</string>
96
+ <string>1.7.2</string>
97
97
  <key>LSMinimumSystemVersion</key>
98
98
  <string>13.0</string>
99
99
  <key>LSUIElement</key>
@@ -487,16 +487,13 @@ struct FloatingPopoverView: View {
487
487
  Spacer()
488
488
  }
489
489
  } else {
490
- ScrollView {
491
- VStack(spacing: 2) {
492
- ForEach(state.summary.agents) { agent in
493
- AgentRowView(agent: agent, totalDayTokens: state.summary.totalTokens)
494
- }
490
+ VStack(spacing: 2) {
491
+ ForEach(state.summary.agents) { agent in
492
+ AgentRowView(agent: agent, totalDayTokens: state.summary.totalTokens)
495
493
  }
496
- .padding(.horizontal, 8)
497
- .padding(.vertical, 4)
498
494
  }
499
- .frame(maxHeight: 180)
495
+ .padding(.horizontal, 8)
496
+ .padding(.vertical, 4)
500
497
  }
501
498
  }
502
499
 
@@ -2012,7 +2012,13 @@
2012
2012
  el.subTotalTokens.textContent = `Input: ${formatTokens(sum.inputTokens)} | Cache: ${formatTokens(sum.cacheTokens)} | Output: ${formatTokens(sum.outputTokens)}`;
2013
2013
 
2014
2014
  el.valTotalCost.textContent = formatKpiMainCost(model, currentCost);
2015
- el.valTotalCostUsd.textContent = formatKpiSubCost(model, currentCost);
2015
+ if ((data.agent === 'workbuddy' || (sum.credit && sum.credit > 0)) && sum.credit > 0) {
2016
+ const cr = sum.credit;
2017
+ const ratio = currentCost > 0 ? (currentCost / cr).toFixed(4) : '0';
2018
+ el.valTotalCostUsd.innerHTML = `<span style="color:var(--accent-pink,#f43f5e);font-weight:600;">${cr.toFixed(2)} 官方积分</span> · 1积≈¥${ratio}`;
2019
+ } else {
2020
+ el.valTotalCostUsd.textContent = formatKpiSubCost(model, currentCost);
2021
+ }
2016
2022
 
2017
2023
  const costBadge = document.querySelector('.highlight-card .kpi-badge');
2018
2024
  if (costBadge) costBadge.textContent = model.name;
@@ -2747,6 +2753,10 @@
2747
2753
  const aCost = (a.inputTokens !== undefined || a.cacheTokens !== undefined || a.outputTokens !== undefined)
2748
2754
  ? calcCost(model, a.inputTokens, a.cacheTokens, a.outputTokens)
2749
2755
  : (a.costCny || 0);
2756
+ let costDisplay = formatInlineCost(model, aCost);
2757
+ if (a.id === 'workbuddy' && a.credit > 0) {
2758
+ costDisplay += ` · <span style="color:var(--accent-pink,#f43f5e);">${a.credit.toFixed(1)}积</span>`;
2759
+ }
2750
2760
  html += `
2751
2761
  <div class="agent-stat-card" data-agent="${a.id}">
2752
2762
  <div class="agent-stat-name">
@@ -2757,7 +2767,7 @@
2757
2767
  </div>
2758
2768
  <div class="agent-stat-values">
2759
2769
  <span class="agent-token-num">${formatTokens(a.totalTokens)}</span>
2760
- <span class="agent-cost-num">${formatInlineCost(model, aCost)}</span>
2770
+ <span class="agent-cost-num">${costDisplay}</span>
2761
2771
  </div>
2762
2772
  <div style="margin-top: 8px; font-size: 0.75rem; color: var(--text-muted);">
2763
2773
  Prompt 缓存命中率: <strong style="color: var(--color-cache);">${a.cacheHitRate}%</strong>
@@ -459,7 +459,7 @@
459
459
  <!-- 底部状态栏 -->
460
460
  <footer class="footer">
461
461
  <div class="footer-left">
462
- <span>myccusage v1.7.0</span>
462
+ <span>myccusage v1.7.2</span>
463
463
  <span class="divider">|</span>
464
464
  <span>本地缓存源: <code>~/.cache/myccusage/</code></span>
465
465
  </div>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "myccusage"
7
- version = "1.7.0"
7
+ version = "1.7.2"
8
8
  description = "Multi-Agent session usage analytics and DeepSeek-V4.1-Flash cost estimator"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
File without changes
File without changes
File without changes