@weave_protocol/adapter-cursor
v0.3.0
Published
Weave Protocol adapter for Cursor - enforces WARD.md policies via Cursor's agent hooks
Maintainers
Readme
🛡️ @weave_protocol/adapter-cursor
Enforce WARD.md in Cursor with its agent hooks. Shell commands, file reads and writes, and MCP calls are checked against your policy before they run.
The same WARD.md you use with Claude Code, Antigravity, Microsoft Agent Framework, Gemini CLI, Codex CLI and OpenCode.
🆕 What's new
0.3.0: session and spend limits. WARD.md's limits are now enforced per session, keyed on the Cursor conversation_id:
- Behavioral Limits:
maxToolCalls,maxRuntimeSecondsandmaxExternalServices; spending_limits:caps: tool calls, and per-tool call counts and USD amounts over a run, hour, day, week or month.
The counts live in a small local ledger (~/.weave/ledger, or $WEAVE_LEDGER_DIR) because every hook call is a new process. Ward 0.3.6's payment guard also asks before any call that moves money: payment tools, and wallet or Stripe CLIs in shell commands.
Quick start
npm i -g @weave_protocol/adapter-cursor
weave-ward-cursor init # adds the hook to ~/.cursor/hooks.json
weave-ward-cursor statusCursor reloads hooks.json when it changes. Add a WARD.md to your project (npx @weave_protocol/ward init), or a user-wide one at ~/.cursor/WARD.md.
How it hooks in
One command, weave-ward-cursor hook, is registered on four of Cursor's agent hook events. It decides each call with Ward's shared evaluator (evaluateToolCall), so the rules match the other adapters exactly:
| Event | Checked |
|---|---|
| beforeShellExecution | shell_exec, the command's cwd (as a read), and every URL and absolute or ~ path in the command |
| beforeReadFile | the file_path (as a read) |
| beforeMCPExecution | mcp__<server>__<tool>, plus every path and URL argument in its tool_input |
| preToolUse | every other tool (Write, Delete, Grep, Task, …), by capability and every path-named argument. Shell, Read and MCP are left to the events above, which carry richer fields. |
Decisions
| WARD decision | What Cursor sees |
|---|---|
| allow | nothing: the call continues, and Cursor's own approval settings still apply |
| deny | permission: "deny", with the reason in user_message and agent_message |
| require_approval | permission: "ask" for shell and MCP calls, where Cursor enforces it. Elsewhere it's a deny whose reason says approval is needed, because preToolUse doesn't enforce "ask" and beforeReadFile has none. |
Failure modes:
- An invalid WARD.md always denies, so a typo can't silently switch enforcement off.
- No WARD.md anywhere means no enforcement.
- Malformed payloads and evaluator errors allow by default.
init --fail-closedmakes them deny.
WARD.md is looked up in this order:
$WEAVE_WARD_PATH<workspace>/WARD.md<workspace>/.cursor/WARD.md<workspace>/.weave/WARD.md~/.cursor/WARD.md
Commands
weave-ward-cursor init [--timeout=SECONDS] [--fail-closed]
weave-ward-cursor disable
weave-ward-cursor status
weave-ward-cursor test Read --input='{"file_path":"secrets/key"}' # dry run
weave-ward-cursor hook # what Cursor runsinit backs up hooks.json and edits it atomically. It adds one entry per event and leaves your other hooks alone. The command is weave-ward-cursor, matching weave-ward-codex and weave-ward-opencode.
Dashboard
Set WEAVE_DASHBOARD_URL (and WEAVE_API_KEY) where you run the agent, and each decision is reported to a local Weave API dashboard (0.2.0+). Only the decision and the tool name are sent, never command or argument contents. Reporting never changes a decision and gives up after 250 ms.
Verified
Built against Cursor's agent hooks documentation, with 12 fixture tests.
Live-checked in the Cursor app (3.28.7) with a project-level .cursor/hooks.json:
- Denied read: the agent's read of
secrets/keywas blocked throughbeforeReadFile, withWARD: Denied by filesystem rule …. - Allowed read:
notes.txtwent through. - Denied write: creating
secrets/new.txtwas blocked throughpreToolUse. Cursor sends writes astool_name: "Write"withtool_input: { file_path, content }. - Reads are decided once: each read also arrives as a
preToolUse. The adapter leaves those tobeforeReadFile, which fires whenever file content is actually read.
Cursor's docs don't say whether the cursor-agent CLI runs agent hooks, so this is verified for the app.
🕸️ Part of Weave Protocol
One WARD.md policy for every agent you run, locally or at scale, plus the tools around it.
| Package | What it does | |---|---| | Ward | The WARD.md policy standard and the tool-call evaluator every adapter shares | | Mund | Scans content for prompt injection, secrets, PII and exfiltration | | Hord | Encrypted vaults, PII tokenization, sandboxes, capability tokens, attestations | | Dōmere | Audit threads, compliance checkpoints, GDPR and CCPA records, anchoring | | Witan | Multi-agent consensus and spending caps | | Hundredmen | MCP proxy that enforces WARD.md on tool calls | | Tollere | Supply-chain checks: typosquats, CVEs, suspicious version diffs | | Browser | WARD.md and injection scanning for Playwright browser agents | | Adapters | WARD.md in Claude Code, Antigravity, MSAF, Gemini CLI, Codex, OpenCode and Cursor | | Adversary · AgentSecBench | Red-team engine and locked benchmark | | API · CLI · LangChain | REST API and dashboard, setup CLI, LangChain.js integration | | full | Every defensive package in one install | | Yoxallismus | Post-quantum hybrid cipher (experimental beta) |
License
Apache-2.0
