规则系统 (Rules)
规则为 Agent 提供系统级指令,在提示级别提供持久、可重用的上下文。三款工具都支持多层级规则,但配置方式不同。
三工具规则层级对比
| 层级 | Cursor | Copilot | Antigravity |
|---|---|---|---|
| 全局/个人 | Settings → Rules (User Rules) | VS Code: Personal Instructions IDEA: global-copilot-instructions.md |
~/.gemini/GEMINI.md |
| 项目/仓库 | .cursor/rules/*.mdc |
.github/copilot-instructions.md |
.agent/rules/*.md |
| 路径特定 | globs 字段匹配 | .github/instructions/*.instructions.md |
Glob激活方式 |
| 团队/组织 | Dashboard Team Rules | Organization Settings | 通过Git共享 |
| 优先级 (高→低) | Team > Project > User | Personal > Repository > Organization | Workspace > Global |
Cursor 规则详解
文件位置
project/
├── .cursor/
│ └── rules/
│ ├── react-patterns.mdc # 带frontmatter的规则
│ ├── api-guidelines.md # 纯markdown规则
│ └── frontend/
│ └── components.md # 子目录组织
├── AGENTS.md # 根目录Agent指令(可选)
└── .cursorrules # 旧版(即将废弃)
四种激活方式
| 类型 | frontmatter配置 | 触发条件 | 使用场景 |
|---|---|---|---|
| Always Apply | alwaysApply: true |
每个聊天会话自动应用 | 通用编码规范、项目约定 |
| Apply Intelligently | alwaysApply: false + description |
Agent根据description判断相关性 | 特定功能模块的规范 |
| Apply to Specific Files | globs: ["pattern"] |
当前文件匹配glob模式 | API文件、测试文件规范 |
| Apply Manually | 无特殊配置 | 在对话中 @rule-name 手动触发 |
按需调用的模板 |
Glob 语法详解
| 模式 | 匹配范围 | 示例匹配 |
|---|---|---|
* |
当前目录所有文件 | foo.ts, bar.js |
** 或 **/* |
所有目录所有文件 | 递归所有文件 |
*.py |
当前目录 .py 文件 | main.py, utils.py |
**/*.py |
递归匹配所有 .py | src/main.py, lib/util.py |
src/**/*.ts |
src下递归匹配.ts | src/index.ts, src/utils/helper.ts |
**/*.{ts,tsx} |
多扩展名匹配 | 所有 .ts 和 .tsx 文件 |
完整配置示例
示例1: Always Apply (通用规范)
---
description: "项目通用编码规范"
alwaysApply: true
---
# 编码规范
- 使用 TypeScript 编写所有新文件
- 使用函数式组件和 React Hooks
- 数据库字段使用 snake_case
- API 响应使用 camelCase
- 所有导出函数必须有 JSDoc 注释
示例2: Apply to Specific Files (API规范)
---
description: "API 开发规范,适用于 src/api 目录"
alwaysApply: false
globs: ["src/api/**/*.ts", "src/routes/**/*.ts"]
---
# API 开发规范
- 使用 RESTful 命名约定
- 所有端点必须有错误处理中间件
- 返回格式: { success: boolean, data?: T, error?: string }
- 参考 @src/api/template.ts 作为模板
示例3: Apply Intelligently (按需判断)
---
description: "单元测试规范。当用户请求编写测试、test、jest、vitest相关内容时应用此规则。"
alwaysApply: false
---
# 测试规范
- 使用 Vitest 作为测试框架
- 测试文件放在 __tests__ 目录
- 命名格式: {filename}.test.ts
- 每个函数至少3个测试用例: 正常、边界、异常
用户规则 (全局)
在 Cursor Settings → Rules 中设置,适用于所有项目:
请以简洁风格回复。避免不必要的重复。
使用中文回复技术问题。
优先使用函数式编程范式。
团队规则 (Team/Enterprise)
通过 Cursor Dashboard 管理,对所有团队成员生效:
- 立即启用: 创建后即时生效
- 强制执行: 成员无法关闭
- 优先级最高: Team → Project → User
GitHub Copilot 指令详解
三种指令类型
| 类型 | 文件位置 | 适用范围 | frontmatter |
|---|---|---|---|
| Repository-wide | .github/copilot-instructions.md |
整个仓库所有文件 | 无 |
| Path-specific | .github/instructions/*.instructions.md |
匹配applyTo的文件 | applyTo: "glob" |
| Agent指令 | AGENTS.md (任意位置) |
最近的AGENTS.md生效 | 无 |
Repository-wide 指令
# Project Overview
This is a React + Node.js web application.
## Tech Stack
- Frontend: React 18, TypeScript, Tailwind CSS
- Backend: Node.js, Express, PostgreSQL
- Testing: Jest, React Testing Library
## Coding Standards
- Use semicolons at the end of statements
- Use single quotes for strings
- Use function-based React components
- API responses follow { success, data, error } format
Path-specific 指令
---
applyTo: "src/api/**/*.ts,src/services/**/*.ts"
---
# Backend Development Rules
- Use dependency injection pattern
- All database queries must use parameterized statements
- Implement proper error handling with custom error classes
- Log all API requests with request ID
Glob 语法示例
| 模式 | 匹配范围 |
|---|---|
**/*.ts,**/*.tsx |
所有 TypeScript 文件 |
app/models/**/*.rb |
Rails models 目录 |
**/subdir/**/*.py |
任意深度 subdir 下的 .py |
excludeAgent 配置
控制指令适用于哪些 Agent:
---
applyTo: "**"
excludeAgent: "code-review"
---
这些指令只会被 Copilot Coding Agent 读取,
Code Review 功能不会使用。
个人指令 (Personal Instructions)
在 GitHub.com Copilot Chat 中设置,适用于所有仓库:
- 打开 Copilot Chat
- 点击左下角头像 → Personal Instructions
- 添加个人偏好指令
⚠️ 概念辨析:AGENTS.md vs Custom Agents
Copilot 中有两个容易混淆的概念,它们作用完全不同:
| 对比项 | AGENTS.md | Custom Agents |
|---|---|---|
| 本质 | 指令文件 (Instructions) | 专业化智能体 (Agent) |
| 作用 | 为 Copilot 提供项目上下文和行为约束 | 创建可 @ 提及的专业助手 |
| 文件位置 | AGENTS.md (项目根目录或子目录) |
.github/agents/*.md |
| 触发方式 | 自动生效 (最近的 AGENTS.md 优先) | 在 Chat 中 @agent-name 手动触发 |
| 类比 | 相当于 Cursor 的 Project Rules | 相当于 Cursor 的 Subagents |
| 应用场景 | 定义编码规范、项目约定、技术栈说明 | 创建测试专家、文档专家等专业角色 |
简单记忆:AGENTS.md 是"规则",Custom Agents 是"角色"。
Antigravity 规则详解
两层规则体系
| 层级 | 文件位置 | 作用范围 |
|---|---|---|
| Global | ~/.gemini/GEMINI.md |
所有工作区 |
| Workspace | .agent/rules/*.md |
当前项目 |
激活方式
在规则面板中可配置:
- Manual: 通过 @rule-name 手动激活
- Always On: 始终应用
- Model Decision: 根据描述由模型判断
- Glob: 文件匹配模式激活
配置示例
# Coding Standards
- Use Bazel for managing Java dependencies
- JavaScript: double quotes and tabs
- Track work items in Jira
- All commits must reference a ticket number
@ 文件引用
在规则中使用 @filename 引用其他文件:
遵循 @/docs/api-spec.md 中定义的 API 规范。
参考 @templates/service.ts 作为服务模板。
命令系统 (Commands)
命令系统允许封装可复用的提示工作流,通过简单的前缀触发。三款工具实现方式不同。
三工具命令对比
| 特性 | Cursor | Copilot | Antigravity |
|---|---|---|---|
| 名称 | Commands | Prompt Files | Workflows |
| 触发方式 | /command-name |
附加上下文选择 | /workflow-name |
| 文件位置 | .cursor/commands/*.md |
.github/prompts/*.prompt.md |
.agent/workflows/*.md |
| 文件引用 | 不支持 | Markdown link / #file: | @filename |
| 自动执行 | 需确认 | 需确认 | // turbo 注解 |
| 嵌套调用 | 不支持 | 不支持 | 支持调用其他Workflow |
| 团队共享 | Dashboard Team Commands | Git提交 | Git提交 |
Cursor Commands
文件位置
- 项目:
.cursor/commands/*.md - 全局:
~/.cursor/commands/*.md - 团队: Dashboard 管理
# Code Review Checklist
审查当前文件:
1. 检查错误处理是否完整
2. 验证输入参数校验
3. 评估性能影响
4. 检查安全问题
5. 提出改进建议
使用: 在聊天中输入 /code-review
Copilot Prompt Files
启用方式
- 打开 Command Palette (Ctrl+Shift+P)
- 选择 "Open Workspace Settings (JSON)"
- 添加:
"chat.promptFiles": true
将选中的代码重构为 TypeScript:
- 添加完整的类型定义
- 使用接口定义数据结构
- 参考现有类型: [types](../../src/types/index.ts)
- 保持原有功能不变
使用: 在 Chat 中点击附加上下文 → Prompt → 选择文件
Antigravity Workflows
文件位置
- 项目:
.agent/workflows/*.md - 全局:
~/.gemini/antigravity/workflows/*.md
Turbo 自动执行注解
| 注解 | 作用范围 | 说明 |
|---|---|---|
// turbo |
单步 | 放在步骤上一行,仅该步骤自动执行 |
// turbo-all |
全文件 | 放在文件任意位置,所有命令自动执行 |
示例:单步自动执行
---
description: 部署到生产环境
---
1. 运行测试确保通过
// turbo
2. npm test
3. 构建生产版本
// turbo
4. npm run build
示例:全部自动执行
---
description: 快速测试流程
---
// turbo-all
1. npm install
2. npm test
3. npm run lint
技能系统 (Skills)
Skills 遵循 Agent Skills 开放标准(由 GitHub、Anthropic、OpenAI 联合发起),使用 SKILL.md 封装领域知识。三款工具均已支持。
技能目录与触发方式
| 工具 | 项目级位置 | 全局位置 | 触发方式 |
|---|---|---|---|
| Cursor | .cursor/skills/, .claude/skills/ |
~/.cursor/skills/ |
/skill-name 或 Agent自动判断 |
| Copilot | .github/skills/ |
不支持全局 | Agent 根据上下文自动加载 |
| Antigravity | .agent/skills/ |
~/.gemini/antigravity/skills/ |
在查看 SKILL.md 后自动应用 |
Copilot 技能详解 (2025年12月 GA)
文件位置
project/
└── .github/
└── skills/
└── my-skill/
├── SKILL.md # 主指令文件 (必需)
├── scripts/ # 辅助脚本 (可选)
└── examples/ # 参考实现 (可选)
SKILL.md 格式
---
name: web-testing
description: Web应用测试技能。当用户请求编写E2E测试、Playwright、Cypress相关内容时使用。
---
# Web Testing Skill
## When to Use
- 编写端到端测试
- 配置 Playwright/Cypress
- 测试 Web 表单交互
## Instructions
- 使用 Playwright 作为默认测试框架
- 测试文件放在 tests/e2e/ 目录
- 每个页面一个测试文件
触发方式
Copilot 会根据用户的提示和 SKILL.md 的 description 自动判断是否加载技能,无需手动触发。
Cursor 技能触发详解
自动发现
Cursor 启动时自动扫描技能目录,将可用技能注册到 Agent。
触发方式
| 方式 | 操作 | 说明 |
|---|---|---|
| 手动调用 | 在聊天中输入 /skill-name |
直接执行技能指令 |
| Agent判断 | 根据 description 自动判断 | 类似 Apply Intelligently 规则 |
| 搜索调用 | 输入 / 后搜索 |
显示所有可用技能列表 |
Antigravity 技能激活
当 Agent 执行任务时,会根据 SKILL.md 的 description 判断是否需要使用该技能。你也可以通过 view_file 工具主动查看技能文件来激活它。
激活流程
- 将技能文件夹放入
.agent/skills/ - 确保包含
SKILL.md文件 - Agent 根据任务上下文自动加载
SKILL.md 标准格式
---
name: code-review
description: 代码审查技能。当用户请求review、audit、检查代码质量时使用。
---
# Code Review Skill
## When to Use
- 用户请求代码审查
- PR 合并前检查
- 代码质量评估
## Review Checklist
1. **正确性**: 代码是否按预期工作?
2. **边界情况**: 错误条件是否处理?
3. **风格**: 是否符合项目规范?
4. **性能**: 有无明显低效?
## Output Format
提供逐行注释,使用 markdown 格式输出。
技能目录结构
.agent/skills/my-skill/
├── SKILL.md # 主指令文件 (必需)
├── scripts/ # 辅助脚本 (可选)
│ └── helper.py
├── examples/ # 参考实现 (可选)
│ └── sample.ts
└── resources/ # 模板资源 (可选)
└── template.md
子智能体 (Subagents)
Subagents 允许将复杂任务委派给专业化助手,每个子代理在独立上下文中运行。
三工具对比
| 特性 | Cursor | Copilot | Antigravity |
|---|---|---|---|
| 名称 | Subagents | Custom Agents | Browser Subagent |
| 配置位置 | 内置 | .github/agents/*.md |
内置 |
| 并行执行 | 支持 | 不支持 | 不支持 |
| 上下文隔离 | 独立窗口 | 独立 | 浏览器隔离 |
Copilot Custom Agent 配置
.github/agents/*.md)是可 @提及的专业角色,
与规则系统中的 AGENTS.md(项目指令文件)完全不同。
详见第一章 Copilot 指令详解中的辨析表格。
---
name: test-specialist
description: 专门编写和优化测试用例
---
You are a testing specialist focused on:
- Writing comprehensive unit tests
- Improving test coverage
- Optimizing test performance
Always use Jest with TypeScript.
Follow AAA pattern: Arrange, Act, Assert.
Antigravity Browser Subagent 触发详解
| 工具 | 触发方式 | 调用语法 |
|---|---|---|
| Cursor | Agent 自动决定是否启动 Subagent | 无需手动调用,处理复杂任务时自动分配 |
| Copilot | 在 Chat 中 @ 提及 | @agent-name 你的请求 |
| Antigravity | Agent 自动调用 browser_subagent 工具 | 当需要浏览器操作时自动触发 |
Copilot Custom Agent 调用示例
1. 创建 Agent 文件
---
name: doc-writer
description: 专门编写技术文档和 README
---
You are a documentation specialist.
## Responsibilities
- Write clear README files
- Create API documentation
- Generate usage examples
## Style Guidelines
- Use headings for structure
- Include code examples
- Write concise explanations
2. 在 Chat 中调用
@doc-writer 请为这个项目生成 README.md
Cursor Subagent 使用场景
- 代码库分析: 将不同模块分配给多个 Subagent 并行分析
- 测试生成: 主 Agent 继续对话,Subagent 后台生成测试
- 文档生成: 保持上下文隔离,不污染主对话窗口
智能体提及 (Mentions)
三工具 @ 引用对比
| 引用类型 | Cursor | Copilot | Antigravity |
|---|---|---|---|
| 文件 | @file |
#file:path |
@filename |
| 代码库 | @codebase |
@workspace |
自动索引 |
| 文档 | @docs |
@github |
通过MCP |
| 网页 | @web |
不支持 | 通过MCP |
| 规则 | @rule-name |
不支持 | @rule-name |
模型上下文协议 (MCP)
MCP (Model Context Protocol) 允许 AI Agent 连接外部工具和数据源。
配置方式对比
| 特性 | Cursor | Copilot | Antigravity |
|---|---|---|---|
| 项目配置 | .cursor/mcp.json |
.vscode/mcp.json |
mcp_config.json |
| 全局配置 | ~/.cursor/mcp.json |
settings.json 或 GitHub.com 设置 |
MCP Store |
| 一键安装 | 不支持 | 不支持 | MCP Store |
Cursor MCP 配置
项目级配置
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"POSTGRES_URL": "postgresql://user:pass@localhost:5432/db"
}
}
}
}
全局配置
在 ~/.cursor/mcp.json 中配置,对所有项目生效。
Copilot MCP 配置
VS Code 项目级配置
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "ghp_xxx"
}
}
}
}
VS Code 全局配置
在 settings.json 中添加 MCP 配置,或通过 GitHub.com 仓库设置界面配置。
Antigravity MCP Store
支持的一键安装服务:
- GitHub
- Firebase
- Supabase
- Neon
- MongoDB
- Redis
- Notion
- Linear
- Figma
- Stripe
- BigQuery
- Prisma