graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(provider): route native Codegraff aliases over Responses
justrach5fd6ddf53cad
diff --git a/docs/adr/0002-xai-defaults-to-the-responses-wire.md b/docs/adr/0002-xai-defaults-to-the-responses-wire.mdindex dd1b3ea6..f1ec4161 100644--- a/docs/adr/0002-xai-defaults-to-the-responses-wire.md+++ b/docs/adr/0002-xai-defaults-to-the-responses-wire.md@@ -30,8 +30,9 @@ back onto chat completions.- Lossless compaction by default; the intent-aware client summary remainsthe fallback when the endpoint refuses or fails, and the chat wire keepsit as primary.-- WS eligibility stays an explicit provider list (codex, xai) — Platform- OpenAI is Responses-kind but has no WS server and must never probe one.+- WS eligibility stays an explicit provider list (codex, xai, and Codegraff+ when its selected alias is Responses-kind) — Platform OpenAI has no WS+ server and must never probe one.- Chaining via previous_response_id stays codex-only: xAI's store:false +previous_response_id stalls server-side (probed live), so xai ridesfull-resend over the held socket.diff --git a/docs/adr/0003-codegraff-wire-follows-model-capability.md b/docs/adr/0003-codegraff-wire-follows-model-capability.mdnew file mode 100644index 00000000..f0af83bd--- /dev/null+++ b/docs/adr/0003-codegraff-wire-follows-model-capability.md@@ -0,0 +1,31 @@+# 0003. Codegraff gateway wire follows model capability++Status: accepted 2026-08-17++## Context++The Codegraff gateway has one OpenAI-shaped public contract but two transport+capability sets. Chat Completions accepts every alias and translates Claude and+Gemini at the edge. Responses (HTTP or WebSocket) is native only for the+GPT-5.6 family and grok-4.6; Claude and Gemini return 400 there. A single static+provider wire therefore either leaves native Responses features unused or+breaks translated models.++## Decision++Resolve the Codegraff provider's wire per model. `gpt-5.6`,+`gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, and `grok-4.6` use+`/v1/responses` and may use its WebSocket transport. Every other gateway alias+uses `/v1/chat/completions` unless the public gateway contract adds it to the+native Responses set.++## Consequences++- GPT-5.6 and grok-4.6 receive native Responses request shapes, prompt cache+ keys, streaming events, and the WS-to-SSE fallback ladder.+- Claude and Gemini remain on the edge-translated Chat Completions path.+- Switching models on one Codegraff credential must rebuild both `kind` and+ endpoint; the allowlist is the contract boundary and needs updating when the+ gateway adds another native Responses family.++Evidence: [Codegraff gateway contract](https://codegraff.com/docs/gateway).diff --git a/docs/adr/README.md b/docs/adr/README.mdindex beac34df..ee1fb423 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -13,6 +13,7 @@ record only when you need the evidence or the edge cases.|---|---|| [0001](0001-structured-outputs-are-a-formatting-step.md) | Structured output is a final formatting step. Never constrain the agentic phase with a schema grammar, and do not use `--output-schema` unless a program consumes the result. || [0002](0002-xai-defaults-to-the-responses-wire.md) | xAI runs on the Responses wire by default (WS turns, lossless server compaction). `GRAFF_XAI_WIRE=chat` opts out; WS stays an explicit provider list. |+| [0003](0003-codegraff-wire-follows-model-capability.md) | Codegraff uses Responses + WS for GPT-5.6 and grok-4.6 aliases; Claude, Gemini, and other aliases stay on Chat Completions. |## When to write onediff --git a/src/additional_tests.zig b/src/additional_tests.zigindex f92f92e2..0c9258c3 100644--- a/src/additional_tests.zig+++ b/src/additional_tests.zig@@ -3,4 +3,5 @@ test {_ = @import("codedbpro_paths.zig");_ = @import("agent_request_body_responses.zig");_ = @import("agent_server_compact_tests.zig");+ _ = @import("provider_codegraff_tests.zig");}diff --git a/src/agent_request_body.zig b/src/agent_request_body.zigindex 9f5d93d8..5e29c314 100644--- a/src/agent_request_body.zig+++ b/src/agent_request_body.zig@@ -197,7 +197,7 @@ pub fn buildBody(self: *Agent, tools: ?[]const u8, force_tool: bool, stream: bootry sox.writeStructuredOutputTool(&s, schema_json);}},- // The Responses-wire body (codex / xAI #502) lives in its own module+ // The Responses-wire body (codex / xAI / native Codegraff) lives in its own module// under the 600-line ceiling; structured-output writers ride along..responses => try @import("agent_request_body_responses.zig").write(self, &s, tools, force_tool),}diff --git a/src/agent_request_body_responses.zig b/src/agent_request_body_responses.zigindex 266d0551..8340bba8 100644--- a/src/agent_request_body_responses.zig+++ b/src/agent_request_body_responses.zig@@ -1,4 +1,4 @@-//! The Responses-wire request body (codex / xAI #502), split from+//! The Responses-wire request body (codex / xAI / native Codegraff), split from//! agent_request_body.zig under the 600-line ceiling, plus the structured-//! output writers (text.format here, response_format for the chat wire).@@ -12,7 +12,7 @@ const codex_chain = @import("codex_chain.zig");const server_compact = @import("agent_server_compact.zig");pub fn write(self: *Agent, s: *std.json.Stringify, tools: ?[]const u8, force_tool: bool) !void {- // Responses API (codex / ChatGPT backend, and xAI behind GRAFF_XAI_WIRE).+ // Responses API (codex / ChatGPT, xAI, and native Codegraff aliases).// system prompt → instructions; history items are valid input items;// stream is required (we buffer + parse the SSE); reasoning items return// encrypted and are passed back per turn.diff --git a/src/agent_ws.zig b/src/agent_ws.zigindex f3442429..0750848e 100644--- a/src/agent_ws.zig+++ b/src/agent_ws.zig@@ -53,11 +53,11 @@ const rawNonblockStdin = Agent.rawNonblockStdin;const drainSteerStdin = Agent.drainSteerStdin;/// WS: root Responses turns when enabled and not fallen back this session-/// (codex + xai only — Platform OpenAI has no WS endpoint).+/// (codex + xai + Codegraff gateway; Platform OpenAI has no WS endpoint).pub fn wsEligible(self: *Agent) bool {// Provider id is a production filter on top of the spec'd kind/flag- // algebra: only codex and xai actually serve a WS endpoint.- const has_ws = std.mem.eql(u8, self.provider.id, "codex") or std.mem.eql(u8, self.provider.id, "xai");+ // algebra: only these providers actually serve a WS endpoint.+ const has_ws = std.mem.eql(u8, self.provider.id, "codex") or std.mem.eql(u8, self.provider.id, "xai") or std.mem.eql(u8, self.provider.id, "codegraff");return has_ws and transport_gate.eligible(.{ .kind = self.provider.kind, .is_sub = self.sub, .codex_ws = main_mod.g_codex_ws, .ws_off = self.ws_off, .has_out = self.out != null, .quiet = self.stream_quiet });}diff --git a/src/agent_ws_fallback_test.zig b/src/agent_ws_fallback_test.zigindex 95f61de3..3963ea55 100644--- a/src/agent_ws_fallback_test.zig+++ b/src/agent_ws_fallback_test.zig@@ -198,9 +198,9 @@ test "#427: a non-426 handshake failure keeps the ladder's free retry, then latc}// #502 regression: the codex-only gate (correct for Platform OpenAI, which has-// no WS server to probe) must not swallow xAI — both serve a real WS endpoint,-// and the v0.0.25x release line's gate silently killed xAI WS turns once.-test "wsEligible: codex and xai qualify; Platform OpenAI and chat wires never do" {+// no WS server to probe) must not swallow xAI or Codegraff Responses — all three+// serve a real WS endpoint, while the gateway's chat-routed models still do not.+test "wsEligible: native Responses providers qualify; Platform OpenAI and chat wires never do" {const gpa = std.testing.allocator;const io = std.testing.io;@@ -220,6 +220,12 @@ test "wsEligible: codex and xai qualify; Platform OpenAI and chat wires never doagent.provider.id = "xai";try std.testing.expect(agent_ws.wsEligible(&agent)); // #502: xai rides WS+ agent.provider.id = "codegraff";+ try std.testing.expect(agent_ws.wsEligible(&agent)); // native gateway Responses ride WS+ agent.provider.kind = .openai;+ try std.testing.expect(!agent_ws.wsEligible(&agent)); // translated gateway chat never does+ agent.provider.kind = .responses;+agent.provider.id = "openai";try std.testing.expect(!agent_ws.wsEligible(&agent)); // Platform: no WS serverdiff --git a/src/pricing.zig b/src/pricing.zigindex 355170e7..e454fdec 100644--- a/src/pricing.zig+++ b/src/pricing.zig@@ -268,8 +268,10 @@ pub const model_table = [_]ModelInfo{.{ .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.6", .context = 1_050_000 },.{ .provider = "codegraff", .name = "gpt-5.5", .context = 400_000 },.{ .provider = "codegraff", .name = "kimi-k2.6", .context = 262_144 },+ .{ .provider = "codegraff", .name = "grok-4.6", .context = 500_000 },.{ .provider = "codegraff", .name = "grok-build", .context = 256_000 },.{ .provider = "codegraff", .name = "glm-5.2", .context = 204_800 },.{ .provider = "codegraff", .name = "mimo-v2.5", .context = 128_000 },diff --git a/src/provider.zig b/src/provider.zigindex 2c55eb80..d7c92fda 100644--- a/src/provider.zig+++ b/src/provider.zig@@ -238,9 +238,9 @@ pub const Provider = struct {const is_xai_responses = std.mem.eql(u8, spec.id, "xai") and g_xai_responses;return .{.id = spec.id,- .kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses) .responses else spec.kind,+ .kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses or @import("provider_codegraff.zig").usesResponses(spec.id, model)) .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 (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,+ .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 if (@import("provider_codegraff.zig").usesResponses(spec.id, model)) @import("provider_codegraff.zig").responses_url else spec.url,.api_key = base.api_key,.model = model,.context = contextWindowFor(spec.id, model),@@ -334,9 +334,9 @@ pub const Keys = struct {const is_xai_responses = std.mem.eql(u8, spec.id, "xai") and g_xai_responses;return .{.id = spec.id,- .kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses) .responses else spec.kind,+ .kind = if (is_kimi_anthropic) .anthropic else if (is_xai_responses or @import("provider_codegraff.zig").usesResponses(spec.id, model)) .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 (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,+ .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 if (@import("provider_codegraff.zig").usesResponses(spec.id, model)) @import("provider_codegraff.zig").responses_url else spec.url,.api_key = key,.model = model,.context = contextWindowFor(spec.id, model),diff --git a/src/provider_codegraff.zig b/src/provider_codegraff.zignew file mode 100644index 00000000..c511e746--- /dev/null+++ b/src/provider_codegraff.zig@@ -0,0 +1,26 @@+//! Model-specific wire contract for the Codegraff gateway.++const std = @import("std");++pub const responses_url = "https://gateway.codegraff.com/v1/responses";++/// The gateway exposes every alias on Chat Completions, but only native OpenAI+/// and xAI aliases on Responses. Keep this allowlist aligned with the public+/// gateway contract so Claude and Gemini never reach their rejected route.+pub fn usesResponses(provider_id: []const u8, model: []const u8) bool {+ if (!std.mem.eql(u8, provider_id, "codegraff")) return false;+ return std.mem.eql(u8, model, "gpt-5.6") or+ std.mem.eql(u8, model, "gpt-5.6-sol") or+ std.mem.eql(u8, model, "gpt-5.6-terra") or+ std.mem.eql(u8, model, "gpt-5.6-luna") or+ std.mem.eql(u8, model, "grok-4.6");+}++test "Codegraff Responses allowlist matches the public gateway contract" {+ for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "grok-4.6" }) |model|+ try std.testing.expect(usesResponses("codegraff", model));++ for ([_][]const u8{ "gpt-5.5", "grok-4.3", "claude-opus-4.8", "gemini-3.7-flash" }) |model|+ try std.testing.expect(!usesResponses("codegraff", model));+ try std.testing.expect(!usesResponses("openai", "gpt-5.6"));+}diff --git a/src/provider_codegraff_tests.zig b/src/provider_codegraff_tests.zignew file mode 100644index 00000000..fc35849e--- /dev/null+++ b/src/provider_codegraff_tests.zig@@ -0,0 +1,43 @@+const std = @import("std");+const provider = @import("provider.zig");++fn build(model: []const u8) provider.Provider {+ const keys: provider.Keys = .{ .values = @splat(null) };+ return keys.build(provider.specFor("codegraff").?, "key", model);+}++test "Codegraff selects the gateway wire and endpoint per model" {+ for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "grok-4.6" }) |model| {+ const got = build(model);+ try std.testing.expectEqual(provider.Provider.Kind.responses, got.kind);+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/responses", got.url);+ }++ for ([_][]const u8{ "deepseek-v4-pro", "claude-opus-4.8", "gemini-3.7-flash" }) |model| {+ const got = build(model);+ try std.testing.expectEqual(provider.Provider.Kind.openai, got.kind);+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/chat/completions", got.url);+ }+}++test "Codegraff-only credentials route native aliases without live discovery" {+ var keys: provider.Keys = .{ .values = @splat(null) };+ try std.testing.expect(keys.set("codegraff", "key", .environment));+ for ([_][]const u8{ "gpt-5.6", "grok-4.6" }) |model| {+ const got = try keys.providerFor(model);+ try std.testing.expectEqualStrings("codegraff", got.id);+ try std.testing.expectEqual(provider.Provider.Kind.responses, got.kind);+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/responses", got.url);+ }+}++test "Codegraff model switches rebuild both wire and endpoint" {+ const chat = build("gemini-3.7-flash");+ const responses = chat.withModel("grok-4.6");+ try std.testing.expectEqual(provider.Provider.Kind.responses, responses.kind);+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/responses", responses.url);++ const back_to_chat = responses.withModel("claude-opus-4.8");+ try std.testing.expectEqual(provider.Provider.Kind.openai, back_to_chat.kind);+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/chat/completions", back_to_chat.url);+}