AGENT SKILL

pr-review

Fetch open GitHub PR data (diff, files, CI, metadata), perform AI code review using strict KISS/DRY/SOLID rules, save results locally, and present categorized findings. Trigger - any GitHub PR URL or request to "review PR", "check PR", "review open PR".

使用场景代码审查
License 许可
GPL-3.0
所属仓库
Artawower/kaizen
最近更新
2026-11-10
Stars
★ 2
Forks
0

01 前言 Front Matter

name
pr-review
description
Fetch open GitHub PR data (diff, files, CI, metadata), perform AI code review using strict KISS/DRY/SOLID rules, save results locally, and present categorized findings. Trigger - any GitHub PR URL or request to "review PR", "check PR", "review open PR".

02 资源文件 1

03 SKILL.md 正文

What I do

Perform end-to-end AI code review of GitHub Pull Requests:

  1. Fetch PR data (diff, files, metadata, CI status, existing reviews) via a bundled Python script
  2. Analyze each changed file against strict code review rules
  3. Categorize findings by severity
  4. Save results locally (JSON + Markdown) for persistent analysis
  5. Present structured review report
  6. Optionally: post comments to GitHub or apply fixes

When to use me

  • User shares a GitHub PR URL and wants a code review
  • User asks to "review PR", "check PR code", "review open PR"
  • User wants to analyze PR quality before merging
  • User wants to compare reviews across multiple PRs (saved locally)

WORKFLOW

STEP 1: Fetch PR data

Run the bundled script. It handles URL parsing, GraphQL + REST queries, filtering, chunking, and saves data locally:

python3 ~/.agents/skills/pr-review/fetch-pr-data.py <PR_REFERENCE>

Supported input formats:

  • https://github.com/owner/repo/pull/123
  • owner/repo#123
  • owner/repo 123
  • Just 123 (infers owner/repo from current git repo)

The script automatically:

  • Filters out lock files, generated code, vendor dirs, minified files, source maps, snapshots
  • Prioritizes source code (.ts/.py/.go/etc) over config over docs/assets
  • Truncates PR body to 500 chars (configurable via --max-body)
  • Removes diff duplication (only file_patches with per-file patches, no full unified diff)
  • Chunks large PRs into groups of 20 files (configurable via --chunk-size)

Output JSON saved to ~/.local/share/ai/pr-reviews/:

{
  "repo": "owner/repo",
  "pr_number": 123,
  "title": "Add auth middleware",
  "body": "PR description (truncated)...",
  "stats": {
    "additions": 150, "deletions": 30, "changed_files": 25,
    "reviewable_files": 20, "skipped_files": 5,
    "total_review_tokens_est": 35000
  },
  "ci": { "state": "SUCCESS", "checks": [...] },
  "reviews": [...],
  "skipped_files": ["package-lock.json", "dist/bundle.min.js"],
  "chunking": {
    "total_chunks": 2,
    "chunk_size": 20,
    "chunks": [
      { "chunk": 1, "files": 20, "tokens_est": 25000, "file_paths": [...] },
      { "chunk": 2, "files": 5,  "tokens_est": 10000, "file_paths": [...] }
    ]
  },
  "file_patches": [...]
}

If PR fits in 1 chunk (≤20 files, ~40k tokens): file_patches is included inline — proceed to STEP 2. If PR needs multiple chunks: file_patches is NOT included. Use chunked workflow (see STEP 1b).

If the script fails with auth error, tell user to run gh auth login. If the PR is a draft, warn the user and ask if they still want to review.

STEP 1b: Chunked review (large PRs only)

When chunking.total_chunks > 1, review chunk-by-chunk:

python3 ~/.agents/skills/pr-review/fetch-pr-data.py <PR_REFERENCE> --chunk 1
python3 ~/.agents/skills/pr-review/fetch-pr-data.py <PR_REFERENCE> --chunk 2

Each chunk returns only its file patches:

{
  "chunk": 1,
  "total_chunks": 3,
  "files_in_chunk": 20,
  "tokens_est": 25000,
  "file_patches": [...]
}

Chunked workflow:

  1. Run script without --chunk — get metadata + chunking plan
  2. For each chunk N (1 to total_chunks): a. Run script with --chunk N — get file patches for this chunk b. Review this chunk's files (STEP 3) c. Collect findings
  3. After all chunks: merge findings, deduplicate cross-file issues, proceed to STEP 4

