/** * Stage Output Cache - Persistent caching of stage outputs to eliminate redundant LLM calls * * Caches stage outputs based on input file contents, allowing subsequent command * executions to skip expensive LLM calls when inputs haven't changed. * * Cache invalidation: * - Input file content changes (detected via hash) * - TTL expiration (default: 1 hour) * - Manual invalidation via cache.clear() */ /** * Configuration for stage-level caching */ export interface StageCacheConfig { /** Whether caching is enabled for this stage */ enabled: boolean; /** TTL in milliseconds (default: 1 hour) */ ttl_ms?: number; /** Input keys that should be used for cache key generation */ cache_key_inputs?: string[]; /** File paths to include in cache key hash (monitors file changes) */ file_dependencies?: string[]; } /** * Cached stage output entry */ export interface StageCacheEntry { /** Stage identifier (stage.prompt) */ stageId: string; /** Hash of inputs used to generate this cache entry */ inputHash: string; /** Timestamp when entry was created */ createdAt: number; /** TTL in milliseconds */ ttl_ms: number; /** The cached stage outputs */ outputs: Record; /** Duration of original execution in ms (for metrics) */ originalDuration_ms: number; } /** * Result of a cache lookup */ export interface StageCacheLookupResult { entry?: StageCacheEntry; hit: boolean; reason?: 'expired' | 'file_changed' | 'input_changed' | 'no_entry'; savedTime_ms?: number; } /** * Stage Output Cache Service * * Provides persistent file-based caching of stage outputs. * Cache entries are stored in .valora/cache/stages/ as JSON files. */ export declare class StageOutputCache { private static instance; private cacheDir; private cleanupTimer; private defaultTtl; constructor(defaultTtl?: number); /** * Get singleton instance */ static getInstance(): StageOutputCache; /** * Reset singleton instance (for testing) */ static resetInstance(): void; /** * Generate a cache key from stage ID and inputs */ generateCacheKey(stageId: string, inputs: Record, config?: StageCacheConfig): string; /** * Collect inputs to use for cache key generation */ private collectKeyInputs; /** * Compute hashes for file dependencies */ private computeFileDependencyHashes; /** * Store a stage output in the cache */ set(stageId: string, inputs: Record, outputs: Record, durationMs: number, config?: StageCacheConfig): void; /** * Look up a cached stage output */ get(stageId: string, inputs: Record, config?: StageCacheConfig): StageCacheLookupResult; /** * Invalidate a specific cache entry */ invalidate(stageId: string, inputs: Record, config?: StageCacheConfig): boolean; /** * Invalidate all cache entries for a stage */ invalidateStage(stageId: string): number; /** * Clear all cache entries */ clear(): void; /** * Get cache statistics */ getStats(): { entries: Array<{ ageMs: number; savedTime_ms: number; stageId: string; }>; size: number; }; /** * Ensure cache directory exists */ private ensureCacheDir; /** * Get file path for a cache entry */ private getCacheFilePath; /** * Hash content for comparison */ private hashContent; /** * Sort object keys for consistent hashing */ private sortObjectKeys; /** * Evict oldest entries if cache is too large */ private evictIfNeeded; /** * Clean up expired cache entries * @returns Number of entries cleaned */ cleanupExpired(): number; /** * Start periodic cleanup timer */ private startCleanupTimer; /** * Stop the cleanup timer (for graceful shutdown) */ stop(): void; } /** * Get the singleton stage output cache instance */ export declare function getStageOutputCache(): StageOutputCache; //# sourceMappingURL=stage-output-cache.d.ts.map