Skip to content

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

Python

feat(repl): add six Codex reasoning levels

Rach Pradhan0e9189d3286c
diff --git a/scripts/test-json-controls.py b/scripts/test-json-controls.py
index 892ee546..04078ae8 100755
--- a/scripts/test-json-controls.py
+++ b/scripts/test-json-controls.py
@@ -52,9 +52,21 @@ CASES = [
({"type": "set_effort", "level": "medium"},
lambda e: e.get("type") == "effort" and e.get("level") == "medium",
"set_effort medium -> effort ack"),
+ ({"type": "set_effort", "level": "xhigh"},
+ lambda e: e.get("type") == "effort" and e.get("level") == "xhigh",
+ "set_effort xhigh -> effort ack"),
+ ({"type": "set_effort", "level": "max"},
+ lambda e: e.get("type") == "effort" and e.get("level") == "max",
+ "set_effort max -> effort ack"),
+ ({"type": "set_effort", "level": "ultra"},
+ lambda e: e.get("type") == "effort" and e.get("level") == "ultra",
+ "set_effort ultra -> effort ack"),
({"type": "set_effort", "level": "sideways"},
lambda e: e.get("type") == "error" and "low" in e.get("message", ""),
"set_effort invalid -> error"),
+ ({"type": "set_effort", "level": "medium"},
+ lambda e: e.get("type") == "effort" and e.get("level") == "medium",
+ "set_effort reset -> medium"),
({"type": "set_fast", "on": True},
lambda e: e.get("type") == "fast" and e.get("ok") and e.get("on") is True,
"set_fast on -> fast ack"),
diff --git a/src/agent_request.zig b/src/agent_request.zig
index d9bd2003..46357f17 100644
--- a/src/agent_request.zig
+++ b/src/agent_request.zig
@@ -469,7 +469,7 @@ pub fn buildBody(self: *Agent, tools: ?[]const u8, force_tool: bool, stream: boo
// Responses `reasoning.effort` set in the branch below.
if (self.effortApplies() and !self.effort_rejected) {
try s.objectField("reasoning_effort");
- try s.write(@tagName(self.reasoning));
+ try s.write(if (self.reasoning == .ultra) "max" else @tagName(self.reasoning));
}
// Kimi K2.7's model card recommends temperature 1.0 + top_p 0.95
// for its (always-on) Thinking mode; graff otherwise leaves
@@ -508,7 +508,9 @@ pub fn buildBody(self: *Agent, tools: ?[]const u8, force_tool: bool, stream: boo
try s.objectField("reasoning");
try s.beginObject();
try s.objectField("effort");
- try s.write(@tagName(self.reasoning));
+ // Ultra is a Graff/Codex client preset: maximum server reasoning
+ // plus automatic delegation. The backend wire value is `max`.
+ try s.write(if (self.reasoning == .ultra) "max" else @tagName(self.reasoning));
try s.endObject();
try s.objectField("include");
try s.beginArray();
diff --git a/src/cli.zig b/src/cli.zig
index 3bda7814..dad9bfa0 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -21,10 +21,10 @@ const harness_version = root.harness_version;
pub const changelog_text =
\\What's new
\\──────────
- \\0.0.190
- \\ • Codex model discovery now uses Graff's supported Codex client version
- \\ • Older installed Codex CLIs and incompatible caches can no longer hide Sol
- \\ • `graff models refresh` reports whether the live account fetch succeeded
+ \\0.0.191
+ \\ • `/effort` now opens Codex's six-level reasoning picker in the REPL
+ \\ • Extra high, Max, and Ultra work through slash commands and JSON controls
+ \\ • Ultra combines maximum server reasoning with automatic task delegation
\\
;
diff --git a/src/commands_misc.zig b/src/commands_misc.zig
index 010ebb5e..d1f24173 100644
--- a/src/commands_misc.zig
+++ b/src/commands_misc.zig
@@ -400,7 +400,7 @@ pub fn handleRest(line: []const u8, out: *Io.Writer) !void {
\\ /key [prov key] show API-key status; /key <provider> <key> adds one live (+ Keychain)
\\ /login [tgt] OAuth sign-in (no key to paste): codegraff | codex (alias oai) | kimi; bare → picker
\\ /keepcontext toggle keeping the conversation when /model switches wire format (default on)
- \\ /effort thinking depth: low|medium|high (codex, deepseek, codegraff; default medium, persists)
+ \\ /effort reasoning picker: low|medium|high|xhigh|max|ultra (persists)
\\ /reasoning alias for /effort
\\ /fast codex only: priority service tier for lower latency (toggle, persists)
\\ /strict toggle "every message is a tool" mode
diff --git a/src/commands_model.zig b/src/commands_model.zig
index 976c27a4..86d93ad5 100644
--- a/src/commands_model.zig
+++ b/src/commands_model.zig
@@ -33,6 +33,7 @@ const pickers = @import("pickers.zig");
const modelPicker = pickers.modelPicker;
const PickItem = pickers.PickItem;
const listPicker = pickers.listPicker;
+const listPickerAt = pickers.listPickerAt;
const pickUltracodeMode = pickers.pickUltracodeMode;
const reloadLoginKey = pickers.reloadLoginKey;
const offerProviderAuth = pickers.offerProviderAuth;
@@ -42,6 +43,15 @@ const switchProvider = providers.switchProvider;
const oauth = @import("oauth.zig");
+const reasoning_levels = [_]PickItem{
+ .{ .name = "Low", .desc = "Fast responses with lighter reasoning" },
+ .{ .name = "Medium", .desc = "Balances speed and reasoning depth for everyday tasks" },
+ .{ .name = "High", .desc = "Greater reasoning depth for complex problems" },
+ .{ .name = "Extra high", .desc = "Extra high reasoning depth for complex problems" },
+ .{ .name = "Max", .desc = "Maximum reasoning depth for the hardest problems" },
+ .{ .name = "Ultra", .desc = "Maximum reasoning with automatic task delegation" },
+};
+
const vision = @import("vision.zig");
const stageImagePath = vision.stageImagePath;
const visionCapable = vision.visionCapable;
@@ -277,20 +287,28 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
if (std.mem.startsWith(u8, line, "/effort") or std.mem.startsWith(u8, line, "/reasoning")) {
const prefix: []const u8 = if (std.mem.startsWith(u8, line, "/effort")) "/effort" else "/reasoning";
const arg = std.mem.trim(u8, line[prefix.len..], " \t");
- if (std.mem.eql(u8, arg, "low")) {
- root.reasoning = .low;
- } else if (std.mem.eql(u8, arg, "medium") or std.mem.eql(u8, arg, "med")) {
+ 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;
+ root.reasoning = @enumFromInt(idx);
+ } else if (std.mem.eql(u8, arg, "med")) {
root.reasoning = .medium;
- } else if (std.mem.eql(u8, arg, "high")) {
- root.reasoning = .high;
+ } else if (std.mem.eql(u8, arg, "extra") or std.mem.eql(u8, arg, "extra-high") or std.mem.eql(u8, arg, "extra high")) {
+ root.reasoning = .xhigh;
} else if (arg.len != 0) {
- try out.writeAll("usage: /effort low|medium|high\n");
+ root.reasoning = std.meta.stringToEnum(main_mod.ReasoningEffort, arg) orelse {
+ try out.writeAll("usage: /effort low|medium|high|xhigh|max|ultra\n");
+ try out.flush();
+ return true;
+ };
+ } else {
+ try out.print("reasoning effort: {s}\n", .{reasoning_levels[@intFromEnum(root.reasoning)].name});
try out.flush();
return true;
}
_ = saveThinkingSettings(root.io, root.gpa, root.reasoning, root.fast, root.ultracode_mode, root.show_thinking, root.ai_title);
try out.print("reasoning effort: {s}{s}\n", .{
- @tagName(root.reasoning),
+ reasoning_levels[@intFromEnum(root.reasoning)].name,
if (!root.effortApplies()) " (current model ignores it — applies to codex, deepseek, codegraff)" else "",
});
try out.flush();
diff --git a/src/main.zig b/src/main.zig
index 0abcaf8a..8b60b121 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -142,7 +142,7 @@ const telemetry = @import("telemetry.zig");
pub var g_fleet: bool = true;
const unixMs = util.unixMs;
/// Reasoning depth for codex/responses (OpenAI Responses `reasoning.effort`).
-pub const ReasoningEffort = enum { low, medium, high };
+pub const ReasoningEffort = enum { low, medium, high, xhigh, max, ultra };
pub const repl_commands = [_][]const u8{ "/model", "/models", "/clear", "/new", "/rename", "/goal", "/loop", "/bash", "/plan", "/key", "/keepcontext", "/effort", "/fast", "/ultracode", "/thinking", "/title", "/reasoning", "/strict", "/yolo", "/trace", "/fleet", "/trajectory", "/agents", "/skills", "/hooks", "/compact", "/rewind", "/image", "/paste", "/save", "/resume", "/sessions", "/todo", "/jobs", "/cost", "/animation", "/theme", "/mcp", "/help" };
// Lifecycle hooks (Hook/Hooks config types + settings loader + per-hook subprocess runner) live in hooks.zig; g_hooks below, dispatch, and the codedb-guard cache stay here.
const hooks = @import("hooks.zig");
diff --git a/src/mainloop.zig b/src/mainloop.zig
index b78f3291..453d57d8 100644
--- a/src/mainloop.zig
+++ b/src/mainloop.zig
@@ -209,16 +209,10 @@ pub fn run(ctx: *Ctx) !void {
}
if (std.mem.eql(u8, rtype, "set_effort")) {
const level = if (parsed.object.get("level")) |v| (if (v == .string) v.string else "") else "";
- if (std.mem.eql(u8, level, "low")) {
- ctx.root.reasoning = .low;
- } else if (std.mem.eql(u8, level, "medium")) {
- ctx.root.reasoning = .medium;
- } else if (std.mem.eql(u8, level, "high")) {
- ctx.root.reasoning = .high;
- } else {
- ctx.root.emit(.{ .type = "error", .message = "set_effort needs level 'low', 'medium', or 'high'" });
+ ctx.root.reasoning = std.meta.stringToEnum(main_mod.ReasoningEffort, level) orelse {
+ ctx.root.emit(.{ .type = "error", .message = "set_effort needs level low|medium|high|xhigh|max|ultra" });
continue;
- }
+ };
_ = repl_glue.saveThinkingSettings(ctx.root.io, ctx.root.gpa, ctx.root.reasoning, ctx.root.fast, ctx.root.ultracode_mode, ctx.root.show_thinking, ctx.root.ai_title);
ctx.root.emit(.{ .type = "effort", .ok = true, .level = level, .applies = ctx.root.effortApplies() });
continue;
@@ -408,7 +402,7 @@ pub fn run(ctx: *Ctx) !void {
}
// "ultracode" codeword or persistent /ultracode mode: opt turns into multi-agent workflow mode.
- const ultracode_msg = try pickers.applyUltracodeSteering(ctx.arena, msg, ctx.root.ultracode_mode);
+ const ultracode_msg = try pickers.applyUltracodeSteering(ctx.arena, msg, ctx.root.ultracode_mode or ctx.root.reasoning == .ultra);
if (ultracode_msg.explicit) {
if (!main_mod.json_mode) {
if (ctx.interactive) {
diff --git a/src/pickers.zig b/src/pickers.zig
index 0e9ba9d8..6caae787 100644
--- a/src/pickers.zig
+++ b/src/pickers.zig
@@ -182,6 +182,12 @@ pub const PickItem = struct { name: []const u8, desc: []const u8 = "" };
/// filter on name or description, ↑/↓ to move, Enter picks, Ctrl-C cancels.
/// Returns the index into `items`, or null.
pub fn listPicker(root: *Agent, arena: Allocator, out: *Io.Writer, title: []const u8, items: []const PickItem) ?usize {
+ return listPickerAt(root, arena, out, title, items, 0);
+}
+
+/// listPicker with an initially selected row (used by settings pickers to
+/// highlight the current value while retaining the canonical list order).
+pub fn listPickerAt(root: *Agent, arena: Allocator, out: *Io.Writer, title: []const u8, items: []const PickItem, initial: usize) ?usize {
const in = root.in orelse return null;
if (items.len == 0) return null;
const raw_state = tty.enterRaw(true) orelse return null;
@@ -198,7 +204,7 @@ pub fn listPicker(root: *Agent, arena: Allocator, out: *Io.Writer, title: []cons
defer scored.deinit(arena);
var filtered: std.ArrayList(usize) = .empty;
defer filtered.deinit(arena);
- var sel: usize = 0;
+ var sel: usize = @min(initial, items.len - 1);
const visible = 18;
while (true) {
@@ -341,7 +347,7 @@ pub const command_menu = [_]PickItem{
.{ .name = "/yolo", .desc = "toggle permission prompts" },
.{ .name = "/strict", .desc = "toggle every-message-is-a-tool mode" },
.{ .name = "/keepcontext", .desc = "keep history across wire-format switches" },
- .{ .name = "/effort", .desc = "thinking depth: low|medium|high (codex, deepseek, codegraff)" },
+ .{ .name = "/effort", .desc = "reasoning picker: low through ultra (Codex)" },
.{ .name = "/reasoning", .desc = "alias for /effort" },
.{ .name = "/fast", .desc = "codex priority service tier — lower latency on supported models" },
.{ .name = "/ultracode", .desc = "toggle persistent ultracode (multi-agent workflow) mode" },
diff --git a/src/repl.zig b/src/repl.zig
index c2b02b98..10fb8d45 100644
--- a/src/repl.zig
+++ b/src/repl.zig
@@ -51,7 +51,7 @@ test {
// keeps repl.zig decoupled from the harness's Agent/Provider (no circular import).
// ---------------------------------------------------------------------------
-pub const Effort = enum { low, medium, high };
+pub const Effort = enum { low, medium, high, xhigh, max, ultra };
pub const Turn = struct {
role: Role,
@@ -461,6 +461,8 @@ test "model: commands toggle settings" {
defer m.deinit();
_ = m.applyLine("/effort high");
try std.testing.expectEqual(Effort.high, m.effort);
+ _ = m.applyLine("/effort ultra");
+ try std.testing.expectEqual(Effort.ultra, m.effort);
_ = m.applyLine("/fast on");
try std.testing.expect(m.fast);
_ = m.applyLine("/ultracode");
diff --git a/src/repl_glue.zig b/src/repl_glue.zig
index 1a51c040..93ddd98a 100644
--- a/src/repl_glue.zig
+++ b/src/repl_glue.zig
@@ -197,6 +197,9 @@ pub fn replTurnCb(ctx_ptr: ?*anyopaque, gpa: Allocator, history: []const repl.Tu
.low => .low,
.medium => .medium,
.high => .high,
+ .xhigh => .xhigh,
+ .max => .max,
+ .ultra => .ultra,
},
.fast = params.fast,
.ultracode_mode = params.ultracode,
@@ -331,20 +334,14 @@ pub fn saveThinkingSettings(io: Io, gpa: Allocator, effort: ReasoningEffort, fas
}
/// Load persisted thinking controls into the root agent at startup:
-/// {"effort": "low|medium|high"} and {"fast": true}. Best-effort — a missing
+/// {"effort": "low|medium|high|xhigh|max|ultra"} and {"fast": true}. Best-effort — a missing
/// or garbled file just leaves the defaults (medium, off).
pub fn loadThinkingSettings(io: Io, arena: Allocator, root: *Agent) void {
const data = Io.Dir.cwd().readFileAlloc(io, Approvals.settings_path, arena, .limited(1 << 20)) catch return;
const v = std.json.parseFromSliceLeaky(Value, arena, data, .{ .allocate = .alloc_always }) catch return;
if (v != .object) return;
if (v.object.get("effort")) |e| if (e == .string) {
- if (std.mem.eql(u8, e.string, "low")) {
- root.reasoning = .low;
- } else if (std.mem.eql(u8, e.string, "medium")) {
- root.reasoning = .medium;
- } else if (std.mem.eql(u8, e.string, "high")) {
- root.reasoning = .high;
- }
+ root.reasoning = std.meta.stringToEnum(ReasoningEffort, e.string) orelse root.reasoning;
};
if (v.object.get("fast")) |fv| if (fv == .bool) {
root.fast = fv.bool;
diff --git a/src/repl_model_commands.zig b/src/repl_model_commands.zig
index 4c906329..4d8280a2 100644
--- a/src/repl_model_commands.zig
+++ b/src/repl_model_commands.zig
@@ -53,10 +53,11 @@ pub fn runCommand(self: *Model, line: []const u8) void {
} else if (std.mem.eql(u8, cmd, "/models")) {
if (repl.g_models.len > 0) self.pushFmt(.info, "available models:\n {s}\nswitch with /model <name>", .{repl.g_models}) catch {} else self.push(.info, "no model table (offline mode)") catch {};
} else if (eqlAny(cmd, &.{ "/effort", "/reasoning" })) {
- if (std.mem.eql(u8, arg, "low")) self.effort = .low else if (std.mem.eql(u8, arg, "high")) self.effort = .high else if (std.mem.eql(u8, arg, "medium") or std.mem.eql(u8, arg, "med")) self.effort = .medium else {
- self.push(.info, "usage: /effort low|medium|high") catch {};
+ const normalized = if (std.mem.eql(u8, arg, "med")) "medium" else if (std.mem.eql(u8, arg, "extra") or std.mem.eql(u8, arg, "extra-high") or std.mem.eql(u8, arg, "extra high")) "xhigh" else arg;
+ self.effort = std.meta.stringToEnum(repl.Effort, normalized) orelse {
+ self.push(.info, "usage: /effort low|medium|high|xhigh|max|ultra") catch {};
return;
- }
+ };
self.pushFmt(.info, "reasoning effort: {s}", .{@tagName(self.effort)}) catch {};
} else if (std.mem.eql(u8, cmd, "/fast")) {
self.fast = parseToggle(arg, self.fast);
diff --git a/src/repl_model_turn.zig b/src/repl_model_turn.zig
index 25f79beb..4e19fa3a 100644
--- a/src/repl_model_turn.zig
+++ b/src/repl_model_turn.zig
@@ -47,7 +47,7 @@ pub fn startJob(self: *Model) void {
.effort = self.effort,
.fast = self.fast,
.thinking = self.thinking_show,
- .ultracode = self.ultracode,
+ .ultracode = self.ultracode or self.effort == .ultra,
.goal = self.goal orelse "",
},
.stream = .{ .buf = self.alloc.alloc(u8, 256 * 1024) catch &.{} },
diff --git a/src/repl_util.zig b/src/repl_util.zig
index 4d5d76be..cde9fcda 100644
--- a/src/repl_util.zig
+++ b/src/repl_util.zig
@@ -11,7 +11,7 @@ pub const HELP_CHAT =
\\ /help /clear /new /quit conversation
\\ /rewind /compact /cost history
\\ /model [name] /models model (switch / list)
- \\ /effort low|med|high /reasoning reasoning depth
+ \\ /effort low|med|high|xhigh|max|ultra reasoning depth
\\ /fast /thinking /ultracode thinking controls (toggles)
\\ /goal <text> standing objective (tracked as a checklist)
\\ /plan /strict /yolo /keepcontext /title modes
diff --git a/src/schema.zig b/src/schema.zig
index 64bc1c1e..2d30e792 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -24,7 +24,7 @@ const provider_specs = provider_mod.provider_specs;
const schema_protocol_json =
\\{
\\ "transport": "newline-delimited JSON over stdin/stdout (--json)",
- \\ "request": "one JSON object per line: {\"type\":\"user\",\"text\":\"...\"} sends a user turn; {\"type\":\"answer\",\"text\":\"...\",\"cancelled\":false,\"call_id\":\"optional\"} answers an active ask_user event; {\"type\":\"set_system_prompt\",\"text\":\"...\",\"append\":false} replaces (or with append=true extends) the system prompt between turns and acks with a system_prompt event; {\"type\":\"set_model\",\"model\":\"gpt-5.5\",\"provider\":\"codex\"}, {\"type\":\"compact\"}, {\"type\":\"set_mode\",\"mode\":\"plan|normal\"}, and {\"type\":\"set_agent\",\"id\":\"reviewer\"}, {\"type\":\"set_effort\",\"level\":\"low|medium|high\"}, and {\"type\":\"set_fast\",\"on\":true} are live control requests acked by model/compact/mode/agent/effort/fast/ultracode events. For compatibility, set_model also accepts legacy {\"name\":\"provider model|model\"}. NOTE: the system prompt heads the KV-cached prefix, so any mutation invalidates the cache for the whole conversation (per Manus context-engineering lessons) — set it at spawn when possible and mutate only at task boundaries",
+ \\ "request": "one JSON object per line: {\"type\":\"user\",\"text\":\"...\"} sends a user turn; {\"type\":\"answer\",\"text\":\"...\",\"cancelled\":false,\"call_id\":\"optional\"} answers an active ask_user event; {\"type\":\"set_system_prompt\",\"text\":\"...\",\"append\":false} replaces (or with append=true extends) the system prompt between turns and acks with a system_prompt event; {\"type\":\"set_model\",\"model\":\"gpt-5.5\",\"provider\":\"codex\"}, {\"type\":\"compact\"}, {\"type\":\"set_mode\",\"mode\":\"plan|normal\"}, and {\"type\":\"set_agent\",\"id\":\"reviewer\"}, {\"type\":\"set_effort\",\"level\":\"low|medium|high|xhigh|max|ultra\"}, and {\"type\":\"set_fast\",\"on\":true} are live control requests acked by model/compact/mode/agent/effort/fast/ultracode events. For compatibility, set_model also accepts legacy {\"name\":\"provider model|model\"}. NOTE: the system prompt heads the KV-cached prefix, so any mutation invalidates the cache for the whole conversation (per Manus context-engineering lessons) — set it at spawn when possible and mutate only at task boundaries",
\\ "score_request": "{\"type\":\"score\",\"prompt_sha\":\"<16 hex>\",\"score\":0.7,\"notes\":\"...\",\"parent_sha\":\"<16 hex, optional>\"} appends an evaluation record for an agent/prompt variant to harness.trajectory.jsonl (the append-only DGM-style archive; prompt_sha = first 8 bytes of SHA-256 of the system prompt, hex; parent_sha records which prompt this variant was mutated from — the lineage edge DGM parent selection counts children with) and acks with a score event",
\\ "events": [
\\ {"type": "text", "text": "assistant text delta"},
diff --git a/src/session_run.zig b/src/session_run.zig
index a62e4ab4..38f5b5fc 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -95,7 +95,7 @@ pub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_m
root.in = null; // gate: deny instead of prompt; ask_user: self-decide
root.out = null; // tool progress → stderr; stdout carries only the answer
root.stream_quiet = true;
- const ultracode_msg = try pickers.applyUltracodeSteering(arena, prompt_text, root.ultracode_mode);
+ const ultracode_msg = try pickers.applyUltracodeSteering(arena, prompt_text, root.ultracode_mode or root.reasoning == .ultra);
if (ultracode_msg.explicit) {
tracer.note("ultracode", prompt_text[0..@min(prompt_text.len, 120)]);
if (telemetry.g_telem) |t| t.ultracode();