Skip to content

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

Python

one-shot implies yolo: -p runs autonomously by default, --safe opts out

Rach Pradhan7d6ec808dca6
diff --git a/src/args.zig b/src/args.zig
index 7d60377b..b18b1d7a 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -31,6 +31,7 @@ const no_local_tools = @import("no_local_tools.zig"); // #330: `--no-local-tools
/// after the parse loop. One field per former local, same default.
pub const Flags = struct {
yolo_flag: bool = false,
+ safe_flag: bool = false, // --safe: one-shot WITHOUT the implied --yolo (approval-gated, the old -p default)
lean_flag: bool = false, // --lean: skip connecting MCP servers entirely (GRAFF_LEAN=1) — a smaller per-turn prefix for one-shot/CI runs
no_telemetry_flag: bool = false,
learning_privacy_flag: ?learning_privacy.Mode = null,
@@ -73,6 +74,15 @@ pub const Flags = struct {
/// The joined positional args as a one-shot prompt (`harness "say hi"`
/// or `harness -p "..."`), or null when positionals[0] is a subcommand.
oneshot_prompt: ?[]const u8 = null,
+
+ /// One-shot is autonomous by default: -p implies --yolo — the typed-out
+ /// invocation IS the consent, and a no-stdin approval prompt can only
+ /// auto-decline (which stranded unattended coding runs on a policy
+ /// artifact). --safe opts back into the old approval-gated -p.
+ /// Interactive sessions are untouched: no oneshot prompt, no implied yolo.
+ pub fn effectiveYolo(flags: Flags) bool {
+ return flags.yolo_flag or (flags.oneshot_prompt != null and !flags.safe_flag);
+ }
};
/// Parses argv (via init.minimal.args) into a `Flags`. Fatals via
@@ -94,8 +104,11 @@ pub fn parse(init: std.process.Init) !Flags {
} else if (std.mem.startsWith(u8, arg, "-")) {
if (std.mem.eql(u8, arg, "--yolo")) {
flags.yolo_flag = true;
+ } else if (std.mem.eql(u8, arg, "--safe")) {
+ flags.safe_flag = true;
} else if (std.mem.eql(u8, arg, "--lean")) {
flags.lean_flag = true;
+ no_local_tools.lean = true; // the tool-surface half of lean (the MCP half reads lean_flag via session_start.leanSkipsMcp)
} else if (std.mem.eql(u8, arg, "--worktree") or std.mem.eql(u8, arg, "-w")) {
flags.worktree_flag = it.next() orelse std.process.fatal("--worktree needs a name (e.g. --worktree agent1)", .{});
} else if (std.mem.eql(u8, arg, "--goal")) {
@@ -211,3 +224,11 @@ pub fn parse(init: std.process.Init) !Flags {
return flags;
}
+
+test "effectiveYolo: -p implies yolo, --safe opts out, interactive untouched" {
+ try std.testing.expect(Flags.effectiveYolo(.{ .yolo_flag = true }));
+ try std.testing.expect(Flags.effectiveYolo(.{ .oneshot_prompt = "fix it" }));
+ try std.testing.expect(!Flags.effectiveYolo(.{ .oneshot_prompt = "fix it", .safe_flag = true }));
+ try std.testing.expect(!Flags.effectiveYolo(.{}));
+ try std.testing.expect(Flags.effectiveYolo(.{ .oneshot_prompt = "fix it", .yolo_flag = true, .safe_flag = true })); // explicit --yolo wins over --safe
+}
diff --git a/src/main.zig b/src/main.zig
index adc9c0e2..f5a5991d 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -408,7 +408,7 @@ pub fn main(init: std.process.Init) !void {
// Root system-prompt layering (base + AGENTS.md/HARNESS.md/CLAUDE.md + --append-system-prompt + active-skill lines + connected-MCP notes) lives
// in startup.zig as buildSystemPrompt() — pure over io/arena, returns the composed base by value. buildRootAgent derives every prompt variant
// from it via prompts.setSystemPrompts() (#326).
- const sys_normal = try startup.buildSystemPrompt(io, arena, out, flags.system_prompt_flag, flags.append_system_flag, json_mode or flags.oneshot_prompt != null, flags.oneshot_prompt != null and !flags.yolo_flag, mcp_tools, g_codedbpro_licensed, init.environ_map.get("GRAFF_LEARNED_PROMPT"), init.environ_map);
+ const sys_normal = try startup.buildSystemPrompt(io, arena, out, flags.system_prompt_flag, flags.append_system_flag, json_mode or flags.oneshot_prompt != null, flags.oneshot_prompt != null and !flags.effectiveYolo(), mcp_tools, g_codedbpro_licensed, init.environ_map.get("GRAFF_LEARNED_PROMPT"), init.environ_map);
boot.mark(io, "system prompt");
session_run.learningNotice(io, arena, init.environ_map, out, json_mode or flags.oneshot_prompt != null);
diff --git a/src/session_run.zig b/src/session_run.zig
index 96a5e27b..63485146 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -198,7 +198,7 @@ pub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_m
/// its own `defer` for `approvals.prefixes` right after the call (a `defer`
/// registered here would fire when THIS returns, not when main() does).
pub fn initApprovalsHooksFleet(io: Io, gpa: Allocator, arena: Allocator, environ_map: anytype, approvals: *Approvals, flags: args.Flags, out: *Io.Writer, json_mode: bool) !void {
- approvals.* = .{ .yolo = flags.yolo_flag };
+ approvals.* = .{ .yolo = flags.effectiveYolo() }; // -p implies yolo unless --safe
const persisted_approvals = approvals.loadPersisted(io, gpa, arena);
// Agent types: builtins + .harness/agents/*.md (the MAP-Elites niches).
diff --git a/src/session_start.zig b/src/session_start.zig
index b0250869..383e5bbc 100644
--- a/src/session_start.zig
+++ b/src/session_start.zig
@@ -147,9 +147,9 @@ pub fn setupWorktreeAndBanner(
if (codex_account) |acct| sink.emit(io, .{ .session_notice = .{
.text = try std.fmt.allocPrint(arena, "logged into Codex (ChatGPT account {s}…) — /model codex", .{acct[0..@min(acct.len, 8)]}),
} });
- if (flags.yolo_flag) sink.emit(io, .{ .session_notice = .{
+ if (flags.effectiveYolo()) sink.emit(io, .{ .session_notice = .{
.lead = "⚠ YOLO",
- .text = " mode (--yolo): all bash/tool/MCP permission prompts are skipped",
+ .text = if (flags.yolo_flag) " mode (--yolo): all bash/tool/MCP permission prompts are skipped" else " mode (-p implies --yolo; --safe opts out): all bash/tool/MCP permission prompts are skipped",
.tone = .alert,
} });
if (stale_saved_model) |nm| {