Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:52:28 +08:00
commit 0b3ba5ad8e
8 changed files with 929 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
# Gemini CLI Quick Reference
Minimal reference for using Gemini CLI with this skill. For complete documentation, see [official Gemini CLI docs](https://github.com/google-gemini/gemini-cli).
## Installation
**macOS (Recommended):**
```bash
brew install gemini-cli
```
**Cross-Platform (npm):**
```bash
npm install -g @google/gemini-cli
```
**Verify:**
```bash
gemini --version # Should show v0.17.0+
```
## Authentication
⚠️ **IMPORTANT:** Gemini CLI must be authenticated before using this skill. Claude Code will NOT configure authentication for you.
**Prerequisites:**
- Gemini CLI installed and authenticated
- Test that `gemini "test" -o text` works
**Setup instructions:** See the [official Gemini CLI documentation](https://github.com/google-gemini/gemini-cli) for authentication setup.
**If this skill fails with auth errors:**
- Complete authentication setup manually using official docs
- Verify with: `gemini "test" -o text`
- Then retry using the skill
## Basic Usage
**For code review:**
```bash
gemini "Review this code for security issues: [code]" -o text
```
**For web research:**
```bash
gemini "What's new in React 19? Use Google Search." -o text
```
**For architecture analysis:**
```bash
gemini "Use codebase_investigator to analyze this project" -o text
```
## Common Options
Run `gemini --help` for complete list. Key options used by this skill:
- `-o text` - Human-readable output (default for consulting)
- `-o json` - Structured output with stats
- `-m gemini-2.5-flash` - Faster model for simple tasks
## More Information
- **Full CLI reference:** `gemini --help`
- **Official documentation:** https://github.com/google-gemini/gemini-cli
- **Models, configuration, troubleshooting:** See official docs above

View File

@@ -0,0 +1,274 @@
# Gemini CLI Integration Patterns
**Core Principle:** Claude Code handles all code writing, file operations, and commands. Gemini provides consulting (second opinions) and search capabilities.
---
## Pattern 1: Cross-Validation (Primary Pattern)
Leverage both AIs for highest quality by using their complementary strengths.
### Claude Generates, Gemini Reviews
```bash
# 1. Claude writes code (using normal Claude Code tools)
# (Claude generates the code directly)
# 2. Get Gemini's review
gemini "Review this code for bugs and security issues:
[paste code Claude wrote]
Provide specific findings with severity levels." -o text
# 3. Claude implements fixes based on Gemini's feedback
# (Claude makes the changes)
```
### Gemini Researches, Claude Implements
```bash
# 1. Gemini researches best practices
gemini "Use Google Search to find current best practices for [topic]. Summarize key recommendations." -o text
# 2. Claude implements based on research
# (Claude writes the code following the recommendations)
# 3. Optional: Gemini reviews implementation
gemini "Review this implementation of [topic]. Does it follow best practices found earlier?" -o text
```
### Gemini Analyzes Architecture, Claude Refactors
```bash
# 1. Gemini maps the codebase
gemini "Use codebase_investigator to analyze this project's architecture. Identify areas needing improvement." -o text
# 2. Claude refactors based on analysis
# (Claude makes the architectural changes)
# 3. Gemini validates changes
gemini "Use codebase_investigator again. Has the architecture improved?" -o text
```
### Complementary Strengths
- **Claude:** Complex reasoning, following instructions, writing code, file operations
- **Gemini:** Current web knowledge, Google Search access, deep codebase investigation
---
## Pattern 2: JSON Output for Analysis
Use JSON output to programmatically process Gemini's analysis results.
```bash
gemini "Review [file] for security issues" -o json 2>&1
```
### Parsing Response
```python
import json
result = json.loads(output)
analysis = result["response"]
tokens_used = result["stats"]["models"]["gemini-3-pro"]["tokens"]["total"]
tools_used = result["stats"]["tools"]["byName"]
```
### Use Cases
- Extract specific security findings
- Track analysis costs (token usage)
- Monitor tool usage (google_web_search, codebase_investigator)
- Build automated review pipelines
---
## Pattern 3: Model Selection Strategy
Choose the appropriate Gemini model for the consultation type.
### Decision Tree
```
Is this deep architecture analysis or complex codebase review?
├── Yes → Use default (Gemini 3 Pro)
└── No → Is it a quick web search or simple review?
├── Yes → Use gemini-2.5-flash
└── No → Use gemini-2.5-flash
```
### Examples
```bash
# Deep analysis: Use Pro (default)
gemini "Use codebase_investigator to analyze authentication architecture" -o text
# Quick search: Use Flash
gemini "What's the latest version of React? Use Google Search." -m gemini-2.5-flash -o text
# Code review: Use Flash for faster feedback
gemini "Quick review of this function for obvious bugs" -m gemini-2.5-flash -o text
```
---
## Pattern 4: Rate Limit Management
Strategies for working within Gemini's free tier limits (60/min, 1000/day).
### Let Auto-Retry Handle It
Default behavior - CLI retries automatically with backoff.
### Use Flash for Lower Priority
```bash
# Critical review: Use Pro
gemini "Security review of authentication system" -o text
# Less critical: Use Flash (separate quota)
gemini "Quick opinion on this variable naming" -m gemini-2.5-flash -o text
```
### Batch Related Questions
```bash
# Instead of multiple calls:
gemini "Review file A"
gemini "Review file B"
gemini "Review file C"
# Single batched call:
gemini "Review files A, B, and C. For each file, identify bugs and security issues." -o text
```
---
## Pattern 5: Context Enrichment
Provide rich context for better analysis.
### Using File References
```bash
gemini "Based on @./package.json and @./src/auth.js, review the authentication implementation for security issues." -o text
```
### Using GEMINI.md
Create `.gemini/GEMINI.md` for persistent context:
```markdown
# Project Context
This is a Python project using:
- Framework: FastAPI
- Database: SQLAlchemy with PostgreSQL
- Testing: pytest
## Review Guidelines
- Follow PEP 8 style guidelines
- Check for type hints (PEP 484)
- Verify async/await patterns
```
### Explicit Context in Prompt
```bash
gemini "Given this context:
- Python 3.11+ with FastAPI
- Using async/await patterns
- Type hints required
Review this module for type safety and Python best practices." -o text
```
---
## Pattern 6: Session Continuity for Iterative Analysis
Use sessions for multi-turn consultations.
```bash
# Initial analysis
gemini "Use codebase_investigator to analyze this project's architecture" -o text
# Session saved automatically
# List available sessions
gemini --list-sessions
# Continue analysis in same session
echo "What patterns did you find in the authentication flow?" | gemini -r 1 -o text
# Further refinement
echo "Are there any security concerns with that pattern?" | gemini -r 1 -o text
```
### Use Cases
- Iterative architecture analysis
- Multi-step security reviews
- Building on previous research findings
---
## Pattern 7: Validation of Recommendations
Always validate Gemini's recommendations before implementing.
### Validation Steps
1. **Verify Against Official Docs**
- Gemini's web search may find outdated information
- Cross-reference with official documentation
2. **Test Recommendations**
- Don't blindly implement security suggestions
- Verify they work in your specific context
3. **Review for Context**
- Gemini may miss project-specific constraints
- Ensure recommendations fit your architecture
4. **Get Multiple Opinions**
- For critical changes, consult multiple sources
- Use Claude's reasoning to evaluate Gemini's suggestions
---
## Best Practices
### Do: Use Gemini For
- ✓ Code review and security audits
- ✓ Web research for current information
- ✓ Architecture analysis with codebase_investigator
- ✓ Second opinions on design decisions
- ✓ Error diagnosis and troubleshooting
- ✓ Best practice research
### Don't: Use Gemini For
- ✗ Primary code generation (that's Claude's job)
- ✗ File operations (use Claude's tools)
- ✗ Running commands (use Claude's Bash tool)
- ✗ Direct bug fixes (Claude should fix, Gemini reviews)
- ✗ Building features (Claude builds, Gemini consults)
### Remember
- **Claude writes code, Gemini provides feedback**
- **Claude operates files, Gemini analyzes them**
- **Claude implements, Gemini validates**
---
## Anti-Patterns to Avoid
### Don't: Use Gemini as Primary Code Generator
Gemini can generate code, but that's not its role in this skill. Claude Code is better suited for following complex instructions and integrating with your workflow.
**Do**: Have Claude generate code, then get Gemini's review for a second perspective.
### Don't: Ignore Rate Limits
Hammering the API wastes time on retries.
**Do**: Use appropriate models and batch related questions.
### Don't: Trust Recommendations Blindly
Gemini can provide outdated or context-inappropriate suggestions.
**Do**: Validate recommendations against official docs and your project context.
### Don't: Over-Specify in Single Prompt
Extremely long prompts can confuse the model.
**Do**: Break complex analyses into focused questions.
### Don't: Forget Project Context
Gemini doesn't automatically know your project conventions.
**Do**: Use `.gemini/GEMINI.md` or explicit context in prompts for better analysis.

View File

@@ -0,0 +1,168 @@
# Gemini CLI Prompt Templates
**Important:** Gemini provides consulting and search services. Claude Code remains responsible for all code writing, file operations, and command execution.
Use these templates for:
- **Code review** (second opinions)
- **Web research** (current information)
- **Architecture analysis** (codebase investigation)
---
## Code Review
### Comprehensive Review
```bash
gemini "Review [file] that Claude Code wrote and tell me:
1) What features it has
2) Any bugs or security issues
3) Suggestions for improvement
4) Code quality assessment" -o text
```
### Security-Focused Review
```bash
gemini "Review [file] for security vulnerabilities including:
- XSS (cross-site scripting)
- SQL injection
- Command injection
- Insecure data handling
- Authentication issues
Report findings with severity levels." -o text
```
### Performance Review
```bash
gemini "Analyze [file] for performance issues:
- Inefficient algorithms
- Memory leaks
- Unnecessary re-renders
- Blocking operations
- Optimization opportunities
Provide specific recommendations." -o text
```
### Code Quality Assessment
```bash
gemini "Assess code quality of [file]:
- Readability and maintainability
- Adherence to best practices
- Potential technical debt
- Suggested improvements" -o text
```
---
## Web Research
### Current Information
```bash
gemini "What are the latest [topic] as of [date]? Use Google Search to find current information. Summarize key points." -o text
```
### Library/API Research
```bash
gemini "Research [library/API] and provide:
- Latest version and changes
- Best practices
- Common patterns
- Gotchas to avoid
Use Google Search for current information." -o text
```
### Comparison Research
```bash
gemini "Compare [option A] vs [option B] for [use case]. Use Google Search for current benchmarks and community opinions. Provide recommendation." -o text
```
### Security Vulnerability Research
```bash
gemini "What are the known security vulnerabilities in [library] version [x.y.z]? Use Google Search. Include CVE numbers and severity ratings." -o text
```
### Best Practices Research
```bash
gemini "What are the current best practices for [topic] as of [date]? Use Google Search to find recent articles and official documentation." -o text
```
---
## Architecture Analysis
### Project Analysis
```bash
gemini "Use the codebase_investigator tool to analyze this project. Report on:
- Overall architecture
- Key dependencies
- Component relationships
- Potential issues" -o text
```
### Dependency Analysis
```bash
gemini "Analyze dependencies in this project:
- Direct vs transitive
- Outdated packages
- Security vulnerabilities
- Bundle size impact
Use available tools to gather information." -o text
```
### Flow Analysis
```bash
gemini "Use codebase_investigator to map the [authentication/payment/data] flow in this project. Identify all components involved." -o text
```
### Technical Debt Assessment
```bash
gemini "Use codebase_investigator to identify potential technical debt:
- Deprecated patterns
- Inconsistent conventions
- Missing documentation
- Complex dependencies" -o text
```
---
## Code Explanation
### Detailed Explanation
```bash
gemini "Explain what [file/function] does in detail:
- Purpose and use case
- How it works step by step
- Key algorithms/patterns used
- Dependencies and side effects" -o text
```
### Error Diagnosis
```bash
gemini "Diagnose this error:
[error message]
Context: [relevant context]
Provide:
- Root cause
- Recommended solution approach
- Prevention tips" -o text
```
### Design Pattern Identification
```bash
gemini "Analyze [file/codebase] and identify the design patterns being used. Explain their purpose and effectiveness." -o text
```
---
## Template Variables
Use these placeholders in templates:
- `[file]` - File path or name
- `[directory]` - Directory path
- `[library/API]` - Library or API name
- `[topic]` - Subject matter for research
- `[date]` - Date for time-sensitive queries
- `[use case]` - Specific use case scenario
- `[option A/B]` - Options to compare
- `[error message]` - Error text
- `[context]` - Relevant contextual information

View File

@@ -0,0 +1,133 @@
# Gemini CLI Built-in Tools
Gemini's unique capabilities and tool comparison with Claude Code.
## Unique Tools (Gemini Only)
### google_web_search
Real-time internet search via Google Search API.
**Usage:**
```bash
gemini "What are the latest React 19 features? Use Google Search." -o text
```
**Best For:**
- Current events and news
- Latest library versions/documentation
- Community opinions and benchmarks
- Anything requiring post-cutoff information
**Examples:**
- "What are the security vulnerabilities in lodash 4.x? Use Google Search."
- "Best practices for Next.js 14 app router in November 2025."
---
### codebase_investigator
Deep architectural analysis and dependency mapping.
**Usage:**
```bash
gemini "Use codebase_investigator to analyze this project" -o text
```
**Output Includes:**
- Architecture overview
- Component relationships
- Dependency chains
- Potential issues/inconsistencies
**Best For:**
- Onboarding to unfamiliar codebases
- Understanding legacy systems
- Finding hidden dependencies
- Architecture documentation
**Example:**
```bash
gemini "Use codebase_investigator to map the authentication flow" -o text
```
---
### save_memory
Cross-session persistent memory storage.
**Usage:**
```bash
gemini "Remember that this project uses Zustand for state management. Save this to memory." -o text
```
**Best For:**
- Project conventions
- User preferences
- Recurring context
- Custom instructions
---
## Tool Comparison
Gemini has standard file/search tools similar to Claude Code, plus unique capabilities:
| Capability | Claude Code | Gemini CLI |
|------------|-------------|------------|
| File listing | LS, Glob | list_directory, glob |
| File reading | Read | read_file |
| Code search | Grep | search_file_content |
| Web fetch | WebFetch | web_fetch |
| **Web search** | WebSearch | **google_web_search** ⭐ |
| **Architecture** | Task (Explore) | **codebase_investigator** ⭐ |
| **Memory** | N/A | **save_memory** ⭐ |
| Task tracking | TodoWrite | write_todos |
⭐ = Gemini's unique advantages
---
## JSON Output Stats
When using `-o json`, tool usage is reported in stats:
```json
{
"response": "actual content",
"stats": {
"tools": {
"totalCalls": 3,
"byName": {
"google_web_search": {
"count": 1,
"success": 1,
"durationMs": 3000
}
}
}
}
}
```
---
## Tool Combination Patterns
Leverage multiple tools in single prompts:
**Research → Implement:**
```bash
gemini "Use Google Search to find best practices for [topic], then implement them" -o text
```
**Analyze → Report:**
```bash
gemini "Use codebase_investigator to analyze the project, then write a summary report" -o text
```
**Search → Suggest:**
```bash
gemini "Find all files using deprecated API, read them, and suggest updates" -o text
```