Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Pass LLM prompt via stdin
Maximilian Roosbe33048882a6
diff --git a/src/llm.rs b/src/llm.rsindex 33afa60d6..1c5d9d646 100644--- a/src/llm.rs+++ b/src/llm.rs@@ -36,6 +36,9 @@ fn try_generate_llm_message(command: &str,args: &[String],) -> Result<String, Box<dyn std::error::Error>> {+ use std::io::Write;+ use std::process::Stdio;+// Build context promptlet mut context = format!("Squashing commits on current branch since branching from {}\n\n",@@ -49,11 +52,21 @@ fn try_generate_llm_message(let prompt = "Generate a conventional commit message (feat/fix/docs/style/refactor) that combines these changes into one cohesive message. Output only the commit message without any explanation.";let full_prompt = format!("{}\n\n{}", context, prompt);- // Execute LLM command- let output = process::Command::new(command)+ // Execute LLM command with prompt via stdin+ let mut child = process::Command::new(command).args(args)- .arg(&full_prompt)- .output()?;+ .stdin(Stdio::piped())+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .spawn()?;++ // Write prompt to stdin+ if let Some(mut stdin) = child.stdin.take() {+ stdin.write_all(full_prompt.as_bytes())?;+ // stdin is dropped here, closing the pipe+ }++ let output = child.wait_with_output()?;if !output.status.success() {let stderr = String::from_utf8_lossy(&output.stderr);diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex b1407f7c9..2ae18427d 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -365,17 +365,18 @@ fn test_merge_squash_with_llm() {.expect("Failed to commit");// Configure mock LLM command via environment variable- // Use echo to return a fixed message+ // Use sh to consume stdin and return a fixed messagesnapshot_merge_with_env("merge_squash_with_llm",&repo,&["main", "--squash"],Some(&feature_wt),&[- ("WORKTRUNK_LLM__COMMAND", "echo"),+ ("WORKTRUNK_LLM__COMMAND", "sh"),+ ("WORKTRUNK_LLM__ARGS__0", "-c"),(- "WORKTRUNK_LLM__ARGS",- "feat: implement user authentication system",+ "WORKTRUNK_LLM__ARGS__1",+ "cat >/dev/null && echo 'feat: implement user authentication system'",),],);