Repository navigation
feat(zcode): add Z.ai usage adapter - #1
Conversation
|
@coderabbitai @cubic-dev-ai Please review the new ZCode adapter, especially SQLite token normalization, cost-mode semantics, and unified aggregation wiring. |
1daec22 to
be01497
Compare
axisrow
left a comment
There was a problem hiding this comment.
Reviewed the ZCode (Z.ai) adapter PR (head be01497).
Summary: New read-only SQLite-backed adapter under rust/crates/ccusage/src/adapter/zcode/, wired into the unified all report, CLI parser/commands, config schema, JSON schema, docs, and pricing table (embedded GLM-5.2 fallback pricing). Well-covered with fixture-backed tests (path discovery, parser normalization, loader completed/non-completed filtering, report aggregation snapshot) plus a skipped local-data smoke test.
Findings (non-blocking, informational):
parser.rs:read_model_usage_rowdeliberately ignoresmu.reasoning_tokens(selected in the SQL query but never read at index 6) because ZCode already folds reasoning tokens intooutput_tokens. This is documented inadapter/zcode/README.md("ZCode already includes reasoning_tokens in its output-token accounting"), so it reads as an intentional, well-explained design decision rather than dead code - just flagging it since an unused SELECT column is easy to mistake for an oversight on a future pass.pricing.rs: GLM-5.2 pricing (input 1.4e-6 / output 4.4e-6 / cache 0.26e-6) is hardcoded as a built-in fallback rather than sourced from LiteLLM/models.dev, consistent with how ZCode reports no native USD cost. Worth keeping an eye on for staleness if Z.ai changes pricing, but matches the pattern used elsewhere in this file for similar offline fallbacks.report.rs:summarize_entries/rows_keyimplement aWeeklybranch that the CLI parser never exposes forzcode(agent_report_supportedonly allows daily/monthly/session, matchingSTANDARD_AGENT_REPORTS). Harmless (mirrors the shared match pattern from other standard adapters likegoose), just unreachable from the CLI today.
No correctness bugs, missing error handling, or security issues found. Token normalization (input_tokens - cache_read - cache_creation) is documented and covered by a dedicated regression test/snapshot. Documentation (README, docs guide, VitePress nav, getting-started env var tables) is updated consistently for the new adapter. Config/JSON schema additions and CLI snapshots look complete and consistent with sibling adapters.
Approving - ready to merge as-is.
| pub(super) timestamp: TimestampMs, | ||
| pub(super) directory: Option<String>, | ||
| pub(super) usage: TokenUsageRaw, | ||
| } |
There was a problem hiding this comment.
SQL selects mu.reasoning_tokens (index 6) but read_model_usage_row never reads it - confirmed intentional per adapter README (ZCode already includes reasoning tokens in output_tokens), just flagging since it reads like an unused column at a glance.
| ..glm_base | ||
| }, | ||
| ); | ||
| let glm_5_2 = Pricing { |
There was a problem hiding this comment.
GLM-5.2 pricing is hardcoded here as an offline fallback rather than sourced from LiteLLM/models.dev - reasonable given ZCode reports no native cost, but will need manual updates if Z.ai changes pricing.
🔍 Local review (cycle-review, round 4298e3fa-daae-4bc1-aa72-c4a09d96c5b0)Reviewed locally via the built-in
Totals: 1 FIX (not yet applied — see note), 4 SKIP, 1 HALLUCINATION. Note on the FIX item: this review session is scoped as a read-only reviewer (its file-edit tooling is disabled by design) and cannot apply, commit, or push the fix. Recommended change: add |
327f28d to
d2af646
Compare
Summary
ccusage zcodeadapter for ZCode (Z.ai)zcode.defaultsandzcode.commands.<report>configuration blocksautoandcalculatereport zero cost and a missing-pricing warning;displayreports zero costValidation
cargo fmt --checkcargo clippy --workspace --all-targetsRUST_TEST_THREADS=4 cargo test -p ccusage— 307 passed, 1 local-data smoke test ignoredRUST_TEST_THREADS=4 cargo test --workspace— 377 passed, 1 local-data smoke test ignored (before the final config-only regression test)The branch was rebuilt from current
origin/mainand contains only the ZCode adapter, integration, test/snapshot, pricing, configuration, and documentation changes. Nix-specificjustchecks remain for CI because the local Nix dev shell is unavailable.