增加 token 计算 & 计费 & 优化 UI#6
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
本 PR 为 CC Monitor 增加 transcript token 解析与按模型计费能力,并在菜单栏 UI 中展示“今日用量/成本”和历史趋势,同时完善 hooks 事件覆盖与打包资源。
Changes:
- 新增
cc_pricing.py与内置/可覆盖价格表,实现 token 统计、去重与成本计算 cc_monitor.py增强:DB schema 扩展、每日用量落库、通知激活、菜单栏展示 token/成本与历史趋势- 打包/分发更新:py2app / PyInstaller 资源补齐、构建脚本改进、README 重写并补充 Token & Pricing 说明
Reviewed changes
Copilot reviewed 11 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.py | py2app 增加 cc_pricing 与 prices.builtin.json 资源打包 |
| scripts/build_app.sh | py2app 构建输出改为临时目录并避免覆盖已有产物 |
| README.md | 文档重构:新增 Token/Pricing、Quick Start、Safety Notes、截图等 |
| prices.json.example | 新增用户自定义价格覆盖示例 |
| prices.builtin.json | 新增内置模型价格表 |
| install_hooks.py | hooks 覆盖扩展(含 PreToolUse/AskUserQuestion matcher)并复制依赖模块 |
| CCMonitor.spec | PyInstaller 增加价格资源与隐藏导入声明 |
| cc_pricing.py | 新增:usage 解析、去重、按日/按模型汇总、价格加载与格式化 |
| cc_monitor.py | DB/汇总/UI/通知大幅增强:token/成本与历史趋势展示、后台刷新用量 |
| cc_hook.py | hook 写库增强:记录 client bundle id、AskUserQuestion 处理、通知边沿逻辑调整 |
| assets/menubar_white.svg | 新增图标资源(白色) |
| assets/menubar_mono.svg | 新增图标资源(mono/currentColor) |
| assets/app_icon_color.svg | 新增彩色应用图标 SVG |
| .vscode/changelists.json | 新增 VS Code 本地变更清单文件 |
| .gitignore | 忽略 .vscode/ 与(意图).DS_Store |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+37
| # py2app / PyInstaller bundled app | ||
| if getattr(sys, "frozen", False): | ||
| exe_dir = os.path.dirname(os.path.abspath(sys.executable)) | ||
| cands.extend([ | ||
| os.path.join(exe_dir, "..", "Resources"), | ||
| os.path.join(exe_dir, "Resources"), | ||
| ]) |
Comment on lines
+331
to
+337
| FROM sessions | ||
| WHERE source='hook' | ||
| AND transcript_path IS NOT NULL | ||
| AND transcript_path != '' | ||
| AND ( | ||
| status != 'ENDED' | ||
| OR last_event_ts >= ? |
| else: | ||
| for s in sessions: | ||
| parent = rumps.MenuItem(_session_item_text(s)) | ||
| if cc_pricing: |
Comment on lines
+64
to
+78
| def _frontmost_bundle_id(): | ||
| bid = _bundle_id_from_env() | ||
| if bid: | ||
| return bid | ||
| try: | ||
| cp = subprocess.run([ | ||
| "osascript", "-e", | ||
| 'tell application "System Events" to get bundle identifier of first process whose frontmost is true' | ||
| ], check=False, capture_output=True, text=True) | ||
| out = (cp.stdout or "").strip() | ||
| if out: | ||
| return out | ||
| except Exception: | ||
| pass | ||
| return "" |
Comment on lines
+1
to
+6
| { | ||
| "changelists": [ | ||
| { | ||
| "name": "Default", | ||
| "files": [ | ||
| "CCMonitor.spec", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.