earendil-works/pi · error · Error
Replacement range is outside the base content.
Error message
Replacement range is outside the base content.
What it means
Error "Replacement range is outside the base content." thrown in earendil-works/pi.
Source
Thrown at packages/agent/src/harness/tools/edit-diff.ts:93
offset = span.end;
return span;
});
}
function getReplacementLineRange(lines: LineSpan[], replacement: TextReplacement) {
const replacementStart = replacement.matchIndex;
const replacementEnd = replacement.matchIndex + replacement.matchLength;
let startLine = -1;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (replacementStart >= line.start && replacementStart < line.end) {
startLine = i;
break;
}
}
if (startLine === -1) {
throw new Error("Replacement range is outside the base content.");
}
let endLine = startLine;
while (endLine < lines.length && lines[endLine].end < replacementEnd) {
endLine++;
}
if (endLine >= lines.length) {
throw new Error("Replacement range is outside the base content.");
}
return { startLine, endLine: endLine + 1 };
}
function applyReplacements(content: string, replacements: TextReplacement[], offset = 0): string {
let result = content;
for (let i = replacements.length - 1; i >= 0; i--) {
const replacement = replacements[i];
const matchIndex = replacement.matchIndex - offset;View on GitHub (pinned to 4af9d21d3b)
Solutions
- Recompute the replacement range against the current base content before applying the edit.
When it happens
Trigger: Thrown at packages/agent/src/harness/tools/edit-diff.ts:93 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/91084039896f6194.
Report an issue: GitHub.