AgentSkillsCN

aico-frontend-implement

采用 TDD 方法执行前端实现。在编码前仔细阅读所有约束文件,先编写失败的测试,每完成一步都进行验证。 当满足以下条件时,可使用此技能: - 用户要求“实现这个”、“实现计划”、“开始实现”、“执行计划”; - 已经准备好实施计划,需要将其付诸实践; - 根据 /frontend.plan 的输出执行各项步骤; - 用户说“开始编码”、“编写代码”、“开始实施”; - 用户要求“使用 TDD”、“先写测试”、“测试驱动”来编写前端代码; - 用户要求“编写测试”、“添加测试”、“创建测试”; - 修复 UI Bug 时(先编写一个能重现 Bug 的失败测试)。 TDD 铁律:没有先通过失败的测试,绝不允许提交生产代码。 TDD 循环:红色(编写失败的测试)→ 验证失败 → 绿色(极简代码)→ 验证通过 → 重构。 前提条件: - 必须在 docs/reference/frontend/tasks/ 中拥有任务文件(若不存在,可先使用 /frontend.tasks); - 编写任何代码之前,务必阅读 design-system.md、constraints.md 以及设计规范。 流程:检查任务文件 → 阅读约束 → TDD 循环(红色→绿色→重构)→ 逐个验证 → 测试 → 更新任务状态 → 通知 PM。

SKILL.md
--- frontmatter
name: aico-frontend-implement
description: |
  Execute frontend implementation with TDD. Read all constraint files before coding, write failing test first, verify after each step.

  Use this skill when:
  - User asks to "implement this", "implement the plan", "start implementation", "execute plan"
  - Have an implementation plan ready and need to execute it
  - Executing steps from /frontend.plan output
  - User says "start coding", "write the code", "begin implementation"
  - User asks to "use TDD", "write test first", "test-driven" for frontend code
  - User asks to "write tests", "add tests", "create tests"
  - Fixing UI bugs (write failing test that reproduces bug first)

  TDD Iron Law: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
  TDD Cycle: RED (write failing test) → Verify fails → GREEN (minimal code) → Verify passes → REFACTOR

  Prerequisites:
  - MUST have task file in docs/reference/frontend/tasks/ (use /frontend.tasks first if not exists)
  - MUST read design-system.md, constraints.md, and design spec before writing any code.
  Flow: Check Task File → Read Constraints → TDD Cycle (RED→GREEN→REFACTOR) → Verify Each → Test → Update Task Status → Notify PM

Implement

Language Configuration

Before generating any content, check aico.json in project root for language field to determine the output language. If not set, default to English.

Process

  1. Check task file EXISTS (MANDATORY):

    • Look for docs/reference/frontend/tasks/{story-id}.md
    • If NOT exists → STOP and tell user: "Please run /frontend.tasks first to break down the story"
    • If exists → proceed to step 1
  2. Read constraints FIRST (before any code):

    • docs/reference/frontend/design-system.md - Colors, typography, spacing
    • docs/reference/frontend/constraints.md - Tech stack, patterns
    • docs/reference/frontend/designs/{name}.md - Component specs
  3. Execute each step in order:

    • Run the action
    • Run verification command
    • If fail → fix before proceeding
    • If pass → continue to next step
  4. After all steps:

    • Run unit tests
    • Run build check
  5. Update task status in docs/reference/frontend/tasks/{story}.md

  6. Notify PM for acceptance - Notify PM to verify (PM checks all related tasks and updates Story status)

  7. Commit changes (user decides when to commit)

Execution Flow

code
Check Task File → Read Constraints → Execute Steps → Verify Each → Test → Mark Complete → Notify PM → Commit

Step Execution Rules

Rule 1: Follow Constraints Exactly

tsx
// ❌ Wrong: Ignore design system
<button className="bg-blue-500 text-white">

// ✅ Right: Use design tokens
<button className="bg-primary text-primary-foreground">

Rule 2: Verify Before Proceeding

Each step has a Verify section - MUST run it and confirm expected output before moving on.

Rule 3: No Skipping

  • Execute ALL steps in order
  • Do NOT combine steps
  • Do NOT skip verification

Post-Implementation Checklist

  1. Run tests: npm test [component]
  2. Run build: npm run build
  3. Update task status in tasks file
  4. Notify PM: Tell PM frontend tasks are complete, request acceptance
  5. Commit (user decides when): git commit -m "feat([scope]): [description]"

Error Handling

Error TypeAction
TypeScript errorFix type issues, re-verify
Test failureDebug test, fix implementation or test
Build failureCheck imports, fix errors
Constraint violationRe-read constraints, align code

Key Rules

  • ALWAYS read all constraint files before writing any code
  • MUST run verification command for each step
  • ALWAYS run tests before marking task complete
  • MUST update task status in tasks/{story}.md
  • MUST notify PM after completing all tasks (PM handles story verification)
  • Let user decide when to commit

Common Mistakes

  • ❌ Implement without task file → ✅ ALWAYS run /frontend.tasks first to break down story
  • ❌ Skip reading constraints → ✅ ALWAYS read before coding
  • ❌ Skip verification → ✅ Run verify command for each step
  • ❌ Skip tests → ✅ Run tests before marking complete
  • ❌ Forget to update task status → ✅ Update tasks/{story}.md
  • ❌ Directly update story status → ✅ Notify PM, let PM verify and update story

TDD Deep Dive

The TDD Iron Law

code
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

Write code before the test? Delete it. Start over.

Red-Green-Refactor Cycle

code
RED → Verify Fails → GREEN → Verify Passes → REFACTOR → Repeat

1. RED - Write Failing Test

typescript
test('Button shows loading state when clicked', async () => {
  render(<SubmitButton onClick={mockSubmit} />)
  await userEvent.click(screen.getByRole('button'))
  expect(screen.getByRole('button')).toBeDisabled()
  expect(screen.getByTestId('spinner')).toBeInTheDocument()
})

2. Verify RED - Watch It Fail

bash
npm test -- --watch ComponentName

3. GREEN - Write Minimal Code

Write simplest code to pass the test. Don't add features not in test.

4. Verify GREEN - Watch It Pass

5. REFACTOR - Clean Up

Only after green. Keep tests passing.

Testing Library Query Priority

  1. getByRole - accessible by everyone
  2. getByLabelText - form fields
  3. getByText - non-interactive elements
  4. getByTestId - last resort

Test Coverage Requirements

Component TypeRequired Tests
UI ComponentRender, props, variants
FormValidation, submit, error states
InteractiveUser events, callbacks
Data DisplayLoading, error, empty states

TDD Red Flags - STOP and Start Over

  • Code before test
  • Test passes immediately
  • Testing implementation details
  • querySelector everywhere

Iron Law

NO CODE WITHOUT APPROVED PLAN

This rule is non-negotiable. Before writing code:

  1. Task breakdown must exist and be approved
  2. Acceptance criteria must be defined
  3. Dependencies must be identified and available

Rationalization Defense

ExcuseReality
"It's a simple change"Simple changes often have hidden complexity
"I'll document after coding"Post-hoc documentation is always incomplete
"Tests can wait until later"Untested code is broken code
"I know what needs to be done"Assumptions without validation cause bugs