@bobmatnyc/ai-code-review
Version:
A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter
185 lines (184 loc) • 5.56 kB
TypeScript
/**
* @fileoverview Review context for maintaining state between review passes.
*
* This module provides a class for maintaining context between multiple review passes.
* It stores information about the review, including file metadata, important code elements,
* and findings from previous passes.
*/
import { FileInfo } from '../../types/review';
/**
* Type of code element tracked in the context
*/
export declare enum CodeElementType {
Function = "function",
Class = "class",
Interface = "interface",
Variable = "variable",
Import = "import",
ExportedItem = "exported",
Component = "component",
EntryPoint = "entryPoint"
}
/**
* A code element tracked in the context
*/
export interface CodeElement {
/** Type of code element */
type: CodeElementType;
/** Name of the code element */
name: string;
/** File where the element is defined */
file: string;
/** Short description or signature of the element */
signature?: string;
/** Importance score (higher = more important) */
importance: number;
}
/**
* A review finding from a previous pass
*/
export interface ReviewFinding {
/** Type of finding (e.g., 'bug', 'security', 'performance') */
type: string;
/** Short description of the finding */
description: string;
/** File where the finding was located */
file?: string;
/** Severity of the finding (higher = more severe) */
severity: number;
/** Pass number where this finding was identified */
passNumber: number;
}
/**
* Summary of a file from previous review passes
*/
export interface FileSummary {
/** Path to the file */
path: string;
/** File type or extension */
type: string;
/** Short description of the file purpose */
description: string;
/** Key elements in this file (e.g., classes, functions) */
keyElements: string[];
/** Pass number when this summary was created */
passNumber: number;
}
/**
* Context for multi-pass reviews
*/
export declare class ReviewContext {
/** Project name */
private projectName;
/** Review type */
private reviewType;
/** All files involved in the review */
private allFiles;
/** Current pass number */
private currentPass;
/** Important code elements tracked across passes */
private codeElements;
/** Findings from previous passes */
private findings;
/** File summaries from previous passes */
private fileSummaries;
/** General notes about the codebase */
private generalNotes;
/** Timestamp when context was created */
private createdAt;
/** Timestamp of last update */
private updatedAt;
/**
* Create a new review context
* @param projectName Name of the project
* @param reviewType Type of review
* @param files Files involved in the review
*/
constructor(projectName: string, reviewType: string, files: FileInfo[]);
/**
* Start a new review pass
* @returns Updated pass number
*/
startPass(): number;
/**
* Get the current pass number
* @returns Current pass number
*/
getCurrentPass(): number;
/**
* Add a code element to the context
* @param element Code element to add
*/
addCodeElement(element: CodeElement): void;
/**
* Get all tracked code elements
* @returns Array of code elements
*/
getCodeElements(): CodeElement[];
/**
* Get code elements of a specific type
* @param type Type of code elements to get
* @returns Array of code elements of the specified type
*/
getCodeElementsByType(type: CodeElementType): CodeElement[];
/**
* Get code elements in a specific file
* @param filePath Path of the file
* @returns Array of code elements in the file
*/
getCodeElementsInFile(filePath: string): CodeElement[];
/**
* Add a review finding
* @param finding Review finding to add
*/
addFinding(finding: ReviewFinding): void;
/**
* Get all findings
* @returns Array of all findings
*/
getFindings(): ReviewFinding[];
/**
* Add or update a file summary
* @param summary File summary to add
*/
addFileSummary(summary: FileSummary): void;
/**
* Get summary for a specific file
* @param filePath Path of the file
* @returns File summary or undefined if not found
*/
getFileSummary(filePath: string): FileSummary | undefined;
/**
* Get summaries for all files
* @returns Array of file summaries
*/
getAllFileSummaries(): FileSummary[];
/**
* Add a general note about the codebase
* @param note Note to add
*/
addGeneralNote(note: string): void;
/**
* Get all general notes
* @returns Array of general notes
*/
getGeneralNotes(): string[];
/**
* Generate a contextual prompt for the next pass
* @param files Files to include in the next pass
* @param maxContextLength Maximum length of context in characters
* @returns Formatted context string for inclusion in the next prompt
*/
generateNextPassContext(files: string[], maxContextLength?: number): string;
/**
* Serialize the context to JSON
* @returns JSON representation of the context
*/
toJSON(): object;
/**
* Create a review context from JSON
* @param json JSON object
* @returns New ReviewContext instance
*/
static fromJSON(json: Record<string, unknown>): ReviewContext;
}