@specpow/framework 0.2.2 → 0.4.0
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/.specpow/hooks/session-start +1 -1
- package/.specpow/skills/cli-router/SKILL.md +107 -0
- package/.specpow/skills/execution-parallel-agents/SKILL.md +0 -5
- package/.specpow/skills/execution-sdd-orchestrator/SKILL.md +366 -0
- package/.specpow/skills/execution-subagent-dispatch/SKILL.md +295 -0
- package/.specpow/skills/execution-subagent-driven-dev/SKILL.md +0 -5
- package/.specpow/skills/planning-apply-change/SKILL.md +0 -5
- package/.specpow/skills/planning-explore/SKILL.md +0 -5
- package/.specpow/skills/planning-propose/SKILL.md +0 -5
- package/.specpow/skills/using-specpow/SKILL.md +232 -0
- package/CHANGELOG.md +143 -0
- package/README.md +55 -20
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +13 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/apply.d.ts +1 -0
- package/dist/commands/apply.d.ts.map +1 -1
- package/dist/commands/apply.js +93 -3
- package/dist/commands/apply.js.map +1 -1
- package/dist/commands/channel.d.ts.map +1 -1
- package/dist/commands/channel.js +10 -3
- package/dist/commands/channel.js.map +1 -1
- package/dist/commands/config.js +1 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/debug.d.ts.map +1 -1
- package/dist/commands/debug.js +0 -1
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +11 -16
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +125 -4
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/propose.d.ts.map +1 -1
- package/dist/commands/propose.js +23 -10
- package/dist/commands/propose.js.map +1 -1
- package/dist/commands/review.d.ts.map +1 -1
- package/dist/commands/review.js +25 -0
- package/dist/commands/review.js.map +1 -1
- package/dist/commands/status.js +2 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +26 -1
- package/dist/commands/verify.js.map +1 -1
- package/dist/core/agent-contract.d.ts +1 -1
- package/dist/core/agent-contract.d.ts.map +1 -1
- package/dist/core/artifact-graph/types.d.ts +4 -4
- package/dist/core/channel/channel-event-log.d.ts +1 -0
- package/dist/core/channel/channel-event-log.d.ts.map +1 -1
- package/dist/core/channel/channel-event-log.js +4 -2
- package/dist/core/channel/channel-event-log.js.map +1 -1
- package/dist/core/channel/channel-runtime.d.ts +8 -1
- package/dist/core/channel/channel-runtime.d.ts.map +1 -1
- package/dist/core/channel/channel-runtime.js +29 -2
- package/dist/core/channel/channel-runtime.js.map +1 -1
- package/dist/core/hooks/hook-registry.d.ts +1 -1
- package/dist/core/hooks/hook-registry.d.ts.map +1 -1
- package/dist/core/hooks/hook-registry.js +13 -15
- package/dist/core/hooks/hook-registry.js.map +1 -1
- package/dist/core/hooks/hook-types.d.ts +3 -3
- package/dist/core/hooks/hook-types.d.ts.map +1 -1
- package/dist/core/hooks/post-tool-call-hook.d.ts.map +1 -1
- package/dist/core/hooks/post-tool-call-hook.js +17 -11
- package/dist/core/hooks/post-tool-call-hook.js.map +1 -1
- package/dist/core/hooks/pre-tool-call-hook.d.ts.map +1 -1
- package/dist/core/hooks/pre-tool-call-hook.js +1 -2
- package/dist/core/hooks/pre-tool-call-hook.js.map +1 -1
- package/dist/core/hooks/session-start-hook.d.ts +1 -1
- package/dist/core/hooks/session-start-hook.d.ts.map +1 -1
- package/dist/core/hooks/session-start-hook.js +88 -18
- package/dist/core/hooks/session-start-hook.js.map +1 -1
- package/dist/core/init/engine.d.ts +6 -0
- package/dist/core/init/engine.d.ts.map +1 -1
- package/dist/core/init/engine.js +3 -1
- package/dist/core/init/engine.js.map +1 -1
- package/dist/core/parsers/index.d.ts.map +1 -1
- package/dist/core/parsers/index.js +16 -0
- package/dist/core/parsers/index.js.map +1 -1
- package/dist/core/sdd-engine/ai-caller.d.ts +5 -0
- package/dist/core/sdd-engine/ai-caller.d.ts.map +1 -1
- package/dist/core/sdd-engine/ai-caller.js +7 -2
- package/dist/core/sdd-engine/ai-caller.js.map +1 -1
- package/dist/core/sdd-engine/controller.d.ts +8 -0
- package/dist/core/sdd-engine/controller.d.ts.map +1 -1
- package/dist/core/sdd-engine/controller.js +26 -13
- package/dist/core/sdd-engine/controller.js.map +1 -1
- package/dist/core/sdd-engine/index.d.ts.map +1 -1
- package/dist/core/sdd-engine/index.js +0 -1
- package/dist/core/sdd-engine/index.js.map +1 -1
- package/dist/core/sdd-engine/model-selector.d.ts +6 -0
- package/dist/core/sdd-engine/model-selector.d.ts.map +1 -1
- package/dist/core/sdd-engine/model-selector.js +6 -0
- package/dist/core/sdd-engine/model-selector.js.map +1 -1
- package/dist/core/templates/index.d.ts.map +1 -1
- package/dist/core/templates/index.js +12 -2
- package/dist/core/templates/index.js.map +1 -1
- package/dist/templates/claude-commands/specpow-apply.md +23 -0
- package/dist/templates/claude-commands/specpow-archive.md +22 -0
- package/dist/templates/claude-commands/specpow-explore.md +21 -0
- package/dist/templates/claude-commands/specpow-propose.md +27 -0
- package/dist/templates/claude-commands/specpow-status.md +22 -0
- package/dist/templates/claude-commands/specpow-verify.md +21 -0
- package/dist/templates/claude-commands/specpow.md +33 -0
- package/package.json +1 -1
- package/dist/core/sdd-engine/dispatcher.d.ts +0 -62
- package/dist/core/sdd-engine/dispatcher.d.ts.map +0 -1
- package/dist/core/sdd-engine/dispatcher.js +0 -133
- package/dist/core/sdd-engine/dispatcher.js.map +0 -1
|
@@ -42,7 +42,7 @@ if [ -f "${PLUGIN_ROOT}/../openspec/specs" ] 2>/dev/null || [ -d "${PLUGIN_ROOT}
|
|
|
42
42
|
openspec_context="\nOpenSpec structure detected in this project. Follow the spec-driven workflow:\n1. Explore → planning-explore skill\n2. Propose → planning-propose skill\n3. Write Specs/Design/Tasks → planning-write-* skills\n4. Implement → execution-* skills (SDD engine)\n5. Verify → execution-verification-before-completion\n6. Archive → specpow archive\n${active_changes}\n"
|
|
43
43
|
fi
|
|
44
44
|
|
|
45
|
-
session_context="<EXTREMELY_IMPORTANT>\nYou have specpow — a spec-powered AI development framework. It combines OpenSpec's spec-driven planning with Superpowers' subagent-driven execution.\n\n**Below is the full content of your 'specpow:meta-using-skills' skill - your introduction to using skills. For all other skills, use the 'Skill' tool:**\n\n${using_skills_escaped}\n\n${openspec_context}\n\nAvailable skill categories:\n- Planning: planning-explore, planning-propose, planning-write-plans, planning-write-specs, planning-write-design\n- Execution: planning-apply-change, execution-subagent-driven-dev, execution-tdd, execution-systematic-debugging, execution-parallel-agents\n- Quality: execution-requesting-review, execution-receiving-review, execution-verification-before-completion, planning-verify-change\n- Business: business-java-codegen, business-ui-codegen, business-test-gen, business-code-review, business-db-design, business-prd-writer, business-deploy-check\n\nRemember: Check for relevant skills BEFORE any action.\n</EXTREMELY_IMPORTANT>"
|
|
45
|
+
session_context="<EXTREMELY_IMPORTANT>\nYou have specpow — a spec-powered AI development framework. It combines OpenSpec's spec-driven planning with Superpowers' subagent-driven execution.\n\n**Below is the full content of your 'specpow:meta-using-skills' skill - your introduction to using skills. For all other skills, use the 'Skill' tool:**\n\n${using_skills_escaped}\n\n${openspec_context}\n\nAvailable skill categories:\n- Planning: planning-explore, planning-propose, planning-write-plans, planning-write-specs, planning-write-design\n- Execution: planning-apply-change, execution-subagent-driven-dev, execution-tdd, execution-systematic-debugging, execution-parallel-agents\n- Quality: execution-requesting-review, execution-receiving-review, execution-verification-before-completion, planning-verify-change\n- Business: business-java-codegen, business-ui-codegen, business-test-gen, business-code-review, business-db-design, business-prd-writer, business-deploy-check\n- CLI Router: cli-router — maps user intent to SpecPow CLI commands\n\nSpecPow CLI quick reference (execute via Bash tool):\n| Command | Purpose |\n|---------|----------|\n| specpow status | View current change status |\n| specpow explore \"<topic>\" | Socratic requirement exploration (interactive, run in terminal) |\n| specpow propose <name> | Create change proposal |\n| specpow apply | Execute implementation |\n| specpow verify | Verify changes |\n| specpow archive | Archive changes |\n| specpow debug \"<desc>\" | Systematic debugging |\n| specpow doctor | Project diagnostics |\n\nUsers can also use slash commands: /specpow-explore, /specpow-propose, /specpow-apply, /specpow-verify, /specpow-archive, /specpow-status\n\nRemember: Check for relevant skills BEFORE any action.\n</EXTREMELY_IMPORTANT>"
|
|
46
46
|
|
|
47
47
|
# Output context injection as JSON
|
|
48
48
|
# Cursor hooks expect additional_context (snake_case)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cli-router
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
trigger: on-demand
|
|
5
|
+
description: SpecPow CLI 命令路由 — 将用户意图映射到 CLI 命令执行
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# SpecPow CLI 路由技能
|
|
9
|
+
|
|
10
|
+
当用户请求执行 SpecPow CLI 命令时,按以下规则执行。
|
|
11
|
+
|
|
12
|
+
## 铁律
|
|
13
|
+
|
|
14
|
+
1. **所有 CLI 命令通过 Bash 工具执行**,不在对话中模拟输出
|
|
15
|
+
2. **先检查状态**:执行任何命令前先 `specpow status`
|
|
16
|
+
3. **展示完整输出**:将命令输出完整展示给用户
|
|
17
|
+
4. **链式引导**:执行完一步后建议下一步
|
|
18
|
+
|
|
19
|
+
## 意图 → 命令映射表
|
|
20
|
+
|
|
21
|
+
| 用户说 | 执行命令 |
|
|
22
|
+
|--------|---------|
|
|
23
|
+
| "探索需求" / "explore" / "specpow explore" | `specpow explore "主题"` |
|
|
24
|
+
| "创建提案" / "propose" / "specpow propose" | `specpow propose <name>` |
|
|
25
|
+
| "执行" / "apply" / "实现" / "specpow apply" | `specpow apply` |
|
|
26
|
+
| "验证" / "verify" / "检查" / "specpow verify" | `specpow verify` |
|
|
27
|
+
| "归档" / "archive" / "specpow archive" | `specpow archive` |
|
|
28
|
+
| "状态" / "status" / "specpow status" | `specpow status` |
|
|
29
|
+
| "调试" / "debug" / "specpow debug" | `specpow debug "描述"` |
|
|
30
|
+
| "doctor" / "诊断" / "specpow doctor" | `specpow doctor` |
|
|
31
|
+
| "review" / "审查" / "specpow review" | `specpow review` |
|
|
32
|
+
| "schemas" / "schema 列表" | `specpow schemas` |
|
|
33
|
+
| "更新" / "update" / "specpow update" | `specpow update` |
|
|
34
|
+
| "配置" / "config" / "specpow config" | `specpow config` |
|
|
35
|
+
|
|
36
|
+
## 执行规则
|
|
37
|
+
|
|
38
|
+
### 交互式命令处理
|
|
39
|
+
|
|
40
|
+
`specpow explore` 是交互式命令(使用 readline),在 Claude Code 的 Bash 工具中无法交互。
|
|
41
|
+
遇到此命令时:
|
|
42
|
+
1. 告诉用户需要在终端中运行:`specpow explore "主题"`
|
|
43
|
+
2. 或者尝试使用 `--json` 标志获取非交互式输出(如果支持)
|
|
44
|
+
3. 如果用户坚持在 Claude Code 中执行,使用苏格拉底式提问手动模拟探索流程
|
|
45
|
+
|
|
46
|
+
### 非交互式命令
|
|
47
|
+
|
|
48
|
+
其他所有命令(propose/apply/verify/archive/status)都是非交互式的,直接通过 Bash 执行:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 示例:执行状态检查
|
|
52
|
+
specpow status
|
|
53
|
+
|
|
54
|
+
# 示例:创建变更提案
|
|
55
|
+
specpow propose add-login
|
|
56
|
+
|
|
57
|
+
# 示例:使用特定 schema
|
|
58
|
+
specpow propose fix-bug --schema bug-fix
|
|
59
|
+
|
|
60
|
+
# 示例:验证变更
|
|
61
|
+
specpow verify --change add-login
|
|
62
|
+
|
|
63
|
+
# 示例:归档变更
|
|
64
|
+
specpow archive --change add-login
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 错误处理
|
|
68
|
+
|
|
69
|
+
命令失败时:
|
|
70
|
+
1. 展示完整错误信息
|
|
71
|
+
2. 分析可能的原因
|
|
72
|
+
3. 建议解决方案
|
|
73
|
+
4. 如果适用,运行 `specpow doctor` 进行诊断
|
|
74
|
+
|
|
75
|
+
### 工作流引导
|
|
76
|
+
|
|
77
|
+
根据当前阶段引导用户:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
[无变更] → propose → [有提案] → apply → [已实现] → verify → [已验证] → archive
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
每次执行 `specpow status` 后,根据阶段推荐下一步操作:
|
|
84
|
+
- 无活跃变更 → 建议 `/specpow-propose <name>`
|
|
85
|
+
- 有提案但工件未完成 → 建议编辑工件文件
|
|
86
|
+
- 工件已完成 → 建议 `/specpow-apply`
|
|
87
|
+
- 已实现 → 建议 `/specpow-verify`
|
|
88
|
+
- 已验证 → 建议 `/specpow-archive`
|
|
89
|
+
|
|
90
|
+
## 合理化防御表
|
|
91
|
+
|
|
92
|
+
| 你以为的 | 实际应该做的 |
|
|
93
|
+
|---------|------------|
|
|
94
|
+
| "我可以直接告诉用户命令是什么" | 用 Bash 工具执行命令并展示结果 |
|
|
95
|
+
| "这个命令太简单了,不需要执行" | 仍然执行,展示实际输出 |
|
|
96
|
+
| "用户应该自己去终端运行" | 用户要求你执行,你就执行 |
|
|
97
|
+
| "explore 是交互式的,我模拟一下" | 告诉用户需要在终端运行,或手动模拟苏格拉底式提问 |
|
|
98
|
+
|
|
99
|
+
## 红旗
|
|
100
|
+
|
|
101
|
+
以下想法意味着 STOP:
|
|
102
|
+
|
|
103
|
+
| 想法 | 现实 |
|
|
104
|
+
|------|------|
|
|
105
|
+
| "我可以假装执行了命令" | 必须真正用 Bash 执行并展示输出 |
|
|
106
|
+
| "这个命令会改变什么,让我先确认" | 直接执行,展示结果让用户确认 |
|
|
107
|
+
| "用户可能不知道这个命令" | 执行命令后解释输出含义 |
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: execution-sdd-orchestrator
|
|
3
|
+
description: SDD 编排技能。将 controller.ts 的 implement→review→fix 循环转化为宿主 Agent 可执行的指令。当执行 specpow apply 或用户要求实现变更时使用。
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
trigger: on-demand
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# SDD 编排技能
|
|
9
|
+
|
|
10
|
+
当执行 `specpow apply` 或用户要求实现变更时,按以下流程执行。
|
|
11
|
+
|
|
12
|
+
## 前置条件
|
|
13
|
+
|
|
14
|
+
- 变更提案已完成:`.specpow/openspec/changes/{change}/` 存在
|
|
15
|
+
- 任务清单已生成:`.specpow/openspec/changes/{change}/task-manifest.json`(Host-Driven 模式由 `apply.ts` 生成)
|
|
16
|
+
- Ledger 位置:`.specpow/sdd/{change}/progress.md`
|
|
17
|
+
|
|
18
|
+
## 执行流程
|
|
19
|
+
|
|
20
|
+
### 步骤 1:初始化
|
|
21
|
+
|
|
22
|
+
1. 读取 Ledger(`progress.md`),检查是否有已完成的任务(断点续跑)
|
|
23
|
+
2. 读取任务清单:`.specpow/openspec/changes/{change}/task-manifest.json`(包含增强描述和 specConstraints)
|
|
24
|
+
3. 记录 BASE commit:`git rev-parse HEAD`
|
|
25
|
+
|
|
26
|
+
### 步骤 2:逐任务执行
|
|
27
|
+
|
|
28
|
+
对每个未完成任务:
|
|
29
|
+
|
|
30
|
+
#### 2a. 创建 Brief
|
|
31
|
+
|
|
32
|
+
读取任务信息,创建 brief 文件:
|
|
33
|
+
- **路径**:`.specpow/sdd/{change}/task-{N}-brief.md`
|
|
34
|
+
- **内容**:
|
|
35
|
+
```markdown
|
|
36
|
+
# Task {N}: {title}
|
|
37
|
+
|
|
38
|
+
## 描述
|
|
39
|
+
{description}
|
|
40
|
+
|
|
41
|
+
## 涉及文件
|
|
42
|
+
{files list}
|
|
43
|
+
|
|
44
|
+
## Spec 约束
|
|
45
|
+
{spec constraints from specs/ directory}
|
|
46
|
+
|
|
47
|
+
## 输出要求
|
|
48
|
+
完成后写 Report JSON 到:`.specpow/sdd/{change}/task-{N}-report.md`
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### 2b. 派发实现者子代理
|
|
52
|
+
|
|
53
|
+
使用宿主原生 subagent 工具派发:
|
|
54
|
+
- **Prompt**:读取 brief 文件 + TDD 指令 + spec 约束
|
|
55
|
+
- **模型选择**(参考,可根据实际情况调整):
|
|
56
|
+
- ≤2 文件 + 完整 spec → `cheap`(haiku)
|
|
57
|
+
- 多文件协调 → `standard`(sonnet)
|
|
58
|
+
- 需要架构判断 → `capable`(opus)
|
|
59
|
+
- **指令**:
|
|
60
|
+
1. 读取 brief 文件
|
|
61
|
+
2. TDD 流程:RED → GREEN → REFACTOR
|
|
62
|
+
3. 遵守 spec 约束
|
|
63
|
+
4. 完成后写 Report JSON 到 reportPath
|
|
64
|
+
|
|
65
|
+
#### 2c. 检查 Report
|
|
66
|
+
|
|
67
|
+
读取 `.specpow/sdd/{change}/task-{N}-report.md`,解析 JSON:
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"status": "done|blocked|in_progress|done_with_concerns|needs_context",
|
|
71
|
+
"commits": ["sha1", "sha2"],
|
|
72
|
+
"testSummary": "X tests passed",
|
|
73
|
+
"concerns": "any issues or null",
|
|
74
|
+
"fixReport": "修复说明(仅 fix 轮次)"
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- `status === 'blocked'` → 记录到 Ledger:`Task {N}: BLOCKED — {concerns}`,跳过此任务
|
|
79
|
+
- `status === 'done'` → 继续审查
|
|
80
|
+
|
|
81
|
+
#### 2d. 生成审查包
|
|
82
|
+
|
|
83
|
+
运行 `git diff` 生成变更摘要:
|
|
84
|
+
```bash
|
|
85
|
+
BASE_COMMIT={recorded base commit}
|
|
86
|
+
HEAD_COMMIT=$(git rev-parse HEAD)
|
|
87
|
+
git diff ${BASE_COMMIT}..${HEAD_COMMIT} > .specpow/sdd/{change}/review-package.md
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### 2e. 派发审查者子代理
|
|
91
|
+
|
|
92
|
+
使用宿主原生 subagent 工具派发:
|
|
93
|
+
- **Prompt**:brief + review package + spec 约束
|
|
94
|
+
- **指令**:
|
|
95
|
+
1. 读取 brief 文件
|
|
96
|
+
2. 读取 review package(diff)
|
|
97
|
+
3. 两阶段审查:
|
|
98
|
+
- **阶段 A:Spec 合规性** — 实现是否满足 spec 要求
|
|
99
|
+
- **阶段 B:代码质量** — bug、安全问题、性能问题
|
|
100
|
+
- **阶段 C:TDD 合规** — 测试是否充分
|
|
101
|
+
4. 输出 Review JSON 到 `.specpow/sdd/{change}/review-result.json`:
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"specCompliant": true/false,
|
|
105
|
+
"qualityApproved": true/false,
|
|
106
|
+
"findings": [
|
|
107
|
+
{
|
|
108
|
+
"id": "F1",
|
|
109
|
+
"severity": "critical|important|minor",
|
|
110
|
+
"description": "...",
|
|
111
|
+
"file": "src/foo.ts",
|
|
112
|
+
"line": 42,
|
|
113
|
+
"isLoadBearing": false
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"cannotVerify": ["..."]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
**注意**:初始审查不输出 `addressed` 字段(由重审者在修复循环中填充)。
|
|
120
|
+
|
|
121
|
+
#### 2f. 运行测试
|
|
122
|
+
|
|
123
|
+
执行项目测试:
|
|
124
|
+
```bash
|
|
125
|
+
# 检测包管理器并运行测试
|
|
126
|
+
if [ -f pnpm-lock.yaml ]; then
|
|
127
|
+
pnpm test --silent
|
|
128
|
+
elif [ -f yarn.lock ]; then
|
|
129
|
+
yarn test --silent
|
|
130
|
+
else
|
|
131
|
+
npm test --silent
|
|
132
|
+
fi
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
记录测试结果:通过/失败。
|
|
136
|
+
|
|
137
|
+
#### 2g. 分析审查结果
|
|
138
|
+
|
|
139
|
+
读取 review JSON,判定:
|
|
140
|
+
- `specCompliant === true && qualityApproved === true && tests passed` → **PASS**
|
|
141
|
+
- 记录到 Ledger:`Task {N}: complete (commits {BASE}..{HEAD}, review clean)`
|
|
142
|
+
- 进入下一任务
|
|
143
|
+
- `findings.length > 0 || tests failed` → **需要修复**,进入修复循环
|
|
144
|
+
|
|
145
|
+
### 步骤 3:修复循环(最多 5 轮)
|
|
146
|
+
|
|
147
|
+
每轮:
|
|
148
|
+
|
|
149
|
+
1. **派发实现者修复(复用原始 brief)**
|
|
150
|
+
- Brief 路径不变:`.specpow/sdd/{change}/task-{N}-brief.md`(不修改 brief 文件)
|
|
151
|
+
- Open findings 通过指令传递给实现者,不写入 brief 文件
|
|
152
|
+
- **模型升级**:第 4-5 轮使用比当前高一级模型
|
|
153
|
+
- **指令**:修复 findings → 写 Report JSON 到 `task-{N}-report.md.fix-{R}`
|
|
154
|
+
|
|
155
|
+
2. **生成修复 diff**
|
|
156
|
+
```bash
|
|
157
|
+
FIX_BASE=$(git rev-parse HEAD)
|
|
158
|
+
# 实现者修复后...
|
|
159
|
+
FIX_HEAD=$(git rev-parse HEAD)
|
|
160
|
+
git diff ${FIX_BASE}..${FIX_HEAD} > .specpow/sdd/{change}/review-package.md
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
3. **派发重审者(范围限定)**
|
|
164
|
+
- **只审查修复部分**,不重新审查整个任务
|
|
165
|
+
- **指令**:对每个 finding 判定 `addressed: true/false`
|
|
166
|
+
- 输出更新后的 review JSON 到 `.specpow/sdd/{change}/re-review-result.json`
|
|
167
|
+
|
|
168
|
+
4. **运行测试**
|
|
169
|
+
|
|
170
|
+
5. **分析结果**
|
|
171
|
+
- 所有 findings addressed + tests passed → **PASS**
|
|
172
|
+
- 仍有 open findings → 继续下一轮
|
|
173
|
+
|
|
174
|
+
6. **记录到 Ledger**
|
|
175
|
+
```
|
|
176
|
+
Task {N}: fix round {R}/5 ({A} addressed, {O} open — {finding1_summary}; {finding2_summary}; commits {BASE}..{HEAD})
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**断路器**:5 轮后仍未通过 → 对每个 finding 判定:
|
|
180
|
+
- `isLoadBearing === false` → **park**(延后,记录到 Ledger)
|
|
181
|
+
- `isLoadBearing === true` → **block**(阻塞,任务标记为 BLOCKED)
|
|
182
|
+
|
|
183
|
+
### 步骤 4:完成
|
|
184
|
+
|
|
185
|
+
所有任务完成后,输出总结:
|
|
186
|
+
```
|
|
187
|
+
✅ SDD 执行完成
|
|
188
|
+
- 完成任务:X/Y
|
|
189
|
+
- 阻塞任务:Z
|
|
190
|
+
- 停放发现:N(已记录到 Ledger)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 并行执行模式
|
|
194
|
+
|
|
195
|
+
当用户指定 `--parallel` 或任务数量 ≥ 3 且无强依赖时,可启用并行执行。
|
|
196
|
+
|
|
197
|
+
### 前置条件
|
|
198
|
+
|
|
199
|
+
- 任务清单已读取
|
|
200
|
+
- 依赖分析完成(参考 `buildParallelLayers` 逻辑)
|
|
201
|
+
|
|
202
|
+
### 执行流程
|
|
203
|
+
|
|
204
|
+
#### 1. 依赖分析与分层
|
|
205
|
+
|
|
206
|
+
分析任务依赖关系,构建并行层:
|
|
207
|
+
- **文件级依赖**:多个任务修改同一文件 → 顺序执行
|
|
208
|
+
- **逻辑级依赖**:tasks.md 中显式声明的依赖
|
|
209
|
+
- **分层结果**:每层内的任务彼此独立,可并行执行
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
示例:
|
|
213
|
+
- 层 1: [T1, T2, T3] — 无依赖,可并行
|
|
214
|
+
- 层 2: [T4] — 依赖 T1 的输出
|
|
215
|
+
- 层 3: [T5, T6] — 无依赖,可并行
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### 2. 逐层并行执行
|
|
219
|
+
|
|
220
|
+
对每一层:
|
|
221
|
+
|
|
222
|
+
##### 2a. 为每个任务创建 Git Worktree
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# 为每个任务创建独立 worktree
|
|
226
|
+
BASE_COMMIT=$(git rev-parse HEAD)
|
|
227
|
+
BRANCH_NAME="specpow-parallel-{TASK_NUM}-{TIMESTAMP}"
|
|
228
|
+
WORKTREE_PATH=".specpow/sdd/{change}/.worktrees/task-{TASK_NUM}"
|
|
229
|
+
|
|
230
|
+
git worktree add -b "$BRANCH_NAME" "$WORKTREE_PATH" "$BASE_COMMIT"
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**关键**:
|
|
234
|
+
- 每个任务在独立的 worktree 中工作,消除并行竞态
|
|
235
|
+
- worktree 拥有独立的 HEAD 和工作目录
|
|
236
|
+
- 所有文件编辑和 git 操作必须在 worktree 中执行
|
|
237
|
+
|
|
238
|
+
##### 2b. 并行派发实现者子代理
|
|
239
|
+
|
|
240
|
+
使用宿主原生 subagent 工具**同时**派发多个实现者:
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
对层内的每个任务:
|
|
244
|
+
派发子代理(isolation: "worktree"):
|
|
245
|
+
- prompt: 读取 brief + TDD 指令 + spec 约束
|
|
246
|
+
- 指令:在 worktree 中工作,完成后写 report
|
|
247
|
+
- 模型选择:参考串行模式的模型选择表
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**并行派发示例**(Claude Code):
|
|
251
|
+
```
|
|
252
|
+
同时发起多个 Agent 调用:
|
|
253
|
+
- Agent 1: "Task 1 in worktree .specpow/sdd/{change}/.worktrees/task-1"
|
|
254
|
+
- Agent 2: "Task 2 in worktree .specpow/sdd/{change}/.worktrees/task-2"
|
|
255
|
+
- Agent 3: "Task 3 in worktree .specpow/sdd/{change}/.worktrees/task-3"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
##### 2c. 等待所有子代理完成
|
|
259
|
+
|
|
260
|
+
所有子代理完成后,检查各自的 report 文件。
|
|
261
|
+
|
|
262
|
+
##### 2d. 顺序合并分支
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# 按任务编号顺序合并
|
|
266
|
+
for TASK_NUM in 1 2 3; do
|
|
267
|
+
BRANCH="specpow-parallel-${TASK_NUM}-xxx"
|
|
268
|
+
git merge "$BRANCH" --no-edit
|
|
269
|
+
|
|
270
|
+
# 检查冲突
|
|
271
|
+
if [ $? -ne 0 ]; then
|
|
272
|
+
echo "冲突:任务 $TASK_NUM 合并失败"
|
|
273
|
+
# 记录到 Ledger
|
|
274
|
+
fi
|
|
275
|
+
done
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
##### 2e. 冲突检测
|
|
279
|
+
|
|
280
|
+
检查哪些文件被多个任务修改:
|
|
281
|
+
```bash
|
|
282
|
+
# 对每个完成的任务,获取变更文件列表
|
|
283
|
+
for TASK_NUM in 1 2 3; do
|
|
284
|
+
git diff --name-only "$BASE_COMMIT".."$HEAD_COMMIT"
|
|
285
|
+
done
|
|
286
|
+
|
|
287
|
+
# 如果同一文件出现在多个任务的变更列表中 → 冲突
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
##### 2f. 清理 Worktree
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# 删除 worktree 和分支
|
|
294
|
+
git worktree remove ".specpow/sdd/{change}/.worktrees/task-{TASK_NUM}" --force
|
|
295
|
+
git branch -D "specpow-parallel-{TASK_NUM}-xxx"
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
##### 2g. 运行集成测试
|
|
299
|
+
|
|
300
|
+
所有任务合并后,运行完整测试套件:
|
|
301
|
+
```bash
|
|
302
|
+
pnpm test --silent
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
##### 2h. 记录到 Ledger
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
Layer {L}: complete ({N} tasks merged, {C} conflicts detected)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### 3. 层间串行
|
|
312
|
+
|
|
313
|
+
前一层合并完成后,才开始下一层。这确保了依赖关系的正确性。
|
|
314
|
+
|
|
315
|
+
### 并行执行的注意事项
|
|
316
|
+
|
|
317
|
+
1. **绝不并行修改同一文件** — 依赖分析必须准确
|
|
318
|
+
2. **合并后必须运行完整测试** — 并行执行可能引入集成问题
|
|
319
|
+
3. **冲突是并行代价** — 显式报告冲突,而非静默丢失
|
|
320
|
+
4. **Worktree 清理必须彻底** — 即使任务失败也要清理
|
|
321
|
+
5. **断路器保护** — 如果一层中有 ≥ 50% 任务失败,停止后续层
|
|
322
|
+
|
|
323
|
+
### 何时使用并行模式
|
|
324
|
+
|
|
325
|
+
| 场景 | 推荐模式 |
|
|
326
|
+
|------|----------|
|
|
327
|
+
| 3+ 个独立任务,无文件重叠 | 并行 |
|
|
328
|
+
| 任务间有强依赖 | 串行 |
|
|
329
|
+
| CI/CD 自动化 | 并行(节省时间) |
|
|
330
|
+
| 交互式开发,需要实时反馈 | 串行(更易调试) |
|
|
331
|
+
| 多文件非依赖变更 | 并行 |
|
|
332
|
+
|
|
333
|
+
## Ledger 记录格式
|
|
334
|
+
|
|
335
|
+
每完成一个操作,**追加一行**到 `.specpow/sdd/{change}/progress.md`。
|
|
336
|
+
格式为**扁平日志行**(不是结构化 markdown),ledger.ts 用正则解析这些行。
|
|
337
|
+
|
|
338
|
+
首行固定为:
|
|
339
|
+
```
|
|
340
|
+
# SDD ledger — plan: {planFile}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
后续追加的日志行格式:
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
Task {N}: complete (commits {BASE}..{HEAD}, review clean)
|
|
347
|
+
Task {N}: complete (commits {BASE}..{HEAD}, review with parked)
|
|
348
|
+
Task {N}: fix round {R}/{MAX} ({A} addressed, {O} open — {summary1}; {summary2}; commits {RANGE})
|
|
349
|
+
Task {N}: BLOCKED — {reason}
|
|
350
|
+
Task {N}: parked — {description} — ruling: {ruling}
|
|
351
|
+
Task {N}: minor (deferred): {description}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**注意**:
|
|
355
|
+
- 每行独立,不分组、不嵌套
|
|
356
|
+
- `review clean` 表示审查通过无停放;`review with parked` 表示有停放发现
|
|
357
|
+
- fix round 行中的 summaries 用分号分隔,每个 summary 对应一个 open finding 的描述
|
|
358
|
+
- `{MAX}` 来自配置 `sdd.maxFixRounds`(默认 5)
|
|
359
|
+
|
|
360
|
+
## 关键原则
|
|
361
|
+
|
|
362
|
+
1. **文件即接口** — 所有产物通过文件传递,不占用上下文
|
|
363
|
+
2. **信任 Ledger** — 断点续跑时读取 Ledger,不信任记忆
|
|
364
|
+
3. **模型升级** — 修复轮次 4-5 升级模型,避免卡死
|
|
365
|
+
4. **范围限定重审** — 修复后只审查修复部分,提高效率
|
|
366
|
+
5. **断路器保护** — 5 轮后强制判定,避免无限循环
|