graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(tui): Shift+9 / Shift+0 type parentheses
Rach Pradhanee6d5377e89a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c97d86df..37193ddd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,8 @@ current is part of cutting a release.- Leftover Kitty keyboard CSI (`3u7444;9u`) is ignored instead of typed orturned into Escape/Ctrl+C (which cancelled the turn).+- Shift+number keys type the punctuation they should (`Shift+9` is `(`,+ `Shift+0` is `)`), including via Kitty CSI-u and modifyOtherKeys.- The pager appends raw stdin hex to `.graff/tui-traj.jsonl` and the lastvisible frame on exit so the next leak can be replayed.diff --git a/TUI/key.zig b/TUI/key.zigindex f2c8e1ca..5d2b00be 100644--- a/TUI/key.zig+++ b/TUI/key.zig@@ -166,14 +166,19 @@ fn csiMods(params: []const u8) u32 {return mods;}-/// CSI unicode ; mods u — kitty/ghostty. mods bit 2 = ctrl, 1 = shift.+/// CSI unicode[:shifted[:base]] ; mods[:event] ; text ufn kitty(params: []const u8) Key {- const code = leadingInt(params);+ var it = std.mem.splitScalar(u8, params, ';');+ const keys = it.next() orelse "";+ const code = leadingInt(keys);+ var shifted: u32 = 0;+ if (std.mem.indexOfScalar(u8, keys, ':')) |c| shifted = leadingInt(keys[c + 1 ..]);var mods: u32 = 0;- if (std.mem.indexOfScalar(u8, params, ';')) |s| {- mods = leadingInt(params[s + 1 ..]);- if (mods > 0) mods -= 1; // kitty encodes mods+1+ if (it.next()) |m| {+ mods = leadingInt(m);+ if (mods > 0) mods -= 1;}+ const text = leadingInt(it.next() orelse "");const ev = kittyEvent(params);if (code == 57444 or code == 57448) {if (ev == 3) held &= ~@as(u32, 8) else held |= 8;@@ -185,6 +190,9 @@ fn kitty(params: []const u8) Key {}if (code >= 57441 and code <= 57448) return .ignore;if (ev == 3) return .ignore;+ const shift = mods & 1 != 0;+ if (text >= 32 and text < 127) return mapCode(text, mods & ~@as(u32, 1));+ if (shift and shifted >= 32 and shifted < 127) return mapCode(shifted, mods & ~@as(u32, 1));return mapCode(code, mods);}@@ -222,11 +230,41 @@ fn mapCode(code: u32, mods: u32) Key {if ((ctrl or super) and !shift and (ch == 'z' or ch == 'Z')) return .undo;if (ctrl and ch >= 'a' and ch <= 'z') return .{ .ctrl = ch };if (ctrl and ch >= 'A' and ch <= 'Z') return .{ .ctrl = ch + 32 };+ if (shift) return .{ .char = shiftedAscii(ch) };return .{ .char = ch };}return .escape;}+/// Kitty/modifyOtherKeys report the unshifted key + Shift. US layout.+fn shiftedAscii(ch: u8) u8 {+ return switch (ch) {+ 'a'...'z' => ch - 32,+ '1' => '!',+ '2' => '@',+ '3' => '#',+ '4' => '$',+ '5' => '%',+ '6' => '^',+ '7' => '&',+ '8' => '*',+ '9' => '(',+ '0' => ')',+ '-' => '_',+ '=' => '+',+ '[' => '{',+ ']' => '}',+ '\\' => '|',+ ';' => ':',+ '\'' => '"',+ ',' => '<',+ '.' => '>',+ '/' => '?',+ '`' => '~',+ else => ch,+ };+}+fn sgrMouse(params: []const u8, down: bool) Key {if (params.len == 0 or params[0] != '<') return .escape;var it = std.mem.splitScalar(u8, params[1..], ';');@@ -388,3 +426,20 @@ test "orphan kitty CSI-u is ignore, never letters or Escape" {i = 0;try std.testing.expectEqual(Key{ .char = 'h' }, next("hi", &i).?);}++test "Shift+9 is open-paren, Shift+0 is close-paren" {+ var i: usize = 0;+ try std.testing.expectEqual(Key{ .char = '(' }, next("\x1b[57;2u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = ')' }, next("\x1b[48;2u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '(' }, next("\x1b[57:40;2u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '(' }, next("\x1b[57;2;40u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '!' }, next("\x1b[49;2u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = 'A' }, next("\x1b[97;2u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '(' }, next("\x1b[27;2;57~", &i).?);+}diff --git a/TUI/run.zig b/TUI/run.zigindex ecf66e83..6c4f81c4 100644--- a/TUI/run.zig+++ b/TUI/run.zig@@ -58,9 +58,9 @@ pub fn run(const w = &stdout.interface;// 1000/1006: click + wheel as 64/65. Not 1003h — motion floods leak as text.// 2004: bracketed paste. 7l: no autowrap into the prompt.- // >11u: kitty disambiguate + event types + all-keys (Cmd+Delete / Super latch).+ // >31u: kitty disambiguate + events + alternates + all-keys + text (Shift+9 is "(").// >4;2m: xterm modifyOtherKeys so Super+Backspace also arrives as CSI 27;9;127~.- w.writeAll("\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[?7l\x1b[>11u\x1b[>4;2m") catch {};+ w.writeAll("\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[?7l\x1b[>31u\x1b[>4;2m") catch {};w.flush() catch {};traj.open(io);defer {@@ -146,7 +146,7 @@ fn parkToShell(io: Io, w: *Io.Writer, raw: *tty.RawState) void {std.posix.raise(std.posix.SIG.TSTP) catch {};}raw.* = tty.enterRaw() orelse raw.*;- w.writeAll("\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[?7l\x1b[>11u\x1b[>4;2m") catch {};+ w.writeAll("\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[?7l\x1b[>31u\x1b[>4;2m") catch {};w.flush() catch {};_ = io;}@@ -218,7 +218,7 @@ test "run loop enables click tracking and bracketed paste" {const sgr_on = [_]u8{ '?', '1', '0', '0', '6', 'h' };const paste_on = [_]u8{ '?', '2', '0', '0', '4', 'h' };const hover_on = [_]u8{ '?', '1', '0', '0', '3', 'h' };- const kitty_on = [_]u8{ '>', '1', '1', 'u' };+ const kitty_on = [_]u8{ '>', '3', '1', 'u' };const wrap_off = [_]u8{ '?', '7', 'l' };try std.testing.expect(std.mem.indexOf(u8, src, &mouse_on) != null);try std.testing.expect(std.mem.indexOf(u8, src, &sgr_on) != null);diff --git a/docs/releases/v0.0.256.md b/docs/releases/v0.0.256.mdindex 525b205b..baa808bd 100644--- a/docs/releases/v0.0.256.md+++ b/docs/releases/v0.0.256.md@@ -8,5 +8,6 @@ killed the turn.ignore/mouse, never as letters.- TUI stdin is appended to `.graff/tui-traj.jsonl` (hex, rotated at 512KiB)and the last visible frame is written on exit.+- Shift+9 / Shift+0 type `(` / `)` (Kitty reports the unshifted key).Bare `graff` stays the line REPL. `graff tui` is the pager.diff --git a/src/cli.zig b/src/cli.zigindex c157d713..2e57ff03 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -22,7 +22,7 @@ pub const changelog_text =\\What's new\\──────────\\0.0.256- \\ • TUI swallows leftover Kitty CSI-u (3u7444;9u) and logs stdin to .graff/tui-traj.jsonl+ \\ • TUI swallows leftover Kitty CSI-u, types Shift+9 as (, logs stdin to .graff/tui-traj.jsonl\\\\0.0.255\\ • TUI no longer dumps mouse CSI (39;33;23M) into the thinking line