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.mdindex 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 stderrlet 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.rsindex 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.snapindex 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:[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mtest-mixed[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].test-mixed[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0mdiff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snapindex 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:[40m [0m [1m[34mcd[0m [REPO].test-nested-branch [36m&&[0m [1m[34mpwd[0m[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mtest/nested-branch[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].test-nested-branch[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0mdiff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snapindex 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 [1mbuild[0m:post-create [1mtest[0m:[40m [0m [1m[34mecho[0m [32m'Running tests...'[0m[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mtest-named[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].test-named[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0mdiff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snapindex 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: 0post-create:[40m [0m [1m[34mecho[0m [32m'Worktree path: [REPO].feature-test-approval'[0m[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mfeature/test-approval[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].feature-test-approval[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0mdiff --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.snapindex 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:[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mtest-decline[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].test-decline[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0mdiff --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.snapindex 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: 0post-create:[40m [0m [1m[34mecho[0m [32m'test command'[0m [36m>[0m output.txt[0m-+💡 Allow and remember? [1m[y/N][0m[2mpost-create declined[0m✅ [32mCreated new worktree for [1m[32mtest-force-2[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].test-force-2[0m[0mTo enable automatic cd, run: wt config shell----- stderr ------💡 Allow and remember? [1m[y/N][0m