@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
207 lines • 5.17 kB
TypeScript
/**
* Smart Build Tool - 85% Token Reduction
*
* Wraps TypeScript compiler (tsc) to provide:
* - Incremental builds only
* - Cached build outputs
* - Error extraction (failures only, not entire log)
* - Build time optimization suggestions
*/
import { CacheEngine } from '../../core/cache-engine.js';
import { TokenCounter } from '../../core/token-counter.js';
import { MetricsCollector } from '../../core/metrics.js';
interface SmartBuildOptions {
/**
* Force full rebuild (ignore cache)
*/
force?: boolean;
/**
* Watch mode
*/
watch?: boolean;
/**
* Project root directory
*/
projectRoot?: string;
/**
* TypeScript config file
*/
tsconfig?: string;
/**
* Include warnings in output
*/
includeWarnings?: boolean;
/**
* Maximum cache age in seconds (default: 3600 = 1 hour)
*/
maxCacheAge?: number;
}
interface SmartBuildOutput {
/**
* Build summary
*/
summary: {
success: boolean;
duration: number;
filesCompiled: number;
errorCount: number;
warningCount: number;
fromCache: boolean;
};
/**
* Only errors and warnings (categorized)
*/
errors: Array<{
category: string;
file: string;
location: string;
message: string;
code: string;
}>;
/**
* Optimization suggestions
*/
suggestions: Array<{
type: 'performance' | 'config' | 'code';
message: string;
impact: 'high' | 'medium' | 'low';
}>;
/**
* Changed files since last build
*/
changedFiles: string[];
/**
* Token reduction _metrics
*/
_metrics: {
originalTokens: number;
compactedTokens: number;
reductionPercentage: number;
};
}
export declare class SmartBuild {
private cache;
private cacheNamespace;
private projectRoot;
constructor(cache: CacheEngine, _tokenCounter: TokenCounter, _metrics: MetricsCollector, projectRoot?: string);
/**
* Run build with smart caching and output reduction
*/
run(options?: SmartBuildOptions): Promise<SmartBuildOutput>;
/**
* Run TypeScript compiler and capture results
*/
private runTsc;
/**
* Parse TypeScript compiler output for errors and warnings
*/
private parseCompilerOutput;
/**
* Count files compiled from output
*/
private countCompiledFiles;
/**
* Count TypeScript source files
*/
private countSourceFiles;
/**
* Generate cache key based on source files and config
*/
private generateCacheKey;
/**
* Get cached result if available and fresh
*/
private getCachedResult;
/**
* Cache build result
*/
private cacheResult;
/**
* Detect changed files since last build
*/
private detectChangedFiles;
/**
* Generate optimization suggestions based on build result
*/
private generateSuggestions;
/**
* Categorize errors by code
*/
private categorizeErrors;
/**
* Transform full build output to smart output
*/
private transformOutput;
/**
* Categorize and format errors
*/
private categorizeAndFormatErrors;
/**
* Categorize error by TS error code
*/
private categorizeErrorCode;
/**
* Format cached output
*/
private formatCachedOutput;
/**
* Estimate original output size (full tsc output)
*/
private estimateOriginalOutputSize;
/**
* Estimate compact output size
*/
private estimateCompactSize;
/**
* Close cache connection
*/
close(): void;
}
/**
* Factory function for creating SmartBuild with shared resources
* Use this in benchmarks and tests where resources are shared
*/
export declare function getSmartBuildTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector, projectRoot?: string): SmartBuild;
/**
* CLI-friendly function for running smart build
*/
export declare function runSmartBuild(options?: SmartBuildOptions): Promise<string>;
export declare const SMART_BUILD_TOOL_DEFINITION: {
name: string;
description: string;
inputSchema: {
type: string;
properties: {
force: {
type: string;
description: string;
default: boolean;
};
watch: {
type: string;
description: string;
default: boolean;
};
projectRoot: {
type: string;
description: string;
};
tsconfig: {
type: string;
description: string;
};
includeWarnings: {
type: string;
description: string;
default: boolean;
};
maxCacheAge: {
type: string;
description: string;
default: number;
};
};
};
};
export {};
//# sourceMappingURL=smart-build.d.ts.map