Check that an edit's old-string occurs exactly once in a file, with match contexts

$0.005 USDC per call · Agent infrastructure · POST /api/v1/edit-anchor-check · Id edit-anchor-check

Counts how many times an old-string occurs in a supplied file text (as a replace-in-file tool would see it) and returns each match's offset, line, column and surrounding lines, for an agent about to issue an edit. pass: exactly one literal match, even counting overlapping ones. unknown: several matches, or one match that overlaps another occurrence of the same text (ambiguous; contexts show how to extend the string). fail: no literal match; the response then reports whitespace-tolerant line matches and typographic-quote or dash folding matches so the agent can see why. Does not apply the edit (use patch-anchor) and never edits anything.

What you get

Catches a failed or ambiguous edit before spending a tool round trip on it.

Call it

Send the JSON body below to https://agents.writerslogic.com/api/v1/edit-anchor-check. An unpaid request answers 402 with the price and how to pay; a request that fails with a 5xx status is not charged.

curl -i -X POST https://agents.writerslogic.com/api/v1/edit-anchor-check \
  -H 'content-type: application/json' \
  -d '{"file":"const a = 1;\nconst b = 2;\nconst a = 1;\n","oldString":"const b = 2;"}'

Input

FieldTypeRequiredDescription
filestring; length 0..524288yesFile text, at most 524288 UTF-8 bytes and 100000 lines.
oldStringstring; length 1..65536yes
contextLinesinteger; 0..10noLines of context before and after each listed match. Default 2.

Example request body

{
  "file": "const a = 1;\nconst b = 2;\nconst a = 1;\n",
  "oldString": "const b = 2;"
}

Result

The response is { "data": ..., "_provenance": ... }. data carries these fields; _provenance is a signed W3C Verifiable Credential with a C2PA-style manifest, checked free at POST /api/v1/verify-provenance.

FieldTypeRequiredDescription
statusstring; one of "pass", "fail", "unknown", "unsupported"nopass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass.
exactCountintegernoNon-overlapping literal occurrences.
overlappingCountintegernoOccurrences counting overlaps; differs from exactCount for self-overlapping strings.
matchesarray<object>noFirst 10 literal matches.
tolerantobjectnoOnly when there is no literal match: whole-line matches under the first tolerance rung that has any.
foldedCountintegernoOnly when there is no literal match: occurrences after folding curly quotes, en/em dashes and NBSP to ASCII.
witnessesarray<object>no
versionsobjectnoEvery semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile).
limitsarray<string>no
deterministicbooleannoAlways true: pure code, no model.

Pay and connect

Available through: x402 (USDC on Base), MCP. MCP clients reach it through the execution-safety-kit package.

Machine-readable