Expand description
Shared edit engine: byte-offset conversion, content replacement, syntax validation, and auto-backup orchestration.
Used by write, edit_symbol, edit_match, and batch commands.
Structs§
- Reformatted
Excerpt - Post-format excerpt of the region(s) the formatter reflowed, so the agent
can re-anchor its next edit on the real on-disk text instead of the text it
submitted.
Noneon WriteResult when the formatter did not change the applied edit (self-suppressing). - Write
Result - Result of the write → format → validate pipeline.
Functions§
- attach_
preview_ diff - Attach the standard preview diff fields to a command response payload.
- auto_
backup - Snapshot the file into the backup store before mutation, scoped to a session.
- build_
unified_ diff - Build the unified-diff string used by internal permission previews.
- compute_
diff_ counts - Compute compact diff counts (additions/deletions) without echoing any file content. This is the agent-facing default — the payload is constant-size regardless of how large the edited file is.
- compute_
diff_ for_ response - Pick the right diff shape for a response based on request flags.
- compute_
diff_ info - Compute diff info between before/after content for UI metadata. Returns a JSON value with before, after, additions, deletions. For files >512KB, omits full content and returns only counts.
- compute_
reformatted_ excerpt - Compute a bounded post-format excerpt when
pre_format(agent-applied edit) differs frompost_format(on-disk after formatting). - format_
validation_ errors - Render structured validation errors as a compact
line N: messagelist for an error message. Used by the refactor handlers when a write was rolled back. - line_
col_ to_ byte - Convert 0-indexed line/col to a byte offset within
source. - replace_
byte_ range - Replace bytes in
[start..end)withreplacement. - validate_
syntax - Validate syntax of a file using a fresh FileParser (D023).
- validate_
syntax_ str - Validate syntax of an in-memory string without touching disk.
- wants_
diff - Check if the caller requested diff info in the response.
- wants_
diff_ content - Check if the caller requested the full before/after file contents in the
diff. This is for UI rendering only (e.g. the OpenCode/Pi plugins building a
diff view in tool metadata) and is deliberately NOT the default: full
content makes the response scale with file size, not edit size, which floods
agent context on large files. Agent-facing/raw consumers should pass
include_diff(counts only) instead. - wants_
preview - Check whether the caller requested an internal, side-effect-free preview.
- write_
format_ validate - Write content to disk, auto-format, then validate syntax.