Skip to content

Commit 12e1c1f

Browse files
committed
git-commit-push-scriptsh updated
1 parent 09d8447 commit 12e1c1f

File tree

1 file changed

+95
-25
lines changed

1 file changed

+95
-25
lines changed

β€Žgit-commit-push-script.shβ€Ž

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ source ~/.bash_profile
33

44
# Configuration
55
MAX_DIFF_CHARS=2000 # Truncate diff to prevent long processing
6-
TIMEOUT_SECONDS=10 # Max time to wait for LLM response
6+
TIMEOUT_SECONDS=45 # Max time to wait for LLM response (squish auto-starts server on first run)
77
MAX_COMMIT_LENGTH=50 # Max characters for commit message
88

9+
# Squish model selection β€” set SQUISH_MODEL to target a specific compressed model.
10+
# Accepts a name hint (e.g. "14b", "7b") or a full path to a model directory.
11+
# Leave empty to let squish auto-detect (uses the first available model in ~/models).
12+
# Examples:
13+
# SQUISH_MODEL="14b" # matches Qwen2.5-14B-*
14+
# SQUISH_MODEL="$HOME/models/Qwen2.5-14B-Instruct-bf16" # explicit path
15+
SQUISH_MODEL="${SQUISH_MODEL:-}"
16+
17+
# Squish server port β€” override if you run multiple squish servers concurrently.
18+
SQUISH_PORT="${SQUISH_PORT:-8000}"
19+
920
# Colors
1021
RED='\033[0;31m'
1122
GREEN='\033[0;32m'
@@ -99,10 +110,10 @@ if [ -n "$ticket" ]; then
99110
fi
100111
echo ""
101112

102-
# Get changed files for fallback message
103-
changed_files=$(git diff --name-only origin/$default_branch | head -3)
113+
# Get changed files for fallback message (staged changes vs last commit)
114+
changed_files=$(git diff --cached --name-only | head -3)
104115
first_file=$(echo "$changed_files" | head -1)
105-
file_count=$(git diff --name-only origin/$default_branch | wc -l | tr -d ' ')
116+
file_count=$(git diff --cached --name-only | wc -l | tr -d ' ')
106117

107118
# Show changed files
108119
print_step "Files changed: ${WHITE}$file_count${NC}"
@@ -125,36 +136,95 @@ else
125136
fallback_message="Updated ${base_branch} branch"
126137
fi
127138

128-
# Get the git diff - truncate for performance
129-
diff=$(git diff origin/$default_branch | head -c $MAX_DIFF_CHARS)
139+
# Get the git diff (staged changes vs last commit) - truncate for performance
140+
diff=$(git diff --cached | head -c $MAX_DIFF_CHARS)
130141

131142
# Skip LLM if diff is too large (use fallback)
132-
diff_size=$(git diff origin/$default_branch | wc -c | tr -d ' ')
143+
diff_size=$(git diff --cached | wc -c | tr -d ' ')
133144
if [ "$diff_size" -gt 10000 ]; then
134145
print_warning "Large diff detected (${diff_size} chars). Using fallback."
135146
commit_message="$fallback_message"
136147
else
137-
# Default model
138-
MODEL="gemma3:4b"
148+
# Squish local LLM β€” no API key, no rate limits, no cloud
149+
# Server auto-starts on first use (~20s), then stays alive for near-instant responses
139150

140-
# Optimized prompt - shorter, more direct
141-
PROMPT="Git commit message (max 50 chars, no quotes/formatting):
142-
$(echo "$diff" | head -50)"
151+
# Build model / port flags from config vars (empty = squish auto-detects)
152+
SQUISH_FLAGS=""
153+
if [ -n "$SQUISH_MODEL" ]; then
154+
SQUISH_FLAGS="--model $SQUISH_MODEL"
155+
fi
156+
if [ -n "$SQUISH_PORT" ]; then
157+
SQUISH_FLAGS="$SQUISH_FLAGS --port $SQUISH_PORT"
158+
fi
143159

144-
# Run model with timeout and spinner
145-
print_step "Asking AI for commit message..."
146-
echo "$PROMPT" | timeout $TIMEOUT_SECONDS ollama run "$MODEL" --verbose 2>/dev/null | head -1 > /tmp/commit_msg.txt &
147-
LLM_PID=$!
148-
spinner $LLM_PID
149-
wait $LLM_PID
150-
exit_code=$?
151-
commit_message=$(cat /tmp/commit_msg.txt)
152-
rm -f /tmp/commit_msg.txt
153-
154-
# Check if timeout occurred or empty response
155-
if [ $exit_code -eq 124 ] || [ -z "$commit_message" ]; then
156-
print_warning "LLM timeout. Using fallback message."
160+
# ── Debug: squish availability ───────────────────────────────────────────
161+
SQUISH_BIN=$(command -v squish 2>/dev/null)
162+
if [ -n "$SQUISH_BIN" ]; then
163+
print_info "squish binary: ${CYAN}$SQUISH_BIN${NC}"
164+
else
165+
print_warning "squish not found in PATH β€” will use fallback message"
157166
commit_message="$fallback_message"
167+
# Skip straight to the fallback (jump past the squish block)
168+
fi
169+
170+
if [ -n "$SQUISH_BIN" ]; then
171+
# Show which model / port will be used
172+
if [ -n "$SQUISH_MODEL" ]; then
173+
print_info "squish model: ${CYAN}$SQUISH_MODEL${NC}"
174+
else
175+
print_info "squish model: ${GRAY}auto-detect${NC}"
176+
fi
177+
print_info "squish port: ${CYAN}${SQUISH_PORT:-8000}${NC}"
178+
print_info "squish flags: ${GRAY}${SQUISH_FLAGS:-<none>}${NC}"
179+
180+
# Check if a server is already listening on the port
181+
_port="${SQUISH_PORT:-8000}"
182+
if nc -z 127.0.0.1 "$_port" 2>/dev/null; then
183+
print_info "squish server: ${GREEN}already running on :$_port${NC}"
184+
else
185+
print_info "squish server: ${YELLOW}not running β€” squish will auto-start (first call ~20–90s)${NC}"
186+
fi
187+
echo ""
188+
189+
# Optimized prompt - shorter, more direct
190+
PROMPT="Git commit message (max 50 chars, no quotes/formatting):
191+
$(echo "$diff" | head -50)"
192+
193+
# Run squish with timeout and spinner
194+
print_step "Asking AI for commit message (Squish local LLM)..."
195+
# shellcheck disable=SC2086 # SQUISH_FLAGS intentionally word-splits for multi-flag support
196+
echo "$PROMPT" | timeout $TIMEOUT_SECONDS squish run $SQUISH_FLAGS --max-tokens 60 --temperature 0.2 2>/tmp/squish_stderr.txt | head -1 > /tmp/commit_msg.txt &
197+
LLM_PID=$!
198+
spinner $LLM_PID
199+
wait $LLM_PID
200+
exit_code=$?
201+
202+
# ── Debug: result diagnostics ─────────────────────────────────────────
203+
commit_message=$(cat /tmp/commit_msg.txt 2>/dev/null)
204+
squish_stderr=$(cat /tmp/squish_stderr.txt 2>/dev/null)
205+
rm -f /tmp/commit_msg.txt /tmp/squish_stderr.txt
206+
207+
print_info "squish exit code: ${CYAN}$exit_code${NC}"
208+
if [ -n "$commit_message" ]; then
209+
print_info "squish raw response: ${GREEN}\"$commit_message\"${NC}"
210+
else
211+
print_info "squish raw response: ${RED}<empty>${NC}"
212+
fi
213+
if [ -n "$squish_stderr" ]; then
214+
print_info "squish stderr: ${YELLOW}$(echo "$squish_stderr" | head -3)${NC}"
215+
fi
216+
echo ""
217+
218+
# Check if timeout occurred or empty response
219+
if [ $exit_code -eq 124 ]; then
220+
print_warning "squish timed out after ${TIMEOUT_SECONDS}s. Using fallback message."
221+
commit_message="$fallback_message"
222+
elif [ -z "$commit_message" ]; then
223+
print_warning "squish returned empty response. Using fallback message."
224+
commit_message="$fallback_message"
225+
else
226+
print_success "squish responded successfully"
227+
fi
158228
fi
159229
fi
160230

0 commit comments

Comments
Β (0)