Skip to content

feat: add GitHub Copilot CLI agent adapter - #15

Merged
vsn411 merged 3 commits into
secfoo-com:mainfrom
AdithKB:agents/copilot-cli-adapter
Sep 23, 2026
Merged

vsn411 merged 3 commits into
secfoo-com:mainfrom
AdithKB:agents/copilot-cli-adapter

Conversation

@AdithKB

@AdithKB AdithKB commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

What does this change, and why?

Adds CopilotAdapter for the GitHub Copilot CLI (Initiative 1 of the Q4 sprint plan) — the standalone copilot binary (npm @github/copilot, GA since Feb 2026), not the retired gh copilot GitHub CLI extension, which is now just a thin wrapper around this same binary.

Flags were verified against a real installed copilot --help (v1.0.86), not just docs — the CLI ships updates often and flags have already drifted once (the pre-GA extension used a different flag set entirely). --allow-all-tools is required for non-interactive mode per the CLI's own --help text; deliberately does not pass the broader --allow-all/--yolo/--allow-all-paths/--allow-all-urls, matching the minimal-grant pattern the other adapters already use.

A real, verified quirk, and the fix that goes with it

Real end-to-end testing (secfoo run --agent copilot against a live target, run twice, two different skills) surfaced a genuine behavior: Copilot CLI unpromptedly runs its own native security-scanning tool first — emitting an unrelated ##/### preamble — before going on to produce the skill's actual requested report, and never writes the required top-level # <Skill> Report heading at all. report/markdown.py's strip_preamble() only knew how to anchor on that heading, so it found nothing and left the whole duplicated block in the stored report (roughly 2x the expected length, confirmed on captured real output — 713 lines down to the real 281).

Fixed by adding a fallback anchor on the literal ## 1. Executive Summary text — every skill's contract requires that exact phrase as its first numbered section (skills/renderer.py), so it's a safe, skill-agnostic backstop that never fires for an already-compliant agent (the primary heading anchor always wins when both are present). The fallback was deliberately made an exact match rather than "any numbered section 1" after finding that a looser version would wrongly match an unrelated preamble that numbers its own "1." section (e.g. a to-do list) — verified with a regression test for that specific false positive.

Both fixes were re-verified against the actual captured Copilot output from real runs, not just synthetic test strings.

Known follow-up, intentionally not addressed here

Real testing also surfaced a pre-existing, agent-agnostic risk in runner.py/storage/repository.py: if any agent's SAST report ever parses to zero findings (a malformed/incomplete answer, not necessarily Copilot-specific — reproduced the same way with a claude-labeled run too), close_stale_sast_findings() has no way to distinguish "genuinely clean rescan" from "couldn't parse the report," and silently marks every previously-open finding for that project as closed. Verified end-to-end: a real, still-open SQL injection finding flipped to closed from a malformed report with zero code changes needed to trigger it. This is out of scope for an adapter PR (it's shared lifecycle-tracking logic, not agent-specific), but flagging it here since Copilot's demonstrated unpredictability makes it materially more likely to trigger than with the steadier existing agents — worth its own issue/fix.

Testing

  • pytest tests passes (643 passed)
  • ruff check clean on every new/changed file
  • Real end-to-end runs: secfoo run --skill sast --agent copilot and secfoo run --skill sast --skill secret-scanning --agent copilot, both against a live GitHub target, from a clean checkout of this exact branch (not just the dev working tree)
  • is_available() verified as genuine black-box behavior (PATH stripped of the binary → no), not just mocked
  • Dashboard run-detail pages verified visually for both real runs — clean rendering, no console errors, no leftover pollution
  • Unit tests added: tests/test_agents/test_copilot.py (8 tests), tests/test_report/test_markdown.py (3 new tests covering the fallback and its false-positive fix)

🤖 Generated with Claude Code

AdithKB and others added 3 commits September 18, 2026 11:17
Adds CopilotAdapter for the standalone `copilot` binary (npm
@github/copilot, GA since Feb 2026) -- not the retired `gh copilot`
extension, which now just shells out to this same binary. Flags
verified against a real `copilot --help` (v1.0.86) and against a real
end-to-end `secfoo run --skill sast --agent copilot` invocation, not
just docs (the pre-GA extension used different flags entirely, and
these change often).

Also fixes report/markdown.py's strip_preamble(): it assumed every
agent emits a literal top-level "# <Skill> Report" heading to anchor
on, but real testing against Copilot CLI found it unpromptedly runs
its own native security-scan tool first (an unrelated "##"/"###"
preamble) and then never emits that single top-level heading at all,
so the anchor search found nothing and left the whole duplicated block
in the stored report. Adds a fallback anchor on "## 1. Executive
Summary" -- every skill's contract requires that as its first numbered
section regardless of agent, so it's a safe backstop that doesn't
change behavior for any already-compliant agent. Verified against the
actual captured Copilot report: 713 lines down to 281, landing exactly
on the real content.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…atch

The fallback added for the copilot adapter matched any "## 1. <text>"
heading, not specifically "## 1. Executive Summary". That's too loose:
a preamble that numbers its own unrelated section "1." (a plan, a
to-do list) would get matched instead of the real report, cutting to
that wrong, earlier point instead of skipping the preamble entirely.

Tightens the regex to the literal "## 1. Executive Summary" text --
every skill's contract requires that exact phrase (skills/renderer.py),
so it's no less general, just no longer over-matching. Adds a
regression test for the false-positive this closes, and re-verified
against both real captured Copilot reports from earlier end-to-end
testing to confirm the actual fix still works.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@vsn411
vsn411 merged commit 0f05096 into secfoo-com:main Sep 23, 2026
2 checks passed
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