opencode-cursor icon indicating copy to clipboard operation
opencode-cursor copied to clipboard

oc_edit / oc_write not registered in tool hook despite system prompt instructing model to use them

Open 14tinchov opened this issue 5 months ago • 6 comments

Summary

In CURSOR_ACP_TOOL_LOOP_MODE=opencode (default), the plugin system prompt tells the model to call tools as oc_edit, oc_write, etc., but buildToolHookEntries() only registers unprefixed names (edit, write, …).

bash already has a shell alias; edit/write/etc. do not have matching oc_* aliases.

Result: with cursor-acp/auto, the model calls oc_edit and the tool fails or retries in a loop.

Environment

  • @rama_nigg/open-cursor: 2.4.6
  • OpenCode with plugin cursor-acp
  • Model: cursor-acp/auto
  • OS: macOS
  • CURSOR_ACP_TOOL_LOOP_MODE: default (opencode)

Steps to reproduce

  1. Install and configure open-cursor per README
  2. Run OpenCode with model cursor-acp/auto
  3. Ask the agent to edit a file with a small targeted change
  4. Observe tool calls to oc_edit (or retries / "tool not found" behavior)

Expected

oc_edit resolves to the same handler as edit (same pattern as bash → shell).

Actual

Only edit is registered in the tool hook. The model follows the injected system message and calls oc_edit, which is missing.

Root cause

  • buildAvailableToolsSystemMessage() advertises oc_${id} names (via refreshTools() in proxy-exec path)
  • buildToolHookEntries() registers only t.name, not oc_${t.id}
  • TOOL_NAME_ALIASES in tool-loop.ts has bash/shell aliases but no ocedit → edit

Proposed fix

  1. In buildToolHookEntries(), register oc_${t.id} for each local tool
  2. In TOOL_NAME_ALIASES, add ocedit → edit, ocwrite → write, etc.

Happy to open a PR if useful.

14tinchov avatar Jun 10 '26 03:06 14tinchov

Thanks bud, will look at this properly Saturday (getting blasted at work this week which is just eating my open source / hobby time).

Nomadcxx avatar Jun 11 '26 06:06 Nomadcxx

same issue here. Any attempt to edit any file with OpenCode+Cursor(OpenCursor) erases the whole file and only keeps the modified lines

eyforia avatar Jun 12 '26 19:06 eyforia

Thanks mate, you were right here.

I’ve merged a fix to main in 277a8d8. The original oc_edit issue was fixed by registering the oc_* tool aliases, but that exposed an older bad edge case in the local edit executor: if a model sent old_string as an empty string, the edit tool treated that as a whole-file overwrite. That explains the “file gets erased and only keeps the modified lines” behaviour.

cheers, RAMA

Nomadcxx avatar Jun 14 '26 03:06 Nomadcxx

Thank you !!!! I assume this fix made it into 2.4.9 ?

eyforia avatar Jun 14 '26 07:06 eyforia

just tested on 2.4.9 and looks like the issue is still there. how to verify:

  1. update open-cursor to latest version:
npm update -g @rama_nigg/open-cursor
  1. run opencode, use one of cursor models (e.g. composer 2.5) and execute a simple text editing task:
create test.txt, fill it with numbers 1..100
save to disk
then change line 50 to "test test"
save to disk
then remove one of "test" so that there are no duplicates

Result: Image

eyforia avatar Jun 14 '26 07:06 eyforia

Yep oc_edit path and the empty old_string case, but composer can also send an edit payload with content / streamContent and no old_string. In that shape, opencode could still treat a tiny changed fragment as a full-file edit, which is why the file ended up getting cut down to just a few lines.

Cursor designs everything IDE-first which causes a lot issues downstream and makes its a real bastard to keep working... hopefully this fix works, if not will keep this one open and hopefully others have suggestions.

Nomadcxx avatar Jun 14 '26 12:06 Nomadcxx

Triage (2026-06-18): Keeping open as bug.

  • oc_* hook aliases shipped in v2.4.7+ (commit 88ba152)
  • Follow-up guards for Composer content/streamContent edit payloads shipped in v2.4.10–v2.4.11 (empty old_string / partial overwrite protection)

Latest report still reproduces on 2.4.9 — please retest on >= 2.4.11 and share whether the line-50 edit case is resolved. If not, we'll keep tracking the Composer IDE-first payload shape here.

Nomadcxx avatar Jun 17 '26 14:06 Nomadcxx

updated. retested. still fails. the agent enters an infinite loop trying to edit a single line of text and never completes.

nes 1–100, then updating line 50.
~ Preparing edit...
Thought: 8.0s
Proceeding with the task.
Write 
Thought: 1.9s
The previous write attempt was refused because it would partially overwrite an existing file. I will use edit with old_string and new_string instead, or pass force: true if I intend to replace the entire file.
~ Reading file...
Thought: 4.6s
The first step is complete. I am now reviewing the remaining tasks.

Line 50 already contains "test test". The file appears corrupted. I am reading the full file to assess its current state.
Checking the file state and finishing the remaining edits.
~ Reading file...
Thought: 1.1s
Proceeding with the task.
Write 
Thought: 10.4s
The write tool refused a partial overwrite of test.txt. I'll use edit with old_string and new_string instead.
Write 
Thought: 1.2s
The write tool refused to overwrite the existing file test.txt because it would reduce 100 lines to 1. I will use edit with old_string and new_string instead, or pass force: true if intentional.
Write 
Thought: 222ms
The write tool refused to overwrite test.txt because the new content is much smaller than the existing file. I will use edit instead to replace only the necessary portion.
Write 
Thought: 854ms
I need to complete the task on test.txt.
Write 
Thought: 2.2s
The user wants me to complete the task on test.txt.
Write 
Thought: 1.1s
The write operation was refused because it would partially overwrite an existing file. I'll use edit with old_string and new_string instead, or pass force: true if intentional full replacement is needed.
Write 
Thought: 1.1s
The previous write attempt was refused due to a suspicious partial overwrite. I will retry with a targeted edit or full replacement.
Write 
Thought: 2.1s
The user wants me to continue the task from the previous conversation.
Write 
Thought: 1.9s
The user wants me to complete the task.
Write 
Thought: 2.3s
The user wants me to continue the task.
Write 
Thought: 1.8s
The previous write operation was refused because it would partially overwrite an existing file. I will proceed by using edit with old_string and new_string instead, or by passing force: true if intentional full replacement is needed.
Write 
Thought: 2.2s
The user wants me to continue the task from the previous conversation. I'm reviewing the context to determine the next step.

Line 50 is now "test test". I'll use edit/strreplace to remove one duplicate "test" from that line.
Write 
Thought: 848ms
The first step is already done. The next steps are being reviewed.
Write 
The user wants me to complete the task on test.txt.

eyforia avatar Jun 17 '26 18:06 eyforia