Skip to main content

Crate cmduse_core

Crate cmduse_core 

Source

Re-exports§

pub use dates::parse_iso_utc;
pub use wire::Credits;
pub use wire::CreditsResp;
pub use wire::SubData;
pub use wire::SubscriptionsResp;
pub use wire::UsageSummary;
pub use wire::Window;
pub use wire::WindowLimits;

Modules§

dates
reports
Usage aggregation — pure math for the daily/hourly/local reports.
wire
Command Code API wire shapes shared by the CLI and the Zed extension. Field names map to the JSON via camelCase rename.

Constants§

ARK_JSON
The Volcengine ARK Agent Plan catalogue, hand-maintained in core/ark.json from the docs (tiers, AFP quota, coefficients, model gates). Exposed here for the same reason as ZEN_JSON: the arkuse bin includes it from the published crate.
DEFAULT_NAME
FIVE_HOUR_SECS
Rolling-window lengths — the API serves only resetAt, the length is implied by the window name.
GATE_CLI_VERSION
GATE_EXTRACTED_AT
WEEKLY_SECS
ZEN_JSON
The OpenCode Go/Zen catalogue, as generated by scripts/extract-zen.ts into core/zen.json. Exposed here so the ocuse bin can include it without reaching outside its own crate (which cargo refuses at package time).

Statics§

CAPS
GATE_ALIASES
GATE_CATEGORIES
GATE_HARD_BLOCKED
GATE_KNOWN
GATE_PLANS
NAME_RULES
PLANS

Functions§

bare_model
Bare model id with any provider qualifier stripped: everything after the FIRST colon. blockedModels entries are provider-qualified (“anthropic:claude-opus-5”); we only serve via command-code lanes, so match on the id portion. A model id that itself contains ‘:’ keeps it.
canonical_model
Exact known id (case-insensitive), else alias target, else date-stripped.
compact
Compact thousands/millions. Rounds half-away-from-zero explicitly before formatting: {:.1} alone is round-half-to-even, which disagrees with JS Math.round at exact .x5 ties (1_250_000 → “1.2M” vs “1.3M”).
duration
Compact “Xh Ym” / “Xd Yh” for a span of seconds. Pure duration — no absolute time involved; use this (not rel_time) for ETAs/countdowns.
elapsed_pct
Elapsed % of a rolling window, one decimal: window length = dur_secs, ends at reset_at. Multiplied-rounded like pct so both ports agree at .x5.
gate
Access decision plus a short human reason (for models --gated --json).
gate_age_days
Age of the gating snapshot in days, from gating.json’s extractedAt. None when the metadata is absent/unparseable (pre-metadata snapshots).
gate_allowed
money
monthly_window
Assemble the monthly usage window from the plan cap and subscription period: used = cap − remaining (clamped to [0, cap]), reset = period end, duration = period length. Returns (window, duration secs). Single source for cli + zed; the opencode TS port mirrors it via conformance vectors.
pace_eta
Seconds until spend hits cap at the current rate, if that lands before the window resets. None = no warning. Suppressed before 10% of the window has elapsed — the flat-rate projection is unreliable that early.
pct
Percent string of used/cap at one decimal: “34.2%” or “—” when cap unknown. Multiply-rounds to one decimal ((x*10).round()/10) before formatting, matching JS toFixed(1)/Math.round in the opencode port; format!("{:.1}") alone is half-to-even and drifts at exact .x5 ties.
plan_monthly_cap
Monthly credit pool per plan. One shared pool per plan (verified — the docs’ per-model allowances are not what the API meters). None = PAYG.
plan_name
Plan display name from the API’s planId (e.g. “individual-goat” → “GOAT”). First rule whose needles are all contained in the lowercased id wins.
plan_rule_matched
True when plan_id matched a NAME_RULES entry rather than falling through to DEFAULT_NAME. Callers warn on false: the API returned a plan we don’t know, so its name/cap may be wrong until plans.json is updated.
rel_time
Compact “Xh Ym” human time until reset_at (epoch ms). now may be None (zed ext without a clock) → falls back to a raw epoch stamp.