Skip to content

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

Python

Stop treating git add as a publication claim

justrach8ff15bb9c417
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63ee1f33..4d388d51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ current is part of cutting a release.
## Unreleased
-- `#1088`: `gh issue create` is not owned by the latest claimed issue; pushing a new branch is not an unrelated PR.
+- `#1088`: claims own one artifact. Staging (`git add`) is not a publication lock; `git -C` uses that tree's branch; issue create and a new-branch push are not the latest issue or an unrelated PR.
- `#1084`: gpt-6-astra `/effort medium` sends medium (no longer remapped to low).
- Empty Enter-Enter while a turn is running interrupts (or steers the next queued prompt). It no longer required a queue to arm.
- Desktop ACP workers can park after a quiet period (`GRAFF_ACP_IDLE_MS`, default 30s) and `--resume` with the saved cache id. Parking is skipped while a prompt or `session/idle` subscriber is live; tab close still reaps immediately.
diff --git a/src/artifact_claim.zig b/src/artifact_claim.zig
index dcc7efdb..474cbac1 100644
--- a/src/artifact_claim.zig
+++ b/src/artifact_claim.zig
@@ -356,7 +356,7 @@ test "persist round-trip survives a resume-shaped reload" {
}
test "claimed mutations include push and gh pr create, not status or checks --watch" {
- try std.testing.expect(isClaimedMutation("git add -A"));
+ try std.testing.expect(!isClaimedMutation("git add -A"));
try std.testing.expect(isClaimedMutation("git commit -m wip"));
try std.testing.expect(isClaimedMutation("git push origin HEAD"));
try std.testing.expect(isClaimedMutation("gh pr create --title x --body y"));
@@ -504,6 +504,8 @@ test "#1088 issue create is not the latest claimed issue; push is not an unrelat
try std.testing.expect(gateCommand(ar, std.testing.io, "gh issue edit 1087 --title x", "") != null);
try std.testing.expect(gateCommand(ar, std.testing.io, "git push origin HEAD", "release/v0.0.302") == null);
try std.testing.expect(gateCommand(ar, std.testing.io, "git push origin HEAD", "") == null);
+ try std.testing.expect(gateCommand(ar, std.testing.io, "git add src/artifact_claim.zig", "release/v0.0.301") == null);
+ try std.testing.expect(gateCommand(ar, std.testing.io, "git -C other commit -m wip", "") == null);
}
test "legacy pid-zero handoff can be released by the labeled session" {
diff --git a/src/artifact_claim_command.zig b/src/artifact_claim_command.zig
index 96b5dcc3..29a2ae5e 100644
--- a/src/artifact_claim_command.zig
+++ b/src/artifact_claim_command.zig
@@ -97,6 +97,49 @@ pub fn action(input: []const u8) ?Action {
return scan(input, null);
}
+pub fn has(input: []const u8, wanted: Action) bool {
+ return scan(input, wanted) != null;
+}
+
+/// First `git -C <path>` directory in `input`, if the path is a literal word.
+pub fn gitWorkDir(input: []const u8) ?[]const u8 {
+ var lexer = Lexer{ .input = input };
+ var state: State = .command;
+ var pending_c = false;
+ while (lexer.next()) |token| switch (token) {
+ .separator => {
+ state = .command;
+ pending_c = false;
+ },
+ .word => |raw| {
+ const word = tokenText(raw);
+ if (word.len == 0) continue;
+ if (pending_c) return word;
+ switch (state) {
+ .command => {
+ if (isAssignment(word)) continue;
+ const exe = std.fs.path.basename(word);
+ if (std.mem.eql(u8, exe, "git")) state = .git else if (isWrapper(exe)) {} else state = .ignore;
+ },
+ .git_value => state = .git,
+ .git => {
+ if (std.mem.eql(u8, word, "-C")) {
+ pending_c = true;
+ } else if (std.mem.eql(u8, word, "-c")) {
+ state = .git_value;
+ } else if (word[0] == '-') {
+ continue;
+ } else {
+ state = .ignore;
+ }
+ },
+ else => {},
+ }
+ },
+ };
+ return null;
+}
+
fn scan(input: []const u8, wanted: ?Action) ?Action {
var lexer = Lexer{ .input = input };
var state: State = .command;
@@ -216,16 +259,19 @@ fn hasCommandFlag(word: []const u8) bool {
return std.mem.indexOfScalar(u8, word[1..], 'c') != null;
}
+/// History rewrites and commits, not staging. `git add` is shared-tree
+/// presence, not an artifact claim (#1088).
fn isSharedTreeGit(subcommand: []const u8) bool {
for ([_][]const u8{
- "add", "rm", "mv", "commit", "reset", "restore", "checkout", "switch", "stash", "pull",
- "rebase", "merge", "cherry-pick", "revert", "am", "apply", "clean", "update-index",
+ "commit", "reset", "checkout", "switch", "rebase", "merge", "cherry-pick", "revert",
}) |name| if (std.mem.eql(u8, subcommand, name)) return true;
return false;
}
test "classify protects actual writes across command boundaries and shell wrappers" {
- try std.testing.expectEqual(Kind.commit, classify("git -C repo add -A").?);
+ try std.testing.expect(classify("git -C repo add -A") == null);
+ try std.testing.expectEqual(Kind.commit, classify("git -C repo commit -m wip").?);
+ try std.testing.expectEqualStrings("repo", gitWorkDir("git -C repo commit -m wip").?);
try std.testing.expectEqual(Kind.publication, classify("cd repo && git push origin HEAD").?);
try std.testing.expectEqual(Kind.pull_request, classify("env gh -R owner/repo pr create --title x").?);
try std.testing.expectEqual(Kind.pull_request, classify("bash -lc 'gh pr ready 42'").?);
diff --git a/src/publish_gate.zig b/src/publish_gate.zig
index d6737ce2..0861144e 100644
--- a/src/publish_gate.zig
+++ b/src/publish_gate.zig
@@ -73,8 +73,9 @@ pub fn bash(self: *Agent, cmd: []const u8) !?ExecResult {
fn mutationKey(self: *Agent, cmd: []const u8) []const u8 {
if (!artifact_claim.isClaimedMutation(cmd)) return "";
- // Unknown shell forms do not establish a comparable branch target.
- if (std.mem.indexOfAny(u8, cmd, ";|&`$\n\"'\\*?{}") != null or
+ // Interpolation and globbing do not establish a comparable branch target.
+ // Compound `;&|` still resolves via cwd or `git -C` (#1014).
+ if (std.mem.indexOfAny(u8, cmd, "`$\"'\\*?{}") != null or
std.mem.indexOf(u8, cmd, " -R") != null or std.mem.indexOf(u8, cmd, " --repo") != null) return "";
const ev = @import("pr_evidence.zig");
const c = @import("pr_command.zig").parse(self.arena, cmd) catch null;
@@ -82,7 +83,8 @@ fn mutationKey(self: *Agent, cmd: []const u8) []const u8 {
if (command.flag("--head", "-H")) |head| return head;
if (!std.mem.eql(u8, command.verb, "create") and command.selector() != null) return "";
}
- const cwd = if (c) |command| command.cwd orelse self.agent_cwd orelse "." else self.agent_cwd orelse ".";
+ const git_c = @import("artifact_claim_command.zig").gitWorkDir(cmd);
+ const cwd = git_c orelse if (c) |command| command.cwd orelse self.agent_cwd orelse "." else self.agent_cwd orelse ".";
return ev.capture(self.gpa, self.io, self.arena, .{ .cwd = cwd, .selector = "" }, &.{ "git", "branch", "--show-current" }) catch "";
}