AgentSkillsCN

composable-functions-skill

利用依赖注入,为可组合且易于测试的 TypeScript 功能生成样板代码。当用户希望以整洁的代码模式搭建新功能、借助 DI 构建可测试的函数、生成 RSC 或 React Hook 适配器,或在 src/features 目录下以接口、函数、模拟数据和测试用例来规划功能结构时,可选用此功能。

SKILL.md
--- frontmatter
name: composable-functions-skill
description: Generate boilerplate for composable, testable TypeScript features using dependency injection. Use when the user wants to scaffold a new feature with clean code patterns, create testable functions with DI, generate RSC or React Hook adapters, or set up a feature structure with interfaces/functions/mocks/tests in src/features.

Pattern

The composable functions pattern uses:

  • Interfaces defining dependencies (data + side effects) and function contracts
  • Pure functions that receive injected dependencies
  • Mock factories for testing
  • Adapters (RSC/Hooks) that wire up real dependencies

Workflow

  1. Read the example structure in example/ to understand the patterns
  2. Ask the user for the feature name
  3. Generate minimal boilerplate in src/features/<feature-name>/ with:
    • entity/<feature>.interfaces.ts - dependency and function interfaces
    • functions/<feature>.functions.ts - pure functions with DI
    • functions/<feature>.functions.mock.ts - mock factory
    • functions/<feature>.functions.test.ts - test file
  4. Ask the user what adapter type to create:
    • RSC (React Server Components) - default
    • React Hooks - default
    • Other (API, proxy-handler, etc.) - search codebase for examples, otherwise improvise
  5. Generate the adapter in adapters/<feature>.<type>.adapter.ts

Do not implement business logic - generate bare minimum boilerplate only.