Repository navigation
Conversation
ana52070
marked this pull request as ready for review
November 11, 2026 14:29
ana52070
force-pushed
the
feat/unified-agent-quota
branch
from
November 11, 2026 14:57
f45119e to
dbab66a
Compare
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.
feat(quota): 统一智能体零风控配额监控架构与智能设置联动开关
概述与背景 (Context & Problem)
此前社区对配额监控(Quota Probe)功能主要存在两项顾虑:
本 PR 提出并落地了一套面向所有智能体的统一「零网络/被动事件驱动」配额架构,彻底消除风控隐患,并在设置界面增设智能联动开关。
核心改动 (Key Changes)
1. 智能体设置面板:「官方账号配额监控」联动开关
codex、antigravity、claude_code、gemini、cursor、kimi_code、minimax_code、grok、cline、kiro、qoder、trae、command_code、zcode)中提供独立开关。CODEG_QUOTA_PROBE_MODE=auto),用户亦可手动关闭。2. Codex 100% 物理级零网络本地会话提取
<CODEX_HOME>/sessions/YYYY/MM/DD/rollout-*.jsonl尾部(读取最后 256 KB)解析 CLI 原生落盘的rate_limits结构(包含 5h 主窗口、7d 辅助窗口、重置时间与计划信息)。3. Google Antigravity 绝对零网络与账号零风控保障
daily-cloudcode-pa.googleapis.com)发送伪装 HTTP 请求的代码逻辑,避免触发 Google 平台的风控限流与异常行为拦截。4. 前端输入框状态栏徽章(事件驱动,无后台轮询)
setInterval后台定时轮询。prompting -> connected)时被动触发更新,辅以用户主动点击刷新。真实测试效果与截图 (Screenshots & Verification)
1. Antigravity 额度弹窗与双窗口状态
2. Codex 额度展示(5h 窗口 / 7d 窗口 / 重置倒计时)
3. 智能体设置界面联动开关
各 Agent 获取订阅配额的技术原理与实现细节 (Technical Deep Dive per Agent)
为了让架构更透明并方便社区伙伴进行审查与扩展,现将 Codeg 支持的全部 15 类智能体配额获取的具体技术思路、数据载体、触发时机与风控边界逐一拆解如下:
核心设计哲学:四大安全合规路径 (Architectural Categorization)
第一梯队:已落地并本地实机验证通过
1. OpenAI Codex (
codex)<CODEX_HOME>/sessions/YYYY/MM/DD/rollout-*.jsonl(默认~/.codex/sessions)~/.codex/auth.json(存放 ChatGPT OAuth access_token / refresh_token,判断auth_mode == "chatgpt")rollout-*.jsonl尾部追加一条 JSON 行:{"type": "event_msg", "payload": {"type": "token_count", "rate_limits": { ... }}}。payload.rate_limits.primary:5 小时滑动窗口限流。包含used_percent(已使用百分比浮点数,如 0.24)、resets_at(重置时间戳毫秒数,如 1741700000000)、window_minutes: 300。payload.rate_limits.secondary:7 天长周期周限流。包含used_percent、resets_at、window_minutes: 10080。payload.rate_limits.plan_type:账号订阅类型(如"plus"、"pro"、"team")。payload.rate_limits.credits:若有按量抵扣余额,包含剩余点数。std::io::Seek定位到当天最新活跃日志的倒数 256 KB,使用逆向行扫描器(Reverse Line Scanner)自底向上搜寻最近的一条包含"type":"token_count"的行进行反序列化。耗时 < 1ms,内存占用 < 300KB,零外部网络发包,零封号风险。2. Google Antigravity (
antigravity)~/.gemini/antigravity-engine/oauth_token.json、~/.gemini/antigravity-acp/acp_token.jsonUser-Agent: antigravity/2.23.1 <os>/<arch>并携带 token 主动 HTTP POST 请求 Google 内部私有 RPC 网关https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary。该行为属于典型的高风险非官方抓包行为,已被 Google 服务端反爬与异常行为检测系统(ABUSE / Rate Limit)标记,极易导致账号封禁或降级。agy_acp_server二进制进程在与 Codeg 通过 stdio 通信时,在 ACP 协议流中原生被动上报 turn completion telemetry;本地仅做离线 Token 文件存在性及有效期(expiry)解析,不向 Google 发起任何非标准的主动心跳探测。第二梯队:已具备开关联动与状态判断,供社区扩展接入
3. Claude Code (
claude_code)~/.claude.json(认证配置)及~/.claude/projects/<encoded-cwd>/<session-id>.jsonlturn/completed事件中附带原生的metadata.usage(包含input_tokens、cache_read_input_tokens、cache_creation_input_tokens、output_tokens)以及单轮估算成本cost_usd。/usage与/cost。Codeg 直接在其 ACP 会话上下文中监听状态通知,无须越权向 Anthropic API 发送非官方探测请求,杜绝 Session Token 失效与异地并发封禁。4. Cursor CLI (
cursor)%APPDATA%\Cursor\User\globalStorage\state.vscdb;macOS/Linux 为~/.config/Cursor/User/globalStorage/state.vscdb$CURSOR_CONFIG_DIR/cli-config.json(默认~/.cursor/cli-config.json)~/.cursor/chats/<md5-cwd>/<chat-uuid>/store.db或acp-sessions/<session-uuid>/store.dbstate.vscdb的ItemTable中。rusqlite以只读模式(OpenFlags::SQLITE_OPEN_READ_ONLY)执行:SELECT value FROM ItemTable WHERE key = 'cursorAuth/cachedUsage'fastRequests:当前月已使用的 Fast 请求次数;maxFastRequests:当月总额度(如 Pro 订阅为 500);startOfBillingPeriod/endOfBillingPeriod:当期账单结算日与额度刷新倒计时;membershipType:会员等级(pro/business/free)。cursor-agentCLI,则直接从store.db的 Protobuf 记录(agent.v1.ConversationStateStructure.token_details)读取used_tokens与max_tokens。完全本地读盘,无任何外部网络请求。5. TRAE CLI (
trae)<TRAE_HOME>/cli/sessions/YYYY/MM/DD/rollout-*.jsonl(受TRAE_HOME或TRAECLI_HOME环境变量重定向,默认~/.trae)traecli login(企业 SSO / 浏览器登录)或 PAT(TRAECLI_PERSONAL_ACCESS_TOKEN)src-tauri/src/parsers/trae_usage.rs所述:TRAE CLI 2.0(字节跳动基于 Codex 架构的衍生版)在每次模型调用时,会将精确计费数据持久化在本地 rollout 文件中。token_usage_record、SubAgentActivity、CollabAgentToolCall),提取每一轮的input_tokens、output_tokens、cache_read计数。6. Kimi Code (
kimi_code)$KIMI_CODE_HOME/(默认~/.kimi-code),配置位于config.toml,会话位于sessions/<workDirKey>/<sessionId>/agents/main/wire.jsonlcredentials.json或config.toml中的 Session Token)wire.jsonl中读取usage.record行,提取inputOther、output、inputCacheRead、inputCacheCreation,汇总单轮与会话总消耗。7. MiniMax Code (
minimax_code/mcode)~/.minimax/config.json或环境变量MINIMAX_HOMEmcode login登录获取的合法access_token与group_idaccess_token。https://api.minimax.chat/v1/user/usage),获取当前计费包余额、Coding 专属模型已消耗 Token 及剩余赠送额度。8. xAI Grok (
grok)~/.grok/auth.jsonx-ratelimit-limit-requests、x-ratelimit-remaining-requests、x-ratelimit-reset-requests。Resets in 42m),全程无额外网络开销,100% 真实。9. Cline CLI (
cline)%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\或~/.cline/cline-pass)驱动时,读取本地持久化账单缓存;10. Kiro CLI (
kiro)~/.kiro/credentials与~/.aws/sso/cache/*.jsonexpiresAt时间戳;11. Qoder (
qoder)~/.qoder/config.json12. Google Gemini CLI (
gemini)~/.gemini/或~/.config/gcloud/application_default_credentials.json13. Command Code (
command_code) & 14. ZCode (zcode)~/.commandcode/与~/.zcode/parsers::acp_native架构,在会话生命周期结束时捕获各 CLI 写入的计费元数据。第三梯队:第三方 API Key / 自定义端点(
open_code,open_claw,hermes,code_buddy,pi,deepseek等)ProbeDisabled,严禁向用户的自定义 Base URL 发送任何未知的配额探测请求,彻底避免 API Key 被截获或向第三方服务端泄露敏感凭证。自动化测试与质量保证 (Test Evidence)
Note
此次基于最新 upstream/main 重新整理为单 commit(移除了仓库内 3 张图片,正文保留 Release 托管图片链接),未在本地执行编译、构建与测试;旧 CI 记录属于历史 SHA,不能宣称覆盖新 SHA。
quota模块 25 项测试全部通过(覆盖本地 rollout 解析、路径识别、多 Agent 订阅状态判定等):ComposerQuotaBadge、web-transport配额端点、设置页开关与禁用状态等):eslint以及cargo clippy --all-targets -- -D warnings严格代码质量检查。社区共建号召与免安装测试包下载 (Call for Community Testing)
由于当前开发机仅具备 Codex 和 Google Antigravity 的官方订阅环境,其他支持官方订阅的 Agent(如
Claude Code、Cursor、Kimi Code、Grok等)已在代码架构上完成订阅模式判断与开关联动设计。为了方便社区伙伴参与测试与体验,我们特别准备了已编译好的 Windows 免安装便携版测试包,无需配置 Rust / Node 开发环境,解压即测:
codeg-win-x64-quota-preview.zip;codeg.exe即可启动客户端;