feat(cli): sanitized capacity snapshot export via quota --json - #2087
Draft
andrew05060414 wants to merge 2 commits into
Draft
feat(cli): sanitized capacity snapshot export via quota --json#2087andrew05060414 wants to merge 2 commits into
andrew05060414 wants to merge 2 commits into
Conversation
Add a read-only machine-readable capacity surface for external routing: - cockpit-core/capacity_snapshot: normalize antigravity + codex account quota/health into a sanitized snapshot (schema_version, generated_at, ttl_seconds, routes with route_id/account_alias/opaque credential_ref/ plan/quota_windows/health/metadata). Whitelist-only fields; tokens, API keys, emails and raw error messages never enter the output. - cockpit-core/secure_account_reader: read-only AES-256-GCM envelope reader so the CLI can load encrypted account detail files written by the GUI. Never creates keys or writes files. - cockpit-cli: 'quota [platform] --json' emits the snapshot; default table view shows route/provider/plan/health/min-remaining. Unit tests cover alias opacity/determinism, credential-leak fixtures (access/refresh/id tokens, API keys, session ids), window normalization and health mapping.
中文:把 CLI 安装为 cockpit/cockpit-cli,并在快照中标明 availability,供 MCPX 直接读取。
| "acct-123", | ||
| "runtime-1", | ||
| ] { | ||
| assert!(!json.contains(secret), "快照泄漏了敏感值: {}", secret); |
| use serde::de::DeserializeOwned; | ||
| use std::path::Path; | ||
|
|
||
| const KEY_FILE: &str = "secure-account-storage.key"; |
| if bytes.len() != 32 { | ||
| return Err("账号详情加密密钥长度无效".to_string()); | ||
| } | ||
| let mut key = [0u8; 32]; |
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.
功能说明
为
cockpit-cli增加机器可读的只读容量快照导出:cockpit quota [--json]。背景:Cockpit GUI 已有各平台最完整的账号/配额/健康数据,但 CLI 的
quota子命令一直是空桩,外部工具无法以机器可读方式复用这份数据。本 PR 把它补上,输出规范化、净化(sanitized)后的快照,供外部调度/路由工具消费。改动内容
crates/cockpit-core/src/modules/capacity_snapshot.rs(新增):将现有 antigravity + codex 账号/配额数据规范化为快照:schema_version/generated_at/ttl_seconds(300) /source/sources(各数据源读取状态)/routesroute_id、provider、account_alias、不透明credential_ref、is_current、plan、quota_windows[](name / remaining_ratio / reset_at(RFC3339) / window_minutes)、health(healthy/degraded/unavailable + 最近 401/429 时间戳 + 错误码)、updated_at、非敏感metadata(tags/tier_id/credits/auth_mode)QuotaData(逐模型剩余百分比 + reset_time)+ 本地配额缓存合并;codex:primary_5h / weekly 双窗口crates/cockpit-core/src/modules/secure_account_reader.rs(新增):账号详情文件 AES-256-GCM 信封的只读解密读取(与secure_account_storage的信封格式一致)。绝不创建密钥、绝不写回/迁移文件;密钥缺失时直接报错crates/cockpit-cli/src/main.rs:quota [platform] [--json]。无参数输出人类可读表格;--json输出快照;platform可选过滤(antigravity/codex)安全边界
credential_ref为账号 ID 的 SHA-256 派生不透明引用,Cockpit 仍是唯一凭据持有方测试
cargo test -p cockpit-core capacity_snapshot:10 通过(别名稳定性/不可逆、泄漏检测、窗口归一化、reset_time 解析容错、健康映射)cargo test -p cockpit-core secure_account_reader:1 通过(信封解密 + 历史明文兼容 + 缺钥只报错不创建)范围说明