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

239 lines 6.22 kB
/** * Smart Merge Tool - 80% Token Reduction * * Achieves token reduction through: * 1. Structured merge status (instead of raw git merge output) * 2. Conflict-only mode (show only conflicts, not all changes) * 3. Summary mode (counts and status, not full diffs) * 4. Smart conflict resolution helpers * 5. Minimal merge history (only essential info) * * Target: 80% reduction vs full git merge/status output */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface ConflictInfo { file: string; type: string; ours?: string; theirs?: string; base?: string; } export interface MergeStatus { inProgress: boolean; hasConflicts: boolean; branch?: string; strategy?: string; conflicts?: ConflictInfo[]; mergedFiles?: string[]; conflictCount?: number; mergedCount?: number; } export interface MergeResult { success: boolean; merged: boolean; fastForward: boolean; conflicts: string[]; message?: string; hash?: string; } export interface SmartMergeOptions { cwd?: string; mode?: 'status' | 'merge' | 'abort' | 'continue'; branch?: string; commit?: string; noCommit?: boolean; noFf?: boolean; ffOnly?: boolean; squash?: boolean; strategy?: 'recursive' | 'ours' | 'theirs' | 'octopus' | 'subtree'; strategyOption?: string[]; conflictsOnly?: boolean; includeContent?: boolean; summaryOnly?: boolean; maxConflicts?: number; resolveUsing?: 'ours' | 'theirs'; useCache?: boolean; ttl?: number; } export interface SmartMergeResult { success: boolean; mode: string; metadata: { repository: string; currentBranch: string; mergeInProgress: boolean; hasConflicts: boolean; conflictCount: number; mergedCount: number; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; duration: number; cacheHit: boolean; }; status?: MergeStatus; result?: MergeResult; error?: string; } export declare class SmartMergeTool { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart merge operations with structured output and conflict management */ merge(options?: SmartMergeOptions): Promise<SmartMergeResult>; /** * Check if directory is a git repository */ private isGitRepository; /** * Get current branch name */ private getCurrentBranch; /** * Get git commit hash */ private getGitHash; /** * Build cache key from options */ private buildCacheKey; /** * Get current merge status */ private getMergeStatus; /** * Check if merge is in progress */ private isMergeInProgress; /** * Get merge head branch name */ private getMergeHead; /** * Get list of conflicted files */ private getConflicts; /** * Get conflict type for a file */ private getConflictType; /** * Get different versions (stages) of a conflicted file */ private getConflictStages; /** * Get list of successfully merged files */ private getMergedFiles; /** * Perform merge operation */ private performMerge; /** * Abort current merge */ private abortMerge; /** * Continue merge after resolving conflicts */ private continueMerge; /** * Get merge statistics */ getStats(): { totalMerges: number; cacheHits: number; totalTokensSaved: number; averageReduction: number; }; } /** * Get smart merge tool instance */ export declare function getSmartMergeTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartMergeTool; /** * CLI function - Creates resources and uses factory */ export declare function runSmartMerge(options?: SmartMergeOptions): Promise<SmartMergeResult>; /** * MCP Tool Definition */ export declare const SMART_MERGE_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { cwd: { type: string; description: string; }; mode: { type: string; enum: string[]; description: string; default: string; }; branch: { type: string; description: string; }; commit: { type: string; description: string; }; noCommit: { type: string; description: string; default: boolean; }; noFf: { type: string; description: string; default: boolean; }; ffOnly: { type: string; description: string; default: boolean; }; squash: { type: string; description: string; default: boolean; }; strategy: { type: string; enum: string[]; description: string; default: string; }; conflictsOnly: { type: string; description: string; default: boolean; }; includeContent: { type: string; description: string; default: boolean; }; summaryOnly: { type: string; description: string; default: boolean; }; maxConflicts: { type: string; description: string; }; }; }; }; //# sourceMappingURL=smart-merge.d.ts.map