Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

perf(prompt): pay-per-use context — git authoring gated on a repo, deferred listings deduped

Rach Pradhane912e8ba8697
diff --git a/scripts/eval/mock_model.py b/scripts/eval/mock_model.py
old mode 100755
new mode 100644
index befbb924..6381b891
--- a/scripts/eval/mock_model.py
+++ b/scripts/eval/mock_model.py
@@ -34,6 +34,7 @@ class ScriptedModel:
self.script = script
self.exhausted_text = exhausted_text
self.requests: list[dict[str, Any]] = []
+ self.request_headers: list[dict[str, str]] = []
self._lock = threading.Lock()
self._server: http.server.ThreadingHTTPServer | None = None
@@ -72,6 +73,7 @@ class ScriptedModel:
def do_POST(self) -> None: # noqa: N802
body = self._body()
+ model.request_headers.append({k.lower(): v for k, v in self.headers.items()})
reply = model.next_reply(body)
if body.get("stream"):
self._stream(reply)
diff --git a/src/agent.zig b/src/agent.zig
index 6326a787..5dc1ae8a 100644
--- a/src/agent.zig
+++ b/src/agent.zig
@@ -343,13 +343,13 @@ pub const Agent = struct {
// No per-turn teardown: the socket and the chain span user turns, guarded by codex_chain.usable instead.
self.completed = null;
if (!self.sub and !root_turn_prepared.swap(false, .acq_rel)) esc_cancel.store(false, .release);
- // Effort routing (effort_route.zig): a lookup-shaped turn runs at low
- // effort while the session knob is the untouched default — an explicit
- // /effort or a persisted setting always wins. Restored after the turn.
+ // Effort routing: lookup-shaped SUBAGENT turns only. Flipping the
+ // root's reasoning_effort mid-conversation misses the prompt cache
+ // and drops the WS chain. Children have their own conv id.
const saved_reasoning = self.reasoning;
- if (!self.sub and self.reasoning == .medium and effort_route.routesToLowEffort(self.lastUserText())) {
+ if (effort_route.shouldRouteLookupLow(self.sub, self.reasoning == .medium, self.lastUserText())) {
self.reasoning = .low;
- tool_render.routedEffortLine(self); // the prompt badge predates the prompt; this is the truth
+ tool_render.routedEffortLine(self);
}
defer self.reasoning = saved_reasoning;
while (true) {
diff --git a/src/args.zig b/src/args.zig
index 26b171e7..883d97de 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -254,6 +254,12 @@ pub fn parse(init: std.process.Init) !Flags {
// the knob silently no-ops; applyEnvKnobs re-parses the same value later.
if (init.environ_map.get("GRAFF_XAI_WIRE")) |xw|
@import("provider.zig").g_xai_responses = std.ascii.eqlIgnoreCase(std.mem.trim(u8, xw, " \t"), "responses");
+ if (init.environ_map.get("GRAFF_XAI_URL")) |xu| {
+ if (xu.len > 0) {
+ const provider_mod = @import("provider.zig");
+ provider_mod.g_xai_url_override = xu;
+ }
+ }
return flags;
}
diff --git a/src/cli.zig b/src/cli.zig
index f446dfbf..b191a7cf 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -85,7 +85,7 @@ pub const changelog_text =
\\ • /peek <session> shows what a live co-resident session is doing right now — its last prompt, last action, last tool
\\ • Session recaps ride the event stream: settled turns carry a Completed or Needs-input status with a one-line recap for the GUI agent overview
\\ • Subscriptions are billed and routed as subscriptions: a flat-rate login (Codex, Kimi, SuperGrok) now outranks an API key on the same provider instead of losing to it, costs $0 in /cost, and the key it displaced is parked and takes over — announced — only if the plan runs out of quota
- \\ • Worker tiers land on seats you already pay for: an explicit tier ask crosses to a logged-in plan (mid → k3, small → gpt-5.6-luna) rather than a metered rung, which the #291 ladder descent used to block by looking like a manual pin
+ \\ • Worker tiers land on seats you already pay for: an explicit tier ask crosses to a logged-in plan (mid → k3, small → gpt-5.6-luna) rather than a metered rung — except a DeepSeek session (direct or via codegraff), which stays on flash instead of dropping to luna
\\ • A tier rung must now be a genuinely cheaper SEAT, so anthropic descends opus-5 → sonnet-5 instead of to an equally-priced older opus, and deepseek-v4-flash replaces pro outright
\\ • `graff route` with no model lists every provider you can reach, what it bills, and the tiers it offers
\\ • Anthropic serves its live model list, so new Claude releases arrive without a rebuild
diff --git a/src/effort_route.zig b/src/effort_route.zig
index 50a0d5fa..f4480bdc 100644
--- a/src/effort_route.zig
+++ b/src/effort_route.zig
@@ -1,15 +1,13 @@
-//! Per-turn effort routing (k3 benchmark, 2026-08): a lookup/Q&A-shaped prompt
-//! runs its turn at low effort when the session knob is still the untouched
-//! default. Measured on the graff×kimi-cli k3 benchmark: lookup tasks at low
-//! effort lose no answer quality (12/12 correct, false-premise corrections
-//! included) and cut wall time ~40-50% (runEval 32.6s vs 57.4-81.3s), because
-//! per-call thinking dominates and low effort thinks less. Edit-shaped prompts
-//! keep the default: low effort there INFLATES tool-call count (permgate went
-//! 11→16 calls and +85% wall), so anything that smells like mutation is never
-//! routed down.
+//! Per-turn effort routing (k3 benchmark, 2026-08): a lookup/Q&A-shaped
+//! SUBAGENT turn runs at low effort when that child inherited the stock
+//! `.medium` default (no effort pin). Root never routes: `reasoning_effort`
+//! / `reasoning.effort` sits in the cached prefix, and flipping it mid-
+//! conversation misses the prompt cache and breaks the WS chain fingerprint
+//! (codex_chain.propsFp). Children already have their own conv id.
//!
-//! An explicit user choice always wins: routing only fires while the session
-//! effort is the stock `.medium` default (see the runTurn call site).
+//! Edit-shaped prompts keep the default: low effort there INFLATES tool-
+//! call count (permgate went 11→16 calls and +85% wall). An explicit
+//! /effort or a worker `effort:` pin always wins.
const std = @import("std");
@@ -50,6 +48,12 @@ pub fn routesToLowEffort(prompt: []const u8) bool {
return false;
}
+/// Root stays sticky for cache. Only an unpinned child (default medium) may
+/// drop a lookup-shaped task to low.
+pub fn shouldRouteLookupLow(is_sub: bool, default_medium: bool, prompt: []const u8) bool {
+ return is_sub and default_medium and routesToLowEffort(prompt);
+}
+
test "lookup prompts route low, mutation prompts and bare commands do not" {
// The three benchmark tasks are the pinned shape: two route low, and the
// one that REGRESSED at low effort (permgate) must not route.
@@ -60,4 +64,9 @@ test "lookup prompts route low, mutation prompts and bare commands do not" {
try std.testing.expect(!routesToLowEffort("implement the feature and update the docs"));
try std.testing.expect(!routesToLowEffort("hi"));
try std.testing.expect(routesToLowEffort("Explain how the permission gate works here?"));
+ const q = "Explain how the permission gate works here?";
+ try std.testing.expect(!shouldRouteLookupLow(false, true, q)); // root: keep the cached prefix
+ try std.testing.expect(shouldRouteLookupLow(true, true, q)); // unpinned child
+ try std.testing.expect(!shouldRouteLookupLow(true, false, q)); // explicit effort pin
+ try std.testing.expect(!shouldRouteLookupLow(true, true, "fix the failing test"));
}
diff --git a/src/mcp_schema_gate.zig b/src/mcp_schema_gate.zig
index 82bebec4..c6153c41 100644
--- a/src/mcp_schema_gate.zig
+++ b/src/mcp_schema_gate.zig
@@ -83,7 +83,7 @@ pub const env_eager = "GRAFF_MCP_EAGER"; // comma-separated server names; "*" pi
/// entry and no import cycle. The description is spliced into a raw JSON
/// string, so it must stay free of characters needing JSON escapes.
pub const tool_name = "load_tool_schemas";
-pub const tool_desc = "Load the full JSON input schemas for deferred tools and enable them for the rest of this session. Deferred MCP tools — and folded native tools (workflow, imagegen, learn_candidate, eval, clock_sleep, subagent, todo_write, todo_read, peer_message, note_constraint, agent_output, skill, webfetch) — ship no schemas up front, so that thousands of tokens of JSON Schema stay out of every request; any deferred servers and their tool names are listed at the end of this description. A tool whose schema has not been loaded CANNOT be called: calling it returns an error telling you to load it first. Pass tools with exact names (mcp__server__tool for MCP, or a folded native name like workflow), pass server to load every deferred tool on one MCP server, or pass query with keywords to search deferred tools by name and description. Call it with no arguments to list what is currently deferred. Loading is permanent for this session and free to repeat, because the schemas are cached.";
+pub const tool_desc = "Load the full JSON input schemas for deferred tools and enable them for the rest of this session. Deferred tools — MCP and folded native — ship without their schemas so those bytes stay out of every request; what is deferred right now is listed at the end of this description. A tool whose schema has not been loaded CANNOT be called: load it first. Pass tools with exact names (mcp__server__tool for MCP, a bare name like workflow for native), server to load one whole MCP server, or query with keywords to search deferred tools; no arguments lists everything deferred. Loading is permanent for this session and free to repeat.";
pub const tool_schema =
\\{"type": "object", "properties": {"tools": {"type": "array", "items": {"type": "string"}, "description": "Exact qualified MCP tool names to load, e.g. mcp__deepwiki__ask_question"}, "server": {"type": "string", "description": "Load every deferred tool on this MCP server instead of naming them one by one"}, "query": {"type": "string", "description": "Search deferred tools by keyword (matches name and description, loads the top 8 matches) — use when you know what you need but not the exact tool name"}}}
;
@@ -487,7 +487,19 @@ fn matchQuery(arena: Allocator, all: []const mcp.Tool, query: []const u8) ![]usi
/// listing is how the model learns what exists (codex's tool_search source
/// listing), and `query` covers discovery beyond it (#476).
pub fn descWithListing(arena: Allocator, all: []const mcp.Tool) ![]const u8 {
- if (!anyDeferred(all)) return tool_desc;
+ // Folded NATIVES ride this listing too (#476, the schema.zig zero-stub
+ // rule): their names live here, once, instead of a static enumeration
+ // every session re-pays after the tools load. Same stable-catalog rule
+ // as the MCP half — stable mode lists by policy, never by load state.
+ const native_fold = @import("native_fold.zig");
+ var natives: std.ArrayList([]const u8) = .empty;
+ if (native_fold.anyFolded()) {
+ for (native_fold.folded) |name| {
+ if (!g_stable_catalog and native_fold.isLoaded(name)) continue;
+ try natives.append(arena, name);
+ }
+ }
+ if (!anyDeferred(all) and natives.items.len == 0) return tool_desc;
// Stable-catalog mode lists by POLICY, not load state: a listing that
// shrinks as tools load would change the prefix this mode exists to fix.
const deferredRule: *const fn ([]const mcp.Tool, mcp.Tool) bool = if (g_stable_catalog) &policyDeferred else &isDeferred;
@@ -502,7 +514,12 @@ pub fn descWithListing(arena: Allocator, all: []const mcp.Tool) ![]const u8 {
}
var aw: Io.Writer.Allocating = .init(arena);
try aw.writer.writeAll(tool_desc);
- try aw.writer.writeAll(" Deferred now:");
+ if (natives.items.len > 0) {
+ try aw.writer.writeAll(" Folded native:");
+ for (natives.items, 0..) |name, i| try aw.writer.print("{s}{s}", .{ if (i == 0) " " else ", ", name });
+ try aw.writer.writeAll(";");
+ }
+ if (servers.items.len > 0) try aw.writer.writeAll(" Deferred now:");
for (servers.items) |sv| {
try aw.writer.print(" {s} (", .{sv});
var first = true;
@@ -558,42 +575,9 @@ pub fn handleLoad(agent: anytype, input: Value) ExecResult {
// --- size accounting -------------------------------------------------------
-const max_depth = 32;
-
-/// Serialized byte count of a JSON value, near enough for a budget decision
-/// (escapes and float formatting are approximated). Depth-capped: the value
-/// comes from an MCP server, so it is untrusted input.
-pub fn jsonBytes(v: Value, depth: u8) usize {
- if (depth >= max_depth) return 0;
- return switch (v) {
- .null => 4,
- .bool => |b| if (b) @as(usize, 4) else 5,
- .integer => |i| blk: {
- var buf: [24]u8 = undefined;
- const printed = std.fmt.bufPrint(&buf, "{d}", .{i}) catch break :blk 1;
- break :blk printed.len;
- },
- .float => 8,
- .number_string => |s| s.len,
- .string => |s| s.len + 2,
- .array => |a| blk: {
- var n: usize = 2;
- for (a.items, 0..) |item, i| n += jsonBytes(item, depth + 1) + @intFromBool(i > 0);
- break :blk n;
- },
- .object => |o| blk: {
- var n: usize = 2;
- var it = o.iterator();
- var first = true;
- while (it.next()) |e| {
- n += e.key_ptr.len + 3 + jsonBytes(e.value_ptr.*, depth + 1);
- if (!first) n += 1;
- first = false;
- }
- break :blk n;
- },
- };
-}
+/// Body in util.zig (600-line cap); re-exported so serverCost and the tests
+/// keep naming this module.
+pub const jsonBytes = util.jsonBytes;
// Tests live in mcp_schema_gate_tests.zig (both files answer to the 600-line
// ceiling); the catalog-level half is in tool_schema_tests.zig, next to
// renderRootTools.
diff --git a/src/pricing.zig b/src/pricing.zig
index db7a5ad3..74f5e446 100644
--- a/src/pricing.zig
+++ b/src/pricing.zig
@@ -260,6 +260,7 @@ pub const model_table = [_]ModelInfo{
.{ .provider = "codegraff", .name = "claude-opus-4.8", .context = 1_000_000 },
.{ .provider = "codegraff", .name = "claude-sonnet-4.6", .context = 1_000_000 },
.{ .provider = "codegraff", .name = "deepseek-v4-pro", .context = 1_000_000 },
+ .{ .provider = "codegraff", .name = "deepseek-v4-flash", .context = 1_000_000 },
.{ .provider = "codegraff", .name = "minimax-m3", .context = 1_000_000 },
.{ .provider = "codegraff", .name = "gpt-5.5", .context = 400_000 },
.{ .provider = "codegraff", .name = "kimi-k2.6", .context = 262_144 },
diff --git a/src/prompt_snapshot_tests.zig b/src/prompt_snapshot_tests.zig
index 2bd68780..692527c1 100644
--- a/src/prompt_snapshot_tests.zig
+++ b/src/prompt_snapshot_tests.zig
@@ -153,7 +153,8 @@ const matrix = [_]struct { name: []const u8, caps: prompts.Caps }{
.{ .name = "no-subagents", .caps = .{ .subagents = false } },
.{ .name = "no-todos", .caps = .{ .todos = false } },
.{ .name = "no-constraints", .caps = .{ .constraints = false } },
- .{ .name = "floor", .caps = .{ .local_tools = false, .subagents = false, .todos = false, .constraints = false } },
+ .{ .name = "no-git-repo (scratch cwd)", .caps = .{ .git_repo = false } },
+ .{ .name = "floor", .caps = .{ .local_tools = false, .subagents = false, .todos = false, .constraints = false, .git_repo = false } },
};
test "#421 golden: the full-capability root prompt is exactly this, byte for byte" {
@@ -225,16 +226,20 @@ test "#421: a gated-off capability's tool names disappear from the prompt entire
const no_constraints = try prompts.composeSegments(a, .{ .constraints = false });
try std.testing.expect(std.mem.indexOf(u8, no_constraints, "note_constraint") == null);
+ // Outside a git repo, the AUTHORING guidance goes — commit identity and
+ // PR discipline have nothing to act on — while the safety rail stays.
+ const no_git = try prompts.composeSegments(a, .{ .git_repo = false });
+ for ([_][]const u8{ "## What changed", "Co-Authored-By: Codegraff", "GIT_AUTHOR_" }) |dead|
+ try std.testing.expect(std.mem.indexOf(u8, no_git, dead) == null);
+
// What survives EVERY gate: identity, the two prompt-doctrine lines, the
- // git/PR discipline, the do-not-discard-work rail, and the closing style.
+ // do-not-discard-work rail, and the closing style.
for (matrix) |row| {
const out = try prompts.composeSegments(a, row.caps);
for ([_][]const u8{
"You are a coding agent",
"never invent", // #421 doctrine 1: no wrapper APIs, no assumed capabilities
"its OWN environment", // #421 doctrine 2: verify where the project lives
- "## What changed",
- "Co-Authored-By: Codegraff",
"Never run git commands that discard work",
"Parallelize tool calls",
"Be direct and concise",
diff --git a/src/prompt_text.zig b/src/prompt_text.zig
index 54bba8c5..eb080566 100644
--- a/src/prompt_text.zig
+++ b/src/prompt_text.zig
@@ -110,10 +110,11 @@ pub const harness_issue_note =
\\...`), never in the current working repository's issue tracker.
;
-/// Always present. Deliberately NOT gated on `caps.local_tools`: an embedder
-/// that removed the local tools still reaches a sandbox where git may run, and
-/// "never discard the user's work" is the wrong instruction to make optional.
-pub const git_note =
+/// Gate: `caps.git_repo`. Commit-identity and PR-description discipline only
+/// earn their tokens where a repository exists to commit to — a scratch-dir
+/// one-shot or an eval run pays ~250 tokens/call for guidance it can never
+/// act on. The SAFETY rule stays in `git_safety_note` below, unconditional.
+pub const git_authoring_note =
\\
\\
\\When making git commits on behalf of the user, commit as the USER's own git
@@ -133,6 +134,15 @@ pub const git_note =
\\never pad a small change with boilerplate headings. Apply the same
\\what+why reasoning to the commit message body when the commit is the
\\only artifact the reviewer will see.
+;
+
+/// Always present. Deliberately NOT gated on `caps.local_tools` OR
+/// `caps.git_repo`: an embedder that removed the local tools still reaches a
+/// sandbox where git may run, a repo can appear mid-session (`git clone`),
+/// and "never discard the user's work" is the wrong instruction to make
+/// optional either way.
+pub const git_safety_note =
+ \\
\\
\\Never run git commands that discard work — `reset --hard`, `clean -f`,
\\`checkout --`/`restore`, force-push, or `branch -D` — unless the user
diff --git a/src/prompts.zig b/src/prompts.zig
index 5584a137..9e4be29a 100644
--- a/src/prompts.zig
+++ b/src/prompts.zig
@@ -45,7 +45,7 @@ const session_index = @import("session_index.zig"); // #410: where the durable t
pub const parallel_tools_note = text.parallel_tools_note;
/// The capability a segment needs. `.always` is what survives every gate.
-pub const Gate = enum { always, local_tools, subagents, todos, constraints };
+pub const Gate = enum { always, local_tools, subagents, todos, constraints, git_repo };
/// `name` exists for the snapshot tests: it lets an assertion say WHICH
/// segment a gate dropped instead of only how many bytes went missing.
@@ -62,7 +62,8 @@ pub const segments = [_]Segment{
.{ .name = "todo", .text = text.todo_note, .gate = .todos },
.{ .name = "trace", .text = text.trace_note, .gate = .local_tools },
.{ .name = "harness_issue", .text = text.harness_issue_note, .gate = .local_tools },
- .{ .name = "git", .text = text.git_note, .gate = .always },
+ .{ .name = "git_authoring", .text = text.git_authoring_note, .gate = .git_repo },
+ .{ .name = "git_safety", .text = text.git_safety_note, .gate = .always },
.{ .name = "work", .text = text.work_note, .gate = .always },
.{ .name = "headsup", .text = text.headsup_note, .gate = .always },
.{ .name = "todo_progress", .text = text.todo_progress_note, .gate = .todos },
@@ -104,6 +105,10 @@ pub const Caps = struct {
todos: bool = true,
/// `note_constraint`.
constraints: bool = true,
+ /// The cwd is inside a git repository, so commit/PR authoring guidance
+ /// has something to act on. Session state like the others: settled once
+ /// at startup (probeGitRepo), before buildSystemPrompt composes.
+ git_repo: bool = true,
pub fn has(self: Caps, gate: Gate) bool {
return switch (gate) {
@@ -112,12 +117,13 @@ pub const Caps = struct {
.subagents => self.subagents,
.todos => self.todos,
.constraints => self.constraints,
+ .git_repo => self.git_repo,
};
}
/// Nothing gated: composeBase may hand back the comptime constant.
pub fn full(self: Caps) bool {
- return self.local_tools and self.subagents and self.todos and self.constraints;
+ return self.local_tools and self.subagents and self.todos and self.constraints and self.git_repo;
}
};
@@ -138,9 +144,29 @@ pub fn detectCaps() Caps {
.subagents = toolAdvertised("subagent"),
.todos = toolAdvertised("todo_write") and !no_local_tools.lean,
.constraints = toolAdvertised("note_constraint") and !no_local_tools.lean,
+ .git_repo = g_git_repo,
};
}
+/// Whether the cwd sits inside a git repository — the `git_repo` gate's
+/// backing state. Defaults TRUE so an embedder (or a test) that never probes
+/// keeps the full prompt; startup.buildSystemPrompt is the one prober.
+pub var g_git_repo: bool = true;
+
+/// Walk up from the cwd looking for `.git` — access(), not a dir stat,
+/// because a worktree checkout keeps `.git` as a FILE. Bounded: 32 levels
+/// covers any real checkout, and the filesystem root just fails access.
+pub fn probeGitRepo(io: Io) void {
+ var buf: [128]u8 = undefined;
+ var prefix: usize = 0;
+ g_git_repo = while (prefix + 4 <= buf.len) {
+ @memcpy(buf[prefix..][0..4], ".git");
+ if (Io.Dir.cwd().access(io, buf[0 .. prefix + 4], .{})) |_| break true else |_| {}
+ @memcpy(buf[prefix..][0..3], "../");
+ prefix += 3;
+ } else false;
+}
+
/// The segment list in `main_system_prompt` order, minus every segment whose
/// capability is absent. Always allocates; composeBase is the caller that
/// short-circuits. Kept public so the snapshot tests can prove the
diff --git a/src/provider.zig b/src/provider.zig
index 80841c5c..3fa2b2aa 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -151,6 +151,7 @@ pub const kimi_anthropic_url = "https://api.kimi.com/coding/v1/messages?beta=tru
/// provider (re)build path (startup, /model switches, session restore) goes
/// through Keys.build; both the WS and SSE transports read provider.url.
pub var g_codex_url_override: ?[]const u8 = null;
+pub var g_xai_url_override: ?[]const u8 = null; // GRAFF_XAI_URL (chat or Responses path)
pub const Provider = struct {
id: []const u8,
@@ -239,7 +240,7 @@ pub const Provider = struct {
.id = spec.id,
.kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses) .responses else spec.kind,
.auth = if (is_kimi_anthropic) .x_api_key else spec.auth,
- .url = if (is_kimi_anthropic) kimi_anthropic_url else if (is_codex) g_codex_url_override orelse spec.url else if (is_xai_responses) xai_responses_url else spec.url,
+ .url = if (is_kimi_anthropic) kimi_anthropic_url else if (is_codex) g_codex_url_override orelse spec.url else if (std.mem.eql(u8, spec.id, "xai")) (g_xai_url_override orelse if (is_xai_responses) xai_responses_url else spec.url) else spec.url,
.api_key = base.api_key,
.model = model,
.context = contextWindowFor(spec.id, model),
@@ -335,7 +336,7 @@ pub const Keys = struct {
.id = spec.id,
.kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses) .responses else spec.kind,
.auth = if (is_kimi_anthropic) .x_api_key else spec.auth,
- .url = if (is_kimi_anthropic) kimi_anthropic_url else if (is_codex) g_codex_url_override orelse spec.url else if (is_xai_responses) xai_responses_url else spec.url,
+ .url = if (is_kimi_anthropic) kimi_anthropic_url else if (is_codex) g_codex_url_override orelse spec.url else if (std.mem.eql(u8, spec.id, "xai")) (g_xai_url_override orelse if (is_xai_responses) xai_responses_url else spec.url) else spec.url,
.api_key = key,
.model = model,
.context = contextWindowFor(spec.id, model),
diff --git a/src/session_settings.zig b/src/session_settings.zig
index 94ed8b3b..eefa3e57 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -158,6 +158,9 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
if (environ_map.get("GRAFF_XAI_WIRE")) |v| {
provider_mod.g_xai_responses = std.ascii.eqlIgnoreCase(std.mem.trim(u8, v, " \t"), "responses");
}
+ if (environ_map.get("GRAFF_XAI_URL")) |v| {
+ if (v.len > 0) provider_mod.g_xai_url_override = v;
+ }
ws.g_debug = environ_map.get("GRAFF_WS_DEBUG") != null;
// #502 follow-up: opt-in xAI on-socket chaining (see codex_chain.g_xai_ws_chain).
if (environ_map.get("GRAFF_XAI_WS_CHAIN")) |v|
diff --git a/src/skills.zig b/src/skills.zig
index b47b7c25..3b476d6b 100644
--- a/src/skills.zig
+++ b/src/skills.zig
@@ -67,17 +67,17 @@ pub const skills_registry = [_]SkillDef{
/// Edits inside the cwd stay native: edit_file/write_file are
/// /rewind-snapshotted and already splice via zigpatch, whereas codedb-pro
/// edit/patch/replace bypass /rewind. Explicit external targets use gated bash.
-const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED — its mcp__codedbpro__* tools (load once per session via load_tool_schemas, e.g. by query) REPLACE the native read/search defaults, which are BLOCKED while the server is healthy: read/search calls are refused with a pointer to the pro equivalent, shell searches to `zigrep` via bash; any codedb-pro failure unblocks the natives for the rest of the session. Size reads to the file: mode=full in ONE call for small files — outline/symbol/lines modes are for files too big to read whole; never outline-first a file you could have read in one call. KEEP EDITS inside the cwd on the native edit_file/write_file tools — they are snapshot-tracked for /rewind; codedb-pro edit/patch/replace bypass /rewind. An explicitly user-requested external target is the exception: permission-gated bash, quoted paths, and explain /rewind does not cover it.";
+const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED — its mcp__codedbpro__* tools (load once per session via load_tool_schemas, e.g. by query) REPLACE the native read/search defaults, which are BLOCKED while the server is healthy: read/search calls are refused with a pointer to the pro equivalent, shell searches to `zigrep` via bash; any codedb-pro failure unblocks the natives for the rest of the session. Size reads to the file: mode=full in ONE call for small files — outline/symbol/lines modes are for files too big to read whole. KEEP EDITS on the native edit_file/write_file tools — codedb-pro edit/patch/replace bypass /rewind; the cwd and explicit-external-target rules above apply unchanged.";
const McpNote = struct { server: []const u8, note: []const u8 };
pub const mcp_notes = [_]McpNote{
.{
.server = "codedbpro",
- .note = "The codedb-pro MCP server is connected (mcp__codedbpro__* tools). SEARCH ORDER: the native codedb tool is free and indexed — always try it first for code search (search/symbol/callers/outline/find); reach for mcp__codedbpro__faster_search or meta_search only when codedb can't answer (raw literal/regex content matches, fuzzy queries, non-indexed files) — codedb-pro is metered. Prefer mcp__codedbpro__read (mode=outline first, then symbol) over read_file for navigating large code files, and mcp__codedbpro__batch to run several independent reads/searches/edits in one round-trip. Keep edits inside the cwd on the native edit_file/write_file tools (they are snapshot-tracked for /rewind); for an explicitly user-requested external target, use permission-gated bash with quoted paths and disclose that /rewind does not cover it. These tools are accelerators, not requirements: whenever an mcp__codedbpro__ call fails or is unavailable, fall back to read_file/codedb/bash and continue.",
+ .note = "The codedb-pro MCP server is connected (mcp__codedbpro__* tools). SEARCH ORDER: the native codedb tool is free and indexed — always try it first for code search (search/symbol/callers/outline/find); reach for mcp__codedbpro__faster_search or meta_search only when codedb can't answer (raw literal/regex content matches, fuzzy queries, non-indexed files) — codedb-pro is metered. Prefer mcp__codedbpro__read (mode=outline first, then symbol) over read_file for navigating large code files, and mcp__codedbpro__batch to run several independent reads/searches/edits in one round-trip. Keep edits on the native edit_file/write_file tools (/rewind-tracked; the cwd and explicit-external-target rules above apply). These tools are accelerators, not requirements: if an mcp__codedbpro__ call fails, fall back to read_file/codedb/bash and continue.",
},
.{
.server = "muonry",
- .note = "The muonry MCP server is connected (mcp__muonry__* tools). SEARCH ORDER: the native codedb tool is free and indexed — always try it first for code search (search/symbol/callers/outline/find); use mcp__muonry__search or faster_search only when codedb can't answer (raw literal/regex content matches, non-code or non-indexed files) — muonry is metered. Prefer mcp__muonry__read (mode=outline first, then symbol) over read_file for navigating large code files, and mcp__muonry__batch to run several independent reads/searches/edits in one round-trip. Keep edits inside the cwd on the native edit_file/write_file tools (they are snapshot-tracked for /rewind); for an explicitly user-requested external target, use permission-gated bash with quoted paths and disclose that /rewind does not cover it. These tools are accelerators, not requirements: whenever an mcp__muonry__ call fails or is unavailable, fall back to read_file/codedb/bash and continue.",
+ .note = "The muonry MCP server is connected (mcp__muonry__* tools). SEARCH ORDER: the native codedb tool is free and indexed — always try it first for code search (search/symbol/callers/outline/find); use mcp__muonry__search or faster_search only when codedb can't answer (raw literal/regex content matches, non-code or non-indexed files) — muonry is metered. Prefer mcp__muonry__read (mode=outline first, then symbol) over read_file for navigating large code files, and mcp__muonry__batch to run several independent reads/searches/edits in one round-trip. Keep edits on the native edit_file/write_file tools (/rewind-tracked; the cwd and explicit-external-target rules above apply). These tools are accelerators, not requirements: if an mcp__muonry__ call fails, fall back to read_file/codedb/bash and continue.",
},
.{
.server = "smolify",
diff --git a/src/startup.zig b/src/startup.zig
index e55e7086..b577bca9 100644
--- a/src/startup.zig
+++ b/src/startup.zig
@@ -89,6 +89,9 @@ pub fn buildSystemPrompt(
learned_policy_env: ?[]const u8,
environ: anytype,
) ![]const u8 {
+ // #421: settle the git_repo gate before the base composes — commit/PR
+ // authoring guidance is only sent where a repository exists to act on.
+ prompts.probeGitRepo(io);
// A learned policy is used unless this session opted out of it.
const learned: ?learn_store.ActiveAgent = if (system_prompt_flag == null and learn_auto.enabled(learned_policy_env)) learnedRootPolicy(io, arena) else null;
if (learned) |policy| if (!quiet) {
diff --git a/src/subagent_pin.zig b/src/subagent_pin.zig
index 943998f5..88a98cb8 100644
--- a/src/subagent_pin.zig
+++ b/src/subagent_pin.zig
@@ -288,15 +288,23 @@ pub const subscription_providers = blk: {
break :blk frozen;
};
+/// Direct DeepSeek, or the same family through the codegraff gateway.
+/// Both DeepSeek seats outclass gpt-5.6-luna; hopping a DeepSeek session
+/// onto Codex's small rung is a capability drop, not a free upgrade.
+fn deepseekFamily(p: Provider) bool {
+ return std.mem.eql(u8, p.id, "deepseek") or std.mem.startsWith(u8, p.model, "deepseek");
+}
+
/// SUB-FIRST TIER ROUTING (explicit `tier` asks only — the silent no-tier
/// default still inherits the user's chosen family): a logged-in flat-rate
-/// subscription is marginal-cost-zero, so its rung outranks ANY metered
-/// model — a deepseek session's tier:"small" goes to luna on the codex sub,
-/// not to a metered gateway row — and the login itself is the user's
-/// standing consent for that vendor. Metered cross-provider routing keeps
-/// the explicit --subagent-provider + --allow-cross-provider-subagents bar.
+/// subscription is marginal-cost-zero, so its rung outranks a metered
+/// model — except a DeepSeek session (direct or via codegraff), which
+/// already sits on seats better than luna and must not be dumped there.
+/// The login is still standing consent for an *exact* model pin. Metered
+/// cross-provider routing keeps the explicit --subagent-provider bar.
/// When several subs serve the rung, the bench sheet's score picks.
fn subscriptionRung(tier: Tier, base: Provider) ?Resolved {
+ if (deepseekFamily(base)) return null;
const keys = bench_priors.g_keys orelse return null;
var best: ?Resolved = null;
var best_score: f64 = -1;
diff --git a/src/subagent_pin_tests.zig b/src/subagent_pin_tests.zig
index d8cdb1d8..c033fe4b 100644
--- a/src/subagent_pin_tests.zig
+++ b/src/subagent_pin_tests.zig
@@ -171,10 +171,10 @@ test "graceful fallback: every unhonorable pin keeps the session default, never
// A provider with no ladder at all: a tier pin is a no-op, not a crash.
const xai: Provider = .{ .id = "xai", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "grok-4.3", .context = 256_000 };
try std.testing.expectEqual(pin_mod.Outcome.no_ladder, pin_mod.forSpawn(xai, obj(a, "{\"tier\":\"small\"}"), true).outcome);
- // A ladder without that rung (deepseek is frontier-only, anthropic has no
- // `mid`) — never rounds to the nearest rung.
+ // A ladder without that rung (deepseek has no mid) — never rounds to
+ // the nearest rung.
const deepseek: Provider = .{ .id = "deepseek", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "deepseek-v4-flash", .context = 128_000 };
- try std.testing.expectEqual(pin_mod.Outcome.no_rung, pin_mod.forSpawn(deepseek, obj(a, "{\"tier\":\"small\"}"), true).outcome);
+ try std.testing.expectEqual(pin_mod.Outcome.no_rung, pin_mod.forSpawn(deepseek, obj(a, "{\"tier\":\"mid\"}"), true).outcome);
const opus: Provider = .{ .id = "anthropic", .kind = .anthropic, .auth = .x_api_key, .url = "", .api_key = "k", .model = "claude-opus-5", .context = 1_000_000 };
try std.testing.expectEqual(pin_mod.Outcome.no_rung, pin_mod.forSpawn(opus, obj(a, "{\"tier\":\"mid\"}"), true).outcome);
try std.testing.expectEqualStrings("claude-sonnet-5", pin_mod.forSpawn(opus, obj(a, "{\"tier\":\"small\"}"), true).provider.?.model);
@@ -215,18 +215,18 @@ test "sub-first routing: a logged-in flat-rate sub outranks metered for explicit
if (std.mem.eql(u8, spec.id, "codex")) keys.values[i] = "tok";
}
bench.g_keys = &keys;
- // A deepseek session asking tier:"small": the codex sub is logged in and
- // luna is the better pick — of course it goes to luna, on the sub.
+ // A DeepSeek session asking tier:"small" stays on DeepSeek flash even
+ // when Codex is logged in — luna is the worse seat, not a free upgrade.
const dsv: Provider = .{ .id = "deepseek", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "deepseek-v4-pro", .context = 128_000 };
const routed = pin_mod.forSpawn(dsv, obj(a, "{\"tier\":\"small\"}"), true);
- try std.testing.expectEqual(pin_mod.Outcome.sub_routed, routed.outcome);
- try std.testing.expectEqualStrings("codex", routed.provider.?.id);
- try std.testing.expectEqualStrings("gpt-5.6-luna", routed.provider.?.model);
- try std.testing.expect(routed.outcome.describe().len > 0);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, routed.outcome);
+ try std.testing.expectEqualStrings("deepseek", routed.provider.?.id);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", routed.provider.?.model);
// An explicit --subagent-provider (sub_ok=false) is a human choice no
- // auto-route may override: back to the provider-local path (deepseek has
- // no small rung → no_rung, session default kept).
- try std.testing.expectEqual(pin_mod.Outcome.no_rung, pin_mod.forSpawn(dsv, obj(a, "{\"tier\":\"small\"}"), false).outcome);
+ // auto-route may override: the provider-local flash rung still applies.
+ const local = pin_mod.forSpawn(dsv, obj(a, "{\"tier\":\"small\"}"), false);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, local.outcome);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", local.provider.?.model);
// Exact model pins: provider-local first, but a name the child's provider
// does not serve falls through to a logged-in sub that serves it exactly
// — the same standing consent as the tier path, rescuing a pin that used
@@ -242,10 +242,21 @@ test "sub-first routing: a logged-in flat-rate sub outranks metered for explicit
// …and the match is strictly exact/alias — a substring must NOT cross a
// provider boundary to find a model the pin did not name.
try std.testing.expectEqual(pin_mod.Outcome.unknown_model, pin_mod.forSpawn(dsv, obj(a, "{\"model\":\"luna\"}"), true).outcome);
- // No login (g_keys null) → no candidates → the metered ceiling rules.
+ // No login (g_keys null) → no subscription hop; DeepSeek still has a
+ // local flash rung. An exact luna pin with no login stays unknown.
bench.g_keys = null;
- try std.testing.expectEqual(pin_mod.Outcome.no_rung, pin_mod.forSpawn(dsv, obj(a, "{\"tier\":\"small\"}"), true).outcome);
+ const nologin = pin_mod.forSpawn(dsv, obj(a, "{\"tier\":\"small\"}"), true);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, nologin.outcome);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", nologin.provider.?.model);
try std.testing.expectEqual(pin_mod.Outcome.unknown_model, pin_mod.forSpawn(dsv, obj(a, "{\"model\":\"gpt-5.6-luna\"}"), true).outcome);
+
+ // Same family through a codegraff login: stay on gateway flash, not luna.
+ bench.g_keys = &keys;
+ const cg: Provider = .{ .id = "codegraff", .kind = .openai, .auth = .bearer, .url = "", .api_key = "k", .model = "deepseek-v4-pro", .context = 1_000_000 };
+ const cg_small = pin_mod.forSpawn(cg, obj(a, "{\"tier\":\"small\"}"), true);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, cg_small.outcome);
+ try std.testing.expectEqualStrings("codegraff", cg_small.provider.?.id);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", cg_small.provider.?.model);
}
test "exact pin: the child's own provider wins over a logged-in sub serving the same name" {
diff --git a/src/subagent_selection.zig b/src/subagent_selection.zig
index 266be944..d155c612 100644
--- a/src/subagent_selection.zig
+++ b/src/subagent_selection.zig
@@ -193,10 +193,11 @@ test "defaultLadderModel: descends one rung per provider, bottom rung inherits"
try std.testing.expectEqualStrings("claude-sonnet-5", defaultLadderModel(mk("anthropic", "claude-opus-5")).?);
try std.testing.expect(defaultLadderModel(mk("anthropic", "claude-sonnet-5")) == null);
try std.testing.expect(defaultLadderModel(mk("anthropic", "claude-opus-4-8")) == null);
- // deepseek: flash overtook pro and is 3x cheaper too, so it is the whole
- // ladder — one seat, nothing to descend to, and pro is not a rung at all.
+ // deepseek / codegraff: pro (the session default) descends to flash;
+ // a flash root is already the cheap seat and inherits.
+ try std.testing.expectEqualStrings("deepseek-v4-flash", defaultLadderModel(mk("deepseek", "deepseek-v4-pro")).?);
try std.testing.expect(defaultLadderModel(mk("deepseek", "deepseek-v4-flash")) == null);
- try std.testing.expect(defaultLadderModel(mk("deepseek", "deepseek-v4-pro")) == null);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", defaultLadderModel(mk("codegraff", "deepseek-v4-pro")).?);
// 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
@@ -285,14 +286,8 @@ test "ladder rungs vs providerClass: documented, intentional disagreement (#291)
try std.testing.expectEqualStrings("frontier", @import("scoring.zig").providerClass("gpt-5.6-sol"));
try std.testing.expectEqualStrings("mid", @import("scoring.zig").providerClass("gpt-5.6-terra")); // ladder rung: mid
try std.testing.expectEqualStrings("small", @import("scoring.zig").providerClass("gpt-5.6-luna")); // ladder rung: small
- // The one remaining disagreement, still reported rather than papered
- // over: the ladder treats deepseek-v4-flash as deepseek's only cheaper
- // rung (mid), while providerClass's "flash" needle states its absolute
- // capability (small). Relative-vs-absolute semantics, not a bug — the
- // needle table's other callers (DGM fitness scoring/fleet niche gating)
- // want the absolute answer.
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
+ try std.testing.expectEqualStrings("small", @import("scoring.zig").providerClass("deepseek-v4-flash")); // ladder rung: small
// Claude 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"));
diff --git a/src/subagent_tier_ladder.zig b/src/subagent_tier_ladder.zig
index 29ee77d6..250998ad 100644
--- a/src/subagent_tier_ladder.zig
+++ b/src/subagent_tier_ladder.zig
@@ -12,9 +12,8 @@
//! `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: the gpt-5.6 family now agrees end-to-end, leaving
-//! deepseek-v4-flash as the documented (intentional, not papered over)
-//! disagreement.
+//! subagent_selection.zig: the gpt-5.6 family and DeepSeek flash now agree
+//! end-to-end with providerClass.
const std = @import("std");
const pricing = @import("pricing.zig");
@@ -50,7 +49,7 @@ pub const TierLadder = struct {
small: ?[]const u8 = null,
/// The model this provider serves at `tier`, or null when the family has
- /// no such rung (deepseek has no `small`). Never falls through to a
+ /// no such rung (deepseek has no `mid`). Never falls through to a
/// neighbouring rung — an absent rung means "no opinion", which the
/// caller turns into the session default rather than a guess.
pub fn modelFor(self: TierLadder, tier: Tier) ?[]const u8 {
@@ -71,10 +70,14 @@ pub const ladders = [_]TierLadder{
// it is the same seat, one generation older. sonnet-5 at $2/$10 is the
// real cheap rung, 2.5x under opus on both halves of the bill.
.{ .provider = "anthropic", .frontier = "claude-opus-5", .small = "claude-sonnet-5" },
- // deepseek-v4-flash overtook pro: better AND $0.14/$0.28 against pro's
- // $0.435/$0.87. Pro is dominated on both axes, so it is not a rung under
- // flash — it is just worse. One seat, no descent.
- .{ .provider = "deepseek", .frontier = "deepseek-v4-flash" },
+ // Flash is the cheaper DeepSeek seat ($0.14/$0.28 vs pro $1.1/$2.2) and
+ // still outclasses luna. Pro stays the frontier name a codegraff/direct
+ // session actually starts on; small descends to flash instead of hopping
+ // to Codex luna. Flash-as-root is off-ladder and inherits.
+ .{ .provider = "deepseek", .frontier = "deepseek-v4-pro", .small = "deepseek-v4-flash" },
+ // Same family through the gateway login: stay on DeepSeek, do not dump
+ // mechanical workers onto a logged-in Codex luna.
+ .{ .provider = "codegraff", .frontier = "deepseek-v4-pro", .small = "deepseek-v4-flash" },
// Kimi's plan is one flagship. k3 is the MID-tier subscription seat —
// sub-first routing sends `tier:"mid"` here (codex has no mid rung) while
// `tier:"small"` still lands on codex's luna, which is what the cheap
@@ -159,7 +162,8 @@ fn inShippedTable(provider_id: []const u8, model: []const u8) bool {
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.expectEqualStrings("deepseek-v4-flash", forProvider("deepseek").?.small.?);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", forProvider("codegraff").?.small.?);
try std.testing.expect(forProvider("xai") == null);
}
@@ -179,7 +183,8 @@ test "Tier.parse/modelFor: the rung vocabulary #292 pins against (#291 names)" {
try std.testing.expectEqualStrings("gpt-5.6-terra", codex.modelFor(.mid).?);
try std.testing.expectEqualStrings("gpt-5.6-luna", codex.modelFor(.small).?);
// A family with no such rung answers null rather than the nearest rung.
- try std.testing.expect(forProvider("deepseek").?.modelFor(.small) == null);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", forProvider("deepseek").?.modelFor(.small).?);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", forProvider("codegraff").?.modelFor(.small).?);
}
test "#471 a rung must be a cheaper SEAT, not merely a terser one" {
diff --git a/src/util.zig b/src/util.zig
index 93abeba3..50ffa0ad 100644
--- a/src/util.zig
+++ b/src/util.zig
@@ -105,6 +105,44 @@ pub fn unixMs(io: Io) i64 {
return @intCast(@divTrunc(ts.nanoseconds, 1_000_000));
}
+const json_bytes_max_depth = 32;
+
+/// Serialized byte count of a JSON value, near enough for a budget decision
+/// (escapes and float formatting are approximated). Depth-capped: values may
+/// come from an MCP server, so they are untrusted input. Lives here (not
+/// mcp_schema_gate.zig, at the 600-line cap); that module re-exports it.
+pub fn jsonBytes(v: Value, depth: u8) usize {
+ if (depth >= json_bytes_max_depth) return 0;
+ return switch (v) {
+ .null => 4,
+ .bool => |b| if (b) @as(usize, 4) else 5,
+ .integer => |i| blk: {
+ var buf: [24]u8 = undefined;
+ const printed = std.fmt.bufPrint(&buf, "{d}", .{i}) catch break :blk 1;
+ break :blk printed.len;
+ },
+ .float => 8,
+ .number_string => |s| s.len,
+ .string => |s| s.len + 2,
+ .array => |a| blk: {
+ var n: usize = 2;
+ for (a.items, 0..) |item, i| n += jsonBytes(item, depth + 1) + @intFromBool(i > 0);
+ break :blk n;
+ },
+ .object => |o| blk: {
+ var n: usize = 2;
+ var it = o.iterator();
+ var first = true;
+ while (it.next()) |e| {
+ n += e.key_ptr.len + 3 + jsonBytes(e.value_ptr.*, depth + 1);
+ if (!first) n += 1;
+ first = false;
+ }
+ break :blk n;
+ },
+ };
+}
+
test "utf8Prefix truncates without splitting codepoints" {
try std.testing.expectEqualStrings("abc", utf8Prefix("abc", 10));
const s = [_]u8{ 'a', 'b', 0xC3, 0xA9, 'c' }; // "abéc"
diff --git a/src/vision_ask_tests.zig b/src/vision_ask_tests.zig
index f973a0b3..040661b6 100644
--- a/src/vision_ask_tests.zig
+++ b/src/vision_ask_tests.zig
@@ -402,13 +402,12 @@ test "#471 the #291 ladder descent is not a human pin, so a tier ask still reach
var keys: provider_mod.Keys = undefined;
withKeys(&keys, &.{"codex"});
- // Seated by the automatic ladder: an explicit tier:"small" crosses to the
- // codex plan, because nothing here was a human decision.
+ // A DeepSeek session's tier:"small" stays on flash — luna is a drop.
selection.g_default_from_ladder = true;
const auto = va.forSpawn(deepseek(), obj(a, "{\"tier\":\"small\"}"), true, .{}, "extract the imports");
- try std.testing.expectEqual(pin_mod.Outcome.sub_routed, auto.pin.outcome);
- try std.testing.expectEqualStrings("codex", auto.pin.provider.?.id);
- try std.testing.expectEqualStrings("gpt-5.6-luna", auto.pin.provider.?.model);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, auto.pin.outcome);
+ try std.testing.expectEqualStrings("deepseek", auto.pin.provider.?.id);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", auto.pin.provider.?.model);
// A real --subagent-model session is still untouchable: the user picked
// the workers, and no auto-route may override that.
@@ -416,8 +415,9 @@ test "#471 the #291 ladder descent is not a human pin, so a tier ask still reach
const pinned = va.forSpawn(deepseek(), obj(a, "{\"tier\":\"small\"}"), true, .{}, "extract the imports");
try std.testing.expect(pinned.pin.outcome != .sub_routed);
- // And an unpinned session behaves as it always did.
+ // Unpinned still stays on DeepSeek flash, not luna.
selection.g_default_from_ladder = false;
const free = va.forSpawn(deepseek(), obj(a, "{\"tier\":\"small\"}"), false, .{}, "extract the imports");
- try std.testing.expectEqual(pin_mod.Outcome.sub_routed, free.pin.outcome);
+ try std.testing.expectEqual(pin_mod.Outcome.pinned, free.pin.outcome);
+ try std.testing.expectEqualStrings("deepseek-v4-flash", free.pin.provider.?.model);
}