Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/actions/scrape-and-improve/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: 'Scrape and Improve'
description: 'Collects agent interaction data and generates instruction improvement recommendations.'

inputs:
token:
description: 'GitHub token for API access'
required: false
default: ${{ github.token }}
pr-numbers:
description: 'Comma-separated list of PR numbers to analyze (optional)'
required: false
default: ''
label:
description: 'GitHub label to filter PRs by'
required: false
default: 'copilot'
since:
description: 'ISO 8601 date to filter PRs from (e.g., 2026-01-01)'
required: false
default: ''
recent-pr-count:
description: 'Number of most recent PRs to scrape for suggestion analysis'
required: false
default: '20'
memory-context:
description: 'Raw memory context text from agent interactions to analyze'
required: false
default: ''

outputs:
report-file:
description: 'Path to the analysis report'
value: ${{ steps.analyze.outputs.report-file }}
recommendations-file:
description: 'Path to the recommendations JSON'
value: ${{ steps.analyze.outputs.recommendations-file }}
recommendations-count:
description: 'Number of recommendations generated'
value: ${{ steps.analyze.outputs.recommendations-count }}

runs:
using: 'composite'
steps:

- name: Collect agent data
id: collect
shell: pwsh
env:
GH_TOKEN: ${{ inputs.token }}
run: |
Write-Host "Collecting agent interaction data..."
$params = @{
RepoRoot = "${{ github.workspace }}"
OutputDir = "${{ runner.temp }}/scrape-and-improve"
Repository = "${{ github.repository }}"
RecentPRCount = ${{ inputs.recent-pr-count }}
}
if ("${{ inputs.pr-numbers }}") {
$params["PRNumbers"] = "${{ inputs.pr-numbers }}"
}
if ("${{ inputs.label }}") {
$params["Label"] = "${{ inputs.label }}"
}
if ("${{ inputs.since }}") {
$params["Since"] = "${{ inputs.since }}"
}
if ("${{ inputs.memory-context }}") {
$params["MemoryContext"] = "${{ inputs.memory-context }}"
}
& "${{ github.workspace }}/.github/skills/scrape-and-improve/scripts/Collect-AgentData.ps1" @params

