Skip to main content

select_and_apply

Function select_and_apply 

Source
pub fn select_and_apply(
    model_slug: &str,
    content: &str,
    path: &Path,
    payloads: &[EditPayload],
) -> Result<(String, EditFormat), FsError>
Expand description

Try payloads against content in model_slug’s preferred format order, returning the first one that applies cleanly.

Why: This is the fallback-retry loop #2068 asks for: SEARCH/REPLACE first (for models that prefer it), falling back to unified-diff, then whole-file, all within a single tool call when the model supplied more than one representation of the same edit. What: Iterates format_order_for, and for each preferred format tries the first payload of that format present in payloads; returns (updated_content, format_used) on the first success. If no payload matches any format (empty payloads), or every present payload fails to apply, returns the last encountered FsError. Test: tests::select_and_apply_*.