import { EventEmitter } from 'events'; /** * ProcessWatcher — Background process output monitoring with pattern matching. * * Inspired by Hermes Agent's watch_patterns feature. * Set patterns to watch for in background process output and get callbacks * when they match — no polling needed. * * Usage: * const watcher = new ProcessWatcher(); * watcher.watch(childProcess.stdout, { * patterns: [ * { regex: /listening on port (\d+)/, label: 'server-ready' }, * { regex: /error|Error|ERROR/, label: 'error-detected' }, * { regex: /build completed/, label: 'build-done', once: true }, * ], * onMatch: (match) => console.log(`[${match.label}] ${match.line}`), * }); */ export interface WatchPattern { /** Regex to match against each line of output */ regex: RegExp; /** Human-readable label for this pattern */ label: string; /** If true, auto-remove after first match */ once?: boolean; } export interface WatchMatch { /** Pattern label */ label: string; /** The full line that matched */ line: string; /** Regex match groups */ groups: string[]; /** Timestamp of match */ timestamp: number; /** Stream source */ stream: 'stdout' | 'stderr'; } export interface WatchOptions { /** Patterns to match */ patterns: WatchPattern[]; /** Callback on match */ onMatch: (match: WatchMatch) => void; /** Optional: max matches to keep in history (default: 100) */ maxHistory?: number; } export declare class ProcessWatcher extends EventEmitter { private watchers; private watcherIdCounter; /** * Start watching a readable stream for patterns. * Returns a watcher ID that can be used to stop watching. */ watch(stream: NodeJS.ReadableStream, options: WatchOptions, streamName?: 'stdout' | 'stderr'): string; /** * Watch both stdout and stderr of a ChildProcess. */ watchProcess(proc: { stdout?: NodeJS.ReadableStream | null; stderr?: NodeJS.ReadableStream | null; }, options: WatchOptions): string[]; /** Stop a specific watcher */ unwatch(id: string): void; /** Get match history for a watcher */ getHistory(id: string): WatchMatch[]; /** Add a pattern to an existing watcher */ addPattern(id: string, pattern: WatchPattern): void; /** Remove a pattern by label from a watcher */ removePattern(id: string, label: string): void; private matchLine; } //# sourceMappingURL=watch.d.ts.map