src/skills/x-fix-pr/SKILL.md
Reads PR review comments and fixes actionable ones with Conventional Commits.
npx skillsauth add edercnj/claude-environment x-fix-prInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Automates the process of addressing PR review comments for {{PROJECT_NAME}}. Reads all review comments from a pull request, classifies them by type, implements fixes for actionable feedback, and validates CI status before finishing.
/x-fix-pr — fix comments on current branch's PR/x-fix-pr 123 — fix comments on PR #123| Parameter | Required | Description |
|-----------|----------|-------------|
| PR-number | No | PR number to process. If omitted, detect from current branch. |
1. DETECT -> Identify PR (argument or branch)
2. FETCH -> Get all review comments via GitHub CLI
3. CLASSIFY -> Categorize each comment (actionable/suggestion/question/praise/resolved)
4. FIX -> Implement fixes for actionable comments
5. VERIFY -> Compile and test after each fix
6. REPLY -> Reply to each comment thread in PT-BR (fix summary or rejection reason)
7. COMMIT -> Commit with conventional commit message
8. CI_WATCH -> Run x-watch-pr-ci and loop remediation when checks are not green
9. REPORT -> Summarize actions taken
10. REMEDIATION-> Update remediation tracker, specialist reports, and dashboard with Fixed status
Determine which PR to process:
# If argument is a number, use it directly
PR_NUMBER=$1
# If no argument, detect from current branch
if [ -z "$PR_NUMBER" ]; then
gh pr view --json number --jq '.number'
fi
If no PR found, abort: No PR found for current branch. Provide a PR number as argument.
# Get all review comments (not issue comments)
gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/comments \
--jq '.[] | {id: .id, path: .path, line: .line, body: .body, user: .user.login, created_at: .created_at}'
# Also get PR review threads for context
gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/reviews \
--jq '.[] | {id: .id, state: .state, body: .body, user: .user.login}'
For each comment, classify into one of:
| Type | Description | Action | |------|-------------|--------| | Actionable | Clear request to change code (fix bug, rename, refactor) | Implement the fix | | Suggestion | Optional improvement with rationale | Implement if aligns with project standards | | Question | Reviewer asking for clarification | Skip (requires human response) | | Praise | Positive feedback | Skip | | Resolved | Already addressed or outdated | Skip |
Classification rules:
For each actionable/suggestion comment:
Read the file at the specified path and line:
# Comment metadata provides path and line
cat -n {path} | sed -n '{line-5},{line+5}p'
Understand the reviewer's request
Implement the fix using Edit tool
If the fix requires understanding broader context, read surrounding code first
Ordering: Process comments file-by-file to minimize context switching. Within a file, process top-to-bottom to avoid line number shifts.
After each fix (or batch of fixes per file):
{{COMPILE_COMMAND}}
{{TEST_COMMAND}}
If compilation fails, revert the last change and try an alternative approach. If tests fail, analyze the failure and adjust the fix.
After each comment is processed (fixed, skipped, or rejected), reply to the review comment thread in Portuguese (pt-BR) explaining the action taken.
Reply command:
# Reply to an inline review comment thread
gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/comments/{comment_id}/replies \
-f body="{message_in_portuguese}"
Reply templates by classification:
| Classification | Reply Template (PT-BR) |
|---------------|----------------------|
| Actionable (fixed) | Corrigido. {descricao da alteracao feita}. Commit: {short_hash} |
| Suggestion (accepted) | Sugestao aceita. {descricao da alteracao feita}. Commit: {short_hash} |
| Suggestion (rejected) | Sugestao analisada, mas nao aplicada. Motivo: {razao tecnica pela qual nao faz sentido no contexto atual} |
| Actionable (rejected) | Observacao analisada, mas nao faz sentido neste contexto. Motivo: {explicacao tecnica detalhada} |
| Actionable (failed) | Tentei corrigir, mas a alteracao causou falha na compilacao/testes. Necessita intervencao manual. |
| Question | (no reply — requires human response) |
| Praise | (no reply) |
| Resolved | (no reply — already resolved) |
Rules:
Examples:
Fix applied:
Corrigido. Renomeei a variavel `d` para `elapsedTimeInMs` conforme padrao de naming do projeto. Commit: abc1234
Suggestion rejected:
Sugestao analisada, mas nao aplicada. Motivo: o metodo precisa ser publico porque implementa a interface Assembler, que define o contrato do pipeline. Tornar package-private quebraria o polimorfismo.
Comment doesn't make sense:
Observacao analisada, mas nao faz sentido neste contexto. Motivo: o null check sugerido e desnecessario aqui — o parametro vem de um Optional.orElseThrow() na linha 42, garantindo que nunca sera null neste ponto.
After all fixes for a logical group are verified:
git add {modified-files}
git commit -m "fix({scope}): address PR review comments
- {summary of change 1}
- {summary of change 2}
Addresses review comments on PR #{PR_NUMBER}"
Scope should match the module/layer affected (e.g., domain, api, config).
After pushing the fix commit(s), the skill MUST validate the PR pipeline:
Skill(skill: "x-watch-pr-ci", args: "--pr-number {PR_NUMBER}")
Decision policy:
SUCCESS (exit 0) or PR_ALREADY_MERGED (exit 40): proceed.CI_FAILED (20), TIMEOUT (30), or CI_PENDING_PROCEED (10): return to Step 2 (FETCH) and run another fix cycle.Use up to 3 cycles (FETCH -> CLASSIFY -> FIX -> VERIFY -> REPLY -> COMMIT -> CI_WATCH) per invocation.
If the third cycle still does not converge to green CI, stop with explicit failure summary.
When analyzing checks[] from x-watch-pr-ci, prioritize actionable failures from SonarQube and Veracode jobs when present.
Output a summary table:
## PR Review Comments — Fix Report
**PR:** #{PR_NUMBER}
**Total comments:** N
**Processed:** M
| # | File | Line | Type | Action | Status | Reply |
|---|------|------|------|--------|--------|-------|
| 1 | src/main/Foo.java | 42 | Actionable | Renamed variable | Fixed | Replied |
| 2 | src/main/Bar.java | 15 | Suggestion | Added null check | Fixed | Replied |
| 3 | src/main/Baz.java | 20 | Actionable | — | Rejected | Replied |
| 4 | src/main/Baz.java | 88 | Question | — | Skipped | — |
| 5 | src/main/Qux.java | 3 | Praise | — | Skipped | — |
### Questions Requiring Human Response
- **src/main/Baz.java:88** (@reviewer): "Why is this method public?"
After Step 9, propagate fix status back to the review artifacts so all reports stay in sync.
Determine story ID from the PR branch name:
gh pr view {PR_NUMBER} --json headRefName --jq '.headRefName'
# Expected pattern: story-XXXX-YYYY or feature/story-XXXX-YYYY
Extract story ID (pattern story-\d{4}-\d{4}). If no story ID can be extracted, log warning
No story ID found for PR #{PR_NUMBER}. Skipping remediation tracker update. and exit Step 10
gracefully (no abort).
Derive paths:
FEATURE_DIR = .aikittools/features/feature-XXXX/reviews/REMEDIATION_FILE = {FEATURE_DIR}remediation-story-XXXX-YYYY.mdDASHBOARD_FILE = {FEATURE_DIR}dashboard-story-XXXX-YYYY.mdFor each comment marked Fixed in the Step 9 report:
REMEDIATION_FILE. Search the Description column of each finding row:
Description contains ≥ 6 consecutive words from the search phrase (case-insensitive).Description contains the file path from the comment metadata (e.g., path/to/File.java).FIND-001).For each matched finding (only when current status is Open):
Status column: Open → Fixed.Fix Commit SHA column with the short commit hash from Step 7.Write(file_path: "{REMEDIATION_FILE}", content: "{updated_content}")
Idempotency: If Status is already Fixed, Deferred, or Accepted, skip — do NOT overwrite.
For each matched finding, identify which specialist reported it (Engineer column in the
remediation tracker). Open the corresponding report:
Engineer is a specialist name (QA, Security, Performance, etc.): open
.aikittools/features/feature-XXXX/reviews/review-{specialist}-story-XXXX-YYYY.mdEngineer is Tech Lead: open
.aikittools/features/feature-XXXX/reviews/review-tech-lead-story-XXXX-YYYY.mdLocate the finding row in the "Failed Items" table (match by Description ≥ 6 words) and update:
Status column → FixedFix Commit column → short commit hashEdit(file_path: "{specialist_or_tech_lead_report}", ...)
Skip if report does not exist or the "Failed Items" table has no Status column
(report generated before template v1.1 was applied).
If DASHBOARD_FILE exists:
Status column for matched findings:
Open → Fixed.Edit(file_path: "{DASHBOARD_FILE}", ...)
After all review artifact writes/edits (Steps 10.3–10.5), commit the changes so the updated
Fixed statuses persist in the branch:
git add \
".aikittools/features/feature-XXXX/reviews/remediation-story-XXXX-YYYY.md" \
".aikittools/features/feature-XXXX/reviews/dashboard-story-XXXX-YYYY.md" \
".aikittools/features/feature-XXXX/reviews/review-*.md"
git commit -m "chore(review): mark {FIXED_COUNT} finding(s) as Fixed in review artifacts
Addresses remediation tracking for PR #{PR_NUMBER}.
Co-authored-by: Copilot <[email protected]>"
Skip this commit if no review artifact files were actually modified (idempotent guard).
After all updates, output:
Remediation tracker updated: {FIXED_COUNT} finding(s) marked Fixed.
Dashboard updated: {DASHBOARD_FILE}
Specialist reports updated: {UPDATED_SPECIALISTS}
If no remediation file was found: Remediation tracker not found — skipped.
After all fixes are applied and remediation artifacts updated (Steps 10.1–10.7), re-trigger the full review pipeline to validate that all issues are now resolved:
Skill(skill: "x-review-pr", args: "{PR_NUMBER} --no-auto-remediation [--agent {agent_name}]")
Decision policy:
x-review-pr returns GO: x-fix-pr finishes successfully with summary.x-review-pr returns GO-WITH-RESERVATIONS: x-fix-pr finishes with a warning listing the reservations.x-review-pr returns NO-GO: x-fix-pr records the NO-GO verdict and exits with a non-zero status code so the calling orchestrator (e.g., x-review-pr Phase 4 remediation loop) can decide whether to retry.Important: The maximum cycle count is controlled by the calling x-review-pr Phase 4 loop. x-fix-pr itself does NOT loop — it defers to the parent orchestrator for cycle management.
After Step 11, output:
=== Fix PR Summary ===
PR: #{PR_NUMBER}
Comments fixed: {FIXED_COUNT}
Comments skipped/rejected: {SKIPPED_COUNT}
Review pipeline result: {GO | GO-WITH-RESERVATIONS | NO-GO}
─────────────────────────────────────────────────────────────
{if NO-GO}
Remaining issues (see review reports):
- [SPECIALIST/DEVELOPER]: {FAILED_ITEM} [{SEVERITY}]
...
| Scenario | Action |
|----------|--------|
| PR not found | Abort with message |
| No comments on PR | Report "No review comments found" |
| Comment references deleted file | Skip with warning |
| Fix causes compilation failure | Revert and report as "Unable to fix automatically" |
| Fix causes test failure | Revert and report as "Fix caused regression" |
| CI watch fails after 3 cycles | Abort with "CI not green after max remediation cycles" |
| API rate limit | Wait and retry (max 3 attempts) |
| Story ID not extractable from branch name | Log warning; skip Step 10 gracefully (no abort) |
| Remediation tracker not found | Log warning; skip Steps 10.2–10.5 gracefully (no abort) |
| Finding match not found in tracker | Log WARNING: no matching finding for comment #{comment_id} and continue |
| x-review-pr returns NO-GO after fixes | Exit non-zero; surface NO-GO verdict to calling orchestrator |
| Skill | Relationship | Context |
|-------|-------------|---------|
| x-implement-story | called-by | Invoked during Phase 4 (fix review comments) |
| x-watch-pr-ci | calls | Polls CI checks and Copilot review before finishing each remediation cycle |
| x-push-branch | calls | Uses Conventional Commits format for fix commits |
| x-review-pr | calls (Step 11) | Re-triggers full review pipeline after fixes to validate resolution |
| x-review-specialist | reads | Processes comments produced by specialist reviews |
| _TEMPLATE-REVIEW-REMEDIATION.md | updates (Step 10.3) | Marks findings Fixed with commit SHA |
| _TEMPLATE-CONSOLIDATED-REVIEW-DASHBOARD.md | updates (Step 10.5) | Keeps Remediation Status in sync |
development
Documentation freshness gate: validates 6 dimensions (readme, api, adr, etc.) per PR.
testing
Conditional dep-policy gate: CVEs, licenses, versions, freshness; SARIF + report.
documentation
Incrementally updates the service or system architecture document; never regenerative.
development
Scans code and git history for leaked credentials, API keys, and tokens; SARIF output.