plan-reproducibility.md
6.45 KB
Claude Code 复现指南
把这套 PRD + SDD 喂给一个全新的 Claude Code session,让它从空仓库(仅有 LemonBoss 既有代码)重建整套 DevLoop 系统。本页含:执行 prompt 模板 + manifest 抽取脚本 + 验收清单。
三步法
步骤 ① · 抽取 build-manifest.json
需要 node + cheerio。脚本 ~80 行:
// scripts/extract-manifest.js · NEW
const fs = require('fs');
const path = require('path');
const cheerio = require('cheerio');
const docsDir = path.resolve(__dirname, '../docs/prd/newfunction');
const manifest = {
meta: { source: 'docs/prd/newfunction', prdRev: 'v0.2' },
model: [], view: [], control: [], process: [],
units: [],
};
// 1. 从 sdd-{mvcp}.html 抽 4 象限
for (const mvcp of ['model', 'view', 'control', 'process']) {
const html = fs.readFileSync(path.join(docsDir, `sdd-${mvcp}.html`), 'utf8');
const $ = cheerio.load(html);
$('[data-def-name]').each((_, el) => {
manifest[mvcp].push({
name: $(el).attr('data-def-name'),
path: $(el).find('code.path').first().text() ||
$(el).find('code.path.mono').first().text(),
shape: $(el).find('pre.shape').text() ||
$(el).find('pre.code.shape').text(),
contract: $(el).find('ul.contract li').map((_,li) => $(li).text()).get(),
tests: $(el).find('ul.tests li').map((_,li) => $(li).text()).get(),
});
});
}
// 2. 从 prd-feature-tree.html 抽 Unit 列表(粗)
// 这步实际由 Architect Agent 做 P1 时的拆分;脚本只做最简取出 file tree 中的 Unit id
fs.writeFileSync('build-manifest.json', JSON.stringify(manifest, null, 2));
console.log(`✓ extracted ${manifest.model.length + manifest.view.length + manifest.control.length + manifest.process.length} definitions`);
跑一下:
cd lemonboss
node scripts/extract-manifest.js
# → build-manifest.json (~30KB)
步骤 ② · 复现 Prompt 模板
把以下 prompt 喂给一个全新的 Claude Code session(在空 lemonboss 仓库根目录启动)。
# 复现 prompt · 直接粘到 claude code
我手上有一份 LemonBoss DevLoop 系统的完整 PRD + SDD(HTML 形式),位于
docs/prd/newfunction/ 下,共 41 页。我已用脚本抽出 build-manifest.json。
请你扮演 Architect + Coder + Tester 三个角色,完成以下工作:
【阶段 A · 拆 Unit】
1. 读 docs/prd/newfunction/prd-feature-tree.html,确认 34 个 Unit
2. 读 build-manifest.json,把 MVCP 四象限的定义映射到 Unit
3. 在 data/companies/c-repro/projects/p-init/units.json 落地 DAG
【阶段 B · 实现每个 Unit】
对每个 Unit 顺次:
1. 读对应 Unit 的所有 MVCP 定义(manifest 里的 model/view/control/process)
2. 按 path 字段落盘,按 shape 字段写代码骨架
3. 按 contract 列表实现行为
4. 按 tests 列表写 vitest 用例(后端 supertest + 内存 SQLite,前端 @vue/test-utils)
5. 跑 vitest,红了反思(参考 docs/prd/newfunction/loops-l1.html 的 retryWithReflection
章节),重写直到绿
【阶段 C · 集成】
1. 读 docs/prd/newfunction/sdd-process.html 实现 LoopController.runProject
2. 启动后端 + 前端,cd 到 docs/prd/newfunction,用 docs 自己做 demo 项目跑一遍
3. 注入「contract_mismatch」演示自愈
【约束】
- 严格遵守 docs/prd/newfunction/agents-coder.html 的沙箱规则
- 任何带 JSON body 的 curl 必须先写 /tmp/*.json 再 -d @file
(参见 CLAUDE.md L91-99)
- 不动 server/services/evolution-loop.js(参见 arch-mapping.html PATCH 说明)
- 不动 packages/acp-core/ · core/master-session.js · core/agent-manager.js
【验收】
完成后跑 npm test,所有 vitest 必须通过。然后跑:
curl -X POST http://localhost:3010/api/devloop/projects -d @/tmp/test.json
(/tmp/test.json 单行紧凑:
{"company_id":"c-001","name":"todo","requirement":"做个 TODO API"})
应在 60 秒内看到 prd.html + sdd.html + units.json 三份文档生成。
开始吧。
步骤 ③ · 验收清单
Claude Code 跑完后,人类只需对照以下 12 条逐项检查:
| # | 检查点 | 判定 |
|---|---|---|
| 1 | server/src/core/loop-controller.js 存在且导出 loopController |
✓ require 不报错 |
| 2 | server/services/doc-store.js 存在 |
✓ |
| 3 | server/services/unit-registry.js 存在 |
✓ |
| 4 | server/services/sse-broker.js 存在 |
✓ |
| 5 | server/routes/devloop.js 存在且 7 个端点全 |
✓ curl /api/health + grep |
| 6 | system/templates/devloop-{pm,architect,coder,tester,integrator,triager}.md 全部存在 |
✓ ls 应见 6 个 |
| 7 | system/templates/_registry.json 含 devloop-* 六条 |
✓ grep |
| 8 | web/src/views/DevLoopDashboard.vue + 7 个子组件 |
✓ ls web/src/components/devloop/ |
| 9 | npm test 全绿 | ✓ |
| 10 | POST /api/devloop/projects 60s 内生成 3 份文档 | ✓ file 存在 |
| 11 | SSE 流持续推 unit.state 事件 | ✓ curl -N 看到 |
| 12 | 整套 DevLoop 能对自己做增量(用 DevLoop 给 DevLoop 加新需求) | ✓ 元-自举测试 |
典型失败模式与诊断
| 失败 | 诊断 | 修 |
|---|---|---|
| 缺某个 MVCP 定义 | build-manifest.json 该项空 | 检查对应 SDD 页是否漏 data-def-name |
| shape 抽不到 | HTML class 不规范 | 用 pre.shape 不是 pre.code 也不是 pre.code.shape,统一 |
| Claude Code 写出的代码风格与 LemonBoss 不一致 | prompt 缺约束 | 在复现 prompt 顶部 require 它先读 CLAUDE.md |
| contract.json 与 SDD 不一致 | Architect 没遵循 hashContract 算法 | 看 docs/prd/newfunction/api-contracts.html 第 4 节 |
| L2 修复死循环 | l2_budget 没设 | project.json 默认值校验 |
| SSE 不断重连 | 心跳没发 | 看 sse-broker.js 25s setInterval |
「文档驱动」承诺
这套 PRD + SDD 的一致性是项目本身的健康指标。
如果未来某次实际代码与文档脱节超过 20%(脚本扫描 unit id 对齐率),系统会发 SSE 警告,提示要么改文档要么改代码。文档永远是 source of truth;代码是执行结果。
下一步
完成本页所述复现一次,相当于:
- ✓ 验证 PRD + SDD 的可执行性(不只是写给人看)
- ✓ 验证 Claude Code + LemonBoss ACP 的能力上限
- ✓ 给团队和投资人一个明确的能力证明(demo 时直接放复现录屏)
复现成功的录屏 + 时间戳 + manifest hash 应保存在 docs/prd/newfunction/repro-evidence/,作为项目交付物的一部分。