flow-comet 1.6.5 → 1.8.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 +32 -18
- package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +2 -2
- package/.flow-comet/skills/flow-comet/reference/decision-points.md +5 -5
- package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/entry-detail.md +30 -11
- package/.flow-comet/skills/flow-comet/reference/fix-loop.md +4 -4
- package/.flow-comet/skills/flow-comet/reference/init-detection.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/platform-facts.md +2 -2
- package/.flow-comet/skills/flow-comet/reference/post-archive-handoff.md +264 -0
- package/.flow-comet/skills/flow-comet/reference/recovery.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/replan.md +1 -1
- package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +1 -0
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +270 -30
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +26 -23
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +14 -94
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +122 -11
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +79 -40
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +11 -9
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +52 -10
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +128 -56
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +357 -3
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +26 -1
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +6 -2
- package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +29 -21
- package/.flow-comet/skills/flow-comet/scripts/lib/ac-coverage.mjs +317 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +4 -15
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-artifact-skeleton.mjs +47 -5
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +357 -219
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +725 -309
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +182 -54
- 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 +224 -83
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +17 -28
- 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 +61 -33
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +663 -205
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +68 -9
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +11 -4
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +92 -13
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +232 -11
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +140 -74
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +8 -4
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +84 -31
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +0 -3
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +248 -24
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +63 -3
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +181 -8
- package/.flow-comet/skills/flow-comet/scripts/lib/wave-projection.mjs +340 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +132 -20
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +12 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +1564 -54
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1489 -38
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1466 -243
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +743 -24
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +220 -92
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +657 -21
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +41 -27
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +285 -9
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +7 -6
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +21 -15
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +8 -5
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +45 -36
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +2381 -85
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +135 -2
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +143 -16
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +339 -103
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +5 -2
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +33 -11
- package/.flow-comet/skills/flow-comet-change/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +5 -3
- package/.flow-comet/skills/flow-comet-dev/SKILL.md +2 -2
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +37 -13
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +10 -4
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +13 -6
- package/.flow-comet/skills/flow-comet-review/SKILL.md +21 -12
- package/.flow-comet/skills/flow-comet-subagent-execute/GUIDANCE.md +1 -1
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +43 -18
- package/.flow-comet/skills/flow-comet-task/SKILL.md +4 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +2 -2
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +1 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +238 -21
|
@@ -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
|
+
}
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { isValidTimestamp } from '../time-utils.mjs';
|
|
5
5
|
import { verifyFailuresFor, setVerifyFailuresFor, writeJsonAtomic } from '../state-schema.mjs';
|
|
6
|
-
import { findActiveChange, readState, writeState,
|
|
6
|
+
import { findActiveChange, readState, writeState, runRootDir, resolveChangeLocation } from './state-io.mjs';
|
|
7
7
|
import {
|
|
8
8
|
describeTemplateList,
|
|
9
9
|
findTemplatesArg,
|
|
10
10
|
nodeTemplateDeclaration,
|
|
11
11
|
templateDeclarationProblems,
|
|
12
|
-
templateDeclareCommand,
|
|
13
12
|
} from '../protocol-utils.mjs';
|
|
14
|
-
|
|
13
|
+
// 声明命令的唯一装配与状态命令族的运行上下文(与守卫侧同一份命令文本)。
|
|
14
|
+
import { commandContext, declarationCommand } from './state-explain.mjs';
|
|
15
|
+
import { findPromptArgs, protocolUnderFlowKitPrompts } from './state-skillmarkers.mjs';
|
|
15
16
|
|
|
16
17
|
// config set <key> <value>——branchMode 只读(init 自动判定),enablePrReview 手动
|
|
17
18
|
// 开关,last_evolve_at 为 evolve 元数据时刻(形态校验 fail-closed,写通道唯一)
|
|
@@ -82,10 +83,11 @@ export async function runExecutionMode(argv) {
|
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
// skill-load <node> <skill> [--prompt <path>] [--templates <a.md,b.md>]——写声明标记
|
|
86
|
+
// skill-load <node> <skill> [--prompt <path>]... [--templates <a.md,b.md>]——写声明标记
|
|
86
87
|
// .specs/<change-id>/.skill-loads/<node>-<skill>.json
|
|
87
|
-
// ({ node, skill, protocol, templates, at }
|
|
88
|
-
//
|
|
88
|
+
// ({ node, skill, protocol, protocols, templates, at };protocol 为首个 --prompt 的 basename,
|
|
89
|
+
// protocols 为全部 --prompt 的 basename——后者供出口的覆盖判据核对);record 校验 completedChecks
|
|
90
|
+
// 的 required-skill 条目与节点模板声明以此为准。
|
|
89
91
|
// 诚实边界:标记是"声明"而非物理证明——运行时没有 Skill 调用观察点,脚本无法确认执行者
|
|
90
92
|
// 真实加载过该 skill;标记仅记录"执行者主动声明已加载",由流程纪律兜底。
|
|
91
93
|
export async function runSkillLoad(protocol, argv) {
|
|
@@ -107,30 +109,39 @@ export async function runSkillLoad(protocol, argv) {
|
|
|
107
109
|
// flow-kit 为 vendored 上游,协议提示只读引用)。协议加载本身由 resolveProtocol 全局
|
|
108
110
|
// 处理(含受保护读取)——--protocol 语义不变(工作流协议 JSON);此处仅校验用户显式传入的
|
|
109
111
|
// --prompt 原始值(skill-load 专属参数,不再与全局协议解析共用 --protocol)。
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}
|
|
113
119
|
}
|
|
114
120
|
// 产出物模板声明(C4 / C11):置入既有标记 JSON 的 templates 数组(节点级一份)。
|
|
115
|
-
// 内置节点:声明集合必须与 C3 映射一致(required ⊆ declared ⊆ required ∪ optional
|
|
116
|
-
// 缺失 / 多写 / 漏写 / 错名一律 BLOCK(fail-closed
|
|
117
|
-
// WARN(渐进兼容:旧项目不可能一夜补齐声明,缺失由 record 侧统一给提示,不在声明处重复报)。
|
|
121
|
+
// 内置节点:声明集合必须与 C3 映射一致(required ⊆ declared ⊆ required ∪ optional)——
|
|
122
|
+
// 缺失 / 多写 / 漏写 / 错名一律 BLOCK(fail-closed)。
|
|
118
123
|
// 自定义协议节点:不比对集合(ADR-002 特化层,C12:协议声明什么就记什么)。
|
|
119
124
|
const templateArg = findTemplatesArg(argv.slice(3));
|
|
120
|
-
const
|
|
125
|
+
const declarationNode = (protocol.nodes ?? []).find((item) => item.id === nodeId);
|
|
126
|
+
const templateDeclaration = nodeTemplateDeclaration(declarationNode);
|
|
121
127
|
if (templateDeclaration.source === 'builtin') {
|
|
122
|
-
const isNewChange = (await readState()).newChange === true;
|
|
123
128
|
const requiredNames = describeTemplateList(templateDeclaration.required);
|
|
124
|
-
|
|
129
|
+
// 重新声明命令由协议派生(state-explain 的唯一装配):脚本路径 + 该节点**全部**协议文件 +
|
|
130
|
+
// 模板全清单 + 协议上下文。此前的形态只带首份 --prompt,且是裸脚本名(照抄 command not found,
|
|
131
|
+
// 或照抄后同一 exit 仍被覆盖门点名另一份——报文与判据不是同一份)。
|
|
132
|
+
const declareCommand = declarationCommand({
|
|
133
|
+
node: declarationNode,
|
|
134
|
+
skill: skillName,
|
|
135
|
+
context: commandContext({ argv }),
|
|
136
|
+
});
|
|
137
|
+
// 命令自成一行(与其他两处声明报文同形):整行可照抄,不会被前后措辞切碎。
|
|
125
138
|
const reportUnsoundDeclaration = (reason) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
console.error('WARN: ' + reason + '——重跑 ' + declareCommand + ' 重新声明(旧 change 渐进不阻断)');
|
|
139
|
+
console.error('BLOCKED: ' + reason
|
|
140
|
+
+ '——照抄下面的命令重新声明(同一 node-skill 重跑会覆写该标记)后重试:\n ' + declareCommand);
|
|
141
|
+
process.exit(1);
|
|
131
142
|
};
|
|
132
143
|
const problems = templateDeclarationProblems(templateDeclaration, templateArg.values);
|
|
133
|
-
if (!templateArg.provided && templateDeclaration.required.length > 0
|
|
144
|
+
if (!templateArg.provided && templateDeclaration.required.length > 0) {
|
|
134
145
|
reportUnsoundDeclaration('节点 ' + nodeId + ' 的模板声明缺失(C3 映射: ' + requiredNames + ')');
|
|
135
146
|
}
|
|
136
147
|
if (templateArg.provided && (problems.missing.length > 0 || problems.extra.length > 0)) {
|
|
@@ -145,19 +156,36 @@ export async function runSkillLoad(protocol, argv) {
|
|
|
145
156
|
// 同 node-skill 重复调用覆盖(记录最新声明)
|
|
146
157
|
const changeName = await findActiveChange();
|
|
147
158
|
if (!changeName) {
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
// 无活跃 change:声明标记的唯一写入通道就是本命令——不得承诺任何自动补写。
|
|
160
|
+
throw new Error('skill-load requires an active change(先运行 init <change-id>;声明标记必须由执行者手动 skill-load 写入,引擎不会代记)');
|
|
161
|
+
}
|
|
162
|
+
// 位置门 = state-io 的唯一解析器(活动目录优先、归档兜底)。标记写进**解析到的目录**:归档搬移之后
|
|
163
|
+
// 声明照常可用(此前身份绑在活动目录存在上,移动后直接抛「无活跃 change」),报告如实说出落点。
|
|
164
|
+
// 解析不到(目录两处都没有 / 归档多候选)→ fail-closed,报文与 status / next / record 同一句。
|
|
165
|
+
const located = await resolveChangeLocation({
|
|
166
|
+
root: runRootDir(),
|
|
167
|
+
changeName,
|
|
168
|
+
createdAt: (await readState()).createdAt,
|
|
169
|
+
});
|
|
170
|
+
if (!located.ok) {
|
|
171
|
+
console.error(located.message);
|
|
172
|
+
process.exit(1);
|
|
151
173
|
}
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
// 标记的协议声明两形态并存:
|
|
175
|
+
// · protocols = 全部 --prompt 的 basename(保序)——出口覆盖判据按它判「该读的每份协议是否
|
|
176
|
+
// 都被声明过」,一份命令声明多份时不会再丢;
|
|
177
|
+
// · protocol = 首个 basename(旧读法:入口的声明核对与既有读标记的消费方只认这个单值)。
|
|
178
|
+
// 未传 --prompt → protocol = null、protocols = [](无协议声明,exit 覆盖判据 fail-closed)。
|
|
179
|
+
// 写 basename 而非 resolveProtocol 解析后的完整绝对路径:与节点协议映射表 basename 精确比对
|
|
180
|
+
// 同值(真实链路 skill-load → exit 一致);写完整路径会让比对必然失败(机制实际不可用)。
|
|
181
|
+
const protocols = promptArgs.map((promptArg) => path.basename(promptArg));
|
|
182
|
+
const marker = { node: nodeId, skill: skillName, protocol: protocols[0] ?? null, protocols, templates: templateArg.values, at: new Date().toISOString() };
|
|
183
|
+
// 落点 = 解析到的 change 目录(活动或归档)+ .skill-loads/<node>-<skill>.json;报告与写入同源,
|
|
184
|
+
// 执行者据此能直接核对「标记到底进了哪个目录」。
|
|
185
|
+
const markerName = nodeId + '-' + skillName + '.json';
|
|
186
|
+
await writeJsonAtomic(path.join(located.resolution.dir, '.skill-loads', markerName), marker);
|
|
187
|
+
console.log('SKILL-LOAD: ' + nodeId + ' ' + skillName + ' → ' + located.resolution.display
|
|
188
|
+
+ '/.skill-loads/' + markerName);
|
|
161
189
|
return;
|
|
162
190
|
}
|
|
163
191
|
|