Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: update AI reviewer to download script from FAIR repository

LearningCircuitd17aca439d75
diff --git a/.github/workflows/ai-code-reviewer.yml b/.github/workflows/ai-code-reviewer.yml
index 28fa12de19..5ae60af2b4 100644
--- a/.github/workflows/ai-code-reviewer.yml
+++ b/.github/workflows/ai-code-reviewer.yml
@@ -6,7 +6,7 @@ on:
jobs:
comprehensive-review:
- name: 🤖 AI Code Review
+ name: AI Code Review
runs-on: ubuntu-latest
if: github.event.action == 'labeled' && github.event.label.name == 'ai_code_review'
permissions:
@@ -30,13 +30,18 @@ jobs:
git fetch origin ${{ github.event.pull_request.base.ref }}
git diff origin/${{ github.event.pull_request.base.ref }}...HEAD --no-color > diff.txt
+ - name: Download AI reviewer script
+ run: |
+ curl -fsSL https://raw.githubusercontent.com/LearningCircuit/Friendly-AI-Reviewer/main/ai-reviewer.sh -o ai-reviewer.sh
+ chmod +x ai-reviewer.sh
+
- name: AI Code Review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
- AI_MODEL: ${{ vars.AI_MODEL || 'z-ai/glm-4.6' }}
+ AI_MODEL: ${{ vars.AI_MODEL || 'moonshotai/kimi-k2-thinking' }}
AI_TEMPERATURE: ${{ vars.AI_TEMPERATURE || '0.1' }}
- AI_MAX_TOKENS: ${{ vars.AI_MAX_TOKENS || '2000' }}
+ AI_MAX_TOKENS: ${{ vars.AI_MAX_TOKENS || '64000' }}
MAX_DIFF_SIZE: ${{ vars.MAX_DIFF_SIZE || '800000' }}
EXCLUDE_FILE_PATTERNS: ${{ vars.EXCLUDE_FILE_PATTERNS || '*.lock,*.min.js,*.min.css,package-lock.json,yarn.lock' }}
PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -46,12 +51,13 @@ jobs:
run: |
# Run the AI reviewer and save response to file
echo "Running AI code review..."
- AI_RESPONSE=$(bash ai-reviewer.sh < diff.txt)
+ AI_RESPONSE=$(cat diff.txt | bash ai-reviewer.sh)
- # Save response for debugging (only in debug mode)
+ # Output raw response for debugging (only in debug mode)
if [ "$DEBUG_MODE" = "true" ]; then
- echo "Debug: AI response saved to ai_response.txt"
- echo "$AI_RESPONSE" > ai_response.txt
+ echo "=== RAW AI RESPONSE FOR DEBUG ==="
+ echo "$AI_RESPONSE"
+ echo "=== END RAW AI RESPONSE ==="
fi
# Check if AI_RESPONSE is empty
@@ -63,8 +69,28 @@ jobs:
# Parse JSON response
if ! echo "$AI_RESPONSE" | jq . >/dev/null 2>&1; then
echo "⚠️ AI response is not valid JSON. Cannot process review."
+
+ # Log raw response for debugging (only in debug mode)
+ if [ "$DEBUG_MODE" = "true" ]; then
+ echo "=== DEBUG: Raw AI Response (first 2000 chars) ==="
+ echo "$AI_RESPONSE" | head -c 2000
+ echo ""
+ echo "=== END DEBUG ==="
+
+ # Try to extract JSON from thinking model response
+ if echo "$AI_RESPONSE" | grep -q '"content"'; then
+ echo "=== DEBUG: Attempting to extract content from response ==="
+ EXTRACTED_CONTENT=$(echo "$AI_RESPONSE" | jq -r '.choices[0].message.content // empty' 2>/dev/null || echo "")
+ if [ -n "$EXTRACTED_CONTENT" ]; then
+ echo "Extracted content (first 1000 chars):"
+ echo "$EXTRACTED_CONTENT" | head -c 1000
+ echo ""
+ fi
+ fi
+ fi
+
# Don't post raw response as it may contain sensitive data
- echo "AI response could not be processed. Please check the workflow logs." | gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} -F -
+ echo "AI response could not be processed. Please check the workflow logs for debugging information (enable DEBUG_MODE to see details)." | gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} -F -
exit 1
fi
@@ -92,14 +118,11 @@ jobs:
fi
done
- # Handle workflow decision
+ # Handle workflow decision (after posting review and labels)
echo "AI decision: $DECISION"
- if [ "$FAIL_ON_REQUESTED_CHANGES" = "true" ] && [ "$DECISION" = "fail" ]; then
- echo "❌ AI requested changes and FAIL_ON_REQUESTED_CHANGES is enabled. Failing workflow."
- exit 1
- fi
- echo "✅ AI review completed successfully"
+ # Store the decision for later use
+ echo "DECISION=$DECISION" >> $GITHUB_ENV
# Remove the ai_code_review label to make re-triggering easier
echo "Removing ai_code_review label to allow easy re-triggering"
@@ -109,6 +132,15 @@ jobs:
echo "Failed to remove ai_code_review label (may have been already removed)"
fi
+ echo "✅ AI review completed successfully"
+
+ - name: Fail Workflow if Requested
+ if: env.FAIL_ON_REQUESTED_CHANGES == 'true' && env.DECISION == 'fail'
+ run: |
+ echo "❌ AI requested changes and FAIL_ON_REQUESTED_CHANGES is enabled. Failing workflow."
+ echo "The review has been posted above. Please address the requested changes."
+ exit 1
+
- name: Cleanup
if: always()
run: |
diff --git a/ai-reviewer.sh b/ai-reviewer.sh
deleted file mode 100755
index 1d6060092f..0000000000
--- a/ai-reviewer.sh
+++ /dev/null
@@ -1,249 +0,0 @@
-#!/bin/bash
-
-# AI Code Reviewer Script - Simple Comment Version
-# Usage: OPENROUTER_API_KEY=xxx AI_MODEL=model AI_TEMPERATURE=0.1 AI_MAX_TOKENS=2000 echo "DIFF_CONTENT" | ./ai-reviewer.sh
-
-set -e
-
-
-# Get API key from environment variable
-API_KEY="${OPENROUTER_API_KEY}"
-
-if [ -z "$API_KEY" ]; then
- echo "## 🤖 AI Code Review
-
-❌ **Error**: Missing OPENROUTER_API_KEY environment variable"
- exit 1
-fi
-
-# Configuration with defaults
-AI_MODEL="${AI_MODEL:-z-ai/glm-4.6}"
-AI_TEMPERATURE="${AI_TEMPERATURE:-0.1}"
-AI_MAX_TOKENS="${AI_MAX_TOKENS:-2000}"
-MAX_DIFF_SIZE="${MAX_DIFF_SIZE:-800000}" # 800KB default limit (~200K tokens, matching model context size)
-EXCLUDE_FILE_PATTERNS="${EXCLUDE_FILE_PATTERNS:-*.lock,*.min.js,*.min.css,package-lock.json,yarn.lock}"
-
-# Read diff content from stdin
-DIFF_CONTENT=$(cat)
-
-if [ -z "$DIFF_CONTENT" ]; then
- echo "## 🤖 AI Code Review
-
-❌ **Error**: No diff content to analyze"
- exit 1
-fi
-
-# Simple exclude file patterns filter
-if [ -n "$EXCLUDE_FILE_PATTERNS" ]; then
- FILTERED_DIFF=$(mktemp)
- echo "$DIFF_CONTENT" | grep -v -E "diff --git a/($(echo "$EXCLUDE_FILE_PATTERNS" | sed 's/,/|/g' | sed 's/\*/\\*/g')) b/" > "$FILTERED_DIFF" 2>/dev/null || true
- if [ -s "$FILTERED_DIFF" ]; then
- DIFF_CONTENT=$(cat "$FILTERED_DIFF")
- fi
- rm -f "$FILTERED_DIFF"
-fi
-
-# Validate diff size to prevent excessive API usage
-DIFF_SIZE=${#DIFF_CONTENT}
-if [ "$DIFF_SIZE" -gt "$MAX_DIFF_SIZE" ]; then
- echo "## 🤖 AI Code Review
-
-❌ **Error**: Diff is too large ($DIFF_SIZE bytes, max: $MAX_DIFF_SIZE bytes)
-Please split this PR into smaller changes for review."
- exit 1
-fi
-
-# Fetch previous AI review comments for context (if PR_NUMBER and REPO_FULL_NAME are set)
-PREVIOUS_REVIEWS=""
-if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
- # Fetch comments that start with "## 🤖 AI Code Review"
- PREVIOUS_REVIEWS=$(gh api "repos/$REPO_FULL_NAME/issues/$PR_NUMBER/comments" \
- --jq '.[] | select(.body | startswith("## 🤖 AI Code Review")) | "### Previous Review (" + .created_at + "):\n" + .body + "\n---\n"' 2>/dev/null | head -c 50000 || echo "")
-fi
-
-# Fetch GitHub Actions check runs status (if PR_NUMBER and REPO_FULL_NAME are set)
-CHECK_RUNS_STATUS=""
-if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
- # Get the head SHA of the PR
- HEAD_SHA=$(gh api "repos/$REPO_FULL_NAME/pulls/$PR_NUMBER" --jq '.head.sha' 2>/dev/null || echo "")
-
- if [ -n "$HEAD_SHA" ]; then
- # Fetch check runs for this commit
- CHECK_RUNS_STATUS=$(gh api "repos/$REPO_FULL_NAME/commits/$HEAD_SHA/check-runs" \
- --jq '.check_runs // [] | .[] | "- **\(.name)**: \(.status)\(if .conclusion then " (\(.conclusion))" else "" end)"' 2>/dev/null || echo "")
- fi
-fi
-
-# Fetch available repository labels (if PR_NUMBER and REPO_FULL_NAME are set)
-AVAILABLE_LABELS=""
-if [ -n "$PR_NUMBER" ] && [ -n "$REPO_FULL_NAME" ] && [ -n "$GITHUB_TOKEN" ]; then
- # Fetch all labels from the repository
- echo "🔍 Fetching available labels from repository..." >&2
- AVAILABLE_LABELS=$(gh api "repos/$REPO_FULL_NAME/labels" --paginate 2>/dev/null \
- --jq '.[] | "- **\(.name)**: \(.description // "No description") (color: #\(.color))"' || echo "")
-
- if [ -n "$AVAILABLE_LABELS" ]; then
- LABEL_COUNT=$(echo "$AVAILABLE_LABELS" | wc -l)
- echo "✅ Successfully fetched $LABEL_COUNT labels from repository" >&2
- else
- echo "ℹ️ No existing labels found in repository or API call failed" >&2
- fi
-fi
-
-# Create the JSON request with proper escaping using jq
-# Write diff to temporary file to avoid "Argument list too long" error
-DIFF_FILE=$(mktemp)
-echo "$DIFF_CONTENT" > "$DIFF_FILE"
-
-# Build the user prompt using the diff file
-PROMPT_PREFIX="Please analyze this code diff and provide a comprehensive review in markdown format:
-
-Focus Areas:
-- Security: Look for hardcoded secrets, SQL injection, XSS, authentication issues, input validation problems
-- Performance: Check for inefficient algorithms, N+1 queries, missing indexes, memory issues, blocking operations
-- Code Quality: Evaluate readability, maintainability, proper error handling, naming conventions, documentation
-- Best Practices: Ensure adherence to coding standards, proper patterns, type safety, dead code removal
-"
-
-# Add GitHub Actions check status if available
-if [ -n "$CHECK_RUNS_STATUS" ]; then
- PROMPT_PREFIX="${PROMPT_PREFIX}
-GitHub Actions Check Status:
-$CHECK_RUNS_STATUS
-
-Please consider any failed or pending checks in your review. If tests are failing, investigate whether the code changes might be the cause.
-"
-fi
-
-# Add available labels context if available
-if [ -n "$AVAILABLE_LABELS" ]; then
- PROMPT_PREFIX="${PROMPT_PREFIX}
-Available Repository Labels:
-Please prefer using existing labels from this list over creating new ones:
-$AVAILABLE_LABELS
-
-If none of these labels are appropriate for the changes, you may suggest new ones.
-"
-fi
-
-# Add previous reviews context if available
-if [ -n "$PREVIOUS_REVIEWS" ]; then
- PROMPT_PREFIX="${PROMPT_PREFIX}
-Previous AI Reviews (for context on what was already reviewed):
-$PREVIOUS_REVIEWS
-"
-fi
-
-PROMPT_PREFIX="${PROMPT_PREFIX}
-Code diff to analyze:
-
-"
-
-# Create a simple text prompt
-# Read diff content
-DIFF_CONTENT=$(cat "$DIFF_FILE")
-
-# Simple text prompt
-PROMPT="Please analyze this code diff and provide a comprehensive review.
-
-Focus on security, performance, code quality, and best practices.
-
-IMPORTANT: Respond with valid JSON only using this exact format:
-{
- \"review\": \"Detailed review in markdown format\",
- \"fail_pass_workflow\": \"pass\",
- \"labels_added\": [\"bug\", \"feature\", \"enhancement\"]
-}
-
-Focus action items on critical fixes only, not trivial nitpicks.
-
-IMPORTANT: End your review with a clear final assessment section like:
----
-## Final Assessment: APPROVED / CHANGES REQUESTED / NEEDS REVISION
-
-Code to review:
-$PROMPT_PREFIX
-
-$DIFF_CONTENT"
-
-
-# Clean up diff file
-rm -f "$DIFF_FILE"
-
-# Make API call to OpenRouter with simple JSON
-# Use generic or repo-specific referer
-REFERER_URL="https://github.com/${REPO_FULL_NAME:-unknown/repo}"
-RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
- -H "Content-Type: application/json" \
- -H "Authorization: Bearer $API_KEY" \
- -H "HTTP-Referer: $REFERER_URL" \
- -d "{
- \"model\": \"$AI_MODEL\",
- \"messages\": [
- {
- \"role\": \"user\",
- \"content\": $(echo "$PROMPT" | jq -Rs .)
- }
- ],
- \"temperature\": $AI_TEMPERATURE,
- \"max_tokens\": $AI_MAX_TOKENS
- }")
-
-# Check if API call was successful
-if [ -z "$RESPONSE" ]; then
- echo '{"review":"## 🤖 AI Code Review\n\n❌ **Error**: API call failed - no response received","fail_pass_workflow":"uncertain","labels_added":[]}'
- exit 1
-fi
-
-# Check if response is valid JSON
-if ! echo "$RESPONSE" | jq . >/dev/null 2>&1; then
- echo '{"review":"## 🤖 AI Code Review\n\n❌ **Error**: Invalid JSON response from API","fail_pass_workflow":"uncertain","labels_added":[]}'
- exit 1
-fi
-
-# Extract the content
-CONTENT=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // "error"')
-
-if [ "$CONTENT" = "error" ]; then
- # Try to extract error details from the API response
- ERROR_MSG=$(echo "$RESPONSE" | jq -r '.error.message // "Invalid API response format"')
- ERROR_CODE=$(echo "$RESPONSE" | jq -r '.error.code // ""')
-
- # Return error as JSON
- ERROR_CONTENT="## 🤖 AI Code Review\n\n❌ **Error**: $ERROR_MSG"
- if [ -n "$ERROR_CODE" ]; then
- ERROR_CONTENT="$ERROR_CONTENT\n\nError code: \`$ERROR_CODE\`"
- fi
- ERROR_CONTENT="$ERROR_CONTENT\n\n---\n*Review by [FAIR](https://github.com/LearningCircuit/Friendly-AI-Reviewer) - needs human verification*"
-
- echo "{\"review\":\"$ERROR_CONTENT\",\"fail_pass_workflow\":\"uncertain\",\"labels_added\":[]}"
-
- # Don't log full response as it may contain sensitive API data
- # Only log error code for debugging
- if [ -n "$ERROR_CODE" ]; then
- echo "API Error code: $ERROR_CODE" >&2
- fi
- exit 1
-fi
-
-# Ensure CONTENT is not empty
-if [ -z "$CONTENT" ]; then
- echo '{"review":"## 🤖 AI Code Review\n\n❌ **Error**: AI returned empty response","fail_pass_workflow":"uncertain","labels_added":[]}'
- exit 0
-fi
-
-# Validate that CONTENT is valid JSON
-if ! echo "$CONTENT" | jq . >/dev/null 2>&1; then
- # If not JSON, wrap it in JSON structure
- JSON_CONTENT="{\"review\":\"## 🤖 AI Code Review\n\n$CONTENT\n\n---\n*Review by [FAIR](https://github.com/LearningCircuit/Friendly-AI-Reviewer) - needs human verification*\",\"fail_pass_workflow\":\"uncertain\",\"labels_added\":[]}"
- echo "$JSON_CONTENT"
-else
- # If already JSON, validate it has the required structure
- if ! echo "$CONTENT" | jq -e '.review' >/dev/null 2>&1; then
- JSON_CONTENT="{\"review\":\"## 🤖 AI Code Review\n\n$CONTENT\n\n---\n*Review by [FAIR](https://github.com/LearningCircuit/Friendly-AI-Reviewer) - needs human verification*\",\"fail_pass_workflow\":\"uncertain\",\"labels_added\":[]}"
- echo "$JSON_CONTENT"
- else
- # If already valid JSON with required structure, return as-is
- echo "$CONTENT"
- fi
-fi