flow-comet 1.6.4 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +36 -6
- package/.flow-comet/skills/flow-comet/reference/artifact-template-overlay.md +154 -0
- package/.flow-comet/skills/flow-comet/reference/artifact-templates.json +387 -0
- package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/entry-detail.md +29 -4
- package/.flow-comet/skills/flow-comet/reference/workflow-protocol.json +22 -0
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +26 -23
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +174 -0
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +17 -95
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +28 -4
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +136 -19
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +54 -18
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +52 -10
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +25 -10
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +4 -2
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +21 -13
- package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +163 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/ac-coverage.mjs +317 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-artifact-skeleton.mjs +448 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +396 -27
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +1035 -172
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +129 -98
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +8 -6
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +797 -232
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +91 -22
- package/.flow-comet/skills/flow-comet/scripts/lib/lessons-hits.mjs +160 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/run-root.mjs +21 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/section-body.mjs +92 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +69 -13
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +454 -135
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +66 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +109 -13
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +55 -2
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +149 -34
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +79 -9
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +84 -31
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +78 -8
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +60 -3
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +167 -3
- package/.flow-comet/skills/flow-comet/scripts/lib/wave-projection.mjs +341 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +1454 -16
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1202 -8
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1205 -77
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +753 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +52 -11
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +582 -3
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +9 -1
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +5 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +22 -6
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +2 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +18 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +4100 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +135 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +6 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +203 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +312 -63
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +5 -2
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-change/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-design/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-design/SKILL.md +15 -8
- package/.flow-comet/skills/flow-comet-dev/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-evolve/SKILL.md +1 -0
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +42 -15
- package/.flow-comet/skills/flow-comet-health/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-open/GUIDANCE.md +14 -4
- package/.flow-comet/skills/flow-comet-open/SKILL.md +11 -9
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +21 -10
- package/.flow-comet/skills/flow-comet-requirement/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +33 -18
- package/.flow-comet/skills/flow-comet-subagent-execute/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +44 -16
- package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
- package/.flow-comet/skills/flow-comet-test/SKILL.md +6 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +2 -2
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +12 -8
- package/README.md +3 -3
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-flowkit.mjs +43 -3
|
@@ -10,13 +10,20 @@
|
|
|
10
10
|
// 按 `<nodeId>.<skill>` 键控,工件门与出口自动补写共用 applicabilityGatedBinding 查询。
|
|
11
11
|
//
|
|
12
12
|
// 判据必须结构性可判:CHANGE.md 的「视觉调性」段在场且段内不含**结构形态**的「不适用」标记 ⇒
|
|
13
|
-
//
|
|
14
|
-
//
|
|
13
|
+
// 前端;段内以结构形态标注 ⇒ 非前端。段**缺席**只在旧 change 上沿用「判非前端」的兼容口径——
|
|
14
|
+
// 新 change 由 open 出口按模板条件段拦(标题必须在场),此处缺席即拦,不再默认判非前端
|
|
15
|
+
// (否则「漏写段」会被静默翻译成一个更弱的门)。
|
|
16
|
+
//
|
|
17
|
+
// UI-DESIGN.md 在场时,其模板结构(frontmatter 8 键 / H2 骨架 / 结构型 H3)由产出物模板结构门禁
|
|
18
|
+
// 统一校验(与七类产出物同一实现,不在这里另写一份段名校验)。
|
|
15
19
|
|
|
16
20
|
import { promises as fs } from 'fs';
|
|
17
21
|
import path from 'path';
|
|
18
22
|
import { runRoot, fileExists } from './guard-state-io.mjs';
|
|
19
23
|
import { isNewChange, templateSectionPatterns, TEMPLATE_FALLBACK_SECTION_PATTERNS } from './guard-routing.mjs';
|
|
24
|
+
import { assessArtifact, evaluateArtifact, reportArtifactStructure } from './guard-template-fidelity.mjs';
|
|
25
|
+
// 段界(下一个二级标题 / 文末)取 lib/section-body.mjs 的唯一实现:围栏代码块里的 `## ` 是正文示例。
|
|
26
|
+
import { sectionBody } from './section-body.mjs';
|
|
20
27
|
|
|
21
28
|
export const UI_DESIGN_SKILL = 'flow-comet-ui-design';
|
|
22
29
|
const APPLICABILITY_GATED_BINDINGS = new Set(['design.' + UI_DESIGN_SKILL]);
|
|
@@ -40,27 +47,32 @@ const TONE_MARKER_FIELD_VALUE = new RegExp(String.raw`(?:^|[\s|])(?:\*\*)?(?:`
|
|
|
40
47
|
+ TONE_MARKER_FIELD_LABELS + String.raw`)(?:\*\*)?\s*[::]\s*(?:\*\*)?`
|
|
41
48
|
+ VISUAL_TONE_NOT_APPLICABLE + String.raw`(?:\*\*)?` + TONE_MARKER_TAIL);
|
|
42
49
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
// 「视觉调性」段读取四态(区分「CHANGE.md 不存在」「模板整份缺失」「段缺席」「段在场」——四者判据
|
|
51
|
+
// 不同:文件不存在时本门没有输入,交给其余门禁处理;模板整份缺失时段名无从派生(no-basis,按
|
|
52
|
+
// 「未校验」显式跳过);段缺席才按 newChange 分级,C10)。
|
|
53
|
+
async function visualToneSectionState(changeName) {
|
|
54
|
+
if (!changeName) return { state: 'file-missing', body: null };
|
|
46
55
|
let text;
|
|
47
56
|
try {
|
|
48
57
|
text = await fs.readFile(path.join(runRoot, '.specs', changeName, 'CHANGE.md'), 'utf8');
|
|
49
58
|
} catch {
|
|
50
|
-
return null;
|
|
59
|
+
return { state: 'file-missing', body: null };
|
|
51
60
|
}
|
|
52
61
|
const headingPattern = (await templateSectionPatterns())
|
|
53
62
|
.pick('change', ['视觉调性'], TEMPLATE_FALLBACK_SECTION_PATTERNS.changeVisualTone);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (body !== null) body += line + '\n';
|
|
63
|
+
// 整份模板缺席时 pick 返回可判别的跳过判据(TEMPLATE_SECTION_SKIP:skip 标记 + `.test` 恒真)。
|
|
64
|
+
// 不能拿它扫描:`.test` 恒真会让 CHANGE.md 的**首个小节**被当成「视觉调性」段(错的输入 = 错的
|
|
65
|
+
// 判据)。此时段名无从派生,显式报 no-basis 由调用方按「未校验(模板缺失)」处理;模板在场时
|
|
66
|
+
// pick 返回正则或 fallback,行为不变。
|
|
67
|
+
if (headingPattern !== null && typeof headingPattern === 'object' && headingPattern.skip === true) {
|
|
68
|
+
return { state: 'no-basis', body: null };
|
|
62
69
|
}
|
|
63
|
-
|
|
70
|
+
// 段界由 lib/section-body.mjs 单点决定(围栏代码块里的 `## ` 不结束本段)。此前这里是一份围栏盲
|
|
71
|
+
// 的按行扫描:段内贴一段 Markdown 示例后,示例之后的「不适用」声明整段消失,非前端 change 被误判
|
|
72
|
+
// 成前端(要求一份本不该存在的 UI-DESIGN.md)。本判据自己的语义保留:只认二级标题(level: 2)、
|
|
73
|
+
// 分隔线不结束本段(endOnSeparator: false)——「视觉调性」段以 `---` 分隔清单是既有书写形态。
|
|
74
|
+
const body = sectionBody(text, headingPattern, { level: 2, endOnSeparator: false });
|
|
75
|
+
return body === null ? { state: 'section-missing', body: null } : { state: 'present', body };
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
// 段内负向标记命中(逐行判定——判据限段内):命中 → 返回命中行片段(去空白 + 超长截断),未命中
|
|
@@ -90,15 +102,36 @@ export function applicabilityGatedBinding(node, skill) {
|
|
|
90
102
|
return (node.requiredSkillCalls ?? []).find((call) => call.skill === skill && call.enforcement === 'guarded') ?? null;
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
// 前端判据:{ applicable, reason }——applicable=true 表示本 change
|
|
105
|
+
// 前端判据:{ applicable, reason, toneState }——applicable=true 表示本 change 判为前端项目。
|
|
106
|
+
// toneState 让调用方区分「段缺席」「模板整份缺失(no-basis,判据无依据)」与「段内标注不适用」:
|
|
107
|
+
// 段缺席在新 change 上必须拦(不能静默降级成非前端),最后一种是执行者显式声明,直接放行;
|
|
108
|
+
// no-basis 按「未校验」显式跳过,由调用方决定如何发声。
|
|
94
109
|
export async function frontendCriterion(changeName) {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
110
|
+
const tone = await visualToneSectionState(changeName);
|
|
111
|
+
if (tone.state === 'file-missing') {
|
|
112
|
+
return { applicable: false, reason: 'CHANGE.md 不存在(本门无输入)', toneState: tone.state };
|
|
113
|
+
}
|
|
114
|
+
if (tone.state === 'no-basis') {
|
|
115
|
+
// 模板整份缺失 ⇒ 段名无从派生,本判据没有输入依据。不猜(不用首个小节冒充「视觉调性」段),
|
|
116
|
+
// 也不判前端:交给调用方按「未校验(模板缺失)」显式跳过(未验证 ≠ 通过,C9)。
|
|
117
|
+
return {
|
|
118
|
+
applicable: false,
|
|
119
|
+
reason: '「视觉调性」段判据无可依据(模板整份缺失,段名无从派生)',
|
|
120
|
+
toneState: tone.state,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (tone.state === 'section-missing') {
|
|
124
|
+
return { applicable: false, reason: '「视觉调性」段缺席', toneState: tone.state };
|
|
125
|
+
}
|
|
126
|
+
const hit = visualToneNotApplicableHit(tone.body);
|
|
98
127
|
if (hit !== null) {
|
|
99
|
-
return {
|
|
128
|
+
return {
|
|
129
|
+
applicable: false,
|
|
130
|
+
reason: '「视觉调性」段标注「不适用」(判非前端;命中片段: ' + hit + ')',
|
|
131
|
+
toneState: tone.state,
|
|
132
|
+
};
|
|
100
133
|
}
|
|
101
|
-
return { applicable: true, reason: '「视觉调性」段在场且未标注「不适用」(判前端;无结构形态标记)' };
|
|
134
|
+
return { applicable: true, reason: '「视觉调性」段在场且未标注「不适用」(判前端;无结构形态标记)', toneState: tone.state };
|
|
102
135
|
}
|
|
103
136
|
|
|
104
137
|
// design 出口 ui-design 工件门(按协议绑定键控:登记 ∧ 等级 = guarded ∧ 判据成立)——判据成立 ⇒
|
|
@@ -115,12 +148,48 @@ export async function checkUiDesignArtifact(node, state) {
|
|
|
115
148
|
return;
|
|
116
149
|
}
|
|
117
150
|
const frontend = await frontendCriterion(state.activeChange);
|
|
151
|
+
if (frontend.toneState === 'no-basis') {
|
|
152
|
+
// 模板整份缺失:适用性门控的输入判据不存在,按「未校验」显式跳过(不静默通过,也不误报非前端)。
|
|
153
|
+
console.error('UI-DESIGN 未校验(模板缺失)——flow-kit/templates/CHANGE.md 不在项目根,'
|
|
154
|
+
+ '「视觉调性」段名无从派生,适用性门控跳过');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (frontend.toneState === 'section-missing') {
|
|
158
|
+
// 段缺席不再默认判非前端:新 change 由 open 出口的条件段门禁拦,此处兜底同口径拦下,
|
|
159
|
+
// 要求执行者显式写「不适用」(缺席与声明不适用是两件事,只有后者是决策)。
|
|
160
|
+
const toneRecovery = '在 .specs/' + state.activeChange + '/CHANGE.md 的「视觉调性」段填写选定调性,'
|
|
161
|
+
+ '或以结构形态标注「不适用」(非前端项目),然后重试 exit design';
|
|
162
|
+
if (isNewChange(state)) {
|
|
163
|
+
console.error('BLOCKED: CHANGE.md 的「视觉调性」段缺席——新 change 须显式标注「不适用」或填写调性(段缺席不再默认判非前端)');
|
|
164
|
+
console.error('恢复: ' + toneRecovery);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
console.error('UI-DESIGN: skipped(旧 change 兼容)——「视觉调性」段缺席,沿用旧口径判非前端');
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
118
170
|
if (!frontend.applicable) {
|
|
119
171
|
console.error('UI-DESIGN: skipped(非前端)——' + frontend.reason + ',不要求 UI-DESIGN.md');
|
|
120
172
|
return;
|
|
121
173
|
}
|
|
122
174
|
const artifact = path.join(runRoot, '.specs', state.activeChange, 'UI-DESIGN.md');
|
|
123
|
-
if (await fileExists(artifact))
|
|
175
|
+
if (await fileExists(artifact)) {
|
|
176
|
+
// 工件在场 → 按模板结构校验(frontmatter 8 键 / H2 骨架 / 结构型 H3);模板缺席只输出未校验行。
|
|
177
|
+
let text;
|
|
178
|
+
try {
|
|
179
|
+
text = await fs.readFile(artifact, 'utf8');
|
|
180
|
+
} catch {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// 标题形态与 frontmatter 键都属于「模板结构」面:模板缺席时整体判「未校验(模板缺失)」,
|
|
184
|
+
// 不拿登记表形态去替模板做缺席判定(C9/AC-21 的统一口径)。
|
|
185
|
+
const { skeleton, derived, issues } = await evaluateArtifact('UI-DESIGN', text, { underivedPolicy: 'skip' });
|
|
186
|
+
await reportArtifactStructure({
|
|
187
|
+
changeDir: path.join(runRoot, '.specs', state.activeChange),
|
|
188
|
+
state,
|
|
189
|
+
assessments: [assessArtifact({ fileLabel: 'UI-DESIGN.md', skeleton, derived, issues })],
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
124
193
|
const recovery = '补 .specs/' + state.activeChange + '/UI-DESIGN.md(加载 ' + UI_DESIGN_SKILL + ' 并按其协议产出 design token / 反 AI-slop 自检),'
|
|
125
194
|
+ '或在 .specs/' + state.activeChange + '/CHANGE.md 的「视觉调性」段以结构形态标注「不适用」(非前端项目)后重试 exit design';
|
|
126
195
|
if (isNewChange(state)) {
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// lessons-hits.mjs — LESSONS 命中集的单一实现(出口门禁与 handoff request 共用)
|
|
2
|
+
//
|
|
3
|
+
// 命中集 = 任务 <write_files> 的路径词元 × .specs/LESSONS.md 条目的关键词行(共享词元多者在前,
|
|
4
|
+
// 同分按条目出现顺序,取前 LESSONS_HIT_LIMIT 条)。出口据此要求 SUMMARY 的 ## LESSONS 扫描 段
|
|
5
|
+
// 逐条回应这些编号;开工前 handoff request 打印同一集合——执行者按看到的集合写回应,不必等到
|
|
6
|
+
// 出口才发现缺项。
|
|
7
|
+
//
|
|
8
|
+
// 两处必须同一实现:各算一套会让「写回应的人」与「验回应的人」按不同集合对齐。本模块只做纯文本
|
|
9
|
+
// 计算,读文件由调用方负责(出口读 change 目录,request 读项目级教训册)。
|
|
10
|
+
|
|
11
|
+
import { taskBlocks, taskOpeningAttrs } from '../task-parsing.mjs';
|
|
12
|
+
// 围栏行判定取段体单源的唯一实现(反引号与波浪号同口径):本模块自己按行判围栏时只认反引号,
|
|
13
|
+
// 波浪号围栏里的书写样例就被当成真条目(出口与 request 打印面会多出「该回应」的假编号)。
|
|
14
|
+
import { isFenceLine } from './section-body.mjs';
|
|
15
|
+
|
|
16
|
+
// 命中上限:出口与打印面同取此值(单处定义,消费方不得各写一个数字)。
|
|
17
|
+
export const LESSONS_HIT_LIMIT = 5;
|
|
18
|
+
|
|
19
|
+
// 路径词元的停用词(目录布局噪音 + 扩展名残片):只作用于「命中计算」的路径侧——条目关键词侧
|
|
20
|
+
// 原样保留,过滤口径不扩散成第二份规则。
|
|
21
|
+
const LESSONS_PATH_STOPWORDS = new Set([
|
|
22
|
+
// 目录布局噪音
|
|
23
|
+
'src', 'lib', 'libs', 'app', 'apps', 'core', 'pkg', 'packages', 'bin', 'dist', 'build', 'out',
|
|
24
|
+
'tmp', 'temp', 'test', 'tests', 'spec', 'specs', 'unit', 'e2e', 'fixture', 'fixtures',
|
|
25
|
+
'mock', 'mocks', 'docs', 'doc', 'scripts', 'script', 'assets', 'static', 'public',
|
|
26
|
+
'config', 'configs', 'utils', 'util', 'helpers', 'helper', 'common', 'shared', 'internal',
|
|
27
|
+
'modules', 'module', 'components', 'pages', 'views', 'styles', 'data', 'types', 'index',
|
|
28
|
+
// 扩展名 / 备份后缀残片
|
|
29
|
+
'mjs', 'cjs', 'jsx', 'tsx', 'json', 'yaml', 'yml', 'toml', 'lock', 'bak', 'log', 'txt', 'css',
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const LESSONS_ENTRY_HEADING = /^###\s*L-(\d+)\b/u;
|
|
33
|
+
const LESSONS_KEYWORD_LINE = /^[-*\s]*\*\*关键词\*\*\s*[::]\s*(.+)$/u;
|
|
34
|
+
// 条目标题(### L-NNN 之后的部分)与编号之间的分隔符:只用于打印面,命中判定仍只看关键词行。
|
|
35
|
+
const LESSONS_TITLE_LEAD = /^[\s·::\-—]+/u;
|
|
36
|
+
|
|
37
|
+
// <write_files> 元素提取:正则**唯一一份**,且大小写不敏感——元素名按 HTML 语义与大小写无关
|
|
38
|
+
// (`<WRITE_FILES>` 与 `<write_files>` 是同一种元素;plan 出口的 7 字段门正是按 /i 判在场的)。
|
|
39
|
+
// 写面判定若只认小写,同一份 TASK.md 会在两道门里得到两种结论:任务被判「字段在场」,却在
|
|
40
|
+
// 「算不算有写面」处判未知——判据缺席即放行。
|
|
41
|
+
const WRITE_FILES_ELEMENT_RE = /<write_files>([\s\S]*?)<\/write_files>/iu;
|
|
42
|
+
|
|
43
|
+
// 块内写面元素原文(块内没有该元素 → null)。
|
|
44
|
+
function writeFilesElement(block) {
|
|
45
|
+
const matched = String(block ?? '').match(WRITE_FILES_ELEMENT_RE);
|
|
46
|
+
return matched === null ? null : matched[1];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// write_files 元素原文(键 = 任务 id):块提取与开标签解析复用 task-parsing 的既有实现——出口按任务
|
|
50
|
+
// 文件逐个任务取写面,打印面按同一提取取同一个任务的写面,两侧输入必须同源。
|
|
51
|
+
export function taskWriteFilesById(taskContent) {
|
|
52
|
+
const out = new Map();
|
|
53
|
+
for (const block of taskBlocks(taskContent)) {
|
|
54
|
+
const attrs = taskOpeningAttrs(block);
|
|
55
|
+
if (!attrs || !attrs.id) continue;
|
|
56
|
+
const element = writeFilesElement(block);
|
|
57
|
+
if (element !== null) out.set(attrs.id, element);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// write_files 元素原文 → 条目列表(剥 HTML 注释 → 按行切 → 分号容错二次切 → trim → 滤空)。
|
|
63
|
+
// 这是**条目边界**的唯一实现,三个消费方取用它:workflow-handoff 的提交子集校验(允许列表)、
|
|
64
|
+
// guard-gates 的伪并行启发式(哪些条目只落在测试面)、task-graph 的路径解析(族①②③的读写面)。
|
|
65
|
+
// 同一份写面被切成不同条目集时,「谁越界」「哪一对并行任务重叠」会给出互相矛盾的结论,而两处
|
|
66
|
+
// 各自自洽、不会变红——边界只在 SDK 侧可见,故收在此处。
|
|
67
|
+
// 路径归一是各消费方自己的事,刻意不进来:handoff 只做 POSIX 化(为了与 git 的 --name-only 输出
|
|
68
|
+
// 对齐),task-graph 另有 `.` / `..` 段的解析(逃出项目根按越界返回 null)。归一差异不改变条目
|
|
69
|
+
// 边界,两件事不要混在一层。
|
|
70
|
+
export function writeFilesEntries(elementText) {
|
|
71
|
+
return String(elementText ?? '')
|
|
72
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
73
|
+
.trim()
|
|
74
|
+
.split(/\s*\n\s*/)
|
|
75
|
+
.map((entry) => entry.trim())
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.flatMap((entry) => entry.split(';'))
|
|
78
|
+
.map((entry) => entry.trim())
|
|
79
|
+
.filter(Boolean);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 任务块「有写面」判定(本条判定的唯一落点):元素在场**且**按条目边界切出的条目非空——空元素与
|
|
83
|
+
// 只有注释的元素都是「写面不可判」,不是「写面为空」。元素提取与条目边界都取本模块的唯一实现,
|
|
84
|
+
// 故「7 字段门判字段在场」与「算不算有写面」不会在元素名大小写或注释剥离上分叉:分叉时任务被
|
|
85
|
+
// 静默排除在判定面之外,而判据缺席与判据通过在下游看起来一样(都只是「没有明细」)。
|
|
86
|
+
export function taskHasWriteFace(block) {
|
|
87
|
+
const element = writeFilesElement(block);
|
|
88
|
+
return element !== null && writeFilesEntries(element).length > 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 路径段 → 词元:目录名与文件主干(去最后一层扩展名)按非字母数字切分,长度 ≥3、去停用词、去纯数字。
|
|
92
|
+
// 只在「命中计算」这一侧做长度与停用词过滤——条目关键词侧原样保留,过滤口径不扩散成第二份规则。
|
|
93
|
+
// 条目边界同样取 writeFilesEntries(本模块内不再有第二份按行/分号的切分:注释里的词不构成路径)。
|
|
94
|
+
export function lessonsPathTokens(writeFilesText) {
|
|
95
|
+
const tokens = new Set();
|
|
96
|
+
for (const raw of writeFilesEntries(writeFilesText)) {
|
|
97
|
+
const segments = raw.trim().replace(/\\/gu, '/').split('/').filter((s) => s !== '' && s !== '.' && s !== '..');
|
|
98
|
+
segments.forEach((segment, index) => {
|
|
99
|
+
const body = index === segments.length - 1 ? segment.replace(/\.[^.]*$/u, '') : segment;
|
|
100
|
+
for (const piece of body.split(/[^0-9A-Za-z\u4e00-\u9fff]+/u)) {
|
|
101
|
+
const token = piece.toLowerCase();
|
|
102
|
+
if ([...token].length < 3) continue;
|
|
103
|
+
if (/^\d+$/u.test(token)) continue;
|
|
104
|
+
if (LESSONS_PATH_STOPWORDS.has(token)) continue;
|
|
105
|
+
tokens.add(token);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return tokens;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// LESSONS 条目:`### L-NNN` 标题开启一个条目,块内 `- **关键词**:` 行的词元即命中输入;下一个 H2
|
|
113
|
+
// 结束条目区(区外的 `###` 不参与)。围栏代码块内是书写样例(模板里的「条目格式」示例即此形态),
|
|
114
|
+
// 按行扫描会被误当成真条目——围栏内一律跳过。围栏语法取段体单源的 isFenceLine(反引号与波浪号
|
|
115
|
+
// 同口径):本模块自写一份只认反引号的判定时,`~~~` 围栏里的示例条目会被当成真条目,出口与
|
|
116
|
+
// request 打印面因此凭空多出「该回应」的编号。无关键词行的条目不进结果集(旧条目跳过)。
|
|
117
|
+
// title 只供打印面识别「是哪条教训」;命中判定与出口验收都只看 id / 关键词词元。
|
|
118
|
+
export function lessonsEntries(lessonsText) {
|
|
119
|
+
const entries = [];
|
|
120
|
+
let current = null;
|
|
121
|
+
let inFence = false;
|
|
122
|
+
for (const line of String(lessonsText ?? '').replace(/\r\n?/gu, '\n').split('\n')) {
|
|
123
|
+
if (isFenceLine(line)) { inFence = !inFence; continue; }
|
|
124
|
+
if (inFence) continue;
|
|
125
|
+
if (/^##\s/u.test(line)) { current = null; continue; }
|
|
126
|
+
const heading = line.match(LESSONS_ENTRY_HEADING);
|
|
127
|
+
if (heading) {
|
|
128
|
+
current = {
|
|
129
|
+
id: 'L-' + String(Number(heading[1])).padStart(3, '0'),
|
|
130
|
+
title: line.slice(heading[0].length).replace(LESSONS_TITLE_LEAD, '').trim(),
|
|
131
|
+
tokens: [],
|
|
132
|
+
order: entries.length,
|
|
133
|
+
};
|
|
134
|
+
entries.push(current);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (current === null) continue;
|
|
138
|
+
const keyword = line.match(LESSONS_KEYWORD_LINE);
|
|
139
|
+
if (!keyword) continue;
|
|
140
|
+
for (const piece of keyword[1].split(/[\s,,、;;/|]+/u)) {
|
|
141
|
+
const token = piece.trim().toLowerCase();
|
|
142
|
+
if (token !== '') current.tokens.push(token);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return entries.filter((entry) => entry.tokens.length > 0);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 命中计算:路径词元 × 条目关键词词元求交,共享词元多的条目优先(相关度),同分按条目出现顺序
|
|
149
|
+
// (结果确定、可复核),取前 LESSONS_HIT_LIMIT 条。
|
|
150
|
+
export function lessonsHits(pathTokens, entries) {
|
|
151
|
+
if (pathTokens.size === 0) return [];
|
|
152
|
+
const scored = [];
|
|
153
|
+
for (const entry of entries) {
|
|
154
|
+
const shared = [...new Set(entry.tokens.filter((token) => pathTokens.has(token)))];
|
|
155
|
+
if (shared.length === 0) continue;
|
|
156
|
+
scored.push({ id: entry.id, title: entry.title ?? '', shared, order: entry.order });
|
|
157
|
+
}
|
|
158
|
+
scored.sort((a, b) => b.shared.length - a.shared.length || a.order - b.order);
|
|
159
|
+
return scored.slice(0, LESSONS_HIT_LIMIT);
|
|
160
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// 运行根解析(单一来源):这次调用把哪个目录当项目根,只在这里回答一次。
|
|
2
|
+
//
|
|
3
|
+
// 为什么单独立模块:同一个问题此前被两处各自回答——守卫族读 FLOW_COMET_RUN_ROOT(守卫的运行根
|
|
4
|
+
// 模块),状态命令族直接用进程 cwd。两份推导在「只想用变量在临时目录里试一下」时静默分叉:
|
|
5
|
+
// 变量指向临时目录,状态命令却仍在 cwd 仓库里建分支、并把正在跑的 change 的 state 覆盖成新
|
|
6
|
+
// change 的初始状态(数据覆盖,靠备份才恢复)。收成一处后,同一个调用里两族只能给同一个答案。
|
|
7
|
+
//
|
|
8
|
+
// 取值语义(与守卫族既有语义逐字一致,默认行为不变):
|
|
9
|
+
// FLOW_COMET_RUN_ROOT 在场 → path.resolve(它)(相对值按调用进程的 cwd 解析)
|
|
10
|
+
// 否则 → process.cwd()
|
|
11
|
+
//
|
|
12
|
+
// 边界:默认根仍是「调起进程的 cwd」。需要与 cwd 解耦的调用(测试夹具、脚本化实验)必须显式
|
|
13
|
+
// 设置该变量。hook 运行根另有兜底链(FLOW_COMET_RUN_ROOT → CLAUDE_PROJECT_DIR → 祖先锚定 →
|
|
14
|
+
// cwd)——多出来的候选来自宿主注入与 hook 的 cwd 漂移,属于 hook 判定面,不在本模块表达。
|
|
15
|
+
import path from 'path';
|
|
16
|
+
|
|
17
|
+
export function resolveRunRoot() {
|
|
18
|
+
return process.env.FLOW_COMET_RUN_ROOT
|
|
19
|
+
? path.resolve(process.env.FLOW_COMET_RUN_ROOT)
|
|
20
|
+
: process.cwd();
|
|
21
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// section-body.mjs — 段体切片的单一实现(按行扫描:段标题之后取正文,直到「围栏外的同级标题 /
|
|
2
|
+
// 围栏外的分隔线 / 文末」)。围栏(连续三个及以上的反引号或波浪号)内的一切标题与分隔线都是正文
|
|
3
|
+
// 示例,不结束段体。
|
|
4
|
+
//
|
|
5
|
+
// 为什么单独成模块:同一件事(「这一段到哪里结束」)此前在仓里有五份各写一份的实现——波次段(一条
|
|
6
|
+
// 惰性正则)、修复段(按行找下一个 `## `)、REVIEW 发现区(标题驱动的状态机)、LESSONS 扫描段与
|
|
7
|
+
// TEST 1.1 矩阵段(带围栏同步的按行扫描)。其中三份没有围栏同步:工件里的围栏代码块一旦贴了
|
|
8
|
+
// Markdown 示例(块内 `## ` / `---`),段体就在示例处静默截断。REVIEW 发现区最危险——围栏内的
|
|
9
|
+
// 一行 `## ` 会把发现区重置成「非发现区」,其后的发现条目整段消失,「每条发现都必须有处置标记」
|
|
10
|
+
// 那道门禁因此对它们形同虚设(记录后无声消失)。
|
|
11
|
+
//
|
|
12
|
+
// 分工:段界只在这里决定。各消费方保留自己的额外语义(发现区的严重度分区、波次段的 Wave 行解析、
|
|
13
|
+
// 修复段的标题归一匹配、矩阵段的 AC 编号解析),并且只表达差异——结束标题的级别(level)、是否以
|
|
14
|
+
// 分隔线结束(endOnSeparator)、标题命中方式(正则或谓词)。只取**首个**命中:五个消费方都只要
|
|
15
|
+
// 一段;需要按文档序逐段处理的一方(REVIEW 发现区)用 scanHeadings 自己走,不在这里再要一份
|
|
16
|
+
// 「全部命中」的返回值。
|
|
17
|
+
|
|
18
|
+
// 围栏行:行首(允许缩进)三个及以上的反引号或波浪号。口径刻意极简(同一行翻转状态、不配对长度):
|
|
19
|
+
// 与既有消费方的行为一致,且工件里的围栏都是三记号成对书写。
|
|
20
|
+
const FENCE_LINE_RE = /^\s*(?:`{3,}|~{3,})/u;
|
|
21
|
+
// ATX 标题行:等级 + 标题文本(闭合 `##` 留给消费方归一时处理)。
|
|
22
|
+
const HEADING_LINE_RE = /^(#{1,6})\s+(.+?)\s*$/u;
|
|
23
|
+
// 分隔线(主题分隔):整行只有三个连字符。
|
|
24
|
+
const SEPARATOR_LINE_RE = /^---\s*$/u;
|
|
25
|
+
|
|
26
|
+
// 行归一(BOM / 行尾):段定位与下标计算共用同一口径——行尾差异是检出的噪音。
|
|
27
|
+
function normalizeLines(content) {
|
|
28
|
+
return String(content ?? '').replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n').split('\n');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 结构扫描(唯一一处按行判定「哪个标题行真的开一段」):围栏内的标题与分隔线不进结果。
|
|
32
|
+
function scanDocument(content) {
|
|
33
|
+
const lines = normalizeLines(content);
|
|
34
|
+
const headings = [];
|
|
35
|
+
const separators = [];
|
|
36
|
+
let inFence = false;
|
|
37
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
38
|
+
const line = lines[index];
|
|
39
|
+
if (FENCE_LINE_RE.test(line)) {
|
|
40
|
+
inFence = !inFence;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (inFence) continue;
|
|
44
|
+
if (SEPARATOR_LINE_RE.test(line)) {
|
|
45
|
+
separators.push(index);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const matched = line.match(HEADING_LINE_RE);
|
|
49
|
+
if (matched !== null) {
|
|
50
|
+
headings.push({ index, level: matched[1].length, text: matched[2].trim(), line });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { lines, headings, separators };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 围栏行判定(唯一一处):需要自己过滤「围栏内 / 围栏外」行的消费方(如只取书写样例里的字段键)
|
|
57
|
+
// 用它,不另写一份围栏语法。
|
|
58
|
+
export function isFenceLine(line) {
|
|
59
|
+
return FENCE_LINE_RE.test(String(line ?? ''));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 围栏外的标题行(下标 / 级别 / 标题文本 / 原始行)与归一后的行:给需要自己按文档序遍历的消费方
|
|
63
|
+
// (REVIEW 发现区要维持文档序与其自身的严重度分区语义,不能由段体切片代劳)。
|
|
64
|
+
export function scanHeadings(content) {
|
|
65
|
+
const { lines, headings } = scanDocument(content);
|
|
66
|
+
return { lines, headings };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 段体:首个命中处(标题行)之后,直到「围栏外的同级或更高级标题 / 围栏外的分隔线 / 文末」的正文。
|
|
70
|
+
// 无命中 → null(「段缺席」与「段在场但正文为空」是两种可区分的结果,调用方按 null 判缺席)。
|
|
71
|
+
// options.level 结束段的标题最高级别(2 → `##` 与 `#`;3 → `###` 及以上);默认 2
|
|
72
|
+
// options.endOnSeparator 围栏外的分隔线是否结束段体;默认 true
|
|
73
|
+
// headingPattern 是正则(对整行 test,须自带行锚定——正文里「引用段名」不得劫持匹配)或谓词
|
|
74
|
+
// (heading, line) => boolean(修复段按归一标题比较,正则表达不了)。
|
|
75
|
+
export function sectionBody(content, headingPattern, options = {}) {
|
|
76
|
+
const level = options.level ?? 2;
|
|
77
|
+
const endOnSeparator = options.endOnSeparator ?? true;
|
|
78
|
+
const { lines, headings, separators } = scanDocument(content);
|
|
79
|
+
const start = headings.findIndex((heading) => (typeof headingPattern === 'function'
|
|
80
|
+
? headingPattern(heading, heading.line) === true
|
|
81
|
+
: headingPattern.test(heading.line)));
|
|
82
|
+
if (start < 0) return null;
|
|
83
|
+
const heading = headings[start];
|
|
84
|
+
let end = lines.length;
|
|
85
|
+
const nextHeading = headings.slice(start + 1).find((candidate) => candidate.level <= level);
|
|
86
|
+
if (nextHeading !== undefined) end = nextHeading.index;
|
|
87
|
+
if (endOnSeparator) {
|
|
88
|
+
const separator = separators.find((index) => index > heading.index && index < end);
|
|
89
|
+
if (separator !== undefined) end = separator;
|
|
90
|
+
}
|
|
91
|
+
return lines.slice(heading.index + 1, end).join('\n');
|
|
92
|
+
}
|
|
@@ -4,7 +4,15 @@ import path from 'path';
|
|
|
4
4
|
import { isValidTimestamp } from '../time-utils.mjs';
|
|
5
5
|
import { verifyFailuresFor, setVerifyFailuresFor, writeJsonAtomic } from '../state-schema.mjs';
|
|
6
6
|
import { findActiveChange, readState, writeState, specsDir } from './state-io.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
describeTemplateList,
|
|
9
|
+
findTemplatesArg,
|
|
10
|
+
nodeTemplateDeclaration,
|
|
11
|
+
templateDeclarationProblems,
|
|
12
|
+
} from '../protocol-utils.mjs';
|
|
13
|
+
// 声明命令的唯一装配与状态命令族的运行上下文(与守卫侧同一份命令文本)。
|
|
14
|
+
import { commandContext, declarationCommand } from './state-explain.mjs';
|
|
15
|
+
import { findPromptArgs, protocolUnderFlowKitPrompts } from './state-skillmarkers.mjs';
|
|
8
16
|
|
|
9
17
|
// config set <key> <value>——branchMode 只读(init 自动判定),enablePrReview 手动
|
|
10
18
|
// 开关,last_evolve_at 为 evolve 元数据时刻(形态校验 fail-closed,写通道唯一)
|
|
@@ -75,16 +83,18 @@ export async function runExecutionMode(argv) {
|
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
// skill-load <node> <skill> [--prompt <path>]——写声明标记
|
|
79
|
-
// .specs/<change-id>/.skill-loads/<node>-<skill>.json
|
|
80
|
-
//
|
|
86
|
+
// skill-load <node> <skill> [--prompt <path>]... [--templates <a.md,b.md>]——写声明标记
|
|
87
|
+
// .specs/<change-id>/.skill-loads/<node>-<skill>.json
|
|
88
|
+
// ({ node, skill, protocol, protocols, templates, at };protocol 为首个 --prompt 的 basename,
|
|
89
|
+
// protocols 为全部 --prompt 的 basename——后者供出口的覆盖判据核对);record 校验 completedChecks
|
|
90
|
+
// 的 required-skill 条目与节点模板声明以此为准。
|
|
81
91
|
// 诚实边界:标记是"声明"而非物理证明——运行时没有 Skill 调用观察点,脚本无法确认执行者
|
|
82
92
|
// 真实加载过该 skill;标记仅记录"执行者主动声明已加载",由流程纪律兜底。
|
|
83
93
|
export async function runSkillLoad(protocol, argv) {
|
|
84
94
|
const nodeId = argv[3];
|
|
85
95
|
const skillName = argv[4];
|
|
86
96
|
if (!nodeId || !skillName) {
|
|
87
|
-
throw new Error('skill-load requires <node> <skill>. 用法: workflow-state.mjs skill-load <node> <skill> [--prompt <path>]');
|
|
97
|
+
throw new Error('skill-load requires <node> <skill>. 用法: workflow-state.mjs skill-load <node> <skill> [--prompt <path>] [--templates <a.md,b.md>]');
|
|
88
98
|
}
|
|
89
99
|
// 参数校验:node 为当前协议节点集合之一(动态读取协议 nodes[].id——内置 +
|
|
90
100
|
// 自定义,compose 自定义协议节点可声明);协议外节点名依然非法(fail-closed)。
|
|
@@ -99,9 +109,51 @@ export async function runSkillLoad(protocol, argv) {
|
|
|
99
109
|
// flow-kit 为 vendored 上游,协议提示只读引用)。协议加载本身由 resolveProtocol 全局
|
|
100
110
|
// 处理(含受保护读取)——--protocol 语义不变(工作流协议 JSON);此处仅校验用户显式传入的
|
|
101
111
|
// --prompt 原始值(skill-load 专属参数,不再与全局协议解析共用 --protocol)。
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
// 可重复出现:一个节点该读的协议常常不止一份(open 两份、review 两份),全部值逐个校验——
|
|
113
|
+
// 只校验第一个会让第二个非法路径混进标记(与「只记录第一个」是同一个缺陷的两面)。
|
|
114
|
+
const promptArgs = findPromptArgs(argv.slice(3));
|
|
115
|
+
for (const promptArg of promptArgs) {
|
|
116
|
+
if (!protocolUnderFlowKitPrompts(promptArg)) {
|
|
117
|
+
throw new Error('skill-load --prompt 路径必须位于 flow-kit/prompts/ 下(flow-kit 为 vendored 上游,协议提示只读引用): ' + promptArg);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// 产出物模板声明(C4 / C11):置入既有标记 JSON 的 templates 数组(节点级一份)。
|
|
121
|
+
// 内置节点:声明集合必须与 C3 映射一致(required ⊆ declared ⊆ required ∪ optional)——新 change
|
|
122
|
+
// 缺失 / 多写 / 漏写 / 错名一律 BLOCK(fail-closed),旧 change 只在「显式传了不一致的清单」时
|
|
123
|
+
// WARN(渐进兼容:旧项目不可能一夜补齐声明,缺失由 record 侧统一给提示,不在声明处重复报)。
|
|
124
|
+
// 自定义协议节点:不比对集合(ADR-002 特化层,C12:协议声明什么就记什么)。
|
|
125
|
+
const templateArg = findTemplatesArg(argv.slice(3));
|
|
126
|
+
const declarationNode = (protocol.nodes ?? []).find((item) => item.id === nodeId);
|
|
127
|
+
const templateDeclaration = nodeTemplateDeclaration(declarationNode);
|
|
128
|
+
if (templateDeclaration.source === 'builtin') {
|
|
129
|
+
const isNewChange = (await readState()).newChange === true;
|
|
130
|
+
const requiredNames = describeTemplateList(templateDeclaration.required);
|
|
131
|
+
// 重新声明命令由协议派生(state-explain 的唯一装配):脚本路径 + 该节点**全部**协议文件 +
|
|
132
|
+
// 模板全清单 + 协议上下文。此前的形态只带首份 --prompt,且是裸脚本名(照抄 command not found,
|
|
133
|
+
// 或照抄后同一 exit 仍被覆盖门点名另一份——报文与判据不是同一份)。
|
|
134
|
+
const declareCommand = declarationCommand({
|
|
135
|
+
node: declarationNode,
|
|
136
|
+
skill: skillName,
|
|
137
|
+
context: commandContext({ argv }),
|
|
138
|
+
});
|
|
139
|
+
// 命令自成一行(与其他两处声明报文同形):整行可照抄,不会被前后措辞切碎。
|
|
140
|
+
const reportUnsoundDeclaration = (reason) => {
|
|
141
|
+
console.error((isNewChange ? 'BLOCKED: ' : 'WARN: ') + reason
|
|
142
|
+
+ '——照抄下面的命令重新声明(同一 node-skill 重跑会覆写该标记)'
|
|
143
|
+
+ (isNewChange ? '后重试' : ';旧 change 渐进不阻断') + ':\n ' + declareCommand);
|
|
144
|
+
if (isNewChange) process.exit(1);
|
|
145
|
+
};
|
|
146
|
+
const problems = templateDeclarationProblems(templateDeclaration, templateArg.values);
|
|
147
|
+
if (!templateArg.provided && templateDeclaration.required.length > 0 && isNewChange) {
|
|
148
|
+
reportUnsoundDeclaration('节点 ' + nodeId + ' 的模板声明缺失(C3 映射: ' + requiredNames + ')');
|
|
149
|
+
}
|
|
150
|
+
if (templateArg.provided && (problems.missing.length > 0 || problems.extra.length > 0)) {
|
|
151
|
+
const detail = [];
|
|
152
|
+
if (problems.missing.length > 0) detail.push('漏写: ' + problems.missing.join('、'));
|
|
153
|
+
if (problems.extra.length > 0) detail.push('多写/错名: ' + problems.extra.join('、'));
|
|
154
|
+
reportUnsoundDeclaration('节点 ' + nodeId + ' 的模板声明与节点映射不一致(' + detail.join(';')
|
|
155
|
+
+ ';映射要求: ' + requiredNames + ')');
|
|
156
|
+
}
|
|
105
157
|
}
|
|
106
158
|
// 声明标记写入:.skill-loads/ 目录不存在时创建(writeJsonAtomic 自带 mkdir recursive);
|
|
107
159
|
// 同 node-skill 重复调用覆盖(记录最新声明)
|
|
@@ -111,11 +163,15 @@ export async function runSkillLoad(protocol, argv) {
|
|
|
111
163
|
// 但 record 的声明自动化仍可写归档路径标记——消息如实引导
|
|
112
164
|
throw new Error('skill-load requires an active change(先运行 init <change-id>;若该 change 已归档,声明标记由 record 自动补写——M5 会写入归档路径的 .skill-loads/)');
|
|
113
165
|
}
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
166
|
+
// 标记的协议声明两形态并存:
|
|
167
|
+
// · protocols = 全部 --prompt 的 basename(保序)——出口覆盖判据按它判「该读的每份协议是否
|
|
168
|
+
// 都被声明过」,一份命令声明多份时不会再丢;
|
|
169
|
+
// · protocol = 首个 basename(旧读法:入口的声明核对与既有读标记的消费方只认这个单值)。
|
|
170
|
+
// 未传 --prompt → protocol = null、protocols = [](无协议声明,exit 覆盖判据 fail-closed)。
|
|
171
|
+
// 写 basename 而非 resolveProtocol 解析后的完整绝对路径:与节点协议映射表 basename 精确比对
|
|
172
|
+
// 同值(真实链路 skill-load → exit 一致);写完整路径会让比对必然失败(机制实际不可用)。
|
|
173
|
+
const protocols = promptArgs.map((promptArg) => path.basename(promptArg));
|
|
174
|
+
const marker = { node: nodeId, skill: skillName, protocol: protocols[0] ?? null, protocols, templates: templateArg.values, at: new Date().toISOString() };
|
|
119
175
|
// specsDir 已含 .specs/,相对路径为 <change-id>/.skill-loads/<node>-<skill>.json
|
|
120
176
|
const markerRel = path.posix.join(changeName, '.skill-loads', nodeId + '-' + skillName + '.json');
|
|
121
177
|
await writeJsonAtomic(path.join(specsDir(), markerRel), marker);
|