三、第一个项目:从想法到代码的完整流程

2 阅读7分钟

你已安装Superpowers,准备开始实际使用。这篇文章通过一个完整的Todo应用案例,展示Superpowers的每个阶段。

我们不是看概念,而是看真实的对话和行动。

场景设定:我们要构建什么

目标:一个简单的Todo应用。

功能:

  • 添加任务
  • 删除任务
  • 标记任务完成

技术栈:Node.js + Express + 内存存储(简单起见,不用数据库)

阶段一:Brainstorming(需求探索)

我启动Claude Code,输入:

我想创建一个Todo应用

AI没有直接开始写代码。它说:

I notice this is about creating a feature. I need to use the brainstorming skill first.

Let me understand your project context. I'll check files and recent commits.

AI读取了当前目录(空的),然后开始问问题:

Before we start designing, I have some questions:

1. What is this project for?
   - Personal use?
   - Part of a larger application?
   - A demo/learning project?

2. Who will use this Todo app?
   - Just you?
   - A team?
   - End users of a product?

3. What are the success criteria?
   - Basic CRUD functionality?
   - Specific performance requirements?
   - Integration with other systems?

这是brainstorming的核心:AI不猜测,而是问。

我回答:

1. A demo project to learn Superpowers workflow
2. Just me for testing
3. Basic CRUD: add, delete, mark complete. No extra features.

AI继续问:

Good. A few more questions:

4. What's the API style?
   - REST API?
   - CLI interface?
   - Web UI?

5. How should tasks be stored?
   - In-memory (simple, but lost on restart)?
   - File-based (persists)?
   - Database?

6. Any specific format for tasks?
   - Just text?
   - Priority levels?
   - Due dates?

我回答:

4. REST API (I want to test with HTTP requests)
5. In-memory is fine for this demo
6. Just text. No priority, no dates. Keep it simple.

AI形成了一个初步设计:

Based on our conversation, I'll present the design in sections.

## Architecture

- Node.js + Express
- REST API endpoints:
  - POST /todos - create task
  - GET /todos - list all tasks
  - DELETE /todos/:id - delete task
  - PUT /todos/:id/complete - mark complete
- In-memory storage: array of task objects
- Task object: { id, text, completed }

Does this architecture look right so far?

我说:

Yes, continue.

AI继续:

## Components

- server.js: Express app and route definitions
- todoStore.js: In-memory storage and CRUD operations
- routes/todos.js: Route handlers (optional, can be in server.js for simplicity)

## Testing

- Jest for testing
- Test coverage for all CRUD operations
- Integration tests for API endpoints

Does this look right?

我说:

Yes, but keep routes in server.js for simplicity.

AI调整并继续:

Adjusted. One file: server.js contains all.

## Error Handling

- 400 for invalid input (empty text)
- 404 for non-existent task ID
- 500 for unexpected errors

Does this look right?

我说:

Yes.

AI完成设计:

Design complete. I'll write the spec document.

Writing to docs/superpowers/specs/2026-04-28-todo-app-design.md...

AI写了一个spec文件,然后进行自检:

Spec written. Let me review it for placeholders, contradictions, and ambiguity.

Self-review passed. No placeholders, internally consistent, scope focused, no ambiguity.

Please review the spec file and let me know if you want to make changes before we proceed.

我打开spec文件,确认内容正确,回复:

Looks good. Proceed.

阶段二:Writing Plans(实现计划)

AI说:

I'll use the writing-plans skill to create an implementation plan.

Breaking the spec into bite-sized tasks (each 2-5 minutes)...

AI生成了计划:

# Implementation Plan

## Task 1: Setup Project
- Create package.json with Express and Jest
- Create server.js skeleton
- Verify: npm install succeeds, npm test runs (no tests yet)

## Task 2: Implement TodoStore
- Write test for addTodo
- Watch test fail
- Implement addTodo function
- Watch test pass
- Write test for deleteTodo
- Watch test fail
- Implement deleteTodo
- Watch test pass
- Write test for getTodos
- Watch test fail
- Implement getTodos
- Watch test pass
- Write test for markComplete
- Watch test fail
- Implement markComplete
- Watch test pass
- Verify: all tests pass

## Task 3: Implement API Endpoints
- Write test for POST /todos
- Watch test fail
- Implement POST /todos endpoint
- Watch test pass
- Write test for GET /todos
- Watch test fail
- Implement GET /todos endpoint
- Watch test pass
- Write test for DELETE /todos/:id
- Watch test fail
- Implement DELETE /todos/:id endpoint
- Watch test pass
- Write test for PUT /todos/:id/complete
- Watch test fail
- Implement PUT /todos/:id/complete endpoint
- Watch test pass
- Verify: all API tests pass

## Task 4: Error Handling
- Write test for POST with empty text (expect 400)
- Watch test fail
- Add validation for empty text
- Watch test pass
- Write test for DELETE non-existent ID (expect 404)
- Watch test fail
- Add 404 handling
- Watch test pass
- Verify: all error tests pass

## Task 5: Final Verification
- Run all tests
- Verify: 100% coverage
- Manual test with curl
- Verify: all endpoints work

AI问:

Plan created. Does this look good?

我说:

Yes, proceed.

阶段三:Worktree(隔离工作空间)

AI说:

I'll use the using-git-worktrees skill to create an isolated workspace.

Creating worktree on a new branch...

AI执行:

git worktree add .claude/worktrees/todo-app -b todo-app

然后:

Worktree created at .claude/worktrees/todo-app on branch todo-app.

Setting up project in worktree...
Verifying clean test baseline (no tests yet, baseline clean)...

You can observe my work in the worktree directory, or I can report here.

我选择观察,但主要让AI自主工作。

阶段四:Subagent-driven Development(执行)

AI说:

I'll use the subagent-driven-development skill to execute the plan.

Each task will be handled by an independent subagent with review loops.

任务1:Setup Project

AI dispatch子代理:

Dispatching subagent for Task 1: Setup Project...

Subagent report:
- Created package.json with Express and Jest
- npm install succeeded
- Created empty server.js
- npm test runs (no tests, baseline clean)

Self-review: Completed all items in task spec.

审查者(另一个子代理)检查:

Spec compliance review:
- package.json created ✓
- Express and Jest dependencies ✓
- server.js skeleton ✓
- npm install succeeds ✓
- npm test runs ✓

No issues. Proceed to code quality review.

Code quality review:
- package.json format correct ✓
- server.js minimal skeleton ✓

No issues. Task 1 complete.

任务2:Implement TodoStore

这个任务展示了TDD流程:

Dispatching subagent for Task 2: Implement TodoStore...

Subagent report (detailed):

RED phase - addTodo:
- Wrote test: test('addTodo creates task with id')
- Ran test: FAIL - addTodo not defined
- Failure message correct: "ReferenceError: addTodo is not defined"
- Fails because feature missing 

GREEN phase - addTodo:
- Implemented minimal addTodo function in todoStore.js
- Ran test: PASS

REFACTOR: Not needed, minimal implementation

RED phase - deleteTodo:
- Wrote test: test('deleteTodo removes task')
- Ran test: FAIL - deleteTodo not defined
- Failure message correct 

GREEN phase - deleteTodo:
- Implemented deleteTodo
- Ran test: PASS

... (similar for getTodos and markComplete)

Self-review: All tests pass. Coverage: 100% for todoStore.js.

审查者检查:

Spec compliance review:
- Tests written before code ✓
- Tests watched failing ✓
- Minimal implementations ✓
- All tests pass ✓

Checking TDD compliance for each function:
- addTodo: test first, fail verified, code minimal ✓
- deleteTodo: test first, fail verified, code minimal ✓
- getTodos: test first, fail verified, code minimal ✓
- markComplete: test first, fail verified, code minimal ✓

No issues.

Code quality review:
- Code clear and minimal ✓
- No extra features added ✓
- Tests cover edge cases ✓

No issues. Task 2 complete.

我观察到:AI严格执行TDD。每个函数都先写测试,运行看失败,再写代码。

任务3和4:API和错误处理

类似流程,每个endpoint都经过TDD循环。

审查者检查spec compliance:确认实现了所有endpoint,确认错误处理正确。

任务5:Final Verification

Dispatching subagent for Task 5: Final Verification...

Subagent report:
- All tests pass (15 tests)
- Coverage: 100%
- Manual test with curl:
  - POST /todos: created task with id 1 
  - GET /todos: returned [ { id: 1, text: "test", completed: false } ] 
  - PUT /todos/1/complete: returned updated task 
  - DELETE /todos/1: returned 204 
  - GET /todos: returned [] 

All verification passed.

阶段五:Finishing(完成)

AI说:

All tasks complete. Using finishing-a-development-branch skill.

Verifying tests: all pass.
Verifying git status: all changes committed.

Options:
1. Merge to main
2. Create PR
3. Keep branch for later
4. Discard work

What would you like to do?

我选择:

Create PR.

AI执行:

Pushing branch todo-app to origin...
Creating PR...

PR URL: https://github.com/your-repo/pull/1

Cleaning up worktree...

AI删除了worktree,保持工作目录干净。

我观察到的AI行为

整个过程大约50分钟。我的参与主要在:

  • Brainstorming阶段:回答问题,批准spec
  • Plan阶段:批准计划
  • PR阶段:选择创建PR

其余时间AI自主工作。我看到:

  • AI严格执行TDD:没有一次跳过测试
  • AI自我检查:每个子代理报告前都自检
  • 审查循环:审查者独立验证,不信任实现者报告
  • 没有添加额外功能:只做了spec里定义的

时间对比

传统方式(没有Superpowers):

  • 直接写代码:10分钟
  • 手动测试:5分钟
  • 发现bug修复:5分钟
  • 添加测试(后补):10分钟
  • 总计:30分钟,但不确定覆盖

Superpowers方式:

  • Brainstorming:10分钟
  • Plan:5分钟
  • Execution:35分钟
  • 总计:50分钟,但确定覆盖

多花了20分钟,但结果是:

  • 有spec文档,可以回顾
  • 有完整测试,覆盖率100%
  • 没有猜测,知道每个函数为什么存在
  • 可以安全重构

总结

Superpowers的完整流程:

  1. Brainstorming:问答探索需求,形成spec,你批准
  2. Writing Plans:分解为任务,你批准
  3. Worktree:隔离环境,干净基线
  4. Subagent-driven Development:AI自主执行,TDD循环,审查验证
  5. Finishing:验证测试,选择merge/PR/discard

你的角色:参与关键决策点(设计批准、计划批准、PR选择),观察AI自主工作。

AI的角色:执行方法论,严格执行TDD,自我检查,独立审查。

下一步

下一篇《TDD实战:AI助手的测试驱动开发强制执行》将深入Superpowers的TDD技能:

  • RED-GREEN-REFACTOR流程详解
  • 为什么"看测试失败"是必要的
  • AI如何抵抗"跳过测试"的压力