graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(subagent): default provider-local worker tier ladder (#291)
Rach Pradhan4f9e7a7a8fc3
diff --git a/README.md b/README.mdindex 1ae5527a..dcc4efe5 100644--- a/README.md+++ b/README.md@@ -866,14 +866,23 @@ history, its own arena, and a subagent-specific system prompt (`execSubagent`).Because tool calls already fan out via `io.async`, the model spawning threesubagents in one response gets three agent loops running concurrently, eachmaking its own HTTPS calls through the shared (thread-safe) `std.http.Client`.-Subagents inherit the parent's provider/model by default. A model shape can pin-all direct children, workflow workers/retries, and LLM judges to another model-on the same provider/account:+Absent an explicit pin, subagents default onto a provider-local worker tier+ladder one rung cheaper than the root model (codex/openai gpt-5.6 sol/flagship+-> terra -> luna; anthropic opus -> sonnet -> haiku; deepseek pro -> flash),+so a fan-out of file-reading researchers doesn't run on the flagship by+default. The ladder only ever resolves within the root's own provider; a root+model outside the ladder, or already at its cheapest rung, inherits unchanged.+`--no-subagent-tier` (or an explicit `--subagent-model`) opts out and restores+plain inherit-root. A model shape can also pin all direct children, workflow+workers/retries, and LLM judges to a specific model on the same+provider/account:```shgraff --model gpt-5.6-sol --subagent-model gpt-5.6-terra# equivalent lower-precedence worker setting:GRAFF_SUBAGENT_MODEL=gpt-5.6-terra graff --model gpt-5.6-sol+# force every worker onto the root model, ignoring the default ladder:+graff --model gpt-5.6-sol --no-subagent-tier```This keeps orchestration/synthesis on Sol and parallel execution on Terradiff --git a/src/args.zig b/src/args.zigindex 4b924600..f54491b8 100644--- a/src/args.zig+++ b/src/args.zig@@ -50,6 +50,7 @@ pub const Flags = struct {subagent_provider_flag: ?[]const u8 = null,subagent_model_flag: ?[]const u8 = null,allow_cross_provider_subagents_flag: bool = false,+ no_subagent_tier_flag: bool = false, // --no-subagent-tier: opt out of the default worker tier ladder (#291), keep plain inherit-rootsystem_prompt_flag: ?[]const u8 = null,append_system_flag: ?[]const u8 = null,host_flag: []const u8 = "127.0.0.1", // harness serve@@ -164,6 +165,8 @@ pub fn parse(init: std.process.Init) !Flags {flags.subagent_model_flag = try arena.dupe(u8, mv);} else if (std.mem.eql(u8, arg, "--allow-cross-provider-subagents")) {flags.allow_cross_provider_subagents_flag = true;+ } else if (std.mem.eql(u8, arg, "--no-subagent-tier")) {+ flags.no_subagent_tier_flag = true;} else if (std.mem.eql(u8, arg, "--system-prompt")) {const sv = it.next() orelse std.process.fatal("--system-prompt needs a value — harness --help", .{});flags.system_prompt_flag = try arena.dupe(u8, sv);diff --git a/src/cli.zig b/src/cli.zigindex aeafd0f1..b2e68a05 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -90,6 +90,7 @@ pub const usage_text =\\ --subagent-model <name> pin children/workflows/judges on the root provider\\ --subagent-provider <id> route pinned workers through this provider\\ --allow-cross-provider-subagents confirm prompts/code may go to the worker provider+ \\ --no-subagent-tier opt out of the default worker tier ladder (inherit the root model)\\ --resume <name> resume/autosave <name>.session.json\\ --new start a fresh autosaved session (default)\\ --no-resume ignore --resume and start freshdiff --git a/src/main.zig b/src/main.zigindex 95724917..2d52c6ba 100644--- a/src/main.zig+++ b/src/main.zig@@ -284,7 +284,7 @@ pub fn main(init: std.process.Init) !void {boot.mark(io, "credentials/model");var keys = resolved_keys.keys;const default_provider = resolved_keys.default_provider;- const subagent_provider = startup.resolveSubagentProvider(keys, default_provider, flags.subagent_provider_flag orelse init.environ_map.get("GRAFF_SUBAGENT_PROVIDER"), flags.subagent_model_flag orelse init.environ_map.get("GRAFF_SUBAGENT_MODEL"), flags.allow_cross_provider_subagents_flag);+ const subagent_provider = startup.resolveSubagentProvider(keys, default_provider, flags.subagent_provider_flag orelse init.environ_map.get("GRAFF_SUBAGENT_PROVIDER"), flags.subagent_model_flag orelse init.environ_map.get("GRAFF_SUBAGENT_MODEL"), flags.allow_cross_provider_subagents_flag, flags.no_subagent_tier_flag);const stale_saved_model = resolved_keys.stale_saved_model;const preferred_provider = resolved_keys.preferred_provider;const codex_account = resolved_keys.codex_account;diff --git a/src/schema_protocol.zig b/src/schema_protocol.zigindex f54d4b59..7ccecaea 100644--- a/src/schema_protocol.zig+++ b/src/schema_protocol.zig@@ -10,9 +10,10 @@pub const flags =\\[\\ {"flag": "--model", "arg": "name", "description": "start on this model (same fuzzy resolution as /model)"},- \\ {"flag": "--subagent-model", "arg": "name", "description": "pin direct subagents, workflow workers/retries, and judges to this model on the root provider; GRAFF_SUBAGENT_MODEL is the lower-precedence equivalent"},+ \\ {"flag": "--subagent-model", "arg": "name", "description": "pin direct subagents, workflow workers/retries, and judges to this model on the root provider; GRAFF_SUBAGENT_MODEL is the lower-precedence equivalent; overrides the default tier ladder"},\\ {"flag": "--subagent-provider", "arg": "id", "description": "route pinned workers through this explicit provider; GRAFF_SUBAGENT_PROVIDER is the lower-precedence equivalent"},\\ {"flag": "--allow-cross-provider-subagents", "arg": null, "description": "explicitly consent to sending worker prompts, code, and tool results to a provider different from the root"},+ \\ {"flag": "--no-subagent-tier", "arg": null, "description": "opt out of the default worker tier ladder; workers inherit the root model unless an explicit --subagent-model is given"},\\ {"flag": "--yolo", "arg": null, "description": "skip all permission prompts for the session"},\\ {"flag": "--no-local-tools", "arg": null, "description": "embedder mode: hard-disable the built-in bash/bash_output/bash_kill/read_file/edit_file/write_file/codedb tools for the whole process, so the harness can run outside the sandbox and source its coding tools from an MCP server instead; webfetch, orchestration and MCP tools are unaffected, and subagents inherit the gate. GRAFF_NO_LOCAL_TOOLS=1 is the equivalent"},\\ {"flag": "--system-prompt", "arg": "text", "description": "replace the built-in system prompt (cwd project-instructions file is still appended)"},diff --git a/src/schema_serve.zig b/src/schema_serve.zigindex 94ee3821..7b416648 100644--- a/src/schema_serve.zig+++ b/src/schema_serve.zig@@ -10,7 +10,7 @@ pub const json =\\ "endpoints": [\\ {"method": "GET", "path": "/healthz", "description": "liveness + version, no auth"},\\ {"method": "GET", "path": "/v1/schema", "description": "this schema document"},- \\ {"method": "POST", "path": "/v1/sessions", "description": "create OR resume a session (a graff --json child); optional JSON body {\"session\",\"model\",\"subagentProvider\",\"subagentModel\",\"allowCrossProviderSubagents\",\"yolo\",\"system_prompt\",\"append_system_prompt\",\"maxToolCalls\",\"maxModelCalls\",\"dedupeToolCalls\"} overrides serve-level defaults. \"session\" (aliases \"session_id\"/\"resume\") names a durable session: 1-64 chars of [A-Za-z0-9._-], not starting with . or -; omitted means a fresh 16-hex name. Responds {\"session_id\":\"<name>\",\"resumed\":<bool>,\"last_seq\":<N>} - resumed says a session file already existed, last_seq is where the persisted event tape ends (reconnect with ?from=last_seq+1)"},+ \\ {"method": "POST", "path": "/v1/sessions", "description": "create OR resume a session (a graff --json child); optional JSON body {\"session\",\"model\",\"subagentProvider\",\"subagentModel\",\"allowCrossProviderSubagents\",\"noSubagentTier\",\"yolo\",\"system_prompt\",\"append_system_prompt\",\"maxToolCalls\",\"maxModelCalls\",\"dedupeToolCalls\"} overrides serve-level defaults. \"session\" (aliases \"session_id\"/\"resume\") names a durable session: 1-64 chars of [A-Za-z0-9._-], not starting with . or -; omitted means a fresh 16-hex name. Responds {\"session_id\":\"<name>\",\"resumed\":<bool>,\"last_seq\":<N>} - resumed says a session file already existed, last_seq is where the persisted event tape ends (reconnect with ?from=last_seq+1)"},\\ {"method": "POST", "path": "/v1/sessions/{id}", "description": "body is ONE stdio-protocol request object (user / review / set_system_prompt / set_model / compact / set_mode / set_agent / set_effort / set_fast / score / answer); non-answer requests stream application/x-ndjson events until the request's terminal event (turn/error, or the request-specific ack); answer requests return a JSON ack while the original user stream continues; one non-answer request in flight per session at a time. ?from=N or {\"resume_from\":N} replays persisted events with seq >= N before the live stream. {\"type\":\"reattach\"} sends nothing to the child and only replays+follows, so it is safe while another connection is mid-turn"},\\ {"method": "GET", "path": "/v1/sessions/{id}/events?from=N", "description": "reconnect: replay persisted events with seq >= N (default 1), then keep following the log live while a request is in flight, ending at that request's terminal event. Takes no protocol lock and never writes to the child, and works for a session this process never spawned as long as its event log is in the workspace"},\\ {"method": "DELETE", "path": "/v1/sessions/{id}", "description": "graceful close: waits for any in-flight request, then EOFs the child's stdin. The session file and the event log stay on disk, so the id remains resumable"}diff --git a/src/serve.zig b/src/serve.zigindex 215937cd..a1a398b8 100644--- a/src/serve.zig+++ b/src/serve.zig@@ -38,6 +38,7 @@ const ServeConfig = struct {subagent_provider: ?[]const u8,subagent_model: ?[]const u8,allow_cross_provider_subagents: bool,+ no_subagent_tier: bool,system_prompt: ?[]const u8,append_system_prompt: ?[]const u8,max_tool_calls: ?u64,diff --git a/src/serve_create.zig b/src/serve_create.zigindex 1bae96a5..a47ac090 100644--- a/src/serve_create.zig+++ b/src/serve_create.zig@@ -36,6 +36,7 @@ pub fn create(st: *ServeState, req: *std.http.Server.Request) !void {var subagent_provider = st.cfg.subagent_provider;var subagent_model = st.cfg.subagent_model;var allow_cross_provider_subagents = st.cfg.allow_cross_provider_subagents;+ var no_subagent_tier = st.cfg.no_subagent_tier;var yolo = st.cfg.yolo;var sys = st.cfg.system_prompt;var append_sys = st.cfg.append_system_prompt;@@ -64,6 +65,9 @@ pub fn create(st: *ServeState, req: *std.http.Server.Request) !void {if (v.object.get("allowCrossProviderSubagents") orelse v.object.get("allow_cross_provider_subagents")) |a| if (a == .bool) {allow_cross_provider_subagents = a.bool;};+ if (v.object.get("noSubagentTier") orelse v.object.get("no_subagent_tier")) |a| if (a == .bool) {+ no_subagent_tier = a.bool;+ };if (v.object.get("yolo")) |y| if (y == .bool) {yolo = y.bool;};@@ -106,6 +110,7 @@ pub fn create(st: *ServeState, req: *std.http.Server.Request) !void {if (subagent_provider) |p| try argv.appendSlice(arena, &.{ "--subagent-provider", p });if (subagent_model) |m| try argv.appendSlice(arena, &.{ "--subagent-model", m });if (allow_cross_provider_subagents) try argv.append(arena, "--allow-cross-provider-subagents");+ if (no_subagent_tier) try argv.append(arena, "--no-subagent-tier");if (max_tools) |n| try argv.appendSlice(arena, &.{ "--max-tool-calls", try std.fmt.allocPrint(arena, "{d}", .{n}) });if (max_models) |n| try argv.appendSlice(arena, &.{ "--max-model-calls", try std.fmt.allocPrint(arena, "{d}", .{n}) });if (dedupe_tools) try argv.append(arena, "--dedupe-tool-calls");diff --git a/src/startup.zig b/src/startup.zigindex 023156f0..7bb2da77 100644--- a/src/startup.zig+++ b/src/startup.zig@@ -474,6 +474,7 @@ pub fn runSubcommand(io: Io, gpa: Allocator, arena: Allocator, init: std.process.subagent_provider = flags.subagent_provider_flag,.subagent_model = flags.subagent_model_flag,.allow_cross_provider_subagents = flags.allow_cross_provider_subagents_flag,+ .no_subagent_tier = flags.no_subagent_tier_flag,.system_prompt = flags.system_prompt_flag,.append_system_prompt = flags.append_system_flag,.max_tool_calls = main_mod.max_tool_calls,diff --git a/src/subagent_selection.zig b/src/subagent_selection.zigindex ef239c06..ea7fa82a 100644--- a/src/subagent_selection.zig+++ b/src/subagent_selection.zig@@ -4,10 +4,19 @@//! tool results, billing, and credentials move to another service. Cross-//! provider workers therefore require both an explicit provider and an//! explicit consent flag.+//!+//! Absent an explicit --subagent-model/--subagent-provider, a default worker+//! tier ladder (#291, tier_ladder.zig) descends one rung from wherever the+//! root model sits — same precedence-tail as the explicit pin's own+//! provider-local/cross-provider-consent rules, since the default is+//! resolved through the same subagentProvider() call with cross-provider+//! forced off. --no-subagent-tier (or GRAFF_NO_SUBAGENT_TIER) opts out and+//! restores today's plain inherit-root behavior.const std = @import("std");const pricing = @import("pricing.zig");const provider_mod = @import("provider.zig");+const tier_ladder = @import("subagent_tier_ladder.zig");pub const Error = error{UnknownModel,@@ -44,6 +53,31 @@ fn modelForProvider(provider_id: []const u8, query: []const u8) ?[]const u8 {return candidate;}+/// Default worker sibling for `root` on its own ladder, descending exactly+/// one rung. `root.model` must exactly match a rung name (frontier or mid)+/// for this provider's ladder — an off-ladder or unrecognized root model+/// returns null rather than guessing at the nearest rung.+fn defaultLadderModel(root: provider_mod.Provider) ?[]const u8 {+ const ladder = tier_ladder.forProvider(root.id) orelse return null;+ if (std.mem.eql(u8, root.model, ladder.frontier)) return ladder.mid orelse ladder.small;+ if (ladder.mid) |mid| {+ if (std.mem.eql(u8, root.model, mid)) return ladder.small;+ }+ return null; // root is already the bottom rung, or isn't on this ladder+}++/// Resolves the default ladder sibling to an actual Provider, reusing+/// subagentProvider's exact/alias/key resolution so a ladder name a live+/// catalog refresh has since dropped fails soft into "inherit root" instead+/// of the fatal path an explicit --subagent-model takes. Always same-+/// provider — cross_provider is forced off, since ladder siblings never+/// cross a provider boundary implicitly (preserves the invariant explicit+/// pins already enforce).+fn defaultLadderProvider(keys: provider_mod.Keys, root: provider_mod.Provider) ?provider_mod.Provider {+ const target = defaultLadderModel(root) orelse return null;+ return subagentProvider(keys, root, null, target, false) catch null;+}+pub fn subagentProvider(keys: provider_mod.Keys,root: provider_mod.Provider,@@ -74,13 +108,15 @@ pub fn resolveSubagentProvider(provider_query: ?[]const u8,model_query: ?[]const u8,allow_cross_provider: bool,+ disable_default_ladder: bool,) ?provider_mod.Provider {const raw_provider = provider_query orelse "";const requested_provider = std.mem.trim(u8, raw_provider, " \t\r\n");const raw_model = model_query orelse {if (requested_provider.len != 0)std.process.fatal("--subagent-provider requires --subagent-model", .{});- return null;+ if (disable_default_ladder) return null;+ return defaultLadderProvider(keys, root);};const requested_model = std.mem.trim(u8, raw_model, " \t\r\n");if (requested_model.len == 0)@@ -125,3 +161,123 @@ test "worker selection stays provider-local unless explicitly allowed" {subagentProvider(keys, root, "not-a-provider", "k3", true),);}++test "defaultLadderModel: descends one rung per provider, bottom rung inherits" {+ const mk = struct {+ fn p(id: []const u8, model: []const u8) provider_mod.Provider {+ return .{ .id = id, .kind = .openai, .auth = .bearer, .url = "", .api_key = "", .model = model, .context = 0 };+ }+ }.p;+ // codex: sol -> terra -> luna -> (bottom, inherit)+ try std.testing.expectEqualStrings("gpt-5.6-terra", defaultLadderModel(mk("codex", "gpt-5.6-sol")).?);+ try std.testing.expectEqualStrings("gpt-5.6-luna", defaultLadderModel(mk("codex", "gpt-5.6-terra")).?);+ try std.testing.expect(defaultLadderModel(mk("codex", "gpt-5.6-luna")) == null);+ // openai: same shape, sibling names+ try std.testing.expectEqualStrings("gpt-5.6-terra", defaultLadderModel(mk("openai", "gpt-5.6")).?);+ // anthropic: opus -> sonnet -> haiku -> (bottom)+ try std.testing.expectEqualStrings("claude-sonnet-4-6", defaultLadderModel(mk("anthropic", "claude-opus-4-8")).?);+ try std.testing.expectEqualStrings("claude-haiku-4-5", defaultLadderModel(mk("anthropic", "claude-sonnet-4-6")).?);+ try std.testing.expect(defaultLadderModel(mk("anthropic", "claude-haiku-4-5")) == null);+ // deepseek: pro steps to its only cheaper rung (flash); flash has nowhere lower+ try std.testing.expectEqualStrings("deepseek-v4-flash", defaultLadderModel(mk("deepseek", "deepseek-v4-pro")).?);+ try std.testing.expect(defaultLadderModel(mk("deepseek", "deepseek-v4-flash")) == null);+ // unlisted provider -> no ladder at all+ try std.testing.expect(defaultLadderModel(mk("xai", "grok-4.3")) == null);+ // a real, catalogued model that just isn't a rung on its own provider's+ // ladder -> never guess at the nearest one+ try std.testing.expect(defaultLadderModel(mk("anthropic", "claude-opus-4-5")) == null);+}++test "default ladder: resolves the mid sibling when no flags are given" {+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex") or std.mem.eql(u8, spec.id, "anthropic"))+ value.* = "test-token";+ }+ const codex_root = try keys.providerById("codex", "gpt-5.6-sol");+ const worker = resolveSubagentProvider(keys, codex_root, null, null, false, false).?;+ try std.testing.expectEqualStrings("codex", worker.id); // provider-local, unpinned+ try std.testing.expectEqualStrings("gpt-5.6-terra", worker.model);++ const anthropic_root = try keys.providerById("anthropic", "claude-opus-4-8");+ const anthropic_worker = resolveSubagentProvider(keys, anthropic_root, null, null, false, false).?;+ try std.testing.expectEqualStrings("anthropic", anthropic_worker.id);+ try std.testing.expectEqualStrings("claude-sonnet-4-6", anthropic_worker.model);+}++test "default ladder: bottom-rung and off-ladder roots inherit (resolve to null)" {+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex") or std.mem.eql(u8, spec.id, "xai"))+ value.* = "test-token";+ }+ const luna_root = try keys.providerById("codex", "gpt-5.6-luna");+ try std.testing.expect(resolveSubagentProvider(keys, luna_root, null, null, false, false) == null);++ const xai_root = try keys.providerById("xai", "grok-4.3"); // unlisted family, never guess+ try std.testing.expect(resolveSubagentProvider(keys, xai_root, null, null, false, false) == null);+}++test "--no-subagent-tier opts out of the default ladder back to plain inherit" {+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex")) value.* = "test-token";+ }+ const root = try keys.providerById("codex", "gpt-5.6-sol");+ try std.testing.expect(resolveSubagentProvider(keys, root, null, null, false, true) == null);+}++test "explicit --subagent-model still wins over the default ladder" {+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex")) value.* = "test-token";+ }+ const root = try keys.providerById("codex", "gpt-5.6-sol");+ // The ladder default would be terra; an explicit pin to luna wins.+ const pinned = resolveSubagentProvider(keys, root, null, "gpt-5.6-luna", false, false).?;+ try std.testing.expectEqualStrings("gpt-5.6-luna", pinned.model);+}++test "default ladder never crosses a provider boundary implicitly" {+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex") or std.mem.eql(u8, spec.id, "openai") or+ std.mem.eql(u8, spec.id, "anthropic") or std.mem.eql(u8, spec.id, "deepseek"))+ value.* = "test-token";+ }+ const Case = struct { id: []const u8, model: []const u8 };+ for ([_]Case{+ .{ .id = "codex", .model = "gpt-5.6-sol" },+ .{ .id = "openai", .model = "gpt-5.6" },+ .{ .id = "anthropic", .model = "claude-opus-4-8" },+ .{ .id = "deepseek", .model = "deepseek-v4-pro" },+ }) |case| {+ const root = try keys.providerById(case.id, case.model);+ const worker = resolveSubagentProvider(keys, root, null, null, false, false) orelse continue;+ try std.testing.expectEqualStrings(case.id, worker.id); // same provider as root, always+ }+}++test "ladder rungs vs providerClass: documented, intentional disagreement (#291)" {+ // #291 requires ladder tier labels to match scoring.providerClass()+ // output for the same models, "or report the discrepancy rather than+ // papering over it." providerClass's needle table buckets the whole+ // gpt-5.x family (sol/terra/luna alike) as "frontier" — it has no+ // name-based way to split terra/luna out — and deepseek-v4-flash as+ // "small" via its "flash" needle, even though the ladder treats flash as+ // deepseek's only cheaper (mid) rung. This test pins that the mismatch+ // is real and known today, not a bug the ladder introduced; it is+ // reported rather than silently patched into scoring.zig's needle+ // table, which other, unrelated callers (DGM fitness scoring/fleet+ // niche gating) also depend on.+ try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("gpt-5.6-sol"));+ try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("gpt-5.6-terra")); // ladder rung: mid+ try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("gpt-5.6-luna")); // ladder rung: small+ try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("deepseek-v4-pro"));+ try std.testing.expectEqualStrings("small", @import("scoring.zig").providerClass("deepseek-v4-flash")); // ladder rung: mid+ // Claude already agrees end-to-end (opus/sonnet/haiku are tier-distinct+ // needles in providerClass, matching the ladder one-for-one).+ try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("claude-opus-4-8"));+ try std.testing.expectEqualStrings("mid", @import("scoring.zig").providerClass("claude-sonnet-4-6"));+ try std.testing.expectEqualStrings("small", @import("scoring.zig").providerClass("claude-haiku-4-5"));+}diff --git a/src/subagent_tier_ladder.zig b/src/subagent_tier_ladder.zignew file mode 100644index 00000000..a914c68f--- /dev/null+++ b/src/subagent_tier_ladder.zig@@ -0,0 +1,67 @@+//! Default worker-model tier ladder (#291): a provider-local sibling to fall+//! back on for subagents/workflow-workers/judges when no explicit+//! --subagent-model is given. Kept as its own module (rather than folded+//! into pricing.zig, which is already at the 600-line split ceiling) — pure+//! data + a model_table membership test, no key/provider wiring.+//!+//! Resolution (subagent_selection.zig) descends one rung from wherever the+//! root model sits: a frontier root steps to mid (or straight to small when+//! the family has no mid rung), a mid root steps to small, and a small root+//! has nowhere cheaper and inherits root unchanged.+//!+//! `frontier`/`mid`/`small` here are the ladder's OWN rung labels; they are+//! NOT guaranteed to equal scoring.providerClass(name) for that literal+//! model string — see the "ladder rungs vs providerClass" pinned test in+//! subagent_selection.zig for the documented (intentional, not papered+//! over) disagreement on the gpt-5.6 family and deepseek-v4-flash.+const std = @import("std");++const pricing = @import("pricing.zig");++pub const TierLadder = struct {+ provider: []const u8,+ frontier: []const u8,+ mid: ?[]const u8 = null,+ small: ?[]const u8 = null,+};++pub const ladders = [_]TierLadder{+ .{ .provider = "codex", .frontier = "gpt-5.6-sol", .mid = "gpt-5.6-terra", .small = "gpt-5.6-luna" },+ .{ .provider = "openai", .frontier = "gpt-5.6", .mid = "gpt-5.6-terra", .small = "gpt-5.6-luna" },+ .{ .provider = "anthropic", .frontier = "claude-opus-4-8", .mid = "claude-sonnet-4-6", .small = "claude-haiku-4-5" },+ .{ .provider = "deepseek", .frontier = "deepseek-v4-pro", .mid = "deepseek-v4-flash" },+};++/// The ladder row for a provider, if any. A provider absent from `ladders`+/// has no default tiering — every root on it always inherits.+pub fn forProvider(provider_id: []const u8) ?TierLadder {+ for (ladders) |l| if (std.mem.eql(u8, l.provider, provider_id)) return l;+ return null;+}++test "subagent tier ladder: every rung is a real model on its own provider (#291)" {+ // Every non-null name must be verified against the shipped model_table+ // before it's usable as a default worker pin — a typo/renamed model here+ // would silently fail every ladder resolution for that provider. Checked+ // against the comptime table, not models(): other tests (and their+ // background work) swap the runtime-active table, and this invariant is+ // about what the binary ships, not what a previous test left active.+ for (ladders) |l| {+ try std.testing.expect(inShippedTable(l.provider, l.frontier));+ if (l.mid) |m| try std.testing.expect(inShippedTable(l.provider, m));+ if (l.small) |s| try std.testing.expect(inShippedTable(l.provider, s));+ }+}++fn inShippedTable(provider_id: []const u8, model: []const u8) bool {+ for (pricing.model_table) |m| {+ if (std.mem.eql(u8, m.provider, provider_id) and std.mem.eql(u8, m.name, model)) return true;+ }+ return false;+}++test "forProvider: known providers found, others null" {+ try std.testing.expectEqualStrings("gpt-5.6-sol", forProvider("codex").?.frontier);+ try std.testing.expect(forProvider("deepseek").?.small == null);+ try std.testing.expect(forProvider("xai") == null);+}