From 9ced0ed79a207319220f6d5279c23e8a30a710b0 Mon Sep 17 00:00:00 2001 From: Tushar Date: Mon, 13 Apr 2026 11:44:34 +0530 Subject: [PATCH] fix(executor): append newline when shell command output lacks trailing newline --- crates/forge_infra/src/executor.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/forge_infra/src/executor.rs b/crates/forge_infra/src/executor.rs index 13f30d8c8d..c8683a706d 100644 --- a/crates/forge_infra/src/executor.rs +++ b/crates/forge_infra/src/executor.rs @@ -117,11 +117,21 @@ impl ForgeCommandExecutorService { } else { let stdout_writer = OutputPrinterWriter::stdout(self.output_printer.clone()); let stderr_writer = OutputPrinterWriter::stderr(self.output_printer.clone()); - tokio::try_join!( + let result = tokio::try_join!( child.wait(), stream(&mut stdout_pipe, stdout_writer), stream(&mut stderr_pipe, stderr_writer) - )? + )?; + + // If the command's stdout did not end with a newline, the terminal + // cursor is left mid-line. Write a newline so that subsequent output + // (e.g. the LLM response) starts on a fresh line. + if result.1.last() != Some(&b'\n') && !result.1.is_empty() { + let _ = self.output_printer.write(b"\n"); + let _ = self.output_printer.flush(); + } + + result }; // Drop happens after `try_join` due to