@michaelxwb/code-flow 0.5.2 → 0.6.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/docs/migrations/spec-workflow-0.6.0.md +42 -0
- package/package.json +4 -2
- package/src/adapters/claude/CLAUDE.md +11 -17
- package/src/adapters/claude/commands/cf-init.md +5 -4
- package/src/adapters/claude/commands/cf-spec.md +50 -0
- package/src/adapters/claude/commands/cf-task/align.md +23 -1
- package/src/adapters/claude/commands/cf-task/archive.md +7 -0
- package/src/adapters/claude/commands/cf-task/plan.md +16 -0
- package/src/adapters/claude/commands/cf-task/prd.md +24 -0
- package/src/adapters/claude/commands/cf-task/start.md +13 -10
- package/src/adapters/claude/settings.local.json +1 -11
- package/src/adapters/codex/AGENTS.md +11 -17
- package/src/adapters/codex/hooks.json +6 -4
- package/src/adapters/codex/skills/cf-init/SKILL.md +5 -4
- package/src/adapters/codex/skills/cf-spec/SKILL.md +55 -0
- package/src/adapters/codex/skills/cf-task-align/SKILL.md +23 -1
- package/src/adapters/codex/skills/cf-task-archive/SKILL.md +7 -0
- package/src/adapters/codex/skills/cf-task-plan/SKILL.md +16 -0
- package/src/adapters/codex/skills/cf-task-prd/SKILL.md +24 -0
- package/src/adapters/codex/skills/cf-task-start/SKILL.md +13 -10
- package/src/adapters/costrict/CLAUDE.md +11 -17
- package/src/adapters/costrict/commands/cf-init.md +5 -4
- package/src/adapters/costrict/commands/cf-spec.md +50 -0
- package/src/adapters/costrict/commands/cf-task/align.md +23 -1
- package/src/adapters/costrict/commands/cf-task/archive.md +7 -0
- package/src/adapters/costrict/commands/cf-task/plan.md +16 -0
- package/src/adapters/costrict/commands/cf-task/prd.md +24 -0
- package/src/adapters/costrict/commands/cf-task/start.md +13 -10
- package/src/adapters/costrict/settings.local.json +1 -11
- package/src/adapters/opencode/AGENTS.md +11 -17
- package/src/adapters/opencode/commands/cf-init.md +4 -3
- package/src/adapters/opencode/commands/cf-spec.md +54 -0
- package/src/adapters/opencode/commands/cf-task/align.md +24 -1
- package/src/adapters/opencode/commands/cf-task/archive.md +8 -0
- package/src/adapters/opencode/commands/cf-task/plan.md +17 -0
- package/src/adapters/opencode/commands/cf-task/prd.md +25 -0
- package/src/adapters/opencode/commands/cf-task/start.md +14 -10
- package/src/adapters/opencode/plugins/code-flow/index.js +0 -1
- package/src/cli.js +51 -2
- package/src/core/code-flow/config.yml +13 -16
- package/src/core/code-flow/scripts/cf_checks.py +30 -0
- package/src/core/code-flow/scripts/cf_core.py +12 -255
- package/src/core/code-flow/scripts/cf_log.py +8 -0
- package/src/core/code-flow/scripts/cf_post_hook.py +33 -9
- package/src/core/code-flow/scripts/cf_pre_tool_hook.py +65 -0
- package/src/core/code-flow/scripts/cf_spec_context.py +1233 -0
- package/src/core/code-flow/scripts/cf_spec_gate.py +224 -0
- package/src/core/code-flow/scripts/cf_spec_metadata.py +304 -0
- package/src/core/code-flow/scripts/cf_spec_migrate.py +512 -0
- package/src/core/code-flow/scripts/cf_spec_resolver.py +271 -0
- package/src/core/code-flow/scripts/cf_spec_router.py +145 -0
- package/src/core/code-flow/scripts/cf_spec_session.py +122 -0
- package/src/core/code-flow/scripts/cf_spec_verify.py +293 -0
- package/src/core/code-flow/scripts/cf_stats.py +40 -5
- package/src/core/code-flow/scripts/cf_stop_hook.py +22 -2
- package/src/core/code-flow/scripts/cf_task_runtime.py +142 -0
- package/src/core/code-flow/scripts/cf_user_prompt_hook.py +34 -360
- package/src/core/code-flow/specs/backend/code-quality-performance.md +13 -1
- package/src/core/code-flow/specs/backend/database.md +13 -1
- package/src/core/code-flow/specs/backend/directory-structure.md +13 -1
- package/src/core/code-flow/specs/backend/logging.md +13 -1
- package/src/core/code-flow/specs/backend/platform-rules.md +13 -1
- package/src/core/code-flow/specs/frontend/component-specs.md +13 -1
- package/src/core/code-flow/specs/frontend/directory-structure.md +13 -1
- package/src/core/code-flow/specs/frontend/quality-standards.md +13 -1
- package/src/core/code-flow/specs/shared/design/design-frontend.md +10 -0
- package/src/core/code-flow/specs/shared/design/design-full.md +10 -0
- package/src/core/code-flow/specs/shared/design/design-lite.md +10 -0
- package/src/core/code-flow/specs/shared/prd-template.md +14 -3
- package/src/migrate/spec-workflow.js +238 -0
- package/src/adapters/claude/commands/cf-inject.md +0 -55
- package/src/adapters/codex/skills/cf-inject/SKILL.md +0 -56
- package/src/adapters/costrict/commands/cf-inject.md +0 -55
- package/src/adapters/opencode/commands/cf-inject.md +0 -59
- package/src/core/code-flow/scripts/cf_inject_hook.py +0 -178
- package/src/core/code-flow/scripts/cf_session_hook.py +0 -42
|
@@ -163,6 +163,13 @@ AI 从设计文档中识别关键缺口,输出结构化分析并与用户交
|
|
|
163
163
|
5. Checklist 禁止使用泛化的“编写测试”。必须写成 `[场景ID][测试层级] + 真实边界 + 关键断言`,并为新功能/缺陷修复安排先写测试和 RED 记录。
|
|
164
164
|
6. 如果场景缺测试层级、真实边界或 RULE/高影响 RISK 没有验证场景,先以 `#NOTES` 列为设计缺口;未解决前不得开始编码。
|
|
165
165
|
|
|
166
|
+
**Spec 责任拆解(硬约束)**:
|
|
167
|
+
|
|
168
|
+
1. 先执行 Context `refresh`,读取 Design `Spec Compliance Matrix` 与每个 design-stage/plan-stage Rule 的 `verifier_ref`,继承已有 applied refs,禁止重新选择或降级。
|
|
169
|
+
2. 每条 plan-stage required Rule 必须有且仅有一个责任 TASK;该 TASK 的 `Spec-Refs` 写完整 `{spec-id}#{rule-ref}`,Checklist 写具体 verifier 命令/输入,Acceptance Contract 写测试层级、不得 Mock 的真实边界和关键断言。
|
|
170
|
+
3. Rule 可被其他 TASK 引用为依赖,但 Acceptance Coverage 只能有一个最终负责人。E2E 层级**不得降级**;manual 仍仅限经用户确认的外部边界。
|
|
171
|
+
4. 缺 `verifier_ref`、责任 TASK 为 0/多个、Checklist/Contract 不含 Rule-specific 验证责任时,任务文件只能保留为缺口草稿,不能启动。
|
|
172
|
+
|
|
166
173
|
### 4. 生成任务文件方案
|
|
167
174
|
|
|
168
175
|
将拆解结果按以下格式组织,展示给用户确认:
|
|
@@ -210,6 +217,7 @@ AI 从设计文档中识别关键缺口,输出结构化分析并与用户交
|
|
|
210
217
|
- **Priority**: P0
|
|
211
218
|
- **Depends**:
|
|
212
219
|
- **Source**: docs/xxx.md#§3.1 数据模型(L83-L110)
|
|
220
|
+
- **Spec-Refs**: product-rules#RULE-product-001
|
|
213
221
|
- **Acceptance-Refs**: S-01, E-01, RULE-01
|
|
214
222
|
|
|
215
223
|
### Description
|
|
@@ -285,6 +293,14 @@ TASK-002: <标题> [P1]
|
|
|
285
293
|
3. 如果输入为 docs/ 设计文档(无需求目录)→ 按当前日期创建需求目录 `.code-flow/tasks/<YYYY-MM-DD>/<需求>/` 并写入其中
|
|
286
294
|
4. 用 apply_patch 写入
|
|
287
295
|
|
|
296
|
+
写入后用 `bind --stage plan` 的 `applications` 将每条 required Rule 指向任务文件内唯一 TASK item,并执行:
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage plan --artifact <任务文件> --json
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
只有 Context Plan 状态与任务结构校验都 `decision=pass` 才输出 Start 下一步;缺唯一 owner、`verifier_ref`、测试层级或真实边界时必须回到拆解修复。
|
|
303
|
+
|
|
288
304
|
### 6. 输出摘要
|
|
289
305
|
|
|
290
306
|
```
|
|
@@ -35,6 +35,22 @@ description: Generate a Product Requirements Document (PRD) from a one-liner req
|
|
|
35
35
|
|
|
36
36
|
目的:**让 PRD 基于实际业务背景**,而非泛泛的通用描述。本步只读不提问,所有提问统一放到 Step 3。
|
|
37
37
|
|
|
38
|
+
### 2.1 先解析并绑定 Existing Specs(硬门禁)
|
|
39
|
+
|
|
40
|
+
在开始写需求内容前,先确定 Step 5 的需求目录和预计涉及路径,再执行:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python3 .code-flow/scripts/cf_spec_context.py catalog --stage prd --root "$PWD" --paths <预计路径...> --json
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
1. 必须检查完整 `candidates`,不得按展示条数截断;只消费 resolver 返回的 `stages` 含 `prd` 的产品、安全、兼容、业务约束,`code-only` Spec 不得进入 PRD。
|
|
47
|
+
2. 对每个适用候选记录 `selected_by` 和具体 `reason`,立即用 `bind --stage prd` 写入需求目录的 `spec-context.yml`(首次 `applications` 为空),然后再进入需求细化。
|
|
48
|
+
3. required Rule 必须进入 PRD 的 `Existing Spec Constraints`,并明确影响哪个范围项、FEAT 验收或 NFR;只复制一句“遵循规范”不算承接。
|
|
49
|
+
4. 不适用的 required Rule 必须逐 Rule 说明具体理由并请求用户确认,再调用 `decision` 保存 `not_applicable`;禁止批量 N/A,**Agent 不得代确认**。
|
|
50
|
+
5. Catalog/Context 失败、同级 required 冲突或 required Rule 尚未决定时 fail-closed:保留草稿并修复,不得绕过后继续产出可批准 PRD。
|
|
51
|
+
|
|
52
|
+
> 预计路径尚不明确时仍须以空 `--paths` 运行,确保 global/task-stage 规则先进入 Context;后续范围明确时重新 catalog,并补充绑定新增候选。
|
|
53
|
+
|
|
38
54
|
### 3. 交互式细化
|
|
39
55
|
|
|
40
56
|
围绕 PRD 各要素逐步推进,**每轮提 2-3 个问题**:
|
|
@@ -95,6 +111,7 @@ description: Generate a Product Requirements Document (PRD) from a one-liner req
|
|
|
95
111
|
| 5. 非功能需求 | Step 3 的"非功能需求"(按需,分配 NFR 编号) |
|
|
96
112
|
| 6. 范围与边界 | Step 3 的"范围与边界" |
|
|
97
113
|
| 7. 依赖与风险 | Step 3 的"依赖与风险"(按需) |
|
|
114
|
+
| 8. Existing Spec Constraints | Step 2.1 的 prd-stage Rule;逐条关联范围/FEAT 验收/NFR |
|
|
98
115
|
|
|
99
116
|
**编号与追溯(硬约束,`cf-task-align` 派生的基础)**:
|
|
100
117
|
- 用户故事按出现顺序分配 `US-01`、`US-02`…,写入 §3.2 用户故事表
|
|
@@ -117,6 +134,12 @@ description: Generate a Product Requirements Document (PRD) from a one-liner req
|
|
|
117
134
|
3. **重名检查**:需求目录已存在且非本次草稿时,目录名追加序号 `<name>-2`、`<name>-3`… 避免覆盖;恢复模式复用原目录、不改名
|
|
118
135
|
4. 用 apply_patch 写入 `.code-flow/tasks/<YYYY-MM-DD>/<name>/<name>.prd.md`
|
|
119
136
|
|
|
137
|
+
写入后必须完成 Context 回填和 PRD Gate:
|
|
138
|
+
|
|
139
|
+
1. 再次调用 `bind --stage prd`,`selections` 可为空,`applications` 为每条已承接 Rule 写入 `artifact`、`section_id`、`item_id`;artifact 必须指向本需求目录内 PRD,由脚本计算 `artifact_sha256`。
|
|
140
|
+
2. 执行 `python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage prd --json`。
|
|
141
|
+
3. 只有 `decision=pass` 才能把 PRD 标为可评审并输出下一步;pending/conflict/stale、缺少范围/验收落点或无有效用户确认的 N/A 均保持阻断。
|
|
142
|
+
|
|
120
143
|
**文件位置说明**:PRD、设计简报(`<name>.frontend.design.md` / `<name>.backend.design.md`)、任务文件(`<name>.md`)同放**需求目录** `.code-flow/tasks/<日期>/<name>/`,`cf-task-archive` 按整个需求目录归档。
|
|
121
144
|
|
|
122
145
|
### 6. 输出摘要
|
|
@@ -129,6 +152,7 @@ description: Generate a Product Requirements Document (PRD) from a one-liner req
|
|
|
129
152
|
- 用户故事: N 个
|
|
130
153
|
- 功能: N 个(P0: X, P1: Y)
|
|
131
154
|
- 追溯自检: FEAT↔US 全部关联 ✓ | 有缺口则列出「未关联 FEAT-XX / 未覆盖 US-XX」
|
|
155
|
+
- Existing Specs: N 个 / required Rules: N 条 / PRD Gate: pass
|
|
132
156
|
|
|
133
157
|
> 自检发现缺口(FEAT 无来源 US 或 US 无 FEAT 覆盖)时,在摘要显式标注并提示用户补 US 或降级,不要静默放过。
|
|
134
158
|
|
|
@@ -59,12 +59,15 @@ description: Activate a subtask and begin coding. Runs pre-checks (status, #NOTE
|
|
|
59
59
|
|
|
60
60
|
### 3. 激活并准备验收测试
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
在改状态或生产代码前,顺序固定且不得跳步:
|
|
63
|
+
|
|
64
|
+
1. 调用 `cf_spec_context.py refresh --task-dir ...`,执行 Start Gate;stale/pending/conflict 或依赖未闭合均不得继续。
|
|
65
|
+
2. 重新读取 refresh 后的 Context hash,再调用 `cf_spec_context.py active start`,传 task/context hash 和逐路径确认的 pre-existing ownership;已有/损坏 marker、未归属 diff 或 hash 不一致立即阻断。禁止先 start 再 refresh,避免 active marker 在编码前自行漂移。
|
|
66
|
+
3. 调用 `cf_spec_session.py`,只根据当前 TASK 的 `Spec-Refs`、Source 与 Acceptance Contract 覆盖写入 `_session/task-<name>.md`。禁止重新 catalog 或猜测规则。
|
|
67
|
+
4. 只有前三步全部成功,才用 apply_patch 更新子任务 Status 为 `in-progress`、追加 started log 并更新文件头日期。
|
|
68
|
+
5. 在修改任何生产代码前,为每个 Acceptance-Ref 填写测试文件、包含场景 ID 的测试用例名和可单独执行的命令
|
|
69
|
+
6. 先编写验收测试。E2E 测试必须经过契约声明的真实边界,不得用 mock 绕过 Store、Resolver、Builder、Renderer、Browser 等指定组件
|
|
70
|
+
7. 新功能或缺陷修复先执行一次测试并记录 RED:失败命令、失败用例和与预期缺陷对应的失败原因。纯重构或已有行为补测无法 RED 时,记录原因,不得伪造失败
|
|
68
71
|
|
|
69
72
|
RED 证据写入 `Acceptance Evidence`:
|
|
70
73
|
|
|
@@ -88,15 +91,15 @@ RED 证据写入 `Acceptance Evidence`:
|
|
|
88
91
|
4. 负责该场景的任务验证完成后,将全局 `Acceptance Coverage` 对应行改为 `verified`
|
|
89
92
|
5. 测试文件存在但未被测试框架收集、命令未实际执行、只有场景 ID 没有关键断言,都视为未验证
|
|
90
93
|
|
|
91
|
-
### 3.5
|
|
94
|
+
### 3.5 TASK-bound Spec Session
|
|
92
95
|
|
|
93
96
|
激活后,若任务文件头 Source 指向的 design 文档含验收条件章节(如 §2.5 验收条件 / 验收标准):
|
|
94
97
|
|
|
95
|
-
1. 只提取当前任务 `Acceptance-Refs`
|
|
98
|
+
1. 只提取当前任务 `Spec-Refs` 与 `Acceptance-Refs` 对应的 Rule hash、verifier、artifact refs、场景、测试层级和真实边界,生成 `.code-flow/specs/_session/task-<name>.md`:
|
|
96
99
|
- frontmatter:`description: 当前任务 <name> 的验收约束(cf-task:start 生成,archive 清理)`
|
|
97
100
|
- 正文:验收场景与约束的精简列表(≤300 token);必须保留全部引用 ID、层级、边界和预期结果,不能为压缩而删除场景
|
|
98
|
-
2. Spec Catalog
|
|
99
|
-
3.
|
|
101
|
+
2. 任务模式直接读取这个投影,禁止经 Spec Catalog 二次选择;同名文件已存在则原子覆盖。
|
|
102
|
+
3. 50 Rule 等超预算任务按 required/当前阶段优先输出受控摘要,完整 Context 保留不丢失,并明确提示拆 TASK;不得用截断隐藏 required 缺口。
|
|
100
103
|
|
|
101
104
|
> `_session/` 不入库(.gitignore 模板已覆盖)、不参与规范审计与预算。
|
|
102
105
|
|
|
@@ -16,23 +16,17 @@
|
|
|
16
16
|
- Unparameterized SQL
|
|
17
17
|
- Network calls inside tight loops
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
2. 读取 `.code-flow/specs/<domain>/_map.md` 获取导航上下文
|
|
31
|
-
3. 收到 **Spec Catalog** 时,编码前先 Read 其中与当前任务匹配的 spec 全文(路径相对 `.code-flow/specs/`);prompt 引用明确文件路径或你编辑代码(PreToolUse)时,完整约束自动注入,无需手动读取
|
|
32
|
-
4. 问题跨多个领域时,读取所有匹配的 `_map.md`
|
|
33
|
-
5. 没有匹配领域时,跳过规范加载
|
|
34
|
-
|
|
35
|
-
不要询问用户加载哪些规范——按 Catalog 自取或等待自动注入即可。
|
|
19
|
+
<!-- code-flow:spec-loading schema=1 start -->
|
|
20
|
+
## Spec Workflow (schema 1)
|
|
21
|
+
|
|
22
|
+
- If `.code-flow/.active-task.json` exists, validate it and `spec-context.yml`, then use only the active TASK's `Spec-Refs`, Design refs, and Acceptance Contract. Never reselect Specs from Catalog.
|
|
23
|
+
- Without an active TASK, explicit file paths use deterministic `path_mapping` constraints; prompts without paths receive the Spec Catalog for exploration or creation of the next Context.
|
|
24
|
+
- PRD, Design, Plan, Start, Coding, and Done inherit one persisted Context. Required rules must be applied and verified before their stage gate passes.
|
|
25
|
+
- A corrupt marker, Context hash drift, or required scope expansion is `SPEC_WORKFLOW_BLOCKED`; run `cf-spec refresh/doctor` instead of falling back.
|
|
26
|
+
- Tier 0 `_map.md` files are navigation only. Rule constraints live in metadata-bearing Tier 1 Specs.
|
|
27
|
+
|
|
28
|
+
Do NOT ask the user which Specs to load—the Context-first router is authoritative.
|
|
29
|
+
<!-- code-flow:spec-loading schema=1 end -->
|
|
36
30
|
|
|
37
31
|
## 合规反馈协议(quality_loop)
|
|
38
32
|
|
|
@@ -39,10 +39,11 @@
|
|
|
39
39
|
`code-flow init` 已从 `src/core/code-flow/config.yml` 复制当前核心模板。cf-init 不要复制或手写旧版 YAML;应该读取现有 `.code-flow/config.yml`,只做保守修补。
|
|
40
40
|
|
|
41
41
|
必须保持或补齐这些核心能力:
|
|
42
|
-
- `
|
|
43
|
-
- `
|
|
42
|
+
- `spec_workflow.schema_version: 1`
|
|
43
|
+
- `spec_workflow.catalog.dedup_window: 5`
|
|
44
|
+
- `quality_loop.compress: true`
|
|
44
45
|
- 完整 `skip_extensions`,包括图片、压缩包、PDF 等非代码文件
|
|
45
|
-
- `skip_paths` 中的平台目录:`.claude/**`、`.codex/**`、`.costrict/**`
|
|
46
|
+
- `skip_paths` 中的平台目录:`.claude/**`、`.codex/**`、`.costrict/**`、`.opencode/**`
|
|
46
47
|
- `path_mapping.shared`,包括 `shared/_map.md`、`shared/prd-template.md`、`shared/design/design-lite.md`、`shared/design/design-full.md`、`shared/design/design-frontend.md`
|
|
47
48
|
- backend patterns 中同时包含 `*.py` 与 `**/*.py`
|
|
48
49
|
- 按检测到的前端框架动态补 `frontend.patterns`:Vue→`**/*.vue`、Svelte→`**/*.svelte`、Next→`app/**` 等(保守追加,按检测结果,不预塞所有框架)
|
|
@@ -151,7 +152,7 @@ CLAUDE.md 的完整内容由适配器模板统一定义,`code-flow init` 已
|
|
|
151
152
|
|
|
152
153
|
### 6. 生成 .costrict/settings.local.json Hook 配置
|
|
153
154
|
|
|
154
|
-
检查 `.costrict/settings.local.json` 是否存在。如果不存在,按当前适配器模板创建,必须包含 `PreToolUse`、`
|
|
155
|
+
检查 `.costrict/settings.local.json` 是否存在。如果不存在,按当前适配器模板创建,必须包含 `PreToolUse`、`PostToolUse`、`UserPromptSubmit`、`Stop` 四类 hook,并使用 guarded project root 定位脚本路径。
|
|
155
156
|
|
|
156
157
|
如果文件已存在,只合并缺失的 hook 事件、matcher 或 command,保留用户已有 permissions、settings 和自定义 hooks,不得整文件覆盖。
|
|
157
158
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# cf-spec
|
|
2
|
+
|
|
3
|
+
管理 schema v1 Spec Context 与一次性迁移。用法:
|
|
4
|
+
|
|
5
|
+
- `cf-spec migrate --plan <migration-plan.yml>`
|
|
6
|
+
- `cf-spec context [需求目录]`
|
|
7
|
+
- `cf-spec refresh [需求目录]`
|
|
8
|
+
- `cf-spec doctor [需求目录]`
|
|
9
|
+
|
|
10
|
+
## 通用硬门禁
|
|
11
|
+
|
|
12
|
+
1. 先读取 `.code-flow/config.yml`;`spec_workflow.schema_version` 不是 `1` 时,只有 `migrate --plan` 可继续。
|
|
13
|
+
2. 不存在有效 Context 时,不得伪造 binding、Rule 状态、Evidence 或用户确认。
|
|
14
|
+
3. stdout JSON 由 `cf_*.py` 产生;本命令不得手写成功结果。
|
|
15
|
+
|
|
16
|
+
## migrate --plan
|
|
17
|
+
|
|
18
|
+
只处理 `code-flow migrate --spec-workflow --prepare` 已产生的 prepared plan:
|
|
19
|
+
|
|
20
|
+
1. 校验 plan 位于当前项目 `.code-flow/migrations/<id>/`,状态为 `prepared_blocked` 或 `prepared`,source hashes 未漂移。
|
|
21
|
+
2. 逐条展示 `unresolved` 的来源、候选和影响;读取关联 Spec 与活跃需求文档后给出建议。
|
|
22
|
+
3. 每项必须由用户明确选择。写入 `confirmed_by`、`confirmed_at`、`source`、`reason`;Agent 不能代确认,不能批量 N/A。
|
|
23
|
+
4. 只修改 prepared plan,不修改项目目标、backup、staging、journal 或 `.version`。
|
|
24
|
+
5. unresolved 清零后提示执行:
|
|
25
|
+
`code-flow migrate --spec-workflow --apply --plan <migration-plan.yml>`
|
|
26
|
+
|
|
27
|
+
## context
|
|
28
|
+
|
|
29
|
+
定位显式需求目录;省略时只可使用有效 `.active-task.json` 的 `task_dir`。
|
|
30
|
+
|
|
31
|
+
1. 读取并展示 `spec-context.yml` 的 bindings、Rule stage status、artifact refs、Evidence 与 drift。
|
|
32
|
+
2. 执行:
|
|
33
|
+
`python3 .code-flow/scripts/cf_spec_context.py validate --task-dir <目录> --json`
|
|
34
|
+
3. Context 缺失、schema/hash 无效时 fail-closed,不回退 Catalog。
|
|
35
|
+
|
|
36
|
+
## refresh
|
|
37
|
+
|
|
38
|
+
执行:
|
|
39
|
+
|
|
40
|
+
`python3 .code-flow/scripts/cf_spec_context.py refresh --task-dir <目录> --root "$PWD" --json`
|
|
41
|
+
|
|
42
|
+
- changed required Rule 标为 stale,关联 stage Gate 必须阻断。
|
|
43
|
+
- missing/conflict 不自动降级;回 Align 或 Plan 更新承接后再继续。
|
|
44
|
+
- refresh 不替用户做 N/A/waiver 决策。
|
|
45
|
+
|
|
46
|
+
## doctor
|
|
47
|
+
|
|
48
|
+
1. 校验 config schema、active marker、lock、Context hash、task/status、migration journal 和 legacy residue。
|
|
49
|
+
2. active marker 存在时执行 `cf_spec_context.py active doctor`,传入可证明的 Context hash;无法证明时保持 `recovery_required`。
|
|
50
|
+
3. 输出明确修复命令。不得删除损坏 marker、越过 required Gate 或静默切换到无任务模式。
|
|
@@ -110,6 +110,18 @@ PRD 已覆盖的维度如无需调整,将直接使用。
|
|
|
110
110
|
- Step 3 中已从 PRD 获得充分信息的维度**不重复提问**,除非用户主动修改
|
|
111
111
|
- design 中 FEAT 的"来源"列必须引用 PRD 中对应的 US-XX
|
|
112
112
|
|
|
113
|
+
### 2.7. 继承并刷新 Spec Context(硬门禁)
|
|
114
|
+
|
|
115
|
+
进入技术讨论前先定位需求目录中的 `spec-context.yml`:
|
|
116
|
+
|
|
117
|
+
1. PRD 派生/恢复模式必须执行 `python3 .code-flow/scripts/cf_spec_context.py refresh --task-dir <需求目录> --root "$PWD" --json`;missing/stale/conflict 必须先处理。
|
|
118
|
+
2. 已有 binding 必须从 PRD Context 原样继承,**不得重新选择**、降级 enforcement 或清空 PRD 阶段 refs/decision/evidence。根据预计实现路径运行 `catalog --stage design`,只对新增 design-stage 候选做增量 bind,并记录 reason。
|
|
119
|
+
3. 为每条 design-stage required Rule 预建 `Spec Compliance Matrix` 行:`Spec/Rule`、enforcement、设计影响、具体设计落点、验证场景/verifier、状态或 N/A 理由。
|
|
120
|
+
4. required Rule 没有具体 heading/item 和验证方式时不得进入可评审状态;只写“遵循规范”无效。
|
|
121
|
+
5. N/A/waiver 必须逐 Rule 请求用户确认并调用 `decision`;`batch` 必须为 false,Agent 不得代确认。无有效确认来源时 fail-closed。
|
|
122
|
+
|
|
123
|
+
> 无 PRD 的新建模式也必须先 catalog/bind 并创建 Context,再写 Design;不能因为缺 PRD 跳过 Specs。
|
|
124
|
+
|
|
113
125
|
### 3. 交互式细化
|
|
114
126
|
|
|
115
127
|
围绕选中的维度逐步推进,**每轮提 2-3 个问题**(不要一次性抛 10 个问题):
|
|
@@ -190,7 +202,8 @@ CLI 场景:
|
|
|
190
202
|
3. **只包含适用的章节**,模板中有但需求不涉及的章节跳过
|
|
191
203
|
4. 用 `{}` 占位符替换为实际内容
|
|
192
204
|
5. PRD 派生模式:功能清单的"来源"列填 PRD 中对应的 US-XX
|
|
193
|
-
6.
|
|
205
|
+
6. 生成 `Spec Compliance Matrix`,每条 required Rule 的验证场景必须引用 S-/E-/B- 或说明仅可人工验证的外部边界
|
|
206
|
+
7. 展示生成的设计简报
|
|
194
207
|
|
|
195
208
|
**章节映射**(Lite 模板,对应 `design-lite.md` 实际章节):
|
|
196
209
|
|
|
@@ -267,6 +280,14 @@ CLI 场景:
|
|
|
267
280
|
- **全栈需求**:前后端各写一份到同一需求目录
|
|
268
281
|
4. 用 Write 写入最终路径
|
|
269
282
|
|
|
283
|
+
写入后,对 Matrix 每一行调用 `bind --stage design` 的 `applications` 回填 design artifact、`section_id`、稳定 `item_id` 和脚本计算的 hash;随后执行:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage design --json
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
只有 Design Gate `decision=pass` 才能输出 Plan 下一步。缺 Matrix 行、artifact ref、验证方式、用户确认或发生 drift 时保留草稿并修复,不得推迟到 Coding/Done 才发现。
|
|
290
|
+
|
|
270
291
|
### 6. 输出摘要
|
|
271
292
|
|
|
272
293
|
```
|
|
@@ -278,6 +299,7 @@ CLI 场景:
|
|
|
278
299
|
- <按实际包含的章节列出>
|
|
279
300
|
- 验收标准: N 项
|
|
280
301
|
- 追溯自检: 每个 FEAT 有来源(US/需求)✓、有验收场景✓;每个场景有测试层级和关键真实边界✓;RULE/高影响 RISK 有验证场景✓;Full 模板 §6 矩阵闭合
|
|
302
|
+
- Spec Compliance: required Rules N/N 已落点;Design Gate: pass
|
|
281
303
|
- 性能自检: 标记性能敏感则方案须体现最优性能设计依据(§3.1/§3.5 或 lite §3.4),否则提示补全或显式声明"无性能敏感点"
|
|
282
304
|
|
|
283
305
|
下一步:
|
|
@@ -32,6 +32,13 @@
|
|
|
32
32
|
|
|
33
33
|
### 2. 归档前校验(Verify)
|
|
34
34
|
|
|
35
|
+
**Spec Context / Code Gate(先于四维校验)**:
|
|
36
|
+
|
|
37
|
+
- 需求目录必须存在 `spec-context.yml`;执行 `python3 .code-flow/scripts/cf_spec_context.py refresh --task-dir <需求目录> --root "$PWD" --json`
|
|
38
|
+
- 执行 `python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage code --json`;required Rule 的 stale/pending/conflict/unverified 任一存在即 FAIL
|
|
39
|
+
- 若 `.code-flow/.active-task.json` 仍指向本需求,必须先完成对应 TASK 的 Done Gate,并以 `{"gate_passed": true}` 调用 `active complete`;不得通过归档绕过 active 状态
|
|
40
|
+
- Context 与 Evidence 随需求目录一并归档,`_session` 仅是可重建投影,不是事实源
|
|
41
|
+
|
|
35
42
|
所有子任务 done 后,执行四维校验:
|
|
36
43
|
|
|
37
44
|
**完整性**:
|
|
@@ -162,6 +162,13 @@ AI 从设计文档中识别关键缺口,输出结构化分析并与用户交
|
|
|
162
162
|
5. Checklist 禁止使用泛化的“编写测试”。必须写成 `[场景ID][测试层级] + 真实边界 + 关键断言`,并为新功能/缺陷修复安排先写测试和 RED 记录。
|
|
163
163
|
6. 如果场景缺测试层级、真实边界或 RULE/高影响 RISK 没有验证场景,先以 `#NOTES` 列为设计缺口;未解决前不得开始编码。
|
|
164
164
|
|
|
165
|
+
**Spec 责任拆解(硬约束)**:
|
|
166
|
+
|
|
167
|
+
1. 先执行 Context `refresh`,读取 Design `Spec Compliance Matrix` 与每个 design-stage/plan-stage Rule 的 `verifier_ref`,继承已有 applied refs,禁止重新选择或降级。
|
|
168
|
+
2. 每条 plan-stage required Rule 必须有且仅有一个责任 TASK;该 TASK 的 `Spec-Refs` 写完整 `{spec-id}#{rule-ref}`,Checklist 写具体 verifier 命令/输入,Acceptance Contract 写测试层级、不得 Mock 的真实边界和关键断言。
|
|
169
|
+
3. Rule 可被其他 TASK 引用为依赖,但 Acceptance Coverage 只能有一个最终负责人。E2E 层级**不得降级**;manual 仍仅限经用户确认的外部边界。
|
|
170
|
+
4. 缺 `verifier_ref`、责任 TASK 为 0/多个、Checklist/Contract 不含 Rule-specific 验证责任时,任务文件只能保留为缺口草稿,不能启动。
|
|
171
|
+
|
|
165
172
|
### 4. 生成任务文件方案
|
|
166
173
|
|
|
167
174
|
将拆解结果按以下格式组织,展示给用户确认:
|
|
@@ -209,6 +216,7 @@ AI 从设计文档中识别关键缺口,输出结构化分析并与用户交
|
|
|
209
216
|
- **Priority**: P0
|
|
210
217
|
- **Depends**:
|
|
211
218
|
- **Source**: docs/xxx.md#§3.1 数据模型(L83-L110)
|
|
219
|
+
- **Spec-Refs**: product-rules#RULE-product-001
|
|
212
220
|
- **Acceptance-Refs**: S-01, E-01, RULE-01
|
|
213
221
|
|
|
214
222
|
### Description
|
|
@@ -284,6 +292,14 @@ TASK-002: <标题> [P1]
|
|
|
284
292
|
3. 如果输入为 docs/ 设计文档(无需求目录)→ 按当前日期创建需求目录 `.code-flow/tasks/<YYYY-MM-DD>/<需求>/` 并写入其中
|
|
285
293
|
4. 用 Write 写入
|
|
286
294
|
|
|
295
|
+
写入后用 `bind --stage plan` 的 `applications` 将每条 required Rule 指向任务文件内唯一 TASK item,并执行:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage plan --artifact <任务文件> --json
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
只有 Context Plan 状态与任务结构校验都 `decision=pass` 才输出 Start 下一步;缺唯一 owner、`verifier_ref`、测试层级或真实边界时必须回到拆解修复。
|
|
302
|
+
|
|
287
303
|
### 6. 输出摘要
|
|
288
304
|
|
|
289
305
|
```
|
|
@@ -34,6 +34,22 @@
|
|
|
34
34
|
|
|
35
35
|
目的:**让 PRD 基于实际业务背景**,而非泛泛的通用描述。本步只读不提问,所有提问统一放到 Step 3。
|
|
36
36
|
|
|
37
|
+
### 2.1 先解析并绑定 Existing Specs(硬门禁)
|
|
38
|
+
|
|
39
|
+
在开始写需求内容前,先确定 Step 5 的需求目录和预计涉及路径,再执行:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python3 .code-flow/scripts/cf_spec_context.py catalog --stage prd --root "$PWD" --paths <预计路径...> --json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
1. 必须检查完整 `candidates`,不得按展示条数截断;只消费 resolver 返回的 `stages` 含 `prd` 的产品、安全、兼容、业务约束,`code-only` Spec 不得进入 PRD。
|
|
46
|
+
2. 对每个适用候选记录 `selected_by` 和具体 `reason`,立即用 `bind --stage prd` 写入需求目录的 `spec-context.yml`(首次 `applications` 为空),然后再进入需求细化。
|
|
47
|
+
3. required Rule 必须进入 PRD 的 `Existing Spec Constraints`,并明确影响哪个范围项、FEAT 验收或 NFR;只复制一句“遵循规范”不算承接。
|
|
48
|
+
4. 不适用的 required Rule 必须逐 Rule 说明具体理由并请求用户确认,再调用 `decision` 保存 `not_applicable`;禁止批量 N/A,**Agent 不得代确认**。
|
|
49
|
+
5. Catalog/Context 失败、同级 required 冲突或 required Rule 尚未决定时 fail-closed:保留草稿并修复,不得绕过后继续产出可批准 PRD。
|
|
50
|
+
|
|
51
|
+
> 预计路径尚不明确时仍须以空 `--paths` 运行,确保 global/task-stage 规则先进入 Context;后续范围明确时重新 catalog,并补充绑定新增候选。
|
|
52
|
+
|
|
37
53
|
### 3. 交互式细化
|
|
38
54
|
|
|
39
55
|
围绕 PRD 各要素逐步推进,**每轮提 2-3 个问题**:
|
|
@@ -94,6 +110,7 @@
|
|
|
94
110
|
| 5. 非功能需求 | Step 3 的"非功能需求"(按需,分配 NFR 编号) |
|
|
95
111
|
| 6. 范围与边界 | Step 3 的"范围与边界" |
|
|
96
112
|
| 7. 依赖与风险 | Step 3 的"依赖与风险"(按需) |
|
|
113
|
+
| 8. Existing Spec Constraints | Step 2.1 的 prd-stage Rule;逐条关联范围/FEAT 验收/NFR |
|
|
97
114
|
|
|
98
115
|
**编号与追溯(硬约束,`cf-task:align` 派生的基础)**:
|
|
99
116
|
- 用户故事按出现顺序分配 `US-01`、`US-02`…,写入 §3.2 用户故事表
|
|
@@ -116,6 +133,12 @@
|
|
|
116
133
|
3. **重名检查**:需求目录已存在且非本次草稿时,目录名追加序号 `<name>-2`、`<name>-3`… 避免覆盖;恢复模式复用原目录、不改名
|
|
117
134
|
4. 用 Write 写入 `.code-flow/tasks/<YYYY-MM-DD>/<name>/<name>.prd.md`
|
|
118
135
|
|
|
136
|
+
写入后必须完成 Context 回填和 PRD Gate:
|
|
137
|
+
|
|
138
|
+
1. 再次调用 `bind --stage prd`,`selections` 可为空,`applications` 为每条已承接 Rule 写入 `artifact`、`section_id`、`item_id`;artifact 必须指向本需求目录内 PRD,由脚本计算 `artifact_sha256`。
|
|
139
|
+
2. 执行 `python3 .code-flow/scripts/cf_spec_gate.py --task-dir <需求目录> --stage prd --json`。
|
|
140
|
+
3. 只有 `decision=pass` 才能把 PRD 标为可评审并输出下一步;pending/conflict/stale、缺少范围/验收落点或无有效用户确认的 N/A 均保持阻断。
|
|
141
|
+
|
|
119
142
|
**文件位置说明**:PRD、设计简报(`<name>.frontend.design.md` / `<name>.backend.design.md`)、任务文件(`<name>.md`)同放**需求目录** `.code-flow/tasks/<日期>/<name>/`,`cf-task:archive` 按整个需求目录归档。
|
|
120
143
|
|
|
121
144
|
### 6. 输出摘要
|
|
@@ -128,6 +151,7 @@
|
|
|
128
151
|
- 用户故事: N 个
|
|
129
152
|
- 功能: N 个(P0: X, P1: Y)
|
|
130
153
|
- 追溯自检: FEAT↔US 全部关联 ✓ | 有缺口则列出「未关联 FEAT-XX / 未覆盖 US-XX」
|
|
154
|
+
- Existing Specs: N 个 / required Rules: N 条 / PRD Gate: pass
|
|
131
155
|
|
|
132
156
|
> 自检发现缺口(FEAT 无来源 US 或 US 无 FEAT 覆盖)时,在摘要显式标注并提示用户补 US 或降级,不要静默放过。
|
|
133
157
|
|
|
@@ -58,12 +58,15 @@
|
|
|
58
58
|
|
|
59
59
|
### 3. 激活并准备验收测试
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
在改状态或生产代码前,顺序固定且不得跳步:
|
|
62
|
+
|
|
63
|
+
1. 调用 `cf_spec_context.py refresh --task-dir ...`,执行 Start Gate;stale/pending/conflict 或依赖未闭合均不得继续。
|
|
64
|
+
2. 重新读取 refresh 后的 Context hash,再调用 `cf_spec_context.py active start`,传 task/context hash 和逐路径确认的 pre-existing ownership;已有/损坏 marker、未归属 diff 或 hash 不一致立即阻断。禁止先 start 再 refresh,避免 active marker 在编码前自行漂移。
|
|
65
|
+
3. 调用 `cf_spec_session.py`,只根据当前 TASK 的 `Spec-Refs`、Source 与 Acceptance Contract 覆盖写入 `_session/task-<name>.md`。禁止重新 catalog 或猜测规则。
|
|
66
|
+
4. 只有前三步全部成功,才用 Edit 更新子任务 Status 为 `in-progress`、追加 started log 并更新文件头日期。
|
|
67
|
+
5. 在修改任何生产代码前,为每个 Acceptance-Ref 填写测试文件、包含场景 ID 的测试用例名和可单独执行的命令
|
|
68
|
+
6. 先编写验收测试。E2E 测试必须经过契约声明的真实边界,不得用 mock 绕过 Store、Resolver、Builder、Renderer、Browser 等指定组件
|
|
69
|
+
7. 新功能或缺陷修复先执行一次测试并记录 RED:失败命令、失败用例和与预期缺陷对应的失败原因。纯重构或已有行为补测无法 RED 时,记录原因,不得伪造失败
|
|
67
70
|
|
|
68
71
|
RED 证据写入 `Acceptance Evidence`:
|
|
69
72
|
|
|
@@ -87,15 +90,15 @@ RED 证据写入 `Acceptance Evidence`:
|
|
|
87
90
|
4. 负责该场景的任务验证完成后,将全局 `Acceptance Coverage` 对应行改为 `verified`
|
|
88
91
|
5. 测试文件存在但未被测试框架收集、命令未实际执行、只有场景 ID 没有关键断言,都视为未验证
|
|
89
92
|
|
|
90
|
-
### 3.5
|
|
93
|
+
### 3.5 TASK-bound Spec Session
|
|
91
94
|
|
|
92
95
|
激活后,若任务文件头 Source 指向的 design 文档含验收条件章节(如 §2.5 验收条件 / 验收标准):
|
|
93
96
|
|
|
94
|
-
1. 只提取当前任务 `Acceptance-Refs`
|
|
97
|
+
1. 只提取当前任务 `Spec-Refs` 与 `Acceptance-Refs` 对应的 Rule hash、verifier、artifact refs、场景、测试层级和真实边界,生成 `.code-flow/specs/_session/task-<name>.md`:
|
|
95
98
|
- frontmatter:`description: 当前任务 <name> 的验收约束(cf-task:start 生成,archive 清理)`
|
|
96
99
|
- 正文:验收场景与约束的精简列表(≤300 token);必须保留全部引用 ID、层级、边界和预期结果,不能为压缩而删除场景
|
|
97
|
-
2. Spec Catalog
|
|
98
|
-
3.
|
|
100
|
+
2. 任务模式直接读取这个投影,禁止经 Spec Catalog 二次选择;同名文件已存在则原子覆盖。
|
|
101
|
+
3. 50 Rule 等超预算任务按 required/当前阶段优先输出受控摘要,完整 Context 保留不丢失,并明确提示拆 TASK;不得用截断隐藏 required 缺口。
|
|
99
102
|
|
|
100
103
|
> `_session/` 不入库(.gitignore 模板已覆盖)、不参与规范审计与预算。
|
|
101
104
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "d=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}\"; f=\"$d/.code-flow/scripts/
|
|
9
|
+
"command": "d=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}\"; f=\"$d/.code-flow/scripts/cf_pre_tool_hook.py\"; if [ -f \"$f\" ]; then cd \"$d\" && python3 \"$f\"; fi",
|
|
10
10
|
"timeout": 5
|
|
11
11
|
}
|
|
12
12
|
]
|
|
@@ -24,16 +24,6 @@
|
|
|
24
24
|
]
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
|
-
"SessionStart": [
|
|
28
|
-
{
|
|
29
|
-
"hooks": [
|
|
30
|
-
{
|
|
31
|
-
"type": "command",
|
|
32
|
-
"command": "d=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}\"; f=\"$d/.code-flow/scripts/cf_session_hook.py\"; if [ -f \"$f\" ]; then cd \"$d\" && python3 \"$f\"; fi"
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
27
|
"UserPromptSubmit": [
|
|
38
28
|
{
|
|
39
29
|
"hooks": [
|
|
@@ -16,23 +16,17 @@
|
|
|
16
16
|
- Unparameterized SQL
|
|
17
17
|
- Network calls inside tight loops
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
2. 读取 `.code-flow/specs/<domain>/_map.md` 获取导航上下文
|
|
31
|
-
3. 收到 **Spec Catalog** 时,编码前先 Read 其中与当前任务匹配的 spec 全文(路径相对 `.code-flow/specs/`);prompt 引用明确文件路径时插件自动注入完整约束,无需手动读取
|
|
32
|
-
4. 问题跨多个领域时,读取所有匹配的 `_map.md`
|
|
33
|
-
5. 没有匹配领域时,跳过规范加载
|
|
34
|
-
|
|
35
|
-
不要询问用户加载哪些规范——按 Catalog 自取或等待自动注入即可。
|
|
19
|
+
<!-- code-flow:spec-loading schema=1 start -->
|
|
20
|
+
## Spec Workflow (schema 1)
|
|
21
|
+
|
|
22
|
+
- If `.code-flow/.active-task.json` exists, validate it and `spec-context.yml`, then use only the active TASK's `Spec-Refs`, Design refs, and Acceptance Contract. Never reselect Specs from Catalog.
|
|
23
|
+
- Without an active TASK, explicit file paths use deterministic `path_mapping` constraints; prompts without paths receive the Spec Catalog for exploration or creation of the next Context.
|
|
24
|
+
- PRD, Design, Plan, Start, Coding, and Done inherit one persisted Context. Required rules must be applied and verified before their stage gate passes.
|
|
25
|
+
- A corrupt marker, Context hash drift, or required scope expansion is `SPEC_WORKFLOW_BLOCKED`; run `cf-spec refresh/doctor` instead of falling back.
|
|
26
|
+
- Tier 0 `_map.md` files are navigation only. Rule constraints live in metadata-bearing Tier 1 Specs.
|
|
27
|
+
|
|
28
|
+
Do NOT ask the user which Specs to load—the Context-first router is authoritative.
|
|
29
|
+
<!-- code-flow:spec-loading schema=1 end -->
|
|
36
30
|
|
|
37
31
|
## 合规反馈协议(quality_loop)
|
|
38
32
|
|
|
@@ -43,10 +43,11 @@ description: 一键初始化项目规范体系,检测技术栈,生成 spec
|
|
|
43
43
|
`code-flow init` 已从 `src/core/code-flow/config.yml` 复制当前核心模板。cf-init 不要复制或手写旧版 YAML;应该读取现有 `.code-flow/config.yml`,只做保守修补。
|
|
44
44
|
|
|
45
45
|
必须保持或补齐这些核心能力:
|
|
46
|
-
- `
|
|
47
|
-
- `
|
|
46
|
+
- `spec_workflow.schema_version: 1`
|
|
47
|
+
- `spec_workflow.catalog.dedup_window: 5`
|
|
48
|
+
- `quality_loop.compress: true`
|
|
48
49
|
- 完整 `skip_extensions`,包括图片、压缩包、PDF 等非代码文件
|
|
49
|
-
- `skip_paths` 中的平台目录:`.claude/**`、`.codex/**`、`.costrict/**`
|
|
50
|
+
- `skip_paths` 中的平台目录:`.claude/**`、`.codex/**`、`.costrict/**`、`.opencode/**`
|
|
50
51
|
- `path_mapping.shared`,包括 `shared/_map.md`、`shared/prd-template.md`、`shared/design/design-lite.md`、`shared/design/design-full.md`、`shared/design/design-frontend.md`
|
|
51
52
|
- backend patterns 中同时包含 `*.py` 与 `**/*.py`
|
|
52
53
|
- 按检测到的前端框架动态补 `frontend.patterns`:Vue→`**/*.vue`、Svelte→`**/*.svelte`、Next→`app/**` 等(保守追加,按检测结果,不预塞所有框架)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 管理 Spec Context、漂移恢复与一次性迁移
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# cf-spec
|
|
6
|
+
|
|
7
|
+
管理 schema v1 Spec Context 与一次性迁移。用法:
|
|
8
|
+
|
|
9
|
+
- `cf-spec migrate --plan <migration-plan.yml>`
|
|
10
|
+
- `cf-spec context [需求目录]`
|
|
11
|
+
- `cf-spec refresh [需求目录]`
|
|
12
|
+
- `cf-spec doctor [需求目录]`
|
|
13
|
+
|
|
14
|
+
## 通用硬门禁
|
|
15
|
+
|
|
16
|
+
1. 先读取 `.code-flow/config.yml`;`spec_workflow.schema_version` 不是 `1` 时,只有 `migrate --plan` 可继续。
|
|
17
|
+
2. 不存在有效 Context 时,不得伪造 binding、Rule 状态、Evidence 或用户确认。
|
|
18
|
+
3. stdout JSON 由 `cf_*.py` 产生;本命令不得手写成功结果。
|
|
19
|
+
|
|
20
|
+
## migrate --plan
|
|
21
|
+
|
|
22
|
+
只处理 `code-flow migrate --spec-workflow --prepare` 已产生的 prepared plan:
|
|
23
|
+
|
|
24
|
+
1. 校验 plan 位于当前项目 `.code-flow/migrations/<id>/`,状态为 `prepared_blocked` 或 `prepared`,source hashes 未漂移。
|
|
25
|
+
2. 逐条展示 `unresolved` 的来源、候选和影响;读取关联 Spec 与活跃需求文档后给出建议。
|
|
26
|
+
3. 每项必须由用户明确选择。写入 `confirmed_by`、`confirmed_at`、`source`、`reason`;Agent 不能代确认,不能批量 N/A。
|
|
27
|
+
4. 只修改 prepared plan,不修改项目目标、backup、staging、journal 或 `.version`。
|
|
28
|
+
5. unresolved 清零后提示执行:
|
|
29
|
+
`code-flow migrate --spec-workflow --apply --plan <migration-plan.yml>`
|
|
30
|
+
|
|
31
|
+
## context
|
|
32
|
+
|
|
33
|
+
定位显式需求目录;省略时只可使用有效 `.active-task.json` 的 `task_dir`。
|
|
34
|
+
|
|
35
|
+
1. 读取并展示 `spec-context.yml` 的 bindings、Rule stage status、artifact refs、Evidence 与 drift。
|
|
36
|
+
2. 执行:
|
|
37
|
+
`python3 .code-flow/scripts/cf_spec_context.py validate --task-dir <目录> --json`
|
|
38
|
+
3. Context 缺失、schema/hash 无效时 fail-closed,不回退 Catalog。
|
|
39
|
+
|
|
40
|
+
## refresh
|
|
41
|
+
|
|
42
|
+
执行:
|
|
43
|
+
|
|
44
|
+
`python3 .code-flow/scripts/cf_spec_context.py refresh --task-dir <目录> --root "$PWD" --json`
|
|
45
|
+
|
|
46
|
+
- changed required Rule 标为 stale,关联 stage Gate 必须阻断。
|
|
47
|
+
- missing/conflict 不自动降级;回 Align 或 Plan 更新承接后再继续。
|
|
48
|
+
- refresh 不替用户做 N/A/waiver 决策。
|
|
49
|
+
|
|
50
|
+
## doctor
|
|
51
|
+
|
|
52
|
+
1. 校验 config schema、active marker、lock、Context hash、task/status、migration journal 和 legacy residue。
|
|
53
|
+
2. active marker 存在时执行 `cf_spec_context.py active doctor`,传入可证明的 Context hash;无法证明时保持 `recovery_required`。
|
|
54
|
+
3. 输出明确修复命令。不得删除损坏 marker、越过 required Gate 或静默切换到无任务模式。
|