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,471 @@
|
|
|
1
|
+
// task-graph.mjs — 任务与协议图的底层共享判定(单一权威实现)
|
|
2
|
+
// 承载:① 协议节点顺序 / 启用 / 任务文件路径(route · protocolNodeEnabled · protocolTaskFilePath ·
|
|
3
|
+
// EXECUTE_FAMILY_NODE_IDS);② 任务依赖解析与依赖图(taskDependencyEligibility · analyzeDependencyGraph);
|
|
4
|
+
// ③ 并行写冲突检测三族(findParallelWriteConflicts 及其构件);④ 任务集签名与版本语义 ·
|
|
5
|
+
// history 事件归属 · change 名形态 · 修复任务族文本谓词;⑤ 任务块 7 字段集合(TASK7_REQUIRED)。
|
|
6
|
+
// 纯判定:只读 TASK.md 文本、协议对象与 state.history,无 console 输出、无 process.exit、无 state 写入。
|
|
7
|
+
// 依赖方向:本模块不 import 其他 lib 模块(lib 层最底层)——入口与兄弟模块单向依赖本模块。
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { createHash } from 'crypto';
|
|
11
|
+
import { taskBlocks, taskOpeningAttrs } from '../task-parsing.mjs';
|
|
12
|
+
|
|
13
|
+
// 任务块 7 字段集合(单一权威):plan 出口的 TASK 完整性门禁与执行期 `replan` 的重签判据共用本常量。
|
|
14
|
+
// `replan` 是执行期唯一允许修订任务集的通道,两侧判据必须同源——任何一侧另写一份字面集合,都会在
|
|
15
|
+
// 规则演进时静默分叉(plan 出口会拒的任务集被 `replan` 放行)。消费方一律 import 取用。
|
|
16
|
+
export const TASK7_REQUIRED = ['name', 'read_files', 'write_files', 'action', 'verify', 'done', 'depends_on'];
|
|
17
|
+
|
|
18
|
+
// 节点顺序 = 协议 nodes 顺序(disabled 过滤)。全部节点排序判定共用本实现(单一来源)。
|
|
19
|
+
export function route(protocol) {
|
|
20
|
+
return (protocol.nodes ?? []).filter((n) => !n.disabled);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 协议节点是否 enabled:route 顺序中存在且未 disabled。协议 enabled 语义以本函数为唯一来源,
|
|
24
|
+
// 路由、请求归属门禁、受控重入与受控重校一律复用,不各自过滤。
|
|
25
|
+
export function protocolNodeEnabled(protocol, nodeId) {
|
|
26
|
+
return route(protocol).some((node) => node.id === nodeId);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// execute 家族节点:协议 route 顺序中由任务状态特判的节点。多消费方(路由镜像 / 签名闭合 /
|
|
30
|
+
// Fix 回因与轮次)共用本常量,禁止任一消费方内联家族成员对。
|
|
31
|
+
export const EXECUTE_FAMILY_NODE_IDS = new Set(['execute', 'subagent-execute']);
|
|
32
|
+
|
|
33
|
+
// 协议任务文件路径:协议可选 taskFile 字段(相对 .specs/<change-id>/),无声明时缺省 TASK.md。
|
|
34
|
+
// 路由、Fix 回溯与受控重入共用同一解析(防两处漂移)。
|
|
35
|
+
export function protocolTaskFilePath(protocol, changeName, specsRoot) {
|
|
36
|
+
const taskFile = typeof protocol.taskFile === 'string' && protocol.taskFile !== ''
|
|
37
|
+
? protocol.taskFile
|
|
38
|
+
: 'TASK.md';
|
|
39
|
+
return path.join(specsRoot, changeName, taskFile);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 依赖资格:解析任务块的 <depends_on> 并与已完成任务 id 集合比较。依赖文本解析只此一处,
|
|
43
|
+
// 路由的可委托并行过滤、依赖图分析与并行写冲突检测一律调用本函数。返回 { eligible, deps, unmet };
|
|
44
|
+
// 无 <depends_on> 元素或内容为空视为无依赖(eligible=true)。
|
|
45
|
+
export function taskDependencyEligibility(block, doneIds = new Set()) {
|
|
46
|
+
const depsMatch = String(block ?? '').match(/<depends_on>([\s\S]*?)<\/depends_on>/);
|
|
47
|
+
if (!depsMatch || !depsMatch[1].trim()) return { eligible: true, deps: [], unmet: [] };
|
|
48
|
+
const deps = depsMatch[1].trim().split(/[,\s]+/).filter(Boolean);
|
|
49
|
+
const unmet = deps.filter((dep) => !doneIds.has(dep));
|
|
50
|
+
return { eligible: unmet.length === 0, deps, unmet };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 正则元字符转义(glob 形态共用):路径重叠判定与产物 glob 存在检查共用本实现。
|
|
54
|
+
export function escapeRegExp(value) {
|
|
55
|
+
return String(value).replace(/[|\\{}()[\]^$+?.]/gu, '\\$&');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---------- 任务集签名(算法版本 + 内容 digest · 单一实现) ----------
|
|
59
|
+
// 算法版本元数据:值格式 <算法版本>:<digest>(如 v1:<sha256 hex>)。签名算法实现变更时必须同步
|
|
60
|
+
// 提升版本常量——冻结锚据此判别;state 的 taskHash 与 exit-applied 事件的 taskSetSignature 都写
|
|
61
|
+
// 版本前缀,事件另带 signatureAlgo 字段;legacy 裸 hex 一律按 v1 解析;消费点只做同版本比较,
|
|
62
|
+
// 版本不同视为不可比(不判发散、不误归位、不误拦任务集)。
|
|
63
|
+
export const TASK_SET_SIGNATURE_ALGO = 'v1';
|
|
64
|
+
const TASK_SET_SIGNATURE_PREFIX = /^(v\d+):([0-9a-f]{64})$/u;
|
|
65
|
+
const TASK_SET_SIGNATURE_BARE_HEX = /^[0-9a-f]{64}$/u;
|
|
66
|
+
const LEGACY_TASK_SET_SIGNATURE_ALGO = 'v1';
|
|
67
|
+
|
|
68
|
+
// 内容 digest:提取全部 <task> 块,剥离开标签上的标记类属性(只保留影响路由语义的 id/parallel),
|
|
69
|
+
// 排序防顺序漂移,拼接后 sha256。行尾归一——跨工具编辑(heredoc 写 LF、其它工具写 CRLF)会让
|
|
70
|
+
// 「任务集逻辑未变但字节变」误报 BLOCK,故签名前统一 CRLF → LF(只归一化行尾,不改内容语义)。
|
|
71
|
+
// 标记类属性白名单——任务标记 done 会在开标签追加 completed_at / assigned_to 等纯状态属性,
|
|
72
|
+
// 只剥离 status 仍会误报;改为白名单保留 id/parallel(含未来新增标记属性,无需再改);
|
|
73
|
+
// 任务内容(name / action / write_files / verify / depends_on)保持签名敏感。
|
|
74
|
+
function digestTaskSetContent(taskContent) {
|
|
75
|
+
const normalized = String(taskContent).replace(/\r\n/g, '\n');
|
|
76
|
+
const blocks = (normalized.match(/<task[\s\S]*?<\/task>/g) || [])
|
|
77
|
+
.map((block) =>
|
|
78
|
+
block.replace(/<task[^>]*>/, (open) =>
|
|
79
|
+
open.replace(/\s+[a-zA-Z_][\w-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'))?/g, (attr) =>
|
|
80
|
+
/^\s*(?:id|parallel)(?=[\s=>])/.test(attr) ? attr : ''
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
.sort();
|
|
85
|
+
return createHash('sha256').update(blocks.join('\n'), 'utf8').digest('hex');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 计算签名:返回 <算法版本>:<digest>;algo 缺省为当前版本(供跨版本夹具显式传入旧版本)。
|
|
89
|
+
export function taskSetSignature(taskContent, algo = TASK_SET_SIGNATURE_ALGO) {
|
|
90
|
+
const version = String(algo ?? '').trim() || TASK_SET_SIGNATURE_ALGO;
|
|
91
|
+
return version + ':' + digestTaskSetContent(taskContent);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 解析签名值:新格式 <vN>:<64 hex>;legacy 裸 64 hex 按 v1;空值 / 非字符串 / 其它形态 → null。
|
|
95
|
+
export function parseTaskSetSignature(value) {
|
|
96
|
+
if (typeof value !== 'string' || value === '') return null;
|
|
97
|
+
const prefixed = TASK_SET_SIGNATURE_PREFIX.exec(value);
|
|
98
|
+
if (prefixed) return { algo: prefixed[1], digest: prefixed[2] };
|
|
99
|
+
if (TASK_SET_SIGNATURE_BARE_HEX.test(value)) {
|
|
100
|
+
return { algo: LEGACY_TASK_SET_SIGNATURE_ALGO, digest: value };
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 同版本且同 digest = 一致;任一不可解析 / 版本不同 = false(调用方必须按不可比语义处理)。
|
|
106
|
+
export function sameTaskSetSignature(left, right) {
|
|
107
|
+
const a = parseTaskSetSignature(left);
|
|
108
|
+
const b = parseTaskSetSignature(right);
|
|
109
|
+
if (a === null || b === null) return false;
|
|
110
|
+
return a.algo === b.algo && a.digest === b.digest;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 两侧均可解析但算法版本不同 → true(需要「跳过比对」而非「判为发散」的消费点使用)。
|
|
114
|
+
export function taskSetSignatureVersionSkew(left, right) {
|
|
115
|
+
const a = parseTaskSetSignature(left);
|
|
116
|
+
const b = parseTaskSetSignature(right);
|
|
117
|
+
return a !== null && b !== null && a.algo !== b.algo;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// history 事件 change 归属(单一权威):state.history 跨 change 保留(select 只切 activeChange),
|
|
121
|
+
// 带 change 字段的事件只在 change 名一致时参与;无 change 字段的旧 state 事件保持兼容(legacy 参与)。
|
|
122
|
+
// execute 家族出口签名读取 / Fix 回因分类 / 受控重入与重校轮次一律调用本函数,禁止再内联同一过滤判据
|
|
123
|
+
// ——注释互指同源不是同步机制。
|
|
124
|
+
export function historyEventBelongsToChange(event, changeName) {
|
|
125
|
+
return typeof event?.change !== 'string' || event.change === changeName;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// change 名形态(单一权威 · 受控重入 / 受控重校判定与 select 入口共用):change-id 必须是 .specs/
|
|
129
|
+
// 下的单段目录名——拒绝空串、路径分隔符与「.」「..」,并保留目录名 archive(归档区)不得作为
|
|
130
|
+
// change 名。本判据只做字符串形态判定(纯函数);「realpath 归一后仍是 .specs 真实直接子目录」
|
|
131
|
+
// 的物理包含性由调用方的路径段扫描(protocol-utils 单一权威)负责。
|
|
132
|
+
export function isSingleSegmentChangeName(value) {
|
|
133
|
+
if (typeof value !== 'string') return false;
|
|
134
|
+
const name = value.trim();
|
|
135
|
+
if (name === '' || name === '.' || name === '..') return false;
|
|
136
|
+
// 原始值必须与 trim 后逐字相等:Windows 与部分文件系统忽略首尾空白 / 尾点,放行「空白变体」
|
|
137
|
+
// 会让 path.join 指到真实目录、而 activeChange 存的是变体字符串——轮次事件按 activeChange
|
|
138
|
+
// 精确匹配(配额被换键重置),事件归属随即失真。
|
|
139
|
+
if (value !== name) return false;
|
|
140
|
+
if (name.includes('/') || name.includes('\\')) return false;
|
|
141
|
+
// 保留目录名按大小写归一判定:Windows 与默认 macOS 的路径解析不区分大小写,「ARCHIVE」
|
|
142
|
+
// 「Archive」同样指向归档区,逐字比较会漏判。
|
|
143
|
+
if (name.toLowerCase() === 'archive') return false;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ---------- 修复任务族文本谓词(单一权威 · 供并行写冲突第三族与回因分类共用) ----------
|
|
148
|
+
export const FIX_SECTION_TITLE_FALLBACK = 'Fix 任务';
|
|
149
|
+
|
|
150
|
+
// 共享 heading 归一(单一权威):去 ATX 标记 / 闭合 ATX 标记 / 尾部括号内容 / 编号前缀后比较,
|
|
151
|
+
// 让「Fix 任务」「Fix 任务(来自 REVIEW / INTEGRATION)」「## Fix 任务 ##」等合法写法命中同一段;
|
|
152
|
+
// 修复段标题匹配与调用方的模板段名归一均委托本实现,禁止另起第二份。
|
|
153
|
+
export function normalizeHeading(raw) {
|
|
154
|
+
return String(raw ?? '')
|
|
155
|
+
.replace(/\r/g, '')
|
|
156
|
+
.replace(/^#{1,6}\s*/, '')
|
|
157
|
+
.replace(/\s+#+\s*$/, '')
|
|
158
|
+
.replace(/[((][^))\n]*[))]\s*$/u, '')
|
|
159
|
+
.replace(/^\d+(?:\.\d+)?\.?\s*/u, '')
|
|
160
|
+
.trim()
|
|
161
|
+
.toLowerCase();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 修复段正文切片:首个同级(##)标题命中 → 返回标题行之后、下一个同级标题(或 EOF)之前的正文;
|
|
165
|
+
// 无命中标题 → null。只认二级标题(### 不闭合本段);CRLF / LF 归一后按行定位。
|
|
166
|
+
function fixSectionBody(taskContent, fixSectionTitle) {
|
|
167
|
+
const lines = String(taskContent ?? '').replace(/\r\n?/g, '\n').split('\n');
|
|
168
|
+
const wanted = normalizeHeading(fixSectionTitle);
|
|
169
|
+
if (wanted === '') return null;
|
|
170
|
+
let start = -1;
|
|
171
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
172
|
+
const m = lines[i].match(/^##\s+(.+?)\s*$/);
|
|
173
|
+
if (!m) continue;
|
|
174
|
+
const heading = normalizeHeading(m[1]);
|
|
175
|
+
if (heading === wanted || heading.startsWith(wanted)) { start = i; break; }
|
|
176
|
+
}
|
|
177
|
+
if (start < 0) return null;
|
|
178
|
+
let end = lines.length;
|
|
179
|
+
for (let i = start + 1; i < lines.length; i += 1) {
|
|
180
|
+
if (/^##\s/.test(lines[i])) { end = i; break; }
|
|
181
|
+
}
|
|
182
|
+
return lines.slice(start + 1, end).join('\n');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 修复任务族 id 前缀(唯一谓词的 id 边界,全模块只此一处定义):含尾连字符——形似编号(前缀
|
|
186
|
+
// 之后缺连字符的形态)不属该族;宽松前缀会把非修复编号整族放过(边界只在这里表达一次)。
|
|
187
|
+
const FIX_TASK_ID_PREFIX = /^[TP]-FIX-/i;
|
|
188
|
+
|
|
189
|
+
// 修复任务族唯一谓词(单一权威):返回 (block) => boolean 的判定函数——命中 id 前缀,或任务块
|
|
190
|
+
// 位于修复段内(段定位复用 fixSectionBody / normalizeHeading 的既有标题语义,标题缺省回退
|
|
191
|
+
// FIX_SECTION_TITLE_FALLBACK)。回因分类的结构标记与并行写冲突第三族的参与者排除一律调用本函数,
|
|
192
|
+
// 禁止任何消费方另起一套边界——id 前缀与「位于修复段内」两条边界只在此处表达一次。
|
|
193
|
+
export function fixTaskClassifier(taskContent, fixSectionTitle) {
|
|
194
|
+
const content = String(taskContent ?? '');
|
|
195
|
+
const title = (typeof fixSectionTitle === 'string' && fixSectionTitle.trim() !== '')
|
|
196
|
+
? fixSectionTitle
|
|
197
|
+
: FIX_SECTION_TITLE_FALLBACK;
|
|
198
|
+
const section = fixSectionBody(content, title);
|
|
199
|
+
const sectionBlocks = new Set(section === null ? [] : taskBlocks(section));
|
|
200
|
+
return (block) => {
|
|
201
|
+
const attrs = taskOpeningAttrs(block);
|
|
202
|
+
if (!attrs || typeof attrs.id !== 'string') return false;
|
|
203
|
+
if (FIX_TASK_ID_PREFIX.test(attrs.id)) return true;
|
|
204
|
+
// 行尾归一(与任务集签名的归一纪律同源):fixSectionBody 产出 LF,而待判 block 来自原文
|
|
205
|
+
// (跨平台编辑可能是 CRLF)。不归一会让「修复段内非前缀 id」任务匹配失败——第三族把它当
|
|
206
|
+
// 普通参与者误拦,且结构标记同时失效。
|
|
207
|
+
return sectionBlocks.has(String(block ?? '').replace(/\r\n/g, '\n'));
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 修复任务结构标记:全文存在修复任务(id 命中修复族前缀——覆盖文件尾追加等非规范落点;或修复段
|
|
212
|
+
// 内出现 <task> 块——标题与任务需同段,段内无任务不误报)→ true;否则 false。判定一律经唯一谓词
|
|
213
|
+
// fixTaskClassifier,本函数只做「是否存在」的聚合,不再自持边界。
|
|
214
|
+
// 解析复用 taskBlocks / taskOpeningAttrs(与路由、门禁共享同一 <task> 解析语义)。
|
|
215
|
+
export function fixTaskMarker(taskContent, fixSectionTitle) {
|
|
216
|
+
const isFixTask = fixTaskClassifier(taskContent, fixSectionTitle);
|
|
217
|
+
return taskBlocks(String(taskContent ?? '')).some((block) => isFixTask(block));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ---------- 任务依赖图分析(单一权威 · plan 出口波次校验 / subagent-execute 出口孤儿检测 / replan 重校共用) ----------
|
|
221
|
+
// 对全部 <task> 块建依赖图(deps 边),Kahn 拓扑排序判环 + 缺失依赖收集。
|
|
222
|
+
// 返回 { ids, depsById, missing: [{id, dep}], cyclic, cycleIds }(cycleIds = 拓扑排序无解的
|
|
223
|
+
// 任务集合,含被环传递拖累的下游任务)。单一语义:依赖图无环 + 依赖链可满足。
|
|
224
|
+
// 依赖文本解析复用本模块 taskDependencyEligibility(依赖解析单一权威——不再另起第二份正则)。
|
|
225
|
+
export function analyzeDependencyGraph(blocks) {
|
|
226
|
+
const parsed = blocks
|
|
227
|
+
.map((block) => ({ block, attrs: taskOpeningAttrs(block) }))
|
|
228
|
+
.filter((x) => x.attrs && x.attrs.id);
|
|
229
|
+
const ids = new Set(parsed.map((x) => x.attrs.id));
|
|
230
|
+
const depsById = new Map();
|
|
231
|
+
const missing = [];
|
|
232
|
+
for (const x of parsed) {
|
|
233
|
+
const deps = [...new Set(taskDependencyEligibility(x.block).deps)];
|
|
234
|
+
depsById.set(x.attrs.id, deps);
|
|
235
|
+
for (const d of deps) {
|
|
236
|
+
if (!ids.has(d)) missing.push({ id: x.attrs.id, dep: d });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const indegree = new Map([...ids].map((id) => [id, 0]));
|
|
240
|
+
const dependents = new Map([...ids].map((id) => [id, []]));
|
|
241
|
+
for (const [id, deps] of depsById) {
|
|
242
|
+
for (const d of deps) {
|
|
243
|
+
if (!ids.has(d)) continue;
|
|
244
|
+
indegree.set(id, indegree.get(id) + 1);
|
|
245
|
+
dependents.get(d).push(id);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
let queue = [...ids].filter((id) => indegree.get(id) === 0);
|
|
249
|
+
const sorted = [];
|
|
250
|
+
while (queue.length > 0) {
|
|
251
|
+
const n = queue.shift();
|
|
252
|
+
sorted.push(n);
|
|
253
|
+
for (const m of dependents.get(n)) {
|
|
254
|
+
indegree.set(m, indegree.get(m) - 1);
|
|
255
|
+
if (indegree.get(m) === 0) queue.push(m);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const cyclic = sorted.length < ids.size;
|
|
259
|
+
const cycleIds = cyclic ? [...ids].filter((id) => !sorted.includes(id)) : [];
|
|
260
|
+
return { ids, depsById, missing, cyclic, cycleIds };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ---------- 并行文件依赖检测(单源:plan 出口门禁与 replan 重校共用) ----------
|
|
264
|
+
// 解析 TASK.md 的任务 read/write_files 声明,分三族返回:
|
|
265
|
+
// ① writeConflicts(写写强判):本趟可运行的 parallel=pending 任务间 write∩write 非空——同波次
|
|
266
|
+
// 并行写同一路径必竞态覆盖;
|
|
267
|
+
// ② readWarnings(读写弱判):并行对一方读取对方写路径——仅对彼此无显式 depends_on 关联的并行对
|
|
268
|
+
// 探测,有显式关联=依赖已声明,跳过→合法拓扑零新增告警;
|
|
269
|
+
// ③ crossTaskConflicts(同文件跨任务且无依赖路径):两个未完成任务(status 非 done)写入面重叠
|
|
270
|
+
// 且两任务间不存在依赖路径(depends_on 传递闭包,双向任一可达即视为已显式排序 → 放行)——
|
|
271
|
+
// 串行拆分出的同文件任务同样命中(未显式排序的同文件多任务);修复任务族不参与本族(族谓词
|
|
272
|
+
// 复用唯一权威 fixTaskClassifier)——其顺序由修复生命周期保证,回修同一文件是必然形态;
|
|
273
|
+
// 与①按任务对去重(同一对已计入写写强判则不再计入本族)。
|
|
274
|
+
// 编排与判定分离:族③计算抽为具名纯函数 collectCrossTaskConflicts(只做集合推导,无 fs / console /
|
|
275
|
+
// process.exit / 入参改写),findParallelWriteConflicts 只负责读文件、解析、族①②与去重键的组织。
|
|
276
|
+
// 路径解析 / 归一(parsePaths / normalizeTaskPath)为单份实现,族①②③共用;依赖文本解析复用
|
|
277
|
+
// taskDependencyEligibility(单一权威)。路径**重叠判定**(含 glob 语义)同样是单份实现:具名纯函数
|
|
278
|
+
// collectPathOverlaps,族①②③一律经它比较——任一族内联第二份比较逻辑即违规(同一判据两份实现必然分叉)。
|
|
279
|
+
// 开标签属性解析与路由共享 taskOpeningAttrs(属性序无关;不读块内文本)。
|
|
280
|
+
|
|
281
|
+
// 任务对键(无序——不依赖任务书写顺序;NUL 分隔,任务 id 不含 NUL):同文件跨任务族与写写强判族
|
|
282
|
+
// 按任务对去重时使用(同一对已计入写写强判则不再计入第三族)。
|
|
283
|
+
function taskPairKey(a, b) {
|
|
284
|
+
return a < b ? a + '\u0000' + b : b + '\u0000' + a;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 依赖可达集(depends_on 传递闭包):从 start 沿依赖边可达的全部任务 id(含经由其它任务中转的
|
|
288
|
+
// 路径)。判定语义 = 双向任一可达即视为两任务已显式排序 → 第三族放行(见上方族说明)。
|
|
289
|
+
function reachableTaskIds(depsById, start) {
|
|
290
|
+
const seen = new Set();
|
|
291
|
+
const stack = [...(depsById.get(start) ?? [])];
|
|
292
|
+
while (stack.length > 0) {
|
|
293
|
+
const cur = stack.pop();
|
|
294
|
+
if (seen.has(cur)) continue;
|
|
295
|
+
seen.add(cur);
|
|
296
|
+
for (const next of depsById.get(cur) ?? []) stack.push(next);
|
|
297
|
+
}
|
|
298
|
+
return seen;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 路径归一化:分隔符统一 '/'、解 '.' 段(`./` / `a/./b`)、`..` 逃出项目根按越界处理(返回 null
|
|
302
|
+
// 不参与重叠比较)——`src/a.mjs` vs `src/./a.mjs` / `src\a.mjs` 变体不再绕过写写强判与读写弱判;
|
|
303
|
+
// 与委托入口共用同一函数(两侧同语义)。族①②③共用本实现。
|
|
304
|
+
function normalizeTaskPath(raw) {
|
|
305
|
+
const p = String(raw).trim();
|
|
306
|
+
if (p === '') return null;
|
|
307
|
+
const segments = p.replace(/\\/g, '/').split('/').filter((s) => s !== '' && s !== '.');
|
|
308
|
+
const out = [];
|
|
309
|
+
for (const seg of segments) {
|
|
310
|
+
if (seg === '..') {
|
|
311
|
+
if (out.length === 0) return null; // 逃出项目根 → 越界(不参与比较)
|
|
312
|
+
out.pop();
|
|
313
|
+
} else {
|
|
314
|
+
out.push(seg);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return out.join('/');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 路径解析与既有自动解析同源:剥 HTML 注释 → 换行切分 → 分号二次切分 → trim → 滤空 → 归一。
|
|
321
|
+
// 按声明实际内容解析,不做扩展名白名单过滤——txt/log/无扩展名路径同等检出(链式重命名的 .txt
|
|
322
|
+
// 事故面闭合)。族①②③共用本实现,不另起第二份。
|
|
323
|
+
function parsePaths(matchText) {
|
|
324
|
+
return String(matchText ?? '')
|
|
325
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
326
|
+
.trim().split(/\s*\n\s*/).map((l) => l.trim()).filter(Boolean)
|
|
327
|
+
.flatMap((l) => l.split(';')).map((l) => l.trim()).filter(Boolean)
|
|
328
|
+
.map(normalizeTaskPath)
|
|
329
|
+
.filter((p) => p !== null && p !== '');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// 元字符判定:glob 魔法 = `*` / `?` / `[` 三类——与委托侧的字面路径资格判定
|
|
333
|
+
// (literalRelativePosixPath 的 /[*?[]/)同口径;「什么算 glob」不另立第三套定义。
|
|
334
|
+
const GLOB_MAGIC_CHAR = /[*?[]/;
|
|
335
|
+
|
|
336
|
+
// 路径重叠判定(族①②③共用的唯一具名纯函数):入参为两组**已归一**路径声明(normalizeTaskPath
|
|
337
|
+
// 产物,分隔符统一 `/`),返回重叠描述串数组(直接进冲突消息的 files 字段)或空数组(不重叠);
|
|
338
|
+
// 无 fs / console / process.exit,不改任何入参。
|
|
339
|
+
// 三形态:
|
|
340
|
+
// ① 两侧均无元字符 ⇒ 既有字面相等语义(逐字等价:相等报该路径本身——消费方消息零变化);
|
|
341
|
+
// ② 单侧含元字符 ⇒ 用该侧模式匹配另一侧字面路径:**段数必须相等**(`*` 不跨 `/`,`**` 亦非递归)、
|
|
342
|
+
// 段内 `*` 匹配段内任意字符(`[^/]*`)、其余字符字面锚定(正则元字符转义);段内无 `*` 即不命中;
|
|
343
|
+
// ③ 双侧均含 glob ⇒ **保守视为重叠**(宁可误拦不可漏检——漏检正是本判据要修的缺陷);无共同字面
|
|
344
|
+
// 路径可报,故报两侧声明。
|
|
345
|
+
// ②的语义**对齐基准** = workflow-handoff.mjs 的 matchWriteFilePattern:该函数未导出、所在模块
|
|
346
|
+
// 又是 CLI 顶层脚本(import 即执行 main),物理不可复用;故本模块按同一形态实现并在此锚定基准
|
|
347
|
+
// 位置——基准若变,此处必须同步(漂移可见;不互指「同源」了事)。零第三方 glob 库(ADR-007):
|
|
348
|
+
// 复用本模块既有 escapeRegExp(转义集与基准内联转义一致)。
|
|
349
|
+
export function collectPathOverlaps(leftPaths, rightPaths) {
|
|
350
|
+
const overlaps = [];
|
|
351
|
+
for (const left of leftPaths) {
|
|
352
|
+
for (const right of rightPaths) {
|
|
353
|
+
if (left === right) { overlaps.push(left); continue; } // ① 逐字相等(含两侧同 glob)
|
|
354
|
+
const leftGlob = GLOB_MAGIC_CHAR.test(left);
|
|
355
|
+
const rightGlob = GLOB_MAGIC_CHAR.test(right);
|
|
356
|
+
if (!leftGlob && !rightGlob) continue; // ① 两侧字面且不等 ⇒ 不重叠
|
|
357
|
+
if (leftGlob && rightGlob) { // ③ 双侧 glob:保守判重叠
|
|
358
|
+
overlaps.push(left + ' ∩ ' + right);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const patternSegments = (leftGlob ? left : right).split('/'); // ② 单侧 glob:模式 × 字面
|
|
362
|
+
const literalSegments = (leftGlob ? right : left).split('/');
|
|
363
|
+
if (patternSegments.length !== literalSegments.length) continue;
|
|
364
|
+
const matched = patternSegments.every((seg, index) => {
|
|
365
|
+
if (seg === literalSegments[index]) return true;
|
|
366
|
+
if (!seg.includes('*')) return false;
|
|
367
|
+
return new RegExp('^' + seg.split('*').map(escapeRegExp).join('[^/]*') + '$')
|
|
368
|
+
.test(literalSegments[index]);
|
|
369
|
+
});
|
|
370
|
+
if (matched) overlaps.push(left + ' ∩ ' + right);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return overlaps;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 第三族(同文件跨任务且无依赖路径)计算——本模块具名纯函数:输入任务块 / 依赖图 / 既有族去重键,
|
|
377
|
+
// 输出冲突对数组({ a, b, files });无 fs / console / process.exit,不改任何入参。
|
|
378
|
+
// taskContent 与 allBlocks 须同源(taskContent = 产出 allBlocks 的 TASK.md 文本)——修复任务族
|
|
379
|
+
// 谓词需要全文以定位修复段(段标题取该谓词的缺省回退常量,与 fixTaskClassifier 的缺省一致)。
|
|
380
|
+
export function collectCrossTaskConflicts({ taskContent = '', allBlocks = [], depsById = new Map(), excludedPairKeys = new Set() } = {}) {
|
|
381
|
+
const isFixTask = fixTaskClassifier(taskContent);
|
|
382
|
+
const reachCache = new Map();
|
|
383
|
+
const reachableFrom = (id) => {
|
|
384
|
+
if (!reachCache.has(id)) reachCache.set(id, reachableTaskIds(depsById, id));
|
|
385
|
+
return reachCache.get(id);
|
|
386
|
+
};
|
|
387
|
+
const participants = [];
|
|
388
|
+
for (const block of allBlocks) {
|
|
389
|
+
const attrs = taskOpeningAttrs(block);
|
|
390
|
+
if (!attrs || !attrs.id || attrs.status === 'done' || isFixTask(block)) continue;
|
|
391
|
+
const wf = block.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
392
|
+
if (!wf) continue;
|
|
393
|
+
const writes = new Set(parsePaths(wf[1]));
|
|
394
|
+
if (writes.size === 0) continue;
|
|
395
|
+
participants.push({ id: attrs.id, writes });
|
|
396
|
+
}
|
|
397
|
+
const conflicts = [];
|
|
398
|
+
for (let i = 0; i < participants.length; i++) {
|
|
399
|
+
for (let j = i + 1; j < participants.length; j++) {
|
|
400
|
+
if (excludedPairKeys.has(taskPairKey(participants[i].id, participants[j].id))) continue;
|
|
401
|
+
const overlap = collectPathOverlaps(participants[i].writes, participants[j].writes);
|
|
402
|
+
if (overlap.length === 0) continue;
|
|
403
|
+
if (reachableFrom(participants[i].id).has(participants[j].id)
|
|
404
|
+
|| reachableFrom(participants[j].id).has(participants[i].id)) continue;
|
|
405
|
+
conflicts.push({ a: participants[i].id, b: participants[j].id, files: overlap });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return conflicts;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export async function findParallelWriteConflicts(changeDir) {
|
|
412
|
+
const taskFile = path.join(changeDir, 'TASK.md');
|
|
413
|
+
let text;
|
|
414
|
+
try { text = await fs.readFile(taskFile, 'utf8'); } catch { return { writeConflicts: [], readWarnings: [], crossTaskConflicts: [] }; }
|
|
415
|
+
const allBlocks = taskBlocks(text);
|
|
416
|
+
// 依赖资格收窄:仅统计「本趟可运行」的并行任务——deps ⊆ doneIds;等待后续趟次的并行任务
|
|
417
|
+
// (依赖未满足)与已交付任务不参与同趟冲突判定,使 A→B 同写路径的跨趟合法计划不再被首趟误拦
|
|
418
|
+
// (与路由谓词同一口径)。依赖文本解析与资格判定一律走 taskDependencyEligibility——本函数不再
|
|
419
|
+
// 自持第二份 <depends_on> 解析,候选集过滤与读写弱判的「显式关联」判定同源。
|
|
420
|
+
const doneIds = new Set(allBlocks
|
|
421
|
+
.map((b) => taskOpeningAttrs(b))
|
|
422
|
+
.filter((a) => a && a.id && a.status === 'done')
|
|
423
|
+
.map((a) => a.id));
|
|
424
|
+
const blocks = allBlocks.filter((b) => {
|
|
425
|
+
const a = taskOpeningAttrs(b);
|
|
426
|
+
if (!a || !a.parallel || a.status !== 'pending') return false;
|
|
427
|
+
return taskDependencyEligibility(b, doneIds).eligible;
|
|
428
|
+
});
|
|
429
|
+
const perTask = [];
|
|
430
|
+
for (const b of blocks) {
|
|
431
|
+
const a = taskOpeningAttrs(b);
|
|
432
|
+
if (!a || !a.id) continue;
|
|
433
|
+
const wf = b.match(/<write_files>([\s\S]*?)<\/write_files>/);
|
|
434
|
+
const rf = b.match(/<read_files>([\s\S]*?)<\/read_files>/);
|
|
435
|
+
if (!wf && !rf) continue;
|
|
436
|
+
perTask.push({
|
|
437
|
+
id: a.id,
|
|
438
|
+
deps: new Set(taskDependencyEligibility(b).deps),
|
|
439
|
+
writes: new Set(parsePaths(wf && wf[1])),
|
|
440
|
+
reads: new Set(parsePaths(rf && rf[1])),
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
const writeConflicts = [];
|
|
444
|
+
const readWarnings = [];
|
|
445
|
+
for (let i = 0; i < perTask.length; i++) {
|
|
446
|
+
for (let j = i + 1; j < perTask.length; j++) {
|
|
447
|
+
const overlap = collectPathOverlaps(perTask[i].writes, perTask[j].writes);
|
|
448
|
+
if (overlap.length) writeConflicts.push({ a: perTask[i].id, b: perTask[j].id, files: overlap });
|
|
449
|
+
// 读写弱判触发面:仅无显式 depends_on 关联的并行对(有显式关联=依赖已声明,跳过)
|
|
450
|
+
const associated = perTask[i].deps.has(perTask[j].id) || perTask[j].deps.has(perTask[i].id);
|
|
451
|
+
if (associated) continue;
|
|
452
|
+
const readOverlap = collectPathOverlaps(perTask[i].reads, perTask[j].writes);
|
|
453
|
+
if (readOverlap.length) readWarnings.push({ a: perTask[i].id, b: perTask[j].id, files: readOverlap });
|
|
454
|
+
const readOverlap2 = collectPathOverlaps(perTask[j].reads, perTask[i].writes);
|
|
455
|
+
if (readOverlap2.length) readWarnings.push({ a: perTask[j].id, b: perTask[i].id, files: readOverlap2 });
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
// 第三族:同文件跨任务且无依赖路径(族语义见上方块注释)。编排只做三件事——族①任务对去重键、
|
|
459
|
+
// 依赖图(analyzeDependencyGraph 单一权威,其依赖解析走 taskDependencyEligibility)、调用具名
|
|
460
|
+
// 纯函数 collectCrossTaskConflicts;参与者规则(status 非 done 且非修复任务族)与依赖闭包判定
|
|
461
|
+
// 全在该纯函数内,此处不内联第二份。
|
|
462
|
+
const writePairKeys = new Set(writeConflicts.map((c) => taskPairKey(c.a, c.b)));
|
|
463
|
+
const { depsById } = analyzeDependencyGraph(allBlocks);
|
|
464
|
+
const crossTaskConflicts = collectCrossTaskConflicts({
|
|
465
|
+
taskContent: text,
|
|
466
|
+
allBlocks,
|
|
467
|
+
depsById,
|
|
468
|
+
excludedPairKeys: writePairKeys,
|
|
469
|
+
});
|
|
470
|
+
return { writeConflicts, readWarnings, crossTaskConflicts };
|
|
471
|
+
}
|