Skip to content

refactor(review-pr): delegate diff collection to workflow agents#49

Open
cblecker wants to merge 1 commit into
mainfrom
refactor/review-pr-delegate-diff-collection
Open

refactor(review-pr): delegate diff collection to workflow agents#49
cblecker wants to merge 1 commit into
mainfrom
refactor/review-pr-delegate-diff-collection

Conversation

@cblecker

@cblecker cblecker commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Delegate diff collection to agents: Each workflow agent now collects its own patches via diffPreamble() — local agents use git diff, remote agents use GitHub MCP get_files/get_file_contents. Eliminates shuttling large diffs through the orchestration layer.
  • Move agent selection to orchestrator: Replace regex-based selectAgents() in the workflow with intelligent selection by the orchestrator using git diff --name-status and judgment about which specialist agents are warranted.
  • Simplify workflow args: Pass baseRef and agents instead of changedFiles/excludedFileSummary — agents handle file filtering (vendor, generated) themselves.

Test plan

  • Run /review-pr on a local PR (where isLocal is true) and verify agents collect diffs via git
  • Run /review-pr on a remote PR (where isLocal is false) and verify agents collect diffs via GitHub MCP
  • Verify agent selection works correctly — code-reviewer always runs, optional agents selected based on file changes
  • Confirm vendor and generated files are filtered by agents, not the orchestrator
  • Run claude plugin validate ./pr-review-toolkit — passes
  • Run node -c pr-review-toolkit/skills/review-pr/review-pr.js — no syntax errors
  • Run markdownlint on SKILL.md — no errors

Summary by CodeRabbit

  • Refactor
    • Streamlined the PR review workflow, including tighter and more reliable agent selection.
    • Improved handling of local vs. remote review context using git-based checks.
    • Refined how diff information is collected and included in review prompts, with stronger file filtering.
  • Documentation
    • Updated PR review skill instructions and operational constraints for allowed tooling.
  • Updates
    • Bumped plugin version to 1.2.0.

Copilot AI review requested due to automatic review settings June 17, 2026 23:31
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The review-pr skill is refactored to remove in-skill file categorization and diff fetching. SKILL.md tightens tool permissions, rewrites PR metadata and locality detection, and streamlines Phase 1 to pass only headSha, baseRef, isLocal, and agents to the workflow. review-pr.js introduces diffPreamble() to embed diff collection instructions per agent, and agent selection shifts from changedFiles-derived logic to config.agents directly. plugin.json is bumped to 1.2.0.

Changes

review-pr diff collection and agent orchestration refactor

Layer / File(s) Summary
SKILL.md: constraints, metadata, agent selection, and workflow invocation
pr-review-toolkit/skills/review-pr/SKILL.md
Restricts allowed-tools to git diff --name-status *, adds a Constraints section enforcing git/jq/MCP-only data processing, rewrites PR metadata collection to compute isLocal via git rev-parse HEAD vs headSha, adds git fetch origin <baseRef> for merge-base readiness, selects optional agents from git diff --name-status origin/<baseRef>...HEAD, and removes the earlier in-skill steps for file categorization and changedFiles/excludedFileSummary construction.
diffPreamble() implementation and agent prompt assembly
pr-review-toolkit/skills/review-pr/review-pr.js, pr-review-toolkit/.claude-plugin/plugin.json
Introduces diffPreamble() which generates local-vs-remote-aware diff collection instructions with shared filename filter rules. Updates main execution to read agents from config.agents instead of deriving them via selectAgents()/changedFiles. Each parallel agent prompt is now composed as diffPreamble() + PROMPTS[name]. Updates code-reviewer agent text to reference diff collected in setup section. Plugin version bumped to 1.2.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • cblecker/claude-plugins#45: Introduced the workflow-based review-pr orchestration in review-pr.js that this PR directly refactors.
  • cblecker/claude-plugins#47: Added excludedFileSummary-driven context and large-PR file filtering in review-pr.js, which this PR's diffPreamble() and simplified agent selection supersedes.

Poem

