Prompt 设计最佳实践
Prompt 部分是 Skill 的「大脑」— 它定义了 Skill 的行为模式、工作流程和输出标准。
结构模板
markdown
# Skill Name
## When to Use
- Scenario A: when the user wants X
- Scenario B: when the user mentions Y
## When NOT to Use
- Don't use for Z — use [other-skill] instead
## Workflow
1. First, understand the user's goal by asking...
2. Then, analyze the code by...
3. Finally, produce output in the following format...
## Output Format
- Section 1: ...
- Section 2: ...
- Always include a summary
## Key Principles
- Principle 1: ...
- Principle 2: ...
## Common Mistakes to Avoid
- Mistake A: ... instead do ...
- Mistake B: ...
## Notes
- Edge case X: handle by...
- Limitation Y: this Skill cannot...设计原则
1. 明确边界
好:
markdown
## When to Use
- Code review for correctness, readability, and maintainability
- General-purpose review of any code change
## When NOT to Use
- Security-specific audits — use /security-review instead
- Architecture-level review — use /improve-codebase-architecture不好:
markdown
Use this Skill to review code.2. 分步骤工作流
好:
markdown
## Workflow
1. Read the changed files to understand the scope
2. Check for: logic errors, edge cases, type safety
3. Check for: security vulnerabilities (XSS, injection, etc.)
4. Check for: performance concerns (N+1, memory leaks)
5. Check for: readability and naming quality
6. Produce a structured review with severity tags不好:
markdown
Review the code and report issues.3. 指定输出格式
markdown
## Output Format
### Critical (must fix)
- [file:line] Issue description → Suggested fix
### Should Fix
- [file:line] Issue description → Suggested fix
### Nice to Have
- [file:line] Issue description → Suggested fix
### Positive Findings
- What's done well: ...4. 包含反面案例
markdown
## Common Anti-Patterns to Flag
- Catching and ignoring errors silently
- Using `any` type in TypeScript
- Hardcoded credentials or URLs
- Mutating props in React components
- Missing `key` prop in list rendersPrompt 长度指南
| 复杂度 | 长度 | 例子 |
|---|---|---|
| 简单 | 20-50 行 | 格式转换、简单代码生成 |
| 中等 | 50-150 行 | 代码审查、测试生成 |
| 复杂 | 150-300 行 | 安全审查、架构分析 |
超过 300 行考虑把细节放到 resources/ 中。
测试你的 Prompt
- 触发测试: 用不同说法测试是否能正确触发
- 边界测试: 确认「不该触发」的场景不会误触
- 输出测试: 验证输出格式和内容质量
- 协作测试: 确认与其他 Skill 的组合使用效果