graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: grok maps /effort max to high instead of 400ing
Rach Pradhanb81939c77221
diff --git a/TUI/dispatch.zig b/TUI/dispatch.zigindex ad31d82b..c8cfd2c6 100644--- a/TUI/dispatch.zig+++ b/TUI/dispatch.zig@@ -150,6 +150,10 @@ pub fn runCommand(self: *Model, line: []const u8) Effect {} else self.push(.system, "model switching isn't available (offline)") catch {};} else if (std.mem.eql(u8, canon, "/effort")) {if (arg.len == 0) {+ const p = engine.g_model_provider;+ const m = engine.g_model_name;+ if ((std.mem.eql(u8, p, "xai") or std.mem.startsWith(u8, m, "grok")) and (self.effort == .max or self.effort == .ultra))+ self.effort = .high;self.openOverlay(.effort);self.overlay_sel = @intFromEnum(self.effort);return .stay;@@ -159,6 +163,10 @@ pub fn runCommand(self: *Model, line: []const u8) Effect {self.push(.system, "usage: /effort low|medium|high|xhigh|max|ultra") catch {};return .stay;};+ const p = engine.g_model_provider;+ const m = engine.g_model_name;+ if ((std.mem.eql(u8, p, "xai") or std.mem.startsWith(u8, m, "grok")) and (self.effort == .max or self.effort == .ultra))+ self.effort = .high;self.pushFmt(.system, "reasoning effort: {s}", .{@tagName(self.effort)}) catch {};} else if (std.mem.eql(u8, canon, "/always-approve")) {self.mode = if (self.mode == .always_approve) .normal else .always_approve;diff --git a/TUI/effort.zig b/TUI/effort.zigindex 69c24f4e..de419d84 100644--- a/TUI/effort.zig+++ b/TUI/effort.zig@@ -20,9 +20,16 @@ fn blurb(e: engine.Effort) []const u8 {};}+fn hidesMax() bool {+ const p = engine.g_model_provider;+ const m = engine.g_model_name;+ return std.mem.eql(u8, p, "xai") or std.mem.startsWith(u8, m, "grok");+}+pub fn filter(query: []const u8, out: []engine.Effort) usize {var n: usize = 0;for (all) |e| {+ if (hidesMax() and (e == .max or e == .ultra)) continue;const name = @tagName(e);if (query.len > 0 and std.mem.indexOf(u8, name, query) == null) continue;if (n >= out.len) break;@@ -78,6 +85,21 @@ test "filter matches effort names" {try std.testing.expectEqual(@as(usize, all.len), filter("", &buf));}+test "grok seat hides max and ultra" {+ const saved_p = engine.g_model_provider;+ const saved_m = engine.g_model_name;+ defer {+ engine.g_model_provider = saved_p;+ engine.g_model_name = saved_m;+ }+ engine.g_model_provider = "xai";+ engine.g_model_name = "grok-4.6";+ var buf: [8]engine.Effort = undefined;+ const n = filter("", &buf);+ try std.testing.expectEqual(@as(usize, 4), n);+ for (buf[0..n]) |e| try std.testing.expect(e != .max and e != .ultra);+}+test "effort overlay lists levels and marks current" {var m: Model = undefined;m.setup(std.testing.allocator);diff --git a/src/agent_prompt.zig b/src/agent_prompt.zigindex 219b7843..f0194441 100644--- a/src/agent_prompt.zig+++ b/src/agent_prompt.zig@@ -138,7 +138,12 @@ fn effectiveEffort(self: *Agent) ?engine_events.ReasoningEffort {}return null;}- return if (self.effortApplies()) effortTier(self.reasoning) else null;+ if (!self.effortApplies()) return null;+ const wire = @import("effort_route.zig").wireEffort(self.provider.model, @tagName(self.reasoning));+ inline for (std.meta.tags(main_mod.ReasoningEffort)) |tag| {+ if (std.mem.eql(u8, @tagName(tag), wire)) return effortTier(tag);+ }+ return effortTier(self.reasoning);}fn privacyTier(mode: learning_privacy.Mode) engine_events.PrivacyTier {diff --git a/src/agent_request_body_responses.zig b/src/agent_request_body_responses.zigindex 542cc4bb..00af5959 100644--- a/src/agent_request_body_responses.zig+++ b/src/agent_request_body_responses.zig@@ -87,10 +87,9 @@ pub fn write(self: *Agent, s: *std.json.Stringify, tools: ?[]const u8, force_tootry s.objectField("reasoning");try s.beginObject();try s.objectField("effort");- // Ultra preset → wire value `max`. #379: compaction summaries run at low- // effort — a high-effort reasoner can complete with only reasoning items- // and zero output text, i.e. an empty summary.- try s.write(if (self.compaction_request or self.server_compaction_request) "low" else if (self.reasoning == .ultra) "max" else @tagName(self.reasoning));+ // #379: compaction summaries run at low — a high-effort reasoner can+ // complete with only reasoning items and zero output text.+ try s.write(if (self.compaction_request or self.server_compaction_request) "low" else @import("effort_route.zig").wireEffort(self.provider.model, @tagName(self.reasoning)));try s.endObject();try s.objectField("include");try s.beginArray();@@ -413,6 +412,12 @@ test "xai Responses body is bearer-clean: no codex-isms, xAI-legal fields only (try std.testing.expect(std.mem.indexOf(u8, body, "prompt_cache_options") == null);try std.testing.expect(std.mem.indexOf(u8, body, "context_management") == null);try std.testing.expect(std.mem.indexOf(u8, body, "previous_response_id") == null);++ agent.reasoning = .max;+ const max_body = try agent.buildBody(null, false, true, true);+ defer std.testing.allocator.free(max_body);+ try std.testing.expect(std.mem.indexOf(u8, max_body, "\"effort\":\"high\"") != null);+ try std.testing.expect(std.mem.indexOf(u8, max_body, "\"effort\":\"max\"") == null);}test "xAI Responses splices hosted x_search onto a tools turn; Codex and chat do not" {diff --git a/src/commands_model.zig b/src/commands_model.zigindex 5a30df8e..f03cf1e2 100644--- a/src/commands_model.zig+++ b/src/commands_model.zig@@ -26,7 +26,6 @@ const Rewound = @import("tools.zig").Rewound; // what one /rewind restored/skippconst pricing = @import("pricing.zig");const kimi_catalog = @import("kimi_catalog.zig");const resolveModelName = pricing.resolveModelName;-const pickers = @import("pickers.zig");const modelPicker = pickers.modelPicker;const PickItem = pickers.PickItem;@@ -40,11 +39,9 @@ const providers = @import("providers.zig");const switchProvider = providers.switchProvider;const fallback_config = @import("fallback_config.zig");const serde = @import("serde.zig");-const oauth = @import("oauth.zig");const images_command = @import("images_command.zig");const images = @import("images.zig");-const reasoning_levels = [_]PickItem{.{ .name = "Low", .desc = "Fast responses with lighter reasoning" },.{ .name = "Medium", .desc = "Balances speed and reasoning depth for everyday tasks" },@@ -321,7 +318,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,if (std.mem.eql(u8, line, "/title") or std.mem.eql(u8, line, "/title on") or std.mem.eql(u8, line, "/title off")) {const was_on = root.ai_title;root.ai_title = if (std.mem.eql(u8, line, "/title on")) true else if (std.mem.eql(u8, line, "/title off")) false else !root.ai_title;- if (was_on and !root.ai_title) root.title_generation +%= 1; // discard any detached result already in flight+ if (was_on and !root.ai_title) root.title_generation +%= 1;const saved = saveThinkingSettings(root.io, root.gpa, root.reasoning, root.fast, root.ultracode_mode, root.show_thinking, root.ai_title);try out.print("AI session title: {s} ({s}){s}\n", .{if (root.ai_title) "on" else "off",@@ -361,7 +358,10 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,const arg = std.mem.trim(u8, line[prefix.len..], " \t");if (arg.len == 0 and main_mod.use_color and root.in != null) {const title = try std.fmt.allocPrint(arena, "Reasoning level for {s} ›", .{root.provider.model});- const idx = listPickerAt(root, arena, out, title, &reasoning_levels, @intFromEnum(root.reasoning)) orelse return true;+ const er = @import("effort_route.zig");+ const levels: []const PickItem = if (er.hidesMax(root.provider.id, root.provider.model)) reasoning_levels[0..4] else &reasoning_levels;+ const cur = @min(@intFromEnum(root.reasoning), levels.len - 1);+ const idx = listPickerAt(root, arena, out, title, levels, cur) orelse return true;root.reasoning = @enumFromInt(idx);} else if (std.mem.eql(u8, arg, "med")) {root.reasoning = .medium;@@ -373,6 +373,8 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,try out.flush();return true;};+ if (!@import("effort_route.zig").allows(root.provider.id, root.provider.model, @tagName(root.reasoning)))+ root.reasoning = .high;} else {try out.print("reasoning effort: {s}\n", .{reasoning_levels[@intFromEnum(root.reasoning)].name});try out.flush();diff --git a/src/effort_route.zig b/src/effort_route.zigindex 336a36b9..2deb8275 100644--- a/src/effort_route.zig+++ b/src/effort_route.zig@@ -59,13 +59,31 @@ pub fn omitsDefaultFlashEffort(model: []const u8) bool {return std.mem.indexOf(u8, model, "flash") != null;}+/// grok-4.6 (xAI docs): low | medium | high | xhigh. `max`/`ultra` 400.+pub fn grokFamily(model: []const u8) bool {+ return std.mem.startsWith(u8, model, "grok");+}++/// Hide Max/Ultra in the picker when the current seat cannot take them.+pub fn hidesMax(provider_id: []const u8, model: []const u8) bool {+ return std.mem.eql(u8, provider_id, "xai") or grokFamily(model);+}++pub fn allows(provider_id: []const u8, model: []const u8, tag: []const u8) bool {+ if (!hidesMax(provider_id, model)) return true;+ return std.mem.eql(u8, tag, "low") or std.mem.eql(u8, tag, "medium") or+ std.mem.eql(u8, tag, "high") or std.mem.eql(u8, tag, "xhigh");+}+/// Wire `reasoning_effort` for an effort-capable provider. Flash / Gemini-/// default `medium` becomes `low`: omit still thinks (27 reasoning_tokens-/// on a `pong`); `low` bills 0 on GLM. DeepSeek V4 still thinks at `low`-/// until `thinking.type=disabled` (ADR 0054). `none` is a 400. `/effort high`-/// unchanged.+/// default `medium` becomes `low`. grok maps max/ultra → high (xAI rejects+/// `max`). Other seats still send ultra as `max` (Z.AI / Kimi).pub fn wireEffort(model: []const u8, requested: []const u8) []const u8 {if (std.mem.eql(u8, requested, "medium") and omitsDefaultFlashEffort(model)) return "low";+ if (grokFamily(model)) {+ if (std.mem.eql(u8, requested, "max") or std.mem.eql(u8, requested, "ultra")) return "high";+ return requested;+ }if (std.mem.eql(u8, requested, "ultra")) return "max";return requested;}@@ -96,5 +114,11 @@ test "flash and Gemini map default medium to low; grok and glm-5.3 stay medium"try std.testing.expectEqualStrings("low", wireEffort("glm-5.3-flash", "medium"));try std.testing.expectEqualStrings("high", wireEffort("glm-5.3-flash", "high"));try std.testing.expectEqualStrings("medium", wireEffort("grok-4.6", "medium"));- try std.testing.expectEqualStrings("max", wireEffort("grok-4.6", "ultra"));+ try std.testing.expectEqualStrings("high", wireEffort("grok-4.6", "ultra"));+ try std.testing.expectEqualStrings("high", wireEffort("grok-4.6", "max"));+ try std.testing.expectEqualStrings("xhigh", wireEffort("grok-4.6", "xhigh"));+ try std.testing.expect(hidesMax("xai", "grok-4.6"));+ try std.testing.expect(!hidesMax("codex", "gpt-5.6-sol"));+ try std.testing.expect(!allows("xai", "grok-4.6", "max"));+ try std.testing.expect(allows("xai", "grok-4.6", "high"));}