An intelligent code analysis and modification tool built with Mastra framework that can work on any codebase.
- Comprehensive Code Analysis: Understands project structure, languages, and frameworks
- File Operations: Read, write, and edit files with safety checks
- Code Search: Powerful grep and glob pattern matching
- Command Execution: Run bash commands with proper timeouts
- LSP Integration: Get diagnostics, hover info, and symbol information
- Testing Support: Run tests across multiple frameworks
- Web Research: Fetch documentation and resources when needed
- Interactive Mode: Chat with the agent about your codebase
-
Install dependencies:
bun install
-
Set up environment variables:
cp .env.example .env
Edit
.envand add your OpenRouter API key:OPENROUTER_API_KEY=your_openrouter_api_key_here CODE_MODEL=google/gemini-2.5-flash # or anthropic/claude-3.7-sonnetGet your API key from: https://openrouter.ai/keys
Analyze any codebase by providing a folder path:
bun run cli /path/to/your/projectGive the agent a specific task to perform:
bun run cli /path/to/your/project -t "Add error handling to all API calls"Or:
bun run cli /path/to/your/project "Refactor the authentication system"Start an interactive session where you can chat with the agent:
bun run cli /path/to/your/project -i# Use a different AI model
bun run cli /path/to/your/project -m "anthropic/claude-3.7-sonnet"
# Combine task with interactive mode
bun run cli /path/to/your/project -t "Analyze the code quality" -i
# Show help
bun run cli --helpbun run cli ./my-react-appThe agent will:
- Explore the directory structure
- Identify React as the framework
- Check package.json and dependencies
- Look for documentation
- Provide insights about the project structure
bun run cli ./my-api -t "Add input validation to all endpoints"bun run cli ./my-app -t "Find and fix any TypeScript errors" -ibun run cli ./my-project -t "Review the code for security vulnerabilities and performance issues"The code agent has access to these powerful tools:
- readTool: Read files with line limits and offset support
- editTool: Advanced string replacement with fallback strategies
- writeTool: Create new files with directory structure validation
- bashTool: Execute shell commands with safety checks
- grepTool: Text search using ripgrep with regex support
- listTool: Directory listing with tree structure
- globTool: Pattern-based file matching
- webfetchTool: Fetch web content and documentation
- lspDiagnosticsTool: Get syntax errors and type checking
- lspHoverTool: Get symbol information and documentation
- testTool: Run tests using various frameworks
- patchTool: Apply patches and diffs safely
- File Validation: Checks file paths and permissions before operations
- Command Timeouts: Prevents hanging operations
- Safe Execution: Avoids destructive commands
- Backup Creation: Creates backups before applying patches
- Dry-run Mode: Preview changes before applying them
bun testbun run typecheckbun run dev-
Missing API Key:
❌ Error: OPENROUTER_API_KEY environment variable is requiredSolution: Set your OpenRouter API key in the
.envfile -
Folder Not Found:
❌ Error: Folder './my-project' does not existSolution: Check the path and ensure the folder exists
-
Permission Issues: Make sure you have read/write permissions for the target folder
- Use
bun run cli --helpfor command options - Check the OpenRouter API status if you get API errors
- Ensure your API key has sufficient credits
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
ISC License