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
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// 共享判定枢纽(守卫模块):路由谓词、证据/产物存在性判据、节点技能命名、模板段名派生、
|
|
2
|
+
// Fix 段标题派生。这些判据被入口与其余守卫模块共用,故落此处一处实现——入口零内联副本。
|
|
3
|
+
//
|
|
4
|
+
// 依赖方向单向:本模块 → 既有共享模块(state-schema / protocol-utils / task-parsing /
|
|
5
|
+
// route-node)+ guard-state-io;反向 import 不存在。
|
|
6
|
+
|
|
7
|
+
import { promises as fs } from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { handoffRequestWithdrawn } from '../state-schema.mjs';
|
|
10
|
+
import { inspectWorkflowProtectedPath } from '../protocol-utils.mjs';
|
|
11
|
+
import { taskOpeningAttrs } from '../task-parsing.mjs';
|
|
12
|
+
import { resolveNextNode, normalizeHeading, FIX_SECTION_TITLE_FALLBACK } from '../route-node.mjs';
|
|
13
|
+
import { runRoot, fileExists, workflowRelativeSegments } from './guard-state-io.mjs';
|
|
14
|
+
|
|
15
|
+
// 新旧 change 区分——init 写入的 newChange: true = 新 change(严格,不依赖 entry——防系统性
|
|
16
|
+
// 跳 entry 绕过);缺失/非 true(旧 change)= 渐进 WARN 兼容。
|
|
17
|
+
export function isNewChange(state) {
|
|
18
|
+
return state.newChange === true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// flow-kit SUMMARY 模板必填段(正则匹配,大小写不敏感 + 变体兼容)
|
|
22
|
+
export const SUMMARY_REQUIRED_SECTIONS = [
|
|
23
|
+
{ regex: /##\s*verify\s*输出/i, label: '## verify 输出' },
|
|
24
|
+
{ regex: /##\s*6\s*维自查/i, label: '## 6 维自查' },
|
|
25
|
+
{ regex: /##\s*(越界检查|边界检查)/i, label: '## 越界检查' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// 校验 change 目录下每份 *-SUMMARY.md 含 SUMMARY 模板的三个必填段。用正则(大小写不敏感 +
|
|
29
|
+
// 变体兼容)——避免现有 SUMMARY 格式漂移导致误 BLOCKED。
|
|
30
|
+
export async function verifySummaries(changeDir) {
|
|
31
|
+
const files = (await fs.readdir(changeDir).catch(() => [])).filter(f => f.endsWith('-SUMMARY.md'));
|
|
32
|
+
const violations = [];
|
|
33
|
+
for (const f of files) {
|
|
34
|
+
const content = await fs.readFile(path.join(changeDir, f), 'utf8');
|
|
35
|
+
for (const section of SUMMARY_REQUIRED_SECTIONS) {
|
|
36
|
+
if (!section.regex.test(content)) violations.push(`${f} 缺 ${section.label}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return violations;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function slug(value) {
|
|
43
|
+
return String(value).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function generatedNodeSkillName(protocol, id) {
|
|
47
|
+
return (slug(protocol.name) || 'workflow') + '-' + (slug(id) || 'node');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function route(protocol) {
|
|
51
|
+
return protocol.nodes.filter((node) => !node.disabled);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function findNode(protocol, id) {
|
|
55
|
+
return route(protocol).find((node) => node.id === id || generatedNodeSkillName(protocol, node.id) === id) ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function completedSet(state) {
|
|
59
|
+
return new Set(Array.isArray(state.completedNodes) ? state.completedNodes : []);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 路由判定统一委托共享模块 route-node.mjs 的 resolveNextNode(单一实现——守卫与 workflow-state
|
|
63
|
+
// 两侧同语义,含多趟 parallel 回流与串行 pending → execute)。展示层(NEXT/NODE/SKILL 行)保留
|
|
64
|
+
// 在 printNext(展示文案逐字)。无活跃 change → null(完成态)。
|
|
65
|
+
export async function nextNode(protocol, state) {
|
|
66
|
+
if (!state.activeChange) return null;
|
|
67
|
+
const id = await resolveNextNode({
|
|
68
|
+
runRoot,
|
|
69
|
+
changeName: state.activeChange,
|
|
70
|
+
protocol,
|
|
71
|
+
completedNodes: Array.isArray(state.completedNodes) ? state.completedNodes : [],
|
|
72
|
+
});
|
|
73
|
+
return id ? findNode(protocol, id) : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function printNext(protocol, node) {
|
|
77
|
+
if (!node) {
|
|
78
|
+
console.log('NEXT: done');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
console.log('NEXT: auto');
|
|
82
|
+
console.log('NODE: ' + node.id);
|
|
83
|
+
console.log('SKILL: ' + generatedNodeSkillName(protocol, node.id));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// <depends_on> 提取(逗号/空白分隔)。与 workflow-state.mjs 各自保留既有正则实现、不提取到共享
|
|
87
|
+
// 解析层(task-parsing / state-schema 冻结为只消费)——两处语义由场景族锚定一致。
|
|
88
|
+
export function taskDependsOn(block) {
|
|
89
|
+
const m = String(block ?? '').match(/<depends_on>([\s\S]*?)<\/depends_on>/);
|
|
90
|
+
if (!m || !m[1].trim()) return [];
|
|
91
|
+
return m[1].trim().split(/[,\s]+/).filter(Boolean);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 委托进入谓词(每趟求值):∃ p ∈ tasks:p.parallel ∧ p.status=pending ∧ deps(p) ⊆ doneIds。
|
|
95
|
+
// 返回满足谓词的任务块数组——subagent-execute 出口的「尚有可委托」判定用,与 workflow-state.mjs
|
|
96
|
+
// determineNode 的路由谓词同语义(镜像同步点)。
|
|
97
|
+
export function eligibleParallelBlocks(blocks, doneIds) {
|
|
98
|
+
return blocks.filter((block) => {
|
|
99
|
+
const a = taskOpeningAttrs(block);
|
|
100
|
+
if (!a || !a.parallel || a.status !== 'pending') return false;
|
|
101
|
+
const deps = taskDependsOn(block);
|
|
102
|
+
return deps.every((d) => doneIds.has(d));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function evidenceFor(state, id) {
|
|
107
|
+
const value = state.evidence && typeof state.evidence === 'object' ? state.evidence[id] : null;
|
|
108
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function missingRequiredSkillChecks(node, evidence) {
|
|
112
|
+
const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
|
|
113
|
+
return (node.requiredSkillCalls ?? [])
|
|
114
|
+
.map((binding) => 'required-skill:' + node.id + '.' + binding.skill)
|
|
115
|
+
.filter((check) => !values.includes(check));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function missingAugmentationChecks(node, evidence) {
|
|
119
|
+
const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
|
|
120
|
+
return (node.augmentations ?? [])
|
|
121
|
+
.filter((binding) => binding.enforcement && binding.enforcement !== 'advisory')
|
|
122
|
+
.map((binding) => 'augmentation:' + node.id + '.' + binding.skill)
|
|
123
|
+
.filter((check) => !values.includes(check));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function hasEvidenceField(evidence, id) {
|
|
127
|
+
if (Object.prototype.hasOwnProperty.call(evidence, id)) return true;
|
|
128
|
+
const schemaEvidence = evidence.schemaEvidence;
|
|
129
|
+
return !!(
|
|
130
|
+
schemaEvidence &&
|
|
131
|
+
typeof schemaEvidence === 'object' &&
|
|
132
|
+
!Array.isArray(schemaEvidence) &&
|
|
133
|
+
Object.prototype.hasOwnProperty.call(schemaEvidence, id)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 共用证据库 handoffResult 识别——subagent-execute 的委托结果由 workflow-handoff result 写入嵌套
|
|
138
|
+
// handoffResult({ <taskId>: { result, completedAt } }),非顶层 handoff-result 字段;嵌套对象存在
|
|
139
|
+
// 且非空(至少一个任务记录)视为该 evidence 已产生(门禁只认存在性,内容严格校验由 Return
|
|
140
|
+
// Contract 校验负责)。
|
|
141
|
+
export function hasNonEmptyHandoffResult(evidence) {
|
|
142
|
+
const handoff = evidence?.handoffResult;
|
|
143
|
+
return !!(
|
|
144
|
+
handoff &&
|
|
145
|
+
typeof handoff === 'object' &&
|
|
146
|
+
!Array.isArray(handoff) &&
|
|
147
|
+
Object.keys(handoff).length > 0
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 在飞委托判定(验证隔离「同一时刻只有一个写者」)——handoffRequests 中存在条目而 handoffResult
|
|
152
|
+
// 无对应记录 = 写者未收工的既有可判形态。判据单处求值(出口校验唯一消费方)。三态收敛:无
|
|
153
|
+
// evidence['subagent-execute'] / 无 handoffRequests 条目 ⇒ 返回空数组(调用方零输出,不制造噪音);
|
|
154
|
+
// 全部有对应 result ⇒ 同样空数组(放行)。锚定既有字段,零新增 state 顶层字段。已撤回的 request
|
|
155
|
+
// 不构成在飞委托(补撤回通道):零提交复验失败 / 写边界被拒之后 request 可能留在「有 request 无
|
|
156
|
+
// result」态而命令面无从撤回——`workflow-handoff.mjs withdraw` 在原地落留痕(withdrawnAt +
|
|
157
|
+
// withdrawnBy,历史不删),守卫据此放行出口。判据复用 state-schema.mjs 的单一实现(撤回留痕两
|
|
158
|
+
// 字段齐备才算撤回),本模块不另写一份。
|
|
159
|
+
export function inFlightHandoffRequests(evidence) {
|
|
160
|
+
const requests = evidence && typeof evidence === 'object' ? evidence.handoffRequests : null;
|
|
161
|
+
if (!requests || typeof requests !== 'object' || Array.isArray(requests)) return [];
|
|
162
|
+
const results = evidence.handoffResult && typeof evidence.handoffResult === 'object' && !Array.isArray(evidence.handoffResult)
|
|
163
|
+
? evidence.handoffResult
|
|
164
|
+
: {};
|
|
165
|
+
return Object.keys(requests).filter((taskId) => {
|
|
166
|
+
if (handoffRequestWithdrawn(requests[taskId])) return false;
|
|
167
|
+
return results[taskId] === undefined || results[taskId] === null;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function schemaMap(protocol) {
|
|
172
|
+
return new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function missingRequiredSchemaEvidence(protocol, node, evidence) {
|
|
176
|
+
const schemas = schemaMap(protocol);
|
|
177
|
+
const missing = [];
|
|
178
|
+
// schema evidence 缺失但 record 传了 summary → 以 summary 视为产出证据(避免手动构造各字段)
|
|
179
|
+
const hasSummary = typeof evidence?.summary === 'string' && evidence.summary.trim() !== '';
|
|
180
|
+
for (const schemaId of node.outputSchemas ?? []) {
|
|
181
|
+
const schema = schemas.get(schemaId);
|
|
182
|
+
for (const field of schema?.evidence ?? []) {
|
|
183
|
+
if (field.required && !hasEvidenceField(evidence, field.id) && !hasSummary) {
|
|
184
|
+
missing.push(schemaId + '.' + field.id);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return missing;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function escapeRegExp(value) {
|
|
192
|
+
return String(value).replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function patternToRegExp(pattern) {
|
|
196
|
+
return new RegExp('^' + String(pattern).split('*').map(escapeRegExp).join('.*') + '$', 'u');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function pathPatternExists(root, relativePattern) {
|
|
200
|
+
const parts = workflowRelativeSegments(relativePattern, 'artifact path', true);
|
|
201
|
+
async function walk(current, index) {
|
|
202
|
+
const inspection = await inspectWorkflowProtectedPath(
|
|
203
|
+
runRoot,
|
|
204
|
+
current,
|
|
205
|
+
'workflow artifact path',
|
|
206
|
+
index >= parts.length ? 'any' : 'directory',
|
|
207
|
+
);
|
|
208
|
+
if (!inspection.exists) return false;
|
|
209
|
+
if (index >= parts.length) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
const part = parts[index];
|
|
213
|
+
if (!part.includes('*')) {
|
|
214
|
+
return walk(path.join(current, part), index + 1);
|
|
215
|
+
}
|
|
216
|
+
let entries;
|
|
217
|
+
try {
|
|
218
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
const matcher = patternToRegExp(part);
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
if (entry.isSymbolicLink()) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
'workflow artifact path crosses a symbolic link or junction at ' +
|
|
227
|
+
path.join(current, entry.name),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
if (matcher.test(entry.name) && (await walk(path.join(current, entry.name), index + 1))) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
return walk(root, 0);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 产物根解析:'project'/缺省 → runRoot;'specs-root' → runRoot/.specs。classic/native 等 pathBase
|
|
240
|
+
// 依赖项目配置文件,已随 Comet 感知层剥离——不再读取任何项目配置,遇到即显式报错(fail-fast,
|
|
241
|
+
// 与 route-node.mjs 的状态机推导侧同语义),不静默兜底。
|
|
242
|
+
export async function workflowArtifactRoot(pathBase) {
|
|
243
|
+
if (pathBase === undefined || pathBase === 'project') {
|
|
244
|
+
await inspectWorkflowProtectedPath(runRoot, runRoot, 'workflow path base', 'directory');
|
|
245
|
+
return runRoot;
|
|
246
|
+
}
|
|
247
|
+
if (pathBase === 'specs-root') {
|
|
248
|
+
return path.join(runRoot, '.specs');
|
|
249
|
+
}
|
|
250
|
+
throw new Error('产物根 pathBase "' + pathBase + '" 不再支持——请改用 specs-root/project + 完整路径(如 project + openspec/changes/xxx.md)');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export async function missingRequiredArtifacts(protocol, node, change) {
|
|
254
|
+
const schemas = schemaMap(protocol);
|
|
255
|
+
const missing = [];
|
|
256
|
+
for (const schemaId of node.outputSchemas ?? []) {
|
|
257
|
+
const schema = schemas.get(schemaId);
|
|
258
|
+
for (const artifact of schema?.artifacts ?? []) {
|
|
259
|
+
if (!artifact.required) continue;
|
|
260
|
+
const exists = (
|
|
261
|
+
await Promise.all(
|
|
262
|
+
(artifact.paths ?? []).map(async (artifactPath) => {
|
|
263
|
+
// 替换 <change-id> 占位符为实际 change(如 name-format-unify)
|
|
264
|
+
const resolvedPath = change ? artifactPath.replaceAll('<change-id>', change) : artifactPath;
|
|
265
|
+
return pathPatternExists(await workflowArtifactRoot(artifact.pathBase), resolvedPath);
|
|
266
|
+
}),
|
|
267
|
+
)
|
|
268
|
+
).some(Boolean);
|
|
269
|
+
if (!exists) missing.push(schemaId + '.' + artifact.id);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return missing;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 历史归档 change 不强制真实跑验证命令(判断 .specs/archive/ 目录)
|
|
276
|
+
export async function isArchivedChange(changeName) {
|
|
277
|
+
if (!changeName) return false;
|
|
278
|
+
const archiveRoot = path.join(runRoot, '.specs', 'archive');
|
|
279
|
+
if (await fileExists(path.join(archiveRoot, changeName))) return true;
|
|
280
|
+
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
281
|
+
return entries.some(e => e === changeName || e.endsWith('-' + changeName));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 声明标记目录解析——活动路径 .specs/<change-id>/.skill-loads/ 优先;归档路径兜底(archive 节点
|
|
285
|
+
// 「先移目录后 record/exit」顺序下 change 目录已在 .specs/archive/<前缀>-<change-id>/,标记只随
|
|
286
|
+
// 目录移动——只查活动路径会把「标记存在」误判成「机制未激活」)。归档扫描匹配后缀 -<change-id>
|
|
287
|
+
// (前缀可含日期等,与协议 flowkit.archive.v1 的 archive/*-<change-id> 同构)。两者皆无 → null
|
|
288
|
+
// (声明机制从未激活,调用方按旧 change 兼容跳过)。
|
|
289
|
+
export async function findSkillLoadsDir(root, changeName) {
|
|
290
|
+
const activeDir = path.join(root, '.specs', changeName, '.skill-loads');
|
|
291
|
+
if (await fileExists(activeDir)) {
|
|
292
|
+
return { dir: activeDir, display: '.specs/' + changeName + '/.skill-loads/' };
|
|
293
|
+
}
|
|
294
|
+
const archiveRoot = path.join(root, '.specs', 'archive');
|
|
295
|
+
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
296
|
+
for (const entry of entries) {
|
|
297
|
+
if (!entry.endsWith('-' + changeName)) continue;
|
|
298
|
+
const candidate = path.join(archiveRoot, entry, '.skill-loads');
|
|
299
|
+
if (await fileExists(candidate)) {
|
|
300
|
+
return { dir: candidate, display: '.specs/archive/' + entry + '/.skill-loads/' };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 段名校验从模板自动派生——读 <runRoot>/flow-kit/templates/{CHANGE,REQUIREMENT,DESIGN,SUMMARY}.md
|
|
307
|
+
// 提取全部 ^## 段名,正则化生成宽松匹配模式;模板目录/文件缺失时 fallback 内置段名。
|
|
308
|
+
export const TEMPLATE_FALLBACK_SECTION_PATTERNS = {
|
|
309
|
+
changeWhy: /^##\s*Why\b/im,
|
|
310
|
+
changeVisualTone: /^##\s*视觉调性/im,
|
|
311
|
+
requirementUserStory: /^##\s*用户故事/im,
|
|
312
|
+
requirementAcceptance: /##\s*(验收准则|验收标准|AC|Acceptance Criteria)/i,
|
|
313
|
+
designDecisionList: /^##\s*\d*\.?\s*决策清单/m,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
let templateSectionPatternsCacheRoot = null;
|
|
317
|
+
let templateSectionPatternsCache = null;
|
|
318
|
+
|
|
319
|
+
// 模板段名 → 宽松匹配正则:编号前缀(1. / 0.5)可选 + 段名主体字面匹配 + 尾部括号内容(如 (AC))可选
|
|
320
|
+
export function templateSectionPattern(rawName) {
|
|
321
|
+
const name = String(rawName).trim();
|
|
322
|
+
const body = name
|
|
323
|
+
.replace(/[((][^))\n]*[))]\s*$/u, '') // 去尾部括号内容:Why(为什么做)→ Why
|
|
324
|
+
.replace(/^\d+(?:\.\d+)?\.?\s*/u, '') // 去编号前缀:1. 决策清单 → 决策清单
|
|
325
|
+
.trim();
|
|
326
|
+
const escaped = escapeRegExp(body || name);
|
|
327
|
+
return new RegExp(
|
|
328
|
+
'^##\\s*(?:\\d+(?:\\.\\d+)?\\.?\\s*)?' + escaped + '\\s*(?:[((][^\\n))]*[))])?\\s*$',
|
|
329
|
+
'im',
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 读取模板全部段名生成模式列表(模块级缓存,避免每次 exit 重复读文件);pick 按关键词选段,找不到 → fallback
|
|
334
|
+
export async function templateSectionPatterns() {
|
|
335
|
+
if (templateSectionPatternsCacheRoot === runRoot && templateSectionPatternsCache) {
|
|
336
|
+
return templateSectionPatternsCache;
|
|
337
|
+
}
|
|
338
|
+
const templateDir = path.join(runRoot, 'flow-kit', 'templates');
|
|
339
|
+
const result = { change: [], requirement: [], design: [], summary: [] };
|
|
340
|
+
for (const [key, fileName] of Object.entries({
|
|
341
|
+
change: 'CHANGE.md',
|
|
342
|
+
requirement: 'REQUIREMENT.md',
|
|
343
|
+
design: 'DESIGN.md',
|
|
344
|
+
summary: 'SUMMARY.md',
|
|
345
|
+
})) {
|
|
346
|
+
const templateFile = path.join(templateDir, fileName);
|
|
347
|
+
if (await fileExists(templateFile)) {
|
|
348
|
+
try {
|
|
349
|
+
const text = await fs.readFile(templateFile, 'utf8');
|
|
350
|
+
for (const match of text.matchAll(/^##\s+(.+)$/gmu)) {
|
|
351
|
+
const sectionName = match[1].trim();
|
|
352
|
+
result[key].push({ name: sectionName, regex: templateSectionPattern(sectionName) });
|
|
353
|
+
}
|
|
354
|
+
} catch {}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
result.pick = (key, keywords, fallback) => {
|
|
358
|
+
for (const section of result[key] ?? []) {
|
|
359
|
+
if (keywords.some((keyword) => section.name.includes(keyword))) return section.regex;
|
|
360
|
+
}
|
|
361
|
+
return fallback;
|
|
362
|
+
};
|
|
363
|
+
templateSectionPatternsCache = result;
|
|
364
|
+
templateSectionPatternsCacheRoot = runRoot;
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Fix 段标题从 <runRoot>/flow-kit/templates/TASK.md 派生(单一模板源 + 模块级缓存 + runRoot 键控):
|
|
369
|
+
// 扫描模板全部 H2,用 route-node 共享 heading 归一(单一权威,含闭合 ATX)识别 Fix 段标题;无匹配
|
|
370
|
+
// (模板缺失 / 读取失败 / 无 Fix 段)返回 undefined,由回程分类器的内置 fallback 常量兜底。标题只
|
|
371
|
+
// 喂给回程分类器决定审计行(不参与路由/state 写入)。识别标记词从单一权威 fallback 派生(归一后
|
|
372
|
+
// 首词,如 Fix 任务 → Fix),因此模板基名改为其它语言后缀(如 Fix Tasks)仍可识别;闭合 ATX 与尾部
|
|
373
|
+
// 括号变体由共享归一消化。
|
|
374
|
+
const FIX_SECTION_HEADING_MARKER = normalizeHeading(FIX_SECTION_TITLE_FALLBACK).split(/\s+/u)[0];
|
|
375
|
+
|
|
376
|
+
// 模板文本全部 H2 中的 Fix 段标题(无匹配 → undefined):共享归一后与识别标记词比较,
|
|
377
|
+
// 因此语言后缀可变(Fix 任务 / Fix Tasks);闭合 ATX 与尾部括号由共享归一消化。
|
|
378
|
+
export function fixSectionTitleFromTemplateText(text) {
|
|
379
|
+
for (const match of String(text).matchAll(/^##\s+(.+)$/gmu)) {
|
|
380
|
+
const raw = match[1].trim();
|
|
381
|
+
const normalized = normalizeHeading(raw);
|
|
382
|
+
if (normalized === FIX_SECTION_HEADING_MARKER
|
|
383
|
+
|| normalized.startsWith(FIX_SECTION_HEADING_MARKER + ' ')) return raw;
|
|
384
|
+
}
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let fixSectionTitleCacheRoot = null;
|
|
389
|
+
let fixSectionTitleCached = false;
|
|
390
|
+
let fixSectionTitleCache;
|
|
391
|
+
export async function derivedFixSectionTitle() {
|
|
392
|
+
if (fixSectionTitleCacheRoot === runRoot && fixSectionTitleCached) return fixSectionTitleCache;
|
|
393
|
+
let title;
|
|
394
|
+
const templateFile = path.join(runRoot, 'flow-kit', 'templates', 'TASK.md');
|
|
395
|
+
if (await fileExists(templateFile)) {
|
|
396
|
+
try {
|
|
397
|
+
title = fixSectionTitleFromTemplateText(await fs.readFile(templateFile, 'utf8'));
|
|
398
|
+
} catch {}
|
|
399
|
+
}
|
|
400
|
+
fixSectionTitleCache = title;
|
|
401
|
+
fixSectionTitleCacheRoot = runRoot;
|
|
402
|
+
fixSectionTitleCached = true;
|
|
403
|
+
return title;
|
|
404
|
+
}
|