Skip to content

Instantly share code, notes, and snippets.

@sputnikus
Last active July 11, 2025 14:15
Show Gist options
  • Save sputnikus/fc5fbd6bcee9a77963e968465e0e436f to your computer and use it in GitHub Desktop.
Save sputnikus/fc5fbd6bcee9a77963e968465e0e436f to your computer and use it in GitHub Desktop.

Revisions

  1. sputnikus revised this gist Jul 11, 2025. 1 changed file with 38 additions and 5 deletions.
    43 changes: 38 additions & 5 deletions llm_conventional_desc.fish
    Original file line number Diff line number Diff line change
    @@ -9,18 +9,51 @@ if [ -z "$DIFF" ]
    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
    set -l DESC_MSG $(echo "$DIFF" | llm -m claude-3.5-sonnet "\
    Generate a concise commit message (first line), blank line and detailed
    description based on these changes. Follow conventional commits format.
    Your response will be passed directly into version control command. Diff:\
    ")
    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

  2. sputnikus revised this gist Jun 19, 2025. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions llm_conventional_desc.fish
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/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" ]
  3. sputnikus revised this gist Jun 19, 2025. No changes.
  4. sputnikus created this gist Jun 19, 2025.
    27 changes: 27 additions & 0 deletions llm_conventional_desc.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env fish
    # Shebang for testing, Jujutsu config at the end of this file

    set -l DIFF $(jj diff --git -r @)
    if [ -z "$DIFF" ]
    echo "No changes found."
    return 1
    end

    # Generate commit message using LLM
    set -l DESC_MSG $(echo "$DIFF" | llm -m claude-3.5-sonnet "\
    Generate a concise commit message (first line), blank line and detailed
    description based on these changes. Follow conventional commits format.
    Your response will be passed directly into version control command. Diff:\
    ")

    if [ -z "$DESC_MSG" ]
    echo "Failed to generate change description."
    return 1
    end

    # Describe changes
    printf %s\n $DESC_MSG | jj desc --stdin

    # Jujutsu config
    # [aliases]
    # cdesc = ["util", "exec", "--", "llm_conventional_desc.fish"]