can1357/oh-my-pi · error
${REWRITE_HEADER}${reference[1]} is valid only inside an inl
Error message
${REWRITE_HEADER}${reference[1]} is valid only inside an inline replacement or REWRITE, never MATCH. What it means
A » reference (a patternReference like »N pointing at another operation's rewrite) found in a MATCH section's inline pattern is invalid — » rewrites are only meaningful as the target of an inline replacement or inside a REWRITE block, never as bare MATCH pattern text.
Source
Thrown at packages/coding-agent/src/edit/sloppy.ts:1099
if (inline.replacements.length === 1 && inline.replacements[0] === "") {
const tail = inline.patternText.match(/(?:^|\n)[ \t]*⟪⟫[ \t]*$/u);
if (tail?.index !== undefined) {
const remainder = inline.patternText.slice(0, tail.index);
if (normalizeText(remainder).text !== "") {
const wholeDeletion: Operation = {
patternText: remainder,
sourcePatternText,
rewrite: { kind: "explicit", text: "" },
all,
};
if (inline.notes.length > 0) wholeDeletion.recoveryNote = inline.notes.join("\n");
return wholeDeletion;
}
}
}
const reference = patternReference(inline.patternText);
if (reference) {
throw new Error(
`${REWRITE_HEADER}${reference[1]} is valid only inside an inline replacement or REWRITE, never MATCH.`,
);
}
const operation: Operation = {
patternText: relocateSelectionLines(inline.patternText),
sourcePatternText,
rewrite: { kind: "inline", replacements: inline.replacements },
all,
};
if (inline.notes.length > 0) operation.recoveryNote = inline.notes.join("\n");
return operation;
}
const reference = patternReference(sourcePatternText);
if (reference) {
throw new Error(`${REWRITE_HEADER}${reference[1]} is valid only in REWRITE, never MATCH.`);
}
if (rewriteText.trim() !== "") {View on GitHub (pinned to 9690622007)
Solutions
- Move the »N reference into the replacement part of an inline selection (⟪old│»N⟫) or a REWRITE block
- Replace the reference with the literal text it pointed to in the MATCH pattern
- Change the section from MATCH to REWRITE if the intent was a rewrite
Example fix
// before § MATCH ⟪old⟫ »2 // after § MATCH ⟪old│»2⟫
Defensive patterns
Strategy: validation
Validate before calling
if (/^\s*»\d+/m.test(matchPatternSection)) {
throw new Error('»N references are not allowed in MATCH pattern text');
} Try / catch
try {
applySloppy(content, input, ctx);
} catch (err) {
if (err instanceof Error && err.message.includes('valid only inside an inline replacement or REWRITE')) {
// move the »N reference into the replacement/REWRITE and re-send
} else throw err;
} Prevention
- Place »N references only in replacement positions (⟪old│»N⟫) or REWRITE bodies
- Keep MATCH patterns as plain literal text
- Review MATCH section layout before submitting
When it happens
Trigger: createOperation parsing a MATCH (inline) operation whose pattern text contains a »N reference outside an inline replacement context.
Common situations: An LLM emits '»2' in a MATCH section intending to alias another op's rewrite; confusion between MATCH and REWRITE section semantics when composing a payload.
Related errors
- ${REWRITE_HEADER}${reference[1]} is valid only in REWRITE, n
- Operation ${operationNumber} has an unclosed selection marke
- Operation ${operationNumber} has an unmatched closing select
- lines.join("\n")
- Operation ${operationNumber} has nested selection markers; u
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/7021f1e2f93a7710.
Report an issue: GitHub.