Skip to content

fix(prompts): line-number stripping warning missing from search_replace, edit_file, and read_file tool descriptions #716

Description

@edelauna

Problem (one or two sentences)

Models that use read_file output as input to search_replace or edit_file fail with exact-match errors because the line-number prefixes (137 | content) produced by read_file are copied verbatim into old_string. The tool descriptions for these two tools have no warning about this, unlike the recently patched apply_diff (PR #641).

Context (who is affected and when)

Affects any model/provider that copies read_file output directly into search_replace or edit_file — observed with Gemini but likely reproducible with others. Occurs whenever a model reads a file and then attempts an edit using content from that output.

Reproduction steps

  1. Use Zoo Code with any model that references read_file output when constructing edit calls.
  2. Model calls read_file on a file — output is prefixed with 137 | someCode() etc.
  3. Model calls search_replace or edit_file with old_string copied verbatim from that output (including the 137 | prefix).
  4. Tool fails with an exact-match / Edit Unsuccessful error because the raw file contains no such prefixes.
  5. Repeated failures eventually hit consecutiveMistakeLimit.

Expected result

Tool descriptions warn models that read_file line-number prefixes (e.g. 137 | ) are decorative and must not be included in old_string.

Actual result

search_replace.ts and edit_file.ts parameter descriptions say old_string must match file contents exactly, but give no guidance about stripping read_file prefixes. edit.ts (the native Edit tool) already has this warning at line 7 — making the omission inconsistent across sibling tools.

Variations tried

The root-cause fix would be a single upstream warning in the read_file description itself (read_file.ts:65), protecting all downstream tools without requiring each to repeat it. The actual format from addLineNumbers() in extract-text.ts:155 is ${lineNumber} | ${line} (space-padded integer + | + content).

Suggested per-tool additions:

  • read_file.ts: "NOTE: Line-number prefixes (e.g. 137 | ) are for reference only and do NOT exist in the raw file. Do NOT copy them into old_string, SEARCH blocks, or other edit inputs."
  • search_replace.ts old_string: "Do NOT include line-number prefixes (e.g. 137 | ) from read_file output — the file itself does not contain them."
  • edit_file.ts old_string: same note as above.

App Version

Observed against current main (post PR #641).

API Provider

Google Gemini (originally reported), but affects any model that copies read_file output verbatim.

Model Used

Gemini (and likely others).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions