wb_edit_code replace_lines corrupts the code block when lineIds are out of document order
- Dominant language
- TypeScript
- Stars
- 37.2k
- Forks
- 5.9k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 195
Description
`ActionEngine.executeWbEditCode`'s `replace_lines` operation (`lib/action/engine.ts`) computes the splice anchor as `lines.findIndex(l => l.id === replaceIds[0])` **before** filtering out the replaced lines. `WbEditCodeAction.lineIds` (`lib/types/action.ts`) is a plain `string[]` with no ordering contract, and the agent producing it may emit IDs out of document order.
When `replaceIds[0]` is not the topmost replaced line (e.g. `["L5", "L2"]`), the subsequent `.filter()` removes a line **above** the anchor, so the saved index goes stale and the replacement lines are spliced at the wrong position — corrupting the displayed code block.
### Reproduction (logic)
Lines `[A, B, C, D, E]`, `replace_lines` with `lineIds: ["D", "B"]`, content `"X"` → produces `[A, C, E, X]` (X appended at the end) instead of `[A, X, C, E]` (X where B was).
### Suggested fix
Anchor the insertion at the topmost (minimum original index) replaced line. PR to follow.
Contributor guide
Assessment
This issue has not been assessed yet.