aitable-workflow-cli 0.1.28 → 0.1.29-beta.1790736949347
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistant/assets/index-BA6il19d.css +1 -0
- package/dist/assistant/assets/{index-B3LvYfRW.js → index-BMzAOp70.js} +31 -31
- package/dist/assistant/index.html +2 -2
- package/dist/chunk-BBP5RVFU.js +15 -0
- package/dist/cli.js +180 -73
- package/dist/{config-ui-server-4SVD42Z3.js → config-ui-server-UWELHUH4.js} +1 -1
- package/dist/web/assets/index-Bnmnydwk.css +1 -0
- package/dist/web/assets/index-Dbs1xWB9.js +331 -0
- package/dist/web/index.html +2 -2
- package/dist/web/install.ps1 +173 -0
- package/dist/web/install.sh +188 -0
- package/package.json +3 -3
- package/templates/ai-native-sdlc/.env.example +11 -0
- package/templates/ai-native-sdlc/aitable-workflow.config.yml +47 -0
- package/templates/ai-native-sdlc/coding-agents.config.json +17 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-15-ai-native-sdlc-dual-staff-implementation-plan.md +150 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-15-ai-native-sdlc-dual-staff.md +213 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-16-domain-role-notification-routing.md +36 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-16-execution-resume-and-cr-loop.md +29 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-16-project-handoff.md +148 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-17-prd-code-context-and-readable-prompts.md +37 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-21-plan-merge-sync-and-agent-source.md +19 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-21-sdlc-base-ref-and-review-notification.md +18 -0
- package/templates/ai-native-sdlc/docs/plans/2026-09-29-borrow-from-joe-design.md +943 -0
- package/templates/ai-native-sdlc/lib/artifacts.ts +126 -0
- package/templates/ai-native-sdlc/lib/recipe-config.ts +34 -0
- package/templates/ai-native-sdlc/lib/recipe-helpers.ts +595 -0
- package/templates/ai-native-sdlc/npmrc +1 -0
- package/templates/ai-native-sdlc/package.json +19 -0
- package/templates/ai-native-sdlc/profile/profile.yml +115 -0
- package/templates/ai-native-sdlc/setup/module-config.seed.json +37 -0
- package/templates/ai-native-sdlc/test/artifacts.test.ts +72 -0
- package/templates/ai-native-sdlc/test/recipe-helpers.test.ts +931 -0
- package/templates/ai-native-sdlc/tsconfig.json +17 -0
- package/templates/ai-native-sdlc/workflows/.gitkeep +3 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/blocked-questions-dev.json +91 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/blocked-questions.json +91 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/cr-review-dev.json +80 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/cr-review.json +81 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/resume-answers.json +42 -0
- package/templates/ai-native-sdlc/workflows/execution/automations/spec-review-dev.json +138 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/coding.recipe.ts +161 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/prd-review.recipe.ts +200 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/prd.recipe.ts +163 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/review.recipe.ts +257 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/spec-review.recipe.ts +242 -0
- package/templates/ai-native-sdlc/workflows/execution/recipes/spec.recipe.ts +173 -0
- package/templates/ai-native-sdlc/workflows/execution/workflow.yml +79 -0
- package/templates/ai-native-sdlc/workflows/intake/automations/accept-intake.json +101 -0
- package/templates/ai-native-sdlc/workflows/intake/recipes/classify-module.recipe.ts +133 -0
- package/templates/ai-native-sdlc/workflows/intake/recipes/create-change.recipe.ts +94 -0
- package/templates/ai-native-sdlc/workflows/intake/recipes/mechanical-deduplicate.recipe.ts +33 -0
- package/templates/ai-native-sdlc/workflows/intake/workflow.yml +62 -0
- package/templates/ai-native-sdlc/workspaces/dev/AGENTS.md +69 -0
- package/templates/ai-native-sdlc/workspaces/pm/AGENTS.md +48 -0
- package/templates/ai-native-sdlc/workspaces/reviewer/AGENTS.md +79 -0
- package/dist/assistant/assets/index-CCEHOkkJ.css +0 -1
- package/dist/chunk-YDJTCQW4.js +0 -15
- package/dist/web/assets/index-DPc2WOdp.css +0 -1
- package/dist/web/assets/index-HTw8K38o.js +0 -332
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
# Joe 优秀设计借鉴方案
|
|
2
|
+
|
|
3
|
+
> **日期**: 2026-09-29
|
|
4
|
+
> **状态**: 草案(待评审,暂不落地)
|
|
5
|
+
> **范围**: 从 Joe 项目中提炼可借鉴的设计模式,增强 AI Native SDLC 的 Prompt 质量与 Agent 行为可控性
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 一、背景
|
|
10
|
+
|
|
11
|
+
### 1.1 两个项目的定位差异
|
|
12
|
+
|
|
13
|
+
| 维度 | AI Native SDLC(双数字员工) | Joe |
|
|
14
|
+
|------|---------------------------|-----|
|
|
15
|
+
| 核心隐喻 | PM + Dev 双 Agent 协作 | 单 Agent + Skills 方法论切换 |
|
|
16
|
+
| 覆盖范围 | 完整 SDLC:需求 → PRD → 技术方案 → 编码 → 评审 | 聚焦 bug-fix:理解 → 排查 → 修复 → 审查 → 部署 |
|
|
17
|
+
| 工作流定义 | YAML 声明式步骤图 | JS 命令式动态脚本 |
|
|
18
|
+
| 质量门禁 | 每阶段 CR merge 硬门禁 | 证据铁律 + 对抗性审查 |
|
|
19
|
+
| 工程成熟度 | 框架支撑,测试覆盖待完善 | 95%+ 测试覆盖,Dashboard 可观测 |
|
|
20
|
+
|
|
21
|
+
### 1.2 借鉴动机
|
|
22
|
+
|
|
23
|
+
Joe 在以下方面有显著优势,值得引入 AI Native SDLC:
|
|
24
|
+
|
|
25
|
+
1. **Prompt 工程**:对抗性 framing、证据铁律、结构化输出
|
|
26
|
+
2. **Skills 系统**:可插拔的方法论模块(TDD、验证、审查、计划)
|
|
27
|
+
3. **Agent 行为控制**:Gate 门禁、有界重试、管线感知
|
|
28
|
+
4. **架构设计**:Resume Shim、Tool 能力注入、人工反馈文档化
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 二、Prompt 设计模式借鉴
|
|
33
|
+
|
|
34
|
+
### 2.1 证据铁律(Iron Law)— 注入 Coding 阶段
|
|
35
|
+
|
|
36
|
+
**来源**: Joe 的 `verification-before-completion` Skill
|
|
37
|
+
|
|
38
|
+
**核心原则**: 没有当场跑过验证命令并看到输出 → 不能声称通过。
|
|
39
|
+
|
|
40
|
+
**解决的问题**: LLM 幻觉测试结果——Agent 声称"测试通过"但实际从未运行测试命令。
|
|
41
|
+
|
|
42
|
+
**Joe 的实现**:
|
|
43
|
+
|
|
44
|
+
```markdown
|
|
45
|
+
## ⚖️ 证据铁律
|
|
46
|
+
**没有当场跑过验证命令并看到输出 → 不能声称通过。**
|
|
47
|
+
|
|
48
|
+
### 操作规程
|
|
49
|
+
1. 识别验证命令(测试/类型检查/构建)
|
|
50
|
+
2. 运行完整命令(不是部分)
|
|
51
|
+
3. 阅读完整输出(不是尾部)
|
|
52
|
+
4. 确认输出支持你的声明
|
|
53
|
+
5. 只有此时才能声称"通过"
|
|
54
|
+
|
|
55
|
+
### 🚩 红旗信号
|
|
56
|
+
- 使用"应该"、"大概"、"可能" → 你还没有验证
|
|
57
|
+
- 在验证前说"太好了"、"搞定了" → 停下来,先跑验证
|
|
58
|
+
- 准备提交但没跑测试 → 不允许
|
|
59
|
+
- 信任另一个 Agent 的成功报告 → 自己验证
|
|
60
|
+
|
|
61
|
+
### 回归验证(关键 Bug 修复必须)
|
|
62
|
+
编写修复 → 跑测试(通过)→ 回退修复 → 跑测试(必须失败)→ 恢复修复 → 跑测试(通过)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**AI Native SDLC 的当前差距**:
|
|
66
|
+
|
|
67
|
+
当前 `coding.recipe.ts` 只有一句"失败不能伪造通过",缺乏具体操作规程和红旗信号。
|
|
68
|
+
|
|
69
|
+
**建议注入位置**: `coding.recipe.ts` 的 prompt 模板中新增 `## ⚖️ 证据铁律` 段落。
|
|
70
|
+
|
|
71
|
+
**预期工件增强**: `03-coding.md` 必须包含以下证据段落:
|
|
72
|
+
|
|
73
|
+
```markdown
|
|
74
|
+
## 测试证据
|
|
75
|
+
- ✅ 测试命令: `pnpm test`
|
|
76
|
+
- ✅ 实际输出: (粘贴完整输出,不是"应该通过")
|
|
77
|
+
|
|
78
|
+
## 类型检查证据
|
|
79
|
+
- ✅ 命令: `pnpm typecheck`
|
|
80
|
+
- ✅ 实际输出: (粘贴完整输出)
|
|
81
|
+
|
|
82
|
+
## Git Diff 证据
|
|
83
|
+
- ✅ `git diff HEAD~1` 输出: (粘贴实际 diff)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### 2.2 对抗性 Framing — 注入 Review 阶段
|
|
89
|
+
|
|
90
|
+
**来源**: Joe 的 `requesting-code-review` Skill + 动态工作流 Review prompt
|
|
91
|
+
|
|
92
|
+
**核心原则**: 翻转 Agent 的默认倾向——从"确认正确"变为"尽力找问题"。
|
|
93
|
+
|
|
94
|
+
**Joe 的实现**:
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
## 审查者角色设定
|
|
98
|
+
你现在是一个**独立的代码审查者**。
|
|
99
|
+
- 你没有参与前面的设计和编码过程
|
|
100
|
+
- 你只看到 diff 和原始需求
|
|
101
|
+
- 你的职责是**尽力找出问题**,而不是确认修复正确
|
|
102
|
+
- 假设代码有 Bug,你的任务是找到它
|
|
103
|
+
|
|
104
|
+
### 问题分级
|
|
105
|
+
- 🔴 Critical:必须立即修复(逻辑错误、数据丢失风险)
|
|
106
|
+
- 🟡 Important:必须修复后才能合并(性能问题、缺少错误处理)
|
|
107
|
+
- 🔵 Minor:可以后续处理(代码风格、命名优化)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**AI Native SDLC 的当前差距**:
|
|
111
|
+
|
|
112
|
+
当前 review recipe 是同一个 Agent session 继续处理 CR 评论,存在"自我确认偏误"。Review 阶段的 prompt 只是说"逐项修复评论",缺乏对抗性思维。
|
|
113
|
+
|
|
114
|
+
**建议注入位置**: 各 review recipe(`prd-review.recipe.ts`、`spec-review.recipe.ts`、`review.recipe.ts`)的 prompt 中增加对抗性角色设定。
|
|
115
|
+
|
|
116
|
+
**各阶段的对抗性 prompt 变体**:
|
|
117
|
+
|
|
118
|
+
| 阶段 | 对抗性 Framing |
|
|
119
|
+
|------|---------------|
|
|
120
|
+
| PRD Review | "你的职责是找出 PRD 中的遗漏和矛盾,而不是确认 PRD 写得好" |
|
|
121
|
+
| Spec Review | "假设技术方案有致命缺陷,你的任务是找到它" |
|
|
122
|
+
| Code Review | "假设代码有 Bug,你的任务是找到它" |
|
|
123
|
+
| 需求澄清 | "如果你没有提出问题,说明你理解得不够深——至少找出 3 个不确定点" |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### 2.3 反幻觉守卫 — 注入所有阶段
|
|
128
|
+
|
|
129
|
+
**来源**: Joe 的 `WORKFLOW.skills.md` 中的反 hedging 语句
|
|
130
|
+
|
|
131
|
+
**核心原则**: 直接针对 LLM 的模糊表达倾向,强制具体证据。
|
|
132
|
+
|
|
133
|
+
**Joe 的实现**:
|
|
134
|
+
|
|
135
|
+
```markdown
|
|
136
|
+
如果你发现自己在用"可能"、"应该"、"大概"——你还没有找到根因,继续排查。
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**建议注入位置**: 所有 recipe 的 `## 约束` 段落中增加:
|
|
140
|
+
|
|
141
|
+
```markdown
|
|
142
|
+
## 约束
|
|
143
|
+
- 禁止使用"应该"、"大概"、"可能"、"或许"等模糊表述
|
|
144
|
+
- 每个结论必须有代码级证据(文件路径 + 行号 + 实际输出)
|
|
145
|
+
- 如果不确定,通过 SDLC_QUESTIONS 向人工确认,而不是猜测
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### 2.4 Gate 门禁模式 — 注入阶段转换
|
|
151
|
+
|
|
152
|
+
**来源**: Joe 的 `WORKFLOW.skills.md` 中每个 Phase 后的 Gate checklist
|
|
153
|
+
|
|
154
|
+
**核心原则**: 每个阶段结束时必须满足明确的 ✅ 条件才能进入下一阶段。
|
|
155
|
+
|
|
156
|
+
**Joe 的实现**:
|
|
157
|
+
|
|
158
|
+
```markdown
|
|
159
|
+
### Gate
|
|
160
|
+
- ✅ 根因已定位,有代码级证据(不是推测)
|
|
161
|
+
- ✅ 失败测试已编写并看到失败输出
|
|
162
|
+
- ✅ 修复代码已编写,测试通过(有实际运行输出)
|
|
163
|
+
- ✅ 代码已提交
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**建议**: 在 AI Native SDLC 的每个阶段末尾增加 Gate 检查,Agent 在声称完成前必须自检:
|
|
167
|
+
|
|
168
|
+
| 阶段 | Gate 条件 |
|
|
169
|
+
|------|----------|
|
|
170
|
+
| PRD | ✅ 需求点全部覆盖 ✅ 验收标准可量化 ✅ 依赖项已列出 ✅ 无 TBD/待补充 |
|
|
171
|
+
| PRD Review | ✅ 所有 CR 评论已处理 ✅ CR 已合并(isMerged=true) |
|
|
172
|
+
| Spec | ✅ 选中仓库及理由 ✅ 实施步骤原子化 ✅ 每步有验证命令 ✅ 无 placeholder |
|
|
173
|
+
| Spec Review | ✅ 所有 CR 评论已处理 ✅ CR 已合并 |
|
|
174
|
+
| Coding | ✅ 代码已提交 ✅ 测试有实际运行输出 ✅ 类型检查有实际运行输出 |
|
|
175
|
+
| Review | ✅ 所有 CR 已合并 ✅ CI 全绿 ✅ 无遗留 TODO/FIXME |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 三、Skills 方法论借鉴
|
|
180
|
+
|
|
181
|
+
### 3.1 Brainstorming — 注入 PRD / Spec 阶段
|
|
182
|
+
|
|
183
|
+
**来源**: Joe 的 `brainstorming` Skill(vendor: obra/superpowers)
|
|
184
|
+
|
|
185
|
+
**核心流程**: 探索上下文 → 逐一澄清 → 提出 2-3 方案 → 分节展示设计 → 确认后才进入下一步
|
|
186
|
+
|
|
187
|
+
**AI Native SDLC 的当前差距**: PRD recipe 直接让 PM Agent "读需求、写 PRD",缺少结构化的需求探索过程。Agent 容易直接跳到一个方案。
|
|
188
|
+
|
|
189
|
+
**建议注入 PRD prompt**:
|
|
190
|
+
|
|
191
|
+
```markdown
|
|
192
|
+
## 工作方法:需求探索
|
|
193
|
+
|
|
194
|
+
在撰写 PRD 之前,你必须按以下步骤思考:
|
|
195
|
+
|
|
196
|
+
### 1. 上下文探索
|
|
197
|
+
阅读业务仓库的以下内容,理解当前系统:
|
|
198
|
+
- README.md
|
|
199
|
+
- 目录结构(src/ 下的主要模块)
|
|
200
|
+
- 最近 10 条 commit message
|
|
201
|
+
|
|
202
|
+
### 2. 澄清问题
|
|
203
|
+
列出需求中不明确的地方(最多 5 个),通过 SDLC_QUESTIONS 向人工确认。
|
|
204
|
+
每个问题提供 2-3 个选项和推荐答案。
|
|
205
|
+
|
|
206
|
+
### 3. 方案对比
|
|
207
|
+
提出 2-3 个实现方案,每个方案写明:
|
|
208
|
+
- 优势
|
|
209
|
+
- 劣势
|
|
210
|
+
- 风险
|
|
211
|
+
- 预估工作量
|
|
212
|
+
|
|
213
|
+
### 4. 推荐方案
|
|
214
|
+
给出你的推荐及理由。
|
|
215
|
+
|
|
216
|
+
### 5. 详细 PRD
|
|
217
|
+
在人工确认方案方向后,撰写完整的 PRD 文档。
|
|
218
|
+
|
|
219
|
+
⛔ 硬性门禁:未经人工确认方案方向,不得进入详细 PRD 撰写。
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**建议注入 Spec prompt**:
|
|
223
|
+
|
|
224
|
+
```markdown
|
|
225
|
+
## 工作方法:技术方案探索
|
|
226
|
+
|
|
227
|
+
### 1. 阅读 PRD
|
|
228
|
+
先阅读 PRD 工件(路径见下方),理解需求全貌。
|
|
229
|
+
|
|
230
|
+
### 2. 仓库评估
|
|
231
|
+
对每个候选仓库,评估:
|
|
232
|
+
- 与本次需求的关联度(高/中/低)
|
|
233
|
+
- 修改范围预估(文件数、行数)
|
|
234
|
+
- 风险等级
|
|
235
|
+
|
|
236
|
+
### 3. 方案对比
|
|
237
|
+
提出 2-3 个技术方案,对比维度:
|
|
238
|
+
- 实现复杂度
|
|
239
|
+
- 对现有代码的侵入性
|
|
240
|
+
- 可测试性
|
|
241
|
+
- 回滚难度
|
|
242
|
+
|
|
243
|
+
### 4. 推荐方案
|
|
244
|
+
给出推荐及理由,明确列出选中/未选中仓库及原因。
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
### 3.2 Writing-Plans — 注入 Spec 阶段
|
|
250
|
+
|
|
251
|
+
**来源**: Joe 的 `writing-plans` Skill(vendor: obra/superpowers)
|
|
252
|
+
|
|
253
|
+
**核心原则**: 实施计划必须假设执行者"零上下文"——每个步骤是 2-5 分钟的原子操作。
|
|
254
|
+
|
|
255
|
+
**Joe 的关键约束**:
|
|
256
|
+
|
|
257
|
+
- **原子步骤**: 每个步骤是一个 2-5 分钟的原子操作
|
|
258
|
+
- **零 Placeholder**: 禁止 "TBD"、"后续补充"、"适当处理"
|
|
259
|
+
- **精确路径**: 每个步骤指明要修改的文件路径(精确到行号范围)
|
|
260
|
+
- **完整代码**: 关键函数给出完整代码,不是伪代码
|
|
261
|
+
- **验证命令**: 每个步骤附带验证命令和预期输出
|
|
262
|
+
- **自检清单**: Spec 覆盖度 + placeholder 扫描 + 类型一致性
|
|
263
|
+
|
|
264
|
+
**建议注入 Spec prompt**:
|
|
265
|
+
|
|
266
|
+
```markdown
|
|
267
|
+
## 工作方法:技术方案编写
|
|
268
|
+
|
|
269
|
+
你的 Spec(02-spec.md)必须满足以下标准:
|
|
270
|
+
|
|
271
|
+
### 原子步骤
|
|
272
|
+
每个实施步骤是一个 2-5 分钟的原子操作,格式如下:
|
|
273
|
+
|
|
274
|
+
#### 步骤 N: <标题>
|
|
275
|
+
- **文件**: `src/path/to/file.ts` (行 42-58)
|
|
276
|
+
- **操作**: <具体描述>
|
|
277
|
+
- **代码**: (关键函数给出完整代码)
|
|
278
|
+
- **验证**: `<命令>` → 预期输出: `<预期>`
|
|
279
|
+
|
|
280
|
+
### 禁止项
|
|
281
|
+
- ❌ "TBD"、"后续补充"、"适当处理"
|
|
282
|
+
- ❌ 伪代码(必须给出可运行的代码)
|
|
283
|
+
- ❌ "添加适当的错误处理"(必须指明具体错误类型和处理方式)
|
|
284
|
+
|
|
285
|
+
### 自检清单(写入 Spec 末尾)
|
|
286
|
+
- ✅ 每个需求点都有对应步骤
|
|
287
|
+
- ✅ 无 placeholder 扫描通过
|
|
288
|
+
- ✅ 类型一致性检查通过
|
|
289
|
+
- ✅ 每个步骤有验证命令和预期输出
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### 3.3 TDD(测试驱动开发)— 注入 Coding 阶段
|
|
295
|
+
|
|
296
|
+
**来源**: Joe 的 `test-driven-development` Skill(vendor: obra/superpowers)
|
|
297
|
+
|
|
298
|
+
**核心原则**: 没有失败的测试,就不写生产代码。
|
|
299
|
+
|
|
300
|
+
**Joe 的实现**:
|
|
301
|
+
|
|
302
|
+
```markdown
|
|
303
|
+
## TDD 铁律
|
|
304
|
+
**没有失败的测试 → 不写生产代码。**
|
|
305
|
+
|
|
306
|
+
### Red-Green-Refactor 循环
|
|
307
|
+
1. **RED**: 写一个最小的失败测试,验证它确实失败
|
|
308
|
+
2. **GREEN**: 写最简单的代码让测试通过,验证所有测试仍然绿色
|
|
309
|
+
3. **REFACTOR**: 只在绿色之后才重构,不添加新行为
|
|
310
|
+
|
|
311
|
+
### 如果你先写了代码再写测试 → 删掉代码,从头来过
|
|
312
|
+
没有例外。不要保留作为"参考",不要"改编"。
|
|
313
|
+
|
|
314
|
+
### 常见借口及反驳
|
|
315
|
+
- "太简单不需要测试" → 简单的代码也可能有边界情况
|
|
316
|
+
- "我先写代码后补测试" → 后补的测试无法证明代码正确
|
|
317
|
+
- "TDD 会拖慢我" → 第一次就做对比返工快
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**建议注入 Coding prompt**:
|
|
321
|
+
|
|
322
|
+
```markdown
|
|
323
|
+
## 工作方法:测试驱动开发
|
|
324
|
+
|
|
325
|
+
在编写实现代码之前,你必须遵循 TDD 循环:
|
|
326
|
+
|
|
327
|
+
### 1. RED — 编写失败测试
|
|
328
|
+
- 针对需求中的每个行为点,编写一个测试
|
|
329
|
+
- 运行测试,确认它**确实失败**(看到失败输出)
|
|
330
|
+
- 将失败输出记录到 03-coding.md
|
|
331
|
+
|
|
332
|
+
### 2. GREEN — 最小实现
|
|
333
|
+
- 编写最简单的代码让测试通过
|
|
334
|
+
- 运行测试,确认**所有测试通过**(看到通过输出)
|
|
335
|
+
- 将通过输出记录到 03-coding.md
|
|
336
|
+
|
|
337
|
+
### 3. REFACTOR — 重构(可选)
|
|
338
|
+
- 只在测试全绿后才重构
|
|
339
|
+
- 重构后再次运行测试,确认仍然通过
|
|
340
|
+
|
|
341
|
+
### ⛔ 硬性约束
|
|
342
|
+
- 如果你先写了实现代码再写测试 → 删掉实现代码,从 RED 开始
|
|
343
|
+
- 每个新增函数必须有对应测试
|
|
344
|
+
- 测试必须使用真实代码,避免不必要的 mock
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
### 3.4 Finishing-a-Branch — 注入 Review 完成阶段
|
|
350
|
+
|
|
351
|
+
**来源**: Joe 的 `finishing-a-development-branch` Skill
|
|
352
|
+
|
|
353
|
+
**建议注入 Review 完成条件**:
|
|
354
|
+
|
|
355
|
+
```markdown
|
|
356
|
+
## 分支完成门禁
|
|
357
|
+
|
|
358
|
+
在标记为 shipped 之前,必须确认:
|
|
359
|
+
- ✅ 所有 CR 已合并(isMerged=true for all)
|
|
360
|
+
- ✅ CI 全绿(有截图/链接证据)
|
|
361
|
+
- ✅ 无遗留 TODO/FIXME/HACK 注释
|
|
362
|
+
- ✅ commit message 符合 Conventional Commits
|
|
363
|
+
- ✅ 工件文档(03-coding.md)与实际代码变更一致
|
|
364
|
+
- ✅ 无未推送的本地 commit
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## 四、架构设计借鉴
|
|
370
|
+
|
|
371
|
+
### 4.1 Persona 真正注入 Prompt
|
|
372
|
+
|
|
373
|
+
**来源**: Joe 的 `AGENTS.md` + `execution-context.ts` 分层注入
|
|
374
|
+
|
|
375
|
+
**AI Native SDLC 的当前差距**:
|
|
376
|
+
|
|
377
|
+
`profile/profile.yml` 定义了 PM/Dev 的 persona 和 guardrails,但**从未注入到 prompt 中**。当前 recipe 只说"你是 Dev"甚至什么都不说。AGENTS.md 依赖 Agent 自己去读,不可靠。
|
|
378
|
+
|
|
379
|
+
**建议**: 在 prompt builder 中显式注入 persona + guardrails:
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
// lib/prompt-builder.ts(新增)
|
|
383
|
+
function buildRoleSection(role: 'pm' | 'dev', profile: Profile): string {
|
|
384
|
+
const roleConfig = profile.roles[role];
|
|
385
|
+
return `
|
|
386
|
+
## 角色
|
|
387
|
+
${roleConfig.persona}
|
|
388
|
+
|
|
389
|
+
## 行为约束(铁律)
|
|
390
|
+
${roleConfig.guardrails}
|
|
391
|
+
|
|
392
|
+
## 详细规程
|
|
393
|
+
请阅读工作目录下的 AGENTS.md 获取完整操作规程。
|
|
394
|
+
`.trim();
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**注入效果示例**:
|
|
399
|
+
|
|
400
|
+
```markdown
|
|
401
|
+
## 角色
|
|
402
|
+
你是 PM(产品经理),负责需求分析、PRD 撰写和验收标准定义。
|
|
403
|
+
|
|
404
|
+
## 行为约束(铁律)
|
|
405
|
+
所有结论必须写入 Git 工件(changes/ 目录下的 Markdown 文件),不能只出现在对话中。
|
|
406
|
+
|
|
407
|
+
## 详细规程
|
|
408
|
+
请阅读工作目录下的 AGENTS.md 获取完整操作规程。
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
### 4.2 管线位置感知(Pipeline Awareness)
|
|
414
|
+
|
|
415
|
+
**来源**: Joe 的 `dynamic-workflow.ts` 中 phase 进度注入
|
|
416
|
+
|
|
417
|
+
**AI Native SDLC 的当前差距**: Agent 不知道自己在 6 步流程中的哪一步,也不知道产出会被谁消费。
|
|
418
|
+
|
|
419
|
+
**建议**: 在每个 recipe 的 prompt 中注入管线上下文:
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
// lib/prompt-builder.ts(新增)
|
|
423
|
+
function buildPipelineContextSection(
|
|
424
|
+
currentStep: string,
|
|
425
|
+
steps: string[],
|
|
426
|
+
stepLabels: Record<string, string>
|
|
427
|
+
): string {
|
|
428
|
+
const currentIndex = steps.indexOf(currentStep);
|
|
429
|
+
const total = steps.length;
|
|
430
|
+
const progress = steps.map((s, i) => {
|
|
431
|
+
const icon = i < currentIndex ? '✅' : i === currentIndex ? '🔵' : '⬜';
|
|
432
|
+
return `${icon} ${stepLabels[s]}`;
|
|
433
|
+
}).join(' → ');
|
|
434
|
+
|
|
435
|
+
const downstream = steps.slice(currentIndex + 1).map(s => stepLabels[s]);
|
|
436
|
+
const downstreamConsumer = downstream[0] ?? '完成';
|
|
437
|
+
|
|
438
|
+
return `
|
|
439
|
+
## 管线位置
|
|
440
|
+
你正在 SDLC 流水线的 **第 ${currentIndex + 1} 步 / 共 ${total} 步**:
|
|
441
|
+
${progress}
|
|
442
|
+
|
|
443
|
+
### 你的产出将被谁消费?
|
|
444
|
+
${downstreamConsumer === '完成'
|
|
445
|
+
? '你是最后一步,你的产出将直接交付。'
|
|
446
|
+
: `你的工件将被 **${downstreamConsumer}** 阶段的 Agent 阅读和使用。`}
|
|
447
|
+
`.trim();
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**各阶段的注入效果**:
|
|
452
|
+
|
|
453
|
+
| 阶段 | 管线位置 | 下游消费者 |
|
|
454
|
+
|------|---------|-----------|
|
|
455
|
+
| PRD | 第 1 步 / 共 6 步 | PRD Review 阶段的 CR 审查者 |
|
|
456
|
+
| PRD Review | 第 2 步 / 共 6 步 | Spec 阶段的 Dev Agent |
|
|
457
|
+
| Spec | 第 3 步 / 共 6 步 | Spec Review 阶段的 CR 审查者 |
|
|
458
|
+
| Spec Review | 第 4 步 / 共 6 步 | Coding 阶段的 Dev Agent |
|
|
459
|
+
| Coding | 第 5 步 / 共 6 步 | Review 阶段的 CR 审查者 |
|
|
460
|
+
| Review | 第 6 步 / 共 6 步 | 你是最后一步,你的产出将直接交付 |
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
### 4.3 Tool Capabilities 自动注入
|
|
465
|
+
|
|
466
|
+
**来源**: Joe 的 `tool-capabilities.ts` — 启动时运行 `a1 --help` / `dws --help` 并缓存
|
|
467
|
+
|
|
468
|
+
**AI Native SDLC 的当前差距**: Agent 不知道 `ctx.toolkit` 提供了什么能力,全靠 AGENTS.md 里手写(可能过时)。
|
|
469
|
+
|
|
470
|
+
**建议**: 在 prompt 中动态注入 toolkit 能力清单:
|
|
471
|
+
|
|
472
|
+
```markdown
|
|
473
|
+
## 可用工具
|
|
474
|
+
|
|
475
|
+
你可以通过以下方式与系统交互:
|
|
476
|
+
|
|
477
|
+
### Git 操作
|
|
478
|
+
- 确保 worktree 存在: 已在下方列出路径
|
|
479
|
+
- 提交并推送: `git add -A && git commit && git push`
|
|
480
|
+
- 创建 Code Review: 通过平台 API 或 CLI
|
|
481
|
+
|
|
482
|
+
### AI Table 操作
|
|
483
|
+
- 更新记录字段: 由工作流引擎自动处理
|
|
484
|
+
- 读取记录: 由工作流引擎自动处理
|
|
485
|
+
|
|
486
|
+
### 消息通知
|
|
487
|
+
- 发送钉钉通知: 由工作流自动化规则处理
|
|
488
|
+
|
|
489
|
+
### 约束
|
|
490
|
+
- 你不能直接修改 AI Table 的"当前步骤"字段(由引擎管理)
|
|
491
|
+
- 你不能执行 git merge(由人工在 CR 平台操作)
|
|
492
|
+
- 你不能直接发送钉钉消息(通过自动化规则触发)
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
### 4.4 有界重试循环(Bounded Retry)
|
|
498
|
+
|
|
499
|
+
**来源**: Joe 的 `WORKFLOW.dynamic.js` 中 review 循环最多 2 轮
|
|
500
|
+
|
|
501
|
+
**AI Native SDLC 的当前差距**: 当前 CR 评论修复没有轮次限制,理论上可以无限循环。
|
|
502
|
+
|
|
503
|
+
**建议**: 在 review recipe 中加入轮次计数:
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
// review.recipe.ts
|
|
507
|
+
const MAX_REVIEW_ROUNDS = 3;
|
|
508
|
+
|
|
509
|
+
async execute(ctx) {
|
|
510
|
+
const row = await ctx.toolkit.table.readRow(ctx.rowId);
|
|
511
|
+
const currentRound = Number(recordValue(row, '审查轮次') ?? 1);
|
|
512
|
+
|
|
513
|
+
if (currentRound > MAX_REVIEW_ROUNDS) {
|
|
514
|
+
// 超过最大轮次,升级为人工处理
|
|
515
|
+
await ctx.toolkit.table.updateRow(ctx.rowId, {
|
|
516
|
+
'状态': 'blocked',
|
|
517
|
+
'阻塞原因': `审查已超过 ${MAX_REVIEW_ROUNDS} 轮,请人工介入`,
|
|
518
|
+
});
|
|
519
|
+
return blocked(`审查已超过 ${MAX_REVIEW_ROUNDS} 轮,请人工介入`);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// ... 正常 review 逻辑
|
|
523
|
+
|
|
524
|
+
// 每轮修复后递增轮次
|
|
525
|
+
await ctx.toolkit.table.updateRow(ctx.rowId, {
|
|
526
|
+
'审查轮次': currentRound + 1,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Tracker 字段新增**:
|
|
532
|
+
|
|
533
|
+
```yaml
|
|
534
|
+
field_definitions:
|
|
535
|
+
- name: 审查轮次
|
|
536
|
+
type: number
|
|
537
|
+
default: 1
|
|
538
|
+
description: 当前 CR 审查修复的轮次,超过上限则升级人工
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
### 4.5 Resume Shim(断点恢复缓存)
|
|
544
|
+
|
|
545
|
+
**来源**: Joe 的 `dynamic-script.ts` — 代码变换技巧
|
|
546
|
+
|
|
547
|
+
**核心思想**: 不靠 session 持久化恢复上下文,而是缓存已完成阶段的结果,resume 时直接跳过。
|
|
548
|
+
|
|
549
|
+
**Joe 的实现原理**:
|
|
550
|
+
|
|
551
|
+
```javascript
|
|
552
|
+
// 原始工作流脚本被包装:
|
|
553
|
+
const __cached = args.__cachedResults || []; // 上次已完成的结果
|
|
554
|
+
let __idx = 0;
|
|
555
|
+
|
|
556
|
+
async function __cachedAgent(prompt, opts) {
|
|
557
|
+
const i = __idx++;
|
|
558
|
+
if (i < __cached.length && __cached[i] != null) {
|
|
559
|
+
return __cached[i]; // ← 命中缓存,跳过执行(0 token)
|
|
560
|
+
}
|
|
561
|
+
// 首次调用(人工介入后):注入人工反馈
|
|
562
|
+
if (__humanCtx && !__humanCtxUsed) {
|
|
563
|
+
prompt += '\n\n## 人工反馈\n\n' + __humanCtx;
|
|
564
|
+
}
|
|
565
|
+
return await __originalAgent(prompt, opts);
|
|
566
|
+
}
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
**AI Native SDLC 的当前做法**: 靠 `sessionId` 恢复对话上下文。问题:
|
|
570
|
+
- 每次 resume 都要重新加载完整历史(token 浪费)
|
|
571
|
+
- session 可能过期或被清理
|
|
572
|
+
- 无法跳过已完成的阶段
|
|
573
|
+
|
|
574
|
+
**建议**: 在 recipe 层引入 stage-level 产出缓存:
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
// lib/resume-cache.ts(新增)
|
|
578
|
+
interface ResumeCache {
|
|
579
|
+
// key: stage name, value: artifact content + metadata
|
|
580
|
+
artifacts: Record<string, {
|
|
581
|
+
content: string;
|
|
582
|
+
timestamp: string;
|
|
583
|
+
agentSessionId: string;
|
|
584
|
+
}>;
|
|
585
|
+
// 人工答复历史
|
|
586
|
+
humanAnswers: Array<{
|
|
587
|
+
timestamp: string;
|
|
588
|
+
question: string;
|
|
589
|
+
answer: string;
|
|
590
|
+
}>;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// prd.recipe.ts
|
|
594
|
+
async execute(ctx) {
|
|
595
|
+
const cache = ctx.resume.getCache();
|
|
596
|
+
|
|
597
|
+
// 检查是否已有 PRD 产出缓存
|
|
598
|
+
const cachedPrd = cache.artifacts['prd'];
|
|
599
|
+
if (cachedPrd && !ctx.resume.hasNewHumanAnswers()) {
|
|
600
|
+
// 直接复用,不调 Agent(节省 token)
|
|
601
|
+
return success({
|
|
602
|
+
artifact: cachedPrd.content,
|
|
603
|
+
cached: true,
|
|
604
|
+
message: '复用上次 PRD 产出(无人工新反馈)'
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// 首次执行或有新的人工答复 → 调 Agent
|
|
609
|
+
const prompt = buildPrompt(ctx, {
|
|
610
|
+
previousArtifact: cachedPrd?.content, // 注入上次产出供参考
|
|
611
|
+
newHumanAnswers: ctx.resume.getNewAnswers(), // 注入新的人工反馈
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
const result = await ctx.toolkit.coding.run(prompt, { sessionId });
|
|
615
|
+
|
|
616
|
+
// 缓存本次产出
|
|
617
|
+
ctx.resume.setArtifact('prd', result);
|
|
618
|
+
|
|
619
|
+
return success({ artifact: result, cached: false });
|
|
620
|
+
}
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
**收益**:
|
|
624
|
+
- Resume 时跳过已完成阶段,节省 token
|
|
625
|
+
- 人工反馈精准注入到断点处的 prompt
|
|
626
|
+
- 不依赖外部 session 存储的可用性
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
### 4.6 渐进式上下文压缩(Progressive Context Accumulation)
|
|
631
|
+
|
|
632
|
+
**来源**: Joe 的 `WORKFLOW.dynamic.js` — 后续阶段只收到前序阶段的 `summary`
|
|
633
|
+
|
|
634
|
+
**AI Native SDLC 的当前差距**: Spec 阶段只拿到 PRD 的文件路径让 Agent 自己读,没有预提取关键信息。Review 阶段直接 dump JSON 评论,没有摘要。
|
|
635
|
+
|
|
636
|
+
**建议**: 在 recipe 中增加上下文摘要 helper:
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
// lib/context-compression.ts(新增)
|
|
640
|
+
async function extractArtifactSummary(
|
|
641
|
+
artifactPath: string,
|
|
642
|
+
options: { sections: string[]; maxLength: number }
|
|
643
|
+
): Promise<string> {
|
|
644
|
+
// 读取工件文件,提取指定章节,压缩到 maxLength
|
|
645
|
+
const content = await fs.readFile(artifactPath, 'utf-8');
|
|
646
|
+
const sections = extractSections(content, options.sections);
|
|
647
|
+
return truncate(sections.join('\n\n'), options.maxLength);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// spec.recipe.ts — 注入 PRD 摘要
|
|
651
|
+
const prdSummary = await extractArtifactSummary(prdArtifactPath, {
|
|
652
|
+
sections: ['需求概述', '验收标准', '依赖项', '非功能需求'],
|
|
653
|
+
maxLength: 2000,
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const prompt = `
|
|
657
|
+
## 前序阶段产出:PRD 摘要
|
|
658
|
+
${prdSummary}
|
|
659
|
+
|
|
660
|
+
## PRD 完整文件
|
|
661
|
+
路径:${prdArtifactPath}(需要细节时请阅读原文件)
|
|
662
|
+
`;
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
**CR 评论摘要**(注入 review repair prompt):
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
// review.recipe.ts
|
|
669
|
+
function summarizeComments(comments: CRComment[]): string {
|
|
670
|
+
const bySeverity = groupBy(comments, c => c.severity);
|
|
671
|
+
return `
|
|
672
|
+
### 评论摘要
|
|
673
|
+
- 🔴 Critical: ${bySeverity.critical?.length ?? 0} 条
|
|
674
|
+
- 🟡 Important: ${bySeverity.important?.length ?? 0} 条
|
|
675
|
+
- 🔵 Minor: ${bySeverity.minor?.length ?? 0} 条
|
|
676
|
+
|
|
677
|
+
### Critical 评论(必须优先处理)
|
|
678
|
+
${bySeverity.critical?.map(c => `- ${c.path}:${c.line} — ${c.body}`).join('\n') ?? '无'}
|
|
679
|
+
|
|
680
|
+
### 全部评论
|
|
681
|
+
${comments.map(c => `- [${c.severity}] ${c.path}:${c.line} — ${c.body}`).join('\n')}
|
|
682
|
+
`;
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
### 4.7 结构化输出 Schema
|
|
689
|
+
|
|
690
|
+
**来源**: Joe 的 `WORKFLOW.dynamic.js` — 每个 `agent()` 调用传 JSON Schema
|
|
691
|
+
|
|
692
|
+
**AI Native SDLC 的当前差距**: Agent 产出是自由格式 Markdown,解析全靠正则(如 `SDLC_QUESTIONS`),脆弱。
|
|
693
|
+
|
|
694
|
+
**建议**: 定义标准化的输出契约(YAML front matter):
|
|
695
|
+
|
|
696
|
+
```markdown
|
|
697
|
+
## 输出契约
|
|
698
|
+
|
|
699
|
+
你的回复必须包含以下结构化部分(用 YAML front matter 包裹):
|
|
700
|
+
|
|
701
|
+
\`\`\`yaml
|
|
702
|
+
---
|
|
703
|
+
status: success | blocked | failed
|
|
704
|
+
confidence: high | medium | low
|
|
705
|
+
questions: # 仅 status=blocked 时填写
|
|
706
|
+
- id: q1
|
|
707
|
+
question: "..."
|
|
708
|
+
options: ["A", "B", "C"]
|
|
709
|
+
recommendation: "A"
|
|
710
|
+
reason: "..."
|
|
711
|
+
artifacts:
|
|
712
|
+
- path: "changes/CHG-xxx/02-spec.md"
|
|
713
|
+
type: spec
|
|
714
|
+
sections: ["方案概述", "仓库选择", "实施步骤"]
|
|
715
|
+
gate_checklist: # 对应阶段的 Gate 条件
|
|
716
|
+
- condition: "需求点全部覆盖"
|
|
717
|
+
met: true
|
|
718
|
+
- condition: "无 placeholder"
|
|
719
|
+
met: true
|
|
720
|
+
---
|
|
721
|
+
\`\`\`
|
|
722
|
+
|
|
723
|
+
然后是你的工件正文内容。
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
**解析增强**:
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
// lib/output-parser.ts(新增)
|
|
730
|
+
function parseStructuredOutput(response: string): {
|
|
731
|
+
frontMatter: OutputContract;
|
|
732
|
+
body: string;
|
|
733
|
+
} {
|
|
734
|
+
const match = response.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
735
|
+
if (!match) {
|
|
736
|
+
// fallback: 尝试从自由文本中提取 SDLC_QUESTIONS
|
|
737
|
+
return { frontMatter: inferFromFreeText(response), body: response };
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
frontMatter: YAML.parse(match[1]) as OutputContract,
|
|
741
|
+
body: match[2],
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
---
|
|
747
|
+
|
|
748
|
+
### 4.8 分层 Prompt 组合(架构改造)
|
|
749
|
+
|
|
750
|
+
**来源**: Joe 的 `src/agent/prompt/` 目录分层
|
|
751
|
+
|
|
752
|
+
**AI Native SDLC 的当前差距**: 每个 recipe 都是一个大模板字符串,重复代码多,难以维护。
|
|
753
|
+
|
|
754
|
+
**建议**: 引入分层 Prompt 组合器:
|
|
755
|
+
|
|
756
|
+
```
|
|
757
|
+
Prompt = System Layer + Role Layer + Skill Layer + Context Layer + Task Layer
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
| 层 | 内容 | 来源 | 复用范围 |
|
|
761
|
+
|---|---|---|---|
|
|
762
|
+
| System | 证据铁律、Git 规程、中文输出、反幻觉守卫 | `prompts/system.md` | 所有 recipe |
|
|
763
|
+
| Role | PM/Dev 的 persona + guardrails | `profile/profile.yml` | 同角色 recipe |
|
|
764
|
+
| Skill | 当前阶段的方法论(brainstorming/TDD/review) | `prompts/skills/<name>.md` | 同方法论 recipe |
|
|
765
|
+
| Context | 管线位置 + 前序摘要 + worktree 路径 | recipe 动态注入 | 当前 recipe |
|
|
766
|
+
| Task | 本轮具体任务 + 产出要求 + Gate 条件 | recipe 动态注入 | 当前 recipe |
|
|
767
|
+
|
|
768
|
+
**代码结构**:
|
|
769
|
+
|
|
770
|
+
```typescript
|
|
771
|
+
// lib/prompt-builder.ts(新增)
|
|
772
|
+
class PromptBuilder {
|
|
773
|
+
private layers: string[] = [];
|
|
774
|
+
|
|
775
|
+
system(): this {
|
|
776
|
+
this.layers.push(loadTemplate('prompts/system.md'));
|
|
777
|
+
return this;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
role(role: 'pm' | 'dev', profile: Profile): this {
|
|
781
|
+
this.layers.push(buildRoleSection(role, profile));
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
skill(skillName: string): this {
|
|
786
|
+
this.layers.push(loadTemplate(`prompts/skills/${skillName}.md`));
|
|
787
|
+
return this;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
pipelineContext(currentStep: string, steps: string[]): this {
|
|
791
|
+
this.layers.push(buildPipelineContextSection(currentStep, steps));
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
task(taskContent: string): this {
|
|
796
|
+
this.layers.push(taskContent);
|
|
797
|
+
return this;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
build(): string {
|
|
801
|
+
return this.layers.join('\n\n---\n\n');
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// prd.recipe.ts 使用示例
|
|
806
|
+
const prompt = new PromptBuilder()
|
|
807
|
+
.system() // 证据铁律 + 反幻觉
|
|
808
|
+
.role('pm', profile) // PM persona + guardrails
|
|
809
|
+
.skill('brainstorming') // 需求探索方法论
|
|
810
|
+
.pipelineContext('prd', executionSteps) // 第 1 步 / 共 6 步
|
|
811
|
+
.task(buildPrdTaskSection(ctx)) // 本轮任务
|
|
812
|
+
.build();
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
---
|
|
816
|
+
|
|
817
|
+
### 4.9 人工反馈文档化
|
|
818
|
+
|
|
819
|
+
**来源**: Joe 的 `execution-context.ts` — `buildHumanLoopContext()`
|
|
820
|
+
|
|
821
|
+
**AI Native SDLC 的当前做法**: 人工在 AI Table 的 `人工答复` 字段填写文本,recipe 直接读取字段值注入 prompt。
|
|
822
|
+
|
|
823
|
+
**差距**: Table 字段空间有限,人工很难写清楚复杂反馈(截图、代码片段、多段分析)。
|
|
824
|
+
|
|
825
|
+
**建议**: 支持"文档级"人工反馈:
|
|
826
|
+
|
|
827
|
+
```typescript
|
|
828
|
+
// lib/human-feedback.ts(新增)
|
|
829
|
+
async function consumeHumanFeedback(ctx: RecipeContext, row: TableRow): Promise<string> {
|
|
830
|
+
const feedbackType = recordValue(row, '反馈类型'); // 'field' | 'doc'
|
|
831
|
+
|
|
832
|
+
if (feedbackType === 'doc') {
|
|
833
|
+
const docUrl = recordValue(row, '反馈文档');
|
|
834
|
+
// 让 Agent 自己读文档,而不是把内容塞进 prompt
|
|
835
|
+
return `
|
|
836
|
+
## 人工反馈(文档)
|
|
837
|
+
|
|
838
|
+
请阅读以下文档获取详细反馈:
|
|
839
|
+
${docUrl}
|
|
840
|
+
|
|
841
|
+
阅读后,提取关键信息继续执行任务。
|
|
842
|
+
如果文档中有多个问题点,请逐一处理。
|
|
843
|
+
`.trim();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// 兼容原有的字段模式
|
|
847
|
+
const answers = recordValue(row, '人工答复');
|
|
848
|
+
return `## 已消费的人工答复\n${answers}`;
|
|
849
|
+
}
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
**Tracker 字段新增**:
|
|
853
|
+
|
|
854
|
+
```yaml
|
|
855
|
+
field_definitions:
|
|
856
|
+
- name: 反馈类型
|
|
857
|
+
type: single_select
|
|
858
|
+
options: ['field', 'doc']
|
|
859
|
+
default: 'field'
|
|
860
|
+
- name: 反馈文档
|
|
861
|
+
type: url
|
|
862
|
+
description: 当反馈类型=doc 时,填写钉钉文档链接
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
---
|
|
866
|
+
|
|
867
|
+
## 五、实施路线图
|
|
868
|
+
|
|
869
|
+
### 第一周:P0 — 纯 Prompt 改动(零架构风险)
|
|
870
|
+
|
|
871
|
+
| 改动项 | 涉及文件 | 改动量 | 预期收益 |
|
|
872
|
+
|--------|---------|--------|---------|
|
|
873
|
+
| 证据铁律注入 Coding | `coding.recipe.ts` | ~30 行 prompt | 消除测试结果幻觉 |
|
|
874
|
+
| 对抗性 Review prompt | `prd-review.recipe.ts`, `spec-review.recipe.ts`, `review.recipe.ts` | ~20 行/文件 | 提升 CR 修复质量 |
|
|
875
|
+
| 有界重试循环 | `review.recipe.ts` + tracker schema | ~20 行代码 + 1 字段 | 防止无限修复循环 |
|
|
876
|
+
| 反幻觉守卫 | 所有 recipe 的 `## 约束` | ~5 行/文件 | 减少模糊表述 |
|
|
877
|
+
|
|
878
|
+
### 第二周:P1 — 小改动大收益
|
|
879
|
+
|
|
880
|
+
| 改动项 | 涉及文件 | 改动量 | 预期收益 |
|
|
881
|
+
|--------|---------|--------|---------|
|
|
882
|
+
| Persona 注入 prompt | 新增 `lib/prompt-builder.ts`,改所有 recipe | ~80 行新代码 | 角色行为稳定 |
|
|
883
|
+
| 管线位置感知 | 新增 helper,改所有 recipe | ~40 行新代码 | Agent 理解上下文 |
|
|
884
|
+
| Gate 门禁模式 | 改所有 recipe 的完成条件 | ~10 行/文件 | 阶段转换可审计 |
|
|
885
|
+
| Tool capabilities 注入 | 新增 helper | ~30 行新代码 | Agent 知道可用工具 |
|
|
886
|
+
|
|
887
|
+
### 第三周:P2 — 方法论注入
|
|
888
|
+
|
|
889
|
+
| 改动项 | 涉及文件 | 改动量 | 预期收益 |
|
|
890
|
+
|--------|---------|--------|---------|
|
|
891
|
+
| Brainstorming 注入 PRD | `prd.recipe.ts` + 新增 `prompts/skills/brainstorming.md` | ~50 行 | PRD 质量提升 |
|
|
892
|
+
| Writing-plans 注入 Spec | `spec.recipe.ts` + 新增 `prompts/skills/writing-plans.md` | ~50 行 | Spec 可执行性 |
|
|
893
|
+
| TDD 注入 Coding | `coding.recipe.ts` + 新增 `prompts/skills/tdd.md` | ~40 行 | 代码质量提升 |
|
|
894
|
+
| 渐进式上下文压缩 | 新增 `lib/context-compression.ts`,改 spec/review recipe | ~60 行 | 减少 context 浪费 |
|
|
895
|
+
|
|
896
|
+
### 后续迭代:P3 — 架构改造
|
|
897
|
+
|
|
898
|
+
| 改动项 | 涉及文件 | 改动量 | 预期收益 |
|
|
899
|
+
|--------|---------|--------|---------|
|
|
900
|
+
| 分层 Prompt 组合 | 新增 `lib/prompt-builder.ts`,重构所有 recipe | ~200 行 | 可维护性 |
|
|
901
|
+
| Resume Shim | 新增 `lib/resume-cache.ts`,改 engine | ~150 行 | Resume 省 token |
|
|
902
|
+
| 结构化输出 Schema | 新增 `lib/output-parser.ts`,改所有 recipe | ~100 行 | 产出解析可靠 |
|
|
903
|
+
| 人工反馈文档化 | 新增 `lib/human-feedback.ts`,改 tracker schema | ~50 行 | 复杂反馈支持 |
|
|
904
|
+
|
|
905
|
+
---
|
|
906
|
+
|
|
907
|
+
## 六、风险与注意事项
|
|
908
|
+
|
|
909
|
+
### 6.1 Prompt 膨胀风险
|
|
910
|
+
|
|
911
|
+
注入更多方法论和约束会增加 prompt 长度,可能挤压 Agent 的有效 context window。
|
|
912
|
+
|
|
913
|
+
**缓解措施**:
|
|
914
|
+
- 使用渐进式上下文压缩,控制总 prompt 在 8K token 以内
|
|
915
|
+
- 方法论指令用精炼的语言,避免冗长
|
|
916
|
+
- 优先注入 P0(证据铁律、对抗性审查),观察效果后再决定 P1/P2
|
|
917
|
+
|
|
918
|
+
### 6.2 Agent 遵循度
|
|
919
|
+
|
|
920
|
+
注入更多约束不等于 Agent 会遵循。LLM 的指令遵循能力有上限。
|
|
921
|
+
|
|
922
|
+
**缓解措施**:
|
|
923
|
+
- 关键约束(证据铁律、Gate 门禁)放在 prompt 开头和结尾(注意力最强位置)
|
|
924
|
+
- 用 ⛔、🚩 等视觉标记强调关键约束
|
|
925
|
+
- 通过 AGENTS.md 和 recipe prompt 双重强化
|
|
926
|
+
|
|
927
|
+
### 6.3 向后兼容
|
|
928
|
+
|
|
929
|
+
所有改动必须保持向后兼容——现有的 workflow.yml、profile.yml、tracker schema 不需要修改即可运行。
|
|
930
|
+
|
|
931
|
+
**缓解措施**:
|
|
932
|
+
- P0/P1 只改 prompt 文本,不改 schema
|
|
933
|
+
- P2 新增的 tracker 字段设 default 值,旧记录不受影响
|
|
934
|
+
- P3 架构改造通过 feature flag 控制
|
|
935
|
+
|
|
936
|
+
---
|
|
937
|
+
|
|
938
|
+
## 七、参考
|
|
939
|
+
|
|
940
|
+
- Joe 项目: `/Users/s/Documents/code/workflow/other/Joe/`
|
|
941
|
+
- Joe Skills (vendor: obra/superpowers): `skills/` 目录
|
|
942
|
+
- AI Native SDLC: `packages/cli/templates/ai-native-sdlc/`
|
|
943
|
+
- 前期对比分析: 2026-09-29 会话记录
|