Important: When reviewing chunks, keep the metadata from step 1 in context (CI status, PR description, existing reviews). Only the file_patches change per chunk.

STEP 2: Pre-review context

Before reviewing, gather context:

  1. Read PR description (body) — understand the intent and scope
  2. Check CI status — note failures, they may indicate broken code
  3. Check existing reviews — note previous reviewer feedback
  4. Check unresolved threads — avoid duplicating existing feedback
  5. Scan file list — identify the scope (frontend, backend, infra, tests)
  6. If the project has AGENTS.md — read it to understand project-specific rules and conventions

STEP 3: Review each changed file

For each file in file_patches, analyze the patch (diff) against the review rules.

Load ../../references/code-reviewer.md and apply its shared review policy to the requested PR diff. Prioritize verified defects and regressions, respect project conventions and keep optional suggestions separate from blockers.

STEP 4: Categorize findings

Group all findings into severity categories:

  • CRITICAL — Blocking: bugs, security vulns, data loss risks, broken functionality
  • MAJOR — Should fix: architecture violations, missing error handling, performance issues, missing tests
  • MINOR — Nice to fix: style, naming, code quality improvements, minor DRY violations
  • INFO — Observations: positive patterns noticed, architectural notes, suggestions for future

STEP 5: Save results locally

Save the review in two formats:

JSON (for programmatic analysis):

Save to ~/.local/share/ai/pr-reviews/{owner}_{repo}_{pr_number}_review.json:

{
  "reviewed_at": "2026-02-16T17:33:04Z",
  "repo": "owner/repo",
  "pr_number": 123,
  "pr_url": "https://github.com/owner/repo/pull/123",
  "title": "PR title",
  "author": "developer",
  "stats": { "additions": 150, "deletions": 30, "changed_files": 5 },
  "ci_state": "SUCCESS",
  "verdict": "CHANGES_REQUESTED",
  "summary": "One paragraph summary...",
  "findings": [
    {
      "severity": "critical",
      "category": "security",
      "file": "src/auth.ts",
      "line": 42,
      "title": "SQL injection via unsanitized input",
      "description": "User input passed directly to query without parameterization",
      "suggestion": "Use parameterized query: db.query('SELECT * FROM users WHERE id = $1', [userId])"
    }
  ],
  "finding_counts": {
    "critical": 1,
    "major": 3,
    "minor": 5,
    "info": 2
  },
  "files_reviewed": 5
}

Markdown (for human reading):

Save to ~/.local/share/ai/pr-reviews/{owner}_{repo}_{pr_number}_review.md.

Use the OUTPUT FORMAT from Step 6.

STEP 6: Present review to user

Use this STRICT output format:

## PR Review: {TITLE}
**URL**: {PR_URL}
**Author**: @{AUTHOR} | **Branch**: {HEAD} → {BASE}
**Stats**: +{ADDITIONS} -{DELETIONS} across {CHANGED_FILES} files
**CI**: {CI_STATE} | **Existing reviews**: {REVIEW_COUNT}
**Verdict**: {APPROVE | CHANGES_REQUESTED | COMMENT}

---

### 1) Summary
One concise paragraph of the biggest issues and the overall direction.

### 2) Critical Issues ({COUNT})

#### [{N}] {FILE}:{LINE} — {TITLE}
**Category**: {security|bug|data-loss}
> {description of the issue}
**Fix**: {specific fix with code if needed}

### 3) Major Issues ({COUNT})

#### [{N}] {FILE}:{LINE} — {TITLE}
**Category**: {architecture|error-handling|performance|testing}
> {description}
**Fix**: {specific fix}

### 4) Minor / Style ({COUNT})
- [{N}] {FILE}:{LINE} — {short description} → {fix}

### 5) Security & Robustness
- Input validation: {assessment}
- Error handling: {assessment}
- Resource cleanup: {assessment}
- Race conditions: {assessment}

### 6) Proposed Refactor (≤5 steps)
1. {step 1}
2. {step 2}
...

### 7) Tests to Add
- `{testName}`: {what it asserts}

