Last active
July 11, 2025 14:15
-
-
Save sputnikus/fc5fbd6bcee9a77963e968465e0e436f to your computer and use it in GitHub Desktop.
Generate Jujutsu change description using llm tool in Conventional Commit format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fish | |
# Shebang for testing, Jujutsu config at the end of this file | |
# LLMs are useful for generating the first line of the CC (the What), but you | |
# should always review generated description to include the Why and the How. | |
set -l DIFF $(jj diff --git -r @) | |
if [ -z "$DIFF" ] | |
echo "No changes found." | |
return 1 | |
end | |
# Use existing revset description to provide CC description | |
set -l DESC_DETAIL $(jj log --no-graph -T description -r @) | |
if [ -z "$DESC_DETAIL" ] | |
set -l DESC_DETAIL "" | |
end | |
# Generate commit message using LLM | |
if [ -n "$DESC_DETAIL" ] | |
# Use handwritten description | |
set -f DESC_MSG $(printf '\ | |
Generate a conventional commit message following this exact format: | |
- First line: type(scope): brief description (50 chars max) | |
- Blank line | |
- This detailed explanation: %s | |
Use conventional commit types: feat, fix, docs, style, refactor, test, chore, build, ci, perf. | |
Only output the commit message - no code blocks, explanations, or extra formatting. | |
Code changes: | |
%s' $DESC_DETAIL $(echo "$DIFF") | llm --log) | |
else | |
# Generate simple conventional commit message | |
set -f DESC_MSG $(printf '\ | |
Generate a conventional commit message from this diff: | |
- First line only: type(scope): brief description (50 chars max) | |
- Use conventional commit types: feat, fix, docs, style, refactor, test, chore, build, ci, perf | |
- Only output the commit message - no code blocks, explanations, or extra formatting | |
Code changes: | |
%s' $(echo "$DIFF") | llm --log) | |
end | |
if [ -z "$DESC_MSG" ] | |
echo "Failed to generate change description." | |
return 1 | |
end | |
set -l FIRST_LINE $(echo "$DESC_MSG" | head -1) | |
if ! echo "$FIRST_LINE" | grep -q "^[a-z][a-z]*\(.*\)*:" | |
echo "Warning: Generated message may not follow conventional commits format:" | |
echo " First line: $FIRST_LINE" | |
echo " Expected: type(scope): description" | |
echo "" | |
end | |
# Describe changes | |
printf %s\n $DESC_MSG | jj desc --stdin | |
# Jujutsu config | |
# [aliases] | |
# cdesc = ["util", "exec", "--", "llm_conventional_desc.fish"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://gist.github.com/RafalWilinski/f0167ae404c7623ffb54c1429394323a, adapted for Jujutsu and Fish.