graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Merge fix/tui-input-lane: debris-guard family + paste-latch recovery + keypad map
Rach Pradhanb3741c9dcbe3
diff --cc TUI/key.zigindex 35baf424,c8fb5198..1dd5af4b--- a/TUI/key.zig+++ b/TUI/key.zig@@@ -496,69 -540,7 +540,11 @@@ fn sgrMouse(params: []const u8, down: b} };}- const Orphan = union(enum) {- /// Not debris — hand the bytes to the normal parser (typed text).- none,- /// Debris shape, cut short by the read boundary: hold, do not type it.- partial,- took: Key,- };-- /// CSI debris after a lost ESC (`7444;9u`, `39;33;23M`, `<35;80;24M`). Never a- /// letter and never Escape/Ctrl-C — those cancel or kill the turn.- ///- /// Strictly shaped, because this runs against text a human may have typed: an- /// optional `<`, then digits with `;`/`:` separators, then a MOUSE or CSI-u- /// final (`M`/`m`/`u`/`~`). Any other terminator is text — accepting the whole- /// 0x40..0x7e range ate `0x1f` (final `x`), `[12]` (final `]`) and `1e5`- /// (final `e`). A run with neither `<` nor a separator (`3u`) is debris only- /// while `orphan_armed` says the loop really did drop a truncated sequence.- fn takeOrphanCsi(bytes: []const u8, i: *usize) Orphan {- const start = i.*;- if (start >= bytes.len) return .none;- var j = start;- const lt = bytes[j] == '<';- if (lt) j += 1;- if (j >= bytes.len or bytes[j] < '0' or bytes[j] > '9') return .none;- var sep = false;- var k = j;- while (k < bytes.len) : (k += 1) {- const c = bytes[k];- if (c >= '0' and c <= '9') continue;- if (c == ';' or c == ':') {- sep = true;- continue;- }- if (c == 'M' or c == 'm' or c == 'u' or c == '~') {- if (!lt and !sep and !orphan_armed) return .none;- i.* = k + 1;- if (c == 'M' or c == 'm') {- const body = bytes[j..k];- var it = std.mem.splitScalar(u8, body, ';');- const btn = leadingInt(it.next() orelse "0");- const x = leadingInt(it.next() orelse "1");- const y = leadingInt(it.next() orelse "1");- return .{ .took = .{ .mouse = .{- .btn = @intCast(@min(btn, 255)),- .x = @intCast(@min(x, 999)),- .y = @intCast(@min(y, 999)),- .down = c == 'M',- } } };- }- return .{ .took = .ignore };- }- return .none;- }- // Ran off the end mid-fragment. Hold it when it already reads as a CSI- // parameter list, or when the loop armed us; a bare unarmed digit run is- // somebody typing, and holding it would strand the keystrokes.- return if (lt or sep or orphan_armed) .partial else .none;- }-- fn leadingInt(s: []const u8) u32 {+ pub fn leadingInt(s: []const u8) u32 {+ // Saturating (#545): params come raw off stdin, and a 10+-digit run —+ // hostile or corrupt input, never a real key — overflowed u32 and aborted+ // the whole TUI. maxInt decodes as .ignore / clamped coords everywhere.++ // pub: key_orphan.zig (the extracted debris sweeper) parses with it too.var n: u32 = 0;for (s) |c| {if (c < '0' or c > '9') break;