跳转到主要内容
可将这些模板作为编写提示时的起点。请根据你的具体需求,自定义方括号中的内容 [像这样]

Bug 修复

修复特定 Bug

修复 `[describe the bug behavior]` 的问题。

复现步骤:
1. `[Step 1]`
2. `[Step 2]`
3. `[Step 3]`

预期行为:`[what should happen]`
实际行为:`[what actually happens]`

请:
1. 在 `[relevant file/directory]` 中排查根本原因
2. 实现针对根本原因的修复方案
3. 添加回归测试,防止该问题再次出现
4. 运行现有测试套件,确保没有引入回归问题

排查生产环境问题

用户在生产环境中反馈了 `[describe the issue]` 问题。

请执行以下操作:
1. 使用 `[Sentry/DataDog/Log monitoring tool]` MCP 拉取近期错误日志和堆栈跟踪
2. 定位问题根本原因
3. 进行修复
4. 添加适当的错误处理,以防止类似问题再次发生
5. 创建回归测试
6. 在 PR 描述中附上监控/告警链接

功能实现

新增 API 端点

创建一个新的 API 端点 `[endpoint path]`,用于 `[describe what it does]`。

要求:
- 方法:`[GET/POST/PUT/DELETE]`
- 请求体:`[describe request structure]`
- 响应格式:`[describe response structure]`
- 身份验证:`[describe auth requirements]`

请:
1. 参考现有的 `[similar endpoint file]` 了解实现模式
2. 按照现有规范实现该端点
3. 添加输入验证和错误处理
4. 为新端点编写单元测试
5. 如适用,更新 API 文档
6. 运行测试套件以确保所有测试均通过

新增 UI 组件

在 `[file/location]` 中添加一个新的 `[component type]` 组件。

要求:
- 组件名称:`[ComponentName]`
- Props:`[list props and their types]`
- 功能:`[describe what it should do]`
- 样式:以 `[existing component/library]` 为参考

请:
1. 按照现有模式创建组件
2. 实现所需功能
3. 添加正确的 TypeScript 类型
4. 调整样式以符合我们的设计系统
5. 为组件添加单元测试
6. 将其集成到 `[parent component/page]` 中
7. 启动开发服务器进行手动测试

根据设计实现功能

从此设计文件实现 `[feature name]` 功能:`[Figma/link to design]`

重点关注 `[specific frame/section]` 框架。

要求:
- 使用 `[component library path]` 中的现有组件
- 遵循 `[design system file]` 中的样式规范
- 确保在 `[breakpoint 1]` 和 `[breakpoint 2]` 断点下实现响应式设计

请完成以下事项:
1. 按照设计规范实现该功能
2. 尽可能复用现有组件
3. 在桌面端(1440px)和移动端(375px)宽度下进行测试
4. 截图验证实现效果与设计稿一致
5. 在视觉效果与设计稿完全匹配之前,请勿提交 PR

代码重构

重构模块

Refactor the `[module/file name]` to improve `[specific aspect: maintainability/performance/readability]`.

Current issues:
- `[Issue 1]`
- `[Issue 2]`
- `[Issue 3]`

Requirements:
- Keep all existing functionality intact
- Follow the patterns in `[reference file]`
- Improve `[specific metric: code complexity/performance]`

Please:
1. Analyze the current implementation
2. Refactor following best practices
3. Ensure all existing tests still pass
4. Add tests for any new functions introduced
5. Run the full test suite
6. Measure and report performance improvements if applicable

迁移到新模式

将 `[file/directory]` 转换为使用 `[new pattern/library/framework]`。

参考:`[link to documentation or example file]`

要求:
- 保留所有现有功能
- 遵循 `[example file]` 中的规范
- 更新所有依赖代码

请:
1. 查阅文档和示例
2. 逐步转换代码
3. 更新导入项和依赖
4. 确保所有测试通过
5. 运行 `[build command]` 以验证无错误
6. 手动测试功能

测试

补充测试覆盖

为 `[file/module/function]` 添加全面的测试覆盖。

当前覆盖率:`[current coverage %]`
目标覆盖率:`[target coverage %]`

请:
1. 分析现有代码以识别边界用例
2. 为所有公共方法编写单元测试
3. 如适用,添加集成测试
4. 参考 `[existing test file]` 中的测试模式
5. 运行 `npm test -- --coverage` 并验证覆盖率是否达到目标
6. 确保所有测试通过

调试未通过的测试

修复 `[test file or directory]` 中失败的测试。

测试失败情况:
- `[Test name 1]`:`[error message]`
- `[Test name 2]`:`[error message]`

请执行以下操作:
1. 排查测试失败的原因
2. 判断需要修复测试本身还是实现代码
3. 修复根本原因
4. 确保测试套件中的所有测试均通过
5. 运行完整测试套件,检查是否存在回归问题

