pub enum PatchOp {
Insert {
offset: usize,
content: String,
},
Delete {
offset: usize,
len: usize,
expected: Option<String>,
},
Replace {
offset: usize,
len: usize,
content: String,
expected: Option<String>,
},
InsertLine {
line: usize,
content: String,
},
DeleteLine {
line: usize,
expected: Option<String>,
},
ReplaceLine {
line: usize,
content: String,
expected: Option<String>,
},
Append {
content: String,
},
}Expand description
Generic patch operation for file modifications.
Maps to POSIX operations, CRDTs, or REST APIs. All positional ops
support compare-and-set (CAS) via optional expected field.
If expected is Some, the operation fails with ConflictError if the
current content at that position doesn’t match.
§Line Ending Normalization
Line-based operations (InsertLine, DeleteLine, ReplaceLine) normalize
line endings to Unix-style (\n). Files with \r\n (Windows) line endings
will be converted to \n after a line-based patch. This is intentional for
kaish’s Unix-first design. Use byte-based operations (Insert, Delete,
Replace) to preserve original line endings.
Variants§
Insert
Insert content at byte offset.
Delete
Delete bytes from offset to offset+len.
expected: if Some, must match content being deleted (CAS)
Replace
Replace content at offset.
expected: if Some, must match content being replaced (CAS)
InsertLine
Insert a line at line number (1-indexed).
DeleteLine
Delete a line at line number (1-indexed).
expected: if Some, must match line being deleted (CAS)
ReplaceLine
Replace a line at line number (1-indexed).
expected: if Some, must match line being replaced (CAS)
Append
Append content to end of file (no CAS needed - always safe).