Skip to main content

Crate harness_write

Crate harness_write 

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

ApplyResult
EditMeta
EditParams
EditSpec
ErrorResult
FuzzyCandidate
InMemoryLedger
LedgerEntry
MatchLocation
MultiEditMeta
MultiEditParams
PreviewMeta
PreviewResult
TextWriteResult
WriteMeta
WriteParams
WriteSessionConfig

Enums§

EditResult
MultiEditResult
PipelineResult
WriteParseError
WriteResult

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 Ledger surface: 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 needle in haystack. 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 needle sits adjacent to identifier characters — caller may be stomping on a longer identifier.
unified_diff
Produce a unified-diff string. Uses the similar crate’s grouped hunks. Output shape: --- old\n+++ new\n@@ ... @@\n ...\n- ...\n+ ....
write