Skip to content

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

Share LLM generation command handling across commit, squash, and diagnostics (#4553)

Maximilian Roos70b4082e5eb9
diff --git a/src/llm.rs b/src/llm.rs
index 9963bbc19..84b5c5c83 100644
--- a/src/llm.rs
+++ b/src/llm.rs
@@ -720,22 +720,7 @@ pub(crate) fn generate_commit_message(
// wrapper — mirroring `SquashInputs::generate_message`.
let prompt =
build_commit_prompt(commit_generation_config, wt, staging_index, project_append)?;
- // A slow or hung command is otherwise silent (stdout is captured); the
- // watchdog surfaces a "still waiting" status. Held until this function
- // returns, clearing the block before the caller prints the message.
- let _watchdog = watch_llm_command(command);
- // Commit generation is explicitly configured - fail if it doesn't work
- return execute_llm_command(command, &prompt).map_err(|e| {
- worktrunk::git::GitError::LlmCommandFailed {
- command: command.clone(),
- error: e.display_message(),
- reproduction_command: Some(format_reproduction_command(
- "wt step commit --show-prompt",
- command,
- )),
- }
- .into()
- });
+ return execute_generation_command(command, &prompt, Some("wt step commit --show-prompt"));
}
// Fallback: generate a descriptive commit message based on changed files
@@ -861,20 +846,11 @@ impl SquashInputs<'_> {
let command = self.config.command.as_ref().unwrap();
let prompt = self.prompt()?;
- // See `generate_commit_message` — keep a slow squash-message
- // generation from being silent.
- let _watchdog = watch_llm_command(command);
- return execute_llm_command(command, &prompt).map_err(|e| {
- worktrunk::git::GitError::LlmCommandFailed {
- command: command.clone(),
- error: e.display_message(),
- reproduction_command: Some(format_reproduction_command(
- "wt step squash --show-prompt",
- command,
- )),
- }
- .into()
- });
+ return execute_generation_command(
+ command,
+ &prompt,
+ Some("wt step squash --show-prompt"),
+ );
}
let mut commit_message = format!("Squash commits from {}\n\n", self.current_branch);
@@ -985,14 +961,25 @@ pub(crate) fn test_commit_generation(
};
let prompt = build_prompt(commit_generation_config, TemplateType::Commit, &context)?;
- // The connectivity test shells out the same way real generation does, so a
- // slow command would be just as silent — surface the same waiting status.
+ execute_generation_command(command, &prompt, None)
+}
+
+/// Share waiting status and diagnostics across commit, squash, and connectivity
+/// checks.
+fn execute_generation_command(
+ command: &str,
+ prompt: &str,
+ prompt_command: Option<&str>,
+) -> anyhow::Result<String> {
+ // Captured stdout makes slow commands otherwise silent. Dropping the
+ // watchdog clears its status before the caller prints the result.
let _watchdog = watch_llm_command(command);
- execute_llm_command(command, &prompt).map_err(|e| {
+ execute_llm_command(command, prompt).map_err(|e| {
worktrunk::git::GitError::LlmCommandFailed {
- command: command.clone(),
+ command: command.to_owned(),
error: e.display_message(),
- reproduction_command: None, // Already a test command
+ reproduction_command: prompt_command
+ .map(|prompt_command| format_reproduction_command(prompt_command, command)),
}
.into()
})