flow-comet 1.6.3 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +11 -13
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -18878
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +72 -1123
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -7559
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2476
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +5 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +27 -2190
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/README.md +52 -69
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +119 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +21 -1313
|
@@ -1,1171 +1,88 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// 节点门禁入口:CLI + 分派 + 编排 + 收口。
|
|
3
|
+
//
|
|
4
|
+
// 本文件只做三件事——解析命令行参数、按命令分派、按固定顺序调用门禁模块并收口输出与退出码;
|
|
5
|
+
// 判据实现一律落 lib/guard-*.mjs(入口零内联副本)。协议路径解析在此完成(state.protocolPath
|
|
6
|
+
// 需先读标准运行时状态文件引导,协议决定 statePath 时存在先后次序)。
|
|
7
|
+
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
3
9
|
import path from 'path';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
import {
|
|
11
|
+
RUNTIME_STATE_PATH,
|
|
12
|
+
hasProtocolCliArg,
|
|
13
|
+
resolveProtocolPathWithState,
|
|
14
|
+
setVerifyFailuresFor,
|
|
15
|
+
validateStateFields,
|
|
16
|
+
} from './state-schema.mjs';
|
|
17
|
+
import { readProtocolFile, validateProtocolSchema } from './protocol-utils.mjs';
|
|
18
|
+
import {
|
|
19
|
+
EXECUTE_FAMILY_NODE_IDS,
|
|
20
|
+
TASK_SET_SIGNATURE_ALGO,
|
|
21
|
+
classifyFixReturnCause,
|
|
22
|
+
resolveFixReturnNode,
|
|
23
|
+
taskSetSignature,
|
|
24
|
+
} from './route-node.mjs';
|
|
25
|
+
import { taskBlocks as extractTaskBlocks, taskOpeningAttrs } from './task-parsing.mjs';
|
|
26
|
+
import {
|
|
27
|
+
fileExists,
|
|
28
|
+
packageRoot,
|
|
29
|
+
readStateJson,
|
|
30
|
+
runRoot,
|
|
31
|
+
setProtocolPath,
|
|
32
|
+
statePath,
|
|
33
|
+
writeJson,
|
|
34
|
+
} from './lib/guard-state-io.mjs';
|
|
35
|
+
import {
|
|
36
|
+
completedSet,
|
|
37
|
+
derivedFixSectionTitle,
|
|
38
|
+
findNode,
|
|
39
|
+
nextNode,
|
|
40
|
+
printNext,
|
|
41
|
+
route,
|
|
42
|
+
} from './lib/guard-routing.mjs';
|
|
43
|
+
import { checkUiDesignArtifact } from './lib/guard-uidesign.mjs';
|
|
44
|
+
import {
|
|
45
|
+
runIntakeDocFidelityGate,
|
|
46
|
+
runSummaryTemplateFidelityGate,
|
|
47
|
+
runTaskSevenFieldGate,
|
|
48
|
+
} from './lib/guard-template-fidelity.mjs';
|
|
49
|
+
import {
|
|
50
|
+
requireNodeEvidence,
|
|
51
|
+
runArchiveBranchMergeGate,
|
|
52
|
+
runArchiveLogOrderGate,
|
|
53
|
+
runContextAppendGate,
|
|
54
|
+
runDesignDecisionListGate,
|
|
55
|
+
runDesignStackGate,
|
|
56
|
+
runEntryGates,
|
|
57
|
+
runEntryRecordGate,
|
|
58
|
+
runExitDriftGate,
|
|
59
|
+
runFixBatchExitGate,
|
|
60
|
+
runLessonsZoneGate,
|
|
61
|
+
runOpenRequiredSectionsGate,
|
|
62
|
+
runPlanExitGate,
|
|
63
|
+
runRequirementAcGate,
|
|
64
|
+
runReviewExitGate,
|
|
65
|
+
runSkillLoadMarkerGate,
|
|
66
|
+
runTaskSetSignatureExitGate,
|
|
67
|
+
runTransitionEvidenceGate,
|
|
68
|
+
} from './lib/guard-gates.mjs';
|
|
69
|
+
import {
|
|
70
|
+
runArtifactGate,
|
|
71
|
+
runDirectOverrideGate,
|
|
72
|
+
runEvidenceCompletionGate,
|
|
73
|
+
runExecuteExitGate,
|
|
74
|
+
runInFlightHandoffGate,
|
|
75
|
+
runMultiPassCompletionGate,
|
|
76
|
+
runRequiredEvidenceGate,
|
|
77
|
+
runReturnContractGate,
|
|
78
|
+
runSubagentSummaryGate,
|
|
79
|
+
runSummarySectionsGate,
|
|
80
|
+
runVerifyExitGate,
|
|
81
|
+
} from './lib/guard-evidence-gates.mjs';
|
|
9
82
|
|
|
10
83
|
const command = process.argv[2] ?? 'verify';
|
|
11
84
|
const nodeId = process.argv[3] ?? null;
|
|
12
85
|
const apply = process.argv.includes('--apply');
|
|
13
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
const packageRoot = path.resolve(__dirname, '..');
|
|
15
|
-
const runRoot = process.env.FLOW_COMET_RUN_ROOT ? path.resolve(process.env.FLOW_COMET_RUN_ROOT) : process.cwd();
|
|
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;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const WORKFLOW_PROJECT_FILE_MAX_BYTES = 2 * 1024 * 1024;
|
|
24
|
-
|
|
25
|
-
// W1-A: 节点 → 合法 exit 的前置条件(对齐 flow-kit 阶段门 + flowkit.*.v1 evidence)
|
|
26
|
-
const NODE_TRANSITION_GATES = {
|
|
27
|
-
open: { evidence: ['intake-summary'] },
|
|
28
|
-
design: { evidence: ['design-summary'] },
|
|
29
|
-
plan: { evidence: ['plan-summary'] },
|
|
30
|
-
execute: { evidence: ['implementation-summary'] },
|
|
31
|
-
'subagent-execute':{ evidence: ['handoff-result'] },
|
|
32
|
-
review: { evidence: ['review-summary'] },
|
|
33
|
-
verify: { evidence: ['verification-result'] },
|
|
34
|
-
archive: { evidence: ['archive-summary'] },
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// 节点协议映射(单一来源): NODE_PROTOCOL_FILES 已移入 protocol-utils.mjs(exit 协议声明校验 + record 自动补声明共用)
|
|
38
|
-
|
|
39
|
-
// 声明标记 protocol → basename 提取(exit 校验与 节点协议映射表 basename 精确比对)。
|
|
40
|
-
// 兼容新旧两种格式:新格式(skill-load 写入)= 纯 basename(如 0-change.md),原样返回;
|
|
41
|
-
// 旧格式(缺陷修复前写入)= resolveProtocol 解析后的完整绝对路径(Windows 反斜杠 /
|
|
42
|
-
// POSIX 斜杠),提取最后一段后可比对。非字符串(null——skill-load 未传 --protocol 的
|
|
43
|
-
// 新格式缺省)→ null(协议集内无 null,fail-closed 由 includes 比对兜底)。
|
|
44
|
-
// R6: 新旧 change 区分——init 写入的 newChange: true = 新 change(严格,不依赖 entry——防系统性
|
|
45
|
-
// 跳 entry 绕过);缺失/非 true(旧 change) = 渐进 WARN 兼容。供 R1/R2 升级与 M 机制使用。
|
|
46
|
-
function isNewChange(state) {
|
|
47
|
-
return state.newChange === true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function markerProtocolBasename(value) {
|
|
51
|
-
if (typeof value !== 'string' || value === '') return null;
|
|
52
|
-
return String(value).replaceAll('\\', '/').split('/').pop() || null;
|
|
53
|
-
}
|
|
54
|
-
|
|
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;
|
|
97
|
-
}
|
|
98
|
-
if (current) {
|
|
99
|
-
if (line.trim() === '') pushCurrent();
|
|
100
|
-
else current.lines.push(line);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
pushCurrent();
|
|
104
|
-
items.forEach((item, i) => { item.ordinal = i + 1; });
|
|
105
|
-
return items;
|
|
106
|
-
}
|
|
107
|
-
|
|
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);
|
|
122
|
-
}
|
|
123
|
-
|
|
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);
|
|
133
|
-
}
|
|
134
|
-
|
|
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;
|
|
161
|
-
}
|
|
162
|
-
|
|
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
|
-
];
|
|
169
|
-
|
|
170
|
-
// 受保护读取 / 文件身份比较 / 路径包含与逐段扫描判据的单一权威在 protocol-utils.mjs
|
|
171
|
-
// (readWorkflowProtectedFile / workflowFileObjectIdentity / workflowSameFileObject /
|
|
172
|
-
// workflowSameFileStat / workflowPathInside / inspectWorkflowProtectedPath),本文件不再保留
|
|
173
|
-
// 本地副本:同一判据两份实现会静默分叉,注释互指同源不是同步机制。错误语义(越界 / 非真实根 /
|
|
174
|
-
// symlink 或 junction / 类型不符 / 物理逃逸 / 读取期间身份漂移的抛错文案与 fail-closed 行为)
|
|
175
|
-
// 由该单一实现统一保证。
|
|
176
|
-
|
|
177
|
-
function workflowRelativeSegments(value, label, allowWildcards = false) {
|
|
178
|
-
if (typeof value !== 'string') throw new Error(label + ' must be a string');
|
|
179
|
-
const trimmed = value.trim().replaceAll('\\', '/');
|
|
180
|
-
if (
|
|
181
|
-
trimmed.length === 0 ||
|
|
182
|
-
path.posix.isAbsolute(trimmed) ||
|
|
183
|
-
path.win32.isAbsolute(trimmed) ||
|
|
184
|
-
trimmed.startsWith('~') ||
|
|
185
|
-
trimmed.startsWith('/') ||
|
|
186
|
-
trimmed.startsWith('\\')
|
|
187
|
-
) {
|
|
188
|
-
throw new Error(label + ' must be relative to its declared path base');
|
|
189
|
-
}
|
|
190
|
-
const segments = trimmed.split('/');
|
|
191
|
-
if (segments.some((segment) => segment === '..')) {
|
|
192
|
-
const boundary = label === 'workflow-run statePath' ? 'the project root' : 'its declared path base';
|
|
193
|
-
throw new Error(label + ' must stay inside ' + boundary);
|
|
194
|
-
}
|
|
195
|
-
if (segments.some((segment) => segment === '' || segment === '.')) {
|
|
196
|
-
throw new Error(label + ' must not contain empty or dot path segments');
|
|
197
|
-
}
|
|
198
|
-
if (!allowWildcards && (trimmed.includes('*') || trimmed.includes('?'))) {
|
|
199
|
-
throw new Error(label + ' cannot contain wildcards');
|
|
200
|
-
}
|
|
201
|
-
return segments;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function resolveWorkflowRelativePath(base, value, label, allowWildcards = false) {
|
|
205
|
-
const segments = workflowRelativeSegments(value, label, allowWildcards);
|
|
206
|
-
const target = path.resolve(base, ...segments);
|
|
207
|
-
const relative = path.relative(path.resolve(base), target);
|
|
208
|
-
if (
|
|
209
|
-
path.isAbsolute(relative) ||
|
|
210
|
-
relative === '..' ||
|
|
211
|
-
relative.startsWith('..' + path.sep)
|
|
212
|
-
) {
|
|
213
|
-
const boundary = label === 'workflow-run statePath' ? 'the project root' : 'its declared path base';
|
|
214
|
-
throw new Error(label + ' must stay inside ' + boundary);
|
|
215
|
-
}
|
|
216
|
-
return { target, segments };
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
async function workflowProtectedDirectorySnapshot(projectRoot, directory, label) {
|
|
221
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
222
|
-
projectRoot,
|
|
223
|
-
directory,
|
|
224
|
-
label,
|
|
225
|
-
'directory',
|
|
226
|
-
);
|
|
227
|
-
if (!inspection.exists) {
|
|
228
|
-
throw new Error(label + ' does not exist');
|
|
229
|
-
}
|
|
230
|
-
const stat = await fs.lstat(directory, { bigint: true });
|
|
231
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
232
|
-
throw new Error(label + ' must be a real directory');
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
stat,
|
|
236
|
-
realPath: await fs.realpath(directory),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async function assertWorkflowProtectedDirectorySnapshot(
|
|
241
|
-
projectRoot,
|
|
242
|
-
directory,
|
|
243
|
-
label,
|
|
244
|
-
expected,
|
|
245
|
-
) {
|
|
246
|
-
const actual = await workflowProtectedDirectorySnapshot(
|
|
247
|
-
projectRoot,
|
|
248
|
-
directory,
|
|
249
|
-
label,
|
|
250
|
-
);
|
|
251
|
-
if (
|
|
252
|
-
actual.realPath !== expected.realPath ||
|
|
253
|
-
!workflowSameFileObject(
|
|
254
|
-
workflowFileObjectIdentity(actual.stat),
|
|
255
|
-
workflowFileObjectIdentity(expected.stat),
|
|
256
|
-
)
|
|
257
|
-
) {
|
|
258
|
-
throw new Error(label + ' changed before commit');
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async function ensureWorkflowProtectedDirectory(projectRoot, directory, label) {
|
|
263
|
-
const root = path.resolve(projectRoot);
|
|
264
|
-
const target = path.resolve(directory);
|
|
265
|
-
if (!workflowPathInside(root, target)) {
|
|
266
|
-
throw new Error(label + ' must stay inside the project root');
|
|
267
|
-
}
|
|
268
|
-
const relative = path.relative(root, target);
|
|
269
|
-
const segments = relative === '' ? [] : relative.split(path.sep);
|
|
270
|
-
let cursor = root;
|
|
271
|
-
await inspectWorkflowProtectedPath(root, cursor, label, 'directory');
|
|
272
|
-
for (const segment of segments) {
|
|
273
|
-
const parent = cursor;
|
|
274
|
-
cursor = path.join(cursor, segment);
|
|
275
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
276
|
-
root,
|
|
277
|
-
cursor,
|
|
278
|
-
label,
|
|
279
|
-
'directory',
|
|
280
|
-
);
|
|
281
|
-
if (!inspection.exists) {
|
|
282
|
-
const parentSnapshot = await workflowProtectedDirectorySnapshot(
|
|
283
|
-
root,
|
|
284
|
-
parent,
|
|
285
|
-
label + ' parent',
|
|
286
|
-
);
|
|
287
|
-
try {
|
|
288
|
-
await fs.mkdir(cursor);
|
|
289
|
-
} catch (error) {
|
|
290
|
-
if (!error || typeof error !== 'object' || error.code !== 'EEXIST') {
|
|
291
|
-
throw error;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
295
|
-
root,
|
|
296
|
-
parent,
|
|
297
|
-
label + ' parent',
|
|
298
|
-
parentSnapshot,
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
const created = await inspectWorkflowProtectedPath(
|
|
302
|
-
root,
|
|
303
|
-
cursor,
|
|
304
|
-
label,
|
|
305
|
-
'directory',
|
|
306
|
-
);
|
|
307
|
-
if (!created.exists) {
|
|
308
|
-
throw new Error(label + ' could not be created safely');
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
async function workflowProtectedTargetSnapshot(projectRoot, file, label) {
|
|
314
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
315
|
-
projectRoot,
|
|
316
|
-
file,
|
|
317
|
-
label,
|
|
318
|
-
'file',
|
|
319
|
-
);
|
|
320
|
-
if (!inspection.exists) return { exists: false };
|
|
321
|
-
const stat = await fs.lstat(file, { bigint: true });
|
|
322
|
-
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
323
|
-
throw new Error(label + ' must be a real file');
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
exists: true,
|
|
327
|
-
stat,
|
|
328
|
-
realPath: await fs.realpath(file),
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async function assertWorkflowProtectedTargetSnapshot(
|
|
333
|
-
projectRoot,
|
|
334
|
-
file,
|
|
335
|
-
label,
|
|
336
|
-
expected,
|
|
337
|
-
) {
|
|
338
|
-
const actual = await workflowProtectedTargetSnapshot(projectRoot, file, label);
|
|
339
|
-
if (actual.exists !== expected.exists) {
|
|
340
|
-
throw new Error(label + ' changed before commit');
|
|
341
|
-
}
|
|
342
|
-
if (
|
|
343
|
-
actual.exists &&
|
|
344
|
-
expected.exists &&
|
|
345
|
-
(actual.realPath !== expected.realPath ||
|
|
346
|
-
!workflowSameFileStat(actual.stat, expected.stat))
|
|
347
|
-
) {
|
|
348
|
-
throw new Error(label + ' changed before commit');
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
async function writeWorkflowProtectedFile(
|
|
353
|
-
projectRoot,
|
|
354
|
-
file,
|
|
355
|
-
label,
|
|
356
|
-
value,
|
|
357
|
-
maxBytes,
|
|
358
|
-
) {
|
|
359
|
-
const bytes = Buffer.isBuffer(value) ? value : Buffer.from(String(value), 'utf8');
|
|
360
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {
|
|
361
|
-
throw new Error(label + ' byte limit must be a positive integer');
|
|
362
|
-
}
|
|
363
|
-
if (bytes.length > maxBytes) {
|
|
364
|
-
throw new Error(label + ' exceeds ' + String(maxBytes) + ' bytes');
|
|
365
|
-
}
|
|
366
|
-
const root = path.resolve(projectRoot);
|
|
367
|
-
const target = path.resolve(file);
|
|
368
|
-
const directory = path.dirname(target);
|
|
369
|
-
await ensureWorkflowProtectedDirectory(root, directory, label + ' directory');
|
|
370
|
-
const directorySnapshot = await workflowProtectedDirectorySnapshot(
|
|
371
|
-
root,
|
|
372
|
-
directory,
|
|
373
|
-
label + ' directory',
|
|
374
|
-
);
|
|
375
|
-
const targetSnapshot = await workflowProtectedTargetSnapshot(root, target, label);
|
|
376
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
377
|
-
root,
|
|
378
|
-
directory,
|
|
379
|
-
label + ' directory',
|
|
380
|
-
directorySnapshot,
|
|
381
|
-
);
|
|
382
|
-
await assertWorkflowProtectedTargetSnapshot(root, target, label, targetSnapshot);
|
|
383
|
-
|
|
384
|
-
const temporary = path.join(
|
|
385
|
-
directory,
|
|
386
|
-
'.' +
|
|
387
|
-
path.basename(target) +
|
|
388
|
-
'.' +
|
|
389
|
-
String(process.pid) +
|
|
390
|
-
'.' +
|
|
391
|
-
String(Date.now()) +
|
|
392
|
-
'.' +
|
|
393
|
-
Math.random().toString(16).slice(2) +
|
|
394
|
-
'.tmp',
|
|
395
|
-
);
|
|
396
|
-
const flags =
|
|
397
|
-
fsConstants.O_WRONLY |
|
|
398
|
-
fsConstants.O_CREAT |
|
|
399
|
-
fsConstants.O_EXCL |
|
|
400
|
-
(process.platform === 'win32' ? 0 : fsConstants.O_NOFOLLOW);
|
|
401
|
-
let handle;
|
|
402
|
-
let committed = false;
|
|
403
|
-
try {
|
|
404
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
405
|
-
root,
|
|
406
|
-
directory,
|
|
407
|
-
label + ' directory',
|
|
408
|
-
directorySnapshot,
|
|
409
|
-
);
|
|
410
|
-
handle = await fs.open(temporary, flags, 0o600);
|
|
411
|
-
await handle.writeFile(bytes);
|
|
412
|
-
await handle.sync();
|
|
413
|
-
const temporaryStat = await handle.stat({ bigint: true });
|
|
414
|
-
if (!temporaryStat.isFile()) {
|
|
415
|
-
throw new Error(label + ' temporary path must be a real file');
|
|
416
|
-
}
|
|
417
|
-
await handle.close();
|
|
418
|
-
handle = undefined;
|
|
419
|
-
await inspectWorkflowProtectedPath(
|
|
420
|
-
root,
|
|
421
|
-
temporary,
|
|
422
|
-
label + ' temporary file',
|
|
423
|
-
'file',
|
|
424
|
-
);
|
|
425
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
426
|
-
root,
|
|
427
|
-
directory,
|
|
428
|
-
label + ' directory',
|
|
429
|
-
directorySnapshot,
|
|
430
|
-
);
|
|
431
|
-
await assertWorkflowProtectedTargetSnapshot(root, target, label, targetSnapshot);
|
|
432
|
-
await fs.rename(temporary, target);
|
|
433
|
-
committed = true;
|
|
434
|
-
await inspectWorkflowProtectedPath(root, target, label, 'file');
|
|
435
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
436
|
-
root,
|
|
437
|
-
directory,
|
|
438
|
-
label + ' directory',
|
|
439
|
-
directorySnapshot,
|
|
440
|
-
);
|
|
441
|
-
} finally {
|
|
442
|
-
if (handle) {
|
|
443
|
-
await handle.close().catch(() => {});
|
|
444
|
-
}
|
|
445
|
-
if (!committed) {
|
|
446
|
-
try {
|
|
447
|
-
await assertWorkflowProtectedDirectorySnapshot(
|
|
448
|
-
root,
|
|
449
|
-
directory,
|
|
450
|
-
label + ' directory',
|
|
451
|
-
directorySnapshot,
|
|
452
|
-
);
|
|
453
|
-
await fs.rm(temporary, { force: true });
|
|
454
|
-
} catch {
|
|
455
|
-
// Do not follow a replaced parent during cleanup.
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
function slug(value) {
|
|
462
|
-
return String(value).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function generatedNodeSkillName(protocol, id) {
|
|
466
|
-
return (slug(protocol.name) || 'workflow') + '-' + (slug(id) || 'node');
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// 组装 statePath 失效错误:声明的字段值 + 实际解析出的绝对路径 + 跨命名空间探测 + 调整指引。
|
|
470
|
-
// 交叉探测的两个命名空间取值来自 state-schema.mjs 的运行时路径常量(单一来源,本文件不再硬编码);
|
|
471
|
-
// 探测只读、只改善错误措辞,不参与路径解析,也不改变控制流(绝不回退到另一命名空间,fail-closed 语义不变)。
|
|
472
|
-
// 探测基准 = statePath 所在目录的父目录(项目根布局下即项目根);该基准落在项目外时回落
|
|
473
|
-
// 到项目根,保证探测点不越出项目。探测失败一律按"未探测到"处理,不掩盖主错误。
|
|
474
|
-
async function statePathMissingError(declared, target) {
|
|
475
|
-
const lines = [
|
|
476
|
-
'workflow-run statePath does not exist: ' + declared + ' (resolved to ' + target + ')',
|
|
477
|
-
];
|
|
478
|
-
const parent = path.resolve(path.dirname(target), '..');
|
|
479
|
-
const probeBase = workflowPathInside(runRoot, parent) ? parent : runRoot;
|
|
480
|
-
const declaredNormalized = declared.replaceAll('\\', '/');
|
|
481
|
-
const elsewhere = [];
|
|
482
|
-
for (const candidate of [LEGACY_RUNTIME_STATE_PATH, RUNTIME_STATE_PATH]) {
|
|
483
|
-
if (candidate === declaredNormalized) continue;
|
|
484
|
-
if (await fileExists(path.resolve(probeBase, ...candidate.split('/')))) elsewhere.push(candidate);
|
|
485
|
-
}
|
|
486
|
-
if (elsewhere.length > 0) {
|
|
487
|
-
lines.push(
|
|
488
|
-
'hint: a state file exists in the other runtime namespace (' + elsewhere.join(', ') +
|
|
489
|
-
') — the project may not be migrated yet; run the installer (prepare-env) to finish the migration, or correct the statePath field',
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
lines.push(
|
|
493
|
-
'fix: edit "state.statePath" in the workflow protocol JSON (' + protocolPath +
|
|
494
|
-
') — the value must be the state file path relative to the project root (current runtime namespace: ' +
|
|
495
|
-
RUNTIME_STATE_PATH + ')',
|
|
496
|
-
);
|
|
497
|
-
const error = new Error(lines.join('\n'));
|
|
498
|
-
error.code = 'ENOENT';
|
|
499
|
-
return error;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
async function statePath(protocol) {
|
|
503
|
-
const preferred = String(protocol.state?.statePath ?? '');
|
|
504
|
-
const target = resolveWorkflowRelativePath(
|
|
505
|
-
runRoot,
|
|
506
|
-
preferred,
|
|
507
|
-
'workflow-run statePath',
|
|
508
|
-
).target;
|
|
509
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
510
|
-
runRoot,
|
|
511
|
-
target,
|
|
512
|
-
'workflow-run statePath',
|
|
513
|
-
'file',
|
|
514
|
-
);
|
|
515
|
-
if (!inspection.exists) {
|
|
516
|
-
throw await statePathMissingError(preferred, target);
|
|
517
|
-
}
|
|
518
|
-
return target;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
async function readStateJson(file) {
|
|
522
|
-
// 容忍 UTF-8 BOM(外部写入可能带 BOM)
|
|
523
|
-
return JSON.parse(
|
|
524
|
-
(
|
|
525
|
-
await readWorkflowProtectedFile(
|
|
526
|
-
runRoot,
|
|
527
|
-
file,
|
|
528
|
-
'workflow-run state',
|
|
529
|
-
WORKFLOW_PROJECT_FILE_MAX_BYTES,
|
|
530
|
-
)
|
|
531
|
-
).toString('utf8').replace(/^/, ''),
|
|
532
|
-
);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
async function writeJson(file, value) {
|
|
536
|
-
await writeWorkflowProtectedFile(
|
|
537
|
-
runRoot,
|
|
538
|
-
file,
|
|
539
|
-
'workflow-run state',
|
|
540
|
-
JSON.stringify(value, null, 2) + '\n',
|
|
541
|
-
WORKFLOW_PROJECT_FILE_MAX_BYTES,
|
|
542
|
-
);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function route(protocol) {
|
|
546
|
-
return protocol.nodes.filter((node) => !node.disabled);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function findNode(protocol, id) {
|
|
550
|
-
return route(protocol).find((node) => node.id === id || generatedNodeSkillName(protocol, node.id) === id) ?? null;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function completedSet(state) {
|
|
554
|
-
return new Set(Array.isArray(state.completedNodes) ? state.completedNodes : []);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// 路由判定统一委托共享模块 route-node.mjs 的 resolveNextNode(单一实现——guard 与
|
|
558
|
-
// workflow-state 两侧同语义,含多趟 parallel 回流与串行 pending → execute)。展示层
|
|
559
|
-
// (NEXT/NODE/SKILL 行)保留在本文件(AC-6 展示文案逐字)。无活跃 change → null(完成态)。
|
|
560
|
-
async function nextNode(protocol, state) {
|
|
561
|
-
if (!state.activeChange) return null;
|
|
562
|
-
const id = await resolveNextNode({
|
|
563
|
-
runRoot,
|
|
564
|
-
changeName: state.activeChange,
|
|
565
|
-
protocol,
|
|
566
|
-
completedNodes: Array.isArray(state.completedNodes) ? state.completedNodes : [],
|
|
567
|
-
});
|
|
568
|
-
return id ? findNode(protocol, id) : null;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// ---------- 多趟路由共享判定(依赖图校验决策与完成判定谓词决策 · 多趟路由架构决策记录) ----------
|
|
572
|
-
|
|
573
|
-
// <depends_on> 提取(逗号/空白分隔)。DESIGN 0.5.2:与 workflow-state.mjs 各自保留既有正则实现、
|
|
574
|
-
// 不提取到共享解析层(task-parsing/state-schema 冻结为只消费)——两处语义由场景族锚定一致。
|
|
575
|
-
function taskDependsOn(block) {
|
|
576
|
-
const m = String(block ?? '').match(/<depends_on>([\s\S]*?)<\/depends_on>/);
|
|
577
|
-
if (!m || !m[1].trim()) return [];
|
|
578
|
-
return m[1].trim().split(/[,\s]+/).filter(Boolean);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// 委托进入谓词(每趟求值):∃ p ∈ tasks:p.parallel ∧ p.status=pending ∧ deps(p) ⊆ doneIds。
|
|
582
|
-
// 返回满足谓词的任务块数组——subagent-execute 出口的「尚有可委托」判定用,
|
|
583
|
-
// 与 workflow-state.mjs determineNode 的路由谓词同语义(镜像同步点)。
|
|
584
|
-
function eligibleParallelBlocks(blocks, doneIds) {
|
|
585
|
-
return blocks.filter((block) => {
|
|
586
|
-
const a = taskOpeningAttrs(block);
|
|
587
|
-
if (!a || !a.parallel || a.status !== 'pending') return false;
|
|
588
|
-
const deps = taskDependsOn(block);
|
|
589
|
-
return deps.every((d) => doneIds.has(d));
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function printNext(protocol, node) {
|
|
594
|
-
if (!node) {
|
|
595
|
-
console.log('NEXT: done');
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
console.log('NEXT: auto');
|
|
599
|
-
console.log('NODE: ' + node.id);
|
|
600
|
-
console.log('SKILL: ' + generatedNodeSkillName(protocol, node.id));
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
function evidenceFor(state, id) {
|
|
604
|
-
const value = state.evidence && typeof state.evidence === 'object' ? state.evidence[id] : null;
|
|
605
|
-
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
function missingRequiredSkillChecks(node, evidence) {
|
|
609
|
-
const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
|
|
610
|
-
return (node.requiredSkillCalls ?? [])
|
|
611
|
-
.map((binding) => 'required-skill:' + node.id + '.' + binding.skill)
|
|
612
|
-
.filter((check) => !values.includes(check));
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function missingAugmentationChecks(node, evidence) {
|
|
616
|
-
const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
|
|
617
|
-
return (node.augmentations ?? [])
|
|
618
|
-
.filter((binding) => binding.enforcement && binding.enforcement !== 'advisory')
|
|
619
|
-
.map((binding) => 'augmentation:' + node.id + '.' + binding.skill)
|
|
620
|
-
.filter((check) => !values.includes(check));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function hasEvidenceField(evidence, id) {
|
|
624
|
-
if (Object.prototype.hasOwnProperty.call(evidence, id)) return true;
|
|
625
|
-
const schemaEvidence = evidence.schemaEvidence;
|
|
626
|
-
return !!(
|
|
627
|
-
schemaEvidence &&
|
|
628
|
-
typeof schemaEvidence === 'object' &&
|
|
629
|
-
!Array.isArray(schemaEvidence) &&
|
|
630
|
-
Object.prototype.hasOwnProperty.call(schemaEvidence, id)
|
|
631
|
-
);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// 共用证据库 handoffResult 识别——subagent-execute 的委托结果由 workflow-handoff
|
|
635
|
-
// result 写入嵌套 handoffResult({ <taskId>: { result, completedAt } }),非顶层
|
|
636
|
-
// handoff-result 字段;嵌套对象存在且非空(至少一个任务记录)视为该 evidence 已产生
|
|
637
|
-
// (gate 只认存在性,内容严格校验由 W1-D Return Contract 校验负责)。
|
|
638
|
-
function hasNonEmptyHandoffResult(evidence) {
|
|
639
|
-
const handoff = evidence?.handoffResult;
|
|
640
|
-
return !!(
|
|
641
|
-
handoff &&
|
|
642
|
-
typeof handoff === 'object' &&
|
|
643
|
-
!Array.isArray(handoff) &&
|
|
644
|
-
Object.keys(handoff).length > 0
|
|
645
|
-
);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// AC-8 在飞委托判定(验证隔离「同一时刻只有一个写者」)——handoffRequests 中存在条目而
|
|
649
|
-
// handoffResult 无对应记录 = 写者未收工的既有可判形态。判据单处求值(出口校验唯一消费方)。
|
|
650
|
-
// 三态收敛:无 evidence['subagent-execute'] / 无 handoffRequests 条目 ⇒ 返回空数组(调用方零输出,
|
|
651
|
-
// 不制造噪音);全部有对应 result ⇒ 同样空数组(放行)。锚定既有字段,零新增 state 顶层字段。
|
|
652
|
-
// 已撤回的 request 不构成在飞委托(2026-10-07 补撤回通道):零提交复验失败 / 写边界被拒之后
|
|
653
|
-
// request 可能留在「有 request 无 result」态而命令面无从撤回——`workflow-handoff.mjs withdraw`
|
|
654
|
-
// 在原地落留痕(withdrawnAt + withdrawnBy,历史不删),守卫据此放行出口。判据复用
|
|
655
|
-
// state-schema.mjs 的单一实现(撤回留痕两字段齐备才算撤回),本文件不另写一份。
|
|
656
|
-
function inFlightHandoffRequests(evidence) {
|
|
657
|
-
const requests = evidence && typeof evidence === 'object' ? evidence.handoffRequests : null;
|
|
658
|
-
if (!requests || typeof requests !== 'object' || Array.isArray(requests)) return [];
|
|
659
|
-
const results = evidence.handoffResult && typeof evidence.handoffResult === 'object' && !Array.isArray(evidence.handoffResult)
|
|
660
|
-
? evidence.handoffResult
|
|
661
|
-
: {};
|
|
662
|
-
return Object.keys(requests).filter((taskId) => {
|
|
663
|
-
if (handoffRequestWithdrawn(requests[taskId])) return false;
|
|
664
|
-
return results[taskId] === undefined || results[taskId] === null;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
function schemaMap(protocol) {
|
|
669
|
-
return new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function missingRequiredSchemaEvidence(protocol, node, evidence) {
|
|
673
|
-
const schemas = schemaMap(protocol);
|
|
674
|
-
const missing = [];
|
|
675
|
-
// schema evidence 缺失但 record 传了 summary → 以 summary 视为产出证据(避免手动构造各字段)
|
|
676
|
-
const hasSummary = typeof evidence?.summary === 'string' && evidence.summary.trim() !== '';
|
|
677
|
-
for (const schemaId of node.outputSchemas ?? []) {
|
|
678
|
-
const schema = schemas.get(schemaId);
|
|
679
|
-
for (const field of schema?.evidence ?? []) {
|
|
680
|
-
if (field.required && !hasEvidenceField(evidence, field.id) && !hasSummary) {
|
|
681
|
-
missing.push(schemaId + '.' + field.id);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
return missing;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
function escapeRegExp(value) {
|
|
689
|
-
return String(value).replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
function patternToRegExp(pattern) {
|
|
693
|
-
return new RegExp('^' + String(pattern).split('*').map(escapeRegExp).join('.*') + '$', 'u');
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
async function pathPatternExists(root, relativePattern) {
|
|
697
|
-
const parts = workflowRelativeSegments(relativePattern, 'artifact path', true);
|
|
698
|
-
async function walk(current, index) {
|
|
699
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
700
|
-
runRoot,
|
|
701
|
-
current,
|
|
702
|
-
'workflow artifact path',
|
|
703
|
-
index >= parts.length ? 'any' : 'directory',
|
|
704
|
-
);
|
|
705
|
-
if (!inspection.exists) return false;
|
|
706
|
-
if (index >= parts.length) {
|
|
707
|
-
return true;
|
|
708
|
-
}
|
|
709
|
-
const part = parts[index];
|
|
710
|
-
if (!part.includes('*')) {
|
|
711
|
-
return walk(path.join(current, part), index + 1);
|
|
712
|
-
}
|
|
713
|
-
let entries;
|
|
714
|
-
try {
|
|
715
|
-
entries = await fs.readdir(current, { withFileTypes: true });
|
|
716
|
-
} catch {
|
|
717
|
-
return false;
|
|
718
|
-
}
|
|
719
|
-
const matcher = patternToRegExp(part);
|
|
720
|
-
for (const entry of entries) {
|
|
721
|
-
if (entry.isSymbolicLink()) {
|
|
722
|
-
throw new Error(
|
|
723
|
-
'workflow artifact path crosses a symbolic link or junction at ' +
|
|
724
|
-
path.join(current, entry.name),
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
if (matcher.test(entry.name) && (await walk(path.join(current, entry.name), index + 1))) {
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
return walk(root, 0);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// 产物根解析:'project'/缺省 → runRoot;'specs-root' → runRoot/.specs。
|
|
737
|
-
// classic/native 等 pathBase 依赖项目配置文件,已随 Comet 感知层剥离——不再读取任何项目配置,
|
|
738
|
-
// 遇到即显式报错(fail-fast,与 route-node.mjs 的状态机推导侧同语义),不静默兜底。
|
|
739
|
-
async function workflowArtifactRoot(pathBase) {
|
|
740
|
-
if (pathBase === undefined || pathBase === 'project') {
|
|
741
|
-
await inspectWorkflowProtectedPath(runRoot, runRoot, 'workflow path base', 'directory');
|
|
742
|
-
return runRoot;
|
|
743
|
-
}
|
|
744
|
-
if (pathBase === 'specs-root') {
|
|
745
|
-
return path.join(runRoot, '.specs');
|
|
746
|
-
}
|
|
747
|
-
throw new Error('产物根 pathBase "' + pathBase + '" 不再支持——请改用 specs-root/project + 完整路径(如 project + openspec/changes/xxx.md)');
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
async function missingRequiredArtifacts(protocol, node, change) {
|
|
751
|
-
const schemas = schemaMap(protocol);
|
|
752
|
-
const missing = [];
|
|
753
|
-
for (const schemaId of node.outputSchemas ?? []) {
|
|
754
|
-
const schema = schemas.get(schemaId);
|
|
755
|
-
for (const artifact of schema?.artifacts ?? []) {
|
|
756
|
-
if (!artifact.required) continue;
|
|
757
|
-
const exists = (
|
|
758
|
-
await Promise.all(
|
|
759
|
-
(artifact.paths ?? []).map(async (artifactPath) => {
|
|
760
|
-
// 替换 <change-id> 占位符为实际 change(如 name-format-unify)
|
|
761
|
-
const resolvedPath = change ? artifactPath.replaceAll('<change-id>', change) : artifactPath;
|
|
762
|
-
return pathPatternExists(await workflowArtifactRoot(artifact.pathBase), resolvedPath);
|
|
763
|
-
}),
|
|
764
|
-
)
|
|
765
|
-
).some(Boolean);
|
|
766
|
-
if (!exists) missing.push(schemaId + '.' + artifact.id);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return missing;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
async function fileExists(file) {
|
|
773
|
-
try { await fs.access(file); return true; } catch { return false; }
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// W1-B: 校验 change 目录下每份 *-SUMMARY.md 含 SUMMARY 模板的三个必填段
|
|
777
|
-
// 用正则(大小写不敏感 + 变体兼容)——避免现有 SUMMARY 格式漂移导致误 BLOCKED
|
|
778
|
-
async function verifySummaries(changeDir) {
|
|
779
|
-
const files = (await fs.readdir(changeDir).catch(() => [])).filter(f => f.endsWith('-SUMMARY.md'));
|
|
780
|
-
const violations = [];
|
|
781
|
-
for (const f of files) {
|
|
782
|
-
const content = await fs.readFile(path.join(changeDir, f), 'utf8');
|
|
783
|
-
for (const section of SUMMARY_REQUIRED_SECTIONS) {
|
|
784
|
-
if (!section.regex.test(content)) violations.push(`${f} 缺 ${section.label}`);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return violations;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
// W1-C 过渡规则: 历史归档 change 不强制真实跑验证命令(判断 .specs/archive/ 目录)
|
|
791
|
-
async function isArchivedChange(changeName) {
|
|
792
|
-
if (!changeName) return false;
|
|
793
|
-
const archiveRoot = path.join(runRoot, '.specs', 'archive');
|
|
794
|
-
if (await fileExists(path.join(archiveRoot, changeName))) return true;
|
|
795
|
-
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
796
|
-
return entries.some(e => e === changeName || e.endsWith('-' + changeName));
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// 声明标记目录解析——活动路径 .specs/<change-id>/.skill-loads/ 优先;归档路径兜底
|
|
800
|
-
// (archive 节点「先移目录后 record/exit」顺序下 change 目录已在 .specs/archive/<前缀>-<change-id>/,
|
|
801
|
-
// 标记只随目录移动——只查活动路径会把「标记存在」误判成「机制未激活」)。归档扫描匹配后缀
|
|
802
|
-
// -<change-id>(前缀可含日期等,与协议 flowkit.archive.v1 的 archive/*-<change-id> 同构)。
|
|
803
|
-
// 两者皆无 → null(声明机制从未激活,调用方按旧 change 兼容跳过)。
|
|
804
|
-
async function findSkillLoadsDir(root, changeName) {
|
|
805
|
-
const activeDir = path.join(root, '.specs', changeName, '.skill-loads');
|
|
806
|
-
if (await fileExists(activeDir)) {
|
|
807
|
-
return { dir: activeDir, display: '.specs/' + changeName + '/.skill-loads/' };
|
|
808
|
-
}
|
|
809
|
-
const archiveRoot = path.join(root, '.specs', 'archive');
|
|
810
|
-
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
811
|
-
for (const entry of entries) {
|
|
812
|
-
if (!entry.endsWith('-' + changeName)) continue;
|
|
813
|
-
const candidate = path.join(archiveRoot, entry, '.skill-loads');
|
|
814
|
-
if (await fileExists(candidate)) {
|
|
815
|
-
return { dir: candidate, display: '.specs/archive/' + entry + '/.skill-loads/' };
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return null;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
// C2: 段名校验从模板自动派生——读 <runRoot>/flow-kit/templates/{CHANGE,REQUIREMENT,DESIGN}.md
|
|
822
|
-
// 提取全部 ^## 段名,正则化生成宽松匹配模式;模板目录/文件缺失时 fallback 内置段名
|
|
823
|
-
let templateSectionPatternsCacheRoot = null;
|
|
824
|
-
let templateSectionPatternsCache = null;
|
|
825
|
-
|
|
826
|
-
const TEMPLATE_FALLBACK_SECTION_PATTERNS = {
|
|
827
|
-
changeWhy: /^##\s*Why\b/im,
|
|
828
|
-
changeVisualTone: /^##\s*视觉调性/im,
|
|
829
|
-
requirementUserStory: /^##\s*用户故事/im,
|
|
830
|
-
requirementAcceptance: /##\s*(验收准则|验收标准|AC|Acceptance Criteria)/i,
|
|
831
|
-
designDecisionList: /^##\s*\d*\.?\s*决策清单/m,
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// 模板段名 → 宽松匹配正则:编号前缀(1. / 0.5)可选 + 段名主体字面匹配 + 尾部括号内容(如 (AC))可选
|
|
835
|
-
function templateSectionPattern(rawName) {
|
|
836
|
-
const name = String(rawName).trim();
|
|
837
|
-
const body = name
|
|
838
|
-
.replace(/[((][^))\n]*[))]\s*$/u, '') // 去尾部括号内容:Why(为什么做)→ Why
|
|
839
|
-
.replace(/^\d+(?:\.\d+)?\.?\s*/u, '') // 去编号前缀:1. 决策清单 → 决策清单
|
|
840
|
-
.trim();
|
|
841
|
-
const escaped = escapeRegExp(body || name);
|
|
842
|
-
return new RegExp(
|
|
843
|
-
'^##\\s*(?:\\d+(?:\\.\\d+)?\\.?\\s*)?' + escaped + '\\s*(?:[((][^\\n))]*[))])?\\s*$',
|
|
844
|
-
'im',
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// 读取模板全部段名生成模式列表(模块级缓存,避免每次 exit 重复读文件);pick 按关键词选段,找不到 → fallback
|
|
849
|
-
async function templateSectionPatterns() {
|
|
850
|
-
if (templateSectionPatternsCacheRoot === runRoot && templateSectionPatternsCache) {
|
|
851
|
-
return templateSectionPatternsCache;
|
|
852
|
-
}
|
|
853
|
-
const templateDir = path.join(runRoot, 'flow-kit', 'templates');
|
|
854
|
-
const result = { change: [], requirement: [], design: [], summary: [] };
|
|
855
|
-
for (const [key, fileName] of Object.entries({
|
|
856
|
-
change: 'CHANGE.md',
|
|
857
|
-
requirement: 'REQUIREMENT.md',
|
|
858
|
-
design: 'DESIGN.md',
|
|
859
|
-
summary: 'SUMMARY.md',
|
|
860
|
-
})) {
|
|
861
|
-
const templateFile = path.join(templateDir, fileName);
|
|
862
|
-
if (await fileExists(templateFile)) {
|
|
863
|
-
try {
|
|
864
|
-
const text = await fs.readFile(templateFile, 'utf8');
|
|
865
|
-
for (const match of text.matchAll(/^##\s+(.+)$/gmu)) {
|
|
866
|
-
const sectionName = match[1].trim();
|
|
867
|
-
result[key].push({ name: sectionName, regex: templateSectionPattern(sectionName) });
|
|
868
|
-
}
|
|
869
|
-
} catch {}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
result.pick = (key, keywords, fallback) => {
|
|
873
|
-
for (const section of result[key] ?? []) {
|
|
874
|
-
if (keywords.some((keyword) => section.name.includes(keyword))) return section.regex;
|
|
875
|
-
}
|
|
876
|
-
return fallback;
|
|
877
|
-
};
|
|
878
|
-
templateSectionPatternsCache = result;
|
|
879
|
-
templateSectionPatternsCacheRoot = runRoot;
|
|
880
|
-
return result;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// ===== ui-design 适用性门控(前端判据 · 结构级,不做语义)=====
|
|
884
|
-
// 协议 design 节点的 ui-design 绑定为 guarded,但它「仅前端」适用 ⇒ 出口自动补 required-skill
|
|
885
|
-
// 声明对该绑定失效(须真实 skill-load 声明),判据不成立(非前端)时按 advisory 处理并在出口
|
|
886
|
-
// 输出可见跳过行(不留假绿:跳过是显式记录,非静默省略)。
|
|
887
|
-
// 键控(enforcement 是这道门的单一表达处):门只在「协议登记了该绑定 ∧ enforcement === 'guarded'」
|
|
888
|
-
// 时存在——协议副本删掉绑定或把等级调回 advisory ⇒ 门不适用(留可见「门未启用」行,不静默消失),
|
|
889
|
-
// 相应路径逐字回到未登记绑定的原语义。门禁侧不持有第二份键表:登记表 APPLICABILITY_GATED_BINDINGS
|
|
890
|
-
// 按 `<nodeId>.<skill>` 键控,工件门与出口自动补写共用下方 applicabilityGatedBinding 查询。
|
|
891
|
-
// 判据必须结构性可判:CHANGE.md 的「视觉调性」段在场且段内不含**结构形态**的「不适用」标记 ⇒
|
|
892
|
-
// 前端;段缺席 / 段内以结构形态标注 ⇒ 非前端。段名基准从 flow-kit/templates/CHANGE.md 派生
|
|
893
|
-
// (与 C2/M3 同源,模板缺失 → 内置骨架名),不做段名第二实现。
|
|
894
|
-
const UI_DESIGN_SKILL = 'flow-comet-ui-design';
|
|
895
|
-
const APPLICABILITY_GATED_BINDINGS = new Set(['design.' + UI_DESIGN_SKILL]);
|
|
896
|
-
const VISUAL_TONE_NOT_APPLICABLE = '不适用';
|
|
897
|
-
|
|
898
|
-
// 负向标记的结构约束(三种形态,共用同一词形边界)——裸子串会让「不适用于暗色主题」这类自然句子
|
|
899
|
-
// 关掉整道门(fail-open),故标记必须落在结构锚位且成词形边界:
|
|
900
|
-
// 形态 A 独立行:整行(去块引用 / 列表符 / 加粗)就是标记,可带括注理由与尾标点;
|
|
901
|
-
// 形态 B 行首:行以标记开头(如「不适用 —— CLI 工具,无用户可见界面。」);
|
|
902
|
-
// 形态 C 字段值位:`<适用性标签>: 不适用`——标签限本约定的短标签表(适用性 / 前端 / 视觉调性 …),
|
|
903
|
-
// 不通配任意字段名:`- 暗色主题:不适用` 这类「某子维度不适用」的字段不得关掉整道门。
|
|
904
|
-
// 词形边界 = 标记后为行尾 / 空白 / 标点 / 括注引号——「不适用于…」的「于」不是边界。
|
|
905
|
-
const TONE_MARKER_TAIL = String.raw`(?=$|[\s,。;、,;.::!!??…—()()【】「」『』“”"'])`;
|
|
906
|
-
const TONE_MARKER_LEAD = String.raw`^[>\s]*(?:[-*+]\s+)?(?:\*\*)?`;
|
|
907
|
-
const TONE_MARKER_FIELD_LABELS = '适用性|适用范围|是否前端|视觉调性|前端|界面|适用';
|
|
908
|
-
const TONE_MARKER_ALONE_LINE = new RegExp(TONE_MARKER_LEAD + VISUAL_TONE_NOT_APPLICABLE
|
|
909
|
-
+ String.raw`(?:\*\*)?(?:\s*[((][^))]*[))])?[。.;;,,]?\s*$`);
|
|
910
|
-
const TONE_MARKER_LINE_HEAD = new RegExp(TONE_MARKER_LEAD + VISUAL_TONE_NOT_APPLICABLE
|
|
911
|
-
+ String.raw`(?:\*\*)?` + TONE_MARKER_TAIL);
|
|
912
|
-
const TONE_MARKER_FIELD_VALUE = new RegExp(String.raw`(?:^|[\s|])(?:\*\*)?(?:`
|
|
913
|
-
+ TONE_MARKER_FIELD_LABELS + String.raw`)(?:\*\*)?\s*[::]\s*(?:\*\*)?`
|
|
914
|
-
+ VISUAL_TONE_NOT_APPLICABLE + String.raw`(?:\*\*)?` + TONE_MARKER_TAIL);
|
|
915
|
-
|
|
916
|
-
// 「视觉调性」段正文(段标题之后、下一个 H2 之前;段缺席 → null)
|
|
917
|
-
async function visualToneSectionBody(changeName) {
|
|
918
|
-
if (!changeName) return null;
|
|
919
|
-
let text;
|
|
920
|
-
try {
|
|
921
|
-
text = await fs.readFile(path.join(runRoot, '.specs', changeName, 'CHANGE.md'), 'utf8');
|
|
922
|
-
} catch {
|
|
923
|
-
return null;
|
|
924
|
-
}
|
|
925
|
-
const headingPattern = (await templateSectionPatterns())
|
|
926
|
-
.pick('change', ['视觉调性'], TEMPLATE_FALLBACK_SECTION_PATTERNS.changeVisualTone);
|
|
927
|
-
let body = null;
|
|
928
|
-
for (const line of String(text).replace(/\uFEFF/g, '').split(/\r?\n/)) {
|
|
929
|
-
if (/^##\s+/.test(line)) {
|
|
930
|
-
if (body !== null) break; // 到达下一个 H2 → 本段结束
|
|
931
|
-
if (headingPattern.test(line)) body = '';
|
|
932
|
-
continue;
|
|
933
|
-
}
|
|
934
|
-
if (body !== null) body += line + '\n';
|
|
935
|
-
}
|
|
936
|
-
return body;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
// 段内负向标记命中(逐行判定——判据限段内):命中 → 返回命中行片段(去空白 + 超长截断),
|
|
940
|
-
// 未命中 → null。片段回显进出口的跳过行,跳过因此自证(不是「段内某处出现过什么字面」)。
|
|
941
|
-
function visualToneNotApplicableHit(body) {
|
|
942
|
-
for (const rawLine of String(body).split(/\r?\n/)) {
|
|
943
|
-
const line = rawLine.trim();
|
|
944
|
-
if (line === '') continue;
|
|
945
|
-
if (TONE_MARKER_ALONE_LINE.test(line)
|
|
946
|
-
|| TONE_MARKER_LINE_HEAD.test(line)
|
|
947
|
-
|| TONE_MARKER_FIELD_VALUE.test(line)) {
|
|
948
|
-
return line.length > 60 ? line.slice(0, 60) + '…' : line;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
return null;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
// 登记表查询(唯一键表,键形 `<nodeId>.<skill>`):该节点 + 技能是否受适用性门控
|
|
955
|
-
function isRegisteredApplicabilityBinding(node, skill) {
|
|
956
|
-
return APPLICABILITY_GATED_BINDINGS.has(node.id + '.' + skill);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
// 适用性门控绑定的单一查询:在场 ∧ enforcement === 'guarded' ∧ 登记在表 → 协议绑定;否则 null。
|
|
960
|
-
// 工件门、出口自动补写与缺声明恢复指引共用本查询——enforcement 是该门的单一表达处。
|
|
961
|
-
function applicabilityGatedBinding(node, skill) {
|
|
962
|
-
if (!isRegisteredApplicabilityBinding(node, skill)) return null;
|
|
963
|
-
return (node.requiredSkillCalls ?? []).find((call) => call.skill === skill && call.enforcement === 'guarded') ?? null;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
// 前端判据:{ applicable, reason }——applicable=true 表示本 change 判为前端项目
|
|
967
|
-
async function frontendCriterion(changeName) {
|
|
968
|
-
const body = await visualToneSectionBody(changeName);
|
|
969
|
-
if (body === null) return { applicable: false, reason: '「视觉调性」段缺席(判非前端)' };
|
|
970
|
-
const hit = visualToneNotApplicableHit(body);
|
|
971
|
-
if (hit !== null) {
|
|
972
|
-
return { applicable: false, reason: '「视觉调性」段标注「不适用」(判非前端;命中片段: ' + hit + ')' };
|
|
973
|
-
}
|
|
974
|
-
return { applicable: true, reason: '「视觉调性」段在场且未标注「不适用」(判前端;无结构形态标记)' };
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
// design 出口 ui-design 工件门(按协议绑定键控:登记 ∧ 等级 = guarded ∧ 判据成立)——判据成立 ⇒
|
|
978
|
-
// 要求 UI-DESIGN.md 在场:新 change 缺件 BLOCKED + 恢复指引,旧 change WARN 渐进不阻断(不静默
|
|
979
|
-
// 放行);判据不成立(非前端)⇒ 可见跳过行(含命中片段)后照常放行;协议删掉该绑定或等级非
|
|
980
|
-
// guarded ⇒ 门未启用(同样可见输出),行为回到未登记绑定的原语义——闸门开关由协议表达。
|
|
981
|
-
async function checkUiDesignArtifact(node, state) {
|
|
982
|
-
if (!state.activeChange || !isRegisteredApplicabilityBinding(node, UI_DESIGN_SKILL)) return;
|
|
983
|
-
if (!applicabilityGatedBinding(node, UI_DESIGN_SKILL)) {
|
|
984
|
-
const protocolState = (node.requiredSkillCalls ?? []).some((call) => call.skill === UI_DESIGN_SKILL)
|
|
985
|
-
? '协议 ' + node.id + ' 绑定等级 = advisory,非 guarded'
|
|
986
|
-
: '协议 ' + node.id + ' 节点未登记 ' + UI_DESIGN_SKILL + ' 绑定';
|
|
987
|
-
console.error('UI-DESIGN: 门未启用(' + protocolState + ')');
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
const frontend = await frontendCriterion(state.activeChange);
|
|
991
|
-
if (!frontend.applicable) {
|
|
992
|
-
console.error('UI-DESIGN: skipped(非前端)——' + frontend.reason + ',不要求 UI-DESIGN.md');
|
|
993
|
-
return;
|
|
994
|
-
}
|
|
995
|
-
const artifact = path.join(runRoot, '.specs', state.activeChange, 'UI-DESIGN.md');
|
|
996
|
-
if (await fileExists(artifact)) return;
|
|
997
|
-
const recovery = '补 .specs/' + state.activeChange + '/UI-DESIGN.md(加载 ' + UI_DESIGN_SKILL + ' 并按其协议产出 design token / 反 AI-slop 自检),'
|
|
998
|
-
+ '或在 .specs/' + state.activeChange + '/CHANGE.md 的「视觉调性」段以结构形态标注「不适用」(非前端项目)后重试 exit design';
|
|
999
|
-
if (isNewChange(state)) {
|
|
1000
|
-
console.error('BLOCKED: design 出口缺 UI-DESIGN.md——' + frontend.reason + ',前端项目须产出 UI-DESIGN.md');
|
|
1001
|
-
console.error('恢复: ' + recovery);
|
|
1002
|
-
process.exit(1);
|
|
1003
|
-
}
|
|
1004
|
-
console.error('UI-DESIGN WARN: 缺 .specs/' + state.activeChange + '/UI-DESIGN.md——' + frontend.reason + '(旧 change 渐进不阻断;新 change 将强制)');
|
|
1005
|
-
console.error('恢复: ' + recovery);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
// Fix 段标题从 <runRoot>/flow-kit/templates/TASK.md 派生(单一模板源 + 模块级缓存 + runRoot 键控):
|
|
1009
|
-
// 扫描模板全部 H2,用 route-node 共享 heading 归一(单一权威,含闭合 ATX)识别 Fix 段标题;
|
|
1010
|
-
// 无匹配(模板缺失 / 读取失败 / 无 Fix 段)返回 undefined,由回程分类器的内置 fallback 常量兜底。
|
|
1011
|
-
// 标题只喂给回程分类器决定审计行(不参与路由/state 写入)。
|
|
1012
|
-
// 识别标记词从单一权威 fallback 派生(归一后首词,如 Fix 任务 → Fix),因此模板基名改为其它
|
|
1013
|
-
// 语言后缀(如 Fix Tasks)仍可识别;闭合 ATX 与尾部括号变体由共享归一消化。
|
|
1014
|
-
const FIX_SECTION_HEADING_MARKER = normalizeHeading(FIX_SECTION_TITLE_FALLBACK).split(/\s+/u)[0];
|
|
1015
|
-
|
|
1016
|
-
// 模板文本全部 H2 中的 Fix 段标题(无匹配 → undefined):共享归一后与识别标记词比较,
|
|
1017
|
-
// 因此语言后缀可变(Fix 任务 / Fix Tasks);闭合 ATX 与尾部括号由共享归一消化。
|
|
1018
|
-
function fixSectionTitleFromTemplateText(text) {
|
|
1019
|
-
for (const match of String(text).matchAll(/^##\s+(.+)$/gmu)) {
|
|
1020
|
-
const raw = match[1].trim();
|
|
1021
|
-
const normalized = normalizeHeading(raw);
|
|
1022
|
-
if (normalized === FIX_SECTION_HEADING_MARKER
|
|
1023
|
-
|| normalized.startsWith(FIX_SECTION_HEADING_MARKER + ' ')) return raw;
|
|
1024
|
-
}
|
|
1025
|
-
return undefined;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
let fixSectionTitleCacheRoot = null;
|
|
1029
|
-
let fixSectionTitleCached = false;
|
|
1030
|
-
let fixSectionTitleCache;
|
|
1031
|
-
async function derivedFixSectionTitle() {
|
|
1032
|
-
if (fixSectionTitleCacheRoot === runRoot && fixSectionTitleCached) return fixSectionTitleCache;
|
|
1033
|
-
let title;
|
|
1034
|
-
const templateFile = path.join(runRoot, 'flow-kit', 'templates', 'TASK.md');
|
|
1035
|
-
if (await fileExists(templateFile)) {
|
|
1036
|
-
try {
|
|
1037
|
-
title = fixSectionTitleFromTemplateText(await fs.readFile(templateFile, 'utf8'));
|
|
1038
|
-
} catch {}
|
|
1039
|
-
}
|
|
1040
|
-
fixSectionTitleCache = title;
|
|
1041
|
-
fixSectionTitleCacheRoot = runRoot;
|
|
1042
|
-
fixSectionTitleCached = true;
|
|
1043
|
-
return title;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
// ===== 模板保真(M1/M2/M3·设计语义 / AC-7~AC-9)=====
|
|
1047
|
-
// 段名归一化:委托 route-node 共享 heading 归一(单一权威)——去标题标记 / 尾部括号
|
|
1048
|
-
// (如 Why(为什么做)→ Why)/ 编号前缀(1. 决策清单 → 决策清单)/ 闭合 ATX,去首尾空白 + 小写。
|
|
1049
|
-
function normalizeTemplateHeading(raw) {
|
|
1050
|
-
return normalizeHeading(raw);
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
// 提取文档全部 ^## 段(归一化后),供段序/缺段校验
|
|
1054
|
-
function documentSectionHeadings(content) {
|
|
1055
|
-
const out = [];
|
|
1056
|
-
for (const m of String(content).matchAll(/^##\s+(.+)$/gmu)) {
|
|
1057
|
-
out.push({ raw: m[1].trim(), norm: normalizeTemplateHeading(m[1]) });
|
|
1058
|
-
}
|
|
1059
|
-
return out;
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
// 模板段序骨架:段名从 flow-kit/templates 派生(与 C2 同源,模板缺失 fallback 内置骨架)
|
|
1063
|
-
const TEMPLATE_FIDELITY_FALLBACK_SKELETON = {
|
|
1064
|
-
change: ['why', 'what', '视觉调性', '影响面', '范围排除', '验收线', '风险与未知'],
|
|
1065
|
-
requirement: ['用户故事', '验收准则', '范围切分', '非功能性需求', '依赖与假设'],
|
|
1066
|
-
design: ['技术栈选定', '既有架构对齐', '决策清单', '数据流', '关键状态机', 'adr 索引', '风险', '不在范围', '架构沉淀建议'],
|
|
1067
|
-
// SUMMARY 模板缺失时的内置全骨架:十段(含条件段——条件段允许正文 N/A,但 H2 标题须在场)
|
|
1068
|
-
summary: ['做了什么', '改动文件', 'verify 输出', '6 维自查', '数据库迁移', '越界检查', '破坏性变更', '决策与偏离', '是否触发新工作', '完成判定'],
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
|
-
async function templateSkeleton(key) {
|
|
1072
|
-
const tpl = await templateSectionPatterns(); // 复用 C2 模板缓存(runRoot 内模板)
|
|
1073
|
-
const src = tpl[key] ?? [];
|
|
1074
|
-
if (src.length > 0) return src.map((s) => normalizeTemplateHeading(s.name));
|
|
1075
|
-
return (TEMPLATE_FIDELITY_FALLBACK_SKELETON[key] ?? []).map((s) => normalizeTemplateHeading(s));
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
// SUMMARY 全骨架来源:模板全部 H2 派生(derived=true);模板缺失/无 H2 → 内置十段兜底
|
|
1079
|
-
// (derived=false——调用方据此保持渐进兼容,不新增硬阻断)
|
|
1080
|
-
async function summaryTemplateSkeleton() {
|
|
1081
|
-
const tpl = await templateSectionPatterns();
|
|
1082
|
-
const derived = (tpl.summary ?? []).length > 0;
|
|
1083
|
-
return { derived, sections: await templateSkeleton('summary') };
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
// 段序校核(宽容):模板骨架段里「实际出现」的段须按模板先后出现;返回乱序描述(无则 null)
|
|
1087
|
-
function templateOrderViolation(skeletons, headings) {
|
|
1088
|
-
let last = -1;
|
|
1089
|
-
for (const h of headings) {
|
|
1090
|
-
const idx = skeletons.indexOf(h.norm);
|
|
1091
|
-
if (idx === -1) continue;
|
|
1092
|
-
if (idx < last) return h.raw;
|
|
1093
|
-
last = idx;
|
|
1094
|
-
}
|
|
1095
|
-
return null;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// M1: SUMMARY 模板保真——标题 # SUMMARY: + 首部 4 字段 + 段序(含 flow-comet 增量 ## 自检方法)。
|
|
1099
|
-
// 返回各维度缺口;调用方按新 BLOCK / 旧 WARN 渐进处置
|
|
1100
|
-
const SUMMARY_TEMPLATE_HEADER_FIELDS = [
|
|
1101
|
-
{ label: 'Change ID', re: /\*\*\s*Change\s+ID\s*\*\*/i },
|
|
1102
|
-
{ label: 'Task ID', re: /\*\*\s*Task\s+ID\s*\*\*/i },
|
|
1103
|
-
{ label: '完成时间', re: /\*\*\s*完成时间\s*\*\*/ },
|
|
1104
|
-
{ label: 'AI 角色', re: /\*\*\s*AI\s*角色\s*\*\*/ },
|
|
1105
|
-
];
|
|
1106
|
-
// 段序(含 flow-comet 增量段;越界检查在模板中位于 6 维自查 与 自检方法 之间)
|
|
1107
|
-
const SUMMARY_ORDERED_SECTIONS = ['做了什么', '改动文件', 'verify 输出', '6 维自查', '越界检查', '自检方法']
|
|
1108
|
-
.map(normalizeTemplateHeading);
|
|
1109
|
-
|
|
1110
|
-
function summaryTemplateFidelity(content) {
|
|
1111
|
-
const text = String(content).replace(/\uFEFF/g, '');
|
|
1112
|
-
const firstRealLine = (text.split('\n').find((l) => l.trim().length > 0) || '').trim();
|
|
1113
|
-
const titleMissing = !/^#\s*summary\s*:/i.test(firstRealLine);
|
|
1114
|
-
const headerRegion = text.split(/\n##\s/)[0];
|
|
1115
|
-
const headerMissing = SUMMARY_TEMPLATE_HEADER_FIELDS
|
|
1116
|
-
.filter((f) => !f.re.test(headerRegion))
|
|
1117
|
-
.map((f) => f.label);
|
|
1118
|
-
const headings = documentSectionHeadings(text);
|
|
1119
|
-
const seen = new Set();
|
|
1120
|
-
let last = -1;
|
|
1121
|
-
let orderIssue = null;
|
|
1122
|
-
for (const h of headings) {
|
|
1123
|
-
const idx = SUMMARY_ORDERED_SECTIONS.indexOf(normalizeTemplateHeading(h.raw));
|
|
1124
|
-
if (idx === -1) continue;
|
|
1125
|
-
if (idx < last) { orderIssue = h.raw; break; }
|
|
1126
|
-
last = idx;
|
|
1127
|
-
seen.add(idx);
|
|
1128
|
-
}
|
|
1129
|
-
const missingSections = [];
|
|
1130
|
-
for (let i = 0; i < SUMMARY_ORDERED_SECTIONS.length; i++) {
|
|
1131
|
-
if (!seen.has(i)) missingSections.push(SUMMARY_ORDERED_SECTIONS[i]);
|
|
1132
|
-
}
|
|
1133
|
-
return { titleMissing, headerMissing, orderIssue, missingSections };
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
// 全骨架保真:骨架来自 SUMMARY 模板全部 H2;每段须存在(条件段内容可写 N/A,但须有 H2 标题),
|
|
1137
|
-
// 实际出现的骨架段须按模板先后排列。## 自检方法 不进入骨架,单独校验:须位于 ## 越界检查 之后,
|
|
1138
|
-
// 且只允许两种位置——紧随 ## 越界检查 之后(下一段即自检方法)或位于全文末尾(最后一个 H2)。
|
|
1139
|
-
function summarySkeletonFidelity(content, skeleton) {
|
|
1140
|
-
const text = String(content).replace(/\uFEFF/g, '');
|
|
1141
|
-
const headings = documentSectionHeadings(text);
|
|
1142
|
-
const seen = new Set();
|
|
1143
|
-
for (const h of headings) {
|
|
1144
|
-
const idx = skeleton.sections.indexOf(h.norm);
|
|
1145
|
-
if (idx !== -1) seen.add(idx);
|
|
1146
|
-
}
|
|
1147
|
-
// 段序复用既有骨架校核(单一实现),段存在性单列——两者共用同一骨架
|
|
1148
|
-
const orderIssue = templateOrderViolation(skeleton.sections, headings);
|
|
1149
|
-
const missingSections = [];
|
|
1150
|
-
for (let i = 0; i < skeleton.sections.length; i++) {
|
|
1151
|
-
if (!seen.has(i)) missingSections.push(skeleton.sections[i]);
|
|
1152
|
-
}
|
|
1153
|
-
const selfHeading = normalizeTemplateHeading('自检方法');
|
|
1154
|
-
const boundsHeading = normalizeTemplateHeading('越界检查');
|
|
1155
|
-
const selfIdx = headings.findIndex((h) => h.norm === selfHeading);
|
|
1156
|
-
const boundsIdx = headings.findIndex((h) => h.norm === boundsHeading);
|
|
1157
|
-
let selfCheckIssue = null;
|
|
1158
|
-
if (selfIdx === -1) {
|
|
1159
|
-
selfCheckIssue = '缺 ## 自检方法 段(须位于 ## 越界检查 之后:文末或紧随越界检查两种合法位置)';
|
|
1160
|
-
} else if (
|
|
1161
|
-
boundsIdx === -1 ||
|
|
1162
|
-
selfIdx < boundsIdx ||
|
|
1163
|
-
(selfIdx !== headings.length - 1 && selfIdx !== boundsIdx + 1)
|
|
1164
|
-
) {
|
|
1165
|
-
selfCheckIssue = '## 自检方法 位置非法(须位于 ## 越界检查 之后:只允许文末或紧随越界检查两种位置)';
|
|
1166
|
-
}
|
|
1167
|
-
return { missingSections, orderIssue, selfCheckIssue };
|
|
1168
|
-
}
|
|
1169
86
|
|
|
1170
87
|
// WARN 计数——entry/exit 成功路径末尾输出汇总行(可观测性;追加不改变既有输出)
|
|
1171
88
|
let __warnCount = 0;
|
|
@@ -1207,7 +124,8 @@ async function main() {
|
|
|
1207
124
|
// 协议路径选择 + 受保护读取 + fail-closed schema 校验(读失败/校验失败沿用 throw →
|
|
1208
125
|
// main().catch 统一处理;来源为 state.protocolPath 时补充来源与不回退说明)
|
|
1209
126
|
const selectedProtocol = await resolveGuardProtocolPath();
|
|
1210
|
-
protocolPath = selectedProtocol.protocolPath;
|
|
127
|
+
const protocolPath = selectedProtocol.protocolPath;
|
|
128
|
+
setProtocolPath(protocolPath);
|
|
1211
129
|
let protocol;
|
|
1212
130
|
try {
|
|
1213
131
|
protocol = await readProtocolFile(runRoot, protocolPath);
|
|
@@ -1233,1317 +151,74 @@ async function main() {
|
|
|
1233
151
|
state.completedNodes = Array.isArray(state.completedNodes) ? state.completedNodes : [];
|
|
1234
152
|
state.evidence = state.evidence && typeof state.evidence === 'object' ? state.evidence : {};
|
|
1235
153
|
if (command === 'entry') {
|
|
1236
|
-
|
|
1237
|
-
// Fix 批次受控归位(共享谓词,唯一受控例外 · ADR-011):review/verify 驻留 + TASK 有
|
|
1238
|
-
// pending 修复任务(串行/并行)或有未闭合家族出口签名时,entry 家族节点(execute /
|
|
1239
|
-
// subagent-execute)归位工作归属并写盘;仅当入口节点与共享谓词目标一致才归位。
|
|
1240
|
-
// 前置 currentNode 校验对该受控例外放行(L-070 实录路径即直接 entry);其余节点/状态行为不变。
|
|
1241
|
-
const fixBatchDecision = EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange
|
|
1242
|
-
? await resolveFixRollbackDecision({
|
|
1243
|
-
runRoot,
|
|
1244
|
-
changeName: state.activeChange,
|
|
1245
|
-
protocol,
|
|
1246
|
-
completedNodes: state.completedNodes,
|
|
1247
|
-
currentNode: state.currentNode,
|
|
1248
|
-
history: state.history,
|
|
1249
|
-
})
|
|
1250
|
-
: null;
|
|
1251
|
-
const fixBatchRollback = !!fixBatchDecision && fixBatchDecision.target === node.id;
|
|
1252
|
-
if (current !== node.id && !state.completedNodes.includes(node.id) && !fixBatchRollback) {
|
|
1253
|
-
console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
|
|
1254
|
-
process.exit(1);
|
|
1255
|
-
}
|
|
1256
|
-
if (fixBatchRollback) {
|
|
1257
|
-
const sourceNode = state.currentNode;
|
|
1258
|
-
// 轮次计数与阈值/授权判定全部走共享 helper:分支②不计数;第 4 轮新 change 先 BLOCK
|
|
1259
|
-
// (此处尚未写盘,满足不写 currentNode),旧 change WARN 后照常归位。
|
|
1260
|
-
const rollbackRound = applyFixRollbackRound({ state, sourceNode, decision: fixBatchDecision });
|
|
1261
|
-
if (rollbackRound.blocked) {
|
|
1262
|
-
console.error(rollbackRound.blockedMessage);
|
|
1263
|
-
process.exit(1);
|
|
1264
|
-
}
|
|
1265
|
-
if (rollbackRound.warn) console.error(rollbackRound.warnMessage);
|
|
1266
|
-
state.currentNode = node.id;
|
|
1267
|
-
console.log('FIX-BATCH: 受控归位 ' + node.id + '(源节点 ' + sourceNode + ')' + rollbackRound.auditSuffix);
|
|
1268
|
-
const bad = validateStateFields(state);
|
|
1269
|
-
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
1270
|
-
await writeJson(file, state);
|
|
1271
|
-
}
|
|
1272
|
-
// E2: entry archive 分支校验(新模式 branchMode=true)——归档必须在 change/<activeChange> 分支上进行
|
|
1273
|
-
// 旧模式(无 branchMode 字段 / 非 git 仓库 / git 不可用)跳过,向后兼容
|
|
1274
|
-
if (node.id === 'archive' && state.branchMode === true && state.activeChange) {
|
|
1275
|
-
const { execFileSync } = await import('child_process');
|
|
1276
|
-
try {
|
|
1277
|
-
const branch = String(execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' })).trim();
|
|
1278
|
-
// 归档分支前缀用 state.branchPrefix(缺省 'change/',适配仓库自身规范)
|
|
1279
|
-
const archivePrefix = state.branchPrefix ?? 'change/';
|
|
1280
|
-
if (branch !== archivePrefix + state.activeChange) {
|
|
1281
|
-
console.error('BLOCKED: 归档必须在 ' + archivePrefix + state.activeChange + ' 分支上进行(当前: ' + branch + ')');
|
|
1282
|
-
process.exit(1);
|
|
1283
|
-
}
|
|
1284
|
-
} catch {
|
|
1285
|
-
// git 不可用 → 跳过分支校验(旧模式兼容)
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
// 并行冲突检测——subagent-execute 委托前校验 wave 内 parallel 任务 write_files 无交集
|
|
1289
|
-
// (第二道写写锚:只取强判组,行为与消息保持既有语义不变)
|
|
1290
|
-
if (node.id === 'subagent-execute' && state.activeChange) {
|
|
1291
|
-
const { writeConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
|
|
1292
|
-
if (writeConflicts.length > 0) {
|
|
1293
|
-
console.error('BLOCKED: parallel tasks write_files 冲突: ' + writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
|
|
1294
|
-
process.exit(1);
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
// C4: 委托前工件 commit 检查——worktree isolation 子代理看不到未提交工件(WARN 不 BLOCKED)
|
|
1298
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1299
|
-
const { execFileSync } = await import('child_process');
|
|
1300
|
-
try {
|
|
1301
|
-
execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: runRoot, stdio: 'pipe' });
|
|
1302
|
-
const statusOut = execFileSync(
|
|
1303
|
-
'git',
|
|
1304
|
-
['status', '--porcelain', '--', path.posix.join('.specs', state.activeChange) + '/'],
|
|
1305
|
-
{ cwd: runRoot, stdio: 'pipe', encoding: 'utf8' },
|
|
1306
|
-
);
|
|
1307
|
-
if (String(statusOut).trim() !== '') {
|
|
1308
|
-
console.error('WORKTREE WARN: .specs/' + state.activeChange + '/ 有未提交工件,worktree isolation 子代理将看不到它们——建议先 commit 或 prompt 内联上下文');
|
|
1309
|
-
}
|
|
1310
|
-
} catch (err) {
|
|
1311
|
-
// 检测失败可见化——非 git 仓库/路径不可查时提示 SKIP 原因(防静默失效)
|
|
1312
|
-
console.error('C4-CHECK SKIP: ' + (err && err.message ? String(err.message).split('\n')[0] : String(err)));
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
// C7: PROGRESS.md 存在警告(清窗恢复产物,R1.6 反重复)
|
|
1316
|
-
if (node.id === 'execute' && state.activeChange) {
|
|
1317
|
-
if (await fileExists(path.join(runRoot, '.specs', state.activeChange, 'PROGRESS.md'))) {
|
|
1318
|
-
console.error('WARNING: PROGRESS.md 存在(清窗恢复产物),先读"已排除方案"段(R1.6 反重复)');
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
// C3: enter execute / subagent-execute 记录 TASK.md 任务集签名(exit 时比对,防 execute 期间增删任务/改 action/改边界)
|
|
1322
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1323
|
-
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1324
|
-
if (await fileExists(taskFile)) {
|
|
1325
|
-
try {
|
|
1326
|
-
state.taskHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
1327
|
-
const bad = validateStateFields(state);
|
|
1328
|
-
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
1329
|
-
await writeJson(file, state);
|
|
1330
|
-
} catch {}
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
// 协调者禁令:execute / subagent-execute 阶段主会话只能委托,禁止直接写源码
|
|
1334
|
-
// 例外:direct 模式 execute 是主代理直写(逃生口),不输出协调者禁令
|
|
1335
|
-
const entryExecutionMode = state.executionMode ?? 'subagent';
|
|
1336
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1337
|
-
if (!(entryExecutionMode === 'direct' && node.id === 'execute')) {
|
|
1338
|
-
console.log('COORDINATOR: 你是协调者,不是执行者。禁止在主会话直接修改源码;只能通过 Agent 工具 worktree isolation 委托子代理;子代理回传后仅更新 TASK.md / SUMMARY / handoff evidence。');
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
// M1: enter 证据——entry 记录节点进入标记(enteredNodes),exit 检测未 entry(防跳过 entry 无痕)
|
|
1342
|
-
state.enteredNodes = Array.isArray(state.enteredNodes) ? state.enteredNodes : [];
|
|
1343
|
-
if (!state.enteredNodes.includes(node.id)) {
|
|
1344
|
-
state.enteredNodes.push(node.id);
|
|
1345
|
-
const bad = validateStateFields(state);
|
|
1346
|
-
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
1347
|
-
await writeJson(file, state);
|
|
1348
|
-
// G13: 进入已记录提示(执行者可知 entry 有副作用——进入证据写入)
|
|
1349
|
-
console.log('ENTER RECORDED: ' + node.id + ' 进入已记录(enteredNodes)');
|
|
1350
|
-
}
|
|
1351
|
-
// 输出点名(机器点名节点技能):进入节点时机器点名该节点实现技能必须经 Skill 工具加载——
|
|
1352
|
-
// skill 名取节点实现 skill(内置协议 = flow-comet-plan 等,与 SKILL: 行一致)
|
|
1353
|
-
const entryImplSkill = node.implementation && typeof node.implementation === 'object' && node.implementation.skill
|
|
1354
|
-
? node.implementation.skill
|
|
1355
|
-
: null;
|
|
1356
|
-
if (entryImplSkill) {
|
|
1357
|
-
console.log('LOAD SKILL: ' + entryImplSkill + '(用 Skill 工具,禁止跳过)');
|
|
1358
|
-
}
|
|
1359
|
-
console.log('ENTRY OK: ' + node.id);
|
|
154
|
+
await runEntryGates({ protocol, node, state, file });
|
|
1360
155
|
return;
|
|
1361
156
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
if (driftedNodeEvidence) {
|
|
1378
|
-
const derivedNext = await nextNode(protocol, state);
|
|
1379
|
-
const missingDriftArtifacts = await missingRequiredArtifacts(protocol, node, state.activeChange);
|
|
1380
|
-
const missingDriftSchemaEvidence = missingRequiredSchemaEvidence(protocol, node, driftedNodeEvidence);
|
|
1381
|
-
tolerable = !!(
|
|
1382
|
-
derivedNext && derivedNext.id === state.currentNode
|
|
1383
|
-
&& missingDriftArtifacts.length === 0
|
|
1384
|
-
&& missingDriftSchemaEvidence.length === 0
|
|
1385
|
-
);
|
|
1386
|
-
}
|
|
1387
|
-
if (tolerable) {
|
|
1388
|
-
console.log('NOTE: 容错放行——currentNode 已为文件推导下一节点且本节点证据/产物齐(执行者确认本节点实际已完成),exit ' + node.id + ' --apply 补齐欠账(漂移容忍路径)');
|
|
1389
|
-
}
|
|
1390
|
-
if (!tolerable) {
|
|
1391
|
-
console.error('BLOCKED: currentNode is ' + String(state.currentNode) + ', cannot exit ' + node.id + '.');
|
|
1392
|
-
console.error('恢复: 若节点状态漂移/卡死 → 用 workflow-state.mjs advance(强制推进,确认节点实际已完成后再用)或 select(切换 change);禁止手改 state 机器字段');
|
|
1393
|
-
console.error('提示: 若 currentNode 已漂移到文件推导位置且本节点证据/产物齐(执行者确认本节点实际已完成)→ 可用容错 exit ' + node.id + ' --apply 补齐欠账(漂移容忍路径,不再只有不可行的 advance/select 指引);漂移但证据/产物不齐则不适用');
|
|
1394
|
-
process.exit(1);
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
// FIX-BATCH: 越界拦截——源节点(review/verify)驻留,且 TASK 仍有 pending 修复任务,或修复
|
|
1398
|
-
// 任务已 done 但本批 execute 家族生命周期未闭合(本 change 最新家族出口签名 ≠ 当前任务集签名)
|
|
1399
|
-
// 时,直接 exit 源节点收场会静默跳过 execute 家族生命周期与四类出口(缺陷实录形态)。排在 M1/R2
|
|
1400
|
-
// entry 证据门之前:该越界路径给 Fix 恢复指引,避免通用 entry 提示覆盖更具体的归位路径。
|
|
1401
|
-
// 复用共享回退谓词判定:新 change 强制 BLOCKED 含恢复指引;旧 change 渐进 WARN 不阻断。
|
|
1402
|
-
if ((node.id === 'review' || node.id === 'verify') && state.activeChange) {
|
|
1403
|
-
const fixBatchUnclosed = await resolveFixRollbackState({
|
|
1404
|
-
runRoot,
|
|
1405
|
-
changeName: state.activeChange,
|
|
1406
|
-
protocol,
|
|
1407
|
-
completedNodes: state.completedNodes,
|
|
1408
|
-
currentNode: node.id,
|
|
1409
|
-
history: state.history,
|
|
1410
|
-
});
|
|
1411
|
-
if (fixBatchUnclosed && isNewChange(state)) {
|
|
1412
|
-
console.error('BLOCKED: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合(最近一次 execute 家族 exit 后任务集仍有变更),不能直接 exit ' + node.id + ' 收场(会静默跳过 execute 家族生命周期与四类出口)');
|
|
1413
|
-
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');
|
|
1414
|
-
process.exit(1);
|
|
1415
|
-
}
|
|
1416
|
-
if (fixBatchUnclosed) {
|
|
1417
|
-
console.error('FIX-BATCH WARN: 存在未归位/未跑出口的 Fix 批次——' + node.id + ' 驻留且 TASK.md 存在 pending 修复任务,或修复任务已 done 但本批 execute / subagent-execute 生命周期未闭合,直接 exit ' + node.id + ' 会跳过 execute 家族出口门禁(旧 change 渐进不阻断;建议 next/entry execute 家族节点归位跑完出口后回源节点 exit)');
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
// M1/R2: enter 证据检测——未 entry 直接 exit:新 change(init 标记)强制 BLOCKED,旧 change 渐进 WARN
|
|
1421
|
-
// 跳过 entry 会漏掉进入检查(协调者禁令/C4 WORKTREE/PROGRESS/签名记录)
|
|
1422
|
-
if (isNewChange(state)) {
|
|
1423
|
-
if (!Array.isArray(state.enteredNodes) || !state.enteredNodes.includes(node.id)) {
|
|
1424
|
-
console.error('BLOCKED: 节点 ' + node.id + ' 未执行 entry 直接 exit——新 change 强制先 entry(进入检查/协调者禁令/签名记录)');
|
|
1425
|
-
console.error('恢复: 先运行 workflow-guard.mjs entry ' + node.id + ' 再重试 exit;状态漂移 → advance/select');
|
|
1426
|
-
process.exit(1);
|
|
1427
|
-
}
|
|
1428
|
-
} else if (Array.isArray(state.enteredNodes) && !state.enteredNodes.includes(node.id)) {
|
|
1429
|
-
console.error('ENTER WARN: 节点 ' + node.id + ' 未执行 entry 直接 exit——entry 的进入检查(协调者禁令/C4 委托前检查/签名记录)被跳过,请先 entry 该节点再 exit(旧 change 渐进不阻断)');
|
|
1430
|
-
}
|
|
1431
|
-
// E2: exit archive 分支合并检查(WARN 不 BLOCK)——分支未合并到 main 允许"归档先行、合并后补"
|
|
1432
|
-
if (node.id === 'archive' && state.branchMode === true && state.activeChange) {
|
|
1433
|
-
const { execFileSync } = await import('child_process');
|
|
1434
|
-
try {
|
|
1435
|
-
const branch = String(execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' })).trim();
|
|
1436
|
-
const mergedOut = String(execFileSync('git', ['branch', '--merged', 'main'], { cwd: runRoot, stdio: 'pipe', encoding: 'utf8' }));
|
|
1437
|
-
const mergedBranches = mergedOut.split('\n').map(l => l.trim().replace(/^\*\s*/, ''));
|
|
1438
|
-
if (!mergedBranches.includes(branch)) {
|
|
1439
|
-
console.error('WARN: 分支 change/' + state.activeChange + ' 未合并到 main——归档后请完成 merge + 删除分支');
|
|
1440
|
-
}
|
|
1441
|
-
} catch {
|
|
1442
|
-
// git 不可用 / main 不存在 → 跳过合并检查
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
// 特化校验按节点 id 绑定(ADR-002):内置节点 id 触发 flow-kit 契约校验;自定义协议节点不误触发(通用层防线对其生效)
|
|
1446
|
-
// E7: 追加位置结构检测(全部 WARN 不 BLOCK)——防 CONTEXT/LESSONS/STATE/CHANGELOG 文件尾追加破坏插入位置纪律
|
|
1447
|
-
if (node.id === 'open' && state.activeChange) {
|
|
1448
|
-
const contextFile = path.join(runRoot, '.specs', 'CONTEXT.md');
|
|
1449
|
-
try {
|
|
1450
|
-
const content = await fs.readFile(contextFile, 'utf8');
|
|
1451
|
-
const m = content.match(/^## (术语|已锁决策|决策|术语表)[((][^\n]*(?:追加|update)[^\n]*$/im);
|
|
1452
|
-
if (m) {
|
|
1453
|
-
if (isNewChange(state)) {
|
|
1454
|
-
console.error('BLOCKED: CONTEXT.md 检测到孤立追加段(新 change 强制插入既有结构段);恢复: 把内容移入术语表/已锁决策段');
|
|
1455
|
-
process.exit(1);
|
|
1456
|
-
}
|
|
1457
|
-
console.error('WARN: CONTEXT.md 检测到孤立追加段(术语/决策应插入既有结构段):' + m[0].replace(/^##\s*/, '').trim());
|
|
1458
|
-
}
|
|
1459
|
-
} catch {}
|
|
1460
|
-
}
|
|
1461
|
-
if ((node.id === 'verify' || node.id === 'archive') && state.activeChange) {
|
|
1462
|
-
const lessonsFile = path.join(runRoot, '.specs', 'LESSONS.md');
|
|
1463
|
-
try {
|
|
1464
|
-
const content = await fs.readFile(lessonsFile, 'utf8');
|
|
1465
|
-
// 条目区锚点兼容:## 条目区(模板)/ ## 活跃条目 + ## 已解决条目(实际项目结构)——取最早条目段
|
|
1466
|
-
const zoneIndex = (() => {
|
|
1467
|
-
const hits = ['条目区', '活跃条目', '已解决条目']
|
|
1468
|
-
.map(s => content.search(new RegExp('^##\\s*' + s + '\\s*$', 'm')))
|
|
1469
|
-
.filter(i => i !== -1);
|
|
1470
|
-
return hits.length ? Math.min(...hits) : -1;
|
|
1471
|
-
})();
|
|
1472
|
-
const headings = [...content.matchAll(/^###\s*L-(\d+)/gm)];
|
|
1473
|
-
if (zoneIndex !== -1) {
|
|
1474
|
-
const outside = headings.some(h => h.index < zoneIndex);
|
|
1475
|
-
if (outside) {
|
|
1476
|
-
if (isNewChange(state)) {
|
|
1477
|
-
console.error('BLOCKED: LESSONS.md 有条目在条目区外(新 change 强制条目插入条目区);恢复: 移入条目区');
|
|
1478
|
-
process.exit(1);
|
|
1479
|
-
}
|
|
1480
|
-
// 诊断信息附带 zoneIndex/条目位置——偶发 WARN 排查时可直接定位(文件时序/编码差异兜底)
|
|
1481
|
-
console.error('WARN: LESSONS.md 有条目在条目区外(zoneIndex=' + zoneIndex + ', 条目数=' + headings.length + ', 区外条目: ' + headings.filter(h => h.index < zoneIndex).map(h => 'L-' + h[1]).join(',') + ')');
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
const nums = headings.map(h => parseInt(h[1], 10));
|
|
1485
|
-
// 分段检测:按 ## 标题分段,仅同段内比较编号递增(多段 LESSONS 如「活跃条目/已解决条目」编号体系可独立)
|
|
1486
|
-
const sectionStarts = [...content.matchAll(/^##\s+.*$/gm)].map(m => m.index);
|
|
1487
|
-
for (let i = 1; i < nums.length; i++) {
|
|
1488
|
-
const sameSection = !sectionStarts.some(s => s > headings[i - 1].index && s < headings[i].index);
|
|
1489
|
-
if (sameSection && nums[i] <= nums[i - 1]) {
|
|
1490
|
-
if (isNewChange(state)) {
|
|
1491
|
-
console.error('BLOCKED: LESSONS.md 条目编号乱序(新 change 强制按编号插入条目区);恢复: 按 L-NNN 顺序插入');
|
|
1492
|
-
process.exit(1);
|
|
1493
|
-
}
|
|
1494
|
-
console.error('WARN: LESSONS.md 条目编号乱序(L-' + String(nums[i]).padStart(3, '0') + ' 应按序插入条目区)');
|
|
1495
|
-
break;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
} catch {}
|
|
1499
|
-
}
|
|
1500
|
-
if (node.id === 'archive') {
|
|
1501
|
-
const stateMd = path.join(runRoot, 'STATE.md');
|
|
1502
|
-
try {
|
|
1503
|
-
const content = await fs.readFile(stateMd, 'utf8');
|
|
1504
|
-
const dates = [...content.matchAll(/^- `?\[(\d{4}-\d{2}-\d{2})\]/gm)].map(m => m[1]);
|
|
1505
|
-
for (let i = 1; i < dates.length; i++) {
|
|
1506
|
-
if (dates[i] > dates[i - 1]) {
|
|
1507
|
-
if (isNewChange(state)) {
|
|
1508
|
-
console.error('BLOCKED: STATE.md 决策日志非倒序(新 change 强制顶部插入);恢复: 顶部插入新决策');
|
|
1509
|
-
process.exit(1);
|
|
1510
|
-
}
|
|
1511
|
-
console.error('WARN: STATE.md 决策日志非倒序(新决策应插入顶部)');
|
|
1512
|
-
break;
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
} catch {}
|
|
1516
|
-
const changelogFile = path.join(runRoot, '.specs', 'CHANGELOG.md');
|
|
1517
|
-
try {
|
|
1518
|
-
const content = await fs.readFile(changelogFile, 'utf8');
|
|
1519
|
-
const dates = [...content.matchAll(/^\| (\d{4}-\d{2}-\d{2}) \|/gm)].map(m => m[1]);
|
|
1520
|
-
for (let i = 1; i < dates.length; i++) {
|
|
1521
|
-
if (dates[i] > dates[i - 1]) {
|
|
1522
|
-
if (isNewChange(state)) {
|
|
1523
|
-
console.error('BLOCKED: CHANGELOG.md 表格日期非倒序(新 change 强制顶部插入);恢复: 表格顶部插入新条目');
|
|
1524
|
-
process.exit(1);
|
|
1525
|
-
}
|
|
1526
|
-
console.error('WARN: CHANGELOG.md 表格日期非倒序(新条目应插入表格顶部)');
|
|
1527
|
-
break;
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
// 归档收尾登记兜底(WARN 渐进,新旧一致)——CHANGELOG 未含本 change 标识
|
|
1531
|
-
// (change-id)→ 提示补登记,防静默遗漏(实测:提交信息声称已登记但实际未改,
|
|
1532
|
-
// 机制无兜底;检测为存在级——含 change-id 字样即视为已登记)
|
|
1533
|
-
if (state.activeChange && !content.includes(state.activeChange)) {
|
|
1534
|
-
console.error('WARN: CHANGELOG.md 未登记本 change(' + state.activeChange + ')——归档收尾应在 CHANGELOG 顶部插入本 change 条目(跟随项目既有格式)');
|
|
1535
|
-
}
|
|
1536
|
-
} catch {}
|
|
1537
|
-
}
|
|
1538
|
-
// W1-A: 每个节点合法 exit 必须满足前置 evidence(对应 flowkit.*.v1 的 evidence)
|
|
1539
|
-
// 语义与 missingRequiredSchemaEvidence 一致:summary 视同满足(record 命令默认只写 summary)
|
|
1540
|
-
const gate = NODE_TRANSITION_GATES[node.id];
|
|
1541
|
-
if (gate) {
|
|
1542
|
-
for (const ev of gate.evidence) {
|
|
1543
|
-
// subagent-execute 的 handoff-result gate 兼容共用证据库——委托结果记录在
|
|
1544
|
-
// 嵌套 handoffResult(键名契约 handoff-result vs handoffResult 错位),非空即满足
|
|
1545
|
-
// (存在性校验;每个委托内容的 Return Contract 严格校验由 W1-D 负责)
|
|
1546
|
-
const satisfied = hasEvidenceField(evidence, ev) ||
|
|
1547
|
-
(typeof evidence.summary === 'string' && evidence.summary.trim() !== '') ||
|
|
1548
|
-
(node.id === 'subagent-execute' && ev === 'handoff-result' && hasNonEmptyHandoffResult(evidence));
|
|
1549
|
-
if (!satisfied) {
|
|
1550
|
-
console.error('BLOCKED: node ' + node.id + ' exit requires evidence: ' + ev);
|
|
1551
|
-
process.exit(1);
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
// C3: exit execute / subagent-execute 校验 TASK.md 任务集签名未变(status 标记 done 合法已剥离;增删任务/改 action/改边界 BLOCKED)
|
|
1556
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1557
|
-
if (typeof state.taskHash === 'string' && state.taskHash.length > 0) {
|
|
1558
|
-
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
1559
|
-
if (await fileExists(taskFile)) {
|
|
1560
|
-
try {
|
|
1561
|
-
const currentHash = taskSetSignature(await fs.readFile(taskFile, 'utf8'));
|
|
1562
|
-
if (taskSetSignatureVersionSkew(state.taskHash, currentHash)) {
|
|
1563
|
-
// 跨算法版本不做一致性比对(值不可比),不误拦任务集;要强制一致需重新 entry 重建签名
|
|
1564
|
-
const storedAlgo = parseTaskSetSignature(state.taskHash)?.algo ?? 'unknown';
|
|
1565
|
-
console.error('SIGNATURE-ALGO WARN: state.taskHash 算法版本 ' + storedAlgo + ' 与当前任务集签名版本 ' + TASK_SET_SIGNATURE_ALGO + ' 不同——跨版本不做一致性比对,本轮不阻断;如需强制一致请重新 entry execute 家族节点重建签名');
|
|
1566
|
-
} else if (!sameTaskSetSignature(state.taskHash, currentHash)) {
|
|
1567
|
-
console.error('BLOCKED: TASK.md 任务集被修改(签名不匹配),execute 期间不允许增删任务/改 action/改边界');
|
|
1568
|
-
process.exit(1);
|
|
1569
|
-
}
|
|
1570
|
-
} catch {}
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
// open exit 校验 REQUIREMENT 含 AC 段(段名基准从 REQUIREMENT 模板派生,模板缺失 fallback 内置段名)
|
|
1575
|
-
if (node.id === 'open' && state.activeChange) {
|
|
1576
|
-
const reqFile = path.join(runRoot, '.specs', state.activeChange, 'REQUIREMENT.md');
|
|
1577
|
-
try {
|
|
1578
|
-
const content = await fs.readFile(reqFile, 'utf8');
|
|
1579
|
-
const acceptance = (await templateSectionPatterns()).pick('requirement', ['验收'], TEMPLATE_FALLBACK_SECTION_PATTERNS.requirementAcceptance);
|
|
1580
|
-
if (!acceptance.test(content) && !/Given/i.test(content)) {
|
|
1581
|
-
console.error('BLOCKED: REQUIREMENT.md 缺少验收标准/AC 段');
|
|
1582
|
-
process.exit(1);
|
|
1583
|
-
}
|
|
1584
|
-
} catch {}
|
|
1585
|
-
}
|
|
1586
|
-
// design exit 校验 DESIGN 含技术栈段
|
|
1587
|
-
if (node.id === 'design' && state.activeChange) {
|
|
1588
|
-
const designFile = path.join(runRoot, '.specs', state.activeChange, 'DESIGN.md');
|
|
1589
|
-
const designLite = path.join(runRoot, '.specs', state.activeChange, 'DESIGN-lite.md');
|
|
1590
|
-
const target = (await fileExists(designFile)) ? designFile : (await fileExists(designLite)) ? designLite : null;
|
|
1591
|
-
if (target) {
|
|
1592
|
-
try {
|
|
1593
|
-
const content = await fs.readFile(target, 'utf8');
|
|
1594
|
-
if (!/##\s*0[\s.]/.test(content) && !/##\s*技术栈/.test(content)) {
|
|
1595
|
-
console.error('BLOCKED: DESIGN.md 缺少 §0 技术栈段');
|
|
1596
|
-
process.exit(1);
|
|
1597
|
-
}
|
|
1598
|
-
} catch {}
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
// C2: open exit 补必填段校验(结构+存在级,不做语义)——CHANGE.md 含 Why 段;REQUIREMENT.md 含 用户故事 段
|
|
1602
|
-
if (node.id === 'open' && state.activeChange) {
|
|
1603
|
-
const changeDir = path.join(runRoot, '.specs', state.activeChange);
|
|
1604
|
-
// 段名基准从 flow-kit 模板派生(CHANGE 模板 "## Why(为什么做)"、REQUIREMENT 模板 "## 用户故事"),模板缺失 fallback
|
|
1605
|
-
const tpl = await templateSectionPatterns();
|
|
1606
|
-
const required = [
|
|
1607
|
-
['CHANGE.md', tpl.pick('change', ['Why', '为什么'], TEMPLATE_FALLBACK_SECTION_PATTERNS.changeWhy)],
|
|
1608
|
-
['REQUIREMENT.md', tpl.pick('requirement', ['用户故事'], TEMPLATE_FALLBACK_SECTION_PATTERNS.requirementUserStory)],
|
|
1609
|
-
];
|
|
1610
|
-
for (const [file, regex] of required) {
|
|
1611
|
-
const p = path.join(changeDir, file);
|
|
1612
|
-
if (await fileExists(p)) {
|
|
1613
|
-
try {
|
|
1614
|
-
const text = await fs.readFile(p, 'utf8');
|
|
1615
|
-
if (!regex.test(text)) {
|
|
1616
|
-
console.error('BLOCKED: ' + file + ' 缺必填段 ' + regex);
|
|
1617
|
-
process.exit(1);
|
|
1618
|
-
}
|
|
1619
|
-
} catch {}
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
// C2: design exit 补必填段校验——DESIGN.md 含 ## 决策清单(段名基准从 DESIGN 模板派生,"## 1. 决策清单" 编号前缀可选)
|
|
1624
|
-
if (node.id === 'design' && state.activeChange) {
|
|
1625
|
-
const designFile = path.join(runRoot, '.specs', state.activeChange, 'DESIGN.md');
|
|
1626
|
-
const designLite = path.join(runRoot, '.specs', state.activeChange, 'DESIGN-lite.md');
|
|
1627
|
-
const target = (await fileExists(designFile)) ? designFile : (await fileExists(designLite)) ? designLite : null;
|
|
1628
|
-
if (target) {
|
|
1629
|
-
try {
|
|
1630
|
-
const text = await fs.readFile(target, 'utf8');
|
|
1631
|
-
const decisionList = (await templateSectionPatterns()).pick('design', ['决策清单'], TEMPLATE_FALLBACK_SECTION_PATTERNS.designDecisionList);
|
|
1632
|
-
if (!decisionList.test(text)) {
|
|
1633
|
-
console.error('BLOCKED: DESIGN.md 缺必填段 ## 决策清单');
|
|
1634
|
-
process.exit(1);
|
|
1635
|
-
}
|
|
1636
|
-
} catch {}
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
// design 出口 ui-design 工件门(按协议绑定键控:登记 ∧ 等级 = guarded ∧ 判据成立)——见 checkUiDesignArtifact
|
|
157
|
+
// —— 出口校验链(顺序即语义:每条门禁命中即按既有分级 BLOCKED / WARN)——
|
|
158
|
+
const evidence = requireNodeEvidence({ node, state });
|
|
159
|
+
await runExitDriftGate({ protocol, node, state, evidence });
|
|
160
|
+
await runFixBatchExitGate({ protocol, node, state });
|
|
161
|
+
runEntryRecordGate({ node, state });
|
|
162
|
+
await runArchiveBranchMergeGate({ node, state });
|
|
163
|
+
await runContextAppendGate({ node, state });
|
|
164
|
+
await runLessonsZoneGate({ node, state });
|
|
165
|
+
await runArchiveLogOrderGate({ node, state });
|
|
166
|
+
runTransitionEvidenceGate({ node, evidence });
|
|
167
|
+
await runTaskSetSignatureExitGate({ node, state });
|
|
168
|
+
await runRequirementAcGate({ node, state });
|
|
169
|
+
await runDesignStackGate({ node, state });
|
|
170
|
+
await runOpenRequiredSectionsGate({ node, state });
|
|
171
|
+
await runDesignDecisionListGate({ node, state });
|
|
1640
172
|
await checkUiDesignArtifact(node, state);
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
try {
|
|
1651
|
-
// <task> 块提取与属性解析统一走 task-parsing.mjs(开标签语义,属性序无关)
|
|
1652
|
-
const taskList = extractTaskBlocks(content);
|
|
1653
|
-
if (taskList.length === 0) {
|
|
1654
|
-
console.error('BLOCKED: TASK.md 无 <task> 块');
|
|
1655
|
-
process.exit(1);
|
|
1656
|
-
}
|
|
1657
|
-
const missingVerify = taskList.filter(b => !/<verify>/.test(b));
|
|
1658
|
-
if (missingVerify.length > 0) {
|
|
1659
|
-
console.error('BLOCKED: TASK.md 中 ' + missingVerify.length + ' 个 task 缺 <verify> 字段');
|
|
1660
|
-
process.exit(1);
|
|
1661
|
-
}
|
|
1662
|
-
// 波次散文一致性检测: 波次散文一致性检测(WARN 渐进)——## 波次划分 的 Wave 行任务带 [P] 标记
|
|
1663
|
-
// (并行语义)但 XML 任务无 parallel="true" → WARN(散文与机器路由依据不一致,以任务
|
|
1664
|
-
// 标记为准)。容错:无并行语义的 Wave 行不参与比对;解析不到波次段跳过(不误报)。
|
|
1665
|
-
// 段尾判定 = 下一个段标题(\n## )或分隔线(\n---)或**输入末尾**。JS 正则没有 \Z:
|
|
1666
|
-
// \Z 是「未知转义 ⇒ 字面字符 Z」,惰性匹配一遇段内大写 Z 就提前收尾,段被静默截断
|
|
1667
|
-
// (含 ZERO- 一类机检标记的 TASK 会整段漏检)。串尾一律用 (?![\s\S]) 真断言——
|
|
1668
|
-
// 它只是「此处之后已无任何字符」,不受行首/行尾标志影响,与「多行模式下的 $」语义无歧义。
|
|
1669
|
-
const waveSection = content.match(/##\s*波次划分\s*\n([\s\S]*?)(?=\n##\s|\n---|(?![\s\S]))/);
|
|
1670
|
-
if (waveSection) {
|
|
1671
|
-
const proseParallelIds = [];
|
|
1672
|
-
for (const line of waveSection[1].split('\n')) {
|
|
1673
|
-
if (!/(Wave|\d+\s*波|parallel|并行)/i.test(line)) continue; // 无并行语义行跳过
|
|
1674
|
-
for (const m of line.matchAll(/([A-Z][A-Z0-9-]*)\[P\]/g)) proseParallelIds.push(m[1]);
|
|
1675
|
-
}
|
|
1676
|
-
if (proseParallelIds.length > 0) {
|
|
1677
|
-
const xmlParallelIds = taskList
|
|
1678
|
-
.filter(b => { const a = taskOpeningAttrs(b); return a && a.parallel; })
|
|
1679
|
-
.map(b => (taskOpeningAttrs(b) || {}).id)
|
|
1680
|
-
.filter(Boolean);
|
|
1681
|
-
const missing = proseParallelIds.filter(id => !xmlParallelIds.includes(id));
|
|
1682
|
-
if (missing.length > 0) {
|
|
1683
|
-
if (isNewChange(state)) {
|
|
1684
|
-
console.error('BLOCKED: 波次散文标记任务为并行([P])但任务无 parallel="true"(新 change 强制散文与任务标记一致);恢复: 对齐散文或任务标记');
|
|
1685
|
-
process.exit(1);
|
|
1686
|
-
}
|
|
1687
|
-
console.error('WARN: 波次散文标记为并行([P])但任务无 parallel="true"——散文与任务标记不一致(以任务标记为准): ' + missing.join(', '));
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
// 波次分组校验重定义(依赖图校验决策 · 混排合法化):原「并行块必须单个连续且居首/尾」形态约束废除——
|
|
1692
|
-
// 串行任务位置不再受限,串→并→串 / 并→串→并 / 多波混合均合法(多趟循环路由按依赖拓扑分趟)。
|
|
1693
|
-
// 改为依赖图校验:① 全部任务建依赖图(deps 边)做 Kahn 拓扑排序判环——有环即规划结构性死锁;
|
|
1694
|
-
// ② 全部引用的任务 id 必须存在(无环图下「每个 parallel 任务的全部传递依赖存在且非环」
|
|
1695
|
-
// ⟺ 直接引用都存在)。违规分级:新 change BLOCKED(含「依赖环」/缺失依赖明细 + depends_on
|
|
1696
|
-
// 调整恢复指引);旧 change 渐进 WARN 不阻断。波次散文一致性检测保留不动(与形态约束正交的既有独立检测,维持不变)。
|
|
1697
|
-
const depGraph = analyzeDependencyGraph(taskList);
|
|
1698
|
-
if (depGraph.cyclic || depGraph.missing.length > 0) {
|
|
1699
|
-
const detail = depGraph.cyclic
|
|
1700
|
-
? '依赖环(拓扑排序无解,涉及任务: ' + depGraph.cycleIds.join(', ') + ')'
|
|
1701
|
-
: '依赖不存在的任务: ' + depGraph.missing.map((m) => m.id + '→' + m.dep).join(', ');
|
|
1702
|
-
const guide = ';恢复: 调整任务 depends_on——移除成环引用或改为真实存在的任务 id 后重试';
|
|
1703
|
-
if (isNewChange(state)) {
|
|
1704
|
-
console.error('BLOCKED: TASK.md ' + detail + '——依赖图不可满足(任务的依赖链必须存在且无环)' + guide);
|
|
1705
|
-
process.exit(1);
|
|
1706
|
-
}
|
|
1707
|
-
console.error('WARN: TASK.md ' + detail + '——依赖图不可满足(旧 change 渐进不阻断)' + guide);
|
|
1708
|
-
}
|
|
1709
|
-
// 伪并行检测(真实载体验证暴露的设计盲区兜底):如果一个标记为并行的任务只写测试文件
|
|
1710
|
-
// 而无任何生产代码文件,它很可能隐式依赖某个实现类并行任务的产出(如测试 import
|
|
1711
|
-
// 尚未存在的函数)。这种"伪并行"在多趟路由下会导致委托后测试失败。
|
|
1712
|
-
// 启发式:并行任务的 write_files 全部匹配 tests/ 或 test_ 前缀 → 视为疑似伪并行。
|
|
1713
|
-
// WARN 渐进不阻断——由执行者判断是否真独立(纯测试基础设施改动可合法全测试面)。
|
|
1714
|
-
const testOnlyParallelIds = [];
|
|
1715
|
-
for (const block of taskList) {
|
|
1716
|
-
const attrs = taskOpeningAttrs(block);
|
|
1717
|
-
if (!attrs || !attrs.parallel || attrs.status !== 'pending') continue;
|
|
1718
|
-
const wfMatch = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
1719
|
-
if (!wfMatch) continue;
|
|
1720
|
-
// 分号容错:与 workflow-handoff.mjs 自动解析同源实现(分号容错双点内联,与 workflow-handoff.mjs 同源互锚)——
|
|
1721
|
-
// 换行切分后逐段按 ';' 二次切分、trim、滤空与 HTML 注释行(路径含分号的极端形态不支持,须换行书写)
|
|
1722
|
-
const blockContent = wfMatch[1].replace(/<!--[\s\S]*?-->/g, '');
|
|
1723
|
-
const filePaths = blockContent.trim().split(/\s*\n\s*/).map(l => l.trim()).filter(Boolean)
|
|
1724
|
-
.flatMap(l => l.split(';')).map(l => l.trim()).filter(Boolean);
|
|
1725
|
-
if (filePaths.length === 0) continue;
|
|
1726
|
-
const prodFiles = filePaths.filter(f => !/(?:^|[\/\\])(?:__tests__\/|test_|tests?\/)|\.(?:test|spec)\.(?:mjs|js|jsx|ts|tsx|cjs)$/.test(f));
|
|
1727
|
-
if (prodFiles.length === 0) {
|
|
1728
|
-
testOnlyParallelIds.push(attrs.id || 'unknown');
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
if (testOnlyParallelIds.length > 0) {
|
|
1732
|
-
console.error('WARN: 伪并行检测——以下并行任务仅写测试文件而无生产代码文件: '
|
|
1733
|
-
+ testOnlyParallelIds.join(', ')
|
|
1734
|
-
+ '。测试通常依赖实现产出的符号,可能存在隐式依赖;建议添加 depends_on 声明或合并为垂直切片');
|
|
1735
|
-
}
|
|
1736
|
-
// 并行文件依赖检测前移(触发面):write∩write 写写强判(新 change BLOCKED / 旧 change
|
|
1737
|
-
// WARN 渐进,与依赖环分级同先例)+ read∩write 读写弱判(仅无显式 depends_on 关联的并行对;
|
|
1738
|
-
// WARN 提示级,新/旧均不 BLOCK——渐进提示)+ 同文件跨任务且无依赖路径(未完成任务写入面
|
|
1739
|
-
// 重叠而两任务间无依赖路径——新 change BLOCKED / 旧 change WARN 渐进;串行拆分同样命中,
|
|
1740
|
-
// 修复任务族不参与,族语义见 route-node 判定块注释)。与委托前既有拦截并存(委托前为第二道
|
|
1741
|
-
// 写写锚,行为与消息保持既有语义不变)。
|
|
1742
|
-
const { writeConflicts, readWarnings, crossTaskConflicts } = await findParallelWriteConflicts(path.join(runRoot, '.specs', state.activeChange));
|
|
1743
|
-
if (writeConflicts.length > 0) {
|
|
1744
|
-
const detail = writeConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1745
|
-
const guide = ';恢复: 补显式 depends_on 或拆为串行任务后重试';
|
|
1746
|
-
if (isNewChange(state)) {
|
|
1747
|
-
console.error('BLOCKED: TASK.md 并行任务 write_files 重叠(写写冲突,同波次并行会竞态覆盖): ' + detail + guide);
|
|
1748
|
-
process.exit(1);
|
|
1749
|
-
}
|
|
1750
|
-
console.error('WARN: TASK.md 并行任务 write_files 重叠(写写冲突,建议补显式 depends_on 或拆为串行任务): ' + detail + guide);
|
|
1751
|
-
}
|
|
1752
|
-
if (crossTaskConflicts.length > 0) {
|
|
1753
|
-
const detail = crossTaskConflicts.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; ');
|
|
1754
|
-
const guide = ';恢复: 补显式 depends_on 或合并为一个任务后重试';
|
|
1755
|
-
if (isNewChange(state)) {
|
|
1756
|
-
console.error('BLOCKED: TASK.md 同文件跨任务且无依赖路径: ' + detail + guide);
|
|
1757
|
-
process.exit(1);
|
|
1758
|
-
}
|
|
1759
|
-
console.error('WARN: TASK.md 同文件跨任务且无依赖路径(建议补显式 depends_on 或合并为一个任务): ' + detail + guide);
|
|
1760
|
-
}
|
|
1761
|
-
if (readWarnings.length > 0) {
|
|
1762
|
-
console.error('WARN: TASK.md 并行任务 read∩write 隐式依赖嫌疑(一方读取对方写路径,建议补显式 depends_on 声明): '
|
|
1763
|
-
+ readWarnings.map((c) => `${c.a}×${c.b}(${c.files.join(',')})`).join('; '));
|
|
1764
|
-
}
|
|
1765
|
-
} catch (judgeError) {
|
|
1766
|
-
console.error('BLOCKED: TASK.md 文件依赖判据未执行: '
|
|
1767
|
-
+ (judgeError && judgeError.message ? judgeError.message : String(judgeError))
|
|
1768
|
-
+ '——门禁无法完成校验,按 fail-closed 拒绝通过(未验证 ≠ 通过)');
|
|
1769
|
-
process.exit(1);
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
// review exit 校验 REVIEW 含实质内容 + 发现区条目处置状态结构级校验
|
|
1774
|
-
if (node.id === 'review' && state.activeChange) {
|
|
1775
|
-
const reviewFile = path.join(runRoot, '.specs', state.activeChange, 'REVIEW.md');
|
|
1776
|
-
try {
|
|
1777
|
-
const stat = await fs.stat(reviewFile);
|
|
1778
|
-
if (stat.size < 100) {
|
|
1779
|
-
console.error('BLOCKED: REVIEW.md 内容不足(' + stat.size + ' 字节,需 ≥ 100)');
|
|
1780
|
-
process.exit(1);
|
|
1781
|
-
}
|
|
1782
|
-
// 发现项(含 Minor)须有处置状态标记——[已修](对应 fix 任务)/ [升级](用户决策:
|
|
1783
|
-
// 接受+理由)/ [转待办](归档时进 KNOWN-ISSUES)。结构级校验,WARN 渐进不 BLOCK:
|
|
1784
|
-
// 旧 REVIEW 未按新格式写标记只警告不阻断(防旧 REVIEW 卡死),执行者补标记后可消除。
|
|
1785
|
-
const reviewText = await fs.readFile(reviewFile, 'utf8');
|
|
1786
|
-
const missingDisposition = reviewFindingsMissingDisposition(reviewText);
|
|
1787
|
-
if (missingDisposition.length > 0) {
|
|
1788
|
-
if (isNewChange(state)) {
|
|
1789
|
-
console.error('BLOCKED: REVIEW.md 发现区 ' + missingDisposition.length + ' 项条目缺处置状态标记([已修]/[升级]/[转待办])——新 change 强制每项发现须有处置');
|
|
1790
|
-
console.error('恢复: 为发现区条目补处置标记后重试;未处置的发现(含 Minor)不应无声消失');
|
|
1791
|
-
process.exit(1);
|
|
1792
|
-
}
|
|
1793
|
-
console.error('REVIEW WARN: REVIEW.md 发现区 ' + missingDisposition.length +
|
|
1794
|
-
' 项条目缺处置状态标记([已修]/[升级]/[转待办]): ' + missingDisposition.join('、') +
|
|
1795
|
-
'——未处置的发现(含 Minor)不应无声消失,补标记后本警告消除(渐进不阻断)');
|
|
1796
|
-
}
|
|
1797
|
-
// Major 延期裁决门禁:Major 的处置是用户决策点——reviewer 不得自行 [转待办]。结构校验:
|
|
1798
|
-
// Major 条目标 [转待办] 时须同时存在用户裁决记录(同段或文末含「用户裁决:接受延期」
|
|
1799
|
-
// 且指向该条目,并由 [升级] 承接);缺失 → 新 change BLOCKED / 旧 change WARN 渐进。
|
|
1800
|
-
// Minor 不受影响;Major [升级]/[已修] 直接放行。
|
|
1801
|
-
const deferredMajor = reviewDeferredMajorProblems(reviewText);
|
|
1802
|
-
if (deferredMajor.length > 0) {
|
|
1803
|
-
const guide = ';恢复: 先把 Major 改为 [升级] 交用户裁决;用户接受延期后在同段或文末记录「用户裁决:接受延期」并指向该条目(由 [升级] 承接)';
|
|
1804
|
-
if (isNewChange(state)) {
|
|
1805
|
-
console.error('BLOCKED: REVIEW.md 发现区 ' + deferredMajor.length + ' 项 Major 条目为 [转待办] 但缺少用户裁决记录(Major 不得由 reviewer 自行转待办): ' + deferredMajor.join('、') + guide);
|
|
1806
|
-
process.exit(1);
|
|
1807
|
-
}
|
|
1808
|
-
console.error('REVIEW WARN: REVIEW.md 发现区 ' + deferredMajor.length +
|
|
1809
|
-
' 项 Major 条目为 [转待办] 但缺少用户裁决记录: ' + deferredMajor.join('、') +
|
|
1810
|
-
'——Major 不得由 reviewer 自行转待办' + guide + '(渐进不阻断)');
|
|
1811
|
-
}
|
|
1812
|
-
} catch {}
|
|
1813
|
-
}
|
|
1814
|
-
// W3: directOverride 授权约束(direct 是用户决策点,不可自决——机制约束)——
|
|
1815
|
-
// execute / subagent-execute 出口校验:executionMode=direct 且 directOverride=true(显式
|
|
1816
|
-
// 直显授权态)须存在授权审计记录(directOverrideAt/来源,由 workflow-state execution-mode
|
|
1817
|
-
// 命令在协调者显式授权时写入)——否则 BLOCKED + 恢复指引(协调者显式授权 / 回 subagent)。
|
|
1818
|
-
// 旧 state 缺省(directOverride=false / 缺字段)放行(前向兼容——未处于显式 direct 不受影响)。
|
|
1819
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
1820
|
-
const directMode = state.executionMode ?? 'subagent';
|
|
1821
|
-
if (directMode === 'direct' && state.directOverride === true) {
|
|
1822
|
-
const hasAuditRecord = typeof state.directOverrideAt === 'string'
|
|
1823
|
-
&& state.directOverrideAt.trim() !== '';
|
|
1824
|
-
if (!hasAuditRecord) {
|
|
1825
|
-
console.error('BLOCKED: executionMode=direct 且 directOverride=true 但无授权审计记录(direct 是用户决策点,不可自决——须存在授权留痕 directOverrideAt/来源,由协调者显式 execution-mode direct 写入)');
|
|
1826
|
-
console.error('恢复: 由协调者执行 workflow-state.mjs execution-mode direct 显式授权(写入授权审计记录)后重试 exit;或 execution-mode subagent 切回(清除 directOverride)后重试 exit;禁止手改 state 机器字段');
|
|
1827
|
-
process.exit(1);
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
// W1-E: 验证隔离「同一时刻只有一个写者」出口校验(AC-8 · 判级决策见 ADR-014)——读
|
|
1832
|
-
// state.evidence['subagent-execute'].handoffRequests:存在条目且**至少一个无对应 handoffResult**
|
|
1833
|
-
// ⇒ 在飞委托(写者未收工,跑全量判据会被未提交中间态污染):新 change BLOCKED(含恢复指引
|
|
1834
|
-
// 「待写入者收工后重跑 / 已作废则撤回」)/ 旧 change WARN 渐进;全部有对应 result ⇒ 放行;
|
|
1835
|
-
// 已撤回(withdrawnAt + withdrawnBy 齐备)的 request 不构成在飞委托 ⇒ 放行;无该证据对象 ⇒ 零输出。
|
|
1836
|
-
// 落点 = 出口校验流(与其余 violations / WARN 同风格,不新增独立命令面);判据经
|
|
1837
|
-
// inFlightHandoffRequests 单处求值(与 W1-D 的 result 侧契约校验正交,不重复判定)。
|
|
1838
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1839
|
-
const inFlight = inFlightHandoffRequests(state.evidence?.['subagent-execute']);
|
|
1840
|
-
if (inFlight.length > 0) {
|
|
1841
|
-
const inFlightDetail = '存在在飞委托(handoffRequests 有 request 无对应 handoffResult): '
|
|
1842
|
-
+ inFlight.join(', ') + '——验证隔离要求同一时刻只有一个写者(写者未收工)';
|
|
1843
|
-
if (isNewChange(state)) {
|
|
1844
|
-
console.error('BLOCKED: ' + inFlightDetail);
|
|
1845
|
-
console.error('恢复: 待写入者收工后重跑——子代理回传后用 workflow-handoff.mjs result <task-id> <Return Contract> 记录结果再重试 exit;若该委托已作废(零提交复验失败 / 写边界被拒后遗弃),用 workflow-handoff.mjs withdraw <task-id> --by <来源> [--reason <原因>] 撤回后再重试 exit(撤回留痕 withdrawnAt/withdrawnBy,已撤回 = 终态,历史不删)');
|
|
1846
|
-
process.exit(1);
|
|
1847
|
-
}
|
|
1848
|
-
console.error('WARN: ' + inFlightDetail + '(旧 change 渐进不阻断;待写入者收工后重跑全量判据;已作废的委托可用 workflow-handoff.mjs withdraw <task-id> --by <来源> 撤回)');
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
// W1-B: execute / subagent-execute 出口校验每份 SUMMARY 含三个必填段 + 6 维自查非空 + 自检方法
|
|
1852
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
1853
|
-
const changeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
1854
|
-
const violations = await verifySummaries(changeDir);
|
|
1855
|
-
// brooks-lint 自检方法审计:检查 6 维自查段是否声明了自检方法
|
|
1856
|
-
const summaryFiles = (await fs.readdir(changeDir).catch(() => [])).filter(f => f.endsWith('-SUMMARY.md'));
|
|
1857
|
-
for (const f of summaryFiles) {
|
|
1858
|
-
try {
|
|
1859
|
-
const content = await fs.readFile(path.join(changeDir, f), 'utf8');
|
|
1860
|
-
// 段终止 lookahead 用 \n##\s(而非 \n##):###/#### 级子标题(如 "### 🟢 R1")是段内内容,不是段结束
|
|
1861
|
-
// 段尾同样 = 段标题 / 分隔线 / 输入末尾;末尾一律写 (?![\s\S]),不得写 \Z
|
|
1862
|
-
// (JS 无 \Z——它是「字面字符 Z」,且本正则带 i 标志,连小写 z 都会命中,段被静默截断)
|
|
1863
|
-
const sixDim = content.match(/##\s*6\s*维自查[\s\S]*?(?=\n##\s|\n---|(?![\s\S]))/i);
|
|
1864
|
-
// C1: 6 维自查段非空——去掉所有标题行后剩余实质内容 ≥ 10 字符
|
|
1865
|
-
// 按行过滤标题(/^\s*#/)比正则替换稳健:任何标题格式(emoji 🟢/中英文/数字)都不计入内容
|
|
1866
|
-
const dimBody = sixDim ? sixDim[0].split('\n').filter(l => !/^\s*#/.test(l)).join('').trim() : '';
|
|
1867
|
-
if (sixDim && dimBody.length < 10) {
|
|
1868
|
-
violations.push(f + ' 的 6 维自查段无实质内容');
|
|
1869
|
-
}
|
|
1870
|
-
// 生产代码任务必填 ## 自检方法,声明 brooks-review 或 builtin-quickcheck
|
|
1871
|
-
// 格式兼容:方法名行允许中文前缀/括号说明(如 "方法:brooks-review"),按关键词搜索而非 [a-z-]+ 硬匹配
|
|
1872
|
-
// 段名允许带括号后缀(如 "## 自检方法(声明 brooks-review 或 builtin-quickcheck)"——括号为说明非段名部分,
|
|
1873
|
-
// 执行者常按模板标题原样书写导致旧正则不匹配落入"旧格式 WARN";括号后缀与段名等价)
|
|
1874
|
-
// 分隔符用 .?(任意字符)而非 \.?(字面点):canonical 名 "brooks-review"/"builtin-quickcheck" 是连字符,与既有 /brooks.?review/ 约定一致
|
|
1875
|
-
// 真实项目端到端验证实证:方法名可能在段内后续行(子代理列表写法)——段内全文搜索而非仅第一行
|
|
1876
|
-
// 段内容截取到下一个段标题(\n## )或分隔线(\n---)或文件尾(split 处理,避免 JS 无 \Z 的问题)
|
|
1877
|
-
const methodMatch = content.match(/##\s*自检方法(?:[((][^))\n]*[))])?\s*\n([\s\S]*)/i);
|
|
1878
|
-
const methodSection = methodMatch ? methodMatch[1].split(/\n##\s|\n---/)[0] : null;
|
|
1879
|
-
const method = methodSection ? /brooks.?review|cache.?brooks|builtin.?quickcheck/i.exec(methodSection) : null;
|
|
1880
|
-
if (!method) {
|
|
1881
|
-
// 过渡规则:旧格式 SUMMARY 无 ## 自检方法 段——
|
|
1882
|
-
// 若全文已声明 brooks-review/cache-brooks/builtin(旧模板行为),WARN 兼容不 BLOCKED;无任何自检声明才 BLOCKED
|
|
1883
|
-
if (/brooks.?review|cache.?brooks|builtin.?quickcheck/i.test(content)) {
|
|
1884
|
-
if (isNewChange(state)) {
|
|
1885
|
-
violations.push(f + ' 缺 ## 自检方法 段(新 change 强制声明自检方法)');
|
|
1886
|
-
} else {
|
|
1887
|
-
console.error('BROOKS-LINT WARN: ' + f + ' 缺 ## 自检方法 段(旧格式),6 维自查已声明自检方法——兼容通过,建议补全');
|
|
1888
|
-
}
|
|
1889
|
-
} else {
|
|
1890
|
-
violations.push(f + ' 缺 ## 自检方法 字段(必须声明 brooks-review 或 builtin-quickcheck)');
|
|
1891
|
-
}
|
|
1892
|
-
} else if (/builtin/i.test(method[0])) {
|
|
1893
|
-
// builtin 降级两级校验——① 必须声明不可用原因(既有);② 必须含缓存尝试证据
|
|
1894
|
-
// (已尝试 Read 插件缓存协议文件手动执行仍不可行——两级降级路径第 2 级;防「未尝试读缓存」的偷懒降级)
|
|
1895
|
-
// 关键词声明级校验(设计边界:不做语义判断);缺失 → WARN 渐进(不 BLOCK,向后兼容旧 SUMMARY)
|
|
1896
|
-
if (!/brooks-lint 不可用|插件不可用|unavailable|N\/A/i.test(content)) {
|
|
1897
|
-
if (isNewChange(state)) {
|
|
1898
|
-
console.error('BLOCKED: SUMMARY 使用 builtin-quickcheck 未声明 brooks-lint 不可用原因(新 change 强制);恢复: 在 ## 自检方法 段补原因(声明级校验——须含关键词: brooks-lint 不可用 / 插件不可用 / unavailable / N/A,如「brooks-lint 不可用(Skill 仅返回占位,插件执行体未加载)」)');
|
|
1899
|
-
process.exit(1);
|
|
1900
|
-
}
|
|
1901
|
-
console.error('BROOKS-LINT WARN: ' + f + ' 使用 builtin-quickcheck 但未声明 brooks-lint 不可用原因');
|
|
1902
|
-
} else if (!/插件缓存|缓存协议|协议文件|plugins\/cache/i.test(content)) {
|
|
1903
|
-
if (isNewChange(state)) {
|
|
1904
|
-
console.error('BLOCKED: SUMMARY 使用 builtin-quickcheck 未声明缓存尝试证据(新 change 强制先 Read 插件缓存协议文件);恢复: 在 ## 自检方法 段声明缓存尝试(须含关键词: 插件缓存 / 缓存协议 / 协议文件 / plugins/cache,如「已 Read 插件缓存协议文件(~/.claude/plugins/cache/...)手动执行仍不可行」)');
|
|
1905
|
-
process.exit(1);
|
|
1906
|
-
}
|
|
1907
|
-
console.error('BROOKS-LINT WARN: ' + f + ' 使用 builtin-quickcheck 但未声明缓存尝试证据(应先 Read 插件缓存协议文件手动执行完整 brooks 流程)');
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
if (sixDim && !/brooks.?review|cache.?brooks/i.test(sixDim[0])) {
|
|
1911
|
-
if (isNewChange(state)) {
|
|
1912
|
-
console.error('BLOCKED: SUMMARY 的 6 维自查未声明使用 /brooks-review(新 change 强制声明自检方法);恢复: 在 6 维自查段声明 /brooks-review 或理由');
|
|
1913
|
-
process.exit(1);
|
|
1914
|
-
}
|
|
1915
|
-
console.error('BROOKS-LINT WARN: ' + f + ' 的 6 维自查未声明使用 /brooks-review(可能使用了内置快查)');
|
|
1916
|
-
}
|
|
1917
|
-
} catch {}
|
|
1918
|
-
}
|
|
1919
|
-
if (violations.length > 0) {
|
|
1920
|
-
console.error('BLOCKED: SUMMARY 关键段校验失败: ' + violations.join('; '));
|
|
1921
|
-
process.exit(1);
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
// execute 出口空退出豁免(M6 收窄)——豁免仅适用于「无任何串行任务」的全并行 change;
|
|
1925
|
-
// 含串行任务(parallel!=="true",缺省串行——与 task-parsing.mjs 同语义)时豁免不生效,
|
|
1926
|
-
// 后续产物校验照常执行(陈旧 emptyExitApproved 不得静默放行)。
|
|
1927
|
-
// 判据单一来源:evidence 谓词只在此处求值一次,execute 出口块与 M6 共用(L-067)。
|
|
173
|
+
await runPlanExitGate({ protocol, node, state });
|
|
174
|
+
await runReviewExitGate({ node, state });
|
|
175
|
+
runDirectOverrideGate({ node, state });
|
|
176
|
+
runInFlightHandoffGate({ node, state });
|
|
177
|
+
await runSummarySectionsGate({ node, state });
|
|
178
|
+
// execute 出口空退出豁免(豁免仅适用于「无任何串行任务」的全并行 change;含串行任务
|
|
179
|
+
// (parallel!=="true",缺省串行——与 task-parsing.mjs 同语义)时豁免不生效,后续产物校验照常
|
|
180
|
+
// 执行——陈旧标记不得静默放行)。判据单一来源:evidence 谓词只在此处求值一次,execute 出口
|
|
181
|
+
// 门禁与产物门禁共用。
|
|
1928
182
|
const executeEmptyExitApproved = node.id === 'execute' && !!(state.evidence?.execute?.emptyExitApproved);
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
executeEmptyExitExempt = true;
|
|
1953
|
-
console.error('EMPTY-EXIT: execute 空退出豁免已生效(evidence.execute.emptyExitApproved)——审计记录:该 change 在无串行任务时显式豁免空退出');
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
// serialPending 收窄为「可运行串行」(出口拦截集合收窄):仅 deps ⊆ doneIds 的
|
|
1957
|
-
// 未完成串行计入拦截——deps 未满足的串行 pending 是等后续波次的合法中间态,放行由多趟
|
|
1958
|
-
// 路由按依赖拓扑分趟驱动。doneIds 就地派生;deps 提取复用 taskDependsOn(<depends_on>
|
|
1959
|
-
// 内容按 [,\s]+ 切分,与路由谓词同一解析口径),不新增状态。
|
|
1960
|
-
const doneIds = new Set(tasks.filter(t => t.status === 'done').map(t => t.id));
|
|
1961
|
-
const blockById = new Map();
|
|
1962
|
-
for (const block of taskList) {
|
|
1963
|
-
const a = taskOpeningAttrs(block);
|
|
1964
|
-
if (a && a.id) blockById.set(a.id, block);
|
|
1965
|
-
}
|
|
1966
|
-
const serialRunnable = tasks.filter(t =>
|
|
1967
|
-
!t.parallel && t.status === 'pending'
|
|
1968
|
-
&& taskDependsOn(blockById.get(t.id) || '').every(d => doneIds.has(d)));
|
|
1969
|
-
if (serialRunnable.length > 0) {
|
|
1970
|
-
console.error('BLOCKED: execute 出口仍有串行 pending 任务: ' + serialRunnable.map(t => t.id).join(', ')
|
|
1971
|
-
+ '——空退出豁免不适用于存在未完成可运行串行任务的情况(先完成该串行任务,或修正任务标记)'
|
|
1972
|
-
+ ';无可执行的常规恢复动作时,可用 workflow-state.mjs advance 渡过结构性死结(逃生口:使用后本节点须重新 entry 并重做交付记录);常规缺产物/缺证据情形不适用');
|
|
1973
|
-
process.exit(1);
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
// done 任务 ↔ SUMMARY 完整性: done 任务 ↔ <id>-SUMMARY.md 存在(WARN 渐进不 BLOCK——防旧 change 卡死;
|
|
1977
|
-
// 结构级校验与 TASK 签名同源:任务完成声明须有对应产物)
|
|
1978
|
-
// M2: 新 change(enter 机制激活)升级为 BLOCKED——执行遗漏(声称完成但无产物)不静默进归档;旧 change 保持渐进
|
|
1979
|
-
const ki8ChangeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
1980
|
-
for (const tid of tasks.filter(t => t.status === 'done').map(t => t.id)) {
|
|
1981
|
-
if (!(await fileExists(path.join(ki8ChangeDir, tid + '-SUMMARY.md')))) {
|
|
1982
|
-
if (isNewChange(state)) {
|
|
1983
|
-
console.error('BLOCKED: done 任务 ' + tid + ' 缺少 ' + tid + '-SUMMARY.md——execute 产物不完整(新 change 强制任务完成须有对应 SUMMARY;旧 change 渐进 WARN)');
|
|
1984
|
-
console.error('恢复: 补写 ' + tid + '-SUMMARY.md 后重试 exit;任务完成后补产物即可');
|
|
1985
|
-
process.exit(1);
|
|
1986
|
-
}
|
|
1987
|
-
console.error('WARN: done 任务 ' + tid + ' 缺少 ' + tid + '-SUMMARY.md——execute 产物不完整(任务完成须有对应 SUMMARY)');
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
|
|
1991
|
-
// 豁免机制:evidence(当前节点 execute)含 parallelTakeoverApproved: true 时跳过越俎代庖检测(只保留串行 pending 检测)
|
|
1992
|
-
const executeEvidence = state.evidence['execute'];
|
|
1993
|
-
const takeoverApproved = !!(executeEvidence && executeEvidence.parallelTakeoverApproved);
|
|
1994
|
-
|
|
1995
|
-
if (!takeoverApproved) {
|
|
1996
|
-
// 越俎代庖检测按 executionMode 分支:
|
|
1997
|
-
// - direct(逃生口):串行任务主代理直写,不需 handoff;parallel 仍必须委托(防 execute 吞 parallel 回归)
|
|
1998
|
-
// - subagent(默认):所有 done 任务需 handoff(统一委托下只能由子代理完成)
|
|
1999
|
-
const executionMode = state.executionMode ?? 'subagent';
|
|
2000
|
-
const he = state.evidence['subagent-execute'];
|
|
2001
|
-
const results = he && he.handoffResult ? he.handoffResult : {};
|
|
2002
|
-
let unauthorized;
|
|
2003
|
-
if (executionMode === 'direct') {
|
|
2004
|
-
unauthorized = tasks.filter(t => t.parallel && t.status === 'done' && !results[t.id]);
|
|
2005
|
-
} else {
|
|
2006
|
-
unauthorized = tasks.filter(t => t.status === 'done' && !results[t.id]);
|
|
2007
|
-
}
|
|
2008
|
-
if (unauthorized.length > 0) {
|
|
2009
|
-
console.error('BLOCKED: 任务被主代理直接标记 done(越俎代庖)' + (executionMode === 'direct' ? ',direct 模式下 parallel 任务仍必须委托子代理' : ',统一委托下只能由子代理完成并记录 handoff') + ': ' + unauthorized.map(t => t.id).join(', '));
|
|
2010
|
-
console.error('解决: 回退这些任务的 done 标记,重新委托子代理;或用 workflow-state.mjs record execute \'{"parallelTakeoverApproved":true}\' 显式豁免');
|
|
2011
|
-
process.exit(1);
|
|
2012
|
-
}
|
|
2013
|
-
// parallel 仍 pending → 合法(下一步 determineNode 路由到 subagent-execute)
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
// 越权委托检测(execute 出口): 越权委托检测(execute 出口第一道)——TASK 有 parallel done 任务 +
|
|
2017
|
-
// completedNodes 无 subagent-execute + 非 direct 模式 + 协议含 subagent-execute 节点
|
|
2018
|
-
// → WARN 渐进([P] 任务应由 subagent-execute 节点委托——execute 阶段完成 [P] 是
|
|
2019
|
-
// 越权委托痕迹;handoff 记录存在但节点未 exit——上轮真实项目端到端验证实证)
|
|
2020
|
-
const ki10ParallelDone = tasks.filter(t => t.parallel && t.status === 'done').map(t => t.id);
|
|
2021
|
-
const ki10ProtocolHasSubagent = (protocol.nodes ?? []).some(n => n.id === 'subagent-execute');
|
|
2022
|
-
if (ki10ParallelDone.length > 0
|
|
2023
|
-
&& !(state.completedNodes ?? []).includes('subagent-execute')
|
|
2024
|
-
&& (state.executionMode ?? 'subagent') !== 'direct'
|
|
2025
|
-
&& !takeoverApproved
|
|
2026
|
-
&& ki10ProtocolHasSubagent) {
|
|
2027
|
-
if (isNewChange(state)) {
|
|
2028
|
-
console.error('BLOCKED: TASK 有 parallel done 任务(' + ki10ParallelDone.join(', ')
|
|
2029
|
-
+ ')但 subagent-execute 节点未 exit——新 change 强制 [P] 任务由 subagent-execute 节点委托');
|
|
2030
|
-
console.error('恢复: 经 subagent-execute 节点完成委托后再 exit;或说明越权委托原因');
|
|
2031
|
-
process.exit(1);
|
|
2032
|
-
}
|
|
2033
|
-
console.error('WARN: TASK 有 parallel done 任务(' + ki10ParallelDone.join(', ')
|
|
2034
|
-
+ ')但 subagent-execute 节点未 exit——疑似 execute 阶段越权委托,[P] 任务应由 subagent-execute 节点委托');
|
|
2035
|
-
}
|
|
2036
|
-
} catch {}
|
|
2037
|
-
}
|
|
2038
|
-
// W1-C: verify 出口必须真实跑命令(严格版)——历史归档 change 豁免(过渡规则)
|
|
2039
|
-
if (node.id === 'verify' && !(await isArchivedChange(state.activeChange))) {
|
|
2040
|
-
// 越权委托兜底检测(verify 出口): 越权委托兜底检测(verify 出口)——同 KI-10 判定(TASK parallel done +
|
|
2041
|
-
// completedNodes 无 subagent-execute + 非 direct + 协议含 subagent-execute 节点),
|
|
2042
|
-
// verify 时仍未 exit → WARN 兜底(execute 出口未拦截的提示)
|
|
2043
|
-
try {
|
|
2044
|
-
const ki9TaskText = await fs.readFile(path.join(runRoot, '.specs', state.activeChange ?? '', 'TASK.md'), 'utf8');
|
|
2045
|
-
const ki9TaskBlocks = extractTaskBlocks(ki9TaskText);
|
|
2046
|
-
const ki9Tasks = ki9TaskBlocks.map(block => {
|
|
2047
|
-
const a = taskOpeningAttrs(block) || {};
|
|
2048
|
-
return { id: a.id, status: a.status, parallel: a.parallel };
|
|
2049
|
-
}).filter(t => t.id);
|
|
2050
|
-
const ki9ParallelDone = ki9Tasks.filter(t => t.parallel && t.status === 'done').map(t => t.id);
|
|
2051
|
-
const ki9ProtocolHasSubagent = (protocol.nodes ?? []).some(n => n.id === 'subagent-execute');
|
|
2052
|
-
const ki9TakeoverApproved = !!(state.evidence?.execute && state.evidence.execute.parallelTakeoverApproved);
|
|
2053
|
-
if (ki9ParallelDone.length > 0
|
|
2054
|
-
&& !(state.completedNodes ?? []).includes('subagent-execute')
|
|
2055
|
-
&& (state.executionMode ?? 'subagent') !== 'direct'
|
|
2056
|
-
&& !ki9TakeoverApproved
|
|
2057
|
-
&& ki9ProtocolHasSubagent) {
|
|
2058
|
-
if (isNewChange(state)) {
|
|
2059
|
-
console.error('BLOCKED: TASK 有 parallel done 任务(' + ki9ParallelDone.join(', ')
|
|
2060
|
-
+ ')但 subagent-execute 节点未 exit——新 change 强制(verify 兜底拦截)');
|
|
2061
|
-
console.error('恢复: 经 subagent-execute 节点完成委托后再 exit;或说明越权委托原因');
|
|
2062
|
-
process.exit(1);
|
|
2063
|
-
}
|
|
2064
|
-
console.error('WARN: TASK 有 parallel done 任务(' + ki9ParallelDone.join(', ')
|
|
2065
|
-
+ ')但 subagent-execute 节点未 exit——疑似越权委托(execute 出口未拦截,verify 兜底提示)');
|
|
2066
|
-
}
|
|
2067
|
-
} catch {}
|
|
2068
|
-
const { spawnSync } = await import('child_process');
|
|
2069
|
-
let verifyCommand = null;
|
|
2070
|
-
// 1) TEST.md 的 ## 验证命令 段(首行代码块首行)
|
|
2071
|
-
const testDoc = path.join(runRoot, '.specs', state.activeChange ?? '', 'TEST.md');
|
|
2072
|
-
if (await fileExists(testDoc)) {
|
|
2073
|
-
const text = await fs.readFile(testDoc, 'utf8');
|
|
2074
|
-
// 段名允许括号后缀(与 ## 自检方法 段的括号后缀兼容风格一致——执行者按
|
|
2075
|
-
// 模板标题原样书写或补充说明时不被误 BLOCKED)
|
|
2076
|
-
const m = text.match(/##\s*验证命令(?:[((][^))\n]*[))])?\s*\n\s*```[^\n]*\n([\s\S]*?)```/);
|
|
2077
|
-
if (m) verifyCommand = m[1].trim().split('\n').filter(l => l.trim() && !l.trim().startsWith('#')).join(' && ');
|
|
2078
|
-
}
|
|
2079
|
-
// 2) state 的 verifyCommand
|
|
2080
|
-
if (!verifyCommand && state.verifyCommand) verifyCommand = state.verifyCommand;
|
|
2081
|
-
// 3) 项目探测回退
|
|
2082
|
-
if (!verifyCommand) {
|
|
2083
|
-
if (await fileExists(path.join(runRoot, 'pingpong-tournament', 'pyproject.toml'))) verifyCommand = 'cd pingpong-tournament && python -m pytest tests/ -q';
|
|
2084
|
-
else if (await fileExists(path.join(runRoot, 'frontend', 'package.json'))) verifyCommand = 'cd frontend && npm test';
|
|
2085
|
-
}
|
|
2086
|
-
if (!verifyCommand) {
|
|
2087
|
-
console.error('BLOCKED: TEST.md 需声明 ## 验证命令 段(严格版要求)');
|
|
2088
|
-
process.exit(1);
|
|
2089
|
-
}
|
|
2090
|
-
// verify 命令 timeout 可配置——FLOW_COMET_VERIFY_TIMEOUT_MS 环境变量优先,
|
|
2091
|
-
// 缺省 300000ms(300s;后端测试耗时可超 300s,用 env 调大);非数字/0 → 回退缺省
|
|
2092
|
-
const verifyTimeoutMs = Number.parseInt(process.env.FLOW_COMET_VERIFY_TIMEOUT_MS ?? '300000', 10) || 300000;
|
|
2093
|
-
// 二段式执行(受限沙箱兼容):首选管道式捕获(输出可用、行为与既有等价);仅当管道式
|
|
2094
|
-
// 执行在 spawn 层被拒(EPERM——如受限沙箱会话,此时子进程根本不启动)时降级:以继承
|
|
2095
|
-
// stdio 重试同一命令(真实执行保持、退出码判定不变),VERIFY-DEGRADED 行标记降级捕获;
|
|
2096
|
-
// 非 EPERM 失败维持现状路径(不降级,避免吞掉真实测试失败)。
|
|
2097
|
-
try {
|
|
2098
|
-
// 测试钩子(仅测试用途):FLOW_COMET_VERIFY_FORCE_EPERM=1 使首次管道执行模拟 EPERM
|
|
2099
|
-
// 拒绝——真实受限会话中命令在管道阶段不会启动,故跳过管道阶段直接产生 EPERM 结果,
|
|
2100
|
-
// 让降级路径可确定性自动化断言(生产触发条件是真实 spawn 层 EPERM,不经此钩子)
|
|
2101
|
-
const forceEperm = process.env.FLOW_COMET_VERIFY_FORCE_EPERM === '1';
|
|
2102
|
-
const first = forceEperm
|
|
2103
|
-
? { status: null, error: Object.assign(new Error('spawn verify EPERM(FLOW_COMET_VERIFY_FORCE_EPERM=1 模拟受限沙箱拒绝)'), { code: 'EPERM' }), stdout: '', stderr: '' }
|
|
2104
|
-
: spawnSync(verifyCommand, { cwd: runRoot, shell: true, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: verifyTimeoutMs });
|
|
2105
|
-
const firstFailed = first.error != null || first.status !== 0;
|
|
2106
|
-
const epermDenied = first.error != null && (first.error.code === 'EPERM' || String(first.error.message ?? '').includes('EPERM'));
|
|
2107
|
-
if (firstFailed && epermDenied) {
|
|
2108
|
-
console.error('VERIFY-DEGRADED: ' + verifyCommand + '(沙箱管道受限,以 inherit 重试)');
|
|
2109
|
-
const r2 = spawnSync(verifyCommand, { cwd: runRoot, shell: true, stdio: 'inherit', timeout: verifyTimeoutMs });
|
|
2110
|
-
if (!(r2.error == null && r2.status === 0)) {
|
|
2111
|
-
throw new Error(r2.error != null ? String(r2.error.message) : ('exit code ' + r2.status));
|
|
2112
|
-
}
|
|
2113
|
-
} else if (firstFailed) {
|
|
2114
|
-
// 非 EPERM 失败维持现状路径——抛出与既有 execSync 形态兼容的错误对象(stdout 优先展示)
|
|
2115
|
-
const e = new Error('Command failed: ' + verifyCommand + '\n' + String(first.stderr ?? ''));
|
|
2116
|
-
e.stdout = first.stdout;
|
|
2117
|
-
throw e;
|
|
2118
|
-
}
|
|
2119
|
-
} catch (e) {
|
|
2120
|
-
// verify-fail 自动递增(无需 LLM 主动调用)——计数按当前 change 存储
|
|
2121
|
-
// (verifyFailuresByChange,切换 change 不串扰;旧顶层字段迁移并入)
|
|
2122
|
-
const count = verifyFailuresFor(state) + 1;
|
|
2123
|
-
setVerifyFailuresFor(state, count);
|
|
2124
|
-
const file = await statePath(protocol);
|
|
2125
|
-
const bad = validateStateFields(state);
|
|
2126
|
-
if (bad.length) { console.error('BLOCKED: state 字段类型非法: ' + bad[0]); process.exit(1); }
|
|
2127
|
-
await writeJson(file, state);
|
|
2128
|
-
if (count >= 4) {
|
|
2129
|
-
console.error('BLOCKED: verify 已失败 ' + count + ' 次,需用户决策(继续修/停止)。');
|
|
2130
|
-
} else {
|
|
2131
|
-
// stdout 为空(如超时被 kill 时 stdout 是空 Buffer——truthy)→ 显示错误消息;
|
|
2132
|
-
// 消息中带实际应用的 timeout(超时可诊断,且与 Node 版本无关)
|
|
2133
|
-
const detail = (e.stdout && e.stdout.length) ? e.stdout : e.message;
|
|
2134
|
-
console.error('BLOCKED: verify 命令失败(timeout ' + verifyTimeoutMs + 'ms): ' + verifyCommand + '\n' + String(detail).slice(0, 500));
|
|
2135
|
-
console.error('VERIFY-FAIL: ' + count + '/3');
|
|
2136
|
-
}
|
|
2137
|
-
process.exit(1);
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
// W1-D: Return Contract 校验——每个 delegated task 的 result 必须含 commitHash + greenEvidence
|
|
2141
|
-
// handoff-guarded 落实——每个 result 的 completedChecks 必须包含
|
|
2142
|
-
// required-skill:subagent-execute.<skill>(skill 名从协议 requiredSkillCalls 读)。
|
|
2143
|
-
// 严格模式:旧格式非 JSON result(无 completedChecks 载体)同样 BLOCKED,无旧 change 豁免——
|
|
2144
|
-
// 补录/重录必须回传完整契约(含 completedChecks),不允许历史格式绕过委托证明
|
|
2145
|
-
if (node.id === 'subagent-execute') {
|
|
2146
|
-
const he = state.evidence['subagent-execute'];
|
|
2147
|
-
const results = he && he.handoffResult ? he.handoffResult : {};
|
|
2148
|
-
const requiredChecks = (node.requiredSkillCalls ?? [])
|
|
2149
|
-
.map((binding) => 'required-skill:' + node.id + '.' + binding.skill);
|
|
2150
|
-
const violations = [];
|
|
2151
|
-
for (const [taskId, rec] of Object.entries(results)) {
|
|
2152
|
-
const r = typeof rec.result === 'object' && rec.result !== null ? rec.result : null;
|
|
2153
|
-
if (!r) { violations.push(taskId + ' 非 Return Contract(旧格式,缺 completedChecks)'); continue; }
|
|
2154
|
-
// 零提交语义对齐:request 记录 noCommit(write_files 为空,或全部字面路径可证明被 gitignore)
|
|
2155
|
-
// 的任务无提交可回传,豁免 commitHash 缺失断言(其余契约校验不变)——与 workflow-handoff
|
|
2156
|
-
// 零提交跳过同构
|
|
2157
|
-
const taskReq = he.handoffRequests ? he.handoffRequests[taskId] : null;
|
|
2158
|
-
const noCommitTask = !!(taskReq && taskReq.noCommit === true);
|
|
2159
|
-
if (!r.commitHash && !noCommitTask) violations.push(taskId + ' 缺 commitHash');
|
|
2160
|
-
if (!r.greenEvidence || !r.greenEvidence.command) violations.push(taskId + ' 缺 greenEvidence');
|
|
2161
|
-
// redEvidence 缺失警告(过渡期不阻断)——M3: 新 change(enter 机制激活)升级为 BLOCKED(TDD RED 证据强制)
|
|
2162
|
-
if (r && !r.redEvidence) {
|
|
2163
|
-
if (isNewChange(state)) {
|
|
2164
|
-
violations.push(taskId + ' 缺 redEvidence(新 change 强制 TDD RED 证据;旧 change 渐进 WARN)');
|
|
2165
|
-
} else {
|
|
2166
|
-
console.error('HANDOFF WARN: ' + taskId + ' 缺 redEvidence(可能未执行 TDD RED 阶段)');
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
// completedChecks 严格校验(无旧 change 豁免)
|
|
2170
|
-
if (requiredChecks.length > 0) {
|
|
2171
|
-
const checks = Array.isArray(r.completedChecks) ? r.completedChecks : [];
|
|
2172
|
-
const missing = requiredChecks.filter((check) => !checks.includes(check));
|
|
2173
|
-
if (missing.length > 0) {
|
|
2174
|
-
violations.push(taskId + ' 缺 completedChecks: ' + missing.join(', '));
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
if (violations.length > 0) {
|
|
2179
|
-
console.error('BLOCKED: Return Contract 校验失败: ' + violations.join('; '));
|
|
2180
|
-
console.error('恢复: 子代理回传完整契约(含缺失字段)后用 workflow-handoff.mjs result 重录——新 change 强制 TDD RED/GREEN 证据与 completedChecks;注意:若已记录 greenEvidence 而缺 redEvidence,时序防护会拦截事后补录(防掩盖缺 RED)——确认子代理真实执行过 TDD RED 且证据在对应 SUMMARY 中时,用 workflow-state.mjs record subagent-execute 合并写入真实 redEvidence(证据可溯源),或重新委托任务获取完整契约');
|
|
2181
|
-
process.exit(1);
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
// M2: subagent-execute 出口——done 任务缺 SUMMARY(新 change BLOCKED;旧 change 渐进 WARN)
|
|
2185
|
-
// 此前为已知边界(W1-B 只查存在 SUMMARY 的段内容);执行遗漏(声称完成无产物)不应静默进归档
|
|
2186
|
-
if (node.id === 'subagent-execute' && state.activeChange) {
|
|
2187
|
-
const saTaskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
2188
|
-
try {
|
|
2189
|
-
const saContent = await fs.readFile(saTaskFile, 'utf8');
|
|
2190
|
-
const saTasks = (saContent.match(/<task[^>]*>[\s\S]*?<\/task>/g) || [])
|
|
2191
|
-
.map(block => ({ id: (block.match(/id="([^"]+)"/) || [])[1] || null, status: (block.match(/status="([^"]+)"/) || [])[1] || null }))
|
|
2192
|
-
.filter(t => t.id);
|
|
2193
|
-
const saDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
2194
|
-
for (const t of saTasks.filter(t => t.status === 'done')) {
|
|
2195
|
-
if (!(await fileExists(path.join(saDir, t.id + '-SUMMARY.md')))) {
|
|
2196
|
-
if (isNewChange(state)) {
|
|
2197
|
-
console.error('BLOCKED: done 任务 ' + t.id + ' 缺少 ' + t.id + '-SUMMARY.md——subagent-execute 产物不完整(新 change 强制任务完成须有对应 SUMMARY;旧 change 渐进 WARN)');
|
|
2198
|
-
console.error('恢复: 补写 ' + t.id + '-SUMMARY.md 后重试 exit;任务完成后补产物即可');
|
|
2199
|
-
process.exit(1);
|
|
2200
|
-
}
|
|
2201
|
-
console.error('WARN: done 任务 ' + t.id + ' 缺少 ' + t.id + '-SUMMARY.md——subagent-execute 产物不完整(任务完成须有对应 SUMMARY)');
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
|
-
} catch {}
|
|
2205
|
-
}
|
|
2206
|
-
// 多趟完成判定(完成判定谓词决策·合取语义)——subagent-execute 每趟出口校验:
|
|
2207
|
-
// ① 可委托集合必须为空:仍存在 p(parallel ∧ pending ∧ deps⊆done)→ 本趟未委派完即退 →
|
|
2208
|
-
// BLOCK「尚有可委托并行任务(继续委托)」(AC-1:每趟委托全部依赖已满足的并行任务);
|
|
2209
|
-
// ② 孤儿并行单独区分文案:parallel ∧ pending 且依赖链无法满足(直接依赖缺失,或陷入依赖环/
|
|
2210
|
-
// 被环传递拖累)→ BLOCK「孤儿并行任务依赖无法满足(检查 depends_on)」——数据异常 fail-closed,
|
|
2211
|
-
// 防静默跳过(三重防呆决策之二)。
|
|
2212
|
-
// serial pending 不阻断:合法趟间态(回 execute 消化串行)——最终完成的另一支「无 serial pending」
|
|
2213
|
-
// 由 execute 出口的串行 pending 校验把关,两支在流程推进中自然合取。
|
|
2214
|
-
if (node.id === 'subagent-execute' && state.activeChange) {
|
|
2215
|
-
try {
|
|
2216
|
-
const mpContent = await fs.readFile(path.join(runRoot, '.specs', state.activeChange, 'TASK.md'), 'utf8');
|
|
2217
|
-
const mpBlocks = extractTaskBlocks(mpContent);
|
|
2218
|
-
const mpDoneIds = new Set(mpBlocks
|
|
2219
|
-
.map(taskOpeningAttrs)
|
|
2220
|
-
.filter((a) => a && a.status === 'done' && a.id)
|
|
2221
|
-
.map((a) => a.id));
|
|
2222
|
-
const delegable = eligibleParallelBlocks(mpBlocks, mpDoneIds);
|
|
2223
|
-
if (delegable.length > 0) {
|
|
2224
|
-
console.error('BLOCKED: 尚有可委托并行任务(继续委托): ' + delegable
|
|
2225
|
-
.map((b) => (taskOpeningAttrs(b) || {}).id).join(', ') +
|
|
2226
|
-
'——多趟语义下每趟须委派全部依赖已满足的并行任务后才能退出');
|
|
2227
|
-
console.error('恢复: 继续委托上述任务(子代理回传 Return Contract 后再 exit);若确需提前收尾,先调整其 depends_on 使其脱离可委派状态');
|
|
2228
|
-
process.exit(1);
|
|
2229
|
-
}
|
|
2230
|
-
const mpGraph = analyzeDependencyGraph(mpBlocks);
|
|
2231
|
-
const parallelPending = mpBlocks.filter((b) => {
|
|
2232
|
-
const a = taskOpeningAttrs(b);
|
|
2233
|
-
return a && a.parallel && a.status === 'pending';
|
|
2234
|
-
});
|
|
2235
|
-
let orphans = [];
|
|
2236
|
-
if (mpGraph.cyclic || mpGraph.missing.length > 0) {
|
|
2237
|
-
// doomed 闭包:直接依赖缺失的任务 ∪ 环上/被环拖累的任务,再传递扩散到一切(传递)依赖它们
|
|
2238
|
-
// 的任务——这些任务永远进不了可委派状态,一并视为孤儿。
|
|
2239
|
-
const doomed = new Set(mpGraph.cycleIds);
|
|
2240
|
-
for (const m of mpGraph.missing) doomed.add(m.id);
|
|
2241
|
-
let changed = true;
|
|
2242
|
-
while (changed) {
|
|
2243
|
-
changed = false;
|
|
2244
|
-
for (const [id, deps] of mpGraph.depsById) {
|
|
2245
|
-
if (doomed.has(id)) continue;
|
|
2246
|
-
if (deps.some((d) => doomed.has(d))) { doomed.add(id); changed = true; }
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
orphans = parallelPending.filter((b) => {
|
|
2250
|
-
const a = taskOpeningAttrs(b);
|
|
2251
|
-
return a && a.id && doomed.has(a.id);
|
|
2252
|
-
});
|
|
2253
|
-
}
|
|
2254
|
-
if (orphans.length > 0) {
|
|
2255
|
-
console.error('BLOCKED: 孤儿并行任务依赖无法满足(检查 depends_on): ' + orphans
|
|
2256
|
-
.map((b) => (taskOpeningAttrs(b) || {}).id).join(', ') +
|
|
2257
|
-
'——依赖引用了不存在的任务或陷入依赖环,永远无法进入可委派状态');
|
|
2258
|
-
console.error('恢复: 调整这些任务的 depends_on——指向真实存在且无环的任务 id 后重试;依赖环应在 plan 出口被前置拦截,执行期出现请核对 TASK.md 是否被手改');
|
|
2259
|
-
process.exit(1);
|
|
2260
|
-
}
|
|
2261
|
-
} catch {}
|
|
2262
|
-
}
|
|
2263
|
-
// exit 协议声明标记校验——节点 exit 时扫描 .specs/<change-id>/.skill-loads/ 下该节点标记
|
|
2264
|
-
// (<node>-*.json,执行者加载节点 skill 后经 skill-load 写入,含 protocol 字段——指向
|
|
2265
|
-
// flow-kit/prompts/ 协议文件,只读引用),校验至少一个标记的 protocol ∈ 该节点协议集(节点协议映射表)。
|
|
2266
|
-
// 缺失 → BLOCKED(提示缺协议声明标记 + 指引 skill-load --prompt);有 → 通过。
|
|
2267
|
-
// 诚实边界:标记是执行者的自我声明——校验只确认「声明存在且 protocol 归属节点」,
|
|
2268
|
-
// 无法证明执行者真的阅读了协议(声明非物理证明,仅保证协议阅读声明可追溯)。
|
|
2269
|
-
// 旧 change 兼容:旧 change/旧 evidence 不追溯——.skill-loads/ 目录不存在(该 change 从未运行过
|
|
2270
|
-
// skill-load,声明机制未激活)→ 跳过校验;节点已 exit 不重验(校验只在当前 exit 时执行);
|
|
2271
|
-
// 节点重新 exit(重入后再退)时按新规则要求,无豁免。
|
|
2272
|
-
if (state.activeChange && NODE_PROTOCOL_FILES[node.id]) {
|
|
2273
|
-
// 标记目录活动/归档双路径解析(archive 节点「先移目录后 exit」顺序下标记只在
|
|
2274
|
-
// 归档路径——单查活动路径会误报「机制未激活」静默放行);两处皆无才走旧 change 兼容
|
|
2275
|
-
const loadsDir = await findSkillLoadsDir(runRoot, state.activeChange);
|
|
2276
|
-
if (loadsDir) {
|
|
2277
|
-
const prefix = node.id + '-';
|
|
2278
|
-
const protocolSet = NODE_PROTOCOL_FILES[node.id];
|
|
2279
|
-
const markers = (await fs.readdir(loadsDir.dir).catch(() => []))
|
|
2280
|
-
.filter((f) => f.startsWith(prefix) && f.endsWith('.json'));
|
|
2281
|
-
const malformed = [];
|
|
2282
|
-
let declared = false;
|
|
2283
|
-
for (const f of markers) {
|
|
2284
|
-
try {
|
|
2285
|
-
const marker = JSON.parse(await fs.readFile(path.join(loadsDir.dir, f), 'utf8'));
|
|
2286
|
-
// 比对 basename——新格式(skill-load 写入 basename)与旧格式(完整绝对路径)
|
|
2287
|
-
// 经 markerProtocolBasename 提取后统一比对;损坏值(null/非字符串/超集外 basename)
|
|
2288
|
-
// 提取为 null 或不匹配 → 不进 declared,fail-closed
|
|
2289
|
-
if (marker && typeof marker === 'object' && protocolSet.includes(markerProtocolBasename(marker.protocol))) {
|
|
2290
|
-
declared = true;
|
|
2291
|
-
// R3: auto 标记提示——record 自动补的标记(auto:true)不证明手动加载,提示建议手动声明
|
|
2292
|
-
if (marker.auto === true) {
|
|
2293
|
-
console.error('SKILL-LOAD HINT: ' + f + ' 为 record 自动补写标记(auto)——建议手动 skill-load 声明(如实记录加载动作与协议文件)');
|
|
2294
|
-
}
|
|
2295
|
-
break;
|
|
2296
|
-
}
|
|
2297
|
-
} catch {
|
|
2298
|
-
malformed.push(f);
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
if (!declared) {
|
|
2302
|
-
console.error('BLOCKED: 节点 ' + node.id + ' exit 缺协议声明标记——' + loadsDir.display +
|
|
2303
|
-
' 下需有 ' + prefix + '*.json 且 protocol ∈ [' + protocolSet.join(', ') +
|
|
2304
|
-
'];执行 skill-load --prompt <flow-kit/prompts/ 协议文件> 声明已阅读协议(声明非物理证明,仅可追溯)' +
|
|
2305
|
-
(malformed.length > 0 ? ';不可解析标记: ' + malformed.join(', ') : ''));
|
|
2306
|
-
process.exit(1);
|
|
2307
|
-
}
|
|
2308
|
-
} else {
|
|
2309
|
-
// 旧 change 兼容 过渡规则:旧 change 兼容——活动与归档路径均无声明标记目录(机制未激活)不追溯;
|
|
2310
|
-
// 首个 skill-load 写入后新规则生效(该 change 后续节点 exit 均需声明标记)
|
|
2311
|
-
console.error('SKILL-LOAD WARN: 旧 change 兼容——.specs/' + state.activeChange +
|
|
2312
|
-
'/.skill-loads/(活动与归档路径)不存在,协议声明校验跳过(机制未激活;首个 skill-load 后新规则生效)');
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
// ===== M1: SUMMARY 模板保真(execute / subagent-execute 出口·设计语义 / AC-7)=====
|
|
2317
|
-
// 每份 *-SUMMARY.md 校 ① 标题首行 # SUMMARY: ② 首部 4 字段(Change ID/Task ID/完成时间/AI 角色)
|
|
2318
|
-
// ③ 段序(做了什么→改动文件→verify 输出→6 维自查→…→自检方法);宽容匹配(大小写/编号前缀/括号后缀)。
|
|
2319
|
-
// ④ 全骨架存在 + 模板序(骨架从 flow-kit/templates/SUMMARY.md 全部 H2 派生,条件段允许正文 N/A);
|
|
2320
|
-
// ## 自检方法 不在骨架内,单独要求且只允许「文末」「紧随越界检查」两种位置。
|
|
2321
|
-
// 新 change 任一缺失 → BLOCK(含缺失点 + 恢复指引);旧 change/归档批 → WARN 渐进;
|
|
2322
|
-
// 模板缺失(无权威骨架来源)→ 新规则只告警不阻断,保持旧格式渐进。
|
|
2323
|
-
if (EXECUTE_FAMILY_NODE_IDS.has(node.id)) {
|
|
2324
|
-
const summaryChangeDir = path.join(runRoot, '.specs', state.activeChange ?? '');
|
|
2325
|
-
const summaryFiles = (await fs.readdir(summaryChangeDir).catch(() => [])).filter((f) => f.endsWith('-SUMMARY.md'));
|
|
2326
|
-
const skeleton = await summaryTemplateSkeleton();
|
|
2327
|
-
const hardIssues = [];
|
|
2328
|
-
let skeletonGuidanceNeeded = false;
|
|
2329
|
-
for (const f of summaryFiles) {
|
|
2330
|
-
try {
|
|
2331
|
-
const content = await fs.readFile(path.join(summaryChangeDir, f), 'utf8');
|
|
2332
|
-
const fidelity = summaryTemplateFidelity(content);
|
|
2333
|
-
const problems = [];
|
|
2334
|
-
if (fidelity.titleMissing) {
|
|
2335
|
-
problems.push('首行缺 `# SUMMARY: <Task>-<名>` 标题(大小写不敏感,标题可带括号说明后缀)');
|
|
2336
|
-
}
|
|
2337
|
-
if (fidelity.headerMissing.length > 0) {
|
|
2338
|
-
problems.push('首部缺字段: ' + fidelity.headerMissing.join('、'));
|
|
2339
|
-
}
|
|
2340
|
-
if (fidelity.orderIssue) {
|
|
2341
|
-
problems.push('段序乱(「' + fidelity.orderIssue.replace(/^##\s*/, '') +
|
|
2342
|
-
'」偏离模板段序——应为 做了什么→改动文件→verify 输出→6 维自查→越界检查→自检方法)');
|
|
2343
|
-
}
|
|
2344
|
-
if (fidelity.missingSections.length > 0) {
|
|
2345
|
-
problems.push('缺段: ' + fidelity.missingSections.join('、'));
|
|
2346
|
-
}
|
|
2347
|
-
if (problems.length > 0) {
|
|
2348
|
-
if (isNewChange(state)) {
|
|
2349
|
-
hardIssues.push(f + ' 模板保真校验失败: ' + problems.join('; '));
|
|
2350
|
-
} else {
|
|
2351
|
-
console.error('SUMMARY TEMPLATE WARN: ' + f + ' ' + problems.join('; ') +
|
|
2352
|
-
'(旧 change/归档批渐进,不阻断;新 change 将强制)');
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
// ④ 全骨架保真:模板在场时新 change 缺段/乱序/自检位置非法 → BLOCK;
|
|
2356
|
-
// 模板缺失时骨架来自内置兜底,不据此新增阻断(旧格式兼容)。
|
|
2357
|
-
const skeletonFidelity = summarySkeletonFidelity(content, skeleton);
|
|
2358
|
-
const skeletonProblems = [];
|
|
2359
|
-
if (skeletonFidelity.missingSections.length > 0) {
|
|
2360
|
-
skeletonProblems.push('缺段: ' + skeletonFidelity.missingSections.join('、'));
|
|
2361
|
-
}
|
|
2362
|
-
if (skeletonFidelity.orderIssue) {
|
|
2363
|
-
skeletonProblems.push('段序乱(「' + skeletonFidelity.orderIssue.replace(/^##\s*/, '') +
|
|
2364
|
-
'」偏离 flow-kit/templates/SUMMARY.md 的段序)');
|
|
2365
|
-
}
|
|
2366
|
-
if (skeletonFidelity.selfCheckIssue) {
|
|
2367
|
-
skeletonProblems.push(skeletonFidelity.selfCheckIssue);
|
|
2368
|
-
}
|
|
2369
|
-
if (skeletonProblems.length > 0) {
|
|
2370
|
-
if (isNewChange(state) && skeleton.derived) {
|
|
2371
|
-
skeletonGuidanceNeeded = true;
|
|
2372
|
-
hardIssues.push(f + ' SUMMARY 全骨架校验失败: ' + skeletonProblems.join('; '));
|
|
2373
|
-
} else {
|
|
2374
|
-
console.error('SUMMARY TEMPLATE WARN: ' + f + ' ' + skeletonProblems.join('; ') +
|
|
2375
|
-
(skeleton.derived
|
|
2376
|
-
? '(旧 change/归档批渐进,不阻断;新 change 将强制)'
|
|
2377
|
-
: '(模板缺失,按内置骨架提示;不新增阻断)'));
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
} catch {}
|
|
2381
|
-
}
|
|
2382
|
-
if (hardIssues.length > 0) {
|
|
2383
|
-
console.error('BLOCKED: SUMMARY 模板保真校验失败: ' + hardIssues.join('; '));
|
|
2384
|
-
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 修正标题/首部/段序(含 flow-comet 增量 ## 自检方法 段)后重试 exit;新 change 强制模板保真');
|
|
2385
|
-
if (skeletonGuidanceNeeded) {
|
|
2386
|
-
console.error('恢复: 对照 flow-kit/templates/SUMMARY.md 补齐缺失段的 H2 标题(条件段内容可写 N/A)并按模板顺序排列;## 自检方法 只允许文末或紧随 ## 越界检查 之后两种位置');
|
|
2387
|
-
}
|
|
2388
|
-
process.exit(1);
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
// ===== M2: TASK 7 字段完整性(plan 出口·设计语义 / AC-8)=====
|
|
2393
|
-
// 每个 <task> 块须含 name/read_files/write_files/action/verify/done/depends_on;缺任一 → 新 BLOCK / 旧 WARN。
|
|
2394
|
-
// 开标签解析/整块提取沿用 task-parsing.mjs(属性序无关)。宽容:任务块采用旧式一字段形态(无 <name> 标记)
|
|
2395
|
-
// 的 TASK 视为旧格式 → 仅渐进 WARN(不误拦既有波次/路由回归载体);采用新模板形态(含 <name>)则按 7 字段强校验。
|
|
2396
|
-
if (node.id === 'plan' && state.activeChange) {
|
|
2397
|
-
const task7File = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
2398
|
-
try {
|
|
2399
|
-
const task7Blocks = extractTaskBlocks(await fs.readFile(task7File, 'utf8'));
|
|
2400
|
-
const TASK7_REQUIRED = ['name', 'read_files', 'write_files', 'action', 'verify', 'done', 'depends_on'];
|
|
2401
|
-
const planNewFormat = task7Blocks.some((b) => /<name\b/i.test(b));
|
|
2402
|
-
const broken = [];
|
|
2403
|
-
for (const b of task7Blocks) {
|
|
2404
|
-
const missing = TASK7_REQUIRED.filter((field) => !new RegExp('</?' + field + '\\b', 'i').test(b));
|
|
2405
|
-
if (missing.length > 0) {
|
|
2406
|
-
const idAttr = (taskOpeningAttrs(b) || {})?.id || '?';
|
|
2407
|
-
broken.push((idAttr && idAttr !== '?' ? idAttr + ' ' : '') + '缺 ' + missing.join('/'));
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
if (broken.length > 0) {
|
|
2411
|
-
if (planNewFormat) {
|
|
2412
|
-
if (isNewChange(state)) {
|
|
2413
|
-
// 文案的集合字符串**从判据常量派生**(不得在此再写一遍字面集合——第二处同口径表达会在
|
|
2414
|
-
// 判据演进时静默落后于实现;构造方式不改变渲染结果)。
|
|
2415
|
-
console.error('BLOCKED: TASK.md 任务缺 7 字段(' + TASK7_REQUIRED.join('/') + '): ' + broken.join('; '));
|
|
2416
|
-
console.error('恢复: 对照 flow-kit/templates/TASK.md 补齐每个 <task> 的缺字段后重试 exit;新 change 强制任务块结构完整');
|
|
2417
|
-
process.exit(1);
|
|
2418
|
-
}
|
|
2419
|
-
console.error('TASK-7FIELD WARN: TASK.md ' + broken.join('; ') + '(旧 change 渐进,不阻断;新 change 将强制补齐 7 字段)');
|
|
2420
|
-
} else {
|
|
2421
|
-
console.error('TASK-7FIELD WARN: TASK.md 任务为旧式一字段模板形态(' + broken.join('; ') +
|
|
2422
|
-
')——建议按 flow-kit/templates/TASK.md 补全 7 字段(渐进不阻断)');
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
} catch {}
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
// ===== M3: CHANGE/REQUIREMENT/DESIGN 模板保真(open / design 出口·设计语义 / AC-9)=====
|
|
2429
|
-
// 标题与模板一致(# CHANGE: / # REQUIREMENT: / # DESIGN:,大小写不敏感、冒号可省)+ 段序按模板派生骨架宽容匹配
|
|
2430
|
-
// (编号前缀/括号后缀兼容);首部必要字段(Change ID)缺失 → 渐进 WARN。新 change 标题/段序失配 → BLOCK + 恢复指引;
|
|
2431
|
-
// 旧 change/归档批 → WARN 渐进。
|
|
2432
|
-
if ((node.id === 'open' || node.id === 'design') && state.activeChange) {
|
|
2433
|
-
const intakeDir = path.join(runRoot, '.specs', state.activeChange);
|
|
2434
|
-
const skeletonsCache = {};
|
|
2435
|
-
const hardProblems = [];
|
|
2436
|
-
const softWarnings = [];
|
|
2437
|
-
const checkIntakeDoc = async (file, key, label, titleRe) => {
|
|
2438
|
-
const p = path.join(intakeDir, file);
|
|
2439
|
-
if (!(await fileExists(p))) return; // 文件缺失由产物校验兜底
|
|
2440
|
-
const text = await fs.readFile(p, 'utf8');
|
|
2441
|
-
const firstLine = (text.replace(/\uFEFF/g, '').split('\n').find((l) => l.trim().length > 0) || '').trim();
|
|
2442
|
-
if (!titleRe.test(firstLine)) {
|
|
2443
|
-
hardProblems.push(file + ' 标题应以 # ' + label + ' 开头(如 `# ' + label + ': <标题>`,大小写不敏感、冒号可省)');
|
|
2444
|
-
}
|
|
2445
|
-
if (!skeletonsCache[key]) skeletonsCache[key] = await templateSkeleton(key);
|
|
2446
|
-
const viol = templateOrderViolation(skeletonsCache[key], documentSectionHeadings(text));
|
|
2447
|
-
if (viol) {
|
|
2448
|
-
hardProblems.push(file + ' 段序乱(「' + String(viol).replace(/^##\s*/, '') + '」偏离 ' + label + ' 模板段序)');
|
|
2449
|
-
}
|
|
2450
|
-
const changeIdMissing = !/\*\*\s*Change\s+ID\s*\*\*/i.test(text.split(/\n##\s/)[0]);
|
|
2451
|
-
const intakeMsg = file + ' 首部缺 Change ID 字段(' + label + ' 模板首部含 `- **Change ID**: <id>`)';
|
|
2452
|
-
if (changeIdMissing) {
|
|
2453
|
-
if (isNewChange(state)) hardProblems.push(intakeMsg);
|
|
2454
|
-
else softWarnings.push(intakeMsg + '(渐进提示;新 change 将强制)');
|
|
2455
|
-
}
|
|
2456
|
-
};
|
|
2457
|
-
if (node.id === 'open') {
|
|
2458
|
-
await checkIntakeDoc('CHANGE.md', 'change', 'CHANGE', /^#\s*change\b/i);
|
|
2459
|
-
await checkIntakeDoc('REQUIREMENT.md', 'requirement', 'REQUIREMENT', /^#\s*requirement\b/i);
|
|
2460
|
-
} else {
|
|
2461
|
-
// design:与既有校验一致的 target 选择(DESIGN.md 优先,DESIGN-lite 兜底)
|
|
2462
|
-
const designFile = path.join(intakeDir, 'DESIGN.md');
|
|
2463
|
-
const designLite = path.join(intakeDir, 'DESIGN-lite.md');
|
|
2464
|
-
const chosen = (await fileExists(designFile)) ? 'DESIGN.md' : ((await fileExists(designLite)) ? 'DESIGN-lite.md' : null);
|
|
2465
|
-
if (chosen) await checkIntakeDoc(chosen, 'design', 'DESIGN', /^#\s*design\b/i);
|
|
2466
|
-
}
|
|
2467
|
-
for (const w of softWarnings) console.error('INTAKE-DOC WARN: ' + w + '(渐进提示,不阻断;新 change 同)');
|
|
2468
|
-
if (hardProblems.length > 0) {
|
|
2469
|
-
if (isNewChange(state)) {
|
|
2470
|
-
console.error('BLOCKED: 入口文档模板保真校验失败: ' + hardProblems.join('; '));
|
|
2471
|
-
console.error('恢复: 对照 flow-kit/templates/{CHANGE,REQUIREMENT,DESIGN}.md 修正标题与段序后重试 exit;新 change 强制模板保真');
|
|
2472
|
-
process.exit(1);
|
|
2473
|
-
}
|
|
2474
|
-
for (const h of hardProblems) console.error('INTAKE-DOC WARN: ' + h + '(旧 change/归档批渐进,不阻断;新 change 将强制)');
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
// 自动补 required-skill completedChecks——节点被完成即视为其实现 skill 已加载。
|
|
2479
|
-
// 分派(ui-design 门):仅「guarded 且适用性判据成立(判前端)」的登记绑定在**新 change**
|
|
2480
|
-
// 上停止自动补——该绑定须真实 skill-load 声明,由下方 missingRequiredSkillChecks 拦截;
|
|
2481
|
-
// 判据不成立(非前端)、旧 change(渐进兼容——自动补写保持原语义,工件门照常 WARN)或未登记
|
|
2482
|
-
// 的绑定 → 逐字保持原自动补语义(其它节点/绑定不受影响)。
|
|
2483
|
-
if ((node.requiredSkillCalls ?? []).length > 0) {
|
|
2484
|
-
const checks = Array.isArray(evidence.completedChecks) ? evidence.completedChecks : [];
|
|
2485
|
-
for (const binding of node.requiredSkillCalls ?? []) {
|
|
2486
|
-
const check = 'required-skill:' + node.id + '.' + binding.skill;
|
|
2487
|
-
const applicabilityGated = applicabilityGatedBinding(node, binding.skill) !== null;
|
|
2488
|
-
if (applicabilityGated && isNewChange(state) && (await frontendCriterion(state.activeChange)).applicable) continue;
|
|
2489
|
-
if (!checks.includes(check)) checks.push(check);
|
|
2490
|
-
}
|
|
2491
|
-
evidence.completedChecks = checks;
|
|
2492
|
-
}
|
|
2493
|
-
const missingSchemaEvidence = missingRequiredSchemaEvidence(protocol, node, evidence);
|
|
2494
|
-
if (missingSchemaEvidence.length > 0) {
|
|
2495
|
-
console.error('BLOCKED: missing Output Schema evidence: ' + missingSchemaEvidence.join(', '));
|
|
2496
|
-
process.exit(1);
|
|
2497
|
-
}
|
|
2498
|
-
// M6: execute 显式空退出豁免——仅当豁免活性成立(executeEmptyExitApproved 且 TASK 无任何
|
|
2499
|
-
// 串行任务)时跳过产物校验(全 parallel 无 SUMMARY 属预期);含串行任务的 change 豁免不生效,
|
|
2500
|
-
// 照常校验,不得静默放行。生效时追加被跳过项清单(EMPTY-EXIT-SKIPPED)。
|
|
2501
|
-
const checkedArtifacts = await missingRequiredArtifacts(protocol, node, state.activeChange);
|
|
2502
|
-
let missingArtifacts = checkedArtifacts;
|
|
2503
|
-
if (executeEmptyExitApproved && executeEmptyExitExempt) {
|
|
2504
|
-
console.error('EMPTY-EXIT-SKIPPED: ' + (checkedArtifacts.length > 0 ? checkedArtifacts.join(', ') : '(无缺失产物项)'));
|
|
2505
|
-
missingArtifacts = [];
|
|
2506
|
-
}
|
|
2507
|
-
if (missingArtifacts.length > 0) {
|
|
2508
|
-
console.error('BLOCKED: missing Output Schema artifacts: ' + missingArtifacts.join(', '));
|
|
2509
|
-
process.exit(1);
|
|
2510
|
-
}
|
|
2511
|
-
const missingRequired = missingRequiredSkillChecks(node, evidence);
|
|
2512
|
-
if (missingRequired.length > 0) {
|
|
2513
|
-
console.error('BLOCKED: missing required Skill evidence: ' + missingRequired.join(', '));
|
|
2514
|
-
// ui-design 门:适用性门控绑定缺的是「真实 skill-load 声明」(出口不再自动补写)——给出补齐路径
|
|
2515
|
-
// (判据与该门同源:applicabilityGatedBinding 查询,不在此另写键表)
|
|
2516
|
-
for (const binding of node.requiredSkillCalls ?? []) {
|
|
2517
|
-
const check = 'required-skill:' + node.id + '.' + binding.skill;
|
|
2518
|
-
if (missingRequired.includes(check) && applicabilityGatedBinding(node, binding.skill) !== null) {
|
|
2519
|
-
console.error('恢复: ' + check + ' 不再由出口自动补写(guarded + 适用性判据成立)——先加载 ' + binding.skill
|
|
2520
|
-
+ ' 并运行 workflow-state.mjs skill-load ' + node.id + ' ' + binding.skill
|
|
2521
|
-
+ ' --prompt <flow-kit/prompts/ 协议文件> 声明已加载后重试 exit');
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
process.exit(1);
|
|
2525
|
-
}
|
|
2526
|
-
const missingAugmentations = missingAugmentationChecks(node, evidence);
|
|
2527
|
-
if (missingAugmentations.length > 0) {
|
|
2528
|
-
console.error('BLOCKED: missing augmentation evidence: ' + missingAugmentations.join(', '));
|
|
2529
|
-
process.exit(1);
|
|
2530
|
-
}
|
|
183
|
+
const { exempt: executeEmptyExitExempt } = await runExecuteExitGate({
|
|
184
|
+
protocol,
|
|
185
|
+
node,
|
|
186
|
+
state,
|
|
187
|
+
emptyExitApproved: executeEmptyExitApproved,
|
|
188
|
+
});
|
|
189
|
+
await runVerifyExitGate({ protocol, node, state });
|
|
190
|
+
runReturnContractGate({ node, state });
|
|
191
|
+
await runSubagentSummaryGate({ node, state });
|
|
192
|
+
await runMultiPassCompletionGate({ node, state });
|
|
193
|
+
await runSkillLoadMarkerGate({ node, state });
|
|
194
|
+
await runSummaryTemplateFidelityGate({ node, state });
|
|
195
|
+
await runTaskSevenFieldGate({ node, state });
|
|
196
|
+
await runIntakeDocFidelityGate({ node, state });
|
|
197
|
+
await runEvidenceCompletionGate({ protocol, node, state, evidence });
|
|
198
|
+
await runArtifactGate({
|
|
199
|
+
protocol,
|
|
200
|
+
node,
|
|
201
|
+
state,
|
|
202
|
+
emptyExitApproved: executeEmptyExitApproved,
|
|
203
|
+
emptyExitExempt: executeEmptyExitExempt,
|
|
204
|
+
});
|
|
205
|
+
runRequiredEvidenceGate({ node, evidence });
|
|
2531
206
|
if (apply) {
|
|
2532
207
|
const completed = completedSet(state);
|
|
2533
208
|
// Fix 二次完成信号:exit 的 execute 家族节点在本次 exit 之前已在 completedNodes(首轮 exit
|
|
2534
209
|
// 后再次进入该节点生命周期完成回修)——须在 add 之前捕获,作为回源分支的唯一触发条件。
|
|
2535
210
|
const familyAlreadyCompleted = completed.has(node.id);
|
|
2536
211
|
completed.add(node.id);
|
|
2537
|
-
//
|
|
212
|
+
// verify exit --apply 成功 → 当前 change 的 verifyFailures 清零
|
|
2538
213
|
if (node.id === 'verify') setVerifyFailuresFor(state, 0);
|
|
2539
214
|
state.completedNodes = route(protocol).filter((item) => completed.has(item.id)).map((item) => item.id);
|
|
2540
215
|
// archive 节点完成后 change 已归档 → 清空活跃 change(flow-comet 回到无活跃状态)
|
|
2541
216
|
const isArchive = node.id === 'archive';
|
|
2542
217
|
if (isArchive) state.activeChange = null;
|
|
2543
218
|
let next = isArchive ? null : await nextNode(protocol, state);
|
|
2544
|
-
//
|
|
2545
|
-
//
|
|
2546
|
-
//
|
|
219
|
+
// Fix 批次受控回程——exit execute 家族 --apply:Fix 二次完成(本节点已在 completedNodes)且
|
|
220
|
+
// TASK 全 done 时,回源节点(execute 后第一个未完成节点且 ∈ review/verify)跑其出口;其余情况
|
|
221
|
+
// 维持 resolveNextNode 原判定(正常首轮 exit 与多趟中间 exit 零回归)。
|
|
2547
222
|
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && familyAlreadyCompleted && state.activeChange) {
|
|
2548
223
|
const fixReturnSource = await resolveFixReturnNode({
|
|
2549
224
|
runRoot,
|
|
@@ -2553,11 +228,11 @@ async function main() {
|
|
|
2553
228
|
});
|
|
2554
229
|
if (fixReturnSource) {
|
|
2555
230
|
next = findNode(protocol, fixReturnSource);
|
|
2556
|
-
//
|
|
2557
|
-
//
|
|
2558
|
-
//
|
|
2559
|
-
//
|
|
2560
|
-
//
|
|
231
|
+
// 回程行分类——只在写本次 exit-applied 事件之前(下方 state.history.push)用既有字段派生
|
|
232
|
+
// 因果:历史 execute 家族出口签名发散 ∨ TASK 的 Fix 结构标记 → fix;有签名且全等 → normal;
|
|
233
|
+
// 无签名且无标记 / TASK 不可读 → unknown。分类只决定审计行文案;next / currentNode /
|
|
234
|
+
// completedNodes / history 写入仍按既有 resolveFixReturnNode 无条件覆盖(路由与 state 形状
|
|
235
|
+
// 零变化)。协议 TASK 路径与签名记录一致。
|
|
2561
236
|
let fixTaskContent = null;
|
|
2562
237
|
try {
|
|
2563
238
|
fixTaskContent = await fs.readFile(path.join(runRoot, '.specs', state.activeChange, 'TASK.md'), 'utf8');
|
|
@@ -2580,12 +255,12 @@ async function main() {
|
|
|
2580
255
|
}
|
|
2581
256
|
}
|
|
2582
257
|
// 多趟路由诊断保留(展示层,不并入共享判定):出口推进后下一候选非委托节点时,若任务集存在
|
|
2583
|
-
// parallel 标记任务与任一 pending 任务但无 pending parallel
|
|
2584
|
-
//
|
|
2585
|
-
//
|
|
2586
|
-
//
|
|
2587
|
-
//
|
|
2588
|
-
//
|
|
258
|
+
// parallel 标记任务与任一 pending 任务但无 pending parallel 可委托块,输出路由诊断提示。静默
|
|
259
|
+
// 边界:(a) 全部任务 done 时无 pending 不输出(收尾静默锚);(b) 剩余 pending 全为串行且各
|
|
260
|
+
// parallel 块均带 status(结构正常、P→S 收尾转换)→ 静默(「全 done 静默」扩展为「全串行
|
|
261
|
+
// 剩余」也静默);(c) 存在「parallel 缺 status」的畸形/旧模板块且仍有 pending → 仍报(结构
|
|
262
|
+
// 校验严格,缺 status 不视为 pending,不因扩展误静音——反过静音锚)。路由决策本身由
|
|
263
|
+
// resolveNextNode 单一实现(不维护第二份并行镜像)。
|
|
2589
264
|
if (next && next.id !== 'subagent-execute' && state.activeChange) {
|
|
2590
265
|
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
2591
266
|
try {
|
|
@@ -2603,8 +278,8 @@ async function main() {
|
|
|
2603
278
|
const a = taskOpeningAttrs(block);
|
|
2604
279
|
return a && a.parallel && a.status === 'pending';
|
|
2605
280
|
});
|
|
2606
|
-
// 畸形/旧模板信号:parallel 标记但缺 status 属性(无法分类为 done/pending——缺 status
|
|
2607
|
-
//
|
|
281
|
+
// 畸形/旧模板信号:parallel 标记但缺 status 属性(无法分类为 done/pending——缺 status 不
|
|
282
|
+
// 视为 pending;这正是诊断要提示的检查点)。taskOpeningAttrs 缺属性时 status 返回 null,
|
|
2608
283
|
// 故判 `status == null`(null 或 undefined 双容)。
|
|
2609
284
|
const hasParallelMissingStatus = taskList.some((block) => {
|
|
2610
285
|
const a = taskOpeningAttrs(block);
|
|
@@ -2618,11 +293,11 @@ async function main() {
|
|
|
2618
293
|
state.currentNode = isArchive ? null : (next?.id ?? null);
|
|
2619
294
|
state.status = next ? 'running' : 'completed';
|
|
2620
295
|
state.history = Array.isArray(state.history) ? state.history : [];
|
|
2621
|
-
// 「未闭合 execute 生命周期」信号:exit execute / subagent-execute --apply 把当次 TASK.md
|
|
2622
|
-
//
|
|
2623
|
-
//
|
|
2624
|
-
//
|
|
2625
|
-
//
|
|
296
|
+
// 「未闭合 execute 生命周期」信号:exit execute / subagent-execute --apply 把当次 TASK.md 任务集
|
|
297
|
+
// 签名与 change 归属写入 history 事件——源节点直接 exit 时以「本 change 最新家族出口签名 ≠ 当前
|
|
298
|
+
// 签名」识别 done-but-unclosed 修复批次(lazy entry 只刷新 taskHash、不写本事件,因此仍保持未
|
|
299
|
+
// 闭合)。change 字段只在家族节点事件上写(其它节点事件形状不变),state.history 跨 change 保留
|
|
300
|
+
// 时用于隔离判定;TASK.md 缺失/不可读时省略签名字段(旧 state 形态 → 渐进放行)。
|
|
2626
301
|
const exitEvent = { event: 'exit-applied', node: node.id, at: new Date().toISOString() };
|
|
2627
302
|
if (EXECUTE_FAMILY_NODE_IDS.has(node.id) && state.activeChange) {
|
|
2628
303
|
exitEvent.change = state.activeChange;
|