Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Improve command context labels in UI
Maximilian Roosd3f8077f3366
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rsindex 044b68652..add5bb8cd 100644--- a/src/commands/command_approval.rs+++ b/src/commands/command_approval.rs@@ -33,7 +33,7 @@ pub fn approve_command_batch(let approved = if force {true} else {- prompt_for_batch_approval(&needs_approval, project_id)?+ prompt_for_batch_approval(&needs_approval, project_id, context)?};if !approved {@@ -72,7 +72,11 @@ fn log_approval_warning(message: &str, error: impl std::fmt::Display) {println!("{WARNING_EMOJI} {WARNING}{message}: {error}{WARNING:#}");}-fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io::Result<bool> {+fn prompt_for_batch_approval(+ commands: &[&Command],+ project_id: &str,+ context: &str,+) -> std::io::Result<bool> {use std::io::{self, Write};let project_name = project_id.split('/').next_back().unwrap_or(project_id);@@ -87,10 +91,17 @@ fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io"{WARNING_EMOJI} {WARNING}Permission required to execute {warning_bold}{count}{warning_bold:#} command{plural}{WARNING:#}",);println!();+ println!("{bold}{project_name}{bold:#} ({dim}{project_id}{dim:#}) wants to execute:");+ println!();for cmd in commands {- println!("{bold}{project_name}{bold:#} ({dim}{project_id}{dim:#}) wants to execute:");- println!();+ // Format as: {context} {bold}{name}{bold:#}:+ // context is provided by caller in lowercase (e.g., "post-create", "pre-merge")+ let label = match &cmd.name {+ Some(name) => format!("{context} {bold}{name}{bold:#}:"),+ None => format!("{context}:"),+ };+ println!("{label}");print!("{}", format_bash_with_gutter(&cmd.expanded, ""));println!();}diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 221dd2952..96c07ece4 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -158,13 +158,7 @@ pub fn handle_merge(// Approve all commands in a single batch// Commands collected here are not yet expanded - expansion happens later in prepare_project_commands- approve_command_batch(- &all_commands,- &project_id,- &config,- force,- "Merge operation",- )?;+ approve_command_batch(&all_commands, &project_id, &config, force, "merge")?;// Handle uncommitted changes (skip if --no-commit) - track whether commit occurredlet committed = if !no_commit && repo.is_dirty()? {@@ -504,7 +498,7 @@ pub fn run_pre_merge_commands(&ctx,false,&[("target", target_branch)],- "Pre-merge commands",+ "pre-merge",)?;for prepared in commands {let label = crate::commands::format_command_label("pre-merge", prepared.name.as_deref());@@ -561,7 +555,7 @@ pub fn execute_post_merge_commands(&ctx,false,&[("target", target_branch)],- "Post-merge commands",+ "post-merge",)?;if commands.is_empty() {@@ -624,13 +618,8 @@ pub fn run_pre_commit_commands(vec![]};- let commands = prepare_project_commands(- pre_commit_config,- &ctx,- false,- &extra_vars,- "Pre-commit commands",- )?;+ let commands =+ prepare_project_commands(pre_commit_config, &ctx, false, &extra_vars, "pre-commit")?;if commands.is_empty() {return Ok(());diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex cb4397bcf..9033c00e3 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -452,8 +452,7 @@ pub fn execute_post_create_commands(let repo_root = repo.main_worktree_root()?;let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);- let commands =- prepare_project_commands(post_create_config, &ctx, false, &[], "Post-create commands")?;+ let commands = prepare_project_commands(post_create_config, &ctx, false, &[], "post-create")?;if commands.is_empty() {return Ok(());@@ -502,8 +501,7 @@ pub fn spawn_post_start_commands(let repo_root = repo.main_worktree_root()?;let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);- let commands =- prepare_project_commands(post_start_config, &ctx, false, &[], "Post-start commands")?;+ let commands = prepare_project_commands(post_start_config, &ctx, false, &[], "post-start")?;if commands.is_empty() {return Ok(());@@ -559,8 +557,7 @@ pub fn execute_post_start_commands_sequential(let repo_root = repo.main_worktree_root()?;let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);- let commands =- prepare_project_commands(post_start_config, &ctx, false, &[], "Post-start commands")?;+ let commands = prepare_project_commands(post_start_config, &ctx, false, &[], "post-start")?;if commands.is_empty() {return Ok(());diff --git a/src/config/mod.rs b/src/config/mod.rsindex 00d097eb6..9eef0026c 100644--- a/src/config/mod.rs+++ b/src/config/mod.rs@@ -275,8 +275,7 @@ impl<'de> Deserialize<'de> for CommandConfig {CommandConfigToml::Single(cmd) => vec![Command::new(None, cmd)],CommandConfigToml::Multiple(cmds) => cmds.into_iter()- .enumerate()- .map(|(i, template)| Command::new(Some((i + 1).to_string()), template))+ .map(|template| Command::new(None, template)).collect(),CommandConfigToml::Named(map) => {// IndexMap preserves insertion order from TOML@@ -879,14 +878,8 @@ mod tests {let cmd_config = config.post_create_command.unwrap();let commands = cmd_config.commands();assert_eq!(commands.len(), 2);- assert_eq!(- commands[0],- Command::new(Some("1".to_string()), "npm install".to_string())- );- assert_eq!(- commands[1],- Command::new(Some("2".to_string()), "npm test".to_string())- );+ assert_eq!(commands[0], Command::new(None, "npm install".to_string()));+ assert_eq!(commands[1], Command::new(None, "npm test".to_string()));}#[test]@@ -1000,12 +993,9 @@ task2 = "echo 'Task 2 running' > task2.txt"assert_eq!(commands.len(), 2);assert_eq!(commands[0],- Command::new(Some("1".to_string()), "cargo fmt -- --check".to_string())- );- assert_eq!(- commands[1],- Command::new(Some("2".to_string()), "cargo test".to_string())+ Command::new(None, "cargo fmt -- --check".to_string()));+ assert_eq!(commands[1], Command::new(None, "cargo test".to_string()));}#[test]diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rsindex 8430dc253..6c5bec974 100644--- a/tests/integration_tests/approval_ui.rs+++ b/tests/integration_tests/approval_ui.rs@@ -253,3 +253,30 @@ approved-commands = ["echo 'Second command'"]false,);}++#[test]+fn test_approval_named_commands() {+ let repo = TestRepo::new();+ repo.commit("Initial commit");++ let config_dir = repo.root_path().join(".config");+ fs::create_dir_all(&config_dir).expect("Failed to create .config dir");+ fs::write(+ config_dir.join("wt.toml"),+ r#"[post-create-command]+install = "echo 'Installing dependencies...'"+build = "echo 'Building project...'"+test = "echo 'Running tests...'"+"#,+ )+ .expect("Failed to write config");++ repo.commit("Add config");++ snapshot_approval(+ "approval_named_commands",+ &repo,+ &["--create", "test-named"],+ false,+ );+}diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snapindex cc6d34d4f..704874d9a 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap@@ -2,12 +2,12 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()----π [36mRunning post-create: [1m1[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Installing dependencies...'[0m[0mInstalling dependencies...-π [36mRunning post-create: [1m2[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Building project...'[0m[0mBuilding project...diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snapindex 3f048aa63..96327de94 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap@@ -4,11 +4,11 @@ expression: output.normalized()---Installing dependencies...Building project...-π [36mRunning post-create: [1m1[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Installing dependencies...'[0m[0m-π [36mRunning post-create: [1m2[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Building project...'[0m[0mdiff --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 260bb3868..44e8f6b39 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@@ -9,14 +9,14 @@ exit_code: 0[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:+post-create:[40m [0m [1m[34mecho[0m [32m'First command'[0m[0m-[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:-+post-create:[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m-[2mPost-create commands declined[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 shelldiff --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 1f1bdbe7a..6ceb27503 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@@ -9,22 +9,20 @@ exit_code: 0[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:+post-create:[40m [0m [1m[34mecho[0m [32m'Branch: test-nested-branch'[0m[0m-[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:-+post-create:[40m [0m [1m[34mecho[0m [32m'Worktree: [REPO].test-nested-branch'[0m[0m-[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:-+post-create:[40m [0m [1m[34mecho[0m [32m'Repo: test-repo'[0m[0m-[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:-+post-create:[40m [0m [1m[34mcd[0m [REPO].test-nested-branch [36m&&[0m [1m[34mpwd[0m[0m-[2mPost-create commands declined[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 shelldiff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snapnew file mode 100644index 000000000..a628ef7f1--- /dev/null+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap@@ -0,0 +1,28 @@+---+source: tests/integration_tests/approval_ui.rs+expression: combined+---+exit_code: 0+----- stdout -----++π‘ [33mPermission required to execute [1m[33m3[0m commands[0m++[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:++post-create [1minstall[0m:+[40m [0m [1m[34mecho[0m [32m'Installing dependencies...'[0m[0m++post-create [1mbuild[0m:+[40m [0m [1m[34mecho[0m [32m'Building project...'[0m[0m++post-create [1mtest[0m:+[40m [0m [1m[34mecho[0m [32m'Running tests...'[0m[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[0m++To 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 87f3be190..567b7bc20 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@@ -9,10 +9,11 @@ exit_code: 0[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:+post-create:[40m [0m [1m[34mecho[0m [32m'Worktree path: [REPO].feature-test-approval'[0m[0m-[2mPost-create commands declined[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 shelldiff --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 06eaa11fe..ce98ad141 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@@ -9,14 +9,14 @@ exit_code: 0[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:+post-create:[40m [0m [1m[34mecho[0m [32m'First command'[0m[0m-[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:-+post-create:[40m [0m [1m[34mecho[0m [32m'Third command'[0m[0m-[2mPost-create commands declined[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 shelldiff --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 90b08af90..d1d3c0c8d 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@@ -9,10 +9,11 @@ exit_code: 0[1mtest-repo[0m ([2mtest-repo[0m) wants to execute:+post-create:[40m [0m [1m[34mecho[0m [32m'test command'[0m [36m>[0m output.txt[0m-[2mPost-create commands declined[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 shelldiff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snapindex a609d18ab..e77d9f446 100644--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap@@ -17,15 +17,15 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqTsQ2h/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp3fiKSk/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mRunning post-create: [1m1[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'First'[0m[0m-π [36mRunning post-create: [1m2[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Second'[0m[0mβ [32mCreated new worktree for [1m[32mfeature[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].feature[0m[0mdiff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snapindex ed55d9c9a..34f89ae54 100644--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap@@ -17,21 +17,21 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpI8VcDn/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpEHiur6/test-config.toml---success: trueexit_code: 0----- stdout ------π [36mRunning post-create: [1m1[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Repo: test-repo'[0m [36m>[0m info.txt[0m-π [36mRunning post-create: [1m2[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Branch: feature-test'[0m [36m>>[0m info.txt[0m-π [36mRunning post-create: [1m3[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Worktree: [REPO].feature-test'[0m [36m>>[0m info.txt[0m-π [36mRunning post-create: [1m4[0m[0m+π [36mRunning post-create:[0m[40m [0m [1m[34mecho[0m [32m'Root: [REPO]'[0m [36m>>[0m info.txt[0mβ [32mCreated new worktree for [1m[32mfeature/test[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].feature-test[0m[0m