import { DocumentId } from '../../../platform/inlineEdits/common/dataTypes/documentId';
import { DuplicateAdditionsMode } from '../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions';
import { NoNextEditReason, StreamedEdit } from '../../../platform/inlineEdits/common/statelessNextEditProvider';
import { ILogger } from '../../../platform/log/common/logService';
import { URI } from '../../../util/vs/base/common/uri';
import { LineReplacement } from '../../../util/vs/editor/common/core/edits/lineEdit';
import { OffsetRange } from '../../../util/vs/editor/common/core/ranges/offsetRange';
import { AbstractText } from '../../../util/vs/editor/common/core/text/abstractText';
import { CurrentDocument } from '../common/xtabCurrentDocument';
export { DuplicateAdditionsMode };
declare class Patch {
    /**
     * Expected to be file path relative to workspace root.
     */
    readonly filePath: string;
    readonly lineNumZeroBased: number;
    removedLines: string[];
    addedLines: string[];
    private constructor();
    static ofLine(line: string): Patch | null;
    addLine(line: string): boolean;
    toString(): string;
}
/**
 * Information about a single duplicate-addition removal.
 *
 * `kind` identifies which heuristic shape fired:
 *   - `'suffix'`: trailing additions matched the lines after the deletion.
 *   - `'prefix'`: leading addition matched the first line after the deletion.
 *   - `'middle'`: a pair of additions inside the patch matched the start of
 *     the following lines (streaming model partially copied the continuation).
 *
 * `removedLines` are the actual addition lines that were dropped (in order),
 * preserved for diagnostics/logging.
 */
export interface DuplicateAdditionRemoval {
    readonly kind: 'suffix' | 'prefix' | 'middle';
    readonly newAdditions: string[];
    readonly removedLines: readonly string[];
}
/**
 * Telemetry-safe summary of a single duplicate-addition detection.
 *
 * Deliberately excludes raw line content (`newAdditions` / `removedLines`)
 * to keep `OnDuplicateRemovedCallback` from accidentally surfacing user
 * source code through telemetry pipelines. Use the internal
 * {@link DuplicateAdditionRemoval} returned by
 * {@link tryRemoveDuplicateAdditions} when you legitimately need the
 * content (e.g. to apply the trim).
 */
export interface DuplicateAdditionRemovalSummary {
    readonly kind: 'suffix' | 'prefix' | 'middle';
    readonly removedLineCount: number;
    readonly remainingAdditionCount: number;
}
/**
 * Callback invoked once per duplicate-addition detection. Receives only
 * redacted, telemetry-safe metadata (counts and shape). The callback fires
 * for every action mode (Log / DropPatch / DropAllRemaining / TrimDuplicate),
 * including `Log` where the patch is not actually modified.
 */
export type OnDuplicateRemovedCallback = (info: {
    readonly summary: DuplicateAdditionRemovalSummary;
    readonly mode: Exclude<DuplicateAdditionsMode, DuplicateAdditionsMode.Off>;
    readonly filePath: string;
    readonly lineNumZeroBased: number;
}) => void;
/**
 * Checks whether the patch's added lines duplicate the file content immediately
 * following the deleted range, and if so, trims the duplicated lines.
 *
 * The diff-patch model can occasionally regress and emit additions that copy
 * the existing continuation code. When that happens, applying the patch
 * produces visibly duplicated lines in the file (e.g. an extra closing brace
 * after a code block).
 *
 * Three duplication shapes are detected, mirroring the heuristic used in the
 * offline analysis tooling. Only one shape is applied per patch — the checks
 * run in priority order and the first match wins. This avoids cascading
 * removals where one shape's trimming exposes a spurious match for another.
 *
 * Priority order:
 *   1. **Suffix** — last `k` additions match first `k` following lines (most
 *      common case: trailing `}` re-emitted). Picks the longest matching `k`.
 *      No additional ambiguity guard is applied: the prior heuristic
 *      preserved single-token suffixes when they consumed the entire
 *      addition (e.g. `addedLines = ['}']` with `following = ['}']`), but
 *      that's the headline-bug case — applying the patch would insert a
 *      stray closing token into already-balanced code. The trade-off is a
 *      rare false positive when the file is mid-typing and unbalanced; the
 *      common case (file is balanced, model is duplicating) is the one we
 *      optimize for.
 *   2. **Prefix** — first addition matches first following line, and the line
 *      is "meaningful" (>1 non-whitespace char) to avoid dropping legitimate
 *      single-token lines (e.g. an inner-scope `}` followed by an outer `}`).
 *   3. **Middle** — a consecutive pair of additions starting at offset > 0
 *      (and not at the end) matches the first two following lines. Both
 *      following lines must be meaningful, again to avoid trivial matches.
 *      The match is then **greedily extended**: only the verified-equal
 *      lines are dropped; any addition lines beyond the equal range are
 *      preserved (the model may have appended new content after the
 *      streaming-style regenerated context).
 *
 * Returns a `DuplicateAdditionRemoval` describing what was dropped, or
 * `undefined` if no duplication was detected.
 */
export declare function tryRemoveDuplicateAdditions(replacement: LineReplacement, currentText: AbstractText): DuplicateAdditionRemoval | undefined;
export declare class XtabCustomDiffPatchResponseHandler {
    static handleResponse(linesStream: AsyncIterable<string>, currentDocument: CurrentDocument, activeDocumentId: DocumentId, workspaceRoot: URI | undefined, window: OffsetRange | undefined, parentTracer: ILogger, duplicateAdditionsMode?: DuplicateAdditionsMode, onDuplicateRemoved?: OnDuplicateRemovedCallback): AsyncGenerator<StreamedEdit, NoNextEditReason, void>;
    private static resolveEdit;
    private static resolveTargetDocument;
    static extractEdits(linesStream: AsyncIterable<string>): AsyncGenerator<Patch>;
}
//# sourceMappingURL=xtabCustomDiffPatchResponseHandler.d.ts.map