Explanation: why tact is shaped this way#

Drift is routine, not a permission to guess#

An edit can become stale for reasons unrelated to its intent: a formatter removes whitespace, a copy-paste changes a quote, a block moves one indent level, or another edit lands first. Exact matching correctly notices that the bytes changed, but it cannot distinguish harmless drift from a meaningful change. Tact makes that distinction explicit rather than asking a caller to reconstruct the edit from scratch.

Its benchmark fixtures replay historical edit failures, so the tool can be evaluated against the kind of drift it was made to handle. Those fixtures are evidence about a fixed corpus, not a universal accuracy claim.

A ladder preserves the strongest evidence#

find_block tries seven rungs in order: EXACT, CANON, RSTRIP, INDENT, SUBLINE, REFLOW, and FUZZY. It stops at the finest rung with one candidate and reports that rung. A single fixed tolerance is either too brittle or too permissive; always using the loosest match would conceal that stronger evidence existed.

The first four rungs are equality under progressively coarser normalizations. SUBLINE and REFLOW are exact matches on projections of the text, and therefore can safely precede approximate matching. They are the only rungs that can change part of a line, so their results include character columns. FUZZY is last because similarity is not transitive: two locations can both be close to a target without being interchangeable.

Refusal is part of the write contract#

Two or more candidates at any rung are an ambiguity, not a tie to break by position. Tact returns a structured refusal and accepts a near hint when the caller can supply one. It also rejects overlapping edits and refuses an indentation-adjusted write when no uniform indentation shift can be established.

The same posture applies to batches. A single-file batch resolves all edits before writing. A multi-file batch resolves and stages every file before committing any; after the first per-file rename, however, a crash or commit failure can leave a partial batch. That POSIX limitation is reported rather than hidden.

Forgiving about shape, strict about meaning#

The ladder forgives drift in the file. A month of agent transcripts showed a second, larger source of failed edits: drift in the call itself. Agents arrived with the argument names of whichever edit tool they were trained on (old_string, file_path, old/new), with Codex’s *** Begin Patch grammar instead of a unified diff, with hunk headers whose line counts were off, and with multi-line text whose newlines a shell had left as the two characters backslash and n. Each was a hard failure, and the usual recovery was to abandon tact for an improvised string-replace script, which has no ladder and no refusals at all. A strict front door was pushing edits onto the least safe path available.

So tact accepts every input shape whose meaning is unambiguous, and refuses the rest by name:

  • Aliases are accepted when each one names exactly one field. Two aliases for the same field with different values are refused, never reconciled.

  • Unknown keys are refused with the accepted shapes listed. Dropping one silently could drop a dry_run and turn a preview into a write. For the same reason, an edits value that is itself a whole argument object ({"edits": [...], "dry_run": true}) is merged into the call, not unwrapped, and null means the key was not given.

  • replace_all: true is refused. Tact anchors each edit to one unique location and cannot honor it.

  • Escape decoding is tried only when the literal text is absent from the file or resolves only at FUZZY, and only when decoding yields a line break. Text found verbatim, even ambiguously, is meant literally: decoding an ambiguous verbatim block once moved the write to a different line. The decoded text is adopted only when it resolves at a stronger rung. The result says escapes_decoded, and a decoded write never collapses into the compact receipt. In a Python file, a decoded edit that would not parse is refused. In other code, a decoded line break inside a quoted string (printf("hi\n")) is refused, because nothing says whether that one was meant as source text.

  • Patch text that parses to nothing is a refusal. It is never ok: true over an empty list of files.

  • One dialect per patch. The first structural marker decides which grammar reads the text. A marker inside a block that grammar consumed is content, so a SEARCH/REPLACE edit of a document that shows a patch example edits the document. A marker outside it is refused by line number, because the alternative was silently dropping half of a mixed patch.

  • Patch structure that two readings fit is refused rather than resolved. Examples: a SEARCH/REPLACE block with two ======= lines, a hunk whose counted body is followed by extra + lines after a context line, a bare -- after the last hunk (a mail signature or a removed - line), and a \ No newline at end of file that applies to only one side. Wrong hunk counts are still forgiven where the file can check the reading: extra context and removed lines must match the file, and a counted body that ends inside an insertion run continues it.

  • A first line that lost its indentation, the most common way a copied block stops being a whole-line match, falls through from INDENT to the exact SUBLINE rung instead of being refused.

  • A final blank line the file lacks is dropped from old_block, and from new_block when that ends in one too. SUBLINE used to match it as zero characters of the next line, and a new_block without one was then written onto that line.

Every one of these paths is meant either to find the same unique target the canonical shape would have found, or to refuse. That is checked rather than assumed, in four ways:

  • Field replay. scripts/field_replay.py replays the mined field calls through both skins and compares the bytes on disk.

  • Adversarial reviews. Two hostile reviews of the release found wrong writes at the new edges, and those cases are now tests.

  • Fuzz oracle. It generates diffs with difflib and checks every write against the expected file.

  • Corpus diff. It parses every mined patch body before and after each change, so a new refusal of real input is seen, not guessed at.

LSP is optional, except when identity matters#

Definition, references, hover, symbols, and diagnostics use language servers when they are available. Most return a structured unavailable result when no server is live; Python symbols can fall back to an AST outline. Rename is different: identifying the same binding across files needs the language server’s semantic graph. There is no safe text-replacement substitute, so rename refuses when that graph is unavailable.

Convenience state is disposable#

Undo history and saved anchors live under the configured AI-home directory. Storage errors become structured results, and removing that state sacrifices convenience rather than package correctness. The journal makes undo and delta reads more useful; it is not a dependency for making a sound edit.

Provenance#

canonicalize() and the Levenshtein/similarity primitives adapt portions of dirac, Apache-2.0 version 0.4.11. See NOTICE and tact/reconcile.py for the precise attribution. Tact collects every candidate before deciding, uses a per-line similarity mean that never lets a blank or unrelated quoted line stand in for a real one, and adds SUBLINE and REFLOW; those are deliberate departures from the upstream implementation.