Skip to content

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.toml
index 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.md
index 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.rs
index 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 rendered
let 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.snap
index 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 ~/.config/worktrunk/config.toml with the following content:
# 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 -->
#
@@ -194,26 +183,26 @@ Creates ~/.config/worktrunk/config.toml with the following content:
# 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 -->
#