flow-comet 1.6.4 → 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/evolve.mjs +174 -0
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +3 -1
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +28 -4
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +41 -18
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +16 -16
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +9 -7
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +17 -13
- package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +154 -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 +206 -3
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +458 -60
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +38 -58
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +642 -230
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +85 -14
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +43 -5
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +15 -1
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +18 -1
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +60 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +73 -9
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +21 -1
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +9 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +212 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +15 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +20 -10
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +4 -1
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +13 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +2125 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +6 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +74 -2
- 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 +3 -3
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-flowkit.mjs +43 -3
|
@@ -1,215 +1,678 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// 产出物模板结构门禁(守卫模块):标题形态 / 首部字段(键 + 非空值)/ 全骨架(模板 H2 + 登记表
|
|
2
|
+
// 结构型 H3,模板外多余段不参与)/ 段序 / 空正文(六词白名单)/ 与模板该段正文逐字相同(判未填,
|
|
3
|
+
// 含模板里的示例表格行)/ 条件段标题必须在场(可选段按模板自述可整段删除)/ 增量段位置。段名与
|
|
4
|
+
// 结构一律由 lib/guard-artifact-skeleton.mjs 的骨架派生(模板是内容权威,登记表只补条件段/结构
|
|
5
|
+
// 子段/增量段/首部/标题形态)——本模块不自持段名清单,段名归一复用 route-node 的 normalizeHeading。
|
|
3
6
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
7
|
+
// 模板整份缺失(derived=false,含登记表缺失 registry-missing,C13)→ 模板派生判据全部跳过并输出
|
|
8
|
+
// 「未校验(模板缺失)」;标题形态与首部字段来自登记表而非模板正文,照常校验(既有语义)。
|
|
9
|
+
// 分级沿用 isNewChange:新 change → BLOCKED,旧 change → WARN(C10 无例外)。
|
|
10
|
+
//
|
|
11
|
+
// 两阶段报错(AC-15):首次只给「模板路径 + 类别与数量」,不列「缺段」的段名;同一工件再次
|
|
12
|
+
// 失败时读 .specs/<change>/.template-hints.json 并列段名;该工件通过后清除其键(C5)。其它类别
|
|
13
|
+
// (标题/首部/条件段/段序/空正文/占位符/结构子段/增量段)本身即定位信息,首次就点到具体项——
|
|
14
|
+
// 只有「缺段」会成片出现,才需要先引导读模板。
|
|
6
15
|
|
|
7
16
|
import { promises as fs } from 'fs';
|
|
8
17
|
import path from 'path';
|
|
9
18
|
import { EXECUTE_FAMILY_NODE_IDS, normalizeHeading } from '../route-node.mjs';
|
|
10
19
|
import { taskOpeningAttrs, taskBlocks as extractTaskBlocks } from '../task-parsing.mjs';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
20
|
+
import { nodeTemplateDeclaration, readProtocolFile, templateKeyOf } from '../protocol-utils.mjs';
|
|
21
|
+
import { runRoot, fileExists, protocolPath } from './guard-state-io.mjs';
|
|
22
|
+
import { isNewChange } from './guard-routing.mjs';
|
|
23
|
+
import { buildSkeleton, LEGACY_SUMMARY_ORDER } from './guard-artifact-skeleton.mjs';
|
|
13
24
|
import { TASK7_REQUIRED } from './task-graph.mjs';
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
const HINT_FILE_NAME = '.template-hints.json';
|
|
27
|
+
const H2_LINE = /^##\s+(.+?)\s*$/u;
|
|
28
|
+
const H3_LINE = /^###\s+(.+?)\s*$/u;
|
|
29
|
+
const FRONTMATTER_KEY_LINE = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/u;
|
|
30
|
+
|
|
31
|
+
// 空正文白名单(AC-5):判据是**整段取值**而非子串——词后必须是行尾 / 空白 / 标点 / 括注,
|
|
32
|
+
// 「无变更风险;影响两份工件」这类真实句子仍是已填(判据不得退化为子串命中)。
|
|
33
|
+
const NOT_APPLICABLE_BODY =
|
|
34
|
+
/^(?:无变更|不适用|未涉及|N\/A|无|—)(?=$|[\s,。;、,;.::!!??…—()()【】「」『』“”"'])/iu;
|
|
35
|
+
|
|
36
|
+
function literalRegExp(text) {
|
|
37
|
+
return String(text ?? '').replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 段名精确认键:归一(去编号 / 大小写 / 尾部括号)沿用 route-node 的单一实现,这里**只追加**尾部
|
|
41
|
+
// 括号内容作为区分位——归一口径会把 Button (Primary)/(Secondary) 合成同键(C2),unique=false 的
|
|
42
|
+
// 结构子段必须按精确名匹配,否则「只写了 Secondary」也算 Primary 在场。不复制一份编号/大小写规则。
|
|
43
|
+
function qualifiedHeading(raw) {
|
|
44
|
+
const paren = String(raw ?? '').match(/[((]([^))\n]*)[))]\s*$/u);
|
|
45
|
+
return normalizeHeading(raw) + '\u0000' + (paren ? paren[1].trim().toLowerCase() : '');
|
|
19
46
|
}
|
|
20
47
|
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
48
|
+
// 工件文本 → 行锚定轮廓(L-128:只认行首标题,正文里引用段名不劫持)。frontmatter 仅做顶层键
|
|
49
|
+
// 行级解析(不引入 YAML 库):一个键的值区 = 行内余下文本 + 到下一个顶层键之前的非空行
|
|
50
|
+
// (嵌套映射是缩进行,而「值另起一行且不缩进」也同样是已填——两种书写形态都不判空)。
|
|
51
|
+
function parseOutline(text) {
|
|
52
|
+
const lines = String(text ?? '').replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n').split('\n');
|
|
53
|
+
const outline = { frontmatter: { present: false, keys: [] }, titleLine: '', headerLines: [], sections: [] };
|
|
54
|
+
let cursor = 0;
|
|
55
|
+
if (lines[0] !== undefined && lines[0].trim() === '---') {
|
|
56
|
+
const end = lines.findIndex((line, index) => index > 0 && line.trim() === '---');
|
|
57
|
+
if (end > 0) {
|
|
58
|
+
outline.frontmatter.present = true;
|
|
59
|
+
const body = lines.slice(1, end);
|
|
60
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
61
|
+
const matched = body[index].match(FRONTMATTER_KEY_LINE);
|
|
62
|
+
if (!matched) continue;
|
|
63
|
+
let value = matched[2].trim();
|
|
64
|
+
if (value === '') {
|
|
65
|
+
for (let next = index + 1; next < body.length && !FRONTMATTER_KEY_LINE.test(body[next]); next += 1) {
|
|
66
|
+
if (body[next].trim() !== '') { value = 'filled'; break; }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
outline.frontmatter.keys.push({ key: matched[1].toLowerCase(), value });
|
|
70
|
+
}
|
|
71
|
+
cursor = end + 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
while (cursor < lines.length && lines[cursor].trim() === '') cursor += 1;
|
|
75
|
+
outline.titleLine = lines[cursor] ?? '';
|
|
76
|
+
cursor += 1;
|
|
77
|
+
while (cursor < lines.length && !H2_LINE.test(lines[cursor])) {
|
|
78
|
+
outline.headerLines.push(lines[cursor]);
|
|
79
|
+
cursor += 1;
|
|
26
80
|
}
|
|
27
|
-
|
|
81
|
+
let current = null;
|
|
82
|
+
for (; cursor < lines.length; cursor += 1) {
|
|
83
|
+
const line = lines[cursor];
|
|
84
|
+
const heading = line.match(H2_LINE);
|
|
85
|
+
if (heading) {
|
|
86
|
+
current = {
|
|
87
|
+
raw: heading[1].trim(),
|
|
88
|
+
norm: normalizeHeading(heading[1]),
|
|
89
|
+
qualified: qualifiedHeading(heading[1]),
|
|
90
|
+
bodyLines: [],
|
|
91
|
+
subsections: [],
|
|
92
|
+
};
|
|
93
|
+
outline.sections.push(current);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (current === null) continue;
|
|
97
|
+
const sub = line.match(H3_LINE);
|
|
98
|
+
if (sub) {
|
|
99
|
+
current.subsections.push({
|
|
100
|
+
raw: sub[1].trim(),
|
|
101
|
+
norm: normalizeHeading(sub[1]),
|
|
102
|
+
qualified: qualifiedHeading(sub[1]),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
current.bodyLines.push(line);
|
|
106
|
+
}
|
|
107
|
+
return outline;
|
|
28
108
|
}
|
|
29
109
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
async function templateSkeleton(key) {
|
|
40
|
-
const tpl = await templateSectionPatterns(); // 复用模板缓存(runRoot 内模板)
|
|
41
|
-
const src = tpl[key] ?? [];
|
|
42
|
-
if (src.length > 0) return src.map((s) => normalizeTemplateHeading(s.name));
|
|
43
|
-
return (TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? []).map((s) => normalizeTemplateHeading(s));
|
|
110
|
+
// 段正文归一(首尾空行剥离、行尾空白剥离):逐字比对与空正文判定共用同一口径。
|
|
111
|
+
function bodyText(lines) {
|
|
112
|
+
const trimmed = (lines ?? []).map((line) => String(line).replace(/\s+$/u, ''));
|
|
113
|
+
let start = 0;
|
|
114
|
+
let end = trimmed.length;
|
|
115
|
+
while (start < end && trimmed[start].trim() === '') start += 1;
|
|
116
|
+
while (end > start && trimmed[end - 1].trim() === '') end -= 1;
|
|
117
|
+
return trimmed.slice(start, end).join('\n');
|
|
44
118
|
}
|
|
45
119
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
120
|
+
// 模板轮廓缓存(键 = 模板绝对路径):逐字比对要模板该段正文,路径来自骨架(不在此推导模板位置)。
|
|
121
|
+
const templateOutlineCache = new Map();
|
|
122
|
+
|
|
123
|
+
async function templateOutlineFor(skeleton) {
|
|
124
|
+
const file = path.resolve(runRoot, ...String(skeleton.file).split('/'));
|
|
125
|
+
if (templateOutlineCache.has(file)) return templateOutlineCache.get(file);
|
|
126
|
+
let outline = null;
|
|
127
|
+
try {
|
|
128
|
+
outline = parseOutline(await fs.readFile(file, 'utf8'));
|
|
129
|
+
} catch {
|
|
130
|
+
outline = null;
|
|
131
|
+
}
|
|
132
|
+
templateOutlineCache.set(file, outline);
|
|
133
|
+
return outline;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function emptyIssues() {
|
|
137
|
+
return {
|
|
138
|
+
title: null,
|
|
139
|
+
headerMissing: [],
|
|
140
|
+
headerEmpty: [],
|
|
141
|
+
frontmatter: [],
|
|
142
|
+
missing: [],
|
|
143
|
+
conditional: [],
|
|
144
|
+
order: null,
|
|
145
|
+
empty: [],
|
|
146
|
+
verbatim: [],
|
|
147
|
+
structure: [],
|
|
148
|
+
increments: [],
|
|
149
|
+
};
|
|
52
150
|
}
|
|
53
151
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
152
|
+
// 表格分隔行(`|---|---|`):其后的行才是数据行,表头行不参与「示例数据」判定。
|
|
153
|
+
const TABLE_SEPARATOR_LINE = /^\s*\|(?:\s*:?-{2,}:?\s*\|)+\s*$/u;
|
|
154
|
+
|
|
155
|
+
// 模板正文里的**示例表格行**是成品形态:照抄它等于把别的项目的示例内容(如 SUMMARY「改动文件」
|
|
156
|
+
// 的示例文件清单)当成自己的工件内容。空表格(只有表头 / 分隔行 / 全空单元行)不属示例数据——
|
|
157
|
+
// 照抄空表与「这一项没有内容」同义。
|
|
158
|
+
function tableHasExampleRow(body) {
|
|
159
|
+
let afterSeparator = false;
|
|
160
|
+
for (const line of String(body ?? '').split('\n')) {
|
|
161
|
+
const trimmed = line.trim();
|
|
162
|
+
if (trimmed === '' || !trimmed.startsWith('|')) {
|
|
163
|
+
afterSeparator = false;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (TABLE_SEPARATOR_LINE.test(trimmed)) {
|
|
167
|
+
afterSeparator = true;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (!afterSeparator) continue;
|
|
171
|
+
const cells = trimmed.replace(/^\|/u, '').replace(/\|$/u, '').split('|').map((cell) => cell.trim());
|
|
172
|
+
if (cells.some((cell) => cell !== '')) return true;
|
|
62
173
|
}
|
|
63
|
-
return
|
|
174
|
+
return false;
|
|
64
175
|
}
|
|
65
176
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
function
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
177
|
+
// 模板正文是否留了待填位:尖括号占位符(排除 HTML 注释)或未勾选复选框——照抄即未填。
|
|
178
|
+
function templateBodyHasFillInSlot(body) {
|
|
179
|
+
return /<(?!\/?!--)[^<>\n]+>/u.test(body) || /^\s*[-*]\s*\[\s*\]/mu.test(body);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 模板正文是否「成品形态」:留了待填位,或本身已是示例成品(示例表格行)。只有这类正文才做逐字
|
|
183
|
+
// 比对——表头 / 图例 / 空表格 / 占位注释这类正文本身就是骨架的段,照抄不算未填(自指试跑在真实
|
|
184
|
+
// TASK.md 的状态字段说明、空阻塞日志、Fix 任务占位区上实证)。
|
|
185
|
+
function templateBodyIsFinishedForm(body) {
|
|
186
|
+
return templateBodyHasFillInSlot(body) || tableHasExampleRow(body);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function collectSectionIssues({ text, skeleton, template, issues }) {
|
|
190
|
+
const outline = parseOutline(text);
|
|
191
|
+
const indexByNorm = new Map();
|
|
192
|
+
for (let index = 0; index < skeleton.sections.length; index += 1) {
|
|
193
|
+
const section = skeleton.sections[index];
|
|
194
|
+
if (!indexByNorm.has(section.norm)) indexByNorm.set(section.norm, index);
|
|
195
|
+
}
|
|
196
|
+
const matched = new Map();
|
|
197
|
+
for (const section of outline.sections) {
|
|
198
|
+
if (indexByNorm.has(section.norm) && !matched.has(section.norm)) matched.set(section.norm, section);
|
|
199
|
+
}
|
|
200
|
+
// 标题缺席分两类(模板自述决定,不得并成一支):conditional = 模板标注「条件适用 / 如有」,
|
|
201
|
+
// 标题必须在场(正文可写 N/A);optional = 模板允许整段删除(UI-DESIGN §0「greenfield 删掉此段」),
|
|
202
|
+
// 整段缺席合法——把 optional 当 conditional 会把按模板指示删段的工件拦死(C-1)。
|
|
203
|
+
for (const section of skeleton.sections) {
|
|
204
|
+
if (matched.has(section.norm)) continue;
|
|
205
|
+
if (section.conditional === true) issues.conditional.push(section.name);
|
|
206
|
+
else if (section.optional !== true) issues.missing.push(section.name);
|
|
207
|
+
}
|
|
208
|
+
// 段序:只对模板骨架段排序,模板外多余段直接跳过(AC-10)
|
|
209
|
+
let lastIndex = -1;
|
|
210
|
+
for (const section of outline.sections) {
|
|
211
|
+
const index = indexByNorm.get(section.norm);
|
|
212
|
+
if (index === undefined) continue;
|
|
213
|
+
if (index < lastIndex) {
|
|
214
|
+
issues.order = { heading: section.raw };
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
lastIndex = index;
|
|
218
|
+
}
|
|
219
|
+
const parentNorms = new Set();
|
|
220
|
+
for (const sub of skeleton.structureSubsections) {
|
|
221
|
+
if (sub.parentNorm !== null) parentNorms.add(sub.parentNorm);
|
|
222
|
+
}
|
|
223
|
+
// 结构子段归属到「其上最近的骨架 H2」:模板外多余段(如工具输出贴入的 `## Findings`)夹在父段与
|
|
224
|
+
// 子段之间时不切断归属(AC-10:多余段不参与骨架判定)。
|
|
225
|
+
const subsectionsByParent = new Map();
|
|
226
|
+
let enclosingNorm = null;
|
|
227
|
+
for (const section of outline.sections) {
|
|
228
|
+
if (indexByNorm.has(section.norm)) enclosingNorm = section.norm;
|
|
229
|
+
if (enclosingNorm === null) continue;
|
|
230
|
+
if (!subsectionsByParent.has(enclosingNorm)) subsectionsByParent.set(enclosingNorm, []);
|
|
231
|
+
subsectionsByParent.get(enclosingNorm).push(...section.subsections);
|
|
232
|
+
}
|
|
233
|
+
for (const section of skeleton.sections) {
|
|
234
|
+
const docSection = matched.get(section.norm);
|
|
235
|
+
if (!docSection) continue;
|
|
236
|
+
const body = bodyText(docSection.bodyLines);
|
|
237
|
+
// 结构型父段的正文由子段承载,空正文只在叶子段判(父段只写子标题是合法形态)
|
|
238
|
+
if (!parentNorms.has(section.norm) && body === '') issues.empty.push(section.name);
|
|
239
|
+
if (template === null) continue;
|
|
240
|
+
const templateSection = template.sections.find((item) => item.norm === section.norm);
|
|
241
|
+
const templateBody = templateSection ? bodyText(templateSection.bodyLines) : '';
|
|
242
|
+
// 与模板该段正文逐字相同 ⇒ 判未填:模板正文留了待填位(占位符 / 复选框)或本身是示例成品
|
|
243
|
+
// (示例表格行)时,逐字相同只可能是照抄模板(AC-6);模板正文本身即骨架形态的段不判。
|
|
244
|
+
if (templateBody !== '' && body === templateBody && templateBodyIsFinishedForm(templateBody)) {
|
|
245
|
+
issues.verbatim.push(section.name);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// 结构子段:父段在场才要求;父段整段 N/A → 子段不要求(AC-8 ②)
|
|
249
|
+
for (const sub of skeleton.structureSubsections) {
|
|
250
|
+
const parent = sub.parentNorm === null ? null : matched.get(sub.parentNorm);
|
|
251
|
+
if (!parent) continue;
|
|
252
|
+
if (NOT_APPLICABLE_BODY.test(bodyText(parent.bodyLines))) continue;
|
|
253
|
+
const candidates = subsectionsByParent.get(sub.parentNorm) ?? parent.subsections;
|
|
254
|
+
const found = candidates.some((docSub) => (sub.unique === false
|
|
255
|
+
? docSub.qualified === qualifiedHeading(sub.name)
|
|
256
|
+
: docSub.norm === sub.norm));
|
|
257
|
+
if (!found) issues.structure.push(sub.name);
|
|
258
|
+
}
|
|
259
|
+
// 增量段:只校验在场者的位置(必填与否由登记表 required + 各自门禁决定,本模块不做存在性兜底)
|
|
260
|
+
for (const increment of skeleton.increments) {
|
|
261
|
+
if (increment.kind !== 'section') continue;
|
|
262
|
+
const docIndex = outline.sections.findIndex((section) => section.norm === increment.norm);
|
|
263
|
+
if (docIndex === -1) continue;
|
|
264
|
+
const laterSkeletonSection = outline.sections
|
|
265
|
+
.slice(docIndex + 1)
|
|
266
|
+
.some((section) => indexByNorm.has(section.norm));
|
|
267
|
+
const position = increment.position ?? {};
|
|
268
|
+
if (position.mode === 'after-or-end') {
|
|
269
|
+
const previous = outline.sections[docIndex - 1];
|
|
270
|
+
const followsAnchor = previous !== undefined
|
|
271
|
+
&& position.afterNorm !== null && position.afterNorm !== undefined
|
|
272
|
+
&& previous.norm === position.afterNorm;
|
|
273
|
+
// 「文末」分支允许其后再有其它登记的增量段(如 LESSONS 扫描 紧随自检方法,AC-12 ②⑤)
|
|
274
|
+
if (!followsAnchor && laterSkeletonSection) issues.increments.push(increment.section);
|
|
275
|
+
} else if (position.mode === 'end') {
|
|
276
|
+
if (laterSkeletonSection) issues.increments.push(increment.section);
|
|
277
|
+
} else if (position.mode === 'anywhere' && position.constraint === 'code-block-follows') {
|
|
278
|
+
const firstContentLine = outline.sections[docIndex].bodyLines.find((line) => line.trim() !== '');
|
|
279
|
+
if (firstContentLine === undefined || !/^\s*(?:```|~~~)/u.test(firstContentLine)) {
|
|
280
|
+
issues.increments.push(increment.section);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// underivedPolicy:模板缺席时保留哪些检查。'registry'(缺省)= 保留登记表级的标题/首部检查(入口文档
|
|
287
|
+
// 的既有语义);'skip' = 整体判「未校验(模板缺失)」(UI-DESIGN 等完全由模板形态定义的工件)。
|
|
288
|
+
function collectArtifactIssues({ text, skeleton, derived, template, requiredHeaderFields = [], underivedPolicy = 'registry' }) {
|
|
289
|
+
const issues = emptyIssues();
|
|
290
|
+
if (!derived && underivedPolicy === 'skip') return issues;
|
|
291
|
+
const outline = parseOutline(text);
|
|
292
|
+
if (skeleton.titleRegExp !== null) {
|
|
293
|
+
const title = outline.titleLine.trim();
|
|
294
|
+
if (title === '' || !skeleton.titleRegExp.test(title)) {
|
|
295
|
+
issues.title = { expected: skeleton.titleForm ?? '' };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const headerText = outline.headerLines.join('\n');
|
|
299
|
+
// 首部行的正则只用行内空白([ \t]):`\s*` 会吃掉换行并把下一行当成字段值,空值判断随即失效。
|
|
300
|
+
for (const field of requiredHeaderFields) {
|
|
301
|
+
const pattern = new RegExp('^[ \\t]*[-*][ \\t]+\\*\\*[ \\t]*' + literalRegExp(field) + '[ \\t]*\\*\\*[ \\t]*[::]', 'mu');
|
|
302
|
+
if (!pattern.test(headerText)) issues.headerMissing.push(field);
|
|
303
|
+
}
|
|
304
|
+
for (const field of skeleton.headerFields ?? []) {
|
|
305
|
+
// 只校验「已在场的键」的值非空(「有键无值」视为未填,AC-4);键集本身不新增硬性要求
|
|
306
|
+
const pattern = new RegExp('^[ \\t]*[-*][ \\t]+\\*\\*[ \\t]*' + literalRegExp(field) + '[ \\t]*\\*\\*[ \\t]*[::][ \\t]*(.*)$', 'mu');
|
|
307
|
+
const matched = headerText.match(pattern);
|
|
308
|
+
if (matched && matched[1].trim() === '') issues.headerEmpty.push(field);
|
|
309
|
+
}
|
|
310
|
+
if (!derived) return issues;
|
|
311
|
+
for (const key of skeleton.frontmatterKeys ?? []) {
|
|
312
|
+
const entry = outline.frontmatter.keys.find((item) => item.key === String(key).toLowerCase());
|
|
313
|
+
if (!entry || entry.value === '') issues.frontmatter.push(key);
|
|
314
|
+
}
|
|
315
|
+
collectSectionIssues({ text, skeleton, template, issues });
|
|
316
|
+
return issues;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function hasAnyIssue(issues) {
|
|
320
|
+
return issues.title !== null
|
|
321
|
+
|| issues.order !== null
|
|
322
|
+
|| issues.headerMissing.length > 0
|
|
323
|
+
|| issues.headerEmpty.length > 0
|
|
324
|
+
|| issues.frontmatter.length > 0
|
|
325
|
+
|| issues.missing.length > 0
|
|
326
|
+
|| issues.conditional.length > 0
|
|
327
|
+
|| issues.empty.length > 0
|
|
328
|
+
|| issues.verbatim.length > 0
|
|
329
|
+
|| issues.structure.length > 0
|
|
330
|
+
|| issues.increments.length > 0;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 两阶段记忆的类别集合沿用 C5 的七类词表:结构子段归 missing(缺的是骨架的一部分),
|
|
334
|
+
// 增量段位置归 order(位置偏离)。
|
|
335
|
+
function hintCategories(issues) {
|
|
336
|
+
const categories = new Set();
|
|
337
|
+
if (issues.title !== null) categories.add('title');
|
|
338
|
+
if (issues.headerMissing.length > 0 || issues.headerEmpty.length > 0 || issues.frontmatter.length > 0) {
|
|
339
|
+
categories.add('header');
|
|
340
|
+
}
|
|
341
|
+
if (issues.missing.length > 0 || issues.structure.length > 0) categories.add('missing');
|
|
342
|
+
if (issues.conditional.length > 0) categories.add('conditional');
|
|
343
|
+
if (issues.order !== null || issues.increments.length > 0) categories.add('order');
|
|
344
|
+
if (issues.empty.length > 0) categories.add('empty');
|
|
345
|
+
if (issues.verbatim.length > 0) categories.add('placeholder');
|
|
346
|
+
return [...categories];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function formatIssueParts(issues, { escalate }) {
|
|
350
|
+
const parts = [];
|
|
351
|
+
if (issues.title !== null) parts.push('标题形态不符(模板首行: `' + issues.title.expected + '`)');
|
|
352
|
+
if (issues.headerMissing.length > 0) parts.push('首部缺字段: ' + issues.headerMissing.join('、'));
|
|
353
|
+
if (issues.headerEmpty.length > 0) parts.push('首部字段有键无值: ' + issues.headerEmpty.join('、'));
|
|
354
|
+
if (issues.frontmatter.length > 0) parts.push('frontmatter 缺键或值为空: ' + issues.frontmatter.join('、'));
|
|
355
|
+
if (issues.missing.length > 0) {
|
|
356
|
+
parts.push('缺段 ' + issues.missing.length + ' 项' + (escalate ? ': ' + issues.missing.join('、') : ''));
|
|
357
|
+
}
|
|
358
|
+
if (issues.conditional.length > 0) {
|
|
359
|
+
parts.push('条件段标题缺席 ' + issues.conditional.length + ' 项: ' + issues.conditional.join('、'));
|
|
360
|
+
}
|
|
361
|
+
if (issues.order !== null) {
|
|
362
|
+
parts.push('段序偏离模板(「' + issues.order.heading + '」排在模板中更早的段之后)');
|
|
363
|
+
}
|
|
364
|
+
if (issues.empty.length > 0) parts.push('正文为空 ' + issues.empty.length + ' 项: ' + issues.empty.join('、'));
|
|
365
|
+
if (issues.verbatim.length > 0) {
|
|
366
|
+
parts.push('与模板该段正文逐字相同(判未填)' + issues.verbatim.length + ' 项: ' + issues.verbatim.join('、'));
|
|
367
|
+
}
|
|
368
|
+
if (issues.structure.length > 0) {
|
|
369
|
+
parts.push('缺结构子段 ' + issues.structure.length + ' 项: ' + issues.structure.join('、'));
|
|
370
|
+
}
|
|
371
|
+
if (issues.increments.length > 0) parts.push('增量段位置非法: ' + issues.increments.join('、'));
|
|
372
|
+
return parts;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function readHints(hintsFile) {
|
|
376
|
+
try {
|
|
377
|
+
const data = JSON.parse(await fs.readFile(hintsFile, 'utf8'));
|
|
378
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
379
|
+
} catch {
|
|
380
|
+
return {};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async function writeHints(hintsFile, hints) {
|
|
385
|
+
if (Object.keys(hints).length === 0) {
|
|
386
|
+
await fs.rm(hintsFile, { force: true }).catch(() => {});
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
await fs.mkdir(path.dirname(hintsFile), { recursive: true }).catch(() => {});
|
|
390
|
+
await fs.writeFile(hintsFile, JSON.stringify(hints, null, 2) + '\n', 'utf8').catch(() => {});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function notCheckedReason(skeleton) {
|
|
394
|
+
const file = skeleton.file ?? '(登记表未登记该工件)';
|
|
395
|
+
if (skeleton.reason === 'registry-missing' || skeleton.reason === 'registry-unreadable') {
|
|
396
|
+
return '结构登记表缺失(' + skeleton.reason + '),骨架无从派生——模板在场也不静默判通过';
|
|
397
|
+
}
|
|
398
|
+
if (skeleton.reason === 'unknown-key') return '登记表未登记该工件键,结构无从派生';
|
|
399
|
+
if (skeleton.reason === 'template-undeclared') return '登记表未声明该工件的模板路径';
|
|
400
|
+
return file + ' 不存在或不可读(模板缺失)——安装 flow-kit 模板后本工件才会做结构校验';
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// 骨架评估入口(供产出物门禁与 ui-design 门共用):返回骨架、派生状态与问题清单。
|
|
404
|
+
export async function evaluateArtifact(key, text, options = {}) {
|
|
405
|
+
const skeleton = await buildSkeleton(key);
|
|
406
|
+
const derived = skeleton.derived === true;
|
|
407
|
+
const template = derived ? await templateOutlineFor(skeleton) : null;
|
|
408
|
+
const issues = collectArtifactIssues({
|
|
409
|
+
text,
|
|
410
|
+
skeleton,
|
|
411
|
+
derived,
|
|
412
|
+
template,
|
|
413
|
+
requiredHeaderFields: options.requiredHeaderFields ?? [],
|
|
414
|
+
underivedPolicy: options.underivedPolicy ?? 'registry',
|
|
415
|
+
});
|
|
416
|
+
return { skeleton, derived, issues };
|
|
102
417
|
}
|
|
103
418
|
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
419
|
+
// 单工件判定(纯函数,不输出):把问题清单压成报错编排要的形态(是否阻断 + 类别 + 提示账本键)。
|
|
420
|
+
// 结构子段缺席与其它结构问题同权——父段「适用」时子段必须在场(AC-2/AC-8),不按工件分叉。
|
|
421
|
+
export function assessArtifact({ fileLabel, skeleton, derived, issues }) {
|
|
422
|
+
return {
|
|
423
|
+
fileLabel,
|
|
424
|
+
key: skeleton.key,
|
|
425
|
+
skeleton,
|
|
426
|
+
derived,
|
|
427
|
+
hardIssues: issues,
|
|
428
|
+
hard: hasAnyIssue(issues),
|
|
429
|
+
categories: hintCategories(issues),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// 记忆键 = 工件键 + 文件:同一个模板键会被多份工件共用(execute 出口的每份 *-SUMMARY.md 都是
|
|
434
|
+
// SUMMARY),只按键记忆会让后一份工件继承前一份的「再犯」状态——同一次出口就升级成列段名,而修好
|
|
435
|
+
// 其中一份时另一份的失败又替它保住了键。
|
|
436
|
+
function hintKeyOf(item) {
|
|
437
|
+
return item.key + ':' + item.fileLabel;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 提示账本(两阶段记忆的纯逻辑,不写盘):把失败记进 hints 并给出各工件的报告行;escalate = 该工件
|
|
441
|
+
// 上一次也失败过(此时列出段名)。escalate 取自**进入本次报告前**的账本快照——同一次报告里两份
|
|
442
|
+
// 工件各自首败时互不升级。
|
|
443
|
+
function planFailureLines(hints, failing) {
|
|
444
|
+
const lines = [];
|
|
445
|
+
const previous = new Set(Object.keys(hints));
|
|
446
|
+
for (const item of failing) {
|
|
447
|
+
const hintKey = hintKeyOf(item);
|
|
448
|
+
const escalate = previous.has(hintKey);
|
|
449
|
+
hints[hintKey] = { failedAt: new Date().toISOString(), categories: item.categories };
|
|
450
|
+
lines.push(item.fileLabel + ' 模板结构校验失败: '
|
|
451
|
+
+ formatIssueParts(item.hardIssues, { escalate }).join('; ')
|
|
452
|
+
+ '(模板: ' + (item.skeleton.file ?? '(登记表未登记模板路径)') + ')');
|
|
453
|
+
}
|
|
454
|
+
return lines;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 通过的工件释放其记忆键(返回是否有改动,避免无谓写盘)。通过面在**每次**报告都释放——只在
|
|
458
|
+
// 「全部通过」时释放,会让已修好的工件在别的工件仍失败时留着旧键,下次再坏就被当成再犯。
|
|
459
|
+
function releasePassedHints(hints, assessments) {
|
|
460
|
+
let changed = false;
|
|
461
|
+
for (const item of assessments) {
|
|
462
|
+
const hintKey = hintKeyOf(item);
|
|
463
|
+
if (!Object.prototype.hasOwnProperty.call(hints, hintKey)) continue;
|
|
464
|
+
delete hints[hintKey];
|
|
465
|
+
changed = true;
|
|
466
|
+
}
|
|
467
|
+
return changed;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// 报错编排(单一实现):模板缺席 → 未校验行;有硬问题 → 两阶段 BLOCKED/WARN;通过面每次都释放
|
|
471
|
+
// 记忆键(与本次出口是否还有其他工件失败无关)。
|
|
472
|
+
// 同一出口的全部工件合并成一次报告——逐件 exit 会让执行者修一个再撞下一个,而这次出口的所有
|
|
473
|
+
// 结构问题一次就能看全。
|
|
474
|
+
export async function reportArtifactStructure({ changeDir, state, assessments }) {
|
|
475
|
+
for (const item of assessments) {
|
|
476
|
+
if (!item.derived) {
|
|
477
|
+
console.error('未校验(模板缺失): ' + item.fileLabel + ' —— ' + notCheckedReason(item.skeleton));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const failing = assessments.filter((item) => item.hard);
|
|
481
|
+
const hintsFile = path.join(changeDir, HINT_FILE_NAME);
|
|
482
|
+
const hints = await readHints(hintsFile);
|
|
483
|
+
const released = releasePassedHints(hints, assessments.filter((item) => !item.hard));
|
|
484
|
+
if (failing.length > 0) {
|
|
485
|
+
const lines = planFailureLines(hints, failing);
|
|
486
|
+
await writeHints(hintsFile, hints);
|
|
487
|
+
if (isNewChange(state)) {
|
|
488
|
+
for (const line of lines) console.error('BLOCKED: ' + line);
|
|
489
|
+
const templatePaths = [...new Set(failing.map((item) => item.skeleton.file ?? '(未登记模板路径)'))];
|
|
490
|
+
console.error('恢复: 对照 ' + templatePaths.join(' / ') + ' 修正标题 / 首部字段 / 段序,并按模板补齐缺失的 H2 与结构型 H3 标题'
|
|
491
|
+
+ '(条件段与无内容段正文可写 N/A;可选段按模板自述可整段删除)后重试 exit;同一工件再次失败时会列出具体段名'
|
|
492
|
+
+ '(已记录在 .specs/' + (state.activeChange ?? '<change>') + '/' + HINT_FILE_NAME + ')');
|
|
493
|
+
process.exit(1);
|
|
494
|
+
}
|
|
495
|
+
for (const line of lines) {
|
|
496
|
+
console.error('TEMPLATE-STRUCTURE WARN: ' + line + '(旧 change 渐进,不阻断;新 change 将强制)');
|
|
497
|
+
}
|
|
498
|
+
} else if (released) {
|
|
499
|
+
await writeHints(hintsFile, hints);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// SUMMARY 模板缺席时的既有段序兜底(无模板可派生骨架时仍拦乱序/缺段——这是模板权威门禁落地前
|
|
504
|
+
// 就有的判据,保留它避免「模板缺席 = 连乱序也不看」的倒退)。清单唯一来源 = 骨架模块的导出
|
|
505
|
+
// (本模块不自持第二份段名清单,只做归一)。
|
|
506
|
+
const LEGACY_SUMMARY_ORDER_NORMALIZED = LEGACY_SUMMARY_ORDER.map((name) => normalizeHeading(name));
|
|
507
|
+
|
|
508
|
+
function addLegacySummaryIssues(text, issues) {
|
|
509
|
+
const outline = parseOutline(text);
|
|
110
510
|
const seen = new Set();
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const boundsHeading = normalizeTemplateHeading('越界检查');
|
|
123
|
-
const selfIdx = headings.findIndex((h) => h.norm === selfHeading);
|
|
124
|
-
const boundsIdx = headings.findIndex((h) => h.norm === boundsHeading);
|
|
125
|
-
let selfCheckIssue = null;
|
|
126
|
-
if (selfIdx === -1) {
|
|
127
|
-
selfCheckIssue = '缺 ## 自检方法 段(须位于 ## 越界检查 之后:文末或紧随越界检查两种合法位置)';
|
|
128
|
-
} else if (
|
|
129
|
-
boundsIdx === -1 ||
|
|
130
|
-
selfIdx < boundsIdx ||
|
|
131
|
-
(selfIdx !== headings.length - 1 && selfIdx !== boundsIdx + 1)
|
|
132
|
-
) {
|
|
133
|
-
selfCheckIssue = '## 自检方法 位置非法(须位于 ## 越界检查 之后:只允许文末或紧随越界检查两种位置)';
|
|
134
|
-
}
|
|
135
|
-
return { missingSections, orderIssue, selfCheckIssue };
|
|
511
|
+
let lastIndex = -1;
|
|
512
|
+
for (const section of outline.sections) {
|
|
513
|
+
const index = LEGACY_SUMMARY_ORDER_NORMALIZED.indexOf(section.norm);
|
|
514
|
+
if (index === -1) continue;
|
|
515
|
+
if (index < lastIndex && issues.order === null) issues.order = { heading: section.raw };
|
|
516
|
+
lastIndex = Math.max(lastIndex, index);
|
|
517
|
+
seen.add(index);
|
|
518
|
+
}
|
|
519
|
+
for (let index = 0; index < LEGACY_SUMMARY_ORDER_NORMALIZED.length; index += 1) {
|
|
520
|
+
if (!seen.has(index)) issues.missing.push(LEGACY_SUMMARY_ORDER_NORMALIZED[index]);
|
|
521
|
+
}
|
|
136
522
|
}
|
|
137
523
|
|
|
138
|
-
// SUMMARY
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
// 不在骨架内,单独要求且只允许「文末」「紧随越界检查」两种位置。新 change 任一缺失 → BLOCK
|
|
143
|
-
// (含缺失点 + 恢复指引);旧 change/归档批 → WARN 渐进;模板缺失(无权威骨架来源)→ 新规则只
|
|
144
|
-
// 告警不阻断,保持旧格式渐进。
|
|
524
|
+
// SUMMARY 结构门禁(execute / subagent-execute):标题形态 / 首部四字段 / 全骨架(H2 + 结构型 H3,
|
|
525
|
+
// 条件段允许正文 N/A)/ 段序 / 空正文 / 逐字占位 / 增量段位置(自检方法 紧随越界检查或文末;
|
|
526
|
+
// LESSONS 扫描 紧随自检方法或在自检方法之后),新 change BLOCKED、旧 change WARN;模板缺席时
|
|
527
|
+
// 只保留既有兜底段序判据并显式输出「未校验(模板缺失)」。
|
|
145
528
|
export async function runSummaryTemplateFidelityGate({ node, state }) {
|
|
146
529
|
if (!EXECUTE_FAMILY_NODE_IDS.has(node.id)) return;
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
530
|
+
const changeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
531
|
+
const files = (await fs.readdir(changeDir).catch(() => [])).filter((file) => file.endsWith('-SUMMARY.md'));
|
|
532
|
+
if (files.length === 0) return;
|
|
533
|
+
const skeleton = await buildSkeleton('SUMMARY');
|
|
534
|
+
const derived = skeleton.derived === true;
|
|
535
|
+
const template = derived ? await templateOutlineFor(skeleton) : null;
|
|
536
|
+
const entries = [];
|
|
537
|
+
for (const file of files) {
|
|
538
|
+
let text;
|
|
153
539
|
try {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
540
|
+
text = await fs.readFile(path.join(changeDir, file), 'utf8');
|
|
541
|
+
} catch {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
// 首部字段键集来自登记表(模板缺席时同样可得)——SUMMARY 首部四字段是既有硬要求,不退化为软提醒
|
|
545
|
+
const issues = collectArtifactIssues({
|
|
546
|
+
text,
|
|
547
|
+
skeleton,
|
|
548
|
+
derived,
|
|
549
|
+
template,
|
|
550
|
+
requiredHeaderFields: skeleton.headerFields,
|
|
551
|
+
});
|
|
552
|
+
if (!derived) addLegacySummaryIssues(text, issues);
|
|
553
|
+
entries.push({ fileLabel: file, issues });
|
|
554
|
+
}
|
|
555
|
+
if (entries.length === 0) return;
|
|
556
|
+
await reportArtifactStructure({
|
|
557
|
+
changeDir,
|
|
558
|
+
state,
|
|
559
|
+
assessments: entries.map((entry) => assessArtifact({ ...entry, skeleton, derived })),
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// 节点 → 待校验工件:单一来源 = 协议。**该节点是否受模板门禁**由 protocol-utils 的
|
|
564
|
+
// nodeTemplateDeclaration 决定(内置节点取引擎映射、自定义节点取协议 node.templates,未声明 =
|
|
565
|
+
// 零模板 ⇒ 不校验,ADR-002 特化层);**产出哪份工件**取该节点 outputSchemas 的 artifacts[].paths
|
|
566
|
+
// (`<change-id>/…` 基),模板基名从工件名派生(`TASK.md` → TASK、`*-SUMMARY.md` → SUMMARY;`.md`
|
|
567
|
+
// 的剥离沿用 protocol-utils 的 templateKeyOf 单一实现)——本模块不另写节点→工件映射。
|
|
568
|
+
// SUMMARY 由 execute 家族的专用门负责(它还要消费无模板时的兜底段序),此处跳过以免同一工件被
|
|
569
|
+
// 两条门重复判定。
|
|
570
|
+
function templateKeyFromArtifactName(namePattern) {
|
|
571
|
+
const base = String(namePattern ?? '').split('*').pop().replace(/^[^A-Za-z0-9]+/u, '');
|
|
572
|
+
return base === '' ? null : templateKeyOf(base);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async function nodeArtifactTargets(node) {
|
|
576
|
+
let protocol = null;
|
|
577
|
+
try {
|
|
578
|
+
protocol = await readProtocolFile(runRoot, protocolPath);
|
|
579
|
+
} catch {
|
|
580
|
+
return [];
|
|
581
|
+
}
|
|
582
|
+
const schemas = new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
|
|
583
|
+
const targets = [];
|
|
584
|
+
for (const schemaId of node.outputSchemas ?? []) {
|
|
585
|
+
const schema = schemas.get(schemaId);
|
|
586
|
+
for (const artifact of schema?.artifacts ?? []) {
|
|
587
|
+
for (const pattern of artifact.paths ?? []) {
|
|
588
|
+
const segments = String(pattern ?? '').replaceAll('\\', '/').split('/');
|
|
589
|
+
if (segments.length !== 2 || segments[0] !== '<change-id>') continue;
|
|
590
|
+
const key = templateKeyFromArtifactName(segments[1]);
|
|
591
|
+
if (key === null) continue;
|
|
592
|
+
targets.push({ key, namePattern: segments[1] });
|
|
202
593
|
}
|
|
203
|
-
}
|
|
594
|
+
}
|
|
204
595
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
596
|
+
return targets;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
async function expandArtifactTargets(changeDir, targets) {
|
|
600
|
+
const expanded = [];
|
|
601
|
+
for (const target of targets) {
|
|
602
|
+
if (!target.namePattern.includes('*')) {
|
|
603
|
+
expanded.push({ key: target.key, file: target.namePattern });
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
const matcher = new RegExp('^' + target.namePattern.split('*').map(literalRegExp).join('.*') + '$', 'u');
|
|
607
|
+
for (const entry of await fs.readdir(changeDir).catch(() => [])) {
|
|
608
|
+
if (matcher.test(entry)) expanded.push({ key: target.key, file: entry });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return expanded;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// 工件 → 首部硬要求:入口文档(CHANGE/REQUIREMENT/DESIGN)沿用既有「Change ID 必在场」检查,
|
|
615
|
+
// SUMMARY 的四字段由专用门要求;其余工件的键集不新增硬性要求(只校验已在场键的值非空)。
|
|
616
|
+
const INTAKE_HEADER_KEYS = new Set(['CHANGE', 'REQUIREMENT', 'DESIGN']);
|
|
617
|
+
|
|
618
|
+
// 产出物的结构门(各节点出口):受门禁的节点逐个校验本节点产出的登记工件(模板权威)。导出名沿用
|
|
619
|
+
// 既有调用面(workflow-guard 的固定出口链)。所有工件同一口径:父段「适用」时结构子段必须在场
|
|
620
|
+
// (缺席即阻断,AC-2/AC-8),只有父段整段 N/A / 不适用时子段才豁免——不按工件分叉。
|
|
621
|
+
export async function runIntakeDocFidelityGate({ node, state }) {
|
|
622
|
+
if (!state.activeChange) return;
|
|
623
|
+
const declaration = nodeTemplateDeclaration(node);
|
|
624
|
+
if (declaration.source === 'none') return;
|
|
625
|
+
const changeDir = path.join(runRoot, '.specs', state.activeChange);
|
|
626
|
+
const declaredKeys = new Set([...declaration.required, ...declaration.optional].map((name) => templateKeyOf(name)));
|
|
627
|
+
const targets = await nodeArtifactTargets(node);
|
|
628
|
+
const assessments = [];
|
|
629
|
+
for (const target of await expandArtifactTargets(changeDir, targets)) {
|
|
630
|
+
const key = target.key;
|
|
631
|
+
if (templateKeyOf(key) === 'summary') continue;
|
|
632
|
+
if (declaration.source === 'protocol' && !declaredKeys.has(templateKeyOf(key))) continue;
|
|
633
|
+
const skeleton = await buildSkeleton(key);
|
|
634
|
+
if (skeleton.reason === 'unknown-key') continue; // 未登记的工件(UAT / DESIGN-lite 等)不做结构校验
|
|
635
|
+
const filePath = path.join(changeDir, target.file);
|
|
636
|
+
if (!(await fileExists(filePath))) continue;
|
|
637
|
+
let text;
|
|
638
|
+
try {
|
|
639
|
+
text = await fs.readFile(filePath, 'utf8');
|
|
640
|
+
} catch {
|
|
641
|
+
continue;
|
|
210
642
|
}
|
|
643
|
+
const evaluated = await evaluateArtifact(key, text, {
|
|
644
|
+
requiredHeaderFields: INTAKE_HEADER_KEYS.has(String(key).toUpperCase()) ? ['Change ID'] : [],
|
|
645
|
+
});
|
|
646
|
+
assessments.push(assessArtifact({
|
|
647
|
+
fileLabel: target.file,
|
|
648
|
+
skeleton: evaluated.skeleton,
|
|
649
|
+
derived: evaluated.derived,
|
|
650
|
+
issues: evaluated.issues,
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
if (assessments.length > 0) await reportArtifactStructure({ changeDir, state, assessments });
|
|
654
|
+
if (node.id === 'design' && assessments.length === 0) await legacyDesignLiteTitle(changeDir, state);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// DESIGN-lite 不是登记工件(模板权威不收它的段形)→ 只保留既有标题形态校验。
|
|
658
|
+
async function legacyDesignLiteTitle(changeDir, state) {
|
|
659
|
+
const file = path.join(changeDir, 'DESIGN-lite.md');
|
|
660
|
+
if (!(await fileExists(file))) return;
|
|
661
|
+
let text;
|
|
662
|
+
try {
|
|
663
|
+
text = await fs.readFile(file, 'utf8');
|
|
664
|
+
} catch {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const firstLine = (text.replace(/^\uFEFF/u, '').split('\n').find((line) => line.trim() !== '') ?? '').trim();
|
|
668
|
+
if (/^#\s*design\b/iu.test(firstLine)) return;
|
|
669
|
+
const message = 'DESIGN-lite.md 标题应以 # DESIGN 开头(如 `# DESIGN: <标题>`,大小写不敏感、冒号可省)';
|
|
670
|
+
if (isNewChange(state)) {
|
|
671
|
+
console.error('BLOCKED: ' + message);
|
|
672
|
+
console.error('恢复: 修正 DESIGN-lite.md 首行标题后重试 exit design');
|
|
211
673
|
process.exit(1);
|
|
212
674
|
}
|
|
675
|
+
console.error('INTAKE-DOC WARN: ' + message + '(旧 change 渐进,不阻断;新 change 将强制)');
|
|
213
676
|
}
|
|
214
677
|
|
|
215
678
|
// TASK 7 字段完整性门禁(plan 出口):每个 <task> 块须含
|
|
@@ -249,54 +712,3 @@ export async function runTaskSevenFieldGate({ node, state }) {
|
|
|
249
712
|
}
|
|
250
713
|
} catch {}
|
|
251
714
|
}
|
|
252
|
-
|
|
253
|
-
// 入口文档模板保真门禁(open / design 出口):标题与模板一致(# CHANGE: / # REQUIREMENT: /
|
|
254
|
-
// # DESIGN:,大小写不敏感、冒号可省)+ 段序按模板派生骨架宽容匹配(编号前缀/括号后缀兼容);
|
|
255
|
-
// 首部必要字段(Change ID)缺失 → 渐进 WARN。新 change 标题/段序失配 → BLOCK + 恢复指引;
|
|
256
|
-
// 旧 change/归档批 → WARN 渐进。
|
|
257
|
-
export async function runIntakeDocFidelityGate({ node, state }) {
|
|
258
|
-
if ((node.id !== 'open' && node.id !== 'design') || !state.activeChange) return;
|
|
259
|
-
const intakeDir = path.join(runRoot, '.specs', state.activeChange);
|
|
260
|
-
const skeletonsCache = {};
|
|
261
|
-
const hardProblems = [];
|
|
262
|
-
const softWarnings = [];
|
|
263
|
-
const checkIntakeDoc = async (file, key, label, titleRe) => {
|
|
264
|
-
const p = path.join(intakeDir, file);
|
|
265
|
-
if (!(await fileExists(p))) return; // 文件缺失由产物校验兜底
|
|
266
|
-
const text = await fs.readFile(p, 'utf8');
|
|
267
|
-
const firstLine = (text.replace(/\uFEFF/g, '').split('\n').find((l) => l.trim().length > 0) || '').trim();
|
|
268
|
-
if (!titleRe.test(firstLine)) {
|
|
269
|
-
hardProblems.push(file + ' 标题应以 # ' + label + ' 开头(如 `# ' + label + ': <标题>`,大小写不敏感、冒号可省)');
|
|
270
|
-
}
|
|
271
|
-
if (!skeletonsCache[key]) skeletonsCache[key] = await templateSkeleton(key);
|
|
272
|
-
const viol = templateOrderViolation(skeletonsCache[key], documentSectionHeadings(text));
|
|
273
|
-
if (viol) {
|
|
274
|
-
hardProblems.push(file + ' 段序乱(「' + String(viol).replace(/^##\s*/, '') + '」偏离 ' + label + ' 模板段序)');
|
|
275
|
-
}
|
|
276
|
-
const changeIdMissing = !/\*\*\s*Change\s+ID\s*\*\*/i.test(text.split(/\n##\s/)[0]);
|
|
277
|
-
const intakeMsg = file + ' 首部缺 Change ID 字段(' + label + ' 模板首部含 `- **Change ID**: <id>`)';
|
|
278
|
-
if (changeIdMissing) {
|
|
279
|
-
if (isNewChange(state)) hardProblems.push(intakeMsg);
|
|
280
|
-
else softWarnings.push(intakeMsg + '(渐进提示;新 change 将强制)');
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
if (node.id === 'open') {
|
|
284
|
-
await checkIntakeDoc('CHANGE.md', 'change', 'CHANGE', /^#\s*change\b/i);
|
|
285
|
-
await checkIntakeDoc('REQUIREMENT.md', 'requirement', 'REQUIREMENT', /^#\s*requirement\b/i);
|
|
286
|
-
} else {
|
|
287
|
-
// design:与既有校验一致的 target 选择(DESIGN.md 优先,DESIGN-lite 兜底)
|
|
288
|
-
const designFile = path.join(intakeDir, 'DESIGN.md');
|
|
289
|
-
const designLite = path.join(intakeDir, 'DESIGN-lite.md');
|
|
290
|
-
const chosen = (await fileExists(designFile)) ? 'DESIGN.md' : ((await fileExists(designLite)) ? 'DESIGN-lite.md' : null);
|
|
291
|
-
if (chosen) await checkIntakeDoc(chosen, 'design', 'DESIGN', /^#\s*design\b/i);
|
|
292
|
-
}
|
|
293
|
-
for (const w of softWarnings) console.error('INTAKE-DOC WARN: ' + w + '(渐进提示,不阻断;新 change 同)');
|
|
294
|
-
if (hardProblems.length > 0) {
|
|
295
|
-
if (isNewChange(state)) {
|
|
296
|
-
console.error('BLOCKED: 入口文档模板保真校验失败: ' + hardProblems.join('; '));
|
|
297
|
-
console.error('恢复: 对照 flow-kit/templates/{CHANGE,REQUIREMENT,DESIGN}.md 修正标题与段序后重试 exit;新 change 强制模板保真');
|
|
298
|
-
process.exit(1);
|
|
299
|
-
}
|
|
300
|
-
for (const h of hardProblems) console.error('INTAKE-DOC WARN: ' + h + '(旧 change/归档批渐进,不阻断;新 change 将强制)');
|
|
301
|
-
}
|
|
302
|
-
}
|