remcode
Version:
Turn your AI assistant into a codebase expert. Intelligent code analysis, semantic search, and software engineering guidance through MCP integration.
137 lines (136 loc) • 4.13 kB
TypeScript
import { SearchResult, SemanticSearch } from './semantic';
import { EmbeddingManager } from '../vectorizers/embedders/manager';
/**
* Known code patterns that can be detected
*/
export declare enum CodePattern {
ERROR_HANDLING = "error-handling",
ASYNC_AWAIT = "async-await",
CLASS_BASED = "class-based",
FUNCTIONAL = "functional",
SINGLETON = "singleton",
FACTORY = "factory",
OBSERVER = "observer",
MVC = "mvc",
API_CLIENT = "api-client",
DATA_TRANSFORMATION = "data-transformation",
STATE_MANAGEMENT = "state-management"
}
/**
* Type of code segment being analyzed
*/
export type PatternType = 'function' | 'class' | 'module' | 'pattern';
/**
* Result of a similarity analysis
*/
export interface SimilarityResult {
targetCode: string;
similarCode: SearchResult[];
similarityReasons: string[];
patternType: PatternType;
patternName?: string;
confidence: number;
}
/**
* Configuration options for the similarity analyzer
*/
export interface SimilarityOptions {
semanticSearch?: SemanticSearch;
embeddingManager?: EmbeddingManager;
minSimilarity?: number;
enableSemanticSearch?: boolean;
enableSyntaxAnalysis?: boolean;
enablePatternDetection?: boolean;
}
/**
* Analyzes code for similarity and pattern detection
*/
export declare class SimilarityAnalyzer {
private semanticSearch;
private embeddingManager;
private options;
private initialized;
private patterns;
/**
* Creates a new SimilarityAnalyzer
*/
constructor(options?: SimilarityOptions);
/**
* Initialize the analyzer if needed
*/
private ensureInitialized;
/**
* Find code patterns similar to the provided code snippet
* @param codeSnippet The code snippet to analyze
* @param threshold Minimum similarity threshold (0-1)
* @returns Similarity analysis result
*/
findSimilarPatterns(codeSnippet: string, threshold?: number): Promise<SimilarityResult>;
/**
* Calculate overall confidence score
*/
private calculateOverallConfidence;
/**
* Compare the similarity between two code snippets
* @param code1 First code snippet
* @param code2 Second code snippet
* @returns Similarity score (0-1)
*/
compareCodeSimilarity(code1: string, code2: string): Promise<number>;
/**
* Identify code patterns in a file or code content
* @param filePathOrContent Path to the file to analyze or code content directly
* @param isContent Whether the first parameter is content (true) or file path (false)
* @returns Array of detected pattern names
*/
identifyCodePatterns(filePathOrContent: string, isContent?: boolean): Promise<string[]>;
/**
* Find design patterns in a repository
* @param repoPath Path to the repository
* @returns Map of file paths to detected patterns
*/
analyzeRepositoryPatterns(repoPath: string): Promise<Map<string, string[]>>;
/**
* Detect patterns in code
* @param code Code to analyze
* @returns Array of detected pattern names
*/
private detectPatterns;
/**
* Detect the type of code pattern
* @param code Code to analyze
* @returns Pattern type
*/
private detectPatternType;
/**
* Generate reasons why code is similar based on detected patterns
* @param code Code to analyze
* @param detectedPatterns Array of detected patterns
* @returns Array of reasons
*/
private generateSimilarityReasons;
/**
* Extract tokens from code
*/
private extractTokens;
/**
* Calculate similarity between token sets
*/
private calculateTokenSimilarity;
/**
* Calculate similarity between pattern sets
*/
private calculatePatternSimilarity;
/**
* Normalize code for better comparison
*/
private normalizeCode;
/**
* Find all code files in a directory recursively
*/
private findCodeFiles;
/**
* Calculate cosine similarity between two vectors
*/
private cosineSimilarity;
}