Skip to content

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

Add --show-prompt flag to step and squash commands

Maximilian Roos05b969c20527
diff --git a/src/git/error.rs b/src/git/error.rs
index 0ffa5b7a4..ebb0ad900 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -121,6 +121,8 @@ pub enum GitError {
LlmCommandFailed {
command: String,
error: String,
+ /// Full command to reproduce the failure, e.g., "wt step commit --show-prompt | llm"
+ reproduction_command: Option<String>,
},
ProjectConfigNotFound {
config_path: PathBuf,
@@ -447,10 +449,16 @@ impl std::fmt::Display for GitError {
}
}
- GitError::LlmCommandFailed { command, error } => {
+ GitError::LlmCommandFailed {
+ command,
+ error,
+ reproduction_command,
+ } => {
let error_header = error_message("Commit generation command failed");
let error_block = format_error_block(error_header, error);
- let command_gutter = format_with_gutter(command, "", None);
+ // Show full pipeline command if available, otherwise just the LLM command
+ let display_command = reproduction_command.as_ref().unwrap_or(command);
+ let command_gutter = format_with_gutter(display_command, "", None);
write!(
f,
"{}\n\n{}\n{}",
diff --git a/src/llm.rs b/src/llm.rs
index 019f3badd..4e28389e8 100644
--- a/src/llm.rs
+++ b/src/llm.rs
@@ -433,10 +433,12 @@ pub fn generate_commit_message(
let command = commit_generation_config.command.as_ref().unwrap();
let args = &commit_generation_config.args;
// Commit generation is explicitly configured - fail if it doesn't work
+ let llm_command = format_command_display(command, args);
return try_generate_commit_message(command, args, commit_generation_config).map_err(|e| {
worktrunk::git::GitError::LlmCommandFailed {
- command: format_command_display(command, args),
+ command: llm_command.clone(),
error: e.to_string(),
+ reproduction_command: Some(format!("wt step commit --show-prompt | {llm_command}")),
}
.into()
});
@@ -550,10 +552,12 @@ pub fn generate_squash_message(
commit_generation_config,
)?;
+ let llm_command = format_command_display(command, args);
return execute_llm_command(command, args, &prompt).map_err(|e| {
worktrunk::git::GitError::LlmCommandFailed {
- command: format_command_display(command, args),
+ command: llm_command.clone(),
error: e.to_string(),
+ reproduction_command: Some(format!("wt step squash --show-prompt | {llm_command}")),
}
.into()
});
@@ -668,6 +672,7 @@ pub fn test_commit_generation(
worktrunk::git::GitError::LlmCommandFailed {
command: format_command_display(command, args),
error: e.to_string(),
+ reproduction_command: None, // Already a test command
}
.into()
})
diff --git a/tests/integration_tests/git_error_display.rs b/tests/integration_tests/git_error_display.rs
index d8cfb9d65..b608caf72 100644
--- a/tests/integration_tests/git_error_display.rs
+++ b/tests/integration_tests/git_error_display.rs
@@ -209,11 +209,23 @@ fn display_llm_command_failed() {
let err = GitError::LlmCommandFailed {
command: "llm --model claude".into(),
error: "Error: API key not found".into(),
+ reproduction_command: None,
};
assert_snapshot!("llm_command_failed", err.to_string());
}
+#[test]
+fn display_llm_command_failed_with_reproduction() {
+ let err = GitError::LlmCommandFailed {
+ command: "llm --model claude".into(),
+ error: "Error: API key not found".into(),
+ reproduction_command: Some("wt step commit --show-prompt | llm --model claude".into()),
+ };
+
+ assert_snapshot!("llm_command_failed_with_reproduction", err.to_string());
+}
+
#[test]
fn display_project_config_not_found() {
let err = GitError::ProjectConfigNotFound {
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__llm_command_failed_with_reproduction.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__llm_command_failed_with_reproduction.snap
new file mode 100644
index 000000000..5d36bac1a
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__llm_command_failed_with_reproduction.snap
@@ -0,0 +1,9 @@
+---
+source: tests/integration_tests/git_error_display.rs
+expression: err.to_string()
+---
+❌ Commit generation command failed
+  Error: API key not found
+
+⚪ Ran command:
+  wt step commit --show-prompt | llm --model claude
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap
index 5c9231ed7..8ee215862 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_command_not_found.snap
@@ -6,6 +6,7 @@ info:
- merge
- main
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,11 +14,15 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_COMMIT_GENERATION__COMMAND: nonexistent-llm-command
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: false
exit_code: 1
@@ -30,4 +35,4 @@ exit_code: 1
  Failed to spawn LLM command
⚪ Ran command:
-  nonexistent-llm-command
+  wt step squash --show-prompt | nonexistent-llm-command
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_error.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_error.snap
index a56999c67..709916070 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_error.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_error.snap
@@ -6,6 +6,7 @@ info:
- merge
- main
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,10 +14,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: false
exit_code: 1
@@ -29,4 +34,4 @@ exit_code: 1
  Error: connection refused
⚪ Ran command:
-  sh -c cat > /dev/null; echo 'Error: connection refused' >&2 && exit 1
+  wt step squash --show-prompt | sh -c cat > /dev/null; echo 'Error: connection refused' >&2 && exit 1