Project Guidelines
【免费下载链接】Mastering-GitHub-Copilot-for-Paired-ProgrammingA multi-module course teaching everything you need to know about using GitHub Copilot as an AI Peer Programming resource.项目地址: https://gitcode.com/GitHub_Trending/ma/Mastering-GitHub-Copilot-for-Paired-Programming
Technology Stack
- Node.js with Express
- SQLite via better-sqlite3
- EJS templates for server-rendered HTML
- xUnit-style tests with Jest
Code Style
- Use async/await — never raw callbacks or
.then()chains - Follow the existing error handling pattern in
src/errorHandler.js - All new routes must be added to
src/routes.jsfollowing the existing pattern - Use 2-space indentation
Testing
- Every new route must have a corresponding test in
tests/ - Use supertest for HTTP integration tests
Security
- Never log user-provided input directly
- Validate all request parameters before database access
3. 提交该文件。此后该仓库中所有 Copilot Coding Agent 会话都会自动遵循这些指令。 > **提示**:你也可以在组织设置中定义**组织级**自定义指令,作用域覆盖该组织的所有仓库。 自定义指令不仅指导 Coding Agent 的编码行为,也会指导 **Copilot 代码评审**——评审时会依据你定义的约定与模式检查代码。 ### 5.2 评审并迭代 Copilot 生成的 PR 当 Copilot 完成任务后,它会打开一个 Pull Request 并请求你评审: 1. 进入仓库的 **Pull Requests** 标签页; 2. 打开 Copilot 创建的 PR(带有 Copilot 作者徽标); 3. 评审变更。PR 描述通常包含:变更内容与原因的摘要、对原始 Issue 的引用、自动化验证产生的安全扫描结果; 4. 留下要求修改的评审意见,例如:The delete confirmation modal is a good start, but please also add an accessible aria-label to the confirmation button.
5. 提交评审后,Copilot 会采纳你的反馈、向同一分支推送新提交,并重新请求你的评审。 **治理要点**:请求 Copilot 创建 PR 的用户**不能审批该 PR**(以强制独立评审);Copilot 也不能将自己的 PR 标记为 "Ready for review" 或自行合并。 ### 5.3 让 Copilot 评审你的 PR Copilot 还可以作为你自有 PR 的第一道评审者,在人审之前先行把关: 1. 打开你编写的 PR; 2. 在右侧 **Reviewers** 面板点击齿轮图标; 3. 从评审者列表中选择 **Copilot**; 4. 数秒内 Copilot 就会在 diff 上留下行内评论,指出 bug、低效之处与改进建议; 5. 使用行内评论控件采纳或忽略每条建议。 ## 六、高级定制:自定义 Agent、MCP、Hooks 与 Memory ### 6.1 自定义 Agent 配置 **自定义 Agent** 是你用 Markdown 文件一次性定义的特殊化 Copilot 版本,每个配置编码特定的人格、工具集与行为。自定义 Agent 也可以在组织级定义(存放于 `.github-private` 仓库),使组织内所有仓库均可使用。 **示例 1:文档 Agent**——创建 `.github/agents/documentation-agent.md`: ```markdown --- name: documentation-agent description: Specialist for maintaining and improving project documentation --- You are a technical documentation specialist. Your scope is limited to documentation files only — README.md, docs/, and inline code comments. Do not modify source code logic. Follow these guidelines: - Structure READMEs with: Overview, Installation, Usage, API Reference, Contributing - Use clear, concise language targeted at developers unfamiliar with the project - Add code examples for every API endpoint documented - Use relative links for internal files - Add alt text to all images - Ensure all headings are in sentence case示例 2:测试 Agent——创建.github/agents/test-agent.md:
--- name: test-agent description: Specialist for writing comprehensive test coverage using Jest --- You are a testing specialist focused exclusively on writing and improving tests. Do not modify application source code — only test files. Guidelines: - Use Jest with supertest for HTTP route tests - Write both happy-path and error-path tests for every function - Aim for 80%+ line coverage on any file you touch - Use descriptive test names that explain the scenario being tested - Mock external dependencies using jest.mock()提交这两个文件后,当你从 agents 面板或 Issue 指派任务时,就可以选择特定的自定义 Agent 来执行。
6.2 MCP 服务器:接入外部数据源与工具
MCP 服务器为 Coding Agent 提供访问外部数据源与工具的能力(如项目管理系统、内部文档、数据库),这些资源 Agent 原本无法触及。对于组织级或企业级自定义 Agent,Agent 定义由中心化管理(不仅限于仓库中的.github/agents/),管理员可以在配置文件的 YAML frontmatter 中直接定义 MCP 服务器,从而集中管控 Agent 可访问的外部工具。
在仓库中创建.github/mcp.json:
{ "mcpServers": { "github": { "type": "github", "tools": ["list_issues", "search_code", "get_pull_request"] } } }其中,默认的 GitHub MCP 服务器已预先配置,赋予 Agent 访问仓库 Issue、历史 Pull Request 与代码搜索的能力,使其回答基于真实项目上下文。若要添加第三方 MCP 服务器(例如 Jira、Azure DevOps 或其他第三方服务),按照 MCP 集成指南把服务器配置加入.github/mcp.json即可。
本仓库中另有独立的 Integrate MCP with Copilot 模块,可深入学习 MCP 的完整集成实践。
6.3 Hooks:生命周期自动化
Hooks允许你在 Agent 会话的特定节点执行自定义 shell 命令,可用于增加校验、自定义 lint、安全扫描或通知工作流。可用的 Hook 节点:
pre-run—— Copilot 开始工作之前;post-run—— Copilot 完成工作之后。
创建.github/copilot/hooks.yaml:
hooks: post-run: - name: Run custom linter run: npm run lint -- --max-warnings 0 - name: Check for TODO comments run: | if grep -r "TODO" src/; then echo "Warning: TODO comments found in src/" fi如果某个 hook 以非零状态退出,Copilot 会看到输出,并在结束会话前尝试解决该问题。
6.4 Copilot Memory(公开预览)
Copilot Memory允许 Coding Agent 跨会话持久化它学到的仓库事实——随时间积累知识,无需你重复提供上下文。
启用方法:
- 进入 GitHub Copilot 设置页面;
- 启用Copilot Memory(适用于 Pro 与 Pro+ 计划);
- 会话完成后,Copilot 会写入类似 "This project uses better-sqlite3, not the default sqlite3 package." 的记忆条目。
七、安全、SDLC 集成与 AI 模型选择
7.1 内置安全防护
Copilot 的每个会话在打开 PR 前都会自动执行安全验证:
| 防护机制 | 作用 |
|---|---|
| CodeQL 分析 | 扫描生成代码中的安全漏洞 |
| 依赖漏洞检查 | 对照 GitHub Advisory Database 检查新增依赖是否存在 High/Critical CVE |
| Secret scanning | 检测硬编码的 API 密钥、令牌与机密信息 |
| 防火墙受限环境 | Copilot 的开发环境仅允许访问白名单内的互联网资源 |
| 分支限制 | Copilot 只能推送到copilot/分支,绝不允许推送到main或master |
所有安全检查的细节都会显示在会话日志中。注意:这些内置检查需要GitHub Advanced Security(GHAS)许可证。
7.2 使用安全活动规模化修复漏洞
安全活动(Security campaigns)让你批量将安全告警指派给 Coding Agent 进行修复:
- 进入仓库Security标签页 →Code scanning alerts;
- 若有未处理的告警,点击左侧导航的Campaigns(适用于启用了 GitHub Advanced Security 的组织);
- 创建新活动,选择相关告警,并将Copilot设为负责人;
- Copilot 会逐个处理告警,为每个修复创建一个 Pull Request。
提示:对于没有活跃告警的仓库,也可以手动进入某个 code scanning 告警,选择 "Assign to Copilot" 触发该流程。
7.3 治理与合规模型
| 治理规则 | 效果 |
|---|---|
| 仅写入权限用户可触发 Agent | 防止未授权的代码变更 |
| Copilot 不能审批自己的 PR | 强制独立的人工评审 |
| 提交由请求者共同署名 | 提供完整的归属与合规追踪 |
| PR 工作流需审批后才运行 | Actions 在写入权限用户点击 "Approve and run workflows" 前不会运行 |
| 支持内容排除(content exclusions) | 配置 Copilot 不应访问的文件 |
7.4 通过 GitHub CLI 集成
GitHub CLI 方式要求 v2.80.0 或更高版本(用gh --version检查):
# 列出最近的 Agent 会话 gh agent-task list # 查看与仓库中 PR #45 关联的会话 gh agent-task view --repo YOUR-ORG/YOUR-REPO 45 # 查看完整会话日志 gh agent-task view --repo YOUR-ORG/YOUR-REPO 45 --log # 流式跟踪 Copilot 工作时的实时日志 gh agent-task view --repo YOUR-ORG/YOUR-REPO 45 --log --follow【免费下载链接】Mastering-GitHub-Copilot-for-Paired-ProgrammingA multi-module course teaching everything you need to know about using GitHub Copilot as an AI Peer Programming resource.项目地址: https://gitcode.com/GitHub_Trending/ma/Mastering-GitHub-Copilot-for-Paired-Programming
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考