一个 GitHub Copilot Agent Prompt 用于更安全的更改

发布: (2025年12月2日 GMT+8 15:51)
4 min read
原文: Dev.to

Source: Dev.to

Cover image for One GitHub Copilot Agent Prompt for Safer Changes

核心思路

描述你想要的更改,然后在提示的最后加上这一行:

Before you do any changes, show me your detailed step by step implementation plan for approval.

先让代理给出计划——还不进行编辑,只是一个清晰的步骤列表。审阅计划后,你可以确认、完善或拒绝它。

为什么这样有帮助

“先计划”模式可以提升工作流:

  • 在编辑触及代码前明确意图
  • 更容易审查,因为你看到的是步骤列表而不是原始 diff
  • 降低半成品重构的风险

代理从“开火即忘”转变为“提出方案,然后执行”,让你掌控范围和方向。

小示例

提示

I want to extract logging concerns from this C# class into a separate service.

Steps:
1. Identify all logging calls.
2. Introduce an IAppLogger interface.
3. Inject IAppLogger into the constructor.
4. Replace direct logging calls with the new abstraction.

Before you do any changes, show me your detailed step by step implementation plan for approval.

代理可能给出的计划

Step 1: Scan the class and list all logging calls, grouped by log level.
Step 2: Propose the IAppLogger interface signature which covers the current usage.
Step 3: Add the new interface and a concrete implementation in a Logging folder.
Step 4: Update the target class constructor to accept IAppLogger through dependency injection.
Step 5: Replace direct logging calls with calls to IAppLogger.
Step 6: Update the composition root to register the concrete logger.
Step 7: Propose unit test updates for the new abstraction.

随后你可以发现缺失的点或风险,例如:

  • 未提及结构化日志
  • 未提及日志上下文
  • 未提及其他类中的横切关注点

回复

Good start.

Extend the plan with:
- Structured logging support
- Log context (correlation id, user id)
- Follow‑up steps for other classes using logging in this project

Then show me the updated plan. Do not change any code yet.

只有当计划看起来稳固时,你才让代理执行它。

提示变体

安全与审查

Before you do any changes, show me your detailed step by step implementation plan for approval. Wait for my confirmation before you start.

配对编程

Before you do any changes, propose a detailed step by step implementation plan. Ask me questions if anything in my request is unclear.

大规模重构

Before you do any changes, outline a detailed step by step implementation plan with milestones. Mark risky steps explicitly.

通用结构

  • 请求详细计划
  • 要求有序的步骤
  • 在编辑前必须暂停
  • 留出提问空间

日常使用小贴士

  • 保持变更请求简短且聚焦
  • 要求使用编号步骤
  • 对较大的改动请求风险提示
  • 在计划中要求列出测试影响
  • 将你最喜欢的提示变体保存为代码片段或笔记
  • 在团队中使用相同模式以保持一致性

何时使用此模式最有效

这行单句在以下情形下表现最佳:

  • 重构遗留代码
  • 修改共享库
  • 更改公共 API
  • 在不熟悉的代码库中工作
  • 与团队成员在聊天或 PR 中审查计划

在这些场景中,你可以在任何编辑发生前获得对工作范围、风险和测试影响的共享视图,然后决定让代理走多远。你是在引导代理,而不是被代理驱动。

Back to Blog

相关文章

阅读更多 »

切换账户

@blink_c5eb0afe3975https://dev.to/blink_c5eb0afe3975 正如大家所知,我正重新开始记录我的进展,我认为最好在一个不同的…

Strands 代理 + Agent Core AWS

入门指南:Amazon Bedrock AgentCore 目录 - 前置要求(requisitos‑previos) - 工具包安装(instalación‑del‑toolkit) - 创建…