flow-comet 1.5.1 → 1.6.1
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/GUIDANCE.md +22 -3
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +40 -3
- package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +3 -3
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +18 -17
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +27 -12
- package/.flow-comet/skills/flow-comet/reference/recovery.md +1 -7
- package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +21 -3
- package/.flow-comet/skills/flow-comet/scripts/contract-check.mjs +41 -31
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +6687 -330
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +25 -5
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +1145 -15
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +72 -3
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +2077 -14
- package/.flow-comet/skills/flow-comet/scripts/task-parsing.mjs +13 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +568 -501
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +331 -14
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +783 -40
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +17 -0
- package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-design/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-dev/SKILL.md +3 -1
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +21 -1
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-open/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +17 -6
- package/.flow-comet/skills/flow-comet-requirement/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-review/SKILL.md +23 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +23 -11
- package/.flow-comet/skills/flow-comet-task/SKILL.md +7 -3
- package/.flow-comet/skills/flow-comet-test/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +21 -4
- package/README.md +45 -115
- 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, analyzeDependencyGraph, findParallelWriteConflicts } 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');
|
|
@@ -699,48 +590,6 @@ function eligibleParallelBlocks(blocks, doneIds) {
|
|
|
699
590
|
});
|
|
700
591
|
}
|
|
701
592
|
|
|
702
|
-
// 依赖图分析:对全部 <task> 块建依赖图(deps 边),Kahn 拓扑排序判环 + 缺失依赖收集。
|
|
703
|
-
// 返回 { ids, depsById, missing: [{id, dep}], cyclic, cycleIds }(cycleIds = 拓扑排序无解的
|
|
704
|
-
// 任务集合,含被环传递拖累的下游任务)。plan 出口波次校验与 subagent-execute 出口孤儿检测
|
|
705
|
-
// 共用同一实现(单一语义:依赖图无环 + 依赖链可满足)。
|
|
706
|
-
function analyzeDependencyGraph(blocks) {
|
|
707
|
-
const parsed = blocks
|
|
708
|
-
.map((block) => ({ block, attrs: taskOpeningAttrs(block) }))
|
|
709
|
-
.filter((x) => x.attrs && x.attrs.id);
|
|
710
|
-
const ids = new Set(parsed.map((x) => x.attrs.id));
|
|
711
|
-
const depsById = new Map();
|
|
712
|
-
const missing = [];
|
|
713
|
-
for (const x of parsed) {
|
|
714
|
-
const deps = [...new Set(taskDependsOn(x.block))];
|
|
715
|
-
depsById.set(x.attrs.id, deps);
|
|
716
|
-
for (const d of deps) {
|
|
717
|
-
if (!ids.has(d)) missing.push({ id: x.attrs.id, dep: d });
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
const indegree = new Map([...ids].map((id) => [id, 0]));
|
|
721
|
-
const dependents = new Map([...ids].map((id) => [id, []]));
|
|
722
|
-
for (const [id, deps] of depsById) {
|
|
723
|
-
for (const d of deps) {
|
|
724
|
-
if (!ids.has(d)) continue;
|
|
725
|
-
indegree.set(id, indegree.get(id) + 1);
|
|
726
|
-
dependents.get(d).push(id);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
let queue = [...ids].filter((id) => indegree.get(id) === 0);
|
|
730
|
-
const sorted = [];
|
|
731
|
-
while (queue.length > 0) {
|
|
732
|
-
const n = queue.shift();
|
|
733
|
-
sorted.push(n);
|
|
734
|
-
for (const m of dependents.get(n)) {
|
|
735
|
-
indegree.set(m, indegree.get(m) - 1);
|
|
736
|
-
if (indegree.get(m) === 0) queue.push(m);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
const cyclic = sorted.length < ids.size;
|
|
740
|
-
const cycleIds = cyclic ? [...ids].filter((id) => !sorted.includes(id)) : [];
|
|
741
|
-
return { ids, depsById, missing, cyclic, cycleIds };
|
|
742
|
-
}
|
|
743
|
-
|
|
744
593
|
function printNext(protocol, node) {
|
|
745
594
|
if (!node) {
|
|
746
595
|
console.log('NEXT: done');
|
|
@@ -816,90 +665,6 @@ function missingRequiredSchemaEvidence(protocol, node, evidence) {
|
|
|
816
665
|
return missing;
|
|
817
666
|
}
|
|
818
667
|
|
|
819
|
-
// 并行文件依赖检测——解析 TASK.md 中本趟可运行的 parallel=pending 任务的 read/write_files 声明,
|
|
820
|
-
// 分两级返回:write∩write(写写绝对冲突,强判)与 read∩write(共享读写嫌疑,弱判——仅对彼此
|
|
821
|
-
// 无显式 depends_on 关联的并行对探测,有显式关联=依赖已声明,跳过→合法拓扑零新增告警)。
|
|
822
|
-
// 路径解析按声明实际内容(换行切分 → 分号二次切分 → trim → 滤空与 HTML 注释),不做扩展名
|
|
823
|
-
// 白名单过滤——txt/log/无扩展名路径同等检出(链式重命名的 .txt 事故面闭合;与既有自动解析
|
|
824
|
-
// 同源实现)。开标签属性解析与 workflow-state 路由共享 taskOpeningAttrs(属性序无关;不读块内文本)。
|
|
825
|
-
async function findParallelWriteConflicts(changeDir) {
|
|
826
|
-
const taskFile = path.join(changeDir, 'TASK.md');
|
|
827
|
-
let text;
|
|
828
|
-
try { text = await fs.readFile(taskFile, 'utf8'); } catch { return { writeConflicts: [], readWarnings: [] }; }
|
|
829
|
-
const allBlocks = extractTaskBlocks(text);
|
|
830
|
-
// 依赖资格收窄:仅统计「本趟可运行」的并行任务——deps ⊆ doneIds;
|
|
831
|
-
// 等待后续趟次的并行任务(依赖未满足)与已交付任务不参与同趟冲突判定,
|
|
832
|
-
// 使 A→B 同写路径的跨趟合法计划不再被首趟误拦(与路由谓词同一口径)。
|
|
833
|
-
const doneIds = new Set(allBlocks
|
|
834
|
-
.map((b) => taskOpeningAttrs(b))
|
|
835
|
-
.filter((a) => a && a.id && a.status === 'done')
|
|
836
|
-
.map((a) => a.id));
|
|
837
|
-
const dependsOnOf = (b) => {
|
|
838
|
-
const m = b.match(/<depends_on>([\s\S]*?)<\/depends_on>/);
|
|
839
|
-
return m ? m[1].trim().split(/[,\s]+/).filter(Boolean) : [];
|
|
840
|
-
};
|
|
841
|
-
const blocks = allBlocks.filter((b) => {
|
|
842
|
-
const a = taskOpeningAttrs(b);
|
|
843
|
-
if (!a || !a.parallel || a.status !== 'pending') return false;
|
|
844
|
-
return dependsOnOf(b).every((d) => doneIds.has(d));
|
|
845
|
-
});
|
|
846
|
-
// 路径解析与既有自动解析同源:剥 HTML 注释 → 换行切分 → 分号二次切分 → trim → 滤空
|
|
847
|
-
// 路径归一化(CodeRabbit 采纳):分隔符统一 '/'、解 '.' 段(`./` / `a/./b`)、`..` 逃出项目根
|
|
848
|
-
// 按越界处理(返回 null 不参与重叠比较)——`src/a.mjs` vs `src/./a.mjs` / `src\a.mjs` 变体不再
|
|
849
|
-
// 绕过写写强判与读写弱判;与委托入口共用同一函数(两侧同语义)。
|
|
850
|
-
const normalizeTaskPath = (raw) => {
|
|
851
|
-
const p = String(raw).trim();
|
|
852
|
-
if (p === '') return null;
|
|
853
|
-
const segments = p.replace(/\\/g, '/').split('/').filter((s) => s !== '' && s !== '.');
|
|
854
|
-
const out = [];
|
|
855
|
-
for (const seg of segments) {
|
|
856
|
-
if (seg === '..') {
|
|
857
|
-
if (out.length === 0) return null; // 逃出项目根 → 越界(不参与比较)
|
|
858
|
-
out.pop();
|
|
859
|
-
} else {
|
|
860
|
-
out.push(seg);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
return out.join('/');
|
|
864
|
-
};
|
|
865
|
-
const parsePaths = (matchText) => String(matchText ?? '')
|
|
866
|
-
.replace(/<!--[\s\S]*?-->/g, '')
|
|
867
|
-
.trim().split(/\s*\n\s*/).map((l) => l.trim()).filter(Boolean)
|
|
868
|
-
.flatMap((l) => l.split(';')).map((l) => l.trim()).filter(Boolean)
|
|
869
|
-
.map(normalizeTaskPath)
|
|
870
|
-
.filter((p) => p !== null && p !== '');
|
|
871
|
-
const perTask = [];
|
|
872
|
-
for (const b of blocks) {
|
|
873
|
-
const a = taskOpeningAttrs(b);
|
|
874
|
-
if (!a || !a.id) continue;
|
|
875
|
-
const wf = b.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
876
|
-
const rf = b.match(/<read_files>([\s\S]*?)<\/read_files>/);
|
|
877
|
-
if (!wf && !rf) continue;
|
|
878
|
-
perTask.push({
|
|
879
|
-
id: a.id,
|
|
880
|
-
deps: new Set(dependsOnOf(b)),
|
|
881
|
-
writes: new Set(parsePaths(wf && wf[1])),
|
|
882
|
-
reads: new Set(parsePaths(rf && rf[1])),
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
const writeConflicts = [];
|
|
886
|
-
const readWarnings = [];
|
|
887
|
-
for (let i = 0; i < perTask.length; i++) {
|
|
888
|
-
for (let j = i + 1; j < perTask.length; j++) {
|
|
889
|
-
const overlap = [...perTask[i].writes].filter((f) => perTask[j].writes.has(f));
|
|
890
|
-
if (overlap.length) writeConflicts.push({ a: perTask[i].id, b: perTask[j].id, files: overlap });
|
|
891
|
-
// 读写弱判触发面:仅无显式 depends_on 关联的并行对(有显式关联=依赖已声明,跳过)
|
|
892
|
-
const associated = perTask[i].deps.has(perTask[j].id) || perTask[j].deps.has(perTask[i].id);
|
|
893
|
-
if (associated) continue;
|
|
894
|
-
const readOverlap = [...perTask[i].reads].filter((f) => perTask[j].writes.has(f));
|
|
895
|
-
if (readOverlap.length) readWarnings.push({ a: perTask[i].id, b: perTask[j].id, files: readOverlap });
|
|
896
|
-
const readOverlap2 = [...perTask[j].reads].filter((f) => perTask[i].writes.has(f));
|
|
897
|
-
if (readOverlap2.length) readWarnings.push({ a: perTask[j].id, b: perTask[i].id, files: readOverlap2 });
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return { writeConflicts, readWarnings };
|
|
901
|
-
}
|
|
902
|
-
|
|
903
668
|
function escapeRegExp(value) {
|
|
904
669
|
return String(value).replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
|
|
905
670
|
}
|
|
@@ -1065,11 +830,12 @@ async function templateSectionPatterns() {
|
|
|
1065
830
|
return templateSectionPatternsCache;
|
|
1066
831
|
}
|
|
1067
832
|
const templateDir = path.join(runRoot, 'flow-kit', 'templates');
|
|
1068
|
-
const result = { change: [], requirement: [], design: [] };
|
|
833
|
+
const result = { change: [], requirement: [], design: [], summary: [] };
|
|
1069
834
|
for (const [key, fileName] of Object.entries({
|
|
1070
835
|
change: 'CHANGE.md',
|
|
1071
836
|
requirement: 'REQUIREMENT.md',
|
|
1072
837
|
design: 'DESIGN.md',
|
|
838
|
+
summary: 'SUMMARY.md',
|
|
1073
839
|
})) {
|
|
1074
840
|
const templateFile = path.join(templateDir, fileName);
|
|
1075
841
|
if (await fileExists(templateFile)) {
|
|
@@ -1093,17 +859,49 @@ async function templateSectionPatterns() {
|
|
|
1093
859
|
return result;
|
|
1094
860
|
}
|
|
1095
861
|
|
|
862
|
+
// Fix 段标题从 <runRoot>/flow-kit/templates/TASK.md 派生(单一模板源 + 模块级缓存 + runRoot 键控):
|
|
863
|
+
// 扫描模板全部 H2,用 route-node 共享 heading 归一(单一权威,含闭合 ATX)识别 Fix 段标题;
|
|
864
|
+
// 无匹配(模板缺失 / 读取失败 / 无 Fix 段)返回 undefined,由回程分类器的内置 fallback 常量兜底。
|
|
865
|
+
// 标题只喂给回程分类器决定审计行(不参与路由/state 写入)。
|
|
866
|
+
// 识别标记词从单一权威 fallback 派生(归一后首词,如 Fix 任务 → Fix),因此模板基名改为其它
|
|
867
|
+
// 语言后缀(如 Fix Tasks)仍可识别;闭合 ATX 与尾部括号变体由共享归一消化。
|
|
868
|
+
const FIX_SECTION_HEADING_MARKER = normalizeHeading(FIX_SECTION_TITLE_FALLBACK).split(/\s+/u)[0];
|
|
869
|
+
|
|
870
|
+
// 模板文本全部 H2 中的 Fix 段标题(无匹配 → undefined):共享归一后与识别标记词比较,
|
|
871
|
+
// 因此语言后缀可变(Fix 任务 / Fix Tasks);闭合 ATX 与尾部括号由共享归一消化。
|
|
872
|
+
function fixSectionTitleFromTemplateText(text) {
|
|
873
|
+
for (const match of String(text).matchAll(/^##\s+(.+)$/gmu)) {
|
|
874
|
+
const raw = match[1].trim();
|
|
875
|
+
const normalized = normalizeHeading(raw);
|
|
876
|
+
if (normalized === FIX_SECTION_HEADING_MARKER
|
|
877
|
+
|| normalized.startsWith(FIX_SECTION_HEADING_MARKER + ' ')) return raw;
|
|
878
|
+
}
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
let fixSectionTitleCacheRoot = null;
|
|
883
|
+
let fixSectionTitleCached = false;
|
|
884
|
+
let fixSectionTitleCache;
|
|
885
|
+
async function derivedFixSectionTitle() {
|
|
886
|
+
if (fixSectionTitleCacheRoot === runRoot && fixSectionTitleCached) return fixSectionTitleCache;
|
|
887
|
+
let title;
|
|
888
|
+
const templateFile = path.join(runRoot, 'flow-kit', 'templates', 'TASK.md');
|
|
889
|
+
if (await fileExists(templateFile)) {
|
|
890
|
+
try {
|
|
891
|
+
title = fixSectionTitleFromTemplateText(await fs.readFile(templateFile, 'utf8'));
|
|
892
|
+
} catch {}
|
|
893
|
+
}
|
|
894
|
+
fixSectionTitleCache = title;
|
|
895
|
+
fixSectionTitleCacheRoot = runRoot;
|
|
896
|
+
fixSectionTitleCached = true;
|
|
897
|
+
return title;
|
|
898
|
+
}
|
|
899
|
+
|
|
1096
900
|
// ===== 模板保真(M1/M2/M3·设计语义 / AC-7~AC-9)=====
|
|
1097
|
-
//
|
|
1098
|
-
//
|
|
901
|
+
// 段名归一化:委托 route-node 共享 heading 归一(单一权威)——去标题标记 / 尾部括号
|
|
902
|
+
// (如 Why(为什么做)→ Why)/ 编号前缀(1. 决策清单 → 决策清单)/ 闭合 ATX,去首尾空白 + 小写。
|
|
1099
903
|
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();
|
|
904
|
+
return normalizeHeading(raw);
|
|
1107
905
|
}
|
|
1108
906
|
|
|
1109
907
|
// 提取文档全部 ^## 段(归一化后),供段序/缺段校验
|
|
@@ -1120,13 +918,23 @@ async function templateSectionPatterns() {
|
|
|
1120
918
|
change: ['why', 'what', '视觉调性', '影响面', '范围排除', '验收线', '风险与未知'],
|
|
1121
919
|
requirement: ['用户故事', '验收准则', '范围切分', '非功能性需求', '依赖与假设'],
|
|
1122
920
|
design: ['技术栈选定', '既有架构对齐', '决策清单', '数据流', '关键状态机', 'adr 索引', '风险', '不在范围', '架构沉淀建议'],
|
|
921
|
+
// SUMMARY 模板缺失时的内置全骨架:十段(含条件段——条件段允许正文 N/A,但 H2 标题须在场)
|
|
922
|
+
summary: ['做了什么', '改动文件', 'verify 输出', '6 维自查', '数据库迁移', '越界检查', '破坏性变更', '决策与偏离', '是否触发新工作', '完成判定'],
|
|
1123
923
|
};
|
|
1124
924
|
|
|
1125
925
|
async function templateSkeleton(key) {
|
|
1126
926
|
const tpl = await templateSectionPatterns(); // 复用 C2 模板缓存(runRoot 内模板)
|
|
1127
927
|
const src = tpl[key] ?? [];
|
|
1128
928
|
if (src.length > 0) return src.map((s) => normalizeTemplateHeading(s.name));
|
|
1129
|
-
return TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? [];
|
|
929
|
+
return (TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? []).map((s) => normalizeTemplateHeading(s));
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// SUMMARY 全骨架来源:模板全部 H2 派生(derived=true);模板缺失/无 H2 → 内置十段兜底
|
|
933
|
+
// (derived=false——调用方据此保持渐进兼容,不新增硬阻断)
|
|
934
|
+
async function summaryTemplateSkeleton() {
|
|
935
|
+
const tpl = await templateSectionPatterns();
|
|
936
|
+
const derived = (tpl.summary ?? []).length > 0;
|
|
937
|
+
return { derived, sections: await templateSkeleton('summary') };
|
|
1130
938
|
}
|
|
1131
939
|
|
|
1132
940
|
// 段序校核(宽容):模板骨架段里「实际出现」的段须按模板先后出现;返回乱序描述(无则 null)
|
|
@@ -1179,40 +987,93 @@ async function templateSectionPatterns() {
|
|
|
1179
987
|
return { titleMissing, headerMissing, orderIssue, missingSections };
|
|
1180
988
|
}
|
|
1181
989
|
|
|
1182
|
-
//
|
|
1183
|
-
//
|
|
1184
|
-
//
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
)
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
990
|
+
// 全骨架保真:骨架来自 SUMMARY 模板全部 H2;每段须存在(条件段内容可写 N/A,但须有 H2 标题),
|
|
991
|
+
// 实际出现的骨架段须按模板先后排列。## 自检方法 不进入骨架,单独校验:须位于 ## 越界检查 之后,
|
|
992
|
+
// 且只允许两种位置——紧随 ## 越界检查 之后(下一段即自检方法)或位于全文末尾(最后一个 H2)。
|
|
993
|
+
function summarySkeletonFidelity(content, skeleton) {
|
|
994
|
+
const text = String(content).replace(/\uFEFF/g, '');
|
|
995
|
+
const headings = documentSectionHeadings(text);
|
|
996
|
+
const seen = new Set();
|
|
997
|
+
for (const h of headings) {
|
|
998
|
+
const idx = skeleton.sections.indexOf(h.norm);
|
|
999
|
+
if (idx !== -1) seen.add(idx);
|
|
1000
|
+
}
|
|
1001
|
+
// 段序复用既有骨架校核(单一实现),段存在性单列——两者共用同一骨架
|
|
1002
|
+
const orderIssue = templateOrderViolation(skeleton.sections, headings);
|
|
1003
|
+
const missingSections = [];
|
|
1004
|
+
for (let i = 0; i < skeleton.sections.length; i++) {
|
|
1005
|
+
if (!seen.has(i)) missingSections.push(skeleton.sections[i]);
|
|
1006
|
+
}
|
|
1007
|
+
const selfHeading = normalizeTemplateHeading('自检方法');
|
|
1008
|
+
const boundsHeading = normalizeTemplateHeading('越界检查');
|
|
1009
|
+
const selfIdx = headings.findIndex((h) => h.norm === selfHeading);
|
|
1010
|
+
const boundsIdx = headings.findIndex((h) => h.norm === boundsHeading);
|
|
1011
|
+
let selfCheckIssue = null;
|
|
1012
|
+
if (selfIdx === -1) {
|
|
1013
|
+
selfCheckIssue = '缺 ## 自检方法 段(须位于 ## 越界检查 之后:文末或紧随越界检查两种合法位置)';
|
|
1014
|
+
} else if (
|
|
1015
|
+
boundsIdx === -1 ||
|
|
1016
|
+
selfIdx < boundsIdx ||
|
|
1017
|
+
(selfIdx !== headings.length - 1 && selfIdx !== boundsIdx + 1)
|
|
1018
|
+
) {
|
|
1019
|
+
selfCheckIssue = '## 自检方法 位置非法(须位于 ## 越界检查 之后:只允许文末或紧随越界检查两种位置)';
|
|
1020
|
+
}
|
|
1021
|
+
return { missingSections, orderIssue, selfCheckIssue };
|
|
1022
|
+
}
|
|
1202
1023
|
|
|
1203
1024
|
// WARN 计数——entry/exit 成功路径末尾输出汇总行(可观测性;追加不改变既有输出)
|
|
1204
1025
|
let __warnCount = 0;
|
|
1205
1026
|
const __origError = console.error;
|
|
1206
1027
|
|
|
1028
|
+
// 协议绑定引导读取:协议决定 statePath,故协议未解析前只能读标准运行时状态文件,仅取
|
|
1029
|
+
// state.protocolPath 用于协议选择;文件缺失/旧 state 缺字段/读取失败 → null(未绑定),由统一
|
|
1030
|
+
// 解析回退 CLI/环境变量/默认协议。不改变后续 statePath 解析与读写语义。
|
|
1031
|
+
async function readPersistedProtocolBinding() {
|
|
1032
|
+
const standardStateFile = path.join(runRoot, ...RUNTIME_STATE_PATH.split('/'));
|
|
1033
|
+
try {
|
|
1034
|
+
if (!(await fileExists(standardStateFile))) return null;
|
|
1035
|
+
const state = await readStateJson(standardStateFile);
|
|
1036
|
+
return state && typeof state === 'object' ? state : null;
|
|
1037
|
+
} catch {
|
|
1038
|
+
return null;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// 协议路径选择(单一权威):显式 --protocol CLI 参数优先;无 CLI 时按 state.protocolPath >
|
|
1043
|
+
// FLOW_COMET_PROTOCOL 环境变量 > 默认解析。state.protocolPath 存在但不可读时 fail-closed
|
|
1044
|
+
// (受保护读取/schema 校验抛错由 main().catch 统一处理)——不静默回退到另一份协议造成门禁按错误
|
|
1045
|
+
// 协议判定。
|
|
1046
|
+
async function resolveGuardProtocolPath() {
|
|
1047
|
+
const cliArgs = process.argv.slice(3);
|
|
1048
|
+
if (hasProtocolCliArg(cliArgs)) {
|
|
1049
|
+
return resolveProtocolPathWithState({ packageRoot, runRoot, cliArgs });
|
|
1050
|
+
}
|
|
1051
|
+
const state = await readPersistedProtocolBinding();
|
|
1052
|
+
return resolveProtocolPathWithState({ packageRoot, runRoot, state });
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1207
1055
|
async function main() {
|
|
1208
1056
|
// 包装 console.error 统计 WARN 输出(转发原实现,行为不变)
|
|
1209
1057
|
console.error = (...args) => {
|
|
1210
1058
|
if (/WARN/.test(args.join(' '))) __warnCount += 1;
|
|
1211
1059
|
__origError(...args);
|
|
1212
1060
|
};
|
|
1213
|
-
// 受保护读取 + fail-closed schema 校验(读失败/校验失败沿用 throw →
|
|
1214
|
-
|
|
1215
|
-
|
|
1061
|
+
// 协议路径选择 + 受保护读取 + fail-closed schema 校验(读失败/校验失败沿用 throw →
|
|
1062
|
+
// main().catch 统一处理;来源为 state.protocolPath 时补充来源与不回退说明)
|
|
1063
|
+
const selectedProtocol = await resolveGuardProtocolPath();
|
|
1064
|
+
protocolPath = selectedProtocol.protocolPath;
|
|
1065
|
+
let protocol;
|
|
1066
|
+
try {
|
|
1067
|
+
protocol = await readProtocolFile(runRoot, protocolPath);
|
|
1068
|
+
validateProtocolSchema(protocol);
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
if (selectedProtocol.source === 'state') {
|
|
1071
|
+
throw new Error('state.protocolPath 指向的协议不可读(' + protocolPath + '):'
|
|
1072
|
+
+ (error && typeof error.message === 'string' ? error.message : String(error))
|
|
1073
|
+
+ '——不回退环境变量/默认协议(回退会按错误协议判定门禁);修正 state.protocolPath 或移除绑定后重试');
|
|
1074
|
+
}
|
|
1075
|
+
throw error;
|
|
1076
|
+
}
|
|
1216
1077
|
if (command === 'verify') {
|
|
1217
1078
|
console.log('workflow-guard-ok');
|
|
1218
1079
|
return;
|
|
@@ -1227,10 +1088,41 @@ async function main() {
|
|
|
1227
1088
|
state.evidence = state.evidence && typeof state.evidence === 'object' ? state.evidence : {};
|
|
1228
1089
|
if (command === 'entry') {
|
|
1229
1090
|
const current = state.currentNode ?? (await nextNode(protocol, state))?.id ?? null;
|
|
1230
|
-
|
|
1091
|
+
// Fix 批次受控归位(共享谓词,唯一受控例外 · ADR-011):review/verify 驻留 + TASK 有
|
|
1092
|
+
// pending 修复任务(串行/并行)或有未闭合家族出口签名时,entry 家族节点(execute /
|
|
1093
|
+
// subagent-execute)归位工作归属并写盘;仅当入口节点与共享谓词目标一致才归位。
|
|
1094
|
+
// 前置 currentNode 校验对该受控例外放行(L-070 实录路径即直接 entry);其余节点/状态行为不变。
|
|
1095
|
+
const fixBatchDecision = EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange
|
|
1096
|
+
? await resolveFixRollbackDecision({
|
|
1097
|
+
runRoot,
|
|
1098
|
+
changeName: state.activeChange,
|
|
1099
|
+
protocol,
|
|
1100
|
+
completedNodes: state.completedNodes,
|
|
1101
|
+
currentNode: state.currentNode,
|
|
1102
|
+
history: state.history,
|
|
1103
|
+
})
|
|
1104
|
+
: null;
|
|
1105
|
+
const fixBatchRollback = !!fixBatchDecision && fixBatchDecision.target === node.id;
|
|
1106
|
+
if (current !== node.id && !state.completedNodes.includes(node.id) && !fixBatchRollback) {
|
|
1231
1107
|
console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
|
|
1232
1108
|
process.exit(1);
|
|
1233
1109
|
}
|
|
1110
|
+
if (fixBatchRollback) {
|
|
1111
|
+
const sourceNode = state.currentNode;
|
|
1112
|
+
// 轮次计数与阈值/授权判定全部走共享 helper:分支②不计数;第 4 轮新 change 先 BLOCK
|
|
1113
|
+
// (此处尚未写盘,满足不写 currentNode),旧 change WARN 后照常归位。
|
|
1114
|
+
const rollbackRound = applyFixRollbackRound({ state, sourceNode, decision: fixBatchDecision });
|
|
1115
|
+
if (rollbackRound.blocked) {
|
|
1116
|
+
console.error(rollbackRound.blockedMessage);
|
|
1117
|
+
process.exit(1);
|
|
1118
|
+
}
|
|
1119
|
+
if (rollbackRound.warn) console.error(rollbackRound.warnMessage);
|
|
1120
|
+
state.currentNode = node.id;
|
|
1121
|
+
console.log('FIX-BATCH: 受控归位 ' + node.id + '(源节点 ' + sourceNode + ')' + rollbackRound.auditSuffix);
|
|
1122
|
+
const bad = validateStateFields(state);
|
|
1123
|
+
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
1124
|
+
await writeJson(file, state);
|
|
1125
|
+
}
|
|
1234
1126
|
// E2: entry archive 分支校验(新模式 branchMode=true)——归档必须在 change/<activeChange> 分支上进行
|
|
1235
1127
|
// 旧模式(无 branchMode 字段 / 非 git 仓库 / git 不可用)跳过,向后兼容
|
|
1236
1128
|
if (node.id === 'archive' && state.branchMode === true && state.activeChange) {
|
|
@@ -1257,7 +1149,7 @@ async function main() {
|
|
|
1257
1149
|
}
|
|
1258
1150
|
}
|
|
1259
1151
|
// C4: 委托前工件 commit 检查——worktree isolation 子代理看不到未提交工件(WARN 不 BLOCKED)
|
|
1260
|
-
if ((node.id
|
|
1152
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1261
1153
|
const { execFileSync } = await import('child_process');
|
|
1262
1154
|
try {
|
|
1263
1155
|
execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: runRoot, stdio: 'pipe' });
|
|
@@ -1281,7 +1173,7 @@ async function main() {
|
|
|
1281
1173
|
}
|
|
1282
1174
|
}
|
|
1283
1175
|
// C3: enter execute / subagent-execute 记录 TASK.md 任务集签名(exit 时比对,防 execute 期间增删任务/改 action/改边界)
|
|
1284
|
-
if ((node.id
|
|
1176
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1285
1177
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1286
1178
|
if (await fileExists(taskFile)) {
|
|
1287
1179
|
try {
|
|
@@ -1295,7 +1187,7 @@ async function main() {
|
|
|
1295
1187
|
// 协调者禁令:execute / subagent-execute 阶段主会话只能委托,禁止直接写源码
|
|
1296
1188
|
// 例外:direct 模式 execute 是主代理直写(逃生口),不输出协调者禁令
|
|
1297
1189
|
const entryExecutionMode = state.executionMode ?? 'subagent';
|
|
1298
|
-
if (
|
|
1190
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1299
1191
|
if (!(entryExecutionMode === 'direct' && node.id === 'execute')) {
|
|
1300
1192
|
console.log('COORDINATOR: 你是协调者,不是执行者。禁止在主会话直接修改源码;只能通过 Agent 工具 worktree isolation 委托子代理;子代理回传后仅更新 TASK.md / SUMMARY / handoff evidence。');
|
|
1301
1193
|
}
|
|
@@ -1356,6 +1248,29 @@ async function main() {
|
|
|
1356
1248
|
process.exit(1);
|
|
1357
1249
|
}
|
|
1358
1250
|
}
|
|
1251
|
+
// FIX-BATCH: 越界拦截——源节点(review/verify)驻留,且 TASK 仍有 pending 修复任务,或修复
|
|
1252
|
+
// 任务已 done 但本批 execute 家族生命周期未闭合(本 change 最新家族出口签名 ≠ 当前任务集签名)
|
|
1253
|
+
// 时,直接 exit 源节点收场会静默跳过 execute 家族生命周期与四类出口(缺陷实录形态)。排在 M1/R2
|
|
1254
|
+
// entry 证据门之前:该越界路径给 Fix 恢复指引,避免通用 entry 提示覆盖更具体的归位路径。
|
|
1255
|
+
// 复用共享回退谓词判定:新 change 强制 BLOCKED 含恢复指引;旧 change 渐进 WARN 不阻断。
|
|
1256
|
+
if ((node.id === 'review' || node.id === 'verify') && state.activeChange) {
|
|
1257
|
+
const fixBatchUnclosed = await resolveFixRollbackState({
|
|
1258
|
+
runRoot,
|
|
1259
|
+
changeName: state.activeChange,
|
|
1260
|
+
protocol,
|
|
1261
|
+
completedNodes: state.completedNodes,
|
|
1262
|
+
currentNode: node.id,
|
|
1263
|
+
history: state.history,
|
|
1264
|
+
});
|
|
1265
|
+
if (fixBatchUnclosed && isNewChange(state)) {
|
|
1266
|
+
console.error('BLOCKED: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合(最近一次 execute 家族 exit 后任务集仍有变更),不能直接 exit ' + node.id + ' 收场(会静默跳过 execute 家族生命周期与四类出口)');
|
|
1267
|
+
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');
|
|
1268
|
+
process.exit(1);
|
|
1269
|
+
}
|
|
1270
|
+
if (fixBatchUnclosed) {
|
|
1271
|
+
console.error('FIX-BATCH WARN: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合,直接 exit ' + node.id + ' 会跳过 execute 家族出口门禁(旧 change 渐进不阻断;建议 next/entry execute 家族节点归位跑完出口后回源节点 exit)');
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1359
1274
|
// M1/R2: enter 证据检测——未 entry 直接 exit:新 change(init 标记)强制 BLOCKED,旧 change 渐进 WARN
|
|
1360
1275
|
// 跳过 entry 会漏掉进入检查(协调者禁令/C4 WORKTREE/PROGRESS/签名记录)
|
|
1361
1276
|
if (isNewChange(state)) {
|
|
@@ -1492,13 +1407,17 @@ async function main() {
|
|
|
1492
1407
|
}
|
|
1493
1408
|
}
|
|
1494
1409
|
// C3: exit execute / subagent-execute 校验 TASK.md 任务集签名未变(status 标记 done 合法已剥离;增删任务/改 action/改边界 BLOCKED)
|
|
1495
|
-
if ((node.id
|
|
1410
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1496
1411
|
if (typeof state.taskHash === 'string' && state.taskHash.length > 0) {
|
|
1497
1412
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1498
1413
|
if (await fileExists(taskFile)) {
|
|
1499
1414
|
try {
|
|
1500
1415
|
const currentHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
1501
|
-
if (
|
|
1416
|
+
if (taskSetSignatureVersionSkew(state.taskHash, currentHash)) {
|
|
1417
|
+
// 跨算法版本不做一致性比对(值不可比),不误拦任务集;要强制一致需重新 entry 重建签名
|
|
1418
|
+
const storedAlgo = parseTaskSetSignature(state.taskHash)?.algo ?? 'unknown';
|
|
1419
|
+
console.error('SIGNATURE-ALGO WARN: state.taskHash 算法版本 ' + storedAlgo + ' 与当前任务集签名版本 ' + TASK_SET_SIGNATURE_ALGO + ' 不同——跨版本不做一致性比对,本轮不阻断;如需强制一致请重新 entry execute 家族节点重建签名');
|
|
1420
|
+
} else if (!sameTaskSetSignature(state.taskHash, currentHash)) {
|
|
1502
1421
|
console.error('BLOCKED: TASK.md 任务集被修改(签名不匹配),execute 期间不允许增删任务/改 action/改边界');
|
|
1503
1422
|
process.exit(1);
|
|
1504
1423
|
}
|
|
@@ -1574,108 +1493,130 @@ async function main() {
|
|
|
1574
1493
|
// plan exit 校验 TASK 含 task 块和 verify 字段
|
|
1575
1494
|
if (node.id === 'plan' && state.activeChange) {
|
|
1576
1495
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
}
|
|
1590
|
-
// 波次散文一致性检测: 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记
|
|
1591
|
-
// (并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务
|
|
1592
|
-
// 标记为准)。容错:无并行语义的 Wave 行不参与比对;解析不到波次段跳过(不误报)。
|
|
1593
|
-
const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|\Z)/);
|
|
1594
|
-
if (waveSection) {
|
|
1595
|
-
const proseParallelIds = [];
|
|
1596
|
-
for (const line of waveSection[1].split('\n')) {
|
|
1597
|
-
if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
|
|
1598
|
-
for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
|
|
1496
|
+
// 读文件是唯一需要容错的动作(TASK.md 缺失 → 无内容可判,判据段不适用,保持既有语义);
|
|
1497
|
+
// 判据段独立成层——判据自身抛错不得被空 catch 吞掉:空 catch 会让整段文件依赖门禁(含既有
|
|
1498
|
+
// 写写强判 BLOCK)静默失效,与「未验证 ≠ 通过」相悖。命中即显式报出原因并按 fail-closed 拒绝。
|
|
1499
|
+
let content = null;
|
|
1500
|
+
try { content = await fs.readFile(taskFile, 'utf8'); } catch { content = null; }
|
|
1501
|
+
if (content !== null) {
|
|
1502
|
+
try {
|
|
1503
|
+
// <task> 块提取与属性解析统一走 task-parsing.mjs(开标签语义,属性序无关)
|
|
1504
|
+
const taskList = extractTaskBlocks(content);
|
|
1505
|
+
if (taskList.length === 0) {
|
|
1506
|
+
console.error('BLOCKED: TASK.md 无 <task> 块');
|
|
1507
|
+
process.exit(1);
|
|
1599
1508
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
.map(b => (taskOpeningAttrs(b) || {}).id)
|
|
1604
|
-
.filter(Boolean);
|
|
1605
|
-
const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
|
|
1606
|
-
if (missing.length > 0) {
|
|
1607
|
-
if (isNewChange(state)) {
|
|
1608
|
-
console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
|
|
1509
|
+
const missingVerify = taskList.filter(b => !/<verify>/.test(b));
|
|
1510
|
+
if (missingVerify.length > 0) {
|
|
1511
|
+
console.error('BLOCKED: TASK.md 中 ' + missingVerify.length + ' 个 task 缺 <verify> 字段');
|
|
1609
1512
|
process.exit(1);
|
|
1610
1513
|
}
|
|
1611
|
-
|
|
1514
|
+
// 波次散文一致性检测: 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记
|
|
1515
|
+
// (并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务
|
|
1516
|
+
// 标记为准)。容错:无并行语义的 Wave 行不参与比对;解析不到波次段跳过(不误报)。
|
|
1517
|
+
const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|\Z)/);
|
|
1518
|
+
if (waveSection) {
|
|
1519
|
+
const proseParallelIds = [];
|
|
1520
|
+
for (const line of waveSection[1].split('\n')) {
|
|
1521
|
+
if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
|
|
1522
|
+
for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
|
|
1523
|
+
}
|
|
1524
|
+
if (proseParallelIds.length > 0) {
|
|
1525
|
+
const xmlParallelIds = taskList
|
|
1526
|
+
.filter(b => { const a = taskOpeningAttrs(b); return a && a.parallel; })
|
|
1527
|
+
.map(b => (taskOpeningAttrs(b) || {}).id)
|
|
1528
|
+
.filter(Boolean);
|
|
1529
|
+
const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
|
|
1530
|
+
if (missing.length > 0) {
|
|
1531
|
+
if (isNewChange(state)) {
|
|
1532
|
+
console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
|
|
1533
|
+
process.exit(1);
|
|
1534
|
+
}
|
|
1535
|
+
console.error('WARN: 波次散文标记为并行([P])但任务无 parallel="true"——散文与任务标记不一致(以任务标记为准): ' + missing.join(', '));
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
// 波次分组校验重定义(依赖图校验决策 · 混排合法化):原「并行块必须单个连续且居首/尾」形态约束废除——
|
|
1540
|
+
// 串行任务位置不再受限,串→并→串 / 并→串→并 / 多波混合均合法(多趟循环路由按依赖拓扑分趟)。
|
|
1541
|
+
// 改为依赖图校验:① 全部任务建依赖图(deps 边)做 Kahn 拓扑排序判环——有环即规划结构性死锁;
|
|
1542
|
+
// ② 全部引用的任务 id 必须存在(无环图下「每个 parallel 任务的全部传递依赖存在且非环」
|
|
1543
|
+
// ⟺ 直接引用都存在)。违规分级:新 change BLOCKED(含「依赖环」/缺失依赖明细 + depends_on
|
|
1544
|
+
// 调整恢复指引);旧 change 渐进 WARN 不阻断。波次散文一致性检测保留不动(与形态约束正交的既有独立检测,维持不变)。
|
|
1545
|
+
const depGraph = analyzeDependencyGraph(taskList);
|
|
1546
|
+
if (depGraph.cyclic || depGraph.missing.length > 0) {
|
|
1547
|
+
const detail = depGraph.cyclic
|
|
1548
|
+
? '依赖环(拓扑排序无解,涉及任务: ' + depGraph.cycleIds.join(', ') + ')'
|
|
1549
|
+
: '依赖不存在的任务: ' + depGraph.missing.map((m) => m.id + '→' + m.dep).join(', ');
|
|
1550
|
+
const guide = ';恢复: 调整任务 depends_on——移除成环引用或改为真实存在的任务 id 后重试';
|
|
1551
|
+
if (isNewChange(state)) {
|
|
1552
|
+
console.error('BLOCKED: TASK.md ' + detail + '——依赖图不可满足(任务的依赖链必须存在且无环)' + guide);
|
|
1553
|
+
process.exit(1);
|
|
1612
1554
|
}
|
|
1555
|
+
console.error('WARN: TASK.md ' + detail + '——依赖图不可满足(旧 change 渐进不阻断)' + guide);
|
|
1613
1556
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1557
|
+
// 伪并行检测(真实载体验证暴露的设计盲区兜底):如果一个标记为并行的任务只写测试文件
|
|
1558
|
+
// 而无任何生产代码文件,它很可能隐式依赖某个实现类并行任务的产出(如测试 import
|
|
1559
|
+
// 尚未存在的函数)。这种"伪并行"在多趟路由下会导致委托后测试失败。
|
|
1560
|
+
// 启发式:并行任务的 write_files 全部匹配 tests/ 或 test_ 前缀 → 视为疑似伪并行。
|
|
1561
|
+
// WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可合法全测试面)。
|
|
1562
|
+
const testOnlyParallelIds = [];
|
|
1563
|
+
for (const block of taskList) {
|
|
1564
|
+
const attrs = taskOpeningAttrs(block);
|
|
1565
|
+
if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
|
|
1566
|
+
const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
1567
|
+
if (!wfMatch) continue;
|
|
1568
|
+
// 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs 同源互锚)——
|
|
1569
|
+
// 换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态不支持,须换行书写)
|
|
1570
|
+
const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
|
|
1571
|
+
const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
|
|
1572
|
+
.flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
|
|
1573
|
+
if (filePaths.length === 0) continue;
|
|
1574
|
+
const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
|
|
1575
|
+
if (prodFiles.length === 0) {
|
|
1576
|
+
testOnlyParallelIds.push(attrs.id || 'unknown');
|
|
1577
|
+
}
|
|
1630
1578
|
}
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
// 尚未存在的函数)。这种"伪并行"在多趟路由下会导致委托后测试失败。
|
|
1636
|
-
// 启发式:并行任务的 write_files 全部匹配 tests/ 或 test_ 前缀 → 视为疑似伪并行。
|
|
1637
|
-
// WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可合法全测试面)。
|
|
1638
|
-
const testOnlyParallelIds = [];
|
|
1639
|
-
for (const block of taskList) {
|
|
1640
|
-
const attrs = taskOpeningAttrs(block);
|
|
1641
|
-
if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
|
|
1642
|
-
const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
1643
|
-
if (!wfMatch) continue;
|
|
1644
|
-
// 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs 同源互锚)——
|
|
1645
|
-
// 换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态不支持,须换行书写)
|
|
1646
|
-
const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
|
|
1647
|
-
const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
|
|
1648
|
-
.flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
|
|
1649
|
-
if (filePaths.length === 0) continue;
|
|
1650
|
-
const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
|
|
1651
|
-
if (prodFiles.length === 0) {
|
|
1652
|
-
testOnlyParallelIds.push(attrs.id || 'unknown');
|
|
1579
|
+
if (testOnlyParallelIds.length > 0) {
|
|
1580
|
+
console.error('WARN: 伪并行检测——以下并行任务仅写测试文件而无生产代码文件: '
|
|
1581
|
+
+ testOnlyParallelIds.join(', ')
|
|
1582
|
+
+ '。测试通常依赖实现产出的符号,可能存在隐式依赖;建议添加 depends_on 声明或合并为垂直切片');
|
|
1653
1583
|
}
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
|
|
1670
|
-
process.exit(1);
|
|
1584
|
+
// 并行文件依赖检测前移(触发面):write∩write 写写强判(新 change BLOCKED / 旧 change
|
|
1585
|
+
// WARN 渐进,与依赖环分级同先例)+ read∩write 读写弱判(仅无显式 depends_on 关联的并行对;
|
|
1586
|
+
// WARN 提示级,新/旧均不 BLOCK——渐进提示)+ 同文件跨任务且无依赖路径(未完成任务写入面
|
|
1587
|
+
// 重叠而两任务间无依赖路径——新 change BLOCKED / 旧 change WARN 渐进;串行拆分同样命中,
|
|
1588
|
+
// 修复任务族不参与,族语义见 route-node 判定块注释)。与委托前既有拦截并存(委托前为第二道
|
|
1589
|
+
// 写写锚,行为与消息保持既有语义不变)。
|
|
1590
|
+
const { writeConflicts, readWarnings, crossTaskConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
|
|
1591
|
+
if (writeConflicts.length > 0) {
|
|
1592
|
+
const detail = writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1593
|
+
const guide = ';恢复: 补显式 depends_on 或拆为串行任务后重试';
|
|
1594
|
+
if (isNewChange(state)) {
|
|
1595
|
+
console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
|
|
1596
|
+
process.exit(1);
|
|
1597
|
+
}
|
|
1598
|
+
console.error('WARN: TASK.md 并行任务 write_files 重叠(写写冲突,建议补显式 depends_on 或拆为串行任务): ' + detail + guide);
|
|
1671
1599
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1600
|
+
if (crossTaskConflicts.length > 0) {
|
|
1601
|
+
const detail = crossTaskConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1602
|
+
const guide = ';恢复: 补显式 depends_on 或合并为一个任务后重试';
|
|
1603
|
+
if (isNewChange(state)) {
|
|
1604
|
+
console.error('BLOCKED: TASK.md 同文件跨任务且无依赖路径: ' + detail + guide);
|
|
1605
|
+
process.exit(1);
|
|
1606
|
+
}
|
|
1607
|
+
console.error('WARN: TASK.md 同文件跨任务且无依赖路径(建议补显式 depends_on 或合并为一个任务): ' + detail + guide);
|
|
1608
|
+
}
|
|
1609
|
+
if (readWarnings.length > 0) {
|
|
1610
|
+
console.error('WARN: TASK.md 并行任务 read∩write 隐式依赖嫌疑(一方读取对方写路径,建议补显式 depends_on 声明): '
|
|
1611
|
+
+ readWarnings.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
|
|
1612
|
+
}
|
|
1613
|
+
} catch (judgeError) {
|
|
1614
|
+
console.error('BLOCKED: TASK.md 文件依赖判据未执行: '
|
|
1615
|
+
+ (judgeError && judgeError.message ? judgeError.message : String(judgeError))
|
|
1616
|
+
+ '——门禁无法完成校验,按 fail-closed 拒绝通过(未验证 ≠ 通过)');
|
|
1617
|
+
process.exit(1);
|
|
1677
1618
|
}
|
|
1678
|
-
}
|
|
1619
|
+
}
|
|
1679
1620
|
}
|
|
1680
1621
|
// review exit 校验 REVIEW 含实质内容 + 发现区条目处置状态结构级校验
|
|
1681
1622
|
if (node.id === 'review' && state.activeChange) {
|
|
@@ -1686,10 +1627,11 @@ async function main() {
|
|
|
1686
1627
|
console.error('BLOCKED: REVIEW.md 内容不足(' + stat.size + ' 字节,需 ≥ 100)');
|
|
1687
1628
|
process.exit(1);
|
|
1688
1629
|
}
|
|
1689
|
-
//
|
|
1630
|
+
// 发现项(含 Minor)须有处置状态标记——[已修](对应 fix 任务)/ [升级](用户决策:
|
|
1690
1631
|
// 接受+理由)/ [转待办](归档时进 KNOWN-ISSUES)。结构级校验,WARN 渐进不 BLOCK:
|
|
1691
1632
|
// 旧 REVIEW 未按新格式写标记只警告不阻断(防旧 REVIEW 卡死),执行者补标记后可消除。
|
|
1692
|
-
const
|
|
1633
|
+
const reviewText = await fs.readFile(reviewFile, 'utf8');
|
|
1634
|
+
const missingDisposition = reviewFindingsMissingDisposition(reviewText);
|
|
1693
1635
|
if (missingDisposition.length > 0) {
|
|
1694
1636
|
if (isNewChange(state)) {
|
|
1695
1637
|
console.error('BLOCKED: REVIEW.md 发现区 ' + missingDisposition.length + ' 项条目缺处置状态标记([已修]/[升级]/[转待办])——新 change 强制每项发现须有处置');
|
|
@@ -1700,6 +1642,21 @@ async function main() {
|
|
|
1700
1642
|
' 项条目缺处置状态标记([已修]/[升级]/[转待办]): ' + missingDisposition.join('、') +
|
|
1701
1643
|
'——未处置的发现(含 Minor)不应无声消失,补标记后本警告消除(渐进不阻断)');
|
|
1702
1644
|
}
|
|
1645
|
+
// Major 延期裁决门禁:Major 的处置是用户决策点——reviewer 不得自行 [转待办]。结构校验:
|
|
1646
|
+
// Major 条目标 [转待办] 时须同时存在用户裁决记录(同段或文末含「用户裁决:接受延期」
|
|
1647
|
+
// 且指向该条目,并由 [升级] 承接);缺失 → 新 change BLOCKED / 旧 change WARN 渐进。
|
|
1648
|
+
// Minor 不受影响;Major [升级]/[已修] 直接放行。
|
|
1649
|
+
const deferredMajor = reviewDeferredMajorProblems(reviewText);
|
|
1650
|
+
if (deferredMajor.length > 0) {
|
|
1651
|
+
const guide = ';恢复: 先把 Major 改为 [升级] 交用户裁决;用户接受延期后在同段或文末记录「用户裁决:接受延期」并指向该条目(由 [升级] 承接)';
|
|
1652
|
+
if (isNewChange(state)) {
|
|
1653
|
+
console.error('BLOCKED: REVIEW.md 发现区 ' + deferredMajor.length + ' 项 Major 条目为 [转待办] 但缺少用户裁决记录(Major 不得由 reviewer 自行转待办): ' + deferredMajor.join('、') + guide);
|
|
1654
|
+
process.exit(1);
|
|
1655
|
+
}
|
|
1656
|
+
console.error('REVIEW WARN: REVIEW.md 发现区 ' + deferredMajor.length +
|
|
1657
|
+
' 项 Major 条目为 [转待办] 但缺少用户裁决记录: ' + deferredMajor.join('、') +
|
|
1658
|
+
'——Major 不得由 reviewer 自行转待办' + guide + '(渐进不阻断)');
|
|
1659
|
+
}
|
|
1703
1660
|
} catch {}
|
|
1704
1661
|
}
|
|
1705
1662
|
// W3: directOverride 授权约束(direct 是用户决策点,不可自决——机制约束)——
|
|
@@ -1707,7 +1664,7 @@ async function main() {
|
|
|
1707
1664
|
// 直显授权态)须存在授权审计记录(directOverrideAt/来源,由 workflow-state execution-mode
|
|
1708
1665
|
// 命令在协调者显式授权时写入)——否则 BLOCKED + 恢复指引(协调者显式授权 / 回 subagent)。
|
|
1709
1666
|
// 旧 state 缺省(directOverride=false / 缺字段)放行(前向兼容——未处于显式 direct 不受影响)。
|
|
1710
|
-
if ((node.id
|
|
1667
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1711
1668
|
const directMode = state.executionMode ?? 'subagent';
|
|
1712
1669
|
if (directMode === 'direct' && state.directOverride === true) {
|
|
1713
1670
|
const hasAuditRecord = typeof state.directOverrideAt === 'string'
|
|
@@ -1720,7 +1677,7 @@ async function main() {
|
|
|
1720
1677
|
}
|
|
1721
1678
|
}
|
|
1722
1679
|
// W1-B: execute / subagent-execute 出口校验每份 SUMMARY 含三个必填段 + 6 维自查非空 + 自检方法
|
|
1723
|
-
if (
|
|
1680
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1724
1681
|
const changeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
1725
1682
|
const violations = await verifySummaries(changeDir);
|
|
1726
1683
|
// brooks-lint 自检方法审计:检查 6 维自查段是否声明了自检方法
|
|
@@ -1790,6 +1747,12 @@ async function main() {
|
|
|
1790
1747
|
process.exit(1);
|
|
1791
1748
|
}
|
|
1792
1749
|
}
|
|
1750
|
+
// execute 出口空退出豁免(M6 收窄)——豁免仅适用于「无任何串行任务」的全并行 change;
|
|
1751
|
+
// 含串行任务(parallel!=="true",缺省串行——与 task-parsing.mjs 同语义)时豁免不生效,
|
|
1752
|
+
// 后续产物校验照常执行(陈旧 emptyExitApproved 不得静默放行)。
|
|
1753
|
+
// 判据单一来源:evidence 谓词只在此处求值一次,execute 出口块与 M6 共用(L-067)。
|
|
1754
|
+
const executeEmptyExitApproved = node.id === 'execute' && !!(state.evidence?.execute?.emptyExitApproved);
|
|
1755
|
+
let executeEmptyExitExempt = false;
|
|
1793
1756
|
// execute 出口校验——统一委托后所有 done 任务需 handoff(越俎代庖检测覆盖串行/并行)
|
|
1794
1757
|
if (node.id === 'execute' && state.activeChange) {
|
|
1795
1758
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
@@ -1806,9 +1769,15 @@ async function main() {
|
|
|
1806
1769
|
// 串行 pending → BLOCKED(execute 任务没做完)——emptyExitApproved 不豁免串行 pending:
|
|
1807
1770
|
// 豁免语义是"全 parallel 无串行可做时空退出";存在未完成串行任务时豁免不应生效
|
|
1808
1771
|
// (防规划错误被豁免掩盖;豁免仅作用于后续产物校验跳过,审计提示保留)
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1772
|
+
if (executeEmptyExitApproved) {
|
|
1773
|
+
// M6 前置条件(收窄):TASK 存在任一串行任务块(parallel!=="true",含缺省)时豁免不生效,
|
|
1774
|
+
// 无论该串行任务 pending 还是 done——陈旧标记不得跳过产物/摘要校验。
|
|
1775
|
+
if (tasks.some(t => !t.parallel)) {
|
|
1776
|
+
console.error('EMPTY-EXIT 未生效:本 change 含串行任务,豁免仅适用于全并行 change');
|
|
1777
|
+
} else {
|
|
1778
|
+
executeEmptyExitExempt = true;
|
|
1779
|
+
console.error('EMPTY-EXIT: execute 空退出豁免已生效(evidence.execute.emptyExitApproved)——审计记录:该 change 在无串行任务时显式豁免空退出');
|
|
1780
|
+
}
|
|
1812
1781
|
}
|
|
1813
1782
|
// serialPending 收窄为「可运行串行」(出口拦截集合收窄):仅 deps ⊆ doneIds 的
|
|
1814
1783
|
// 未完成串行计入拦截——deps 未满足的串行 pending 是等后续波次的合法中间态,放行由多趟
|
|
@@ -2008,8 +1977,9 @@ async function main() {
|
|
|
2008
1977
|
for (const [taskId, rec] of Object.entries(results)) {
|
|
2009
1978
|
const r = typeof rec.result === 'object' && rec.result !== null ? rec.result : null;
|
|
2010
1979
|
if (!r) { violations.push(taskId + ' 非 Return Contract(旧格式,缺 completedChecks)'); continue; }
|
|
2011
|
-
// 零提交语义对齐:request 记录 noCommit(write_files
|
|
2012
|
-
//
|
|
1980
|
+
// 零提交语义对齐:request 记录 noCommit(write_files 为空,或全部字面路径可证明被 gitignore)
|
|
1981
|
+
// 的任务无提交可回传,豁免 commitHash 缺失断言(其余契约校验不变)——与 workflow-handoff
|
|
1982
|
+
// 零提交跳过同构
|
|
2013
1983
|
const taskReq = he.handoffRequests ? he.handoffRequests[taskId] : null;
|
|
2014
1984
|
const noCommitTask = !!(taskReq && taskReq.noCommit === true);
|
|
2015
1985
|
if (!r.commitHash && !noCommitTask) violations.push(taskId + ' 缺 commitHash');
|
|
@@ -2172,14 +2142,20 @@ async function main() {
|
|
|
2172
2142
|
// ===== M1: SUMMARY 模板保真(execute / subagent-execute 出口·设计语义 / AC-7)=====
|
|
2173
2143
|
// 每份 *-SUMMARY.md 校 ① 标题首行 # SUMMARY: ② 首部 4 字段(Change ID/Task ID/完成时间/AI 角色)
|
|
2174
2144
|
// ③ 段序(做了什么→改动文件→verify 输出→6 维自查→…→自检方法);宽容匹配(大小写/编号前缀/括号后缀)。
|
|
2175
|
-
//
|
|
2176
|
-
|
|
2145
|
+
// ④ 全骨架存在 + 模板序(骨架从 flow-kit/templates/SUMMARY.md 全部 H2 派生,条件段允许正文 N/A);
|
|
2146
|
+
// ## 自检方法 不在骨架内,单独要求且只允许「文末」「紧随越界检查」两种位置。
|
|
2147
|
+
// 新 change 任一缺失 → BLOCK(含缺失点 + 恢复指引);旧 change/归档批 → WARN 渐进;
|
|
2148
|
+
// 模板缺失(无权威骨架来源)→ 新规则只告警不阻断,保持旧格式渐进。
|
|
2149
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
2177
2150
|
const summaryChangeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
2178
2151
|
const summaryFiles = (await fs.readdir(summaryChangeDir).catch(() => [])).filter((f) => f.endsWith('-SUMMARY.md'));
|
|
2152
|
+
const skeleton = await summaryTemplateSkeleton();
|
|
2179
2153
|
const hardIssues = [];
|
|
2154
|
+
let skeletonGuidanceNeeded = false;
|
|
2180
2155
|
for (const f of summaryFiles) {
|
|
2181
2156
|
try {
|
|
2182
|
-
const
|
|
2157
|
+
const content = await fs.readFile(path.join(summaryChangeDir, f), 'utf8');
|
|
2158
|
+
const fidelity = summaryTemplateFidelity(content);
|
|
2183
2159
|
const problems = [];
|
|
2184
2160
|
if (fidelity.titleMissing) {
|
|
2185
2161
|
problems.push('首行缺 `# SUMMARY: <Task>-<名>` 标题(大小写不敏感,标题可带括号说明后缀)');
|
|
@@ -2202,11 +2178,39 @@ async function main() {
|
|
|
2202
2178
|
'(旧 change/归档批渐进,不阻断;新 change 将强制)');
|
|
2203
2179
|
}
|
|
2204
2180
|
}
|
|
2181
|
+
// ④ 全骨架保真:模板在场时新 change 缺段/乱序/自检位置非法 → BLOCK;
|
|
2182
|
+
// 模板缺失时骨架来自内置兜底,不据此新增阻断(旧格式兼容)。
|
|
2183
|
+
const skeletonFidelity = summarySkeletonFidelity(content, skeleton);
|
|
2184
|
+
const skeletonProblems = [];
|
|
2185
|
+
if (skeletonFidelity.missingSections.length > 0) {
|
|
2186
|
+
skeletonProblems.push('缺段: ' + skeletonFidelity.missingSections.join('、'));
|
|
2187
|
+
}
|
|
2188
|
+
if (skeletonFidelity.orderIssue) {
|
|
2189
|
+
skeletonProblems.push('段序乱(「' + skeletonFidelity.orderIssue.replace(/^##\s*/, '') +
|
|
2190
|
+
'」偏离 flow-kit/templates/SUMMARY.md 的段序)');
|
|
2191
|
+
}
|
|
2192
|
+
if (skeletonFidelity.selfCheckIssue) {
|
|
2193
|
+
skeletonProblems.push(skeletonFidelity.selfCheckIssue);
|
|
2194
|
+
}
|
|
2195
|
+
if (skeletonProblems.length > 0) {
|
|
2196
|
+
if (isNewChange(state) && skeleton.derived) {
|
|
2197
|
+
skeletonGuidanceNeeded = true;
|
|
2198
|
+
hardIssues.push(f + ' SUMMARY 全骨架校验失败: ' + skeletonProblems.join('; '));
|
|
2199
|
+
} else {
|
|
2200
|
+
console.error('SUMMARY TEMPLATE WARN: ' + f + ' ' + skeletonProblems.join('; ') +
|
|
2201
|
+
(skeleton.derived
|
|
2202
|
+
? '(旧 change/归档批渐进,不阻断;新 change 将强制)'
|
|
2203
|
+
: '(模板缺失,按内置骨架提示;不新增阻断)'));
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2205
2206
|
} catch {}
|
|
2206
2207
|
}
|
|
2207
2208
|
if (hardIssues.length > 0) {
|
|
2208
2209
|
console.error('BLOCKED: SUMMARY 模板保真校验失败: ' + hardIssues.join('; '));
|
|
2209
2210
|
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 修正标题/首部/段序(含 flow-comet 增量 ## 自检方法 段)后重试 exit;新 change 强制模板保真');
|
|
2211
|
+
if (skeletonGuidanceNeeded) {
|
|
2212
|
+
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 补齐缺失段的 H2 标题(条件段内容可写 N/A)并按模板顺序排列;## 自检方法 只允许文末或紧随 ## 越界检查 之后两种位置');
|
|
2213
|
+
}
|
|
2210
2214
|
process.exit(1);
|
|
2211
2215
|
}
|
|
2212
2216
|
}
|
|
@@ -2309,9 +2313,15 @@ async function main() {
|
|
|
2309
2313
|
console.error('BLOCKED: missing Output Schema evidence: ' + missingSchemaEvidence.join(', '));
|
|
2310
2314
|
process.exit(1);
|
|
2311
2315
|
}
|
|
2312
|
-
// M6: execute
|
|
2313
|
-
|
|
2314
|
-
|
|
2316
|
+
// M6: execute 显式空退出豁免——仅当豁免活性成立(executeEmptyExitApproved 且 TASK 无任何
|
|
2317
|
+
// 串行任务)时跳过产物校验(全 parallel 无 SUMMARY 属预期);含串行任务的 change 豁免不生效,
|
|
2318
|
+
// 照常校验,不得静默放行。生效时追加被跳过项清单(EMPTY-EXIT-SKIPPED)。
|
|
2319
|
+
const checkedArtifacts = await missingRequiredArtifacts(protocol, node, state.activeChange);
|
|
2320
|
+
let missingArtifacts = checkedArtifacts;
|
|
2321
|
+
if (executeEmptyExitApproved && executeEmptyExitExempt) {
|
|
2322
|
+
console.error('EMPTY-EXIT-SKIPPED: ' + (checkedArtifacts.length > 0 ? checkedArtifacts.join(', ') : '(无缺失产物项)'));
|
|
2323
|
+
missingArtifacts = [];
|
|
2324
|
+
}
|
|
2315
2325
|
if (missingArtifacts.length > 0) {
|
|
2316
2326
|
console.error('BLOCKED: missing Output Schema artifacts: ' + missingArtifacts.join(', '));
|
|
2317
2327
|
process.exit(1);
|
|
@@ -2328,6 +2338,9 @@ async function main() {
|
|
|
2328
2338
|
}
|
|
2329
2339
|
if (apply) {
|
|
2330
2340
|
const completed = completedSet(state);
|
|
2341
|
+
// Fix 二次完成信号:exit 的 execute 家族节点在本次 exit 之前已在 completedNodes(首轮 exit
|
|
2342
|
+
// 后再次进入该节点生命周期完成回修)——须在 add 之前捕获,作为回源分支的唯一触发条件。
|
|
2343
|
+
const familyAlreadyCompleted = completed.has(node.id);
|
|
2331
2344
|
completed.add(node.id);
|
|
2332
2345
|
// W2-A: verify exit --apply 成功 → 当前 change 的 verifyFailures 清零
|
|
2333
2346
|
if (node.id === 'verify') setVerifyFailuresFor(state, 0);
|
|
@@ -2336,6 +2349,44 @@ async function main() {
|
|
|
2336
2349
|
const isArchive = node.id === 'archive';
|
|
2337
2350
|
if (isArchive) state.activeChange = null;
|
|
2338
2351
|
let next = isArchive ? null : await nextNode(protocol, state);
|
|
2352
|
+
// FIX-BATCH: exit execute 家族 --apply 受控回程——Fix 二次完成(本节点已在 completedNodes)
|
|
2353
|
+
// 且 TASK 全 done 时,回源节点(execute 后第一个未完成节点且 ∈ review/verify)跑其出口;
|
|
2354
|
+
// 其余情况维持 resolveNextNode 原判定(正常首轮 exit 与多趟中间 exit 零回归)。
|
|
2355
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && familyAlreadyCompleted && state.activeChange) {
|
|
2356
|
+
const fixReturnSource = await resolveFixReturnNode({
|
|
2357
|
+
runRoot,
|
|
2358
|
+
changeName: state.activeChange,
|
|
2359
|
+
protocol,
|
|
2360
|
+
completedNodes: state.completedNodes,
|
|
2361
|
+
});
|
|
2362
|
+
if (fixReturnSource) {
|
|
2363
|
+
next = findNode(protocol, fixReturnSource);
|
|
2364
|
+
// 决策 1/2/4: 回程行分类——只在写本次 exit-applied 事件之前(下方 state.history.push)
|
|
2365
|
+
// 用既有字段派生因果:历史 execute 家族出口签名发散 ∨ TASK 的 Fix 结构标记 → fix;
|
|
2366
|
+
// 有签名且全等 → normal;无签名且无标记 / TASK 不可读 → unknown。分类只决定审计行
|
|
2367
|
+
// 文案;next / currentNode / completedNodes / history 写入仍按既有 resolveFixReturnNode
|
|
2368
|
+
// 无条件覆盖(路由与 state 形状零变化)。协议 TASK 路径与 C3/exitEvent 一致。
|
|
2369
|
+
let fixTaskContent = null;
|
|
2370
|
+
try {
|
|
2371
|
+
fixTaskContent = await fs.readFile(path.join(runRoot, '.specs', state.activeChange, 'TASK.md'), 'utf8');
|
|
2372
|
+
} catch {}
|
|
2373
|
+
const fixReturnCause = fixTaskContent === null
|
|
2374
|
+
? 'unknown'
|
|
2375
|
+
: classifyFixReturnCause({
|
|
2376
|
+
history: state.history,
|
|
2377
|
+
changeName: state.activeChange,
|
|
2378
|
+
taskContent: fixTaskContent,
|
|
2379
|
+
fixSectionTitle: await derivedFixSectionTitle(),
|
|
2380
|
+
});
|
|
2381
|
+
if (fixReturnCause === 'fix') {
|
|
2382
|
+
console.log('FIX-BATCH: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成)');
|
|
2383
|
+
} else if (fixReturnCause === 'normal') {
|
|
2384
|
+
console.log('RETURN: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成;正常多趟收尾,非 Fix 回修)');
|
|
2385
|
+
} else {
|
|
2386
|
+
console.log('RETURN: 回源节点 ' + fixReturnSource + '(' + node.id + ' 出口已完成;旧 state 缺闭合/修复证据,未分类)');
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2339
2390
|
// 多趟路由诊断保留(展示层,不并入共享判定):出口推进后下一候选非委托节点时,若任务集存在
|
|
2340
2391
|
// parallel 标记任务与任一 pending 任务但无 pending parallel 可委托块,输出路由诊断提示。
|
|
2341
2392
|
// 静默边界(M4 批次扩展):(a) 全部任务 done 时无 pending 不输出(收尾静默锚);
|
|
@@ -2375,7 +2426,23 @@ async function main() {
|
|
|
2375
2426
|
state.currentNode = isArchive ? null : (next?.id ?? null);
|
|
2376
2427
|
state.status = next ? 'running' : 'completed';
|
|
2377
2428
|
state.history = Array.isArray(state.history) ? state.history : [];
|
|
2378
|
-
|
|
2429
|
+
// 「未闭合 execute 生命周期」信号:exit execute / subagent-execute --apply 把当次 TASK.md
|
|
2430
|
+
// 任务集签名与 change 归属写入 history 事件——源节点直接 exit 时以「本 change 最新家族出口
|
|
2431
|
+
// 签名 ≠ 当前签名」识别 done-but-unclosed 修复批次(lazy entry 只刷新 taskHash、不写本事件,
|
|
2432
|
+
// 因此仍保持未闭合)。change 字段只在家族节点事件上写(其它节点事件形状不变),state.history
|
|
2433
|
+
// 跨 change 保留时用于隔离判定;TASK.md 缺失/不可读时省略签名字段(旧 state 形态 → 渐进放行)。
|
|
2434
|
+
const exitEvent = { event: 'exit-applied', node: node.id, at: new Date().toISOString() };
|
|
2435
|
+
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
2436
|
+
exitEvent.change = state.activeChange;
|
|
2437
|
+
const exitTaskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
2438
|
+
try {
|
|
2439
|
+
if (await fileExists(exitTaskFile)) {
|
|
2440
|
+
exitEvent.taskSetSignature = taskSetSignature(await fs.readFile(exitTaskFile, 'utf8'));
|
|
2441
|
+
exitEvent.signatureAlgo = TASK_SET_SIGNATURE_ALGO;
|
|
2442
|
+
}
|
|
2443
|
+
} catch {}
|
|
2444
|
+
}
|
|
2445
|
+
state.history.push(exitEvent);
|
|
2379
2446
|
const bad = validateStateFields(state);
|
|
2380
2447
|
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
2381
2448
|
await writeJson(file, state);
|