| 104 | } |
| 105 | |
| 106 | function enrichEditStartLines(event) { |
| 107 | const content = event.message && event.message.content; |
| 108 | if (!Array.isArray(content)) return; |
| 109 | for (const block of content) { |
| 110 | if (block.type !== 'tool_use' || block.name !== 'Edit') continue; |
| 111 | const input = block.input; |
| 112 | if (!input || !input.file_path || input.old_string === undefined) continue; |
| 113 | try { |
| 114 | const filePath = path.resolve(state.CWD, input.file_path); |
| 115 | const src = fs.readFileSync(filePath, 'utf8'); |
| 116 | const needle = input.new_string || input.old_string; |
| 117 | const idx = src.indexOf(needle); |
| 118 | if (idx >= 0) { |
| 119 | input._startLine = src.substring(0, idx).split('\n').length; |
| 120 | } |
| 121 | } catch {} |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // ============================================================ |
| 126 | // Hook Session Resolution |