Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions diff_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ potential logic error – added_lines now stores dicts instead of plain strings, which may break code that expects string entries.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Incrementing new_line_num for a removed line; should only increment after added lines.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 remove incorrect new_line_num increment for removed lines

Suggested change
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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion review_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ 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.
- 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
Expand Down Expand Up @@ -155,7 +159,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 = ""

Expand Down