graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Route native judgments through gateway and track uncertain usage
Rach Pradhanab36fa8a4474
diff --git a/docs/experiments/jev-use-harness.md b/docs/experiments/jev-use-harness.mdindex e80e800a..d78cbf19 100644--- a/docs/experiments/jev-use-harness.md+++ b/docs/experiments/jev-use-harness.md@@ -9,9 +9,10 @@ recognized local login store; it does not probe the account online. Directdispatch enforces the same rules. Model switches and an in-session`/login codegraff` refresh the root tool catalog.-Set `TYPESAFE_API_KEY` in Graff's environment to opt in as well. The tool sends only-its explicitly supplied short `state` and one typed `question` to TypeSafe's-`/v1/systemone` endpoint; it never automatically uploads repository context.+The tool sends only its explicitly supplied short `state` and one typed+`question` to Codegraff's `/v1/systemone` endpoint using the persisted login;+it never automatically uploads repository context. No separate upstream key is+needed.Do not put code, paths, secrets, or customer data in a tool call. Use`JEV_BACKEND=mock` for a no-network wiring check.diff --git a/src/commands_misc.zig b/src/commands_misc.zigindex c33f24e7..cb14d169 100644--- a/src/commands_misc.zig+++ b/src/commands_misc.zig@@ -500,7 +500,7 @@ pub fn renderSessionUsage(c: pricing.CostTally, out: *Io.Writer) !void {try out.print("{s}session usage{s}\n", .{ style.bold, style.reset });try out.print(" api calls: {d}", .{c.api_calls});if (c.sub_calls > 0) try out.print(" ({d} subscription, flat-rate)", .{c.sub_calls});- if (c.unpriced_calls > 0) try out.print(" ({d} on unpriced models)", .{c.unpriced_calls});+ if (c.unpriced_calls > 0) try out.print(" ({d} with unknown cost)", .{c.unpriced_calls});try out.print("\n tokens: {d} in ({d} cached) + {d} out\n", .{ c.in_tokens + c.cache_tokens, c.cache_tokens, c.out_tokens });try out.print(" cost: {s}${d:.4}{s}{s}\n", .{style.green, c.usd, style.reset,diff --git a/src/exec.zig b/src/exec.zigindex da76af85..1481edaf 100644--- a/src/exec.zig+++ b/src/exec.zig@@ -429,7 +429,7 @@ test "native Jev dispatch rejects other models and latches off after one failedconst no_login = try execToolInner(ctx, call);defer std.testing.allocator.free(no_login.text);try std.testing.expect(no_login.is_error);- _ = jev.setCodegraffLogin(true);+ _ = jev.setCodegraffLoginKey(std.testing.io, "synthetic-login");try std.testing.expect(jev.available(ctx.provider)); // no upstream attempt before loginctx.provider.id = "xai";ctx.provider.model = "grok-4.7";diff --git a/src/jev_provider_switch_tests.zig b/src/jev_provider_switch_tests.zigindex a7290791..34e867de 100644--- a/src/jev_provider_switch_tests.zig+++ b/src/jev_provider_switch_tests.zig@@ -46,7 +46,7 @@ test "native Jev catalog refreshes on eligible and ineligible model switches" {return null;}}{});- _ = jev_tool.setCodegraffLogin(true);+ _ = jev_tool.setCodegraffLoginKey(std.testing.io, "synthetic-login");var gpt6 = p;gpt6.model = "gpt-6-sol";@@ -79,7 +79,7 @@ test "native Jev catalog refreshes on eligible and ineligible model switches" {return if (std.mem.eql(u8, key, "JEV_BACKEND")) "mock-fail" else null;}}{});- _ = jev_tool.setCodegraffLogin(true);+ _ = jev_tool.setCodegraffLoginKey(std.testing.io, "synthetic-login");const old_catalog = root.toolsJson();const input = try std.json.parseFromSliceLeaky(std.json.Value, a, "{\"state\":\"10 tests passed\",\"question\":\"Did CI pass?\",\"type\":\"noul\"}", .{});var client: std.http.Client = undefined;diff --git a/src/jev_tool.zig b/src/jev_tool.zigindex b2ee6cf7..8448fb6f 100644--- a/src/jev_tool.zig+++ b/src/jev_tool.zig@@ -10,6 +10,7 @@ const ToolCtx = @import("tools.zig").ToolCtx;const ToolOutput = @import("tools.zig").ToolOutput;const ToolSpec = @import("schema.zig").ToolSpec;const scope = @import("jev_model_scope.zig");+const pricing = @import("pricing.zig");pub const name = "jev_judge";pub const description = "Ask Jev one closed-form judgment about a SHORT, NON-SENSITIVE state. Requires a Codegraff login and an eligible GPT-6 or MiMo model. Use for yes/no (noul), a choice, or an ordered score, not writing or open-ended reasoning. Never send source code, secrets, customer data, paths, or unrelated context. A low-confidence verdict escalates to you. If Jev fails once, this tool skips all later Jev calls for this session; decide yourself instead.";@@ -17,13 +18,16 @@ pub const input_schema =\\{"type":"object","properties":{"state":{"type":"string","description":"Short non-sensitive facts needed for this judgment only; no code, paths or secrets"},"question":{"type":"string","description":"One closed-form question about state"},"type":{"type":"string","enum":["noul","choice","score"],"description":"noul=yes/no probability; choice=one option; score=ordered level"},"options":{"type":"array","items":{"type":"string"},"description":"Required for choice: 2-16 distinct labels"},"levels":{"type":"array","items":{"type":"string"},"description":"Required for score: 2-10 ordered descriptions"}},"required":["state","question","type"]};const spec = ToolSpec{ .name = name, .desc = description, .schema = input_schema };-const endpoint = "https://api.typesafe.ai/v1/systemone";+const endpoint = "https://gateway.codegraff.com/v1/systemone";const skip_text = "Jev unavailable: skipped. No more Jev requests will be sent this session; judge this step with the main model instead.";-const Backend = enum { typesafe, mock, mock_fail };+const auth_skip_text = "Jev unavailable (Codegraff authorization failed): skipped. No more Jev requests will be sent this session; judge this step with the main model instead.";+const credit_skip_text = "Jev unavailable (Codegraff credits or key budget): skipped. No more Jev requests will be sent this session; judge this step with the main model instead.";+const rate_skip_text = "Jev unavailable (Codegraff rate limit): skipped. No more Jev requests will be sent this session; judge this step with the main model instead.";+const Backend = enum { gateway, mock, mock_fail };const State = struct {mu: Io.Mutex = .init,key: []const u8 = "",- backend: Backend = .typesafe,+ backend: Backend = .gateway,codegraff_login: std.atomic.Value(bool) = .init(false),down: std.atomic.Value(bool) = .init(false),refresh: std.atomic.Value(bool) = .init(false),@@ -32,25 +36,30 @@ const State = struct {var state: State = .{};pub fn configure(env: anytype) void {- // Called once at session startup, before any tool work begins. Retain the- // environment's key in memory; it is never copied into a catalog/result.- state.key = env.get("TYPESAFE_API_KEY") orelse "";- const mode = env.get("JEV_BACKEND") orelse "";- state.backend = if (std.mem.eql(u8, mode, "mock")) .mock else if (std.mem.eql(u8, mode, "mock-fail")) .mock_fail else .typesafe;+ // Only a persisted Codegraff login may supply the gateway credential.+ // The provider's own key and any upstream-specific environment key are ignored.+ state.key = "";state.codegraff_login.store(false, .release);+ const mode = env.get("JEV_BACKEND") orelse "";+ state.backend = if (std.mem.eql(u8, mode, "mock")) .mock else if (std.mem.eql(u8, mode, "mock-fail")) .mock_fail else .gateway;state.down.store(false, .release);state.refresh.store(false, .release);state.attempts.store(0, .release);}/// Returns true when a login transition changes the live tool catalog.-pub fn setCodegraffLogin(logged_in: bool) bool {- return state.codegraff_login.swap(logged_in, .acq_rel) != logged_in;+pub fn setCodegraffLoginKey(io: Io, key: ?[]const u8) bool {+ state.mu.lockUncancelable(io);+ defer state.mu.unlock(io);+ const was_present = state.codegraff_login.load(.acquire);+ state.key = key orelse "";+ const present = state.key.len > 0;+ state.codegraff_login.store(present, .release);+ return was_present != present;}pub fn available(provider: Provider) bool {return state.codegraff_login.load(.acquire) and- (state.backend != .typesafe or state.key.len > 0) and!state.down.load(.acquire) and scope.eligible(provider);}@@ -155,9 +164,47 @@ fn mockResponse(arena: Allocator, input: Value) ![]const u8 {return aw.writer.buffered();}+fn gatewayBearer(arena: Allocator, key: []const u8) ![]const u8 {+ return std.fmt.allocPrint(arena, "Bearer {s}", .{key});+}++fn skipForError(err: anyerror) []const u8 {+ return switch (err) {+ error.JevUnauthorized => auth_skip_text,+ error.JevNoCredits => credit_skip_text,+ error.JevRateLimited => rate_skip_text,+ else => skip_text,+ };+}++fn usageCount(v: Value) ?i64 {+ return if (v == .integer and v.integer >= 0) v.integer else null;+}++fn noteGatewayUsage(io: Io, tally: *pricing.CostTally, arena: Allocator, raw: []const u8) void {+ const parsed = std.json.parseFromSliceLeaky(Value, arena, raw, .{}) catch {+ tally.missingUsage(io);+ return;+ };+ const usage = if (parsed == .object) parsed.object.get("usage") orelse .null else Value.null;+ if (usage == .object) {+ const input = usageCount(usage.object.get("input_tokens") orelse .null);+ const output = usageCount(usage.object.get("output_tokens") orelse .null);+ if (input != null and output != null) {+ // The gateway returns token usage but no settled charge. Preserve+ // known tokens while keeping the dollar total explicitly unknown.+ tally.addForProvider(io, .unpriced, "codegraff", "jev-latest", input.?, 0, 0, output.?);+ return;+ }+ }+ tally.missingUsage(io);+}+fn fetch(ctx: ToolCtx, arena: Allocator, body: []const u8) ![]const u8 {- const bearer = try std.fmt.allocPrint(arena, "Bearer {s}", .{state.key});+ const bearer = try gatewayBearer(arena, state.key);var aw = Io.Writer.fixed(try arena.alloc(u8, 64 * 1024));+ var completed = false;+ defer if (!completed) pricing.g_cost.failedWithoutUsage(ctx.io, 1);const res = try ctx.client.fetch(.{.location = .{ .url = endpoint },.method = .POST,@@ -169,7 +216,15 @@ fn fetch(ctx: ToolCtx, arena: Allocator, body: []const u8) ![]const u8 {.authorization = .{ .override = bearer },},});- if (@intFromEnum(res.status) != 200) return error.JevUnavailable;+ switch (@intFromEnum(res.status)) {+ 200 => {},+ 401, 403 => return error.JevUnauthorized,+ 402 => return error.JevNoCredits,+ 429 => return error.JevRateLimited,+ else => return error.JevUnavailable,+ }+ noteGatewayUsage(ctx.io, &pricing.g_cost, arena, aw.buffered());+ completed = true;return aw.buffered();}@@ -214,7 +269,6 @@ pub fn execute(ctx: ToolCtx, input: Value) !ToolOutput {if (ctx.from_sub) return invalid(ctx.gpa, "jev_judge is available only to the root agent");if (!state.codegraff_login.load(.acquire)) return invalid(ctx.gpa, "jev_judge requires a Codegraff login (`graff login`)");if (!scope.eligible(ctx.provider)) return invalid(ctx.gpa, "jev_judge is available only with Codex/OpenAI GPT-6 or Xiaomi MiMo models");- if (state.backend == .typesafe and state.key.len == 0) return skipped(ctx.gpa);if (state.down.load(.acquire)) return skipped(ctx.gpa);if (input != .object) return invalid(ctx.gpa, "jev_judge needs state, question and type");var temp = std.heap.ArenaAllocator.init(ctx.gpa);@@ -226,16 +280,17 @@ pub fn execute(ctx: ToolCtx, input: Value) !ToolOutput {};state.mu.lockUncancelable(ctx.io);defer state.mu.unlock(ctx.io);+ if (state.key.len == 0) return invalid(ctx.gpa, "jev_judge requires a Codegraff login (`graff login`)");if (state.down.load(.acquire)) return skipped(ctx.gpa);_ = state.attempts.fetchAdd(1, .acq_rel);const raw = switch (state.backend) {.mock => try mockResponse(arena, input),.mock_fail => error.JevUnavailable,- .typesafe => fetch(ctx, arena, body),- } catch {+ .gateway => fetch(ctx, arena, body),+ } catch |err| {state.down.store(true, .release);state.refresh.store(true, .release);- return skipped(ctx.gpa);+ return .{ .text = try ctx.gpa.dupe(u8, skipForError(err)) };};const result = verdict(arena, input, raw) catch {state.down.store(true, .release);@@ -257,7 +312,7 @@ test "native Jev failure makes exactly one attempt then skips without retry" {return null;}}{});- _ = setCodegraffLogin(true);+ _ = setCodegraffLoginKey(std.testing.io, "synthetic-login");const p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "", .model = "gpt-6-sol", .context = 100_000 };var client: std.http.Client = undefined;const ctx: ToolCtx = .{ .gpa = std.testing.allocator, .io = std.testing.io, .client = &client, .provider = p, .registry = null, .from_sub = false, .approvals = null, .tracer = null };@@ -276,7 +331,7 @@ test "native Jev failure makes exactly one attempt then skips without retry" {try std.testing.expect(!takeCatalogRefresh());}-test "native Jev mock uses TypeSafe wire and returns a typed verdict" {+test "native Jev mock uses SystemOne wire and returns a typed verdict" {configure(struct {fn get(_: @This(), key: []const u8) ?[]const u8 {return if (std.mem.eql(u8, key, "JEV_BACKEND")) "mock" else null;@@ -287,7 +342,7 @@ test "native Jev mock uses TypeSafe wire and returns a typed verdict" {return null;}}{});- _ = setCodegraffLogin(true);+ _ = setCodegraffLoginKey(std.testing.io, "synthetic-login");const parsed = try std.json.parseFromSlice(Value, std.testing.allocator, "{\"state\":\"10 passed, 0 failed\",\"question\":\"Did CI pass?\",\"type\":\"noul\"}", .{});defer parsed.deinit();var temp = std.heap.ArenaAllocator.init(std.testing.allocator);@@ -302,6 +357,7 @@ test "native Jev mock uses TypeSafe wire and returns a typed verdict" {const p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "", .model = "gpt-6-sol", .context = 100_000 };var client: std.http.Client = undefined;const ctx: ToolCtx = .{ .gpa = std.testing.allocator, .io = std.testing.io, .client = &client, .provider = p, .registry = null, .from_sub = false, .approvals = null, .tracer = null };+ const before = pricing.g_cost.snap(std.testing.io);const out = try execute(ctx, parsed.value);defer std.testing.allocator.free(out.text);try std.testing.expect(!out.is_error);@@ -309,6 +365,10 @@ test "native Jev mock uses TypeSafe wire and returns a typed verdict" {try std.testing.expect(@abs(number(result.object.get("answer").?).? - 0.98) < 0.0001);try std.testing.expect(!result.object.get("escalate").?.bool);try std.testing.expectEqual(@as(usize, 1), state.attempts.load(.acquire));+ const after = pricing.g_cost.snap(std.testing.io);+ try std.testing.expectEqual(before.api_calls, after.api_calls);+ try std.testing.expectEqual(before.missing_usage_calls, after.missing_usage_calls);+ try std.testing.expectEqual(before.unreported_failed_attempts, after.unreported_failed_attempts);}test "native Jev rejects out-of-range scores and malformed confidence" {@@ -322,3 +382,77 @@ test "native Jev rejects out-of-range scores and malformed confidence" {const good = try verdict(a, input, "{\"answers\":{\"q1\":{\"type\":\"score\",\"score\":1.5,\"confidence\":0.9}}}");try std.testing.expect(std.mem.indexOf(u8, good, "\"answer\":1.5") != null);}++test "native Jev gateway uses persisted login independent of chat provider and upstream key" {+ configure(struct {+ fn get(_: @This(), key: []const u8) ?[]const u8 {+ return if (std.mem.eql(u8, key, "TYPESAFE_API_KEY")) "upstream-secret" else null;+ }+ }{});+ defer configure(struct {+ fn get(_: @This(), _: []const u8) ?[]const u8 {+ return null;+ }+ }{});+ const p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "chat-key", .model = "gpt-6-sol", .context = 100_000 };+ try std.testing.expect(!available(p));+ try std.testing.expect(setCodegraffLoginKey(std.testing.io, "persisted-login"));+ try std.testing.expect(available(p));+ try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/systemone", endpoint);+ const bearer = try gatewayBearer(std.testing.allocator, state.key);+ defer std.testing.allocator.free(bearer);+ try std.testing.expectEqualStrings("Bearer persisted-login", bearer);+ try std.testing.expect(std.mem.indexOf(u8, bearer, p.api_key) == null);+ try std.testing.expect(std.mem.indexOf(u8, bearer, "upstream-secret") == null);+ try std.testing.expect(setCodegraffLoginKey(std.testing.io, null));+ try std.testing.expect(!available(p));+}++test "native Jev reports safe gateway failures and does not invent usage or cost" {+ try std.testing.expect(std.mem.indexOf(u8, skipForError(error.JevUnauthorized), "authorization failed") != null);+ try std.testing.expect(std.mem.indexOf(u8, skipForError(error.JevNoCredits), "credits or key budget") != null);+ try std.testing.expect(std.mem.indexOf(u8, skipForError(error.JevRateLimited), "rate limit") != null);+ try std.testing.expectEqualStrings(skip_text, skipForError(error.ConnectionRefused));+ var temp = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer temp.deinit();+ const a = temp.allocator();+ const input = try std.json.parseFromSliceLeaky(Value, a, "{\"state\":\"build passed\",\"question\":\"Did CI pass?\",\"type\":\"noul\"}", .{});+ const out = try verdict(a, input, "{\"answers\":{\"q1\":{\"type\":\"noul\",\"noul\":0.98}},\"usage\":{\"input_tokens\":20,\"output_tokens\":5}}");+ const parsed = try std.json.parseFromSliceLeaky(Value, a, out, .{});+ try std.testing.expect(parsed.object.get("usage") == null);+ try std.testing.expect(parsed.object.get("cost") == null);+}++test "native Jev gateway usage preserves tokens but marks unsettled cost unknown" {+ const io = std.testing.io;+ var tally: pricing.CostTally = .{};+ var temp = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer temp.deinit();+ noteGatewayUsage(io, &tally, temp.allocator(), "{\"answers\":{},\"usage\":{\"input_tokens\":20,\"output_tokens\":5}}");+ var c = tally.snap(io);+ try std.testing.expectEqual(@as(u64, 1), c.api_calls);+ try std.testing.expectEqual(@as(u64, 20), c.in_tokens);+ try std.testing.expectEqual(@as(u64, 5), c.out_tokens);+ try std.testing.expectEqual(@as(u64, 1), c.unpriced_calls);+ try std.testing.expectEqual(@as(f64, 0), c.usd); // known subtotal, not an invented settled charge+ var wire: Io.Writer.Allocating = .init(std.testing.allocator);+ defer wire.deinit();+ try @import("acp_usage.zig").write(&wire.writer, "fixture", &tally, io);+ const event = try std.json.parseFromSliceLeaky(Value, temp.allocator(), wire.written(), .{});+ const usage = event.object.get("params").?.object.get("usage").?.object;+ try std.testing.expect(usage.get("usage_complete").?.bool);+ try std.testing.expect(!usage.get("cost_complete").?.bool);+ try std.testing.expect(usage.get("cost_usd").? == .null);+ noteGatewayUsage(io, &tally, temp.allocator(), "{\"answers\":{}}");+ noteGatewayUsage(io, &tally, temp.allocator(), "{\"usage\":{\"input_tokens\":-1,\"output_tokens\":5}}");+ noteGatewayUsage(io, &tally, temp.allocator(), "{\"usage\":{\"input_tokens\":2.5,\"output_tokens\":5}}");+ c = tally.snap(io);+ try std.testing.expectEqual(@as(u64, 4), c.api_calls);+ try std.testing.expectEqual(@as(u64, 3), c.missing_usage_calls);+ const turn = @import("turn_event.zig").fromTally(&tally, io, "done", 100, true);+ try std.testing.expect(!turn.usage_complete);+ tally.failedWithoutUsage(io, 1); // a sent request failed before a receipt+ c = tally.snap(io);+ try std.testing.expectEqual(@as(u64, 1), c.unreported_failed_attempts);+ try std.testing.expectEqual(@as(u64, 4), c.api_calls); // failed attempts are separate+}diff --git a/src/obs_cost_test.zig b/src/obs_cost_test.zigindex f97de09b..d4faa58b 100644--- a/src/obs_cost_test.zig+++ b/src/obs_cost_test.zig@@ -83,7 +83,7 @@ test "usage/debug match the cost-tally renderer and add turn/decision extras" {var cost2_buf: [384]u8 = undefined;const cost2 = renderCost(io, &cost2_buf);try std.testing.expect(contains(cost2, "subscription"));- try std.testing.expect(contains(cost2, "unpriced"));+ try std.testing.expect(contains(cost2, "unknown cost"));var usage2_buf: [512]u8 = undefined;var usage2_w: Io.Writer = .fixed(&usage2_buf);diff --git a/src/picker_auth.zig b/src/picker_auth.zigindex cbab7956..6f7fe763 100644--- a/src/picker_auth.zig+++ b/src/picker_auth.zig@@ -43,7 +43,7 @@ pub const PickerFn = *const fn (/// the startup loaders.pub fn reloadLoginKey(root: *Agent, keys: *Keys, arena: Allocator, provider_id: []const u8) void {const home = root.home;- var codegraff_reloaded = false;+ var codegraff_key: ?[]const u8 = null;for (provider_specs, &keys.values, &keys.sources) |spec, *value, *source| {if (!std.mem.eql(u8, spec.id, provider_id)) continue;var reloaded = false;@@ -52,7 +52,9 @@ pub fn reloadLoginKey(root: *Agent, keys: *Keys, arena: Allocator, provider_id:value.* = k;source.* = .login;reloaded = true;- codegraff_reloaded = true;+ // The caller's arena may be scoped to this command. Jev keeps+ // its own session-lifetime copy for later root tool calls.+ codegraff_key = root.arena.dupe(u8, k) catch null;}} else if (std.mem.eql(u8, provider_id, "kimi")) {if (oauth.loadKimiOAuth(root.io, root.gpa, arena, home, false, null)) |k| {@@ -99,7 +101,7 @@ pub fn reloadLoginKey(root: *Agent, keys: *Keys, arena: Allocator, provider_id:root.closeCodexWs(); // the held socket was dialed with the stale bearer};}- if (std.mem.eql(u8, provider_id, "codegraff") and jev_tool.setCodegraffLogin(codegraff_reloaded))+ if (std.mem.eql(u8, provider_id, "codegraff") and jev_tool.setCodegraffLoginKey(root.io, codegraff_key))root.invalidateRootTools();if (std.mem.eql(u8, provider_id, "codex") and keys.get("codex") != null)root.reloadModelCatalog(keys.*);diff --git a/src/pricing.zig b/src/pricing.zigindex bd7a7a3a..1aa99c36 100644--- a/src/pricing.zig+++ b/src/pricing.zig@@ -35,7 +35,8 @@ pub fn priceForProvider(provider: []const u8, model: []const u8) ?ModelPrice {}/// Billing class of one API call: a flat-rate subscription login bills nothing-/// per token, price_table rows bill per token, anything else is unpriced.+/// per token, price_table rows bill per token, anything without a reliable+/// settled charge is unpriced for the session tally./// Classifying a SEAT is billing.zig's job — it needs the provider spec and the/// credential source, neither of which belongs in a price sheet.pub const Billing = enum { sub, priced, unpriced };@@ -63,7 +64,7 @@ pub const CostTally = struct {sub_calls: u64 = 0, // subscription-billed (flat-rate; contribute $0)unreported_failed_attempts: u64 = 0, // not successful calls; billing is unknownmissing_usage_calls: u64 = 0, // completed responses whose usage was absent- unpriced_calls: u64 = 0, // no price_table row+ unpriced_calls: u64 = 0, // no reliable settled charge (or no price_table row)/// `billing` is the caller's already-classified seat (billing.forSeat): a/// flat-rate login and a metered env key on the SAME provider+model are@@ -113,14 +114,14 @@ pub const CostTally = struct {/// One-line summary shared by /cost and the one-shot stderr report.pub fn render(c: CostTally, w: *Io.Writer) !void {- if (c.missing_usage_calls > 0 or c.unreported_failed_attempts > 0) try w.writeAll("known subtotal: ");+ if (c.missing_usage_calls > 0 or c.unreported_failed_attempts > 0 or c.unpriced_calls > 0) try w.writeAll("known subtotal: ");try w.print("{d} api call(s) · {d} in ({d} cached, {d} cache writes) + {d} out tokens · ${d:.8}", .{c.api_calls, c.in_tokens +| c.cache_tokens, c.cache_tokens, c.cache_write_tokens, c.out_tokens, c.usd,});if (c.missing_usage_calls > 0) try w.print(" · totals incomplete: {d} call(s) missing usage (tokens and cost unknown)", .{c.missing_usage_calls});if (c.unreported_failed_attempts > 0) try w.print(" · totals incomplete: {d} failed request attempt(s) without usage (tokens and cost unknown)", .{c.unreported_failed_attempts});if (c.sub_calls > 0) try w.print(" · {d} subscription call(s), flat-rate (not in $)", .{c.sub_calls});- if (c.unpriced_calls > 0) try w.print(" · {d} call(s) on unpriced models", .{c.unpriced_calls});+ if (c.unpriced_calls > 0) try w.print(" · {d} call(s) with unknown cost", .{c.unpriced_calls});}};diff --git a/src/session_settings.zig b/src/session_settings.zigindex 79748046..806ed259 100644--- a/src/session_settings.zig+++ b/src/session_settings.zig@@ -266,14 +266,14 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {}}-fn codegraffLoginPresent(io: Io, arena: Allocator, environ_map: anytype) bool {- const home = keys_cli.homeEnv(environ_map) orelse return false;- return oauth.loadCodegraffKey(io, arena, home) != null;+fn codegraffLoginKey(io: Io, arena: Allocator, environ_map: anytype) ?[]const u8 {+ const home = keys_cli.homeEnv(environ_map) orelse return null;+ return oauth.loadCodegraffKey(io, arena, home);}pub fn setupSkillsAndTheme(io: Io, arena: Allocator, environ_map: anytype, out: *Io.Writer, flags: args.Flags, use_color: bool, json_mode: bool, cwd_display: []const u8) !ThemeSetup {try applyEnvKnobs(arena, environ_map);- _ = jev_tool.setCodegraffLogin(codegraffLoginPresent(io, arena, environ_map));+ _ = jev_tool.setCodegraffLoginKey(io, codegraffLoginKey(io, arena, environ_map));skills.loadSkillSettings(io, arena); // per-skill opt-outs, also gates the auto-connectanim.loadAnimationSetting(io, arena); // {"animation": "..."} → thinking spinner choiceanim.loadThemeSetting(io, arena); // {"theme": "<name>"} → opt-in terminal color theme@@ -371,12 +371,12 @@ test "Jev startup gate requires a persisted Codegraff login, not an env API key"return null;}}{ .home = home };- try std.testing.expect(!codegraffLoginPresent(io, arena, env));+ try std.testing.expect(codegraffLoginKey(io, arena, env) == null);try Io.Dir.cwd().writeFile(io, .{.sub_path = try std.fmt.allocPrint(arena, "{s}/.simple-harness-codegraff.json", .{home}),.data = "{\"api_key\":\"synthetic-login\"}",});- try std.testing.expect(codegraffLoginPresent(io, arena, env));+ try std.testing.expectEqualStrings("synthetic-login", codegraffLoginKey(io, arena, env).?);try tmp.dir.deleteFile(io, ".simple-harness-codegraff.json");- try std.testing.expect(!codegraffLoginPresent(io, arena, env));+ try std.testing.expect(codegraffLoginKey(io, arena, env) == null);}