/** * Smart Processes Tool - 60% Token Reduction * * Monitors running processes with: * - Process filtering (hide noise) * - Resource usage tracking * - Smart aggregation * - Anomaly detection */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; interface SmartProcessesOptions { /** * Filter processes by name pattern */ filter?: string; /** * Show only high CPU usage processes (> threshold %) */ cpuThreshold?: number; /** * Show only high memory usage processes (> threshold MB) */ memoryThreshold?: number; /** * Include system processes */ includeSystem?: boolean; /** * Maximum number of processes to show */ limit?: number; /** * Project root directory */ projectRoot?: string; /** * Use cached snapshot (for comparison) */ useCache?: boolean; /** * Maximum cache age in seconds */ maxCacheAge?: number; } interface SmartProcessesOutput { /** * Summary of process state */ summary: { totalProcesses: number; filteredCount: number; highCpuCount: number; highMemoryCount: number; timestamp: number; }; /** * Top processes by resource usage */ topProcesses: { byCpu: Array<{ pid: number; name: string; cpu: number; memory: number; }>; byMemory: Array<{ pid: number; name: string; cpu: number; memory: number; }>; }; /** * Anomalies detected */ anomalies: Array<{ type: 'cpu_spike' | 'memory_leak' | 'zombie' | 'duplicate'; severity: 'high' | 'medium' | 'low'; message: string; processes: Array<{ pid: number; name: string; }>; }>; /** * Resource usage trends (if cache available) */ trends?: { cpuDelta: number; memoryDelta: number; processCountDelta: number; }; /** * Token reduction metrics */ metrics: { originalTokens: number; compactedTokens: number; reductionPercentage: number; }; } export declare class SmartProcesses { private cache; private cacheNamespace; private platform; constructor(cache: CacheEngine, _tokenCounter: TokenCounter, _metrics: MetricsCollector, _projectRoot?: string); /** * Get process information with smart filtering and caching */ run(options?: SmartProcessesOptions): Promise; /** * Capture current process snapshot */ private captureSnapshot; /** * Get list of running processes */ private getProcessList; /** * Get processes on Windows. * * WMIC RETURNS COLUMNS ALPHABETICALLY, not in the order they were requested, * and the previous mapping assumed request order. Measured against a real * table on this machine, four of five fields were reading the wrong column: * * header: Node,CommandLine,CreationDate,KernelModeTime,Name,ProcessId,... * name <- CommandLine ("C:\WINDOWS\Explorer.EXE", not explorer.exe) * cpu <- parseInt(Name) always NaN -> 0, for every process * memory <- UserModeTime explorer.exe reported as 414,398 MB * command <- Node the HOSTNAME, identical for every row * * `cpu` being pinned at 0 is why a default cpuThreshold filtered the entire * table away -- the thresholds were lowered to compensate, which treated the * symptom. Only `pid` was right. */ private getWindowsProcesses; /** @see parseWmicProcessCsv -- the parsing rules and why they are what they are. */ private parseWmicCsv; /** * Supported replacement for wmic. Emits JSON, so no CSV parsing is involved. */ private getWindowsProcessesViaCim; /** * Get processes on Unix/Linux/macOS */ private getUnixProcesses; /** * Filter processes based on criteria */ private filterProcesses; /** * Get cached snapshot */ private getCachedSnapshot; /** * Cache snapshot */ private cacheSnapshot; /** * Detect anomalies in process list */ private detectAnomalies; /** * Calculate resource usage trends */ private calculateTrends; /** * Transform process data to smart output */ private transformOutput; /** * What the full process listing actually costs. * * THE BASELINE WAS INVENTED. This returned * `snapshot.processes.length * 200 + 500` -- an assumed 200 characters per * process, measured from nothing. Paired with the default `cpuThreshold` of * 10, which filters out everything on a machine that is not on fire, the * tool reported a 100% reduction for returning an EMPTY list: 25,825 tokens * "saved" by omitting the answer. * * The snapshot is right here, so it is measured. */ private measureOriginalOutputSize; /** * Estimate compact output size */ private estimateCompactSize; /** * Close cache connection */ close(): void; } /** * Factory function for creating SmartProcesses with shared resources (for benchmarks) */ export declare function getSmartProcessesTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector, projectRoot?: string): SmartProcesses; /** * CLI-friendly function for running smart processes */ export declare function runSmartProcesses(options?: SmartProcessesOptions): Promise; export declare const SMART_PROCESSES_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { filter: { type: string; description: string; }; cpuThreshold: { type: string; description: string; }; memoryThreshold: { type: string; description: string; }; includeSystem: { type: string; description: string; default: boolean; }; limit: { type: string; description: string; default: number; }; projectRoot: { type: string; description: string; }; compareWithPrevious: { type: string; description: string; default: boolean; }; useCache: { type: string; description: string; default: boolean; }; maxCacheAge: { type: string; description: string; default: number; }; }; }; }; export {}; //# sourceMappingURL=smart-processes.d.ts.map