AgentSkillsCN

code-implementer

当用户要求“实现”、“编写代码”、“构建功能”、“创建函数”、“添加功能”、“写这个”、“让这个工作”或需要按照FP、DDD和可测试性模式为Java/Spring Boot或TypeScript/Next.js编写生产代码时,应使用此技能。确保代码遵循函数式核心/命令行界面,正确的不变量,基于Either的错误处理,并且设计为无需模拟即可测试。

SKILL.md
--- frontmatter
name: code-implementer
version: "1.0.0"
description: "This skill should be used when the user asks to 'implement', 'write code', 'build a feature', 'create a function', 'add functionality', 'code this', 'make this work', or needs to write production code for Java/Spring Boot or TypeScript/Next.js following FP, DDD, and testability patterns. Ensures code follows functional core/imperative shell, proper invariants, Either-based error handling, and is designed for testing without mocks."
imports:
  - "../../rules/architecture.md"
  - "../../rules/java-patterns.md"
  - "../../rules/typescript-patterns.md"
  - "../../rules/property-testing.md"

Code Implementer Skill

Expert implementation guidance ensuring code follows FP principles, DDD patterns, and is designed for maximum testability.

This is an IMPLEMENTATION skill - write production code following the architectural patterns in the imported rules. For design decisions and architectural review, use /architecture-tech-lead instead.


Pre-Implementation Checklist

Before writing code, verify:

  • Boundaries clear: Where does I/O happen vs pure logic?
  • Invariants identified: What must always be true?
  • Types designed: Records/sealed types for domain? Discriminated unions?
  • Parse, don't validate: Return validated types? Invalid states unrepresentable?
  • Error handling: Using Either/Result? What errors are possible?
  • Testability: Can business logic be unit tested without mocks?

During Implementation

Structure Code as Functional Core + Imperative Shell

Imperative Shell (thin):

  • Fetches data (DB, APIs)
  • Calls pure functions
  • Persists results
  • Handles I/O errors

Functional Core (where logic lives):

  • Pure functions, no side effects
  • Receives all data as parameters
  • Returns new data, never mutates
  • Trivially unit testable

Apply Type Design

Apply patterns from imported rules:

  • Java: Records, sealed types, pattern matching (see java-patterns.md)
  • TypeScript: Discriminated unions, ts-pattern, Zod (see typescript-patterns.md)

Handle Errors Properly

Use Either/Result for all expected failures (see java-patterns.md for Either examples):

  • Chain operations with flatMap
  • Collect validation errors with Eithers.allFailures()
  • Never throw for expected failures - return typed errors

Post-Implementation Checklist

After writing code, verify:

  • No business logic in shell: All logic in pure functions?
  • Immutability: No mutations? Defensive copies where needed?
  • Invariants enforced: Constructors validate? Invalid states unrepresentable?
  • Error paths typed: Using Either/Result? No hidden throws?
  • Testable without mocks: Can test core logic with plain data?

Implementation Patterns Quick Reference

Data Transformation Flow

code
fetch (I/O) -> transform (pure) -> persist (I/O)

Service Method Structure

code
1. Fetch required data (shell - I/O)
2. Call pure function with data (core - testable)
3. Persist result (shell - I/O)
4. Return result

Invariant Enforcement

code
Constructor validates -> Object always valid -> No defensive checks elsewhere

Error Handling Chain

code
validate -> process -> transform -> (all via flatMap/map)

Test Strategy

For every implementation, consider:

Unit Tests (core logic)

  • Test pure functions with plain data
  • No mocks needed
  • Cover edge cases

Property Tests (invariants)

  • What must ALWAYS be true?
  • Round-trip properties
  • Idempotence where applicable

Integration Tests (shell only)

  • Minimal - just verify I/O works
  • Use real DB/APIs in test containers
  • Don't test business logic here

Quality Standards

  • Complete: Implement full feature, not partial
  • Testable: Every function testable without mocks
  • Typed Errors: Either/Result for all failures
  • Immutable: No mutations without justification
  • Validated: Parse, don't validate - return validated types

Context Awareness

Tailor to detected stack. See imported rules for patterns:

  • Java: java-patterns.md (records, sealed types, Either)
  • TypeScript: typescript-patterns.md (discriminated unions, ts-pattern)
  • Testing: property-testing.md (jqwik patterns)