Skip to content

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

Python

feat(models): gpt-5.6 (Sol/Terra/Luna) + `graff models [refresh]` from models.dev

justrach3b495d94702f
diff --git a/sdk/py/harness_sdk.py b/sdk/py/harness_sdk.py
index a48604ec..0f26c273 100644
--- a/sdk/py/harness_sdk.py
+++ b/sdk/py/harness_sdk.py
@@ -13,7 +13,7 @@ import urllib.error
import urllib.request
from typing import Iterator, Optional
-MODELS = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.4", "gpt-5.4-pro", "gpt-5.5", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"]
+MODELS = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-terra", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"]
TOOLS = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "subagent", "workflow"]
PROVIDERS = ["anthropic", "codegraff", "deepseek", "openai", "minimax", "xiaomi", "kimi", "moonshot", "xai", "zai", "fugu", "fireworks", "mlx", "lmstudio", "codex"]
diff --git a/sdk/ts/harness.ts b/sdk/ts/harness.ts
index 9e989c39..1f4bfbc8 100644
--- a/sdk/ts/harness.ts
+++ b/sdk/ts/harness.ts
@@ -10,7 +10,7 @@ import { createInterface } from "node:readline";
export const HARNESS_VERSION = "0.4";
-export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.4" | "gpt-5.4-pro" | "gpt-5.5" | "grok-4.3" | "grok-build" | "kimi-k2.6" | "kimi-k2.7" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit";
+export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "kimi-k2.6" | "kimi-k2.7" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit";
export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "subagent" | "workflow";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
@@ -410,5 +410,5 @@ export async function* runAgent(opts: RunAgentOptions): AsyncGenerator<Event> {
}
}
-export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.4", "gpt-5.4-pro", "gpt-5.5", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
+export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-terra", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "subagent", "workflow"];
diff --git a/sdk/ts/remote.ts b/sdk/ts/remote.ts
index 44fe0673..f706bb67 100644
--- a/sdk/ts/remote.ts
+++ b/sdk/ts/remote.ts
@@ -9,7 +9,7 @@
export const HARNESS_VERSION = "0.4";
-export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.4" | "gpt-5.4-pro" | "gpt-5.5" | "grok-4.3" | "grok-build" | "kimi-k2.6" | "kimi-k2.7" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit";
+export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "kimi-k2.6" | "kimi-k2.7" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit";
export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "subagent" | "workflow";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
@@ -244,5 +244,5 @@ export async function* runAgentRemote(opts: RunAgentRemoteOptions): AsyncGenerat
}
}
-export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.4", "gpt-5.4-pro", "gpt-5.5", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
+export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-terra", "grok-4.3", "grok-build", "kimi-k2.6", "kimi-k2.7", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "subagent", "workflow"];
diff --git a/src/args.zig b/src/args.zig
index 48f9e3fe..e1c8bd4f 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -166,7 +166,7 @@ pub fn parse(init: std.process.Init) !Flags {
flags.is_subcommand = flags.positionals.items.len > 0 and
(std.mem.eql(u8, flags.positionals.items[0], "login") or std.mem.eql(u8, flags.positionals.items[0], "key") or std.mem.eql(u8, flags.positionals.items[0], "mcp") or
std.mem.eql(u8, flags.positionals.items[0], "serve") or std.mem.eql(u8, flags.positionals.items[0], "update") or std.mem.eql(u8, flags.positionals.items[0], "title") or std.mem.eql(u8, flags.positionals.items[0], "repl") or
- std.mem.eql(u8, flags.positionals.items[0], "worktree") or std.mem.eql(u8, flags.positionals.items[0], "sandboxes") or std.mem.eql(u8, flags.positionals.items[0], "cube"));
+ std.mem.eql(u8, flags.positionals.items[0], "worktree") or std.mem.eql(u8, flags.positionals.items[0], "sandboxes") or std.mem.eql(u8, flags.positionals.items[0], "cube") or std.mem.eql(u8, flags.positionals.items[0], "models"));
if (!flags.is_subcommand and flags.positionals.items.len > 0) {
flags.oneshot_prompt = try std.mem.join(arena, " ", flags.positionals.items);
}
diff --git a/src/cli.zig b/src/cli.zig
index dd9f885b..10e6b3a2 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -42,6 +42,7 @@ pub const usage_text =
\\ graff login kimi Kimi Code OAuth login (device-code)
\\ graff key set <provider> <key> store a key (macOS Keychain, else 0600 file)
\\ graff key list show which providers have keys
+ \\ graff models [refresh] list the model catalog; refresh pulls window/price from models.dev
\\ graff mcp add <name> -- <cmd> add an MCP server to .mcp.json
\\ graff mcp list configured MCP servers
\\ graff worktree list list the per-tab worktrees created by -w
diff --git a/src/main.zig b/src/main.zig
index 57992edd..3325ca1a 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -50,10 +50,12 @@ pub var dedupe_tool_calls = false; // --dedupe-tool-calls: reject duplicate root
pub var plan_mode = false; // /plan: read-only — mutating tools are denied, the model proposes
pub var unattended = false; // -p one-shot: no human to prompt; unapproved tool calls are denied
const pricing = @import("pricing.zig"); // model pricing/catalog + session cost tally
+const models_cache = @import("models_cache.zig"); // graff models [refresh]: models.dev metadata cache + runtime overlay
const util = @import("util.zig"); // shared JSON ObjectMap getters (strFieldObj/intFieldObj)
test {
// build.zig's unit_tests root is main.zig only — reference every split-out module so their test blocks keep running.
_ = pricing;
+ _ = models_cache;
_ = ansi;
_ = serve;
_ = util;
diff --git a/src/models_cache.zig b/src/models_cache.zig
new file mode 100644
index 00000000..18386ad8
--- /dev/null
+++ b/src/models_cache.zig
@@ -0,0 +1,338 @@
+//! `graff models` — the model-catalog CLI and the models.dev refresh cache.
+//!
+//! graff's catalog (pricing.model_table / price_table) is a hand-maintained
+//! snapshot: instant to read, works offline, and the source of truth for
+//! ROUTING (which provider serves a name). But snapshots drift as OpenAI/etc.
+//! ship models. This module keeps the METADATA (context window + per-token
+//! price) fresh without a rebuild and without slowing startup:
+//!
+//! * `graff models` — print the effective catalog (baked + overlay)
+//! * `graff models refresh` — GET https://models.dev/api.json, extract the
+//! window/price for every model graff already
+//! knows by name, and cache it to disk
+//!
+//! At startup resolveKeys() calls loadOverlay(), which reads that small cache
+//! (NOT the 3 MB models.dev doc — startup stays instant) into two runtime
+//! overlays in pricing.zig that priceFor()/contextFor() consult before the
+//! baked table. No cache / offline / fresh install → the baked table is the
+//! sole source, so nothing here can break a run. Routing is untouched: the
+//! overlay only refreshes numbers for names the baked table already routes.
+//!
+//! Cache path: ~/.codegraff/models.json, falling back to the flat dotfile
+//! ~/.codegraff-models.json when that directory doesn't exist (zig 0.16's
+//! Io.Dir has no mkdir, and the flat form matches ~/.simple-harness-*.json).
+
+const std = @import("std");
+const Io = std.Io;
+const Value = std.json.Value;
+const Allocator = std.mem.Allocator;
+
+const pricing = @import("pricing.zig");
+const util = @import("util.zig");
+const strFieldObj = util.strFieldObj;
+
+const models_dev_url = "https://models.dev/api.json";
+
+/// models.dev provider ids to trust FIRST when a model id appears under
+/// several providers — a vendor's own listing beats a reseller's markup
+/// (models.dev keys resellers like requesty/openrouter/vercel alongside the
+/// canonical labs). Names not found here fall back to an any-provider scan.
+const canonical_providers = [_][]const u8{
+ "openai", "anthropic", "deepseek", "xai", "zai",
+ "z-ai", "zhipuai", "google", "minimax", "moonshotai",
+ "moonshot", "mistral", "meta", "xiaomi", "fireworks-ai",
+ "fireworks", "alibaba",
+};
+
+/// One refreshed metadata row — the subset of a models.dev model we cache.
+const Meta = struct { name: []const u8, context: u64, in: f64, out: f64, cache: f64 };
+
+/// Read a JSON number field as f64 (models.dev costs are floats, windows ints).
+fn numField(obj: std.json.ObjectMap, name: []const u8) ?f64 {
+ const v = obj.get(name) orelse return null;
+ return switch (v) {
+ .float => |f| f,
+ .integer => |i| @floatFromInt(i),
+ .number_string => |s| std.fmt.parseFloat(f64, s) catch null,
+ else => null,
+ };
+}
+
+/// Non-negative integer field as u64 (0 when absent / negative / wrong type).
+fn u64Field(obj: std.json.ObjectMap, name: []const u8) u64 {
+ const v = obj.get(name) orelse return 0;
+ return switch (v) {
+ .integer => |i| if (i > 0) @intCast(i) else 0,
+ .float => |f| if (f > 0) @intFromFloat(f) else 0,
+ else => 0,
+ };
+}
+
+fn dirPath(arena: Allocator, home: []const u8) []const u8 {
+ return std.fmt.allocPrint(arena, "{s}/.codegraff/models.json", .{home}) catch "";
+}
+fn flatPath(arena: Allocator, home: []const u8) []const u8 {
+ return std.fmt.allocPrint(arena, "{s}/.codegraff-models.json", .{home}) catch "";
+}
+
+/// GET models.dev/api.json (~3 MB) and parse it into the arena, or null on any
+/// failure (offline, non-200, malformed) — the caller falls back to baked data.
+fn fetchModelsDev(io: Io, gpa: Allocator, arena: Allocator) ?Value {
+ var client: std.http.Client = .{ .allocator = gpa, .io = io };
+ defer client.deinit();
+ var aw: Io.Writer.Allocating = .init(arena);
+ const extra = [_]std.http.Header{
+ .{ .name = "Accept", .value = "application/json" },
+ .{ .name = "User-Agent", .value = "graff-models/1.0" }, // models.dev 403s a bare UA
+ };
+ const res = client.fetch(.{
+ .location = .{ .url = models_dev_url },
+ .method = .GET,
+ .response_writer = &aw.writer,
+ .extra_headers = &extra,
+ }) catch return null;
+ if (@intFromEnum(res.status) != 200) return null;
+ const v = std.json.parseFromSliceLeaky(Value, arena, aw.writer.buffered(), .{ .allocate = .alloc_always }) catch return null;
+ if (v != .object) return null;
+ return v;
+}
+
+/// Extract window + costs from one models.dev model object.
+fn metaOf(m: std.json.ObjectMap, name: []const u8) Meta {
+ var context: u64 = 0;
+ if (m.get("limit")) |lv| if (lv == .object) {
+ context = u64Field(lv.object, "context");
+ };
+ var in: f64 = 0;
+ var out: f64 = 0;
+ var cache: f64 = 0;
+ if (m.get("cost")) |cv| if (cv == .object) {
+ in = numField(cv.object, "input") orelse 0;
+ out = numField(cv.object, "output") orelse 0;
+ cache = numField(cv.object, "cache_read") orelse 0;
+ };
+ return .{ .name = name, .context = context, .in = in, .out = out, .cache = cache };
+}
+
+/// Find `name` in a provider's models map: exact id key first, then the same
+/// normalized-alias rule pricing uses (so "gpt5.6" matches "gpt-5.6").
+fn matchInModels(models: std.json.ObjectMap, name: []const u8) ?Meta {
+ if (models.get(name)) |mv| if (mv == .object) return metaOf(mv.object, name);
+ var it = models.iterator();
+ while (it.next()) |e| {
+ if (e.value_ptr.* != .object) continue;
+ if (pricing.modelAliasEquals(e.key_ptr.*, name)) return metaOf(e.value_ptr.object, name);
+ }
+ return null;
+}
+
+fn modelsOf(doc: std.json.ObjectMap, provider_id: []const u8) ?std.json.ObjectMap {
+ const pv = doc.get(provider_id) orelse return null;
+ if (pv != .object) return null;
+ const mv = pv.object.get("models") orelse return null;
+ if (mv != .object) return null;
+ return mv.object;
+}
+
+/// Look up a graff model name across the whole models.dev doc, preferring the
+/// canonical vendor providers before scanning everything else.
+fn findModel(doc: std.json.ObjectMap, name: []const u8) ?Meta {
+ for (canonical_providers) |pid| {
+ if (modelsOf(doc, pid)) |models| if (matchInModels(models, name)) |m| return m;
+ }
+ var it = doc.iterator();
+ while (it.next()) |entry| {
+ if (entry.value_ptr.* != .object) continue;
+ const models = entry.value_ptr.object.get("models") orelse continue;
+ if (models != .object) continue;
+ if (matchInModels(models.object, name)) |m| return m;
+ }
+ return null;
+}
+
+/// Serialize the refreshed rows and write them to the cache file, returning the
+/// path actually written (dir form first, flat dotfile fallback), or null.
+fn writeCache(io: Io, arena: Allocator, home: []const u8, metas: []const Meta) ?[]const u8 {
+ var aw: Io.Writer.Allocating = .init(arena);
+ aw.writer.writeAll("{\"source\":\"models.dev/api.json\",\"models\":[") catch return null;
+ for (metas, 0..) |m, i| {
+ if (i > 0) aw.writer.writeAll(",") catch return null;
+ aw.writer.print("{{\"name\":\"{s}\",\"context\":{d},\"in\":{d},\"out\":{d},\"cache\":{d}}}", .{ m.name, m.context, m.in, m.out, m.cache }) catch return null;
+ }
+ aw.writer.writeAll("]}\n") catch return null;
+ const bytes = aw.writer.buffered();
+ for ([_][]const u8{ dirPath(arena, home), flatPath(arena, home) }) |path| {
+ if (path.len == 0) continue;
+ const f = Io.Dir.cwd().createFile(io, path, .{}) catch continue;
+ defer f.close(io);
+ var wbuf: [4096]u8 = undefined;
+ var fw = f.writer(io, &wbuf);
+ fw.interface.writeAll(bytes) catch continue;
+ fw.interface.flush() catch continue;
+ return path;
+ }
+ return null;
+}
+
+/// Read the cache bytes (dir form first, then flat), or null when neither is
+/// present — the overlays stay empty and the baked table is the sole source.
+fn readCache(io: Io, arena: Allocator, home: []const u8) ?[]const u8 {
+ for ([_][]const u8{ dirPath(arena, home), flatPath(arena, home) }) |path| {
+ if (path.len == 0) continue;
+ if (Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(256 * 1024))) |data| return data else |_| {}
+ }
+ return null;
+}
+
+/// Populate pricing.zig's runtime overlays from the on-disk cache. Called once
+/// at startup (resolveKeys) and again right after a refresh. No-op when the
+/// cache is absent/unreadable/malformed, so it never blocks or fails a run.
+pub fn loadOverlay(io: Io, arena: Allocator, home: []const u8) void {
+ const data = readCache(io, arena, home) orelse return;
+ const v = std.json.parseFromSliceLeaky(Value, arena, data, .{ .allocate = .alloc_always }) catch return;
+ if (v != .object) return;
+ const arr = v.object.get("models") orelse return;
+ if (arr != .array) return;
+ var prices: std.ArrayList(pricing.ModelPrice) = .empty;
+ var ctxs: std.ArrayList(pricing.ModelInfo) = .empty;
+ for (arr.array.items) |item| {
+ if (item != .object) continue;
+ const name = strFieldObj(item.object, "name") orelse continue;
+ if (name.len == 0) continue;
+ const nm = arena.dupe(u8, name) catch continue;
+ const in = numField(item.object, "in") orelse 0;
+ const out = numField(item.object, "out") orelse 0;
+ const cache = numField(item.object, "cache") orelse 0;
+ const context = u64Field(item.object, "context");
+ if (in > 0 or out > 0) prices.append(arena, .{ .name = nm, .in = in, .out = out, .cache = cache }) catch {};
+ if (context > 0) ctxs.append(arena, .{ .provider = "", .name = nm, .context = context }) catch {};
+ }
+ if (prices.items.len > 0) pricing.price_overlay = prices.toOwnedSlice(arena) catch pricing.price_overlay;
+ if (ctxs.items.len > 0) pricing.context_overlay = ctxs.toOwnedSlice(arena) catch pricing.context_overlay;
+}
+
+/// FYI after a refresh: upstream gpt-5+/claude models.dev lists that graff's
+/// catalog doesn't yet, so the user can spot a new release at a glance.
+fn reportNew(doc: std.json.ObjectMap, out: *Io.Writer) void {
+ const checks = [_]struct { pid: []const u8, prefix: []const u8 }{
+ .{ .pid = "openai", .prefix = "gpt-5" },
+ .{ .pid = "openai", .prefix = "gpt-6" },
+ .{ .pid = "anthropic", .prefix = "claude" },
+ };
+ var shown: usize = 0;
+ for (checks) |c| {
+ const models = modelsOf(doc, c.pid) orelse continue;
+ var it = models.iterator();
+ while (it.next()) |e| {
+ const id = e.key_ptr.*;
+ if (!std.mem.startsWith(u8, id, c.prefix)) continue;
+ if (pricing.modelInTable(id)) continue;
+ if (shown == 0) out.writeAll("\nupstream models.dev lists that graff's catalog doesn't yet:\n") catch {};
+ if (shown < 12) out.print(" · {s} ({s})\n", .{ id, c.pid }) catch {};
+ shown += 1;
+ }
+ }
+ if (shown > 12) out.print(" … and {d} more\n", .{shown - 12}) catch {};
+}
+
+/// `graff models refresh`: pull models.dev, cache window+price for every model
+/// graff knows by name, apply it live, and report what changed / what's new.
+pub fn refresh(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, out: *Io.Writer) !void {
+ try out.print("fetching {s} …\n", .{models_dev_url});
+ try out.flush();
+ const doc = fetchModelsDev(io, gpa, arena) orelse {
+ try out.writeAll("✗ could not reach models.dev (offline?) — the baked-in catalog stays in effect\n");
+ try out.flush();
+ return;
+ };
+ var metas: std.ArrayList(Meta) = .empty;
+ defer metas.deinit(gpa);
+ for (pricing.model_table, 0..) |mi, i| {
+ var dup = false; // dedupe: the same name can appear under several providers
+ for (pricing.model_table[0..i]) |prev| {
+ if (std.mem.eql(u8, prev.name, mi.name)) {
+ dup = true;
+ break;
+ }
+ }
+ if (dup) continue;
+ if (findModel(doc.object, mi.name)) |meta| metas.append(gpa, meta) catch {};
+ }
+ const path = writeCache(io, arena, home, metas.items) orelse {
+ try out.writeAll("✗ refreshed, but could not write the cache file (check ~ permissions)\n");
+ try out.flush();
+ return;
+ };
+ try out.print("✓ refreshed {d} models from models.dev → {s}\n", .{ metas.items.len, path });
+ reportNew(doc.object, out);
+ loadOverlay(io, arena, home); // apply to this process too
+ try out.flush();
+}
+
+/// `graff models`: print the effective catalog (baked table + any refresh
+/// overlay), grouped by provider, with the live window and per-1M price.
+pub fn list(out: *Io.Writer) !void {
+ const fresh = pricing.price_overlay.len > 0 or pricing.context_overlay.len > 0;
+ try out.print("model catalog — {d} entries{s}\n", .{ pricing.model_table.len, if (fresh) " (refreshed from models.dev)" else "" });
+ var last: []const u8 = "";
+ for (pricing.model_table) |m| {
+ if (!std.mem.eql(u8, m.provider, last)) {
+ try out.print("\n{s}:\n", .{m.provider});
+ last = m.provider;
+ }
+ const ctx = pricing.contextFor(m.provider, m.name);
+ if (pricing.priceFor(m.name)) |p| {
+ try out.print(" {s:<34}{d:>10} ctx ${d}/{d} per 1M\n", .{ m.name, ctx, p.in, p.out });
+ } else {
+ try out.print(" {s:<34}{d:>10} ctx (unpriced)\n", .{ m.name, ctx });
+ }
+ }
+ try out.writeAll("\nrefresh window/price from models.dev: graff models refresh\n");
+ try out.flush();
+}
+
+/// `graff models [refresh]` entry point (dispatched from startup.runSubcommand).
+pub fn command(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, sub_args: []const []const u8) !void {
+ var obuf: [8 * 1024]u8 = undefined;
+ var ow = Io.File.stdout().writer(io, &obuf);
+ const out = &ow.interface;
+ if (sub_args.len > 0 and (std.mem.eql(u8, sub_args[0], "refresh") or
+ std.mem.eql(u8, sub_args[0], "--refresh") or std.mem.eql(u8, sub_args[0], "update")))
+ {
+ try refresh(io, gpa, arena, home, out);
+ return;
+ }
+ loadOverlay(io, arena, home); // reflect a prior refresh in the listing
+ try list(out);
+}
+
+test "numField reads int and float JSON numbers; u64Field clamps" {
+ var a = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer a.deinit();
+ const v = try std.json.parseFromSliceLeaky(Value, a.allocator(),
+ \\{"i": 42, "f": 2.5, "neg": -3, "s": "x"}
+ , .{ .allocate = .alloc_always });
+ try std.testing.expectEqual(@as(f64, 42), numField(v.object, "i").?);
+ try std.testing.expectEqual(@as(f64, 2.5), numField(v.object, "f").?);
+ try std.testing.expect(numField(v.object, "s") == null);
+ try std.testing.expect(numField(v.object, "missing") == null);
+ try std.testing.expectEqual(@as(u64, 42), u64Field(v.object, "i"));
+ try std.testing.expectEqual(@as(u64, 0), u64Field(v.object, "neg")); // clamped
+ try std.testing.expectEqual(@as(u64, 0), u64Field(v.object, "missing"));
+}
+
+test "findModel prefers the canonical vendor over a reseller markup" {
+ var a = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer a.deinit();
+ // gpt-5.6 listed under a reseller (higher price) AND canonical openai.
+ const v = try std.json.parseFromSliceLeaky(Value, a.allocator(),
+ \\{"reseller":{"models":{"gpt-5.6":{"limit":{"context":100},"cost":{"input":99,"output":99,"cache_read":9}}}},
+ \\ "openai":{"models":{"gpt-5.6":{"limit":{"context":1050000},"cost":{"input":5,"output":30,"cache_read":0.5}}}}}
+ , .{ .allocate = .alloc_always });
+ const m = findModel(v.object, "gpt-5.6").?;
+ try std.testing.expectEqual(@as(f64, 5), m.in); // openai, not the reseller's 99
+ try std.testing.expectEqual(@as(u64, 1_050_000), m.context);
+ // Alias match: "gpt5.6" normalizes to "gpt-5.6".
+ try std.testing.expect(findModel(v.object, "gpt5.6") != null);
+ try std.testing.expect(findModel(v.object, "no-such-model") == null);
+}
diff --git a/src/pickers.zig b/src/pickers.zig
index 90008e88..3b799669 100644
--- a/src/pickers.zig
+++ b/src/pickers.zig
@@ -342,7 +342,7 @@ pub const command_menu = [_]PickItem{
.{ .name = "/keepcontext", .desc = "keep history across wire-format switches" },
.{ .name = "/effort", .desc = "thinking depth: low|medium|high (codex, deepseek, codegraff)" },
.{ .name = "/reasoning", .desc = "alias for /effort" },
- .{ .name = "/fast", .desc = "codex priority service tier — lower latency (gpt-5.5)" },
+ .{ .name = "/fast", .desc = "codex priority service tier — lower latency (gpt-5.6)" },
.{ .name = "/ultracode", .desc = "toggle persistent ultracode (multi-agent workflow) mode" },
.{ .name = "/thinking", .desc = "show/collapse the model's live reasoning stream" },
.{ .name = "/title", .desc = "AI-name the tab from your first prompt (on by default)" },
diff --git a/src/pricing.zig b/src/pricing.zig
index e167ff73..aeb78160 100644
--- a/src/pricing.zig
+++ b/src/pricing.zig
@@ -16,8 +16,15 @@ pub const ModelPrice = struct { name: []const u8, in: f64, out: f64, cache: f64
pub const price_table = [_]ModelPrice{
.{ .name = "deepseek-v4-pro", .in = 1.1, .out = 2.2, .cache = 0.11 },
.{ .name = "deepseek-v4-flash", .in = 0.14, .out = 0.28, .cache = 0.028 },
+ .{ .name = "gpt-5.6", .in = 5, .out = 30, .cache = 0.5 }, // Sol / flagship (models.dev 2026-07-09)
+ .{ .name = "gpt-5.6-terra", .in = 2.5, .out = 15, .cache = 0.25 },
+ .{ .name = "gpt-5.6-luna", .in = 1, .out = 6, .cache = 0.1 },
.{ .name = "gpt-5.5", .in = 5, .out = 30, .cache = 0.5 },
.{ .name = "gpt-5.5-codex", .in = 1.25, .out = 10, .cache = 0.125 },
+ .{ .name = "gpt-5.4", .in = 2.5, .out = 15, .cache = 0.25 },
+ .{ .name = "gpt-5.4-mini", .in = 0.75, .out = 4.5, .cache = 0.075 },
+ .{ .name = "gpt-5.3-codex", .in = 1.75, .out = 14, .cache = 0.175 },
+ .{ .name = "gpt-5.2", .in = 1.75, .out = 14, .cache = 0.175 },
.{ .name = "gpt-5-codex", .in = 1.25, .out = 10, .cache = 0.125 },
.{ .name = "claude-opus-4-8", .in = 15, .out = 75, .cache = 1.5 },
.{ .name = "claude-opus-4.8", .in = 15, .out = 75, .cache = 1.5 },
@@ -40,7 +47,14 @@ pub const price_table = [_]ModelPrice{
.{ .name = "glm-4.5", .in = 0.6, .out = 2.2, .cache = 0.06 },
};
+/// Runtime price overlay populated by `graff models refresh` (models.dev
+/// cache, see models_cache.zig): consulted before the baked-in table so a
+/// refresh keeps prices current without a rebuild. Empty by default → the
+/// baked table is the sole source offline and on a fresh install.
+pub var price_overlay: []const ModelPrice = &.{};
+
pub fn priceFor(model: []const u8) ?ModelPrice {
+ for (price_overlay) |p| if (std.mem.eql(u8, p.name, model)) return p;
for (price_table) |p| if (std.mem.eql(u8, p.name, model)) return p;
return null;
}
@@ -148,9 +162,13 @@ pub const model_table = [_]ModelInfo{
.{ .provider = "deepseek", .name = "deepseek-v4-flash", .context = 1_000_000 },
.{ .provider = "deepseek", .name = "deepseek-chat", .context = 1_000_000 },
.{ .provider = "deepseek", .name = "deepseek-reasoner", .context = 1_000_000 },
+ .{ .provider = "openai", .name = "gpt-5.6", .context = 1_050_000 },
+ .{ .provider = "openai", .name = "gpt-5.6-terra", .context = 1_050_000 },
+ .{ .provider = "openai", .name = "gpt-5.6-luna", .context = 1_050_000 },
.{ .provider = "openai", .name = "gpt-5.5", .context = 1_050_000 },
.{ .provider = "openai", .name = "gpt-5.4", .context = 1_050_000 },
.{ .provider = "openai", .name = "gpt-5.4-pro", .context = 1_050_000 },
+ .{ .provider = "openai", .name = "gpt-5.4-mini", .context = 400_000 },
.{ .provider = "openai", .name = "gpt-5.2", .context = 400_000 },
.{ .provider = "openai", .name = "gpt-5-codex", .context = 400_000 },
.{ .provider = "minimax", .name = "MiniMax-M3", .context = 512_000 },
@@ -160,7 +178,21 @@ pub const model_table = [_]ModelInfo{
.{ .provider = "xiaomi", .name = "mimo-v2.5", .context = 1_048_576 },
.{ .provider = "xiaomi", .name = "mimo-v2.5-pro-ultraspeed", .context = 1_048_576 },
.{ .provider = "xiaomi", .name = "mimo-v2-flash", .context = 262_144 },
+ // Codex/ChatGPT backend lineup (codex-rs models.json): the slugs the
+ // chatgpt.com/backend-api/codex/responses endpoint accepts. Default is
+ // gpt-5.5 (available to every Codex account); gpt-5.6 is the newest but
+ // ENTITLEMENT-GATED — OpenAI rolls it out to Codex accounts gradually, and
+ // one without it 400s ("model not supported when using Codex with a ChatGPT
+ // account"), so it is a selectable opt-in here, NOT the default. Verified
+ // live 2026-07-10. The -codex-suffixed API-only names (gpt-5.5-codex,
+ // gpt-5-codex) are NOT codex-backend slugs and stay openai-only. All share
+ // the ~272k backend window (codex_context_window), not the API's 1.05M.
.{ .provider = "codex", .name = "gpt-5.5", .context = codex_context_window },
+ .{ .provider = "codex", .name = "gpt-5.6", .context = codex_context_window }, // newest; entitlement-gated opt-in
+ .{ .provider = "codex", .name = "gpt-5.4", .context = codex_context_window },
+ .{ .provider = "codex", .name = "gpt-5.4-mini", .context = codex_context_window },
+ .{ .provider = "codex", .name = "gpt-5.3-codex", .context = codex_context_window },
+ .{ .provider = "codex", .name = "gpt-5.2", .context = codex_context_window },
// Sakana AI — Fugu (OpenAI-compatible chat/completions). `fugu` is the fast
// mini model, `fugu-ultra` the multi-agent reasoning conductor. Sakana does
// not publish a context window; use the harness's conservative 200k default
@@ -208,16 +240,27 @@ pub const model_table = [_]ModelInfo{
pub const default_context = 200_000;
+/// Runtime context-window overlay from `graff models refresh` (name-keyed;
+/// models.dev has no per-graff-provider rows). Consulted after the baked-in
+/// provider-specific row (so gateway/codex windows stay authoritative) but
+/// before the baked name-only fallback, so a refresh can widen a model graff
+/// only knows by name. Empty by default.
+pub var context_overlay: []const ModelInfo = &.{};
+
/// Context window for a model as served by a specific provider; falls back
/// to any provider's row for the name, then to the conservative default.
pub fn contextFor(provider_id: []const u8, model: []const u8) u64 {
const is_codex = std.mem.eql(u8, provider_id, "codex");
+ // Provider-specific baked row is authoritative (gateway gpt-5.5 = 400k, not
+ // the API's 1.05M), so it wins over the fresh name-only overlay below.
for (model_table) |m| {
if (std.mem.eql(u8, m.provider, provider_id) and std.mem.eql(u8, m.name, model)) return m.context;
}
- // Name-only fallback: another provider's row may advertise a far larger
- // window (e.g. the OpenAI API's gpt-5.5 = 1.05M) that the Codex backend
- // can't honor — cap codex routes at codex_context_window.
+ // Fresh overlay (models.dev refresh), then the baked name-only fallback. A
+ // name-only window may exceed what the Codex backend honors — cap codex.
+ for (context_overlay) |m| {
+ if (std.mem.eql(u8, m.name, model)) return if (is_codex) @min(m.context, codex_context_window) else m.context;
+ }
for (model_table) |m| {
if (std.mem.eql(u8, m.name, model)) return if (is_codex) @min(m.context, codex_context_window) else m.context;
}
@@ -283,20 +326,42 @@ test "contextFor known model and default fallback" {
try std.testing.expectEqual(@as(u64, default_context), contextFor("nope", "unknown-xyz"));
}
-test "codex catalog excludes unsupported codex-suffixed models" {
- var has_codex_gpt55 = false;
- for (model_table) |model| {
- if (!std.mem.eql(u8, model.provider, "codex")) continue;
- try std.testing.expect(!std.mem.eql(u8, model.name, "gpt-5.5-codex"));
- try std.testing.expect(!std.mem.eql(u8, model.name, "gpt-5-codex"));
- if (std.mem.eql(u8, model.name, "gpt-5.5")) has_codex_gpt55 = true;
- }
- try std.testing.expect(has_codex_gpt55);
+test "codex catalog matches the codex backend lineup" {
+ // The codex ChatGPT backend serves the codex-rs models.json slugs; the
+ // -codex-suffixed API-only names (gpt-5.5-codex, gpt-5-codex) are NOT
+ // backend slugs, so they stay openai-served and out of the codex catalog.
+ try std.testing.expect(providerModelInTable("codex", "gpt-5.6")); // newest, entitlement-gated opt-in
+ try std.testing.expect(providerModelInTable("codex", "gpt-5.5"));
+ try std.testing.expect(providerModelInTable("codex", "gpt-5.4"));
+ try std.testing.expect(providerModelInTable("codex", "gpt-5.3-codex"));
+ try std.testing.expect(providerModelInTable("codex", "gpt-5.2"));
try std.testing.expect(!providerModelInTable("codex", "gpt-5.5-codex"));
try std.testing.expect(!providerModelInTable("codex", "gpt-5-codex"));
try std.testing.expect(providerModelInTable("openai", "gpt-5-codex"));
- try std.testing.expect(!providerModelInTable("codex", "gpt-5.2"));
- try std.testing.expect(providerModelInTable("openai", "gpt-5.2"));
+ try std.testing.expect(providerModelInTable("openai", "gpt-5.6"));
+}
+
+test "every provider default_model is catalog-present for that provider" {
+ // Guards the codex/openai gpt-5.6 default flip (and any future one): a
+ // provider whose default_model isn't in model_table would boot on a model
+ // contextFor()/routing can't resolve.
+ const specs = @import("provider.zig").provider_specs;
+ for (specs) |spec|
+ try std.testing.expect(providerModelInTable(spec.id, spec.default_model));
+}
+
+test "refresh overlay augments price/context lookups (codex cap still applies)" {
+ const saved_p = price_overlay;
+ const saved_c = context_overlay;
+ defer price_overlay = saved_p;
+ defer context_overlay = saved_c;
+ const po = [_]ModelPrice{.{ .name = "future-model-x", .in = 9, .out = 9, .cache = 1 }};
+ const co = [_]ModelInfo{.{ .provider = "", .name = "future-model-x", .context = 999_000 }};
+ price_overlay = &po;
+ context_overlay = &co;
+ try std.testing.expect(priceFor("future-model-x") != null);
+ try std.testing.expectEqual(@as(u64, 999_000), contextFor("openai", "future-model-x"));
+ try std.testing.expectEqual(codex_context_window, contextFor("codex", "future-model-x"));
}
test "billingFor: subscription, priced, unpriced classification" {
diff --git a/src/provider.zig b/src/provider.zig
index 8380bbaf..e638b271 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -34,7 +34,7 @@ pub const provider_specs = [_]ProviderSpec{
.{ .id = "anthropic", .kind = .anthropic, .auth = .x_api_key, .url = "https://api.anthropic.com/v1/messages", .env_key = "ANTHROPIC_API_KEY", .default_model = "claude-opus-4-8" },
.{ .id = "codegraff", .kind = .openai, .auth = .bearer, .url = "https://gateway.codegraff.com/v1/chat/completions", .env_key = "CODEGRAFF_API_KEY", .default_model = "deepseek-v4-pro" },
.{ .id = "deepseek", .kind = .openai, .auth = .bearer, .url = "https://api.deepseek.com/chat/completions", .env_key = "DEEPSEEK_API_KEY", .default_model = "deepseek-v4-pro" },
- .{ .id = "openai", .kind = .openai, .auth = .bearer, .url = "https://api.openai.com/v1/chat/completions", .env_key = "OPENAI_API_KEY", .default_model = "gpt-5.5" },
+ .{ .id = "openai", .kind = .openai, .auth = .bearer, .url = "https://api.openai.com/v1/chat/completions", .env_key = "OPENAI_API_KEY", .default_model = "gpt-5.6" },
.{ .id = "minimax", .kind = .anthropic, .auth = .bearer, .url = "https://api.minimax.io/anthropic/v1/messages", .env_key = "MINIMAX_API_KEY", .default_model = "MiniMax-M3" },
.{ .id = "xiaomi", .kind = .openai, .auth = .bearer, .url = "https://api.xiaomimimo.com/v1/chat/completions", .env_key = "XIAOMI_API_KEY", .default_model = "mimo-v2.5-pro" },
// OpenAI-format direct providers (matched to graff's provider.json).
diff --git a/src/startup.zig b/src/startup.zig
index 2f007bed..8c8fba17 100644
--- a/src/startup.zig
+++ b/src/startup.zig
@@ -32,6 +32,7 @@ const provider_mod = @import("provider.zig");
const keys_cli = @import("keys_cli.zig");
const oauth = @import("oauth.zig");
const pricing = @import("pricing.zig");
+const models_cache = @import("models_cache.zig");
const serde = @import("serde.zig");
const skills = @import("skills.zig");
const prompts = @import("prompts.zig");
@@ -93,6 +94,10 @@ pub fn resolveKeys(io: Io, gpa: Allocator, arena: Allocator, environ_map: anytyp
if (value.* == null) value.* = keys_cli.loadStoredKey(io, arena, home, spec.id);
}
}
+ // Apply the models.dev refresh cache (if `graff models refresh` ever ran)
+ // before any Provider is built, so contextFor()/priceFor() use the fresh
+ // window/price. No cache → a no-op; the baked catalog stays authoritative.
+ if (keys_cli.homeEnv(environ_map)) |home| models_cache.loadOverlay(io, arena, home);
var default_provider = keys.defaultProvider() catch {
std.process.fatal(
\\no API key found. quickest fixes:
@@ -295,6 +300,14 @@ pub fn runSubcommand(io: Io, gpa: Allocator, arena: Allocator, init: std.process
return true;
}
+ // `graff models [refresh]`: print the effective model catalog, or pull
+ // fresh window/price metadata from models.dev into the local cache.
+ if (flags.positionals.items.len > 0 and std.mem.eql(u8, flags.positionals.items[0], "models")) {
+ const home = keys_cli.homeEnv(init.environ_map) orelse std.process.fatal("no HOME/USERPROFILE", .{});
+ try models_cache.command(io, gpa, arena, home, flags.positionals.items[1..]);
+ return true;
+ }
+
// `--schema`: print the machine-readable interface and exit. No keys,
// network, or MCP — so it works anywhere (CI codegen calls this).
if (flags.schema_flag) {