From 157232327bcfbc495b5024c6d346ef47f52e620c Mon Sep 17 00:00:00 2001 From: Oleksii Radetskyi Date: Fri, 13 Feb 2026 12:28:09 +0100 Subject: [PATCH 1/2] add the line numbers to diff --- diff_parser.py | 21 +++++++++++++++------ review_core.py | 4 +++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/diff_parser.py b/diff_parser.py index ad9c914..40cc9b2 100644 --- a/diff_parser.py +++ b/diff_parser.py @@ -56,6 +56,7 @@ def parse_diff(self, diff_text: str) -> List[Dict[str, Any]]: files = [] current_file = None current_hunk = None + new_line_num = 0 lines = diff_text.split("\n") i = 0 @@ -108,6 +109,8 @@ def parse_diff(self, diff_text: str) -> List[Dict[str, Any]]: new_start = int(match.group(3)) new_count = int(match.group(4) or 1) + new_line_num = new_start + current_hunk = { "old_start": old_start, "old_count": old_count, @@ -130,12 +133,16 @@ def parse_diff(self, diff_text: str) -> List[Dict[str, Any]]: current_hunk["context_before"].append(line[1:]) elif current_hunk["added_lines"] or current_hunk["removed_lines"]: current_hunk["context_after"].append(line[1:]) + new_line_num += 1 elif line.startswith("-"): - # Removed line + # Removed line (do not increment new_line_num) current_hunk["removed_lines"].append(line[1:]) elif line.startswith("+"): - # Added line - current_hunk["added_lines"].append(line[1:]) + # Added line with line number + current_hunk["added_lines"].append( + {"line": new_line_num, "content": line[1:]} + ) + new_line_num += 1 i += 1 @@ -196,9 +203,11 @@ def format_for_llm(self, parsed_files: List[Dict[str, Any]]) -> str: for line in hunk["removed_lines"]: formatted_sections.append(f"- {line}") - # Show added lines - for line in hunk["added_lines"]: - formatted_sections.append(f"+ {line}") + # Show added lines with line numbers + for entry in hunk["added_lines"]: + formatted_sections.append( + f"+ {entry['line']}: {entry['content']}" + ) formatted_sections.append("") # Empty line for readability diff --git a/review_core.py b/review_core.py index 6c28763..8bd8b90 100644 --- a/review_core.py +++ b/review_core.py @@ -58,6 +58,7 @@ class LLMReviewer: Rules: - Report ONLY issues you can see in the actual diff. Do NOT give generic advice. - Each issue MUST reference a specific file and line, using format: file.py:42: description +- Added lines in the diff are prefixed with their line number (e.g., "+ 42: code"). Use these exact numbers when referencing issues. - If no issues found, respond "NONE" for that category. - Be concise. Do not repeat yourself. @@ -155,7 +156,8 @@ def _build_prompt(self, diff_content: str) -> str: Rules for code suggestions: - Every SUGGESTION with file:line MUST have a ```suggestion block with exact replacement code - Keep indentation matching the original code -- Only omit the code block for general advice without a specific file:line reference""" +- Only omit the code block for general advice without a specific file:line reference +- Line numbers prefixed on added lines (e.g., "+ 42: code") are metadata only. Do NOT include them in suggested code.""" else: code_suggestion_format = "" From b680d75462344ecb6caff4e3afcbcb223f5ce267 Mon Sep 17 00:00:00 2001 From: Oleksii Radetskyi Date: Fri, 13 Feb 2026 13:46:01 +0100 Subject: [PATCH 2/2] update prompt to reduce false/positives --- review_core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/review_core.py b/review_core.py index 8bd8b90..1767761 100644 --- a/review_core.py +++ b/review_core.py @@ -61,6 +61,9 @@ class LLMReviewer: - Added lines in the diff are prefixed with their line number (e.g., "+ 42: code"). Use these exact numbers when referencing issues. - If no issues found, respond "NONE" for that category. - Be concise. Do not repeat yourself. +- Before reporting a bug or logic error, carefully trace the COMPLETE control flow — check all branches, shared statements after if/elif/else blocks, and surrounding context. Do NOT report issues based on partial reading of the code. +- NEVER reference line numbers or code that is not present in the diff below. Every file:line you cite must correspond to actual content in the diff. +- Do NOT speculate about how code might be called or what data structures might look like outside the diff. Only report issues visible in the provided code. CRITICAL ISSUES (block commit): - Hardcoded credentials, API keys, secrets