🐰 With diffPreamble hops, the agents now align,
No file sifting in the skill—just a tidy design!
Each reviewer gets their setup, constraints run tight,
1.2.0 marks the refactor done right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: delegating diff collection responsibilities from the orchestrator to individual workflow agents, which is the central refactoring described across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/review-pr-delegate-diff-collection

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.0)
pr-review-toolkit/skills/review-pr/review-pr.js

File contains syntax errors that prevent linting: Line 562: Illegal return statement outside of a function


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the /review-pr workflow so each review agent collects its own diff context (via diffPreamble()), while the orchestrator selects which agents to run based on git diff --name-status, reducing large diff payloads passed through the workflow layer.

Changes:

  • Moved diff collection responsibilities into workflow agents via a new diffPreamble() prompt block.
  • Replaced in-workflow regex agent selection with orchestrator-provided agents.
  • Updated skill documentation and bumped plugin version to 1.2.0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pr-review-toolkit/skills/review-pr/SKILL.md Updates allowed tools and rewrites Phase 1 to fetch base ref + select agents via git diff --name-status.
pr-review-toolkit/skills/review-pr/review-pr.js Removes centralized diff/context building; adds diffPreamble() and switches to orchestrator-provided agents.
pr-review-toolkit/.claude-plugin/plugin.json Bumps plugin version to 1.2.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 536 to 538
const results = await parallel(selected.map(name => () => {
const prompt = PROMPTS[name] + buildContext()
const prompt = diffPreamble() + PROMPTS[name]
const opts = { label: name, schema: FINDING_SCHEMA, phase: 'Analyze', effort: 'max' }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed — swapped to PROMPTS[name] + '\n\n' + diffPreamble() so role/identity comes first. Also updated the stale code-reviewer reference from "Review the diff provided in the review context below" to "Review the PR diff collected in the setup section above."

Comment on lines 533 to 534
const selected = config.agents
log('Running ' + selected.length + ' review agents: ' + selected.join(', '))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Added validation that falls back to ['code-reviewer'] when config.agents is missing/non-array, and filters for agent names with valid entries in the PROMPTS object.

Comment on lines 9 to +13
allowed-tools:
- Workflow
- Bash(git rev-parse *)
- Bash(git fetch *)
- Bash(git diff *)
- Bash(jq *)
- Bash(git diff --name-status *)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applicable — the allowed-tools in SKILL.md constrain the orchestrator (skill runner), not the workflow subagents. Workflow agents get the default workflow subagent toolset which includes all Bash and MCP tools. The orchestrator only needs git diff --name-status for agent selection; it never runs full diffs or jq itself.

@cblecker

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pr-review-toolkit/skills/review-pr/review-pr.js`:
- Around line 533-537: The code does not validate that config.agents exists
before accessing its .length property, which will crash if config.agents is
undefined, and it does not verify that agent names in config.agents have
corresponding prompts in the PROMPTS object before dispatching them. Add a guard
to ensure config.agents is provided with a fallback to an empty array if
missing, then filter the selected array to only include agent names where
PROMPTS[name] is defined before passing them to the parallel function. This
prevents crashes and ensures only valid agents with defined prompts are
executed.
- Around line 60-63: The remote collection instructions currently use
get_file_contents which loses the actual diff-hunk context and fails on deleted
or renamed files. Replace the instruction that uses get_file_contents with
instructions to retrieve and use patch hunks or diffs from the pull_request_read
method instead. This will preserve the true diff context, properly handle file
changes (including deletions and renames), and ensure line comments map
correctly to the actual PR diff lines.

In `@pr-review-toolkit/skills/review-pr/SKILL.md`:
- Line 13: The Bash skill definition in this file is too restrictive and only
permits `git diff --name-status`, but review-pr.js now requires running full
`git diff` commands with branch references and file filters (e.g., `git diff
origin/<baseRef>...HEAD -- <files>`). Update the Bash skill definition to allow
the complete git diff syntax needed for patch collection by removing the
restrictive `--name-status` flag constraint and permitting the full git diff
command with branch comparisons and file path arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: cblecker/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 80c4c1b0-6e52-450b-9099-f8046db1b351

📥 Commits

Reviewing files that changed from the base of the PR and between baaf598 and ac807bb.

📒 Files selected for processing (3)
  • pr-review-toolkit/.claude-plugin/plugin.json
  • pr-review-toolkit/skills/review-pr/SKILL.md
  • pr-review-toolkit/skills/review-pr/review-pr.js

Comment thread pr-review-toolkit/skills/review-pr/review-pr.js
Comment thread pr-review-toolkit/skills/review-pr/review-pr.js Outdated
Comment thread pr-review-toolkit/skills/review-pr/SKILL.md
@cblecker cblecker force-pushed the refactor/review-pr-delegate-diff-collection branch from ac807bb to aeae0cc Compare June 18, 2026 00:20
@cblecker cblecker requested a review from Copilot June 18, 2026 00:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +534 to +536
const selected = Array.isArray(config.agents)
? config.agents.filter(name => typeof PROMPTS[name] === 'string')
: ['code-reviewer']
Move diff fetching from the orchestrator into each workflow agent via a
diffPreamble() that generates setup instructions. Agents now collect
their own patches using git (local) or GitHub MCP (remote), eliminating
the token cost of shuttling large diffs through the orchestration layer.

Agent selection moves from regex matching in the workflow to the
orchestrator, which can evaluate whether each specialist agent is
warranted based on the nature of the changes.

Assisted-by: Claude:claude-opus-4-6
@cblecker cblecker force-pushed the refactor/review-pr-delegate-diff-collection branch from aeae0cc to e79a9ee Compare June 18, 2026 00:55
@cblecker cblecker requested a review from Copilot June 18, 2026 00:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pr-review-toolkit/skills/review-pr/review-pr.js`:
- Line 542: The prompt assembly is concatenating PROMPTS[name] before
diffPreamble(), but the role prompt expects setup instructions to appear above
it. Reverse the order of concatenation in the prompt assignment so that
diffPreamble() comes first, followed by PROMPTS[name], to match the expectation
referenced in the role prompt definition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9829e394-648b-4792-885f-12f091499876

📥 Commits

Reviewing files that changed from the base of the PR and between ac807bb and e79a9ee.

📒 Files selected for processing (3)
  • pr-review-toolkit/.claude-plugin/plugin.json
  • pr-review-toolkit/skills/review-pr/SKILL.md
  • pr-review-toolkit/skills/review-pr/review-pr.js
✅ Files skipped from review due to trivial changes (1)
  • pr-review-toolkit/.claude-plugin/plugin.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • pr-review-toolkit/skills/review-pr/SKILL.md


const results = await parallel(selected.map(name => () => {
const prompt = PROMPTS[name] + buildContext()
const prompt = PROMPTS[name] + '\n\n' + diffPreamble()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Place diffPreamble() before agent instructions.

At Line 542, prompt assembly appends setup instructions after the role prompt, but the role prompt (Line 88) explicitly references setup “above.” This ordering mismatch can reduce reliability of agent behavior.

Proposed fix
-  const prompt = PROMPTS[name] + '\n\n' + diffPreamble()
+  const prompt = diffPreamble() + '\n\n' + PROMPTS[name]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const prompt = PROMPTS[name] + '\n\n' + diffPreamble()
const prompt = diffPreamble() + '\n\n' + PROMPTS[name]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pr-review-toolkit/skills/review-pr/review-pr.js` at line 542, The prompt
assembly is concatenating PROMPTS[name] before diffPreamble(), but the role
prompt expects setup instructions to appear above it. Reverse the order of
concatenation in the prompt assignment so that diffPreamble() comes first,
followed by PROMPTS[name], to match the expectation referenced in the role
prompt definition.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +49 to +50
1. Run `git diff --name-status origin/<baseRef>...HEAD` to get the list of
changed files with statuses (cheap — filenames only, no patches).
3. Run `git fetch origin <baseRef>` to ensure the merge-base is available
locally for agents.

Note: `base.sha` from the API is the tip of the base branch at PR creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants