/** * Local Intelligence Service * * Pure local implementations of code intelligence features. * Uses SQLite (LocalDatabase) + Git + AST parsing. * NO cloud dependencies. * * Features: * - Entity evolution tracking (git history) * - Semantic drift detection (signature hashing) * - Code analysis (AST-based) * - Pattern detection (regex/AST) * - Codebase summary * - Smart routing (help_me) * - Session management */ import { LocalDatabase } from './local-db.js'; export interface EntitySnapshot { entityId: string; name: string; type: 'class' | 'function' | 'interface' | 'type' | 'method'; filePath: string; line: number; signature: string; signatureHash: string; bodyHash: string; commitHash: string; commitDate: Date; changeType: 'created' | 'modified' | 'renamed' | 'deleted'; } export interface EntityEvolution { entityName: string; entityType: string; filePath: string; currentSignature: string; totalVersions: number; createdAt: string; lastModifiedAt: string; stabilityScore: number; changes: EntityChange[]; renames: { from: string; to: string; at: string; commit: string; }[]; } export interface EntityChange { date: string; commitHash: string; changeType: 'signature' | 'body' | 'rename' | 'created' | 'deleted'; description: string; author?: string; } export interface SemanticDrift { type: 'signature_change' | 'return_type_change' | 'param_change' | 'major_rewrite'; from: string; to: string; at: string; commitHash: string; isBreaking: boolean; } export interface DriftAnalysis { entityName: string; entityType: string; filePath: string; driftRisk: number; drifts: SemanticDrift[]; recommendation: string; stabilityScore: number; } export interface CodeAnalysis { filePath: string; language: string; structure: { classes: ClassInfo[]; functions: FunctionInfo[]; interfaces: InterfaceInfo[]; imports: string[]; exports: string[]; }; complexity: { lines: number; codeLines: number; commentLines: number; functionCount: number; classCount: number; avgFunctionLength: number; maxFunctionLength: number; cyclomaticComplexity: number; }; patterns: DetectedPattern[]; smells: CodeSmell[]; insights: string[]; } export interface ClassInfo { name: string; line: number; methods: string[]; properties: string[]; extends?: string; implements?: string[]; } export interface FunctionInfo { name: string; line: number; params: string[]; returnType?: string; isAsync: boolean; isExported: boolean; length: number; } export interface InterfaceInfo { name: string; line: number; properties: string[]; extends?: string[]; } export interface DetectedPattern { name: string; confidence: number; location: string; description: string; } export interface CodeSmell { type: string; severity: 'low' | 'medium' | 'high'; location: string; message: string; suggestion: string; } export interface CodebaseSummary { projectName: string; techStack: string[]; structure: { totalFiles: number; totalLines: number; byLanguage: Record; directories: string[]; }; recentActivity: { lastCommit: string; commitsThisWeek: number; activeFiles: string[]; }; conventions: string[]; hotspots: string[]; } export interface SessionState { projectId: string; startedAt: string; lastActivity: string; summary: string; accomplishments: string[]; pendingItems: string[]; filesModified: string[]; decisionsCount: number; errorsFixed: number; } export declare class LocalIntelligence { private db; private projectRoot; private gitRoot; constructor(db: LocalDatabase, projectRoot?: string); /** * Find the git repository root directory */ private findGitRoot; /** * Convert an absolute path to a path relative to git root */ private toGitRelativePath; /** * Convert a relative path to absolute, resolving from project root */ private toAbsolutePath; /** * Get evolution history of a function/class using git history */ getEntityEvolution(projectId: string, entityName: string, filePath?: string): Promise; /** * Find entities that change frequently (unstable) */ getUnstableEntities(projectId: string, threshold?: number, limit?: number): Promise<{ entityName: string; filePath: string; changeCount: number; stabilityScore: number; }[]>; /** * Detect semantic drift in an entity */ detectSemanticDrift(projectId: string, entityName: string, filePath?: string): Promise; /** * Analyze code structure, patterns, and smells */ analyzeCode(code: string, filePath?: string, sections?: ('structure' | 'complexity' | 'patterns' | 'smells' | 'insights')[]): CodeAnalysis; /** * Extract code structure (classes, functions, interfaces) */ private extractStructure; /** * Calculate code complexity metrics */ private calculateComplexity; /** * Detect common design patterns */ private detectPatterns; /** * Detect code smells */ private detectSmells; /** * Generate insights from analysis */ private generateInsights; /** * Get comprehensive codebase summary */ getCodebaseSummary(projectId: string): CodebaseSummary; /** * Route a natural language question to the appropriate tool * Uses priority-based matching with more specific patterns first */ routeQuestion(intent: string, files?: string[]): { suggestedTool: string; reasoning: string; parameters: Record; }; /** * Get session state for resumption */ getSessionState(projectId: string): SessionState | null; /** * Get what changed since last session */ getWhatChanged(projectId: string, since?: string): { commits: { hash: string; message: string; date: string; author: string; }[]; newDecisions: number; newFixes: number; summary: string; }; /** * Detect evolution patterns in the codebase */ getEvolutionPatterns(projectId: string, patternType?: string): { type: string; description: string; entities: string[]; recommendation: string; }[]; private findEntityFile; private getGitLogForFile; private getFileAtCommit; private extractEntityFromContent; private extractAllEntities; private extractFunctionBody; private extractClassBody; private extractMethodNames; private extractPropertyNames; private extractInterfaceProperties; private extractParams; private extractReturnType; private describeParamChange; private calculateStabilityScore; private calculateDriftRisk; private generateDriftRecommendation; private createCurrentOnlyEvolution; private getFrequentlyChangedFiles; private findCoChangedFiles; private getAllSourceFiles; private detectLanguage; private extractEntityFromIntent; } export declare function createLocalIntelligence(db: LocalDatabase, projectRoot?: string): LocalIntelligence; //# sourceMappingURL=local-intelligence.d.ts.map