{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package edit\n\nPackage 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\\`.\n\n## Functions\n\n```go\nfunc Format(ctx context.Context, root, path string) string\n```\nFormat 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).\n\n```go\nfunc Hash(root, path string) (string, bool)\n```\nHash returns the current content hash of a file (for staleness checks).\n\n```go\nfunc HashBytes(data []byte) string\n```\nHashBytes hashes already-read content the SAME way as Hash, so a hash recorded at read time compares directly against Hash() at write time (the stale-read guard).\n\n## Types\n\n```go\ntype Result struct {\n\tPath        string `json:\"path\"`\n\tApplied     bool   `json:\"applied\"`\n\tOccurrences int    `json:\"occurrences\"`\n\tCreated     bool   `json:\"created\"`\n\tDiff        string `json:\"diff\"`\n}\n```\nResult reports the outcome of an edit.\n\n```go\nfunc Apply(ctx context.Context, root, path, oldString, newString string, replaceAll bool) (Result, error)\n```\nApply performs an anchored search/replace on path (relative to root).\n\n  - oldString == \"\" creates a new file with newString (errors if it exists).\n  - otherwise oldString must occur exactly once, unless replaceAll is set.\n\nThe file is re-read after writing to confirm the change landed, and a git diff is captured for the agent to inspect.\n\n","path":"github.com/memcode-ai/memcode/internal/agent/edit","name":"edit","synopsis":"Package edit implements the safe edit transaction used by the agent: read → verify the anchor is unique → patch → re-read → show the diff.","isRedistributable":true}
