THU-MAIC / THU-MAIC/OpenMAIC

wb_edit_code replace_lines corrupts the code block when lineIds are out of document order

Aperta
#653 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:editor bug priority:P1 status:in-progress
Lingua principale
TypeScript
Stelle
37.2k
Fork
5.9k
Merge medio
1g 3h
PR unite (30g)
195

Descrizione

`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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.