/**
 * CLI Output Converter
 * Converts raw CLI tool output into structured Intermediate Representation (IR)
 *
 * Purpose: Decouple output parsing from consumption scenarios (View, Storage, Resume)
 * Supports: Plain text, JSON Lines, and other structured formats
 */
/**
 * Unified output unit types for the intermediate representation layer
 */
export type CliOutputUnitType = 'stdout' | 'stderr' | 'thought' | 'code' | 'file_diff' | 'progress' | 'metadata' | 'system' | 'tool_call';
/**
 * Intermediate Representation unit
 * Common structure for all CLI output chunks
 */
export interface CliOutputUnit<T = any> {
    type: CliOutputUnitType;
    content: T;
    timestamp: string;
}
/**
 * Parser interface for converting raw output into IR
 */
export interface IOutputParser {
    /**
     * Parse a chunk of data from stdout/stderr stream
     * @param chunk - Raw buffer from stream
     * @param streamType - Source stream (stdout or stderr)
     * @returns Array of parsed output units
     */
    parse(chunk: Buffer, streamType: 'stdout' | 'stderr'): CliOutputUnit[];
    /**
     * Flush any remaining buffered data
     * Called when stream ends to ensure no data is lost
     * @returns Array of remaining output units
     */
    flush(): CliOutputUnit[];
}
/**
 * PlainTextParser - Converts plain text output to IR
 * Simply wraps text in appropriate type envelope
 */
export declare class PlainTextParser implements IOutputParser {
    parse(chunk: Buffer, streamType: 'stdout' | 'stderr'): CliOutputUnit[];
    /**
     * Flush any remaining buffered data
     * Called when stream ends to ensure no data is lost
     *
     * Note: PlainTextParser does not buffer data internally, so this method
     * always returns an empty array. Other parsers (e.g., JsonLinesParser)
     * may have buffered incomplete lines that need to be flushed.
     *
     * @returns Array of remaining output units (always empty for PlainTextParser)
     */
    flush(): CliOutputUnit[];
}
/**
 * JsonLinesParser - Parses newline-delimited JSON output
 *
 * Features:
 * - Handles incomplete lines across chunks
 * - Maps JSON events to appropriate IR types
 * - Falls back to stdout for unparseable lines
 * - Robust error handling for malformed JSON
 */
export declare class JsonLinesParser implements IOutputParser {
    private buffer;
    /**
     * Classify non-JSON content to determine appropriate output type
     * Helps distinguish real errors from normal progress/output sent to stderr
     * (Some CLI tools like Codex send all progress info to stderr)
     */
    private classifyNonJsonContent;
    parse(chunk: Buffer, streamType: 'stdout' | 'stderr'): CliOutputUnit[];
    flush(): CliOutputUnit[];
    /**
     * Map parsed JSON object to appropriate IR type
     * Handles various JSON event formats from different CLI tools:
     * - Gemini CLI: stream-json format (init, message, result)
     * - Codex CLI: --json format (thread.started, item.completed, turn.completed)
     * - Claude CLI: stream-json format (system, assistant, result)
     * - OpenCode CLI: --format json (step_start, text, step_finish)
     */
    private mapJsonToIR;
}
/**
 * Intelligent content formatter that detects and formats JSON content
 * based on structural patterns rather than hardcoded tool-specific formats.
 *
 * Key detection patterns:
 * - Session/Metadata: session_id, sessionID, thread_id, model, stats
 * - Tool Calls: tool_name, tool, function_name, parameters
 * - Progress: status, progress, state, reason
 * - Tokens: tokens, usage, input_tokens, output_tokens
 * - Text Content: content, text, message
 */
export declare class SmartContentFormatter {
    /**
     * Format structured content into human-readable text
     * NEVER returns null - always returns displayable content to prevent data loss
     */
    static format(content: any, type: CliOutputUnitType): string;
    /**
     * Format object as readable JSON with type hint (fallback for unknown content)
     * Ensures content is never lost
     */
    private static formatAsReadableJson;
    /**
     * Format metadata (session info, stats, etc.)
     * Returns null if no meaningful metadata could be extracted
     */
    private static formatMetadata;
    /**
     * Format progress updates
     * Returns null if no meaningful progress info could be extracted
     */
    private static formatProgress;
    /**
     * Format tool call (invoke/result)
     */
    private static formatToolCall;
    /**
     * Format code block
     */
    private static formatCode;
    /**
     * Format file diff
     */
    private static formatFileDiff;
    /**
     * Format thought/reasoning
     * Returns null if no text content could be extracted
     */
    private static formatThought;
    /**
     * Format system message
     * Returns null if no message content could be extracted
     */
    private static formatSystem;
    /**
     * Extract text content from common fields
     */
    private static extractTextContent;
    /**
     * Extract token usage from various formats
     */
    private static extractTokens;
    /**
     * Truncate string to max length
     */
    private static truncate;
    /**
     * Format duration from milliseconds
     */
    private static formatDuration;
}
/**
 * Create an output parser instance based on format
 * @param format - Output format type
 * @returns Parser instance
 */
export declare function createOutputParser(format: 'text' | 'json-lines'): IOutputParser;
/**
 * Flatten output units into plain text string
 * Useful for Resume scenario where we need concatenated context
 *
 * @param units - Array of output units to flatten
 * @param options - Filtering and formatting options
 * @returns Concatenated text content
 */
export declare function flattenOutputUnits(units: CliOutputUnit[], options?: {
    includeTypes?: CliOutputUnitType[];
    excludeTypes?: CliOutputUnitType[];
    includeTimestamps?: boolean;
    separator?: string;
}): string;
/**
 * Extract specific content type from units
 * Convenience helper for common extraction patterns
 */
export declare function extractContent(units: CliOutputUnit[], type: CliOutputUnitType): string[];
/**
 * Get statistics about output units
 * Useful for debugging and analytics
 */
export declare function getOutputStats(units: CliOutputUnit[]): {
    total: number;
    byType: Record<CliOutputUnitType, number>;
    firstTimestamp?: string;
    lastTimestamp?: string;
};
//# sourceMappingURL=cli-output-converter.d.ts.map