# gemini-cli > Auto-triggers after code changes. Implements quality gates (>=85 standard, >=90 security) with Gemini CLI review and automatic fix iterations. - Author: Lushano Perera - Repository: lushanoperera/claude-code - Version: 20260207230041 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-08 - Source: https://github.com/lushanoperera/claude-code - Web: https://mule.run/skillshub/@@lushanoperera/claude-code~gemini-cli:20260207230041 --- --- name: gemini-cli description: Auto-triggers after code changes. Implements quality gates (>=85 standard, >=90 security) with Gemini CLI review and automatic fix iterations. context: fork allowed-tools: Task, Read, Bash, mcp__memory-bank__*, mcp__knowledge-graph__* hooks: Stop: - type: command command: "echo 'QUALITY_GATE: Review complete'" timeout: 5 --- # Gemini CLI Skill ## When to Activate Auto-invokes when: - After writing or modifying significant code - Before committing changes to git - Before creating pull requests - After completing feature implementation - When reviewing security-critical code paths - Before deploying to production ## Purpose Enforce quality standards through automated, quantifiable code review: 1. Score code quality using Gemini CLI 2. **HARD BLOCK** if below threshold (no bypass) 3. Iterate: review -> auto-fix -> re-review until passing 4. Escalate to human after max iterations ## Model Configuration Model is auto-selected by Gemini's model router (`useModelRouter: true` in `~/.gemini/settings.json`). **DO NOT** use `-m` flag in commands - let the model router choose the best model per task. ## Background Execution (v2.0.60+) Run quality gates asynchronously: ```python Task( subagent_type="quality-reviewer", run_in_background=True, prompt="Run quality gate with threshold 85 for recent changes. Report when complete." ) ``` Check status with `TaskOutput(task_id="[id]", block=False)`. ## Critical Requirements ### MANDATORY: 1-Hour Bash Timeout All Gemini CLI commands MUST use timeout=3600000ms: ```python Bash( command='gemini -p "..." -o json', timeout=3600000 ) ``` ### Quality Thresholds (HARD BLOCK) | Code Type | Minimum Score | Enforcement | | ----------------------- | ------------- | ----------- | | Standard | >=85 | HARD BLOCK | | Security-Critical | >=90 | HARD BLOCK | | Critical Infrastructure | >=90 | HARD BLOCK | **NO BYPASS**: Work cannot proceed until threshold is met. ## Instructions ### Phase 1: Initial Review Run Gemini CLI to score the code: ```bash # Quality review with JSON output gemini -p "Review code quality for the following changes. Analyze: 1. Code correctness and logic 2. Security vulnerabilities (OWASP Top 10) 3. Performance considerations 4. Maintainability and readability 5. Error handling completeness 6. Test coverage adequacy Provide a JSON response with: - score: integer 0-100 - breakdown: object with category scores - issues: array of issues found - passed: boolean based on 85 threshold Files changed: $(git diff --name-only HEAD~1) Changes: $(git diff HEAD~1)" -o json ``` ### Phase 2: Score Extraction Parse the JSON response: ```bash # Extract score from JSON SCORE=$(echo "$RESPONSE" | jq '.score') PASSED=$(echo "$RESPONSE" | jq '.passed') ISSUES=$(echo "$RESPONSE" | jq '.issues') ``` ### Phase 3: Threshold Check (HARD BLOCK) **Standard Code (threshold: 85)**: ```bash if [ "$SCORE" -lt 85 ]; then echo "BLOCKED: Score $SCORE is below threshold 85" echo "Quality gate FAILED - must fix before proceeding" # Proceed to Phase 4 (Auto-Fix) fi ``` **Security-Critical Code (threshold: 90)**: ```bash if [ "$SCORE" -lt 90 ]; then echo "BLOCKED: Security-critical score $SCORE is below threshold 90" echo "Quality gate FAILED - must fix before proceeding" # Proceed to Phase 4 (Auto-Fix) fi ``` ### Phase 4: Auto-Fix Iteration Apply targeted fixes: ```bash # Extract top issues TOP_ISSUES=$(echo "$ISSUES" | jq -r '.[0:5] | .[].description') # Apply fixes with auto_edit mode gemini --approval-mode auto_edit -p "Fix these code quality issues: $TOP_ISSUES Apply minimal, targeted fixes only. Do not refactor beyond what is necessary." ``` ### Phase 5: Re-Review Loop Repeat Phase 1-4 until threshold met: ```bash MAX_ITERATIONS=5 ITERATION=1 while [ "$SCORE" -lt "$THRESHOLD" ] && [ "$ITERATION" -le "$MAX_ITERATIONS" ]; do echo "Iteration $ITERATION: Score $SCORE, Target $THRESHOLD" # Run auto-fix # ... (Phase 4) # Re-review # ... (Phase 1) ITERATION=$((ITERATION + 1)) done ``` ### Phase 6: Final Disposition After loop completion: **PASS**: Score meets threshold ```bash echo "PASSED: Quality gate achieved with score $SCORE" # Proceed with commit/PR/deploy ``` **ESCALATE**: Max iterations exceeded ```bash echo "ESCALATE: Score $SCORE after $MAX_ITERATIONS iterations" echo "Requires human review before proceeding" # Block and notify ``` ## Gemini CLI Commands ### Basic Quality Review ```bash gemini -p "Review code quality. Score out of 100." -o json ``` ### Detailed Category Breakdown ```bash gemini -p "Review code with category scores: - Correctness (0-25): Logic, bugs, edge cases - Security (0-25): Vulnerabilities, auth, data handling - Performance (0-25): Efficiency, scalability, resources - Maintainability (0-25): Readability, structure, tests Total score out of 100. Output as JSON." -o json ``` ### Security-Focused Review ```bash gemini -p "Security audit for code: 1. Injection vulnerabilities (SQL, XSS, Command) 2. Authentication/Authorization flaws 3. Sensitive data exposure 4. Security misconfiguration 5. OWASP Top 10 compliance Score out of 100. Flag CRITICAL issues." -o json ``` ### Auto-Fix Mode ```bash gemini --approval-mode auto_edit "Fix these issues: [ISSUES FROM REVIEW]" ``` ## Background Quality Gate Pattern Run quality gate in background while continuing work: ```python # Start background quality check Task( subagent_type="quality-reviewer", run_in_background=True, prompt="""Run quality gate: - Threshold: 85 (or 90 for security-critical) - Hard block until pass - Max 5 iterations - Report final score and disposition""" ) # Continue with other work... # Later, check results TaskOutput(task_id="[task-id]", block=True) ``` ## Guidelines ### DO: - Always use `-o json` for reliable score parsing - Set 3600000ms timeout on all Bash commands - Hard block on threshold failure - Limit iterations to 5 maximum - Escalate to human after max iterations - Log all quality gate decisions - Use security threshold (90) for auth/payment/data code - Use background execution for non-blocking reviews ### DON'T: - Bypass quality gates for any reason - Use short timeouts - Skip re-review after auto-fix - Ignore CRITICAL severity issues - Proceed without passing threshold - Run more than 5 iterations (escalate instead) - Use `-m` flag to specify model (use config instead) ### Determining Security-Critical Code Apply >=90 threshold for: - Authentication/authorization code - Payment processing - Personal data handling - Cryptographic operations - API security (CORS, rate limiting) - Session management - Input validation at boundaries ## Integration with Other Skills ### security-engineer (Agent) Quality gate complements detailed review: 1. `security-engineer` for comprehensive analysis 2. `gemini-cli` for pass/fail scoring ### quality-reviewer (Agent) Invoke for specialized operations: ```python Task( subagent_type="quality-reviewer", model="sonnet", run_in_background=True, prompt="Run quality gate with threshold 85 for recent changes" ) ``` ### security-engineer (Agent) Chain with security audit: 1. Quality gate PASS (>=90 for security code) 2. Then `security-engineer` for comprehensive audit ### plan-critique (Skill) Quality gates validate implementation: 1. `plan-critique` validates plan 2. Implement feature 3. `gemini-cli` validates implementation ## Output Format ### Quality Gate Report ```markdown # Quality Gate Report ## Summary - **Score**: 87/100 - **Threshold**: 85 - **Status**: PASSED - **Iterations**: 2 ## Breakdown | Category | Score | Max | | --------------- | ----- | --- | | Correctness | 23 | 25 | | Security | 22 | 25 | | Performance | 21 | 25 | | Maintainability | 21 | 25 | ## Issues Fixed (Iteration 1) - HIGH: Unsanitized input in query builder - MEDIUM: Missing null check in parser ## Final Disposition Quality gate PASSED. Ready for commit/PR. ``` ## Performance Expectations | Operation | Time | Notes | | ------------------------------ | --------- | -------------------- | | Initial review | 2-5 min | Depends on diff size | | Auto-fix iteration | 3-5 min | Per iteration | | Full quality gate (pass) | 5-10 min | Single iteration | | Full quality gate (iterations) | 15-25 min | Multiple iterations | | Security audit addition | +5-10 min | For critical code | ## Error Handling ### JSON Parsing Failure If JSON output is malformed: 1. Re-run with explicit JSON format instruction 2. Fall back to text parsing for score 3. Escalate to human if still failing ### Timeout (Unlikely) If 1-hour timeout exceeded: 1. Break review into smaller chunks 2. Review files individually 3. Check network connectivity ### Auto-Fix Failures If auto-fix doesn't improve score: 1. Extract specific issue descriptions 2. Apply more targeted fix prompts 3. Escalate after 5 iterations ## Memory Persistence Record quality gate results: ```python # Log to Memory Bank mcp__memory-bank__memory_bank_write( project="current-project", file="quality-review-results.md", content=f""" # Quality Gate: {feature} - Date: {timestamp} - Score: {score} - Threshold: {threshold} - Status: {'PASSED' if score >= threshold else 'BLOCKED'} - Iterations: {iterations} """ ) # Record in Knowledge Graph mcp__knowledge-graph__aim_memory_add_facts( observations=[{ "entityName": "Feature_" + feature_name, "contents": [f"Quality gate: {score}/100, {'PASSED' if passed else 'BLOCKED'}"] }] ) ``` --- _Updated: 2026-02-02 - Fixed model config schema for v0.26.0 (object format)_