实用指南:每位开发者都应保存的常用AI智能体提示语
《实用笔记》操作指南:每位开发者都应保存的有用AI智能体提示语,以及适用于采用该模式的团队的合同、校验规则和可直接插入的代码模板。
不必再从头输入相同的提示语。这里有一个经过实际检验的库,可助力您的日常工作流程。
代码审查与质量
深度代码审查
You are a senior software engineer doing a thorough code review.
Review the following code for:
- Correctness and logic errors
- Edge cases that aren't handled
- Security vulnerabilities (injection, auth issues, data exposure)
- Performance problems (N+1 queries, unnecessary loops, memory leaks)
- Readability and naming clarity
- Missing or misleading commentsFor each issue, state: the problem, why it matters, and a concrete fix.
Don't mention things that are fine. Only flag real issues.Code:
[PASTE CODE HERE]
用橡皮鸭法排查隐蔽错误
I have a bug I can't figure out. I'll describe what I expect to happen and what's actually happening. Ask me clarifying questions one at a time to help me find the root cause. Don't guess the answer yet — walk me through it.
Expected behavior: [DESCRIBE]
Actual behavior: [DESCRIBE]
What I've already tried: [DESCRIBE]Relevant code:
[PASTE CODE HERE]
找出性能瓶颈
Analyze this code for performance issues. Focus on:
- Time complexity of key operations
- Unnecessary re-computation or redundant work
- Memory allocation patterns
- Any blocking operations in an async context
- Database query efficiency (if applicable)
Suggest specific optimizations with expected impact. Show before/after where relevant.Language/framework: [e.g., Node.js / PostgreSQL]
Code:
[PASTE CODE HERE]
编写与优化代码
在“编写与优化代码”阶段,应在修改代码之前明确输入内容、该步骤的负责人以及完成标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 配置信息应置于应用程序代码之外。环境文件、密钥存储以及功能标志应集中存放,以便操作人员无需查看整个系统结构即可进行审核。 当下一步操作是编写代码或调用工具时,优先使用具有模式验证的结构化输出,而非自由形式的文字描述。
根据需求文档实现功能
在“实现功能”阶段,应在修改代码之前明确输入参数、该步骤的负责人以及完成标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 需同时记录正常流程和异常恢复流程。重试机制、人工审核环节以及错误处理都是产品本身的组成部分,而非后续需要补充的内容。 当下一步操作是编写代码或调用工具时,应优先使用具有结构化格式且经过模式验证的输出,而非自由形式的文字描述。
Implement the following feature in [LANGUAGE/FRAMEWORK].
Requirements:
- [REQUIREMENT 1]
- [REQUIREMENT 2]
- [REQUIREMENT 3]Constraints:
- Must integrate with: [EXISTING SYSTEM OR PATTERN]
- Must handle errors by: [e.g., throwing custom errors / returning Result types]
- Must be testable in isolation (no hidden dependencies)Do not add features beyond what's listed. Add inline comments only where the logic is non-obvious.
在不改变功能行为的前提下优化代码可读性
为提升可读性而进行的重构无需分阶段进行,应在修改代码之前明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 相比冗长的脚本,更应采用小型且可测试的单元。当某个步骤失败时,故障原因应指向单一责任模块,而非复杂的流程链。 若后续步骤为代码或工具调用,相比自由形式的文本,更应使用具有结构化格式且经过模式验证的输出。
Refactor the following code to improve readability. Rules:
- Do NOT change behavior or external API
- Rename variables and functions to be self-documenting
- Break up functions longer than 20 lines if it improves clarity
- Remove clever one-liners that sacrifice readability for brevity
- Add a brief comment above any function whose purpose isn't obvious from its name
Show the refactored version with a short explanation of the key changes made.Code:
[PASTE CODE HERE]
将回调式代码转换为 async/await
若要将回调式代码转换为阶段化处理,需在修改代码之前明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 应将此阶段视为输入与已验证输出之间的契约。为相关成果命名,定义成功判定标准,并拒绝默许的半完成状态。 当下一步操作为代码编写或工具调用时,优先采用具有架构验证的结构化输出,而非自由形式的文本描述。
Convert the following callback-based Node.js code to use async/await with proper error handling. Preserve all logic exactly. Use try/catch blocks. If the original uses EventEmitters or streams that can't be straightforwardly promisified, flag them and suggest an approach.
Code:
[PASTE CODE HERE]
根据描述编写工具函数
在“编写实用函数”阶段,应在修改代码之前明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。应在功能结果旁记录执行时间以及令牌或查询成本。提前显示成本信息,可避免在从演示环境切换到共享环境时出现意外费用。当下一步操作是编写代码或调用工具时,优先选择具有架构验证的结构化输出,而非自由形式的文本。
Write a [LANGUAGE] utility function that:
- Does: [DESCRIBE WHAT IT SHOULD DO]
- Input: [DESCRIBE INPUT TYPE AND SHAPE]
- Output: [DESCRIBE OUTPUT TYPE AND SHAPE]
- Edge cases to handle: [LIST THEM, e.g., empty arrays, null values, negative numbers]
Include TypeScript types if applicable. Include 3–5 usage examples as comments below the function.
测试
在测试阶段,应在修改代码之前明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。 配置信息应置于应用程序代码之外。环境文件、密钥存储以及功能开关应集中存放于一个位置,以便操作人员无需查看整个系统结构即可进行审核。 当下一步操作为代码编写或工具调用时,应优先使用具有架构验证的结构化输出,而非自由形式的文本描述。
生成全面的单元测试
在“生成全面单元测试”阶段,修改代码之前需明确输入参数、该步骤的负责人以及结束标准。操作人员应能够从已知的检查点重新运行该步骤,而无需猜测隐藏状态。需同时记录正常流程与异常恢复流程。重试机制、人工审核环节以及错误处理都是产品功能的一部分,而非后续需要补充的内容。
Write unit tests for the following function using [JEST / VITEST / MOCHA / etc.].
Cover:
- The happy path
- All documented edge cases
- Invalid inputs (null, undefined, wrong types, out-of-range values)
- Any error conditions the function is supposed to throwUse descriptive test names that read as plain English. Group related tests with describe blocks. Mock external dependencies.Function to test:
[PASTE FUNCTION HERE]
为 API 路由编写集成测试
Write integration tests for this Express route using supertest and Jest.
Test:
- Successful response (correct status code and response shape)
- Validation errors (missing or invalid fields)
- Authentication/authorization failures
- Resource not found
- Any side effects (e.g., email sent, DB record created)Mock the database and any external services. Use beforeEach/afterEach for setup and teardown.Route handler:
[PASTE CODE HERE]
生成测试数据/固定装置
Generate realistic test fixtures for the following data model. Create:
- 1 valid "happy path" example
- 1 example at boundary values (min/max lengths, edge dates, zero amounts)
- 1 example that should fail validation and why
Format as [JSON / TypeScript const / JS object]. Add a comment on each fixture explaining what scenario it represents.Data model / schema:
[PASTE SCHEMA HERE]
调试与诊断
解读晦涩的错误信息
I'm getting this error in my [LANGUAGE/FRAMEWORK] application. Explain:
1. What exactly this error means in plain English
2. The most common causes, ranked by likelihood
3. Step-by-step how to diagnose which cause applies to my situation
4. The fix for each cause
Error:
[PASTE FULL ERROR AND STACK TRACE HERE]Context (what I was doing when it happened):
[DESCRIBE]
诊断内存泄漏问题
Help me diagnose a memory leak in my Node.js application.
Symptoms: [e.g., heap grows steadily under load, never GC'd, crashes after ~2 hours]
Environment: Node.js [VERSION], [FRAMEWORK]
What I've already checked: [LIST]Here are the relevant parts of the code:
[PASTE CODE]Walk me through:
1. What patterns in this code are likely culprits
2. How to confirm the leak with heap snapshots or --inspect
3. The fix
理解陌生的代码
Explain this code to me as if I'm a competent developer but unfamiliar with this codebase/library.
Tell me:
- What it does at a high level (1–2 sentences)
- What each major section does
- Any non-obvious patterns or idioms being used and why
- What I'd need to understand before safely modifying itCode:
[PASTE CODE HERE]
架构与设计
设计系统组件
I need to design [COMPONENT NAME] for a [TYPE OF APPLICATION].
Context:
- Scale: [e.g., ~10k requests/day, 1M users]
- Existing stack: [e.g., Node.js, PostgreSQL, Redis, deployed on AWS]
- Key constraints: [e.g., must be horizontally scalable, strong consistency required]Give me:
1. A high-level design with the main components and how they interact
2. The data model (tables or document schemas)
3. The API surface (endpoints or function signatures)
4. Where the hard problems are and how you'd approach them
5. What you'd defer to a v2
评审架构决策
I'm deciding between two approaches for [PROBLEM].
Option A: [DESCRIBE]
Option B: [DESCRIBE]My context:
- Team size: [N developers]
- Expected scale: [DESCRIBE]
- Existing infrastructure: [DESCRIBE]
- Main concerns: [e.g., operational complexity, cost, latency]Compare them honestly. Don't hedge — give me a recommendation and explain the trade-offs I'd be accepting.
设计数据库模式
Design a PostgreSQL schema for the following domain.
Domain description:
[DESCRIBE YOUR DATA AND RELATIONSHIPS]Requirements:
- [e.g., support multi-tenancy]
- [e.g., soft deletes]
- [e.g., audit log of all changes]
- [e.g., efficient queries for X and Y access patterns]Output:
- CREATE TABLE statements with constraints and indexes
- Brief explanation of key design decisions
- Any denormalization choices and why
文档编写
为项目撰写README文件
Write a README.md for the following project.
Project name: [NAME]
What it does: [DESCRIBE]
Tech stack: [LIST]
Target audience: [e.g., internal devs, open source contributors, end users]Include sections for: overview, prerequisites, installation, usage with examples, environment variables, running tests, and contributing. Use a practical, no-fluff tone. Don't add sections that would be empty.
为函数或模块编写文档
Write JSDoc / docstring documentation for the following code.
Include:
- A one-sentence summary of what it does
- @param tags with types and descriptions for every parameter
- @returns with type and description
- @throws for any errors it can raise
- A usage example in @exampleBe precise about types. If a parameter has constraints (e.g., must be positive, must be ISO 8601), document that.Code:
[PASTE CODE HERE]
撰写技术设计文档(TDD)
Write a technical design document for the following feature.
Feature: [NAME AND BRIEF DESCRIPTION]
Author: [YOUR NAME]
Status: DraftSections to include:
1. Problem statement — what problem this solves and for whom
2. Goals and non-goals
3. Proposed solution — high-level design
4. Detailed design — data models, API changes, key logic
5. Alternatives considered and why they were rejected
6. Open questions
7. Security and privacy considerations
8. Rollout planContext to incorporate:
[PASTE ANY CONTEXT — TICKETS, DISCUSSIONS, EXISTING CODE]
Git与工作流
撰写有意义的提交信息
Write a commit message for the following change. Follow the Conventional Commits format (type(scope): description). Add a body paragraph explaining *why* the change was made, not just what changed. Keep the subject line under 72 characters.
Changes made:
[PASTE DIFF OR DESCRIBE THE CHANGE]
撰写拉取请求描述
Write a pull request description for the following change.
Include:
- What this PR does (2–3 sentences)
- Why it's being done (the problem or requirement it addresses)
- How to test it manually
- Any risks or areas that need careful review
- Links to related issues or tickets: [LIST]Changes:
[PASTE DIFF SUMMARY OR DESCRIBE KEY CHANGES]
为非技术领域的利益相关者总结拉取请求内容
Summarize the following code changes for a non-technical stakeholder. Avoid jargon. Focus on what changes from the user's perspective, what risk (if any) it introduces, and when it will be available.
Keep it under 5 sentences.Changes:
[PASTE PR DESCRIPTION OR DIFF SUMMARY]
学习与探索
通过实际例子解释概念
Explain [CONCEPT] to me. I'm a [junior/mid/senior] developer familiar with [RELEVANT BACKGROUND].
Use a concrete, practical example — not a toy one. Show me code I'd actually write in a real project. After the example, explain the underlying mechanism in plain language. Then tell me: when should I use this, and when should I avoid it?
找出关于某个主题你还不知道的内容
I know the basics of [TOPIC]. List 10 things about [TOPIC] that intermediate developers often don't know but should. For each one, give a one-paragraph explanation and a practical example of why it matters.
为技术面试主题做准备
I have an interview coming up and I want to study [TOPIC] deeply.
Give me:
1. The 10 most important concepts to understand
2. For each concept: a clear explanation, a code example, and a common interview question about it
3. The 3 questions most likely to trip up mid-level candidates on this topic, with ideal answers