Skip to content

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

Soften explicit command approval prompts (#3953)

Maximilian Roos5895c41fe1a7
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 84016529b..c481ae97f 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -25,8 +25,8 @@ use color_print::cformat;
use worktrunk::config::{Approvals, require_approvals_path};
use worktrunk::git::{GitError, HookType};
use worktrunk::styling::{
- INFO_SYMBOL, WARNING_SYMBOL, eprint, eprintln, hint_message, prompt_message, stderr,
- warning_message,
+ INFO_SYMBOL, WARNING_SYMBOL, eprint, eprintln, format_heading, hint_message, prompt_message,
+ stderr, warning_message,
};
use super::hook_filter::{HookSource, ParsedFilter};
@@ -113,7 +113,7 @@ fn display_project_name(project_id: &str) -> &str {
/// The batch as the user sees it: a header, then each command's label and its
/// template. Shared by the prompt and by `--yes` on `wt config approvals add`.
-fn print_command_batch(header: &str, commands: &[&ApprovableCommand]) {
+fn print_command_batch(header: impl std::fmt::Display, commands: &[&ApprovableCommand]) {
eprintln!("{header}");
for cmd in commands {
// Uses INFO_SYMBOL (○) since this is a preview, not active execution
@@ -124,21 +124,24 @@ fn print_command_batch(header: &str, commands: &[&ApprovableCommand]) {
/// The batch `wt config approvals add --yes` is about to trust. Nothing is
/// being asked, but the batch still prints: it is the record of what an
-/// unattended run just approved. Lives beside [`prompt_for_batch_approval`]
+/// unattended run just approved. Lives beside [`prompt_for_batch_review`]
/// so the two headers stay parallel.
pub fn announce_batch_approval(commands: &[&ApprovableCommand], project_id: &str) {
let project_name = display_project_name(project_id);
let count = commands.len();
let plural = if count == 1 { "" } else { "s" };
print_command_batch(
- &cformat!(
- "{WARNING_SYMBOL} <yellow>Approving <bold>{count}</> command{plural} for <bold>{project_name}</> (--yes):</>"
+ format_heading(
+ &cformat!(
+ "Approving <bold>{count}</> command{plural} for <bold>{project_name}</> (--yes):"
+ ),
+ None,
),
commands,
);
}
-pub fn prompt_for_batch_approval(
+fn prompt_for_batch_approval(
commands: &[&ApprovableCommand],
project_id: &str,
) -> anyhow::Result<bool> {
@@ -146,12 +149,34 @@ pub fn prompt_for_batch_approval(
let count = commands.len();
let plural = if count == 1 { "" } else { "s" };
- print_command_batch(
- &cformat!(
- "{WARNING_SYMBOL} <yellow><bold>{project_name}</> needs approval to execute <bold>{count}</> command{plural}:</>"
- ),
- commands,
+ let header = cformat!(
+ "{WARNING_SYMBOL} <yellow><bold>{project_name}</> needs approval to execute <bold>{count}</> command{plural}:</>"
+ );
+ prompt_for_batch_approval_with_header(commands, header)
+}
+
+/// Prompt used by `wt config approvals add`, where reviewing approvals is the
+/// command's expected workflow rather than an interruption to another action.
+pub fn prompt_for_batch_review(
+ commands: &[&ApprovableCommand],
+ project_id: &str,
+) -> anyhow::Result<bool> {
+ let project_name = display_project_name(project_id);
+ let count = commands.len();
+ let plural = if count == 1 { "" } else { "s" };
+
+ let header = format_heading(
+ &cformat!("Review <bold>{count}</> command{plural} for <bold>{project_name}</>:"),
+ None,
);
+ prompt_for_batch_approval_with_header(commands, header)
+}
+
+fn prompt_for_batch_approval_with_header(
+ commands: &[&ApprovableCommand],
+ header: impl std::fmt::Display,
+) -> anyhow::Result<bool> {
+ print_command_batch(header, commands);
// Check if stdin is a TTY before attempting to prompt
// This happens AFTER showing the commands so they appear in CI/CD logs
diff --git a/src/commands/config/approvals.rs b/src/commands/config/approvals.rs
index 1c8b6b345..87bb09ce4 100644
--- a/src/commands/config/approvals.rs
+++ b/src/commands/config/approvals.rs
@@ -19,7 +19,7 @@ use worktrunk::styling::{
};
use crate::cli::SwitchFormat;
-use crate::commands::command_approval::{announce_batch_approval, prompt_for_batch_approval};
+use crate::commands::command_approval::{announce_batch_approval, prompt_for_batch_review};
use crate::commands::project_config::{
ApprovableCommand, collect_commands_for_aliases, collect_commands_for_hooks,
};
@@ -236,7 +236,7 @@ pub fn add_approvals(show_all: bool, yes: bool) -> anyhow::Result<()> {
announce_batch_approval(&batch, &project_id);
true
} else {
- prompt_for_batch_approval(&batch, &project_id)?
+ prompt_for_batch_review(&batch, &project_id)?
};
if !approved {
diff --git a/tests/snapshots/integration__integration_tests__approvals__add_approvals_all_none_approved.snap b/tests/snapshots/integration__integration_tests__approvals__add_approvals_all_none_approved.snap
index cfecaa6c8..dacff82d0 100644
--- a/tests/snapshots/integration__integration_tests__approvals__add_approvals_all_none_approved.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__add_approvals_all_none_approved.snap
@@ -61,7 +61,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-▲ origin needs approval to execute 1 command:
+Review 1 command for origin:
○ pre-start:
  echo 'test'
✗ Cannot prompt for approval in non-interactive environment
diff --git a/tests/snapshots/integration__integration_tests__approvals__add_approvals_bare_repo_config_in_primary_worktree.snap b/tests/snapshots/integration__integration_tests__approvals__add_approvals_bare_repo_config_in_primary_worktree.snap
index 964a96f7a..7405aa49c 100644
--- a/tests/snapshots/integration__integration_tests__approvals__add_approvals_bare_repo_config_in_primary_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__add_approvals_bare_repo_config_in_primary_worktree.snap
@@ -52,7 +52,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-▲ repo needs approval to execute 1 command:
+Review 1 command for repo:
○ pre-start:
echo 'hello'
✗ Cannot prompt for approval in non-interactive environment
diff --git a/tests/snapshots/integration__integration_tests__approvals__add_approvals_includes_aliases.snap b/tests/snapshots/integration__integration_tests__approvals__add_approvals_includes_aliases.snap
index de8be55f6..82092afc4 100644
--- a/tests/snapshots/integration__integration_tests__approvals__add_approvals_includes_aliases.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__add_approvals_includes_aliases.snap
@@ -60,7 +60,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-▲ origin needs approval to execute 1 command:
+Review 1 command for origin:
○ alias deploy:
  echo deploying {{ branch }}
✗ Cannot prompt for approval in non-interactive environment
diff --git a/tests/snapshots/integration__integration_tests__approvals__add_approvals_yes.snap b/tests/snapshots/integration__integration_tests__approvals__add_approvals_yes.snap
index 357ea650d..8171a83b5 100644
--- a/tests/snapshots/integration__integration_tests__approvals__add_approvals_yes.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__add_approvals_yes.snap
@@ -61,7 +61,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ Approving 2 commands for repo (--yes):
+Approving 2 commands for repo (--yes):
○ pre-merge:
  cargo test
○ alias deploy: