Skip to content

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

Python

fix: distinguish clipboard spawn, helper-exit, and cancel

Cursor Agentc608d36a64fe
diff --git a/src/clipboard_failure_tests.zig b/src/clipboard_failure_tests.zig
index e698870d..e8ce835f 100644
--- a/src/clipboard_failure_tests.zig
+++ b/src/clipboard_failure_tests.zig
@@ -73,10 +73,11 @@ fn check(comptime replies: []const Reply, expected: clip.GrabAttempt) !void {
switch (expected) {
.failed => |kind| {
try std.testing.expectEqual(kind, got.failed);
- if (kind == .access or kind == .unavailable) {
+ if (kind == .access or kind == .unavailable or kind == .spawn or kind == .cancelled) {
const message = paste.pasteMessage(.{ .failed = got.failed });
try std.testing.expect(std.mem.indexOf(u8, message, "Automation") == null);
try std.testing.expect(std.mem.indexOf(u8, message, "synthetic helper error") == null);
+ try std.testing.expect(std.mem.indexOf(u8, message, "Edit > Paste") == null);
}
},
.empty => {},
@@ -92,8 +93,8 @@ fn check(comptime replies: []const Reply, expected: clip.GrabAttempt) !void {
}
}
-test "#883 missing clipboard executable is unavailable" {
- try check(&.{.{ .missing = true }}, .{ .failed = .unavailable });
+test "#1146 missing clipboard executable is a spawn failure" {
+ try check(&.{.{ .missing = true }}, .{ .failed = .spawn });
}
test "#883 clipboard timeout takes precedence over helper reply" {
@@ -142,7 +143,7 @@ test "#883 clipboard retry cannot accept stale output" {
test "#883 truncated denial and cancellation never imply permission failure" {
try check(&.{.{ .exit_code = 1, .stderr = "error (-1743)", .stderr_truncated = true }}, .{ .failed = .unavailable });
- try check(&.{.{ .stdout = "ok:png", .cancelled = true, .file = clip.png_magic }}, .{ .failed = .unavailable });
+ try check(&.{.{ .stdout = "ok:png", .cancelled = true, .file = clip.png_magic }}, .{ .failed = .cancelled });
}
test "#883 empty clipboard removes partial file" {
diff --git a/src/clipboard_native.zig b/src/clipboard_native.zig
index e0196b6a..648992f6 100644
--- a/src/clipboard_native.zig
+++ b/src/clipboard_native.zig
@@ -33,8 +33,8 @@ pub fn grabWithRunner(io: std.Io, gpa: std.mem.Allocator, board: []const u8, pat
// can take time to materialize, but cannot block a paste indefinitely.
for (0..2) |_| {
const r = run(gpa, io, &.{ "/usr/bin/osascript", "-l", "JavaScript", "-e", script, path, board }, 64, 1024, 5000) catch |err| return .{ .failed = switch (err) {
- error.FileNotFound, error.AccessDenied => .unavailable,
- else => .unavailable,
+ error.FileNotFound, error.AccessDenied => .spawn,
+ else => .spawn,
} };
defer gpa.free(r.stdout);
defer gpa.free(r.stderr);
diff --git a/src/clipboard_result.zig b/src/clipboard_result.zig
index 556edd8d..18b581c5 100644
--- a/src/clipboard_result.zig
+++ b/src/clipboard_result.zig
@@ -14,7 +14,7 @@ pub const Result = union(enum) {
pub fn classify(r: runner.CappedRun) Result {
if (r.timed_out) return .{ .failed = .timeout };
- if (r.cancelled) return .{ .failed = .unavailable };
+ if (r.cancelled) return .{ .failed = .cancelled };
if (!runner.ranOk(r)) {
// Only the system's explicit Apple Event denial code warrants a
// permission category. Never show raw stderr (it may contain paths).
@@ -33,3 +33,39 @@ pub fn classify(r: runner.CappedRun) Result {
}
return .{ .failed = .extract };
}
+
+test "#1146 helper-exit and cancel stay distinct" {
+ var empty: [0]u8 = .{};
+ var helper = "helper crashed".*;
+ var denied = "err (-1743)".*;
+ const cancel = classify(.{
+ .term = .{ .exited = 0 },
+ .stdout = &empty,
+ .stderr = &empty,
+ .stdout_truncated = false,
+ .stderr_truncated = false,
+ .timed_out = false,
+ .cancelled = true,
+ });
+ const helper_exit = classify(.{
+ .term = .{ .exited = 1 },
+ .stdout = &empty,
+ .stderr = &helper,
+ .stdout_truncated = false,
+ .stderr_truncated = false,
+ .timed_out = false,
+ .cancelled = false,
+ });
+ const apple = classify(.{
+ .term = .{ .exited = 1 },
+ .stdout = &empty,
+ .stderr = &denied,
+ .stdout_truncated = false,
+ .stderr_truncated = false,
+ .timed_out = false,
+ .cancelled = false,
+ });
+ try std.testing.expectEqual(clip.FailKind.cancelled, cancel.failed);
+ try std.testing.expectEqual(clip.FailKind.unavailable, helper_exit.failed);
+ try std.testing.expectEqual(clip.FailKind.denied, apple.failed);
+}
diff --git a/src/process_runner.zig b/src/process_runner.zig
index bd7fe592..bc39aee0 100644
--- a/src/process_runner.zig
+++ b/src/process_runner.zig
@@ -109,7 +109,7 @@ pub const CappedRunOptions = struct {
pulse_first_ms: u64 = tool_pulse.first_silence_ms,
pulse_interval_ms: u64 = tool_pulse.silence_interval_ms,
/// Clipboard export is not a user turn. Esc would kill osascript and
- /// Ctrl-V would report `clipboard helper unavailable` (#1146).
+ /// Ctrl-V would report a cancelled clipboard read (#1146).
ignore_cancel: bool = false,
};
diff --git a/src/vision_clipboard.zig b/src/vision_clipboard.zig
index de1a3a58..204e559e 100644
--- a/src/vision_clipboard.zig
+++ b/src/vision_clipboard.zig
@@ -53,7 +53,7 @@ pub const Flavor = enum {
/// Why a clipboard extraction failed without yielding an image (#843).
/// Categories stay privacy-safe: they never include clipboard contents.
-pub const FailKind = enum { access, denied, unavailable, timeout, changed, extract, convert };
+pub const FailKind = enum { access, denied, unavailable, spawn, cancelled, timeout, changed, extract, convert };
/// Result of one pasteboard grab. Null used to mean both "nothing there"
/// and "osascript/sips failed", which Ctrl-V then reported as an empty
diff --git a/src/vision_paste.zig b/src/vision_paste.zig
index 7e3d4b36..63a6c0c0 100644
--- a/src/vision_paste.zig
+++ b/src/vision_paste.zig
@@ -43,9 +43,11 @@ pub fn clipboardPasteSource(io: Io, gpa: Allocator, supports_vision: bool, is_ma
pub fn pasteFailMessage(kind: FailKind) []const u8 {
return switch (kind) {
- .access => "clipboard read failed — retry Copy; use Edit > Paste for text or /image <path>",
- .denied => "macOS denied clipboard access — use Edit > Paste for text or /image <path>",
- .unavailable => "clipboard helper unavailable — use Edit > Paste for text or /image <path>",
+ .access => "clipboard read failed — retry Copy, or save it and use /image <path>",
+ .denied => "macOS denied clipboard access — grant permission, or save it and use /image <path>",
+ .unavailable => "clipboard helper failed — use /image <path>",
+ .spawn => "image paste needs the system osascript helper — use /image <path>",
+ .cancelled => "clipboard read was cancelled — try again, or use /image <path>",
.timeout => "clipboard read timed out — copy again, or save it and use /image <path>",
.changed => "clipboard changed while reading — copy again and retry, or use /image <path>",
.extract => "the clipboard image could not be exported — try Copy again, or save it and /image <path>",
@@ -109,6 +111,8 @@ test "pasteMessage: empty clipboard and extraction failure are distinct (#843)"
.{ .failed = .access },
.{ .failed = .denied },
.{ .failed = .unavailable },
+ .{ .failed = .spawn },
+ .{ .failed = .cancelled },
.{ .failed = .timeout },
.{ .failed = .changed },
.{ .failed = .extract },
@@ -121,4 +125,8 @@ test "pasteMessage: empty clipboard and extraction failure are distinct (#843)"
}
try std.testing.expectEqualStrings(no_vision_message, pasteMessage(.no_vision));
try std.testing.expectEqualStrings(pasteFailMessage(.extract), pasteMessage(.{ .failed = .extract }));
+ try std.testing.expectEqualStrings(pasteFailMessage(.spawn), pasteMessage(.{ .failed = .spawn }));
+ try std.testing.expect(std.mem.indexOf(u8, pasteFailMessage(.spawn), "osascript") != null);
+ try std.testing.expect(std.mem.indexOf(u8, pasteFailMessage(.unavailable), "Edit > Paste") == null);
+ try std.testing.expect(std.mem.indexOf(u8, pasteFailMessage(.cancelled), "Edit > Paste") == null);
}