/** * 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'; import { type TruncationReason } from '../shared/bounded-traversal.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; /** * Wall-clock budget in ms for the source-file count fallback. * * When tsc's output carries no "Found N errors" line there is nothing to * count files from, so the tool walked `src` itself -- recursively, with a * `statSync` per entry, following junctions, and with no way to stop. * Defaults to 10 s. */ deadlineMs?: number; } interface SmartBuildOutput { /** * Build summary */ summary: { success: boolean; duration: number; filesCompiled: number; errorCount: number; warningCount: number; fromCache: boolean; /** * Set when `filesCompiled` is a FLOOR rather than a count, because the * fallback walk that produced it hit its deadline. * * There is no honest cap for this number: unlike a search, the answer here * IS the total, so any bound that stops early makes it wrong. Saying so is * the only thing that keeps it usable -- as a lower bound it still * supports the "more than 50 files" test below, which can only err by * withholding a suggestion. */ filesCompiledPartial?: boolean; filesCompiledNote?: string; }; /** * 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; private readonly defaultProjectRoot; constructor(cache: CacheEngine, _tokenCounter: TokenCounter, _metrics: MetricsCollector, projectRoot?: string); /** * Run build with smart caching and output reduction */ run(options?: SmartBuildOptions): Promise; /** * 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; 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; }; deadlineMs: { type: string; description: string; }; }; }; }; /** * Count `.ts` files under a directory, bounded. * * A MODULE FUNCTION RATHER THAN A METHOD so the bound can be exercised * directly. Reaching it through `run()` requires a real `tsc` invocation that * produces no "Found N errors" line, which is a five-second subprocess to test * a walk -- and a bound nobody can test is a bound nobody will keep. */ export declare function countTypeScriptSources(srcDir: string, deadlineMs?: number): Promise<{ count: number; truncatedBy?: TruncationReason; }>; export {}; //# sourceMappingURL=smart-build.d.ts.map