Expand description
Write/Edit/MultiEdit tool — Rust port of @agent-sh/harness-write.
Contract matches agent-knowledge/design/write.md and the TS
package: atomic write via temp file + rename, read-before-edit
ledger enforcement (NOT_READ_THIS_SESSION / STALE_READ), fuzzy
candidates on OLD_STRING_NOT_FOUND, match locations on
OLD_STRING_NOT_UNIQUE, CRLF→LF normalization, sequential
MultiEdit pipeline with rollback on failure.
Structs§
- Apply
Result - Edit
Meta - Edit
Params - Edit
Spec - Error
Result - Fuzzy
Candidate - InMemory
Ledger - Ledger
Entry - Match
Location - Multi
Edit Meta - Multi
Edit Params - Preview
Meta - Preview
Result - Text
Write Result - Write
Meta - Write
Params - Write
Session Config
Enums§
Constants§
- BINARY_
SAMPLE_ BYTES - CONTEXT_
LINES - DEFAULT_
FUZZY_ LENGTH_ TOLERANCE - DEFAULT_
FUZZY_ THRESHOLD - DEFAULT_
FUZZY_ TOP_ K - EDIT_
TOOL_ DESCRIPTION - EDIT_
TOOL_ NAME - MAX_
EDIT_ FILE_ SIZE - MULTIEDIT_
TOOL_ DESCRIPTION - MULTIEDIT_
TOOL_ NAME - WRITE_
TOOL_ DESCRIPTION - WRITE_
TOOL_ NAME
Traits§
- Ledger
- Mirror of the TS
Ledgersurface: keyed by path, most-recent wins.
Functions§
- apply_
edit - Apply a single edit spec to
content. Returns either the new content + counts, or a structured ToolError. - apply_
pipeline - build_
match_ locations - edit
- find_
all_ occurrences - Find all exact occurrences of
needleinhaystack. Returns byte offsets. - find_
fuzzy_ candidates - levenshtein
- Levenshtein distance O(n*m) time, O(min(n,m)) space.
- multi_
edit - normalize_
line_ endings - Normalize CRLF → LF. Matches the TS normalizer exactly.
- safe_
parse_ edit_ params - safe_
parse_ multi_ edit_ params - safe_
parse_ write_ params - similarity
- substring_
boundary_ collisions - Boundary-collision check: flag lines where
needlesits adjacent to identifier characters — caller may be stomping on a longer identifier. - unified_
diff - Produce a unified-diff string. Uses the
similarcrate’s grouped hunks. Output shape:--- old\n+++ new\n@@ ... @@\n ...\n- ...\n+ .... - write