Commit 1db8161
Enhance PR agent: multi-model workflow, blocker handling, shared rules extraction (dotnet#33813)
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
## Summary
This PR significantly enhances the PR agent workflow with improvements
across **two development phases**:
### Phase 1: Original Enhancements (Commits 1-8)
1. **Multi-model try-fix exploration** - Uses 5 different AI models to
explore alternative solutions
2. **Environment blocker handling** - Strict rules to stop and ask user
when environment issues occur
3. **Review automation script** - PowerShell script that invokes Copilot
CLI directly for PR reviews
4. **Branch safety rules** - Prevents agent from switching branches
during reviews
5. **Template formatting rules** - Exact template adherence for
downstream script compatibility
### Phase 2: Consolidation & Simplification (Commit 9)
After multi-model review (5 models: Claude Sonnet 4.5, Claude Opus 4.5,
GPT-5.2, GPT-5.2-Codex, Gemini 3 Pro), the following improvements were
made:
6. **Shared rules extraction** - Created `SHARED-RULES.md` to eliminate
duplication across files
7. **Simplified git policy** - Agent never runs git commands; always
assumes correct branch
8. **State file handling** - Changed "commit" to "save" (state files are
gitignored)
9. **Reduced verbosity** - Compressed cross-pollination section,
converted PLAN-TEMPLATE to checklist
---
## Commits
### 1. `80d7e412c2` - Update pr agent with multi-model try-fix workflow
**Why:** The original PR agent only used a single model for exploring
fixes. Different AI models have different strengths and may find
solutions others miss.
**Changes:**
- Added Phase 4 multi-model workflow using 5 models:
- `claude-sonnet-4.5`, `claude-opus-4.5`, `gpt-5.2`, `gpt-5.2-codex`,
`gemini-3-pro-preview`
- Cross-pollination loop: Share results between models to spark new
ideas
- Continue until all models confirm "no more approaches to explore"
---
### 2. `69cc6af403` - Address Copilot review suggestions
**Why:** Initial PR review feedback suggested improvements.
**Changes:**
- Minor formatting and clarity improvements to pr.md
---
### 3. `fe55c3fd21` - Add rules for template formatting and skill script
usage
**Why:** Downstream scripts depend on exact regex patterns in state
files. Agents were "improving" templates by adding attributes like
`open` which broke parsing.
**Changes:**
- Added "Follow Templates EXACTLY" rule - no adding attributes, no
improving formats
- Added "Use Skills' Scripts" rule - run provided PowerShell scripts,
don't bypass with manual commands
---
### 4. `debbee608e` - Add 'Stop on Environment Blockers' rule to PR
agent
**Why:** Agent was continuing through phases when environment issues
(missing Appium, WinAppDriver errors) prevented completion, leading to
incomplete reviews.
**Changes:**
- Added explicit blocker handling section to pr.md
- Common blockers: Appium drivers, WinAppDriver, Xcode, emulators, port
conflicts
- Must STOP, report the blocker, and ask user how to proceed
- Never mark phase as blocked and continue to next phase
---
### 5. `ad29f6a796` - Add PR review plan template and Review-PR.ps1
script
**Why:** Need a reusable template for consistent PR reviews and a script
to automate invocation.
**Changes:**
- Created `.github/agents/pr/PLAN-TEMPLATE.md` - Reusable 5-phase review
plan
- Created `.github/scripts/Review-PR.ps1` - Script to prepare
environment and invoke Copilot CLI
---
### 6. `886ea2aa8e` - Improve blocker handling and fix Review-PR.ps1 for
Copilot CLI
**Why:** During PR dotnet#27300 review, agent spent 10+ tool calls
troubleshooting WinAppDriver instead of stopping after first failure.
**Changes:**
- Added strict retry limits table:
| Blocker Type | Max Retries | Action |
|--------------|-------------|--------|
| Server errors (500, timeout) | 0 | STOP immediately |
| Missing tools | 1 install | STOP and ask |
| Port conflicts | 1 kill | STOP and ask |
| WinAppDriver errors | 0 | STOP immediately |
- Added "What I tried" section to blocker report template
- New prohibitions: Never spend more than 2-3 tool calls on same blocker
---
### 7. `d67da75e85` - Update Review-PR.ps1 to invoke Copilot CLI
directly
**Why:** Initially thought Copilot CLI was interactive-only. Discovered
it supports `-i <prompt>` and `-p <prompt>` for programmatic invocation.
**Changes:**
- Script now invokes `copilot --agent pr -i "<prompt>"` directly
- Validates both `gh` CLI and `copilot` CLI are installed
- New `-NoInteractive` switch for `-p` mode (exits after completion)
- Dry run mode shows exactly what would be invoked
---
### 8. `ed74c574a5` - Add 'Do NOT Switch Branches' rule to pr agent
**Why:** During PR review testing, the pr agent ran `git checkout`, `git
stash`, and other branch-switching commands, causing loss of local
changes and confusion about which code was being reviewed.
**Changes:**
- Added explicit "Do NOT Switch Branches" rule to both pr.md and
PLAN-TEMPLATE.md
- Forbidden commands: `git checkout`, `git switch`, `gh pr checkout`,
`git stash`
- Agent must work on current branch as-is, using `git diff` or `gh pr
diff` to see PR changes
- Fixed variable expansion in Review-PR.ps1 prompt (double backticks for
here-strings)
---
### 9. `632bfb7155` - Extract shared rules, simplify git policy, reduce
duplication
**Why:** Multi-model review (5 AI models) identified significant
duplication (~200 lines) across files, conflicting "commit" terminology,
and overly verbose sections. The git checkout prohibition also
conflicted with workflow steps that mentioned git checkout.
**Changes:**
- **Created `SHARED-RULES.md`** (167 lines) - Single source of truth
for:
- Phase Completion Protocol
- Follow Templates EXACTLY
- No Direct Git Commands (absolute - agent never runs git)
- Use Skills' Scripts
- Stop on Environment Blockers (with retry limits)
- Multi-Model Configuration (5 models list)
- Platform Selection guidance
- **Simplified git policy** - Agent is ALWAYS on correct branch, never
runs git commands:
- Removed git fetch/checkout from Phase 1 Pre-Flight
- Phase 5: User handles commit/push/PR creation
- Changed all "State file committed" → "State file saved" (gitignored
files)
- **Compressed content**:
- Cross-pollination ASCII box: 51 → 20 lines
- PLAN-TEMPLATE.md: Full docs → Pure checklist (226 → 112 lines)
- pr.md: 662 → 535 lines (-19%)
- post-gate.md: 403 → 302 lines (-25%)
- Total reduction: 1291 → 1116 lines (-14%)
- **Eliminated duplication**:
- Blocker handling was in 3 files → now in SHARED-RULES.md only
- Phase Completion Protocol was in 2 files → now in SHARED-RULES.md only
- Model list was in 3 files → now in SHARED-RULES.md only
---
## Files Changed
| File | Purpose |
|------|---------|
| `.github/agents/pr.md` | Main PR agent instructions (Phases 1-3) |
| `.github/agents/pr/post-gate.md` | Phase 4-5 instructions (multi-model
try-fix) |
| `.github/agents/pr/PLAN-TEMPLATE.md` | **NEW** - Reusable 5-phase
review checklist |
| `.github/agents/pr/SHARED-RULES.md` | **NEW** - Extracted shared rules
(single source of truth) |
| `.github/scripts/Review-PR.ps1` | **NEW** - Script to invoke Copilot
CLI for PR review |
---
## Usage
```powershell
# Interactive mode (default) - stays open for follow-up
pwsh .github/scripts/Review-PR.ps1 -PRNumber 33687
# Non-interactive mode - exits when done
pwsh .github/scripts/Review-PR.ps1 -PRNumber 33687 -NoInteractive
# Specific platform
pwsh .github/scripts/Review-PR.ps1 -PRNumber 33687 -Platform ios
# Skip merge if already on branch
pwsh .github/scripts/Review-PR.ps1 -PRNumber 33687 -SkipMerge
# Dry run to preview
pwsh .github/scripts/Review-PR.ps1 -PRNumber 33687 -DryRun
```
---
## Multi-Model Validation
The final changes (commit 9) were validated by 5 AI models:
| Model | Verdict | Key Feedback |
|-------|---------|--------------|
| Claude Sonnet 4.5 | ✅ READY TO MERGE | "All git command instructions
successfully removed" |
| Claude Opus 4.5 | ✅ READY TO MERGE | "Excellent refactoring, no
conflicting guidance" |
| GPT-5.2 | ✅ READY TO MERGE | "Progressive disclosure maintained" |
| GPT-5.2-Codex | ✅ READY TO MERGE | "No instructions to run git
commands remain" |
| Gemini 3 Pro | ✅ READY TO MERGE | "Agent is instructed to STOP and ask
user for commits" |
---
## Testing
Tested by reviewing PR dotnet#27300 (ScrollView ScrollToAsync fix):
- Pre-Flight phase completed successfully
- Tests phase verified test files exist
- Gate phase encountered WinAppDriver blocker → agent correctly stopped
and asked
- Blocker handling rules validated through real-world usage
- **Branch safety verified**: Agent stayed on branch instead of
switching
---------
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>1 parent 52f9fc2 commit 1db8161
7 files changed
Lines changed: 762 additions & 277 deletions
File tree
- .github
- agents
- pr
- instructions
- scripts
- skills/try-fix
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 60 | + | |
69 | 61 | | |
70 | 62 | | |
71 | 63 | | |
| |||
233 | 225 | | |
234 | 226 | | |
235 | 227 | | |
236 | | - | |
| 228 | + | |
237 | 229 | | |
238 | 230 | | |
239 | 231 | | |
| |||
242 | 234 | | |
243 | 235 | | |
244 | 236 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 237 | + | |
250 | 238 | | |
251 | 239 | | |
252 | 240 | | |
| |||
256 | 244 | | |
257 | 245 | | |
258 | 246 | | |
259 | | - | |
260 | 247 | | |
261 | 248 | | |
262 | 249 | | |
| |||
351 | 338 | | |
352 | 339 | | |
353 | 340 | | |
354 | | - | |
| 341 | + | |
355 | 342 | | |
356 | 343 | | |
357 | 344 | | |
| |||
418 | 405 | | |
419 | 406 | | |
420 | 407 | | |
421 | | - | |
| 408 | + | |
422 | 409 | | |
423 | 410 | | |
424 | 411 | | |
| |||
441 | 428 | | |
442 | 429 | | |
443 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
444 | 460 | | |
445 | 461 | | |
446 | 462 | | |
447 | 463 | | |
448 | 464 | | |
449 | 465 | | |
450 | | - | |
| 466 | + | |
451 | 467 | | |
452 | 468 | | |
453 | 469 | | |
| |||
486 | 502 | | |
487 | 503 | | |
488 | 504 | | |
489 | | - | |
| 505 | + | |
490 | 506 | | |
491 | 507 | | |
492 | 508 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments