@papi-ai/skills 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,443 @@
1
+ ---
2
+ name: pr-reviewer
3
+ description: >
4
+ Use when the user says "review this PR", "code review", "review pull request",
5
+ "check this PR", or when a GitHub PR URL (github.com/*/pull/*) is provided.
6
+ Fetches PR data via gh CLI, creates review workspace, analyzes against quality criteria,
7
+ and optionally posts inline comments.
8
+ version: 1.0.0
9
+ category: code-review
10
+ triggers:
11
+ - review pr
12
+ - code review
13
+ - review pull request
14
+ - check pr
15
+ - pr review
16
+ - github.com/*/pull/*
17
+ - audit
18
+ - review changes
19
+ - check my code
20
+ - check my branch
21
+ author: Claude Code
22
+ license: MIT
23
+ tags:
24
+ - github
25
+ - code-review
26
+ - pull-request
27
+ - quality-assurance
28
+ ---
29
+
30
+ # PR Reviewer Skill
31
+
32
+ Conduct comprehensive, professional code reviews for GitHub Pull Requests using industry-standard criteria and automated tooling.
33
+
34
+ ## Table of Contents
35
+
36
+ - [Purpose](#purpose)
37
+ - [When to Use](#when-to-use)
38
+ - [Review Process Workflow](#review-process-workflow)
39
+ - [Reference Documentation](#reference-documentation)
40
+ - [Scripts Reference](#scripts-reference)
41
+ - [Best Practices](#best-practices)
42
+ - [Quick Reference Commands](#quick-reference-commands)
43
+ - [Tips for Effective Reviews](#tips-for-effective-reviews)
44
+ - [Resources](#resources)
45
+
46
+ ## Purpose
47
+
48
+ This skill performs code reviews by:
49
+
50
+ 1. **Automating data collection** - Fetching all PR-related information (metadata, diff, comments, commits, issues)
51
+ 2. **Organizing review workspace** - Creating structured directory with all artifacts
52
+ 3. **Applying systematic criteria** - Reviewing against comprehensive quality checklist
53
+ 4. **Facilitating inline feedback** - Optionally adding comments directly to PR code
54
+ 5. **Ensuring completeness** - Checking functionality, security, testing, maintainability
55
+
56
+ ## When to Use
57
+
58
+ Activate this skill when:
59
+ - A GitHub PR URL is provided with a review request
60
+ - Receiving "review this PR" or "code review" requests
61
+ - Checking PR quality before merging
62
+ - Providing systematic feedback on proposed changes
63
+ - GitHub PR review is mentioned in any context
64
+
65
+ ## Review Process Workflow
66
+
67
+ **IMPORTANT**: This skill uses a **two-stage approval process**. Nothing is posted to GitHub until explicit approval with `/send` or `/send-decline`.
68
+
69
+ ### Overview
70
+
71
+ 1. **Fetch PR data** - Collect all information
72
+ 2. **Generate review files** - Create detailed, human, and inline comment files
73
+ 3. **Review and edit** - Examine files, make changes as needed (use `/show`)
74
+ 4. **Approve and post** - Use `/send` (approve) or `/send-decline` (request changes)
75
+
76
+ ### Step 1: Fetch PR Data
77
+
78
+ Use `fetch_pr_data.py` to automatically collect all PR information:
79
+
80
+ ```bash
81
+ python scripts/fetch_pr_data.py <pr_url> [--output-dir <dir>] [--no-clone]
82
+ ```
83
+
84
+ **Actions performed:**
85
+ - Parse PR URL to extract owner, repo, and PR number
86
+ - Create directory structure: `<output-dir>/PRs/<repo-name>/<PR-NUMBER>/`
87
+ - Fetch PR metadata (title, author, state, branches, labels)
88
+ - Download PR diff and commit history
89
+ - Retrieve all PR comments and reviews
90
+ - Extract ticket references (JIRA, GitHub issues)
91
+ - Optionally clone source branch and generate git diff
92
+
93
+ **Example:**
94
+ ```bash
95
+ python scripts/fetch_pr_data.py https://github.com/facebook/react/pull/28476
96
+
97
+ # Custom output directory
98
+ python scripts/fetch_pr_data.py https://github.com/owner/repo/pull/123 --output-dir /tmp/reviews
99
+
100
+ # Skip cloning (faster, no git diff)
101
+ python scripts/fetch_pr_data.py https://github.com/owner/repo/pull/123 --no-clone
102
+ ```
103
+
104
+ **Output structure:**
105
+ ```
106
+ /tmp/PRs/<repo-name>/<PR-NUMBER>/
107
+ ├── metadata.json # PR metadata (title, author, branches)
108
+ ├── diff.patch # PR diff from gh CLI
109
+ ├── git_diff.patch # Git diff (if cloned)
110
+ ├── comments.json # Review comments on code
111
+ ├── commits.json # Commit history
112
+ ├── related_issues.json # Linked GitHub issues
113
+ ├── ticket_numbers.json # Extracted ticket references
114
+ ├── SUMMARY.txt # Human-readable summary
115
+ └── source/ # Cloned repository (if not --no-clone)
116
+ ```
117
+
118
+ ### Step 2: Analyze PR Data
119
+
120
+ After fetching, analyze collected data against review criteria:
121
+
122
+ 1. Read `SUMMARY.txt` - High-level overview
123
+ 2. Review `metadata.json` - PR context, labels, assignees
124
+ 3. Examine `diff.patch` - Code changes
125
+ 4. Check `comments.json` - Existing feedback
126
+ 5. Review `commits.json` - Commit quality and messages
127
+ 6. Check `related_issues.json` - Linked tickets/issues
128
+ 7. Apply review criteria - Evaluate against comprehensive checklist
129
+
130
+ Use the Read tool to examine files:
131
+ ```
132
+ Read /tmp/PRs/<repo-name>/<PR-NUMBER>/SUMMARY.txt
133
+ Read /tmp/PRs/<repo-name>/<PR-NUMBER>/metadata.json
134
+ Read /tmp/PRs/<repo-name>/<PR-NUMBER>/diff.patch
135
+ ```
136
+
137
+ ### Step 3: Generate Review Files
138
+
139
+ **CRITICAL**: After analysis, use `generate_review_files.py` to create structured review documents:
140
+
141
+ ```bash
142
+ python scripts/generate_review_files.py <pr_review_dir> --findings <findings_json> [--metadata <metadata_json>]
143
+ ```
144
+
145
+ Creates three files in `pr_review_dir/pr/`:
146
+
147
+ 1. **`pr/review.md`** - Detailed internal review with emojis and line numbers
148
+ 2. **`pr/human.md`** - Clean review for posting (no emojis, em-dashes, line numbers)
149
+ 3. **`pr/inline.md`** - Proposed inline comments with code snippets
150
+
151
+ **Also creates slash commands** in `.claude/commands/`:
152
+ - `/send` - Post human.md and approve PR
153
+ - `/send-decline` - Post human.md and request changes
154
+ - `/show` - Open review directory in VS Code
155
+
156
+ **Findings JSON structure**:
157
+ ```json
158
+ {
159
+ "summary": "Overall assessment of the PR...",
160
+ "metadata": {
161
+ "repository": "owner/repo",
162
+ "number": 123,
163
+ "title": "PR title",
164
+ "author": "username",
165
+ "head_branch": "feature",
166
+ "base_branch": "main"
167
+ },
168
+ "blockers": [
169
+ {
170
+ "category": "Security",
171
+ "issue": "SQL injection vulnerability",
172
+ "file": "src/db/queries.py",
173
+ "line": 45,
174
+ "details": "Using string concatenation for SQL query",
175
+ "fix": "Use parameterized queries",
176
+ "code_snippet": "result = db.execute('SELECT * FROM users WHERE id = ' + user_id)"
177
+ }
178
+ ],
179
+ "important": [...],
180
+ "nits": [...],
181
+ "suggestions": ["Consider adding...", "Future enhancement..."],
182
+ "questions": ["Is this intended to...", "Should we..."],
183
+ "praise": ["Excellent test coverage", "Clear documentation"],
184
+ "inline_comments": [
185
+ {
186
+ "file": "src/app.py",
187
+ "line": 42,
188
+ "comment": "Consider edge case handling for empty input",
189
+ "code_snippet": "def process(data):\n return data.strip()",
190
+ "start_line": 41,
191
+ "end_line": 43,
192
+ "owner": "owner",
193
+ "repo": "repo",
194
+ "pr_number": 123
195
+ }
196
+ ]
197
+ }
198
+ ```
199
+
200
+ ### Step 4: Review and Edit Files
201
+
202
+ **Use `/show` to open the review directory in VS Code.**
203
+
204
+ Actions available:
205
+ - Read `pr/review.md` - Detailed analysis
206
+ - Edit `pr/human.md` - Modify before posting
207
+ - Review `pr/inline.md` - Check proposed comments
208
+ - Adjust any content as needed
209
+
210
+ **NOTHING is posted until explicit approval in Step 5.**
211
+
212
+ ### Step 5: Approve and Post
213
+
214
+ Post the review when ready:
215
+
216
+ **Option A: Approve the PR**
217
+ ```
218
+ /send
219
+ ```
220
+ - Posts `pr/human.md` as comment
221
+ - Approves the PR
222
+ - Confirms action
223
+
224
+ **Option B: Request Changes**
225
+ ```
226
+ /send-decline
227
+ ```
228
+ - Posts `pr/human.md` as comment
229
+ - Requests changes on the PR
230
+ - Confirms action
231
+
232
+ **Posting inline comments** (optional, after /send or /send-decline):
233
+ Review `pr/inline.md` and run the provided commands for specific code comments.
234
+
235
+ ### Step 6: Apply Review Criteria
236
+
237
+ Reference `references/review_criteria.md` for comprehensive checklist. Review against these categories:
238
+
239
+ | Category | Key Questions |
240
+ |----------|--------------|
241
+ | Functionality | Does code solve the problem? Bugs? Edge cases? |
242
+ | Readability | Clear code? Meaningful names? DRY? |
243
+ | Style | Follows linter rules? Consistent with codebase? |
244
+ | Performance | Efficient algorithms? Scalable? |
245
+ | Security | Vulnerabilities addressed? Secrets protected? |
246
+ | Testing | Tests exist? Cover happy paths and edge cases? |
247
+ | PR Quality | Focused scope? Clean commits? Clear description? |
248
+
249
+ **Priority markers for findings:**
250
+ - Blocker: Must be fixed before merge
251
+ - Important: Should be addressed
252
+ - Nit: Nice to have, optional
253
+ - Suggestion: Consider for future
254
+ - Question: Clarification needed
255
+ - Praise: Good work
256
+
257
+ **For detailed criteria:** Read `references/review_criteria.md`
258
+
259
+ ## Reference Documentation
260
+
261
+ This skill includes comprehensive reference guides:
262
+
263
+ | Reference | Purpose |
264
+ |-----------|---------|
265
+ | `references/review_criteria.md` | Complete checklist covering functionality, security, testing, and more |
266
+ | `references/gh_cli_guide.md` | Quick reference for GitHub CLI commands |
267
+ | `references/scenarios.md` | Detailed workflows for common review scenarios |
268
+ | `references/troubleshooting.md` | Common issues and solutions |
269
+
270
+ ## Scripts Reference
271
+
272
+ ### `scripts/fetch_pr_data.py`
273
+
274
+ Automated PR data fetching and organization.
275
+
276
+ ```bash
277
+ python scripts/fetch_pr_data.py <pr_url> [options]
278
+
279
+ Options:
280
+ --output-dir DIR Base output directory (default: /tmp)
281
+ --no-clone Skip cloning repository
282
+ ```
283
+
284
+ ### `scripts/generate_review_files.py`
285
+
286
+ Generate structured review files from analysis findings.
287
+
288
+ ```bash
289
+ python scripts/generate_review_files.py <pr_review_dir> --findings <findings_json> [--metadata <metadata_json>]
290
+ ```
291
+
292
+ **Creates:**
293
+ - `pr/review.md` - Detailed internal review
294
+ - `pr/human.md` - Clean review for posting
295
+ - `pr/inline.md` - Proposed inline comments with commands
296
+ - `.claude/commands/send.md` - Slash command to approve and post
297
+ - `.claude/commands/send-decline.md` - Slash command to request changes
298
+ - `.claude/commands/show.md` - Slash command to open in VS Code
299
+ - `REVIEW_READY.txt` - Summary of next steps
300
+
301
+ ### `scripts/add_inline_comment.py`
302
+
303
+ Add inline code review comments to specific lines in PR.
304
+
305
+ ```bash
306
+ python scripts/add_inline_comment.py <owner> <repo> <pr_number> <commit_id> <file_path> <line> "<comment>" [options]
307
+
308
+ Options:
309
+ --side RIGHT|LEFT Side of diff (default: RIGHT)
310
+ --start-line N Starting line for multi-line comment
311
+ --start-side RIGHT|LEFT Starting side for multi-line comment
312
+ ```
313
+
314
+ ## Best Practices
315
+
316
+ ### Communication
317
+ - Frame feedback as suggestions, not criticism
318
+ - Explain why an issue matters, not just what is wrong
319
+ - Acknowledge excellent practices
320
+ - Prioritize blockers first, style issues last
321
+
322
+ ### Review Efficiency
323
+ - Use scripts to automate data fetching and comment posting
324
+ - Reference `review_criteria.md` as checklist
325
+ - Focus: Critical issues > Important > Nice-to-have
326
+ - Review promptly (within 24 hours if possible)
327
+
328
+ ### Inline Comments
329
+ - Reference exact lines and files
330
+ - Provide better alternatives
331
+ - Test inline comments on test PRs first
332
+ - Use sparingly to avoid overwhelming
333
+
334
+ ### PR Size Handling
335
+ - Large PRs (>400 lines): Suggest splitting
336
+ - Review in logical chunks
337
+ - Focus on architecture for large changes
338
+
339
+ **For detailed scenarios:** Read `references/scenarios.md`
340
+
341
+ ## Quick Reference Commands
342
+
343
+ ```bash
344
+ # Fetch PR data
345
+ python scripts/fetch_pr_data.py https://github.com/owner/repo/pull/123
346
+
347
+ # Add inline comment
348
+ python scripts/add_inline_comment.py owner repo 123 latest "src/app.py" 42 "Comment"
349
+
350
+ # View PR in browser
351
+ gh pr view 123 --repo owner/repo --web
352
+
353
+ # Check PR status
354
+ gh pr checks 123 --repo owner/repo
355
+
356
+ # View existing comments
357
+ gh api /repos/owner/repo/pulls/123/comments --jq '.[] | {path, line, body}'
358
+ ```
359
+
360
+ ## Tips for Effective Reviews
361
+
362
+ 1. Start with context: Read PR description, linked issues, commit messages
363
+ 2. Understand intent: Identify the problem being solved
364
+ 3. Check tests first: Verify tests demonstrate the fix/feature
365
+ 4. Look for patterns: Repeated issues suggest architecture problems
366
+ 5. Consider alternatives: Evaluate simpler approaches
367
+ 6. Think about maintenance: Assess future modification ease
368
+ 7. Remember humans: Maintain kindness, respect, and constructive tone
369
+
370
+ **For troubleshooting:** Read `references/troubleshooting.md`
371
+
372
+ ## PAPI Audit Checks
373
+
374
+ When reviewing a PR on a PAPI-managed project (or when invoked via "audit", "check my branch", "review changes"), perform these additional checks on all changed files:
375
+
376
+ ### Documentation Drift
377
+
378
+ For each changed source file, check if any documentation in `docs/` describes behaviour, architecture, or file interactions that the change modified. If a doc needs updating, report it as a finding with severity "Doc drift" and specify which section is stale.
379
+
380
+ ### Convention Check
381
+
382
+ - Logic errors, off-by-one mistakes, incorrect conditions
383
+ - Unhandled edge cases (null, undefined, empty inputs)
384
+ - Race conditions or state management issues
385
+ - Functions that could throw but aren't wrapped in try/catch where needed
386
+ - Incorrect type narrowing or unsafe casts
387
+
388
+ ### Pre-existing Issues
389
+
390
+ Note pre-existing issues separately — flag them but don't fix them unless they interact with the new changes.
391
+
392
+ ### Branch-level Audit (no PR required)
393
+
394
+ When invoked without a PR URL (e.g. "audit", "check my branch"), run `git diff origin/main --name-only` to find changed files, then apply all review checks directly against the branch diff. Skip PR metadata fetching steps.
395
+
396
+ ## PAPI Integration
397
+
398
+ When reviewing a PR for a PAPI-managed task, pass the review findings to `review_submit` as `auto_review` so they persist alongside human reviews.
399
+
400
+ **After completing your analysis**, map your findings to the `auto_review` parameter:
401
+
402
+ ```
403
+ review_submit with:
404
+ task_id: "<task-id from the PR branch name, e.g. feat/task-641 → task-641>"
405
+ stage: "build-acceptance"
406
+ verdict: "accept" or "request-changes"
407
+ comments: "<your human review summary>"
408
+ auto_review:
409
+ verdict: "pass" | "warn" | "fail"
410
+ summary: "<one-line summary of findings>"
411
+ findings:
412
+ - severity: "error" | "warning" | "info"
413
+ file: "<file path>"
414
+ line: <line number>
415
+ message: "<finding description>"
416
+ ```
417
+
418
+ **Mapping from pr-reviewer findings to auto_review:**
419
+
420
+ | pr-reviewer category | auto_review severity | auto_review verdict impact |
421
+ |---------------------|---------------------|---------------------------|
422
+ | `blockers` | `error` | → verdict: `fail` |
423
+ | `important` | `warning` | → verdict: `warn` |
424
+ | `nits` | `info` | → verdict: `pass` |
425
+ | `suggestions` | `info` | → verdict: `pass` |
426
+ | `praise` | (skip) | (no finding needed) |
427
+
428
+ **Verdict logic:**
429
+ - Any `blockers` → `fail`
430
+ - No blockers but `important` findings → `warn`
431
+ - Only nits/suggestions/praise → `pass`
432
+
433
+ This integration is **optional** — the skill works standalone for non-PAPI repos. Only wire to `review_submit` when the PR belongs to a PAPI-managed project with an active task.
434
+
435
+ ## Resources
436
+
437
+ - **Review Criteria**: `references/review_criteria.md`
438
+ - **gh CLI Guide**: `references/gh_cli_guide.md`
439
+ - **Scenarios**: `references/scenarios.md`
440
+ - **Troubleshooting**: `references/troubleshooting.md`
441
+ - **GitHub PR Review Docs**: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests
442
+ - **Google Engineering Practices**: https://google.github.io/eng-practices/review/
443
+ - **OWASP Top 10**: https://owasp.org/www-project-top-ten/