Skip to content

fix: remove misleading hint from replace pos only description#2176

Merged
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
YLRong:fix/replace-pos-only-description
Mar 2, 2026
Merged

fix: remove misleading hint from replace pos only description#2176
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
YLRong:fix/replace-pos-only-description

Conversation

@YLRong
Copy link
Contributor

@YLRong YLRong commented Feb 27, 2026

Problem

When an agent uses the replace operation with pos only (without end) but provides multi-line content in lines, the tool only replaces a single line. This causes subsequent lines from the original file to be retained, resulting in duplicate code.

Root Cause

The tool description contains a misleading hint: "(MOST COMMON for single-line edits)". This misleads agents into thinking that pos-only replace is the default/recommended approach, even when they need to replace multiple lines.

Concrete Example

Original file (3 lines):

export function cn(...inputs: string[]) {  // line 1
  return inputs.join(' ');                  // line 2
}                                          // line 3

Agent intends to replace with (4 lines):

export function cn(...inputs: string[]) {
  // test comment
  return inputs.join(' ');
}

Agent constructs:

{
  "op": "replace",
  "pos": "1#ZV",
  "lines": "export function cn(...inputs: string[]) {\n  // test comment\n  return inputs.join(' ');\n}"
}

What happens:

  • Tool checks: no end specified → uses applySetLine() (single-line replacement)
  • Tool executes: splice(line - 1, 1, ...replacement) — deletes 1 line, inserts 4 lines
  • Result: Original lines 2-3 are retained!

Actual output (6 lines):

export function cn(...inputs: string[]) {  // new line 1
  // test comment                        // new line 2
  return inputs.join(' ');                // new line 3
}                                         // new line 4
  return inputs.join(' ');                // old line 2 (retained!)
}                                         // old line 3 (retained!)

Solution

Remove the misleading hint from the tool description. Agents should understand that:

  • pos only → replaces exactly one line
  • pos + end → replaces the entire range

Reproduction Steps

  1. Create a file with 3 lines
  2. Use the edit tool with pos-only replace, passing 4 lines in the lines parameter
  3. Result: Lines 2-3 from the original file are retained, causing 6 lines of output

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: This is a safe documentation-only change that clarifies tool behavior by removing a misleading hint, posing no risk of functional regression.

@YLRong
Copy link
Contributor Author

YLRong commented Feb 27, 2026

I have read the CLA Document and I hereby sign the CLA

The hint '(MOST COMMON for single-line edits)' misleads agents into
thinking pos-only replace is the default behavior. When agents want
to replace multiple lines but only specify pos without end, the tool
only replaces one line, causing duplicate code from retained lines.
@YLRong YLRong force-pushed the fix/replace-pos-only-description branch from 1673b28 to c1eaf5f Compare February 27, 2026 09:06
github-actions bot added a commit that referenced this pull request Feb 27, 2026
@code-yeongyu code-yeongyu merged commit 7236e6e into code-yeongyu:dev Mar 2, 2026
2 checks passed
dorgonman pushed a commit to kanohorizonia/oh-my-opencode that referenced this pull request Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants