Repository navigation
Conversation
A route is now a named group of rules that a key can be given, instead
of a flat table where each rule optionally carried a `client:` condition.
routes:
- name: 默认
default: true # applies to every key, at most one
rules:
- name: cached goes to official
when: { cache: true }
to: official
- name: long context
rules:
- name: over 200k downgrades
when: { input_tokens: ">200k" }
set: { model: claude-haiku-4-5 }
clients:
- name: codex
key: tw-…
routes: [long context] # stacked on top of the default
`Route` is renamed `Rule` and `RouteSet` is the new thing called a route.
The rename is the point, not collateral: "assign this route to that key"
means a group of rules, and calling one rule a route would have kept that
ambiguity forever.
**The default route is always evaluated first**, wherever it appears in
the file. Order is semantics here — `to` takes the first match — so a
default written at the end would become the one rule nothing can reach.
**A route serves several keys without being copied.** That is what naming
buys, and there is a test pinning it: two keys referencing one route see
the same rule instance. Copies drift, and only one of them gets fixed.
`when.client` is removed. Assignment does that job now, and keeping both
would be two ways to express one thing.
## What did not change
The engine still evaluates a flat list; it just builds that list per
request from the default route's rules plus the ones assigned to the
requesting key. So `set` and `guard` still accumulate from every matching
rule while `to` and `deny` take the first — the accumulation semantics
that make "everyone gets redaction, codex also swaps the model" two
rules instead of two copies.
## Three new load-time errors
Each corresponds to a failure that was otherwise silent:
· two routes with one name — "which one is assigned" has no answer
· more than one default route
· a key assigned to a route that does not exist — that key would
quietly fall back to the default while its owner believed the rules
were live
## Dry run
Now traces only the rules the simulated key actually evaluates. It used
to list every rule in the config, which reported rules belonging to other
keys as "skipped" — they are not skipped, they were never on this
request's path at all.
## Breaking
`routes:` changes shape and `when.client` is gone. Nothing is released,
and a config carrying the old form fails at the schema stage with the
field it did not expect.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A route is now a named group of rules that a key can be given, instead of a flat table where each rule optionally carried a
client:condition.Routeis renamedRule;RouteSetis the new thing called a route. The rename is the point, not collateral — "assign this route to that key" means a group of rules, and calling one rule a route would have kept that ambiguity permanently.Three properties, each with a test
The default route is always evaluated first, wherever it sits in the file. Order is semantics here —
totakes the first match — so a default written at the end would become the one rule nothing can reach.A route serves several keys without being copied. That is what naming buys. Two keys referencing one route see the same rule instance; copies drift, and only one of them ever gets fixed.
A key with no assignment still works, on the default route alone. That is the first-run state and a freshly created key, not an error.
when.clientis removed — assignment does that job now, and keeping both would be two ways to express one thing.What did not change
The engine still evaluates a flat list. It just builds that list per request from the default route's rules plus the ones assigned to the requesting key, so
setandguardstill accumulate from every matching rule whiletoanddenytake the first.That accumulation is why the flat list survives: "everyone gets redaction, codex also swaps the model" stays two rules rather than two copies of the redaction rule.
Three new load-time errors
Each corresponds to a failure that was otherwise completely silent:
Dry run
Now traces only the rules the simulated key actually evaluates. It used to list every rule in the config, reporting rules belonging to other keys as
skipped— they are not skipped, they were never on this request's path.Breaking
routes:changes shape andwhen.clientis gone. Nothing is released, and a config carrying the old form fails at the schema stage naming the field it did not expect.Verification
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings, 1078 tests (6 new on the route model), andscripts/smoke.sh— 46 checks, 0 failures.🤖 Generated with Claude Code