UNPKG

@ooples/token-optimizer-mcp

Version:

Intelligent context window optimization for Claude Code - store content externally via caching and compression, freeing up your context window for what matters

177 lines 4.62 kB
/** * Smart Diff Tool - 85% Token Reduction * * Achieves token reduction through: * 1. Diff-only output (only changed lines, not full files) * 2. Summary mode (counts only, not actual diffs) * 3. File filtering (specific files or patterns) * 4. Context control (configurable lines before/after changes) * 5. Git-based caching (reuse diff results based on commit hashes) * * Target: 85% reduction vs full file content for changed files */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface DiffStats { file: string; additions: number; deletions: number; changes: number; } export interface SmartDiffOptions { cwd?: string; source?: string; target?: string; staged?: boolean; files?: string[]; filePattern?: string; summaryOnly?: boolean; contextLines?: number; unified?: boolean; includeLineNumbers?: boolean; includeBinary?: boolean; showRenames?: boolean; limit?: number; offset?: number; useCache?: boolean; ttl?: number; } export interface SmartDiffResult { success: boolean; comparison: { source: string; target: string; repository: string; }; metadata: { totalFiles: number; returnedCount: number; truncated: boolean; totalAdditions: number; totalDeletions: number; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; duration: number; cacheHit: boolean; }; stats?: DiffStats[]; diffs?: { file: string; diff: string; }[]; error?: string; } export declare class SmartDiffTool { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart diff with configurable output and token optimization */ diff(options?: SmartDiffOptions): Promise<SmartDiffResult>; /** * Check if directory is a git repository */ private isGitRepository; /** * Get git commit hash */ private getGitHash; /** * Build cache key from options */ private buildCacheKey; /** * Format comparison target for display */ private formatComparison; /** * Get diff statistics for files */ private getDiffStats; /** * Parse git diff --numstat output */ private parseNumstat; /** * Get actual diff content for files */ private getDiffs; /** * Get diff statistics */ getStats(): { totalDiffs: number; cacheHits: number; totalTokensSaved: number; averageReduction: number; }; } /** * Get smart diff tool instance */ export declare function getSmartDiffTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartDiffTool; /** * CLI function - Creates resources and uses factory */ export declare function runSmartDiff(options?: SmartDiffOptions): Promise<SmartDiffResult>; /** * MCP Tool Definition */ export declare const SMART_DIFF_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { cwd: { type: string; description: string; }; source: { type: string; description: string; default: string; }; target: { type: string; description: string; }; staged: { type: string; description: string; default: boolean; }; files: { type: string; items: { type: string; }; description: string; }; filePattern: { type: string; description: string; }; summaryOnly: { type: string; description: string; default: boolean; }; contextLines: { type: string; description: string; default: number; }; limit: { type: string; description: string; }; }; }; }; //# sourceMappingURL=smart-diff.d.ts.map