### 8) Positive Patterns
- {what's done well — acknowledge good code}

---

**Saved to**: `{path_to_json}` and `{path_to_md}`

STEP 7: Ask for action

What would you like to do?
- "post" — post findings as PR review comments on GitHub
- "fix N,N,N" — apply fixes for specific findings (by number)
- "fix all" — fix all critical + major issues
- "compare" — compare with previous review of this PR
- "done" — review complete, no further action

Wait for user response. Do NOT proceed without explicit instruction.

STEP 8: Execute action (if requested)

If "post":

Post review via gh api as a single review with inline comments:

gh api /repos/{owner}/{repo}/pulls/{pr}/reviews \
  -f commit_id='{head_sha}' \
  -f event='COMMENT' \
  -f body='AI Review Summary...' \
  -f comments[][path]='file.ts' \
  -F comments[][line]=42 \
  -f comments[][body]='Finding description'

If "fix":

  1. Checkout the PR branch: gh pr checkout {pr_number}
  2. For each selected finding, read the file and apply minimal fix
  3. Run lsp_diagnostics on changed files
  4. Report what was fixed

If "compare":

Load previous review from ~/.local/share/ai/pr-reviews/ and diff findings.

Hard rules

  • NEVER push changes without explicit user permission
  • NEVER approve/dismiss reviews on GitHub without explicit user permission
  • NEVER modify files not mentioned in the PR diff
  • NEVER ignore AGENTS.md / project-specific rules if the project has them
  • If gh is not authenticated — tell user to run gh auth login and stop
  • Answer in the same language the user uses
  • Review ONLY the diff — don't critique pre-existing code outside the PR scope
  • Be objective: acknowledge good patterns, don't only criticize
  • Focus on impact: a real bug > 10 style nitpicks

Context budget

The script estimates token usage and reports it in stats.total_review_tokens_est.

PR size Tokens est Strategy
≤20 files, <40k tokens ~5-40k Single pass (default)
20-100 files, 40-200k tokens ~40-200k Chunked (auto)
>100 files >200k Chunked + consider --chunk-size 15 for tighter chunks

Adjust chunk size if needed: --chunk-size 15 for large patches, --chunk-size 30 for small ones.

Viewing saved reviews

All reviews are saved persistently in ~/.local/share/ai/pr-reviews/:

  • {owner}_{repo}_{pr}_review.json — structured data
  • {owner}_{repo}_{pr}_review.md — human-readable report
  • {owner}_{repo}_{pr}.json — raw PR data from fetch
  • {owner}_{repo}_{pr}_chunkN.json — chunk data (large PRs)

To list saved reviews:

ls -la ~/.local/share/ai/pr-reviews/

To re-analyze a previously fetched PR without re-fetching:

cat ~/.local/share/ai/pr-reviews/{owner}_{repo}_{pr}.json

04 同仓库更多 Skills

Artawower
Artawower/kaizen

yt-analyze

Fetch YouTrack task + comments via MCP, critically analyze relevance and requirements, produce concise summary of what to implement, and build an implementation plan mapped to codebase. Trigger - YouTrack issue ID or request to "analyze task", "plan task", "break down YT issue".

Skill与智能体开发
★ 2
Artawower
Artawower/kaizen

youtrack-task

Analyzes a YouTrack issue, reviews comments and attachments, and proposes or creates actionable subtasks. Use when the user gives a YouTrack issue ID and wants synthesis, decomposition, or follow-up tasks.

★ 2
Artawower
Artawower/kaizen

youtrack-search

Searches YouTrack from natural language or native query syntax and returns a concise report with the most relevant issues. Use when the user wants to find issues, triage work, or translate a plain-language query into YouTrack search.

★ 2
Artawower
Artawower/kaizen

writing-for-agents

Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.

内容创作者写作与文案
★ 2
Artawower
Artawower/kaizen

write-a-prd

Create a PRD through user interview, codebase exploration, and module design, then submit as a GitHub issue. Use when user wants to write a PRD, create a product requirements document, or plan a new feature.

产品经理
★ 2
Artawower
Artawower/kaizen

vitest

Plan and write Vitest tests for changed code. Analyses git diff, checks existing tests, produces a concrete test plan using flat test structure (no describe/it blocks). Use when adding tests for new/changed code, improving Vitest coverage, or asking what to test after a change.

★ 2