flow-comet 1.6.3 → 1.6.5
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 +21 -3
- 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/entry-detail.md +8 -2
- package/.flow-comet/skills/flow-comet/reference/workflow-protocol.json +22 -0
- 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 +180 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +69 -18878
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +29 -5
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1053 -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 +817 -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 +618 -0
- package/.flow-comet/skills/flow-comet/scripts/items/n.mjs +154 -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-artifact-skeleton.mjs +406 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +756 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +1235 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +384 -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 +714 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +204 -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 +179 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +714 -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 +123 -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 +249 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1505 -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 +1248 -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 +2493 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +214 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +72 -1123
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +976 -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 +1398 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1367 -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 +1492 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/n.mjs +2125 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +59 -7559
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +223 -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-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 +13 -10
- 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 +11 -7
- package/.flow-comet/skills/flow-comet-requirement/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +15 -9
- package/.flow-comet/skills/flow-comet-subagent-execute/GUIDANCE.md +13 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +11 -8
- package/.flow-comet/skills/flow-comet-task/SKILL.md +1 -1
- 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 +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 +159 -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,1248 @@
|
|
|
1
|
+
// test-fixtures.mjs — 引擎套件的夹具、运行器与共享路径常量(单一来源)
|
|
2
|
+
//
|
|
3
|
+
// 定位:`guard-self-test.mjs` 的场景夹具与受控命令运行器。**不含判据**——什么算通过、
|
|
4
|
+
// 什么算残留,落在断言模块与文本锚判据模块;与 `system-test.mjs` 同名同责的工具在
|
|
5
|
+
// `test-helpers.mjs`(单源),本模块只保留本套件特有的夹具。
|
|
6
|
+
//
|
|
7
|
+
// 路径推导:本模块位于 `<技能包>/scripts/lib/`,`SCRIPTS_DIR` 由 import.meta.url 相对推导,
|
|
8
|
+
// 技能树内所有兄弟脚本与内置协议副本一律由它拼接(每个调用面各拼一遍就是第二份推导)。
|
|
9
|
+
//
|
|
10
|
+
// 套件夹具根 = 共享 `makeTmp` 的固定参数形态(套件前缀 + 登记数组):收尾的「临时目录残留」
|
|
11
|
+
// 判据以该登记数组为唯一数据源,故绑定只在此一处,调用点保持零参数。
|
|
12
|
+
|
|
13
|
+
import fs from 'fs';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import { spawnSync } from 'child_process';
|
|
16
|
+
import { createHash } from 'crypto';
|
|
17
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
18
|
+
import {
|
|
19
|
+
assertExit,
|
|
20
|
+
assertOut,
|
|
21
|
+
copyTreePortable,
|
|
22
|
+
runGuard,
|
|
23
|
+
runState,
|
|
24
|
+
writeFile,
|
|
25
|
+
makeTmp as sharedMakeTmp,
|
|
26
|
+
} from './test-helpers.mjs';
|
|
27
|
+
|
|
28
|
+
// 本模块位于 `<技能包>/scripts/lib/` ⇒ 脚本目录是它的上一级;技能树内所有兄弟脚本路径
|
|
29
|
+
// (GUARD / STATE / HOOK / HANDOFF / 侧命令 / 内置协议副本)一律由它拼接,调用面不再各拼一遍。
|
|
30
|
+
export const SCRIPTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
31
|
+
// route-node 共享 Fix 判定纯函数(直接调用锚):动态导入 + 顶层 await——缺失命名导出由
|
|
32
|
+
// requireRouteNodeExport 在场景内显式报告(RED 可定位到具体场景),避免静态命名 import 在
|
|
33
|
+
// 模块加载期失败导致其余场景一并 abort(整套件 0 场景、失败原因失焦)。
|
|
34
|
+
export const routeNodeModule = await import(pathToFileURL(path.join(SCRIPTS_DIR, 'route-node.mjs')).href);
|
|
35
|
+
export const GUARD = path.join(SCRIPTS_DIR, 'workflow-guard.mjs');
|
|
36
|
+
export const STATE = path.join(SCRIPTS_DIR, 'workflow-state.mjs');
|
|
37
|
+
export const HOOK = path.join(SCRIPTS_DIR, 'comet-hook-guard.mjs');
|
|
38
|
+
export const HANDOFF = path.join(SCRIPTS_DIR, 'workflow-handoff.mjs');
|
|
39
|
+
// prepare-env 安装器(平台选择链场景——真实脚本,场景用临时目录 + spawn 断言):
|
|
40
|
+
// 仓库根(权威源检出):脚本位于 <root>/.flow-comet/skills/flow-comet/scripts —— 4 级 .. 到 <root>。
|
|
41
|
+
// 单一来源:安装器路径、仓库文档级场景与底部自检共用(历史教训:同一路径表达式分散在多处,
|
|
42
|
+
// 布局迁移时逐处改写必然遗漏——本次迁移即因此把 4 处深度链收敛为一处)。
|
|
43
|
+
export const REPO_ROOT = path.resolve(SCRIPTS_DIR, '..', '..', '..', '..');
|
|
44
|
+
// 权威源锚点:仅权威源检出含 <root>/.flow-comet/(安装副本把技能树放在 .claude|.agents|.dsh/skills/,
|
|
45
|
+
// 其 .flow-comet/ 只是运行时目录,无 skills/flow-comet/SKILL.md)——与安装器自身判定同判据
|
|
46
|
+
// (prepare-env.mjs 的 gitignore 纳管跳过分支)。
|
|
47
|
+
export const AUTHORITATIVE_SOURCE_ANCHOR = path.join(REPO_ROOT, '.flow-comet', 'skills', 'flow-comet', 'SKILL.md');
|
|
48
|
+
export function isAuthoritativeSourceRepo() {
|
|
49
|
+
return fs.existsSync(AUTHORITATIVE_SOURCE_ANCHOR);
|
|
50
|
+
}
|
|
51
|
+
// 权威源仓库脚本位于仓库根 scripts/prepare-env.mjs;安装副本无此脚本,场景跳过
|
|
52
|
+
export const PREPARE_ENV = path.join(REPO_ROOT, 'scripts', 'prepare-env.mjs');
|
|
53
|
+
// 内置协议源文件(packageRoot/reference/):场景复制到 <tmpdir>/reference/ 内(protected-path 要求 runRoot 内)
|
|
54
|
+
export const BUILTIN_PROTOCOL_SOURCE = path.join(SCRIPTS_DIR, '..', 'reference', 'workflow-protocol.json');
|
|
55
|
+
export const CHANGE_ID = 'ch';
|
|
56
|
+
|
|
57
|
+
// 组件技能树布局感知(单一来源):本 suite 恒位于 <skillsRoot>/flow-comet/scripts/,
|
|
58
|
+
// 组件技能(flow-comet-execute / flow-comet-review / flow-comet-verify 等)是 <skillsRoot>
|
|
59
|
+
// 下的同级目录。权威源 checkout → <root>/.flow-comet/skills/;安装副本 → <目标>/.claude|
|
|
60
|
+
// .agents|.dsh/skills/ —— 同一相对推导覆盖全部形态。禁止再假定权威源布局
|
|
61
|
+
// (REPO_ROOT/.flow-comet/skills 在安装副本形态不存在 → 技能文本锁场景 ENOENT,端到端冒烟缺陷)。
|
|
62
|
+
export function skillsRootForScriptsDir(scriptsDir) {
|
|
63
|
+
return path.resolve(scriptsDir, '..', '..');
|
|
64
|
+
}
|
|
65
|
+
// 解析组件技能 SKILL.md:缺失即显式失败并给指引(MECHANISM 三·6「未验证 ≠ 通过」——
|
|
66
|
+
// 不得静默跳过);scriptsDir 为可测接缝(技能文本锁场景的合成布局回归锚)。
|
|
67
|
+
export function resolveComponentSkillFile(nodeSkill, scriptsDir = SCRIPTS_DIR) {
|
|
68
|
+
const skillsRoot = skillsRootForScriptsDir(scriptsDir);
|
|
69
|
+
const file = path.join(skillsRoot, nodeSkill, 'SKILL.md');
|
|
70
|
+
if (!fs.existsSync(file)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
'技能树布局定位失败:' + nodeSkill + '/SKILL.md 不存在。suite 脚本须位于 <skillsRoot>/flow-comet/scripts/' +
|
|
73
|
+
',组件技能为其同级目录;已解析 skillsRoot=' + skillsRoot + ',期望路径=' + file +
|
|
74
|
+
'。权威源 .flow-comet/skills 与安装副本 .claude|.agents|.dsh/skills 均按此相对布局解析。'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return file;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 技能树分发面文档遍历(返回 [相对 skillsRoot 的斜杠路径, 绝对路径]):全部 `*.md`
|
|
81
|
+
//(各册 `SKILL.md` + `flow-comet/reference/**.md`)。用于「持某锚句的文本集合」「相对路径引用
|
|
82
|
+
// 可解析性」这类**跨册面**判据——单一册判据不用它,避免判据面被无谓放大。
|
|
83
|
+
export function skillTreeDocFiles(scriptsDir = SCRIPTS_DIR) {
|
|
84
|
+
const root = skillsRootForScriptsDir(scriptsDir);
|
|
85
|
+
const out = [];
|
|
86
|
+
const walk = (dir) => {
|
|
87
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
88
|
+
const abs = path.join(dir, entry.name);
|
|
89
|
+
if (entry.isDirectory()) {
|
|
90
|
+
walk(abs);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (!entry.name.endsWith('.md')) continue;
|
|
94
|
+
out.push([path.relative(root, abs).replaceAll('\\', '/'), abs]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
walk(root);
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
export const createdDirs = [];
|
|
101
|
+
|
|
102
|
+
// 同步小睡(末尾延迟重试用;主线程可用 Atomics.wait 阻塞等待)
|
|
103
|
+
export function sleepSync(ms) {
|
|
104
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 桥接身份透传契约(套件侧单一构造点,与真实桥接同形):dsh 桥接在注入身份深度的**同时**注入
|
|
108
|
+
// 通道标记 FLOW_COMET_AGENT_DEPTH_SOURCE='dsh-bridge';守卫要求两者同时在场才接受 env 面身份。
|
|
109
|
+
// 套件里凡是要表达「经桥接通道的子代理身份」,一律经本函数构造 env——变量名/标记值只此一处,
|
|
110
|
+
// 免得各处手抄而与守卫或桥接漂移。反向形态(只注入深度、不注入标记)由身份族的继承形态断言覆盖。
|
|
111
|
+
export function bridgeIdentityEnv(depthValue) {
|
|
112
|
+
return {
|
|
113
|
+
FLOW_COMET_AGENT_DEPTH: depthValue,
|
|
114
|
+
FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh-bridge',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 跑 scripts/prepare-env.mjs(真实安装器——平台选择链场景)。cwd=临时目录;
|
|
119
|
+
// envOverrides 可覆盖 DSH_HOME(dsh 平台 installHooks 写 $DSH_HOME——场景必须设
|
|
120
|
+
// DSH_HOME=临时目录环境变量,禁止污染真实 ~/.dsh;spawn 非 TTY:走探测/默认路径,不触发交互)
|
|
121
|
+
export function runPrepareEnv(args, root, envOverrides = {}) {
|
|
122
|
+
const res = spawnSync(process.execPath, [PREPARE_ENV, ...args], {
|
|
123
|
+
cwd: root,
|
|
124
|
+
env: { ...process.env, ...envOverrides },
|
|
125
|
+
encoding: 'utf8',
|
|
126
|
+
timeout: 120000,
|
|
127
|
+
});
|
|
128
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 跑 workflow-state.mjs 的 bridge-check 只读子命令(T05 实现——六判定态健康/文件缺失/
|
|
132
|
+
// 未挂载/版本偏斜/重复注册/不适用)。runRoot = cwd = 项目根;协议副本须在 runRoot 内
|
|
133
|
+
// (protected-path)——指向运行器已复制到 <root>/reference/ 的内置协议副本
|
|
134
|
+
// (FLOW_COMET_PROTOCOL env 优先级高于默认,见 protocol-utils resolveProtocol)。
|
|
135
|
+
export function runBridgeCheck(root, dshHome) {
|
|
136
|
+
return runState(['bridge-check'], root, {
|
|
137
|
+
DSH_HOME: dshHome,
|
|
138
|
+
FLOW_COMET_PROTOCOL: path.join(root, 'reference', 'workflow-protocol.json'),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 桥接夹具 loader 写入(单一来源——bridge-check 夹具与安装副本形态夹具共用;两处各自
|
|
143
|
+
// 拼装锚点行会随契约格式演进分叉)。返回 loader 绝对路径。
|
|
144
|
+
export function writeBridgeLoaderFixture(dshHome, loaderStamp) {
|
|
145
|
+
const loaderPath = path.join(dshHome, 'plugins', 'dsh-flow-comet-bridge.mjs');
|
|
146
|
+
writeFile(dshHome, 'plugins/dsh-flow-comet-bridge.mjs',
|
|
147
|
+
'// dsh bridge loader fixture\n// BRIDGE_VERSION: ' + loaderStamp + '\n' +
|
|
148
|
+
"export const name = 'dsh-flow-comet-bridge';\nexport const version = '" + loaderStamp + "';\n");
|
|
149
|
+
return loaderPath;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// cordis.patch.yml 托管块(insert 形态 + file:// 引用)逐字构造(单一来源,同上)。
|
|
153
|
+
export function managedCordisBlockFor(loaderPath) {
|
|
154
|
+
const fileUrl = pathToFileURL(loaderPath).href;
|
|
155
|
+
return '# --- flow-comet managed ---\n- insert:\n - id: dsh-flow-comet-bridge\n name: \'' +
|
|
156
|
+
fileUrl.replace(/'/g, "''") + '\'\n# --- end flow-comet managed ---\n';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// bridge-check 版本断言的期望值归一(测试侧镜像生产 bridge-check 契约:仅剥离 git-describe
|
|
160
|
+
// dev 态后缀 `-<N>-g<hash>`,大小写不敏感;预发布标识不匹配、不剥离)。套件自身
|
|
161
|
+
// INSTALLED_VERSION 在权威源检出差为发布标记、在安装副本内为 dev 态戳——期望必须从载体
|
|
162
|
+
// 原始戳归一出的基础版本派生,两种载体形态(权威源 / 安装副本)才都可移植。
|
|
163
|
+
export const FIXTURE_BRIDGE_DEV_SUFFIX_RE = /-\d+-g[0-9a-f]+$/i;
|
|
164
|
+
export function fixtureBridgeBaseVersion(version) {
|
|
165
|
+
return String(version).replace(FIXTURE_BRIDGE_DEV_SUFFIX_RE, '');
|
|
166
|
+
}
|
|
167
|
+
export function fixtureIsBridgeDevVersion(version) {
|
|
168
|
+
return FIXTURE_BRIDGE_DEV_SUFFIX_RE.test(String(version));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 发布同步守卫(场景 200 子断言)纯函数:权威源 loader 的标记行 / 导出常量与载体
|
|
172
|
+
// INSTALLED_VERSION 三处一致性判定——比较语义 = bridge-check 既有语义(MECHANISM 二·二十七
|
|
173
|
+
// 「bridge-check 基础版本归一」:比较前剥离 git-describe dev 态后缀 `-<N>-g<hash>`、按基础版本
|
|
174
|
+
// 比较;预发布标识(如 -rc.N)不是 dev 态后缀、不剥离;基础版本不同(含发布版对发布版)仍报
|
|
175
|
+
// 漂移)。归一复用 fixtureBridgeBaseVersion(单点正则,不再复制第二份实现)——发布态权威源与
|
|
176
|
+
// dev 态安装副本(INSTALLED_VERSION = `<发布>-<N>-g<hash>`)归一后同基础判同步;真实跨文件/
|
|
177
|
+
// 跨值分叉仍必报。返回问题描述数组(空 = 三处基础版本一致)。
|
|
178
|
+
export function bridgeStampSyncProblems(markerStamp, exportStamp, installedVersion) {
|
|
179
|
+
const base = fixtureBridgeBaseVersion;
|
|
180
|
+
const problems = [];
|
|
181
|
+
if (base(markerStamp) !== base(installedVersion)) {
|
|
182
|
+
problems.push('标记行=' + markerStamp + '(基础 ' + base(markerStamp) + ')vs INSTALLED_VERSION=' + installedVersion + '(基础 ' + base(installedVersion) + ')');
|
|
183
|
+
}
|
|
184
|
+
if (base(exportStamp) !== base(installedVersion)) {
|
|
185
|
+
problems.push('export=' + exportStamp + '(基础 ' + base(exportStamp) + ')vs INSTALLED_VERSION=' + installedVersion + '(基础 ' + base(installedVersion) + ')');
|
|
186
|
+
}
|
|
187
|
+
return problems;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 发布同步守卫(场景 200)子锚表(判别力双向,全部由载体基础版本派生):正例 = 三处基础版本一致
|
|
191
|
+
// (含 dev 态副本戳 vs 权威源发布戳的真实形态、两侧 dev 后缀同基础);负例 = 标记行 / export
|
|
192
|
+
// 任一基础版本漂移、发布版对发布版失配、预发布标识不剥离——归一不得放行真实漂移。
|
|
193
|
+
export function bridgeStampSyncSubAnchorCases(baseVersion, devVersion) {
|
|
194
|
+
const major = parseInt(baseVersion.split('.')[0], 10);
|
|
195
|
+
const otherBase = (major + 9) + '.0.0';
|
|
196
|
+
return [
|
|
197
|
+
{ label: 'dev 态副本戳 vs 权威源发布戳同基础', expectSync: true, problems: bridgeStampSyncProblems(baseVersion, baseVersion, devVersion) },
|
|
198
|
+
{ label: '两侧 dev 后缀同基础', expectSync: true, problems: bridgeStampSyncProblems(baseVersion + '-2-g1234567', baseVersion + '-1-gabcdef0', devVersion) },
|
|
199
|
+
{ label: '标记行基础版本不同', expectSync: false, problems: bridgeStampSyncProblems(otherBase, baseVersion, devVersion) },
|
|
200
|
+
{ label: 'export 基础版本不同', expectSync: false, problems: bridgeStampSyncProblems(baseVersion, otherBase, devVersion) },
|
|
201
|
+
{ label: '发布版对发布版失配', expectSync: false, problems: bridgeStampSyncProblems('9.9.9-fixture-skew', baseVersion, baseVersion) },
|
|
202
|
+
{ label: '预发布标识不剥离', expectSync: false, problems: bridgeStampSyncProblems(baseVersion + '-rc.3', baseVersion, devVersion) },
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 组装 dsh 桥接健康夹具(bridge-check 六态场景共用):项目根挂 .dsh/skills/flow-comet
|
|
207
|
+
// 适用性门;$DSH_HOME/plugins/ 放 loader(含契约锚点 BRIDGE_VERSION 戳,值取自权威源
|
|
208
|
+
// INSTALLED_VERSION,与 bridge-check 比对源同值——健康态恒等、偏斜态可控);cordis.patch.yml
|
|
209
|
+
// 托管块按安装器实际写入形态(insert 条目 + file:// 引用——形态断言)逐字构造。
|
|
210
|
+
// overrides: { loaderStamp, skipLoader, patchContent, outsideBlock }
|
|
211
|
+
export function writeBridgeFixture(dir, overrides = {}) {
|
|
212
|
+
const dshHome = overrides.dshHome || path.join(dir, 'dshhome');
|
|
213
|
+
const installedVersion = fs.readFileSync(path.join(SCRIPTS_DIR, '..', 'INSTALLED_VERSION'), 'utf8').trim();
|
|
214
|
+
const loaderStamp = overrides.loaderStamp || installedVersion;
|
|
215
|
+
writeFile(dir, '.dsh/skills/flow-comet/.fixture-anchor', 'fixture\n');
|
|
216
|
+
const loaderPath = path.join(dshHome, 'plugins', 'dsh-flow-comet-bridge.mjs');
|
|
217
|
+
if (!overrides.skipLoader) {
|
|
218
|
+
writeBridgeLoaderFixture(dshHome, loaderStamp);
|
|
219
|
+
}
|
|
220
|
+
const managedBlock = managedCordisBlockFor(loaderPath);
|
|
221
|
+
writeFile(dshHome, 'cordis.patch.yml',
|
|
222
|
+
overrides.patchContent !== undefined
|
|
223
|
+
? overrides.patchContent
|
|
224
|
+
: managedBlock + (overrides.outsideBlock || ''));
|
|
225
|
+
return { dshHome, loaderPath, installedVersion, managedBlock };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 安装副本形态夹具(版本比较场景):把本 suite 自身技能树整体复制为
|
|
229
|
+
// <dir>/.dsh/skills/flow-comet —— 被检脚本与同包 INSTALLED_VERSION 因而都可控。
|
|
230
|
+
// bridge-check 读取脚本同包(`<脚本目录>/..`)的 INSTALLED_VERSION:权威源检出路径固定为
|
|
231
|
+
// 发布标记,无法表达「载体 INSTALLED_VERSION 为 dev 态(git describe 后缀)」的形态;
|
|
232
|
+
// 只有以副本自身脚本运行才能构造真实 dev 态载体(与 prepare-env 安装出的形态同构)。
|
|
233
|
+
// 返回 { dshHome, skillCopy };loader 戳由调用方指定,与 INSTALLED_VERSION 可不同。
|
|
234
|
+
export function writeInstalledCopyBridgeFixture(dir, { installedVersion, loaderStamp }) {
|
|
235
|
+
const skillCopy = path.join(dir, '.dsh', 'skills', 'flow-comet');
|
|
236
|
+
copyTreePortable(path.join(SCRIPTS_DIR, '..'), skillCopy);
|
|
237
|
+
writeFile(skillCopy, 'INSTALLED_VERSION', installedVersion + '\n');
|
|
238
|
+
const dshHome = path.join(dir, 'dshhome');
|
|
239
|
+
const loaderPath = writeBridgeLoaderFixture(dshHome, loaderStamp);
|
|
240
|
+
writeFile(dshHome, 'cordis.patch.yml', managedCordisBlockFor(loaderPath));
|
|
241
|
+
return { dshHome, skillCopy };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 以安装副本自身脚本运行 bridge-check(runRoot = 载体项目根;协议副本在 skill 包内,
|
|
245
|
+
// 与真实安装形态一致——默认协议解析即为 <skillCopy>/reference/workflow-protocol.json)。
|
|
246
|
+
export function runBridgeCheckFromCopy(dir, dshHome, skillCopy) {
|
|
247
|
+
const res = spawnSync(process.execPath, [path.join(skillCopy, 'scripts', 'workflow-state.mjs'), 'bridge-check'], {
|
|
248
|
+
cwd: dir,
|
|
249
|
+
env: {
|
|
250
|
+
...process.env,
|
|
251
|
+
FLOW_COMET_RUN_ROOT: dir,
|
|
252
|
+
FLOW_COMET_PROTOCOL: path.join(skillCopy, 'reference', 'workflow-protocol.json'),
|
|
253
|
+
DSH_HOME: dshHome,
|
|
254
|
+
},
|
|
255
|
+
encoding: 'utf8',
|
|
256
|
+
timeout: 60000,
|
|
257
|
+
});
|
|
258
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 套件夹具根:共享 `makeTmp` 的套件形态固定参数(本套件前缀 + 登记数组);调用点保持零参数。
|
|
262
|
+
export function makeTmp() {
|
|
263
|
+
return sharedMakeTmp({ prefix: 'flow-comet-guard-test-', register: createdDirs });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 具名 import 断言(容忍多行 / 符号重排 / 其它符号共存):source 为模块说明符(`./state-schema.mjs`)。
|
|
267
|
+
// 与场景 154 的内联写法同判据,本处提为复用工具(原子写与元数据常量两处消费面都要断言)。
|
|
268
|
+
export function hasNamedImport(text, source, name) {
|
|
269
|
+
const pattern = /import\s*\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
270
|
+
let match;
|
|
271
|
+
while ((match = pattern.exec(String(text))) !== null) {
|
|
272
|
+
if (match[2] !== source) continue;
|
|
273
|
+
const names = match[1].split(',').map((piece) => piece.trim().split(/\s+as\s+/).pop());
|
|
274
|
+
if (names.includes(name)) return true;
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ---------- 自定义协议场景材料 ----------
|
|
280
|
+
|
|
281
|
+
// 自定义协议(compose-demo):3 节点 brainstorm/tdd/codereview(避开内置 8 节点 id,验证
|
|
282
|
+
// 协议数据化路由与通用层防线对自定义节点生效);无 writeWhitelist(hook 回退内置缺省表);
|
|
283
|
+
// state 与内置协议同构(statePath 指向 .flow-comet/flow-comet-state.json)
|
|
284
|
+
export function customProtocol() {
|
|
285
|
+
return {
|
|
286
|
+
schemaVersion: 1,
|
|
287
|
+
kind: 'workflow-kernel',
|
|
288
|
+
name: 'compose-demo',
|
|
289
|
+
goal: 'T06 自定义协议场景:协议数据化路由 + 通用层防线 + 特化校验绑定。',
|
|
290
|
+
nodes: [
|
|
291
|
+
{
|
|
292
|
+
id: 'brainstorm',
|
|
293
|
+
label: 'Brainstorm',
|
|
294
|
+
kind: 'control',
|
|
295
|
+
responsibility: '产出 notes.md。',
|
|
296
|
+
outputSchemas: ['compose.notes.v1'],
|
|
297
|
+
requiredSkillCalls: [],
|
|
298
|
+
augmentations: [],
|
|
299
|
+
disabled: false,
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
id: 'tdd',
|
|
303
|
+
label: 'TDD',
|
|
304
|
+
kind: 'control',
|
|
305
|
+
responsibility: '产出 *-SUMMARY.md。',
|
|
306
|
+
outputSchemas: ['compose.tdd.v1'],
|
|
307
|
+
requiredSkillCalls: [],
|
|
308
|
+
augmentations: [],
|
|
309
|
+
disabled: false,
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
id: 'codereview',
|
|
313
|
+
label: 'Code Review',
|
|
314
|
+
kind: 'control',
|
|
315
|
+
responsibility: '产出 verdict.md。',
|
|
316
|
+
outputSchemas: ['compose.verdict.v1'],
|
|
317
|
+
requiredSkillCalls: [],
|
|
318
|
+
augmentations: [],
|
|
319
|
+
disabled: false,
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
outputSchemas: [
|
|
323
|
+
{
|
|
324
|
+
id: 'compose.notes.v1',
|
|
325
|
+
description: 'notes.md',
|
|
326
|
+
artifacts: [
|
|
327
|
+
{
|
|
328
|
+
id: 'notes',
|
|
329
|
+
kind: 'file',
|
|
330
|
+
required: true,
|
|
331
|
+
paths: ['<change-id>/notes.md'],
|
|
332
|
+
pathBase: 'specs-root',
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
evidence: [{ id: 'notes-summary', required: true }],
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
id: 'compose.tdd.v1',
|
|
339
|
+
description: '*-SUMMARY.md',
|
|
340
|
+
artifacts: [
|
|
341
|
+
{
|
|
342
|
+
id: 'summaries',
|
|
343
|
+
kind: 'file',
|
|
344
|
+
required: true,
|
|
345
|
+
paths: ['<change-id>/*-SUMMARY.md'],
|
|
346
|
+
pathBase: 'specs-root',
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
evidence: [{ id: 'tdd-summary', required: true }],
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
id: 'compose.verdict.v1',
|
|
353
|
+
description: 'verdict.md',
|
|
354
|
+
artifacts: [
|
|
355
|
+
{
|
|
356
|
+
id: 'verdict',
|
|
357
|
+
kind: 'file',
|
|
358
|
+
required: true,
|
|
359
|
+
paths: ['<change-id>/verdict.md'],
|
|
360
|
+
pathBase: 'specs-root',
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
evidence: [{ id: 'verdict-summary', required: true }],
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
state: {
|
|
367
|
+
kind: 'workflow-run',
|
|
368
|
+
statePath: '.flow-comet/flow-comet-state.json',
|
|
369
|
+
currentNodeField: 'currentNode',
|
|
370
|
+
completedNodesField: 'completedNodes',
|
|
371
|
+
evidenceField: 'evidence',
|
|
372
|
+
},
|
|
373
|
+
edges: [],
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// 含 requiredSkillCalls 的自定义协议变体——compose 自定义节点可声明必调 skill
|
|
378
|
+
// (compose SKILL 节点组装 requiredSkillCalls 可空);skill-load/record 端到端验证用:
|
|
379
|
+
// 仅 brainstorm 带 main scope 绑定(协调者加载 → 需 skill-load 声明标记),其余与 customProtocol() 同
|
|
380
|
+
export function customProtocolWithSkillCall() {
|
|
381
|
+
const p = customProtocol();
|
|
382
|
+
p.nodes[0].requiredSkillCalls = [{ skill: 'flow-comet-brainstorm', scope: 'main' }];
|
|
383
|
+
return p;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// 写入 <dir>/custom-protocol.json,返回绝对路径(供 --protocol CLI / FLOW_COMET_PROTOCOL env 使用)
|
|
387
|
+
export function writeCustomProtocol(dir) {
|
|
388
|
+
writeFile(dir, 'custom-protocol.json', JSON.stringify(customProtocol(), null, 2) + '\n');
|
|
389
|
+
return path.join(dir, 'custom-protocol.json');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// compose-demo 场景 state(currentNode 默认 brainstorm;hook 场景需补 status:'running')
|
|
393
|
+
export function composeState(overrides = {}) {
|
|
394
|
+
return {
|
|
395
|
+
activeChange: 'compose-demo',
|
|
396
|
+
currentNode: 'brainstorm',
|
|
397
|
+
completedNodes: [],
|
|
398
|
+
evidence: {},
|
|
399
|
+
verifyFailures: 0,
|
|
400
|
+
executionMode: 'subagent',
|
|
401
|
+
directOverride: false,
|
|
402
|
+
...overrides,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// 完整 SUMMARY:六段齐全(## verify 输出 / ## 6 维自查 / ## 越界检查 / ## 做了什么 / ## 改动文件 / ## 自检方法)
|
|
407
|
+
// 6 维自查默认含实质内容且声明 brooks-review;method='' 表示去掉 ## 自检方法 段(旧格式场景)
|
|
408
|
+
// 结构子段与增量段按模板骨架补齐(`### 已知接受 + 理由` / `### 已知小问题` / `## LESSONS 扫描`):
|
|
409
|
+
// 这些 H3/增量段已成为新 change 的必填结构,夹具缺它们会被结构门当成工件缺陷而不是被测行为。
|
|
410
|
+
export function summaryContent(options = {}) {
|
|
411
|
+
const sixDim = options.sixDim !== undefined
|
|
412
|
+
? options.sixDim
|
|
413
|
+
: '## 6 维自查\n\n- 功能: 通过(brooks-review 已跑)\n- 性能: 无影响\n- 安全: 无影响\n- 兼容: 通过\n- 可观测: 通过\n- 可维护: 通过\n\n### 已知接受 + 理由\n\n- 无(夹具)。\n\n### 已知小问题\n\n- 无(夹具)。';
|
|
414
|
+
const method = options.method !== undefined ? options.method : '## 自检方法\n\nbrooks-review';
|
|
415
|
+
return [
|
|
416
|
+
'# T01-SUMMARY',
|
|
417
|
+
'',
|
|
418
|
+
'## verify 输出',
|
|
419
|
+
'',
|
|
420
|
+
'```',
|
|
421
|
+
'node --check src/t1.mjs',
|
|
422
|
+
'```',
|
|
423
|
+
'',
|
|
424
|
+
sixDim,
|
|
425
|
+
'',
|
|
426
|
+
'## 越界检查',
|
|
427
|
+
'',
|
|
428
|
+
'仅修改 src/t1.mjs,无越界。',
|
|
429
|
+
'',
|
|
430
|
+
'## 做了什么',
|
|
431
|
+
'',
|
|
432
|
+
'实现 T01。',
|
|
433
|
+
'',
|
|
434
|
+
'## 改动文件',
|
|
435
|
+
'',
|
|
436
|
+
'- src/t1.mjs',
|
|
437
|
+
'',
|
|
438
|
+
method,
|
|
439
|
+
'',
|
|
440
|
+
'## LESSONS 扫描',
|
|
441
|
+
'',
|
|
442
|
+
'无 active 条目命中(夹具)。',
|
|
443
|
+
'',
|
|
444
|
+
].join('\n');
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// 新 change 模板保真 SUMMARY(M1 严格形态:# SUMMARY: 标题 + 首部 4 字段 + 段序保真——
|
|
448
|
+
// directOverride 授权约束场景(213~216)用:新 change 出口强制模板保真,旧 summaryContent
|
|
449
|
+
// 无 # SUMMARY: 标题会被 M1 BLOCKED,不能用于正例/恢复场景)
|
|
450
|
+
// 结构子段(### 已知接受 + 理由 / ### 已知小问题)与增量段(## 自检方法 / ## LESSONS 扫描)按模板
|
|
451
|
+
// 骨架补齐——新 change 缺它们属工件缺陷,不应让夹具自身触发结构门。
|
|
452
|
+
export function strictSummary(taskId) {
|
|
453
|
+
return [
|
|
454
|
+
'# SUMMARY: ' + taskId + ' - 实现 ' + taskId,
|
|
455
|
+
'',
|
|
456
|
+
'- **Change ID**: ' + CHANGE_ID,
|
|
457
|
+
'- **Task ID**: ' + taskId,
|
|
458
|
+
'- **完成时间**: 2026-08-29 10:00',
|
|
459
|
+
'- **AI 角色**: Dev',
|
|
460
|
+
'',
|
|
461
|
+
'---',
|
|
462
|
+
'',
|
|
463
|
+
'## 做了什么',
|
|
464
|
+
'',
|
|
465
|
+
'实现 ' + taskId + '(TDD:先写失败场景再实现)。',
|
|
466
|
+
'',
|
|
467
|
+
'## 改动文件',
|
|
468
|
+
'',
|
|
469
|
+
'| 文件 | 性质 | 说明 |',
|
|
470
|
+
'|---|---|---|',
|
|
471
|
+
'| src/' + taskId.toLowerCase() + '.mjs | 修改 | 实现任务 |',
|
|
472
|
+
'',
|
|
473
|
+
'## verify 输出',
|
|
474
|
+
'',
|
|
475
|
+
'```',
|
|
476
|
+
'node --check src/' + taskId.toLowerCase() + '.mjs',
|
|
477
|
+
'```',
|
|
478
|
+
'',
|
|
479
|
+
'## 6 维自查',
|
|
480
|
+
'',
|
|
481
|
+
'- 功能: 通过(brooks-review 已跑)',
|
|
482
|
+
'- 性能: 无影响',
|
|
483
|
+
'- 安全: 无影响',
|
|
484
|
+
'- 兼容: 通过',
|
|
485
|
+
'- 可观测: 通过',
|
|
486
|
+
'- 可维护: 通过',
|
|
487
|
+
'',
|
|
488
|
+
'### 已知接受 + 理由',
|
|
489
|
+
'',
|
|
490
|
+
'- 无(夹具)。',
|
|
491
|
+
'',
|
|
492
|
+
'### 已知小问题',
|
|
493
|
+
'',
|
|
494
|
+
'- 无(夹具)。',
|
|
495
|
+
'',
|
|
496
|
+
'## 数据库迁移',
|
|
497
|
+
'',
|
|
498
|
+
'N/A:本任务无 schema 变更(条件段按模板占位)。',
|
|
499
|
+
'',
|
|
500
|
+
'## 越界检查',
|
|
501
|
+
'',
|
|
502
|
+
'仅修改 src/' + taskId.toLowerCase() + '.mjs,无越界。',
|
|
503
|
+
'',
|
|
504
|
+
'## 破坏性变更',
|
|
505
|
+
'',
|
|
506
|
+
'N/A:本任务不涉及破坏性变更。',
|
|
507
|
+
'',
|
|
508
|
+
'## 决策与偏离',
|
|
509
|
+
'',
|
|
510
|
+
'无偏离。',
|
|
511
|
+
'',
|
|
512
|
+
'## 是否触发新工作',
|
|
513
|
+
'',
|
|
514
|
+
'无。',
|
|
515
|
+
'',
|
|
516
|
+
'## 完成判定',
|
|
517
|
+
'',
|
|
518
|
+
'- TASK.md 中对应任务已勾选:是',
|
|
519
|
+
'',
|
|
520
|
+
'## 自检方法',
|
|
521
|
+
'',
|
|
522
|
+
'brooks-review',
|
|
523
|
+
'',
|
|
524
|
+
'## LESSONS 扫描',
|
|
525
|
+
'',
|
|
526
|
+
'无 active 条目命中(夹具)。',
|
|
527
|
+
'',
|
|
528
|
+
].join('\n');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// 伪造 handoffResult(越俎代庖检测要求 done 任务有 handoff;Return Contract 完整形状)
|
|
532
|
+
// handoff-guarded 落实——result 必须回传 completedChecks 含
|
|
533
|
+
// required-skill:subagent-execute.flow-comet-dev(guard W1-D 严格校验;相关场景同步补齐,
|
|
534
|
+
// 缺该字段的旧格式材料已明确覆盖 BLOCKED 路径)
|
|
535
|
+
export function handoffFor(taskIds) {
|
|
536
|
+
const handoffResult = {};
|
|
537
|
+
for (const id of taskIds) {
|
|
538
|
+
handoffResult[id] = {
|
|
539
|
+
result: {
|
|
540
|
+
commitHash: 'abcd1234',
|
|
541
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
542
|
+
greenEvidence: { command: 'node --check src/' + id.toLowerCase() + '.mjs' },
|
|
543
|
+
redEvidence: { command: 'node --check src/' + id.toLowerCase() + '.mjs' },
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
return handoffResult;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export const TASK_DONE =
|
|
551
|
+
'<task id="T01" status="done"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n';
|
|
552
|
+
export const TASK_DONE_TWO =
|
|
553
|
+
'<task id="T01" status="done"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n' +
|
|
554
|
+
'<task id="T02" status="done"><action>实现 T02</action><write_files>src/t2.mjs</write_files><verify>node --check src/t2.mjs</verify></task>\n';
|
|
555
|
+
export const TASK_SERIAL_PENDING =
|
|
556
|
+
'<task id="T01"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n';
|
|
557
|
+
export const TASK_P1 =
|
|
558
|
+
'<task id="P01" status="done" parallel="true"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify></task>\n';
|
|
559
|
+
export const TASK_P2 =
|
|
560
|
+
'<task id="P02" status="done" parallel="true"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify></task>\n';
|
|
561
|
+
// 第二波 parallel pending 任务(depends_on P01 已满足——第一波 P01 done 后才可委托;
|
|
562
|
+
// status 属性在前,与上方 parallel 任务常量的属性顺序一致)
|
|
563
|
+
export const TASK_P2_PENDING =
|
|
564
|
+
'<task id="P02" status="pending" parallel="true"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify><depends_on>P01</depends_on></task>\n';
|
|
565
|
+
// 串行 pending 任务(depends P01,P02——第二波 P02 完成前不可执行)
|
|
566
|
+
export const TASK_T03_PENDING =
|
|
567
|
+
'<task id="T03"><action>实现 T03</action><write_files>src/t3.mjs</write_files><verify>node --check src/t3.mjs</verify><depends_on>P01,P02</depends_on></task>\n';
|
|
568
|
+
// review/verify 阶段追加的 pending 修复任务(标准回退路径触发源)
|
|
569
|
+
export const TASK_TFIX =
|
|
570
|
+
'<task id="T-FIX-01" status="pending"><action>修复 verify 发现的缺陷</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n';
|
|
571
|
+
|
|
572
|
+
// ---------- 波次分组合法性场景任务集(T01 新增) ----------
|
|
573
|
+
// parallel="true" = 并行任务,parallel="false"/缺省 = 串行任务;序列判定以 <task> 块出现顺序为准。
|
|
574
|
+
// 回归:混排集里 P01 写成属性序 status 在前(status="pending" parallel="true"),
|
|
575
|
+
// 且串行任务 T01 的 <action> 文本内含 literal parallel="true" 字样(不改变语义)——开标签解析
|
|
576
|
+
// 属性序无关且不被块内文本干扰(旧整块查找会误判 T01 为并行 → 混排漏报)。
|
|
577
|
+
// 串→并→串(S→P→S):串行 T01 → 并行 P01/P02 → 串行 T02(混排,禁止)
|
|
578
|
+
export const TASK_MIXED_SPS =
|
|
579
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01(串行任务,动作描述含 literal parallel="true" 字样,不影响并行标记)</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n' +
|
|
580
|
+
'<task id="P01" status="pending" parallel="true"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify><depends_on>T01</depends_on></task>\n' +
|
|
581
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify><depends_on>T01</depends_on></task>\n' +
|
|
582
|
+
'<task id="T02" parallel="false" status="pending"><action>实现 T02</action><write_files>src/t2.mjs</write_files><verify>node --check src/t2.mjs</verify><depends_on>P01,P02</depends_on></task>\n';
|
|
583
|
+
// 并→串→并(P→S→P):并行 P01/P02 → 串行 T01 → 并行 P03/P04(混排,禁止)。
|
|
584
|
+
// 回归同上:P01 属性序 status 在前;串行任务 T01 的 <action> 文本含 literal parallel="true"。
|
|
585
|
+
export const TASK_MIXED_PSP =
|
|
586
|
+
'<task id="P01" status="pending" parallel="true"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify></task>\n' +
|
|
587
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify></task>\n' +
|
|
588
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01(串行任务,动作描述含 literal parallel="true" 字样,不影响并行标记)</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify><depends_on>P01,P02</depends_on></task>\n' +
|
|
589
|
+
'<task id="P03" parallel="true" status="pending"><action>实现 P03</action><write_files>src/p3.mjs</write_files><verify>node --check src/p3.mjs</verify><depends_on>T01</depends_on></task>\n' +
|
|
590
|
+
'<task id="P04" parallel="true" status="pending"><action>实现 P04</action><write_files>src/p4.mjs</write_files><verify>node --check src/p4.mjs</verify><depends_on>T01</depends_on></task>\n';
|
|
591
|
+
// 并存前+串在后(P→S):并行 P01/P02 → 串行 T01(合法成组)。
|
|
592
|
+
// 引号形态回归(解析一致性):P01/P02 用**单引号属性**(XML 合法形态)——单引号属性若不解析,
|
|
593
|
+
// 并行任务退化为非并行(route-node 误路由到 execute、并行写写检测漏判),本常量被场景 175 用于
|
|
594
|
+
// 断言 `NODE: subagent-execute`,漏解析即 RED。
|
|
595
|
+
export const TASK_VALID_PS =
|
|
596
|
+
"<task id='P01' parallel='true' status='pending'><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify></task>\n" +
|
|
597
|
+
"<task id='P02' parallel='true' status='pending'><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify></task>\n" +
|
|
598
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify><depends_on>P01,P02</depends_on></task>\n';
|
|
599
|
+
// 串在前+并在后(S→P):串行 T01 → 并行 P01/P02(合法成组)
|
|
600
|
+
export const TASK_VALID_SP =
|
|
601
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n' +
|
|
602
|
+
'<task id="P01" parallel="true" status="pending"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify><depends_on>T01</depends_on></task>\n' +
|
|
603
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify><depends_on>T01</depends_on></task>\n';
|
|
604
|
+
// 全串行(全 S)
|
|
605
|
+
export const TASK_VALID_ALL_SERIAL =
|
|
606
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n' +
|
|
607
|
+
'<task id="T02" parallel="false" status="pending"><action>实现 T02</action><write_files>src/t2.mjs</write_files><verify>node --check src/t2.mjs</verify><depends_on>T01</depends_on></task>\n';
|
|
608
|
+
// 全并行(全 P,单连续块)
|
|
609
|
+
export const TASK_VALID_ALL_PARALLEL =
|
|
610
|
+
'<task id="P01" parallel="true" status="pending"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify></task>\n' +
|
|
611
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify></task>\n' +
|
|
612
|
+
'<task id="P03" parallel="true" status="pending"><action>实现 P03</action><write_files>src/p3.mjs</write_files><verify>node --check src/p3.mjs</verify></task>\n' +
|
|
613
|
+
'<task id="P04" parallel="true" status="pending"><action>实现 P04</action><write_files>src/p4.mjs</write_files><verify>node --check src/p4.mjs</verify></task>\n';
|
|
614
|
+
|
|
615
|
+
// ---------- 多趟路由场景任务集(多趟语义批次:依赖环拦截与缺失依赖拦截场景原位重写 + 尾部新增场景族) ----------
|
|
616
|
+
// 依赖环:P01↔P02 互为 depends_on(依赖图有环 → plan 出口 BLOCKED 含「依赖环」+ depends_on 恢复指引)
|
|
617
|
+
export const TASK_DEP_CYCLE =
|
|
618
|
+
'<task id="P01" parallel="true" status="pending"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify><depends_on>P02</depends_on></task>\n' +
|
|
619
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/p2.mjs</write_files><verify>node --check src/p2.mjs</verify><depends_on>P01</depends_on></task>\n';
|
|
620
|
+
// 依赖缺失:P01 依赖不存在的 T99(依赖链不可满足 → plan 出口 BLOCKED 含恢复指引)
|
|
621
|
+
export const TASK_MISSING_DEP =
|
|
622
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n' +
|
|
623
|
+
'<task id="P01" status="pending" parallel="true"><action>实现 P01</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify><depends_on>T99</depends_on></task>\n';
|
|
624
|
+
// 并行写冲突(replan 越界场景扩展):前置串行任务已 done,两个并行任务依赖已满足且 write_files
|
|
625
|
+
// 重叠——plan 出口写写强判为 BLOCKED,replan 不做校验豁免、必须同样 BLOCK 且状态零改写(禁止备份先于拦截)。
|
|
626
|
+
export const TASK_PARALLEL_WRITE_CONFLICT =
|
|
627
|
+
'<task id="S01" parallel="false" status="done"><action>完成 S01</action><write_files>src/s01.mjs</write_files><verify>node --check src/s01.mjs</verify></task>\n' +
|
|
628
|
+
'<task id="P01" parallel="true" status="pending"><action>实现 P01</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify><depends_on>S01</depends_on></task>\n' +
|
|
629
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify><depends_on>S01</depends_on></task>\n';
|
|
630
|
+
|
|
631
|
+
// 并行读写弱判(replan 侧):同一对并行任务无显式 depends_on,一方读取对方
|
|
632
|
+
// 写路径 → 与 plan 出口同一判据:read∩write 仅 WARN 不阻断,replan 照常重签并写重签前备份。
|
|
633
|
+
export const TASK_PARALLEL_READ_OVERLAP =
|
|
634
|
+
'<task id="P01" parallel="true" status="pending"><action>实现 P01</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify></task>\n' +
|
|
635
|
+
'<task id="P02" parallel="true" status="pending"><action>实现 P02</action><read_files>src/shared.mjs</read_files><write_files>src/other.mjs</write_files><verify>node --check src/other.mjs</verify></task>\n';
|
|
636
|
+
|
|
637
|
+
// 同文件跨任务(第三族)夹具族:串行拆分出的同文件任务、彼此无 depends_on(#125 要抓的形态)。
|
|
638
|
+
// ① 非修复任务对 → 必须命中;② 修复任务族对(同文件回修)→ 不参与(顺序由修复生命周期保证);
|
|
639
|
+
// ③ 混合夹具:两类并存 → 只报非修复对(反向构造:第三族缺位时 ①③ 必然放过)。
|
|
640
|
+
export const CROSS_TASK_PLAIN_PAIR =
|
|
641
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify></task>\n'
|
|
642
|
+
+ '<task id="T02" parallel="false" status="pending"><action>实现 T02</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify></task>\n';
|
|
643
|
+
export const CROSS_TASK_FIX_PAIR =
|
|
644
|
+
'<task id="T-FIX-01" parallel="false" status="pending"><action>修复 T-FIX-01</action><write_files>src/fix-shared.mjs</write_files><verify>node --check src/fix-shared.mjs</verify></task>\n'
|
|
645
|
+
+ '<task id="T-FIX-02" parallel="false" status="pending"><action>修复 T-FIX-02</action><write_files>src/fix-shared.mjs</write_files><verify>node --check src/fix-shared.mjs</verify></task>\n';
|
|
646
|
+
export const CROSS_TASK_MIXED_PAIR =
|
|
647
|
+
'<task id="T01" parallel="false" status="pending"><action>实现 T01</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify></task>\n'
|
|
648
|
+
+ '<task id="T02" parallel="false" status="pending"><action>实现 T02</action><write_files>src/shared.mjs</write_files><verify>node --check src/shared.mjs</verify></task>\n'
|
|
649
|
+
+ '<task id="T-FIX-01" parallel="false" status="pending"><action>修复 T-FIX-01</action><write_files>src/other-shared.mjs</write_files><verify>node --check src/other-shared.mjs</verify></task>\n'
|
|
650
|
+
+ '<task id="T-FIX-02" parallel="false" status="pending"><action>修复 T-FIX-02</action><write_files>src/other-shared.mjs</write_files><verify>node --check src/other-shared.mjs</verify></task>\n';
|
|
651
|
+
// ④ **段归属分支**夹具:修复段内的任务 id **不带**修复族前缀(F01/F02)——判定必须靠「位于修复
|
|
652
|
+
// 任务段内」这条边界,而不是 id 命名。既有 ② 用的是带前缀 id,走的是 id 分支,段归属分支此前
|
|
653
|
+
// 没有行为夹具(该分支的行尾归一口径缺陷因此漏过)。
|
|
654
|
+
// **块内必须跨行**:单行块在 LF 与 CRLF 下文本完全相同,行尾口径缺陷无从显现——真实 TASK.md
|
|
655
|
+
// 的任务块本就跨行,夹具按真实形态构造(否则夹具自身无判别力)。
|
|
656
|
+
export const CROSS_TASK_FIX_SECTION_PAIR =
|
|
657
|
+
'## Fix 任务(来自 REVIEW)\n\n'
|
|
658
|
+
+ '<task id="F01" parallel="false" status="pending">\n'
|
|
659
|
+
+ ' <action>回修 F01</action>\n'
|
|
660
|
+
+ ' <write_files>src/section-shared.mjs</write_files>\n'
|
|
661
|
+
+ ' <verify>node --check src/section-shared.mjs</verify>\n'
|
|
662
|
+
+ '</task>\n'
|
|
663
|
+
+ '<task id="F02" parallel="false" status="pending">\n'
|
|
664
|
+
+ ' <action>回修 F02</action>\n'
|
|
665
|
+
+ ' <write_files>src/section-shared.mjs</write_files>\n'
|
|
666
|
+
+ ' <verify>node --check src/section-shared.mjs</verify>\n'
|
|
667
|
+
+ '</task>\n';
|
|
668
|
+
|
|
669
|
+
// 波次分组场景公共路径:注入 TASK.md → entry plan(记录 enteredNodes,新 change 强制先 entry;
|
|
670
|
+
// 旧 change 亦先 entry 避免 ENTER WARN 干扰断言)→ exit plan。返回 exit plan 结果。
|
|
671
|
+
export function runPlanExit(dir, taskContent) {
|
|
672
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n## 任务清单\n\n' + taskContent);
|
|
673
|
+
assertExit(runGuard(['entry', 'plan'], dir), 0);
|
|
674
|
+
return runGuard(['exit', 'plan'], dir);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// 多波混合任务集:串 T01 → 并 P01/P02(dep T01) → 串 T02(dep P01,P02) → 并 P03/P04(dep T02)。
|
|
678
|
+
// ≥2 个并行块被串行任务分隔(混排合法锚 / 多趟推进完成场景共用);doneIds 控制各任务 status,
|
|
679
|
+
// 模拟执行推进(next 分趟路由断言用)。
|
|
680
|
+
export const MULTI_WAVE_TASKS = [
|
|
681
|
+
['T01', false, []],
|
|
682
|
+
['P01', true, ['T01']],
|
|
683
|
+
['P02', true, ['T01']],
|
|
684
|
+
['T02', false, ['P01', 'P02']],
|
|
685
|
+
['P03', true, ['T02']],
|
|
686
|
+
['P04', true, ['T02']],
|
|
687
|
+
];
|
|
688
|
+
|
|
689
|
+
export function renderMultiWaveTasks(doneIds = []) {
|
|
690
|
+
const done = new Set(doneIds);
|
|
691
|
+
return MULTI_WAVE_TASKS.map(([id, parallel, deps]) =>
|
|
692
|
+
'<task id="' + id + '"' + (parallel ? ' parallel="true"' : ' parallel="false"') +
|
|
693
|
+
' status="' + (done.has(id) ? 'done' : 'pending') + '">' +
|
|
694
|
+
'<action>实现 ' + id + '</action><write_files>src/' + id.toLowerCase() + '.mjs</write_files>' +
|
|
695
|
+
'<verify>node --check src/' + id.toLowerCase() + '.mjs</verify>' +
|
|
696
|
+
(deps.length > 0 ? '<depends_on>' + deps.join(',') + '</depends_on>' : '') +
|
|
697
|
+
'</task>\n').join('');
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// 多波 next 断言公共材料:前序产物文件(open/design/plan 的产物门控按文件推导)
|
|
701
|
+
export function writeIntakeArtifacts(dir) {
|
|
702
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/CHANGE.md', '# CHANGE\n\n## Why\n\nx');
|
|
703
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REQUIREMENT.md', '# REQUIREMENT\n\n## 用户故事\n\nx\n\n## 验收准则(AC)\n\n- Given x When y Then z');
|
|
704
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md', '# DESIGN\n\n## 0. 技术栈\n\nNode\n\n## 决策清单\n\n| # | D | R |\n|---|---|---|\n| D1 | x | y |');
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// ---------- 位置迁移 / 备份 / 感知层剥离场景材料 ----------
|
|
708
|
+
// 全部经真实安装器(scripts/prepare-env.mjs)在临时项目上执行——断言落在真实文件系统状态与
|
|
709
|
+
// 进程输出上(端到端执行断言),不用形态断言替代。夹具路径一律 os.tmpdir()/path.join 生成
|
|
710
|
+
// (Windows 平台:bash 的 /tmp 会被 node 解析为当前盘根——夹具必须由 node 侧构造)。
|
|
711
|
+
|
|
712
|
+
export const LEGACY_RUNTIME_DIR = '.comet';
|
|
713
|
+
export const RUNTIME_DIR = '.flow-comet';
|
|
714
|
+
export const RUNTIME_STATE_NAME = 'flow-comet-state.json';
|
|
715
|
+
export const MIGRATION_CHANGE = 'mig-ch';
|
|
716
|
+
|
|
717
|
+
// 迁移前状态字节(健康 JSON——白名单唯一在册的运行时文件)
|
|
718
|
+
export function migratableStateBytes(activeChange = MIGRATION_CHANGE) {
|
|
719
|
+
return Buffer.from(JSON.stringify({
|
|
720
|
+
activeChange,
|
|
721
|
+
currentNode: 'design',
|
|
722
|
+
completedNodes: ['open'],
|
|
723
|
+
evidence: { open: { summary: 'intake complete' } },
|
|
724
|
+
verifyFailures: 0,
|
|
725
|
+
executionMode: 'subagent',
|
|
726
|
+
directOverride: false,
|
|
727
|
+
}, null, 2) + '\n', 'utf8');
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// 旧命名空间三方共占夹具(实测形态):flow-comet 运行时文件 + Comet 资产(config.yaml / runs/)
|
|
731
|
+
// + 用户自有文件(*.bak-*)。返回各非白名单项的迁移前字节,供「原位未动」断言(位置 + 内容)。
|
|
732
|
+
export function writeSharedCometDir(proj, stateBytes) {
|
|
733
|
+
const legacyDir = path.join(proj, LEGACY_RUNTIME_DIR);
|
|
734
|
+
fs.mkdirSync(path.join(legacyDir, 'runs'), { recursive: true });
|
|
735
|
+
fs.writeFileSync(path.join(legacyDir, RUNTIME_STATE_NAME), stateBytes);
|
|
736
|
+
fs.writeFileSync(path.join(legacyDir, 'config.yaml'), 'workflow:\n projectPath: docs/openspec\n');
|
|
737
|
+
fs.writeFileSync(path.join(legacyDir, 'runs', 'run-001.json'), '{"comet":true}\n');
|
|
738
|
+
fs.writeFileSync(path.join(legacyDir, RUNTIME_STATE_NAME + '.bak-20260901-user'), 'user backup\n');
|
|
739
|
+
const kept = ['config.yaml', 'runs/run-001.json', RUNTIME_STATE_NAME + '.bak-20260901-user'];
|
|
740
|
+
return kept.map((rel) => ({ rel, bytes: fs.readFileSync(path.join(legacyDir, rel)) }));
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// 迁移生成的备份清单(新命名空间内 flow-comet-state.json.bak-<时间戳>)
|
|
744
|
+
export function migrationBackups(proj) {
|
|
745
|
+
const dir = path.join(proj, RUNTIME_DIR);
|
|
746
|
+
if (!fs.existsSync(dir)) return [];
|
|
747
|
+
return fs.readdirSync(dir).filter((name) => /^flow-comet-state\.json\.bak-/.test(name)).sort();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// 目标项目的 .specs 工件(迁移后「流程可继续」断言需要活动 change 目录在场)
|
|
751
|
+
export function writeMigratedProjectArtifacts(proj, changeId = MIGRATION_CHANGE) {
|
|
752
|
+
writeFile(proj, '.specs/' + changeId + '/CHANGE.md', '# CHANGE\n\n- **Change ID**: ' + changeId + '\n\n## Why(为什么做)\n\nx\n');
|
|
753
|
+
writeFile(proj, '.specs/' + changeId + '/REQUIREMENT.md', '# REQUIREMENT\n\n- **Change ID**: ' + changeId + '\n\n## 用户故事(User Story)\n\nx\n\n## 验收准则(AC)\n\n- y\n');
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// 跑安装副本内的脚本(cwd = 目标项目根——runRoot = process.cwd()):迁移后链路在
|
|
757
|
+
// 真实安装形态(而非权威源脚本)上验证
|
|
758
|
+
export function runInstalled(proj, platformRoot, scriptName, args) {
|
|
759
|
+
const script = path.join(proj, platformRoot, 'skills', 'flow-comet', 'scripts', scriptName);
|
|
760
|
+
const res = spawnSync(process.execPath, [script, ...args], {
|
|
761
|
+
cwd: proj,
|
|
762
|
+
env: { ...process.env, FLOW_COMET_RUN_ROOT: proj },
|
|
763
|
+
encoding: 'utf8',
|
|
764
|
+
timeout: 60000,
|
|
765
|
+
});
|
|
766
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// 安装器输出/判定文本归一化(两个夹具的项目根不同——比较判定一致性前抹掉根路径差异)
|
|
770
|
+
export function normalizeRoot(text, ...roots) {
|
|
771
|
+
let out = String(text);
|
|
772
|
+
for (const root of roots) {
|
|
773
|
+
out = out.split(root).join('<root>');
|
|
774
|
+
out = out.split(root.replace(/\\/g, '/')).join('<root>');
|
|
775
|
+
}
|
|
776
|
+
return out;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Comet classic 资产夹具(感知层对照用):classic 配置 + 一个 phase=build 的活动 change
|
|
780
|
+
// + overlay 证据目录——旧感知层正是据此推导节点,故它们是"判定是否还读这些文件"的探针。
|
|
781
|
+
export function writeClassicCometAssets(proj) {
|
|
782
|
+
writeFile(proj, '.comet/config.yaml', 'workflow:\n projectPath: docs/openspec\n');
|
|
783
|
+
writeFile(proj, 'docs/openspec/changes/classic-marker/.comet.yaml', 'phase: build\nbuild_pause: plan-ready\n');
|
|
784
|
+
writeFile(proj, '.comet/workflow-evidence/classic-marker/overlay.json', '{}\n');
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// gitignore 纳管公共链路(三形态共用):写入既有内容 → 连续两次安装 → 返回两次结果与两次
|
|
788
|
+
// 安装后的 .gitignore 全文(字符串,逐字节比较用)
|
|
789
|
+
export function runGitignoreForm(dir, proj, initialContent) {
|
|
790
|
+
fs.writeFileSync(path.join(proj, '.gitignore'), initialContent, 'utf8');
|
|
791
|
+
const first = runPrepareEnv(['--target', proj, '--platform', 'claude-code'], dir);
|
|
792
|
+
const afterFirst = fs.readFileSync(path.join(proj, '.gitignore'), 'utf8');
|
|
793
|
+
const second = runPrepareEnv(['--target', proj, '--platform', 'claude-code'], dir);
|
|
794
|
+
const afterSecond = fs.readFileSync(path.join(proj, '.gitignore'), 'utf8');
|
|
795
|
+
return { first, second, afterFirst, afterSecond };
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// 纳管公共断言:两次安装均成功;新命名空间条目恰一行;第二次安装逐字节无变化(幂等)
|
|
799
|
+
export function assertGitignoreManaged(result) {
|
|
800
|
+
assertExit(result.first, 0);
|
|
801
|
+
assertExit(result.second, 0);
|
|
802
|
+
const entries = result.afterFirst.split(/\r?\n/)
|
|
803
|
+
.filter((line) => line.trim().replace(/^\/+/, '').replace(/\/+$/, '') === RUNTIME_DIR);
|
|
804
|
+
if (entries.length !== 1) throw new Error(RUNTIME_DIR + '/ 条目应恰一行,实际 ' + entries.length + ' 行');
|
|
805
|
+
if (result.afterSecond !== result.afterFirst) {
|
|
806
|
+
throw new Error('第二次安装改写了 gitignore(应幂等):\n' +
|
|
807
|
+
JSON.stringify({ afterFirst: result.afterFirst, afterSecond: result.afterSecond }, null, 2));
|
|
808
|
+
}
|
|
809
|
+
assertOut(result.second, '保持原样');
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// ---------- 结构锚的共享判定(判别力升级:按表达式形态计数,而不只是数标识符名) ----------
|
|
813
|
+
|
|
814
|
+
// ---------- 引擎实现面(结构锚的单一受检面) ----------
|
|
815
|
+
// 结构锚测的是**引擎实现面**,不是「scripts/ 顶层的文件名集合」:判定族下沉到 `lib/` 后,按顶层
|
|
816
|
+
// 平铺扫描的锚对迁出的实现**静默失明**(不红、继续绿——比红更危险),故受检面按**模块图派生**:
|
|
817
|
+
// 入口(顶层 `.mjs`,除两个套件入口)∪ 从入口静态可达的模块。套件自持模块(夹具 / 断言 / 文本锚
|
|
818
|
+
// 判据 / 计数派生)与两个数据目录(`scenarios/`、`items/`)因此落在面外——它们的文本本身携带被禁
|
|
819
|
+
// 形态的**样例**(夹具输入、反向构造探针),是判据的输入而非引擎实现;它们的分发面纪律由词表
|
|
820
|
+
// 扫描的递归面(注释层零代号,含数据目录)另行看守。
|
|
821
|
+
// 面无文件名清单:模块再搬家 / 再切分不必改锚;面收缩同样有读数(迁移后的实现若掉出面,白名单
|
|
822
|
+
// 「实际 0 处」一类断言即红,不静默)。
|
|
823
|
+
export const SUITE_ENTRY_FILES = new Set(['guard-self-test.mjs', 'system-test.mjs']);
|
|
824
|
+
|
|
825
|
+
// 静态导入 / 再导出的相对说明符(`from '…'` / `import('…')` / 裸 `import '…'`):模块图的边。
|
|
826
|
+
function staticImportSpecifiers(text) {
|
|
827
|
+
const out = [];
|
|
828
|
+
for (const match of String(text).matchAll(/(?:from|import)\s*\(?\s*['"](\.[^'"]+)['"]/g)) out.push(match[1]);
|
|
829
|
+
return out;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// 说明符 → 技能树内相对路径(posix 形态);越出脚本目录或非 `.mjs` 时返回 null。
|
|
833
|
+
export function resolveEngineSpecifier(fromRel, specifier) {
|
|
834
|
+
const target = path.posix.normalize(path.posix.join(path.posix.dirname(fromRel), specifier));
|
|
835
|
+
if (!target.endsWith('.mjs') || target.startsWith('..')) return null;
|
|
836
|
+
return target;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// 从给定根集合出发的静态可达闭包(模块图的 BFS):返回相对路径集合。
|
|
840
|
+
export function engineReachableFrom(roots, scriptsDir = SCRIPTS_DIR) {
|
|
841
|
+
const queue = [...roots];
|
|
842
|
+
const seen = new Set();
|
|
843
|
+
while (queue.length > 0) {
|
|
844
|
+
const rel = queue.shift();
|
|
845
|
+
if (seen.has(rel)) continue;
|
|
846
|
+
const abs = path.join(scriptsDir, rel);
|
|
847
|
+
if (!fs.existsSync(abs)) continue;
|
|
848
|
+
seen.add(rel);
|
|
849
|
+
for (const specifier of staticImportSpecifiers(fs.readFileSync(abs, 'utf8'))) {
|
|
850
|
+
const target = resolveEngineSpecifier(rel, specifier);
|
|
851
|
+
if (target !== null && !seen.has(target)) queue.push(target);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return seen;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// 引擎实现面(相对路径,已排序):入口(顶层 `.mjs`,除两个套件入口)∪ 从入口静态可达的模块
|
|
858
|
+
// ∪ `lib/` 下**非套件自持**的模块。第三项是刻意的保守面:掉进 `lib/` 却还没被入口 import 的文件
|
|
859
|
+
// (第二份实现最省事的藏身处、或迁移途中尚未接线的模块)同样必须可见——否则「放一处第二份实现」
|
|
860
|
+
// 会静默无感。套件自持面由**模块图**排除(只被套件入口可达者),不是文件名清单。
|
|
861
|
+
export function engineScriptFiles(scriptsDir = SCRIPTS_DIR) {
|
|
862
|
+
const topLevel = fs.readdirSync(scriptsDir).filter((name) => name.endsWith('.mjs'));
|
|
863
|
+
const entries = topLevel.filter((name) => !SUITE_ENTRY_FILES.has(name)).sort();
|
|
864
|
+
const face = engineReachableFrom(entries, scriptsDir);
|
|
865
|
+
const suiteRoots = topLevel.filter((name) => SUITE_ENTRY_FILES.has(name));
|
|
866
|
+
const suiteOwned = engineReachableFrom(suiteRoots, scriptsDir);
|
|
867
|
+
for (const rel of libModules(scriptsDir)) {
|
|
868
|
+
if (!suiteOwned.has(rel)) face.add(rel);
|
|
869
|
+
}
|
|
870
|
+
return [...face].sort();
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// 递归列举目录下的 `.mjs`(相对路径,posix 分隔):`scriptTreeFiles` 与 `libModules` 的唯一 walker。
|
|
874
|
+
function walkModules(dir, prefix) {
|
|
875
|
+
const out = [];
|
|
876
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
877
|
+
if (entry.isDirectory()) out.push(...walkModules(path.join(dir, entry.name), prefix + entry.name + '/'));
|
|
878
|
+
else if (entry.name.endsWith('.mjs')) out.push(prefix + entry.name);
|
|
879
|
+
}
|
|
880
|
+
return out;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// `lib/` 下的全部模块(相对路径):只在引擎面派生中用(面自身不写成文件名清单)。
|
|
884
|
+
function libModules(scriptsDir) {
|
|
885
|
+
const libDir = path.join(scriptsDir, 'lib');
|
|
886
|
+
if (!fs.existsSync(libDir)) return [];
|
|
887
|
+
return walkModules(libDir, '').map((rel) => 'lib/' + rel);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// 技能树内**全部**脚本文件(入口 + `lib/**` + `scenarios/**` + `items/**`,递归派生):分发面
|
|
891
|
+
// 文本纪律(注释层零代号 / 计数派生)的受检面——与引擎实现面不同,它**包含**套件自持模块与数据
|
|
892
|
+
// 目录(它们的注释同样随技能包分发)。
|
|
893
|
+
export function scriptTreeFiles(scriptsDir = SCRIPTS_DIR) {
|
|
894
|
+
return walkModules(scriptsDir, '').sort();
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// 引擎面的**真实形态 shadow 树**(递归受检面探针用):把引擎面(入口 + `lib/**`)整棵复制到
|
|
898
|
+
// `<shadowRoot>`,调用方再往里放「第二份实现」——结构锚若不递归就看不到 `lib/` 内的新增。
|
|
899
|
+
// 三处探针(277 定义面 / 291 惯用法 / 298 裸拼接)共用本夹具:真实形态的构造只写一遍。
|
|
900
|
+
// 返回 shadow 脚本目录路径。
|
|
901
|
+
export function copyEngineTree(shadowRoot, scriptsDir = SCRIPTS_DIR) {
|
|
902
|
+
const scripts = path.join(shadowRoot, 'scripts');
|
|
903
|
+
fs.mkdirSync(path.join(scripts, 'lib'), { recursive: true });
|
|
904
|
+
for (const rel of fs.readdirSync(scriptsDir)) {
|
|
905
|
+
if (rel.endsWith('.mjs')) fs.copyFileSync(path.join(scriptsDir, rel), path.join(scripts, rel));
|
|
906
|
+
}
|
|
907
|
+
for (const rel of engineScriptFiles(scriptsDir)) {
|
|
908
|
+
if (!rel.includes('/')) continue;
|
|
909
|
+
const target = path.join(scripts, rel);
|
|
910
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
911
|
+
fs.copyFileSync(path.join(scriptsDir, rel), target);
|
|
912
|
+
}
|
|
913
|
+
return scripts;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// 引擎面模块文本:相对路径 → 文本(面内读取的单一入口)。
|
|
917
|
+
export function engineScriptTexts(scriptsDir = SCRIPTS_DIR) {
|
|
918
|
+
const out = new Map();
|
|
919
|
+
for (const rel of engineScriptFiles(scriptsDir)) {
|
|
920
|
+
out.set(rel, fs.readFileSync(path.join(scriptsDir, rel), 'utf8'));
|
|
921
|
+
}
|
|
922
|
+
return out;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// 代码层文本(注释行剥离):结构锚判「代码里有没有某形态」——注释里提到标识符是说明,不是实现
|
|
926
|
+
// (与检查工具的注释层口径同源:行首 `//` / `*` / `/*` 才算注释行)。
|
|
927
|
+
export function engineCodeText(text) {
|
|
928
|
+
return String(text).split(/\r?\n/).filter((line) => !isScriptCommentLine(line)).join('\n');
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// 消费面(入口 ∪ `lib/**`):面内**引用**某符号的模块——由真实引用派生,不写文件名清单,
|
|
932
|
+
// 故模块搬迁 / 再切分不会让判据静默失焦,新增消费方自动进入对账。
|
|
933
|
+
export function engineConsumersOf(name, scriptsDir = SCRIPTS_DIR) {
|
|
934
|
+
const pattern = new RegExp('\\b' + name + '\\b');
|
|
935
|
+
return engineScriptFiles(scriptsDir).filter((rel) =>
|
|
936
|
+
pattern.test(engineCodeText(fs.readFileSync(path.join(scriptsDir, rel), 'utf8'))));
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// 从具名 import 列表里摘掉一个名字(反向构造用;名前 / 名后 / 唯一项三种位置都覆盖):
|
|
940
|
+
// 摘掉后消费方仍引用该符号 ⇒ 「未从单源取用」必报。位置感知是必须的——只处理「名字后带逗号」
|
|
941
|
+
// 的写法在名字位于列表末位时会静默不改,探针遂退化为恒绿(无判别力)。
|
|
942
|
+
export function dropNamedImport(text, name) {
|
|
943
|
+
return String(text)
|
|
944
|
+
.replace(new RegExp('(import\\s*\\{[^}]*?)\\b' + name + '\\b\\s*,\\s*'), '$1')
|
|
945
|
+
.replace(new RegExp('(import\\s*\\{[^}]*?)\\s*,\\s*\\b' + name + '\\b'), '$1');
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// 定义形态(函数声明 / 常量赋值)的单一表达式:定义面计数与「单源静态锁」共用——两处各写一份
|
|
949
|
+
// 会在口径演进时分叉。
|
|
950
|
+
export function engineDefinitionPattern(name, flags = '') {
|
|
951
|
+
return new RegExp('(?:export\\s+)?(?:async\\s+)?function\\s+' + name + '\\b'
|
|
952
|
+
+ '|(?:export\\s+)?const\\s+' + name + '\\s*=', flags);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// 定义处计数(结构锚的单源半边):某名字在引擎面内的定义次数(函数声明 / 常量赋值)。
|
|
956
|
+
// scriptsDir 是可测性接缝:使「同名第二份定义 → 检出 2 处」能在合成目录上被场景驱动(场景 277 的
|
|
957
|
+
// 反向构造),否则该判据只能靠人工实验证明判别力。
|
|
958
|
+
export function engineDefinitionHits(name, scriptsDir = SCRIPTS_DIR) {
|
|
959
|
+
const pattern = engineDefinitionPattern(name, 'g');
|
|
960
|
+
const hits = [];
|
|
961
|
+
for (const rel of engineScriptFiles(scriptsDir)) {
|
|
962
|
+
const count = (fs.readFileSync(path.join(scriptsDir, rel), 'utf8').match(pattern) ?? []).length;
|
|
963
|
+
if (count > 0) hits.push({ file: rel, count });
|
|
964
|
+
}
|
|
965
|
+
return hits;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// **反查定义模块**(判据形态:落点由导出符号派生,不写文件名常量):定义处恰好一处时返回
|
|
969
|
+
// { file, text };零处或非唯一(第二份实现)时返回 null——调用方据此显式报「前提失效」,
|
|
970
|
+
// 不静默取第一个。
|
|
971
|
+
export function engineDefinitionModule(name, scriptsDir = SCRIPTS_DIR) {
|
|
972
|
+
const hits = engineDefinitionHits(name, scriptsDir);
|
|
973
|
+
if (hits.length !== 1 || hits[0].count !== 1) return null;
|
|
974
|
+
return { file: hits[0].file, text: fs.readFileSync(path.join(scriptsDir, hits[0].file), 'utf8') };
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// 模块是否**再导出**某符号(`export { … }` / `export { … } from '…'`):re-export 枢纽
|
|
978
|
+
// (route-node.mjs 一类)是合法取用面,消费方从枢纽或从定义模块取用都算单一来源。
|
|
979
|
+
export function reExportsSymbol(text, symbol) {
|
|
980
|
+
for (const match of String(text).matchAll(/export\s*\{([^}]*)\}/g)) {
|
|
981
|
+
const names = match[1].split(',').map((piece) => piece.trim().split(/\s+as\s+/).pop());
|
|
982
|
+
if (names.includes(symbol)) return true;
|
|
983
|
+
}
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// 消费方是否**从单源取用**某符号(取用面的**唯一**实现):三种合法形态——① 具名 `import` 的
|
|
988
|
+
// 说明符解析后落在单源模块;② 落在再导出该符号的面内模块(re-export 枢纽合法);③
|
|
989
|
+
// `export { … } from '<单源>'`(转出枢纽自己不消费符号,也是单源通道而非第二份实现)。
|
|
990
|
+
// 说明符由消费方位置推导,不写死 `'./x.mjs'`(模块位于 `lib/` 时是 `'../x.mjs'`),模块再搬家
|
|
991
|
+
// 不必改锚。`texts` 给定时用它解析枢纽(纯函数形态,合成输入可驱动);否则读 `scriptsDir` 磁盘。
|
|
992
|
+
export function engineImportsSymbolFrom({ text, consumerRel, symbol, sourceRel, scriptsDir = SCRIPTS_DIR, texts = null }) {
|
|
993
|
+
const targetText = (target) => {
|
|
994
|
+
if (texts !== null) return texts.get(target) ?? null;
|
|
995
|
+
const abs = path.join(scriptsDir, target);
|
|
996
|
+
return fs.existsSync(abs) ? fs.readFileSync(abs, 'utf8') : null;
|
|
997
|
+
};
|
|
998
|
+
const reachesSource = (specifier) => {
|
|
999
|
+
const target = resolveEngineSpecifier(consumerRel, specifier);
|
|
1000
|
+
if (target === null) return false;
|
|
1001
|
+
if (target === sourceRel) return true;
|
|
1002
|
+
const hub = targetText(target);
|
|
1003
|
+
return hub !== null && reExportsSymbol(hub, symbol);
|
|
1004
|
+
};
|
|
1005
|
+
const names = (list) => list.split(',').flatMap((piece) => piece.trim().split(/\s+as\s+/)).map((piece) => piece.trim());
|
|
1006
|
+
for (const match of String(text).matchAll(/(?:import|export)\s*\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
1007
|
+
if (names(match[1]).includes(symbol) && reachesSource(match[2])) return true;
|
|
1008
|
+
}
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// 注释行判定:与检查工具的注释层口径一致(行首 // / /* / * 才算注释行,行尾注释不在此列)。
|
|
1013
|
+
export function isScriptCommentLine(line) {
|
|
1014
|
+
return /^\s*(\/\/|\*|\/\*)/.test(line);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// 具名函数体文本:先配平参数表圆括号(解构入参内含 `new Map()` 一类调用),再配平函数体花括号。
|
|
1018
|
+
// 目标函数体内不含字符串花括号,故不做字面量扫描。找不到定义返回 null——调用方据此显式报告
|
|
1019
|
+
// "结构锚前提失效",不静默按通过处理。
|
|
1020
|
+
export function functionBodyText(text, name) {
|
|
1021
|
+
const start = text.indexOf('function ' + name + '(');
|
|
1022
|
+
if (start < 0) return null;
|
|
1023
|
+
let i = text.indexOf('(', start);
|
|
1024
|
+
if (i < 0) return null;
|
|
1025
|
+
let parens = 0;
|
|
1026
|
+
for (; i < text.length; i += 1) {
|
|
1027
|
+
if (text[i] === '(') parens += 1;
|
|
1028
|
+
else if (text[i] === ')') {
|
|
1029
|
+
parens -= 1;
|
|
1030
|
+
if (parens === 0) break;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
i = text.indexOf('{', i);
|
|
1034
|
+
if (i < 0) return null;
|
|
1035
|
+
let depth = 0;
|
|
1036
|
+
for (; i < text.length; i += 1) {
|
|
1037
|
+
if (text[i] === '{') depth += 1;
|
|
1038
|
+
else if (text[i] === '}') {
|
|
1039
|
+
depth -= 1;
|
|
1040
|
+
if (depth === 0) return text.slice(start, i + 1);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return null;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// 修复族 id 前缀边界的权威表达式文本(单一来源:判据与夹具锚共用同一份字面量)。
|
|
1047
|
+
export const FIX_PREFIX_LITERAL_TEXT = '/^[TP]-FIX-/i';
|
|
1048
|
+
|
|
1049
|
+
// 修复族边界"出现处"扫描(纯读取,单一实现):引擎脚本里的五类出现面——
|
|
1050
|
+
// 前缀正则字面量 / 含 FIX 词干的其它正则字面量 / 修复族 id 字符串字面量 / 段内成员判定 /
|
|
1051
|
+
// 边界常量的按文件使用次数。注释行不参与(与检查工具的注释层口径一致):注释里提到标识符
|
|
1052
|
+
// 是说明,不是第二份实现。判定与扫描分离(本函数只收集事实,下函数只下结论)。
|
|
1053
|
+
export function fixFamilyBoundarySites(scriptsDir = SCRIPTS_DIR) {
|
|
1054
|
+
const sites = {
|
|
1055
|
+
prefixLiterals: [],
|
|
1056
|
+
otherFixRegexes: [],
|
|
1057
|
+
idLiterals: [],
|
|
1058
|
+
sectionMemberships: [],
|
|
1059
|
+
prefixUsesByFile: new Map(),
|
|
1060
|
+
};
|
|
1061
|
+
for (const file of engineScriptFiles(scriptsDir)) {
|
|
1062
|
+
const text = fs.readFileSync(path.join(scriptsDir, file), 'utf8');
|
|
1063
|
+
const lines = text.split(/\r?\n/);
|
|
1064
|
+
let prefixUses = 0;
|
|
1065
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
1066
|
+
const line = lines[i];
|
|
1067
|
+
if (isScriptCommentLine(line)) continue;
|
|
1068
|
+
let at = line.indexOf(FIX_PREFIX_LITERAL_TEXT);
|
|
1069
|
+
while (at >= 0) {
|
|
1070
|
+
sites.prefixLiterals.push(file + ':' + (i + 1));
|
|
1071
|
+
at = line.indexOf(FIX_PREFIX_LITERAL_TEXT, at + 1);
|
|
1072
|
+
}
|
|
1073
|
+
// 含 FIX 词干的其它正则字面量(单行内闭合、\ 转义感知):第二份前缀表达式在此现形
|
|
1074
|
+
for (const m of line.matchAll(/\/(?:\\.|[^/\\\n])*FIX(?:\\.|[^/\\\n])*\/[a-z]*/g)) {
|
|
1075
|
+
if (m[0] !== FIX_PREFIX_LITERAL_TEXT) sites.otherFixRegexes.push(file + ':' + (i + 1) + ' ' + m[0]);
|
|
1076
|
+
}
|
|
1077
|
+
for (const token of ['T-FIX', 'P-FIX']) {
|
|
1078
|
+
if (line.includes(token)) sites.idLiterals.push(file + ':' + (i + 1) + ' ' + token);
|
|
1079
|
+
}
|
|
1080
|
+
if (line.includes('sectionBlocks.has(')) sites.sectionMemberships.push(file + ':' + (i + 1));
|
|
1081
|
+
prefixUses += line.split('FIX_TASK_ID_PREFIX').length - 1;
|
|
1082
|
+
}
|
|
1083
|
+
if (prefixUses > 0) sites.prefixUsesByFile.set(file, prefixUses);
|
|
1084
|
+
}
|
|
1085
|
+
return sites;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// 修复族边界判据的**落点反查**:边界常量的定义模块由导出符号派生(不写文件名)。定义面零处或
|
|
1089
|
+
// 非唯一(第二份实现)时返回 { problems }——调用方原样上报,不静默取第一个。
|
|
1090
|
+
function fixFamilyBoundaryIndex(scriptsDir) {
|
|
1091
|
+
const definition = engineDefinitionModule('FIX_TASK_ID_PREFIX', scriptsDir);
|
|
1092
|
+
if (definition === null) {
|
|
1093
|
+
return {
|
|
1094
|
+
problems: ['修复族 id 边界常量 FIX_TASK_ID_PREFIX 的定义面不唯一(全引擎应恰一处): '
|
|
1095
|
+
+ JSON.stringify(engineDefinitionHits('FIX_TASK_ID_PREFIX', scriptsDir))],
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
return { identifierModule: definition.file, text: definition.text };
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// 修复族约定「只表达一次」判定(AC-15 判别力锚):返回问题描述数组(空数组 = 唯一表达)。
|
|
1102
|
+
// 判别力设计——旧锚按**标识符名**统计(哪个文件里出现该常量名),对"同一约定被表达两次"
|
|
1103
|
+
// 零判别力:第二份等价前缀表达式(交替式写法)不含该常量名 → 旧锚必放过(虚假单一来源信心)。
|
|
1104
|
+
// 本判据按**表达式形态**计数(扫描见 fixFamilyBoundarySites),四条一起构成"约定被表达两次即红":
|
|
1105
|
+
// ① id 前缀边界:唯一前缀正则字面量只允许出现一次,且必须落在**该常量的定义模块**内(落点由
|
|
1106
|
+
// 导出符号反查——模块搬家不必改锚,"唯一实现位于哪个文件名"不再在锚里存第二份事实);
|
|
1107
|
+
// ② 第二份表达式:引擎代码行不得出现其它含 FIX 词干的正则字面量,也不得出现修复族 id 的
|
|
1108
|
+
// 字符串字面量(`.startsWith(...)` 一类内联前缀判定形态);
|
|
1109
|
+
// ③ 段内边界:段内成员判定(`sectionBlocks.has(`)只允许出现一次——「位于修复段内」这条
|
|
1110
|
+
// 边界只在唯一分类器里表达;
|
|
1111
|
+
// ④ 谓词共用:修复族标记与并行文件依赖第三族的参与者排除必须各自调用唯一分类器,且不得
|
|
1112
|
+
// 自持边界常量 / 段切片(任一消费方自建第二份边界即红)。
|
|
1113
|
+
// 判据自身的判别力由场景内的反向夹具锚(同源 → 无问题;逐条注入 → 逐条专项报告)常驻保证。
|
|
1114
|
+
export function fixFamilyBoundaryProblems(scriptsDir = SCRIPTS_DIR) {
|
|
1115
|
+
const problems = [];
|
|
1116
|
+
const sites = fixFamilyBoundarySites(scriptsDir);
|
|
1117
|
+
const index = fixFamilyBoundaryIndex(scriptsDir);
|
|
1118
|
+
if (index.problems !== undefined) return index.problems;
|
|
1119
|
+
if (sites.prefixLiterals.length !== 1 || !sites.prefixLiterals[0].startsWith(index.identifierModule + ':')) {
|
|
1120
|
+
problems.push('修复族 id 前缀边界必须只表达一次且落在其定义模块(' + index.identifierModule + '),实际出现处: '
|
|
1121
|
+
+ JSON.stringify(sites.prefixLiterals));
|
|
1122
|
+
}
|
|
1123
|
+
if (sites.otherFixRegexes.length !== 0) {
|
|
1124
|
+
problems.push('引擎内出现第二份修复族 id 前缀表达式(同一约定被表达两次): '
|
|
1125
|
+
+ sites.otherFixRegexes.join('; '));
|
|
1126
|
+
}
|
|
1127
|
+
if (sites.idLiterals.length !== 0) {
|
|
1128
|
+
problems.push('引擎代码行出现修复族 id 字面量(内联前缀判定形态,应经唯一分类器): '
|
|
1129
|
+
+ sites.idLiterals.join('; '));
|
|
1130
|
+
}
|
|
1131
|
+
if (sites.sectionMemberships.length !== 1) {
|
|
1132
|
+
problems.push('「位于修复段内」边界(段内成员判定)必须只表达一次,实际出现处: '
|
|
1133
|
+
+ JSON.stringify(sites.sectionMemberships));
|
|
1134
|
+
}
|
|
1135
|
+
// 边界常量的使用面:定义 1 处 + 唯一分类器内 1 次 test = 2(其他消费方一律经分类器)
|
|
1136
|
+
const prefixUseTotal = [...sites.prefixUsesByFile.values()].reduce((a, b) => a + b, 0);
|
|
1137
|
+
if (prefixUseTotal !== 2 || sites.prefixUsesByFile.size !== 1
|
|
1138
|
+
|| !sites.prefixUsesByFile.has(index.identifierModule)) {
|
|
1139
|
+
problems.push('修复族 id 边界常量的使用面必须恰为「定义 + 唯一分类器内一次判定」,实际: '
|
|
1140
|
+
+ JSON.stringify([...sites.prefixUsesByFile.entries()]));
|
|
1141
|
+
}
|
|
1142
|
+
for (const fnName of ['fixTaskMarker', 'collectCrossTaskConflicts']) {
|
|
1143
|
+
const body = functionBodyText(index.text, fnName);
|
|
1144
|
+
if (body === null) {
|
|
1145
|
+
problems.push('结构锚前提失效:' + index.identifierModule + ' 未找到 ' + fnName + ' 的定义');
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (!/fixTaskClassifier\s*\(/.test(body)) {
|
|
1149
|
+
problems.push(fnName + ' 必须经唯一分类器判定修复族(不得自持第二份边界)');
|
|
1150
|
+
}
|
|
1151
|
+
if (/FIX_TASK_ID_PREFIX|fixSectionBody/.test(body)) {
|
|
1152
|
+
problems.push(fnName + ' 自持修复族边界常量 / 段切片(应只调用唯一分类器)');
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
return problems;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// ---------- 侧命令锚点材料(evolve / health / context-scan + 到期提示 + ui-design 强制等级) ----------
|
|
1159
|
+
// 三条侧命令与 ui-design 门是横向机制:判据一律走**真实 CLI**(spawn)或**模块导出**(动态导入
|
|
1160
|
+
// 同一实现),套件内不复制第二份判据。零写入判据用**树指纹**(相对路径清单 + 文件 sha256)表达——
|
|
1161
|
+
// 「跑完没变」与「跑前跑后一致」是同一判据的两种说法,此处只实现一次。
|
|
1162
|
+
|
|
1163
|
+
export const timeUtilsModule = await import(pathToFileURL(path.join(SCRIPTS_DIR, 'time-utils.mjs')).href);
|
|
1164
|
+
export const contextInitModule = await import(pathToFileURL(path.join(SCRIPTS_DIR, 'context-init.mjs')).href);
|
|
1165
|
+
export const stateSchemaModule = await import(pathToFileURL(path.join(SCRIPTS_DIR, 'state-schema.mjs')).href);
|
|
1166
|
+
|
|
1167
|
+
export const SIDE_EVOLVE = path.join(SCRIPTS_DIR, 'evolve.mjs');
|
|
1168
|
+
export const SIDE_HEALTH = path.join(SCRIPTS_DIR, 'health.mjs');
|
|
1169
|
+
export const SIDE_CONTEXT_SCAN = path.join(SCRIPTS_DIR, 'context-scan.mjs');
|
|
1170
|
+
export const SKILL_PROTOCOL_FILE = path.join(SCRIPTS_DIR, '..', 'reference', 'workflow-protocol.json');
|
|
1171
|
+
|
|
1172
|
+
export function requireModuleExport(moduleObject, name, where) {
|
|
1173
|
+
const value = moduleObject[name];
|
|
1174
|
+
if (value === undefined) {
|
|
1175
|
+
throw new Error(where + ' 缺导出 ' + name + '(套件锚点前提失效:单一实现被改名 / 移除)');
|
|
1176
|
+
}
|
|
1177
|
+
return value;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// 侧命令真实调用(cwd = 项目根;--root 由调用方显式传入——侧命令不进 8 节点流程)。
|
|
1181
|
+
// FLOW_COMET_PROTOCOL 注入场景内协议副本,与 runGuard / runStateWithProtocol 同一表达:协议路径的
|
|
1182
|
+
// 唯一权威是 state-schema 的选择器(state.protocolPath > 环境变量 > 内置默认),侧命令的子进程
|
|
1183
|
+
// (workflow-state 通道)因此要看到与门禁同一份协议来源——平台侧注入环境变量正是真实项目形态。
|
|
1184
|
+
// 需要构造「无环境变量」的场景用 `{ FLOW_COMET_PROTOCOL: '' }` 覆盖(空串按未设置处理)。
|
|
1185
|
+
export function runSideScript(script, args, root, envOverrides = {}) {
|
|
1186
|
+
const res = spawnSync(process.execPath, [script, ...args], {
|
|
1187
|
+
cwd: root,
|
|
1188
|
+
env: {
|
|
1189
|
+
...process.env,
|
|
1190
|
+
FLOW_COMET_PROTOCOL: path.join(root, 'reference', 'workflow-protocol.json'),
|
|
1191
|
+
...envOverrides,
|
|
1192
|
+
},
|
|
1193
|
+
encoding: 'utf8',
|
|
1194
|
+
timeout: 120000,
|
|
1195
|
+
});
|
|
1196
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// 树指纹:目录(含空目录)与文件内容的 sha256,按相对路径排序
|
|
1200
|
+
export function treeFingerprint(root) {
|
|
1201
|
+
const rows = [];
|
|
1202
|
+
const walk = (dir) => {
|
|
1203
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
1204
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
1205
|
+
for (const entry of entries) {
|
|
1206
|
+
const full = path.join(dir, entry.name);
|
|
1207
|
+
const rel = path.relative(root, full).split(path.sep).join('/');
|
|
1208
|
+
if (entry.isDirectory()) { rows.push(rel + '/'); walk(full); continue; }
|
|
1209
|
+
rows.push(rel + ' ' + createHash('sha256').update(fs.readFileSync(full)).digest('hex'));
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
walk(root);
|
|
1213
|
+
return rows.join('\n');
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export function fingerprintChanges(before, after) {
|
|
1217
|
+
const beforeRows = before === '' ? [] : before.split('\n');
|
|
1218
|
+
const afterRows = after === '' ? [] : after.split('\n');
|
|
1219
|
+
const beforeSet = new Set(beforeRows);
|
|
1220
|
+
const afterSet = new Set(afterRows);
|
|
1221
|
+
return [
|
|
1222
|
+
...beforeRows.filter((row) => !afterSet.has(row)).map((row) => '消失: ' + row),
|
|
1223
|
+
...afterRows.filter((row) => !beforeSet.has(row)).map((row) => '新增: ' + row),
|
|
1224
|
+
];
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// 时间单源**消费面**判据(场景 277 使用;纯函数 + 合成输入可驱动):每个符号必须同时满足
|
|
1228
|
+
// 「具名 import 自单源模块」与「真实调用」才算真实消费。旧判据只看 `name + '('` 的子串——
|
|
1229
|
+
// 消费脚本里内联一份同名实现即可满足(判据被本地影子实现骗过),故必须查 import 来源;
|
|
1230
|
+
// 说明符由消费方位置推导(`lib/` 内是 `'../time-utils.mjs'`),不写死单层形态。
|
|
1231
|
+
export function timeSingleSourceConsumerProblems(text, symbols, file = '', sourceRel = 'time-utils.mjs', scriptsDir = SCRIPTS_DIR) {
|
|
1232
|
+
const problems = [];
|
|
1233
|
+
const prefix = file === '' ? '' : file + ' ';
|
|
1234
|
+
for (const symbol of symbols) {
|
|
1235
|
+
if (!engineImportsSymbolFrom({ text, consumerRel: file, symbol, sourceRel, scriptsDir })) {
|
|
1236
|
+
problems.push(prefix + '未从 ' + sourceRel + ' 取用 ' + symbol
|
|
1237
|
+
+ '(单源纪律:不得在消费脚本内联同名第二份实现)');
|
|
1238
|
+
}
|
|
1239
|
+
if (!text.includes(symbol + '(')) {
|
|
1240
|
+
problems.push(prefix + '未真实消费 ' + symbol + '(单一权威应被调用)');
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return problems;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// 两层加载模型的**入口层**判据(场景 167 使用;纯函数 + 合成输入可驱动):入口册与入口展开册
|
|
1247
|
+
// 各须含入口层锚点句(「Skill 工具加载该节点的 Implementation 技能」)与「前置门」表述,且不得含
|
|
1248
|
+
// Implementation/Required 混淆句式与无限定自动补表述。返回问题描述数组。
|