wb_edit_code replace_lines corrupts the code block when lineIds are out of document order
- 主要言語
- TypeScript
- スター
- 37.7k
- フォーク
- 5.9k
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 205
説明
`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.
コントリビューションガイド
調査の方向性
lib/action/engine.ts の ActionEngine.executeWbEditCode から始めて、replace_lines 操作を調べ、その後 lib/types/action.ts の WbEditCodeAction.lineIds を確認します。Issue の ["D", "B"] ケースを再現し、順序付けられた ID に対する期待される動作を変更せずに、置換が置換対象の最上位の行を基準に行われることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 76/100