/** * Plain Text Log Processor * * Processes plain text output from GitHub Copilot CLI, stripping ANSI escape codes * and batching lines into paragraphs for normalized output. * * @module execution-engine/agents/copilot */ import type { NormalizedEntry } from '../types/agent-executor.js'; /** * Entry index provider for generating sequential entry indices */ export interface EntryIndexProvider { /** * Get the next available entry index */ next(): number; } /** * Simple counter-based entry index provider */ export declare class CounterIndexProvider implements EntryIndexProvider { private currentIndex; constructor(startIndex?: number); next(): number; } /** * Conversation patch operation * * Represents a change to the conversation history (add new entry or replace existing) */ export interface ConversationPatch { /** Patch type: add new entry or replace existing */ type: 'add' | 'replace'; /** Entry index in conversation */ index: number; /** Normalized entry content */ entry: NormalizedEntry; } /** * Configuration for PlainTextLogProcessor */ export interface PlainTextProcessorConfig { /** * Function to create NormalizedEntry from content string */ entryProducer: (content: string) => NormalizedEntry; /** * Optional function to transform lines before processing * Receives mutable array of lines that can be modified in-place */ transformLines?: (lines: string[]) => void; /** * Provider for generating entry indices */ indexProvider: EntryIndexProvider; } /** * Plain Text Log Processor * * Processes plain text output streams by: * 1. Stripping ANSI escape codes from each line * 2. Batching lines into paragraphs (separated by blank lines) * 3. Creating normalized entries for streaming updates * * @example * ```typescript * const processor = PlainTextLogProcessor.builder() * .normalizedEntryProducer((content) => ({ * timestamp: new Date(), * type: { kind: 'assistant_message' }, * content, * metadata: null, * })) * .indexProvider(new CounterIndexProvider(0)) * .build(); * * // Process output line by line * for await (const line of outputLines) { * const patches = processor.process(line); * for (const patch of patches) { * msgStore.push(patch); * } * } * ``` */ export declare class PlainTextLogProcessor { private config; private lineBuffer; private currentIndex; /** * Create a new PlainTextLogProcessor with the given configuration * * @param config - Processor configuration */ constructor(config: PlainTextProcessorConfig); /** * Create a builder for configuring the processor * * @returns New builder instance */ static builder(): PlainTextProcessorBuilder; /** * Process a line of output and return patches to emit * * Lines are batched into paragraphs. A paragraph ends when: * - An empty line is encountered (blank line separator) * - The paragraph is explicitly flushed * * **Streaming behavior**: * - First line of paragraph: Emits 'add' patch * - Subsequent lines: Emit 'replace' patches to update the entry * - Blank line: Flushes paragraph and resets buffer * * @param line - Output line to process (may include ANSI escapes) * @returns Array of patches to apply (usually 0-1 patches) * * @example * ```typescript * // First line * processor.process("Hello\n"); // [{ type: 'add', index: 0, entry: {...} }] * * // Continuation * processor.process("World\n"); // [{ type: 'replace', index: 0, entry: {...} }] * * // Blank line (flush) * processor.process("\n"); // [{ type: 'replace', index: 0, entry: {...} }] * ``` */ process(line: string): ConversationPatch[]; /** * Flush the current paragraph buffer * * Applies line transformations (if configured) and creates a final * replace patch with the complete paragraph content. * * @returns Final replace patch for the paragraph */ private flushParagraph; /** * Force flush any pending content * * Useful when the stream ends without a trailing blank line. * * @returns Final patch if buffer has content, null otherwise */ flush(): ConversationPatch | null; } /** * Builder for PlainTextLogProcessor * * Provides a fluent API for configuring the processor. * * @example * ```typescript * const processor = PlainTextLogProcessor.builder() * .normalizedEntryProducer((content) => createEntry(content)) * .transformLines((lines) => { * // Strip ANSI from each line * lines.forEach((line, i) => { * lines[i] = stripAnsi(line); * }); * }) * .indexProvider(new CounterIndexProvider(0)) * .build(); * ``` */ export declare class PlainTextProcessorBuilder { private entryProducer?; private transformLines?; private indexProvider?; /** * Set the entry producer function * * @param producer - Function that creates NormalizedEntry from content string * @returns This builder for chaining */ normalizedEntryProducer(producer: (content: string) => NormalizedEntry): this; /** * Set the line transformation function * * @param transformer - Function that modifies lines array in-place * @returns This builder for chaining */ transformLinesFunc(transformer: (lines: string[]) => void): this; /** * Set the entry index provider * * @param provider - Provider for generating entry indices * @returns This builder for chaining */ setIndexProvider(provider: EntryIndexProvider): this; /** * Build the configured processor * * @returns New PlainTextLogProcessor instance * @throws Error if required configuration is missing */ build(): PlainTextLogProcessor; } //# sourceMappingURL=plain-text-processor.d.ts.map