Skip to content

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

Python

fix(tui): bind Ctrl+D to quit and stop leaking the presence registry path

Rach Pradhanb3b4463fa735
diff --git a/TUI/keys.zig b/TUI/keys.zig
index f5c88556..1436deb1 100644
--- a/TUI/keys.zig
+++ b/TUI/keys.zig
@@ -65,6 +65,7 @@ pub fn handle(self: *Model, k: Key) Effect {
return .stay;
}
+ if (isCtrl(k, 'd')) return ctrlD(self);
if (k == .escape) return esc(self);
if (isCtrl(k, 'p') or (isChar(k, '?') and std.mem.trim(u8, self.input.getValue(), " \t").len == 0)) {
self.openOverlay(.palette);
@@ -310,6 +311,14 @@ fn esc(self: *Model) Effect {
return .stay;
}
+/// The line REPL advertises "ctrl-d quits" but the fullscreen TUI swallowed it
+/// silently (#549). Empty composer quits, exactly like Ctrl+Q; with a draft in
+/// hand it stays ignored, so a stray ^D can never throw work away.
+fn ctrlD(self: *Model) Effect {
+ if (std.mem.trim(u8, self.input.getValue(), " \t\r\n").len > 0) return .stay;
+ return .quit;
+}
+
fn ctrlC(self: *Model) Effect {
if (self.bg) |op| {
if (!op.cancelled) {
@@ -365,6 +374,19 @@ test "Ctrl+C quits when idle" {
try std.testing.expectEqualStrings("ab", m.input.getValue());
}
+test "Ctrl+D quits an empty composer and is ignored with a draft (#549)" {
+ var m: Model = undefined;
+ m.setup(std.testing.allocator);
+ defer m.deinit();
+ try m.input.setValue("half a thought");
+ try std.testing.expectEqual(Effect.stay, handle(&m, .{ .ctrl = 'd' }));
+ try std.testing.expectEqualStrings("half a thought", m.input.getValue());
+ try m.input.setValue(" ");
+ try std.testing.expectEqual(Effect.quit, handle(&m, .{ .ctrl = 'd' }));
+ try m.input.setValue("");
+ try std.testing.expectEqual(Effect.quit, handle(&m, .{ .ctrl = 'd' }));
+}
+
test "Tab toggles focus" {
var m: Model = undefined;
m.setup(std.testing.allocator);
diff --git a/src/presence.zig b/src/presence.zig
index 8ecdf396..21533dd2 100644
--- a/src/presence.zig
+++ b/src/presence.zig
@@ -245,6 +245,8 @@ pub fn announce(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, sess
if (builtin.is_test) return null; // tests get the parameterized store, never the real registry
if (home.len == 0) return null;
const dir_path = std.fmt.allocPrint(gpa, "{s}/{s}", .{ home, registry_subdir }) catch return null;
+ var dir_owned = true; // deinit frees only what the globals point at, so every bail before `g_dir` is set owns dir_path — it used to leak (#549)
+ defer if (dir_owned) gpa.free(dir_path);
Io.Dir.cwd().createDirPath(io, dir_path) catch return null;
const identity = worktree_lease.currentIdentity(gpa, io, arena);
if (identity.id.len == 0) return null;
@@ -252,6 +254,7 @@ pub fn announce(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, sess
var name_buf: [64]u8 = undefined;
const name = std.fmt.bufPrint(&name_buf, "{d}-{x}.json", .{ self.pid, self.start_id }) catch return null;
g_dir = dir_path;
+ dir_owned = false;
g_identity = gpa.dupe(u8, identity.id) catch return null;
g_session = gpa.dupe(u8, session_id) catch "";
g_goal = gpa.dupe(u8, goal) catch "";