flow-comet 1.5.1 → 1.6.1
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/rules/flow-comet-orchestration.md +1 -2
- package/.flow-comet/skills/flow-comet/GUIDANCE.md +22 -3
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +40 -3
- package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +3 -3
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +18 -17
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +27 -12
- package/.flow-comet/skills/flow-comet/reference/recovery.md +1 -7
- package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +21 -3
- package/.flow-comet/skills/flow-comet/scripts/contract-check.mjs +41 -31
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +6687 -330
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +25 -5
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +1145 -15
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +72 -3
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +2077 -14
- package/.flow-comet/skills/flow-comet/scripts/task-parsing.mjs +13 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +568 -501
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +331 -14
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +783 -40
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +17 -0
- package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-design/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-dev/SKILL.md +3 -1
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +21 -1
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-open/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +17 -6
- package/.flow-comet/skills/flow-comet-requirement/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-review/SKILL.md +23 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +23 -11
- package/.flow-comet/skills/flow-comet-task/SKILL.md +7 -3
- package/.flow-comet/skills/flow-comet-test/SKILL.md +2 -0
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +21 -4
- package/README.md +45 -115
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/prepare-env.mjs +77 -46
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
2
3
|
import { promises as fs } from 'fs';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import { validateStateFields, looksLikeObjectLiteral, RUNTIME_DIR, RUNTIME_STATE_FILE_NAME } from './state-schema.mjs';
|
|
6
|
+
import { validateStateFields, looksLikeObjectLiteral, RUNTIME_DIR, RUNTIME_STATE_FILE_NAME, resolveProtocolPathWithState } from './state-schema.mjs';
|
|
7
|
+
import { EXECUTE_FAMILY_NODE_IDS, protocolNodeEnabled, resolveDelegationTarget, taskDependencyEligibility } from './route-node.mjs';
|
|
8
|
+
import {
|
|
9
|
+
readProtocolFile,
|
|
10
|
+
validateProtocolSchema,
|
|
11
|
+
inspectWorkflowPathSegments,
|
|
12
|
+
} from './protocol-utils.mjs';
|
|
13
|
+
import { taskAttrsById, taskBlocks, taskOpeningAttrs } from './task-parsing.mjs';
|
|
6
14
|
|
|
7
15
|
// workflow-handoff.mjs: Record subagent handoff evidence
|
|
8
16
|
// evidence 统一记录在 subagent-execute 名下作为委托证据库——execute(串行委托)与 subagent-execute(并行委托)共用。不改成节点参数,保持最小改动。
|
|
@@ -11,6 +19,9 @@ import { validateStateFields, looksLikeObjectLiteral, RUNTIME_DIR, RUNTIME_STATE
|
|
|
11
19
|
// node workflow-handoff.mjs result <task-id> <result-or-JSON> -- record handoff result (W1-D: JSON Return Contract; W2-D: commitHash subset check; : completedChecks 规范化; redEvidence 时间顺序校验)
|
|
12
20
|
// node workflow-handoff.mjs status -- show all handoff evidence
|
|
13
21
|
|
|
22
|
+
// 归属门禁读取协议用:与其它脚本同源(packageRoot 默认协议;env 可覆盖),不消费 request 参数。
|
|
23
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
14
25
|
const runRoot = process.cwd();
|
|
15
26
|
// 状态文件路径(单一来源:state-schema.mjs 的运行时路径常量)
|
|
16
27
|
const statePath = path.join(runRoot, RUNTIME_DIR, RUNTIME_STATE_FILE_NAME);
|
|
@@ -74,9 +85,15 @@ async function resolveJsonFileWithinRunRoot(jsonFile) {
|
|
|
74
85
|
// writeFiles 段感知 glob 匹配:按 / 分段,`*` 只匹配段内任意字符(不跨段);
|
|
75
86
|
// 精确条目要求完全相等(不用前缀匹配——src/foo 不得匹配 src/foobar);
|
|
76
87
|
// 段内含 * 的部分通配(如 src/*.test.js、src/*.mjs)转锚定正则匹配
|
|
88
|
+
// 路径分隔符归一(单一来源):Windows 反斜杠 → POSIX `/`;matchWriteFilePattern 与
|
|
89
|
+
// F-6 字面路径资格判定共用(同口径两处实现必分叉——L-067)。
|
|
90
|
+
function toPosixPath(value) {
|
|
91
|
+
return String(value).replace(/\\/g, '/');
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
function matchWriteFilePattern(file, pattern) {
|
|
78
|
-
const f =
|
|
79
|
-
const p =
|
|
95
|
+
const f = toPosixPath(file);
|
|
96
|
+
const p = toPosixPath(pattern);
|
|
80
97
|
const fp = f.split('/');
|
|
81
98
|
const pp = p.split('/');
|
|
82
99
|
if (fp.length !== pp.length) return false;
|
|
@@ -95,6 +112,138 @@ function matchWriteFilePattern(file, pattern) {
|
|
|
95
112
|
return true;
|
|
96
113
|
}
|
|
97
114
|
|
|
115
|
+
// ---------- F-6 零提交资格(DESIGN 决策 7 · fail-closed) ----------
|
|
116
|
+
// 字面路径 → repo 相对 POSIX 路径归一:仅接受不含 glob 魔法(* ? [)的字面路径;拒绝绝对
|
|
117
|
+
// 路径(POSIX 前导 /、盘符前缀、UNC)与 .. 逃逸、空段。返回归一后相对路径,或 null(无资格)。
|
|
118
|
+
function literalRelativePosixPath(entry) {
|
|
119
|
+
if (typeof entry !== 'string') return null;
|
|
120
|
+
const raw = entry.trim();
|
|
121
|
+
if (raw === '' || /[*?[]/.test(raw)) return null;
|
|
122
|
+
const posix = toPosixPath(raw);
|
|
123
|
+
if (posix.startsWith('/') || /^[A-Za-z]:/.test(posix)) return null;
|
|
124
|
+
const normalized = path.posix.normalize(posix);
|
|
125
|
+
if (normalized === '' || normalized === '.' || normalized === '..' || normalized.startsWith('../')) return null;
|
|
126
|
+
// 必须位于 runRoot 内:解析后相对路径逐字复核(词法拒绝后的二次保险,含平台路径语义差异)
|
|
127
|
+
const relToRoot = path.relative(runRoot, path.resolve(runRoot, normalized));
|
|
128
|
+
if (relToRoot === '' || path.isAbsolute(relToRoot) || relToRoot === '..' || relToRoot.startsWith('..' + path.sep)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return normalized;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// `check-ignore` 退出 1 时判别路径是否已被 index 跟踪(index-aware 默认下 tracked 不算 ignored):
|
|
135
|
+
// 命中 → became-tracked,未命中 → 忽略规则变化。仅作失败归类,任一探测异常按未跟踪处理(仍 fail-closed)。
|
|
136
|
+
function gitIndexTracksPath(rel) {
|
|
137
|
+
try {
|
|
138
|
+
execFileSync('git', ['ls-files', '--error-unmatch', '--', rel], { cwd: runRoot, stdio: 'ignore' });
|
|
139
|
+
return true;
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 资格判定:全部字面路径 + runRoot 等于 git top-level 的 realpath + 逐路径
|
|
146
|
+
// `git check-ignore -q -- <repo-relative-path>` 退出 0(cwd=runRoot,数组参数、index-aware
|
|
147
|
+
// 默认:tracked 文件退出 1)→ eligible;任一不满足 → 带 reason 的 fail-closed 结论
|
|
148
|
+
//(request 侧只看 eligible、不记 noCommit、不阻断原流程;result 侧把 reason 写入撤销审计)。
|
|
149
|
+
// 不用 --no-index、不 import prepare-env(不分发)。
|
|
150
|
+
// 路径扫描增强(m-13):runRoot 先 realpath 归一;对每个字面路径的最近已存在祖先逐段 lstat,
|
|
151
|
+
// 任一段为 symlink/junction(或物理逃出 runRoot)→ fail-closed(目标不存在不算失败)。
|
|
152
|
+
// 逐段扫描复用 protocol-utils 的单一权威,本处不得另写第二份 symlink/包含判据(L-067)。
|
|
153
|
+
// 失败类别(稳定机器码,作为 result 撤销审计的 revokeReason):invalid-path(glob / 绝对路径 /
|
|
154
|
+
// `..` 逃逸等字面形态不成立)、stale-eligibility(忽略规则变化,路径不再被证明 gitignored)、
|
|
155
|
+
// became-tracked(路径已在 index 中)、symlink-junction-escape(祖先段 symlink/junction 或
|
|
156
|
+
// 物理越界)、non-git(非 git 仓 / runRoot 非 top-level / git 探测错误)。
|
|
157
|
+
async function classifyWriteFilesProvablyIgnored(entries) {
|
|
158
|
+
if (!Array.isArray(entries) || entries.length === 0) return { eligible: false, reason: 'invalid-path' };
|
|
159
|
+
const relPaths = [];
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
const rel = literalRelativePosixPath(entry);
|
|
162
|
+
if (rel === null) return { eligible: false, reason: 'invalid-path' };
|
|
163
|
+
relPaths.push(rel);
|
|
164
|
+
}
|
|
165
|
+
let realRoot;
|
|
166
|
+
let realTop;
|
|
167
|
+
try {
|
|
168
|
+
realRoot = await fs.realpath(runRoot);
|
|
169
|
+
const out = execFileSync('git', ['rev-parse', '--show-toplevel'], {
|
|
170
|
+
cwd: runRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'],
|
|
171
|
+
});
|
|
172
|
+
const top = String(out).split('\n').map((s) => s.trim()).filter(Boolean)[0];
|
|
173
|
+
if (!top) return { eligible: false, reason: 'non-git' };
|
|
174
|
+
realTop = await fs.realpath(top);
|
|
175
|
+
} catch {
|
|
176
|
+
return { eligible: false, reason: 'non-git' }; // 非 git 仓 / git 不可用 / 命令错误
|
|
177
|
+
}
|
|
178
|
+
// windows 路径大小写不敏感(realpath 双方同源,仍按平台归一比较)
|
|
179
|
+
const sameRoot = process.platform === 'win32'
|
|
180
|
+
? realRoot.toLowerCase() === realTop.toLowerCase()
|
|
181
|
+
: realRoot === realTop;
|
|
182
|
+
if (!sameRoot) return { eligible: false, reason: 'non-git' }; // runRoot 必须是 git top-level
|
|
183
|
+
for (const rel of relPaths) {
|
|
184
|
+
try {
|
|
185
|
+
await inspectWorkflowPathSegments(realRoot, path.resolve(realRoot, rel), 'write_files 字面路径');
|
|
186
|
+
} catch {
|
|
187
|
+
return { eligible: false, reason: 'symlink-junction-escape' }; // 穿越 / 非目录祖先 / 物理越界
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
execFileSync('git', ['check-ignore', '-q', '--', rel], { cwd: runRoot, stdio: 'ignore' });
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (error && typeof error === 'object' && error.status === 1) {
|
|
193
|
+
// check-ignore 退出 1 = 未命中忽略规则,或路径已被 index 跟踪(index-aware 默认)——
|
|
194
|
+
// 用 ls-files 判别后落入既有失败归类。
|
|
195
|
+
return { eligible: false, reason: gitIndexTracksPath(rel) ? 'became-tracked' : 'stale-eligibility' };
|
|
196
|
+
}
|
|
197
|
+
return { eligible: false, reason: 'non-git' }; // 命令错误等
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { eligible: true, reason: null };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 失败类别 → 审计文案(撤销 detail 与 revokeReason 机器码一一对应;新失败形态只在此扩展)。
|
|
204
|
+
const ZERO_COMMIT_REVOKE_REASON_TEXT = {
|
|
205
|
+
'invalid-path': 'write_files 字面形态不成立(glob / 绝对路径 / .. 逃逸等)',
|
|
206
|
+
'stale-eligibility': '.gitignore 变化(路径不再被证明 ignored)',
|
|
207
|
+
'became-tracked': '路径变为 tracked',
|
|
208
|
+
'symlink-junction-escape': 'symlink-junction 逃逸',
|
|
209
|
+
'non-git': '非 git 仓 / runRoot 非 top-level / git 探测错误',
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// ---------- m-13 result 零提交资格重验 ----------
|
|
213
|
+
// 仅当 request 记录 noCommit=true 且 writeFiles 非空时,在 result 时刻按同一增强资格重跑。
|
|
214
|
+
// 失败 → 撤销 request evidence 的 noCommit(置 false)并加法式记录 revokedAt(ISO 时间)与
|
|
215
|
+
// revokeReason(失败类别机器码——invalid-path / stale-eligibility / became-tracked /
|
|
216
|
+
// symlink-junction-escape / non-git):
|
|
217
|
+
// 新 change → HANDOFF ERROR、不落 result(只落资格撤销),出口 W1-D 不再豁免缺 commitHash;
|
|
218
|
+
// 旧 change → HANDOFF WARN 后继续记录 result(出口 W1-D 同样不再豁免)。
|
|
219
|
+
// 返回 'skip'(形态不适用)/ 'pass'(资格仍成立)/ 'warn'(旧 change 已撤销)/ 'block'(新 change 已撤销)。
|
|
220
|
+
// 空 writeFiles、非 noCommit、无 request 记录均不扩大行为;未引用提交 / HEAD 移动 / TOCTOU /
|
|
221
|
+
// worktree 提交不可见等结构性 residual 由 T11/T12 文档登记,本函数不宣称已闭合。
|
|
222
|
+
async function revalidateResultZeroCommit(state, taskId, handoffReq) {
|
|
223
|
+
if (!handoffReq || handoffReq.noCommit !== true) return 'skip';
|
|
224
|
+
const entries = Array.isArray(handoffReq.writeFiles) ? handoffReq.writeFiles : [];
|
|
225
|
+
if (entries.length === 0) return 'skip';
|
|
226
|
+
const verdict = await classifyWriteFilesProvablyIgnored(entries);
|
|
227
|
+
if (verdict.eligible) return 'pass';
|
|
228
|
+
// 加法式撤销审计:noCommit=false(既有语义不变)+ revokedAt(ISO 时间)+ revokeReason
|
|
229
|
+
//(失败类别,复用资格判定的失败归类);每次撤销刷新为本次的 at/reason。
|
|
230
|
+
handoffReq.noCommit = false;
|
|
231
|
+
handoffReq.revokedAt = new Date().toISOString();
|
|
232
|
+
handoffReq.revokeReason = verdict.reason;
|
|
233
|
+
// 资格撤销先落盘(新旧 change 一致):旧 change 后续若被其它门禁阻断,审计也不丢失,
|
|
234
|
+
// 避免 WARN 声称已撤销而 state 仍是旧值。
|
|
235
|
+
await writeState(state);
|
|
236
|
+
const reasonText = ZERO_COMMIT_REVOKE_REASON_TEXT[verdict.reason] || verdict.reason;
|
|
237
|
+
const detail = '任务 ' + taskId + ' 零提交资格 result 重验失败(' + reasonText + ')——request evidence noCommit=false, revokedAt=' + handoffReq.revokedAt + ', revokeReason=' + verdict.reason;
|
|
238
|
+
if (state.newChange === true) {
|
|
239
|
+
// 新 change 只落 request 资格撤销;此刻尚未默认 handoffResult,确保「不落 result」不是文案承诺
|
|
240
|
+
console.error('HANDOFF ERROR: ' + detail + ';新 change 不落 result,出口校验不再豁免缺 commitHash。恢复: 修正 write_files / .gitignore 与路径形态后重新 request,或回传含合法 commitHash 的 Return Contract');
|
|
241
|
+
return 'block';
|
|
242
|
+
}
|
|
243
|
+
console.error('HANDOFF WARN: ' + detail + '(旧 change 渐进,继续记录 result;出口校验不再豁免缺 commitHash)');
|
|
244
|
+
return 'warn';
|
|
245
|
+
}
|
|
246
|
+
|
|
98
247
|
async function readState() {
|
|
99
248
|
if (await fileExists(statePath)) return JSON.parse(await fs.readFile(statePath, 'utf8'));
|
|
100
249
|
return { activeChange: null, currentNode: null, completedNodes: [], evidence: {} };
|
|
@@ -111,6 +260,148 @@ async function writeState(state) {
|
|
|
111
260
|
await fs.writeFile(statePath, JSON.stringify(state, null, 2) + '\n', 'utf8');
|
|
112
261
|
}
|
|
113
262
|
|
|
263
|
+
// ---------- request 归属门禁(只读判定) ----------
|
|
264
|
+
// 归属目标与依赖资格一律复用 route-node 的共享纯函数(单一权威):门禁不在本文件内联
|
|
265
|
+
// 「parallel → 目标节点」映射。协议无对应 enabled 节点 → 跳过门禁(不产生归属 WARN);
|
|
266
|
+
// 协议不可读 → 可见 WARN(含原因 +「本次未执行归属校验」)后放行,不静默、不新增硬 BLOCK。
|
|
267
|
+
// 判定只读 state 与协议:BLOCK 路径在首个 state.evidence 写入之前返回,state 字节零改写、不落请求记录。
|
|
268
|
+
|
|
269
|
+
// 协议读取(归属判定用):协议路径统一由 state-schema.mjs 的 resolveProtocolPathWithState 选择
|
|
270
|
+
// (不消费 request 的 CLI 参数):state.protocolPath(init 持久化绑定)> FLOW_COMET_PROTOCOL 环境变量 >
|
|
271
|
+
// 内置默认协议。state.protocolPath 存在但不可读时不回退环境变量/默认——回退会在自定义协议缺节点时
|
|
272
|
+
// 按默认协议误判归属;读取/解析/schema 校验失败统一返回失败原因,由调用方输出低噪声可见 WARN,
|
|
273
|
+
// 新/旧 change 均不因此新增硬 BLOCK。
|
|
274
|
+
async function readOwnershipProtocol(state) {
|
|
275
|
+
let protocolPath = null;
|
|
276
|
+
let source = null;
|
|
277
|
+
try {
|
|
278
|
+
const selected = resolveProtocolPathWithState({ packageRoot, runRoot, state });
|
|
279
|
+
protocolPath = selected.protocolPath;
|
|
280
|
+
source = selected.source;
|
|
281
|
+
const protocol = await readProtocolFile(runRoot, protocolPath);
|
|
282
|
+
validateProtocolSchema(protocol);
|
|
283
|
+
return { protocol, failure: null };
|
|
284
|
+
} catch (error) {
|
|
285
|
+
return { protocol: null, failure: describeProtocolReadFailure(error, protocolPath, source) };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// 协议读取失败原因归类(低噪声单行消息用;不打印堆栈、不回显文件内容):
|
|
290
|
+
// 缺失 / 受保护路径拒绝 / JSON 解析失败 / schema 非法 / 其余原样归类。
|
|
291
|
+
// 来源为 state.protocolPath 时附注来源,便于区分「绑定协议不可读」与「回退解析不可读」。
|
|
292
|
+
function describeProtocolReadFailure(error, protocolPath, source = null) {
|
|
293
|
+
const location = protocolPath === null ? '(路径未解析)' : ':' + protocolPath;
|
|
294
|
+
const origin = source === 'state' ? '(来源 state.protocolPath)' : '';
|
|
295
|
+
const message = error && typeof error.message === 'string' ? error.message : String(error);
|
|
296
|
+
if (error && error.code === 'ENOENT') return '协议文件不存在' + location + origin;
|
|
297
|
+
if (message.includes('must stay inside the project root')) {
|
|
298
|
+
return '协议路径不在当前项目根内(受保护读取拒绝)' + location + origin;
|
|
299
|
+
}
|
|
300
|
+
if (message.includes('is not valid JSON')) return '协议文件不是合法 JSON' + location + origin;
|
|
301
|
+
if (message.includes('protocol') || message.includes('schema')) {
|
|
302
|
+
return '协议内容不合法:' + message + origin;
|
|
303
|
+
}
|
|
304
|
+
return '协议读取失败:' + message + origin;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 路由事实:从 TASK.md 全文派生 done id 集合与目标任务块。解析走 task-parsing 的开标签
|
|
308
|
+
// 解析(与路由、guard 同一语义),不新增第二份正则。
|
|
309
|
+
function taskRouteFacts(taskContent, taskId) {
|
|
310
|
+
const doneIds = new Set();
|
|
311
|
+
let targetBlock = null;
|
|
312
|
+
for (const block of taskBlocks(taskContent)) {
|
|
313
|
+
const attrs = taskOpeningAttrs(block);
|
|
314
|
+
if (!attrs) continue;
|
|
315
|
+
if (attrs.status === 'done' && attrs.id) doneIds.add(attrs.id);
|
|
316
|
+
if (taskId !== null && taskId !== undefined && attrs.id === String(taskId)) targetBlock = block;
|
|
317
|
+
}
|
|
318
|
+
return { doneIds, targetBlock };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// 归属判定:仅 status=pending 的任务参与;比较原始 state.currentNode(不取任何派生 currentNode)。
|
|
322
|
+
// 目标与依赖资格经 route-node 共享纯函数求得,与 next/路由使用同一判定。
|
|
323
|
+
// 返回 { verdict: 'skip' | 'pass' | 'not-entered' | 'mismatch' | 'not-delegable', ... };
|
|
324
|
+
// skip 的 reason='protocol-unavailable' 携带 protocolFailure(调用方输出可见 WARN 后放行)。
|
|
325
|
+
async function assessRequestOwnership(state, taskAttrs, taskContent) {
|
|
326
|
+
if (!taskAttrs || taskAttrs.status !== 'pending') return { verdict: 'skip', reason: 'not-pending' };
|
|
327
|
+
const protocolRead = await readOwnershipProtocol(state);
|
|
328
|
+
if (protocolRead.protocol === null) {
|
|
329
|
+
return { verdict: 'skip', reason: 'protocol-unavailable', protocolFailure: protocolRead.failure };
|
|
330
|
+
}
|
|
331
|
+
const protocol = protocolRead.protocol;
|
|
332
|
+
const { doneIds, targetBlock } = taskRouteFacts(taskContent, taskAttrs.id);
|
|
333
|
+
const dependency = targetBlock
|
|
334
|
+
? taskDependencyEligibility(targetBlock, doneIds)
|
|
335
|
+
: { eligible: false, deps: [], unmet: [] };
|
|
336
|
+
const ownership = resolveDelegationTarget({
|
|
337
|
+
taskAttrs,
|
|
338
|
+
dependencyEligible: dependency.eligible,
|
|
339
|
+
subagentNodeEnabled: protocolNodeEnabled(protocol, 'subagent-execute'),
|
|
340
|
+
executeNodeEnabled: protocolNodeEnabled(protocol, 'execute'),
|
|
341
|
+
});
|
|
342
|
+
if (ownership.reason === 'not-pending' || ownership.reason === 'no-delegation-node') {
|
|
343
|
+
return { verdict: 'skip', reason: ownership.reason };
|
|
344
|
+
}
|
|
345
|
+
if (ownership.reason === 'dependencies-unmet') {
|
|
346
|
+
return { verdict: 'not-delegable', reason: ownership.reason, unmet: dependency.unmet };
|
|
347
|
+
}
|
|
348
|
+
if (state.currentNode !== ownership.targetNode) {
|
|
349
|
+
return { verdict: 'mismatch', targetNode: ownership.targetNode, reason: ownership.reason };
|
|
350
|
+
}
|
|
351
|
+
const enteredNodes = Array.isArray(state.enteredNodes) ? state.enteredNodes : [];
|
|
352
|
+
if (!enteredNodes.includes(ownership.targetNode)) {
|
|
353
|
+
return { verdict: 'not-entered', targetNode: ownership.targetNode, reason: ownership.reason };
|
|
354
|
+
}
|
|
355
|
+
return { verdict: 'pass', reason: ownership.reason };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 渲染归属判定结果(只输出与退出,不写 state):
|
|
359
|
+
// 协议不可读 → 可见 WARN(含原因与「本次未执行归属校验」)后放行,不静默、不阻断。
|
|
360
|
+
// 不可委托 → 新 change BLOCK / 旧 change 可见 WARN 后继续;恢复指引以 workflow-state next 的
|
|
361
|
+
// 实际 NODE 输出为准,不固定指向 next 不会输出的节点(依赖未满足时路由按串行消化走 execute)。
|
|
362
|
+
// 归属目标不匹配 → 同样先按 next 的路由指引进入;正确节点未 entry → 可见 WARN 不阻断。
|
|
363
|
+
function reportRequestOwnership(state, taskId, taskAttrs, ownership) {
|
|
364
|
+
const kind = taskAttrs && taskAttrs.parallel === true ? '并行' : '串行';
|
|
365
|
+
const current = String(state.currentNode);
|
|
366
|
+
if (ownership.verdict === 'skip' && ownership.reason === 'protocol-unavailable') {
|
|
367
|
+
console.error('WARN: 任务 ' + taskId + ' 的委托归属校验未执行——协议不可读('
|
|
368
|
+
+ ownership.protocolFailure + ');本次未执行归属校验,请求照常记录(新/旧 change 均不因此阻断)');
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (ownership.verdict === 'not-delegable') {
|
|
372
|
+
const unmet = Array.isArray(ownership.unmet) ? ownership.unmet : [];
|
|
373
|
+
const detail = '任务 ' + taskId + '(' + kind + ' pending)当前不可委托:依赖未满足'
|
|
374
|
+
+ (unmet.length > 0 ? '(未完成: ' + unmet.join(', ') + ')' : '')
|
|
375
|
+
+ ';原始 currentNode=' + current;
|
|
376
|
+
const guide = '恢复指引: 运行 workflow-state next,按输出的 NODE 进入;若输出 execute 表示依赖未满足'
|
|
377
|
+
+ '(该任务当前按串行消化),待任务变为可委托(next 输出对应委托节点)后再 request';
|
|
378
|
+
if (state.newChange === true) {
|
|
379
|
+
console.error('BLOCKED: ' + detail + '——' + guide + ';本次请求未写入 state,也未记录 handoffRequests');
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
console.error('WARN: ' + detail + '(旧 change 渐进不阻断,请求照常记录)——' + guide);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (ownership.verdict === 'mismatch') {
|
|
386
|
+
const detail = '任务 ' + taskId + '(' + kind + ' pending)应归属节点 '
|
|
387
|
+
+ ownership.targetNode + ',原始 currentNode=' + current;
|
|
388
|
+
const guide = '恢复指引: 运行 workflow-state next 查看当前路由,按 NODE 输出进入'
|
|
389
|
+
+ '(本任务归属节点 ' + ownership.targetNode + ':workflow-state entry ' + ownership.targetNode
|
|
390
|
+
+ ' 或 workflow-guard entry ' + ownership.targetNode + ')后再发起委托';
|
|
391
|
+
if (state.newChange === true) {
|
|
392
|
+
console.error('BLOCKED: ' + detail + '——' + guide + ';本次请求未写入 state,也未记录 handoffRequests');
|
|
393
|
+
process.exit(1);
|
|
394
|
+
}
|
|
395
|
+
console.error('WARN: ' + detail + '(旧 change 渐进不阻断,请求照常记录)——' + guide);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (ownership.verdict === 'not-entered') {
|
|
399
|
+
console.error('WARN: 任务 ' + taskId + ' 的归属节点 ' + ownership.targetNode
|
|
400
|
+
+ ' 与原始 currentNode 一致,但该节点尚未 entry(enteredNodes 缺 ' + ownership.targetNode
|
|
401
|
+
+ ')——建议先运行 workflow-state entry ' + ownership.targetNode + ' 或 workflow-guard entry '
|
|
402
|
+
+ ownership.targetNode + ' 记录进入');
|
|
403
|
+
}
|
|
404
|
+
}
|
|
114
405
|
async function main() {
|
|
115
406
|
const action = process.argv[2] ?? 'status';
|
|
116
407
|
const state = await readState();
|
|
@@ -124,7 +415,7 @@ async function main() {
|
|
|
124
415
|
// 并 skill-load 声明,再发起委托。缺失 → 新 change BLOCK / 旧 change 渐进 WARN。
|
|
125
416
|
// 与零提交语义独立共存:本门只校验节点技能声明,不依赖任务 write_files 内容。
|
|
126
417
|
const requestNode = state.currentNode;
|
|
127
|
-
if (requestNode && (requestNode
|
|
418
|
+
if (requestNode && EXECUTE_FAMILY_NODE_IDS.has(requestNode)) {
|
|
128
419
|
const declared = await nodeSkillDeclared(requestNode, state.activeChange);
|
|
129
420
|
if (!declared) {
|
|
130
421
|
const loadGuide = '先加载技能(用 Skill 工具,禁止跳过)并运行 workflow-state.mjs skill-load ' + requestNode + ' <skill> 再发起委托';
|
|
@@ -149,12 +440,19 @@ async function main() {
|
|
|
149
440
|
// 解析三态(bot 评审收紧):① 匹配到任务块且 <write_files> 存在 → 按内容分类;
|
|
150
441
|
// ② 任务块缺失或块内无 <write_files> 元素 → 任务不可解析,新 change BLOCK,旧 change
|
|
151
442
|
// WARN 且不设 noCommit(防未解析任务静默变零提交逃逸口);③ TASK.md 读不到同 ②。
|
|
443
|
+
// TASK.md 只读一次:任务开标签属性解析(归属门禁)复用 task-parsing.mjs;
|
|
444
|
+
// 下方 write_files 元素提取沿用既有实现(该路径的解析策略不在本任务改动面内)。
|
|
445
|
+
const taskFile = state.activeChange
|
|
446
|
+
? path.join(runRoot, '.specs', state.activeChange, 'TASK.md')
|
|
447
|
+
: null;
|
|
448
|
+
let taskContent = null;
|
|
449
|
+
if (taskFile) {
|
|
450
|
+
taskContent = await fs.readFile(taskFile, 'utf8').catch(() => null);
|
|
451
|
+
}
|
|
152
452
|
let taskResolved = false;
|
|
153
453
|
let emptyWriteFilesElement = false;
|
|
154
454
|
if (!writeFiles || writeFiles.length === 0) {
|
|
155
|
-
|
|
156
|
-
const taskFile = path.join(runRoot, '.specs', state.activeChange, 'TASK.md');
|
|
157
|
-
const taskContent = await fs.readFile(taskFile, 'utf8');
|
|
455
|
+
if (taskContent !== null) {
|
|
158
456
|
const taskRegex = new RegExp(`<task[^>]*id="${taskId.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&')}"[\\s\\S]*?<write_files>([\\s\\S]*?)</write_files>`, 'i');
|
|
159
457
|
const match = taskContent.match(taskRegex);
|
|
160
458
|
if (match) {
|
|
@@ -166,7 +464,7 @@ async function main() {
|
|
|
166
464
|
if (files.length > 0) { writeFiles = files; }
|
|
167
465
|
else { emptyWriteFilesElement = true; }
|
|
168
466
|
}
|
|
169
|
-
}
|
|
467
|
+
}
|
|
170
468
|
if (wfIdx >= 0) { taskResolved = true; emptyWriteFilesElement = false; }
|
|
171
469
|
} else {
|
|
172
470
|
taskResolved = true;
|
|
@@ -179,18 +477,32 @@ async function main() {
|
|
|
179
477
|
}
|
|
180
478
|
console.error('WARN: ' + msg + '(旧 change 渐进,不阻断,不记录 noCommit)');
|
|
181
479
|
}
|
|
480
|
+
// request 归属门禁:技能声明门之后、任务解析之后、首个 state.evidence 写入之前。
|
|
481
|
+
// 只读判定;新 change 不匹配 → BLOCK(state 字节零改写、不落 handoffRequests);旧 change → 可见 WARN 后照常记录。
|
|
482
|
+
const parsedTask = taskAttrsById(taskContent, taskId);
|
|
483
|
+
if (!parsedTask && wfIdx >= 0) {
|
|
484
|
+
console.error('WARN: 显式 --write-files 且 TASK.md 无匹配任务 ' + taskId + '——无法判定 pending 与归属,跳过归属门禁(不阻断,照常记录)');
|
|
485
|
+
}
|
|
486
|
+
reportRequestOwnership(state, taskId, parsedTask, await assessRequestOwnership(state, parsedTask, taskContent));
|
|
182
487
|
state.evidence = state.evidence || {};
|
|
183
488
|
state.evidence['subagent-execute'] = state.evidence['subagent-execute'] || {};
|
|
184
489
|
if (!state.evidence['subagent-execute'].handoffRequests) {
|
|
185
490
|
state.evidence['subagent-execute'].handoffRequests = {};
|
|
186
491
|
}
|
|
187
492
|
const zeroEligible = taskResolved && emptyWriteFilesElement && writeFiles.length === 0;
|
|
493
|
+
// F-6(DESIGN 决策 7):非空 write_files 的「全部可证明 gitignored」资格——与空元素同语义,
|
|
494
|
+
// 记 noCommit:true;不具资格 → 不记 noCommit、不阻断原流程(保持既有完整提交子集校验)。
|
|
495
|
+
const literalIgnoredEligible = taskResolved && writeFiles.length > 0
|
|
496
|
+
&& (await classifyWriteFilesProvablyIgnored(writeFiles)).eligible;
|
|
188
497
|
state.evidence['subagent-execute'].handoffRequests[taskId] = {
|
|
189
498
|
description, requestedAt: new Date().toISOString(),
|
|
190
499
|
...(writeFiles.length ? { writeFiles } : {}),
|
|
191
|
-
...(zeroEligible ? { noCommit: true } : {})
|
|
500
|
+
...(zeroEligible || literalIgnoredEligible ? { noCommit: true } : {})
|
|
192
501
|
};
|
|
193
502
|
await writeState(state);
|
|
503
|
+
if (literalIgnoredEligible) {
|
|
504
|
+
console.error('HANDOFF 零提交资格: ' + taskId + ' — write_files 全部可证明 gitignored');
|
|
505
|
+
}
|
|
194
506
|
console.log('HANDOFF REQUEST: ' + taskId);
|
|
195
507
|
return;
|
|
196
508
|
}
|
|
@@ -235,19 +547,24 @@ async function main() {
|
|
|
235
547
|
}
|
|
236
548
|
state.evidence = state.evidence || {};
|
|
237
549
|
state.evidence['subagent-execute'] = state.evidence['subagent-execute'] || {};
|
|
550
|
+
const handoffReq = state.evidence['subagent-execute'].handoffRequests?.[taskId];
|
|
551
|
+
const hasRequest = !!handoffReq && typeof handoffReq === 'object';
|
|
552
|
+
// m-13:result 重验在默认 handoffResult 之前——新 change 失败路径只落 request.noCommit=false,
|
|
553
|
+
// 不落下空 handoffResult 充当 result 载体;重验通过/旧 change 之后才初始化结果容器。
|
|
554
|
+
if (await revalidateResultZeroCommit(state, taskId, handoffReq) === 'block') process.exit(1);
|
|
238
555
|
state.evidence['subagent-execute'].handoffResult = state.evidence['subagent-execute'].handoffResult || {};
|
|
239
556
|
// 零提交任务语义:已有 request 记录且其写文件列表为空(无 tracked 写意图)或带 noCommit
|
|
240
|
-
//
|
|
557
|
+
// 标记(空 write_files 或全部可证明 gitignored——request 侧 F-6 资格判定的结论)时,判定为
|
|
558
|
+
// 零提交——跳过提交文件子集校验并输出可审计提示。契约侧 noCommit 声明仅作
|
|
241
559
|
// 审计线索:写文件列表非空的任务即使契约声称零提交,仍执行完整提交文件子集校验(不可借
|
|
242
560
|
// 零提交声明绕过真实提交检查)。无 request 记录的任务不适用零提交(保持既有完整校验)。
|
|
243
|
-
|
|
244
|
-
const hasRequest = !!handoffReq && typeof handoffReq === 'object';
|
|
561
|
+
// m-13:request.noCommit 在上述重验失败时已被撤销,故此处按撤销后的真实值重算。
|
|
245
562
|
const reqWriteFiles = hasRequest ? (handoffReq.writeFiles || []) : [];
|
|
246
563
|
const reqNoCommit = hasRequest && handoffReq.noCommit === true;
|
|
247
564
|
const contractNoCommit = typeof parsed === 'object' && parsed !== null && parsed.noCommit === true;
|
|
248
565
|
const isZeroCommit = hasRequest && (reqWriteFiles.length === 0 || reqNoCommit);
|
|
249
566
|
if (isZeroCommit) {
|
|
250
|
-
console.error('HANDOFF 零提交: ' + taskId + ' — 无 tracked 写文件(write_files
|
|
567
|
+
console.error('HANDOFF 零提交: ' + taskId + ' — 无 tracked 写文件(write_files 为空或全部可证明 gitignored),已跳过提交文件子集校验');
|
|
251
568
|
// 零提交边界收紧(bot 评审实证逃逸口):声明零提交的结果若携带含 tracked 文件的提交,
|
|
252
569
|
// 等于从「空 write_files」旁路逃逸——新 change BLOCK / 旧 change WARN。探测异常降级
|
|
253
570
|
// WARN 不阻断(对齐 M4 提交对象确认提示先例)。
|
|
@@ -366,7 +683,7 @@ async function main() {
|
|
|
366
683
|
console.log(JSON.stringify({
|
|
367
684
|
activeChange: state.activeChange,
|
|
368
685
|
handoffRequests: handoff.handoffRequests || {},
|
|
369
|
-
|
|
686
|
+
handoffResult: handoff.handoffResult || {}
|
|
370
687
|
}, null, 2));
|
|
371
688
|
return;
|
|
372
689
|
}
|