graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
refactor(repl): split ReplStreamSink into its own module
Rach Pradhanfb3e1fc399cd
diff --git a/src/repl_glue.zig b/src/repl_glue.zigindex 6f866240..9fe78270 100644--- a/src/repl_glue.zig+++ b/src/repl_glue.zig@@ -55,38 +55,8 @@ pub const ReplCtx = struct {tools_responses: []const u8,};-/// A thread-safe sink the worker writes the agent's output to and the repl's-/// render loop polls — this is what makes `graff repl` stream live. Custom-/// Io.Writer whose drain appends (under the StreamBuf mutex) to the repl buffer.-pub const ReplStreamSink = struct {- target: *repl.StreamBuf,- buf: [4096]u8 = undefined,- writer: Io.Writer = undefined,-- const vtable: Io.Writer.VTable = .{ .drain = drain };-- pub fn init(self: *ReplStreamSink, target: *repl.StreamBuf) void {- self.target = target;- self.writer = .{ .vtable = &vtable, .buffer = &self.buf, .end = 0 };- }-- fn drain(w: *Io.Writer, data: []const []const u8, splat: usize) Io.Writer.Error!usize {- const self: *ReplStreamSink = @alignCast(@fieldParentPtr("writer", w));- self.target.appendBytes(w.buffer[0..w.end]);- w.end = 0;- const slices = data[0 .. data.len - 1];- const pattern = data[data.len - 1];- var written: usize = 0;- for (slices) |b| {- self.target.appendBytes(b);- written += b.len;- }- var i: usize = 0;- while (i < splat) : (i += 1) self.target.appendBytes(pattern);- written += pattern.len * splat;- return written;- }-};+/// The live-pane writer, in repl_stream_sink.zig (move+alias, #123).+pub const ReplStreamSink = @import("repl_stream_sink.zig").ReplStreamSink;/// The standing-goal steering note for a turn when /goal is set. The checklist/// itself is deliberately NOT embedded (#318): the model sees it in todo_writediff --git a/src/repl_stream_sink.zig b/src/repl_stream_sink.zignew file mode 100644index 00000000..6c56b990--- /dev/null+++ b/src/repl_stream_sink.zig@@ -0,0 +1,41 @@+//! The turn writer that publishes into a REPL/TUI live pane. Split out of+//! repl_glue.zig (the move+alias pattern from #123) when the typed-event sink+//! landed there.++const std = @import("std");+const Io = std.Io;++const repl = @import("repl.zig");++/// A thread-safe sink the worker writes the agent's output to and the repl's+/// render loop polls — this is what makes `graff repl` stream live. Custom+/// Io.Writer whose drain appends (under the StreamBuf mutex) to the repl buffer.+pub const ReplStreamSink = struct {+ target: *repl.StreamBuf,+ buf: [4096]u8 = undefined,+ writer: Io.Writer = undefined,++ const vtable: Io.Writer.VTable = .{ .drain = drain };++ pub fn init(self: *ReplStreamSink, target: *repl.StreamBuf) void {+ self.target = target;+ self.writer = .{ .vtable = &vtable, .buffer = &self.buf, .end = 0 };+ }++ fn drain(w: *Io.Writer, data: []const []const u8, splat: usize) Io.Writer.Error!usize {+ const self: *ReplStreamSink = @alignCast(@fieldParentPtr("writer", w));+ self.target.appendBytes(w.buffer[0..w.end]);+ w.end = 0;+ const slices = data[0 .. data.len - 1];+ const pattern = data[data.len - 1];+ var written: usize = 0;+ for (slices) |b| {+ self.target.appendBytes(b);+ written += b.len;+ }+ var i: usize = 0;+ while (i < splat) : (i += 1) self.target.appendBytes(pattern);+ written += pattern.len * splat;+ return written;+ }+};