Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Ensure stderr is NUL-terminated in directive output
Maximilian Roos460ed4675f54
diff --git a/src/output/directive.rs b/src/output/directive.rsindex 59ef43db7..b431b9362 100644--- a/src/output/directive.rs+++ b/src/output/directive.rs@@ -15,24 +15,39 @@ impl DirectiveOutput {}pub fn success(&mut self, message: String) -> io::Result<()> {+ // Ensure any prior stderr output is NUL-terminated before writing to stdout+ write!(io::stderr(), "\0")?;+ io::stderr().flush()?;+let plain = strip_str(&message).to_string();write!(io::stdout(), "{}\0", plain)?;io::stdout().flush()}pub fn change_directory(&mut self, path: &Path) -> io::Result<()> {+ // Ensure any prior stderr output is NUL-terminated before writing directive+ // The shell wrapper merges stderr+stdout via 2>&1 and splits on NUL bytes,+ // so we need to terminate stderr to prevent it from concatenating with directives+ write!(io::stderr(), "\0")?;+ io::stderr().flush()?;+write!(io::stdout(), "__WORKTRUNK_CD__{}\0", path.display())?;io::stdout().flush()}pub fn execute(&mut self, command: String) -> io::Result<()> {+ // Ensure any prior stderr output is NUL-terminated before writing directive+ write!(io::stderr(), "\0")?;+ io::stderr().flush()?;+write!(io::stdout(), "__WORKTRUNK_EXEC__{}\0", command)?;io::stdout().flush()}pub fn flush(&mut self) -> io::Result<()> {writeln!(io::stdout())?;- io::stdout().flush()+ io::stdout().flush()?;+ io::stderr().flush()}pub fn is_interactive(&self) -> bool {diff --git a/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snap b/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snapindex a1f59d37f..ddee76395 100644Binary files a/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snap and b/tests/snapshots/integration__integration_tests__directives__merge_internal_keep.snap differdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snapindex a5923067b..a6302c4bb 100644Binary files a/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap and b/tests/snapshots/integration__integration_tests__remove__remove_internal_mode.snap differdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap b/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snapindex 9a04d0d8d..1637ba8b5 100644Binary files a/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap and b/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap differdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snapindex 89c86a9e8..036637d04 100644Binary files a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap and b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap differdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap b/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snapindex d49dcd411..3bc4254d9 100644Binary files a/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap and b/tests/snapshots/integration__integration_tests__switch__switch_internal_with_execute.snap differ