/** * Parser for the sub-agent streaming format with search/replace support. * * The LLM outputs edits using markers with square-bracket delimiters * (to avoid confusion with HTML angle brackets in the content): * * ``` * [[[FIELD:0]]] * [[[SEARCH]]] * misspelled word * [[[REPLACE]]] * correctly spelled word * [[[FIELD:2]]] * [[[FULL]]] * complete new value for field 2 * ``` * * - `[[[FIELD:N]]]` starts edits for field at 0-based index N. * - `[[[SEARCH]]]...[[[REPLACE]]]...` is a find-and-replace pair. * - `[[[FULL]]]` replaces the entire field value. * - Multiple SEARCH/REPLACE pairs per field are allowed. * - Only fields that need changes are included. */ export type ParserEvent = { type: 'field_start'; index: number; mode: 'full' | 'patch'; } | { type: 'full_delta'; index: number; value: string; } | { type: 'replace_delta'; index: number; search: string; value: string; } | { type: 'operation_end'; index: number; search: string; replace: string; } | { type: 'field_end'; index: number; }; export declare class FieldStreamParser { private buffer; private state; private fieldIndex; private fieldMode; private currentValue; private currentSearch; private stripLeadingNewline; /** * Feed a text chunk and return any events produced. */ feed(text: string): ParserEvent[]; /** * Call when the stream ends to close any open state. */ flush(): ParserEvent[]; /** * Try to match a marker at the start of the buffer. * Returns true if a marker was consumed. */ private tryMatchMarker; /** * Consume a marker from the buffer, stripping the optional newline after it. */ private consumeMarker; /** * Append content to the current accumulator and emit deltas. */ private appendContent; /** * Emit buffered content as delta, keeping a tail for partial markers. * Returns true if content was emitted. */ private emitBufferedContent; /** * Close any open operation or field, emitting the appropriate events. */ private closeCurrentState; private trimTrailingNewline; }