Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Direct interactive prompts to stdout

Maximilian Roos68463d5e1190
diff --git a/CLAUDE.md b/CLAUDE.md
index a432fe05c..5daf4d89e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -91,14 +91,29 @@ Five canonical message patterns with their emojis:
**Why:** Simple reasoning (one decision point), better for piping (`wt list | jq`), child output never interferes with directives. Trade-off: violates Unix convention of errors→stderr, but our "errors" are structured program output, not crashes.
```rust
-// ALL our output goes to stdout (including errors)
+// ALL our output goes to stdout (including errors and interactive prompts)
println!("{ERROR_EMOJI} {ERROR}Branch already exists{ERROR:#}");
+// Interactive prompts are worktrunk output → stdout
+print!("{HINT_EMOJI} Allow and remember? [y/N] ");
+
// Redirect child processes to stderr
let wrapped = format!("{{ {}; }} 1>&2", command);
Command::new("sh").arg("-c").arg(&wrapped).status()?;
```
+**Interactive prompts and stdin:**
+- Prompts are worktrunk output → always use stdout
+- **CRITICAL**: Flush stdout before blocking on stdin to prevent interleaving:
+ ```rust
+ print!("💡 Allow and remember? [y/N] ");
+ stdout().flush()?; // Ensures prompt is visible before blocking
+
+ let mut response = String::new();
+ io::stdin().read_line(&mut response)?;
+ ```
+- Without flushing, buffered stdout can appear after the prompt is shown
+
### Temporal Locality: Output Should Be Close to Operations
**Core Principle: Output should appear immediately adjacent to the operations they describe.**
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index add5bb8cd..676da474c 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -5,8 +5,8 @@
use worktrunk::config::{Command, WorktrunkConfig};
use worktrunk::git::{GitError, GitResultExt};
use worktrunk::styling::{
- AnstyleStyle, HINT_EMOJI, WARNING, WARNING_EMOJI, eprint, format_bash_with_gutter, print,
- println, stderr,
+ AnstyleStyle, HINT_EMOJI, WARNING, WARNING_EMOJI, format_bash_with_gutter, print, println,
+ stdout,
};
/// Batch approval helper used when multiple commands are queued for execution.
@@ -106,8 +106,11 @@ fn prompt_for_batch_approval(
println!();
}
- eprint!("{HINT_EMOJI} Allow and remember? {bold}[y/N]{bold:#} ");
- stderr().flush()?;
+ // Flush stdout before showing prompt to ensure all output is visible
+ stdout().flush()?;
+
+ print!("{HINT_EMOJI} Allow and remember? {bold}[y/N]{bold:#} ");
+ stdout().flush()?;
let mut response = String::new();
io::stdin().read_line(&mut response)?;
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
index 44e8f6b39..a73aed600 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
@@ -15,11 +15,10 @@ post-create:
post-create:
  echo 'Third command'
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for test-mixed from main at [REPO].test-mixed
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
index 6ceb27503..ef014f1d3 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
@@ -21,11 +21,10 @@ post-create:
post-create:
  cd [REPO].test-nested-branch && pwd
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for test/nested-branch from main at [REPO].test-nested-branch
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap
index a628ef7f1..741bc332f 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap
@@ -18,11 +18,10 @@ post-create build:
post-create test:
  echo 'Running tests...'
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for test-named from main at [REPO].test-named
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
index 567b7bc20..171463857 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
@@ -12,11 +12,10 @@ exit_code: 0
post-create:
  echo 'Worktree path: [REPO].feature-test-approval'
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for feature/test-approval from main at [REPO].feature-test-approval
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
index ce98ad141..c9d774c95 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
@@ -15,11 +15,10 @@ post-create:
post-create:
  echo 'Third command'
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for test-decline from main at [REPO].test-decline
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
index d1d3c0c8d..2805bcf5c 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
@@ -12,11 +12,10 @@ exit_code: 0
post-create:
  echo 'test command' > output.txt
-
+💡 Allow and remember? [y/N]
post-create declined
✅ Created new worktree for test-force-2 from main at [REPO].test-force-2
To enable automatic cd, run: wt config shell
----- stderr -----
-💡 Allow and remember? [y/N]