can1357/oh-my-pi · error · Error

Operation ${operationNumber} inline replacements do not alig

Error message

Operation ${operationNumber} inline replacements do not align with its selections.

What it means

For an inline-style rewrite operation, each selection in the PATTERN must have exactly one replacement in REWRITE. This check fires when pattern.selectionPairs.length differs from the number of resolved inline replacements, so the library cannot pair them up. It is a strict arity guard before applying per-selection edits.

Source

Thrown at packages/coding-agent/src/edit/sloppy.ts:3596

				deferredAmbiguous.add(index);
				queue.push(index);
				continue;
			}
			throw error;
		}
		const operation = located.operation;
		const pattern = located.pattern;
		const candidates = located.candidates;
		const orderedCandidates = operation.all
			? [...candidates].sort((left, right) => right.start - left.start)
			: candidates;

		if (operation.rewrite.kind === "inline") {
			const replacements = operation.rewrite.replacements.map(rewrite =>
				resolveRewriteReferences(rewrite, removedByOperation),
			);
			if (pattern.selectionPairs.length !== replacements.length) {
				throw new Error(`Operation ${operationNumber} inline replacements do not align with its selections.`);
			}
			let changes = 0;
			let deletedText: string | undefined;
			for (const located of orderedCandidates) {
				const selections = located.selectionSpans
					.map((span, selectionIndex) => ({
						span,
						selection: pattern.selectionPairs[selectionIndex],
						rewrite: replacements[selectionIndex],
					}))
					.sort((left, right) => right.span.start - left.span.start);
				for (const selection of selections) {
					if (selection.selection === undefined || selection.rewrite === undefined) {
						throw new Error(`Operation ${operationNumber} inline replacements do not align with its selections.`);
					}
					const prepared = prepareInlineSelectionEdit(
						content,
						located,

View on GitHub (pinned to 9690622007)

Solutions

  1. Make the number of REWRITE replacement segments equal the number of PATTERN selections, in order.
  2. Fix or remove dangling »N reference lines so each replacement resolves.
  3. Recount selections in PATTERN (each marked span counts) and pad/trim REWRITE accordingly.

Example fix

// before (2 selections, 1 replacement)
====
replacementA

// after
====
replacementA
replacementB
Defensive patterns

Strategy: validation

Validate before calling

function assertInlineAlignment(selectionCount: number, replacements: string[]) {
  if (selectionCount !== replacements.length)
    throw new Error(`inline operation: ${selectionCount} selections but ${replacements.length} replacements`);
}

Type guard

const aligned = (pairs: unknown[], replacements: (string | undefined)[]): boolean =>
  pairs.length === replacements.length && replacements.every(r => typeof r === "string");

Try / catch

try {
  applySloppyEdit(payload);
} catch (err) {
  if (err instanceof Error && err.message.includes("inline replacements do not align")) {
    payload = padReplacementsToSelectionCount(payload);
    applySloppyEdit(payload);
  } else throw err;
}

Prevention

When it happens

Trigger: An operation with kind 'inline' whose REWRITE supplies fewer or more replacement segments than the PATTERN's selections, after cross-operation »N references are resolved.

Common situations: Author adds a selection to PATTERN but forgets a replacement segment; a »N reference line resolves to nothing, shrinking the replacement list; copy-paste dropping one replacement block.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/759bd3253d8418b5. Report an issue: GitHub.