--- description: Dispatch Gemini CLI to analyze large codebases. Gemini does the grunt work with its 1M token context, returns distilled intel to Claude. --- # G-SLAVE: Gemini Large-context Analysis & Verification Engine You are dispatching Gemini CLI as a subordinate tool to analyze code that would bloat your context window. Gemini does the heavy lifting; you receive distilled intelligence. ## Target $ARGUMENTS If no arguments provided, analyze current working directory. ## Execution Protocol ### Step 1: Verify Gemini CLI is Available ```bash which gemini || echo "ERROR: Gemini CLI not installed. Install: https://github.com/google-gemini/gemini-cli" ``` ### Step 2: Check for Agent Configuration Files Before analysis, check if the project has any agent instruction files that Gemini should respect: ```bash # Check for common agent config files ls -la AGENTS.md GEMINI.md CLAUDE.md WARP.md COPILOT.md CURSOR.md CODEX.md README.md CONTRIBUTING.md .github/AGENTS.md .claude/CLAUDE.md 2>/dev/null ``` If found, inform the user: - **GEMINI.md**: Gemini CLI will automatically use this - **Other agent files**: Suggest including them in the prompt with `@AGENTS.md` etc. so Gemini respects the project conventions ### Step 3: Parse Arguments & Determine Mode **Modes:** | Pattern | Mode | Description | |---------|------|-------------| | `/g-slave ` | **Analyze** | Full analysis of target | | `/g-slave ask ""` | **Ask** | Direct question about codebase | | `/g-slave verify ""` | **Verify** | Yes/no verification check | | `/g-slave compare ` | **Compare** | Diff analysis between two targets | **Flags:** | Flag | Effect | |------|--------| | `--arch` | Focus: Architecture, structure, design patterns | | `--security` | Focus: Security vulnerabilities, auth, injection risks | | `--deps` | Focus: Dependencies, imports, coupling analysis | | `--quality` | Focus: Code quality, tech debt, antipatterns | | `--test` | Focus: Test coverage, testing patterns, gaps | | `--perf` | Focus: Performance bottlenecks, optimization opportunities | | `--brief` | Output: ~500 char summary | | `--detailed` | Output: ~5000 char comprehensive breakdown | | `--raw` | Output: Unfiltered Gemini response (no distillation) | | `--save ` | Export: Save analysis to specified file | | `--exclude ` | Ignore: Comma-separated patterns (e.g., `node_modules,dist,.git`) | | `--prompt ""` | Custom: Use provided prompt instead of default | | `--all` | Scope: Use `--all_files` flag for entire project | ### Step 4: Construct Default Exclusions Always recommend excluding these token-wasters unless user specifically needs them: - `node_modules/`, `vendor/`, `venv/`, `.venv/`, `__pycache__/` - `.git/`, `.svn/`, `.hg/` - `dist/`, `build/`, `out/`, `target/` - `*.lock`, `*.log`, `coverage/` Use the `--exclude` flag or advise user to add exclusions to their GEMINI.md. ### Step 5: Execute Gemini Command **CRITICAL: Gemini must operate in READ-ONLY mode. No code execution, no file modifications.** Add to all prompts: `"IMPORTANT: This is a read-only analysis. Do not execute code or modify files."` --- #### Mode: Analyze (default) ```bash gemini -p "@/ IMPORTANT: Read-only analysis only. Analyze this codebase. Focus: . Provide: 1) Architecture overview 2) Key patterns 3) Notable issues 4) Recommendations. Be thorough but concise." ``` #### Mode: Ask ```bash gemini -p "@/ IMPORTANT: Read-only analysis only. Provide a direct, specific answer with file paths and line references where applicable." ``` #### Mode: Verify ```bash gemini -p "@/ IMPORTANT: Read-only analysis only. Verify: . Answer with: YES/NO followed by evidence (file paths, code snippets) supporting your answer." ``` #### Mode: Compare ```bash gemini -p "@/ @/ IMPORTANT: Read-only analysis only. Compare these two codebases/directories. Identify: 1) Structural differences 2) Logic changes 3) Added/removed features 4) Potential issues from changes." ``` #### With Custom Prompt ```bash gemini -p "@/ IMPORTANT: Read-only analysis only. " ``` #### Full Project Scan ```bash gemini --all_files -p "IMPORTANT: Read-only analysis only. " ``` ### Step 6: Detect Framework & Tailor Analysis Before executing, quickly identify the stack and adjust analysis focus: | Detected | Tailor Prompt To Include | |----------|--------------------------| | `package.json` | React/Vue/Node patterns, npm security | | `requirements.txt` / `pyproject.toml` | Django/Flask/FastAPI patterns, Python idioms | | `Cargo.toml` | Rust ownership patterns, unsafe usage | | `go.mod` | Go concurrency patterns, error handling | | `composer.json` | Laravel/Symfony patterns, PHP security | | `Gemfile` | Rails patterns, Ruby idioms | | `pom.xml` / `build.gradle` | Spring patterns, Java architecture | ### Step 7: Distill Results **If `--raw` flag: Skip distillation, return full Gemini output.** Otherwise, extract and present based on verbosity: **--brief (~500 chars):** ```markdown ## Gemini Analysis: <3-4 sentence executive summary covering architecture, main issues, top recommendation> ``` **Default (~2000 chars):** ```markdown ## Gemini Analysis: **Scope:** **Focus:** ### Architecture ### Key Patterns - Pattern 1 - Pattern 2 ### Issues (prioritized) 1. **High:** 2. **Medium:** 3. **Low:** ### Recommendations 1. 2. --- *Analysis via Gemini CLI (1M token context) | Distilled for Claude* ``` **--detailed (~5000 chars):** Include all of the above plus: - Detailed file-by-file breakdown of key components - Dependency analysis with version concerns - Security considerations - Performance observations - Testing gaps - Technical debt inventory ### Step 8: Handle --save Flag If `--save ` provided: 1. Write the analysis output to the specified file 2. Confirm save location to user 3. Still display summary in conversation ```bash # Example save echo "" > ``` ## Response Templates ### For Ask Mode ```markdown ## Answer: **Evidence:** - `path/to/file.py:42` - - `path/to/other.js:17` - --- *Via Gemini CLI | Read-only analysis* ``` ### For Verify Mode ```markdown ## Verification: **Result:** YES / NO / PARTIAL **Evidence:** - - **Location(s):** `file:line`, `file:line` --- *Via Gemini CLI | Read-only analysis* ``` ### For Compare Mode ```markdown ## Comparison: vs ### Structural Differences - - ### Logic Changes - - ### Added/Removed | Added | Removed | |-------|---------| | | | ### Risk Assessment --- *Via Gemini CLI | Read-only analysis* ``` ## Error Handling | Error | Action | |-------|--------| | Gemini CLI not found | Provide install link: https://github.com/google-gemini/gemini-cli | | Path doesn't exist | Report error, ask for correct path | | Analysis timeout | Suggest narrower scope or `--exclude` patterns | | Output too large | Summarize more aggressively (unless `--raw`) | | Rate limited | Inform user, suggest waiting or reducing scope | | Permission denied | Check file permissions, suggest alternatives | ## Usage Examples ```bash # Basic analysis /g-slave src/ # Direct question /g-slave ask "Where is user authentication implemented?" # Verification check /g-slave verify "All API endpoints have rate limiting" # Security audit with exclusions /g-slave . --security --exclude node_modules,dist,coverage # Compare branches (checkout both first) /g-slave compare ./main-branch ./feature-branch # Custom analysis saved to file /g-slave . --prompt "Find all API endpoints and document their HTTP methods, parameters, and auth requirements" --save api-docs.md # Quick overview /g-slave . --brief # Full deep-dive /g-slave . --detailed --save full-analysis.md # Raw Gemini output (no distillation) /g-slave . --arch --raw ``` ## Remember 1. **You are the commander.** Gemini is the grunt. Extract value, don't relay noise. 2. **Read-only always.** Never let Gemini execute or modify. 3. **Distill by default.** Only pass raw output when explicitly requested. 4. **Check for agent files.** Respect project conventions. 5. **Exclude junk.** Don't waste the 1M context on node_modules.