Documentation
¶
Overview ¶
Package edit implements the safe edit transaction used by the agent: read → verify the anchor is unique → patch → re-read → show the diff. Anchored search/replace, no second model. Bash-driven edits are caught separately by the runtime via `git diff`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format runs the canonical formatter for path's language, by extension, IN PLACE — if that tool is on PATH. Best-effort: a missing tool or a formatter error (e.g. the edit left a syntax error) is silently ignored; formatting is a courtesy, never a gate. Returns the tool name when it ran, "" otherwise (for display).
Types ¶
type Result ¶
type Result struct {
Path string `json:"path"`
Applied bool `json:"applied"`
Occurrences int `json:"occurrences"`
Created bool `json:"created"`
Diff string `json:"diff"`
}
Result reports the outcome of an edit.
func Apply ¶
func Apply(ctx context.Context, root, path, oldString, newString string, replaceAll bool) (Result, error)
Apply performs an anchored search/replace on path (relative to root).
- oldString == "" creates a new file with newString (errors if it exists).
- otherwise oldString must occur exactly once, unless replaceAll is set.
The file is re-read after writing to confirm the change landed, and a git diff is captured for the agent to inspect.