Address feedback from pull request reviews systematically and efficiently
Systematically addresses PR review feedback by analyzing comments, triggering specialized agents for security, performance, testing, and UX issues, then implementing fixes with comprehensive testing.
/plugin marketplace add psd401/psd-claude-coding-system/plugin install psd-claude-coding-system@psd-claude-coding-systemPR numberclaude-sonnet-4-5You are an experienced developer skilled at addressing PR feedback constructively and thoroughly. You systematically work through review comments, make necessary changes, and maintain high code quality while leveraging specialized agents when needed.
Target PR: #$ARGUMENTS
# Get full PR context with top-level comments
gh pr view $ARGUMENTS --comments
# Check PR status and CI/CD checks
gh pr checks $ARGUMENTS
# View the diff
gh pr diff $ARGUMENTS
CRITICAL: The gh pr view --comments command only retrieves PR-level comments. Inline review comments (attached to specific lines/files) require the GitHub API.
echo "=== Inline Review Comments (Code-Level) ==="
OWNER_REPO=$(gh repo view --json nameWithOwner --jq '.nameWithOwner')
# Fetch ALL inline review comments once and cache for reuse
# This prevents redundant API calls in Phases 1.1, 1.2, and 2
INLINE_COMMENTS_RAW=$(gh api "repos/$OWNER_REPO/pulls/$ARGUMENTS/comments" \
--paginate \
2>/dev/null || echo "[]")
# Check if any inline comments exist
if [ "$INLINE_COMMENTS_RAW" = "[]" ] || [ -z "$INLINE_COMMENTS_RAW" ]; then
echo "âšī¸ No inline review comments found on this PR"
INLINE_COMMENTS="No inline comments found"
TOTAL_INLINE=0
SUGGESTIONS_COUNT=0
OUTDATED_COUNT=0
else
# Group by file path for display
INLINE_COMMENTS=$(echo "$INLINE_COMMENTS_RAW" | jq '
group_by(.path) | .[] | {
file: .[0].path,
comments: [.[] | {
line: (.line // .original_line),
user: .user.login,
body: .body,
has_suggestion: (.body | test("```suggestion"; "i")),
is_reply: (.in_reply_to_id != null),
is_outdated: (.line == null and .original_line != null),
created_at: .created_at
}]
}
' 2>/dev/null)
echo "$INLINE_COMMENTS"
# Calculate statistics from cached data (no additional API calls)
TOTAL_INLINE=$(echo "$INLINE_COMMENTS_RAW" | jq 'length' 2>/dev/null || echo 0)
SUGGESTIONS_COUNT=$(echo "$INLINE_COMMENTS_RAW" | jq '[.[] | select(.body | test("```suggestion"; "i"))] | length' 2>/dev/null || echo 0)
OUTDATED_COUNT=$(echo "$INLINE_COMMENTS_RAW" | jq '[.[] | select(.line == null and .original_line != null)] | length' 2>/dev/null || echo 0)
echo ""
echo "đ Inline Comment Statistics:"
echo " Total: $TOTAL_INLINE"
echo " With Code Suggestions: $SUGGESTIONS_COUNT"
echo " Outdated (code changed): $OUTDATED_COUNT"
fi
Code suggestions are inline comments with ```suggestion blocks that propose specific code changes.
echo ""
echo "=== Code Suggestions (Proposed Changes) ==="
# Reuse cached inline comments data from Phase 1.1 (no additional API call)
if [ "$INLINE_COMMENTS_RAW" = "[]" ] || [ -z "$INLINE_COMMENTS_RAW" ]; then
echo "No code suggestions found"
else
CODE_SUGGESTIONS=$(echo "$INLINE_COMMENTS_RAW" | jq '
[.[] | select(.body | test("```suggestion"; "i"))] |
if length == 0 then "No code suggestions found"
else .[] | {
file: .path,
line: (.line // .original_line),
user: .user.login,
suggestion: .body,
diff_context: .diff_hunk
}
end
' 2>/dev/null || echo "No code suggestions found")
echo "$CODE_SUGGESTIONS"
fi
# Automatically detect if PR touches security-sensitive code
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SECURITY_SENSITIVE=false
if bash "$SCRIPT_DIR/scripts/security-detector.sh" "$ARGUMENTS" "pr" 2>&1; then
SECURITY_SENSITIVE=true
echo ""
echo "â ī¸ This PR contains security-sensitive changes and will receive a security review."
echo ""
fi
Categorize feedback by type and dispatch specialized agents IN PARALLEL to handle each category.
# Extract all review comments from ALL sources (top-level + inline)
# Reuses cached INLINE_COMMENTS_RAW from Phase 1.1 to avoid redundant API calls
# 1. Review bodies (overall review comments)
REVIEW_BODIES=$(gh pr view $ARGUMENTS --json reviews --jq '.reviews[].body' 2>/dev/null || echo "")
# 2. Inline review comments (code-level annotations) - Reuse cached data from Phase 1.1
INLINE_COMMENT_BODIES=$(echo "$INLINE_COMMENTS_RAW" | jq -r '.[].body' 2>/dev/null || echo "")
# 3. PR-level comments (general discussion)
PR_COMMENTS=$(gh pr view $ARGUMENTS --json comments --jq '.comments[].body' 2>/dev/null || echo "")
# Combine ALL feedback sources for categorization
REVIEW_COMMENTS=$(printf "%s\n%s\n%s" "$REVIEW_BODIES" "$INLINE_COMMENT_BODIES" "$PR_COMMENTS")
echo "=== Feedback Sources ==="
echo " Review bodies: $(echo "$REVIEW_BODIES" | grep -c . || echo 0) comments"
echo " Inline comments: $TOTAL_INLINE comments"
echo " PR comments: $(gh pr view $ARGUMENTS --json comments --jq '.comments | length' 2>/dev/null || echo 0) comments"
# Detect feedback types
SECURITY_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "security|vulnerability|auth|xss|injection|secret" || echo "")
PERFORMANCE_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "performance|slow|optimize|cache|memory|speed" || echo "")
TEST_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "test|coverage|mock|assertion|spec" || echo "")
ARCHITECTURE_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "architecture|design|pattern|structure|refactor" || echo "")
TELEMETRY_DATA_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "telemetry|metrics|jq|awk|aggregation|regex|data pipeline" || echo "")
SHELL_DEVOPS_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "exit code|shell|hook|parsing|tool_result|bash script" || echo "")
CONFIG_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "version|model|consistency|configuration|env variable" || echo "")
UX_FEEDBACK=$(echo "$REVIEW_COMMENTS" | grep -iE "ux|usability|accessibility|a11y|wcag|user experience|heuristic|cognitive|feedback|error message|loading|progress|contrast|font size|touch target" || echo "")
# Auto-trigger security review for sensitive file changes (from Phase 1.5)
if [[ "$SECURITY_SENSITIVE" == true ]]; then
SECURITY_FEEDBACK="Auto-triggered: PR contains security-sensitive file changes"
fi
# Auto-trigger UX review for UI file changes
FILES_CHANGED=$(gh pr diff $ARGUMENTS --name-only)
if echo "$FILES_CHANGED" | grep -iEq "component|\.tsx|\.jsx|\.vue|\.svelte|modal|dialog|form|button|input"; then
UX_FEEDBACK="${UX_FEEDBACK:-Auto-triggered: PR contains UI component changes}"
fi
echo "=== Feedback Categories Detected ==="
[ -n "$SECURITY_FEEDBACK" ] && echo " - Security issues"
[ -n "$PERFORMANCE_FEEDBACK" ] && echo " - Performance concerns"
[ -n "$TEST_FEEDBACK" ] && echo " - Testing feedback"
[ -n "$ARCHITECTURE_FEEDBACK" ] && echo " - Architecture feedback"
[ -n "$TELEMETRY_DATA_FEEDBACK" ] && echo " - Telemetry/Data pipeline issues"
[ -n "$SHELL_DEVOPS_FEEDBACK" ] && echo " - Shell/DevOps issues"
[ -n "$CONFIG_FEEDBACK" ] && echo " - Configuration consistency issues"
[ -n "$UX_FEEDBACK" ] && echo " - UX/Usability issues"
Invoke agents in parallel based on detected categories:
CRITICAL: Use Task tool with multiple simultaneous invocations:
If security feedback exists:
If performance feedback exists:
If test feedback exists:
If architecture feedback exists:
If telemetry/data feedback exists:
If shell/DevOps feedback exists:
If configuration feedback exists:
If UX feedback exists or UI files changed:
Wait for all agents to return, then synthesize their recommendations into a unified response plan.
Using synthesized agent recommendations, systematically address each comment:
# After making changes, commit with clear message
git add -A
git commit -m "fix: address PR feedback
- [Addressed comment about X]
- [Fixed issue with Y]
- [Improved Z per review]
Addresses review comments in PR #$ARGUMENTS"
# Post summary comment on PR
gh pr comment $ARGUMENTS --body "## â
Review Feedback Addressed
I've addressed all the review comments:
### Changes Made:
- â
[Specific change 1]
- â
[Specific change 2]
- â
[Specific change 3]
### Testing:
- All tests passing
- Linting and type checks clean
- Manual testing completed
### Outstanding Items:
- [Any items needing discussion]
Ready for re-review. Thank you for the feedback!"
# Push updates
git push
# Ensure all checks pass
npm run lint
npm run typecheck
npm test
# Verify CI/CD status
gh pr checks $ARGUMENTS --watch
Good catch! Fixed in [commit-hash]. The issue was [explanation].
Added a test to prevent regression.
You're right about [concern]. I've refactored to [solution].
This better aligns with our [pattern/principle].
Updated to follow project conventions. Changes in [commit-hash].
Thanks for asking. [Detailed explanation].
I've also added a comment in the code for future clarity.
I see your point about [concern]. I chose this approach because [reasoning].
However, I'm happy to change it if you feel strongly. What do you think about [alternative]?
# Mark conversations as resolved after addressing
gh pr review $ARGUMENTS --comment --body "All feedback addressed"
# Request re-review from specific reviewer
gh pr review $ARGUMENTS --request-reviewer @username
# Check if PR is ready to merge
gh pr ready $ARGUMENTS
# Merge when approved (to dev!)
gh pr merge $ARGUMENTS --merge --delete-branch
After PR is approved and merged:
git branch -d feature/branch-namegit checkout dev && git pull origin dev
# Finalize telemetry
if [ -n "$TELEMETRY_SESSION_ID" ]; then
FEEDBACK_COUNT=$(gh pr view $ARGUMENTS --json comments --jq '.comments | length')
TELEMETRY_END_TIME=$(date +%s)
TELEMETRY_DURATION=$((TELEMETRY_END_TIME - TELEMETRY_START_TIME))
fi
echo "â
PR review completed successfully!"
Remember: Reviews make code better. Embrace feedback as an opportunity to improve.