@@ -17,6 +17,8 @@ SQUISH_MODEL="${SQUISH_MODEL:-}"
1717# Squish server port — override if you run multiple squish servers concurrently.
1818SQUISH_PORT=" ${SQUISH_PORT:- 8000} "
1919
20+ # test
21+
2022# Colors
2123RED=' \033[0;31m'
2224GREEN=' \033[0;32m'
139141# Get the git diff (staged changes vs last commit) - truncate for performance
140142diff=$( git diff --cached | head -c $MAX_DIFF_CHARS )
141143
142- # Skip LLM if diff is too large (use fallback)
143- diff_size=$( git diff --cached | wc -c | tr -d ' ' )
144- if [ " $diff_size " -gt 10000 ]; then
145- print_warning " Large diff detected (${diff_size} chars). Using fallback."
146- commit_message=" $fallback_message "
144+ # Squish local LLM — no API key, no rate limits, no cloud
145+ # Server auto-starts on first use (~20s), then stays alive for near-instant responses
146+
147+ # Build model / port flags from config vars (empty = squish auto-detects)
148+ SQUISH_FLAGS=" "
149+ if [ -n " $SQUISH_MODEL " ]; then
150+ SQUISH_FLAGS=" --model $SQUISH_MODEL "
151+ fi
152+ if [ -n " $SQUISH_PORT " ]; then
153+ SQUISH_FLAGS=" $SQUISH_FLAGS --port $SQUISH_PORT "
154+ fi
155+
156+ # ── Debug: squish availability ───────────────────────────────────────────
157+ SQUISH_BIN=$( command -v squish 2> /dev/null)
158+ if [ -n " $SQUISH_BIN " ]; then
159+ print_info " squish binary: ${CYAN} $SQUISH_BIN ${NC} "
147160else
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
161+ print_warning " squish not found in PATH — will use fallback message"
162+ commit_message=" $fallback_message "
163+ fi
150164
151- # Build model / port flags from config vars (empty = squish auto-detects)
152- SQUISH_FLAGS= " "
165+ if [ -n " $SQUISH_BIN " ] ; then
166+ # Show which model / port will be used
153167 if [ -n " $SQUISH_MODEL " ]; then
154- SQUISH_FLAGS=" --model $SQUISH_MODEL "
168+ print_info " squish model: ${CYAN} $SQUISH_MODEL ${NC} "
169+ else
170+ print_info " squish model: ${GRAY} auto-detect${NC} "
155171 fi
156- if [ -n " $SQUISH_PORT " ]; then
157- SQUISH_FLAGS=" $SQUISH_FLAGS --port $SQUISH_PORT "
172+ print_info " squish port: ${CYAN}${SQUISH_PORT:- 8000}${NC} "
173+ print_info " squish flags: ${GRAY}${SQUISH_FLAGS:- <none>}${NC} "
174+
175+ # Check if a server is already listening on the port
176+ _port=" ${SQUISH_PORT:- 8000} "
177+ if nc -z 127.0.0.1 " $_port " 2> /dev/null; then
178+ print_info " squish server: ${GREEN} already running on :$_port ${NC} "
179+ else
180+ print_info " squish server: ${YELLOW} not running — squish will auto-start (first call ~20–90s)${NC} "
158181 fi
182+ echo " "
159183
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} "
184+ # Prompt — send full diff, truncated only at MAX_DIFF_CHARS for token sanity
185+ PROMPT=" Git commit message (max 50 chars, no quotes/formatting):
186+ $diff "
187+
188+ # Run squish with timeout and spinner
189+ print_step " Asking AI for commit message (Squish local LLM)..."
190+ # shellcheck disable=SC2086 # SQUISH_FLAGS intentionally word-splits for multi-flag support
191+ 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 &
192+ LLM_PID=$!
193+ spinner $LLM_PID
194+ wait $LLM_PID
195+ exit_code=$?
196+
197+ # ── Debug: result diagnostics ─────────────────────────────────────────
198+ commit_message=$( cat /tmp/commit_msg.txt 2> /dev/null)
199+ squish_stderr=$( cat /tmp/squish_stderr.txt 2> /dev/null)
200+ rm -f /tmp/commit_msg.txt /tmp/squish_stderr.txt
201+
202+ print_info " squish exit code: ${CYAN} $exit_code ${NC} "
203+ if [ -n " $commit_message " ]; then
204+ print_info " squish raw response: ${GREEN} \" $commit_message \" ${NC} "
164205 else
165- print_warning " squish not found in PATH — will use fallback message"
166- commit_message=" $fallback_message "
167- # Skip straight to the fallback (jump past the squish block)
206+ print_info " squish raw response: ${RED} <empty>${NC} "
207+ fi
208+ if [ -n " $squish_stderr " ]; then
209+ print_info " squish stderr: ${YELLOW} $( echo " $squish_stderr " | head -3) ${NC} "
168210 fi
211+ echo " "
169212
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
213+ # Check if timeout occurred or empty response
214+ if [ $exit_code -eq 124 ]; then
215+ print_warning " squish timed out after ${TIMEOUT_SECONDS} s. Using fallback message."
216+ commit_message=" $fallback_message "
217+ elif [ -z " $commit_message " ]; then
218+ print_warning " squish returned empty response. Using fallback message."
219+ commit_message=" $fallback_message "
220+ else
221+ print_success " squish responded successfully"
228222 fi
229223fi
230224
0 commit comments