fix(agent): stream assistant text only in the REPL

Streaming defaulted on for every mode, so one-shot `--task` and script
runs interleaved intermediate assistant commentary into stdout, which
wrappers treat as the answer. Gate the stream hook on `Terminal.isRepl`
so non-interactive modes keep the buffered final answer.
This commit is contained in:
Adrià Arrufat
2026-07-12 22:09:48 +02:00
parent 5abae593d8
commit a64ced0ccc
2 changed files with 5 additions and 3 deletions

View File

@@ -604,9 +604,11 @@ fn endStreamedText(self: *Agent) void {
}
/// The text-delta hook, or null when `/stream off` — a null hook makes
/// `runTools` fall back to a buffered response.
/// `runTools` fall back to a buffered response. Streaming is an interactive
/// REPL affordance; one-shot (`--task`) and script modes keep stdout to the
/// buffered final answer so wrappers can parse it cleanly.
fn streamHook(self: *Agent) ?zenai.provider.Client.TextDeltaHook {
if (!self.stream_enabled) return null;
if (!self.stream_enabled or !self.terminal.isRepl()) return null;
return .{ .context = @ptrCast(self), .onText = streamAssistantDelta };
}

View File

@@ -186,7 +186,7 @@ pub fn init(allocator: std.mem.Allocator, history_paths: ?HistoryPaths, verbosit
};
}
fn isRepl(self: *const Terminal) bool {
pub fn isRepl(self: *const Terminal) bool {
return self.repl_arena != null;
}