UNPKG

@bobmatnyc/ai-code-review

Version:

A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter

761 lines (760 loc) 25.2 kB
/** * @fileoverview Schema for unused code review structured output. * * This module defines the schema for structured output from the unused code review, * using Zod for schema validation and LangChain for parsing. */ import { z } from 'zod'; import { StructuredOutputParser } from '@langchain/core/output_parsers'; /** * Risk level for removing unused code */ export type RiskLevel = 'high' | 'medium' | 'low'; /** * Impact level for unused code issues */ export type ImpactLevel = 'high' | 'medium' | 'low'; /** * Schema for an unused code issue */ export declare const UnusedCodeIssueSchema: z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>; /** * Schema for the complete unused code review result */ export declare const UnusedCodeReviewSchema: z.ZodObject<{ /** * Array of high impact unused code issues */ highImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Array of medium impact unused code issues */ mediumImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Array of low impact unused code issues */ lowImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Summary of the unused code review */ summary: z.ZodString; /** * General recommendations for preventing unused code */ recommendations: z.ZodArray<z.ZodString, "many">; }, "strip", z.ZodTypeAny, { summary: string; recommendations: string[]; highImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; mediumImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; lowImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; }, { summary: string; recommendations: string[]; highImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; mediumImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; lowImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; }>; /** * Type for an unused code issue */ export type UnusedCodeIssue = z.infer<typeof UnusedCodeIssueSchema>; /** * Type for the complete unused code review result */ export type UnusedCodeReview = z.infer<typeof UnusedCodeReviewSchema>; /** * LangChain parser for unused code review output */ export declare const unusedCodeReviewParser: StructuredOutputParser<z.ZodObject<{ /** * Array of high impact unused code issues */ highImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Array of medium impact unused code issues */ mediumImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Array of low impact unused code issues */ lowImpactIssues: z.ZodArray<z.ZodObject<{ /** * Title/name of the unused code issue */ title: z.ZodString; /** * Detailed description of the unused code issue */ description: z.ZodString; /** * Location information (file and line numbers) */ location: z.ZodObject<{ file: z.ZodOptional<z.ZodString>; lineStart: z.ZodOptional<z.ZodNumber>; lineEnd: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }, { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }>; /** * Assessment of confidence that this code is truly unused */ assessment: z.ZodString; /** * Suggested action (remove or keep with explanation) */ suggestedAction: z.ZodString; /** * Risk level of removing this code */ riskLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Impact level of the issue */ impactLevel: z.ZodEnum<["high", "medium", "low"]>; /** * Category of unused code */ category: z.ZodEnum<["deadCode", "redundantCode", "deprecatedFeature", "featureFlag", "other"]>; }, "strip", z.ZodTypeAny, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }, { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }>, "many">; /** * Summary of the unused code review */ summary: z.ZodString; /** * General recommendations for preventing unused code */ recommendations: z.ZodArray<z.ZodString, "many">; }, "strip", z.ZodTypeAny, { summary: string; recommendations: string[]; highImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; mediumImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; lowImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; }, { summary: string; recommendations: string[]; highImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; mediumImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; lowImpactIssues: { description: string; location: { file?: string | undefined; lineStart?: number | undefined; lineEnd?: number | undefined; }; title: string; assessment: string; suggestedAction: string; riskLevel: "high" | "medium" | "low"; impactLevel: "high" | "medium" | "low"; category: "other" | "deadCode" | "redundantCode" | "deprecatedFeature" | "featureFlag"; }[]; }>>; /** * Get format instructions for the unused code review parser * @returns Format instructions string */ export declare function getUnusedCodeReviewFormatInstructions(): string;