- name: Analyze and generate recommendations
id: analyze
shell: pwsh
run: |
Write-Host "Analyzing collected data..."
$outputDir = "${{ runner.temp }}/scrape-and-improve"
& "${{ github.workspace }}/.github/skills/scrape-and-improve/scripts/Analyze-And-Recommend.ps1" `
-InputFile "$outputDir/collected-data.json" `
-OutputDir $outputDir `
-RepoRoot "${{ github.workspace }}"

"report-file=$outputDir/analysis-report.md" >> $env:GITHUB_OUTPUT
"recommendations-file=$outputDir/recommendations.json" >> $env:GITHUB_OUTPUT

$recommendations = Get-Content -Path "$outputDir/recommendations.json" -Raw | ConvertFrom-Json
$count = if ($recommendations -is [System.Array]) { $recommendations.Count } else { if ($recommendations) { 1 } else { 0 } }
"recommendations-count=$count" >> $env:GITHUB_OUTPUT

- name: Upload analysis artifacts
uses: actions/upload-artifact@v4
with:
name: scrape-and-improve-results
path: |
${{ runner.temp }}/scrape-and-improve/analysis-report.md
${{ runner.temp }}/scrape-and-improve/recommendations.json
${{ runner.temp }}/scrape-and-improve/collected-data.json
retention-days: 30

- name: Print summary
shell: pwsh
run: |
$reportFile = "${{ steps.analyze.outputs.report-file }}"
if (Test-Path $reportFile) {
Write-Host "::group::Analysis Report"
Get-Content -Path $reportFile
Write-Host "::endgroup::"
}
Write-Host ""
Write-Host "Recommendations: ${{ steps.analyze.outputs.recommendations-count }}"
167 changes: 167 additions & 0 deletions .github/agents/scrape-and-improve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
name: scrape-and-improve
description: Scrapes agent PR sessions, Copilot comments, CCA session data, and repository memories to identify patterns and generate instruction file updates for improved agent success rates.
---

# Scrape and Improve Agent

Autonomously collects data from multiple agent interaction sources, analyzes patterns of success and failure, and **applies** instruction file updates to improve future agent performance.

## When to Invoke

- "Scrape and improve agent instructions"
- "Analyze agent patterns and apply improvements"
- "What patterns are agents struggling with? Fix them."
- "Run scrape-and-improve and check in improvements"
- Periodically (weekly/monthly) to improve agent instructions

## When NOT to Invoke

- For a single PR analysis → Use `learn-from-pr` agent or `/learn-from-pr` skill
- During active PR work → Use `pr` agent
- For analysis only without applying changes → Use `/scrape-and-improve` skill directly

---

## Workflow

### Phase 1: Collect Data

Run the data collection script to gather information from all sources:

```bash
pwsh .github/skills/scrape-and-improve/scripts/Collect-AgentData.ps1 \
-RepoRoot "." \
-RecentPRCount 20
```

**Data sources collected:**

| Source | Location | What It Contains |
|--------|----------|------------------|
| Agent PR Sessions | `.github/agent-pr-session/*.md` | Fix candidates, root causes, phase statuses |
| Copilot Comments | PR comments via `gh` CLI | AI Summary, try-fix attempts, test verification |
| CCA Session Logs | `CustomAgentLogsTmp/PRState/` | Session state, fix attempts, convention patterns |
| Repository Memories | Agent memory context | Stored facts (conventions, build commands, patterns) |
| Recent PR Reviews | Most recent 20 PRs via `gh` API | Review comments, suggestion acceptance/rejection |

If the agent has access to repository memories (provided in the conversation context), pass them via `-MemoryContext`:

```bash
pwsh .github/skills/scrape-and-improve/scripts/Collect-AgentData.ps1 \
-RepoRoot "." \
-RecentPRCount 20 \
-MemoryContext "<paste memory block>"
```

### Phase 2: Analyze Patterns

Run the analysis script to identify patterns across collected data:

```bash
pwsh .github/skills/scrape-and-improve/scripts/Analyze-And-Recommend.ps1 \
-RepoRoot "."
```

This produces:
- `CustomAgentLogsTmp/scrape-and-improve/analysis-report.md` — Full report
- `CustomAgentLogsTmp/scrape-and-improve/recommendations.json` — Structured recommendations

### Phase 3: Present Results

Display the analysis report to the user, including:

1. **Data Summary** — What was collected (session files, comments, memories, PRs)
2. **Pattern Analysis** — Slow discovery PRs, quick successes, root causes
3. **Memory Analysis** — Subject frequency, convention patterns
4. **Recent PR Suggestion Analysis** — Acceptance/rejection rates, hotspot areas
5. **Recommendations** — Prioritized list with evidence and impact

### Phase 4: Apply Improvements

For each **High or Medium priority** recommendation from the analysis (priorities are determined by the `Analyze-And-Recommend.ps1` script based on evidence strength, recurrence across PRs, and expected impact on agent success rates):

| Category | Action |
|----------|--------|
| Instruction file | Edit existing or create new `.github/instructions/*.instructions.md` |
| Skill enhancement | Edit `.github/skills/*/SKILL.md` |
| Architecture doc | Edit `/docs/design/*.md` or create in `.github/architecture/` |
| General AI guidance | Edit `.github/copilot-instructions.md` |

**Before each edit:**
- Read the target file first
- Check for existing similar content (don't duplicate)
- Match the existing style/format
- Find the appropriate section

**Skip applying if:**
- Content already exists
- Recommendation is too vague
- Would require major restructuring

### Phase 5: Verify and Report

After applying changes:

1. Run `git diff` to review all edits
2. Verify no syntax errors in modified files (valid markdown)
3. Confirm style matches existing content

Present a summary:

```markdown
## Scrape and Improve Results

### Data Collected
| Source | Count |
|--------|-------|
| [source] | [count] |

### Recommendations Applied
| File | Change |
|------|--------|
| [path] | [what was added/modified] |

### Recommendations Not Applied
| Recommendation | Reason |
|----------------|--------|
| [rec] | [why skipped] |

### Key Findings
- [finding 1]
- [finding 2]
```

---

## Error Handling

| Situation | Action |
|-----------|--------|
| No agent PR sessions found | Report empty, suggest checking date range |
| `gh` CLI not authenticated | Report error, proceed with local data only |
| No Copilot comments found | Proceed with session files and memories |
| No CCA session data | Proceed with other sources |
| No patterns identified | Report "insufficient data" with data source summary |
| Target file doesn't exist | Create if instruction doc, skip if code |
| Duplicate content exists | Skip, note in report |

## Constraints

- **Evidence-based** — Every recommendation must cite specific PRs or data
- **Don't duplicate** — Check existing instruction files before recommending or applying
- **Match style** — Read file before editing
- **Only apply High/Medium priority** — Report Low priority without applying
- **Focus on actionable** — Skip vague observations
- **Respect existing patterns** — Match style and structure of existing instruction files

---

## Difference from Skill

| Aspect | `/scrape-and-improve` Skill | This Agent |
|--------|----------------------------|------------|
| Output | Analysis report and recommendations | Applied changes to instruction files |
| Mode | Analysis only | Autonomous — collects, analyzes, applies |
| Use when | Want to review without applying | Want full automation |
| Trigger | "analyze agent patterns" | "scrape and improve, check in improvements" |
48 changes: 47 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,39 @@ Platform-specific files use naming conventions to control compilation:
- `src/Essentials/samples/Essentials.Sample` - Essentials API demonstrations (non-UI MAUI APIs)
- `src/BlazorWebView/samples/` - BlazorWebView sample applications

## Common Fix Patterns (From Agent Analysis)

These patterns were identified from scrape-and-improve analysis of past agent PR sessions. They help agents find fixes faster by documenting what worked and what didn't.

### NavigationPage Handler Disconnection

When fixing handler disconnection issues with `NavigationPage.RemovePage()`:
- ❌ **Don't** add `DisconnectHandlers()` inside `SendHandlerUpdateAsync` callback (failed in PR #32289)
- ❌ **Don't** add `DisconnectHandlers()` synchronously after `SendHandlerUpdateAsync` (failed in PR #32289)
- ✅ **Do** add `DisconnectHandlers()` at the end of the Legacy `RemovePage` method path
- **Key insight**: The fix location is in the legacy code path, not the modern handler update path

### CollectionView EmptyView (Android)

When fixing EmptyView display issues inside unconstrained layouts (e.g., `VerticalStackLayout`):
- ❌ **Don't** just check for infinity before casting in `GetHeight()`/`GetWidth()` (failed in PR #33134)
- ✅ **Do** handle `double.PositiveInfinity` → `int.MaxValue` propagation in `EmptyViewAdapter`
- **Key insight**: In C#, `(int)double.PositiveInfinity` produces `int.MaxValue`. The fix must normalize dimensions where they're consumed (e.g., convert `int.MaxValue` back to `double.PositiveInfinity` for layout measurement), not where they're cast
- **Root cause**: When CollectionView is inside VerticalStackLayout, height constraint is `double.PositiveInfinity` which propagates through `EmptyViewAdapter.RecyclerViewHeight`

### Shell Navigation Tests (iOS)

When fixing Shell back button / navigation tests on iOS:
- Check if `OnAppearing` count expectations changed due to lifecycle changes in related PRs
- Shell navigation involves both `DidPopItem` and `SendPop()` — ensure stacks stay in sync
- **Key insight**: Simplify `DidPopItem` to always call `SendPop()` when stacks are out of sync

### Device Test Isolation

When fixing flaky device tests (e.g., Stepper tests):
- Tests that modify control state (like `Minimum`, `Maximum`) can leak state to subsequent tests
- **Key insight**: Check if a previous test in the same class modifies shared state without resetting it

## Development Workflow

### Testing
Expand Down Expand Up @@ -220,6 +253,13 @@ The repository includes specialized custom agents and reusable skills for specif
- **Output**: Applied changes to instruction files, skills, architecture docs, code comments
- **Do NOT use for**: Analysis only without applying changes → Use `/learn-from-pr` skill instead

5. **scrape-and-improve** - Scrapes agent data from multiple sources and applies instruction improvements
- **Use when**: Want to analyze agent patterns across multiple PRs and apply improvements automatically
- **Capabilities**: Collects data from PR sessions, Copilot comments, CCA sessions, memories, and recent PRs; analyzes patterns; applies High/Medium priority instruction updates
- **Trigger phrases**: "scrape and improve agent instructions", "analyze agent patterns and apply improvements", "run scrape-and-improve and check in improvements"
- **Output**: Applied changes to instruction files based on aggregated pattern analysis
- **Do NOT use for**: Analysis only without applying → Use `/scrape-and-improve` skill instead; single PR analysis → Use `learn-from-pr` agent

### Reusable Skills

Skills are modular capabilities that can be invoked directly or used by agents. Located in `.github/skills/`:
Expand Down Expand Up @@ -277,9 +317,15 @@ Skills are modular capabilities that can be invoked directly or used by agents.
- **Categories**: Build, WindowsTemplates, macOSTemplates, Blazor, MultiProject, Samples, AOT, RunOnAndroid, RunOniOS
- **Note**: **ALWAYS use this skill** instead of manual `dotnet test` commands for integration tests

9. **scrape-and-improve** (`.github/skills/scrape-and-improve/SKILL.md`)
- **Purpose**: Scrapes agent PR sessions, Copilot comments, CCA sessions, and memories to generate instruction updates
- **Trigger phrases**: "improve agent instructions", "scrape agent data", "analyze agent patterns", "what patterns are agents struggling with?"
- **Scripts**: `Collect-AgentData.ps1`, `Analyze-And-Recommend.ps1`
- **Note**: Also available as a GitHub Action (`.github/actions/scrape-and-improve/`) and scheduled workflow

#### Internal Skills (Used by Agents)

9. **try-fix** (`.github/skills/try-fix/SKILL.md`)
10. **try-fix** (`.github/skills/try-fix/SKILL.md`)
- **Purpose**: Proposes ONE independent fix approach, applies it, tests, records result with failure analysis, then reverts
- **Used by**: pr agent Phase 3 (Fix phase) - rarely invoked directly by users
- **Behavior**: Reads prior attempts to learn from failures. Max 5 attempts per session.
Expand Down
Loading