Cursor
Cursor is a finished harness inside an editor. You cannot change its loop. You control it through rules, an instructions file, MCP servers, and hooks.Cursor 是嵌在编辑器里的现成 Harness。它的循环无法修改。你通过规则、指令文件、MCP 服务和钩子来控制它。
These guides were written from vendor documentation read in October 2026. None was executed: there was no account on these platforms. Product names change often. Confirm each command against the linked source before you rely on it.这些指南依据 2026 年 10 月查阅的厂商文档编写。全部未经实际执行:编写时没有这些平台的账号。产品名称经常变化。使用前请对照链接的来源逐条核实命令。
What you own归你负责的
Rules, AGENTS.md, MCP servers, hook scripts, the eval scripts in your repository.规则、AGENTS.md、MCP 服务、钩子脚本、仓库里的评估脚本。
What the platform runs由平台运行的
The loop, code indexing, context selection, model routing.循环、代码索引、上下文选择、模型路由。
Build steps搭建步骤
01Write project rules编写项目规则
Do this操作
- Rules live in `.cursor/rules` as `.mdc` files. A plain `.md` file there is ignored.规则以 `.mdc` 文件的形式放在 `.cursor/rules` 下。放在那里的普通 `.md` 文件会被忽略。
- Frontmatter has three fields: `description`, `globs`, `alwaysApply`.frontmatter 有三个字段:`description`、`globs`、`alwaysApply`。
- With only a description, the agent pulls the rule in when relevant. That is the skill pattern from module 8.只写 description 时,智能体会在相关时自行引入该规则。这就是第 8 模块的技能模式。
---
description: Questions about what was actually spent, by whom, where or when
alwaysApply: false
---
Call query_expenses before stating any amount. Name the filters you used.
When the result is empty, read the diagnostic and relax the filter it names.
Never explain why spending could not exist.You are done when完成标志The rule is applied for a spending question and absent for a greeting.遇到支出类问题时规则被应用,遇到问候语时没有。
02Add AGENTS.md for standing instructions添加 AGENTS.md 存放长期指令
Do this操作
- AGENTS.md is supported in the project root and in subdirectories.项目根目录和子目录里的 AGENTS.md 都受支持。
- Nested files apply to their directory and combine with parent files. The more specific one takes precedence.嵌套的文件对所在目录生效,并与上级文件合并。更具体的那个优先。
You are done when完成标志An instruction in a subdirectory file applies only to work in that directory.子目录文件里的指令只对该目录下的工作生效。
03Register the MCP server注册 MCP 服务
Do this操作
- Add the server to the project MCP config with a command and arguments.在项目的 MCP 配置里添加该服务,写明命令和参数。
- The file location `.cursor/mcp.json` is from general knowledge and was not on the pages read. Confirm it on the vendor's MCP page.`.cursor/mcp.json` 这个文件位置来自一般性了解,所查阅的页面上没有出现。请到厂商的 MCP 文档确认。
{
"mcpServers": {
"policy-desk": {
"command": "/abs/path/to/venv/bin/python3",
"args": ["-m", "labs.m06_tools.mcp_server"]
}
}
}You are done when完成标志The two tools are listed in the editor's tool settings.编辑器的工具设置里列出了这两个工具。
04Enforce policy with hooks用钩子强制执行策略
Do this操作
- Project hooks live in `.cursor/hooks.json`. User hooks live in `~/.cursor/hooks.json`.项目级钩子在 `.cursor/hooks.json`,用户级钩子在 `~/.cursor/hooks.json`。
- The `hooks` object maps an event name to a list of definitions, each with a `command`.`hooks` 对象把事件名映射到一组定义,每个定义都有一个 `command`。
- A hook script reads JSON on stdin. Exit code 2 blocks the action. Other non-zero codes fail open unless `failClosed` is set.钩子脚本从 stdin 读取 JSON。退出码 2 会阻止操作。其他非零退出码默认放行,除非设置了 `failClosed`。
{
"version": 1,
"hooks": {
"beforeMCPExecution": [
{ "command": "./.cursor/hooks/check-tool.sh", "failClosed": true }
],
"beforeShellExecution": [
{ "command": "./.cursor/hooks/check-shell.sh" }
]
}
}You are done when完成标志A blocked action shows as denied and the agent continues without it.被阻止的操作显示为已拒绝,智能体在没有它的情况下继续工作。
05Keep evals as scripts and require them把评估做成脚本,并要求必须通过
Do this操作
- Evals are files in your repository. The labs run with one command.评估就是仓库里的文件。lab 用一条命令就能跑完。
- Use a `stop` or `afterFileEdit` hook to run the retrieval eval when ranking code changes.用 `stop` 或 `afterFileEdit` 钩子,在排序代码发生变化时运行检索评估。
You are done when完成标志Editing the search code triggers the eval.编辑检索代码会触发评估。
06Subagents and skills子智能体与技能
Do this操作
- The vendor documentation has pages for subagents and skills. They were not read for this guide.厂商文档里有子智能体和技能的页面。本指南没有查阅它们。
- Apply the test from module 12 before adding one: name the need and the measurement.增加之前先做第 12 模块的检验:说出具体需求和测量方式。
You are done when完成标志You can state why the subagent exists.你能说出这个子智能体为什么存在。