wb_edit_code replace_lines corrupts the code block when lineIds are out of document order
- Lenguaje dominante
- TypeScript
- Estrellas
- 37.7k
- Forks
- 5.9k
- Merge medio
- 1 d 6 h
- PR fusionados (30 d)
- 205
Descripción
`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.
Guía de contribución
Línea de trabajo
Comienza en lib/action/engine.ts, en ActionEngine.executeWbEditCode, e inspecciona la operación replace_lines. Después, revisa WbEditCodeAction.lineIds en lib/types/action.ts. Reproduce el caso ["D", "B"] del issue y verifica que el reemplazo esté anclado en la línea reemplazada más alta sin cambiar el comportamiento esperado para los IDs ordenados.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 76/100