flow-comet 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +64 -46
- package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +32 -0
- package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
- package/.flow-comet/skills/flow-comet/{GUIDANCE.md → reference/entry-detail.md} +18 -28
- package/.flow-comet/skills/flow-comet/reference/fix-loop.md +57 -0
- package/.flow-comet/skills/flow-comet/reference/platform-facts.md +58 -0
- package/.flow-comet/skills/flow-comet/reference/replan.md +23 -0
- package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +5 -4
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +266 -25
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -16325
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +73 -1077
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +14 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -6692
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2428
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +116 -9
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +29 -2086
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
- package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -3
- package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +6 -6
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +8 -5
- package/.flow-comet/skills/flow-comet-open/SKILL.md +5 -1
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
- package/.flow-comet/skills/flow-comet-review/SKILL.md +9 -12
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +59 -16
- package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +3 -3
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
- package/README.md +53 -70
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +59 -26
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +119 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +36 -1164
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +0 -116
- package/.flow-comet/skills/flow-comet/reference/composition-report.md +0 -65
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +0 -184
- package/.flow-comet/skills/flow-comet/reference/resolved-skills.json +0 -661
- package/.flow-comet/skills/flow-comet/reference/skill-review.md +0 -13
- package/.flow-comet/skills/flow-comet/reference/subagents/script-author.md +0 -7
- package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +0 -70
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// evolve 到期提示(单一归属):达阈值才输出,未达阈值零噪音。
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { isValidTimestamp, daysSince, isArchivedAfterTimestamp, hasSection9, EVOLVE_STALE_DAYS, EVOLVE_DUE_NEW_ARCHIVE_CHANGES } from '../time-utils.mjs';
|
|
5
|
+
import { specsDir } from './state-io.mjs';
|
|
6
|
+
|
|
7
|
+
// 该时刻之后归档、且 DESIGN.md 带 §9 的 change 数。归档时刻取目录名日期前缀(flow-kit 约定
|
|
8
|
+
// archive/<YYYY-MM-DD>-<change-id>,该标签随提交固化、跨 clone 稳定);「归档于何时」与「§9 是否
|
|
9
|
+
// 在场」两个判定都走 time-utils 单一来源——不在本模块内联第二份表达式(单一来源)。
|
|
10
|
+
// 读取失败 / 非目录 / 无 DESIGN.md / 无 §9 一律不计入(不误报)。
|
|
11
|
+
async function countSection9ArchivesSince(timestamp) {
|
|
12
|
+
const archiveRoot = path.join(specsDir(), 'archive');
|
|
13
|
+
let entries = [];
|
|
14
|
+
try {
|
|
15
|
+
entries = await fs.readdir(archiveRoot, { withFileTypes: true });
|
|
16
|
+
} catch {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
let count = 0;
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (!entry.isDirectory() || !isArchivedAfterTimestamp(entry.name, timestamp)) continue;
|
|
22
|
+
let design = '';
|
|
23
|
+
try {
|
|
24
|
+
design = await fs.readFile(path.join(archiveRoot, entry.name, 'DESIGN.md'), 'utf8');
|
|
25
|
+
} catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (hasSection9(design)) count += 1;
|
|
29
|
+
}
|
|
30
|
+
return count;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 到期提示:`last_evolve_at` 距今 > 60 天,或其后新增 ≥ 5 个带 §9 的归档 change → 输出一行;
|
|
34
|
+
// 否则**不打印任何行**(反例锚:未达阈值零噪音)。旧 state 无该字段 = 从未跑过 evolve →
|
|
35
|
+
// 静默(不强制未接入 evolve 的项目补字段:无基线可判时不制造噪音)。提示行内不含花括号——
|
|
36
|
+
// status 的 JSON 块按「首个 { 到末个 }」截取(既有消费方 parseStatusJson 同形)。
|
|
37
|
+
export async function printEvolveDueHint(state) {
|
|
38
|
+
const lastEvolveAt = state && typeof state.last_evolve_at === 'string' ? state.last_evolve_at : '';
|
|
39
|
+
if (!isValidTimestamp(lastEvolveAt)) return;
|
|
40
|
+
const elapsedDays = daysSince(lastEvolveAt);
|
|
41
|
+
if (Number.isNaN(elapsedDays)) return;
|
|
42
|
+
const staleByAge = elapsedDays > EVOLVE_STALE_DAYS;
|
|
43
|
+
const newArchives = await countSection9ArchivesSince(lastEvolveAt);
|
|
44
|
+
const staleByCount = newArchives >= EVOLVE_DUE_NEW_ARCHIVE_CHANGES;
|
|
45
|
+
if (!staleByAge && !staleByCount) return;
|
|
46
|
+
const reasons = [];
|
|
47
|
+
if (staleByAge) {
|
|
48
|
+
reasons.push('距今 ' + Math.floor(elapsedDays) + ' 天,超阈值 ' + EVOLVE_STALE_DAYS + ' 天');
|
|
49
|
+
}
|
|
50
|
+
if (staleByCount) {
|
|
51
|
+
reasons.push('其后新增 ' + newArchives + ' 个带 §9 的归档 change,达阈值 ' + EVOLVE_DUE_NEW_ARCHIVE_CHANGES + ' 个');
|
|
52
|
+
}
|
|
53
|
+
console.log('EVOLVE-DUE: 上次架构沉淀 ' + lastEvolveAt + '(' + reasons.join(';')
|
|
54
|
+
+ ')——建议显式调用 evolve(/flow-comet-evolve)同步 CONTEXT.md');
|
|
55
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// explain(单一归属):节点现问——只读派生自协议 JSON。
|
|
2
|
+
// 「某节点产出什么 / 门禁是什么 / 要加载什么 / 跑哪三条命令」此前只在册子里手抄,本命令把它
|
|
3
|
+
// 暴露为节点现问通道。数据全部取自协议 JSON 的 nodes[] 与 outputSchemas[]——零新事实源、零状态
|
|
4
|
+
// 读写(不写 state、不改路由、不绕门禁,与 bridge-check 同为纯读通道)。节点 id 非法 →
|
|
5
|
+
// fail-closed 并列出协议内全部合法节点。
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { runRootDir } from './state-io.mjs';
|
|
8
|
+
|
|
9
|
+
// 命令路径形态(平台化):权威源保持设计形态 .claude/skills/(与册子命令形态一致,安装时由
|
|
10
|
+
// prepare-env 的 pathReplacements 平台化);安装副本按脚本自定位输出运行根相对形态——.claude /
|
|
11
|
+
// .agents / .dsh 乃至将来新增的平台根同一推导覆盖,无需在此登记平台清单;落在运行根之外
|
|
12
|
+
// (用户级安装)时输出脚本自身的绝对路径。不得硬编码单一形态:pathReplacements 只处理 .md
|
|
13
|
+
// (prepare-env 的 applyPathReplacements 按扩展名过滤),脚本内的字面量在安装副本上不会被
|
|
14
|
+
// 替换——硬编码 .claude 会让 Codex / dsh 单平台安装的 explain 输出不存在的命令路径。
|
|
15
|
+
// scriptsDir 由入口以自定位绝对路径传入(入口所在目录即脚本目录)。
|
|
16
|
+
function platformScriptsDir(scriptsDir) {
|
|
17
|
+
const posixDir = scriptsDir.replace(/\\/g, '/');
|
|
18
|
+
if (posixDir.includes('/.flow-comet/skills/')) return '.claude/skills/flow-comet/scripts';
|
|
19
|
+
const relative = path.relative(runRootDir(), scriptsDir).split(path.sep).join('/');
|
|
20
|
+
if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative)) return posixDir;
|
|
21
|
+
return relative;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ① 该节点的 outputSchema 名与产物路径(含 evidence id)。产物根语义与状态机 / guard 的节点完成
|
|
25
|
+
// 判定一致:'specs-root' → .specs/;'project' / 缺省 → 项目根。悬空 schema 引用如实标注、不编造
|
|
26
|
+
// 产物(自定义协议允许悬空引用,route-node 的产物推导同样容忍)。
|
|
27
|
+
function printNodeArtifacts(protocol, node) {
|
|
28
|
+
const schemaById = new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
|
|
29
|
+
const schemaIds = node.outputSchemas ?? [];
|
|
30
|
+
if (schemaIds.length === 0) console.log('OUTPUT-SCHEMA: (none)');
|
|
31
|
+
for (const schemaId of schemaIds) {
|
|
32
|
+
const schema = schemaById.get(schemaId);
|
|
33
|
+
console.log('OUTPUT-SCHEMA: ' + schemaId + (schema && schema.description ? ' — ' + schema.description : ''));
|
|
34
|
+
if (!schema) {
|
|
35
|
+
console.log(' ARTIFACT: (none)——协议 outputSchemas[] 未声明该 schema,无法派生产物路径');
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
for (const artifact of schema.artifacts ?? []) {
|
|
39
|
+
// 同一 artifact 的 paths 为互斥备选(命中任一即产物存在,与节点完成判定同语义)
|
|
40
|
+
const artifactRoot = artifact.pathBase === 'specs-root' ? '.specs/' : '';
|
|
41
|
+
const paths = (artifact.paths ?? []).map((declaredPath) => artifactRoot + String(declaredPath));
|
|
42
|
+
console.log(' ARTIFACT: ' + (artifact.id ?? '(unnamed)')
|
|
43
|
+
+ (artifact.kind ? ' [' + artifact.kind + ']' : '')
|
|
44
|
+
+ (artifact.required === false ? ' optional' : ' required')
|
|
45
|
+
+ ' → ' + (paths.length > 0 ? paths.join(' | ') : '(未声明路径)'));
|
|
46
|
+
}
|
|
47
|
+
const evidenceIds = (schema.evidence ?? []).map((evidence) => evidence.id
|
|
48
|
+
+ (evidence.required === false ? ' (optional)' : ' (required)'));
|
|
49
|
+
console.log(' EVIDENCE: ' + (evidenceIds.length > 0 ? evidenceIds.join(' | ') : '(none)'));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ② guardrails 表(id / label / validation)
|
|
54
|
+
function printNodeGuardrails(node) {
|
|
55
|
+
const guardrails = node.guardrails ?? [];
|
|
56
|
+
if (guardrails.length === 0) console.log('GUARDRAIL: (none)');
|
|
57
|
+
for (const guardrail of guardrails) {
|
|
58
|
+
console.log('GUARDRAIL: ' + (guardrail.id ?? '(unnamed)') + ' | ' + (guardrail.label ?? '-')
|
|
59
|
+
+ ' | ' + (guardrail.validation ?? '-'));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ③ requiredSkillCalls(skill / scope / enforcement / reason)
|
|
64
|
+
function printNodeSkillCalls(node) {
|
|
65
|
+
const calls = node.requiredSkillCalls ?? [];
|
|
66
|
+
if (calls.length === 0) console.log('REQUIRED-SKILL: (none)');
|
|
67
|
+
for (const call of calls) {
|
|
68
|
+
console.log('REQUIRED-SKILL: ' + (call.skill ?? '(unnamed)')
|
|
69
|
+
+ ' | scope=' + (call.scope ?? '-') + ' | enforcement=' + (call.enforcement ?? '-')
|
|
70
|
+
+ ' | reason=' + (call.reason ?? '-'));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ④ 三条命令(entry / exit / record,按节点 id 与平台化路径形态生成)。脚本路径整体加双引号:
|
|
75
|
+
// 安装根含空格时未加引号的路径会被 shell 按空格切分(只剩路径首段被当作脚本),打印出来的命令
|
|
76
|
+
// 便跑不了——加引号后三种平台语义下都是**单一参数**(引号本身对无空格路径无害)。
|
|
77
|
+
function printNodeCommands(node, scriptsDir) {
|
|
78
|
+
const platformDir = platformScriptsDir(scriptsDir);
|
|
79
|
+
console.log('COMMAND entry: node "' + platformDir + '/workflow-guard.mjs" entry ' + node.id);
|
|
80
|
+
console.log('COMMAND exit: node "' + platformDir + '/workflow-guard.mjs" exit ' + node.id + ' --apply');
|
|
81
|
+
console.log('COMMAND record: node "' + platformDir + '/workflow-state.mjs" record ' + node.id
|
|
82
|
+
+ " '{\"summary\":\"<完成摘要>\"}'");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// explain <node>:缺参 / 纯空白 / 拿选项当节点名(如 --help)→ 用法错误(fail-closed,不猜)
|
|
86
|
+
export function runExplain(protocol, argv, scriptsDir) {
|
|
87
|
+
const explainNodeId = argv[3];
|
|
88
|
+
const legalNodeIds = (protocol.nodes ?? []).map((node) => node.id);
|
|
89
|
+
if (typeof explainNodeId !== 'string' || explainNodeId.trim() === '' || explainNodeId.startsWith('--')) {
|
|
90
|
+
throw new Error('explain requires a <node> id. 用法: workflow-state.mjs explain <node>'
|
|
91
|
+
+ '(合法节点: ' + legalNodeIds.join('/') + ')');
|
|
92
|
+
}
|
|
93
|
+
const explainNode = (protocol.nodes ?? []).find((node) => node.id === explainNodeId);
|
|
94
|
+
if (!explainNode) {
|
|
95
|
+
throw new Error('explain node 非法: ' + explainNodeId + '(协议节点: ' + legalNodeIds.join('/') + ')');
|
|
96
|
+
}
|
|
97
|
+
console.log('NODE: ' + explainNode.id);
|
|
98
|
+
if (explainNode.label) console.log('LABEL: ' + explainNode.label);
|
|
99
|
+
if (explainNode.kind) console.log('KIND: ' + explainNode.kind);
|
|
100
|
+
if (explainNode.disabled === true) console.log('DISABLED: true(该节点在当前协议中被停用)');
|
|
101
|
+
printNodeArtifacts(protocol, explainNode);
|
|
102
|
+
printNodeGuardrails(explainNode);
|
|
103
|
+
printNodeSkillCalls(explainNode);
|
|
104
|
+
printNodeCommands(explainNode, scriptsDir);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// intel-scan 双落点一致性(单一归属):init 侧的形态对齐与漂移可见。
|
|
2
|
+
// `last_intel_scan` 是**双落点**字段:引擎 state(机器真相、schema 校验)与 `.specs/CONTEXT.md` 的
|
|
3
|
+
// `## intel-scan 元数据` 段(项目可见)。段行的改写——含改写前备份与结构校验——只有 context-scan
|
|
4
|
+
// 一条通道一份实现;init 侧因此**不写段**(在第二处复制段行改写判据必然与前者分叉),只承担两条:
|
|
5
|
+
// ① 形态对齐:state 侧取值一律经 time-utils 的 nowTimestamp()(本地时间 + 显式偏移),与
|
|
6
|
+
// context-scan 写入的形态同源;历史 `Z` 形态继续可解析(不迁移)。
|
|
7
|
+
// ② 漂移可见:写完后与段侧取值比对(口径 = **取值词元**,与段行写通道替换的那个词元同口径)——
|
|
8
|
+
// 不一致(含**同一时刻的两种形态**、段内取值不可解析)即输出可见提示并点名收敛命令;一致则
|
|
9
|
+
// 静默(不误报);带行尾说明的段行不构成差异(说明由写通道原样保留,不是取值的一部分)。
|
|
10
|
+
import { promises as fs } from 'fs';
|
|
11
|
+
import { extractContextStructure } from '../context-init.mjs';
|
|
12
|
+
import { parseTimestamp } from '../time-utils.mjs';
|
|
13
|
+
|
|
14
|
+
export const INTEL_SECTION_NAME = 'intel-scan 元数据';
|
|
15
|
+
export const INTEL_FIELD_NAME = 'last_intel_scan';
|
|
16
|
+
|
|
17
|
+
// 段侧取值词元的归一:`extractContextStructure` 返回的是字段行冒号后的**整行剩余文本**
|
|
18
|
+
// (取值词元 + 可选的 markdown 引号 + 可选的行尾说明),而段行的写通道 `context-scan` 按
|
|
19
|
+
// `INTEL_FIELD_LINE = (…)(\S+)([\s\S]*)` 只替换**首个取值词元**、行尾说明原样保留(首次接入的
|
|
20
|
+
// CONTEXT 生成物即「词元 + 说明」形态)。读侧因此必须取同一口径的词元再比对:按整行剩余文本比对时,
|
|
21
|
+
// 带说明的段行与 state 永不相等 ⇒ 同刻同形态也恒亮「不一致」、类别退化成「段内取值不是合法时间戳」,
|
|
22
|
+
// 提示点名的 `context-scan` 收敛承诺不可达(提示噪声化 = 没人看的行)。
|
|
23
|
+
// 空白切分与写侧正则的 `\S+` 同一字符类语义;行结构(段名 / 字段行形态)仍唯一来自
|
|
24
|
+
// extractContextStructure——本函数只做「词元 + 引号」归一,不解析段行(单一来源)。
|
|
25
|
+
export function normalizeIntelFieldValue(value) {
|
|
26
|
+
return String(value).trim().split(/\s+/)[0].replace(/^`+/, '').replace(/`+$/, '').trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 漂移判定(纯函数):两侧取值不一致时返回差异类别,一致(或任一侧缺席)返回 null(不误报)。
|
|
30
|
+
export function intelScanDriftKind(stateValue, sectionValue) {
|
|
31
|
+
if (typeof stateValue !== 'string' || typeof sectionValue !== 'string') return null;
|
|
32
|
+
if (stateValue === sectionValue) return null;
|
|
33
|
+
const atSection = parseTimestamp(sectionValue);
|
|
34
|
+
if (Number.isNaN(atSection)) return '段内取值不是合法时间戳';
|
|
35
|
+
const atState = parseTimestamp(stateValue);
|
|
36
|
+
if (!Number.isNaN(atState) && atState === atSection) return '同刻不同形态';
|
|
37
|
+
return '刻与形态均不一致';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 双落点比对(读盘 + 输出):段侧文档缺席 / 段或缺字段不在场 = 无可比对面 → 静默(不无中生有);
|
|
41
|
+
// 检出漂移 → 可见提示(stdout,与 INIT-* 提示同族且不阻断 init),点名两侧取值与收敛命令。
|
|
42
|
+
export async function reportIntelScanDrift(contextFile, stateValue) {
|
|
43
|
+
let contextText;
|
|
44
|
+
try {
|
|
45
|
+
contextText = await fs.readFile(contextFile, 'utf8');
|
|
46
|
+
} catch {
|
|
47
|
+
return; // 段侧文档不可读 = 无可比对面
|
|
48
|
+
}
|
|
49
|
+
const fields = extractContextStructure(contextText).metadata[INTEL_SECTION_NAME];
|
|
50
|
+
if (!fields || !fields[INTEL_FIELD_NAME]) return; // 段或缺字段不在场 = 无可比对面
|
|
51
|
+
const landed = normalizeIntelFieldValue(fields[INTEL_FIELD_NAME].value);
|
|
52
|
+
const kind = intelScanDriftKind(stateValue, landed);
|
|
53
|
+
if (kind === null) return;
|
|
54
|
+
console.log('INIT-NOTICE: ' + INTEL_FIELD_NAME + ' 双落点不一致(' + kind + ')——引擎 state = '
|
|
55
|
+
+ stateValue + ';`.specs/CONTEXT.md` 的 `## ' + INTEL_SECTION_NAME + '` 段 = ' + landed
|
|
56
|
+
+ '。本命令只写 state(该段行的写通道是 context-scan);运行 context-scan 即把两处收敛为'
|
|
57
|
+
+ '同刻同形态(冲突时以 state 为准)。');
|
|
58
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// 状态读写与 .specs 路径上下文(单一归属):状态文件解析 / 原子写落盘 / 活动 change 解析 /
|
|
2
|
+
// change 目录边界,以及各命令族共用的路径锚(runRoot · specsRoot · statePath)。
|
|
3
|
+
// 路径锚由入口在分派前初始化一次(runRoot = 进程 cwd)——模块内不自行取 cwd:入口与模块
|
|
4
|
+
// 各持一份「运行根」就是同一事实的第二处表达。目录名与状态文件名常量来自 state-schema.mjs。
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { validateStateFields, writeJsonAtomic, RUNTIME_DIR, RUNTIME_STATE_FILE_NAME } from '../state-schema.mjs';
|
|
8
|
+
import { inspectWorkflowPathSegments } from '../protocol-utils.mjs';
|
|
9
|
+
import { isSingleSegmentChangeName } from '../route-node.mjs';
|
|
10
|
+
|
|
11
|
+
let runtimeContext = null;
|
|
12
|
+
|
|
13
|
+
export function initStateContext(runRoot) {
|
|
14
|
+
runtimeContext = {
|
|
15
|
+
runRoot,
|
|
16
|
+
specsRoot: path.join(runRoot, '.specs'),
|
|
17
|
+
statePath: path.join(runRoot, RUNTIME_DIR, RUNTIME_STATE_FILE_NAME),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function runRootDir() {
|
|
22
|
+
return runtimeContext.runRoot;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function specsDir() {
|
|
26
|
+
return runtimeContext.specsRoot;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function stateFile() {
|
|
30
|
+
return runtimeContext.statePath;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 读 JSON:容忍 UTF-8 BOM(外部写入如会话 Write 可能带 BOM)
|
|
34
|
+
export async function readJson(file) {
|
|
35
|
+
return JSON.parse((await fs.readFile(file, 'utf8')).replace(/^\uFEFF/, ''));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function fileExists(file) {
|
|
39
|
+
try { await fs.access(file); return true; } catch { return false; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function findActiveChange() {
|
|
43
|
+
// 1. Read from state file if exists
|
|
44
|
+
if (await fileExists(stateFile())) {
|
|
45
|
+
const state = await readJson(stateFile());
|
|
46
|
+
// completed 检查优先于 activeChange 分支——归档完成态(无论 activeChange 是否残留)
|
|
47
|
+
// 一律不识别为 active(防归档残留目录 / 残留字段误判)
|
|
48
|
+
if (state.status === 'completed') return null;
|
|
49
|
+
if (state.activeChange) {
|
|
50
|
+
const changeDir = path.join(specsDir(), state.activeChange);
|
|
51
|
+
if (await fileExists(changeDir)) return state.activeChange;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// 2. Scan .specs/ for directories with TASK.md (active flow-kit changes)
|
|
55
|
+
// 注: 曾尝试按 archive/ 对应归档跳过残留目录——但会误伤同名新 change(既有实证),已撤回。
|
|
56
|
+
// 「state 缺失 + 归档残留」为已知限制;归档后正常态由上文 completed 分支覆盖。
|
|
57
|
+
try {
|
|
58
|
+
const entries = await fs.readdir(specsDir(), { withFileTypes: true });
|
|
59
|
+
const candidates = [];
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
if (!entry.isDirectory() || entry.name === 'archive' || entry.name === 'health' || entry.name === 'evolve' || entry.name === 'adr') continue;
|
|
62
|
+
const taskFile = path.join(specsDir(), entry.name, 'TASK.md');
|
|
63
|
+
if (await fileExists(taskFile)) candidates.push(entry.name);
|
|
64
|
+
}
|
|
65
|
+
if (candidates.length === 1) return candidates[0];
|
|
66
|
+
if (candidates.length > 1) {
|
|
67
|
+
// Return the most recently modified
|
|
68
|
+
const withTime = await Promise.all(candidates.map(async c => ({
|
|
69
|
+
name: c,
|
|
70
|
+
mtime: (await fs.stat(path.join(specsDir(), c, 'TASK.md'))).mtimeMs
|
|
71
|
+
})));
|
|
72
|
+
withTime.sort((a, b) => b.mtime - a.mtime);
|
|
73
|
+
return withTime[0].name;
|
|
74
|
+
}
|
|
75
|
+
} catch {}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function readState() {
|
|
80
|
+
if (await fileExists(stateFile())) {
|
|
81
|
+
const st = await readJson(stateFile());
|
|
82
|
+
// 兼容旧 state:无 executionMode / directOverride 时补默认(subagent 默认,direct 是显式逃生口)
|
|
83
|
+
if (st.executionMode === undefined) st.executionMode = 'subagent';
|
|
84
|
+
if (st.directOverride === undefined) st.directOverride = false;
|
|
85
|
+
// branchMode 默认 true(git 仓库时 init 会判定为 true;非 git 仓库 init 纠正为 false;
|
|
86
|
+
// status/next 显示以实时 git 检测为准——非 git 仓库显示 BRANCH: none)
|
|
87
|
+
if (st.branchMode === undefined) st.branchMode = true;
|
|
88
|
+
if (st.enablePrReview === undefined) st.enablePrReview = false;
|
|
89
|
+
// 分支前缀(init --branch-prefix 记录;旧 state 缺省 'change/' 向后兼容)
|
|
90
|
+
if (st.branchPrefix === undefined) st.branchPrefix = 'change/';
|
|
91
|
+
return st;
|
|
92
|
+
}
|
|
93
|
+
return { activeChange: null, currentNode: null, completedNodes: [], evidence: {}, verifyFailures: 0, executionMode: 'subagent', directOverride: false, branchMode: true, enablePrReview: false };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 写入前校验已知字段类型(fail-closed:非法 → BLOCKED 拒绝写入,不修复不猜测):未知字段允许
|
|
97
|
+
// (前向兼容),缺字段允许(readState 默认补),只校验存在字段的类型。校验表唯一来源 =
|
|
98
|
+
// state-schema.mjs(本函数不复制判据)。写盘统一走状态层的原子写:先写同目录临时文件再 rename
|
|
99
|
+
// 覆盖,目标要么旧内容要么新内容,不会出现被截断的半写状态;写失败(磁盘满 / 权限 / 目标被占用)
|
|
100
|
+
// 清理临时文件后抛出,调用方按 fail-closed 处理。mkdir recursive 由该实现承担(.skill-loads/ 等
|
|
101
|
+
// 标记目录不存在时创建);状态下发是单写者形态(机器字段只由脚本通道写)。
|
|
102
|
+
export async function writeState(state) {
|
|
103
|
+
const bad = validateStateFields(state);
|
|
104
|
+
if (bad.length) {
|
|
105
|
+
console.error('BLOCKED: state 字段类型非法: ' + bad[0]);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
await writeJsonAtomic(stateFile(), state);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// .specs/ 下必须存在名字「逐字相等」的目录条目(change 名唯一性判据)。大小写不敏感文件系统
|
|
112
|
+
// (Windows / 默认 macOS)会把「CH」解析到 .specs/ch、「Archive」解析到归档区,但 activeChange
|
|
113
|
+
// 存的是变体字符串——轮次事件按 activeChange 精确匹配(配额被换键重置)、保留名检查按小写归一,
|
|
114
|
+
// 故 change 名必须等于真实目录名,大小写/空白变体一律拒绝(fail-closed)。
|
|
115
|
+
export async function hasExactSpecsEntry(changeName) {
|
|
116
|
+
let entries = [];
|
|
117
|
+
try {
|
|
118
|
+
entries = await fs.readdir(specsDir());
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return entries.includes(changeName);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 受控重入路径边界(单一 helper:change 名形态 + realpath 直接子目录 + symlink/junction 逃逸)。
|
|
126
|
+
// change 名必须是单段目录名(形态单一权威在 route-node.mjs,与综合判定同源);目录必须真实存在、
|
|
127
|
+
// 非 symlink/junction、realpath 归一后仍在 .specs/ 内、且名字与真实目录条目逐字相等。物理包含性
|
|
128
|
+
// 判定复用 protocol-utils 的路径段扫描(单一权威,不写第二份路径判据);任何越界 / 链接形态 /
|
|
129
|
+
// 名字变体一律 BLOCK(fail-closed)。
|
|
130
|
+
export async function inspectReentryChangeDir(changeName) {
|
|
131
|
+
if (typeof changeName !== 'string' || changeName.trim() === '') {
|
|
132
|
+
return { ok: false, reason: 'no-active-change' };
|
|
133
|
+
}
|
|
134
|
+
if (!isSingleSegmentChangeName(changeName)) {
|
|
135
|
+
return { ok: false, reason: 'change-name-invalid' };
|
|
136
|
+
}
|
|
137
|
+
const changeDir = path.join(specsDir(), changeName);
|
|
138
|
+
let inspection;
|
|
139
|
+
try {
|
|
140
|
+
inspection = await inspectWorkflowPathSegments(specsDir(), changeDir, 'reenter change dir', 'directory');
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return { ok: false, reason: 'change-dir-escape', detail: error && error.message ? error.message : String(error) };
|
|
143
|
+
}
|
|
144
|
+
if (!inspection.exists) return { ok: false, reason: 'change-dir-missing' };
|
|
145
|
+
if (!(await hasExactSpecsEntry(changeName))) return { ok: false, reason: 'change-name-invalid' };
|
|
146
|
+
return { ok: true, changeDir };
|
|
147
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// skill-load 声明标记族(单一归属):--prompt 参数提取与归属校验、协议 scope 绑定查询、
|
|
2
|
+
// 标记目录解析、节点声明存在性,以及 completedChecks 的真实性校验。
|
|
3
|
+
// 诚实边界:标记是「声明」而非物理证明——运行时没有 Skill 调用观察点,脚本无法确认执行者
|
|
4
|
+
// 真实加载过该 skill;标记仅证明「执行者主动声明已加载」,由流程纪律兜底。handoff 条目的证据
|
|
5
|
+
// 同样不是物理证明——它是子代理回传的 Return Contract 委托声明(子代理自称已加载并执行),
|
|
6
|
+
// 由 handoff result 的 commitHash/greenEvidence 审计性兜底。
|
|
7
|
+
import { promises as fs } from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { fileExists, readJson, specsDir } from './state-io.mjs';
|
|
10
|
+
|
|
11
|
+
// --prompt 原始参数提取(skill-load 专用参数):--protocol 由 resolveProtocol 全局解析
|
|
12
|
+
// (CLI > env > 默认)为工作流协议 JSON——skill-load 曾用 --protocol 传 prompt 路径,主仓真实链路
|
|
13
|
+
// 必现撞车(markdown 被当协议 JSON 解析 → 启动报错「workflow protocol file is not valid JSON」)。
|
|
14
|
+
// 改名 --prompt 后与全局协议解析彻底解耦;此处仅取用户显式传入的原始值,供 skill-load
|
|
15
|
+
// 的 flow-kit/prompts/ 归属校验与标记记录。
|
|
16
|
+
export function findPromptArg(cliArgs) {
|
|
17
|
+
for (let index = 0; index < cliArgs.length; index++) {
|
|
18
|
+
const arg = cliArgs[index];
|
|
19
|
+
if (arg === '--prompt') {
|
|
20
|
+
const value = cliArgs[index + 1];
|
|
21
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (typeof arg === 'string' && arg.startsWith('--prompt=')) {
|
|
25
|
+
const value = arg.slice('--prompt='.length);
|
|
26
|
+
return value === '' ? null : value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// flow-kit/prompts/ 归属校验(相对或绝对路径,前缀校验)——flow-kit 为 vendored 上游,
|
|
33
|
+
// 协议提示只读引用;skill-load 声明的 --prompt 必须位于其 prompts 目录下。
|
|
34
|
+
// 相对路径:字符串前缀必须为 flow-kit/prompts/;绝对路径:路径段中必须含 flow-kit/prompts。
|
|
35
|
+
export function protocolUnderFlowKitPrompts(value) {
|
|
36
|
+
const normalized = String(value).replaceAll('\\', '/');
|
|
37
|
+
if (!path.isAbsolute(value)) {
|
|
38
|
+
return normalized.startsWith('flow-kit/prompts/');
|
|
39
|
+
}
|
|
40
|
+
const segments = normalized.split('/').filter((s) => s !== '');
|
|
41
|
+
for (let index = 0; index <= segments.length - 2; index++) {
|
|
42
|
+
if (segments[index] === 'flow-kit' && segments[index + 1] === 'prompts') return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// requiredSkillCalls scope 分类——按协议 requiredSkillCalls 查 <node>.<skill> 绑定:
|
|
48
|
+
// main scope = 协调者加载(如 flow-comet-subagent-execute),要求协调者 skill-load 标记;
|
|
49
|
+
// handoff scope = 子代理加载(如 subagent-execute 节点的 flow-comet-dev),协调者不加载它。
|
|
50
|
+
// 协议外条目(无绑定 / 非 main / 非 handoff scope)→ null(fail-closed:仍按 main 处理要标记)。
|
|
51
|
+
export function findRequiredSkillBinding(protocol, nodeId, skillName) {
|
|
52
|
+
const node = (protocol.nodes ?? []).find((n) => n.id === nodeId);
|
|
53
|
+
if (!node) return null;
|
|
54
|
+
return (node.requiredSkillCalls ?? []).find((binding) => binding.skill === skillName) ?? null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 标记目录解析——活动路径 .specs/<change-id>/.skill-loads/ 优先;归档路径兜底
|
|
58
|
+
// (archive 节点「先移目录后 record/exit」顺序下 change 目录已在 .specs/archive/<前缀>-<change-id>/,
|
|
59
|
+
// 标记只随目录移动——只查活动路径会误报缺失)。归档扫描匹配后缀 -<change-id>(前缀可含日期等,
|
|
60
|
+
// 与协议 flowkit.archive.v1 的 archive/*-<change-id> artifact 路径同构)。两者皆无 → null。
|
|
61
|
+
export async function findSkillLoadsDir(changeName) {
|
|
62
|
+
const activeDir = path.join(specsDir(), changeName, '.skill-loads');
|
|
63
|
+
if (await fileExists(activeDir)) {
|
|
64
|
+
return { dir: activeDir, display: '.specs/' + changeName + '/.skill-loads/' };
|
|
65
|
+
}
|
|
66
|
+
const archiveRoot = path.join(specsDir(), 'archive');
|
|
67
|
+
const entries = await fs.readdir(archiveRoot).catch(() => []);
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (!entry.endsWith('-' + changeName)) continue;
|
|
70
|
+
const candidate = path.join(archiveRoot, entry, '.skill-loads');
|
|
71
|
+
if (await fileExists(candidate)) {
|
|
72
|
+
return { dir: candidate, display: '.specs/archive/' + entry + '/.skill-loads/' };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 节点技能加载声明标记存在性(技能加载前置门·方案 A):校验 .skill-loads/ 下
|
|
79
|
+
// 是否有该节点的声明标记 <node>-*.json(任一 skill 标记即算已声明——与 guard exit 侧的
|
|
80
|
+
// 「exit 协议声明标记校验」同构:按 <node>- 前缀扫描;活动路径优先,归档路径兜底)。
|
|
81
|
+
// 记录/委托前置门在「先加载技能(Skill 工具)并 skill-load 声明」之前拦截"先干活后补声明"。
|
|
82
|
+
export async function hasNodeSkillDeclaration(nodeId, changeName) {
|
|
83
|
+
if (!nodeId || !changeName) return false;
|
|
84
|
+
const activeDir = path.join(specsDir(), changeName, '.skill-loads');
|
|
85
|
+
const prefix = nodeId + '-';
|
|
86
|
+
const scan = async (dir) => {
|
|
87
|
+
try {
|
|
88
|
+
const entries = await fs.readdir(dir);
|
|
89
|
+
return entries.some((f) => f.startsWith(prefix) && f.endsWith('.json'));
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (await scan(activeDir)) return true;
|
|
95
|
+
const archived = await findSkillLoadsDir(changeName);
|
|
96
|
+
if (archived !== null && archived.dir !== activeDir) return scan(archived.dir);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// completedChecks 真实性校验。解析 completedChecks 的 required-skill:<node>.<skill>
|
|
101
|
+
// 条目 → 对应声明标记 .specs/<change-id>/.skill-loads/<node>-<skill>.json 必须存在(缺失 →
|
|
102
|
+
// BLOCKED + 指引先加载 skill 并运行 skill-load);标记 at 必须 ≤ 本次记录时间(交叉自洽:
|
|
103
|
+
// 标记先于记录声明;ISO-8601 UTC 字符串字典序 = 时间序)。仅校验本次 record 写入的
|
|
104
|
+
// completedChecks(旧 change 兼容:旧 evidence 不追溯——由调用方只传本次 parsed.completedChecks)。
|
|
105
|
+
// 条目按协议 requiredSkillCalls scope 分类——handoff scope 条目(子代理加载的 skill,
|
|
106
|
+
// 如 subagent-execute 节点的 flow-comet-dev)豁免标记,以共用证据库 evidence['subagent-execute']
|
|
107
|
+
// 的 handoffResult(有委托记录即满足)为证据;main scope / 协议外条目仍要求标记(fail-closed)。
|
|
108
|
+
// 返回 { ok: true } 或 { ok: false, reason }(fail-closed:无 active change / 标记损坏同样 BLOCK)。
|
|
109
|
+
export async function verifySkillLoadMarkers(completedChecks, changeName, recordTime, protocol, state) {
|
|
110
|
+
if (!Array.isArray(completedChecks)) return { ok: true };
|
|
111
|
+
const required = [];
|
|
112
|
+
for (const check of completedChecks) {
|
|
113
|
+
if (typeof check !== 'string' || !check.startsWith('required-skill:')) continue;
|
|
114
|
+
const spec = check.slice('required-skill:'.length);
|
|
115
|
+
const dot = spec.lastIndexOf('.');
|
|
116
|
+
if (dot <= 0 || dot === spec.length - 1) {
|
|
117
|
+
return { ok: false, reason: 'completedChecks 条目格式非法(应为 required-skill:<node>.<skill>): ' + check };
|
|
118
|
+
}
|
|
119
|
+
required.push({ raw: check, node: spec.slice(0, dot), skill: spec.slice(dot + 1) });
|
|
120
|
+
}
|
|
121
|
+
if (required.length === 0) return { ok: true };
|
|
122
|
+
if (!changeName) {
|
|
123
|
+
return { ok: false, reason: 'completedChecks 含 required-skill 条目但无 active change——无法定位声明标记(先运行 init <change-id>)' };
|
|
124
|
+
}
|
|
125
|
+
for (const item of required) {
|
|
126
|
+
// handoff scope 条目豁免标记——子代理加载的 skill(协调者不加载它,无法诚实
|
|
127
|
+
// 声明加载),以共用证据库 handoffResult 的委托记录为证据;无委托记录 → BLOCK(不静默
|
|
128
|
+
// 放行,指引先委托并回传 handoff result)
|
|
129
|
+
const binding = findRequiredSkillBinding(protocol, item.node, item.skill);
|
|
130
|
+
if (binding && binding.scope === 'handoff') {
|
|
131
|
+
const handoff = state?.evidence?.['subagent-execute']?.handoffResult;
|
|
132
|
+
const hasDelegation = !!(
|
|
133
|
+
handoff &&
|
|
134
|
+
typeof handoff === 'object' &&
|
|
135
|
+
!Array.isArray(handoff) &&
|
|
136
|
+
Object.keys(handoff).length > 0
|
|
137
|
+
);
|
|
138
|
+
if (!hasDelegation) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
reason: 'completedChecks 条目 ' + item.raw + ' 为 handoff scope(' + item.node +
|
|
142
|
+
' 节点的 ' + item.skill + ' 由子代理加载,协调者无需 skill-load 标记)但共用证据库' +
|
|
143
|
+
' evidence[subagent-execute].handoffResult 无委托记录——先委托子代理并回传 Return Contract(workflow-handoff.mjs result <task-id> <contract>)',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// 标记路径解析——活动路径优先,归档路径兜底(archive 节点「先移目录后 record」
|
|
149
|
+
// 顺序下标记只在 .specs/archive/*-<change-id>/.skill-loads/);两处都找不到 → BLOCK + 指引
|
|
150
|
+
// (不静默放行)。展示路径补 .specs/ 前缀便于用户定位。
|
|
151
|
+
const markerName = item.node + '-' + item.skill + '.json';
|
|
152
|
+
const activeDisplay = '.specs/' + path.posix.join(changeName, '.skill-loads', markerName);
|
|
153
|
+
const activePath = path.join(specsDir(), changeName, '.skill-loads', markerName);
|
|
154
|
+
let markerPath = await fileExists(activePath) ? activePath : null;
|
|
155
|
+
let markerDisplay = activeDisplay;
|
|
156
|
+
if (!markerPath) {
|
|
157
|
+
const loadsDir = await findSkillLoadsDir(changeName);
|
|
158
|
+
if (loadsDir !== null) {
|
|
159
|
+
const altPath = path.join(loadsDir.dir, markerName);
|
|
160
|
+
if (await fileExists(altPath)) {
|
|
161
|
+
markerPath = altPath;
|
|
162
|
+
markerDisplay = loadsDir.display + markerName;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!markerPath) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
reason: 'completedChecks 条目 ' + item.raw + ' 缺少对应声明标记 ' + activeDisplay +
|
|
170
|
+
'(归档路径也未找到)——先加载该 skill 并运行 workflow-state.mjs skill-load ' + item.node + ' ' + item.skill,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
let marker;
|
|
174
|
+
try {
|
|
175
|
+
marker = await readJson(markerPath);
|
|
176
|
+
} catch {
|
|
177
|
+
return { ok: false, reason: '声明标记损坏(非法 JSON,需重新运行 skill-load): ' + markerDisplay };
|
|
178
|
+
}
|
|
179
|
+
// 交叉自洽——标记 at 必须 ≤ 本次记录时间(标记先于记录声明)
|
|
180
|
+
if (typeof marker.at !== 'string' || marker.at > recordTime) {
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
reason: '声明标记时间序非法(标记 at=' + JSON.stringify(marker.at) + ' 不早于本次记录时间 ' + recordTime +
|
|
184
|
+
')——标记必须先于记录声明(重新运行 skill-load)',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return { ok: true };
|
|
189
|
+
}
|