feat: add GitHub Copilot support to guard - #468
Conversation
f00a617 to
cb92e34
Compare
PR Summary by QodoAdd GitHub Copilot hook support to Agent Guard
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo
1. Copilot users receive hooks that never run
|
| COPILOT_HOOK_EVENTS = [ | ||
| "SessionStart", | ||
| "UserPromptSubmit", | ||
| "PreToolUse", | ||
| "PostToolUse", | ||
| "PreCompact", | ||
| "SubagentStart", | ||
| "SubagentStop", | ||
| "Stop", | ||
| ] |
There was a problem hiding this comment.
2. Copilot users receive hooks that never run 🐞 Bug ≡ Correctness
_prepare_copilot_config writes Claude-style PascalCase event keys from COPILOT_HOOK_EVENTS, including placing discovery under SessionStart. Copilot dispatches its hook lifecycle events with its own lower-camel-case names, so the installed forwarding and session-discovery entries are not invoked despite status detection scanning the same invalid keys.
Agent Prompt
## Issue description
The generated GitHub Copilot hook configuration uses Claude-style event names, so Copilot does not dispatch the installed hook commands or the session-start discovery command.
## Issue Context
`_prepare_copilot_config` directly serializes `COPILOT_HOOK_EVENTS` as JSON keys and adds discovery to `SessionStart`; detection also depends on this list. Replace these with Copilot's supported event names and update the discovery event key consistently.
## Fix Focus Areas
- src/agent_scan/guard.py[136-145]
- src/agent_scan/guard.py[782-788]
- src/agent_scan/guard.py[1208-1209]
- tests/unit/test_guard.py[814-856]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
We register the PascalCase hook events which are supported by Github Copilot as well. Documented here: https://docs.github.com/en/copilot/reference/hooks-reference#hook-event-input-payloads
670261d to
e7233e7
Compare
| "SubagentStart", | ||
| "SubagentStop", | ||
| "Stop", | ||
| ] |
There was a problem hiding this comment.
Wrong Copilot hook event keys
High Severity
COPILOT_HOOK_EVENTS uses Claude-style PascalCase names (SessionStart, PreToolUse, UserPromptSubmit, Stop, etc.), but GitHub Copilot’s hooks schema expects camelCase keys such as sessionStart, preToolUse, userPromptSubmitted, and agentStop. Installed entries land under keys Copilot never reads, so guard hooks would not run while install/detect can still look successful.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit e7233e7. Configure here.
There was a problem hiding this comment.
We register the PascalCase hook events which are supported by Github Copilot as well. Documented here: https://docs.github.com/en/copilot/reference/hooks-reference#hook-event-input-payloads
Adds `github-copilot` as a client for `guard install`, `guard uninstall` and `guard discover`. User-level hooks are written to ~/.copilot/hooks/agent-guard.json, which every Copilot surface reads — the CLI, the desktop app, and Copilot inside VS Code. Adds managed hooks, which Copilot calls policy hooks: /etc/github-copilot/ policy.d/agent-guard.json, or C:\ProgramData\GitHub\Copilot\policy.d on Windows, installed with `--managed` and reported by `guard status`. Hook events carry an X-Agent-Surface header (`copilot`, or `copilot-vscode` inside VS Code) resolved from AI_AGENT and COPILOT_CLI.
A Copilot command hook names its script under `bash` (Unix), `powershell` (Windows), or `command` (cross-platform fallback). Write the platform-specific key and read all three, consistently across install filtering, status detection, hook diffs and uninstall.
e7233e7 to
4c2a154
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4c2a154. Configure here.
| "claude-code": HookClient("cwd", "session_id", "/hidden/agent-monitor/hooks/claude-code"), | ||
| "cursor": HookClient("workspace_roots", "conversation_id", "/hidden/agent-monitor/hooks/cursor"), | ||
| "codex": HookClient("cwd", "session_id", "/hidden/agent-monitor/hooks/codex"), | ||
| "github-copilot": HookClient("cwd", "session_id", "/hidden/agent-monitor/hooks/github-copilot"), |
There was a problem hiding this comment.
Copilot discovery ignores sessionId
Medium Severity
GitHub Copilot hook stdin uses camelCase sessionId, but guard discover for github-copilot looks up session_id via HOOK_CLIENTS. Real SessionStart payloads therefore never supply a session id, so discovery always falls back to the generic session-start-server-discovery marker instead of correlating with the active Copilot session.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 4c2a154. Configure here.


Adds
github-copilotas a client forguard install,guard uninstallandguard discover. User-level hooks are written to ~/.copilot/hooks/agent-guard.json, which every Copilot surface reads — the CLI, the desktop app, and Copilot inside VS Code.Adds managed hooks, which Copilot calls policy hooks: /etc/github-copilot/ policy.d/agent-guard.json, or C:\ProgramData\GitHub\Copilot\policy.d on Windows, installed with
--managedand reported byguard status.Hook events carry an X-Agent-Surface header (
copilot, orcopilot-vscodeinside VS Code) resolved from AI_AGENT and COPILOT_CLI.Notes for review
/hidden/agent-monitor/hooks/github-copilot, which only exists once snyk/agent-monitor#367 ships. That PR must merge first.Note
Medium Risk
Installs and modifies agent hook configs (including managed policy files) and depends on a new agent-monitor hook route shipping separately; telemetry uses existing push-key auth with added surface attribution logic.
Overview
Adds GitHub Copilot as a first-class Agent Guard client alongside Claude, Cursor, and Codex. The CLI accepts
github-copilotforguard install,uninstall, anddiscover, andguard install allnow includes Copilot when~/.copilotexists.Install writes user hooks to
~/.copilot/hooks/agent-guard.json(Copilot’s flat hook schema withtype: commandand platformbash/powershellkeys).--managedtargets OS-specificpolicy.d/agent-guard.jsonpaths; on POSIX, writes underpolicy.dstrip group/world write bits so Copilot won’t silently ignore the policy. Hook scripts are co-located without a nestedhooks/hooksdirectory for user-level configs.Hook forwarding and
guard discoverpost to/hidden/agent-monitor/hooks/github-copilot. For Copilot only, events may includeX-Agent-Surface(copilot-vscodevscopilot) derived fromAI_AGENT/COPILOT_CLI, including in the shell/PowerShell forwarders and Pythonsend_hook_event—other clients never send that header even if Copilot env vars are inherited.Uninstall/detect/diff paths recognize guard entries under
bash,powershell, orcommand. Unit and integration tests cover prepare/uninstall, policy hardening, surface scoping, and the new endpoint.Reviewed by Cursor Bugbot for commit 4c2a154. Bugbot is set up for automated code reviews on this repo. Configure here.