GitHub · AI/ML 项目

GitHub Copilot 应用中的斜杠命令指南

A guide to slash commands in the GitHub Copilot app

二〇二六年八月六日 · 英文原文

GitHub Copilot 应用引入斜杠命令(slash commands),扩展了CLI中的概念,提供会话管理、项目导航和工作流控制快捷方式。文章介绍了`/plan`(规划任务)、`/spar`(压力测试方案)、`/autopilot`(自动实现)、`/rubber-duck`(独立模型审查)和`/create-canvas`(创建交互界面)及`/orchestrate`(跨仓库协调)等命令,并附使用示例。原文发布于GitHub Blog。

如果你在 GitHub Copilot CLI 中使用过斜杠命令,你已经知道一个简单的 / 能有多强大。在 GitHub Copilot 应用中,斜杠命令进一步扩展了这一概念,为你提供管理会话、导航项目和自定义 Copilot 工作流的快捷方式。

什么是斜杠命令?

斜杠命令是你直接在 GitHub Copilot 应用的聊天输入框中输入的文字快捷方式。输入 / 后,自动补全菜单会出现,显示当前上下文中可用的命令。这是一个小字符,却潜力巨大,为帮助你以新方式使用 Copilot 的快捷方式打开了大门。

如果你是从 CLI 过来的,这里的关键区别是:CLI 斜杠命令围绕终端优先的工作流设计。添加目录、设置工作目录和管理终端访问等操作都通过命令完成。这很合理,因为 CLI 位于你的终端内,没有可视化界面。

💡 提示:如果你在 Copilot CLI 中使用过斜杠命令,你会注意到一些熟悉的命令。像 /clear/model 在两个地方都可用。但 GitHub Copilot 应用特有的命令是为桌面应用提供的多会话工作流量身定制的。

另一方面,应用提供了管理上下文的可视化界面。像 /add-dir/cwd 这样的文件访问命令不需要,因为应用会自动管理项目上下文。应用斜杠命令更侧重于工作流。你可以在会话之间导航、管理项目,并控制 agent 的工作方式。

为什么要使用斜杠命令?

斜杠命令可能看起来像简单的快捷方式,但它们可以改变你与 Copilot 交互的方式。它们帮助你更快地行动、保持专注,并快速访问所需的工作流。无需翻找选项或打断思路去寻找正确的工具,你可以输入一个命令并继续前进。一个 / 就能打开斜杠命令列表,帮助你更快地行动、探索新想法,并充分利用应用。

让我们看看 GitHub Copilot 应用中可用的一些斜杠命令,以及它们如何融入你的日常工作流。

写代码之前,先做 /plan

好代码始于好计划。/plan 帮助你在开始写代码之前分解任务,思考你的方法,识别潜在挑战,并决定下一步需要做什么。它还会将会话切换到 Plan 模式,你也可以从聊天输入框的 Mode 下拉菜单中选择。

规划新功能。在进入实现之前分解新功能想法。让 Copilot 识别文件、组件和依赖项,这样你就有更清晰的路径。

/plan I need to add two-factor authentication to our application. Help me break down the work involved, identify what files need to change, and outline an implementation approach.

准备大型重构。在动代码之前规划复杂的更改。发现潜在风险,并制定增量方法以安全地进行大型更改。

/plan We want to refactor our notification system code to make it easier to support new channels like push notifications. Help me understand the changes needed and create an incremental migration plan.

分类和修复 bug。如果你知道有问题但不确定从哪里开始,/plan 可以帮助你探索可能的原因,并概述诊断和解决问题的步骤。

/plan Users are reporting that our checkout flow randomly fails after payment processing. Help me investigate possible causes and create a plan to diagnose and fix the issue.

/spar 让 Copilot 唱反调

有时验证一个想法的最佳方式是挑战它。/spar 就像那个举手问“我们有没有想过这出问题时会发生什么?”的队友。它通过让 Copilot 质疑你的假设,并在你确定解决方案之前指出潜在风险或权衡,帮助你压力测试你的方法。

以下是一些使用方式:

验证架构选择。提出你使用 Redis 做缓存的计划,让 Copilot 质疑你的失效策略、可扩展性,或者是否有其他方法更适合你的工作负载。

/spar I'm planning to use Redis as a caching layer for our product API. Challenge my approach and point out any scalability or consistency concerns I may have missed.

比较实现选项。让 Copilot 根据你的应用需求,辩论 REST 与 GraphQL、同步与异步处理的优缺点。

/spar Help me decide between REST and GraphQL for a customer-facing API. Ask questions, challenge my assumptions, and recommend which approach fits best for an app with mobile clients.

