editblock

package
v0.0.0-...-95517ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
var DefaultFence = Fence{"```", "```"}

DefaultFence is triple backticks.

Functions

func CountOccurrences

func CountOccurrences(content, search string) int

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

func FindSimilarLines(search, content string, threshold float64) string

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

func ReplaceMostSimilarChunk(whole, part, replace string) (string, bool)

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

func StripQuotedWrapping(res, fname string, fence Fence) string

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

type Op struct {
	Kind           OpKind
	A1, A2, B1, B2 int
}

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

func LineOps(a, b []string) []Op

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.

type OpKind

type OpKind int

OpKind is how one span of the "before" side relates to the "after" side.

const (
	// OpEqual: the two spans are identical.
	OpEqual OpKind = iota
	// OpDelete: the "before" span is gone, with nothing in its place.
	OpDelete
	// OpInsert: the "after" span is new, replacing nothing.
	OpInsert
	// OpReplace: the "before" span gave way to the "after" span.
	OpReplace
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL