Skip to main content

Module edit

Module edit 

Source
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§

WriteResult
Result of the write → format → validate pipeline.

Functions§

auto_backup
Snapshot the file into the backup store before mutation, scoped to a session.
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.
line_col_to_byte
Convert 0-indexed line/col to a byte offset within source.
replace_byte_range
Replace bytes in [start..end) with replacement.
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.
write_format_validate
Write content to disk, auto-format, then validate syntax.