/** * Smart Grep Tool - 80% Token Reduction * * Achieves token reduction through: * 1. Match-only output (line numbers + matched text, not full files) * 2. Context line control (configurable before/after lines) * 3. Pattern caching (reuse search results) * 4. Result pagination (limit matches returned) * 5. Smart file filtering (skip binary, node_modules, etc.) * * Target: 80% reduction vs returning full file contents */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface GrepMatch { file: string; lineNumber: number; column?: number; line: string; match: string; before?: string[]; after?: string[]; } export interface SmartGrepOptions { cwd?: string; files?: string[]; caseSensitive?: boolean; wholeWord?: boolean; regex?: boolean; extensions?: string[]; excludeExtensions?: string[]; skipBinary?: boolean; ignore?: string[]; includeContext?: boolean; contextBefore?: number; contextAfter?: number; includeColumn?: boolean; maxMatchesPerFile?: number; limit?: number; offset?: number; filesWithMatches?: boolean; count?: boolean; useCache?: boolean; ttl?: number; maxFileSize?: number; encoding?: BufferEncoding; } export interface SmartGrepResult { success: boolean; pattern: string; metadata: { totalMatches: number; filesSearched: number; filesWithMatches: number; returnedMatches: number; truncated: boolean; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; duration: number; cacheHit: boolean; }; matches?: GrepMatch[]; files?: string[]; counts?: Map; error?: string; } export declare class SmartGrepTool { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart grep with match-only output and context control */ grep(pattern: string, options?: SmartGrepOptions): Promise; /** * Build search pattern from string */ private buildPattern; /** * Check if a file is binary */ private isBinaryFile; /** * Get grep statistics */ getStats(): { totalSearches: number; cacheHits: number; totalTokensSaved: number; averageReduction: number; }; } /** * Get smart grep tool instance */ export declare function getSmartGrepTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartGrepTool; /** * CLI function - Creates resources and uses factory */ export declare function runSmartGrep(pattern: string, options?: SmartGrepOptions): Promise; /** * MCP Tool Definition */ export declare const SMART_GREP_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { pattern: { type: string; description: string; }; cwd: { type: string; description: string; }; files: { type: string; items: { type: string; }; description: string; }; caseSensitive: { type: string; description: string; default: boolean; }; regex: { type: string; description: string; default: boolean; }; extensions: { type: string; items: { type: string; }; description: string; }; includeContext: { type: string; description: string; default: boolean; }; contextBefore: { type: string; description: string; default: number; }; contextAfter: { type: string; description: string; default: number; }; limit: { type: string; description: string; }; filesWithMatches: { type: string; description: string; default: boolean; }; count: { type: string; description: string; default: boolean; }; }; required: string[]; }; }; //# sourceMappingURL=smart-grep.d.ts.map