Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
all:
just --list

# Update jj-repo dep
@update-jj:
nix flake update --update-input jj-repo
@update-self-repo:
nix flake update nix-priv jj-repo --commit-lock-file --refresh
39 changes: 28 additions & 11 deletions conf/bash/scripts/git-commit-context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
# get context for llm git commit message generation
# script should redirect output to stdout, so it can be used in a pipeline

# NOTE: This script limits the amount of context provided to avoid exceeding
# the AI model's token limits (max_input_tokens). Large diffs and too much
# commit history can cause "Exceed max_input_tokens limit" errors.

## The context should include:

# 1. Staged changes
# 1. Staged changes (limited to avoid token overflow)
# 2. Current branch name
# 3. Last 10 commit messages
# 3. Last 2 commit messages (reduced from 5)

## It should output in well formatted text

## Steps

### 1. check if repo is dirty, exit 1 if not dirty
### 2. Get staged changes
### 2. Get staged changes (with limits)
### 3. Get current branch name
### 4. Get last 10 commit messages
### 4. Get last 2 commit messages
### 5. Format the output in well formatted text
### 6. Redirect the output to stdout
### 7. Exit 0
Expand All @@ -41,15 +45,28 @@ check_staged_changes() {
fi
}

# Function to get staged changes
# Function to get staged changes (with size limits)
get_staged_changes() {
echo "=== STAGED CHANGES ==="
echo
# Show the actual diff
echo "Changes:"
# Show the actual diff with limits
echo "Changes summary:"
git --no-pager diff --cached --stat --color=never
echo
git --no-pager diff --cached --color=never

# Check if diff is too large
local diff_lines=$(git --no-pager diff --cached --color=never | wc -l)
local max_diff_lines=100

if [ "$diff_lines" -gt "$max_diff_lines" ]; then
echo "Large diff detected ($diff_lines lines). Showing first $max_diff_lines lines:"
git --no-pager diff --cached --color=never | head -n "$max_diff_lines"
echo
echo "... (diff truncated for brevity) ..."
else
echo "Full diff:"
git --no-pager diff --cached --color=never
fi
echo
}

Expand All @@ -66,12 +83,12 @@ get_current_branch() {
echo
}

# Function to get last 10 commit messages
# Function to get last 2 commit messages (reduced from 5)
get_recent_commits() {
echo "=== RECENT COMMIT HISTORY ==="
echo
echo "Last 10 commits:"
git --no-pager log --oneline -10 --color=never --decorate
echo "Last 2 commits:"
git --no-pager log --oneline -2 --color=never --decorate
echo
}

Expand Down
42 changes: 33 additions & 9 deletions conf/bash/scripts/jj-commit-context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# get context for llm jj commit message generation
# script should redirect output to stdout, so it can be used in a pipeline

# NOTE: This script limits the amount of context provided to avoid exceeding
# the AI model's token limits (max_input_tokens). Large diffs and too much
# commit history can cause "Exceed max_input_tokens limit" errors.

## The context should include:

# 1. Changes in the specified revision
# 2. Last 10 commit messages
# 1. Changes in the specified revision (limited to avoid token overflow)
# 2. Last 2 commit messages (reduced for token efficiency)

## It should output in well formatted text

Expand All @@ -15,7 +19,7 @@
### 1. check if repo is a jj repository, exit 1 if not
### 2. Get the revision argument (default to @)
### 3. Get changes for the specified revision
### 4. Get last 10 commit messages
### 4. Get last 2 commit messages
### 5. Format the output in well formatted text
### 6. Redirect the output to stdout
### 7. Exit 0
Expand All @@ -41,22 +45,42 @@ get_revision_changes() {
local rev="$1"
echo "=== STAGED CHANGES ==="
echo
# Show the actual diff
echo "Changes:"
# Show compact summary with file stats
echo "Files changed:"
jj diff -r "$rev" --stat --color=never --no-pager
echo
jj diff -r "$rev" --color=never --no-pager

# Check if diff is too large
local diff_lines=$(jj diff -r "$rev" --color=never --no-pager | wc -l)
local max_diff_lines=50 # Conservative limit for token usage
local minimal_threshold=200 # If diff is huge, use minimal output

if [ "$diff_lines" -gt "$minimal_threshold" ]; then
echo "Very large diff detected ($diff_lines lines). Showing minimal summary:"
# For huge diffs, just show summary stats
jj diff -r "$rev" --stat --color=never --no-pager
echo
echo "... (full diff omitted due to size - $diff_lines lines total) ..."
elif [ "$diff_lines" -gt "$max_diff_lines" ]; then
echo "Large diff detected ($diff_lines lines). Showing truncated diff:"
jj diff -r "$rev" --color=never --no-pager | head -n "$max_diff_lines"
echo
echo "... (diff truncated - $((diff_lines - max_diff_lines)) lines omitted) ..."
else
echo "Full diff:"
jj diff -r "$rev" --color=never --no-pager
fi
echo
}

# Function to get last 10 commit messages using template
# Function to get last 2 commit messages using template
get_recent_commits() {
local rev="$1"
echo "=== RECENT COMMIT HISTORY ==="
echo
echo "Last 10 commits:"
echo "Last 2 commits:"
# Use template to format output similar to git log --oneline
jj log -n 10 -r "..$rev" --no-pager --no-graph --color=never \
jj log -n 2 -r "..$rev" --no-pager --no-graph --color=never \
-T 'change_id.short() ++ " " ++ description.first_line() ++ "\n"'
echo
}
Expand Down
4 changes: 1 addition & 3 deletions conf/bash/scripts/jj-split-on-bookmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ perform_split() {
exit 1
fi

echo "Split created revision: $rev"

# Step 3: Generate AI commit message if requested
if [[ "$use_ai" == "true" ]]; then
echo "Using AI to generate commit message for revision: $rev"
Expand All @@ -82,8 +80,8 @@ perform_split() {
fi
fi

echo "Split operation completed successfully!"
echo "Created revision: $rev with bookmark: $bookmark"
echo "Tip: run ` jj mv-next $bookmark ` to move to the new revision"
}

# Main function
Expand Down
Loading
Loading