dsh-project-flow 0.9.0 → 0.9.2
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/CHANGELOG.md +0 -0
- package/README.md +58 -11
- package/cordis.patch.yml +30 -11
- package/docs/DETAIL.md +6 -6
- package/docs/FEATURES.md +12 -5
- package/docs/LAUNCH.md +3 -3
- package/docs/MOMENTS.md +4 -4
- package/docs/USAGE.md +2 -2
- package/domains.mjs +1 -1
- package/evidence.mjs +19 -3
- package/flow.schema.mjs +192 -35
- package/gate.mjs +49 -23
- package/index.js +639 -120
- package/locale/en.json +15 -4
- package/locale/zh.json +17 -6
- package/package.json +5 -3
- package/tests/_heartbeat-regression.test.mjs +124 -0
- package/tests/aesthetic.test.mjs +534 -0
- package/tests/assertions-e2e.mjs +234 -0
- package/tests/bench-check.mjs +32 -0
- package/tests/client-bundle.test.mjs +707 -0
- package/tests/contract.test.mjs +137 -0
- package/tests/desktop.test.mjs +130 -0
- package/tests/domains.test.mjs +220 -0
- package/tests/e2e.mjs +300 -0
- package/tests/evidence.test.mjs +408 -0
- package/tests/extra-phase.test.mjs +133 -0
- package/tests/feedback.test.mjs +187 -0
- package/tests/flow-create.test.mjs +168 -0
- package/tests/flow-gate.test.mjs +232 -0
- package/tests/flow-schema.test.mjs +213 -0
- package/tests/gate.test.mjs +246 -0
- package/tests/issue-loop.test.mjs +254 -0
- package/tests/issues-e2e.mjs +246 -0
- package/tests/panel-independence.test.mjs +78 -0
- package/tests/panel-report.test.mjs +129 -0
- package/tests/patch-ledger.test.mjs +280 -0
- package/tests/paths.mjs +100 -0
- package/tests/preview-path.test.mjs +69 -0
- package/tests/qa-assertions.test.mjs +352 -0
- package/tests/run-all.mjs +90 -0
- package/tests/stage-model.test.mjs +120 -0
- package/tests/stop-resume.test.mjs +260 -0
- package/tests/watch-root.test.mjs +167 -0
- package/tests/watchdog-tokens.test.mjs +53 -0
- package/tests/watchdog.test.mjs +305 -0
package/flow.schema.mjs
CHANGED
|
@@ -16,13 +16,47 @@
|
|
|
16
16
|
/** 认得的顶层键。其余进 warnings,不拦。 */
|
|
17
17
|
const TOP_KEYS = ['process', 'limits', 'phases']
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* 节点行号挂在解析结果的这个符号上。
|
|
21
|
+
*
|
|
22
|
+
* 用 Symbol 而不是 `__line` 这类普通键:Symbol 不会被 JSON.stringify 序列化,
|
|
23
|
+
* 也不参与 Object.keys,深比较时天然被忽略。校验通过后这个标记就完成了使命。
|
|
24
|
+
*/
|
|
25
|
+
const NODE_LINE = Symbol('flow.node.line')
|
|
26
|
+
|
|
27
|
+
/** 取一个节点在原文里的起始行;取不到返回 0(表示「没有位置信息」)。 */
|
|
28
|
+
function lineOf(node) {
|
|
29
|
+
const value = node !== null && typeof node === 'object' ? node[NODE_LINE] : undefined
|
|
30
|
+
return Number.isInteger(value) ? value : 0
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
/** 认得的 phase 键。 */
|
|
20
|
-
const PHASE_KEYS = ['id', 'reads', 'writes', 'gate', 'model', 'instructions'
|
|
34
|
+
const PHASE_KEYS = ['id', 'reads', 'writes', 'gate', 'model', 'instructions']
|
|
21
35
|
|
|
22
36
|
/** 认得的 gate 键。 */
|
|
23
|
-
const GATE_KEYS = ['kind', '
|
|
37
|
+
const GATE_KEYS = ['kind', 'on_fail', 'max_rework']
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 真正接进执行流程的 gate.kind。**只有这一个。**
|
|
41
|
+
*
|
|
42
|
+
* 以前这里列了四个(intent / artifact_present / assertions_exit_zero / verdict),
|
|
43
|
+
* 但执行器只实现了 artifact_present——其余三个写进 flow.yaml 会被解析、被校验
|
|
44
|
+
* 通过、然后被静默忽略。配置看起来生效了、实际没生效,比直接报错危险得多。
|
|
45
|
+
*
|
|
46
|
+
* 所以现在:写三个里的任何一个,validateFlow 直接给 errors 并拒绝运行,
|
|
47
|
+
* 报错里说清「这个判定在四阶的哪一段里做」,让人知道该去哪改。
|
|
48
|
+
*/
|
|
49
|
+
const SUPPORTED_GATE_KINDS = ['artifact_present']
|
|
24
50
|
|
|
25
|
-
|
|
51
|
+
/**
|
|
52
|
+
* 曾经暴露过、但没接进执行流程的判定。留着这张表是为了给出「你应该去哪」,
|
|
53
|
+
* 而不是一句「不支持」。
|
|
54
|
+
*/
|
|
55
|
+
const UNSUPPORTED_GATE_HINTS = {
|
|
56
|
+
intent: '第 1 阶的意图门控由 project_run 的参数(intentConfidence / blindspots)负责,不在 flow.yaml 里配。',
|
|
57
|
+
assertions_exit_zero: '判据执行发生在第 4 阶质检,用 Requirement.md 前置块里的 check 命令,不在 flow.yaml 里配。',
|
|
58
|
+
verdict: '质检判 FAIL 后按问题清单返工,由 flow.yaml 最后一个 phase 的 on_fail 表达,不用 gate.kind=verdict。',
|
|
59
|
+
}
|
|
26
60
|
|
|
27
61
|
/** 内置四阶的 id。不在这四个里的环节要靠 instructions 才知道该做什么。 */
|
|
28
62
|
const BUILTIN_PHASE_IDS = ['requirement', 'plan', 'build', 'qa']
|
|
@@ -116,6 +150,67 @@ function splitTopLevel(text, sep) {
|
|
|
116
150
|
* 返回 { value, errors }。errors 每条 { line, message },value 可能残缺——
|
|
117
151
|
* 语法错了就别拿它跑,但要把能读出来的部分带回去,方便报错时说清哪一段坏了。
|
|
118
152
|
*/
|
|
153
|
+
/**
|
|
154
|
+
* 把块标量(`key: |` / `key: >`)的内容拼成一个字符串。
|
|
155
|
+
*
|
|
156
|
+
* 块标量的内容行必须按原样保留——里面的 `#` 不是注释,空行不是「没内容」。
|
|
157
|
+
* 所以这一步在读原始行时做,不走 stripComment,也不走「跳过空行」。
|
|
158
|
+
*
|
|
159
|
+
* @param lines 原始行数组
|
|
160
|
+
* @param start 标题行的下一行下标
|
|
161
|
+
* @param headerIndent 标题行的缩进
|
|
162
|
+
* @returns {{ text:string, next:number }}
|
|
163
|
+
*/
|
|
164
|
+
function readBlockScalar(lines, start, headerIndent, style, chomp) {
|
|
165
|
+
const body = []
|
|
166
|
+
let cursor = start
|
|
167
|
+
let contentIndent = -1
|
|
168
|
+
while (cursor < lines.length) {
|
|
169
|
+
const line = lines[cursor]
|
|
170
|
+
if (line.trim() === '') {
|
|
171
|
+
// 空行属于内容,但它同时也会终止「还没确定缩进」的阶段
|
|
172
|
+
body.push('')
|
|
173
|
+
cursor += 1
|
|
174
|
+
continue
|
|
175
|
+
}
|
|
176
|
+
const indent = line.length - line.trimStart().length
|
|
177
|
+
if (indent <= headerIndent) break
|
|
178
|
+
if (contentIndent === -1) contentIndent = indent
|
|
179
|
+
// 缩进比基准少的行(但仍在标题之下)保留相对缩进,别把用户的排版吃掉
|
|
180
|
+
body.push(line.length >= contentIndent ? line.slice(contentIndent) : line.trimStart())
|
|
181
|
+
cursor += 1
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 尾部空行按 chomp 规则处理:- 全删,默认留一个换行,+ 全留
|
|
185
|
+
let trailing = 0
|
|
186
|
+
while (body.length - trailing > 0 && body[body.length - 1 - trailing].trim() === '') trailing += 1
|
|
187
|
+
const core = body.slice(0, body.length - trailing)
|
|
188
|
+
|
|
189
|
+
let text
|
|
190
|
+
if (style === '|') {
|
|
191
|
+
text = core.join('\n')
|
|
192
|
+
} else {
|
|
193
|
+
// `>` 折叠:相邻非空行用空格连起来,空行变成换行
|
|
194
|
+
const out = []
|
|
195
|
+
for (const line of core) {
|
|
196
|
+
if (line.trim() === '') out.push('\n')
|
|
197
|
+
else if (out.length === 0) out.push(line)
|
|
198
|
+
else if (out[out.length - 1] === '\n') out.push(line)
|
|
199
|
+
else out[out.length - 1] += ` ${line}`
|
|
200
|
+
}
|
|
201
|
+
text = out.join('')
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (chomp === '-') {
|
|
205
|
+
text = text.replace(/\n+$/u, '')
|
|
206
|
+
} else if (chomp === '+') {
|
|
207
|
+
text = `${text}${'\n'.repeat(trailing)}`
|
|
208
|
+
} else if (text !== '') {
|
|
209
|
+
text = `${text}\n`
|
|
210
|
+
}
|
|
211
|
+
return { text, next: cursor }
|
|
212
|
+
}
|
|
213
|
+
|
|
119
214
|
export function parseFlowYaml(text) {
|
|
120
215
|
const errors = []
|
|
121
216
|
const root = {}
|
|
@@ -124,16 +219,42 @@ export function parseFlowYaml(text) {
|
|
|
124
219
|
}
|
|
125
220
|
|
|
126
221
|
// 预处理:留下有内容的行,记住原行号。
|
|
222
|
+
//
|
|
223
|
+
// 块标量在这一步就吃掉:它的内容行里 `#` 不是注释、空行也算内容,
|
|
224
|
+
// 交给后面那套「剥注释 + 跳过空行」的流程会被啃得只剩半句。
|
|
127
225
|
const rows = []
|
|
128
226
|
const rawLines = text.split(/\r?\n/u)
|
|
129
|
-
|
|
227
|
+
let i = 0
|
|
228
|
+
while (i < rawLines.length) {
|
|
130
229
|
const stripped = stripComment(rawLines[i])
|
|
131
|
-
if (stripped.trim() === '') continue
|
|
230
|
+
if (stripped.trim() === '') { i += 1; continue }
|
|
132
231
|
const indent = stripped.length - stripped.trimStart().length
|
|
133
|
-
|
|
232
|
+
const trimmed = stripped.trim()
|
|
233
|
+
|
|
234
|
+
// 只认「一行一个 key: |」的写法;`- id: |` 这种挂在下标量上的不处理,
|
|
235
|
+
// 它极少出现,而且要处理得连下标量的缩进一起算,容易把别的写法读飞。
|
|
236
|
+
const header = /^([^\-|>][^:]*?):\s*([|>])([+-]?)\s*$/u.exec(trimmed)
|
|
237
|
+
if (header !== null) {
|
|
238
|
+
const style = header[2]
|
|
239
|
+
const chomp = header[3]
|
|
240
|
+
const block = readBlockScalar(rawLines, i + 1, indent, style, chomp)
|
|
241
|
+
rows.push({ indent, text: `${header[1]}:`, blockValue: block.text, line: i + 1 })
|
|
242
|
+
i = block.next
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
rows.push({ indent, text: trimmed, line: i + 1 })
|
|
247
|
+
i += 1
|
|
134
248
|
}
|
|
135
249
|
if (rows.length === 0) return { value: root, errors: [{ line: 0, message: '文件里只有注释' }] }
|
|
136
250
|
|
|
251
|
+
// 块标量的值按原行号存一份:consumeMapEntry 拿得到行号,用不着靠遍历去找,
|
|
252
|
+
// 也不怕两行恰好同号(`- id: |` 这种目前不处理,但索引方式不该依赖它)。
|
|
253
|
+
const blockValues = new Map()
|
|
254
|
+
for (const row of rows) {
|
|
255
|
+
if (row.blockValue !== undefined) blockValues.set(row.line, row.blockValue)
|
|
256
|
+
}
|
|
257
|
+
|
|
137
258
|
let cursor = 0
|
|
138
259
|
|
|
139
260
|
/** 解析一个缩进块,返回 [值, 是否 seq]。 */
|
|
@@ -157,6 +278,15 @@ export function parseFlowYaml(text) {
|
|
|
157
278
|
}
|
|
158
279
|
continue
|
|
159
280
|
}
|
|
281
|
+
// `- 一个纯标量`(不是 `- key: value`):这一项就是那个值本身。
|
|
282
|
+
// 以前不看这一条,一律当 map 项处理,于是 `reads:\n - a.md` 会变成
|
|
283
|
+
// [{}, {}] 加一句「看不懂」——README 里最常见的一种写法直接读不了。
|
|
284
|
+
if (findColon(rest) === -1) {
|
|
285
|
+
const inline = inlineValue(rest)
|
|
286
|
+
arr.push(inline === null ? scalar(rest) : inline)
|
|
287
|
+
cursor += 1
|
|
288
|
+
continue
|
|
289
|
+
}
|
|
160
290
|
// `- id: xxx`:这一个 seq 项本身就是个 map,横杠后面那截是它的第一行。
|
|
161
291
|
// 后续的兄弟字段缩进必须正好对齐这第一行内容的起始列,多一格少一格都不算。
|
|
162
292
|
// 早先按 `indent + 2` 硬算,遇到 `- id:` 这种多个空格的写法就对不上,
|
|
@@ -164,6 +294,10 @@ export function parseFlowYaml(text) {
|
|
|
164
294
|
const pad = restRaw.length - restRaw.trimStart().length
|
|
165
295
|
const itemIndent = indent + 2 + pad
|
|
166
296
|
const item = {}
|
|
297
|
+
// 把起始行号挂在这个节点上(不可枚举的 symbol,不进 JSON、不影响深比较),
|
|
298
|
+
// 校验阶段报错时就能指到具体第几行。以前一律 line: 0,
|
|
299
|
+
// 文档承诺的「报错带行号」其实只对语法错成立,语义错给不出位置。
|
|
300
|
+
Object.defineProperty(item, NODE_LINE, { value: row.line, enumerable: false })
|
|
167
301
|
cursor += 1
|
|
168
302
|
consumeMapEntry(item, rest, row.line, itemIndent)
|
|
169
303
|
while (cursor < rows.length && rows[cursor].indent === itemIndent) {
|
|
@@ -176,6 +310,7 @@ export function parseFlowYaml(text) {
|
|
|
176
310
|
return [arr, true]
|
|
177
311
|
}
|
|
178
312
|
const obj = {}
|
|
313
|
+
Object.defineProperty(obj, NODE_LINE, { value: rows[cursor]?.line ?? 0, enumerable: false })
|
|
179
314
|
while (cursor < rows.length && rows[cursor].indent === indent) {
|
|
180
315
|
const row = rows[cursor]
|
|
181
316
|
cursor += 1
|
|
@@ -186,6 +321,8 @@ export function parseFlowYaml(text) {
|
|
|
186
321
|
|
|
187
322
|
/** 吃一条 `key: value`,value 空的话继续往下吃子块。 */
|
|
188
323
|
function consumeMapEntry(target, text, line, indent) {
|
|
324
|
+
// 块标量:值已经在预处理阶段拼好了,直接放进去。
|
|
325
|
+
const blockValue = blockValues.get(line)
|
|
189
326
|
const at = findColon(text)
|
|
190
327
|
if (at === -1) {
|
|
191
328
|
errors.push({ line, message: `这一行看不懂,应该是 \`键: 值\` 的形式:${text}` })
|
|
@@ -197,6 +334,10 @@ export function parseFlowYaml(text) {
|
|
|
197
334
|
errors.push({ line, message: '冒号前面没有键名' })
|
|
198
335
|
return
|
|
199
336
|
}
|
|
337
|
+
if (blockValue !== undefined) {
|
|
338
|
+
target[key] = blockValue
|
|
339
|
+
return
|
|
340
|
+
}
|
|
200
341
|
if (rest === '') {
|
|
201
342
|
// 往下找子块。缩进必须更深,否则就是空值。
|
|
202
343
|
if (cursor < rows.length && rows[cursor].indent > indent) {
|
|
@@ -295,57 +436,60 @@ export function validateFlow(doc) {
|
|
|
295
436
|
|
|
296
437
|
const seen = new Set()
|
|
297
438
|
rawPhases.forEach((raw, index) => {
|
|
439
|
+
const at = lineOf(raw)
|
|
298
440
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
299
|
-
err(
|
|
441
|
+
err(at, `第 ${index + 1} 个环节不是 map`)
|
|
300
442
|
return
|
|
301
443
|
}
|
|
302
444
|
const id = typeof raw.id === 'string' ? raw.id.trim() : ''
|
|
303
445
|
if (id === '') {
|
|
304
|
-
err(
|
|
446
|
+
err(at, `第 ${index + 1} 个环节没有 \`id\`:环节之间靠 id 互相指,缺了就连不起来`)
|
|
305
447
|
return
|
|
306
448
|
}
|
|
307
449
|
if (seen.has(id)) {
|
|
308
|
-
err(
|
|
450
|
+
err(at, `环节 id \`${id}\` 重复了`)
|
|
309
451
|
return
|
|
310
452
|
}
|
|
311
453
|
seen.add(id)
|
|
312
454
|
|
|
455
|
+
// 不认识的键直接报错。以前只给 warning,而 warnings 不拦运行——
|
|
456
|
+
// 写错一个键名,配置看着生效了,实际整段被忽略。
|
|
313
457
|
for (const key of Object.keys(raw)) {
|
|
314
|
-
if (!PHASE_KEYS.includes(key))
|
|
458
|
+
if (!PHASE_KEYS.includes(key)) {
|
|
459
|
+
err(at, `环节 \`${id}\` 有不认识的键 \`${key}\`(只认 ${PHASE_KEYS.join(' / ')})`)
|
|
460
|
+
}
|
|
315
461
|
}
|
|
316
462
|
|
|
317
463
|
// 内置四阶各有专用实现,不写 instructions 也知道干什么。
|
|
318
464
|
// 别的环节没有专用实现,只能靠 instructions——不写就别指望它跑出东西来。
|
|
319
465
|
const instructions = typeof raw.instructions === 'string' ? raw.instructions.trim() : ''
|
|
320
466
|
if (!BUILTIN_PHASE_IDS.includes(id) && instructions === '') {
|
|
321
|
-
warn(
|
|
467
|
+
warn(at, `环节 \`${id}\` 不是内置四阶之一,又没写 \`instructions\`:跑起来会因为不知道该做什么而被跳过`)
|
|
322
468
|
}
|
|
323
469
|
|
|
324
470
|
const reads = normalizeStringList(raw.reads)
|
|
325
471
|
const writes = normalizeStringList(raw.writes)
|
|
326
|
-
if (reads === null) err(
|
|
327
|
-
if (writes === null) err(
|
|
472
|
+
if (reads === null) err(at, `环节 \`${id}\` 的 \`reads\` 必须是列表`)
|
|
473
|
+
if (writes === null) err(at, `环节 \`${id}\` 的 \`writes\` 必须是列表`)
|
|
328
474
|
|
|
329
475
|
const gate = raw.gate
|
|
330
476
|
if (gate === undefined || gate === null) {
|
|
331
|
-
warn(
|
|
477
|
+
warn(at, `环节 \`${id}\` 没写 \`gate\`,这一阶不设门禁`)
|
|
332
478
|
} else if (typeof gate !== 'object' || Array.isArray(gate)) {
|
|
333
|
-
err(
|
|
479
|
+
err(at, `环节 \`${id}\` 的 \`gate\` 必须是 map`)
|
|
334
480
|
} else {
|
|
335
481
|
for (const key of Object.keys(gate)) {
|
|
336
|
-
if (!GATE_KEYS.includes(key))
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (gate.min_score !== undefined && !Number.isInteger(gate.min_score)) {
|
|
342
|
-
warn(0, `环节 \`${id}\` 的 \`gate.min_score\` 应该是整数`)
|
|
343
|
-
}
|
|
344
|
-
if (gate.max_rework !== undefined && !Number.isInteger(gate.max_rework)) {
|
|
345
|
-
warn(0, `环节 \`${id}\` 的 \`gate.max_rework\` 应该是整数`)
|
|
482
|
+
if (!GATE_KEYS.includes(key)) {
|
|
483
|
+
// gate 里的键要么执行器认,要么直接报错。以前只是 warn,
|
|
484
|
+
// 而 warnings 不拦运行——写错了照样往下跑,用户以为配上了。
|
|
485
|
+
err(at, `环节 \`${id}\` 的 gate 里有执行器不支持的键 \`${key}\`(只认 ${GATE_KEYS.join(' / ')})`)
|
|
486
|
+
}
|
|
346
487
|
}
|
|
347
|
-
if (
|
|
348
|
-
|
|
488
|
+
if (gate.kind !== undefined && !SUPPORTED_GATE_KINDS.includes(gate.kind)) {
|
|
489
|
+
const hint = UNSUPPORTED_GATE_HINTS[gate.kind]
|
|
490
|
+
err(at, hint === undefined
|
|
491
|
+
? `环节 \`${id}\` 的 \`gate.kind\` 写的是 \`${gate.kind}\`,执行器只实现 ${SUPPORTED_GATE_KINDS.join(' / ')}`
|
|
492
|
+
: `环节 \`${id}\` 的 \`gate.kind: ${gate.kind}\` 没有接进执行流程。${hint}`)
|
|
349
493
|
}
|
|
350
494
|
}
|
|
351
495
|
|
|
@@ -357,12 +501,18 @@ export function validateFlow(doc) {
|
|
|
357
501
|
gate: gate === undefined || gate === null ? null : gate,
|
|
358
502
|
model: raw.model === undefined ? null : raw.model,
|
|
359
503
|
instructions: typeof raw.instructions === 'string' ? raw.instructions : '',
|
|
360
|
-
onSuccess: typeof raw.on_success === 'string' ? raw.on_success.trim() : '',
|
|
361
|
-
onGateFail: typeof raw.on_gate_fail === 'string' ? raw.on_gate_fail.trim() : '',
|
|
362
504
|
})
|
|
363
505
|
})
|
|
364
506
|
|
|
365
|
-
//
|
|
507
|
+
// on_success / on_gate_fail 从 schema 里撤掉了:执行器没有跳转能力。
|
|
508
|
+
//
|
|
509
|
+
// 它们以前被解析、被校验(连「只能指向前面的环节」这种讲究都写了),
|
|
510
|
+
// 但执行器从头到尾没读过这两个字段——写进去等于写了个注释。
|
|
511
|
+
// 「gate.on_fail」是唯一真在用的返工入口(阶段级),保留。
|
|
512
|
+
//
|
|
513
|
+
// 报错已经在上面的 PHASE_KEYS 检查里给出了(带行号),这里不再重复一遍。
|
|
514
|
+
|
|
515
|
+
// gate.on_fail 只能指向前面出现过的环节。
|
|
366
516
|
//
|
|
367
517
|
// 指到后面会成环:A 失败跳 B、B 失败跳 A,跑起来就是无限循环,
|
|
368
518
|
// 而 max_rework 管的是「同一个环节返工几次」,管不了跨环节来回跳。
|
|
@@ -379,8 +529,6 @@ export function validateFlow(doc) {
|
|
|
379
529
|
}
|
|
380
530
|
}
|
|
381
531
|
for (const phase of phases) {
|
|
382
|
-
checkTarget(phase, phase.onSuccess, 'on_success')
|
|
383
|
-
checkTarget(phase, phase.onGateFail, 'on_gate_fail')
|
|
384
532
|
const gateFail = phase.gate !== null && typeof phase.gate === 'object' ? phase.gate.on_fail : undefined
|
|
385
533
|
if (typeof gateFail === 'string' && gateFail.trim() !== '') {
|
|
386
534
|
checkTarget(phase, gateFail.trim(), 'gate.on_fail')
|
|
@@ -432,12 +580,21 @@ export function describeFlowProblems(result) {
|
|
|
432
580
|
}
|
|
433
581
|
|
|
434
582
|
/** 内置四阶。没有 flow.yaml 时就是它,行为和 0.8.x 完全一致。 */
|
|
583
|
+
/**
|
|
584
|
+
* 不装 flow.yaml 时用的内置四阶。
|
|
585
|
+
*
|
|
586
|
+
* gate.kind 只写 artifact_present:另外那三个(intent / verdict /
|
|
587
|
+
* assertions_exit_zero)是写死的流程逻辑,不在执行器的 gate 分发里。
|
|
588
|
+
* 以前这份默认值写着 intent / verdict / assertions_exit_zero,于是
|
|
589
|
+
* 「默认配置自己过不了自己的校验」——把这份对象原样喂回 validateFlow 会报三条错。
|
|
590
|
+
* 现在默认值和执行能力对齐,测试里有一条专门守着这件事。
|
|
591
|
+
*/
|
|
435
592
|
export const BUILTIN_FLOW = {
|
|
436
593
|
process: { name: 'four-stage', version: 1 },
|
|
437
594
|
phases: [
|
|
438
|
-
{ id: 'requirement', reads: [], writes: ['Requirement.md']
|
|
595
|
+
{ id: 'requirement', reads: [], writes: ['Requirement.md'] },
|
|
439
596
|
{ id: 'plan', reads: ['Requirement.md'], writes: ['Plan.md'], gate: { kind: 'artifact_present' } },
|
|
440
|
-
{ id: 'build', reads: ['Plan.md'], writes: ['Execution_Log.md'], gate: { kind: '
|
|
441
|
-
{ id: 'qa', reads: ['Requirement.md', 'Plan.md', 'Execution_Log.md'], writes: ['QA_Report.md'], gate: { kind: '
|
|
597
|
+
{ id: 'build', reads: ['Plan.md'], writes: ['Execution_Log.md'], gate: { kind: 'artifact_present' } },
|
|
598
|
+
{ id: 'qa', reads: ['Requirement.md', 'Plan.md', 'Execution_Log.md'], writes: ['QA_Report.md'], gate: { kind: 'artifact_present', on_fail: 'build' } },
|
|
442
599
|
],
|
|
443
600
|
}
|
package/gate.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* 意图澄清门控(readiness gate)核心逻辑,纯函数、无 I/O。
|
|
3
3
|
*
|
|
4
4
|
* v2 改造要点——把「总分」和「扣分清单」并成一张表:
|
|
@@ -97,7 +97,7 @@ export function extractReadiness(text) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/** 归一化一条结论:去空白、压空格、限长。空串返回 ''。 */
|
|
100
|
-
function normalizeLine(value, cap = 200) {
|
|
100
|
+
export function normalizeLine(value, cap = 200) {
|
|
101
101
|
if (typeof value !== 'string') return ''
|
|
102
102
|
const line = value.trim().replace(/\s+/gu, ' ')
|
|
103
103
|
if (line === '') return ''
|
|
@@ -107,13 +107,46 @@ function normalizeLine(value, cap = 200) {
|
|
|
107
107
|
/**
|
|
108
108
|
* 这条结论算不算「真的写了」。
|
|
109
109
|
* 空串不算;去掉空白和标点后不够 MIN_CONCLUSION_LENGTH 个字也不算——
|
|
110
|
-
*
|
|
110
|
+
* 「已确认。」这类凑数的话在这一步就被拦下,而不是等质检才发现。
|
|
111
111
|
*/
|
|
112
|
-
function isFilled(line) {
|
|
112
|
+
export function isFilled(line) {
|
|
113
113
|
if (line === '') return false
|
|
114
114
|
return line.replace(/[\s\p{P}]/gu, '').length >= MIN_CONCLUSION_LENGTH
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 五维盲区判定的唯一实现。
|
|
119
|
+
*
|
|
120
|
+
* 这里是「一份逻辑两处用」的那个「一份」:`evaluateReadiness` 拿它算裁决,
|
|
121
|
+
* `project_run` 拿它决定要不要拒跑。以前 index.js 里另抄了一份逐字相同的
|
|
122
|
+
* 循环,改一边另一边不知道,两套测试于是测着两个不同的东西。
|
|
123
|
+
*
|
|
124
|
+
* @param blindspots 模型交上来的原始对象,可能是 null / 数组 / 字符串
|
|
125
|
+
* @returns {{ lines:Record<string,string>, empty:string[], vague:string[], gaps:number }}
|
|
126
|
+
* lines 归一化后的结论(键永远是五个维度);empty 是没写的;vague 是写了但太笼统的。
|
|
127
|
+
*/
|
|
128
|
+
export function blindspotGaps(blindspots) {
|
|
129
|
+
const record = blindspots !== null && typeof blindspots === 'object' && !Array.isArray(blindspots)
|
|
130
|
+
? blindspots
|
|
131
|
+
: {}
|
|
132
|
+
const lines = {}
|
|
133
|
+
const empty = []
|
|
134
|
+
const vague = []
|
|
135
|
+
for (const dim of DIMENSIONS) {
|
|
136
|
+
const line = normalizeLine(record[dim.key])
|
|
137
|
+
lines[dim.key] = line
|
|
138
|
+
if (line === '') empty.push(dim.key)
|
|
139
|
+
else if (!isFilled(line)) vague.push(dim.key)
|
|
140
|
+
}
|
|
141
|
+
return { lines, empty, vague, gaps: empty.length + vague.length }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 维度 key → 中文名。写报错文案时用。 */
|
|
145
|
+
export function dimensionLabel(key) {
|
|
146
|
+
const hit = DIMENSIONS.find(d => d.key === key)
|
|
147
|
+
return hit === undefined ? String(key) : hit.label
|
|
148
|
+
}
|
|
149
|
+
|
|
117
150
|
/** 归一化假设列表:去空白、去空串、去重、限条数。 */
|
|
118
151
|
function normalizeList(value, cap = 12) {
|
|
119
152
|
if (!Array.isArray(value)) return []
|
|
@@ -206,29 +239,22 @@ export function evaluateReadiness(raw) {
|
|
|
206
239
|
}
|
|
207
240
|
|
|
208
241
|
// ---- 逐维度归一化,记下空着的和写得太笼统的 ----
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
blindspots[
|
|
216
|
-
|
|
217
|
-
emptyBlindspots.push(dim.key)
|
|
218
|
-
emptyLabels.push(dim.label)
|
|
219
|
-
} else if (!isFilled(line)) {
|
|
220
|
-
vagueBlindspots.push(dim.key)
|
|
221
|
-
emptyLabels.push(`${dim.label}(「${line}」太笼统)`)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
242
|
+
const gap = blindspotGaps(raw.blindspots)
|
|
243
|
+
const blindspots = gap.lines
|
|
244
|
+
const emptyBlindspots = gap.empty
|
|
245
|
+
const vagueBlindspots = gap.vague
|
|
246
|
+
const emptyLabels = [
|
|
247
|
+
...emptyBlindspots.map(dimensionLabel),
|
|
248
|
+
...vagueBlindspots.map(key => `${dimensionLabel(key)}(「${blindspots[key]}」太笼统)`),
|
|
249
|
+
]
|
|
224
250
|
|
|
225
251
|
// ---- 两个条件独立判,都满足才放行 ----
|
|
226
252
|
const scoreShort = score === null || score < SCORE_FLOOR
|
|
227
253
|
const gapsPresent = emptyBlindspots.length > 0 || vagueBlindspots.length > 0
|
|
228
254
|
|
|
229
255
|
if (scoreShort) unmet.push(`score 只有 ${score ?? '(缺失)'},没到 ${SCORE_FLOOR}`)
|
|
230
|
-
if (emptyBlindspots.length > 0) unmet.push(`这 ${emptyBlindspots.length} 个维度还没有结论:${emptyBlindspots.map(
|
|
231
|
-
if (vagueBlindspots.length > 0) unmet.push(`这 ${vagueBlindspots.length} 个维度写得太笼统,要说具体结论:${vagueBlindspots.map(
|
|
256
|
+
if (emptyBlindspots.length > 0) unmet.push(`这 ${emptyBlindspots.length} 个维度还没有结论:${emptyBlindspots.map(dimensionLabel).join('、')}`)
|
|
257
|
+
if (vagueBlindspots.length > 0) unmet.push(`这 ${vagueBlindspots.length} 个维度写得太笼统,要说具体结论:${vagueBlindspots.map(dimensionLabel).join('、')}`)
|
|
232
258
|
|
|
233
259
|
if (scoreShort || gapsPresent) {
|
|
234
260
|
return {
|
|
@@ -385,5 +411,5 @@ export function buttonState(readiness) {
|
|
|
385
411
|
assumptions: verdict.assumptions,
|
|
386
412
|
}
|
|
387
413
|
}
|
|
388
|
-
|
|
389
|
-
|
|
414
|
+
|
|
415
|
+
|