|
| 1 | +# Gemini Code Analysis Agent |
| 2 | + |
| 3 | +This script uses Google's Gemini AI model to analyze code for potential vulnerabilities, best practice deviations, and mathematical instability. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Analyzes code files using the Gemini 2.5 Flash Preview model |
| 8 | +- Provides a Protocol Stability Score (1-10) |
| 9 | +- Identifies potential flaws and security issues |
| 10 | +- Suggests repaired code when issues are found |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Node.js 18+ (which includes built-in fetch support) |
| 15 | +- A Google Gemini API key |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +### Command Line |
| 20 | + |
| 21 | +```bash |
| 22 | +node scripts/gemini_agent.js <filepath> --api-key=<your_key> |
| 23 | +``` |
| 24 | + |
| 25 | +Example: |
| 26 | +```bash |
| 27 | +node scripts/gemini_agent.js ./pkg/model/model.go --api-key=your_gemini_api_key |
| 28 | +``` |
| 29 | + |
| 30 | +### GitHub Actions |
| 31 | + |
| 32 | +The script can be run automatically via GitHub Actions: |
| 33 | + |
| 34 | +1. **Manual Trigger**: Go to Actions → "Gemini Code Analysis" → Run workflow, and specify the file path |
| 35 | +2. **Automatic PR Analysis**: The workflow will automatically analyze changed files in pull requests (if GEMINI_API_KEY secret is configured) |
| 36 | + |
| 37 | +## Setting up the API Key |
| 38 | + |
| 39 | +### For Local Development |
| 40 | + |
| 41 | +```bash |
| 42 | +node scripts/gemini_agent.js path/to/file.go --api-key=YOUR_API_KEY |
| 43 | +``` |
| 44 | + |
| 45 | +### For GitHub Actions |
| 46 | + |
| 47 | +Add `GEMINI_API_KEY` as a repository secret: |
| 48 | + |
| 49 | +1. Go to your repository settings |
| 50 | +2. Navigate to Secrets and variables → Actions |
| 51 | +3. Add a new secret named `GEMINI_API_KEY` |
| 52 | +4. Paste your Google Gemini API key |
| 53 | + |
| 54 | +## Getting a Gemini API Key |
| 55 | + |
| 56 | +1. Visit [Google AI Studio](https://makersuite.google.com/app/apikey) |
| 57 | +2. Sign in with your Google account |
| 58 | +3. Create a new API key |
| 59 | +4. Copy the key for use with this script |
| 60 | + |
| 61 | +## Output |
| 62 | + |
| 63 | +The script will output: |
| 64 | +- Protocol Stability Score (1-10) |
| 65 | +- Summary of potential flaws |
| 66 | +- Repaired code block (if issues are found) |
| 67 | +- "NO REPAIR NEEDED" (if code is perfect) |
| 68 | + |
| 69 | +## Error Handling |
| 70 | + |
| 71 | +The script includes comprehensive error handling: |
| 72 | +- Missing API key: Shows usage instructions |
| 73 | +- Missing file: Shows file read error |
| 74 | +- API failures: Shows detailed error message |
| 75 | +- Network issues: Gracefully handles fetch failures |
| 76 | + |
| 77 | +## Note |
| 78 | + |
| 79 | +This is a conceptual implementation designed for protocol analysis. The script can be extended to: |
| 80 | +- Write repaired code back to files |
| 81 | +- Comment on GitHub PRs with analysis results |
| 82 | +- Support batch analysis of multiple files |
| 83 | +- Integrate with CI/CD pipelines |
0 commit comments