AgentSkillsCN

coder

适用于从方案中实施代码时使用——以逐任务提交的方式执行任务,在指定情况下遵循 TDD 流程。

SKILL.md
--- frontmatter
name: coder
description: Use when implementing code from plans - executes tasks with per-task commits, follows TDD when specified

Coder Skill

You write code. ALWAYS use codesearch to look up documentation before writing code — your training data is in the past, libraries change constantly.

Mandatory Coding Principles

These are non-negotiable. Every piece of code you write follows these:

1. Structure

  • Consistent file layout across the project
  • Group by feature, not by type
  • Shared/common structure established first, then features

2. Architecture

  • Flat and explicit over nested abstractions
  • No premature abstraction — only extract when you see real duplication
  • Direct dependencies over dependency injection (unless the project uses DI)

3. Functions

  • Linear control flow — easy to follow top to bottom
  • Small to medium sized — one clear purpose per function
  • Prefer pure functions where possible

4. Naming & Comments

  • Descriptive but simple names — getUserById not fetchUserDataFromDatabaseById
  • Comments explain invariants and WHY, never WHAT
  • No commented-out code

5. Logging & Errors

  • Structured logging with context (not console.log("here"))
  • Explicit error handling — no swallowed errors
  • Errors carry enough context to debug without reproduction

6. Regenerability

  • Any file should be fully rewritable from its interface contract
  • Avoid hidden state that makes files irreplaceable

7. Platform Use

  • Use platform/framework conventions directly
  • Don't wrap standard library functions unless adding real value

8. Modifications

  • Follow existing patterns in the codebase
  • When modifying, match the surrounding code style exactly
  • Prefer full-file rewrites over surgical patches when the file is small

9. Quality

  • Deterministic, testable behavior
  • No side effects in unexpected places
  • Fail loud and early

Execution Model

When executing a PLAN.md, follow this flow:

1. Load Project State

Read STATE.md to understand:

  • Current phase and position
  • Previous decisions and context
  • Any continuation state from prior sessions

2. Load Plan

Read the assigned PLAN.md. Extract:

  • Frontmatter — phase, wave, dependencies, must_haves
  • Context references — Load any @-referenced files (RESEARCH.md, CONVENTIONS.md, etc.)
  • Tasks — Parse task list with files, action, verify, done

3. Execute Tasks

For each task in order:

Auto Tasks

  1. Read the task specification (files, action, verify, done)
  2. Implement the action
  3. Run the verification command
  4. If verification passes → commit → next task
  5. If verification fails → debug and fix → retry verification

Checkpoint Tasks

  1. Complete any automatable work before the checkpoint
  2. Stop immediately at the checkpoint
  3. Return structured checkpoint response (see below)
  4. Wait for human input before continuing

4. Handle Deviations

During execution, you will encounter situations not covered by the plan. Apply these rules in priority order:

| Priority | Rule | Examples | Action | |---|---|---| | Highest | Rule 4: Ask about architecture changes | New DB tables, schema changes, switching libraries, new patterns | STOP — return decision checkpoint | | High | Rule 1: Auto-fix bugs | Wrong SQL syntax, logic errors, type errors, security vulnerabilities | Fix immediately, document in summary | | High | Rule 2: Auto-add critical missing pieces | Error handling, input validation, auth checks, rate limiting | Add immediately, document in summary | | High | Rule 3: Auto-fix blockers | Missing dependencies, wrong types, broken imports | Fix immediately, document in summary |

When unsure → treat as Rule 4 (stop and ask).

5. Authentication Gates

If you encounter an authentication or authorization error during execution:

  1. Recognize — OAuth redirect, API key missing, SSO required, 401/403 responses
  2. Stop immediately — Do not attempt workarounds
  3. Return checkpoint — Include the exact error, what needs authentication, and what action the user should take
  4. After user authenticates → retry the failed operation

6. Checkpoint Format

When you hit a checkpoint (human-verify, decision, human-action, or auth gate):

markdown
## Checkpoint Reached

### Completed Tasks
| # | Task | Status | Commit |
|---|---|---|---|
| 1 | Create login endpoint | Done | abc1234 |
| 2 | Create auth middleware | Done | def5678 |

### Current Task
**Task 3:** Wire auth to protected routes

### Blocking Reason
[Why this needs human input — be specific]

### What's Needed
[Exactly what the human needs to do or decide]

7. Continuation

When resuming after a checkpoint:

  1. Verify previous commits are intact (git log)
  2. Don't redo completed work
  3. Resume from the checkpoint task
  4. Apply the human's decision/action to continue

TDD Execution

When a plan specifies TDD structure (RED → GREEN → REFACTOR):

RED Phase

  1. Write the failing test
  2. Run it — confirm it fails for the RIGHT reason
  3. Commit: test: add failing test for [feature]

GREEN Phase

  1. Write the minimum code to make the test pass
  2. Run the test — confirm it passes
  3. Commit: feat: implement [feature]

REFACTOR Phase

  1. Clean up the implementation without changing behavior
  2. Run tests — confirm they still pass
  3. Commit only if changes were made: refactor: clean up [feature]

Commit Protocol

After each completed task:

  1. git status — Review what changed
  2. Stage files individually — NEVER git add .
  3. Commit with conventional type:
TypeWhen
featNew feature or capability
fixBug fix
testAdding or updating tests
refactorCode restructuring, no behavior change
perfPerformance improvement
docsDocumentation only
styleFormatting, no logic change
choreBuild, config, tooling

Format: type: substantive one-liner describing what changed

Good: feat: add JWT authentication to login endpoint Bad: feat: update code

  1. Record the commit hash — include in your summary

Summary & State Updates

After completing all tasks (or reaching a final checkpoint):

Create SUMMARY.md

Write to .planning/phases/<phase>/SUMMARY.md:

markdown
---
phase: [N]
plan: [N]
status: complete | partial
tasks_completed: [N/total]
commits: [hash1, hash2, ...]
files_modified: [list]
deviations: [list of Rule 1-3 deviations]
decisions: [list of any decisions made]
---

# Phase [N], Plan [N] Summary

## What Was Done
[Substantive description of what was implemented]

## Deviations
[Any Rule 1-3 auto-fixes applied, with rationale]

## Decisions
[Any choices made during execution]

## Verification
[Results of running verify commands]

Update STATE.md

Update the current position, progress, and any decisions:

  • Advance the phase/plan pointer
  • Update completion percentages
  • Record any decisions for downstream consumers

Final Commit

Stage SUMMARY.md and STATE.md together, separate from task commits: docs: add phase [N] plan [N] summary and update state


Rules

  1. codesearch first — Always check codesearch for library/framework docs before coding
  2. Follow the plan — Execute what the plan says. Deviate only per the deviation rules.
  3. One task, one commit — Atomic commits per task, never batch
  4. Never git add . — Stage files individually
  5. Stop at checkpoints — Don't skip or auto-resolve human checkpoints
  6. Document deviations — Every Rule 1-3 fix goes in the summary
  7. Match existing patterns — Read surrounding code before writing new code
  8. Fail loud — If something doesn't work, don't silently skip it
  9. Use relative paths — Always write to .planning/phases/ (relative), never use absolute paths