文档

编写模块文档

为 `[file/module]` 添加完整的文档。

请:
1. 为所有公共函数添加 JSDoc/TypeDoc 注释
2. 记录参数、返回值和异常
3. 为复杂函数添加使用示例
4. 如果这是新模块,请创建 README
5. 遵循 `[style guide link]` 中的文档风格指南
6. 如适用,更新主 API 文档

更新 API 文档

更新 `[endpoint/function]` 的 API 文档。

所做更改:
- `[Change 1]`
- `[Change 2]`

请执行以下操作:
1. 更新 `[OpenAPI/Swagger]` 规范
2. 更新所有内联代码注释
3. 如行为有变更,请添加使用示例
4. 更新 `[documentation file]`
5. 验证文档可成功构建

性能优化

优化数据库查询

Optimize the database queries in `[file/module]`.

Performance issues:
- `[Specific query]` is slow (takes `[time]`)
- `[Specific operation]` causes N+1 queries

Please:
1. Analyze the query execution plans
2. Add appropriate indexes to `[table/column]`
3. Refactor queries to use joins instead of N+1
4. Benchmark before and after performance
5. Ensure all tests still pass
6. Document the performance improvements

优化前端性能

优化 `[component/page]` 的性能。

性能问题:
- 初始加载时间过慢
- 打包体积过大
- 不必要的重新渲染

请执行以下操作:
1. 使用 `[bundle analyzer]` 分析打包体积
2. 对 `[large module]` 实现代码分割
3. 在适当位置添加记忆化处理
4. 优化图片和静态资源
5. 对首屏以下的组件实现懒加载
6. 使用 Lighthouse 衡量性能提升效果
7. 确保功能保持完整

安全性

修复安全漏洞

修复在 `[file/module]` 中发现的安全漏洞。

漏洞类型:`[e.g., SQL injection, XSS, CSRF]`
严重程度:`[High/Medium/Low]`

请执行以下操作:
1. 查阅安全公告:`[link to advisory]`
2. 实施建议的修复方案
3. 添加输入验证和数据清理
4. 添加安全测试以防止回归
5. 运行安全审计:`[audit command]`
6. 确保不存在其他类似漏洞

添加安全标头

Add security headers to the `[application/API]`.

Required headers:
- `[Header 1]`: `[value]`
- `[Header 2]`: `[value]`
- `[Header 3]`: `[value]`

Please:
1. Configure the headers in `[config file]`
2. Test that headers are set correctly using `[tool/method]`
3. Ensure existing functionality is not broken
4. Document the security improvements

迁移与升级

升级依赖

将 `[package/library]` 从版本 `[old version]` 升级至版本 `[new version]`。

请执行以下步骤:
1. 查阅变更日志以了解破坏性变更:`[changelog link]`
2. 更新 `[package.json/requirements.txt]` 中的依赖项
3. 更新所有已弃用的 API 用法
4. 如适用,运行迁移脚本:`[migration command]`
5. 运行所有测试以确保兼容性
6. 手动测试应用
7. 如 API 有变更,更新相关文档

迁移至新服务

从 `[old service]` 迁移到 `[new service]`。

参考文档:`[link to new service docs]`

请:
1. 按照文档配置新服务
2. 迁移现有数据/配置
3. 更新所有代码以使用新服务
4. 参考 `[example file]` 了解实现模式
5. 运行集成测试以验证功能
6. 逐步发布并监控是否出现问题
7. 验证完成后停用旧服务

代码评审

审查拉取请求

审查此拉取请求(PR):`[PR link or number]`

重点关注:
- 代码质量与可维护性
- 性能影响
- 安全性考量
- 测试覆盖率
- 文档

请:
1. 审查每个已更改的文件
2. 提出具体、可操作的意见
3. 验证所做更改是否符合 PR 描述
4. 检查边界情况和错误处理
5. 确保测试充分
6. 提供明确的反馈,批准或请求更改

总体目的

调研并实现

我需要使用 `[technology/library]` 实现 `[feature/functionality]`。

请:
1. 研究 `[technology/library]` 的最佳实践
2. 查找并查阅文档:`[expected doc sources]`
3. 如适用,参考开源示例
4. 在实现之前提出方案
5. 按照最佳实践实现解决方案
6. 添加测试和文档
7. 验证其是否按预期运行

调试与修复

Something is wrong with `[feature/component]`.

Symptoms:
- `[Symptom 1]`
- `[Symptom 2]`

Please:
1. Investigate the issue in `[relevant files]`
2. Add logging/debugging statements as needed
3. Identify the root cause
4. Implement a fix
5. Test the fix thoroughly
6. Remove any temporary debugging code
7. Ensure no regressions
专业提示:对于重复性任务,可以考虑用这些模板创建一个 Playbook,方便后续重复使用。