Documentation
¶
Overview ¶
Package editblock is the edit engine: the fuzzy matcher that lands a replacement in a file, and the did-you-mean that explains why one didn't.
It used to also parse SEARCH/REPLACE blocks and whole-file listings out of a model's prose, and plan a batch of parsed edits. Both went with the text edit formats: an edit now arrives as a tool call with a typed path, so there is nothing to parse, nothing to re-attribute across files, and no batch report to write in SEARCH/REPLACE terms. What survives is the part that was never about the format — matching text that a model reproduced imperfectly.
Index ¶
- Variables
- func CountOccurrences(content, search string) int
- func DoReplace(fname string, content string, exists bool, beforeText, afterText string, ...) (string, bool)
- func FindSimilarLines(search, content string, threshold float64) string
- func ReplaceMostSimilarChunk(whole, part, replace string) (string, bool)
- func StripQuotedWrapping(res, fname string, fence Fence) string
- type Fence
- type Op
- type OpKind
Constants ¶
This section is empty.
Variables ¶
var AllFences = []Fence{
{"```", "```"},
{"````", "````"},
{"<source>", "</source>"},
{"<code>", "</code>"},
{"<pre>", "</pre>"},
{"<codeblock>", "</codeblock>"},
{"<sourcecode>", "</sourcecode>"},
}
AllFences is the 7-entry escalation list from base_coder.py, in order. chooseFence walks it; the golden parser test uses it to pick a fence per section.
var DefaultFence = Fence{"```", "```"}
DefaultFence is triple backticks.
Functions ¶
func CountOccurrences ¶
CountOccurrences reports how many times the search text appears verbatim in content, so a failed edit can say "three places, narrow it down" instead of "not found" — which is false and sends the model looking for a typo it did not make.
func DoReplace ¶
func DoReplace(fname string, content string, exists bool, beforeText, afterText string, fence Fence) (string, bool)
DoReplace ports do_replace: strip wrapping, then create/append/replace. exists says whether the target file already exists; content is its current text ("" for a new file).
func FindSimilarLines ¶
FindSimilarLines ports find_similar_lines: the best window of content lines resembling the search lines at ratio >= threshold, expanded by 5 lines each way unless the endpoints already line up.
func ReplaceMostSimilarChunk ¶
ReplaceMostSimilarChunk is the matching ladder: perfect match, uniform-leading-whitespace match, the two again without a spurious leading blank line, then "..." elision. The upstream fuzzy step is dead code and is not ported.
func StripQuotedWrapping ¶
StripQuotedWrapping removes a redundant filename line and fence pair the model sometimes wraps around a section.
Types ¶
type Fence ¶
type Fence struct {
Open, Close string
}
Fence is an open/close pair wrapping file content in prompts and model replies.
type Op ¶
Op is one span of a line-level diff: a[A1:A2] became b[B1:B2]. For OpEqual the two spans have the same length; for OpDelete B1 == B2, and for OpInsert A1 == A2.
func LineOps ¶
LineOps returns the opcodes describing how the line list a becomes b, in order and covering both inputs completely. It ports difflib.get_opcodes over the matching blocks the sequence matcher already computes, which is the same engine ReplaceMostSimilarChunk and FindSimilarLines run on.
The renderer uses it to show an edit as what actually changed: the edit tool asks the model for surrounding context so the search matches uniquely, and without a diff every one of those unchanged lines reads as removed and added back.