Skip to content

Commit be3fde7

Browse files
anakrishCopilot
andauthored
fix(copilot): robust diff computation for cloud agent environments (#709)
The cloud agent checks out a branch like copilot/review-pr-NNN which may not have upstream/main or origin/main refs available for merge-base. Changes: - Use gh pr diff as primary method (always works in PR context) - Fall back to git merge-base for local non-PR usage - Remove path filters (*.rs *.toml examples/) — review full diff - Remove head -2000 truncation — let agents see everything - Explicitly fetch origin/main in copilot-setup-steps.yml as backup Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d2c483e commit be3fde7

3 files changed

Lines changed: 60 additions & 29 deletions

File tree

.github/copilot-setup-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ steps:
88
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
99
with:
1010
fetch-depth: 0 # full history needed for git diff against main
11+
- run: git fetch origin main:refs/remotes/origin/main
12+
name: Ensure origin/main ref is available for diff computation

.github/skills/code-review/SKILL.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ Key constraints (details in copilot-instructions.md):
2525
## Step 1: Get the Diff
2626

2727
```bash
28-
BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
29-
|| git merge-base origin/main HEAD 2>/dev/null)
30-
if [ -z "$BASE" ]; then
31-
echo "ERROR: Cannot find upstream/main or origin/main. Cannot determine review scope."
32-
exit 1
28+
# Primary: use gh pr diff (works in cloud agent + any PR context).
29+
# Fallback: git merge-base for local non-PR usage.
30+
if gh pr diff --name-only >/dev/null 2>&1; then
31+
echo "---STAT---"
32+
gh pr diff --name-only
33+
echo "---DIFF---"
34+
gh pr diff
35+
else
36+
BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
37+
|| git merge-base origin/main HEAD 2>/dev/null \
38+
|| git merge-base main HEAD 2>/dev/null)
39+
echo "Reviewing changes since: $BASE"
40+
git diff "$BASE"..HEAD --stat
41+
git diff "$BASE"..HEAD
3342
fi
34-
echo "Reviewing changes since: $BASE"
35-
git diff "$BASE"..HEAD --stat
36-
git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/'
3743
```
3844

3945
If the diff is empty, stop and report: "No changes found to review."
@@ -196,3 +202,9 @@ one pass. If any were skipped, note them and briefly assess.
196202
### Summary
197203

198204
X findings (N critical, N high, N medium, N low). One sentence overall assessment.
205+
206+
### Output
207+
208+
After generating the report above, write the COMPLETE report to `/tmp/code-review-report.md`
209+
using the `create` tool or shell. This ensures the full report is preserved even if
210+
display output is truncated.

.github/skills/deep-review/SKILL.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,25 @@ Use `read_agent` with `wait: true` to wait for each background agent.
4040
## Step 1: Get the Diff and Build Inventory
4141

4242
```bash
43-
BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
44-
|| git merge-base origin/main HEAD 2>/dev/null)
45-
if [ -z "$BASE" ]; then
46-
echo "ERROR: Cannot find upstream/main or origin/main."
47-
exit 1
43+
# Primary: use gh pr diff (works in cloud agent + any PR context).
44+
# Fallback: git merge-base for local non-PR usage.
45+
if gh pr diff --name-only >/dev/null 2>&1; then
46+
echo "---STAT---"
47+
gh pr diff --name-only
48+
echo "---DIFF---"
49+
gh pr diff
50+
else
51+
BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
52+
|| git merge-base origin/main HEAD 2>/dev/null \
53+
|| git merge-base main HEAD 2>/dev/null)
54+
echo "Reviewing changes since: $BASE"
55+
git diff "$BASE"..HEAD --stat
56+
git diff "$BASE"..HEAD
4857
fi
49-
echo "Reviewing changes since: $BASE"
50-
git diff "$BASE"..HEAD --stat
51-
git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/' | head -2000
5258
```
5359

5460
If the diff is empty, stop and report: "No changes found to review."
5561

56-
**Scope rule:** Focus on code files (`*.rs`, `*.toml`, examples). Do NOT pass
57-
docs/config diffs to agents.
58-
5962
**Build a risk-classified inventory.** List every changed function, struct,
6063
impl, trait, pub item, and significant code block. Number them and tag with
6164
risk predicates:
@@ -106,8 +109,10 @@ Use `model: "gpt-5.4"` in the task tool call (provides model diversity).
106109
> Get the diff:
107110
> ```
108111
> BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
109-
> || git merge-base origin/main HEAD 2>/dev/null)
110-
> git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/'
112+
> || git merge-base origin/main HEAD 2>/dev/null \
113+
> || git merge-base main HEAD 2>/dev/null)
114+
> # If no merge-base, use: gh pr diff
115+
> git diff "$BASE"..HEAD # or: gh pr diff
111116
> ```
112117
>
113118
> Key regorus constraints:
@@ -161,8 +166,10 @@ Use `model: "claude-opus-4.6"` in the task tool call.
161166
> Get the diff AND read full source files for context:
162167
> ```
163168
> BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
164-
> || git merge-base origin/main HEAD 2>/dev/null)
165-
> git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/'
169+
> || git merge-base origin/main HEAD 2>/dev/null \
170+
> || git merge-base main HEAD 2>/dev/null)
171+
> # If no merge-base, use: gh pr diff
172+
> git diff "$BASE"..HEAD # or: gh pr diff
166173
> ```
167174
> Then use `view` to read the full source files that were changed.
168175
>
@@ -219,8 +226,10 @@ Use the default model (no `model` parameter).
219226
> Get the diff:
220227
> ```
221228
> BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
222-
> || git merge-base origin/main HEAD 2>/dev/null)
223-
> git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/'
229+
> || git merge-base origin/main HEAD 2>/dev/null \
230+
> || git merge-base main HEAD 2>/dev/null)
231+
> # If no merge-base, use: gh pr diff
232+
> git diff "$BASE"..HEAD # or: gh pr diff
224233
> ```
225234
> Use `view` to read surrounding context.
226235
>
@@ -439,8 +448,10 @@ Launch **1 general-purpose agent in background mode**.
439448
> Get the diff:
440449
> ```
441450
> BASE=$(git merge-base upstream/main HEAD 2>/dev/null \
442-
> || git merge-base origin/main HEAD 2>/dev/null)
443-
> git diff "$BASE"..HEAD -- '*.rs' '*.toml' 'examples/'
451+
> || git merge-base origin/main HEAD 2>/dev/null \
452+
> || git merge-base main HEAD 2>/dev/null)
453+
> # If no merge-base, use: gh pr diff
454+
> git diff "$BASE"..HEAD # or: gh pr diff
444455
> ```
445456
> Use `view` to read full source files.
446457
>
@@ -481,8 +492,8 @@ Launch **1 general-purpose agent in background mode**.
481492
482493
## Step 5: Synthesize and Report
483494
484-
**IMPORTANT:** This is the primary output. Everything above was preparation.
485-
Keep the report COMPACT — one finding per block, no filler prose.
495+
**CRITICAL:** Write the report to `/tmp/deep-review-report.md` FIRST, then display it.
496+
Use a shell command to write the file before any other output in this step.
486497
487498
Apply verdicts from the adversarial verifier:
488499
- **CONFIRMED**: keep at stated severity
@@ -522,3 +533,9 @@ would catch it. If not, name the minimal test that should exist.
522533
X findings (N critical, N high, N medium, N low). Y "likely" findings.
523534
Z dropped (one-line reasons).
524535
Risk assessment in one sentence.
536+
537+
---
538+
539+
**Remember:** The report above MUST be written to `/tmp/deep-review-report.md` at the
540+
START of Step 5 (before displaying it). Use shell: `cat > /tmp/deep-review-report.md << 'REPORT_EOF'`
541+
... report content ... `REPORT_EOF`

0 commit comments

Comments
 (0)