Skip to content

Documentation / @agentick/sandbox / applyEdits

Function: applyEdits() ​

applyEdits(source, edits): EditResult

Defined in: edit.ts:615

Apply edits to a source string. Pure function, no I/O.

Mode detection (by field presence, precedence: range > insert > delete > replace):

  • Range: from + to + content — replace block between markers (inclusive)
  • Insert before/after: old + insert + content — insert relative to anchor
  • Insert start/end: insert + content — prepend/append to file
  • Delete: old + delete: true — remove matched text
  • Replace: old + new — find and replace

Matching strategy per anchor (in order):

  1. Exact byte match
  2. Line-normalized (trailing whitespace stripped)
  3. Indent-adjusted (leading whitespace baseline stripped, new indentation adjusted)

Multi-edit: all matches resolved against original source, validated for overlap, applied bottom-to-top.

Parameters ​

source ​

string

edits ​

Edit[]

Returns ​

EditResult

Throws ​

EditError on match failure, validation error, or overlapping edits

Released under the ISC License.