AgentSkillsCN

code

实现功能、修复缺陷、重构代码,并编写单元测试与集成测试。当被要求“实现”、“修复缺陷”、“重构”、“添加功能”、“编写测试”、“增加测试覆盖率”或“更新代码”时使用。

SKILL.md
--- frontmatter
name: code
description: Implements features, fixes bugs, refactors code, and writes unit and integration tests. Use when asked to "implement", "fix a bug", "refactor", "add a feature", "write tests", "add test coverage", or "update code".

Quick Start

  • Implements features and fixes bugs based on requirements
  • Writes unit tests and integration tests for implemented code
  • Follows existing project conventions and quality standards
  • Reports blockers and ambiguities to orchestrator — does NOT guess

Workflow

  1. Understand the requirement — read relevant existing code first
  2. Plan the approach — identify files to modify, edge cases, dependencies
  3. Implement — make changes following existing project patterns
  4. Verify — run through the completion checklist below
  5. Report — summarize what was done and any concerns

Example: Adding Error Handling to an API Endpoint

code
Requirement: Add proper error handling to the /users/:id endpoint

Step 1 — Read existing code:
  Read src/routes/users.ts and src/middleware/errorHandler.ts
  Identified: Project uses custom AppError class with status codes

Step 2 — Plan:
  - Wrap handler in try/catch
  - Return 404 for missing user (not generic 500)
  - Validate ID parameter format before DB query
  - Add unit test for each error case

Step 3 — Implement:
  Edit src/routes/users.ts:
    - Add ID format validation (return 400 for non-numeric)
    - Add null check after DB query (return 404)
    - Wrap in try/catch using existing AppError pattern
  Edit src/routes/__tests__/users.test.ts:
    - Add test: "returns 400 for non-numeric ID"
    - Add test: "returns 404 for nonexistent user"

Step 4 — Verify:
  ✓ No syntax errors
  ✓ Edge cases handled (bad ID, missing user, DB error)
  ✓ Error handling uses project's AppError pattern
  ✓ No hardcoded values
  ✓ Tests cover error paths

Error Handling

Error TypeAction
Build/Compile failureInclude error output, attempt fix up to 2x
File conflictsStop and report to orchestrator
Unclear requirementsReport ambiguity, do NOT guess
Missing dependenciesReport which dependencies are needed
Large files (>500 LOC)Warn orchestrator before modifying
Large files (>1000 LOC)Report as blocker, recommend splitting

Completion Checklist

Before reporting completion, verify ALL of the following:

  • Code compiles/parses without syntax errors
  • Edge cases are handled appropriately
  • Error handling is in place (no silent failures)
  • Inline comments explain complex logic
  • Code follows existing project conventions (naming, patterns, structure)
  • No hardcoded credentials or secrets
  • Tests cover the new/changed behavior (when applicable)

Constraints (Never Allowed)

  • Git config modifications
  • Hardcoded credentials or secrets
  • Silent failures (every error must be caught and handled or propagated)
  • Using sed/perl/awk/tr for multi-file replacements (use grep + edit)
  • Guessing when requirements are unclear — ask instead