Loupe · Engineering case study
How Loupe gives a local model a smaller edit
A model can return a plausible edit for a line that does not exist. In Loupe, deciding which lines the model sees and checking which lines it names are two separate jobs.
How the excerpt gets chosen
Loupe starts with the shape of the source text. Its Swift code measures indentation on each line and uses line length when indentation varies too little. A set of periodic filters looks for a passage where a repeating pattern breaks. This can flag a disrupted block of regularly shaped functions before the language model reads a word.
When the detector reports a confident finding and the input exceeds sixteen lines, Loupe includes the flagged passage and up to three neighbouring lines on either side. Otherwise it supplies the full input. Each line keeps its original number, so a model looking at a short excerpt and a caller looking at the entire file can refer to the same location.
Following a proposed edit
For a block repair, Loupe asks the local model for a start line, an end line, an issue and replacement code. Suppose the original span includes a function definition and the model returns only a bare expression. The verifier looks for a definition marker in the replacement and can reject the fragment. The model receives the reason for rejection and one chance to revise. A second rejection ends the request.
What the check establishes
The library returns the proposed replacement text to its caller. Its verifier checks the span, required fields and basic shape of the replacement. A complete-looking function can still compute the wrong answer. The published tests exercise the signal detector with known periodic patterns and deliberately disrupted passages. Behavioural correctness of a proposed edit still needs a test of the edited program.