can1357/oh-my-pi · error

Operation has no visible current text.

Error message

Operation ${operationNumber} has no visible current text.

What it means

The sloppy-edit pattern parser rejects an operation whose pattern contains no gap marker (`...`) and no selection markers (`«` `»`), yet after normalizing (trimming indentation and whitespace) has no visible text left. Such a pattern carries no anchor content at all, so the library throws rather than try to match an empty literal against the file.

Solutions

  1. Include actual visible code text in the pattern (e.g. a statement or identifier from the file).
  2. If the pattern intentionally spans a region, add a `...` gap marker between the anchors.
  3. If the pattern is meant to insert into a position, wrap the insertion point with selection markers `«` `»`.

Example fix

// before
const pattern = "   ";
// after
const pattern = "return computeTotal(items);";
Defensive patterns

Strategy: validation

Validate before calling

if (pattern.trim() !== "" && !/\S/.test(pattern)) throw new Error("pattern has no visible text");
// simpler: ensure some non-whitespace, non-marker content exists before calling the edit API
if (!/[\p{L}\p{N}_$]/u.test(pattern.replace(/«|»|\.\.\./g, ""))) {
  throw new Error("pattern must contain visible text, a gap (...), or a selection");
}

Type guard

function hasVisiblePatternText(pattern: string): boolean {
  const stripped = pattern.replace(/«|»|\.\.\./g, "");
  return stripped.trim().length > 0;
}

Try / catch

try {
  await applySloppyEdit({ pattern });
} catch (err) {
  if (err instanceof Error && err.message.includes("no visible current text")) {
    // rebuild pattern with a real anchor line from the file
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the sloppy edit operation with a pattern that is only whitespace, only comment markers, or only indentation between markers, without a `...` gap or `«...»` selection. E.g. pattern `" "` or `"//"` passes the empty-pattern check but fails normalizeText producing an empty normalized string.

Common situations: Hand-copying a pattern that is purely indentation or blank lines from an editor; building patterns programmatically where the gap marker variable ends up empty; pasting a region where the intended anchor line is a whitespace-only line.

Related errors


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

Appendix: source

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

	return { text, starts, ends };
}

function patternGapAt(source: string, offset: number): string | undefined {
	return source.startsWith(GAP, offset) ? GAP : undefined;
}

function patternContainsGap(source: string): boolean {
	return source.includes(GAP);
}

function parsePattern(pattern: string, operationNumber: number): ParsedPattern {
	if (pattern.trim() === "") throw new Error(`Operation ${operationNumber} has an empty pattern.`);
	validateSelectionMarkers(pattern, operationNumber);
	const hasGap = patternContainsGap(pattern);
	const hasSelection = pattern.includes(SELECT_OPEN);
	if (!hasGap && !hasSelection) {
		const normalized = normalizeText(pattern).text;
		if (normalized === "") throw new Error(`Operation ${operationNumber} has no visible current text.`);
		return {
			tokens: [{ kind: "literal", text: pattern, normalized }],
			selectionStart: 0,
			selectionEnd: 1,
			insertion: false,
			lineInsertion: false,
			selectedCaptureIndices: [],
			selectionRanges: [],
			selectionPairs: [],
			literalFallback: undefined,
		};
	}

	const tokens: PatternToken[] = [];
	let literal = "";
	let captureCount = 0;
	const selectionBoundaries: number[] = [];
	const selectionAtLineStart: boolean[] = [];

View on GitHub (pinned to 9690622007)