Skip to main content

Module model_tier

Module model_tier 

Source
Expand description

§Module: model_tier

§Spec

  • Defines Tier: a harness-agnostic complexity bucket (Auto, Low, Med, High) used to classify task complexity and gate model selection.
  • Tier derives PartialOrd such that Auto < Low < Med < High. Gating is a simple > comparison: a task whose effective tier exceeds the running model’s tier should prompt the user to switch.
  • Defines ModelConfig (under [model] in the global TOML config) and TierMap (per-harness tier→model name resolution under [model.tiers.<harness>]).
  • detect_harness() reads environment variables (CLAUDE_CODE_SESSION, CODEX_SESSION) to identify the active agent harness, falling back to "default".
  • resolve_tier_to_model(tier, harness, config) maps a Tier to the concrete model name configured for the given harness, falling back to built-in defaults for the claude-code, codex, and default harnesses.
  • tier_from_model_name(name, harness, config) is the reverse lookup: given a concrete model name (e.g., "opus"), find the tier it belongs to in the harness mapping.
  • Tier::FromStr accepts case-insensitive auto | low | med | high.

§Agentic Contracts

  • Total ordering: Tier implements PartialOrd deterministically; gating logic is a single comparison and can be safely executed by any model tier.
  • Auto is the lowest: Tier::Auto represents “no preference” and compares less than Low. The effective_tier composition treats Auto as “fall through to next source.”
  • Built-in defaults: when no [model.tiers.<harness>] section is present, the resolver falls back to compiled-in maps for known harnesses. This means a fresh install needs zero config for the common case.
  • Reverse lookup is partial: tier_from_model_name returns None if the model name doesn’t appear in any tier slot for the harness. Callers should treat None as “unknown — leave tier as Auto.”

§Evals

  • tier_ordering: Auto < Low < Med < High holds for <, >, <=, >=.
  • tier_from_str_case_insensitive: "LOW", "low", "Low" all parse to Tier::Low.
  • tier_from_str_invalid: unknown strings return Err.
  • harness_detection_default: with no env vars set, detect_harness() returns "default".
  • resolve_builtin_claude_code: resolve_tier_to_model(Tier::High, "claude-code", &Config::default()) returns Some("opus").
  • resolve_unknown_harness_uses_default: an unknown harness falls through to the "default" built-in map.
  • tier_from_model_name_roundtrip: tier_from_model_name("opus", "claude-code", ...) returns Some(Tier::High).

Structs§

ModelConfig
Global [model] config section.
ModelSwitchScan
Result of scanning a unified diff for an inline /model <x> command.
TierMap
Per-harness tier → concrete model name map.

Enums§

Tier
Harness-agnostic model complexity tier.

Functions§

component_value_to_tier
Resolve a <!-- agent:model --> component value to a Tier.
compose_effective_tier
Compose the final effective_tier from all available sources.
detect_harness
Detect the active harness from environment variables.
extract_model_component
Extract the value inside a <!-- agent:model -->...<!-- /agent:model --> component.
parse_model_arg
Parse a /model <arg> argument: either a tier name (low|med|high) or a concrete model name (opus|sonnet|...).
resolve_tier_to_model
Resolve a Tier to a concrete model name for the given harness.
scan_model_switch
Scan a unified diff for an inline /model <x> command in user-added lines.
suggested_tier
Compute a suggested_tier from structural diff signals.
tier_from_model_name
Reverse lookup: given a concrete model name, find its tier in the harness’s mapping.