@gepeiyu/smart 0.1.1
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/LICENSE +21 -0
- package/README.md +94 -0
- package/SKILL.md +269 -0
- package/bin/smart.js +3 -0
- package/package.json +39 -0
- package/reference/file-structure.md +61 -0
- package/reference/issue-lifecycle.md +96 -0
- package/reference/smart-yaml-fields.md +66 -0
- package/scripts/smart-archive.sh +138 -0
- package/scripts/smart-env.sh +145 -0
- package/scripts/smart-guard.sh +214 -0
- package/scripts/smart-handoff.sh +127 -0
- package/scripts/smart-state.sh +365 -0
- package/smart-archive/SKILL.md +102 -0
- package/smart-build/SKILL.md +317 -0
- package/smart-design/SKILL.md +264 -0
- package/smart-hotfix/SKILL.md +200 -0
- package/smart-issue/SKILL.md +259 -0
- package/smart-tweak/SKILL.md +176 -0
- package/smart-verify/SKILL.md +232 -0
- package/src/deploy.js +47 -0
- package/src/index.js +54 -0
- package/src/init.js +80 -0
- package/src/platforms.js +20 -0
- package/src/status.js +31 -0
- package/src/uninstall.js +31 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: smart-build
|
|
3
|
+
description: "Smart 阶段 3:计划与构建。用 /smart-build 调用。制定计划并选择执行方式(subagent 或直接执行)实施。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Smart 阶段 3:计划与构建(Build)
|
|
7
|
+
|
|
8
|
+
## 前置条件
|
|
9
|
+
|
|
10
|
+
- Design Doc 已创建(阶段 2 完成)
|
|
11
|
+
- 活跃 change 存在
|
|
12
|
+
|
|
13
|
+
## 步骤
|
|
14
|
+
|
|
15
|
+
### 0. 入口状态验证(Entry Check)
|
|
16
|
+
|
|
17
|
+
执行入口验证:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
SMART_ENV="${SMART_ENV:-$(find . "$HOME"/.*/skills "$HOME/.config" "$HOME/.gemini" -path '*/smart/scripts/smart-env.sh' -type f -print -quit 2>/dev/null)}"
|
|
21
|
+
if [ -z "$SMART_ENV" ]; then
|
|
22
|
+
echo "ERROR: smart-env.sh not found. Ensure the smart skill is installed." >&2
|
|
23
|
+
return 1
|
|
24
|
+
fi
|
|
25
|
+
. "$SMART_ENV"
|
|
26
|
+
"$SMART_BASH" "$SMART_STATE" check <name> build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
验证通过后继续 Step 1。验证失败时脚本会输出具体失败原因。
|
|
30
|
+
|
|
31
|
+
**幂等性**:build 阶段所有操作可安全重复执行。读取 `.smart.yaml` 的 `phase` 字段确认仍在 build 阶段,读取 plan 文件头的 `base-ref`,再用 `grep -n '\- \[ \]' tasks.md | head -1` 找到第一个未勾选任务继续执行。已提交的任务不得重复提交。
|
|
32
|
+
|
|
33
|
+
### 1. 制定计划(Subagent Offload)
|
|
34
|
+
|
|
35
|
+
通过 subagent 创建实施计划,避免 planning skill 占用主 session 上下文。计划文件和执行反馈必须使用触发本次工作流的用户请求语言。
|
|
36
|
+
|
|
37
|
+
**Subagent 指令**:
|
|
38
|
+
|
|
39
|
+
你是实施计划专家。基于以下输入创建实施计划:
|
|
40
|
+
|
|
41
|
+
1. **立即执行:** 使用 Skill 工具加载 Superpowers `writing-plans` 技能。禁止跳过此步骤。技能加载后,ARGUMENTS 必须包含:`Language: 使用触发本次工作流的用户请求语言输出`
|
|
42
|
+
2. 读取 Design Doc(`docs/superpowers/specs/` 下的技术设计文档)
|
|
43
|
+
3. 读取 `openspec/changes/<name>/tasks.md`(任务边界)
|
|
44
|
+
4. 按技能指引创建计划
|
|
45
|
+
|
|
46
|
+
计划要求:
|
|
47
|
+
- 保存至 `docs/superpowers/plans/YYYY-MM-DD-<feature>.md`
|
|
48
|
+
- 引用设计文档,拆分为可执行任务
|
|
49
|
+
- **Plan 文件头必须包含关联元数据**:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
---
|
|
53
|
+
change: <openspec-change-name>
|
|
54
|
+
design-doc: docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md
|
|
55
|
+
base-ref: <git rev-parse HEAD before implementation>
|
|
56
|
+
---
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`base-ref` 用于验证阶段跨提交统计改动规模。创建计划时先记录当前提交:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git rev-parse HEAD
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
将计划写入文件后,返回文件路径。
|
|
66
|
+
|
|
67
|
+
**执行 subagent**:使用当前平台的 subagent 调度机制派发上述任务。
|
|
68
|
+
|
|
69
|
+
Subagent 完成后:
|
|
70
|
+
- 若返回有效文件路径且文件存在,记录为 plan
|
|
71
|
+
- 若 subagent 失败或返回路径无效,在主 session 内联加载 Superpowers `writing-plans` 技能创建计划(降级回退)
|
|
72
|
+
|
|
73
|
+
### 2. 更新计划状态并提供 plan-ready 暂停点
|
|
74
|
+
|
|
75
|
+
先记录 plan 路径:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
"$SMART_BASH" "$SMART_STATE" set <name> plan docs/superpowers/plans/YYYY-MM-DD-feature.md
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
无需手动更新 phase,阶段守卫(guard `--apply`)会在退出条件满足后推进 `phase` 字段。
|
|
82
|
+
|
|
83
|
+
计划写入后,立即提供一个新的用户决策点:
|
|
84
|
+
|
|
85
|
+
| 选项 | 行为 | 说明 |
|
|
86
|
+
|------|------|------|
|
|
87
|
+
| A | 继续执行 | 保持在当前模型中,进入 Step 3 选择工作区隔离和执行方式 |
|
|
88
|
+
| B | 暂停切换模型 | 记录 `build_pause: plan-ready`,本次 `/smart-build` 停止,用户稍后可从 `/smart` 或 `/smart-build` 恢复 |
|
|
89
|
+
|
|
90
|
+
这是用户决策点。**必须按 `smart/reference/decision-point.md` 的协议暂停并等待用户明确选择**,不得自动继续,也不得把暂停写入 `build_mode`。
|
|
91
|
+
|
|
92
|
+
用户选择继续时:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
"$SMART_BASH" "$SMART_STATE" set <name> build_pause null
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
用户选择暂停时:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
"$SMART_BASH" "$SMART_STATE" set <name> build_pause plan-ready
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
设置 `build_pause: plan-ready` 后,当前调用停止。不要选择 `isolation` 或 `build_mode`,不要加载执行技能。
|
|
105
|
+
|
|
106
|
+
### 3. 选择工作方式
|
|
107
|
+
|
|
108
|
+
如果恢复时检测到 `build_pause: plan-ready` 且 `plan` 文件存在,不要重新运行 `writing-plans`。先告知用户当前停在 plan-ready 暂停点;用户确认继续后,设置:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
"$SMART_BASH" "$SMART_STATE" set <name> build_pause null
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
然后继续本步骤选择工作区隔离和执行方式。
|
|
115
|
+
|
|
116
|
+
计划已写入当前分支。在开始执行前,**一次性询问用户**选择工作区隔离方式、执行方式、TDD 模式和代码审查模式:
|
|
117
|
+
|
|
118
|
+
**工作区隔离**:
|
|
119
|
+
|
|
120
|
+
| 选项 | 方式 | 说明 |
|
|
121
|
+
|------|------|------|
|
|
122
|
+
| A | 创建分支 | 在当前仓库创建新分支,简单快速 |
|
|
123
|
+
| B | 创建 Worktree | 隔离工作区,完全独立,适合并行开发 |
|
|
124
|
+
|
|
125
|
+
**推荐规则**:
|
|
126
|
+
- 变更涉及 ≤ 3 个文件 → 推荐 A
|
|
127
|
+
- 需要并行开发、当前分支有未提交工作 → 推荐 B
|
|
128
|
+
|
|
129
|
+
**执行方式**:
|
|
130
|
+
|
|
131
|
+
| 选项 | 技能 | 适用场景 |
|
|
132
|
+
|------|------|---------|
|
|
133
|
+
| A | Superpowers `subagent-driven-development` | 任务独立、复杂度高、需要双阶段审查 |
|
|
134
|
+
| B | Superpowers `executing-plans` | 任务简单、无子agent环境、轻量快速 |
|
|
135
|
+
|
|
136
|
+
**执行方式推荐规则**:
|
|
137
|
+
- 任务数 ≥ 3 → 推荐 A
|
|
138
|
+
- 任务数 ≤ 2 且无跨模块依赖 → 推荐 B
|
|
139
|
+
- 来自 hotfix 路径 → 推荐 B
|
|
140
|
+
|
|
141
|
+
这是用户决策点。**必须按 `smart/reference/decision-point.md` 的协议暂停并等待用户明确选择隔离方式、执行方式、TDD 模式和代码审查模式**,不得根据推荐规则自行选择 `branch` 或 `worktree`,也不得根据推荐规则自行选择执行方式、TDD 模式或代码审查模式。推荐规则只能用于说明建议,不能替代用户确认。
|
|
142
|
+
|
|
143
|
+
用户选择后,更新 `isolation`、执行方式、TDD 模式和代码审查模式相关字段:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
"$SMART_BASH" "$SMART_STATE" set <name> isolation <branch|worktree>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- 若用户选择 `executing-plans`:运行 `"$SMART_BASH" "$SMART_STATE" set <name> subagent_dispatch null`,再运行 `"$SMART_BASH" "$SMART_STATE" set <name> build_mode executing-plans`
|
|
150
|
+
- 若用户选择 `subagent-driven-development`:先确认当前平台存在可调用的真实后台 subagent / Task / multi-agent 调度能力;确认后先运行 `"$SMART_BASH" "$SMART_STATE" set <name> subagent_dispatch confirmed`,再运行 `"$SMART_BASH" "$SMART_STATE" set <name> build_mode subagent-driven-development`
|
|
151
|
+
- 若无法确认真实后台调度能力,不得写入 `build_mode: subagent-driven-development`;必须暂停等待用户改选 `executing-plans`
|
|
152
|
+
|
|
153
|
+
**TDD 模式**:
|
|
154
|
+
|
|
155
|
+
| 选项 | 含义 | 适用场景 |
|
|
156
|
+
|------|------|---------|
|
|
157
|
+
| `tdd` | 每个任务先写失败测试再写实现 | 推荐。变更涉及业务逻辑、新功能、API |
|
|
158
|
+
| `direct` | 直接实现,不强制 TDD 流程 | 变更不需要测试覆盖,或用户选择跳过测试直接写代码。hotfix/tweak preset 默认使用 `direct` |
|
|
159
|
+
|
|
160
|
+
运行 `"$SMART_BASH" "$SMART_STATE" set <name> tdd_mode <tdd|direct>`
|
|
161
|
+
|
|
162
|
+
**代码审查模式**:
|
|
163
|
+
|
|
164
|
+
| 选项 | 含义 | 适用场景 |
|
|
165
|
+
|------|------|---------|
|
|
166
|
+
| `off` | 不自动派发代码审查 | 文档、配置、文案、小范围低风险任务 |
|
|
167
|
+
| `standard` | 只在任务完成后运行一次最终轻量代码审查;若发现问题,最多自动修复一轮,然后交给用户决策 | 默认推荐,适合大多数普通改动 |
|
|
168
|
+
| `thorough` | 按批次或风险边界运行合并审查,最后再运行一次完整审查 | 高风险、多模块、架构或安全相关改动 |
|
|
169
|
+
|
|
170
|
+
运行 `"$SMART_BASH" "$SMART_STATE" set <name> review_mode <off|standard|thorough>`
|
|
171
|
+
|
|
172
|
+
`isolation` 是脚本级硬约束。full workflow 初始化时可以为 `null`,但只允许存在到本步骤之前。若保持 `null`,`build → verify` 的 guard 和 `smart-state transition build-complete` 都会失败。
|
|
173
|
+
|
|
174
|
+
`subagent_dispatch` 是脚本级硬约束。`build_mode: subagent-driven-development` 离开 build 阶段前必须同时满足 `subagent_dispatch: confirmed`,否则 `smart-guard.sh build --apply` 和 `smart-state transition build-complete` 都会失败。
|
|
175
|
+
|
|
176
|
+
`tdd_mode` 是脚本级硬约束。full workflow 离开 build 阶段前 `tdd_mode` 必须已选择为 `tdd` 或 `direct`,否则 `smart-guard.sh build --apply` 和 `smart-state transition build-complete` 都会失败。
|
|
177
|
+
|
|
178
|
+
`review_mode` 是脚本级硬约束。新建 full workflow 离开 build 阶段前 `review_mode` 必须已选择为 `off`、`standard` 或 `thorough`,否则 `smart-guard.sh build --apply` 和 `smart-state transition build-complete` 都会失败。旧状态文件若没有该字段,按兼容路径继续,但恢复时应补写该字段。
|
|
179
|
+
|
|
180
|
+
`build_mode` 默认仅 hotfix/tweak preset 使用 `direct`。full workflow 不得默认使用 `direct`。只有用户明确要求跳过计划执行技能,且你已记录显式 override 时,才允许:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
"$SMART_BASH" "$SMART_STATE" set <name> direct_override true
|
|
184
|
+
"$SMART_BASH" "$SMART_STATE" set <name> build_mode direct
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
没有 `direct_override: true` 时,full workflow 的 `build_mode=direct` 会被 guard 和状态转换同时拦截。
|
|
188
|
+
|
|
189
|
+
**执行隔离**:
|
|
190
|
+
|
|
191
|
+
- **branch**:根据 workflow 类型和当前日期推荐分支名,然后让用户确认或输入自定义名称。这是用户决策点——**必须使用当前平台可用的用户输入/确认机制暂停并等待用户明确确认或覆盖分支名**,不得跳过此步骤直接创建分支。
|
|
192
|
+
|
|
193
|
+
分支命名规范:
|
|
194
|
+
- 读取 `.smart.yaml` 的 `workflow` 字段确定前缀
|
|
195
|
+
- `workflow: full` → 推荐 `feature/YYYYMMDD/<change-name>`
|
|
196
|
+
- `workflow: hotfix` → 推荐 `hotfix/YYYYMMDD/<change-name>`
|
|
197
|
+
- `workflow: tweak` → 推荐 `tweak/YYYYMMDD/<change-name>`
|
|
198
|
+
- 日期取运行时 `date +%Y%m%d` 的结果
|
|
199
|
+
|
|
200
|
+
示例:如果 change 名称为 `fix-login-bug`,今天是 2026-06-09,则推荐 `feature/20260609/fix-login-bug`
|
|
201
|
+
|
|
202
|
+
用户确认或提供自定义分支名后,执行 `git checkout -b <branch-name>`,后续工作在新分支上进行。
|
|
203
|
+
|
|
204
|
+
- **worktree**:必须使用 Skill 工具加载 Superpowers `using-git-worktrees` 技能创建隔离工作区。禁止用普通 shell 命令或原生工具绕过该技能;如该技能不可用,停止流程并提示安装或启用 Superpowers 技能。
|
|
205
|
+
|
|
206
|
+
创建隔离后,确认计划文件可访问(分支方式天然可访问;worktree 方式需确认计划已提交)。若 worktree 模式下计划文件尚未提交,先提交计划文件再创建 worktree:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
git add docs/superpowers/plans/YYYY-MM-DD-feature.md
|
|
210
|
+
git commit -m "chore: add implementation plan"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**执行计划**:必须按 `build_mode` 的真实运行位置处理。
|
|
214
|
+
|
|
215
|
+
- `build_mode: executing-plans`:**立即执行:** 使用 Skill 工具加载 Superpowers `executing-plans` 技能。禁止跳过此步骤。若该技能不可用,停止流程并提示安装或启用对应技能,不要用普通对话替代该步骤。技能加载后,ARGUMENTS 必须包含与 Step 1 相同的 Language 约束:`Language: 使用触发本次工作流的用户请求语言输出`。按计划执行。
|
|
216
|
+
- `build_mode: subagent-driven-development`:主会话只负责协调,禁止直接编写实现代码。**立即执行:** 使用 Skill 工具加载 Superpowers `subagent-driven-development` 技能。技能加载后,读取 `smart/reference/subagent-dispatch.md` 获取 Smart 专属扩展(真实后台调度、任务隔离、勾选验证、TDD 约束、连续执行、上下文恢复),与技能工作流配合应用。若两者发生冲突,以更具体的 Smart 扩展为准。
|
|
217
|
+
- 如果当前平台没有真实后台 agent 调度能力,必须暂停并等待用户选择改用主窗口执行。用户选择改用主窗口执行后,必须先运行 `"$SMART_BASH" "$SMART_STATE" set <name> build_mode executing-plans`,再按 `build_mode: executing-plans` 分支加载 Superpowers `executing-plans` 技能。用户未明确选择前,不得继续执行任务。
|
|
218
|
+
|
|
219
|
+
**TDD 模式执行约束**:
|
|
220
|
+
|
|
221
|
+
若 `tdd_mode: tdd`:
|
|
222
|
+
- `build_mode: executing-plans`:加载执行技能后、执行第一个任务前,**立即执行:** 使用 Skill 工具加载 Superpowers `test-driven-development` 技能一次。禁止跳过此步骤。技能加载后,从第一个未勾选任务开始,对每个任务遵循已加载的 TDD Red-Green-Refactor 循环执行。不得跳过失败测试验证阶段。后续任务不再重新加载该技能,直接遵循已加载流程。若上下文压缩后恢复,重新运行本步骤加载 TDD 技能一次,然后从第一个未勾选任务继续。
|
|
223
|
+
- `build_mode: subagent-driven-development`:主会话不加载 TDD skill;TDD 约束和证据门槛已在 `smart/reference/subagent-dispatch.md` 中定义,每个后台 implementer 和修复 agent 必须自行使用 Skill 工具加载 Superpowers `test-driven-development` 技能,并遵循 Smart 注入的 TDD 硬约束。
|
|
224
|
+
|
|
225
|
+
若 `tdd_mode: direct`:按正常流程执行,不强制 TDD。
|
|
226
|
+
|
|
227
|
+
**`executing-plans` review gate**:
|
|
228
|
+
|
|
229
|
+
当 `build_mode` 为 `executing-plans` 且 `review_mode` 为 `standard` 或 `thorough` 时,在所有计划任务完成后、运行 build → verify 阶段守卫前,必须使用 Skill 工具加载 Superpowers `requesting-code-review` 技能并请求一次代码审查。`review_mode: off` 时跳过自动代码审查,不加载 `requesting-code-review`,并在验证报告草稿或 tasks.md 中记录跳过原因。
|
|
230
|
+
|
|
231
|
+
要求:
|
|
232
|
+
- `requesting-code-review` 技能必须在 `"$SMART_BASH" "$SMART_GUARD" <change-name> build --apply` 之前加载
|
|
233
|
+
- 若 `requesting-code-review` 技能不可用,跳过 review gate 但必须在 tasks.md 中记录 `<!-- review skipped: skill unavailable -->`,并继续 guard 流转
|
|
234
|
+
- CRITICAL review 发现(安全漏洞、数据丢失风险、构建/测试失败)必须先修复,不得带入 verify
|
|
235
|
+
- 非 CRITICAL review 发现如选择接受,必须在 tasks.md、commit body、验证报告草稿或其他持久产物中记录接受原因和影响范围
|
|
236
|
+
|
|
237
|
+
### 3b. 执行中异常调试(异常调试协议)
|
|
238
|
+
|
|
239
|
+
执行任务期间,只要运行程序、测试、构建或手动验证时出现崩溃、异常行为、测试失败或构建失败,必须使用 Skill 工具加载 Superpowers `systematic-debugging` 技能。在完成根因调查前,不得提出或实施源码修复。
|
|
240
|
+
|
|
241
|
+
具体调查、最小失败测试、修复验证和保持当前 change 验证闭环的要求,按 `smart/reference/debug-gate.md` 执行。
|
|
242
|
+
|
|
243
|
+
### 4. Spec 增量更新
|
|
244
|
+
|
|
245
|
+
实施过程中发现初版 spec 不完整时,按变更规模分级处理:
|
|
246
|
+
|
|
247
|
+
| 规模 | 触发条件 | 做法 |
|
|
248
|
+
|------|---------|------|
|
|
249
|
+
| 小 | 遗漏验收场景、边界条件 | 直接编辑 delta spec + design.md,追加 tasks.md 任务 |
|
|
250
|
+
| 中 | 接口变更、新增组件、数据流变化 | **使用当前平台可用的用户输入/确认机制暂停并等待用户确认后**,必须使用 Skill 工具加载 Superpowers `brainstorming` 更新 Design Doc + delta spec |
|
|
251
|
+
| 大 | 全新 capability 需求 | **必须使用当前平台可用的用户输入/确认机制暂停并等待用户确认拆分**;用户确认后,通过 `/smart-issue` 创建独立 change |
|
|
252
|
+
|
|
253
|
+
**50% 阈值判定**:以 tasks.md 初始任务总数为基准,若新增任务数超过该总数的一半,视为超出原计划范围,**必须按 `smart/reference/decision-point.md` 的协议暂停并等待用户决定是否拆分为新 change**。
|
|
254
|
+
|
|
255
|
+
创建独立 change 时必须调用 `/smart-issue`,不得直接调用 `/opsx:new`。`/smart-issue` 会同时创建 OpenSpec 产物和 `.smart.yaml`,避免新 change 脱离 Smart 状态机。
|
|
256
|
+
|
|
257
|
+
**用户选择必须包含**:
|
|
258
|
+
- 「拆分为新 change」— 通过 `/smart-issue` 创建独立 change
|
|
259
|
+
- 「继续在当前 change 内完成」— 记录范围扩展决策,更新 tasks.md 和 delta spec 后继续
|
|
260
|
+
|
|
261
|
+
**原则**:
|
|
262
|
+
- delta spec 是活文档,本阶段期间随时可修改
|
|
263
|
+
- 每次更新应提交,commit message 说明变更原因
|
|
264
|
+
- 不提前同步到 main spec,归档时统一同步
|
|
265
|
+
- 小规模增量直接改 delta spec 时,应在 commit message 中注明,便于归档时判断 design doc 漂移
|
|
266
|
+
|
|
267
|
+
### 5. 上下文管理
|
|
268
|
+
|
|
269
|
+
Build 是最长阶段,可能跨越大量任务。为支持上下文压缩后断点恢复:
|
|
270
|
+
|
|
271
|
+
- **每完成一个 task**:按当前执行分支和 `review_mode` 完成验收后再勾选对应任务并提交。`subagent-driven-development` 在 `standard` 或 `off` 时不做 per-task reviewer;在 `thorough` 时只按批次或风险边界做合并审查,不做每 task 双审查。所有模式都必须按任务唯一文本完成定向检查。可用 `grep -c '\- \[ \]' tasks.md` 检查剩余未勾选数,无需重新读取整个文件
|
|
272
|
+
- **上下文压缩后恢复**:按 `smart/reference/context-recovery.md` 执行,phase 参数为 `build`。
|
|
273
|
+
- **用户手动修改恢复**:按 `smart/reference/dirty-worktree.md` 协议处理未提交改动。该协议定义了检查步骤、归因分类和禁令。build 阶段的特殊处理:
|
|
274
|
+
1. 归因后,若 diff 暗示计划或 spec 已变化,按 Step 4「Spec 增量更新」分级处理
|
|
275
|
+
- **长任务拆分**:单任务超过 200 行代码变更时,考虑拆分为多个子任务分别提交
|
|
276
|
+
|
|
277
|
+
## 退出条件
|
|
278
|
+
|
|
279
|
+
- tasks.md 全部勾选
|
|
280
|
+
- 代码已提交
|
|
281
|
+
- 已显式运行项目对应的构建/测试命令并通过(不要只依赖 guard 自动猜测)
|
|
282
|
+
- `isolation` 已写为 `branch` 或 `worktree`
|
|
283
|
+
- `build_mode` 已写为 `subagent-driven-development`、`executing-plans` 或带显式 override 的 `direct`;若为 `subagent-driven-development`,`subagent_dispatch` 必须为 `confirmed`
|
|
284
|
+
- `tdd_mode` 已写为 `tdd` 或 `direct`
|
|
285
|
+
- `review_mode` 已写为 `off`、`standard` 或 `thorough`
|
|
286
|
+
- 若 `review_mode` 为 `standard` 或 `thorough`,已按对应模式完成代码审查,且 CRITICAL review 发现已修复或非 CRITICAL review 发现已记录接受理由;若 `review_mode: off`,已在持久产物中记录跳过自动代码审查的原因
|
|
287
|
+
- **阶段守卫**:运行 `"$SMART_BASH" "$SMART_GUARD" <change-name> build --apply`,全部 PASS 后由守卫推进到 `phase: verify`(此步骤更新 `phase` 字段,与 `auto_transition` 无关)
|
|
288
|
+
|
|
289
|
+
Guard 会优先读取项目配置中的命令:
|
|
290
|
+
|
|
291
|
+
```yaml
|
|
292
|
+
build_command: <build command>
|
|
293
|
+
verify_command: <verify command>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
配置位置可为 change 的 `.smart.yaml`,也可为仓库根目录的 `.smart/config.yaml`。
|
|
297
|
+
未配置时才回退到 `npm run build`、Maven 或 Cargo 的默认探测。构建失败时 guard 会打印失败命令输出,作为排查证据。
|
|
298
|
+
|
|
299
|
+
退出前运行阶段守卫推进 phase(此步骤与 `auto_transition` 无关):
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
"$SMART_BASH" "$SMART_GUARD" <change-name> build --apply
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
状态文件自动更新为 `phase: verify`、`verify_result: pending`。
|
|
306
|
+
|
|
307
|
+
## 自动衔接下一阶段
|
|
308
|
+
|
|
309
|
+
按 `smart/reference/auto-transition.md` 执行。关键命令:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
"$SMART_BASH" "$SMART_STATE" next <change-name>
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
- `NEXT: auto` → 调用 `SKILL` 指向的 skill 进入下一阶段
|
|
316
|
+
- `NEXT: manual` → 不要调用下一 skill,按 `HINT` 提示用户手动运行 `/<SKILL>`
|
|
317
|
+
- `NEXT: done` → 流程已完成,无需继续
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: smart-design
|
|
3
|
+
description: "Smart 阶段 2:深度设计。用 /smart-design 调用。通过 brainstorming 产出 Design Doc 和 delta spec。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Smart 阶段 2:深度设计(Design)
|
|
7
|
+
|
|
8
|
+
## 前置条件
|
|
9
|
+
|
|
10
|
+
- 活跃 change 已存在(proposal.md、design.md、tasks.md)
|
|
11
|
+
- 无 Design Doc(`docs/superpowers/specs/` 下无对应文件)
|
|
12
|
+
|
|
13
|
+
## 步骤
|
|
14
|
+
|
|
15
|
+
### 0. 入口状态验证(Entry Check)
|
|
16
|
+
|
|
17
|
+
执行入口验证:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
SMART_ENV="${SMART_ENV:-$(find . "$HOME"/.*/skills "$HOME/.config" "$HOME/.gemini" -path '*/smart/scripts/smart-env.sh' -type f -print -quit 2>/dev/null)}"
|
|
21
|
+
if [ -z "$SMART_ENV" ]; then
|
|
22
|
+
echo "ERROR: smart-env.sh not found. Ensure the smart skill is installed." >&2
|
|
23
|
+
return 1
|
|
24
|
+
fi
|
|
25
|
+
. "$SMART_ENV"
|
|
26
|
+
"$SMART_BASH" "$SMART_STATE" check <name> design
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
验证通过后继续 Step 1。验证失败时脚本会输出具体失败原因。
|
|
30
|
+
|
|
31
|
+
**幂等性**:所有 design 阶段操作可以安全重试。如果 `handoff_context` 和 `handoff_hash` 已存在,先确认它们与当前产物一致再决定是否重新生成。
|
|
32
|
+
|
|
33
|
+
### 1a. 生成 OpenSpec → Superpowers 交接包
|
|
34
|
+
|
|
35
|
+
**必须由脚本生成,不允许 agent 临场手写 summary 代替。**
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
"$SMART_BASH" "$SMART_HANDOFF" <change-name> design --write
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
脚本会根据 change `.smart.yaml` 的 `context_compression` 快照生成并记录交接包。
|
|
42
|
+
|
|
43
|
+
默认 `context_compression: off` 时生成:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
openspec/changes/<name>/.smart/handoff/design-context.json
|
|
47
|
+
openspec/changes/<name>/.smart/handoff/design-context.md
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
启用 beta(项目 `.smart/config.yaml` 中 `context_compression: beta`,创建 change 时快照进入 `.smart.yaml`)时生成:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
openspec/changes/<name>/.smart/handoff/spec-context.json
|
|
54
|
+
openspec/changes/<name>/.smart/handoff/spec-context.md
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
并在 `.smart.yaml` 写入:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
handoff_context: openspec/changes/<name>/.smart/handoff/design-context.json
|
|
61
|
+
handoff_hash: <sha256>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
默认交接包是 **compact 可追溯摘录**,不是 agent summary:
|
|
65
|
+
- `design-context.json`:机器索引,包含 change、phase、canonical spec、source paths、hash
|
|
66
|
+
- `design-context.md`:供 Superpowers 阅读的上下文,包含脚本标记、source path、line range、sha256、确定性摘录
|
|
67
|
+
- 超出摘录预算时标记 `[TRUNCATED]`,并保留 Full source 路径
|
|
68
|
+
|
|
69
|
+
beta 交接包是 **结构化 spec projection**,用于减少 OpenSpec 原文 token 占用但避免实现漂移:
|
|
70
|
+
- `spec-context.json`:机器索引,包含 change、phase、mode=beta、source paths、context_hash、files 角色
|
|
71
|
+
- `spec-context.md`:供 Superpowers 阅读的紧凑上下文,verbatim 投影 delta spec 文件并按 hash 引用支撑产物
|
|
72
|
+
- OpenSpec delta spec 仍是 canonical spec;projection 缺失或过期时必须重新生成或读取源 spec,不得用 agent summary 替代
|
|
73
|
+
|
|
74
|
+
如确实需要全文上下文,可显式运行:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
"$SMART_BASH" "$SMART_HANDOFF" <change-name> design --write --full
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
交接包来源来自 OpenSpec issue 阶段产物:
|
|
81
|
+
- `proposal.md`:目标、动机、范围、非目标
|
|
82
|
+
- `design.md`:高层架构决策、方案约束
|
|
83
|
+
- `tasks.md`:初始任务边界
|
|
84
|
+
- `specs/*/spec.md`:delta 能力规格
|
|
85
|
+
|
|
86
|
+
### 1b. 执行 Brainstorming(带上下文)
|
|
87
|
+
|
|
88
|
+
**立即执行:** 使用 Skill 工具加载 Superpowers `brainstorming` 技能。禁止跳过此步骤。
|
|
89
|
+
|
|
90
|
+
技能加载时,ARGUMENTS 必须包含:
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
Language: 使用触发本次工作流的用户请求语言输出
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
技能加载后,按其指引使用以下上下文:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
Change: <change-name>
|
|
100
|
+
OpenSpec Context Pack: openspec/changes/<name>/.smart/handoff/design-context.md
|
|
101
|
+
Machine handoff: openspec/changes/<name>/.smart/handoff/design-context.json
|
|
102
|
+
|
|
103
|
+
如 context_compression: beta,则使用:
|
|
104
|
+
OpenSpec Context Pack: openspec/changes/<name>/.smart/handoff/spec-context.md
|
|
105
|
+
Machine handoff: openspec/changes/<name>/.smart/handoff/spec-context.json
|
|
106
|
+
|
|
107
|
+
OpenSpec 产物是上游事实源,但不得用“跳过重复上下文探索”削弱 Superpowers `brainstorming` 的澄清流程。
|
|
108
|
+
你的任务是基于交接包做深度技术设计:实现方案、技术风险、测试策略、边界条件。
|
|
109
|
+
如发现目标、范围、非目标、验收场景或关键约束仍不清楚,必须先继续提问并形成设计方案,不得只进行一轮问答就创建 Design Doc。
|
|
110
|
+
不要重写 proposal/spec;如发现 OpenSpec delta spec 缺少验收场景,只能提出 Spec Patch,并回写 OpenSpec delta spec;不要在 Design Doc 中创建第二份需求 spec。Spec Patch 仅限于补充验收场景、修正歧义描述或添加边界条件,不得大幅重写 delta spec 的结构或范围——如需大幅修改,应标记为设计发现并回到 brainstorming 确认。
|
|
111
|
+
|
|
112
|
+
Design Doc frontmatter 必须最小化,只包含:
|
|
113
|
+
---
|
|
114
|
+
smart_change: <change-name>
|
|
115
|
+
role: technical-design
|
|
116
|
+
canonical_spec: openspec
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
按 Superpowers `brainstorming` 技能原流程推进:澄清问题、2-3 个方案、分段确认设计。不得提前写入 Design Doc。
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
禁止在未加载该技能的情况下继续。
|
|
123
|
+
|
|
124
|
+
如 Superpowers `brainstorming` 技能不可用,停止流程并提示安装或启用 Superpowers 技能,不要用普通对话替代该步骤。
|
|
125
|
+
|
|
126
|
+
技能加载后,按其指引产出设计方案(以对话形式呈现):
|
|
127
|
+
- 技术方案:架构、数据流、关键技术选型与风险
|
|
128
|
+
- 测试策略
|
|
129
|
+
- 需求/范围缺口与需回写的 Spec Patch
|
|
130
|
+
- 如需补充验收场景,标明将回写的 delta spec 变更
|
|
131
|
+
|
|
132
|
+
brainstorming 阶段不写入 Design Doc 文件,仅产出设计方案供 Step 1c 用户确认。确认后才创建 `docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md` 并回写 delta spec。
|
|
133
|
+
|
|
134
|
+
但为了上下文压缩恢复,brainstorming 过程中必须增量更新 `brainstorm-summary.md`。每轮澄清或方案迭代后,只要产生新的已确认事实、关键约束、候选方案、取舍/风险、测试策略或 Spec Patch 候选,就更新该文件;未确认内容必须标注为“待确认”或“候选”。该文件是恢复检查点,不是 Design Doc,也不得替代 Step 1c 的用户确认。
|
|
135
|
+
|
|
136
|
+
### 1c. 用户确认设计方案(阻塞点)
|
|
137
|
+
|
|
138
|
+
brainstorming 产出设计方案后,**必须按 `smart/reference/decision-point.md` 的协议暂停并等待用户明确确认设计方案**。不得在用户确认前创建最终 Design Doc、写入 `design_doc`、运行 design guard,或进入 `/smart-build`。
|
|
139
|
+
|
|
140
|
+
暂停时只展示必要摘要:
|
|
141
|
+
- 采用的技术方案
|
|
142
|
+
- 关键取舍与风险
|
|
143
|
+
- 测试策略
|
|
144
|
+
- 如有 Spec Patch,列出将回写的 delta spec 变更
|
|
145
|
+
|
|
146
|
+
用户明确确认后,才继续 Step 2。若用户要求调整,继续 brainstorming 迭代,直到用户确认。
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
### 1d. Brainstorming 检查点定稿
|
|
150
|
+
|
|
151
|
+
用户确认设计方案后,在创建 Design Doc 前,创建或更新已增量维护的检查点文件,将其定稿为确认后的设计方案摘要:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
mkdir -p openspec/changes/<name>/.smart/handoff
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`openspec/changes/<name>/.smart/handoff/brainstorm-summary.md` 结构:
|
|
158
|
+
|
|
159
|
+
```markdown
|
|
160
|
+
# Brainstorm Summary
|
|
161
|
+
|
|
162
|
+
- Change: <change-name>
|
|
163
|
+
- Date: <YYYY-MM-DD>
|
|
164
|
+
|
|
165
|
+
## 确认的技术方案
|
|
166
|
+
|
|
167
|
+
<用户确认的方案摘要>
|
|
168
|
+
|
|
169
|
+
## 关键取舍与风险
|
|
170
|
+
|
|
171
|
+
<主要取舍和风险>
|
|
172
|
+
|
|
173
|
+
## 测试策略
|
|
174
|
+
|
|
175
|
+
<测试方法概述>
|
|
176
|
+
|
|
177
|
+
## Spec Patch
|
|
178
|
+
|
|
179
|
+
<将回写的 delta spec 变更,无则写"无">
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**上下文压缩说明**:每次增量更新 `brainstorm-summary.md` 后,都是相对安全的压缩恢复点。Brainstorming 完成后,如上下文窗口紧张,应优先在此处进行压缩。压缩后重新加载以下文件继续 Step 2:
|
|
183
|
+
- `openspec/changes/<name>/.smart/handoff/brainstorm-summary.md`
|
|
184
|
+
- `openspec/changes/<name>/.smart/handoff/design-context.md`(或 beta 模式的 `spec-context.md`)
|
|
185
|
+
- `openspec/changes/<name>/.smart/handoff/design-context.json`(或 beta 模式的 `spec-context.json`)
|
|
186
|
+
|
|
187
|
+
### 1e. 主动式上下文压缩
|
|
188
|
+
|
|
189
|
+
完成 Step 1d 并确认 `brainstorm-summary.md` 已写入后,进入 Design Doc 创建前的主动式上下文压缩。此时 OpenSpec 交接包、brainstorming 决策和待确认项都已落盘,应主动释放前面读取 Spec 和 brainstorming 消耗的上下文,为 Step 2 及后续 Build 阶段保留窗口。
|
|
190
|
+
|
|
191
|
+
执行规则:
|
|
192
|
+
- 如果当前平台提供原生上下文压缩/清理机制(例如宿主 Agent 的 compact/compaction 命令、工具或 UI 操作),必须在这里触发一次主动压缩;不要尝试用 shell 脚本伪造压缩命令。
|
|
193
|
+
- 压缩恢复提示必须包含 change 名称、当前步骤(Design Step 2)、以及上方三类需重新加载的 handoff 文件。
|
|
194
|
+
- 如果当前平台无法由 agent 程序化触发压缩,必须暂停并提示用户在宿主平台执行手动压缩;用户确认无法压缩或要求继续时,才继续 Step 2。
|
|
195
|
+
|
|
196
|
+
### 2. 创建 Design Doc
|
|
197
|
+
|
|
198
|
+
基于 brainstorming 对话的完整上下文(仍在主 session 中),创建 Design Doc。
|
|
199
|
+
|
|
200
|
+
Design Doc frontmatter 必须最小化:
|
|
201
|
+
|
|
202
|
+
```yaml
|
|
203
|
+
---
|
|
204
|
+
smart_change: <change-name>
|
|
205
|
+
role: technical-design
|
|
206
|
+
canonical_spec: openspec
|
|
207
|
+
---
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
将 Design Doc 写入 `docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md`。
|
|
211
|
+
如需回写 delta spec(Spec Patch),同时编辑对应的 `specs/*/spec.md`。
|
|
212
|
+
|
|
213
|
+
**上下文压缩恢复**:若上下文已被压缩,从 `brainstorm-summary.md` + handoff 上下文恢复。若用户尚未确认设计方案,回到 Step 1b/1c 继续 brainstorming;若用户已确认,继续创建 Design Doc。brainstorm-summary.md 是压缩恢复的落盘点,不是 Design Doc 的唯一输入——创建时应尽可能利用恢复后的完整上下文。
|
|
214
|
+
|
|
215
|
+
### 3. 更新 Smart 状态
|
|
216
|
+
|
|
217
|
+
先记录 design_doc 路径。如果 Spec Patch 回写了 delta spec(新增或修改了 `specs/*/spec.md`),必须重新生成 handoff 以更新 hash:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# 记录 design_doc 路径
|
|
221
|
+
"$SMART_BASH" "$SMART_STATE" set <name> design_doc docs/superpowers/specs/YYYY-MM-DD-topic-design.md
|
|
222
|
+
|
|
223
|
+
# 如有 delta spec 变更,重新生成 handoff(更新 hash)
|
|
224
|
+
"$SMART_BASH" "$SMART_HANDOFF" <change-name> design --write
|
|
225
|
+
|
|
226
|
+
# 阶段守卫推进 phase 到下一阶段
|
|
227
|
+
"$SMART_BASH" "$SMART_GUARD" <change-name> design --apply
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
如果没有 delta spec 变更,跳过 handoff 重新生成步骤。状态文件自动更新,无需手动编辑其他字段。
|
|
231
|
+
|
|
232
|
+
## 退出条件
|
|
233
|
+
|
|
234
|
+
- Design Doc 已创建并保存
|
|
235
|
+
- Design Doc frontmatter 包含 `smart_change`、`role: technical-design`、`canonical_spec: openspec`
|
|
236
|
+
- `handoff_context` 和 `handoff_hash` 已写入 `.smart.yaml`(由 guard 强制校验)
|
|
237
|
+
- `handoff_hash` 与当前 OpenSpec issue 阶段产物一致(由 guard 强制校验)
|
|
238
|
+
- `design-context.md` 或 beta `spec-context.md` 必须是脚本生成,且包含 source path、mode、sha256 等可追溯标记(由 guard 强制校验)
|
|
239
|
+
- beta 模式下,`spec-context.json` 必须结构合法且引用当前源文件(由 guard 强制校验)
|
|
240
|
+
- 如有新能力或补充验收场景,OpenSpec delta spec 已创建/更新
|
|
241
|
+
- `design_doc` 已写入 `.smart.yaml`
|
|
242
|
+
- **阶段守卫**:运行 `"$SMART_BASH" "$SMART_GUARD" <change-name> design --apply`,全部 PASS 后由守卫推进到 `phase: build`(此步骤更新 `phase` 字段,与 `auto_transition` 无关)
|
|
243
|
+
|
|
244
|
+
退出前必须使用 `--apply`:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
"$SMART_BASH" "$SMART_GUARD" <change-name> design --apply
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## 上下文压缩恢复
|
|
251
|
+
|
|
252
|
+
按 `smart/reference/context-recovery.md` 执行,phase 参数为 `design`。
|
|
253
|
+
|
|
254
|
+
## 自动衔接下一阶段
|
|
255
|
+
|
|
256
|
+
按 `smart/reference/auto-transition.md` 执行。关键命令:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
"$SMART_BASH" "$SMART_STATE" next <change-name>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
- `NEXT: auto` → 调用 `SKILL` 指向的 skill 进入下一阶段
|
|
263
|
+
- `NEXT: manual` → 不要调用下一 skill,按 `HINT` 提示用户手动运行 `/<SKILL>`
|
|
264
|
+
- `NEXT: done` → 流程已完成,无需继续
|