feat(provider): 支持 Claude 第三方 Coding Plan 配额对接#12
Open
MVP2142 wants to merge 5 commits into
Open
Conversation
CC 自 0.4.5 开始在 statusLine payload 中上报配额数据后, load_rate_limits() 因优先返回官方数据,导致第三方提供者(如 opencode)的配额值一直被跳过。状态栏脚本也同样只在 CC 未上报时 才查提供者。 修复:load_rate_limits() 改为提供者优先、官方降级;状态栏脚本 改为始终查询 load_rate_limits(),保证两边数据一致。
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.
Summary
通过 API Key 使用第三方平台(如 OpenCode)时,CC 不会自动注入配额数据,状态栏看不到 5h/7d/月用量。本 PR 新增可扩展的 Provider 架构,支持外部脚本注入配额数据并在状态栏和
tt status中显示。效果样例
Changes
Provider 架构(新增 3 文件)
adapters/providers/base.py—RateProvider抽象基类、ProviderRateData中间格式、@register_provider装饰器注册表、文件缓存(~/.cache/token-tracker/,TTL 控制)adapters/providers/script.py—ScriptProvider,通过subprocess执行用户配置的外部脚本,解析 stdout JSON,支持超时和缓存命中adapters/providers/__init__.py— 导出工厂函数create_provider(),自动发现已注册 provider链式配额查询(修改 2 文件)
adapters/types.py—RateLimits增加monthly_pct/monthly_resets_at字段adapters/rate_limits.py—load_rate_limits()改为链式查询:官方配额 > 第三方 provider > 官方 fallback;支持 model overlay(官方有模型名但无配额时,模型名覆盖 provider 结果)CLI 诊断 & 状态栏联动(修改 2 文件)
cli.py— 新增tt quota诊断命令,输出配置/官方/第三方状态;--debug显示脱敏配置详情;自动触发状态栏脚本重烘焙hooks.py— CC statusline 脚本内嵌 provider fallback(官方无配额时自动调用load_rate_limits());修复settings.json陈旧脚本路径的自动检测 + 修正(_cc_settings_path_stale,_fix_cc_settings_path)文档(修改 2 文件)
README.md/README_EN.md— 新增「第三方配额对接」章节测试(新增 1 文件)
tests/test_providers.py— 19 个用例覆盖注册/缓存/超时/非法 JSON/退出码/链式优先级/model overlay配置方式
创建
~/.claude/tt-config.json:{ "rate_provider": { "type": "script", "command": "python ~/.claude/tt-opencode-quota.py", "cache_ttl": 60, "timeout": 10 } }typescriptcommandcache_ttl60timeout10脚本输出格式
自定义脚本需输出以下 JSON 到 stdout(各窗口字段均可选):
{ "five_hour": { "used_percentage": 31.5, "resets_at": 1718457600 }, "seven_day": { "used_percentage": 12.3, "resets_at": 1718889600 }, "monthly": { "used_percentage": 8.7, "resets_at": 1719753600 }, "source": "OpenCode" }used_percentage— 已用百分比(0-100)resets_at— UTC 时间戳,重置时间source— 来源标识,显示在tt status和状态栏中OpenCode 脚本样例
创建
~/.claude/tt-opencode-quota.py:诊断命令
数据优先级
官方注入配额(CC 订阅模式)> 第三方 provider > 官方仅模型信息(fallback)。CC 状态栏在检测到无官方配额时自动走 provider 链式查询。
Test