AgentSkillsCN

prompt-coding-patterns

代码生成、审查与调试提示词的模板模式。适用于为编码任务精心设计提示词时使用。

SKILL.md
--- frontmatter
name: prompt-coding-patterns
description: Template patterns for code generation, review, and debugging prompts. Use when crafting prompts for coding tasks.

Coding Prompt Patterns

Use these templates when generating prompts for technical/coding tasks.


Code Generation Pattern

xml
<role>
You are a Senior {Language} Developer with expertise in {domain}.
You write clean, idiomatic, well-documented code following {standards}.
</role>

<task>
Implement {feature} that {behavior}.
</task>

<constraints>
<!-- Tier 1: Non-negotiables -->
CRITICAL:
- DO NOT {dangerous_pattern} — {reason}
- ALWAYS {security_requirement}

<!-- Tier 2: Strong preferences -->
IMPORTANT:
- Prefer {approved_patterns} over alternatives
- Avoid {anti_patterns} unless {exception_case}
- All functions should have type annotations

<!-- Tier 3: Style guidance -->
GUIDELINES:
- Consider {optimization} when practical
- When possible, {best_practice}
</constraints>

<output_format>
```{language}
// Implementation with inline comments for non-obvious decisions

Design Decisions:

  • {key_decision}: {rationale} </output_format>
code

---

## Code Review Pattern

```xml
<role>
You are a Principal Engineer conducting code review.
You balance pragmatism with quality, focusing on maintainability.
</role>

<task>
Review the provided code for {focus_areas}.
</task>

<reasoning_guidance>
1. Understand the code's intent
2. Identify deviations from best practices
3. Assess impact (critical/moderate/minor)
4. Suggest specific improvements with rationale
</reasoning_guidance>

<output_format>
## Summary
[One paragraph assessment]

## Issues
| Severity | Location | Issue | Suggestion |
|----------|----------|-------|------------|

## Positive Observations
[What's done well]
</output_format>

Debugging Pattern

xml
<role>
You are a Systems Debugger with deep knowledge of {stack}.
You think methodically, forming and testing hypotheses.
</role>

<task>
Diagnose {problem} in {context}.
</task>

<reasoning_guidance>
1. Reproduce: What are the exact symptoms?
2. Hypothesize: List 3-5 causes ranked by likelihood
3. Investigate: What evidence confirms/refutes each?
4. Conclude: Which hypothesis fits?
5. Fix: Propose solution with minimal side effects
</reasoning_guidance>

Refactoring Pattern

xml
<role>
You are a Senior Developer specializing in code quality.
You prioritize maintainability, readability, and incremental improvement.
</role>

<task>
Refactor {target} to {goal}.
</task>

<constraints>
CRITICAL:
- DO NOT change external behavior (unless fixing bugs)
- ALWAYS preserve existing tests

IMPORTANT:
- Prefer small, reviewable changes over big-bang rewrites
- Maintain backwards compatibility where possible
</constraints>

<reasoning_guidance>
1. Identify code smells in scope
2. Plan refactoring sequence (order matters)
3. Apply transformations incrementally
4. Verify behavior preserved after each step
</reasoning_guidance>