Skip to content

feat(cli): [router] config, tole route dry run and doctor lines (#586 part 1b) - #651

Merged
ajianaz merged 4 commits into
developfrom
feat/rule-router-config
Nov 13, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/rule-router-config

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1b of #586: the [router] config, the tole route dry run, and the tole doctor / config check lines. Nothing routes runs yet. #652 (part 2) does the wiring, off by default, and is stacked on this PR.

Depends on: #650 (part 1a, tole_core::router), which is merged. This branch has the latest develop merged in (a merge commit), and the PR now targets develop.

Why

Owners need to declare tiers and rules, check them at load time, and see what a prompt would get before any run is routed. A cloned repository must not be able to route to a model the user did not declare.

Changes

  • config.rs: RouterConfig (enabled, allow_tiers, [router.tiers], [[router.rules]]) with deny_unknown_fields.

    • Parsing compiles the rules, so syntax errors fail at load.
    • layered takes tiers and rules from the user layer only.
    • config check shows the state, tier names and rule names, never models or keywords.
  • routing.rs (new):

    • compile validates every rule with a remedy: an unknown tier, kind or risk, a bad rule or profile name, duplicate names, min_chars > max_chars, bad keywords, at most 64 rules.
    • layered: a project can only set enabled = false or narrow allow_tiers (intersected with the user's). project_warning warns about anything else.
    • Routing::from_config:
      • None unless the user config says enabled = true;
      • checks every rule's tier where it resolves;
      • an undeclared tier or an unknown profile is an error naming the fix.
    • Routing::decide returns the route and the model it selects. None keeps the configured model.
    • doctor_lines: names only.
    • explain: the dry-run text, with every string redacted before it is capped.
  • Owner decisions (2026-11-13), now stated in the docs and the output:

    • What a rule replaces: the configured model, whether it comes from TOLE_MODEL, the config's model or a profile's default. Only a session's own model (/model, ACP) and a cron job's --model pin are never routed.
    • Rules and profiles: a rule without profiles applies only to runs without a profile and resolves through [router.tiers]. A rule with profiles resolves through profiles.<name>.models.
  • tole route PROMPT [--kind] [--risk] [--job] [--budget-left] (with the global --profile) prints:

    • the tier, the model and the reason;
    • the configured model and its source, for example configured model: m (from env TOLE_MODEL).

    It calls no provider.

  • tole doctor prints the router lines from the user config and fails on a broken router.

  • Docs: CHANGELOG [Unreleased], design A9.3 "as implemented, part 1", a README config row and usage line, and a threat-model row.

  • Dependencies: no change.

Testing

  • cargo fmt --all
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace
  • cargo test -p tole-core --no-default-features
  • No-mcp CI commands:
    • cargo check -p tole-cli --no-default-features
    • cargo clippy -p tole-cli --no-default-features --features shell-tools -- -D warnings
    • cargo test -p tole-cli --no-default-features
  • The commands above ran on this head, after the merge of develop.
  • cora review --no-llm --staged: no issues.
  • New tests:
    • routing_tests.rs: 7 unit tests;
    • tests/route_cli.rs: 2 tests on the real binary, including the configured model's source (from env TOLE_MODEL).
  • The configured-model source change was test-first: the tests went red (the new signature did not exist), then green.
  • Mutation breaks, each restored afterwards; the tests caught all 10:
    • project rules accepted;
    • a project widens allow_tiers;
    • a project cannot disable;
    • on by default;
    • an undeclared tier is not a load error;
    • doctor shows models;
    • the dry run skips redaction;
    • parse skips the rule check;
    • the dry run ignores --kind;
    • the dry run drops the source's variable name.

tole_core::router: a Router returns a Route (tier light/standard/heavy,
source, reason), never a model name, budget, allow list or secret.
RuleRouter takes every matching rule, picks the cheapest tier (ties go
cheaper; the first rule of that tier names the route), narrows to an
allowed-tier set, and keeps the configured model when nothing matches.
check() refuses a rule whose tier is not declared where it resolves or
an unknown profile, naming the remedy. Route::record redacts with the
process secrets before it caps. Platform-agnostic, no new dependency.
…part 1b)

[router] is off unless the user config says enabled = true. Tiers
([router.tiers], profiles.<name>.models) and rules come from the user
config only; a project config can only set enabled = false or narrow
allow_tiers, and anything else is ignored with a warning. An unknown
tier, kind or risk, an undeclared tier or an unknown profile is a load
error naming the remedy, never a fallback to another model. tole route
prints the tier, model and reason a run would get without calling a
provider, redacted; tole doctor and config check show names only.
A matching rule replaces the configured model, whether it comes from
TOLE_MODEL, the config's model or a profile's default; only a session's
own model and a cron job's --model pin are never routed. tole route now
prints that configured model and where it came from (for example
"from env TOLE_MODEL"), and the docs say both rules plainly, along with
rules without profiles applying only to runs without a profile.
@ajianaz
ajianaz changed the base branch from feat/rule-router to develop November 13, 2026 00:08
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit c687b45 into develop Nov 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the feat/rule-router-config branch November 20, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants