Skip to content

API Reference

Complete TypeScript/Node.js API for AI Code Reviewer.

Core Functions

FunctionDescriptionReturns
collectDiff()Parse git diff into structured dataParsedDiff[]
collectCommitDiff()Diff for a single commitParsedDiff[]
detectProject()Detect project type and frameworkProjectInfo
formatFinding()Format finding as Markdownstring
formatReviewReport()Generate full Markdown reportstring
mergeConfig()Merge user config with defaultsReviewerConfig
loadConfigFile()Load .ai-code-reviewer-plus.ymlPartial<ReviewerConfig>

Common Patterns

Basic Diff Collection

typescript
import { collectDiff, detectProject } from 'ai-code-reviewer-plus'

const diffs = await collectDiff({
  root: process.cwd(),
  targetBranch: 'main'
})

console.log(`Files changed: ${diffs.length}`)

for (const diff of diffs) {
  console.log(`${diff.file}: +${diff.additions}/-${diff.deletions}`)
}

Project Detection

typescript
import { detectProject } from 'ai-code-reviewer-plus'

const project = await detectProject(process.cwd())

console.log(`Type: ${project.type}`)
console.log(`Framework: ${project.framework || 'N/A'}`)
console.log(`Language: ${project.language}`)
console.log(`Package Manager: ${project.packageManager || 'N/A'}`)

Configuration Management

typescript
import { mergeConfig, loadConfigFile } from 'ai-code-reviewer-plus'

const userConfig = loadConfigFile(process.cwd())
const config = mergeConfig(userConfig)

console.log(`Enabled rules: ${config.rules.enabled.length}`)
console.log(`Excluded paths: ${config.excludePaths.length}`)

Error Handling

typescript
import { GitCommandError, ConfigError } from 'ai-code-reviewer-plus'

try {
  const diffs = await collectDiff({ root, targetBranch })
} catch (error) {
  if (error instanceof GitCommandError) {
    console.error(`Git command failed: ${error.message}`)
  } else if (error instanceof ConfigError) {
    console.error(`Config error: ${error.message}`)
  }
}

Type Safety

All APIs are fully typed with TypeScript:

typescript
import type {
  ParsedDiff,
  ProjectInfo,
  ReviewerConfig,
  ReviewFinding,
  SeverityLevel,
} from 'ai-code-reviewer-plus'

See Types for detailed type definitions.

MIT License