Review timing
Review before opening a pull request and before merging. Reuse the previous result if the relevant diff has not changed; otherwise review again.
Establish review scope
Identify the relevant code diff from the user's input, current worktree, pull request, or merge target. Inspect the repository's existing Git state, conventions, and task context as needed. If the review scope or base remains unclear after inspection, ask the user.
Review sequence
- Check scope: Compare the diff with the stated request and report meaningful scope drift or missing requirements.
- Review code: Review the full diff using the technical checks below.
Technical review
Review the full diff. For each applicable area, verify:
- SQL and data safety: Queries handle untrusted values safely, remain bounded, and preserve data integrity.
- Race conditions and state: Concurrent operations, check-then-act flows, shared state, and asynchronous work remain atomic and consistent.
- Authentication and trust boundaries: Changed entry points enforce authentication, authorization, ownership, token validity, and input validation.
- Error handling: Failures are surfaced and handled, including partial failures, timeouts, cleanup, and recovery.
- Performance and resources: The change does not introduce unbounded work, resource leaks, unnecessary repeated work, or avoidable bottlenecks.
- Completeness and compatibility: For each changed shared contract, such as a state, field, path, identifier, schema, or configuration:
- Inventory relevant occurrences first: search the entire target tree using stable contract fragments such as path prefixes, filename patterns, field names, command names, or resolver functions.
- Trace each producer to all consumers and each consumer back to a concrete producer, including unchanged files outside the diff. A consumer has a concrete producer only when it computes the value or calls a named shared resolver. Prose placeholders, examples, and state expected from an earlier tool do not count.
- Compare the exact values or derivation logic used on both sides. Report unaccounted occurrences, missing implementations, and duplicated or divergent derivations.
- Tests: Tests demonstrate changed behavior, important edge and failure paths, and regression protection.
Evidence and severity
Report a finding only when it is supported by relevant code and a concrete failure scenario.
- P0: Critical or blocking. Can cause a security breach, data loss, service outage, or another failure that must be fixed before merging.
- P1: Serious. Likely to cause incorrect behavior or a major regression and should normally be fixed before merging.
- P2: Moderate and localized. Actionable, but may be scheduled after merging when the risk is acceptable.
For each finding:
- cite the relevant file and line
- describe the trigger and impact
- assign P0, P1, or P2 based on impact
- label it
CONFIRMED when the code proves the issue, or NEEDS INVESTIGATION when required facts are unavailable
- recommend a proportionate action
Do not report speculation or style preferences as defects.
Format: [P0/P1/P2] [CONFIRMED/NEEDS INVESTIGATION] file:line - trigger, impact, description, and recommended action
Review perspectives
Select the perspectives relevant to the changed code and apply their checks:
- Testing: Missing negative and edge-case tests, weak regression coverage, isolation violations, flaky patterns, and changed public behavior without tests
- Maintainability: Unnecessary complexity, duplicated logic, unclear responsibilities, leaky abstractions, and changes that are difficult to understand, test, or extend
- Security: Missing validation at trust boundaries, authentication or authorization failures, insecure direct object references, privilege escalation, weak secret handling, XSS, command injection, SSRF, and path traversal
- Performance: N+1 queries, missing indexes, avoidable quadratic work, expensive loops, heavy dependencies, fetch waterfalls, and unbounded operations
- Data migration: Irreversible migrations, locking schema changes, missing foreign-key indexes, unsafe backfills, and removing old schemas before dependent code
- API contract: Incompatible response changes, new required inputs without defaults, changed error formats, and changed pagination behavior
Skip perspectives that are clearly unrelated to the diff. Deduplicate findings by path, line, and category; keep the highest-impact finding with the strongest evidence.
Adversarial subagent
Run an adversarial subagent when the diff is large, spans multiple components, or affects high-impact behavior such as authentication, authorization, payments, sensitive data, migrations, concurrency, or critical user workflows.
You are an adversarial reviewer. Review the established diff.
Think like an attacker and a chaos engineer. Find ways this code will fail in
production — not style issues, not missing tests, actual breakage or security holes.
Look specifically for:
- race conditions
- auth bypasses
- silent data corruption
- resource leaks
- swallowed failures
- trust boundary violations
For each finding: describe the exact failure scenario and classify as
FIXABLE or INVESTIGATE.
Documentation and guidance consistency
Review documentation and distributable guidance affected by the diff, both at the repository root and within affected packages, modules, or subtrees. Include, where applicable:
- README files, architecture guides, contributing guides, API references, and other explanatory documentation
- Package- or module-specific documentation
- Changelogs and release notes when required by project convention or when the change affects users
- Repository operating contracts for agents working in the repository, such as
AGENTS.md or CLAUDE.md
- Installable agent skills, prompts, templates, examples, plugin metadata, and other agent-facing artifacts distributed by the repository
Check whether changes to behavior, interfaces, setup, configuration, installation, migrations, required artifacts, workflows, handoff rules, tool usage, or deployment constraints are reflected in every affected document or artifact.
When the repository distributes installable skills or other agent-facing artifacts, treat them as product outputs. Verify that their instructions, examples, references, metadata, and packaging remain aligned with the changed behavior.
Report each mismatch with references to both the changed code and the affected document or artifact.
Final output
Lead with actionable findings ordered from P0 to P2. Merge and deduplicate findings from the main review, review perspectives, documentation and guidance checks, and any adversarial review.
Use this structure:
## Diff Inspector
Scope: [CLEAN / DRIFT / MISSING]
Reviewed: [diff source and scope]
Adversarial review: [RUN — Trigger: reason]
### Findings
- [P0/P1/P2] [CONFIRMED/NEEDS INVESTIGATION] file:line - trigger, impact, description, and recommended action
### Scope differences
- [include only when scope drift or missing requirements exist]
Include the Adversarial review line only when that review ran. If there are no findings, state No findings. Do not include empty sections.
1---2name: diff-inspector3description: Inspect code diffs before opening a pull request or merging. This skill MUST be used when the user provides a code diff, pastes code changes, asks for a code or PR review, or when code is about to be submitted as a PR or merged. It MUST NOT be skipped solely because the diff is small. It SHOULD also be used before committing or handing back substantial or high-risk code changes. It MUST NOT be used when changes are limited to non-code content such as documentation, prose, images, or formatting. For small, low-risk self-changes, perform only a lightweight review without specialist dispatch. Checks requirement scope, correctness, security, compatibility, and test coverage. Triggers on: 幫我看程式 diff, 看一下程式改了什麼, review 程式碼, PR review, diff review, code review, 看看程式有沒有問題4---56## Review timing78Review before opening a pull request and before merging. Reuse the previous result if the relevant diff has not changed; otherwise review again.910---1112## Establish review scope1314Identify the relevant code diff from the user's input, current worktree, pull request, or merge target. Inspect the repository's existing Git state, conventions, and task context as needed. If the review scope or base remains unclear after inspection, ask the user.1516---1718## Review sequence19201. **Check scope:** Compare the diff with the stated request and report meaningful scope drift or missing requirements.212. **Review code:** Review the full diff using the technical checks below.2223---2425## Technical review2627Review the full diff. For each applicable area, verify:2829- **SQL and data safety:** Queries handle untrusted values safely, remain bounded, and preserve data integrity.30- **Race conditions and state:** Concurrent operations, check-then-act flows, shared state, and asynchronous work remain atomic and consistent.31- **Authentication and trust boundaries:** Changed entry points enforce authentication, authorization, ownership, token validity, and input validation.32- **Error handling:** Failures are surfaced and handled, including partial failures, timeouts, cleanup, and recovery.33- **Performance and resources:** The change does not introduce unbounded work, resource leaks, unnecessary repeated work, or avoidable bottlenecks.34- **Completeness and compatibility:** For each changed shared contract, such as a state, field, path, identifier, schema, or configuration:35 1. Inventory relevant occurrences first: search the entire target tree using stable contract fragments such as path prefixes, filename patterns, field names, command names, or resolver functions.36 2. Trace each producer to all consumers and each consumer back to a concrete producer, including unchanged files outside the diff. A consumer has a concrete producer only when it computes the value or calls a named shared resolver. Prose placeholders, examples, and state expected from an earlier tool do not count.37 3. Compare the exact values or derivation logic used on both sides. Report unaccounted occurrences, missing implementations, and duplicated or divergent derivations.38- **Tests:** Tests demonstrate changed behavior, important edge and failure paths, and regression protection.3940### Evidence and severity4142Report a finding only when it is supported by relevant code and a concrete failure scenario.4344- **P0:** Critical or blocking. Can cause a security breach, data loss, service outage, or another failure that must be fixed before merging.45- **P1:** Serious. Likely to cause incorrect behavior or a major regression and should normally be fixed before merging.46- **P2:** Moderate and localized. Actionable, but may be scheduled after merging when the risk is acceptable.4748For each finding:4950- cite the relevant file and line51- describe the trigger and impact52- assign P0, P1, or P2 based on impact53- label it `CONFIRMED` when the code proves the issue, or `NEEDS INVESTIGATION` when required facts are unavailable54- recommend a proportionate action5556Do not report speculation or style preferences as defects.5758Format: `[P0/P1/P2] [CONFIRMED/NEEDS INVESTIGATION] file:line - trigger, impact, description, and recommended action`5960---6162## Review perspectives6364Select the perspectives relevant to the changed code and apply their checks:6566- **Testing:** Missing negative and edge-case tests, weak regression coverage, isolation violations, flaky patterns, and changed public behavior without tests67- **Maintainability:** Unnecessary complexity, duplicated logic, unclear responsibilities, leaky abstractions, and changes that are difficult to understand, test, or extend68- **Security:** Missing validation at trust boundaries, authentication or authorization failures, insecure direct object references, privilege escalation, weak secret handling, XSS, command injection, SSRF, and path traversal69- **Performance:** N+1 queries, missing indexes, avoidable quadratic work, expensive loops, heavy dependencies, fetch waterfalls, and unbounded operations70- **Data migration:** Irreversible migrations, locking schema changes, missing foreign-key indexes, unsafe backfills, and removing old schemas before dependent code71- **API contract:** Incompatible response changes, new required inputs without defaults, changed error formats, and changed pagination behavior7273Skip perspectives that are clearly unrelated to the diff. Deduplicate findings by path, line, and category; keep the highest-impact finding with the strongest evidence.7475### Adversarial subagent7677Run an adversarial subagent when the diff is large, spans multiple components, or affects high-impact behavior such as authentication, authorization, payments, sensitive data, migrations, concurrency, or critical user workflows.7879```text80You are an adversarial reviewer. Review the established diff.8182Think like an attacker and a chaos engineer. Find ways this code will fail in83production — not style issues, not missing tests, actual breakage or security holes.8485Look specifically for:86- race conditions87- auth bypasses88- silent data corruption89- resource leaks90- swallowed failures91- trust boundary violations9293For each finding: describe the exact failure scenario and classify as94FIXABLE or INVESTIGATE.95```9697---9899## Documentation and guidance consistency100101Review documentation and distributable guidance affected by the diff, both at the repository root and within affected packages, modules, or subtrees. Include, where applicable:102103- README files, architecture guides, contributing guides, API references, and other explanatory documentation104- Package- or module-specific documentation105- Changelogs and release notes when required by project convention or when the change affects users106- Repository operating contracts for agents working in the repository, such as `AGENTS.md` or `CLAUDE.md`107- Installable agent skills, prompts, templates, examples, plugin metadata, and other agent-facing artifacts distributed by the repository108109Check whether changes to behavior, interfaces, setup, configuration, installation, migrations, required artifacts, workflows, handoff rules, tool usage, or deployment constraints are reflected in every affected document or artifact.110111When the repository distributes installable skills or other agent-facing artifacts, treat them as product outputs. Verify that their instructions, examples, references, metadata, and packaging remain aligned with the changed behavior.112113Report each mismatch with references to both the changed code and the affected document or artifact.114115---116117## Final output118119Lead with actionable findings ordered from P0 to P2. Merge and deduplicate findings from the main review, review perspectives, documentation and guidance checks, and any adversarial review.120121Use this structure:122123```text124## Diff Inspector125Scope: [CLEAN / DRIFT / MISSING]126Reviewed: [diff source and scope]127Adversarial review: [RUN — Trigger: reason]128129### Findings130- [P0/P1/P2] [CONFIRMED/NEEDS INVESTIGATION] file:line - trigger, impact, description, and recommended action131132### Scope differences133- [include only when scope drift or missing requirements exist]134```135136Include the `Adversarial review` line only when that review ran. If there are no findings, state `No findings.` Do not include empty sections.