Skip to content

feat(guard): send X-Agent-Surface: cursor-cloud from Cursor cloud sessions - #575

Open
phsommer wants to merge 1 commit into
mainfrom
feat/cursor-cloud-surface
Open

phsommer wants to merge 1 commit into
mainfrom
feat/cursor-cloud-surface

Conversation

@phsommer

@phsommer phsommer commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Send X-Agent-Surface: cursor-cloud when the cursor client's hook runs with CURSOR_AGENT_SOCKET set (non-empty), i.e. in a Cursor cloud session.
  • Every other Cursor surface sends no header, as before.
  • Scoped to the cursor client, like the Copilot surfaces: the variable is inherited by anything a cloud session spawns, so other clients never claim it.
  • Applied to all three senders: hook_events.agent_surface(), snyk-agent-guard.sh and snyk-agent-guard.ps1.

Why

Cursor cloud sessions do not fire Cursor's specialized hooks (beforeMCPExecution, ...). agent-monitor uses this header to handle their tool calls in the generic hooks instead of skipping them.

Test plan

  • tests/unit/test_hook_events.py and tests/unit/test_guard.py (966 passed, 34 skipped). New cases: cursor with/without/empty CURSOR_AGENT_SOCKET, other clients never claim the surface, and the real .sh script against the test hook server.
  • PowerShell block evaluated under pwsh for cursor with/without the variable, claude-code, and github-copilot (the repo has no execution tests for .ps1).
  • Confirm in a real Cursor cloud session that CURSOR_AGENT_SOCKET is set in the hook process environment.

🤖 Generated with Claude Code


Note

Low Risk
Additive header behavior for one client and env var; scoped to avoid mis-attribution on other agents.

Overview
Hook forwarders now emit X-Agent-Surface: cursor-cloud when the cursor client runs with a non-empty CURSOR_AGENT_SOCKET (Cursor cloud). Other Cursor surfaces still send no surface header, matching the existing Copilot-only surface pattern.

The same detection is wired through agent_surface() in Python and get_agent_surface / PowerShell agent-surface logic in the shell hooks, with CURSOR_AGENT_SOCKET gated to --client cursor so inherited env vars cannot make other clients (e.g. claude-code, codex) claim cursor-cloud.

Unit tests cover cursor with/without the variable, empty values, and cross-client isolation for both Python delivery and the .sh hook script.

Reviewed by Cursor Bugbot for commit 00da6fb. Bugbot is set up for automated code reviews on this repo. Configure here.

…sions

Cursor cloud sessions do not fire Cursor's specialized hooks
(beforeMCPExecution and friends), which agent-monitor needs to know so it
handles their tool calls in the generic hooks.

Report the "cursor-cloud" surface when the cursor client's hook runs with
CURSOR_AGENT_SOCKET set (non-empty). Every other Cursor surface sends no
header, as before. Like the Copilot surfaces, it is scoped to its own client:
the variable is inherited by anything a cloud session spawns, so other
clients never claim it.

Implemented in all three senders: hook_events.agent_surface(),
snyk-agent-guard.sh and snyk-agent-guard.ps1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@phsommer
phsommer requested review from a team and marcelosousa as code owners November 27, 2026 15:03
@qodo-merge-etso

qodo-merge-etso Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Identify Cursor cloud sessions in guard hook requests

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Send X-Agent-Surface: cursor-cloud when a Cursor hook has a non-empty CURSOR_AGENT_SOCKET.
• Leave other Cursor surfaces and clients unchanged, so inherited variables cannot misidentify them.
• Cover Python and Bash senders with tests; apply the same detection to PowerShell.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The Python sender and Bash/PowerShell forwarders implement the same end-to-end outbound hook-event metadata contract.
  • Their paths terminate at one agent-monitor integration behavior rather than independent user capabilities.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before, only Copilot clients produced surface metadata.
  • After, Cursor produces cursor-cloud only with CURSOR_AGENT_SOCKET.
  • New correctness condition: client identity must gate the inherited environment variable so non-Cursor hooks cannot claim Cursor attribution, while empty or absent values remain unreported.
  • The same compatibility rule is implemented in Python, Bash, and PowerShell.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If surface classification regresses, agent-monitor may attribute Cursor cloud events to the wrong surface or omit attribution.
  • Hook delivery and event payload processing otherwise continue.
  • The precise downstream business effect is uncertain because the consumer is external.
  • Reverting the code prevents new misclassification, but previously received attribution may require consumer-side correction or replay if it is persisted.
Assessed commit 00da6fb
Diagram

graph TD
  A["Cursor hook"] --> B["Socket signal"] --> C["Python sender"] --> F["Agent monitor"]
  B --> D["Bash sender"] --> F
  B --> E["PowerShell sender"] --> F
Loading
High-Level Assessment

Keep the client-scoped environment check in each existing sender. It preserves the current hook wire contract and prevents a process spawned by Cursor cloud from labeling another client's request.

Files changed (5) +99 / -5

Enhancement (3) +24 / -5
hook_events.pyDetect the Cursor cloud surface in Python hook events +10/-4

Detect the Cursor cloud surface in Python hook events

• Returns 'cursor-cloud' only for Cursor hooks with a non-empty 'CURSOR_AGENT_SOCKET'. Other Cursor surfaces return no value, while existing Copilot detection remains intact.

src/agent_scan/hook_events.py

snyk-agent-guard.ps1Add Cursor cloud detection to the PowerShell hook +6/-1

Add Cursor cloud detection to the PowerShell hook

• Selects 'cursor-cloud' for Cursor hooks when the socket variable is non-empty, allowing the existing request code to include 'X-Agent-Surface'.

src/agent_scan/hooks/snyk-agent-guard.ps1

snyk-agent-guard.shAdd Cursor cloud detection to the Bash hook +8/-0

Add Cursor cloud detection to the Bash hook

• Extends surface detection to return 'cursor-cloud' only for Cursor hooks with a non-empty socket variable. Other clients retain their previous behavior.

src/agent_scan/hooks/snyk-agent-guard.sh

Tests (2) +75 / -0
test_guard.pyTest Cursor surface headers from the Bash hook +33/-0

Test Cursor surface headers from the Bash hook

• Runs the real Bash hook against the test server to verify cloud, absent, and empty socket cases, plus isolation from other clients.

tests/unit/test_guard.py

test_hook_events.pyTest Cursor surface headers from Python hook events +42/-0

Test Cursor surface headers from Python hook events

• Checks that only Cursor cloud requests receive the header, including cases with no socket or Copilot variables. Verifies that other clients do not claim an inherited Cursor cloud surface.

tests/unit/test_hook_events.py

@qodo-merge-etso

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can commit Qodo's fix in one click with committable suggestions (GitHub & GitLab)

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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.

1 participant