cardbuddy 0.15.0 → 0.16.0
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/dist/preview-editor/assets/index-BkbBxDTT.css +1 -0
- package/dist/preview-editor/assets/{index-CIIfMlwI.js → index-Bro07DTa.js} +91 -88
- package/dist/preview-editor/index.html +2 -2
- package/dist/vendored/card-editor/runtime/adapter.js +2 -2
- package/dist/vendored/mcp/client.mjs +1 -1
- package/dist/vendored/server/core/ai-chat.js +251 -80
- package/dist/vendored/server/core/cardValidate.js +16 -5
- package/dist/vendored/skills/card-skill-trainer/SKILL.md +61 -6
- package/dist/vendored/skills/card-skill-trainer/scripts/diagnose_case.mjs +14 -82
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/diagnosis.mjs +207 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/layout-correction-sim.mjs +62 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/paradigm-router.mjs +76 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/pixel-worker-runner.mjs +31 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/pixel-worker.mjs +138 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/scoring.mjs +24 -20
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/telemetry.mjs +46 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/plan_next_round.mjs +4 -1
- package/dist/vendored/skills/card-skill-trainer/scripts/run_round.mjs +279 -90
- package/dist/vendored/skills/card-skill-trainer/scripts/score_round.mjs +74 -2
- package/dist/vendored/skills/card-skill-trainer/scripts/sink_rules.mjs +127 -0
- package/dist/vendored/skills/dsl-card-generator/SKILL.md +93 -27
- package/dist/vendored/skills/dsl-card-generator/references/dsl_structure.md +1 -15
- package/dist/vendored/skills/dsl-card-generator/references/expression_engine.md +11 -20
- package/dist/vendored/skills/dsl-card-generator/references/generation_pitfalls.md +169 -44
- package/dist/vendored/skills/dsl-card-generator/references/ir-format.md +87 -3
- package/dist/vendored/skills/dsl-card-generator/references/iteration_protocol.md +35 -6
- package/dist/vendored/skills/dsl-card-generator/references/quickref.md +28 -27
- package/dist/vendored/skills/dsl-card-generator/references/recipes.md +30 -8
- package/dist/vendored/skills/dsl-card-generator/references/rules.md +3 -2
- package/dist/vendored/skills/dsl-card-generator/references/scripts_reference.md +5 -2
- package/dist/vendored/skills/dsl-card-generator/references/slices_convention.md +2 -3
- package/dist/vendored/skills/dsl-card-generator/references/spec_to_schema_patterns.md +1 -4
- package/dist/vendored/skills/dsl-card-generator/scripts/add_component.mjs +5 -14
- package/dist/vendored/skills/dsl-card-generator/scripts/autofix_schema.py +88 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/check_fidelity.mjs +143 -42
- package/dist/vendored/skills/dsl-card-generator/scripts/check_topology.py +0 -35
- package/dist/vendored/skills/dsl-card-generator/scripts/expand_ir.mjs +99 -53
- package/dist/vendored/skills/dsl-card-generator/scripts/gate.mjs +5 -2
- package/dist/vendored/skills/dsl-card-generator/scripts/iterate.mjs +388 -29
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/component_contract.mjs +315 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/layout-tokens.mjs +1 -1
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/paths.mjs +23 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/paths.py +0 -37
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/python.mjs +99 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/adaptive-width.mjs +105 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/bindings.mjs +260 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/expr.mjs +52 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/image.mjs +96 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/registry.mjs +166 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/structure.mjs +127 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/rules/walk.mjs +61 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/scope_alias.mjs +125 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_assemble.mjs +325 -41
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_extract.mjs +112 -6
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/v3_shared.mjs +0 -6
- package/dist/vendored/skills/dsl-card-generator/scripts/lint_card.mjs +119 -78
- package/dist/vendored/skills/dsl-card-generator/scripts/preflight.mjs +48 -50
- package/dist/vendored/skills/dsl-card-generator/scripts/readiness.mjs +634 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/register_card_template.mjs +5 -8
- package/dist/vendored/skills/dsl-card-generator/scripts/route_input.mjs +5 -10
- package/dist/vendored/skills/dsl-card-generator/scripts/spec_audit.mjs +122 -8
- package/dist/vendored/skills/dsl-card-generator/scripts/v3_regression.mjs +3 -1
- package/dist/vendored/skills/dsl-card-generator/scripts/validate_schema.py +23 -15
- package/dist/vendored/skills/shared/exit-codes.md +79 -0
- package/dist/vendored/skills/shared/spec-contract.md +118 -0
- package/dist/vendored/skills/sketch-spec-to-card/SKILL.md +26 -9
- package/dist/vendored/skills/sketch-spec-to-card/references/spec-schema.md +3 -3
- package/dist/vendored/skills/sketch-spec-to-card/scripts/build_prompt.py +0 -8
- package/dist/vendored/skills/sketch-spec-to-card/scripts/cluster_states.py +14 -25
- package/dist/vendored/skills/sketch-spec-to-card/scripts/parse_meaxure.py +91 -47
- package/dist/vendored/skills/sketch-spec-to-card/scripts/png_utils.py +0 -5
- package/dist/vendored/skills/sketch-spec-to-card/scripts/test_text_only_artboard.py +75 -15
- package/dist/vendored/skills/sketch-spec-to-card/scripts/vision.py +40 -34
- package/package.json +1 -1
- package/dist/preview-editor/assets/index-DQn0zQBP.css +0 -1
- package/dist/vendored/skills/card-skill-trainer/scripts/test_missing_slice.py +0 -122
- package/dist/vendored/skills/dsl-card-generator/scripts/analyze_component_usage.mjs +0 -153
|
@@ -43,19 +43,30 @@ import { rewriteSliceRefs } from './lib/slice_dedupe.mjs'
|
|
|
43
43
|
import { auditGeometry, describeGeometry } from './lib/geometry_audit.mjs'
|
|
44
44
|
import { lint } from './lint_card.mjs'
|
|
45
45
|
import { buildFidelityReport } from './check_fidelity.mjs'
|
|
46
|
+
import { buildReadinessReport } from './readiness.mjs'
|
|
46
47
|
import { createRenderSession, renderCardScreenshot } from './render_card.mjs'
|
|
47
48
|
import { copyCardDesignImage } from './lib/design_image.mjs'
|
|
48
|
-
import { cardsDir, cardSchemaPath, cardDataPath, readJson, repoRoot } from './lib/paths.mjs'
|
|
49
|
+
import { cardsDir, cardSchemaPath, cardDataPath, readJson, repoRoot, scratchDir as SCRATCH_DIR } from './lib/paths.mjs'
|
|
49
50
|
|
|
50
51
|
const { PNG } = await import('pngjs')
|
|
51
52
|
|
|
52
53
|
const DEFAULT_DIFF_DIR = path.join(repoRoot, '.card-diffs')
|
|
53
54
|
const DEFAULT_WIDTH = 375
|
|
54
|
-
/** 报告落盘目录:门禁(--gate
|
|
55
|
-
|
|
55
|
+
/** 报告落盘目录:门禁(--gate)只认这里的机器产物,不认模型自述。
|
|
56
|
+
* 路径单源在 lib/paths.mjs(check_fidelity / readiness 也读同一份 —— 历史事故:
|
|
57
|
+
* check_fidelity 自己拼 `<cardDir>/.audit.json`,真实位置却是 `.cache/ai-scratch/`)。 */
|
|
56
58
|
const PREFLIGHT_SCRIPT = path.join(repoRoot, 'skills', 'dsl-card-generator', 'scripts', 'preflight.mjs')
|
|
57
|
-
/** 收敛门禁阈值(协议 S5/S6
|
|
58
|
-
|
|
59
|
+
/** 收敛门禁阈值(协议 S5/S6 的机器化版本,改这里即改门禁)。
|
|
60
|
+
* match 是**唯一权威**:SKILL.md 只引用这里的语义,不复制具体数字,
|
|
61
|
+
* 避免「文档写 85、代码判 95」导致模型提前收工被 --gate 判 FAIL 返工。
|
|
62
|
+
* 可用环境变量 DSL_CARD_GATE_MATCH 覆盖(非法/空值回落默认)。 */
|
|
63
|
+
const GATE_MATCH_OVERRIDE = Number(process.env.DSL_CARD_GATE_MATCH)
|
|
64
|
+
const GATE = {
|
|
65
|
+
match: Number.isFinite(GATE_MATCH_OVERRIDE) && GATE_MATCH_OVERRIDE > 0 ? GATE_MATCH_OVERRIDE : 95,
|
|
66
|
+
heightDelta: 0,
|
|
67
|
+
widthDelta: 0,
|
|
68
|
+
contentOffset1x: 2,
|
|
69
|
+
}
|
|
59
70
|
|
|
60
71
|
/* ── IR 原子编辑(--set)────────────────────────────────────
|
|
61
72
|
* 点路径寻址,数字段按数组下标:children.0.s.margin.marginTop="7"
|
|
@@ -230,6 +241,59 @@ function diffHotspots(renderPng, designPng, { cols = 4, rows = 8, floorPct = 3,
|
|
|
230
241
|
return cells.slice(0, maxCells)
|
|
231
242
|
}
|
|
232
243
|
|
|
244
|
+
/* ── 结构性缺口(structuralGaps):逐行几乎全异的连续带区 ──
|
|
245
|
+
* 存在理由(gen-1 实测):雷达图区块整块漏建 / 背景整卡错涂时,hotspots 只给碎片坐标、
|
|
246
|
+
* contributors 把注意力引到「10分/分」这类局部微调,模型调了 8 轮 padding/gap 也没碰到根因。
|
|
247
|
+
* 口径:逐行统计 design vs render 的像素差异率(色距 >30),连续 ≥40pt(1x)且差异率 ≥85%
|
|
248
|
+
* 的带区记为缺口带——要么该带内容整块漏建,要么底色/背景在该带整层错涂;只报事实不猜因。 */
|
|
249
|
+
export function detectStructuralGaps(renderPng, designPng, { scale = 2, minGapPt = 40, maxGaps = 3, rowDiff = 0.85 } = {}) {
|
|
250
|
+
const h = Math.min(renderPng.height, designPng.height)
|
|
251
|
+
const w = Math.min(renderPng.width, designPng.width)
|
|
252
|
+
const step = 2
|
|
253
|
+
const rows = []
|
|
254
|
+
for (let y = 0; y < h; y += step) {
|
|
255
|
+
let diff = 0
|
|
256
|
+
let seen = 0
|
|
257
|
+
for (let x = 0; x < w; x += step) {
|
|
258
|
+
const i = (y * w + x) * 4
|
|
259
|
+
const dr = Math.abs(renderPng.data[i] - designPng.data[i])
|
|
260
|
+
const dg = Math.abs(renderPng.data[i + 1] - designPng.data[i + 1])
|
|
261
|
+
const db = Math.abs(renderPng.data[i + 2] - designPng.data[i + 2])
|
|
262
|
+
if (Math.max(dr, dg, db) > 30) diff++
|
|
263
|
+
seen++
|
|
264
|
+
}
|
|
265
|
+
rows.push({ y, ratio: diff / seen })
|
|
266
|
+
}
|
|
267
|
+
// 设计稿行墨量(供归因参考:该带在设计稿里有多少内容)
|
|
268
|
+
const isInk = (png, x, y) => {
|
|
269
|
+
const i = (y * png.width + x) * 4
|
|
270
|
+
if (png.data[i + 3] < 8) return false
|
|
271
|
+
return Math.abs(255 - png.data[i]) + Math.abs(255 - png.data[i + 1]) + Math.abs(255 - png.data[i + 2]) > 48
|
|
272
|
+
}
|
|
273
|
+
const gaps = []
|
|
274
|
+
let cur = null
|
|
275
|
+
for (const r of rows) {
|
|
276
|
+
if (r.ratio >= rowDiff) {
|
|
277
|
+
if (!cur) cur = { y0: r.y, y1: r.y, ink: [] }
|
|
278
|
+
else cur.y1 = r.y
|
|
279
|
+
cur.ink.push(isInk(designPng, Math.floor(w / 2), r.y) ? 1 : 0)
|
|
280
|
+
} else if (cur) {
|
|
281
|
+
gaps.push(cur)
|
|
282
|
+
cur = null
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (cur) gaps.push(cur)
|
|
286
|
+
return gaps
|
|
287
|
+
.filter((g) => (g.y1 - g.y0) / scale >= minGapPt)
|
|
288
|
+
.sort((a, b) => (b.y1 - b.y0) - (a.y1 - a.y0))
|
|
289
|
+
.slice(0, maxGaps)
|
|
290
|
+
.map((g) => ({
|
|
291
|
+
y: Math.round(g.y0 / scale),
|
|
292
|
+
h: Math.round((g.y1 - g.y0) / scale),
|
|
293
|
+
designInkPct: Number(((g.ink.reduce((a, b) => a + b, 0) / g.ink.length) * 100).toFixed(1)),
|
|
294
|
+
}))
|
|
295
|
+
}
|
|
296
|
+
|
|
233
297
|
/* ── 分项归因(contributors):把差异热区落到具体渲染节点 ─────────
|
|
234
298
|
* 存在理由(2026-09-21 实测):那一轮 23 次 iterate 的报告只说「match 90.04、高度差 2px」,
|
|
235
299
|
* 从不说是**哪个节点**差 —— 模型只能整份重写 IR 去试,16 次全量重写、12.4 万字符、约占全部输出的一半。
|
|
@@ -268,7 +332,9 @@ export function loadFidelityReport({ specPath, schemaPath, designPath, cardId })
|
|
|
268
332
|
const cards = Array.isArray(spec.cards) ? spec.cards : []
|
|
269
333
|
const m = /card-(\d+)\.png$/i.exec(String(designPath || ''))
|
|
270
334
|
const idx = m ? Math.max(0, Math.min(cards.length - 1, Number(m[1]) - 1)) : 0
|
|
271
|
-
|
|
335
|
+
// cardId 显式传入:schema 可能写在临时 out 目录(`--out /tmp/...`),
|
|
336
|
+
// 而审计落点按**卡片 id** 命名(.cache/ai-scratch/<id>.audit.json),靠目录名推会取不到。
|
|
337
|
+
const r = buildFidelityReport({ spec: specPath, schema: schemaPath, card: idx + 1, id: cardId || '' })
|
|
272
338
|
return {
|
|
273
339
|
cardId,
|
|
274
340
|
total: r.elements.texts.total,
|
|
@@ -276,6 +342,9 @@ export function loadFidelityReport({ specPath, schemaPath, designPath, cardId })
|
|
|
276
342
|
missing: r.elements.texts.missing,
|
|
277
343
|
invented: r.elements.texts.invented,
|
|
278
344
|
slices: r.elements.slices,
|
|
345
|
+
// 全类型要素缺口(2026-09-25):图标 / 分割线数量对账(warning 级信息项)
|
|
346
|
+
symbols: r.elements.symbols,
|
|
347
|
+
shapes: r.elements.shapes,
|
|
279
348
|
}
|
|
280
349
|
} catch {
|
|
281
350
|
return null
|
|
@@ -564,7 +633,29 @@ function isBetterThan(a, b) {
|
|
|
564
633
|
return sa > sb + STALL_EPS
|
|
565
634
|
}
|
|
566
635
|
|
|
567
|
-
/**
|
|
636
|
+
/**
|
|
637
|
+
* 内容就绪门禁(S4.9)——**in-process 调用**,不再 shell 出去:
|
|
638
|
+
* 它每轮都跑(挡在 render 前),起进程的冷启成本会把「省一轮 render」的收益吃掉。
|
|
639
|
+
* readiness.mjs 是纯声明性判定,不依赖 Chrome,直接 import 最划算。
|
|
640
|
+
*
|
|
641
|
+
* 失败不阻断调用方:拿不到就返回 null,门禁退化为「无此项」而不是误判未就绪。
|
|
642
|
+
*/
|
|
643
|
+
function runReadiness({ cardId, schemaPath, dataPath, specPath, designPath }) {
|
|
644
|
+
if (!fs.existsSync(schemaPath)) return null
|
|
645
|
+
try {
|
|
646
|
+
return buildReadinessReport({
|
|
647
|
+
cardId,
|
|
648
|
+
schemaPath,
|
|
649
|
+
dataPath,
|
|
650
|
+
specPath: specPath || '',
|
|
651
|
+
designPath: designPath || '',
|
|
652
|
+
})
|
|
653
|
+
} catch {
|
|
654
|
+
return null
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** preflight.mjs = 机械化的 14 项生成前/后检查(项数以 preflight.mjs 自身输出为准)。
|
|
568
659
|
* 此前它没被任何协议阶段点名,模型从来不知道它存在 —— 这里直接并进每轮迭代报告。 */
|
|
569
660
|
function runPreflight({ cardId, specPath }) {
|
|
570
661
|
if (!fs.existsSync(PREFLIGHT_SCRIPT)) return null
|
|
@@ -625,10 +716,33 @@ function describeMatchGap(r) {
|
|
|
625
716
|
export function evaluateGate(r) {
|
|
626
717
|
const pd = r.pixelDiff || {}
|
|
627
718
|
const co = r.contentOffset1x || null
|
|
628
|
-
const
|
|
719
|
+
const contentBlocked = Boolean(r.readiness && r.readiness.ready === false)
|
|
720
|
+
const checks = []
|
|
721
|
+
// 内容就绪(S4.9)放**最前**:它是所有后续判定的前提 ——
|
|
722
|
+
// 要素没齐时 match 毫无参考价值(实测 gen-1:要素不全却刷到 90.46)。
|
|
723
|
+
if (r.readiness) {
|
|
724
|
+
checks.push({
|
|
725
|
+
name: 'readiness.content',
|
|
726
|
+
value: r.readiness.ready === false ? `未就绪(${r.readiness.stage})` : 'ready',
|
|
727
|
+
required: 'ready(要素齐全 ∧ 变量绑定完备 ∧ 图片地址已配置 ∧ 切图已落盘)',
|
|
728
|
+
ok: r.readiness.ready !== false,
|
|
729
|
+
})
|
|
730
|
+
}
|
|
731
|
+
// 渲染宽度基准(S4.9 同级前置):宽度错了 match / dy / contentOffset 全部不可信。
|
|
732
|
+
// 历史事故(gen-1):--width 375 跑了前两轮,best 25.5% 是错基准产物,模型从未注意
|
|
733
|
+
// 报告顶层的 widthMismatch 字段 —— 升级为 gate check(structure 阶段)让它出现在 gate.failed 前列。
|
|
734
|
+
if (r.widthMismatch) {
|
|
735
|
+
checks.push({
|
|
736
|
+
name: 'render.widthMismatch',
|
|
737
|
+
value: r.widthMismatch,
|
|
738
|
+
required: '--width 与设计稿卡面宽一致',
|
|
739
|
+
ok: false,
|
|
740
|
+
})
|
|
741
|
+
}
|
|
742
|
+
checks.push(
|
|
629
743
|
{ name: 'validate.errors', value: r.validate?.errors ?? null, required: '=0', ok: (r.validate?.errors ?? 1) === 0 },
|
|
630
744
|
{ name: 'lint.errors', value: r.lint?.errors ?? null, required: '=0', ok: (r.lint?.errors ?? 1) === 0 },
|
|
631
|
-
|
|
745
|
+
)
|
|
632
746
|
if (r.preflight) checks.push({ name: 'preflight.errors', value: r.preflight.errors, required: '=0', ok: r.preflight.errors === 0 })
|
|
633
747
|
// 要素线(内容真值):设计稿里的文案必须在 schema 里找得到。
|
|
634
748
|
// 放在像素检查之前 —— 要素缺失时先补要素,调像素是白费(改样式不会把丢掉的文案变回来)。
|
|
@@ -654,16 +768,44 @@ export function evaluateGate(r) {
|
|
|
654
768
|
}
|
|
655
769
|
if (co) checks.push({ name: 'contentOffset1x', value: `${co.dx}/${co.dy}`, required: `|dx|,|dy|<=${GATE.contentOffset1x}`, ok: Math.abs(co.dx) <= GATE.contentOffset1x && Math.abs(co.dy) <= GATE.contentOffset1x })
|
|
656
770
|
const failed = checks.filter((c) => !c.ok)
|
|
657
|
-
//
|
|
658
|
-
//
|
|
659
|
-
|
|
771
|
+
// 三段式门禁(内容 → 结构 → 像素):先让「内容就绪」达标,再谈结构,最后才谈像素。
|
|
772
|
+
// 历史事故:两段混在一起时,模型会在「为满足 lint 改结构 → match 掉下来 → 改回去」之间震荡几十步;
|
|
773
|
+
// 而更贵的一次是内容没齐就开始刷像素(gen-1:623 万 token 报废)。
|
|
774
|
+
const structureOk = !failed.some((c) => c.name !== 'pixelDiff.match' && !c.name.startsWith('pixelDiff') && c.name !== 'contentOffset1x' && c.name !== 'readiness.content')
|
|
660
775
|
const gate = {
|
|
661
776
|
passed: failed.length === 0,
|
|
662
|
-
stage: failed.length === 0 ? 'pass' : structureOk ? 'pixel' : 'structure',
|
|
777
|
+
stage: failed.length === 0 ? 'pass' : contentBlocked ? 'content' : structureOk ? 'pixel' : 'structure',
|
|
663
778
|
checks,
|
|
664
779
|
failed: failed.map((c) => `${c.name}=${c.value}(要求 ${c.required})`),
|
|
665
780
|
verdict: failed.length === 0 ? 'PASS' : `FAIL:${failed.map((c) => `${c.name}=${c.value}`).join(',')}`,
|
|
666
781
|
}
|
|
782
|
+
// 结构性缺口提示:存在整片缺失带时,把「先补结构」顶到 hint 首位 ——
|
|
783
|
+
// 局部微调线索(contributors/hotspots)在整块漏建面前全是噪音(gen-1 实测 8 轮无效微调后熔断)。
|
|
784
|
+
const gaps = r.pixelDiff?.structuralGaps || []
|
|
785
|
+
if (gaps.length && typeof r.pixelDiff?.match === 'number' && r.pixelDiff.match < GATE.match) {
|
|
786
|
+
gate.structuralHint =
|
|
787
|
+
`渲染存在 ${gaps.length} 片逐行几乎全异的连续带区(1x 卡内 y/h):` +
|
|
788
|
+
gaps.map((g) => `y=${g.y}~${g.y + g.h}(高 ${g.h}pt,设计稿该带中心有墨比例 ${g.designInkPct}%)`).join(';') +
|
|
789
|
+
` —— 要么整块内容漏建(图表 / 分区 / 列表段),要么背景/底色整层错涂。对照 spec_audit 的 bands[] 先修结构,` +
|
|
790
|
+
`match<${GATE.match} 且缺口仍在时忽略 contributors 的局部微调线索。`
|
|
791
|
+
}
|
|
792
|
+
// 内容未就绪:把 blockers 全文写进 verdict,并**明确写出「本轮没跑 render」** ——
|
|
793
|
+
// 不说清楚的话模型会以为「报告里没像素分 = 迭代器坏了」,转而反复重跑空转。
|
|
794
|
+
if (contentBlocked) {
|
|
795
|
+
gate.blocked = true
|
|
796
|
+
gate.blockedBy = 'readiness'
|
|
797
|
+
gate.stage = 'content'
|
|
798
|
+
gate.readiness = { ready: false, stage: r.readiness.stage, blockers: r.readiness.blockers }
|
|
799
|
+
gate.verdict =
|
|
800
|
+
`BLOCKED(内容未就绪,stage=${r.readiness.stage}):本轮**没有 render、没有 pixelDiff,也不消耗迭代轮次**。` +
|
|
801
|
+
`阻塞项 ${r.readiness.blockers.length} 条:\n` +
|
|
802
|
+
r.readiness.blockers.map((b) => ` · ${b}`).join('\n') +
|
|
803
|
+
(r.readiness.hint ? `\n修法:${r.readiness.hint}` : '') +
|
|
804
|
+
'\n补齐内容后再跑 iterate;内容没齐时的像素分没有参考价值,刷它纯属烧轮次。'
|
|
805
|
+
} else if (r.readiness && r.readiness.checks?.slices?.unreferenced?.length) {
|
|
806
|
+
// 设计稿声明了切图但 schema 里没有同名引用 —— 只提示不拦(名字匹配不可靠,见 readiness.mjs 头部说明)
|
|
807
|
+
gate.sliceHints = r.readiness.checks.slices.unreferenced
|
|
808
|
+
}
|
|
667
809
|
if (r.fidelity && r.fidelity.missing.length) {
|
|
668
810
|
gate.verdict +=
|
|
669
811
|
`;要素缺失 ${r.fidelity.missing.length} 条(设计稿有、schema 里找不到):${r.fidelity.missing.slice(0, 5).map((t) => `「${t}」`).join('、')}` +
|
|
@@ -673,6 +815,16 @@ export function evaluateGate(r) {
|
|
|
673
815
|
if (r.fidelity && r.fidelity.invented && r.fidelity.invented.length) {
|
|
674
816
|
gate.invented = r.fidelity.invented.slice(0, 10)
|
|
675
817
|
}
|
|
818
|
+
// 非文本要素缺口(图标 / 分割线):warning 级提示,不判红 —— symbol 可走 slice 位图实现、
|
|
819
|
+
// shape 可能是背景装饰,数量对账有结构性误差(无金标校准);但必须每轮回喂给模型自查,
|
|
820
|
+
// 否则「图标漏建 / 分割线用 Row+背景色模拟」依旧静默(2026-09-25 用户实测抱怨点)。
|
|
821
|
+
const symGap = r.fidelity?.symbols?.gap || 0
|
|
822
|
+
const divGap = r.fidelity?.shapes?.dividerGap || 0
|
|
823
|
+
if (symGap || divGap) {
|
|
824
|
+
gate.elementHints = []
|
|
825
|
+
if (symGap) gate.elementHints.push(`图标:设计稿 symbol ${r.fidelity.symbols.spec} 个 vs schema Icon ${r.fidelity.symbols.schemaIcon} 个(缺 ${symGap})—— 逐个核对图标是否都有 Icon 组件或 slice 落点`)
|
|
826
|
+
if (divGap) gate.elementHints.push(`分割线:设计稿细长条 shape ${r.fidelity.shapes.specDividerish} 条 vs schema Divider ${r.fidelity.shapes.schemaDivider} 个(缺 ${divGap})—— 分割线必须用 Divider 组件(R-DIVIDER),禁止 Row+背景色模拟`)
|
|
827
|
+
}
|
|
676
828
|
// 几何隐形项:把具体节点写进 verdict —— 只说「collapsed=2」等于让模型自己找是哪两个。
|
|
677
829
|
if (geo && (geo.collapsed?.length || geo.outOfCard?.length)) {
|
|
678
830
|
gate.geometry = { collapsed: geo.collapsed, outOfCard: geo.outOfCard, overWrapped: geo.overWrapped }
|
|
@@ -735,13 +887,18 @@ function heightStalledBlock({ cardId, cur }) {
|
|
|
735
887
|
}
|
|
736
888
|
|
|
737
889
|
function stalledHint({ cardId, roundsSinceBest, best, cur, last, regressed, gate, irRel, reason }) {
|
|
738
|
-
|
|
890
|
+
// gate.failed 在 evaluateGate 里**已经是格式化好的字符串数组**(`name=value(要求 X)`),
|
|
891
|
+
// 这里再按对象取 c.name/c.value 会渲染成 `undefined=undefined(要求 undefined)`——
|
|
892
|
+
// 模型读到的是乱码建议(实测 r14 报告)。直接切片拼接即可。
|
|
893
|
+
const failed = (gate?.failed || []).slice(0, 2)
|
|
894
|
+
// 结构阶段(内容未就绪 / 无像素对比)没有 match 可比,别渲染成「本轮 undefined%」。
|
|
895
|
+
const fmtScore = (v) => (Number.isFinite(v) ? `${v}%` : '(本轮无像素分)')
|
|
739
896
|
// 回退命令里的 `--ir` 必须是**本次跑的那份工作 IR**(persistReport 手里就有),不能猜路径:
|
|
740
897
|
// 模型把 IR 放哪儿由它自己决定(实测有 UI/_gen/<draft>/、.cache/ai-scratch/ 等多种落点),
|
|
741
898
|
// 猜错的结果是回退命令直接报「工作 IR 不存在」,白烧一步。
|
|
742
899
|
const irTarget = irRel || `.cache/ai-scratch/${cardId}.ir.json`
|
|
743
900
|
const lines = [
|
|
744
|
-
`已连续 ${roundsSinceBest} 轮没有刷新最好成绩:最好 ${best.match}
|
|
901
|
+
`已连续 ${roundsSinceBest} 轮没有刷新最好成绩:最好 ${fmtScore(best.match)} @ r${best.round},本轮 ${fmtScore(cur.match)}${regressed && last ? `(比上轮 ${fmtScore(last.match)} 还低)` : ''}。`,
|
|
745
902
|
]
|
|
746
903
|
// 要素下滑单独点名:这类轮次**不该**继续调像素——像素分可能是靠删要素/换占位文案换来的。
|
|
747
904
|
if (cur.elementsMissing != null && best.elementsMissing != null && cur.elementsMissing > best.elementsMissing) {
|
|
@@ -763,8 +920,58 @@ function stalledHint({ cardId, roundsSinceBest, best, cur, last, regressed, gate
|
|
|
763
920
|
return lines.join('\n')
|
|
764
921
|
}
|
|
765
922
|
|
|
923
|
+
/**
|
|
924
|
+
* 迭代身份:**同一张卡换设计稿整卡重做**时必须把轮次历史与最好成绩全部作废。
|
|
925
|
+
*
|
|
926
|
+
* 为什么要(2026-09-24 实机事故):持久化只按 cardId 认,`gen-1` 先按「理财卡」设计稿
|
|
927
|
+
* 迭代到 r17(best 91.64% @ r6 / 19 条要素),用户随后把同一张卡换成「收支分析」设计稿
|
|
928
|
+
* 重做 —— 新设计的第一轮 iterate 直接被记成 r18,撞上旧设计的 best:
|
|
929
|
+
* `score = 80.15 − 6×8 缺要素` 远不如 91.64 ⇒ roundsSinceBest = 18 − 6 = 12 ≥ STALL_ROUNDS
|
|
930
|
+
* ⇒ 当场判 stalled ⇒ ai-chat 的还原度熔断随即禁用 iterate / ir_patch,模型只能收尾交一张
|
|
931
|
+
* **stage=structure、缺 8 条要素、match 80%、高差 −76px** 的卡。整轮 96 万 prompt token 报废。
|
|
932
|
+
*
|
|
933
|
+
* 判据只用设计稿绝对路径:它换新就是另一张卡的内容真值,旧历史对像素/要素两条线都没有参照意义;
|
|
934
|
+
* 同一设计稿重跑则保留历史(`ir_restore --best` 仍可用,别把回退能力一起废掉)。
|
|
935
|
+
* 显式重置用 `--reset`(换设计稿但还是想从零计时)。
|
|
936
|
+
*/
|
|
937
|
+
function iterationIdentity(designPath, irPath) {
|
|
938
|
+
if (designPath) {
|
|
939
|
+
try {
|
|
940
|
+
return `design:${fs.realpathSync(path.resolve(designPath))}`
|
|
941
|
+
} catch {
|
|
942
|
+
return `design:${path.resolve(designPath)}`
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
// 没给 --design(纯结构迭代)时退回 IR 自身路径,至少不会跨卡串味
|
|
946
|
+
return `ir:${irPath ? path.resolve(irPath) : ''}`
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/** 换设计稿重置:轮次快照与 best 都指向旧设计,留着会误导 ir_restore 把另一张卡的 IR 写回来 */
|
|
950
|
+
function dropStaleSnapshots(cardId) {
|
|
951
|
+
const dropped = []
|
|
952
|
+
let names = []
|
|
953
|
+
try {
|
|
954
|
+
names = fs.readdirSync(SCRATCH_DIR)
|
|
955
|
+
} catch {
|
|
956
|
+
return dropped
|
|
957
|
+
}
|
|
958
|
+
const prefix = `${cardId}.ir.`
|
|
959
|
+
for (const n of names) {
|
|
960
|
+
if (n === `${cardId}.ir.best.json` || /\.ir\.r\d+\.json$/.test(n)) {
|
|
961
|
+
if (!n.startsWith(prefix)) continue
|
|
962
|
+
try {
|
|
963
|
+
fs.unlinkSync(path.join(SCRATCH_DIR, n))
|
|
964
|
+
dropped.push(n)
|
|
965
|
+
} catch {
|
|
966
|
+
/* 删不掉不致命:报告已被清空,最多留几个孤儿文件 */
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return dropped
|
|
971
|
+
}
|
|
972
|
+
|
|
766
973
|
/** 报告落盘 + 轮次历史 + 停滞检测(连续多轮没刷新最好成绩 = 微调到天花板,必须叫停并回退)。 */
|
|
767
|
-
export function persistReport(result, { sp, dp, irPath }) {
|
|
974
|
+
export function persistReport(result, { sp, dp, irPath, reset = false, design = '' }) {
|
|
768
975
|
try {
|
|
769
976
|
fs.mkdirSync(SCRATCH_DIR, { recursive: true })
|
|
770
977
|
const reportPath = path.join(SCRATCH_DIR, `${result.cardId}.iterate.json`)
|
|
@@ -773,10 +980,61 @@ export function persistReport(result, { sp, dp, irPath }) {
|
|
|
773
980
|
try {
|
|
774
981
|
prev = JSON.parse(fs.readFileSync(reportPath, 'utf8'))
|
|
775
982
|
} catch {}
|
|
983
|
+
// 设计稿换了(或显式 --reset)⇒ 轮次历史 / best / 快照全部作废,本轮记 r1。
|
|
984
|
+
// 判据见 iterationIdentity:只按 cardId 认会让新设计第 1 轮撞上旧设计的 best 而被误判停滞。
|
|
985
|
+
const identity = iterationIdentity(design, irPath)
|
|
986
|
+
let resetReason = ''
|
|
987
|
+
if (prev) {
|
|
988
|
+
if (reset) resetReason = '显式 --reset'
|
|
989
|
+
// 旧报告(本判据上线前落的)没有 identity,无从比对 ⇒ 按「无法证明是同一设计稿」处理,
|
|
990
|
+
// 一次性重置。代价只有「丢一次回退目标」,而误判停滞的代价是整轮生成报废(见上面注释)。
|
|
991
|
+
else if (!prev.identity) resetReason = '旧报告无迭代身份(判据上线前落的),无法证明与当前设计稿同一'
|
|
992
|
+
else if (prev.identity !== identity) resetReason = `设计稿已更换(${prev.identity} → ${identity})`
|
|
993
|
+
}
|
|
994
|
+
const droppedSnapshots = resetReason ? dropStaleSnapshots(result.cardId) : []
|
|
995
|
+
if (resetReason) prev = null
|
|
776
996
|
const pd = result.pixelDiff || {}
|
|
777
997
|
const hotSig = (pd.hotspots || []).slice(0, 3).map((h) => `${h.x},${h.y}`).join('|')
|
|
778
998
|
const history = Array.isArray(prev?.history) ? prev.history.slice(-9) : []
|
|
779
999
|
const last = history[history.length - 1]
|
|
1000
|
+
|
|
1001
|
+
/* ── 内容未就绪:**不消耗迭代轮次** ────────────────────────────────
|
|
1002
|
+
* 本轮根本没跑 render,谈「第几轮迭代」没有意义;更关键的是——
|
|
1003
|
+
* 若照常 push 一条 history,那么模型「改内容 → 被拦一次 → 又改 → 又被拦」会白白把
|
|
1004
|
+
* 历史窗口(只留 9 条)挤满、并把 `round` 抬高,进而污染 `roundsSinceBest` 与停滞判据
|
|
1005
|
+
* (实测 gen-1 的 r12/r13 就是这种「什么都没变却各占一轮」的幽灵轮次)。
|
|
1006
|
+
* 所以这里只刷新 gate / blockedAt,history 与 best 原样保留,不写 IR 快照。 */
|
|
1007
|
+
if (result.readiness && result.readiness.ready === false) {
|
|
1008
|
+
const blockedReport = {
|
|
1009
|
+
...result,
|
|
1010
|
+
elements: undefined,
|
|
1011
|
+
identity,
|
|
1012
|
+
schemaHash: hashFile(sp),
|
|
1013
|
+
dataHash: hashFile(dp),
|
|
1014
|
+
history,
|
|
1015
|
+
best: prev?.best,
|
|
1016
|
+
round: history.length,
|
|
1017
|
+
stalled: undefined,
|
|
1018
|
+
blockedAt: {
|
|
1019
|
+
ts: Date.now(),
|
|
1020
|
+
stage: result.readiness.stage,
|
|
1021
|
+
blockers: result.readiness.blockers,
|
|
1022
|
+
hint: result.readiness.hint || null,
|
|
1023
|
+
},
|
|
1024
|
+
}
|
|
1025
|
+
blockedReport.gate = evaluateGate(blockedReport)
|
|
1026
|
+
blockedReport.conclusion = 'blocked-content'
|
|
1027
|
+
fs.writeFileSync(reportPath, JSON.stringify(blockedReport, null, 2) + '\n')
|
|
1028
|
+
return {
|
|
1029
|
+
reportPath,
|
|
1030
|
+
stalled: null,
|
|
1031
|
+
gate: blockedReport.gate,
|
|
1032
|
+
conclusion: 'blocked-content',
|
|
1033
|
+
rounds: history.length,
|
|
1034
|
+
blocked: true,
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
780
1038
|
const round = (last?.round || history.length) + 1
|
|
781
1039
|
const snapshot = snapshotIR(result.cardId, irPath, round)
|
|
782
1040
|
// 历史最好成绩(不含本轮):停滞判据的基准。
|
|
@@ -838,6 +1096,8 @@ export function persistReport(result, { sp, dp, irPath }) {
|
|
|
838
1096
|
const persisted = {
|
|
839
1097
|
...result,
|
|
840
1098
|
elements: undefined,
|
|
1099
|
+
// 迭代身份:下一轮据此判「还是同一张内容真值吗」,换了就重置(见 iterationIdentity)
|
|
1100
|
+
identity,
|
|
841
1101
|
schemaHash: hashFile(sp),
|
|
842
1102
|
dataHash: hashFile(dp),
|
|
843
1103
|
history,
|
|
@@ -886,15 +1146,29 @@ export function persistReport(result, { sp, dp, irPath }) {
|
|
|
886
1146
|
fs.writeFileSync(reportPath, JSON.stringify(persisted, null, 2) + '\n')
|
|
887
1147
|
// 轮次快照只留最近 12 轮 + best:这是个「每轮一份 IR 全文」的目录,长任务下会无限堆积
|
|
888
1148
|
const pruned = pruneSnapshots(result.cardId)
|
|
889
|
-
return {
|
|
1149
|
+
return {
|
|
1150
|
+
reportPath,
|
|
1151
|
+
stalled: persisted.stalled,
|
|
1152
|
+
gate: persisted.gate,
|
|
1153
|
+
conclusion: persisted.conclusion,
|
|
1154
|
+
rounds: history.length,
|
|
1155
|
+
pruned,
|
|
1156
|
+
// 重置必须显式回喂:模型看到「r1」才知道前面的历史已作废,否则会拿旧报告里的
|
|
1157
|
+
// match / best 当参照继续谈收敛。
|
|
1158
|
+
iterationReset: resetReason
|
|
1159
|
+
? { reason: resetReason, droppedSnapshots: droppedSnapshots.length, round: persisted.history?.[0]?.round ?? 1 }
|
|
1160
|
+
: undefined,
|
|
1161
|
+
}
|
|
890
1162
|
} catch {
|
|
891
1163
|
return null
|
|
892
1164
|
}
|
|
893
1165
|
}
|
|
894
1166
|
|
|
895
1167
|
/* ── 核心管线 ──────────────────────────────────────────────── */
|
|
896
|
-
async function runPipeline({ ir: irPath, out: outDir, design: designPath, width, session, alwaysDiffImage, withElements, sets, specPath, skipPreflight, slicesDir: slicesDirArg }) {
|
|
1168
|
+
async function runPipeline({ ir: irPath, out: outDir, design: designPath, width, session, alwaysDiffImage, withElements, sets, specPath, skipPreflight, slicesDir: slicesDirArg, reset: resetFlag, noReadiness: noReadinessArg }) {
|
|
897
1169
|
const t0 = performance.now()
|
|
1170
|
+
/** 内容就绪门禁开关:--no-readiness 或环境变量(debug 用逃生门) */
|
|
1171
|
+
const noReadiness = Boolean(noReadinessArg) || process.env.DSL_CARD_SKIP_READINESS === '1'
|
|
898
1172
|
|
|
899
1173
|
// 设计稿侧元素(供 contributors 的 designH/deltaH):只有给了 --spec 才可用。
|
|
900
1174
|
// 拿不到就不给 deltaH —— 宁缺勿滥,编不出可证伪的数字比没有数字更坏。
|
|
@@ -954,6 +1228,47 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
954
1228
|
validateReport = { ok: false, errors: 1, warnings: 0, details: [`validate 执行异常: ${e.message || e}`] }
|
|
955
1229
|
}
|
|
956
1230
|
|
|
1231
|
+
// 3.9 ★ 内容就绪门禁(S4.9)——**挡在最贵的 render + pixelDiff 之前**。
|
|
1232
|
+
//
|
|
1233
|
+
// 2026-09-24 gen-1 事故(用户原话):「只有在确保内容和要素的齐全和准备再做像素自循环,
|
|
1234
|
+
// 不然跟个傻逼一样浪费时间在像素循环里打转。这次卡片连基本的切图引入跑了半天都没为我添加上去」。
|
|
1235
|
+
// 实测:两个回合 623 万 prompt token 全废;iterate 历史 r4–r13 十轮 match 卡在 87–90.46,
|
|
1236
|
+
// `gate.stage` 全程 = 'pixel'(结构早过了),而 Image 的图片地址因属性键写成 `image`
|
|
1237
|
+
// 被运行时静默丢弃、渲染成破图 —— **要素不全却已经在刷像素**。
|
|
1238
|
+
//
|
|
1239
|
+
// 门禁项 A 组件契约 / B 要素齐全 / C 变量绑定完备 / D 图片地址已配置 / E 切图路径已配置,
|
|
1240
|
+
// 全是**声明性判定**(不渲染即可判),所以放在这里:不合格就直接 return,
|
|
1241
|
+
// 一轮 render(≈486ms Chrome) + pixelDiff(全量 84 万像素) + 归因全部省掉。
|
|
1242
|
+
//
|
|
1243
|
+
// 判据选型(全仓 75 张卡实测):71/75 ready,4 条未就绪**全是真实的 r31c 悬空引用**,0 误报。
|
|
1244
|
+
const readiness = noReadiness ? null : runReadiness({ cardId, schemaPath: sp, dataPath: dp, specPath, designPath })
|
|
1245
|
+
if (readiness && readiness.ready === false) {
|
|
1246
|
+
const gateBlocked = evaluateGate({ validate: validateReport, lint: { errors: lintErrors.length }, readiness })
|
|
1247
|
+
const result = {
|
|
1248
|
+
ok: true,
|
|
1249
|
+
cardId,
|
|
1250
|
+
blocked: 'content',
|
|
1251
|
+
readiness: { ready: false, stage: readiness.stage, blockers: readiness.blockers, hint: readiness.hint, checks: readiness.checks },
|
|
1252
|
+
validate: validateReport,
|
|
1253
|
+
lint: { errors: lintErrors.length, warnings: lintWarns.length, infos: lintInfos.length },
|
|
1254
|
+
gate: gateBlocked,
|
|
1255
|
+
conclusion: 'blocked-content',
|
|
1256
|
+
readinessNote:
|
|
1257
|
+
'内容未就绪 ⇒ 本轮**没有** render、**没有** pixelDiff、**不消耗迭代轮次**(不写快照、不进 history)。' +
|
|
1258
|
+
'先按 blockers 把内容补齐(要素 / 变量绑定 / 图片地址 / 切图落盘),补完再跑 iterate。' +
|
|
1259
|
+
'这一步的存在意义就是:内容没齐时像素分毫无参考价值,刷它纯属烧轮次。',
|
|
1260
|
+
elapsedMs: Math.round(performance.now() - t0),
|
|
1261
|
+
}
|
|
1262
|
+
const saved = persistReport(result, { sp, dp, irPath, reset: resetFlag, design: designPath })
|
|
1263
|
+
if (saved) {
|
|
1264
|
+
result.report = saved.reportPath
|
|
1265
|
+
result.rounds = saved.rounds
|
|
1266
|
+
result.gate = saved.gate
|
|
1267
|
+
result.conclusion = saved.conclusion
|
|
1268
|
+
}
|
|
1269
|
+
return result
|
|
1270
|
+
}
|
|
1271
|
+
|
|
957
1272
|
// 4. Render (reuse session if provided, else cold start)
|
|
958
1273
|
// 宽度优先级:显式 --width > 设计稿卡面宽(spec 是 1x,卡面如 343)> schema.view.width > 默认。
|
|
959
1274
|
// 实测事故:第 44 次调用用了默认 375 跑完一轮,第 46 次才改成 343(设计稿 686 = 343×2)—— 白烧一轮。
|
|
@@ -1000,6 +1315,8 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
1000
1315
|
const designPng = PNG.sync.read(designBuf)
|
|
1001
1316
|
const scale = renderWidth ? renderPng.width / renderWidth : 2
|
|
1002
1317
|
pixelDiffResult.hotspots = diffHotspots(renderPng, designPng, { scale })
|
|
1318
|
+
// 结构性缺口:整块漏建的区域(高度差的主要实体)。放在报告里供 gate hint 引用。
|
|
1319
|
+
try { pixelDiffResult.structuralGaps = detectStructuralGaps(renderPng, designPng, { scale }) } catch {}
|
|
1003
1320
|
} catch {}
|
|
1004
1321
|
if (true) {
|
|
1005
1322
|
const composed = composeSideBySide(designBuf, renderBuf)
|
|
@@ -1020,7 +1337,7 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
1020
1337
|
|
|
1021
1338
|
const elapsed = Math.round(performance.now() - t0)
|
|
1022
1339
|
|
|
1023
|
-
// 5.5 preflight
|
|
1340
|
+
// 5.5 preflight(机械化的 14 项)并入本轮报告
|
|
1024
1341
|
const preflight = skipPreflight ? null : runPreflight({ cardId, specPath })
|
|
1025
1342
|
|
|
1026
1343
|
// 5.6 要素清单(内容真值)—— 只查得到就进报告,并作为**机器门禁的一项**(elements.missing=0)。
|
|
@@ -1098,8 +1415,26 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
1098
1415
|
designImage,
|
|
1099
1416
|
preflight: preflight || undefined,
|
|
1100
1417
|
fidelity: fidelityReport || undefined,
|
|
1418
|
+
// 内容就绪结论带进每轮报告:模型不必再单独跑一次 readiness 才知道内容层状态
|
|
1419
|
+
readiness: readiness
|
|
1420
|
+
? {
|
|
1421
|
+
ready: readiness.ready,
|
|
1422
|
+
stage: readiness.stage,
|
|
1423
|
+
blockers: readiness.blockers,
|
|
1424
|
+
// 声明了切图但 schema 里没有同名引用:只提示不拦(名字匹配不可靠,见 readiness.mjs 头部)
|
|
1425
|
+
unreferencedSlices: readiness.checks?.slices?.unreferenced || [],
|
|
1426
|
+
}
|
|
1427
|
+
: undefined,
|
|
1101
1428
|
// 尺寸口径警告:宽度不对时下面所有像素指标都不可信,必须最先修
|
|
1102
1429
|
widthMismatch: widthMismatch || undefined,
|
|
1430
|
+
// 结构性缺口:逐行几乎全异的连续带区 —— 整块漏建 / 背景错涂的第一信号。
|
|
1431
|
+
// 存在它时先修结构,跟着 contributors 调 padding/lineHeight 是在 80% 缺失面前做 1% 微调(gen-1 实测烧 8 轮)。
|
|
1432
|
+
structuralGaps: pixelDiffResult?.structuralGaps?.length
|
|
1433
|
+
? {
|
|
1434
|
+
bands: pixelDiffResult.structuralGaps,
|
|
1435
|
+
note: '检测到「逐行差异率 ≥85%」的连续带区(1x 卡内坐标,按高度降序):该带要么整块内容漏建(图表 / 卡片分区 / 列表段),要么背景/底色整层错涂。对照 spec_audit 的 bands[] 找到该带区对应的元素群,先把它建出来或改对背景再谈别的;match<40 时 contributors/hotspots 的局部微调线索可以全部忽略。',
|
|
1436
|
+
}
|
|
1437
|
+
: undefined,
|
|
1103
1438
|
contentOffset1x: contentOffset1x || undefined,
|
|
1104
1439
|
contentOffsetHint: contentOffsetHint || undefined,
|
|
1105
1440
|
// 分项归因:每个热区给出「最可能的节点 + 它自己实测的 h / 同类中位 / 设计稿高度」
|
|
@@ -1117,11 +1452,13 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
1117
1452
|
}
|
|
1118
1453
|
|
|
1119
1454
|
// 报告落盘 + 门禁判定 + 停滞检测
|
|
1120
|
-
const saved = persistReport(result, { sp, dp, irPath })
|
|
1455
|
+
const saved = persistReport(result, { sp, dp, irPath, reset: resetFlag, design: designPath })
|
|
1121
1456
|
if (saved) {
|
|
1122
1457
|
result.report = saved.reportPath
|
|
1123
1458
|
result.rounds = saved.rounds
|
|
1124
1459
|
result.gate = saved.gate
|
|
1460
|
+
// 换设计稿 / --reset 触发的重置必须显式回喂模型:否则它会拿旧报告里的 match/best 当参照
|
|
1461
|
+
if (saved.iterationReset) result.iterationReset = saved.iterationReset
|
|
1125
1462
|
// 显式结论一路带到工具输出:模型与用户都能一眼看出这卡是 pass / stalled / 还在 iterating,
|
|
1126
1463
|
// 而不是只拿到一个 passed:false 的布尔(旧版因此出现「2 轮后无声转向下一张卡」)。
|
|
1127
1464
|
result.conclusion = saved.conclusion
|
|
@@ -1139,7 +1476,7 @@ async function runPipeline({ ir: irPath, out: outDir, design: designPath, width,
|
|
|
1139
1476
|
|
|
1140
1477
|
/* ── CLI ───────────────────────────────────────────────────── */
|
|
1141
1478
|
function parseArgs(argv) {
|
|
1142
|
-
const out = { ir: '', out: '', design: '', width: 0, keepAlive: false, diffImage: false, elements: false, sets: [], spec: '', gate: false, id: '', skipPreflight: false, slicesDir: '' }
|
|
1479
|
+
const out = { ir: '', out: '', design: '', width: 0, keepAlive: false, diffImage: false, elements: false, sets: [], spec: '', gate: false, id: '', skipPreflight: false, slicesDir: '', reset: false, noReadiness: false }
|
|
1143
1480
|
for (let i = 0; i < argv.length; i++) {
|
|
1144
1481
|
const a = argv[i]
|
|
1145
1482
|
if (a === '--ir') out.ir = argv[++i] || ''
|
|
@@ -1152,9 +1489,13 @@ function parseArgs(argv) {
|
|
|
1152
1489
|
else if (a === '--id') out.id = argv[++i] || ''
|
|
1153
1490
|
else if (a === '--gate') out.gate = true
|
|
1154
1491
|
else if (a === '--no-preflight') out.skipPreflight = true
|
|
1492
|
+
// 逃生门:跳过 S4.9 内容就绪门禁(debug 用;正常流程**不该**用它)
|
|
1493
|
+
else if (a === '--no-readiness') out.noReadiness = true
|
|
1155
1494
|
else if (a === '--keep-alive') out.keepAlive = true
|
|
1156
1495
|
else if (a === '--diff-image') out.diffImage = true
|
|
1157
1496
|
else if (a === '--elements') out.elements = true
|
|
1497
|
+
// 换设计稿时轮次历史/best 会自动作废(见 iterationIdentity);--reset 用于「设计稿没换但要从零计时」
|
|
1498
|
+
else if (a === '--reset') out.reset = true
|
|
1158
1499
|
else if (a === '-h' || a === '--help') {
|
|
1159
1500
|
console.log(`Usage: node iterate.mjs --ir <IR.json> --out <cardDir> [--design <design.png>] [--width 343] [--elements]
|
|
1160
1501
|
[--spec <spec.json>](跑 preflight 元素清单比对) [--no-preflight] [--slices-dir <要素包 slices 目录>]
|
|
@@ -1162,11 +1503,18 @@ function parseArgs(argv) {
|
|
|
1162
1503
|
node iterate.mjs --gate --out <cardDir>(或 --id <cardId>):读最近一轮落盘报告做机器门禁判定,未达标 exit 2(gate-fail,不是脚本报错)
|
|
1163
1504
|
node iterate.mjs --keep-alive (stdin JSON lines → stdout JSON lines)
|
|
1164
1505
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1506
|
+
阶段(gate.stage):content → structure → pixel → pass,**逐段推进**。
|
|
1507
|
+
· content 内容未就绪(S4.9):要素 / 变量绑定 / 图片地址 / 切图落盘 有缺 ⇒ **跳过 render 与 pixelDiff、
|
|
1508
|
+
不消耗迭代轮次**,按 gate.verdict 里的 blockers 补齐内容再来。跳过用 --no-readiness(或环境变量
|
|
1509
|
+
DSL_CARD_SKIP_READINESS=1),正常流程不该用。
|
|
1510
|
+
· structure validate/lint/preflight/geometry/要素线不达标 —— 先改结构,别碰像素。
|
|
1511
|
+
· pixel 结构全过,只差 match / 尺寸 / 整体偏移。
|
|
1512
|
+
|
|
1513
|
+
门禁(--gate / 报告里的 gate 字段):readiness=ready ∧ validate.errors=0 ∧ lint.errors=0 ∧ preflight.errors=0
|
|
1514
|
+
∧ elements.missing=0 ∧ match>=${GATE.match} ∧ heightDelta=${GATE.heightDelta} ∧ widthDelta=${GATE.widthDelta}
|
|
1515
|
+
∧ |contentOffset1x|<=${GATE.contentOffset1x} ∧ geometry.collapsed=0 ∧ geometry.outOfCard=0,
|
|
1168
1516
|
且 schema 未在报告之后被改过。
|
|
1169
|
-
报告落盘:.cache/ai-scratch/<cardId>.iterate.json(含 gate / history / stalled / geometry)。`)
|
|
1517
|
+
报告落盘:.cache/ai-scratch/<cardId>.iterate.json(含 gate / history / stalled / geometry / blockedAt)。`)
|
|
1170
1518
|
process.exit(0)
|
|
1171
1519
|
}
|
|
1172
1520
|
}
|
|
@@ -1200,11 +1548,19 @@ function runGateMode({ id, out: outDir }) {
|
|
|
1200
1548
|
gate.verdict = `FAIL:报告已过期(schema.json 在报告之后被改过:${report.schemaHash} → ${schemaHash})—— 重跑一轮 iterate.mjs 再判门禁`
|
|
1201
1549
|
gate.checks.push({ name: 'reportFreshness', value: 'stale', required: 'schema 未变更', ok: false })
|
|
1202
1550
|
}
|
|
1203
|
-
// 显式结论:pass / stalled / iterating
|
|
1551
|
+
// 显式结论:pass / stalled / blocked-content / iterating。四者之外不允许「无声退出」——
|
|
1204
1552
|
// 实测建卡回合里模型跑完 2 轮就直接转去做下一张卡,卡在「既没过门禁、也没判停滞」的
|
|
1205
1553
|
// 中间态,界面上完全看不出这卡是被放弃了还是还在迭代。
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1554
|
+
const blockedContent = Boolean(report.blockedAt) || report.conclusion === 'blocked-content'
|
|
1555
|
+
const conclusion = gate.passed ? 'pass' : blockedContent ? 'blocked-content' : report.stalled ? 'stalled' : 'iterating'
|
|
1556
|
+
if (blockedContent) {
|
|
1557
|
+
gate.blocked = true
|
|
1558
|
+
gate.stage = 'content'
|
|
1559
|
+
gate.verdict =
|
|
1560
|
+
`BLOCKED(内容未就绪,stage=${report.blockedAt?.stage || '?'}):本轮没跑 render / 没跑 pixelDiff,也没消耗迭代轮次。\n` +
|
|
1561
|
+
(report.blockedAt?.blockers || []).map((b) => ` · ${b}`).join('\n') +
|
|
1562
|
+
(report.blockedAt?.hint ? `\n修法:${report.blockedAt.hint}` : '')
|
|
1563
|
+
} else if (conclusion === 'iterating') {
|
|
1208
1564
|
gate.verdict +=
|
|
1209
1565
|
';结论=iterating:既未过门禁、也未判停滞 —— 不允许无声退出。' +
|
|
1210
1566
|
'要么继续 iterate(一轮只改一项,拿到新报告再判),要么在正文里显式写明放弃理由(例:设计稿本身自相矛盾 / 缺关键切图)再停手。'
|
|
@@ -1213,6 +1569,7 @@ function runGateMode({ id, out: outDir }) {
|
|
|
1213
1569
|
ok: gate.passed,
|
|
1214
1570
|
cardId,
|
|
1215
1571
|
conclusion,
|
|
1572
|
+
blockedAt: report.blockedAt || null,
|
|
1216
1573
|
stalled: report.stalled
|
|
1217
1574
|
? { reason: report.stalled.reason || 'match', rounds: report.stalled.rounds, hint: report.stalled.hint }
|
|
1218
1575
|
: null,
|
|
@@ -1255,7 +1612,7 @@ async function main() {
|
|
|
1255
1612
|
if (!text) continue
|
|
1256
1613
|
try {
|
|
1257
1614
|
const req = JSON.parse(text)
|
|
1258
|
-
const result = await runPipeline({ ...req, specPath: req.spec || req.specPath, session, alwaysDiffImage: req.diffImage || req.alwaysDiffImage, withElements: req.elements })
|
|
1615
|
+
const result = await runPipeline({ ...req, specPath: req.spec || req.specPath, session, alwaysDiffImage: req.diffImage || req.alwaysDiffImage, withElements: req.elements, noReadiness: req.noReadiness || req.skipReadiness })
|
|
1259
1616
|
console.log(JSON.stringify(result))
|
|
1260
1617
|
} catch (e) {
|
|
1261
1618
|
console.log(JSON.stringify({ ok: false, error: 'request-failed', message: e.message }))
|
|
@@ -1283,6 +1640,8 @@ async function main() {
|
|
|
1283
1640
|
specPath: args.spec,
|
|
1284
1641
|
skipPreflight: args.skipPreflight,
|
|
1285
1642
|
slicesDir: args.slicesDir,
|
|
1643
|
+
reset: args.reset,
|
|
1644
|
+
noReadiness: args.noReadiness,
|
|
1286
1645
|
})
|
|
1287
1646
|
|
|
1288
1647
|
console.log(JSON.stringify(result, null, 2))
|