graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Load the catalog of a provider workers may be seated on
Rach Pradhan406c412c4cba
diff --git a/src/catalog_selection.zig b/src/catalog_selection.zigindex b23a81c2..60300175 100644--- a/src/catalog_selection.zig+++ b/src/catalog_selection.zig@@ -36,6 +36,18 @@ pub fn queryMayUse(provider_id: []const u8, query: []const u8) bool {return true;}+/// startupMayUse, plus the providers workers may be seated on: the explicit+/// --subagent-provider, and, once the session consented to cross-provider+/// workers, any provider with a login (a persona may name it as+/// `<provider>/<model>`). Loading their catalogs is what lets those workers'+/// models resolve and their calls be priced.+pub fn startupLoads(keys: provider.Keys, provider_id: []const u8, model_flag: ?[]const u8, saved: ?serde.SavedModel, worker_hint: ?[]const u8) bool {+ if (startupMayUse(keys, provider_id, model_flag, saved)) return true;+ if (keys.get(provider_id) == null) return false;+ if (worker_hint) |h| if (std.mem.eql(u8, std.mem.trim(u8, h, " \t"), provider_id)) return true;+ return @import("subagent_selection.zig").g_cross_provider_consent;+}+pub fn startupMayUse(keys: provider.Keys, provider_id: []const u8, model_flag: ?[]const u8, saved: ?serde.SavedModel) bool {if (keys.get(provider_id) == null) return false;if (model_flag) |query| return queryMayUse(provider_id, query);@@ -73,3 +85,20 @@ test "catalog selection is provider-driven rather than catalog-specific" {try std.testing.expect(startupMayUse(keys, "codegraff", null, .{ .pid = "codegraff", .model = "deepseek-v4-pro" }));try std.testing.expect(!startupMayUse(keys, "codegraff", null, .{ .pid = "kimi", .model = "k3" }));}++test "startup loads the catalog of a provider workers may be seated on" {+ const selection = @import("subagent_selection.zig");+ const saved_consent = selection.g_cross_provider_consent;+ defer selection.g_cross_provider_consent = saved_consent;+ var keys: provider.Keys = .{ .values = @splat(null) };+ for (provider.provider_specs, &keys.values) |spec, *value| {+ if (std.mem.eql(u8, spec.id, "codex") or std.mem.eql(u8, spec.id, "codegraff")) value.* = "test-token";+ }+ selection.g_cross_provider_consent = false;+ try std.testing.expect(!startupLoads(keys, "codegraff", "codex", null, null));+ try std.testing.expect(startupLoads(keys, "codegraff", "codex", null, "codegraff"));+ selection.g_cross_provider_consent = true;+ try std.testing.expect(startupLoads(keys, "codegraff", "codex", null, null));+ // A provider with no login is never loaded for workers.+ try std.testing.expect(!startupLoads(keys, "openrouter", "codex", null, null));+}diff --git a/src/router_catalog.zig b/src/router_catalog.zigindex 12246ea2..8ab21400 100644--- a/src/router_catalog.zig+++ b/src/router_catalog.zig@@ -468,13 +468,13 @@ fn startKimi(io: Io, batch: *catalog_bounded.Batch, arena: Allocator, home: []co/// behind. Hosts with no cache fetch concurrently under one budget, so boot/// pays at most `startup_budget` however slow DNS or TLS is; a fetch that/// misses it still caches its list for the next process.-pub fn ensureForStartup(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, keys: provider.Keys, model_flag: ?[]const u8, saved: ?serde.SavedModel) void {+pub fn ensureForStartup(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, keys: provider.Keys, model_flag: ?[]const u8, saved: ?serde.SavedModel, worker_hint: ?[]const u8) void {_ = gpa;var batch: catalog_bounded.Batch = .{};const kimi_slot = startKimi(io, &batch, arena, home, keys, model_flag, saved);var slots: [provider.provider_specs.len + 1]?usize = @splat(null);for (provider.provider_specs, 0..) |spec, index| {- if (!dynamic(spec) or !catalog_selection.startupMayUse(keys, spec.id, model_flag, saved)) continue;+ if (!dynamic(spec) or !catalog_selection.startupLoads(keys, spec.id, model_flag, saved, worker_hint)) continue;if (attempted[index]) continue;const key = keys.get(spec.id) orelse continue;if (key.len == 0) continue;@@ -482,7 +482,7 @@ pub fn ensureForStartup(io: Io, gpa: Allocator, arena: Allocator, home: []constslots[index] = startSpec(io, &batch, arena, home, spec, key, keys.source(spec.id));}if (provider.additional_router) |spec| {- if (catalog_selection.startupMayUse(keys, spec.id, model_flag, saved) and !additional_attempted) {+ if (catalog_selection.startupLoads(keys, spec.id, model_flag, saved, worker_hint) and !additional_attempted) {if (keys.get(spec.id)) |key| if (key.len != 0) {additional_attempted = true;slots[provider.provider_specs.len] = startSpec(io, &batch, arena, home, spec, key, keys.source(spec.id));diff --git a/src/startup.zig b/src/startup.zigindex a6a61168..39c92360 100644--- a/src/startup.zig+++ b/src/startup.zig@@ -236,6 +236,8 @@ fn serveConfig(flags: args.Flags, environ: anytype) serve.ServeConfig {/// every other terminal trajectory keeps resolveKeys' existing fatal behavior.pub fn resolveKeysOrRunAcpPreAuth(io: Io, gpa: Allocator, arena: Allocator, init: std.process.Init, flags: args.Flags) !?ResolvedKeys {const worker_hint = flags.subagent_provider_flag orelse init.environ_map.get("GRAFF_SUBAGENT_PROVIDER");+ // Before key resolution: the startup catalog load reads it (catalog_selection.startupLoads).+ if (flags.allow_cross_provider_subagents_flag) @import("subagent_selection.zig").g_cross_provider_consent = true;const is_acp = flags.positionals.items.len > 0 and std.mem.eql(u8, flags.positionals.items[0], "acp");if (!is_acp) return try resolveKeys(io, gpa, arena, init.environ_map, flags.model_flag, worker_hint);if (try startup_keys.resolveKeysOptional(io, gpa, arena, init.environ_map, flags.model_flag, worker_hint)) |resolved| return resolved;diff --git a/src/startup_keys.zig b/src/startup_keys.zigindex 90115bbd..c4f76826 100644--- a/src/startup_keys.zig+++ b/src/startup_keys.zig@@ -360,7 +360,7 @@ pub fn resolveKeysOptional(io: Io, gpa: Allocator, arena: Allocator, environ_map// network I/O; model surfaces go online via ensure() when they need it.if (catalog_selection.startupMayUse(keys, "codex", model_flag, saved_model))model_catalog.ensureCached(io, gpa, arena, home, keys.get("codex") orelse "", keys.codex_account);- router_catalog.ensureForStartup(io, gpa, arena, home, keys, model_flag, saved_model);+ router_catalog.ensureForStartup(io, gpa, arena, home, keys, model_flag, saved_model, worker_provider_hint);if (home.len != 0) {// Apply the independent models.dev price/context overlay after routing// discovery. Provider-specific Codex windows remain authoritative.