/** * Smart AST Grep Tool - 83% Token Reduction through Pattern Indexing * * Achieves token reduction through: * 1. AST index caching (parse once, query many times) * 2. Pattern-based result caching (common patterns reuse results) * 3. Incremental indexing (only reindex changed files) * 4. Match-only output (return only matching nodes, not full AST) * 5. Intelligent cache invalidation (file hash-based) * * Target: 83% reduction vs running ast-grep each time */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface SmartAstGrepOptions { pattern: string; language?: 'ts' | 'tsx' | 'js' | 'jsx' | 'py' | 'go' | 'rs' | 'java' | 'c' | 'cpp'; projectPath: string; filePattern?: string; excludePatterns?: string[]; enableCache?: boolean; ttl?: number; contextLines?: number; maxMatches?: number; includeContext?: boolean; respectGitignore?: boolean; incrementalIndexing?: boolean; } export interface AstMatch { file: string; line: number; column: number; match: string; context?: { before: string[]; after: string[]; }; nodeType: string; } export interface SmartAstGrepResult { matches: AstMatch[]; metadata: { pattern: string; language: string; filesScanned: number; filesIndexed: number; matchCount: number; fromCache: boolean; cacheHit: boolean; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; executionTime: number; indexStats?: { indexAge: number; reindexedFiles: number; cachedFiles: number; }; }; suggestions?: string[]; } export declare class SmartAstGrepTool { private cache; private tokenCounter; private metrics; private static readonly INDEX_VERSION; private static readonly DEFAULT_TTL; private static readonly COMMON_PATTERNS; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart AST grep with pattern indexing */ grep(pattern: string, options: SmartAstGrepOptions): Promise; /** * Create new AST index for project */ private createIndex; /** * Update AST index incrementally (only changed files) */ private updateIndex; /** * Execute ast-grep on indexed files */ private executeAstGrep; /** * Find source files in project */ private findSourceFiles; /** * Check if path should be excluded */ private shouldExclude; /** * Get file extensions for language */ private getExtensionsForLanguage; /** * Detect language from pattern or project */ private detectLanguage; /** * Generate cache key for AST index */ private generateIndexKey; /** * Generate cache key for pattern search */ private generatePatternKey; /** * Load AST index from cache */ private loadIndex; /** * Cache AST index */ private cacheIndex; /** * Cache pattern search result */ private cachePatternResult; /** * Estimate tokens saved by index */ private estimateTokensSaved; /** * Format full output (baseline for token comparison) */ private formatFullOutput; /** * Format compact output (optimized for tokens) */ private formatCompactOutput; /** * Generate pattern suggestions based on index */ private generatePatternSuggestions; /** * Record metrics */ private recordMetrics; } /** * Factory function to create SmartAstGrepTool instance */ export declare function getSmartAstGrepTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartAstGrepTool; /** * Main entry point for smart ast-grep */ export declare function runSmartAstGrep(pattern: string, options: SmartAstGrepOptions, cache?: CacheEngine, tokenCounter?: TokenCounter, metrics?: MetricsCollector): Promise; /** * MCP Tool Definition for smart-ast-grep */ export declare const SMART_AST_GREP_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { pattern: { type: string; description: string; }; projectPath: { type: string; description: string; }; language: { type: string; enum: string[]; description: string; }; filePattern: { type: string; description: string; }; excludePatterns: { type: string; items: { type: string; }; description: string; }; contextLines: { type: string; default: number; description: string; }; maxMatches: { type: string; default: number; description: string; }; enableCache: { type: string; default: boolean; description: string; }; }; required: string[]; }; }; //# sourceMappingURL=smart-ast-grep.d.ts.map