graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
A role persona can name its own provider
Rach Pradhanc2c9caac7d2d
diff --git a/src/subagent_pin.zig b/src/subagent_pin.zigindex 27bab4ee..ffe414b8 100644--- a/src/subagent_pin.zig+++ b/src/subagent_pin.zig@@ -67,6 +67,7 @@ const billing = @import("billing.zig"); // #471: seat billing class (flat-rate lconst bench_priors = @import("bench_priors.zig");const fleet = @import("fleet.zig");const selection = @import("subagent_selection.zig");+const catalog_selection = @import("catalog_selection.zig");const tier_ladder = @import("subagent_tier_ladder.zig");const route_policy = @import("route_policy.zig"); // #372 learned (shape, role) tier policy@@ -116,6 +117,8 @@ pub const Outcome = enum {rung_pricier, // the rung would cost more than the child's current modelsub_routed, // the rung went to a logged-in flat-rate subscription insteadmodel_sub_routed, // an exact pin the child's provider does not serve went to a logged-in sub that does+ cross_provider_unconsented, // a `<provider>/<model>` pin names another provider and the session has no consent+ no_login, // a `<provider>/<model>` pin names a provider with no key or loginpub fn describe(self: Outcome) []const u8 {return switch (self) {@@ -129,6 +132,8 @@ pub const Outcome = enum {.rung_pricier => "tier pin ignored: that rung is pricier than this agent's model — cost never escalates implicitly; pin the model by name to escalate",.sub_routed => "tier routed to a logged-in flat-rate subscription — marginal cost zero outranks metered spend; the login is the user's standing consent for that vendor",.model_sub_routed => "model pin routed to a logged-in flat-rate subscription that serves it — the child's provider does not; the login is the user's standing consent for that vendor",+ .cross_provider_unconsented => "model pin ignored: it names another provider — start with --allow-cross-provider-subagents to let workers send prompts and code there",+ .no_login => "model pin ignored: no key or login for the provider it names — kept the session default",};}};@@ -237,7 +242,10 @@ pub fn resolve(base: Provider, pin: Pin) Resolved {/// so learning can never escalate spend either.pub fn resolveIn(base: Provider, pin: Pin, cell: Cell) Resolved {const pin_src: Source = if (pin.from_persona) .persona else .explicit_pin;- if (pin.model) |query| return finish(base, selection.modelForProvider(base.id, query), pin_src);+ if (pin.model) |query| {+ if (qualified(base, query, pin_src)) |r| return r;+ return finish(base, selection.modelForProvider(base.id, query), pin_src);+ }if (pin.tier) |tier| {const ladder = tier_ladder.forModel(base.id, base.model) orelse return .{ .outcome = .no_ladder };const rung = ladder.modelFor(tier) orelse return .{ .outcome = .no_rung };@@ -392,6 +400,26 @@ pub fn rungAffordable(base_model: []const u8, rung_model: []const u8) bool {return rp.in + rp.out <= bp.in + bp.out;}+/// A pin written `<provider>/<model>` names its provider, so a role persona can+/// seat itself on another service (`model: codegraff/mercury-3` for a scout+/// under a subscription root). The same provider just drops the prefix.+/// Another provider is a boundary crossing: it needs the session's+/// --allow-cross-provider-subagents consent and a login, and then takes the+/// exact name under the rule `--model <provider>/<model>` uses, since a+/// gateway serves models the baked table does not list.+fn qualified(base: Provider, query: []const u8, src: Source) ?Resolved {+ const slash = std.mem.indexOfScalar(u8, query, '/') orelse return null;+ const spec = provider_mod.specFor(query[0..slash]) orelse return null;+ const name = query[slash + 1 ..];+ if (std.mem.eql(u8, spec.id, base.id)) return finish(base, selection.modelForProvider(base.id, name), src);+ if (!selection.g_cross_provider_consent) return .{ .outcome = .cross_provider_unconsented, .source = src };+ const model = selection.modelForProvider(spec.id, name) orelse+ (if (catalog_selection.acceptsExplicitModel(spec, name)) name else return .{ .outcome = .unknown_model, .source = src });+ const keys = bench_priors.g_keys orelse return .{ .outcome = .no_login, .source = src };+ const prov = keys.providerById(spec.id, model) catch return .{ .outcome = .no_login, .source = src };+ return .{ .provider = prov, .outcome = .pinned, .source = src };+}+fn finish(base: Provider, name: ?[]const u8, source: Source) Resolved {const resolved = name orelse return .{ .outcome = .unknown_model };if (std.mem.eql(u8, resolved, base.model)) return .{ .outcome = .same, .source = source };diff --git a/src/subagent_pin_qualified_tests.zig b/src/subagent_pin_qualified_tests.zignew file mode 100644index 00000000..a9fb513a--- /dev/null+++ b/src/subagent_pin_qualified_tests.zig@@ -0,0 +1,47 @@+//! A role persona naming its own provider (`model: codegraff/mercury-3`):+//! seated on that provider only with the session's cross-provider consent+//! and a login for it.++const std = @import("std");+const pin_mod = @import("subagent_pin.zig");+const provider_mod = @import("provider.zig");+const Provider = provider_mod.Provider;++fn codexBase() Provider {+ return .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "https://example.invalid", .api_key = "k", .model = "gpt-6-astra", .context = 272_000 };+}++test "a <provider>/<model> pin seats a role on another provider only with consent and a login" {+ const selection = @import("subagent_selection.zig");+ const bench_priors = @import("bench_priors.zig");+ const saved_consent = selection.g_cross_provider_consent;+ const saved_keys = bench_priors.g_keys;+ defer selection.g_cross_provider_consent = saved_consent;+ defer bench_priors.g_keys = saved_keys;+ var keys: provider_mod.Keys = .{ .values = @splat(null) };+ for (provider_mod.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";+ }+ bench_priors.g_keys = &keys;+ const scout: pin_mod.Pin = .{ .model = "codegraff/gateway-only-scout-model", .from_persona = true };++ selection.g_cross_provider_consent = false;+ const refused = pin_mod.resolve(codexBase(), scout);+ try std.testing.expectEqual(pin_mod.Outcome.cross_provider_unconsented, refused.outcome);+ try std.testing.expect(refused.provider == null);++ selection.g_cross_provider_consent = true;+ const seated = pin_mod.resolve(codexBase(), scout);+ try std.testing.expectEqual(pin_mod.Outcome.pinned, seated.outcome);+ try std.testing.expectEqualStrings("codegraff", seated.provider.?.id);+ try std.testing.expectEqualStrings("gateway-only-scout-model", seated.provider.?.model);++ // Naming the child's own provider just drops the prefix.+ const local = pin_mod.resolve(codexBase(), .{ .model = "codex/gpt-6-luna" });+ try std.testing.expectEqualStrings("codex", local.provider.?.id);+ try std.testing.expectEqualStrings("gpt-6-luna", local.provider.?.model);++ // No login for the named provider keeps the session default.+ keys.values = @splat(null);+ try std.testing.expectEqual(pin_mod.Outcome.no_login, pin_mod.resolve(codexBase(), scout).outcome);+}diff --git a/src/subagent_selection.zig b/src/subagent_selection.zigindex 4fd34e42..17c016b5 100644--- a/src/subagent_selection.zig+++ b/src/subagent_selection.zig@@ -134,6 +134,12 @@ pub fn subagentProvider(return keys.providerById(requested_provider, model) catch error.MissingKey;}+/// The session consented (--allow-cross-provider-subagents) to workers on+/// another provider. Latches on at startup; a later model switch re-resolving+/// the worker without the flag does not withdraw it. Read by per-persona+/// `<provider>/<model>` pins (subagent_pin.zig).+pub var g_cross_provider_consent: bool = false;+pub fn resolveSubagentProvider(keys: provider_mod.Keys,root: provider_mod.Provider,@@ -142,6 +148,7 @@ pub fn resolveSubagentProvider(allow_cross_provider: bool,disable_default_ladder: bool,) ?provider_mod.Provider {+ if (allow_cross_provider) g_cross_provider_consent = true;const raw_provider = provider_query orelse "";const requested_provider = std.mem.trim(u8, raw_provider, " \t\r\n");const raw_model = model_query orelse {diff --git a/src/test_hooks.zig b/src/test_hooks.zigindex 1611424b..bc368f12 100644--- a/src/test_hooks.zig+++ b/src/test_hooks.zig@@ -340,6 +340,7 @@ test {_ = @import("mcp_connect_notice.zig"); // ADR 0230_ = @import("image_sniff.zig"); // #1762: image media type from the bytes_ = @import("catalog_bounded.zig"); // model discovery: catalog GETs never hold boot past a budget+ _ = @import("subagent_pin_qualified_tests.zig"); // a role persona can name its own provider_ = @import("opaque_state_persist_tests.zig"); // #1686: a resumed session keeps its compaction-state count_ = @import("oauth_callback.zig");_ = @import("cache_key_tests.zig"); // ADR 0223: moved off http_headers.zig (600-line cap)