Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Rename LLM config to commit-generation
Maximilian Roos3c611b58504b
diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 272a25db6..d70ca1f0c 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -47,7 +47,7 @@ pub fn handle_merge(// Auto-commit uncommitted changes if they existif repo.is_dirty()? {- handle_commit_changes(message, &config.llm)?;+ handle_commit_changes(message, &config.commit_generation)?;}// Run pre-merge checks unless --no-verify was specified@@ -218,7 +218,7 @@ fn handle_merge_summary_output(/// Commit uncommitted changes with LLM-generated messagefn handle_commit_changes(custom_instruction: Option<&str>,- llm_config: &worktrunk::config::LlmConfig,+ commit_generation_config: &worktrunk::config::CommitGenerationConfig,) -> Result<(), GitError> {let repo = Repository::current();@@ -239,7 +239,8 @@ fn handle_commit_changes(}// Generate commit message- let commit_message = crate::llm::generate_commit_message(custom_instruction, llm_config)?;+ let commit_message =+ crate::llm::generate_commit_message(custom_instruction, commit_generation_config)?;// Commitrepo.run_command(&["commit", "-m", &commit_message])@@ -308,7 +309,11 @@ fn handle_squash(target_branch: &str, internal: bool) -> Result<Option<usize>, G// Load config and generate commit messagelet config = WorktrunkConfig::load().map_err(|e| GitError::CommandFailed(format!("Failed to load config: {}", e)))?;- let commit_message = crate::llm::generate_squash_message(target_branch, &subjects, &config.llm);+ let commit_message =+ crate::llm::generate_squash_message(target_branch, &subjects, &config.commit_generation)+ .map_err(|e| {+ GitError::CommandFailed(format!("Failed to generate commit message: {}", e))+ })?;// Reset to merge base (soft reset stages all changes)repo.run_command(&["reset", "--soft", &merge_base])diff --git a/src/config.rs b/src/config.rsindex adf563da2..e905fb064 100644--- a/src/config.rs+++ b/src/config.rs@@ -23,9 +23,9 @@ use toml;/// # Repository-namespaced (useful for shared directories with multiple repos)/// worktree-path = "../worktrees/{main-worktree}/{branch}"///-/// # LLM configuration for commit message generation-/// [llm]-/// command = "llm" # Command to invoke LLM (e.g., "llm", "claude")+/// # Commit generation configuration+/// [commit-generation]+/// command = "llm" # Command to invoke for generating commit messages (e.g., "llm", "claude")/// args = ["-s"] # Arguments to pass to the command/// ```///@@ -40,22 +40,22 @@ pub struct WorktrunkConfig {#[serde(rename = "worktree-path")]pub worktree_path: String,- #[serde(default)]- pub llm: LlmConfig,+ #[serde(default, rename = "commit-generation")]+ pub commit_generation: CommitGenerationConfig,/// Commands that have been approved for automatic execution#[serde(default, rename = "approved-commands")]pub approved_commands: Vec<ApprovedCommand>,}-/// Configuration for LLM integration+/// Configuration for commit message generation#[derive(Debug, Serialize, Deserialize, Clone, Default)]-pub struct LlmConfig {- /// Command to invoke LLM (e.g., "llm", "claude")+pub struct CommitGenerationConfig {+ /// Command to invoke for generating commit messages (e.g., "llm", "claude")#[serde(default)]pub command: Option<String>,- /// Arguments to pass to the LLM command+ /// Arguments to pass to the command#[serde(default)]pub args: Vec<String>,}@@ -122,7 +122,7 @@ impl Default for WorktrunkConfig {fn default() -> Self {Self {worktree_path: "../{main-worktree}.{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),}}@@ -140,8 +140,11 @@ impl WorktrunkConfig {let mut builder = Config::builder().set_default("worktree-path", defaults.worktree_path)?- .set_default("llm.command", defaults.llm.command.unwrap_or_default())?- .set_default("llm.args", defaults.llm.args)?;+ .set_default(+ "commit-generation.command",+ defaults.commit_generation.command.unwrap_or_default(),+ )?+ .set_default("commit-generation.args", defaults.commit_generation.args)?;// Add config file if it existsif let Some(config_path) = get_config_path()@@ -321,6 +324,7 @@ mod tests {let toml = toml::to_string(&config).unwrap();assert!(toml.contains("worktree-path"));assert!(toml.contains("../{main-worktree}.{branch}"));+ assert!(toml.contains("commit-generation"));}#[test]@@ -334,7 +338,7 @@ mod tests {fn test_format_worktree_path() {let config = WorktrunkConfig {worktree_path: "{main-worktree}.{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(@@ -347,7 +351,7 @@ mod tests {fn test_format_worktree_path_custom_template() {let config = WorktrunkConfig {worktree_path: "{main-worktree}-{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(@@ -360,7 +364,7 @@ mod tests {fn test_format_worktree_path_only_branch() {let config = WorktrunkConfig {worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(@@ -374,7 +378,7 @@ mod tests {// Slashes should be replaced with dashes to prevent directory traversallet config = WorktrunkConfig {worktree_path: "{main-worktree}.{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(@@ -387,7 +391,7 @@ mod tests {fn test_format_worktree_path_with_multiple_slashes() {let config = WorktrunkConfig {worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(@@ -401,7 +405,7 @@ mod tests {// Windows-style path separators should also be sanitizedlet config = WorktrunkConfig {worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),- llm: LlmConfig::default(),+ commit_generation: CommitGenerationConfig::default(),approved_commands: Vec::new(),};assert_eq!(diff --git a/src/llm.rs b/src/llm.rsindex cf53d1e1a..d9107a19e 100644--- a/src/llm.rs+++ b/src/llm.rs@@ -1,26 +1,30 @@use std::process;-use worktrunk::config::LlmConfig;+use worktrunk::config::CommitGenerationConfig;use worktrunk::git::{GitError, Repository};-use worktrunk::styling::{WARNING, WARNING_EMOJI, eprintln};pub fn generate_commit_message(custom_instruction: Option<&str>,- llm_config: &LlmConfig,+ commit_generation_config: &CommitGenerationConfig,) -> Result<String, GitError> {- // Try LLM generation if configured- if let Some(ref command) = llm_config.command {- if let Ok(llm_message) =- try_generate_commit_message(custom_instruction, command, &llm_config.args)- {- return Ok(llm_message);+ // Check if commit generation is configured (non-empty command)+ if let Some(ref command) = commit_generation_config.command {+ if !command.trim().is_empty() {+ // Commit generation is explicitly configured - fail if it doesn't work+ return try_generate_commit_message(+ custom_instruction,+ command,+ &commit_generation_config.args,+ )+ .map_err(|e| {+ GitError::CommandFailed(format!(+ "Commit generation command '{}' failed: {}",+ command, e+ ))+ });}- // If LLM fails, fall through to deterministic approach- eprintln!(- "{WARNING_EMOJI} {WARNING}LLM generation failed, using deterministic message{WARNING:#}"- );}- // Fallback: simple deterministic commit message+ // Fallback: simple deterministic commit message (only when not configured)Ok("WIP: Auto-commit before merge".to_string())}@@ -139,29 +143,29 @@ fn try_generate_commit_message(pub fn generate_squash_message(target_branch: &str,subjects: &[String],- llm_config: &LlmConfig,-) -> String {- // Try LLM generation if configured- if let Some(ref command) = llm_config.command {- if let Ok(llm_message) =- try_generate_llm_message(target_branch, subjects, command, &llm_config.args)- {- return llm_message;+ commit_generation_config: &CommitGenerationConfig,+) -> Result<String, Box<dyn std::error::Error>> {+ // Check if commit generation is configured (non-empty command)+ if let Some(ref command) = commit_generation_config.command {+ if !command.trim().is_empty() {+ // Commit generation is explicitly configured - fail if it doesn't work+ return try_generate_llm_message(+ target_branch,+ subjects,+ command,+ &commit_generation_config.args,+ );}- // If LLM fails, fall through to deterministic approach- eprintln!(- "{WARNING_EMOJI} {WARNING}LLM generation failed, using deterministic message{WARNING:#}"- );}- // Fallback: deterministic commit message+ // Fallback: deterministic commit message (only when not configured)let mut commit_message = format!("Squash commits from {}\n\n", target_branch);commit_message.push_str("Combined commits:\n");for subject in subjects.iter().rev() {// Reverse so they're in chronological ordercommit_message.push_str(&format!("- {}\n", subject));}- commit_message+ Ok(commit_message)}fn try_generate_llm_message(diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 61c6b2082..bf86b775b 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -373,10 +373,10 @@ fn test_merge_squash_with_llm() {&["main", "--squash"],Some(&feature_wt),&[- ("WORKTRUNK_LLM__COMMAND", "sh"),- ("WORKTRUNK_LLM__ARGS__0", "-c"),+ ("WORKTRUNK_COMMIT_GENERATION__COMMAND", "sh"),+ ("WORKTRUNK_COMMIT_GENERATION__ARGS__0", "-c"),(- "WORKTRUNK_LLM__ARGS__1",+ "WORKTRUNK_COMMIT_GENERATION__ARGS__1","cat >/dev/null && echo 'feat: implement user authentication system'",),],@@ -430,13 +430,16 @@ fn test_merge_squash_llm_fallback() {.expect("Failed to commit");// Configure LLM command that will fail (non-existent command)- // Should fall back to deterministic message and print warning+ // Should now error instead of falling backsnapshot_merge_with_env("merge_squash_llm_fallback",&repo,&["main", "--squash"],Some(&feature_wt),- &[("WORKTRUNK_LLM__COMMAND", "nonexistent-llm-command")],+ &[(+ "WORKTRUNK_COMMIT_GENERATION__COMMAND",+ "nonexistent-llm-command",+ )],);}@@ -572,8 +575,11 @@ fn test_merge_auto_commit_with_llm() {&["main"],Some(&feature_wt),&[- ("WORKTRUNK_LLM__COMMAND", "echo"),- ("WORKTRUNK_LLM__ARGS", "fix: improve auth validation logic"),+ ("WORKTRUNK_COMMIT_GENERATION__COMMAND", "echo"),+ (+ "WORKTRUNK_COMMIT_GENERATION__ARGS",+ "fix: improve auth validation logic",+ ),],);}@@ -622,8 +628,11 @@ fn test_merge_auto_commit_with_message() {&["main", "-m", "Complete the user dashboard feature"],Some(&feature_wt),&[- ("WORKTRUNK_LLM__COMMAND", "echo"),- ("WORKTRUNK_LLM__ARGS", "feat: complete user dashboard"),+ ("WORKTRUNK_COMMIT_GENERATION__COMMAND", "echo"),+ (+ "WORKTRUNK_COMMIT_GENERATION__ARGS",+ "feat: complete user dashboard",+ ),],);}@@ -687,9 +696,12 @@ fn test_merge_auto_commit_and_squash() {&["main", "--squash"],Some(&feature_wt),&[- ("WORKTRUNK_LLM__COMMAND", "echo"),+ ("WORKTRUNK_COMMIT_GENERATION__COMMAND", "echo"),// First message is for auto-commit- ("WORKTRUNK_LLM__ARGS", "fix: update file 1 content"),+ (+ "WORKTRUNK_COMMIT_GENERATION__ARGS",+ "fix: update file 1 content",+ ),],);}diff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snapindex 351e1e928..64f55fd33 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_and_squash.snap@@ -49,5 +49,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0m-π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snapindex f204f85b2..65f87582b 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_deterministic.snap@@ -43,4 +43,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snapindex c2596293a..e7637b1b7 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_llm.snap@@ -45,4 +45,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snapindex b7f8b1a80..4111c28cf 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_auto_commit_with_message.snap@@ -47,4 +47,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snapindex fb78f237f..882737c71 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap@@ -46,4 +46,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snapindex 4ae3eae67..79775bffb 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap@@ -46,4 +46,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snapindex f6160df3a..ff888fcef 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap@@ -47,4 +47,3 @@ To enable automatic cd, run: wt configure-shell[2mWorktree: Removed[0m----- stderr ------π‘ [33mLLM generation failed, using deterministic message[0m