Expand description
Per-model edit-format selection for the edit tool (#2068, P1B-1).
Why: Aider’s A/B data (cited in #2068) shows edit-application success rate
varies a lot by model family for a given wire format: exact-match
SEARCH/REPLACE is the cheapest (fewest tokens) but some models struggle to
reproduce old_string byte-for-byte; unified-diff is more forgiving of
minor context drift but costs more tokens to emit; whole-file replacement
is the most robust (no precision needed at all) but the most expensive.
Picking a fixed global order wastes retries on models that reliably fail
their first attempt. format_order_for centralises a static per-model
preference matrix (Phase 1 — “simple matrix in agent config”, full
success-rate learning loop deferred to Phase 2) so the tool can offer
formats in the order most likely to succeed for the calling model,
mirroring the strategy_order_for matrix in
llm::tool_call_extractor (#1023).
What: EditFormat names the three supported wire formats; EditPayload
bundles the format-specific arguments recovered from the LLM’s tool call;
format_order_for returns the per-model fallback order; select_and_apply
tries the caller-supplied payloads in that order against the current file
content and returns the first one that applies cleanly. select_and_apply_for_mode
(#2073) is the HarnessMode-aware entry point that reconciles this
per-model matrix with vision spec §5.9’s Parity/DailyDriver split:
HarnessMode::DailyDriver keeps this per-model matrix with full
fallback, unchanged; HarnessMode::Parity is STRICT unified-diff only,
with NO fallback to SEARCH/REPLACE or whole-file (owner decision,
2026-07-07 — see [apply_parity_diff_only]’s docs for the
benchmark-fairness rationale).
§Per-model format matrix
| Model family (slug substring) | Fallback order |
|---|---|
claude-, gpt-, gemini- (flagship, native tool-calling) | SEARCH/REPLACE → unified-diff → whole-file |
qwen, deepseek | unified-diff → SEARCH/REPLACE → whole-file |
everything else (gemma, small/unknown models) | whole-file → SEARCH/REPLACE → unified-diff |
Rationale: flagship models reliably reproduce exact substrings, so the
cheapest format leads. Qwen/DeepSeek’s published chat templates and code
training corpora lean heavily on diff-formatted code, so diff application
out-performs exact match for that family (per the Aider leaderboard data
referenced in #2068). Weaker/unknown models frequently botch both
precision-dependent formats, so the most forgiving format (whole-file)
leads for the catch-all bucket. This table is the HarnessMode::DailyDriver
behaviour (#2073, §5.9): production, per-model-optimised edit-format
selection with full fallback. HarnessMode::Parity does NOT use this
table at all — see [apply_parity_diff_only] for its strict,
no-fallback unified-diff-only behaviour.
Test: tests::format_order_*, tests::select_and_apply_*.
Enums§
- Edit
Format - The three supported edit wire formats.
- Edit
Payload - One candidate edit, in the shape the LLM actually supplied it.
Functions§
- format_
order_ for - Per-model fallback order for edit-format application, when multiple candidate payloads are available.
- format_
order_ for_ mode HarnessMode-aware fallback order for edit-format application (#2073, §5.9’s reconciliation table).- select_
and_ apply - Try
payloadsagainstcontentinmodel_slug’s preferred format order, returning the first one that applies cleanly. - select_
and_ apply_ for_ mode HarnessMode-aware edit-format dispatch (#2073).