Skip to content

rerades/ai-agent-code-reviewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Agent Code Reviewer

A functional, fully-typed TypeScript code reviewer that leverages functional programming principles and AI analysis to automatically review code.

✨ Features

  • 🎯 Functional Programming with fp-ts
  • πŸ”’ Fully typed with TypeScript (strict mode)
  • πŸ€– AI-powered analysis via OpenAI (ai SDK)
  • πŸ›‘οΈ Robust, composable error handling with Either
  • 🧩 Pure, composable functions and modular architecture

πŸš€ Installation

# Clone the repository
git clone <repository-url>
cd ai-agent-code-reviewer

# Install dependencies
pnpm install

# Environment variables
cp .env.example .env
# Edit .env with your OpenAI API key

πŸ”§ Configuration

Create a .env file with your OpenAI API key:

OPENAI_API_KEY=your_api_key_here

πŸ“‹ Available Scripts

# TypeScript (recommended)
npm run review:functional     # Functional code reviewer
npm run review:examples      # Usage examples
npm run type-check          # Type check only (no JS emit)

# JavaScript (legacy)
npm run review              # Original code reviewer

🎯 Basic Usage

Functional Code Reviewer

# Review a specific file
npm run review:functional test/sample.js

# Or using tsx directly
npx tsx src/code-reviewer-functional.ts your-file.js

Usage Examples

# Run functional usage examples
npm run review:examples test/sample.js

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ types/
β”‚   └── index.ts              # Type definitions
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ error-handling.ts     # Functional error handling utilities
β”‚   └── functional.ts         # Functional helpers
β”œβ”€β”€ examples/
β”‚   └── functional-usage.ts   # Usage examples
└── code-reviewer-functional.ts # Main functional code reviewer

🧠 Functional Programming Principles

βœ… Pure Functions

// Pure function - always returns the same result
export const createTimestamp = (): string => new Date().toISOString();

βœ… Function Composition

// Composition using F.pipe
export const getLanguageFromFilename = F.pipe(getFileExtension, detectLanguage);

βœ… Error Handling with Either

// Either for safe error handling
const result = await safeReadFile(filename);
if (result._tag === "Left") {
  return createFailedReview(filename, result.left.message);
}

βœ… Reusable, Typed Functions

export const analyzeCodeWithAI = async (
  config: CodeReviewerConfig,
  code: string,
  filename: string,
  language: SupportedLanguage
) => {
  /* ... */
};

πŸ” What It Reviews

  1. πŸ› Bugs & Logic Issues

    • Runtime errors
    • Edge cases
    • Off-by-one errors
  2. ⚑ Performance Concerns

    • Inefficient algorithms
    • Memory leaks
    • Unnecessary operations
  3. πŸ”’ Security Issues

    • Input validation
    • SQL injection
    • XSS vulnerabilities
  4. πŸ“ Code Quality

    • Readability
    • Maintainability
    • Best practices
  5. πŸ§ͺ Testing Gaps

    • Missing test cases
    • Untestable patterns

πŸ“Š Sample Output

βœ… Review complete: test/sample.js
πŸ“Œ Code Review Results for test/sample.js
Language: JavaScript
Reviewed: 2025-10-05T11:27:44.676Z

============================================================
### 1. Bugs and Logic Issues
- **Issue Type:** Null check
  - **Location:** Line 2
  - **Problem:** No null check for userData.email
  - **Fix:** Add validation before accessing properties
  - **Priority:** High
============================================================

πŸ› οΈ Development

Type Check

npm run type-check

Core Types

// Main types
interface ReviewResult {
  filename: string;
  language: SupportedLanguage;
  analysis: string;
  timestamp: string;
  success: true;
}

interface ReviewError {
  filename: string;
  error: string;
  timestamp: string;
  success: false;
}

🎨 Advanced Examples

Batch Review

const results = await batchReview([
  "src/utils.ts",
  "src/types.ts",
  "src/main.ts",
]);

Functional Composition

const transformResults = F.pipe(
  results,
  filter(isSuccessfulReview),
  map(getAnalysis),
  join("\n\n")
);

Error Handling

const safeReview = async (filename: string) => {
  const result = await reviewer.reviewFile(filename);
  return result.success ? E.right(result) : E.left(result.error);
};

πŸ”§ TypeScript Configuration

Project is configured with:

  • Strict Mode: Maximum type safety
  • No Emit: Type-checking only (no JS output)
  • ES Modules: Full ESM support
  • Functional Types: Types tailored for FP

πŸ“š Dependencies

Main

  • fp-ts: Functional programming in TypeScript
  • ai: AI SDK
  • @ai-sdk/openai: OpenAI integration

Dev

  • typescript: TypeScript compiler
  • tsx: TypeScript executor
  • @types/node: Node.js types

🀝 Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the ISC License. See the LICENSE file for details.

πŸ™ Acknowledgements

  • fp-ts - Functional programming in TypeScript
  • OpenAI - AI API for code analysis
  • TypeScript - Static type system

Enjoy building in a functional and type-safe way! πŸš€

About

General code reviewer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published