Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Simplify default LLM prompt templates
Maximilian Roos107591b30b51
diff --git a/dev/config.example.toml b/dev/config.example.tomlindex 836dfa9a2..d9c686413 100644--- a/dev/config.example.toml+++ b/dev/config.example.toml@@ -83,40 +83,29 @@ approved-commands = ["npm install"]# If not specified, uses the default template shown below:# <!-- DEFAULT_TEMPLATE_START --># template = """-# Format-# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-# - Blank line after first line.-# - Optional details with proper line breaks explaining context. Commits with more substantial changes should have more details.-# - Return ONLY the formatted message without quotes, code blocks, or preamble.-#-# Style-# - Do not give normative statements or otherwise speculate on why the change was made.-# - Broadly match the style of the previous commit messages.-# - For example, if they're in conventional commit format, use conventional commits; if they're not, don't use conventional commits.-#-# The context contains:-# - <git-diff> with the staged changes. This is the ONLY content you should base your message on.-# - <git-info> with branch name and recent commit message titles for style reference ONLY. DO NOT use their content to inform your message.-#-# ----# The following is the context for your task:-# ----# <git-diff>-# ```+# Write a commit message for the staged changes below.+#+# <format>+# - Subject under 50 chars, blank line, then optional body+# - Output only the commit message, no quotes or code blocks+# </format>+#+# <style>+# - Imperative mood: "Add feature" not "Added feature"+# - Match recent commit style (conventional commits if used)+# - Describe the change, not the intent or benefit+# </style>+#+# <diff># {{ git_diff }}-# ```-# </git-diff>-#-# <git-info>-# <current-branch>{{ branch }}</current-branch>-# {% if recent_commits %}-# <previous-commit-message-titles>-# {% for commit in recent_commits %}-# <previous-commit-message-title>{{ commit }}</previous-commit-message-title>-# {% endfor %}-# </previous-commit-message-titles>-# {% endif %}-# </git-info>+# </diff>+#+# <context>+# Branch: {{ branch }}+# {% if recent_commits %}<recent_commits>+# {% for commit in recent_commits %}- {{ commit }}+# {% endfor %}</recent_commits>{% endif %}+# </context># """# <!-- DEFAULT_TEMPLATE_END -->#@@ -149,26 +138,26 @@ approved-commands = ["npm install"]# If not specified, uses the default template:# <!-- DEFAULT_SQUASH_TEMPLATE_START --># squash-template = """-# Generate a commit message that combines these changes into one cohesive message. Output only the commit message without any explanation.+# Combine these commits into a single commit message.#-# Format-# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-# - Blank line after first line.-# - Optional details with proper line breaks explaining context.-# - Match the style of the existing commits being squashed (e.g., if they use conventional commits, use conventional commits).+# <format>+# - Subject under 50 chars, blank line, then optional body+# - Output only the commit message, no quotes or code blocks+# </format>#-# Squashing commits from {{ branch }} to merge into {{ target_branch }}+# <style>+# - Imperative mood: "Add feature" not "Added feature"+# - Match the style of commits being squashed (conventional commits if used)+# - Describe the change, not the intent or benefit+# </style>#-# Commits being combined:-# {% for commit in commits %}-# - {{ commit }}-# {% endfor %}+# <commits branch="{{ branch }}" target="{{ target_branch }}">+# {% for commit in commits %}- {{ commit }}+# {% endfor %}</commits>#-# <git-diff>-# ```+# <diff># {{ git_diff }}-# ```-# </git-diff>+# </diff># """# <!-- DEFAULT_SQUASH_TEMPLATE_END -->#diff --git a/docs/content/config.md b/docs/content/config.mdindex 0bbd8a1d0..a6dd07a34 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -321,40 +321,29 @@ approved-commands = ["npm install"]# If not specified, uses the default template shown below:# <!-- DEFAULT_TEMPLATE_START --># template = """-# Format-# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-# - Blank line after first line.-# - Optional details with proper line breaks explaining context. Commits with more substantial changes should have more details.-# - Return ONLY the formatted message without quotes, code blocks, or preamble.-#-# Style-# - Do not give normative statements or otherwise speculate on why the change was made.-# - Broadly match the style of the previous commit messages.-# - For example, if they're in conventional commit format, use conventional commits; if they're not, don't use conventional commits.-#-# The context contains:-# - <git-diff> with the staged changes. This is the ONLY content you should base your message on.-# - <git-info> with branch name and recent commit message titles for style reference ONLY. DO NOT use their content to inform your message.-#-# ----# The following is the context for your task:-# ----# <git-diff>-# ```+# Write a commit message for the staged changes below.+#+# <format>+# - Subject under 50 chars, blank line, then optional body+# - Output only the commit message, no quotes or code blocks+# </format>+#+# <style>+# - Imperative mood: "Add feature" not "Added feature"+# - Match recent commit style (conventional commits if used)+# - Describe the change, not the intent or benefit+# </style>+#+# <diff># {{ git_diff }}-# ```-# </git-diff>-#-# <git-info>-# <current-branch>{{ branch }}</current-branch>-# {% if recent_commits %}-# <previous-commit-message-titles>-# {% for commit in recent_commits %}-# <previous-commit-message-title>{{ commit }}</previous-commit-message-title>-# {% endfor %}-# </previous-commit-message-titles>-# {% endif %}-# </git-info>+# </diff>+#+# <context>+# Branch: {{ branch }}+# {% if recent_commits %}<recent_commits>+# {% for commit in recent_commits %}- {{ commit }}+# {% endfor %}</recent_commits>{% endif %}+# </context># """# <!-- DEFAULT_TEMPLATE_END -->#@@ -387,26 +376,26 @@ approved-commands = ["npm install"]# If not specified, uses the default template:# <!-- DEFAULT_SQUASH_TEMPLATE_START --># squash-template = """-# Generate a commit message that combines these changes into one cohesive message. Output only the commit message without any explanation.+# Combine these commits into a single commit message.#-# Format-# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-# - Blank line after first line.-# - Optional details with proper line breaks explaining context.-# - Match the style of the existing commits being squashed (e.g., if they use conventional commits, use conventional commits).+# <format>+# - Subject under 50 chars, blank line, then optional body+# - Output only the commit message, no quotes or code blocks+# </format>#-# Squashing commits from {{ branch }} to merge into {{ target_branch }}+# <style>+# - Imperative mood: "Add feature" not "Added feature"+# - Match the style of commits being squashed (conventional commits if used)+# - Describe the change, not the intent or benefit+# </style>#-# Commits being combined:-# {% for commit in commits %}-# - {{ commit }}-# {% endfor %}+# <commits branch="{{ branch }}" target="{{ target_branch }}">+# {% for commit in commits %}- {{ commit }}+# {% endfor %}</commits>#-# <git-diff>-# ```+# <diff># {{ git_diff }}-# ```-# </git-diff>+# </diff># """# <!-- DEFAULT_SQUASH_TEMPLATE_END -->#diff --git a/src/llm.rs b/src/llm.rsindex 7397f0b33..443b8cc49 100644--- a/src/llm.rs+++ b/src/llm.rs@@ -39,65 +39,54 @@ fn format_command_display(command: &str, args: &[String]) -> String {/// Default template for commit message prompts////// Synced to dev/config.example.toml by `cargo test readme_sync`-const DEFAULT_TEMPLATE: &str = r#"Format-- First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-- Blank line after first line.-- Optional details with proper line breaks explaining context. Commits with more substantial changes should have more details.-- Return ONLY the formatted message without quotes, code blocks, or preamble.--Style-- Do not give normative statements or otherwise speculate on why the change was made.-- Broadly match the style of the previous commit messages.- - For example, if they're in conventional commit format, use conventional commits; if they're not, don't use conventional commits.--The context contains:-- <git-diff> with the staged changes. This is the ONLY content you should base your message on.-- <git-info> with branch name and recent commit message titles for style reference ONLY. DO NOT use their content to inform your message.------The following is the context for your task:-----<git-diff>-```+const DEFAULT_TEMPLATE: &str = r#"Write a commit message for the staged changes below.++<format>+- Subject under 50 chars, blank line, then optional body+- Output only the commit message, no quotes or code blocks+</format>++<style>+- Imperative mood: "Add feature" not "Added feature"+- Match recent commit style (conventional commits if used)+- Describe the change, not the intent or benefit+</style>++<diff>{{ git_diff }}-```-</git-diff>--<git-info>- <current-branch>{{ branch }}</current-branch>-{% if recent_commits %}- <previous-commit-message-titles>-{% for commit in recent_commits %}- <previous-commit-message-title>{{ commit }}</previous-commit-message-title>-{% endfor %}- </previous-commit-message-titles>-{% endif %}-</git-info>+</diff>++<context>+Branch: {{ branch }}+{% if recent_commits %}<recent_commits>+{% for commit in recent_commits %}- {{ commit }}+{% endfor %}</recent_commits>{% endif %}+</context>"#;/// Default template for squash commit message prompts////// Synced to dev/config.example.toml by `cargo test readme_sync`-const DEFAULT_SQUASH_TEMPLATE: &str = r#"Generate a commit message that combines these changes into one cohesive message. Output only the commit message without any explanation.+const DEFAULT_SQUASH_TEMPLATE: &str = r#"Combine these commits into a single commit message.-Format-- First line: <50 chars, present tense, describes WHAT and WHY (not HOW).-- Blank line after first line.-- Optional details with proper line breaks explaining context.-- Match the style of the existing commits being squashed (e.g., if they use conventional commits, use conventional commits).+<format>+- Subject under 50 chars, blank line, then optional body+- Output only the commit message, no quotes or code blocks+</format>-Squashing commits from {{ branch }} to merge into {{ target_branch }}+<style>+- Imperative mood: "Add feature" not "Added feature"+- Match the style of commits being squashed (conventional commits if used)+- Describe the change, not the intent or benefit+</style>-Commits being combined:-{% for commit in commits %}-- {{ commit }}-{% endfor %}+<commits branch="{{ branch }}" target="{{ target_branch }}">+{% for commit in commits %}- {{ commit }}+{% endfor %}</commits>-<git-diff>-```+<diff>{{ git_diff }}-```-</git-diff>+</diff>"#;/// Execute an LLM command with the given prompt via stdin.@@ -527,7 +516,7 @@ mod tests {let prompt = result.unwrap();assert!(prompt.contains("feat: add feature"));assert!(prompt.contains("fix: bug"));- assert!(prompt.contains("<previous-commit-message-titles>"));+ assert!(prompt.contains("<recent_commits>"));}#[test]@@ -537,9 +526,14 @@ mod tests {let context = commit_context("diff", "main", Some(&commits), "repo");let result = build_prompt(&config, TemplateType::Commit, &context);assert!(result.is_ok());- // Should not render the recent commits section if empty+ // Should not render the recent commits data section if empty+ // Note: <recent_commits> is mentioned in the style text, but the actual+ // data section (with commit list) should not be renderedlet prompt = result.unwrap();- assert!(!prompt.contains("<previous-commit-message-titles>"));+ // The context section should have the branch but no recent_commits content+ assert!(prompt.contains("Branch: main"));+ assert!(!prompt.contains("- feat:"));+ assert!(!prompt.contains("- fix:"));}#[test]diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex 76c05d1d1..98f73e381 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -128,40 +128,29 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m# If not specified, uses the default template shown below:[0m[2m# <!-- DEFAULT_TEMPLATE_START -->[0m[2m# template = """[0m- [2m# Format[0m- [2m# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).[0m- [2m# - Blank line after first line.[0m- [2m# - Optional details with proper line breaks explaining context. Commits with more substantial changes should have more details.[0m- [2m# - Return ONLY the formatted message without quotes, code blocks, or preamble.[0m- [2m#[0m- [2m# Style[0m- [2m# - Do not give normative statements or otherwise speculate on why the change was made.[0m- [2m# - Broadly match the style of the previous commit messages.[0m- [2m# - For example, if they're in conventional commit format, use conventional commits; if they're not, don't use conventional commits.[0m- [2m#[0m- [2m# The context contains:[0m- [2m# - <git-diff> with the staged changes. This is the ONLY content you should base your message on.[0m- [2m# - <git-info> with branch name and recent commit message titles for style reference ONLY. DO NOT use their content to inform your message.[0m- [2m#[0m- [2m# ---[0m- [2m# The following is the context for your task:[0m- [2m# ---[0m- [2m# <git-diff>[0m- [2m# ```[0m+ [2m# Write a commit message for the staged changes below.[0m+ [2m#[0m+ [2m# <format>[0m+ [2m# - Subject under 50 chars, blank line, then optional body[0m+ [2m# - Output only the commit message, no quotes or code blocks[0m+ [2m# </format>[0m+ [2m#[0m+ [2m# <style>[0m+ [2m# - Imperative mood: "Add feature" not "Added feature"[0m+ [2m# - Match recent commit style (conventional commits if used)[0m+ [2m# - Describe the change, not the intent or benefit[0m+ [2m# </style>[0m+ [2m#[0m+ [2m# <diff>[0m[2m# {{ git_diff }}[0m- [2m# ```[0m- [2m# </git-diff>[0m- [2m#[0m- [2m# <git-info>[0m- [2m# <current-branch>{{ branch }}</current-branch>[0m- [2m# {% if recent_commits %}[0m- [2m# <previous-commit-message-titles>[0m- [2m# {% for commit in recent_commits %}[0m- [2m# <previous-commit-message-title>{{ commit }}</previous-commit-message-title>[0m- [2m# {% endfor %}[0m- [2m# </previous-commit-message-titles>[0m- [2m# {% endif %}[0m- [2m# </git-info>[0m+ [2m# </diff>[0m+ [2m#[0m+ [2m# <context>[0m+ [2m# Branch: {{ branch }}[0m+ [2m# {% if recent_commits %}<recent_commits>[0m+ [2m# {% for commit in recent_commits %}- {{ commit }}[0m+ [2m# {% endfor %}</recent_commits>{% endif %}[0m+ [2m# </context>[0m[2m# """[0m[2m# <!-- DEFAULT_TEMPLATE_END -->[0m[2m#[0m@@ -194,26 +183,26 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m# If not specified, uses the default template:[0m[2m# <!-- DEFAULT_SQUASH_TEMPLATE_START -->[0m[2m# squash-template = """[0m- [2m# Generate a commit message that combines these changes into one cohesive message. Output only the commit message without any explanation.[0m+ [2m# Combine these commits into a single commit message.[0m[2m#[0m- [2m# Format[0m- [2m# - First line: <50 chars, present tense, describes WHAT and WHY (not HOW).[0m- [2m# - Blank line after first line.[0m- [2m# - Optional details with proper line breaks explaining context.[0m- [2m# - Match the style of the existing commits being squashed (e.g., if they use conventional commits, use conventional commits).[0m+ [2m# <format>[0m+ [2m# - Subject under 50 chars, blank line, then optional body[0m+ [2m# - Output only the commit message, no quotes or code blocks[0m+ [2m# </format>[0m[2m#[0m- [2m# Squashing commits from {{ branch }} to merge into {{ target_branch }}[0m+ [2m# <style>[0m+ [2m# - Imperative mood: "Add feature" not "Added feature"[0m+ [2m# - Match the style of commits being squashed (conventional commits if used)[0m+ [2m# - Describe the change, not the intent or benefit[0m+ [2m# </style>[0m[2m#[0m- [2m# Commits being combined:[0m- [2m# {% for commit in commits %}[0m- [2m# - {{ commit }}[0m- [2m# {% endfor %}[0m+ [2m# <commits branch="{{ branch }}" target="{{ target_branch }}">[0m+ [2m# {% for commit in commits %}- {{ commit }}[0m+ [2m# {% endfor %}</commits>[0m[2m#[0m- [2m# <git-diff>[0m- [2m# ```[0m+ [2m# <diff>[0m[2m# {{ git_diff }}[0m- [2m# ```[0m- [2m# </git-diff>[0m+ [2m# </diff>[0m[2m# """[0m[2m# <!-- DEFAULT_SQUASH_TEMPLATE_END -->[0m[2m#[0m