@peterxiaoyang/superspec 0.1.2 → 0.1.4
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/README.md +181 -116
- package/dist/src/cli.js +2 -2
- package/dist/src/cli_args.d.ts +2 -0
- package/dist/src/cli_args.js +28 -10
- package/dist/src/core.js +5 -5
- package/dist/src/doctor.d.ts +44 -0
- package/dist/src/doctor.js +230 -0
- package/dist/src/evidence.d.ts +1 -0
- package/dist/src/evidence.js +7 -0
- package/dist/src/gates.d.ts +1 -0
- package/dist/src/gates.js +39 -10
- package/dist/src/git.js +2 -2
- package/dist/src/init_cli.d.ts +2 -1
- package/dist/src/init_cli.js +31 -17
- package/dist/src/self_update.d.ts +14 -0
- package/dist/src/self_update.js +56 -0
- package/dist/src/util.d.ts +11 -0
- package/dist/src/util.js +218 -2
- package/dist/superspec.d.ts +2 -0
- package/dist/superspec.js +45 -5
- package/package.json +2 -2
- package/templates/workflow/skills/superspec-apply/SKILL.md +16 -6
- package/templates/workflow/skills/superspec-archive/SKILL.md +10 -2
- package/templates/workflow/skills/superspec-explore/SKILL.md +15 -4
- package/templates/workflow/skills/superspec-propose/SKILL.md +19 -9
- package/templates/workflow/skills/superspec-review/SKILL.md +15 -5
package/README.md
CHANGED
|
@@ -2,196 +2,261 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@peterxiaoyang/superspec)
|
|
4
4
|
[](https://nodejs.org)
|
|
5
|
-
[](https://github.com/Fission-AI/OpenSpec)
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> SuperSpec 是一套“先想清楚,再动手”的工作流。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
它解决的是一个很常见的问题:AI 编程工具写代码很快,但有时候还没搞清楚需求、现有代码和测试边界,就已经开始改文件了。
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
它做的是在 OpenSpec 现有变更生命周期之上,再加一层更强的执行纪律:
|
|
11
|
+
SuperSpec 会把一次需求变更拆成 5 步:
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- 先经过多角色审查,再允许宣布“完成”
|
|
18
|
-
- 先确认归档保全完整,再真正归档
|
|
13
|
+
```text
|
|
14
|
+
探索需求 -> 写方案 -> 做实现 -> 做审查 -> 归档收尾
|
|
15
|
+
```
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
这样做的目的很简单:
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
- 改代码前先弄清楚现状
|
|
20
|
+
- 写实现前先有方案和任务
|
|
21
|
+
- 任务完成前先有测试或验证记录
|
|
22
|
+
- 宣布完成前先经过审查
|
|
23
|
+
- 归档时保留关键过程记录
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
- **把执行约束收敛成可复用的叠加层**
|
|
26
|
-
- **让阶段推进依赖证据,而不是模型一句“done”**
|
|
25
|
+
## 适合谁
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
适合已经在用 AI 编程工具或命令行代理做项目开发,并希望流程更稳一点的团队或个人。
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
如果你遇到过这些情况,SuperSpec 会有帮助:
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
- 需求还没说清楚,AI 就开始写代码
|
|
32
|
+
- 方案写得很粗,后面实现时靠猜
|
|
33
|
+
- 测试只跑了命令,但没人说明它证明了什么
|
|
34
|
+
- 代码写完后缺少真正的审查
|
|
35
|
+
- 过几天想回看当时为什么这么改,却找不到过程记录
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
- 测试在,但没有证明真正重要的东西
|
|
36
|
-
- 任务打勾了,但缺少强校验
|
|
37
|
-
- 主线程自己写、自己审、自己宣布通过
|
|
38
|
-
- 归档做了,但辅助证据已经散了
|
|
37
|
+
如果你只是想让 AI 快速改一个很小的文件,且不需要完整方案、审查和记录,那 SuperSpec 可能会显得偏重。
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
## 和 OpenSpec 有什么区别
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
一句话区别:
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
```text
|
|
44
|
+
OpenSpec 管“这次要改什么”。
|
|
45
|
+
SuperSpec 管“AI 应该怎样把这次改动做稳”。
|
|
46
|
+
```
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
更具体一点:
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
| 问题 | OpenSpec 主要负责 | SuperSpec 额外补上 |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| 这次变更是什么 | 方案、规格、设计、任务和归档 | 要求 AI 在写方案前先调查现状 |
|
|
53
|
+
| 方案怎么写 | 提供标准的变更文档结构 | 要求方案前后有范围、风险、业务约束和测试思路 |
|
|
54
|
+
| 代码怎么做 | 记录任务清单和完成状态 | 要求按任务实现,并留下测试或验证记录 |
|
|
55
|
+
| 做完怎么算稳 | 可以校验规格和归档 | 增加代码审查、架构审查、反方审查和最终验证 |
|
|
56
|
+
| 以后怎么追溯 | 保留 OpenSpec 的变更文档 | 额外保留探索、测试、审查和收尾记录 |
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
举个例子:
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- `test-contract.md`:把测试覆盖范围、测试编号、约束映射和验证责任提前写清楚
|
|
60
|
+
OpenSpec 会帮你记录“要增加登录功能、需要哪些规格、设计和任务”。
|
|
61
|
+
SuperSpec 会进一步要求 AI 先看看现有登录/权限代码在哪里、哪些业务规则不能破坏、哪些场景必须测试、实现后要经过哪些审查,最后再归档。
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
所以 SuperSpec 不是 OpenSpec 的替代品。它更像是 OpenSpec 外面的一层执行纪律,专门约束 AI 编程工具不要跳过关键步骤。
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
## 快速开始
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
### 1. 安装
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
- `code-reviewer`
|
|
69
|
-
- `verifier`
|
|
69
|
+
```bash
|
|
70
|
+
npm install -g @peterxiaoyang/superspec@latest
|
|
71
|
+
```
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
需要 Node.js `>= 20.19.0`。
|
|
72
74
|
|
|
73
|
-
###
|
|
75
|
+
### 2. 初始化当前项目
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
进入你的项目根目录,然后运行:
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
- 可归档条件与归档保全条件
|
|
79
|
+
```bash
|
|
80
|
+
superspec init --scope project
|
|
81
|
+
```
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
这条命令的意思是:把 SuperSpec 当前可用的工作流入口安装到项目里。
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
Windows PowerShell 如果拦截 npm 的 `.ps1` 脚本,请改用:
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
```powershell
|
|
88
|
+
superspec.cmd init --scope project
|
|
89
|
+
```
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
- 证据:保存 RED/GREEN、审查、验证、确认等过程证据
|
|
90
|
-
- 审查输出:保存各角色的审查结果和主线程的汇总结论
|
|
91
|
-
- 状态文件:保存当前 gate、指纹和阶段状态,便于恢复和重算
|
|
92
|
-
- ledger:保存关键事件记录,方便追溯流程推进过程
|
|
93
|
-
- 归档保全元数据:确保归档前后能核对辅助目录是否完整保留
|
|
91
|
+
### 3. 按步骤使用
|
|
94
92
|
|
|
95
|
-
|
|
93
|
+
在你使用的 AI 编程工具或 CLI 里,按下面的阶段入口推进。不同工具的触发方式可以不同,但入口名和顺序保持一致。
|
|
96
94
|
|
|
97
|
-
|
|
95
|
+
开始时先探索需求:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
使用 superspec-explore,帮我梳理这个需求:……
|
|
99
|
+
```
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
探索完成后,写正式方案:
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
```text
|
|
104
|
+
使用 superspec-propose,把刚才的探索结果整理成方案。
|
|
105
|
+
```
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
方案确认后,开始实现:
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
使用 superspec-apply,按任务实现。
|
|
111
|
+
```
|
|
106
112
|
|
|
107
|
-
|
|
113
|
+
实现完成后,审查:
|
|
108
114
|
|
|
109
|
-
|
|
115
|
+
```text
|
|
116
|
+
使用 superspec-review,检查实现、测试和风险。
|
|
117
|
+
```
|
|
110
118
|
|
|
111
|
-
|
|
119
|
+
审查通过后,归档:
|
|
112
120
|
|
|
113
|
-
```
|
|
114
|
-
|
|
121
|
+
```text
|
|
122
|
+
使用 superspec-archive,归档这个变更。
|
|
115
123
|
```
|
|
116
124
|
|
|
125
|
+
## 五个入口分别做什么
|
|
117
126
|
|
|
118
|
-
|
|
127
|
+
| 入口 | 什么时候用 | 它会要求做什么 |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `superspec-explore` | 需求刚开始时 | 读代码、查现状、整理范围和风险;这一步不改业务代码 |
|
|
130
|
+
| `superspec-propose` | 需求已经清楚后 | 写正式方案、规格、设计和任务,并提前规划测试 |
|
|
131
|
+
| `superspec-apply` | 方案通过后 | 按任务实现代码,记录测试或验证结果 |
|
|
132
|
+
| `superspec-review` | 实现完成后 | 做代码审查、架构审查、反方审查和最终验证 |
|
|
133
|
+
| `superspec-archive` | 审查通过后 | 用 OpenSpec 完成归档,并检查关键记录是否保留 |
|
|
119
134
|
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
你日常主要记住这五个入口就够了。
|
|
136
|
+
|
|
137
|
+
## 它会多保存哪些记录
|
|
138
|
+
|
|
139
|
+
SuperSpec 会在每次变更下面保存一些辅助记录,方便后续追溯。
|
|
140
|
+
|
|
141
|
+
主要包括:
|
|
142
|
+
|
|
143
|
+
- 探索记录:这次需求是什么、当前代码是什么情况、有哪些风险
|
|
144
|
+
- 业务约束:哪些业务规则不能被改坏
|
|
145
|
+
- 测试约定:哪些场景必须验证
|
|
146
|
+
- 实现记录:每个任务怎么验证通过
|
|
147
|
+
- 审查记录:谁检查了什么、发现了什么、最后为什么通过或退回
|
|
148
|
+
|
|
149
|
+
这些记录默认放在:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
openspec/changes/<变更ID>/.superspec/
|
|
122
153
|
```
|
|
123
154
|
|
|
124
|
-
|
|
155
|
+
这里的 `<变更ID>` 就是一次需求变更的名字。
|
|
156
|
+
|
|
157
|
+
`.superspec/` 要不要提交到 git,由你的团队决定。
|
|
158
|
+
如果不提交,删掉后就没有 git 历史可以恢复。
|
|
159
|
+
|
|
160
|
+
## 重要边界
|
|
161
|
+
|
|
162
|
+
SuperSpec 能让流程更规范,但它不是安全锁。
|
|
163
|
+
|
|
164
|
+
它能帮助你:
|
|
165
|
+
|
|
166
|
+
- 减少 AI 还没想清楚就改代码的情况
|
|
167
|
+
- 让测试、审查和用户确认留下记录
|
|
168
|
+
- 在进入下一步前提醒缺少什么
|
|
169
|
+
- 让一次变更之后更容易回看原因
|
|
170
|
+
|
|
171
|
+
它不能保证:
|
|
125
172
|
|
|
126
|
-
|
|
173
|
+
- 阻止人手动绕过流程直接改文件
|
|
174
|
+
- 阻止人删除过程记录
|
|
175
|
+
- 阻止恶意伪造记录
|
|
176
|
+
- 替代正式的安全审计、合规审计或法律证明
|
|
177
|
+
|
|
178
|
+
也就是说,SuperSpec v1 是“流程纪律工具”,不是“强制安全系统”。
|
|
179
|
+
|
|
180
|
+
## 常用命令
|
|
181
|
+
|
|
182
|
+
查看当前 SuperSpec CLI 版本:
|
|
127
183
|
|
|
128
184
|
```bash
|
|
129
|
-
superspec
|
|
185
|
+
superspec --version
|
|
130
186
|
```
|
|
131
187
|
|
|
132
|
-
|
|
188
|
+
安装到当前项目:
|
|
133
189
|
|
|
134
190
|
```bash
|
|
135
|
-
superspec init
|
|
191
|
+
superspec init --scope project
|
|
136
192
|
```
|
|
137
193
|
|
|
138
|
-
|
|
194
|
+
更新当前项目里的 SuperSpec 入口:
|
|
139
195
|
|
|
140
196
|
```bash
|
|
141
|
-
superspec
|
|
197
|
+
superspec update --scope project
|
|
142
198
|
```
|
|
143
199
|
|
|
144
|
-
|
|
145
|
-
如果项目里还没有对应的 OpenSpec 初始化内容,且本机可用 `openspec` CLI,SuperSpec 会自动尝试执行:
|
|
200
|
+
这条命令会先通过 npm 更新全局 `@peterxiaoyang/superspec`,再用新版本更新当前项目里的入口文件。只想使用当前已安装包更新项目文件时,可以运行:
|
|
146
201
|
|
|
147
|
-
|
|
148
|
-
|
|
202
|
+
```bash
|
|
203
|
+
superspec update --scope project --local-only
|
|
204
|
+
```
|
|
149
205
|
|
|
150
|
-
|
|
206
|
+
卸载当前项目里的 SuperSpec 入口:
|
|
151
207
|
|
|
152
|
-
|
|
208
|
+
```bash
|
|
209
|
+
superspec uninstall --scope project
|
|
210
|
+
```
|
|
153
211
|
|
|
154
|
-
|
|
212
|
+
这些命令默认不会删除已经生成的 `.superspec/` 过程记录。
|
|
155
213
|
|
|
156
|
-
|
|
157
|
-
- `superspec-propose`
|
|
158
|
-
- `superspec-apply`
|
|
159
|
-
- `superspec-review`
|
|
160
|
-
- `superspec-archive`
|
|
214
|
+
诊断全局安装、PATH、OpenSpec 依赖和 npm bin 指向问题:
|
|
161
215
|
|
|
162
|
-
|
|
216
|
+
```bash
|
|
217
|
+
superspec doctor
|
|
218
|
+
```
|
|
163
219
|
|
|
164
|
-
|
|
220
|
+
## 进阶信息
|
|
165
221
|
|
|
166
|
-
|
|
222
|
+
以当前内置的 Codex 适配器为例,初始化后项目里会出现这些入口文件:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
.codex/
|
|
226
|
+
skills/superspec-explore/
|
|
227
|
+
skills/superspec-propose/
|
|
228
|
+
skills/superspec-apply/
|
|
229
|
+
skills/superspec-review/
|
|
230
|
+
skills/superspec-archive/
|
|
231
|
+
```
|
|
167
232
|
|
|
168
|
-
|
|
169
|
-
- `.superspec/artifacts/business-invariants.md`:记录本次变更必须守住的业务不变量
|
|
170
|
-
- `.superspec/artifacts/test-contract.md`:记录测试覆盖矩阵、测试编号和约束映射
|
|
171
|
-
- `.superspec/evidence/...`:保存测试、审查、验证、用户确认等证据文件
|
|
172
|
-
- `.superspec/superspec-state.json`:保存 guard 重算后的状态摘要和指纹
|
|
173
|
-
- `.superspec/ledger.jsonl`:保存关键流程事件,便于审计和追溯
|
|
233
|
+
SuperSpec 内部还有一些检查命令,例如:
|
|
174
234
|
|
|
175
|
-
|
|
235
|
+
```bash
|
|
236
|
+
superspec guard check-init --change <变更ID>
|
|
237
|
+
superspec guard check-apply-ready --change <变更ID>
|
|
238
|
+
superspec guard check-review-ready --change <变更ID>
|
|
239
|
+
superspec guard check-archive-ready --change <变更ID>
|
|
240
|
+
```
|
|
176
241
|
|
|
177
|
-
|
|
178
|
-
- `user` scope
|
|
179
|
-
- 基于清单的 `update`
|
|
180
|
-
- 基于清单的 `uninstall`
|
|
242
|
+
普通使用者通常不需要手动运行这些命令;对应的阶段入口会在需要时使用它们。
|
|
181
243
|
|
|
182
|
-
|
|
244
|
+
如果你要开发 SuperSpec 本身:
|
|
183
245
|
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
→ 更严格,但不过度做重
|
|
246
|
+
```bash
|
|
247
|
+
npm run build
|
|
248
|
+
npm run typecheck
|
|
249
|
+
npm test
|
|
250
|
+
npm run pack:dry-run
|
|
190
251
|
```
|
|
191
252
|
|
|
192
|
-
|
|
253
|
+
更多细节见:
|
|
254
|
+
|
|
255
|
+
- `docs/SPEC.md`:完整设计和规则
|
|
256
|
+
- `docs/DISTRIBUTION.md`:安装、升级、卸载和分发说明
|
|
257
|
+
- `.codex/skills/superspec-*/SKILL.md`:当前 Codex 适配器使用的阶段入口说明
|
|
193
258
|
|
|
194
|
-
|
|
259
|
+
## 致谢与灵感来源
|
|
195
260
|
|
|
196
261
|
- [OpenSpec](https://github.com/Fission-AI/OpenSpec)
|
|
197
262
|
- [oh-my-codex](https://github.com/Yeachan-Heo/oh-my-codex)
|
package/dist/src/cli.js
CHANGED
|
@@ -8,13 +8,13 @@ export function main(argv = process.argv.slice(2)) {
|
|
|
8
8
|
return argparseExit;
|
|
9
9
|
args = parse_argv(argv);
|
|
10
10
|
const [decision] = dispatch(args);
|
|
11
|
-
printDecision(decision, { command: args.command });
|
|
11
|
+
printDecision(decision, { command: args.command, format: args.format });
|
|
12
12
|
return decision.allowed ? 0 : 1;
|
|
13
13
|
}
|
|
14
14
|
catch (err) {
|
|
15
15
|
const change = args?.change ?? "?";
|
|
16
16
|
const errReason = err instanceof GuardError ? reason("guard_error", err.message) : reason("guard_internal_error", `${err.name}: ${err.message}`);
|
|
17
|
-
printDecision(block(change, "guard_error", [errReason]), { command: args?.command });
|
|
17
|
+
printDecision(block(change, "guard_error", [errReason]), { command: args?.command, format: args?.format });
|
|
18
18
|
return 2;
|
|
19
19
|
}
|
|
20
20
|
}
|
package/dist/src/cli_args.d.ts
CHANGED
package/dist/src/cli_args.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { command_zh } from "./i18n.js";
|
|
2
|
+
import { GuardError, parseDecisionOutputFormat } from "./util.js";
|
|
2
3
|
const SIMPLE_COMMANDS = [
|
|
3
4
|
"status",
|
|
4
5
|
"recompute",
|
|
@@ -35,7 +36,7 @@ function requiredBooleanFlags(command) {
|
|
|
35
36
|
return command === "init" ? ["--create"] : [];
|
|
36
37
|
}
|
|
37
38
|
function optionalBooleanFlags(command) {
|
|
38
|
-
return command === "recompute" ? ["--force-unlock", "--rebuild-corrupt"] : [];
|
|
39
|
+
return ["--user-facing", ...(command === "recompute" ? ["--force-unlock", "--rebuild-corrupt"] : [])];
|
|
39
40
|
}
|
|
40
41
|
function rootUsage() {
|
|
41
42
|
return `usage: superspec_guard [-h]\n {${COMMAND_LIST}}\n ...\n`;
|
|
@@ -51,6 +52,7 @@ function commandUsage(command) {
|
|
|
51
52
|
const usageFlags = [
|
|
52
53
|
"[-h]",
|
|
53
54
|
...requiredValueFlags(command).map((flag) => `${flag} ${flag.slice(2).replace(/-/g, "_").toUpperCase()}`),
|
|
55
|
+
"[--format {json,agent,user}]",
|
|
54
56
|
...requiredBooleanFlags(command),
|
|
55
57
|
...optionalBooleanFlags(command),
|
|
56
58
|
];
|
|
@@ -66,6 +68,7 @@ function commandHelp(command) {
|
|
|
66
68
|
for (const flag of requiredBooleanFlags(command)) {
|
|
67
69
|
lines.push(` ${flag}\n`);
|
|
68
70
|
}
|
|
71
|
+
lines.push(" --format {json,agent,user}\n");
|
|
69
72
|
for (const flag of optionalBooleanFlags(command)) {
|
|
70
73
|
lines.push(` ${flag}\n`);
|
|
71
74
|
}
|
|
@@ -108,37 +111,51 @@ export function parse_argv(argv) {
|
|
|
108
111
|
throw new Error("缺少命令");
|
|
109
112
|
const command = argv[0];
|
|
110
113
|
const args = argv.slice(1);
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const getValues = (flag) => {
|
|
115
|
+
const values = [];
|
|
116
|
+
for (let idx = 0; idx < args.length; idx += 1) {
|
|
117
|
+
if (args[idx] !== flag)
|
|
118
|
+
continue;
|
|
119
|
+
const value = args[idx + 1];
|
|
120
|
+
if (value === undefined || value.startsWith("--"))
|
|
121
|
+
throw new GuardError(`${flag} 缺少取值`);
|
|
122
|
+
values.push(value);
|
|
123
|
+
}
|
|
124
|
+
return values;
|
|
116
125
|
};
|
|
126
|
+
const getValue = (flag) => getValues(flag)[0];
|
|
127
|
+
const formatValues = getValues("--format");
|
|
128
|
+
for (const value of formatValues)
|
|
129
|
+
parseDecisionOutputFormat(value);
|
|
130
|
+
const selectedFormat = hasFlag(args, "--user-facing")
|
|
131
|
+
? "user"
|
|
132
|
+
: (formatValues.length > 0 ? formatValues[formatValues.length - 1] : "json");
|
|
133
|
+
const format = parseDecisionOutputFormat(selectedFormat);
|
|
117
134
|
const change = getValue("--change");
|
|
118
135
|
if (!change)
|
|
119
136
|
throw new Error("缺少必填参数 --change");
|
|
120
137
|
if (command === "init") {
|
|
121
138
|
if (!hasFlag(args, "--create"))
|
|
122
139
|
throw new Error("缺少必填参数 --create");
|
|
123
|
-
return { command, change, create: true };
|
|
140
|
+
return { command, change, format, create: true };
|
|
124
141
|
}
|
|
125
142
|
if (command === "check-artifact") {
|
|
126
143
|
const artifact = getValue("--artifact");
|
|
127
144
|
if (!artifact)
|
|
128
145
|
throw new Error("缺少必填参数 --artifact");
|
|
129
|
-
return { command, change, artifact };
|
|
146
|
+
return { command, change, format, artifact };
|
|
130
147
|
}
|
|
131
148
|
if (command === "check-enter") {
|
|
132
149
|
const gate = getValue("--gate");
|
|
133
150
|
if (!gate)
|
|
134
151
|
throw new Error("缺少必填参数 --gate");
|
|
135
|
-
return { command, change, gate };
|
|
152
|
+
return { command, change, format, gate };
|
|
136
153
|
}
|
|
137
154
|
if (command === "check-task-reopen" || command === "check-task-edit" || command === "check-task-complete") {
|
|
138
155
|
const taskId = getValue("--task-id");
|
|
139
156
|
if (!taskId)
|
|
140
157
|
throw new Error("缺少必填参数 --task-id");
|
|
141
|
-
return { command, change, task_id: taskId };
|
|
158
|
+
return { command, change, format, task_id: taskId };
|
|
142
159
|
}
|
|
143
160
|
const simple = new Set(SIMPLE_COMMANDS);
|
|
144
161
|
if (!simple.has(command))
|
|
@@ -146,6 +163,7 @@ export function parse_argv(argv) {
|
|
|
146
163
|
return {
|
|
147
164
|
command,
|
|
148
165
|
change,
|
|
166
|
+
format,
|
|
149
167
|
force_unlock: command === "recompute" && hasFlag(args, "--force-unlock"),
|
|
150
168
|
rebuild_corrupt: command === "recompute" && hasFlag(args, "--rebuild-corrupt"),
|
|
151
169
|
};
|
package/dist/src/core.js
CHANGED
|
@@ -16,12 +16,12 @@ import { relative } from "node:path";
|
|
|
16
16
|
import { GuardError, allow, block, deepEqual, reason, runtime, toPosix, trustWarnings } from "./util.js";
|
|
17
17
|
import { artifact_status_map, gate_route_phase, get_change_root, get_repo_root, openspec_status, openspec_status_shape_reasons, openspec_validate, openspec_version, repo_root_from_cwd, } from "./openspec.js";
|
|
18
18
|
import { config_file, load_config, project_config_file } from "./paths.js";
|
|
19
|
-
import { index_evidence,
|
|
19
|
+
import { index_evidence, live_user_confirmations } from "./evidence.js";
|
|
20
20
|
import { tasks_structure_hash } from "./tasks.js";
|
|
21
21
|
import { dirty_worktree_paths, dirty_worktree_reasons, dirty_write_scope_red_reasons, file_blob_sha, git_lines, review_diff_coverage_reasons, review_diff_paths, } from "./git.js";
|
|
22
22
|
import { append_ledger, load_state, compute_fingerprints, prepare_recomputed_state_write, read_ledger_text, record_supersede_ledger_events, restore_state_snapshot_locked, state_corrupt_reasons, state_file, state_file_corrupt, state_stale_reasons, force_unlock_state, with_state_lock, write_prepared_state_locked, } from "./state.js";
|
|
23
23
|
import { archive_manifest_path, begin_archive_preservation_bundle, check_archived, preset_upgrade_reasons, preset_upgrade_required_from_context, write_archive_preservation_bundle, } from "./archive.js";
|
|
24
|
-
import { check_archive_ready, check_artifact, check_init, check_superspec_gate, check_review_complete, check_review_ready, check_task_complete, check_task_edit, check_task_reopen, check_verify_complete, evidence_schema_guard, superspec_agent_reasons, superspec_workflow_skill_reasons, openspec_cli_capability_reasons, openspec_init_reasons, } from "./gates.js";
|
|
24
|
+
import { check_archive_ready, check_apply_ready, check_artifact, check_init, check_superspec_gate, check_review_complete, check_review_ready, check_task_complete, check_task_edit, check_task_reopen, check_verify_complete, evidence_schema_guard, superspec_agent_reasons, superspec_workflow_skill_reasons, openspec_cli_capability_reasons, openspec_init_reasons, } from "./gates.js";
|
|
25
25
|
const RETRY_WAIT = new Int32Array(new SharedArrayBuffer(4));
|
|
26
26
|
const DEFAULT_MAX_STATE_WRITE_RETRIES = 5;
|
|
27
27
|
function sleep_ms(ms) {
|
|
@@ -134,7 +134,7 @@ function dispatch_once(args) {
|
|
|
134
134
|
if (cmd !== "recompute") {
|
|
135
135
|
const changedPaths = String(config.preset ?? "full") !== "full" ? runtime.dirty_worktree_paths(repoRoot) : [];
|
|
136
136
|
presetRequired = preset_upgrade_required_from_context(config, changedPaths);
|
|
137
|
-
const presetHumanConfirmed =
|
|
137
|
+
const presetHumanConfirmed = live_user_confirmations(evidences, "preset_upgrade").length > 0;
|
|
138
138
|
presetProblems = preset_upgrade_reasons(config, changedPaths, presetHumanConfirmed);
|
|
139
139
|
if (cmd !== "init")
|
|
140
140
|
staleProblems = state_stale_reasons(changeRoot, status);
|
|
@@ -171,7 +171,7 @@ function dispatch_once(args) {
|
|
|
171
171
|
route = gate_route_phase(args.gate ?? "");
|
|
172
172
|
}
|
|
173
173
|
else if (cmd === "check-apply-ready") {
|
|
174
|
-
dec =
|
|
174
|
+
dec = check_apply_ready(change, status, changeRoot, evidences);
|
|
175
175
|
route = "propose";
|
|
176
176
|
}
|
|
177
177
|
else if (cmd === "check-task-edit") {
|
|
@@ -230,7 +230,7 @@ function dispatch_once(args) {
|
|
|
230
230
|
const lockedShapeProblems = openspec_status_shape_reasons(lockedStatus);
|
|
231
231
|
const lockedChangedPaths = String(lockedConfig.preset ?? "full") !== "full" ? runtime.dirty_worktree_paths(lockedRepoRoot) : [];
|
|
232
232
|
const lockedPresetRequired = preset_upgrade_required_from_context(lockedConfig, lockedChangedPaths);
|
|
233
|
-
const lockedPresetHumanConfirmed =
|
|
233
|
+
const lockedPresetHumanConfirmed = live_user_confirmations(lockedEvidences, "preset_upgrade").length > 0;
|
|
234
234
|
const lockedPresetProblems = preset_upgrade_reasons(lockedConfig, lockedChangedPaths, lockedPresetHumanConfirmed);
|
|
235
235
|
const lockedStaleProblems = state_stale_reasons(lockedChangeRoot, lockedStatus);
|
|
236
236
|
const lockedCorruptProblems = state_corrupt_reasons(lockedChangeRoot);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type JsonMap } from "./util.ts";
|
|
2
|
+
type RunResult = {
|
|
3
|
+
status: number | null;
|
|
4
|
+
stdout: string;
|
|
5
|
+
stderr: string;
|
|
6
|
+
error?: Error;
|
|
7
|
+
};
|
|
8
|
+
type RunFn = (cmd: string, args: string[], opts?: {
|
|
9
|
+
cwd?: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
platform?: NodeJS.Platform;
|
|
12
|
+
}) => RunResult;
|
|
13
|
+
type CommandExistsFn = (cmd: string, meta?: {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}) => boolean;
|
|
16
|
+
type CheckStatus = "ok" | "warn" | "fail";
|
|
17
|
+
export type DoctorCheck = {
|
|
18
|
+
status: CheckStatus;
|
|
19
|
+
name: string;
|
|
20
|
+
detail: string;
|
|
21
|
+
refs?: string[];
|
|
22
|
+
};
|
|
23
|
+
export type DoctorReport = {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
cwd: string;
|
|
26
|
+
superspec: JsonMap;
|
|
27
|
+
node: JsonMap;
|
|
28
|
+
npm: JsonMap;
|
|
29
|
+
openspec: JsonMap;
|
|
30
|
+
checks: DoctorCheck[];
|
|
31
|
+
next_actions: string[];
|
|
32
|
+
};
|
|
33
|
+
export declare function superspec_package_version(packageRoot?: string): string;
|
|
34
|
+
export declare function build_doctor_report(opts?: {
|
|
35
|
+
cwd?: string;
|
|
36
|
+
packageRoot?: string;
|
|
37
|
+
argv0?: string;
|
|
38
|
+
platform?: NodeJS.Platform;
|
|
39
|
+
commandExistsFn?: CommandExistsFn;
|
|
40
|
+
run?: RunFn;
|
|
41
|
+
}): DoctorReport;
|
|
42
|
+
export declare function render_doctor_report(report: DoctorReport): string;
|
|
43
|
+
export declare function main_doctor(argv?: string[]): number;
|
|
44
|
+
export {};
|