flow-comet 1.6.3 → 1.6.5
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/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +21 -3
- package/.flow-comet/skills/flow-comet/reference/artifact-template-overlay.md +154 -0
- package/.flow-comet/skills/flow-comet/reference/artifact-templates.json +387 -0
- package/.flow-comet/skills/flow-comet/reference/entry-detail.md +8 -2
- package/.flow-comet/skills/flow-comet/reference/workflow-protocol.json +22 -0
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +11 -13
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +180 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +69 -18878
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +29 -5
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1053 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +817 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +618 -0
- package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +154 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-artifact-skeleton.mjs +406 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +756 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +1235 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +384 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +714 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +204 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +179 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +714 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +123 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +249 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1505 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1248 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2493 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +214 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +72 -1123
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +976 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1398 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1367 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1492 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +2125 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +59 -7559
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +223 -2476
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +5 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +27 -2190
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-change/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-design/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-design/SKILL.md +15 -8
- package/.flow-comet/skills/flow-comet-dev/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-evolve/SKILL.md +1 -0
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +13 -10
- package/.flow-comet/skills/flow-comet-health/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-open/GUIDANCE.md +14 -4
- package/.flow-comet/skills/flow-comet-open/SKILL.md +11 -9
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +11 -7
- package/.flow-comet/skills/flow-comet-requirement/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +15 -9
- package/.flow-comet/skills/flow-comet-subagent-execute/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +11 -8
- package/.flow-comet/skills/flow-comet-task/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-test/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +2 -2
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +12 -8
- package/README.md +52 -69
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +159 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +21 -1313
|
@@ -0,0 +1,1235 @@
|
|
|
1
|
+
// 节点门禁(守卫模块):entry 链 + 出口前置 / 文件纪律 / 节点结构 门禁。
|
|
2
|
+
//
|
|
3
|
+
// 判据只在本模块一处实现(入口零内联副本);每条门禁沿用既有分级——新 change(init 标记)强制
|
|
4
|
+
// BLOCKED + 恢复指引,旧 change 渐进 WARN 不阻断。门禁命中即显式报出原因并按 fail-closed 拒绝
|
|
5
|
+
// (未验证 ≠ 通过)。
|
|
6
|
+
|
|
7
|
+
import { promises as fs } from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { validateStateFields } from '../state-schema.mjs';
|
|
10
|
+
import { NODE_PROTOCOL_FILES } from '../protocol-utils.mjs';
|
|
11
|
+
import {
|
|
12
|
+
EXECUTE_FAMILY_NODE_IDS,
|
|
13
|
+
TASK_SET_SIGNATURE_ALGO,
|
|
14
|
+
analyzeDependencyGraph,
|
|
15
|
+
applyFixRollbackRound,
|
|
16
|
+
findParallelWriteConflicts,
|
|
17
|
+
parseTaskSetSignature,
|
|
18
|
+
resolveFixRollbackDecision,
|
|
19
|
+
resolveFixRollbackState,
|
|
20
|
+
sameTaskSetSignature,
|
|
21
|
+
taskSetSignature,
|
|
22
|
+
taskSetSignatureVersionSkew,
|
|
23
|
+
} from '../route-node.mjs';
|
|
24
|
+
import { taskOpeningAttrs, taskBlocks as extractTaskBlocks } from '../task-parsing.mjs';
|
|
25
|
+
import { runRoot, fileExists, writeJson } from './guard-state-io.mjs';
|
|
26
|
+
import {
|
|
27
|
+
TEMPLATE_FALLBACK_SECTION_PATTERNS,
|
|
28
|
+
buildSkeleton,
|
|
29
|
+
headingPattern,
|
|
30
|
+
} from './guard-artifact-skeleton.mjs';
|
|
31
|
+
import { frontendCriterion } from './guard-uidesign.mjs';
|
|
32
|
+
import {
|
|
33
|
+
evidenceFor,
|
|
34
|
+
findSkillLoadsDir,
|
|
35
|
+
hasEvidenceField,
|
|
36
|
+
hasNonEmptyHandoffResult,
|
|
37
|
+
isNewChange,
|
|
38
|
+
missingRequiredArtifacts,
|
|
39
|
+
missingRequiredSchemaEvidence,
|
|
40
|
+
nextNode,
|
|
41
|
+
templateSectionPatterns,
|
|
42
|
+
} from './guard-routing.mjs';
|
|
43
|
+
|
|
44
|
+
// 节点 → 合法 exit 的前置条件(对齐 flow-kit 阶段门 + flowkit.*.v1 evidence)
|
|
45
|
+
const NODE_TRANSITION_GATES = {
|
|
46
|
+
open: { evidence: ['intake-summary'] },
|
|
47
|
+
design: { evidence: ['design-summary'] },
|
|
48
|
+
plan: { evidence: ['plan-summary'] },
|
|
49
|
+
execute: { evidence: ['implementation-summary'] },
|
|
50
|
+
'subagent-execute':{ evidence: ['handoff-result'] },
|
|
51
|
+
review: { evidence: ['review-summary'] },
|
|
52
|
+
verify: { evidence: ['verification-result'] },
|
|
53
|
+
archive: { evidence: ['archive-summary'] },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// 声明标记 protocol → basename 提取(exit 校验与节点协议映射表 basename 精确比对)。兼容新旧两种
|
|
57
|
+
// 格式:新格式(skill-load 写入)= 纯 basename(如 0-change.md),原样返回;旧格式 = 完整绝对路径
|
|
58
|
+
// (Windows 反斜杠 / POSIX 斜杠),提取最后一段后可比对。非字符串(null——skill-load 未传
|
|
59
|
+
// --protocol 的新格式缺省)→ null(协议集内无 null,fail-closed 由 includes 比对兜底)。
|
|
60
|
+
function markerProtocolBasename(value) {
|
|
61
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
62
|
+
return String(value).replaceAll('\\', '/').split('/').pop() || null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// REVIEW.md 发现区解析——发现的合法位置是模板位置 `### 2.2 …详细发现`(REVIEW 模板的结构子段);
|
|
66
|
+
// 旧形态 `## 发现` 段(历史 REVIEW 的写法)继续按同一套条目口径解析,供旧 change 渐进处置与迁移
|
|
67
|
+
// 提示。发现项有两种合法书写形态:① 列表项("- **" 无序 / "1. **" 有序,两种列表形态同口径解析);
|
|
68
|
+
// ② 模板范例形态(flow-kit/templates/REVIEW.md 2.2 的书写样例 `### 🔴 R<x> · <名字>:<结论>` +
|
|
69
|
+
// 粗体字段行)——模板位置下以严重度 token 起头的 H3 同样是发现,标题行即条目自身的第一行(处置
|
|
70
|
+
// 标记按该行判定)。不以严重度 token 起头的 H3(如 `### Major`)仍是严重度分区。旧 `## 发现` 段
|
|
71
|
+
// 保持列表项口径(历史写法,避免把分区标题误判成发现)。"无"条目("- 无" / "无(...)")表示该
|
|
72
|
+
// 级别无发现,豁免。条目块包含其后的非空续行,直到空行 / 下一条目 / 下一个标题。严重度只取该条目
|
|
73
|
+
// 自身的标题/行首——所属 "### Major" 分区,或标题(加粗部分 / H3 严重度 token)内带级别信息;
|
|
74
|
+
// 条目正文引用他条的 [Major] 字样不改变本条严重度。返回 { title, scope, lines, isMajor, ordinal }。
|
|
75
|
+
const REVIEW_FINDING_ITEM_RE = /^\s*(?:[-*+]|\d+[.)])\s*\*\*(.+?)\*\*/;
|
|
76
|
+
const REVIEW_SEVERITY_TOKEN_RE = /^(?:🔴|🟡|🟢|\[\s*(?:critical|major|minor)\s*\])\s*/iu;
|
|
77
|
+
const REVIEW_DISPOSITION_RE = /\[已修\]|\[升级\]|\[转待办\]/;
|
|
78
|
+
const REVIEW_MAJOR_LABEL_RE = /\[\s*Major\s*\]/i;
|
|
79
|
+
const REVIEW_ADJUDICATION_RE = /用户裁决\s*[::]\s*接受延期/;
|
|
80
|
+
// 旧形态段的「空段」形态:占位词与「无」条目不构成内容(迁移提示只在旧段真有内容时给)。
|
|
81
|
+
const REVIEW_FINDINGS_PLACEHOLDER_RE =
|
|
82
|
+
/^(?:[-*+]\s*)?(?:\*\*)?(?:无|不适用|未涉及|无变更|N\/A|—|(无)|\(无\))(?:\*\*)?[。.;;,,]?$/iu;
|
|
83
|
+
|
|
84
|
+
// 发现区作用域基准从 REVIEW 骨架派生(模板 `### 2.2 6 维诊断 · 详细发现(4 要素…)` → 结构子段
|
|
85
|
+
// 「详细发现」)——段名归一是骨架模块的单一实现,此处不另写段名正则。模板缺席 → primary=null,
|
|
86
|
+
// 模板位置判据整体跳过(模板派生判据不臆造;旧形态解析与处置校验照常)。同一父段的其它
|
|
87
|
+
// 结构子段(2.0 / 2.1 / 2.3)在模板位置作用域内结束该子段;段内其它 H3(如 brooks 输出的
|
|
88
|
+
// `### 🔴 R1 …` 分区)是严重度分区,不结束作用域。
|
|
89
|
+
async function reviewFindingScope() {
|
|
90
|
+
const skeleton = await buildSkeleton('REVIEW');
|
|
91
|
+
const subsections = skeleton.derived ? skeleton.structureSubsections : [];
|
|
92
|
+
const primary = subsections.find((entry) => entry.norm.includes('详细发现')) ?? null;
|
|
93
|
+
return {
|
|
94
|
+
primary: primary === null ? null : primary.pattern,
|
|
95
|
+
siblings: primary === null
|
|
96
|
+
? []
|
|
97
|
+
: subsections
|
|
98
|
+
.filter((entry) => entry !== primary && entry.parentNorm === primary.parentNorm)
|
|
99
|
+
.map((entry) => entry.pattern),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// H3 条目形态的严重度从标题前缀的严重度 token 派生(模板范例的 🔴/🟡/🟢;另接受文字标签形态的
|
|
104
|
+
// [Critical]/[Major]/[Minor])——Major 延期裁决门禁对 H3 条目与列表项同口径。
|
|
105
|
+
function reviewSubheadingIsMajor(heading) {
|
|
106
|
+
const token = (String(heading).match(REVIEW_SEVERITY_TOKEN_RE) ?? [])[0] ?? '';
|
|
107
|
+
if (/🔴|🟡/u.test(token) || /critical|major/iu.test(token)) return true;
|
|
108
|
+
return REVIEW_MAJOR_LABEL_RE.test(heading);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function reviewFindingsItems(text, scope = { primary: null, siblings: [] }) {
|
|
112
|
+
const items = [];
|
|
113
|
+
let mode = 'none'; // 'none' | 'legacy'(旧 ## 发现)| 'primary'(模板位置 2.2)
|
|
114
|
+
let severity = '';
|
|
115
|
+
let current = null;
|
|
116
|
+
const pushCurrent = () => { if (current) { items.push(current); current = null; } };
|
|
117
|
+
for (const line of String(text).split(/\r?\n/)) {
|
|
118
|
+
const h2 = line.match(/^##\s+(.+?)\s*$/);
|
|
119
|
+
if (h2) {
|
|
120
|
+
pushCurrent();
|
|
121
|
+
severity = '';
|
|
122
|
+
mode = /^发现/.test(h2[1].trim()) ? 'legacy' : 'none';
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const h3 = line.match(/^###\s+(.+?)\s*$/);
|
|
126
|
+
if (h3) {
|
|
127
|
+
pushCurrent();
|
|
128
|
+
if (mode === 'primary') {
|
|
129
|
+
// 兄弟结构子段结束模板位置作用域;其余三级标题只是严重度分区
|
|
130
|
+
if ((scope.siblings ?? []).some((pattern) => pattern.test(line))) {
|
|
131
|
+
mode = 'none';
|
|
132
|
+
severity = '';
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
// 模板范例形态:严重度 token 起头的 H3 = 发现条目(标题行即条目自身第一行,处置标记
|
|
136
|
+
// 与列表项同口径按该行判定),续行是粗体字段 / 正文,直到空行或下一个标题。
|
|
137
|
+
const heading = h3[1].trim();
|
|
138
|
+
if (REVIEW_SEVERITY_TOKEN_RE.test(heading)) {
|
|
139
|
+
current = {
|
|
140
|
+
title: heading.replace(REVIEW_SEVERITY_TOKEN_RE, '').trim() || heading,
|
|
141
|
+
scope: 'primary',
|
|
142
|
+
lines: [line],
|
|
143
|
+
isMajor: reviewSubheadingIsMajor(heading),
|
|
144
|
+
};
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
severity = heading;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (mode === 'none' && scope.primary !== null && scope.primary.test(line)) {
|
|
151
|
+
mode = 'primary';
|
|
152
|
+
severity = '';
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
severity = h3[1].trim();
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (mode === 'none') continue;
|
|
159
|
+
const m = line.match(REVIEW_FINDING_ITEM_RE);
|
|
160
|
+
if (m) {
|
|
161
|
+
pushCurrent();
|
|
162
|
+
const title = m[1].trim();
|
|
163
|
+
current = {
|
|
164
|
+
title,
|
|
165
|
+
scope: mode,
|
|
166
|
+
lines: [line],
|
|
167
|
+
isMajor: /^major\b/i.test(severity) || REVIEW_MAJOR_LABEL_RE.test(title),
|
|
168
|
+
};
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (current) {
|
|
172
|
+
if (line.trim() === '') pushCurrent();
|
|
173
|
+
else current.lines.push(line);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
pushCurrent();
|
|
177
|
+
items.forEach((item, i) => { item.ordinal = i + 1; });
|
|
178
|
+
return items;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 旧形态 `## 发现` 段是否有实质内容(占位词 / 子标题 / 空行不计):写在旧段而模板位置无条目时
|
|
182
|
+
// 触发迁移提示——只在旧段真有内容时给,避免空段或只写「无」的旧 REVIEW 被误报。
|
|
183
|
+
function reviewLegacyFindingsHasContent(text) {
|
|
184
|
+
let inLegacy = false;
|
|
185
|
+
for (const line of String(text).split(/\r?\n/)) {
|
|
186
|
+
const h2 = line.match(/^##\s+(.+?)\s*$/);
|
|
187
|
+
if (h2) {
|
|
188
|
+
inLegacy = /^发现/.test(h2[1].trim());
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!inLegacy) continue;
|
|
192
|
+
if (/^#{3,6}\s+/.test(line)) continue;
|
|
193
|
+
const trimmed = line.trim();
|
|
194
|
+
if (trimmed === '' || REVIEW_FINDINGS_PLACEHOLDER_RE.test(trimmed)) continue;
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 发现区条目处置标记存在性:返回缺处置状态标记([已修]/[升级]/[转待办])的条目标题列表——结构级
|
|
201
|
+
// 校验(不做语义判断:标记存在即视为已处置)。发现项(含 Minor;无序与有序条目同口径,均不得
|
|
202
|
+
// "记录后无声消失")的处置标记以该条目自身标题/行首为准——正文引用他条标记不参与判定。
|
|
203
|
+
function reviewFindingsMissingDisposition(text, scope = { primary: null, siblings: [] }) {
|
|
204
|
+
return reviewFindingsItems(text, scope)
|
|
205
|
+
.filter((item) => !/^无/.test(item.title)) // "无" 条目豁免
|
|
206
|
+
// 四要素字段行豁免:REVIEW 发现条目的 Symptom/Source/Consequence/Remedy 是 brooks 审查输出
|
|
207
|
+
// 格式的字段行(带 ** 加粗),不是发现条目本身——不豁免会误判为"发现项缺处置标记"(执行者按
|
|
208
|
+
// 4 要素格式书写时被误 BLOCKED)。精确匹配完整标签(允许尾冒号)——"Source maps expose paths"
|
|
209
|
+
// 这类以 Source 开头的真实发现标题不得被前缀匹配误豁免(其处置校验必须照常进行)
|
|
210
|
+
.filter((item) => !/^(?:Symptom|Source|Consequence|Remedy)\s*:?\s*$/i.test(item.title))
|
|
211
|
+
.filter((item) => !REVIEW_DISPOSITION_RE.test(item.lines[0]))
|
|
212
|
+
.map((item) => item.title);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 裁决记录是否指向某条发现:条目标题全文 / 标题内标识 token(如 F1、m-2)/ 条目序号(发现 N、
|
|
216
|
+
// 第 N 项、#N)/ 标题核心前缀任一命中即视为指认。结构级判定,不做语义判断。
|
|
217
|
+
function reviewAdjudicationPointsTo(record, item) {
|
|
218
|
+
if (record.includes(item.title)) return true;
|
|
219
|
+
const idTokens = item.title.match(/[A-Za-z]{1,8}[-–]?\d{1,4}/g) || [];
|
|
220
|
+
if (idTokens.some((token) => record.includes(token))) return true;
|
|
221
|
+
if (new RegExp('(?:发现|条目|第|#)\\s*' + item.ordinal + '(?!\\d)').test(record)) return true;
|
|
222
|
+
const core = item.title.replace(/[\[\]【】]/g, '').replace(/^[A-Za-z]+\s*/, '').trim().slice(0, 12);
|
|
223
|
+
return core.length >= 6 && record.includes(core);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Major 延期裁决门禁:发现区任何 Major 条目处置为 [转待办] 时,必须同时存在用户裁决记录——同段
|
|
227
|
+
// (条目自身段落)或文末其余段落含「用户裁决:接受延期」且指向该条目,并由 [升级] 承接(条目自身
|
|
228
|
+
// 块或裁决记录含 [升级])。任一缺失 → 返回条目标题(调用方按新 change BLOCK / 旧 change WARN 渐进
|
|
229
|
+
// 处置)。Minor 不参与;Major [升级]/[已修] 直接放行。条目自身的处置标记([转待办])只认该条目标题
|
|
230
|
+
// /行首(无序与有序同口径),正文续行引用他条标记不触发本门禁;[升级] 承接可出现在条目自身块或
|
|
231
|
+
// 用户裁决记录中(承接非本条处置)。
|
|
232
|
+
function reviewDeferredMajorProblems(text, scope = { primary: null, siblings: [] }) {
|
|
233
|
+
const textValue = String(text);
|
|
234
|
+
const items = reviewFindingsItems(textValue, scope);
|
|
235
|
+
const paragraphs = textValue.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
|
|
236
|
+
const problems = [];
|
|
237
|
+
for (const item of items) {
|
|
238
|
+
const ownLine = item.lines[0];
|
|
239
|
+
if (!item.isMajor || !/\[转待办\]/.test(ownLine)) continue;
|
|
240
|
+
const block = item.lines.join('\n');
|
|
241
|
+
const escalatedInBlock = /\[升级\]/.test(block);
|
|
242
|
+
const blockTrimmed = block.trim();
|
|
243
|
+
if (REVIEW_ADJUDICATION_RE.test(block) && escalatedInBlock) continue; // 同段裁决 + [升级] 承接
|
|
244
|
+
const matched = paragraphs.some((paragraph) => {
|
|
245
|
+
if (!REVIEW_ADJUDICATION_RE.test(paragraph)) return false;
|
|
246
|
+
if (paragraph === blockTrimmed) return false; // 跳过条目自身段落
|
|
247
|
+
return (escalatedInBlock || /\[升级\]/.test(paragraph)) && reviewAdjudicationPointsTo(paragraph, item);
|
|
248
|
+
});
|
|
249
|
+
if (!matched) problems.push(item.title);
|
|
250
|
+
}
|
|
251
|
+
return problems;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 节点 entry 链:受控归位 → 归档分支校验 → 委托前并行写冲突 → 委托前工件 commit 提示 →
|
|
255
|
+
// 清窗恢复产物提示 → 任务集签名记录 → 协调者禁令 → 进入标记落盘 → 点名节点实现技能。
|
|
256
|
+
export async function runEntryGates({ protocol, node, state, file }) {
|
|
257
|
+
const current = state.currentNode ?? (await nextNode(protocol, state))?.id ?? null;
|
|
258
|
+
// Fix 批次受控归位(共享谓词,唯一受控例外):review/verify 驻留 + TASK 有 pending 修复任务
|
|
259
|
+
// (串行/并行)或有未闭合家族出口签名时,entry 家族节点(execute / subagent-execute)归位工作
|
|
260
|
+
// 归属并写盘;仅当入口节点与共享谓词目标一致才归位。前置 currentNode 校验对该受控例外放行
|
|
261
|
+
// (该例外允许直接 entry);其余节点/状态行为不变。
|
|
262
|
+
const fixBatchDecision = EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange
|
|
263
|
+
? await resolveFixRollbackDecision({
|
|
264
|
+
runRoot,
|
|
265
|
+
changeName: state.activeChange,
|
|
266
|
+
protocol,
|
|
267
|
+
completedNodes: state.completedNodes,
|
|
268
|
+
currentNode: state.currentNode,
|
|
269
|
+
history: state.history,
|
|
270
|
+
})
|
|
271
|
+
: null;
|
|
272
|
+
const fixBatchRollback = !!fixBatchDecision && fixBatchDecision.target === node.id;
|
|
273
|
+
if (current !== node.id && !state.completedNodes.includes(node.id) && !fixBatchRollback) {
|
|
274
|
+
console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
if (fixBatchRollback) {
|
|
278
|
+
const sourceNode = state.currentNode;
|
|
279
|
+
// 轮次计数与阈值/授权判定全部走共享 helper:分支②不计数;第 4 轮新 change 先 BLOCK
|
|
280
|
+
// (此处尚未写盘,满足不写 currentNode),旧 change WARN 后照常归位。
|
|
281
|
+
const rollbackRound = applyFixRollbackRound({ state, sourceNode, decision: fixBatchDecision });
|
|
282
|
+
if (rollbackRound.blocked) {
|
|
283
|
+
console.error(rollbackRound.blockedMessage);
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
if (rollbackRound.warn) console.error(rollbackRound.warnMessage);
|
|
287
|
+
state.currentNode = node.id;
|
|
288
|
+
console.log('FIX-BATCH: 受控归位 ' + node.id + '(源节点 ' + sourceNode + ')' + rollbackRound.auditSuffix);
|
|
289
|
+
const bad = validateStateFields(state);
|
|
290
|
+
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
291
|
+
await writeJson(file, state);
|
|
292
|
+
}
|
|
293
|
+
// entry archive 分支校验(新模式 branchMode=true)——归档必须在 change/<activeChange> 分支上进行;
|
|
294
|
+
// 旧模式(无 branchMode 字段 / 非 git 仓库 / git 不可用)跳过,向后兼容。
|
|
295
|
+
if (node.id === 'archive' && state.branchMode === true && state.activeChange) {
|
|
296
|
+
const { execFileSync } = await import('child_process');
|
|
297
|
+
try {
|
|
298
|
+
const branch = String(execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' })).trim();
|
|
299
|
+
// 归档分支前缀用 state.branchPrefix(缺省 'change/',适配仓库自身规范)
|
|
300
|
+
const archivePrefix = state.branchPrefix ?? 'change/';
|
|
301
|
+
if (branch !== archivePrefix + state.activeChange) {
|
|
302
|
+
console.error('BLOCKED: 归档必须在 ' + archivePrefix + state.activeChange + ' 分支上进行(当前: ' + branch + ')');
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
// git 不可用 → 跳过分支校验(旧模式兼容)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// 并行冲突检测——subagent-execute 委托前校验 wave 内 parallel 任务 write_files 无交集
|
|
310
|
+
// (第二道写写锚:只取强判组,行为与消息保持既有语义不变)
|
|
311
|
+
if (node.id === 'subagent-execute' && state.activeChange) {
|
|
312
|
+
const { writeConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
|
|
313
|
+
if (writeConflicts.length > 0) {
|
|
314
|
+
console.error('BLOCKED: parallel tasks write_files 冲突: ' + writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
|
|
315
|
+
process.exit(1);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// 委托前工件 commit 检查——worktree isolation 子代理看不到未提交工件(WARN 不 BLOCKED)
|
|
319
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
320
|
+
const { execFileSync } = await import('child_process');
|
|
321
|
+
try {
|
|
322
|
+
execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: runRoot, stdio: 'pipe' });
|
|
323
|
+
const statusOut = execFileSync(
|
|
324
|
+
'git',
|
|
325
|
+
['status', '--porcelain', '--', path.posix.join('.specs', state.activeChange) + '/'],
|
|
326
|
+
{ cwd: runRoot, stdio: 'pipe', encoding: 'utf8' },
|
|
327
|
+
);
|
|
328
|
+
if (String(statusOut).trim() !== '') {
|
|
329
|
+
console.error('WORKTREE WARN: .specs/' + state.activeChange + '/ 有未提交工件,worktree isolation 子代理将看不到它们——建议先 commit 或 prompt 内联上下文');
|
|
330
|
+
}
|
|
331
|
+
} catch (err) {
|
|
332
|
+
// 检测失败可见化——非 git 仓库/路径不可查时提示 SKIP 原因(防静默失效)
|
|
333
|
+
console.error('C4-CHECK SKIP: ' + (err && err.message ? String(err.message).split('\n')[0] : String(err)));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// PROGRESS.md 存在警告(清窗恢复产物,反重复检查)
|
|
337
|
+
if (node.id === 'execute' && state.activeChange) {
|
|
338
|
+
if (await fileExists(path.join(runRoot, '.specs', state.activeChange, 'PROGRESS.md'))) {
|
|
339
|
+
console.error('WARNING: PROGRESS.md 存在(清窗恢复产物),先读"已排除方案"段(R1.6 反重复)');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// enter execute / subagent-execute 记录 TASK.md 任务集签名(exit 时比对,防 execute 期间增删任务
|
|
343
|
+
// /改 action/改边界)
|
|
344
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
345
|
+
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
346
|
+
if (await fileExists(taskFile)) {
|
|
347
|
+
try {
|
|
348
|
+
state.taskHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
349
|
+
const bad = validateStateFields(state);
|
|
350
|
+
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
351
|
+
await writeJson(file, state);
|
|
352
|
+
} catch {}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// 协调者禁令:execute / subagent-execute 阶段主会话只能委托,禁止直接写源码。例外:direct 模式
|
|
356
|
+
// execute 是主代理直写(逃生口),不输出协调者禁令。
|
|
357
|
+
const entryExecutionMode = state.executionMode ?? 'subagent';
|
|
358
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
359
|
+
if (!(entryExecutionMode === 'direct' && node.id === 'execute')) {
|
|
360
|
+
console.log('COORDINATOR: 你是协调者,不是执行者。禁止在主会话直接修改源码;只能通过 Agent 工具 worktree isolation 委托子代理;子代理回传后仅更新 TASK.md / SUMMARY / handoff evidence。');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// enter 证据——entry 记录节点进入标记(enteredNodes),exit 检测未 entry(防跳过 entry 无痕)
|
|
364
|
+
state.enteredNodes = Array.isArray(state.enteredNodes) ? state.enteredNodes : [];
|
|
365
|
+
if (!state.enteredNodes.includes(node.id)) {
|
|
366
|
+
state.enteredNodes.push(node.id);
|
|
367
|
+
const bad = validateStateFields(state);
|
|
368
|
+
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
369
|
+
await writeJson(file, state);
|
|
370
|
+
// 进入已记录提示(执行者可知 entry 有副作用——进入证据写入)
|
|
371
|
+
console.log('ENTER RECORDED: ' + node.id + ' 进入已记录(enteredNodes)');
|
|
372
|
+
}
|
|
373
|
+
// 输出点名(机器点名节点技能):进入节点时机器点名该节点实现技能必须经 Skill 工具加载——
|
|
374
|
+
// skill 名取节点实现 skill(内置协议 = flow-comet-plan 等,与 SKILL: 行一致)
|
|
375
|
+
const entryImplSkill = node.implementation && typeof node.implementation === 'object' && node.implementation.skill
|
|
376
|
+
? node.implementation.skill
|
|
377
|
+
: null;
|
|
378
|
+
if (entryImplSkill) {
|
|
379
|
+
console.log('LOAD SKILL: ' + entryImplSkill + '(用 Skill 工具,禁止跳过)');
|
|
380
|
+
}
|
|
381
|
+
console.log('ENTRY OK: ' + node.id);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 出口前置:本节点 evidence 必须在场(缺失时给出补证据指引)。返回该 evidence。
|
|
385
|
+
export function requireNodeEvidence({ node, state }) {
|
|
386
|
+
const evidence = evidenceFor(state, node.id);
|
|
387
|
+
if (!evidence) {
|
|
388
|
+
console.error('BLOCKED: missing evidence for Node ' + node.id + '.');
|
|
389
|
+
console.error('恢复: 该节点已完成但缺证据记录 → 用 workflow-state.mjs record ' + node.id + ' \'{"summary":"<完成摘要>"}\' 补证据后重试;状态漂移 → advance/select;禁止手改 state 机器字段');
|
|
390
|
+
process.exit(1);
|
|
391
|
+
}
|
|
392
|
+
return evidence;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 转移前置约束——currentNode 必须等于被 exit 的节点(防跳阶段)。currentNode 已漂移到文件推导
|
|
396
|
+
// 位置(resolveNextNode(completedNodes) === currentNode,如 execute 证据/产物齐后路由已指向 review)
|
|
397
|
+
// 且本节点 evidence 齐 + 产物齐(执行者确认本节点实际已完成)→ 容错放行 exit(漂移/提前校正态可
|
|
398
|
+
// 补欠账;BLOCK 消息/提示标注「漂移态可用容错 exit」——不再只有不可行的 advance/select 指引)。
|
|
399
|
+
// 漂移但 evidence/产物不齐 → 仍严格 BLOCK(容错不放开未完成)。
|
|
400
|
+
export async function runExitDriftGate({ protocol, node, state, evidence }) {
|
|
401
|
+
if (state.currentNode === node.id) return;
|
|
402
|
+
let tolerable = false;
|
|
403
|
+
if (evidence) {
|
|
404
|
+
const derivedNext = await nextNode(protocol, state);
|
|
405
|
+
const missingDriftArtifacts = await missingRequiredArtifacts(protocol, node, state.activeChange);
|
|
406
|
+
const missingDriftSchemaEvidence = missingRequiredSchemaEvidence(protocol, node, evidence);
|
|
407
|
+
tolerable = !!(
|
|
408
|
+
derivedNext && derivedNext.id === state.currentNode
|
|
409
|
+
&& missingDriftArtifacts.length === 0
|
|
410
|
+
&& missingDriftSchemaEvidence.length === 0
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (tolerable) {
|
|
414
|
+
console.log('NOTE: 容错放行——currentNode 已为文件推导下一节点且本节点证据/产物齐(执行者确认本节点实际已完成),exit ' + node.id + ' --apply 补齐欠账(漂移容忍路径)');
|
|
415
|
+
}
|
|
416
|
+
if (!tolerable) {
|
|
417
|
+
console.error('BLOCKED: currentNode is ' + String(state.currentNode) + ', cannot exit ' + node.id + '.');
|
|
418
|
+
console.error('恢复: 若节点状态漂移/卡死 → 用 workflow-state.mjs advance(强制推进,确认节点实际已完成后再用)或 select(切换 change);禁止手改 state 机器字段');
|
|
419
|
+
console.error('提示: 若 currentNode 已漂移到文件推导位置且本节点证据/产物齐(执行者确认本节点实际已完成)→ 可用容错 exit ' + node.id + ' --apply 补齐欠账(漂移容忍路径,不再只有不可行的 advance/select 指引);漂移但证据/产物不齐则不适用');
|
|
420
|
+
process.exit(1);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Fix 批次越界拦截——源节点(review/verify)驻留,且 TASK 仍有 pending 修复任务,或修复任务已
|
|
425
|
+
// done 但本批 execute 家族生命周期未闭合(本 change 最新家族出口签名 ≠ 当前任务集签名)时,直接
|
|
426
|
+
// exit 源节点收场会静默跳过 execute 家族生命周期与四类出口(缺陷形态)。排在 entry 证据门之前:
|
|
427
|
+
// 该越界路径给 Fix 恢复指引,避免通用 entry 提示覆盖更具体的归位路径。复用共享回退谓词判定:
|
|
428
|
+
// 新 change 强制 BLOCKED 含恢复指引;旧 change 渐进 WARN 不阻断。
|
|
429
|
+
export async function runFixBatchExitGate({ protocol, node, state }) {
|
|
430
|
+
if ((node.id !== 'review' && node.id !== 'verify') || !state.activeChange) return;
|
|
431
|
+
const fixBatchUnclosed = await resolveFixRollbackState({
|
|
432
|
+
runRoot,
|
|
433
|
+
changeName: state.activeChange,
|
|
434
|
+
protocol,
|
|
435
|
+
completedNodes: state.completedNodes,
|
|
436
|
+
currentNode: node.id,
|
|
437
|
+
history: state.history,
|
|
438
|
+
});
|
|
439
|
+
if (fixBatchUnclosed && isNewChange(state)) {
|
|
440
|
+
console.error('BLOCKED: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合(最近一次 execute 家族 exit 后任务集仍有变更),不能直接 exit ' + node.id + ' 收场(会静默跳过 execute 家族生命周期与四类出口)');
|
|
441
|
+
console.error('恢复: 运行 workflow-state.mjs next 或 workflow-guard.mjs entry execute / entry subagent-execute 受控归位 execute 家族节点 → 在 execute 家族生命周期内完成修复任务 → record/exit 该节点 --apply 跑完四类出口并回源节点 ' + node.id + ' → 再 exit ' + node.id + ' --apply');
|
|
442
|
+
process.exit(1);
|
|
443
|
+
}
|
|
444
|
+
if (fixBatchUnclosed) {
|
|
445
|
+
console.error('FIX-BATCH WARN: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合,直接 exit ' + node.id + ' 会跳过 execute 家族出口门禁(旧 change 渐进不阻断;建议 next/entry execute 家族节点归位跑完出口后回源节点 exit)');
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// enter 证据检测——未 entry 直接 exit:新 change(init 标记)强制 BLOCKED,旧 change 渐进 WARN。
|
|
450
|
+
// 跳过 entry 会漏掉进入检查(协调者禁令 / 委托前工件 commit 提示 / PROGRESS 提示 / 签名记录)。
|
|
451
|
+
export function runEntryRecordGate({ node, state }) {
|
|
452
|
+
if (isNewChange(state)) {
|
|
453
|
+
if (!Array.isArray(state.enteredNodes) || !state.enteredNodes.includes(node.id)) {
|
|
454
|
+
console.error('BLOCKED: 节点 ' + node.id + ' 未执行 entry 直接 exit——新 change 强制先 entry(进入检查/协调者禁令/签名记录)');
|
|
455
|
+
console.error('恢复: 先运行 workflow-guard.mjs entry ' + node.id + ' 再重试 exit;状态漂移 → advance/select');
|
|
456
|
+
process.exit(1);
|
|
457
|
+
}
|
|
458
|
+
} else if (Array.isArray(state.enteredNodes) && !state.enteredNodes.includes(node.id)) {
|
|
459
|
+
console.error('ENTER WARN: 节点 ' + node.id + ' 未执行 entry 直接 exit——entry 的进入检查(协调者禁令/C4 委托前检查/签名记录)被跳过,请先 entry 该节点再 exit(旧 change 渐进不阻断)');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// exit archive 分支合并检查(WARN 不 BLOCK)——分支未合并到 main 允许"归档先行、合并后补"
|
|
464
|
+
export async function runArchiveBranchMergeGate({ node, state }) {
|
|
465
|
+
if (node.id !== 'archive' || state.branchMode !== true || !state.activeChange) return;
|
|
466
|
+
const { execFileSync } = await import('child_process');
|
|
467
|
+
try {
|
|
468
|
+
const branch = String(execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' })).trim();
|
|
469
|
+
const mergedOut = String(execFileSync('git', ['branch', '--merged', 'main'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' }));
|
|
470
|
+
const mergedBranches = mergedOut.split('\n').map(l => l.trim().replace(/^\*\s*/, ''));
|
|
471
|
+
if (!mergedBranches.includes(branch)) {
|
|
472
|
+
console.error('WARN: 分支 change/' + state.activeChange + ' 未合并到 main——归档后请完成 merge + 删除分支');
|
|
473
|
+
}
|
|
474
|
+
} catch {
|
|
475
|
+
// git 不可用 / main 不存在 → 跳过合并检查
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// 特化校验按节点 id 绑定(ADR-002 分层):内置节点 id 触发 flow-kit 契约校验;自定义协议节点不
|
|
480
|
+
// 误触发(通用层防线对其生效)。
|
|
481
|
+
// 追加位置结构检测(全部 WARN 不 BLOCK)——防 CONTEXT/LESSONS/STATE/CHANGELOG 文件尾追加破坏
|
|
482
|
+
// 插入位置纪律;open 出口另做 CONTEXT 模板段校验(项目级工件不受 C3 节点映射约束,也不要求
|
|
483
|
+
// skill-load 声明模板——C17)。
|
|
484
|
+
// 条件子段(C21):`自定义 hooks(前端)` 只在前端 change 要求;其余子段无条件要求(未发现的写
|
|
485
|
+
// 「未发现」)。前端判定沿用 CHANGE.md「视觉调性」段的既有判据(单一实现)。
|
|
486
|
+
const CONTEXT_FRONTEND_ONLY_SUBSECTION = '自定义 hooks';
|
|
487
|
+
|
|
488
|
+
// CONTEXT 模板段问题清单:段集合取自骨架(模板 = 内容权威),段标题按段名归一匹配(忽略编号 /
|
|
489
|
+
// 括号后缀 / 大小写,AC-9);父段缺席时不再列其子段(父段已单独报出,避免同一事实重复计数)。
|
|
490
|
+
// 模板缺席(derived=false)→ 返回 null:模板派生判据整体跳过,由调用方输出显式「未校验(模板缺失)」
|
|
491
|
+
// ——不退回任何内置段名副本。
|
|
492
|
+
async function contextTemplateProblems(state, content) {
|
|
493
|
+
const skeleton = await buildSkeleton('CONTEXT');
|
|
494
|
+
if (!skeleton.derived) return null;
|
|
495
|
+
const problems = [];
|
|
496
|
+
for (const section of skeleton.sections) {
|
|
497
|
+
if (!section.pattern.test(content)) problems.push('缺段「## ' + section.name + '」');
|
|
498
|
+
}
|
|
499
|
+
const frontend = await frontendCriterion(state.activeChange);
|
|
500
|
+
for (const sub of skeleton.structureSubsections) {
|
|
501
|
+
if (!frontend.applicable && sub.name.includes(CONTEXT_FRONTEND_ONLY_SUBSECTION)) continue;
|
|
502
|
+
const parent = skeleton.sections.find((section) => section.name === sub.parent);
|
|
503
|
+
if (parent && !parent.pattern.test(content)) continue;
|
|
504
|
+
if (!sub.pattern.test(content)) problems.push('缺子段「### ' + sub.name + '」');
|
|
505
|
+
}
|
|
506
|
+
return problems;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export async function runContextAppendGate({ node, state }) {
|
|
510
|
+
if (node.id !== 'open' || !state.activeChange) return;
|
|
511
|
+
const contextFile = path.join(runRoot, '.specs', 'CONTEXT.md');
|
|
512
|
+
if (!(await fileExists(contextFile))) return; // 项目级工件可缺席:文件存在才查
|
|
513
|
+
let content = null;
|
|
514
|
+
try { content = await fs.readFile(contextFile, 'utf8'); } catch { content = null; }
|
|
515
|
+
if (content === null) return;
|
|
516
|
+
const m = content.match(/^## (术语|已锁决策|决策|术语表)[((][^\n]*(?:追加|update)[^\n]*$/im);
|
|
517
|
+
if (m) {
|
|
518
|
+
if (isNewChange(state)) {
|
|
519
|
+
console.error('BLOCKED: CONTEXT.md 检测到孤立追加段(新 change 强制插入既有结构段);恢复: 把内容移入术语表/已锁决策段');
|
|
520
|
+
process.exit(1);
|
|
521
|
+
}
|
|
522
|
+
console.error('WARN: CONTEXT.md 检测到孤立追加段(术语/决策应插入既有结构段):' + m[0].replace(/^##\s*/, '').trim());
|
|
523
|
+
}
|
|
524
|
+
const problems = await contextTemplateProblems(state, content);
|
|
525
|
+
if (problems === null) {
|
|
526
|
+
// 模板缺席:段形校验跳过但显式声明(未验证 ≠ 通过),修复指引给出取模板的途径
|
|
527
|
+
console.error('CONTEXT 未校验(模板缺失)——flow-kit/templates/CONTEXT.md 不在项目根,段形校验跳过'
|
|
528
|
+
+ '(修复: 按安装指引获取 flow-kit 模板后重试)');
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (problems.length === 0) return;
|
|
532
|
+
if (isNewChange(state)) {
|
|
533
|
+
console.error('BLOCKED: CONTEXT.md 有 ' + problems.length + ' 处与模板段形不符(新 change 强制项目上下文按模板段形书写):');
|
|
534
|
+
for (const problem of problems) console.error(' - ' + problem);
|
|
535
|
+
console.error('恢复: 按 flow-kit/templates/CONTEXT.md 补齐段标题(未发现的写「未发现」;前端子段按条件段裁剪)后重试 exit open');
|
|
536
|
+
process.exit(1);
|
|
537
|
+
}
|
|
538
|
+
console.error('WARN: CONTEXT.md 有 ' + problems.length + ' 处与模板段形不符(旧 change 渐进不阻断): '
|
|
539
|
+
+ problems.join('、'));
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// LESSONS.md 结构检测(每条判据的作用面逐个交代):
|
|
543
|
+
// ① 旧形态 `## L-NNN`(条目写成二级标题)——open / verify / archive 三处出口都拦(AC-17),新
|
|
544
|
+
// change BLOCKED 并逐行给「文件:行号 → 改法」,旧 change WARN 渐进;
|
|
545
|
+
// ② 条目区外条目(条目区锚点用段名归一,容忍模板标题的括号后缀,如 `## 条目区(夹具)`)与
|
|
546
|
+
// ③ 同段内编号递增——两条保持既有作用面(verify / archive),不随 ① 扩到 open;
|
|
547
|
+
// ④ `### L-NNN` 条目的字段键(C20)——键集合从 LESSONS 模板「条目格式」段的书写样例派生;新 change
|
|
548
|
+
// 的新条目缺任一键 BLOCKED,旧条目(迁移形态 / 首发指向别的 change)与旧 change 只 WARN;
|
|
549
|
+
// ⑤ archive 出口核对 evidence.lessonsNomination:扫描份数 = 该 change 内 SUMMARY 份数、提名编号在
|
|
550
|
+
// LESSONS 中真实存在、无提名时理由非空——归档提名留痕且可核对。
|
|
551
|
+
const LESSONS_LEGACY_ENTRY_RE = /^##\s+(L-\d+)\b/u;
|
|
552
|
+
const LESSONS_ENTRY_ZONE_NAMES = ['条目区', '活跃条目', '已解决条目'];
|
|
553
|
+
// `### L-NNN` 条目块(后接非数字/非字母,避免吞掉更长编号)。模板条目形态 = `### L-NNN · [tag] 标题`
|
|
554
|
+
// (「条目格式」段给出的书写样例);迁移形态(`### L-NNN:` 冒号标题)与裸标题(`### L-NNN`)等
|
|
555
|
+
// 历史写法一律按旧条目处置(不足字段只 WARN)——新条目的判定因此只看「模板标题形态 + 字段键」。
|
|
556
|
+
const LESSONS_ENTRY_HEADING_RE = /^###\s*(L-\d+)(?![\dA-Za-z])/u;
|
|
557
|
+
const LESSONS_TEMPLATE_HEADING_RE = /^###\s*L-\d+\s*·/u;
|
|
558
|
+
// 字段键行:`- **<键>**: <值>`(条目正文里的粗体小标题不带列表符,不会命中)。
|
|
559
|
+
const LESSONS_FIELD_LINE_RE = /^[-*]\s*\*\*(.+?)\*\*\s*[::]\s*(.*)$/u;
|
|
560
|
+
|
|
561
|
+
// 旧形态条目行(行号 1 基):迁移指引逐行可执行,执行者不必自己数行号。
|
|
562
|
+
function lessonsLegacyEntries(content) {
|
|
563
|
+
const hits = [];
|
|
564
|
+
String(content).split(/\r?\n/).forEach((line, index) => {
|
|
565
|
+
const matched = line.match(LESSONS_LEGACY_ENTRY_RE);
|
|
566
|
+
if (matched) hits.push({ line: index + 1, id: matched[1] });
|
|
567
|
+
});
|
|
568
|
+
return hits;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 该 change 的 SUMMARY 份数(C6:先看活动目录,目录已移入归档时看 `.specs/archive/*-<change>/`;
|
|
572
|
+
// 两处都不存在 → null = 归档产物缺失——不可核对的份数不当作 0)。
|
|
573
|
+
async function changeSummaryCount(changeName) {
|
|
574
|
+
const activeDir = path.join(runRoot, '.specs', changeName);
|
|
575
|
+
let dir = null;
|
|
576
|
+
if (await fileExists(activeDir)) {
|
|
577
|
+
dir = activeDir;
|
|
578
|
+
} else {
|
|
579
|
+
const archiveRoot = path.join(runRoot, '.specs', 'archive');
|
|
580
|
+
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
581
|
+
const archived = entries.find((entry) => entry.endsWith('-' + changeName));
|
|
582
|
+
if (archived) dir = path.join(archiveRoot, archived);
|
|
583
|
+
}
|
|
584
|
+
if (dir === null) return null;
|
|
585
|
+
const files = await fs.readdir(dir).catch(() => []);
|
|
586
|
+
return files.filter((name) => name.endsWith('-SUMMARY.md')).length;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// LESSONS 里已登记的条目编号(旧形态与迁移后的新形态都算「编号存在」——形态由 ① 单独校验,
|
|
590
|
+
// 存在性只判编号是否真实登记)。
|
|
591
|
+
async function lessonsEntryNumbers() {
|
|
592
|
+
const lessonsFile = path.join(runRoot, '.specs', 'LESSONS.md');
|
|
593
|
+
let content;
|
|
594
|
+
try { content = await fs.readFile(lessonsFile, 'utf8'); } catch { return new Set(); }
|
|
595
|
+
const numbers = new Set();
|
|
596
|
+
for (const matched of String(content).matchAll(/^#{2,3}\s*L-(\d+)/gm)) numbers.add(parseInt(matched[1], 10));
|
|
597
|
+
return numbers;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// 归档提名核对(结构级):evidence.lessonsNomination = { scanned, nominated[], reasonIfNone }。
|
|
601
|
+
async function lessonsNominationProblems(state) {
|
|
602
|
+
const nomination = evidenceFor(state, 'archive')?.lessonsNomination;
|
|
603
|
+
if (!nomination || typeof nomination !== 'object' || Array.isArray(nomination)) {
|
|
604
|
+
return ['缺 evidence.lessonsNomination(应记录 { scanned, nominated[], reasonIfNone })'];
|
|
605
|
+
}
|
|
606
|
+
const problems = [];
|
|
607
|
+
const actual = await changeSummaryCount(state.activeChange);
|
|
608
|
+
if (actual === null) {
|
|
609
|
+
problems.push('该 change 的工件目录缺失(.specs/<change>/ 与 .specs/archive/*-<change>/ 都不存在),无从核对扫描份数');
|
|
610
|
+
} else if (nomination.scanned !== actual) {
|
|
611
|
+
problems.push('扫描份数 ' + JSON.stringify(nomination.scanned ?? null)
|
|
612
|
+
+ ' ≠ 该 change 内 *-SUMMARY.md 份数 ' + actual);
|
|
613
|
+
}
|
|
614
|
+
if (!Array.isArray(nomination.nominated)) {
|
|
615
|
+
problems.push('lessonsNomination.nominated 须为数组(无提名写 [])');
|
|
616
|
+
} else if (nomination.nominated.length === 0) {
|
|
617
|
+
if (!(typeof nomination.reasonIfNone === 'string' && nomination.reasonIfNone.trim() !== '')) {
|
|
618
|
+
problems.push('无提名时 lessonsNomination.reasonIfNone 不能为空(写明本轮为何没有条目入库)');
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
const known = await lessonsEntryNumbers();
|
|
622
|
+
for (const id of nomination.nominated) {
|
|
623
|
+
const matched = typeof id === 'string' ? id.match(/^L-(\d+)$/iu) : null;
|
|
624
|
+
if (matched === null) {
|
|
625
|
+
problems.push('提名编号格式非法: ' + JSON.stringify(id) + '(应为 L-NNN)');
|
|
626
|
+
} else if (!known.has(parseInt(matched[1], 10))) {
|
|
627
|
+
problems.push('提名编号在 LESSONS.md 中不存在: ' + id);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return problems;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// ① 旧形态条目(`## L-NNN`):open / verify / archive 三处出口都拦(AC-17)——报文逐行给「文件:
|
|
635
|
+
// 行号 → 改法」,迁移口径 = 改级 + 移入条目区 + 按编号排序。新 change BLOCKED / 旧 change WARN。
|
|
636
|
+
function checkLessonsEntryForm({ content, node, state }) {
|
|
637
|
+
const legacyEntries = lessonsLegacyEntries(content);
|
|
638
|
+
if (legacyEntries.length === 0) return;
|
|
639
|
+
if (isNewChange(state)) {
|
|
640
|
+
console.error('BLOCKED: LESSONS.md 有 ' + legacyEntries.length + ' 条旧形态条目(## L-NNN)——新 change 强制条目写成三级标题并置于条目区:');
|
|
641
|
+
for (const entry of legacyEntries) {
|
|
642
|
+
console.error(' - .specs/LESSONS.md:' + entry.line + ' → 改成 "### ' + entry.id + '"(并移入 ## 条目区,按编号升序)');
|
|
643
|
+
}
|
|
644
|
+
console.error('恢复: 逐行按上述改法迁移(改级 + 移入条目区 + 按编号排序)后重试 exit ' + node.id);
|
|
645
|
+
process.exit(1);
|
|
646
|
+
}
|
|
647
|
+
console.error('WARN: LESSONS.md 有 ' + legacyEntries.length + ' 条旧形态条目(应为 ### L-NNN 并置于条目区;旧 change 渐进不阻断): '
|
|
648
|
+
+ legacyEntries.map((entry) => '.specs/LESSONS.md:' + entry.line + ' → ### ' + entry.id).join('、'));
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// ② 条目区外条目 + ③ 同段内编号递增:既有结构判据保持原作用面(verify / archive)——open 出口只
|
|
652
|
+
// 新增 ① 的旧形态迁移判据,不顺手把这两条扩张到 open(判据作用面按 AC 逐个交代)。
|
|
653
|
+
function checkLessonsZoneAndOrder({ content, state }) {
|
|
654
|
+
// 条目区锚点(段名归一:条目区 / 活跃条目 / 已解决条目,容忍括号后缀)——取最早条目段
|
|
655
|
+
const zoneIndex = (() => {
|
|
656
|
+
const hits = LESSONS_ENTRY_ZONE_NAMES
|
|
657
|
+
.map((name) => content.search(headingPattern(name, 2)))
|
|
658
|
+
.filter((index) => index !== -1);
|
|
659
|
+
return hits.length ? Math.min(...hits) : -1;
|
|
660
|
+
})();
|
|
661
|
+
const headings = [...content.matchAll(/^###\s*L-(\d+)/gm)];
|
|
662
|
+
if (zoneIndex !== -1) {
|
|
663
|
+
const outside = headings.some(h => h.index < zoneIndex);
|
|
664
|
+
if (outside) {
|
|
665
|
+
if (isNewChange(state)) {
|
|
666
|
+
console.error('BLOCKED: LESSONS.md 有条目在条目区外(新 change 强制条目插入条目区);恢复: 移入条目区');
|
|
667
|
+
process.exit(1);
|
|
668
|
+
}
|
|
669
|
+
// 诊断信息附带 zoneIndex/条目位置——偶发 WARN 排查时可直接定位(文件时序/编码差异兜底)
|
|
670
|
+
console.error('WARN: LESSONS.md 有条目在条目区外(zoneIndex=' + zoneIndex + ', 条目数=' + headings.length + ', 区外条目: ' + headings.filter(h => h.index < zoneIndex).map(h => 'L-' + h[1]).join(',') + ')');
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
const nums = headings.map(h => parseInt(h[1], 10));
|
|
674
|
+
// 分段检测:按 ## 标题分段,仅同段内比较编号递增(多段 LESSONS 如「活跃条目/已解决条目」编号体系可独立)
|
|
675
|
+
const sectionStarts = [...content.matchAll(/^##\s+.*$/gm)].map(m => m.index);
|
|
676
|
+
for (let i = 1; i < nums.length; i++) {
|
|
677
|
+
const sameSection = !sectionStarts.some(s => s > headings[i - 1].index && s < headings[i].index);
|
|
678
|
+
if (sameSection && nums[i] <= nums[i - 1]) {
|
|
679
|
+
if (isNewChange(state)) {
|
|
680
|
+
console.error('BLOCKED: LESSONS.md 条目编号乱序(新 change 强制按编号插入条目区);恢复: 按 L-NNN 顺序插入');
|
|
681
|
+
process.exit(1);
|
|
682
|
+
}
|
|
683
|
+
console.error('WARN: LESSONS.md 条目编号乱序(L-' + String(nums[i]).padStart(3, '0') + ' 应按序插入条目区)');
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// ④ 条目字段键(C20):键集合从 LESSONS 模板「条目格式」段的书写样例派生(不写字面第二份清单)。
|
|
690
|
+
// 模板缺席 / 无「条目格式」段 / 样例无字段行 → null——调用方显式声明「未校验(模板缺失)」,不臆造。
|
|
691
|
+
async function lessonsEntryFieldKeys() {
|
|
692
|
+
const skeleton = await buildSkeleton('LESSONS');
|
|
693
|
+
if (!skeleton.derived) return null;
|
|
694
|
+
const formatSection = skeleton.sections.find((section) => section.norm.includes('条目格式'));
|
|
695
|
+
if (!formatSection) return null;
|
|
696
|
+
// 模板按 runRoot 解析:登记表的 file 是项目根相对路径,而 guard 可能在与项目根不同的 cwd
|
|
697
|
+
// 被调起(运行上下文由 FLOW_COMET_RUN_ROOT 给定)。按 cwd 读会在模板在场时也判「模板缺失」,
|
|
698
|
+
// 字段键无从派生 → C20 静默退化为「未校验」。
|
|
699
|
+
let text;
|
|
700
|
+
try { text = await fs.readFile(path.join(runRoot, skeleton.file), 'utf8'); } catch { return null; }
|
|
701
|
+
const keys = [];
|
|
702
|
+
let inSection = false;
|
|
703
|
+
let inFence = false;
|
|
704
|
+
for (const line of String(text).replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n').split('\n')) {
|
|
705
|
+
if (!inSection) {
|
|
706
|
+
if (formatSection.pattern.test(line)) inSection = true;
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (/^##\s+/u.test(line)) break;
|
|
710
|
+
if (/^\s*```/u.test(line)) { inFence = !inFence; continue; }
|
|
711
|
+
if (!inFence) continue;
|
|
712
|
+
const matched = line.match(LESSONS_FIELD_LINE_RE);
|
|
713
|
+
if (matched) keys.push(matched[1].trim());
|
|
714
|
+
}
|
|
715
|
+
return keys.length > 0 ? keys : null;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// `### L-NNN` 条目块:标题行 + 其后各行,直到下一个 H2/H3 标题;围栏内的书写样例不算条目
|
|
719
|
+
// (模板的条目格式样例就是 fenced 形态)——与 LESSONS 关键词扫描的围栏口径一致。
|
|
720
|
+
function lessonsEntryBlocks(content) {
|
|
721
|
+
const blocks = [];
|
|
722
|
+
let current = null;
|
|
723
|
+
let inFence = false;
|
|
724
|
+
String(content).replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n').split('\n').forEach((line, index) => {
|
|
725
|
+
if (/^\s*```/u.test(line)) {
|
|
726
|
+
inFence = !inFence;
|
|
727
|
+
if (current) current.lines.push(line);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (inFence) {
|
|
731
|
+
if (current) current.lines.push(line);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (/^#{2,3}\s/u.test(line)) {
|
|
735
|
+
const matched = line.match(LESSONS_ENTRY_HEADING_RE);
|
|
736
|
+
current = matched === null ? null : { id: matched[1], line: index + 1, heading: line, lines: [line] };
|
|
737
|
+
if (current) blocks.push(current);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (current) current.lines.push(line);
|
|
741
|
+
});
|
|
742
|
+
return blocks;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// 旧条目判定(结构级,不做语义判断):非模板标题形态(迁移冒号形态 / 裸标题等历史写法,含 T11
|
|
746
|
+
// 迁移保留原标题形态的条目)或「首发」键指向别的 change。其余缺字段条目按「新条目」处置——
|
|
747
|
+
// 新条目只有标题与正文(无任何字段键)时同样落在 BLOCK 分支(M-5 的失效模式)。
|
|
748
|
+
function lessonsEntryIsOld(block, originKey, state) {
|
|
749
|
+
if (!LESSONS_TEMPLATE_HEADING_RE.test(block.heading)) return true;
|
|
750
|
+
if (originKey === null) return false;
|
|
751
|
+
for (const line of block.lines.slice(1)) {
|
|
752
|
+
const matched = line.match(LESSONS_FIELD_LINE_RE);
|
|
753
|
+
if (matched && matched[1].trim() === originKey) {
|
|
754
|
+
const origin = matched[2].trim();
|
|
755
|
+
return origin !== '' && !origin.includes(state.activeChange);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// ④ 字段键存在性(C20):新 change 的新条目缺任一键 → BLOCKED;旧条目 / 旧 change → WARN 渐进。
|
|
762
|
+
function checkLessonsEntryFields({ content, node, state, keys }) {
|
|
763
|
+
const originKey = keys.find((key) => key.includes('首发')) ?? null;
|
|
764
|
+
const blocked = [];
|
|
765
|
+
const warned = [];
|
|
766
|
+
for (const block of lessonsEntryBlocks(content)) {
|
|
767
|
+
const present = new Map();
|
|
768
|
+
for (const line of block.lines.slice(1)) {
|
|
769
|
+
const matched = line.match(LESSONS_FIELD_LINE_RE);
|
|
770
|
+
if (matched && !present.has(matched[1].trim())) present.set(matched[1].trim(), matched[2].trim());
|
|
771
|
+
}
|
|
772
|
+
const missing = keys.filter((key) => !present.has(key));
|
|
773
|
+
if (missing.length === 0) continue;
|
|
774
|
+
(lessonsEntryIsOld(block, originKey, state) ? warned : blocked)
|
|
775
|
+
.push({ id: block.id, line: block.line, missing });
|
|
776
|
+
}
|
|
777
|
+
const describe = (entry) => '.specs/LESSONS.md:' + entry.line + ' ' + entry.id
|
|
778
|
+
+ '(缺 ' + entry.missing.join('/') + ')';
|
|
779
|
+
if (warned.length > 0) {
|
|
780
|
+
console.error('LESSONS WARN: LESSONS.md 有 ' + warned.length + ' 条旧条目缺字段键(迁移/既有条目渐进不阻断): '
|
|
781
|
+
+ warned.map(describe).join('、'));
|
|
782
|
+
}
|
|
783
|
+
if (blocked.length === 0) return;
|
|
784
|
+
const guide = '恢复: 按 flow-kit/templates/LESSONS.md「条目格式」段补全字段键(' + keys.join(' / ')
|
|
785
|
+
+ ';正文块不强制)后重试 exit ' + node.id;
|
|
786
|
+
if (!isNewChange(state)) {
|
|
787
|
+
console.error('LESSONS WARN: LESSONS.md 有 ' + blocked.length + ' 条条目缺字段键(旧 change 渐进不阻断): '
|
|
788
|
+
+ blocked.map(describe).join('、') + ';' + guide);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
console.error('BLOCKED: LESSONS.md 有 ' + blocked.length + ' 条新条目缺字段键(新 change 强制新条目按模板条目格式书写):');
|
|
792
|
+
for (const entry of blocked) console.error(' - ' + describe(entry));
|
|
793
|
+
console.error(guide);
|
|
794
|
+
process.exit(1);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// ⑤ archive 出口的归档提名核对(对账 SUMMARY 份数 / 提名编号存在性 / 无提名理由)——归档提名
|
|
798
|
+
// 留痕且可核对。新 change BLOCKED / 旧 change WARN(C10)。
|
|
799
|
+
async function checkLessonsNomination({ state }) {
|
|
800
|
+
const problems = await lessonsNominationProblems(state);
|
|
801
|
+
if (problems.length === 0) return;
|
|
802
|
+
if (isNewChange(state)) {
|
|
803
|
+
console.error('BLOCKED: archive 出口的 evidence.lessonsNomination 不成立(' + problems.length + ' 项):');
|
|
804
|
+
for (const problem of problems) console.error(' - ' + problem);
|
|
805
|
+
console.error('恢复: workflow-state.mjs record archive \'{"summary":"<归档摘要>","lessonsNomination":'
|
|
806
|
+
+ '{"scanned":<该 change 内 SUMMARY 份数>,"nominated":["L-NNN"],"reasonIfNone":"<无提名时的理由>"}}\' 补齐后重试 exit archive');
|
|
807
|
+
process.exit(1);
|
|
808
|
+
}
|
|
809
|
+
console.error('NOMINATION WARN: evidence.lessonsNomination 不成立(旧 change 渐进不阻断): ' + problems.join(';'));
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export async function runLessonsZoneGate({ node, state }) {
|
|
813
|
+
if (!['open', 'verify', 'archive'].includes(node.id) || !state.activeChange) return;
|
|
814
|
+
const lessonsFile = path.join(runRoot, '.specs', 'LESSONS.md');
|
|
815
|
+
let content = null;
|
|
816
|
+
try { content = await fs.readFile(lessonsFile, 'utf8'); } catch { content = null; }
|
|
817
|
+
if (content !== null) {
|
|
818
|
+
checkLessonsEntryForm({ content, node, state });
|
|
819
|
+
if (node.id !== 'open') {
|
|
820
|
+
checkLessonsZoneAndOrder({ content, state });
|
|
821
|
+
const fieldKeys = await lessonsEntryFieldKeys();
|
|
822
|
+
if (fieldKeys === null) {
|
|
823
|
+
console.error('LESSONS 条目字段 未校验(模板缺失)——flow-kit/templates/LESSONS.md 或其「条目格式」样例缺席,'
|
|
824
|
+
+ '字段键无法派生(修复: 按安装指引获取 flow-kit 模板后重试)');
|
|
825
|
+
} else {
|
|
826
|
+
checkLessonsEntryFields({ content, node, state, keys: fieldKeys });
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
if (node.id === 'archive') await checkLessonsNomination({ state });
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// STATE.md / CHANGELOG.md 倒序检测(archive 出口):决策日志与表格条目应顶部插入(新→旧)
|
|
834
|
+
export async function runArchiveLogOrderGate({ node, state }) {
|
|
835
|
+
if (node.id !== 'archive') return;
|
|
836
|
+
const stateMd = path.join(runRoot, 'STATE.md');
|
|
837
|
+
try {
|
|
838
|
+
const content = await fs.readFile(stateMd, 'utf8');
|
|
839
|
+
const dates = [...content.matchAll(/^- `?\[(\d{4}-\d{2}-\d{2})\]/gm)].map(m => m[1]);
|
|
840
|
+
for (let i = 1; i < dates.length; i++) {
|
|
841
|
+
if (dates[i] > dates[i - 1]) {
|
|
842
|
+
if (isNewChange(state)) {
|
|
843
|
+
console.error('BLOCKED: STATE.md 决策日志非倒序(新 change 强制顶部插入);恢复: 顶部插入新决策');
|
|
844
|
+
process.exit(1);
|
|
845
|
+
}
|
|
846
|
+
console.error('WARN: STATE.md 决策日志非倒序(新决策应插入顶部)');
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
} catch {}
|
|
851
|
+
const changelogFile = path.join(runRoot, '.specs', 'CHANGELOG.md');
|
|
852
|
+
try {
|
|
853
|
+
const content = await fs.readFile(changelogFile, 'utf8');
|
|
854
|
+
const dates = [...content.matchAll(/^\| (\d{4}-\d{2}-\d{2}) \|/gm)].map(m => m[1]);
|
|
855
|
+
for (let i = 1; i < dates.length; i++) {
|
|
856
|
+
if (dates[i] > dates[i - 1]) {
|
|
857
|
+
if (isNewChange(state)) {
|
|
858
|
+
console.error('BLOCKED: CHANGELOG.md 表格日期非倒序(新 change 强制顶部插入);恢复: 表格顶部插入新条目');
|
|
859
|
+
process.exit(1);
|
|
860
|
+
}
|
|
861
|
+
console.error('WARN: CHANGELOG.md 表格日期非倒序(新条目应插入表格顶部)');
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
// 归档收尾登记兜底(WARN 渐进,新旧一致)——CHANGELOG 未含本 change 标识(change-id)→ 提示
|
|
866
|
+
// 补登记,防静默遗漏(提交信息声称已登记但实际未改时机制无兜底;检测为存在级——含 change-id
|
|
867
|
+
// 字样即视为已登记)
|
|
868
|
+
if (state.activeChange && !content.includes(state.activeChange)) {
|
|
869
|
+
console.error('WARN: CHANGELOG.md 未登记本 change(' + state.activeChange + ')——归档收尾应在 CHANGELOG 顶部插入本 change 条目(跟随项目既有格式)');
|
|
870
|
+
}
|
|
871
|
+
} catch {}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// 每个节点合法 exit 必须满足前置 evidence(对应 flowkit.*.v1 的 evidence)。语义与
|
|
875
|
+
// missingRequiredSchemaEvidence 一致:summary 视同满足(record 命令默认只写 summary)。
|
|
876
|
+
export function runTransitionEvidenceGate({ node, evidence }) {
|
|
877
|
+
const gate = NODE_TRANSITION_GATES[node.id];
|
|
878
|
+
if (!gate) return;
|
|
879
|
+
for (const ev of gate.evidence) {
|
|
880
|
+
// subagent-execute 的 handoff-result gate 兼容共用证据库——委托结果记录在嵌套 handoffResult
|
|
881
|
+
// (键名契约 handoff-result vs handoffResult 错位),非空即满足(存在性校验;每个委托内容的
|
|
882
|
+
// Return Contract 严格校验由 Return Contract 校验负责)
|
|
883
|
+
const satisfied = hasEvidenceField(evidence, ev) ||
|
|
884
|
+
(typeof evidence.summary === 'string' && evidence.summary.trim() !== '') ||
|
|
885
|
+
(node.id === 'subagent-execute' && ev === 'handoff-result' && hasNonEmptyHandoffResult(evidence));
|
|
886
|
+
if (!satisfied) {
|
|
887
|
+
console.error('BLOCKED: node ' + node.id + ' exit requires evidence: ' + ev);
|
|
888
|
+
process.exit(1);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// exit execute / subagent-execute 校验 TASK.md 任务集签名未变(status 标记 done 合法已剥离;
|
|
894
|
+
// 增删任务/改 action/改边界 BLOCKED)
|
|
895
|
+
export async function runTaskSetSignatureExitGate({ node, state }) {
|
|
896
|
+
if (!EXECUTE_FAMILY_NODE_IDS.has(node.id) || !state.activeChange) return;
|
|
897
|
+
if (!(typeof state.taskHash === 'string' && state.taskHash.length > 0)) return;
|
|
898
|
+
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
899
|
+
if (!(await fileExists(taskFile))) return;
|
|
900
|
+
try {
|
|
901
|
+
const currentHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
902
|
+
if (taskSetSignatureVersionSkew(state.taskHash, currentHash)) {
|
|
903
|
+
// 跨算法版本不做一致性比对(值不可比),不误拦任务集;要强制一致需重新 entry 重建签名
|
|
904
|
+
const storedAlgo = parseTaskSetSignature(state.taskHash)?.algo ?? 'unknown';
|
|
905
|
+
console.error('SIGNATURE-ALGO WARN: state.taskHash 算法版本 ' + storedAlgo + ' 与当前任务集签名版本 ' + TASK_SET_SIGNATURE_ALGO + ' 不同——跨版本不做一致性比对,本轮不阻断;如需强制一致请重新 entry execute 家族节点重建签名');
|
|
906
|
+
} else if (!sameTaskSetSignature(state.taskHash, currentHash)) {
|
|
907
|
+
console.error('BLOCKED: TASK.md 任务集被修改(签名不匹配),execute 期间不允许增删任务/改 action/改边界');
|
|
908
|
+
process.exit(1);
|
|
909
|
+
}
|
|
910
|
+
} catch {}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// open exit 校验 REQUIREMENT 含 AC 段(段名基准从 REQUIREMENT 模板派生,模板缺失 fallback 内置段名)
|
|
914
|
+
export async function runRequirementAcGate({ node, state }) {
|
|
915
|
+
if (node.id !== 'open' || !state.activeChange) return;
|
|
916
|
+
const reqFile = path.join(runRoot, '.specs', state.activeChange, 'REQUIREMENT.md');
|
|
917
|
+
try {
|
|
918
|
+
const content = await fs.readFile(reqFile, 'utf8');
|
|
919
|
+
const acceptance = (await templateSectionPatterns()).pick('requirement', ['验收'], TEMPLATE_FALLBACK_SECTION_PATTERNS.requirementAcceptance);
|
|
920
|
+
if (!acceptance.test(content) && !/Given/i.test(content)) {
|
|
921
|
+
console.error('BLOCKED: REQUIREMENT.md 缺少验收标准/AC 段');
|
|
922
|
+
process.exit(1);
|
|
923
|
+
}
|
|
924
|
+
} catch {}
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// design exit 校验 DESIGN 含技术栈段
|
|
928
|
+
export async function runDesignStackGate({ node, state }) {
|
|
929
|
+
if (node.id !== 'design' || !state.activeChange) return;
|
|
930
|
+
const designFile = path.join(runRoot, '.specs', state.activeChange, 'DESIGN.md');
|
|
931
|
+
const designLite = path.join(runRoot, '.specs', state.activeChange, 'DESIGN-lite.md');
|
|
932
|
+
const target = (await fileExists(designFile)) ? designFile : (await fileExists(designLite)) ? designLite : null;
|
|
933
|
+
if (!target) return;
|
|
934
|
+
try {
|
|
935
|
+
const content = await fs.readFile(target, 'utf8');
|
|
936
|
+
if (!/##\s*0[\s.]/.test(content) && !/##\s*技术栈/.test(content)) {
|
|
937
|
+
console.error('BLOCKED: DESIGN.md 缺少 §0 技术栈段');
|
|
938
|
+
process.exit(1);
|
|
939
|
+
}
|
|
940
|
+
} catch {}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// open exit 补必填段校验(结构+存在级,不做语义)——CHANGE.md 含 Why 段;REQUIREMENT.md 含
|
|
944
|
+
// 用户故事 段。段名基准从 flow-kit 模板派生(CHANGE 模板 "## Why(为什么做)"、REQUIREMENT 模板
|
|
945
|
+
// "## 用户故事"),模板缺失 fallback。
|
|
946
|
+
export async function runOpenRequiredSectionsGate({ node, state }) {
|
|
947
|
+
if (node.id !== 'open' || !state.activeChange) return;
|
|
948
|
+
const changeDir = path.join(runRoot, '.specs', state.activeChange);
|
|
949
|
+
const tpl = await templateSectionPatterns();
|
|
950
|
+
const required = [
|
|
951
|
+
['CHANGE.md', tpl.pick('change', ['Why', '为什么'], TEMPLATE_FALLBACK_SECTION_PATTERNS.changeWhy)],
|
|
952
|
+
['REQUIREMENT.md', tpl.pick('requirement', ['用户故事'], TEMPLATE_FALLBACK_SECTION_PATTERNS.requirementUserStory)],
|
|
953
|
+
];
|
|
954
|
+
for (const [file, regex] of required) {
|
|
955
|
+
const p = path.join(changeDir, file);
|
|
956
|
+
if (await fileExists(p)) {
|
|
957
|
+
try {
|
|
958
|
+
const text = await fs.readFile(p, 'utf8');
|
|
959
|
+
if (!regex.test(text)) {
|
|
960
|
+
console.error('BLOCKED: ' + file + ' 缺必填段 ' + regex);
|
|
961
|
+
process.exit(1);
|
|
962
|
+
}
|
|
963
|
+
} catch {}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// design exit 补必填段校验——DESIGN.md 含 ## 决策清单(段名基准从 DESIGN 模板派生,"## 1. 决策清单"
|
|
969
|
+
// 编号前缀可选)
|
|
970
|
+
export async function runDesignDecisionListGate({ node, state }) {
|
|
971
|
+
if (node.id !== 'design' || !state.activeChange) return;
|
|
972
|
+
const designFile = path.join(runRoot, '.specs', state.activeChange, 'DESIGN.md');
|
|
973
|
+
const designLite = path.join(runRoot, '.specs', state.activeChange, 'DESIGN-lite.md');
|
|
974
|
+
const target = (await fileExists(designFile)) ? designFile : (await fileExists(designLite)) ? designLite : null;
|
|
975
|
+
if (!target) return;
|
|
976
|
+
try {
|
|
977
|
+
const text = await fs.readFile(target, 'utf8');
|
|
978
|
+
const decisionList = (await templateSectionPatterns()).pick('design', ['决策清单'], TEMPLATE_FALLBACK_SECTION_PATTERNS.designDecisionList);
|
|
979
|
+
if (!decisionList.test(text)) {
|
|
980
|
+
console.error('BLOCKED: DESIGN.md 缺必填段 ## 决策清单');
|
|
981
|
+
process.exit(1);
|
|
982
|
+
}
|
|
983
|
+
} catch {}
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// plan exit 校验 TASK 含 task 块和 verify 字段 + 依赖图/波次散文/伪并行/写写与读写冲突检测
|
|
987
|
+
export async function runPlanExitGate({ node, state }) {
|
|
988
|
+
if (node.id !== 'plan' || !state.activeChange) return;
|
|
989
|
+
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
990
|
+
// 读文件是唯一需要容错的动作(TASK.md 缺失 → 无内容可判,判据段不适用,保持既有语义);判据段
|
|
991
|
+
// 独立成层——判据自身抛错不得被空 catch 吞掉:空 catch 会让整段文件依赖门禁(含既有写写强判
|
|
992
|
+
// BLOCK)静默失效,与「未验证 ≠ 通过」相悖。命中即显式报出原因并按 fail-closed 拒绝。
|
|
993
|
+
let content = null;
|
|
994
|
+
try { content = await fs.readFile(taskFile, 'utf8'); } catch { content = null; }
|
|
995
|
+
if (content === null) return;
|
|
996
|
+
try {
|
|
997
|
+
// <task> 块提取与属性解析统一走 task-parsing.mjs(开标签语义,属性序无关)
|
|
998
|
+
const taskList = extractTaskBlocks(content);
|
|
999
|
+
if (taskList.length === 0) {
|
|
1000
|
+
console.error('BLOCKED: TASK.md 无 <task> 块');
|
|
1001
|
+
process.exit(1);
|
|
1002
|
+
}
|
|
1003
|
+
const missingVerify = taskList.filter(b => !/<verify>/.test(b));
|
|
1004
|
+
if (missingVerify.length > 0) {
|
|
1005
|
+
console.error('BLOCKED: TASK.md 中 ' + missingVerify.length + ' 个 task 缺 <verify> 字段');
|
|
1006
|
+
process.exit(1);
|
|
1007
|
+
}
|
|
1008
|
+
// 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记(并行语义)但 XML
|
|
1009
|
+
// 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务标记为准)。容错:无并行语义
|
|
1010
|
+
// 的 Wave 行不参与比对;解析不到波次段跳过(不误报)。段尾判定 = 下一个段标题(\n## )或分隔线
|
|
1011
|
+
// (\n---)或**输入末尾**。JS 正则没有 \Z:\Z 是「未知转义 ⇒ 字面字符 Z」,惰性匹配一遇段内
|
|
1012
|
+
// 大写 Z 就提前收尾,段被静默截断(含 ZERO- 一类机检标记的 TASK 会整段漏检)。串尾一律用
|
|
1013
|
+
// (?![\s\S]) 真断言——它只是「此处之后已无任何字符」,不受行首/行尾标志影响,与「多行模式下的
|
|
1014
|
+
// $」语义无歧义。
|
|
1015
|
+
const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|(?![\s\S]))/);
|
|
1016
|
+
if (waveSection) {
|
|
1017
|
+
const proseParallelIds = [];
|
|
1018
|
+
for (const line of waveSection[1].split('\n')) {
|
|
1019
|
+
if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
|
|
1020
|
+
for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
|
|
1021
|
+
}
|
|
1022
|
+
if (proseParallelIds.length > 0) {
|
|
1023
|
+
const xmlParallelIds = taskList
|
|
1024
|
+
.filter(b => { const a = taskOpeningAttrs(b); return a && a.parallel; })
|
|
1025
|
+
.map(b => (taskOpeningAttrs(b) || {}).id)
|
|
1026
|
+
.filter(Boolean);
|
|
1027
|
+
const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
|
|
1028
|
+
if (missing.length > 0) {
|
|
1029
|
+
if (isNewChange(state)) {
|
|
1030
|
+
console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
|
|
1031
|
+
process.exit(1);
|
|
1032
|
+
}
|
|
1033
|
+
console.error('WARN: 波次散文标记为并行([P])但任务无 parallel="true"——散文与任务标记不一致(以任务标记为准): ' + missing.join(', '));
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
// 波次分组校验重定义(依赖图校验决策 · 混排合法化):原「并行块必须单个连续且居首/尾」形态约束
|
|
1038
|
+
// 废除——串行任务位置不再受限,串→并→串 / 并→串→并 / 多波混合均合法(多趟循环路由按依赖拓扑
|
|
1039
|
+
// 分趟)。改为依赖图校验:① 全部任务建依赖图(deps 边)做 Kahn 拓扑排序判环——有环即规划结构性
|
|
1040
|
+
// 死锁;② 全部引用的任务 id 必须存在(无环图下「每个 parallel 任务的全部传递依赖存在且非环」
|
|
1041
|
+
// ⟺ 直接引用都存在)。违规分级:新 change BLOCKED(含「依赖环」/缺失依赖明细 + depends_on 调整
|
|
1042
|
+
// 恢复指引);旧 change 渐进 WARN 不阻断。波次散文一致性检测保留不动(与形态约束正交的既有独立
|
|
1043
|
+
// 检测,维持不变)。
|
|
1044
|
+
const depGraph = analyzeDependencyGraph(taskList);
|
|
1045
|
+
if (depGraph.cyclic || depGraph.missing.length > 0) {
|
|
1046
|
+
const detail = depGraph.cyclic
|
|
1047
|
+
? '依赖环(拓扑排序无解,涉及任务: ' + depGraph.cycleIds.join(', ') + ')'
|
|
1048
|
+
: '依赖不存在的任务: ' + depGraph.missing.map((m) => m.id + '→' + m.dep).join(', ');
|
|
1049
|
+
const guide = ';恢复: 调整任务 depends_on——移除成环引用或改为真实存在的任务 id 后重试';
|
|
1050
|
+
if (isNewChange(state)) {
|
|
1051
|
+
console.error('BLOCKED: TASK.md ' + detail + '——依赖图不可满足(任务的依赖链必须存在且无环)' + guide);
|
|
1052
|
+
process.exit(1);
|
|
1053
|
+
}
|
|
1054
|
+
console.error('WARN: TASK.md ' + detail + '——依赖图不可满足(旧 change 渐进不阻断)' + guide);
|
|
1055
|
+
}
|
|
1056
|
+
// 伪并行检测(真实载体验证暴露的设计盲区兜底):如果一个标记为并行的任务只写测试文件而无任何
|
|
1057
|
+
// 生产代码文件,它很可能隐式依赖某个实现类并行任务的产出(如测试 import 尚未存在的函数)。这种
|
|
1058
|
+
// "伪并行"在多趟路由下会导致委托后测试失败。启发式:并行任务的 write_files 全部匹配 tests/ 或
|
|
1059
|
+
// test_ 前缀 → 视为疑似伪并行。WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可
|
|
1060
|
+
// 合法全测试面)。
|
|
1061
|
+
const testOnlyParallelIds = [];
|
|
1062
|
+
for (const block of taskList) {
|
|
1063
|
+
const attrs = taskOpeningAttrs(block);
|
|
1064
|
+
if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
|
|
1065
|
+
const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
1066
|
+
if (!wfMatch) continue;
|
|
1067
|
+
// 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs
|
|
1068
|
+
// 同源互锚)——换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态
|
|
1069
|
+
// 不支持,须换行书写)
|
|
1070
|
+
const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
|
|
1071
|
+
const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
|
|
1072
|
+
.flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
|
|
1073
|
+
if (filePaths.length === 0) continue;
|
|
1074
|
+
const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
|
|
1075
|
+
if (prodFiles.length === 0) {
|
|
1076
|
+
testOnlyParallelIds.push(attrs.id || 'unknown');
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if (testOnlyParallelIds.length > 0) {
|
|
1080
|
+
console.error('WARN: 伪并行检测——以下并行任务仅写测试文件而无生产代码文件: '
|
|
1081
|
+
+ testOnlyParallelIds.join(', ')
|
|
1082
|
+
+ '。测试通常依赖实现产出的符号,可能存在隐式依赖;建议添加 depends_on 声明或合并为垂直切片');
|
|
1083
|
+
}
|
|
1084
|
+
// 并行文件依赖检测前移(触发面):write∩write 写写强判(新 change BLOCKED / 旧 change WARN
|
|
1085
|
+
// 渐进,与依赖环分级同先例)+ read∩write 读写弱判(仅无显式 depends_on 关联的并行对;WARN
|
|
1086
|
+
// 提示级,新/旧均不 BLOCK——渐进提示)+ 同文件跨任务且无依赖路径(未完成任务写入面重叠而两
|
|
1087
|
+
// 任务间无依赖路径——新 change BLOCKED / 旧 change WARN 渐进;串行拆分同样命中,修复任务族不
|
|
1088
|
+
// 参与)。与委托前既有拦截并存(委托前为第二道写写锚,行为与消息保持既有语义不变)。
|
|
1089
|
+
const { writeConflicts, readWarnings, crossTaskConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
|
|
1090
|
+
if (writeConflicts.length > 0) {
|
|
1091
|
+
const detail = writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1092
|
+
const guide = ';恢复: 补显式 depends_on 或拆为串行任务后重试';
|
|
1093
|
+
if (isNewChange(state)) {
|
|
1094
|
+
console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
|
|
1095
|
+
process.exit(1);
|
|
1096
|
+
}
|
|
1097
|
+
console.error('WARN: TASK.md 并行任务 write_files 重叠(写写冲突,建议补显式 depends_on 或拆为串行任务): ' + detail + guide);
|
|
1098
|
+
}
|
|
1099
|
+
if (crossTaskConflicts.length > 0) {
|
|
1100
|
+
const detail = crossTaskConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1101
|
+
const guide = ';恢复: 补显式 depends_on 或合并为一个任务后重试';
|
|
1102
|
+
if (isNewChange(state)) {
|
|
1103
|
+
console.error('BLOCKED: TASK.md 同文件跨任务且无依赖路径: ' + detail + guide);
|
|
1104
|
+
process.exit(1);
|
|
1105
|
+
}
|
|
1106
|
+
console.error('WARN: TASK.md 同文件跨任务且无依赖路径(建议补显式 depends_on 或合并为一个任务): ' + detail + guide);
|
|
1107
|
+
}
|
|
1108
|
+
if (readWarnings.length > 0) {
|
|
1109
|
+
console.error('WARN: TASK.md 并行任务 read∩write 隐式依赖嫌疑(一方读取对方写路径,建议补显式 depends_on 声明): '
|
|
1110
|
+
+ readWarnings.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
|
|
1111
|
+
}
|
|
1112
|
+
} catch (judgeError) {
|
|
1113
|
+
console.error('BLOCKED: TASK.md 文件依赖判据未执行: '
|
|
1114
|
+
+ (judgeError && judgeError.message ? judgeError.message : String(judgeError))
|
|
1115
|
+
+ '——门禁无法完成校验,按 fail-closed 拒绝通过(未验证 ≠ 通过)');
|
|
1116
|
+
process.exit(1);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// review exit 校验 REVIEW 含实质内容 + 发现区条目处置状态结构级校验
|
|
1121
|
+
export async function runReviewExitGate({ node, state }) {
|
|
1122
|
+
if (node.id !== 'review' || !state.activeChange) return;
|
|
1123
|
+
const reviewFile = path.join(runRoot, '.specs', state.activeChange, 'REVIEW.md');
|
|
1124
|
+
try {
|
|
1125
|
+
const stat = await fs.stat(reviewFile);
|
|
1126
|
+
if (stat.size < 100) {
|
|
1127
|
+
console.error('BLOCKED: REVIEW.md 内容不足(' + stat.size + ' 字节,需 ≥ 100)');
|
|
1128
|
+
process.exit(1);
|
|
1129
|
+
}
|
|
1130
|
+
// 发现项(含 Minor)须有处置状态标记——[已修](对应 fix 任务)/ [升级](用户决策:接受+理由)/
|
|
1131
|
+
// [转待办](归档时进 KNOWN-ISSUES)。结构级校验,WARN 渐进不 BLOCK:旧 REVIEW 未按新格式写标记
|
|
1132
|
+
// 只警告不阻断(防旧 REVIEW 卡死),执行者补标记后可消除。
|
|
1133
|
+
const reviewText = await fs.readFile(reviewFile, 'utf8');
|
|
1134
|
+
// 发现位置(模板 2.2):发现写在旧 `## 发现` 而模板位置 `### 2.2 …详细发现` 下无条目——旧段不被
|
|
1135
|
+
// 任何出口消费,等于「记录后静默丢弃」。新 change BLOCKED + 逐条迁移指引;旧 change WARN 渐进。
|
|
1136
|
+
// 模板缺席(primary=null)时不判位置:模板派生判据不臆造(C9),旧形态解析与处置校验照常。
|
|
1137
|
+
const scope = await reviewFindingScope();
|
|
1138
|
+
const findings = reviewFindingsItems(reviewText, scope);
|
|
1139
|
+
const misplacedFindings = scope.primary !== null
|
|
1140
|
+
&& !findings.some((item) => item.scope === 'primary')
|
|
1141
|
+
&& reviewLegacyFindingsHasContent(reviewText);
|
|
1142
|
+
if (misplacedFindings) {
|
|
1143
|
+
const templateFile = (await buildSkeleton('REVIEW')).file ?? 'flow-kit/templates/REVIEW.md';
|
|
1144
|
+
if (isNewChange(state)) {
|
|
1145
|
+
console.error('BLOCKED: REVIEW.md 的发现写在模板外的段「## 发现」,而模板位置(第二轮下的 2.2 详细发现)无条目——新 change 强制写在模板位置');
|
|
1146
|
+
console.error('恢复: 把「## 发现」下的条目逐条移入「### 2.2 …详细发现」段内(模板: ' + templateFile
|
|
1147
|
+
+ '),删除旧段后重试 exit review');
|
|
1148
|
+
process.exit(1);
|
|
1149
|
+
}
|
|
1150
|
+
console.error('REVIEW WARN: REVIEW.md 的发现写在模板外的段「## 发现」,模板位置 2.2 详细发现 无条目'
|
|
1151
|
+
+ '——迁移到 2.2 后本警告消除(旧 change 渐进不阻断;模板: ' + templateFile + ')');
|
|
1152
|
+
}
|
|
1153
|
+
const missingDisposition = reviewFindingsMissingDisposition(reviewText, scope);
|
|
1154
|
+
if (missingDisposition.length > 0) {
|
|
1155
|
+
if (isNewChange(state)) {
|
|
1156
|
+
console.error('BLOCKED: REVIEW.md 发现区 ' + missingDisposition.length + ' 项条目缺处置状态标记([已修]/[升级]/[转待办])——新 change 强制每项发现须有处置');
|
|
1157
|
+
console.error('恢复: 为发现区条目补处置标记后重试;未处置的发现(含 Minor)不应无声消失');
|
|
1158
|
+
process.exit(1);
|
|
1159
|
+
}
|
|
1160
|
+
console.error('REVIEW WARN: REVIEW.md 发现区 ' + missingDisposition.length +
|
|
1161
|
+
' 项条目缺处置状态标记([已修]/[升级]/[转待办]): ' + missingDisposition.join('、') +
|
|
1162
|
+
'——未处置的发现(含 Minor)不应无声消失,补标记后本警告消除(渐进不阻断)');
|
|
1163
|
+
}
|
|
1164
|
+
// Major 延期裁决门禁:Major 的处置是用户决策点——reviewer 不得自行 [转待办]。结构校验:Major
|
|
1165
|
+
// 条目标 [转待办] 时须同时存在用户裁决记录(同段或文末含「用户裁决:接受延期」且指向该条目,
|
|
1166
|
+
// 并由 [升级] 承接);缺失 → 新 change BLOCKED / 旧 change WARN 渐进。Minor 不受影响;
|
|
1167
|
+
// Major [升级]/[已修] 直接放行。
|
|
1168
|
+
const deferredMajor = reviewDeferredMajorProblems(reviewText, scope);
|
|
1169
|
+
if (deferredMajor.length > 0) {
|
|
1170
|
+
const guide = ';恢复: 先把 Major 改为 [升级] 交用户裁决;用户接受延期后在同段或文末记录「用户裁决:接受延期」并指向该条目(由 [升级] 承接)';
|
|
1171
|
+
if (isNewChange(state)) {
|
|
1172
|
+
console.error('BLOCKED: REVIEW.md 发现区 ' + deferredMajor.length + ' 项 Major 条目为 [转待办] 但缺少用户裁决记录(Major 不得由 reviewer 自行转待办): ' + deferredMajor.join('、') + guide);
|
|
1173
|
+
process.exit(1);
|
|
1174
|
+
}
|
|
1175
|
+
console.error('REVIEW WARN: REVIEW.md 发现区 ' + deferredMajor.length +
|
|
1176
|
+
' 项 Major 条目为 [转待办] 但缺少用户裁决记录: ' + deferredMajor.join('、') +
|
|
1177
|
+
'——Major 不得由 reviewer 自行转待办' + guide + '(渐进不阻断)');
|
|
1178
|
+
}
|
|
1179
|
+
} catch {}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// 节点 exit 协议声明标记校验——扫描 .specs/<change-id>/.skill-loads/ 下该节点标记(<node>-*.json,
|
|
1183
|
+
// 执行者加载节点 skill 后经 skill-load 写入,含 protocol 字段——指向 flow-kit/prompts/ 协议文件,
|
|
1184
|
+
// 只读引用),校验至少一个标记的 protocol ∈ 该节点协议集(节点协议映射表)。缺失 → BLOCKED(提示
|
|
1185
|
+
// 缺协议声明标记 + 指引 skill-load --prompt);有 → 通过。诚实边界:标记是执行者的自我声明——校验
|
|
1186
|
+
// 只确认「声明存在且 protocol 归属节点」,无法证明执行者真的阅读了协议(声明非物理证明,仅保证
|
|
1187
|
+
// 协议阅读声明可追溯)。旧 change 兼容:旧 change/旧 evidence 不追溯——.skill-loads/ 目录不存在
|
|
1188
|
+
// (该 change 从未运行过 skill-load,声明机制未激活)→ 跳过校验;节点已 exit 不重验(校验只在当前
|
|
1189
|
+
// exit 时执行);节点重新 exit(重入后再退)时按新规则要求,无豁免。
|
|
1190
|
+
export async function runSkillLoadMarkerGate({ node, state }) {
|
|
1191
|
+
if (!state.activeChange || !NODE_PROTOCOL_FILES[node.id]) return;
|
|
1192
|
+
// 标记目录活动/归档双路径解析(archive 节点「先移目录后 exit」顺序下标记只在归档路径——单查
|
|
1193
|
+
// 活动路径会误报「机制未激活」静默放行);两处皆无才走旧 change 兼容
|
|
1194
|
+
const loadsDir = await findSkillLoadsDir(runRoot, state.activeChange);
|
|
1195
|
+
if (!loadsDir) {
|
|
1196
|
+
// 旧 change 兼容过渡规则:活动与归档路径均无声明标记目录(机制未激活)不追溯;首个 skill-load
|
|
1197
|
+
// 写入后新规则生效(该 change 后续节点 exit 均需声明标记)
|
|
1198
|
+
console.error('SKILL-LOAD WARN: 旧 change 兼容——.specs/' + state.activeChange +
|
|
1199
|
+
'/.skill-loads/(活动与归档路径)不存在,协议声明校验跳过(机制未激活;首个 skill-load 后新规则生效)');
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
const prefix = node.id + '-';
|
|
1203
|
+
const protocolSet = NODE_PROTOCOL_FILES[node.id];
|
|
1204
|
+
const markers = (await fs.readdir(loadsDir.dir).catch(() => []))
|
|
1205
|
+
.filter((f) => f.startsWith(prefix) && f.endsWith('.json'));
|
|
1206
|
+
const malformed = [];
|
|
1207
|
+
let declared = false;
|
|
1208
|
+
for (const f of markers) {
|
|
1209
|
+
try {
|
|
1210
|
+
const marker = JSON.parse(await fs.readFile(path.join(loadsDir.dir, f), 'utf8'));
|
|
1211
|
+
// 比对 basename——新格式(skill-load 写入 basename)与旧格式(完整绝对路径)经
|
|
1212
|
+
// markerProtocolBasename 提取后统一比对;损坏值(null/非字符串/超集外 basename)提取为 null
|
|
1213
|
+
// 或不匹配 → 不进 declared,fail-closed
|
|
1214
|
+
if (marker && typeof marker === 'object' && protocolSet.includes(markerProtocolBasename(marker.protocol))) {
|
|
1215
|
+
declared = true;
|
|
1216
|
+
// auto 标记提示——record 自动补的标记(auto:true)不证明手动加载,提示建议手动声明
|
|
1217
|
+
if (marker.auto === true) {
|
|
1218
|
+
console.error('SKILL-LOAD HINT: ' + f + ' 为 record 自动补写标记(auto)——建议手动 skill-load 声明(如实记录加载动作与协议文件)');
|
|
1219
|
+
}
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
} catch {
|
|
1223
|
+
malformed.push(f);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
if (!declared) {
|
|
1227
|
+
console.error('BLOCKED: 节点 ' + node.id + ' exit 缺协议声明标记——' + loadsDir.display +
|
|
1228
|
+
' 下需有 ' + prefix + '*.json 且 protocol ∈ [' + protocolSet.join(', ') +
|
|
1229
|
+
'];执行 skill-load --prompt <flow-kit/prompts/ 协议文件> 声明已阅读协议(声明非物理证明,仅可追溯)' +
|
|
1230
|
+
(malformed.length > 0 ? ';不可解析标记: ' + malformed.join(', ') : ''));
|
|
1231
|
+
process.exit(1);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// 受保护状态落盘(沿用 state-io 的受保护写入通道)
|