审查迁移计划。在开始之前,让 Copilot 识别数据库迁移或基础设施变更中的边界情况、风险或部署问题。

/spar I'm migrating our database to a new managed service with minimal downtime. Poke holes in my migration plan and identify any risks or edge cases I should account for.

挑战性能优化。分享你正在考虑的优化方案,让 Copilot 指出隐藏的瓶颈、意外的副作用或更简单的替代方案。

/spar I'm planning to lazy load most of the components on my site to improve initial load time. Critique my approach and tell me where it could hurt user experience or introduce unnecessary complexity.

/autopilot 接管方向盘

一旦你有了 /plan,下一步就是把想法变成可工作的代码。/autopilot 帮助你完成实现、进行更改,并根据需要迭代。无需管理每个单独的步骤,给 Copilot 一个目标,让它完成完成任务所需的步骤。它还会将会话切换到 Autopilot 模式,你也可以从聊天输入框的 Mode 下拉菜单中选择。

实现新功能。移交任务,让 Copilot 完成实现步骤。

/autopilot Add support for exporting user reports as CSV files. Identify the files that need changes, implement the feature, and update any relevant tests.

完成更大的维护任务。使用 /autopilot 处理需要多个步骤的任务,例如更新依赖项、重构代码或改进文档。

/autopilot Update this project to the latest version of React. Identify breaking changes, update the code where needed, and make sure the test suite passes.

/rubber-duck 聊一聊

我从个人经验中学到,和你的猫聊事情并不总是有帮助。它们的倾听技巧充其量值得怀疑,而它们的调试建议通常以坐在我键盘上或咬我电线结束。/rubber-duck 给你更好的东西:一双新的眼睛。它使用不同的模型独立审查你的工作,帮助发现盲点、质疑假设,并捕捉你的主要模型可能遗漏的问题。它对于复杂重构、架构决策、迁移计划,或任何你想在前进之前获得第二意见的时候特别有用。

获取计划的第二意见。在开始实现复杂功能之前,让一个不同的模型独立审查你的计划,并指出假设、缺失步骤或潜在风险。

/rubber-duck Review the implementation plan we've created for adding two-factor authentication. Identify any blind spots, edge cases, or risks that we may have overlooked.

审查大型重构。在做出重大更改后,让 /rubber-duck 批评方法,并指出任何可以简化、改进或以不同方式处理的地方。

/rubber-duck Review the refactoring we've completed for the notification system. Look for architectural concerns, unnecessary complexity, or areas that could be improved before I open a pull request.

验证迁移策略。在推出复杂迁移之前,使用第二个模型独立评估你的方法,并识别部署或可靠性问题。

/rubber-duck Review our database migration plan and implementation. Point out any blind spots, rollback concerns, or edge cases we should address before deployment.

/create-canvas 将对话变成交互式体验

并非每个问题都最适合通过聊天窗口解决。/create-canvas 让你直接从与 Copilot 的对话中创建交互式界面。无需在长聊天中处理信息,你可以将其变成可视化、仪表板或自定义工作流,并与之交互。例如:

/create-canvas Create an interactive diagram showing how services in this application connect.
/create-canvas Create an issue triage board that lets me review and categorize open issues.

有关创建 canvas 的更多信息和示例,请查看我们的博客文章。

当一个任务变成多个,使用 /orchestrate

并非每个任务都适合单一工作流。有时你需要在多个仓库中进行更改,或同时处理几个相关任务。/orchestrate 通过将较大的工作分解为可以并行推进的较小任务,帮助你协调跨会话和仓库的工作。

协调跨仓库的更改。当一个功能涉及多个代码库时,/orchestrate 可以帮助你跟踪工作并协调每个仓库的更新。

/orchestrate I need to add support for a new authentication flow across our frontend, backend, and shared repositories. Help me break down the work and coordinate the changes needed in each codebase.

管理并行开发任务。对于较大的项目,Copilot 可以将工作划分为专注的任务,使多个部分可以同时推进。

/orchestrate Prepare this feature for release. Identify the work needed for implementation, testing, documentation, and deployment, then help coordinate each task.

你的下一个工作流从 / 开始

你不需要记住任何命令就能开始。选择几个符合你工作方式的斜杠命令,然后在此基础上构建。自动补全菜单会帮你处理其余部分。输入 / 开始探索!

你也可以阅读我们的文档,了解更多关于 GitHub Copilot 应用的信息。

在 GitHub Copilot 应用中试用斜杠命令,或查看我们的文档获取可用命令列表。

这篇关于 GitHub Copilot 应用中斜杠命令指南的文章最初出现在 GitHub Blog 上。

译自 GitHub · AI/ML 项目 · 录于 二〇二六年八月六日