flow-comet 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/rules/flow-comet-orchestration.md +1 -2
- 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/TEST-MATRIX.md +9 -8
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +9 -2
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +4233 -94
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +24 -4
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +697 -15
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +69 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +1656 -5
- package/.flow-comet/skills/flow-comet/scripts/task-parsing.mjs +13 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +429 -276
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +330 -13
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +423 -38
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +15 -0
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +19 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +21 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +12 -3
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +19 -4
- package/README.md +6 -2
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/prepare-env.mjs +77 -46
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
import { constants as fsConstants, promises as fs } from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { resolveProtocol, readProtocolFile, validateProtocolSchema, NODE_PROTOCOL_FILES } from './protocol-utils.mjs';
|
|
5
|
+
import { validateStateFields, verifyFailuresFor, setVerifyFailuresFor, RUNTIME_STATE_PATH, LEGACY_RUNTIME_STATE_PATH, resolveProtocolPathWithState, hasProtocolCliArg } from './state-schema.mjs';
|
|
6
|
+
import { readProtocolFile, validateProtocolSchema, NODE_PROTOCOL_FILES, workflowPathInside, inspectWorkflowProtectedPath, readWorkflowProtectedFile, workflowFileObjectIdentity, workflowSameFileObject, workflowSameFileStat } from './protocol-utils.mjs';
|
|
8
7
|
import { taskOpeningAttrs, taskBlocks as extractTaskBlocks } from './task-parsing.mjs';
|
|
9
|
-
import { resolveNextNode } from './route-node.mjs';
|
|
8
|
+
import { resolveNextNode, resolveFixRollbackDecision, resolveFixRollbackState, applyFixRollbackRound, resolveFixReturnNode, EXECUTE_FAMILY_NODE_IDS, TASK_SET_SIGNATURE_ALGO, taskSetSignature, parseTaskSetSignature, sameTaskSetSignature, taskSetSignatureVersionSkew, classifyFixReturnCause, normalizeHeading, FIX_SECTION_TITLE_FALLBACK } from './route-node.mjs';
|
|
10
9
|
|
|
11
10
|
const command = process.argv[2] ?? 'verify';
|
|
12
11
|
const nodeId = process.argv[3] ?? null;
|
|
@@ -14,9 +13,11 @@ const apply = process.argv.includes('--apply');
|
|
|
14
13
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
14
|
const packageRoot = path.resolve(__dirname, '..');
|
|
16
15
|
const runRoot = process.env.FLOW_COMET_RUN_ROOT ? path.resolve(process.env.FLOW_COMET_RUN_ROOT) : process.cwd();
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
16
|
+
// 协议路径解析:显式 --protocol 全局参数(command=argv[2] 之后的剩余参数)> state.protocolPath
|
|
17
|
+
// (init 持久化绑定)> FLOW_COMET_PROTOCOL 环境变量 > 内置默认
|
|
18
|
+
// <packageRoot>/reference/workflow-protocol.json。选择在 main() 内执行(state.protocolPath 需先读
|
|
19
|
+
// 标准运行时状态文件引导,协议决定 statePath 时存在先后次序),此处仅声明供 main 与错误文案使用。
|
|
20
|
+
let protocolPath = null;
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
const WORKFLOW_PROJECT_FILE_MAX_BYTES = 2 * 1024 * 1024;
|
|
@@ -51,237 +52,127 @@ function markerProtocolBasename(value) {
|
|
|
51
52
|
return String(value).replaceAll('\\', '/').split('/').pop() || null;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
// REVIEW.md
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
projectRoot,
|
|
97
|
-
target,
|
|
98
|
-
label,
|
|
99
|
-
expected = 'any',
|
|
100
|
-
) {
|
|
101
|
-
const lexicalRoot = path.resolve(projectRoot);
|
|
102
|
-
const lexicalTarget = path.resolve(target);
|
|
103
|
-
if (!workflowPathInside(lexicalRoot, lexicalTarget)) {
|
|
104
|
-
throw new Error(label + ' must stay inside the project root');
|
|
105
|
-
}
|
|
106
|
-
const rootStat = await fs.lstat(lexicalRoot);
|
|
107
|
-
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
108
|
-
throw new Error(label + ' project root must be a real directory');
|
|
109
|
-
}
|
|
110
|
-
const realRoot = await fs.realpath(lexicalRoot);
|
|
111
|
-
const relative = path.relative(lexicalRoot, lexicalTarget);
|
|
112
|
-
const segments = relative === '' ? [] : relative.split(path.sep);
|
|
113
|
-
let cursor = lexicalRoot;
|
|
114
|
-
for (let index = 0; index < segments.length; index++) {
|
|
115
|
-
cursor = path.join(cursor, segments[index]);
|
|
116
|
-
let stat;
|
|
117
|
-
try {
|
|
118
|
-
stat = await fs.lstat(cursor);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (
|
|
121
|
-
error &&
|
|
122
|
-
typeof error === 'object' &&
|
|
123
|
-
(error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
124
|
-
) {
|
|
125
|
-
return { target: lexicalTarget, exists: false };
|
|
126
|
-
}
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
const display = path.relative(lexicalRoot, cursor).replaceAll('\\', '/');
|
|
130
|
-
if (stat.isSymbolicLink()) {
|
|
131
|
-
throw new Error(label + ' crosses a symbolic link or junction at ' + display);
|
|
132
|
-
}
|
|
133
|
-
const final = index === segments.length - 1;
|
|
134
|
-
if (!final && !stat.isDirectory()) {
|
|
135
|
-
throw new Error(label + ' ancestor ' + display + ' must be a real directory');
|
|
136
|
-
}
|
|
137
|
-
if (
|
|
138
|
-
final &&
|
|
139
|
-
((expected === 'file' && !stat.isFile()) ||
|
|
140
|
-
(expected === 'directory' && !stat.isDirectory()) ||
|
|
141
|
-
(expected === 'any' && !stat.isFile() && !stat.isDirectory()))
|
|
142
|
-
) {
|
|
143
|
-
throw new Error(label + ' must be a real ' + expected);
|
|
55
|
+
// REVIEW.md 发现区条目解析——"## 发现" 段下的发现项 = 列表项("- **" 无序 / "1. **" 有序,
|
|
56
|
+
// 两种列表形态同口径解析);"无" 条目("- 无" / "无(...)")表示该级别无发现,豁免。条目块
|
|
57
|
+
// 包含其后的非空续行(同一段落),直到空行 / 下一条目 / 下一个标题。严重度只取该条目自身的
|
|
58
|
+
// 标题/行首——所属 "### Major" 分区,或标题(加粗部分)内带 [Major] 标签(真实 REVIEW 常用
|
|
59
|
+
// 扁平有序列表 + 条目内级别标签的写法);条目正文引用他条的 [Major] 字样不改变本条严重度。
|
|
60
|
+
// 返回 { title, lines, isMajor, ordinal }。
|
|
61
|
+
const REVIEW_FINDING_ITEM_RE = /^\s*(?:[-*+]|\d+[.)])\s*\*\*(.+?)\*\*/;
|
|
62
|
+
const REVIEW_DISPOSITION_RE = /\[已修\]|\[升级\]|\[转待办\]/;
|
|
63
|
+
const REVIEW_MAJOR_LABEL_RE = /\[\s*Major\s*\]/i;
|
|
64
|
+
const REVIEW_ADJUDICATION_RE = /用户裁决\s*[::]\s*接受延期/;
|
|
65
|
+
|
|
66
|
+
function reviewFindingsItems(text) {
|
|
67
|
+
const items = [];
|
|
68
|
+
let inFindings = false;
|
|
69
|
+
let severity = '';
|
|
70
|
+
let current = null;
|
|
71
|
+
const pushCurrent = () => { if (current) { items.push(current); current = null; } };
|
|
72
|
+
for (const line of String(text).split(/\r?\n/)) {
|
|
73
|
+
const h2 = line.match(/^##\s+(.+?)\s*$/);
|
|
74
|
+
if (h2) {
|
|
75
|
+
pushCurrent();
|
|
76
|
+
inFindings = /^发现/.test(h2[1]);
|
|
77
|
+
severity = '';
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (!inFindings) continue;
|
|
81
|
+
const h3 = line.match(/^###\s+(.+?)\s*$/);
|
|
82
|
+
if (h3) {
|
|
83
|
+
pushCurrent();
|
|
84
|
+
severity = h3[1].trim();
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const m = line.match(REVIEW_FINDING_ITEM_RE);
|
|
88
|
+
if (m) {
|
|
89
|
+
pushCurrent();
|
|
90
|
+
const title = m[1].trim();
|
|
91
|
+
current = {
|
|
92
|
+
title,
|
|
93
|
+
lines: [line],
|
|
94
|
+
isMajor: /^major\b/i.test(severity) || REVIEW_MAJOR_LABEL_RE.test(title),
|
|
95
|
+
};
|
|
96
|
+
continue;
|
|
144
97
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
98
|
+
if (current) {
|
|
99
|
+
if (line.trim() === '') pushCurrent();
|
|
100
|
+
else current.lines.push(line);
|
|
148
101
|
}
|
|
149
102
|
}
|
|
150
|
-
|
|
103
|
+
pushCurrent();
|
|
104
|
+
items.forEach((item, i) => { item.ordinal = i + 1; });
|
|
105
|
+
return items;
|
|
151
106
|
}
|
|
152
107
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
108
|
+
// 发现区条目处置标记存在性:返回缺处置状态标记([已修]/[升级]/[转待办])的条目标题列表——
|
|
109
|
+
// 结构级校验(不做语义判断:标记存在即视为已处置)。发现项(含 Minor;无序与有序条目同口径,
|
|
110
|
+
// 均不得"记录后无声消失")的处置标记以该条目自身标题/行首为准——正文引用他条标记不参与判定。
|
|
111
|
+
function reviewFindingsMissingDisposition(text) {
|
|
112
|
+
return reviewFindingsItems(text)
|
|
113
|
+
.filter((item) => !/^无/.test(item.title)) // "无" 条目豁免
|
|
114
|
+
// 四要素字段行豁免:REVIEW 发现条目的 Symptom/Source/Consequence/Remedy
|
|
115
|
+
// 是 brooks 审查输出格式的字段行(带 ** 加粗),不是发现条目本身——不豁免会误判
|
|
116
|
+
// 为"发现项缺处置标记"(执行者按 4 要素格式书写时被误 BLOCKED)。
|
|
117
|
+
// 精确匹配完整标签(允许尾冒号)——"Source maps expose paths" 这类以 Source 开头的
|
|
118
|
+
// 真实发现标题不得被前缀匹配误豁免(其处置校验必须照常进行)
|
|
119
|
+
.filter((item) => !/^(?:Symptom|Source|Consequence|Remedy)\s*:?\s*$/i.test(item.title))
|
|
120
|
+
.filter((item) => !REVIEW_DISPOSITION_RE.test(item.lines[0]))
|
|
121
|
+
.map((item) => item.title);
|
|
159
122
|
}
|
|
160
123
|
|
|
161
|
-
|
|
162
|
-
|
|
124
|
+
// 裁决记录是否指向某条发现:条目标题全文 / 标题内标识 token(如 F1、m-2)/ 条目序号
|
|
125
|
+
// (发现 N、第 N 项、#N)/ 标题核心前缀任一命中即视为指认。结构级判定,不做语义判断。
|
|
126
|
+
function reviewAdjudicationPointsTo(record, item) {
|
|
127
|
+
if (record.includes(item.title)) return true;
|
|
128
|
+
const idTokens = item.title.match(/[A-Za-z]{1,8}[-–]?\d{1,4}/g) || [];
|
|
129
|
+
if (idTokens.some((token) => record.includes(token))) return true;
|
|
130
|
+
if (new RegExp('(?:发现|条目|第|#)\\s*' + item.ordinal + '(?!\\d)').test(record)) return true;
|
|
131
|
+
const core = item.title.replace(/[\[\]【】]/g, '').replace(/^[A-Za-z]+\s*/, '').trim().slice(0, 12);
|
|
132
|
+
return core.length >= 6 && record.includes(core);
|
|
163
133
|
}
|
|
164
134
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
135
|
+
// Major 延期裁决门禁:发现区任何 Major 条目处置为 [转待办] 时,必须同时存在用户裁决记录——
|
|
136
|
+
// 同段(条目自身段落)或文末其余段落含「用户裁决:接受延期」且指向该条目,并由 [升级] 承接
|
|
137
|
+
// (条目自身块或裁决记录含 [升级])。任一缺失 → 返回条目标题(调用方按新 change BLOCK /
|
|
138
|
+
// 旧 change WARN 渐进处置)。Minor 不参与;Major [升级]/[已修] 直接放行。
|
|
139
|
+
// 条目自身的处置标记([转待办])只认该条目标题/行首(无序与有序同口径),正文续行引用他条
|
|
140
|
+
// 标记不触发本门禁;[升级] 承接可出现在条目自身块或用户裁决记录中(承接非本条处置)。
|
|
141
|
+
function reviewDeferredMajorProblems(text) {
|
|
142
|
+
const textValue = String(text);
|
|
143
|
+
const items = reviewFindingsItems(textValue);
|
|
144
|
+
const paragraphs = textValue.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
|
|
145
|
+
const problems = [];
|
|
146
|
+
for (const item of items) {
|
|
147
|
+
const ownLine = item.lines[0];
|
|
148
|
+
if (!item.isMajor || !/\[转待办\]/.test(ownLine)) continue;
|
|
149
|
+
const block = item.lines.join('\n');
|
|
150
|
+
const escalatedInBlock = /\[升级\]/.test(block);
|
|
151
|
+
const blockTrimmed = block.trim();
|
|
152
|
+
if (REVIEW_ADJUDICATION_RE.test(block) && escalatedInBlock) continue; // 同段裁决 + [升级] 承接
|
|
153
|
+
const matched = paragraphs.some((paragraph) => {
|
|
154
|
+
if (!REVIEW_ADJUDICATION_RE.test(paragraph)) return false;
|
|
155
|
+
if (paragraph === blockTrimmed) return false; // 跳过条目自身段落
|
|
156
|
+
return (escalatedInBlock || /\[升级\]/.test(paragraph)) && reviewAdjudicationPointsTo(paragraph, item);
|
|
157
|
+
});
|
|
158
|
+
if (!matched) problems.push(item.title);
|
|
159
|
+
}
|
|
160
|
+
return problems;
|
|
172
161
|
}
|
|
173
162
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
left.size === right.size &&
|
|
181
|
-
left.ctimeNs === right.ctimeNs
|
|
182
|
-
);
|
|
183
|
-
}
|
|
163
|
+
// W1-B: flow-kit SUMMARY 模板必填段(正则匹配,大小写不敏感 + 变体兼容)
|
|
164
|
+
const SUMMARY_REQUIRED_SECTIONS = [
|
|
165
|
+
{ regex: /##\s*verify\s*输出/i, label: '## verify 输出' },
|
|
166
|
+
{ regex: /##\s*6\s*维自查/i, label: '## 6 维自查' },
|
|
167
|
+
{ regex: /##\s*(越界检查|边界检查)/i, label: '## 越界检查' },
|
|
168
|
+
];
|
|
184
169
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
) {
|
|
192
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {
|
|
193
|
-
throw new Error(label + ' byte limit must be a positive integer');
|
|
194
|
-
}
|
|
195
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
196
|
-
projectRoot,
|
|
197
|
-
file,
|
|
198
|
-
label,
|
|
199
|
-
'file',
|
|
200
|
-
);
|
|
201
|
-
if (!inspection.exists) {
|
|
202
|
-
const error = new Error(label + ' does not exist');
|
|
203
|
-
error.code = 'ENOENT';
|
|
204
|
-
throw error;
|
|
205
|
-
}
|
|
206
|
-
const before = await fs.lstat(file, { bigint: true });
|
|
207
|
-
if (!before.isFile() || before.isSymbolicLink()) {
|
|
208
|
-
throw new Error(label + ' must be a real file');
|
|
209
|
-
}
|
|
210
|
-
if (before.size > BigInt(maxBytes)) {
|
|
211
|
-
throw new Error(label + ' exceeds ' + String(maxBytes) + ' bytes');
|
|
212
|
-
}
|
|
213
|
-
const beforeRealPath = await fs.realpath(file);
|
|
214
|
-
await hooks.afterLstat?.();
|
|
215
|
-
const flags =
|
|
216
|
-
process.platform === 'win32'
|
|
217
|
-
? fsConstants.O_RDONLY
|
|
218
|
-
: fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK;
|
|
219
|
-
let handle;
|
|
220
|
-
try {
|
|
221
|
-
handle = await fs.open(file, flags);
|
|
222
|
-
} catch (error) {
|
|
223
|
-
if (error && typeof error === 'object' && error.code === 'ELOOP') {
|
|
224
|
-
throw new Error(label + ' must be a real file');
|
|
225
|
-
}
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
const [opened, afterOpen, afterOpenRealPath] = await Promise.all([
|
|
230
|
-
handle.stat({ bigint: true }),
|
|
231
|
-
fs.lstat(file, { bigint: true }),
|
|
232
|
-
fs.realpath(file),
|
|
233
|
-
]);
|
|
234
|
-
if (
|
|
235
|
-
!opened.isFile() ||
|
|
236
|
-
!afterOpen.isFile() ||
|
|
237
|
-
afterOpen.isSymbolicLink() ||
|
|
238
|
-
afterOpenRealPath !== beforeRealPath ||
|
|
239
|
-
!workflowSameFileStat(before, opened) ||
|
|
240
|
-
!workflowSameFileStat(before, afterOpen)
|
|
241
|
-
) {
|
|
242
|
-
throw new Error(label + ' changed while opening');
|
|
243
|
-
}
|
|
244
|
-
await inspectWorkflowProtectedPath(projectRoot, file, label, 'file');
|
|
245
|
-
await hooks.afterOpen?.();
|
|
246
|
-
const chunks = [];
|
|
247
|
-
let total = 0;
|
|
248
|
-
const buffer = Buffer.allocUnsafe(Math.min(64 * 1024, maxBytes + 1));
|
|
249
|
-
for (;;) {
|
|
250
|
-
const remaining = maxBytes + 1 - total;
|
|
251
|
-
const { bytesRead } = await handle.read(
|
|
252
|
-
buffer,
|
|
253
|
-
0,
|
|
254
|
-
Math.min(buffer.length, remaining),
|
|
255
|
-
null,
|
|
256
|
-
);
|
|
257
|
-
if (bytesRead === 0) break;
|
|
258
|
-
total += bytesRead;
|
|
259
|
-
if (total > maxBytes) {
|
|
260
|
-
throw new Error(label + ' exceeds ' + String(maxBytes) + ' bytes');
|
|
261
|
-
}
|
|
262
|
-
chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
|
|
263
|
-
}
|
|
264
|
-
await hooks.beforeFinalCheck?.();
|
|
265
|
-
const [afterHandle, afterPath, afterRealPath] = await Promise.all([
|
|
266
|
-
handle.stat({ bigint: true }),
|
|
267
|
-
fs.lstat(file, { bigint: true }),
|
|
268
|
-
fs.realpath(file),
|
|
269
|
-
]);
|
|
270
|
-
if (
|
|
271
|
-
!afterPath.isFile() ||
|
|
272
|
-
afterPath.isSymbolicLink() ||
|
|
273
|
-
afterRealPath !== beforeRealPath ||
|
|
274
|
-
!workflowSameFileStat(before, afterHandle) ||
|
|
275
|
-
!workflowSameFileStat(before, afterPath)
|
|
276
|
-
) {
|
|
277
|
-
throw new Error(label + ' changed while reading');
|
|
278
|
-
}
|
|
279
|
-
await inspectWorkflowProtectedPath(projectRoot, file, label, 'file');
|
|
280
|
-
return Buffer.concat(chunks, total);
|
|
281
|
-
} finally {
|
|
282
|
-
await handle.close();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
170
|
+
// 受保护读取 / 文件身份比较 / 路径包含与逐段扫描判据的单一权威在 protocol-utils.mjs
|
|
171
|
+
// (readWorkflowProtectedFile / workflowFileObjectIdentity / workflowSameFileObject /
|
|
172
|
+
// workflowSameFileStat / workflowPathInside / inspectWorkflowProtectedPath),本文件不再保留
|
|
173
|
+
// 本地副本:同一判据两份实现会静默分叉,注释互指同源不是同步机制。错误语义(越界 / 非真实根 /
|
|
174
|
+
// symlink 或 junction / 类型不符 / 物理逃逸 / 读取期间身份漂移的抛错文案与 fail-closed 行为)
|
|
175
|
+
// 由该单一实现统一保证。
|
|
285
176
|
|
|
286
177
|
function workflowRelativeSegments(value, label, allowWildcards = false) {
|
|
287
178
|
if (typeof value !== 'string') throw new Error(label + ' must be a string');
|
|
@@ -1065,11 +956,12 @@ async function templateSectionPatterns() {
|
|
|
1065
956
|
return templateSectionPatternsCache;
|
|
1066
957
|
}
|
|
1067
958
|
const templateDir = path.join(runRoot, 'flow-kit', 'templates');
|
|
1068
|
-
const result = { change: [], requirement: [], design: [] };
|
|
959
|
+
const result = { change: [], requirement: [], design: [], summary: [] };
|
|
1069
960
|
for (const [key, fileName] of Object.entries({
|
|
1070
961
|
change: 'CHANGE.md',
|
|
1071
962
|
requirement: 'REQUIREMENT.md',
|
|
1072
963
|
design: 'DESIGN.md',
|
|
964
|
+
summary: 'SUMMARY.md',
|
|
1073
965
|
})) {
|
|
1074
966
|
const templateFile = path.join(templateDir, fileName);
|
|
1075
967
|
if (await fileExists(templateFile)) {
|
|
@@ -1093,17 +985,49 @@ async function templateSectionPatterns() {
|
|
|
1093
985
|
return result;
|
|
1094
986
|
}
|
|
1095
987
|
|
|
988
|
+
// Fix 段标题从 <runRoot>/flow-kit/templates/TASK.md 派生(单一模板源 + 模块级缓存 + runRoot 键控):
|
|
989
|
+
// 扫描模板全部 H2,用 route-node 共享 heading 归一(单一权威,含闭合 ATX)识别 Fix 段标题;
|
|
990
|
+
// 无匹配(模板缺失 / 读取失败 / 无 Fix 段)返回 undefined,由回程分类器的内置 fallback 常量兜底。
|
|
991
|
+
// 标题只喂给回程分类器决定审计行(不参与路由/state 写入)。
|
|
992
|
+
// 识别标记词从单一权威 fallback 派生(归一后首词,如 Fix 任务 → Fix),因此模板基名改为其它
|
|
993
|
+
// 语言后缀(如 Fix Tasks)仍可识别;闭合 ATX 与尾部括号变体由共享归一消化。
|
|
994
|
+
const FIX_SECTION_HEADING_MARKER = normalizeHeading(FIX_SECTION_TITLE_FALLBACK).split(/\s+/u)[0];
|
|
995
|
+
|
|
996
|
+
// 模板文本全部 H2 中的 Fix 段标题(无匹配 → undefined):共享归一后与识别标记词比较,
|
|
997
|
+
// 因此语言后缀可变(Fix 任务 / Fix Tasks);闭合 ATX 与尾部括号由共享归一消化。
|
|
998
|
+
function fixSectionTitleFromTemplateText(text) {
|
|
999
|
+
for (const match of String(text).matchAll(/^##\s+(.+)$/gmu)) {
|
|
1000
|
+
const raw = match[1].trim();
|
|
1001
|
+
const normalized = normalizeHeading(raw);
|
|
1002
|
+
if (normalized === FIX_SECTION_HEADING_MARKER
|
|
1003
|
+
|| normalized.startsWith(FIX_SECTION_HEADING_MARKER + ' ')) return raw;
|
|
1004
|
+
}
|
|
1005
|
+
return undefined;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
let fixSectionTitleCacheRoot = null;
|
|
1009
|
+
let fixSectionTitleCached = false;
|
|
1010
|
+
let fixSectionTitleCache;
|
|
1011
|
+
async function derivedFixSectionTitle() {
|
|
1012
|
+
if (fixSectionTitleCacheRoot === runRoot && fixSectionTitleCached) return fixSectionTitleCache;
|
|
1013
|
+
let title;
|
|
1014
|
+
const templateFile = path.join(runRoot, 'flow-kit', 'templates', 'TASK.md');
|
|
1015
|
+
if (await fileExists(templateFile)) {
|
|
1016
|
+
try {
|
|
1017
|
+
title = fixSectionTitleFromTemplateText(await fs.readFile(templateFile, 'utf8'));
|
|
1018
|
+
} catch {}
|
|
1019
|
+
}
|
|
1020
|
+
fixSectionTitleCache = title;
|
|
1021
|
+
fixSectionTitleCacheRoot = runRoot;
|
|
1022
|
+
fixSectionTitleCached = true;
|
|
1023
|
+
return title;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1096
1026
|
// ===== 模板保真(M1/M2/M3·设计语义 / AC-7~AC-9)=====
|
|
1097
|
-
//
|
|
1098
|
-
//
|
|
1027
|
+
// 段名归一化:委托 route-node 共享 heading 归一(单一权威)——去标题标记 / 尾部括号
|
|
1028
|
+
// (如 Why(为什么做)→ Why)/ 编号前缀(1. 决策清单 → 决策清单)/ 闭合 ATX,去首尾空白 + 小写。
|
|
1099
1029
|
function normalizeTemplateHeading(raw) {
|
|
1100
|
-
return
|
|
1101
|
-
.replace(/\r/g, '')
|
|
1102
|
-
.replace(/^#{1,6}\s*/, '')
|
|
1103
|
-
.replace(/[((][^))\n]*[))]\s*$/u, '')
|
|
1104
|
-
.replace(/^\d+(?:\.\d+)?\.?\s*/u, '')
|
|
1105
|
-
.trim()
|
|
1106
|
-
.toLowerCase();
|
|
1030
|
+
return normalizeHeading(raw);
|
|
1107
1031
|
}
|
|
1108
1032
|
|
|
1109
1033
|
// 提取文档全部 ^## 段(归一化后),供段序/缺段校验
|
|
@@ -1120,13 +1044,23 @@ async function templateSectionPatterns() {
|
|
|
1120
1044
|
change: ['why', 'what', '视觉调性', '影响面', '范围排除', '验收线', '风险与未知'],
|
|
1121
1045
|
requirement: ['用户故事', '验收准则', '范围切分', '非功能性需求', '依赖与假设'],
|
|
1122
1046
|
design: ['技术栈选定', '既有架构对齐', '决策清单', '数据流', '关键状态机', 'adr 索引', '风险', '不在范围', '架构沉淀建议'],
|
|
1047
|
+
// SUMMARY 模板缺失时的内置全骨架:十段(含条件段——条件段允许正文 N/A,但 H2 标题须在场)
|
|
1048
|
+
summary: ['做了什么', '改动文件', 'verify 输出', '6 维自查', '数据库迁移', '越界检查', '破坏性变更', '决策与偏离', '是否触发新工作', '完成判定'],
|
|
1123
1049
|
};
|
|
1124
1050
|
|
|
1125
1051
|
async function templateSkeleton(key) {
|
|
1126
1052
|
const tpl = await templateSectionPatterns(); // 复用 C2 模板缓存(runRoot 内模板)
|
|
1127
1053
|
const src = tpl[key] ?? [];
|
|
1128
1054
|
if (src.length > 0) return src.map((s) => normalizeTemplateHeading(s.name));
|
|
1129
|
-
return TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? [];
|
|
1055
|
+
return (TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? []).map((s) => normalizeTemplateHeading(s));
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// SUMMARY 全骨架来源:模板全部 H2 派生(derived=true);模板缺失/无 H2 → 内置十段兜底
|
|
1059
|
+
// (derived=false——调用方据此保持渐进兼容,不新增硬阻断)
|
|
1060
|
+
async function summaryTemplateSkeleton() {
|
|
1061
|
+
const tpl = await templateSectionPatterns();
|
|
1062
|
+
const derived = (tpl.summary ?? []).length > 0;
|
|
1063
|
+
return { derived, sections: await templateSkeleton('summary') };
|
|
1130
1064
|
}
|
|
1131
1065
|
|
|
1132
1066
|
// 段序校核(宽容):模板骨架段里「实际出现」的段须按模板先后出现;返回乱序描述(无则 null)
|
|
@@ -1179,40 +1113,93 @@ async function templateSectionPatterns() {
|
|
|
1179
1113
|
return { titleMissing, headerMissing, orderIssue, missingSections };
|
|
1180
1114
|
}
|
|
1181
1115
|
|
|
1182
|
-
//
|
|
1183
|
-
//
|
|
1184
|
-
//
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
)
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1116
|
+
// 全骨架保真:骨架来自 SUMMARY 模板全部 H2;每段须存在(条件段内容可写 N/A,但须有 H2 标题),
|
|
1117
|
+
// 实际出现的骨架段须按模板先后排列。## 自检方法 不进入骨架,单独校验:须位于 ## 越界检查 之后,
|
|
1118
|
+
// 且只允许两种位置——紧随 ## 越界检查 之后(下一段即自检方法)或位于全文末尾(最后一个 H2)。
|
|
1119
|
+
function summarySkeletonFidelity(content, skeleton) {
|
|
1120
|
+
const text = String(content).replace(/\uFEFF/g, '');
|
|
1121
|
+
const headings = documentSectionHeadings(text);
|
|
1122
|
+
const seen = new Set();
|
|
1123
|
+
for (const h of headings) {
|
|
1124
|
+
const idx = skeleton.sections.indexOf(h.norm);
|
|
1125
|
+
if (idx !== -1) seen.add(idx);
|
|
1126
|
+
}
|
|
1127
|
+
// 段序复用既有骨架校核(单一实现),段存在性单列——两者共用同一骨架
|
|
1128
|
+
const orderIssue = templateOrderViolation(skeleton.sections, headings);
|
|
1129
|
+
const missingSections = [];
|
|
1130
|
+
for (let i = 0; i < skeleton.sections.length; i++) {
|
|
1131
|
+
if (!seen.has(i)) missingSections.push(skeleton.sections[i]);
|
|
1132
|
+
}
|
|
1133
|
+
const selfHeading = normalizeTemplateHeading('自检方法');
|
|
1134
|
+
const boundsHeading = normalizeTemplateHeading('越界检查');
|
|
1135
|
+
const selfIdx = headings.findIndex((h) => h.norm === selfHeading);
|
|
1136
|
+
const boundsIdx = headings.findIndex((h) => h.norm === boundsHeading);
|
|
1137
|
+
let selfCheckIssue = null;
|
|
1138
|
+
if (selfIdx === -1) {
|
|
1139
|
+
selfCheckIssue = '缺 ## 自检方法 段(须位于 ## 越界检查 之后:文末或紧随越界检查两种合法位置)';
|
|
1140
|
+
} else if (
|
|
1141
|
+
boundsIdx === -1 ||
|
|
1142
|
+
selfIdx < boundsIdx ||
|
|
1143
|
+
(selfIdx !== headings.length - 1 && selfIdx !== boundsIdx + 1)
|
|
1144
|
+
) {
|
|
1145
|
+
selfCheckIssue = '## 自检方法 位置非法(须位于 ## 越界检查 之后:只允许文末或紧随越界检查两种位置)';
|
|
1146
|
+
}
|
|
1147
|
+
return { missingSections, orderIssue, selfCheckIssue };
|
|
1148
|
+
}
|
|
1202
1149
|
|
|
1203
1150
|
// WARN 计数——entry/exit 成功路径末尾输出汇总行(可观测性;追加不改变既有输出)
|
|
1204
1151
|
let __warnCount = 0;
|
|
1205
1152
|
const __origError = console.error;
|
|
1206
1153
|
|
|
1154
|
+
// 协议绑定引导读取:协议决定 statePath,故协议未解析前只能读标准运行时状态文件,仅取
|
|
1155
|
+
// state.protocolPath 用于协议选择;文件缺失/旧 state 缺字段/读取失败 → null(未绑定),由统一
|
|
1156
|
+
// 解析回退 CLI/环境变量/默认协议。不改变后续 statePath 解析与读写语义。
|
|
1157
|
+
async function readPersistedProtocolBinding() {
|
|
1158
|
+
const standardStateFile = path.join(runRoot, ...RUNTIME_STATE_PATH.split('/'));
|
|
1159
|
+
try {
|
|
1160
|
+
if (!(await fileExists(standardStateFile))) return null;
|
|
1161
|
+
const state = await readStateJson(standardStateFile);
|
|
1162
|
+
return state && typeof state === 'object' ? state : null;
|
|
1163
|
+
} catch {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// 协议路径选择(单一权威):显式 --protocol CLI 参数优先;无 CLI 时按 state.protocolPath >
|
|
1169
|
+
// FLOW_COMET_PROTOCOL 环境变量 > 默认解析。state.protocolPath 存在但不可读时 fail-closed
|
|
1170
|
+
// (受保护读取/schema 校验抛错由 main().catch 统一处理)——不静默回退到另一份协议造成门禁按错误
|
|
1171
|
+
// 协议判定。
|
|
1172
|
+
async function resolveGuardProtocolPath() {
|
|
1173
|
+
const cliArgs = process.argv.slice(3);
|
|
1174
|
+
if (hasProtocolCliArg(cliArgs)) {
|
|
1175
|
+
return resolveProtocolPathWithState({ packageRoot, runRoot, cliArgs });
|
|
1176
|
+
}
|
|
1177
|
+
const state = await readPersistedProtocolBinding();
|
|
1178
|
+
return resolveProtocolPathWithState({ packageRoot, runRoot, state });
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1207
1181
|
async function main() {
|
|
1208
1182
|
// 包装 console.error 统计 WARN 输出(转发原实现,行为不变)
|
|
1209
1183
|
console.error = (...args) => {
|
|
1210
1184
|
if (/WARN/.test(args.join(' '))) __warnCount += 1;
|
|
1211
1185
|
__origError(...args);
|
|
1212
1186
|
};
|
|
1213
|
-
// 受保护读取 + fail-closed schema 校验(读失败/校验失败沿用 throw →
|
|
1214
|
-
|
|
1215
|
-
|
|
1187
|
+
// 协议路径选择 + 受保护读取 + fail-closed schema 校验(读失败/校验失败沿用 throw →
|
|
1188
|
+
// main().catch 统一处理;来源为 state.protocolPath 时补充来源与不回退说明)
|
|
1189
|
+
const selectedProtocol = await resolveGuardProtocolPath();
|
|
1190
|
+
protocolPath = selectedProtocol.protocolPath;
|
|
1191
|
+
let protocol;
|
|
1192
|
+
try {
|
|
1193
|
+
protocol = await readProtocolFile(runRoot, protocolPath);
|
|
1194
|
+
validateProtocolSchema(protocol);
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
if (selectedProtocol.source === 'state') {
|
|
1197
|
+
throw new Error('state.protocolPath 指向的协议不可读(' + protocolPath + '):'
|
|
1198
|
+
+ (error && typeof error.message === 'string' ? error.message : String(error))
|
|
1199
|
+
+ '——不回退环境变量/默认协议(回退会按错误协议判定门禁);修正 state.protocolPath 或移除绑定后重试');
|
|
1200
|
+
}
|
|
1201
|
+
throw error;
|
|
1202
|
+
}
|
|
1216
1203
|
if (command === 'verify') {
|
|
1217
1204
|
console.log('workflow-guard-ok');
|
|
1218
1205
|
return;
|
|
@@ -1227,10 +1214,41 @@ async function main() {
|
|
|
1227
1214
|
state.evidence = state.evidence && typeof state.evidence === 'object' ? state.evidence : {};
|
|
1228
1215
|
if (command === 'entry') {
|
|
1229
1216
|
const current = state.currentNode ?? (await nextNode(protocol, state))?.id ?? null;
|
|
1230
|
-
|
|
1217
|
+
// Fix 批次受控归位(共享谓词,唯一受控例外 · ADR-011):review/verify 驻留 + TASK 有
|
|
1218
|
+
// pending 修复任务(串行/并行)或有未闭合家族出口签名时,entry 家族节点(execute /
|
|
1219
|
+
// subagent-execute)归位工作归属并写盘;仅当入口节点与共享谓词目标一致才归位。
|
|
1220
|
+
// 前置 currentNode 校验对该受控例外放行(L-070 实录路径即直接 entry);其余节点/状态行为不变。
|
|
1221
|
+
const fixBatchDecision = EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange
|
|
1222
|
+
? await resolveFixRollbackDecision({
|
|
1223
|
+
runRoot,
|
|
1224
|
+
changeName: state.activeChange,
|
|
1225
|
+
protocol,
|
|
1226
|
+
completedNodes: state.completedNodes,
|
|
1227
|
+
currentNode: state.currentNode,
|
|
1228
|
+
history: state.history,
|
|
1229
|
+
})
|
|
1230
|
+
: null;
|
|
1231
|
+
const fixBatchRollback = !!fixBatchDecision && fixBatchDecision.target === node.id;
|
|
1232
|
+
if (current !== node.id && !state.completedNodes.includes(node.id) && !fixBatchRollback) {
|
|
1231
1233
|
console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
|
|
1232
1234
|
process.exit(1);
|
|
1233
1235
|
}
|
|
1236
|
+
if (fixBatchRollback) {
|
|
1237
|
+
const sourceNode = state.currentNode;
|
|
1238
|
+
// 轮次计数与阈值/授权判定全部走共享 helper:分支②不计数;第 4 轮新 change 先 BLOCK
|
|
1239
|
+
// (此处尚未写盘,满足不写 currentNode),旧 change WARN 后照常归位。
|
|
1240
|
+
const rollbackRound = applyFixRollbackRound({ state, sourceNode, decision: fixBatchDecision });
|
|
1241
|
+
if (rollbackRound.blocked) {
|
|
1242
|
+
console.error(rollbackRound.blockedMessage);
|
|
1243
|
+
process.exit(1);
|
|
1244
|
+
}
|
|
1245
|
+
if (rollbackRound.warn) console.error(rollbackRound.warnMessage);
|
|
1246
|
+
state.currentNode = node.id;
|
|
1247
|
+
console.log('FIX-BATCH: 受控归位 ' + node.id + '(源节点 ' + sourceNode + ')' + rollbackRound.auditSuffix);
|
|
1248
|
+
const bad = validateStateFields(state);
|
|
1249
|
+
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
1250
|
+
await writeJson(file, state);
|
|
1251
|
+
}
|
|
1234
1252
|
// E2: entry archive 分支校验(新模式 branchMode=true)——归档必须在 change/<activeChange> 分支上进行
|
|
1235
1253
|
// 旧模式(无 branchMode 字段 / 非 git 仓库 / git 不可用)跳过,向后兼容
|
|
1236
1254
|
if (node.id === 'archive' && state.branchMode === true && state.activeChange) {
|
|
@@ -1257,7 +1275,7 @@ async function main() {
|
|
|
1257
1275
|
}
|
|
1258
1276
|
}
|
|
1259
1277
|
// C4: 委托前工件 commit 检查——worktree isolation 子代理看不到未提交工件(WARN 不 BLOCKED)
|
|
1260
|
-
if ((node.id
|
|
1278
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1261
1279
|
const { execFileSync } = await import('child_process');
|
|
1262
1280
|
try {
|
|
1263
1281
|
execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: runRoot, stdio: 'pipe' });
|
|
@@ -1281,7 +1299,7 @@ async function main() {
|
|
|
1281
1299
|
}
|
|
1282
1300
|
}
|
|
1283
1301
|
// C3: enter execute / subagent-execute 记录 TASK.md 任务集签名(exit 时比对,防 execute 期间增删任务/改 action/改边界)
|
|
1284
|
-
if ((node.id
|
|
1302
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1285
1303
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1286
1304
|
if (await fileExists(taskFile)) {
|
|
1287
1305
|
try {
|
|
@@ -1295,7 +1313,7 @@ async function main() {
|
|
|
1295
1313
|
// 协调者禁令:execute / subagent-execute 阶段主会话只能委托,禁止直接写源码
|
|
1296
1314
|
// 例外:direct 模式 execute 是主代理直写(逃生口),不输出协调者禁令
|
|
1297
1315
|
const entryExecutionMode = state.executionMode ?? 'subagent';
|
|
1298
|
-
if (
|
|
1316
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1299
1317
|
if (!(entryExecutionMode === 'direct' && node.id === 'execute')) {
|
|
1300
1318
|
console.log('COORDINATOR: 你是协调者,不是执行者。禁止在主会话直接修改源码;只能通过 Agent 工具 worktree isolation 委托子代理;子代理回传后仅更新 TASK.md / SUMMARY / handoff evidence。');
|
|
1301
1319
|
}
|
|
@@ -1356,6 +1374,29 @@ async function main() {
|
|
|
1356
1374
|
process.exit(1);
|
|
1357
1375
|
}
|
|
1358
1376
|
}
|
|
1377
|
+
// FIX-BATCH: 越界拦截——源节点(review/verify)驻留,且 TASK 仍有 pending 修复任务,或修复
|
|
1378
|
+
// 任务已 done 但本批 execute 家族生命周期未闭合(本 change 最新家族出口签名 ≠ 当前任务集签名)
|
|
1379
|
+
// 时,直接 exit 源节点收场会静默跳过 execute 家族生命周期与四类出口(缺陷实录形态)。排在 M1/R2
|
|
1380
|
+
// entry 证据门之前:该越界路径给 Fix 恢复指引,避免通用 entry 提示覆盖更具体的归位路径。
|
|
1381
|
+
// 复用共享回退谓词判定:新 change 强制 BLOCKED 含恢复指引;旧 change 渐进 WARN 不阻断。
|
|
1382
|
+
if ((node.id === 'review' || node.id === 'verify') && state.activeChange) {
|
|
1383
|
+
const fixBatchUnclosed = await resolveFixRollbackState({
|
|
1384
|
+
runRoot,
|
|
1385
|
+
changeName: state.activeChange,
|
|
1386
|
+
protocol,
|
|
1387
|
+
completedNodes: state.completedNodes,
|
|
1388
|
+
currentNode: node.id,
|
|
1389
|
+
history: state.history,
|
|
1390
|
+
});
|
|
1391
|
+
if (fixBatchUnclosed && isNewChange(state)) {
|
|
1392
|
+
console.error('BLOCKED: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合(最近一次 execute 家族 exit 后任务集仍有变更),不能直接 exit ' + node.id + ' 收场(会静默跳过 execute 家族生命周期与四类出口)');
|
|
1393
|
+
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');
|
|
1394
|
+
process.exit(1);
|
|
1395
|
+
}
|
|
1396
|
+
if (fixBatchUnclosed) {
|
|
1397
|
+
console.error('FIX-BATCH WARN: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合,直接 exit ' + node.id + ' 会跳过 execute 家族出口门禁(旧 change 渐进不阻断;建议 next/entry execute 家族节点归位跑完出口后回源节点 exit)');
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1359
1400
|
// M1/R2: enter 证据检测——未 entry 直接 exit:新 change(init 标记)强制 BLOCKED,旧 change 渐进 WARN
|
|
1360
1401
|
// 跳过 entry 会漏掉进入检查(协调者禁令/C4 WORKTREE/PROGRESS/签名记录)
|
|
1361
1402
|
if (isNewChange(state)) {
|
|
@@ -1492,13 +1533,17 @@ async function main() {
|
|
|
1492
1533
|
}
|
|
1493
1534
|
}
|
|
1494
1535
|
// C3: exit execute / subagent-execute 校验 TASK.md 任务集签名未变(status 标记 done 合法已剥离;增删任务/改 action/改边界 BLOCKED)
|
|
1495
|
-
if ((node.id
|
|
1536
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1496
1537
|
if (typeof state.taskHash === 'string' && state.taskHash.length > 0) {
|
|
1497
1538
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1498
1539
|
if (await fileExists(taskFile)) {
|
|
1499
1540
|
try {
|
|
1500
1541
|
const currentHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
1501
|
-
if (
|
|
1542
|
+
if (taskSetSignatureVersionSkew(state.taskHash, currentHash)) {
|
|
1543
|
+
// 跨算法版本不做一致性比对(值不可比),不误拦任务集;要强制一致需重新 entry 重建签名
|
|
1544
|
+
const storedAlgo = parseTaskSetSignature(state.taskHash)?.algo ?? 'unknown';
|
|
1545
|
+
console.error('SIGNATURE-ALGO WARN: state.taskHash 算法版本 ' + storedAlgo + ' 与当前任务集签名版本 ' + TASK_SET_SIGNATURE_ALGO + ' 不同——跨版本不做一致性比对,本轮不阻断;如需强制一致请重新 entry execute 家族节点重建签名');
|
|
1546
|
+
} else if (!sameTaskSetSignature(state.taskHash, currentHash)) {
|
|
1502
1547
|
console.error('BLOCKED: TASK.md 任务集被修改(签名不匹配),execute 期间不允许增删任务/改 action/改边界');
|
|
1503
1548
|
process.exit(1);
|
|
1504
1549
|
}
|
|
@@ -1686,10 +1731,11 @@ async function main() {
|
|
|
1686
1731
|
console.error('BLOCKED: REVIEW.md 内容不足(' + stat.size + ' 字节,需 ≥ 100)');
|
|
1687
1732
|
process.exit(1);
|
|
1688
1733
|
}
|
|
1689
|
-
//
|
|
1734
|
+
// 发现项(含 Minor)须有处置状态标记——[已修](对应 fix 任务)/ [升级](用户决策:
|
|
1690
1735
|
// 接受+理由)/ [转待办](归档时进 KNOWN-ISSUES)。结构级校验,WARN 渐进不 BLOCK:
|
|
1691
1736
|
// 旧 REVIEW 未按新格式写标记只警告不阻断(防旧 REVIEW 卡死),执行者补标记后可消除。
|
|
1692
|
-
const
|
|
1737
|
+
const reviewText = await fs.readFile(reviewFile, 'utf8');
|
|
1738
|
+
const missingDisposition = reviewFindingsMissingDisposition(reviewText);
|
|
1693
1739
|
if (missingDisposition.length > 0) {
|
|
1694
1740
|
if (isNewChange(state)) {
|
|
1695
1741
|
console.error('BLOCKED: REVIEW.md 发现区 ' + missingDisposition.length + ' 项条目缺处置状态标记([已修]/[升级]/[转待办])——新 change 强制每项发现须有处置');
|
|
@@ -1700,6 +1746,21 @@ async function main() {
|
|
|
1700
1746
|
' 项条目缺处置状态标记([已修]/[升级]/[转待办]): ' + missingDisposition.join('、') +
|
|
1701
1747
|
'——未处置的发现(含 Minor)不应无声消失,补标记后本警告消除(渐进不阻断)');
|
|
1702
1748
|
}
|
|
1749
|
+
// Major 延期裁决门禁:Major 的处置是用户决策点——reviewer 不得自行 [转待办]。结构校验:
|
|
1750
|
+
// Major 条目标 [转待办] 时须同时存在用户裁决记录(同段或文末含「用户裁决:接受延期」
|
|
1751
|
+
// 且指向该条目,并由 [升级] 承接);缺失 → 新 change BLOCKED / 旧 change WARN 渐进。
|
|
1752
|
+
// Minor 不受影响;Major [升级]/[已修] 直接放行。
|
|
1753
|
+
const deferredMajor = reviewDeferredMajorProblems(reviewText);
|
|
1754
|
+
if (deferredMajor.length > 0) {
|
|
1755
|
+
const guide = ';恢复: 先把 Major 改为 [升级] 交用户裁决;用户接受延期后在同段或文末记录「用户裁决:接受延期」并指向该条目(由 [升级] 承接)';
|
|
1756
|
+
if (isNewChange(state)) {
|
|
1757
|
+
console.error('BLOCKED: REVIEW.md 发现区 ' + deferredMajor.length + ' 项 Major 条目为 [转待办] 但缺少用户裁决记录(Major 不得由 reviewer 自行转待办): ' + deferredMajor.join('、') + guide);
|
|
1758
|
+
process.exit(1);
|
|
1759
|
+
}
|
|
1760
|
+
console.error('REVIEW WARN: REVIEW.md 发现区 ' + deferredMajor.length +
|
|
1761
|
+
' 项 Major 条目为 [转待办] 但缺少用户裁决记录: ' + deferredMajor.join('、') +
|
|
1762
|
+
'——Major 不得由 reviewer 自行转待办' + guide + '(渐进不阻断)');
|
|
1763
|
+
}
|
|
1703
1764
|
} catch {}
|
|
1704
1765
|
}
|
|
1705
1766
|
// W3: directOverride 授权约束(direct 是用户决策点,不可自决——机制约束)——
|
|
@@ -1707,7 +1768,7 @@ async function main() {
|
|
|
1707
1768
|
// 直显授权态)须存在授权审计记录(directOverrideAt/来源,由 workflow-state execution-mode
|
|
1708
1769
|
// 命令在协调者显式授权时写入)——否则 BLOCKED + 恢复指引(协调者显式授权 / 回 subagent)。
|
|
1709
1770
|
// 旧 state 缺省(directOverride=false / 缺字段)放行(前向兼容——未处于显式 direct 不受影响)。
|
|
1710
|
-
if ((node.id
|
|
1771
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1711
1772
|
const directMode = state.executionMode ?? 'subagent';
|
|
1712
1773
|
if (directMode === 'direct' && state.directOverride === true) {
|
|
1713
1774
|
const hasAuditRecord = typeof state.directOverrideAt === 'string'
|
|
@@ -1720,7 +1781,7 @@ async function main() {
|
|
|
1720
1781
|
}
|
|
1721
1782
|
}
|
|
1722
1783
|
// W1-B: execute / subagent-execute 出口校验每份 SUMMARY 含三个必填段 + 6 维自查非空 + 自检方法
|
|
1723
|
-
if (
|
|
1784
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1724
1785
|
const changeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
1725
1786
|
const violations = await verifySummaries(changeDir);
|
|
1726
1787
|
// brooks-lint 自检方法审计:检查 6 维自查段是否声明了自检方法
|
|
@@ -2008,8 +2069,9 @@ async function main() {
|
|
|
2008
2069
|
for (const [taskId, rec] of Object.entries(results)) {
|
|
2009
2070
|
const r = typeof rec.result === 'object' && rec.result !== null ? rec.result : null;
|
|
2010
2071
|
if (!r) { violations.push(taskId + ' 非 Return Contract(旧格式,缺 completedChecks)'); continue; }
|
|
2011
|
-
// 零提交语义对齐:request 记录 noCommit(write_files
|
|
2012
|
-
//
|
|
2072
|
+
// 零提交语义对齐:request 记录 noCommit(write_files 为空,或全部字面路径可证明被 gitignore)
|
|
2073
|
+
// 的任务无提交可回传,豁免 commitHash 缺失断言(其余契约校验不变)——与 workflow-handoff
|
|
2074
|
+
// 零提交跳过同构
|
|
2013
2075
|
const taskReq = he.handoffRequests ? he.handoffRequests[taskId] : null;
|
|
2014
2076
|
const noCommitTask = !!(taskReq && taskReq.noCommit === true);
|
|
2015
2077
|
if (!r.commitHash && !noCommitTask) violations.push(taskId + ' 缺 commitHash');
|
|
@@ -2172,14 +2234,20 @@ async function main() {
|
|
|
2172
2234
|
// ===== M1: SUMMARY 模板保真(execute / subagent-execute 出口·设计语义 / AC-7)=====
|
|
2173
2235
|
// 每份 *-SUMMARY.md 校 ① 标题首行 # SUMMARY: ② 首部 4 字段(Change ID/Task ID/完成时间/AI 角色)
|
|
2174
2236
|
// ③ 段序(做了什么→改动文件→verify 输出→6 维自查→…→自检方法);宽容匹配(大小写/编号前缀/括号后缀)。
|
|
2175
|
-
//
|
|
2176
|
-
|
|
2237
|
+
// ④ 全骨架存在 + 模板序(骨架从 flow-kit/templates/SUMMARY.md 全部 H2 派生,条件段允许正文 N/A);
|
|
2238
|
+
// ## 自检方法 不在骨架内,单独要求且只允许「文末」「紧随越界检查」两种位置。
|
|
2239
|
+
// 新 change 任一缺失 → BLOCK(含缺失点 + 恢复指引);旧 change/归档批 → WARN 渐进;
|
|
2240
|
+
// 模板缺失(无权威骨架来源)→ 新规则只告警不阻断,保持旧格式渐进。
|
|
2241
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
2177
2242
|
const summaryChangeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
2178
2243
|
const summaryFiles = (await fs.readdir(summaryChangeDir).catch(() => [])).filter((f) => f.endsWith('-SUMMARY.md'));
|
|
2244
|
+
const skeleton = await summaryTemplateSkeleton();
|
|
2179
2245
|
const hardIssues = [];
|
|
2246
|
+
let skeletonGuidanceNeeded = false;
|
|
2180
2247
|
for (const f of summaryFiles) {
|
|
2181
2248
|
try {
|
|
2182
|
-
const
|
|
2249
|
+
const content = await fs.readFile(path.join(summaryChangeDir, f), 'utf8');
|
|
2250
|
+
const fidelity = summaryTemplateFidelity(content);
|
|
2183
2251
|
const problems = [];
|
|
2184
2252
|
if (fidelity.titleMissing) {
|
|
2185
2253
|
problems.push('首行缺 `# SUMMARY: <Task>-<名>` 标题(大小写不敏感,标题可带括号说明后缀)');
|
|
@@ -2202,11 +2270,39 @@ async function main() {
|
|
|
2202
2270
|
'(旧 change/归档批渐进,不阻断;新 change 将强制)');
|
|
2203
2271
|
}
|
|
2204
2272
|
}
|
|
2273
|
+
// ④ 全骨架保真:模板在场时新 change 缺段/乱序/自检位置非法 → BLOCK;
|
|
2274
|
+
// 模板缺失时骨架来自内置兜底,不据此新增阻断(旧格式兼容)。
|
|
2275
|
+
const skeletonFidelity = summarySkeletonFidelity(content, skeleton);
|
|
2276
|
+
const skeletonProblems = [];
|
|
2277
|
+
if (skeletonFidelity.missingSections.length > 0) {
|
|
2278
|
+
skeletonProblems.push('缺段: ' + skeletonFidelity.missingSections.join('、'));
|
|
2279
|
+
}
|
|
2280
|
+
if (skeletonFidelity.orderIssue) {
|
|
2281
|
+
skeletonProblems.push('段序乱(「' + skeletonFidelity.orderIssue.replace(/^##\s*/, '') +
|
|
2282
|
+
'」偏离 flow-kit/templates/SUMMARY.md 的段序)');
|
|
2283
|
+
}
|
|
2284
|
+
if (skeletonFidelity.selfCheckIssue) {
|
|
2285
|
+
skeletonProblems.push(skeletonFidelity.selfCheckIssue);
|
|
2286
|
+
}
|
|
2287
|
+
if (skeletonProblems.length > 0) {
|
|
2288
|
+
if (isNewChange(state) && skeleton.derived) {
|
|
2289
|
+
skeletonGuidanceNeeded = true;
|
|
2290
|
+
hardIssues.push(f + ' SUMMARY 全骨架校验失败: ' + skeletonProblems.join('; '));
|
|
2291
|
+
} else {
|
|
2292
|
+
console.error('SUMMARY TEMPLATE WARN: ' + f + ' ' + skeletonProblems.join('; ') +
|
|
2293
|
+
(skeleton.derived
|
|
2294
|
+
? '(旧 change/归档批渐进,不阻断;新 change 将强制)'
|
|
2295
|
+
: '(模板缺失,按内置骨架提示;不新增阻断)'));
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2205
2298
|
} catch {}
|
|
2206
2299
|
}
|
|
2207
2300
|
if (hardIssues.length > 0) {
|
|
2208
2301
|
console.error('BLOCKED: SUMMARY 模板保真校验失败: ' + hardIssues.join('; '));
|
|
2209
2302
|
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 修正标题/首部/段序(含 flow-comet 增量 ## 自检方法 段)后重试 exit;新 change 强制模板保真');
|
|
2303
|
+
if (skeletonGuidanceNeeded) {
|
|
2304
|
+
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 补齐缺失段的 H2 标题(条件段内容可写 N/A)并按模板顺序排列;## 自检方法 只允许文末或紧随 ## 越界检查 之后两种位置');
|
|
2305
|
+
}
|
|
2210
2306
|
process.exit(1);
|
|
2211
2307
|
}
|
|
2212
2308
|
}
|
|
@@ -2328,6 +2424,9 @@ async function main() {
|
|
|
2328
2424
|
}
|
|
2329
2425
|
if (apply) {
|
|
2330
2426
|
const completed = completedSet(state);
|
|
2427
|
+
// Fix 二次完成信号:exit 的 execute 家族节点在本次 exit 之前已在 completedNodes(首轮 exit
|
|
2428
|
+
// 后再次进入该节点生命周期完成回修)——须在 add 之前捕获,作为回源分支的唯一触发条件。
|
|
2429
|
+
const familyAlreadyCompleted = completed.has(node.id);
|
|
2331
2430
|
completed.add(node.id);
|
|
2332
2431
|
// W2-A: verify exit --apply 成功 → 当前 change 的 verifyFailures 清零
|
|
2333
2432
|
if (node.id === 'verify') setVerifyFailuresFor(state, 0);
|
|
@@ -2336,6 +2435,44 @@ async function main() {
|
|
|
2336
2435
|
const isArchive = node.id === 'archive';
|
|
2337
2436
|
if (isArchive) state.activeChange = null;
|
|
2338
2437
|
let next = isArchive ? null : await nextNode(protocol, state);
|
|
2438
|
+
// FIX-BATCH: exit execute 家族 --apply 受控回程——Fix 二次完成(本节点已在 completedNodes)
|
|
2439
|
+
// 且 TASK 全 done 时,回源节点(execute 后第一个未完成节点且 ∈ review/verify)跑其出口;
|
|
2440
|
+
// 其余情况维持 resolveNextNode 原判定(正常首轮 exit 与多趟中间 exit 零回归)。
|
|
2441
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && familyAlreadyCompleted && state.activeChange) {
|
|
2442
|
+
const fixReturnSource = await resolveFixReturnNode({
|
|
2443
|
+
runRoot,
|
|
2444
|
+
changeName: state.activeChange,
|
|
2445
|
+
protocol,
|
|
2446
|
+
completedNodes: state.completedNodes,
|
|
2447
|
+
});
|
|
2448
|
+
if (fixReturnSource) {
|
|
2449
|
+
next = findNode(protocol, fixReturnSource);
|
|
2450
|
+
// 决策 1/2/4: 回程行分类——只在写本次 exit-applied 事件之前(下方 state.history.push)
|
|
2451
|
+
// 用既有字段派生因果:历史 execute 家族出口签名发散 ∨ TASK 的 Fix 结构标记 → fix;
|
|
2452
|
+
// 有签名且全等 → normal;无签名且无标记 / TASK 不可读 → unknown。分类只决定审计行
|
|
2453
|
+
// 文案;next / currentNode / completedNodes / history 写入仍按既有 resolveFixReturnNode
|
|
2454
|
+
// 无条件覆盖(路由与 state 形状零变化)。协议 TASK 路径与 C3/exitEvent 一致。
|
|
2455
|
+
let fixTaskContent = null;
|
|
2456
|
+
try {
|
|
2457
|
+
fixTaskContent = await fs.readFile(path.join(runRoot, '.specs', state.activeChange, 'TASK.md'), 'utf8');
|
|
2458
|
+
} catch {}
|
|
2459
|
+
const fixReturnCause = fixTaskContent === null
|
|
2460
|
+
? 'unknown'
|
|
2461
|
+
: classifyFixReturnCause({
|
|
2462
|
+
history: state.history,
|
|
2463
|
+
changeName: state.activeChange,
|
|
2464
|
+
taskContent: fixTaskContent,
|
|
2465
|
+
fixSectionTitle: await derivedFixSectionTitle(),
|
|
2466
|
+
});
|
|
2467
|
+
if (fixReturnCause === 'fix') {
|
|
2468
|
+
console.log('FIX-BATCH: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成)');
|
|
2469
|
+
} else if (fixReturnCause === 'normal') {
|
|
2470
|
+
console.log('RETURN: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成;正常多趟收尾,非 Fix 回修)');
|
|
2471
|
+
} else {
|
|
2472
|
+
console.log('RETURN: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成;旧 state 缺闭合/修复证据,未分类)');
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2339
2476
|
// 多趟路由诊断保留(展示层,不并入共享判定):出口推进后下一候选非委托节点时,若任务集存在
|
|
2340
2477
|
// parallel 标记任务与任一 pending 任务但无 pending parallel 可委托块,输出路由诊断提示。
|
|
2341
2478
|
// 静默边界(M4 批次扩展):(a) 全部任务 done 时无 pending 不输出(收尾静默锚);
|
|
@@ -2375,7 +2512,23 @@ async function main() {
|
|
|
2375
2512
|
state.currentNode = isArchive ? null : (next?.id ?? null);
|
|
2376
2513
|
state.status = next ? 'running' : 'completed';
|
|
2377
2514
|
state.history = Array.isArray(state.history) ? state.history : [];
|
|
2378
|
-
|
|
2515
|
+
// 「未闭合 execute 生命周期」信号:exit execute / subagent-execute --apply 把当次 TASK.md
|
|
2516
|
+
// 任务集签名与 change 归属写入 history 事件——源节点直接 exit 时以「本 change 最新家族出口
|
|
2517
|
+
// 签名 ≠ 当前签名」识别 done-but-unclosed 修复批次(lazy entry 只刷新 taskHash、不写本事件,
|
|
2518
|
+
// 因此仍保持未闭合)。change 字段只在家族节点事件上写(其它节点事件形状不变),state.history
|
|
2519
|
+
// 跨 change 保留时用于隔离判定;TASK.md 缺失/不可读时省略签名字段(旧 state 形态 → 渐进放行)。
|
|
2520
|
+
const exitEvent = { event: 'exit-applied', node: node.id, at: new Date().toISOString() };
|
|
2521
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
2522
|
+
exitEvent.change = state.activeChange;
|
|
2523
|
+
const exitTaskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
2524
|
+
try {
|
|
2525
|
+
if (await fileExists(exitTaskFile)) {
|
|
2526
|
+
exitEvent.taskSetSignature = taskSetSignature(await fs.readFile(exitTaskFile, 'utf8'));
|
|
2527
|
+
exitEvent.signatureAlgo = TASK_SET_SIGNATURE_ALGO;
|
|
2528
|
+
}
|
|
2529
|
+
} catch {}
|
|
2530
|
+
}
|
|
2531
|
+
state.history.push(exitEvent);
|
|
2379
2532
|
const bad = validateStateFields(state);
|
|
2380
2533
|
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
2381
2534
|
await writeJson(file, state);
|