@@ -223,25 +223,40 @@ agents:
223223
224224 ## Line Number Calculation Algorithm
225225
226- 1. Find the hunk header before your target line: `@@ -X,Y +Z,W @@`
227- - Z is the line number of the FIRST line after the header in the new file
228- 2. Starting from that first line (which is line Z), count through context (` `) and added (`+`) lines
229- 3. SKIP all deleted (`-`) lines - they don't exist in the new file
230- 4. Your target line number = Z + (number of ` ` and `+` lines before your target)
226+ CRITICAL: Use this exact algorithm to avoid off-by-one errors.
231227
232- Example:
228+ 1. Find the hunk header: `@@ -X,Y +Z,W @@`
229+ - **USE THE +Z VALUE** (the number after the +, NOT the -X value)
230+ - Z is the 1-indexed line number where the hunk starts in the NEW file
231+ - Z is ALREADY 1-indexed (first line of file is 1, not 0)
232+ - Example: In `@@ -81,11 +82,12 @@`, use Z=82 (not 81!)
233+
234+ 2. For each line after the hunk header, maintain a running line number starting at Z:
235+ - Context line (starts with ` `) → this is current_line_number, increment counter
236+ - Added line (starts with `+`) → this is current_line_number, increment counter
237+ - Deleted line (starts with `-`) → SKIP, do NOT increment counter
238+
239+ 3. When you find your target `+` line, the current_line_number IS the line to report.
240+
241+ Example walkthrough:
233242 ```
234- @@ -10,5 +15,7 @@
235- context line <- This is line 15 (Z from header, offset 0 )
236- context line <- This is line 16 (Z + 1 context line )
237- +problematic line <- This is line 17 (Z + 2 lines ) ← report as LINE: 17
238- context line <- This is line 18 (Z + 3 lines )
239- -deleted line <- SKIP - doesn't exist in new file
240- context line <- This is line 19 (Z + 4 lines, skipped the - )
243+ @@ -10,5 +15,7 @@ <- Z=15, start counting from 15
244+ context line <- Line 15 (current=15, increment to 16 )
245+ context line <- Line 16 (current=16, increment to 17 )
246+ +problematic line <- Line 17 (current=17, THIS is your target ) ← report LINE: 17
247+ context line <- Line 18 (current=18, increment to 19 )
248+ -deleted line <- NOT in new file, current stays at 19
249+ context line <- Line 19 (current=19, increment to 20 )
241250 ```
242251
243- IMPORTANT: GitHub uses 1-indexed lines. Do NOT use 0-indexed line numbers.
244- Do NOT say "around line X" - give the exact line number of the problematic `+` line.
252+ ANOTHER WAY TO THINK ABOUT IT:
253+ Line number = Z + (count of ` ` and `+` lines that appear BEFORE your target in the diff)
254+ - "Before" means: lines that come earlier in the hunk, NOT including the target itself
255+ - First line in hunk: Z + 0 lines before it = Z
256+ - Second line in hunk: Z + 1 line before it = Z + 1
257+ - Third line in hunk: Z + 2 lines before it = Z + 2
258+
259+ IMPORTANT: GitHub expects 1-indexed line numbers. Z is already 1-indexed from the diff.
245260
246261 toolsets :
247262 - type : filesystem
0 commit comments