Skip to content

Commit 66ab313

Browse files
authored
fix(executor): append newline when shell command stdout lacks trailing newline (#2979)
1 parent 37b5e39 commit 66ab313

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

crates/forge_infra/src/executor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,21 @@ impl ForgeCommandExecutorService {
117117
} else {
118118
let stdout_writer = OutputPrinterWriter::stdout(self.output_printer.clone());
119119
let stderr_writer = OutputPrinterWriter::stderr(self.output_printer.clone());
120-
tokio::try_join!(
120+
let result = tokio::try_join!(
121121
child.wait(),
122122
stream(&mut stdout_pipe, stdout_writer),
123123
stream(&mut stderr_pipe, stderr_writer)
124-
)?
124+
)?;
125+
126+
// If the command's stdout did not end with a newline, the terminal
127+
// cursor is left mid-line. Write a newline so that subsequent output
128+
// (e.g. the LLM response) starts on a fresh line.
129+
if result.1.last() != Some(&b'\n') && !result.1.is_empty() {
130+
let _ = self.output_printer.write(b"\n");
131+
let _ = self.output_printer.flush();
132+
}
133+
134+
result
125135
};
126136

127137
// Drop happens after `try_join` due to <https://github.com/tokio-rs/tokio/issues/4309>

0 commit comments

Comments
 (0)