Skip to content

Commit b93e284

Browse files
jorbenclaude
andauthored
fix(ci): 👷 improve LLM PR review workflow (#40)
* ci: 👷 add LLM PR review workflow with manual trigger Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 use x-api-key header for Anthropic API auth Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 use vars instead of secrets for API base URL and model ID Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 extract text content by type instead of fixed index Some models return thinking blocks before text content, causing the review text extraction to fail when using content[0]. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 use shallow clone and defensive jq extraction Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 improve diff handling for LLM review - Truncate on line boundary to avoid splitting multi-byte UTF-8 chars - Wrap diff in code fence for clearer LLM parsing - Add hunk header guidance in system prompt for accurate line references Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): 🐛 use correct Anthropic system field format The Anthropic Messages API expects system as an array of objects with type and text fields, not a plain string. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci(llm-review): ✨ enhance system prompt with project context and structured review guidelines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 500bc41 commit b93e284

1 file changed

Lines changed: 45 additions & 21 deletions

File tree

.github/workflows/llm-pr-review.yml

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,56 @@ jobs:
6666
max_diff_chars=131072
6767
pr_diff_trimmed=$(printf "%s" "$pr_diff" | head -c $max_diff_chars | sed '$d')
6868
69-
system_prompt=$(cat <<'EOF'
70-
You are a senior software engineer performing a pull request code review.
71-
Focus on: Correctness, Security, Performance, Maintainability, Readability, Testing.
72-
Output must be in English.
69+
system_prompt=$(cat <<'SYSPROMPT'
70+
You are a senior software engineer reviewing a pull request for an Electron desktop application (React 18 + TypeScript + Vite + Prisma/SQLite + Ant Design). The codebase follows Clean Architecture with domain/application/infrastructure layers and a three-stage worker pipeline (Split → Convert → Merge) for PDF-to-Markdown conversion via LLM vision APIs.
7371
74-
The diff is in unified diff format. Each hunk starts with a header like:
75-
@@ -old_start,old_count +new_start,new_count @@
76-
Use the +new_start line numbers from these hunk headers to calculate the
77-
actual file line numbers when referencing code in your review.
72+
## Review priorities (highest to lowest)
7873
79-
Use this exact format and omit empty sections:
80-
# Summary
81-
<1-2 sentences overall assessment>
74+
1. **Correctness** — Logic errors, race conditions, broken control flow, incorrect types, off-by-one errors, null/undefined mishandling
75+
2. **Security** — Command injection, path traversal, credential leaks, unsafe IPC, unvalidated external input (OWASP Top 10)
76+
3. **Resource & performance** — Memory leaks, unbounded loops, missing cleanup in Electron main process, unnecessary re-renders in React, N+1 queries
77+
4. **Error handling** — Swallowed errors, overly broad catch blocks, missing user-facing error feedback, silent failures that hide bugs
78+
5. **API & type contracts** — Breaking changes to IPC channel signatures, mismatched shared types between main/renderer, incorrect Prisma usage
79+
6. **Maintainability** — Violations of existing project patterns, dead code, missing or misleading abstractions
8280
83-
# Critical
84-
- [file:line] Title: explanation...
81+
## What NOT to comment on
8582
86-
# Important
87-
- [file:line] Title: explanation...
83+
- Pure style/formatting (handled by Prettier + ESLint)
84+
- Adding comments or docstrings to unchanged code
85+
- Minor naming preferences that don't affect clarity
86+
- Suggesting tests for trivial changes
87+
- Hypothetical future improvements unrelated to this PR
8888
89-
# Suggestion
90-
- [file:line] Title: explanation...
89+
## How to read the diff
9190
92-
# Praise
93-
- [file:line] Title: explanation...
94-
EOF
91+
The diff uses unified format. Each hunk header looks like:
92+
`@@ -old_start,old_count +new_start,new_count @@ optional_context`
93+
94+
To reference a line: start from `+new_start` and count only context lines (` `) and added lines (`+`), skipping removed lines (`-`). Use the format `file_path:line_number`.
95+
96+
## Output format
97+
98+
Use this exact structure. **Omit any section that has no items.** Each item must reference a specific location and be actionable.
99+
100+
### Summary
101+
1-3 sentences: what this PR does, overall quality assessment, and whether it is ready to merge.
102+
103+
### Critical
104+
Issues that **must** be fixed before merge — bugs, security vulnerabilities, data loss risks.
105+
- `file:line` — **Title**: Explanation of the issue and a concrete suggestion to fix it.
106+
107+
### Important
108+
Issues that **should** be fixed — error handling gaps, performance concerns, contract violations.
109+
- `file:line` — **Title**: Explanation and suggestion.
110+
111+
### Suggestion
112+
Non-blocking improvements — cleaner patterns, minor simplifications, readability tweaks.
113+
- `file:line` — **Title**: Explanation and suggestion.
114+
115+
### Praise
116+
Highlight 1-3 notably well-done aspects to reinforce good practices.
117+
- `file:line` — **Title**: What was done well and why it matters.
118+
SYSPROMPT
95119
)
96120
97121
request_body=$(jq -n \
@@ -103,7 +127,7 @@ jobs:
103127
'{
104128
model: $model,
105129
max_tokens: 8192,
106-
system: $system,
130+
system: [{ type: "text", text: $system }],
107131
messages: [
108132
{ role: "user", content: ("Review the following pull request.\n\n## Title\n" + $title + "\n\n## Description\n" + $body + "\n\n## Diff\n```diff\n" + $diff + "\n```") }
109133
]

0 commit comments

Comments
 (0)