Expand description
The shared Costroid user-config crate: a non-secret TOML at
${XDG_CONFIG_HOME:-$HOME/.config}/costroid/config.toml, hand-edited by the user and
read-only here — Costroid never writes it (no writer, no budget set command). It is
forward-compatible: every section/field defaults and unknown keys are ignored, so an older
build reads a newer file (and vice-versa) without error.
Both apps consume this one schema + loader: the costroid CLI/TUI (T14/T17) and the
costroid-bar taskbar (Step 6, T20) — extracted out of apps/cli/src/config.rs so the bar
gets the same [budget]/[alerts] parsing without depending on apps/cli. A pure leaf of the
workspace: it depends only on costroid-core (for the config-neutral AlertThresholds /
BudgetTargets input types) + serde/toml/rust_decimal; it links no network/keychain code.
Secrets never live here — credentials are keychain-only (costroid-connect). Today the
file carries [budget] targets (monthly $ caps, API-lane only; money is
rust_decimal::Decimal, never f64), the [alerts] opt-in (T17, default off), and the
[breakeven] what-if scenario defaults (M4, all optional; every numeric knob is exact
Decimal — quote for guaranteed exactness).
[budget]
total_monthly_usd = 100.00
[budget.per_tool]
claude-code = 60.00
codex = 40.00
[alerts]
enabled = true # opt-in; default false (quiet) — the master switch
# quota_warn = 0.80 # optional per-class overrides (default 0.80 / 0.95)
# quota_critical = 0.95
# forecast = true # advisory (T17b): month-end projection over the TOTAL budget; default off
# anomalies = true # advisory (T17b): a daily spend spike vs your own norm; default off
[breakeven] # `costroid breakeven` what-if defaults (M4); CLI flags override these
# depreciation_period_days = 1095 # the break-even amortization calendar (the basis, MED3)
# output_share = 0.5 # output-token share for the cloud-price blend (0..=1)
# utilization = 1.0 # duty cycle for the feasibility ceiling (0..=1)
# electricity_rate_per_kwh = "0.16" # quote for exactness (a bare 0.16 is not f64-exact)
# hardware_price = "2000.00" # the amortized capex
# cloud_model = "claude-opus-4-8" # the cloud model to compare againstforecast and anomalies are opt-in advisory SUB-flags — each off by default and each still
requiring enabled = true. They surface heads-up advisories (a projected total-budget overrun
and a spend spike) in the same banner / alerts list as the hard quota and budget crossings.
Structs§
- Config
- The parsed user config. Forward-compatible: every section defaults, so a missing or partial
file is valid and unknown keys are silently ignored (serde’s default behavior — no
deny_unknown_fields).
Enums§
- Config
Error - A config-load failure. A missing file is NOT one of these — it yields the zero-config default. These are surfaced as a TUI/taskbar status line (never a crash).
Functions§
- config_
path - Resolve the config-file path
${XDG_CONFIG_HOME:-$HOME/.config}/costroid/config.toml.Nonewhen neither$XDG_CONFIG_HOMEnor$HOMEyields a base directory (treated as “no config” — the zero-config default, never an error). Mirrorscostroid-connect’sdefault_registry_path, but rooted at the config dir (this file is non-secret). - load
- Load the user config from the resolved default path. A missing file (or an unresolved path) yields the zero-config default (no budgets) — only a present-but-malformed file is an error.
- load_
from - Load the config from an explicit path — the testable seam (no env access). A missing file =>
default; an unreadable file or invalid TOML => a typed
ConfigError.