Run a cheap model first, verify the result deterministically, and escalate to a
stronger model only when verification fails. Most runs finish at the cheap tier;
the rest get a stronger attempt that receives the exact failing checks as context.
Flag-gated (ALTIMATE_ROUTER), default off — the normal single-model path is unchanged.
verifier.ts—Verifier: a deterministicVerdictfromdbt build/dbt testoutput (fromDbt,parseDbtSummary,failingNodes).Implis the pluggable verifier interface; the defaultdbtVerifier(run)shells dbt (runner injected, fail-open).ALLOW_ALLpasses everything when no verifier is configured.router.ts—Router: the escalation mechanism.route({tiers, runAgent, verify})runs each tier, verifies, escalates on a failed verdict with the failing checks (escalationContext), stops at the first pass.DEFAULT_LADDERis ordered cheapest → strongest; override viaALTIMATE_ROUTER_LADDER.policy.ts—Policy: where the ladder comes from.STATICis the built-in default;altimate(key)fetches a per-context ladder from the altimate API whenALTIMATE_API_KEYis set (degrades to static on any failure);resolve()picks between them;reportOutcome()posts verified outcomes back (key-gated, best-effort).sanitizeTiersvalidates + caps any ladder from the API.verdict.ts—Verdict.Envelope: a machine-checkable record of the result (which tier, per-attempt history, checks, evidence hash, timestamp, optional signature).
ALTIMATE_ROUTER=1— enable routing (default off).ALTIMATE_ROUTER_LADDER— comma-separatedprovider/modelids to override the default ladder.ALTIMATE_API_KEY/ALTIMATE_API_URL— use the altimate API for the routing policy and outcome reporting instead of the static ladder.
src/cli/cmd/run.ts (RunCommand): when Router.enabled(), the run resolves a policy,
runs each tier by re-invoking the existing run path with that model (escalation note
prepended) in the same workspace, verifies with dbt build between tiers, and emits a
verdict envelope. The default (non-router) path is untouched.
- Unit —
test/router/{verifier,router,verdict,policy}.test.ts. Pure logic, incl. adversarial cases (dbt summary-line injection, ANSI/huge/multi-summary output, endpoint response validation/capping). - E2E (
test/router/*.e2e.test.ts, env-gated — require docker + a dbt image + network, excluded from default CI):verifier.e2e— realdbt build(pass / compile-error / failing-test) and that a model emitting a fake summary does not change the verdict.E2E_IMG=<image> bun test verifier.e2e.router.e2e— real model calls + real dbt: cheap tier solves; an unsatisfiable workspace escalates through tiers, caps, and threads failing-check context.OPENROUTER_API_KEY=… E2E_IMG=… bun test router.e2e.policy.e2e— real network: live local server (incl. error/malformed/oversized responses) and an unreachable endpoint, all degrade gracefully.bun test policy.e2e.