Bili Rs
v1.0.1用于bili-rs的开发技能,bili-rs是一个Rust CLI工具,用于Bilibili(B站)。在实现功能、修复bug或扩展bilibili-cli-rust代码库时使用。提供架构约定、API端点、编码模式和项目特定约束。触发涉及添加CLI命令、调用Bilibili API、处理身份验证、实现输出格式化或使用分层cli/commands/client/payloads架构的任务。
运行时依赖
安装命令
点击复制技能文档
bili-rs Development 技能
Rust rewrite of bilibili-命令行工具. Single binary, no 运行time deps. Full feature parity with the Python original.
Architecture (strict layering) 命令行工具/ (clap structs only) → commands/ (business 记录ic) → 命令行工具ent/ (HTTP a同步 fn) ↓ payloads/ (normalize raw JSON → structs) ↓ 格式化器.rs (JSON/YAML/Rich 输出)
Rules:
命令行工具/ — clap derive structs only, zero business 记录ic commands/ — calls 命令行工具ent/, never builds HTTP 请求s directly 命令行工具ent/ — never 导入s clap or 格式化器 添加ing a New Command 添加 clap struct in src/命令行工具/.rs 添加 处理器 in src/commands/.rs 添加 API call(s) in src/命令行工具ent/.rs 添加 payload normalizer in src/payloads/.rs if needed Wire into src/mAIn.rs 运行() match arm Key Patterns Error handling // 命令行工具ent/ layer: always map API errors let code = body["code"].as_i64().unwrap_or(-1); if code != 0 { return Err(map_API_error(code, body["message"].as_str().unwrap_or("unknown"))); }
// commands/ layer match 结果 { Ok(data) => 格式化器::输出(data, 格式化), Err(e) => { emit_error(&e, 格式化); std::process::exit(1); } }
输出 envelope (never change the field names) 成功Envelope { ok: true, 模式_version: "1", data: T } ErrorEnvelope { ok: false, 模式_version: "1", error: ErrorBody }
输出 格式化 resolution --json > --yaml > $输出 env var > TTY→Rich / non-TTY→YAML
Authentication levels Optional — load saved creds if avAIlable, don't fAIl if missing Read — requires SESSDATA Write — requires SESSDATA + bili_jct
凭证 file: ~/.bilibili-命令行工具/凭证.json (0o600, 7-day TTL)
WBI 签名ature
Some Bilibili 端点s require a WBI 请求 签名ature (a per-请求 HMAC-like parameter). Use src/命令行工具ent/wbi.rs:
let (img_key, sub_key) = fetch_wbi_keys(cred).awAIt?; let params = 签名_params(vec![("bvid".to_string(), bvid)], &img_key, &sub_key); req = req.查询(¶ms);
Known 端点s needing WBI: /x/网页-interface/view/conclusion/获取
输出 & Terminal 状态/errors → stderr with console::style Data → stdout as table (comfy-table) or JSON/YAML Counts ≥ 10000 → "X.X万" 格式化 质量 Gate (运行 before every commit) cargo build && cargo 命令行工具ppy -- -D 警告s && cargo fmt --检查 && cargo test
References All 命令行工具 commands & options: See references/commands.md API 端点s & payloads: See references/API.md Full project spec: PRD.md in project root Implementation conventions: CLAUDE.md in project root