dsh-vibe-math 2.3.0 → 2.3.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.
Files changed (30) hide show
  1. package/AUDIT-CHECKLIST.md +33 -3
  2. package/README.md +21 -0
  3. package/RELEASE-NOTES-2.3.1.md +134 -0
  4. package/audit-formal-sensitivity.mjs +125 -39
  5. package/audit-v5-integrity.mjs +5 -3
  6. package/docs/formal-verification.md +92 -12
  7. package/docs/test-timing.md +79 -0
  8. package/formal-verify-v2.test.mjs +286 -7
  9. package/formal-verify-v3.test.mjs +215 -8
  10. package/formal-verify-v4.test.mjs +282 -3
  11. package/formal-verify-v5.test.mjs +72 -0
  12. package/package.json +9 -2
  13. package/prompt-corpus-v2/formal-verify-v2.json +394 -0
  14. package/prompt-corpus-v2/formal-verify-v2.md +4250 -0
  15. package/prompt-corpus-v3/formal-verify-v3.json +159 -57
  16. package/prompt-corpus-v3/formal-verify-v3.md +1302 -285
  17. package/prompt-corpus-v4/formal-verify-v4.json +84 -0
  18. package/prompt-corpus-v4/formal-verify-v4.md +255 -0
  19. package/prompt-corpus-v5/prompt-corpus-v5.json +54 -16
  20. package/prompt-corpus-v5/prompt-corpus-v5.md +378 -153
  21. package/prompt-v5-integrity.test.mjs +1158 -1085
  22. package/run-tests.mjs +99 -0
  23. package/vibe-math-v2/vibe-math-v2.js +204 -22
  24. package/vibe-math-v2//345/256/236/347/216/260/346/226/271/346/241/210.md +77 -4
  25. package/vibe-math-v3/vibe-math-v3.js +82 -21
  26. package/vibe-math-v3//345/256/236/347/216/260/346/226/271/346/241/210.md +17 -0
  27. package/vibe-math-v4/vibe-math-v4.js +114 -22
  28. package/vibe-math-v4//345/256/236/347/216/260/346/226/271/346/241/210.md +29 -0
  29. package/vibe-math-v5/vibe-math-v5.js +81 -22
  30. package/vibe-math-v5//345/256/236/347/216/260/346/226/271/346/241/210.md +27 -4
@@ -63,9 +63,14 @@ let spawnThrows = false
63
63
  // Interaction corpus (AUDIT-CHECKLIST §2.4): every prompt the framework actually sent, with the
64
64
  // workspace path normalised so the dump is deterministic and diffable.
65
65
  const corpus = []
66
- // Normalise BOTH slash forms: prompts built through vibeRoot() carry forward slashes while other
67
- // framework hints carry native backslashes, and a half-normalised corpus is not diffable.
68
- const scrub = (s) => String(s == null ? '' : s).split(WS).join('<WS>').split(WS.replace(/\\/g, '/')).join('<WS>')
66
+ // Normalise BOTH slash forms. The VibeMath ROOT must be replaced BEFORE the workspace root,
67
+ // otherwise `<WS>/VibeMath` would survive as a half-substituted path: the corpus would still leak
68
+ // the machine layout and would not be diffable against another checkout.
69
+ const scrub = (s) => String(s == null ? '' : s)
70
+ .split(VIBE).join('<VIBEMATH>')
71
+ .split(VIBE.replace(/\\/g, '/')).join('<VIBEMATH>')
72
+ .split(WS).join('<WS>')
73
+ .split(WS.replace(/\\/g, '/')).join('<WS>')
69
74
 
70
75
  // A fake Lean: a file PASSES unless it still contains `sorry` or the marker `-- FAIL`.
71
76
  // `-- HANG` simulates a toolchain that never returns (the timeout path).
@@ -335,7 +340,7 @@ assert(await drive(RC, () => !!lastSpawn(RC, 'explorer:qE'), 'explorer:qE'), 'fa
335
340
  assert(/【顺手形式化(鼓励)】/.test(p), 'the explorer work prompt carries the 顺手形式化 line')
336
341
  assert(/vibe_math_lean_archive kind='def'/.test(p), 'the work prompt points at the archive tool for reusable definitions')
337
342
  assert(/vibe_math_lean_lib 查重/.test(p), 'the work prompt tells agents to check the reuse library first')
338
- assert(/形式化回执/.test(p) && /"decision":"used\|blocked"/.test(p), '★ the work-round reply contract also advertises the formal field (契约 §6.3)')
343
+ assert(/形式化回执/.test(p) && /"decision":"used\|blocked\|defect"/.test(p), '★ the work-round reply contract also advertises the formal field, defect included (契约 §6.3)')
339
344
  }
340
345
  fireEnd(lastSpawn(RC, 'explorer:qE').childId, { meta: { kind: 'directions', qid: 'qE', formal: { target: 'qE', decision: 'blocked', note: '需要先形式化连分数收敛定理' }, directions: [{ id: 'd1', title: '连分数法', method: 'e 的连分数', core_assumption: '', feasibility: 0.7 }] } })
341
346
  // Answer EVERY explorer the fallback scheduler dispatches (it re-derives when a direction looks
@@ -390,7 +395,7 @@ if (encBatch) {
390
395
  assert(/一旦 Lean 通过,你唯一需要确认的就是忠实性/.test(vp), 'the review prompt states that a passing Lean run shrinks the question to fidelity')
391
396
  assert(/实现难度/.test(vp), 'the review prompt asks for the implementation-difficulty judgement')
392
397
  assert(/可以不做,但请在回执的 formal 字段写明难度判断/.test(vp), "'encourage' explicitly allows skipping (with a recorded judgement)")
393
- assert(/"formal":/.test(vp) && /"decision":"used\|blocked"/.test(vp), 'the reply contract documents the formal field')
398
+ assert(/"formal":/.test(vp) && /"decision":"used\|blocked\|defect"/.test(vp), 'the reply contract documents the formal field (defect included)')
394
399
  assert(/vibe_math_lean_run/.test(vp) && /vibe_math_lean_archive/.test(vp) && /vibe_math_lean_lib/.test(vp), 'the prompt names the three v3 Lean tools')
395
400
  assert(/Formal\/(相对项目根)/.test(vp) && /VibeMath\/Formal\/Lib/.test(vp), 'the prompt states the path layout')
396
401
  }
@@ -599,6 +604,12 @@ await callTool('vibe_math_start', {}, RF)
599
604
  assert(/必须产出 Lean 形式化/.test(vp), "'require' states the formalization is mandatory")
600
605
  assert(/本次裁定不会生效/.test(vp), 'the prompt warns that the verdict will not take effect without it')
601
606
  assert(/formal-required/.test(vp), 'the prompt names the machine-readable reason')
607
+ assert(/归档可复用定义\/引理前先跑通(vibe_math_lean_archive run=true 或先 vibe_math_lean_run);跑不通不要入库。/.test(vp),
608
+ '★ the verification prompt requires a GREEN run before archiving into the reuse library (§6 hard requirement 3)')
609
+ assert(/宿主没有 Lean 工具链(LEAN_NOT_FOUND)时:把代码写下来归档,并在回执的 note 里写明"宿主无 Lean 工具链"/.test(vp),
610
+ '★ and spells out the way out when the host has no Lean toolchain (§6 hard requirement 4)')
611
+ assert(/Result/.test(vp) && !/verdict/.test(vp) && !/(^|[^a-z_])lean_(run|archive|lib)/.test(vp),
612
+ '★ the voting prompt uses FULL tool names and names Result, never verdict (§6 hard requirements 1-2)')
602
613
  }
603
614
  }
604
615
  assert(await drive(RF, () => /p-gate/.test(readIf(join(gateProj, 'Formal', 'TODO.md'))), 'p-gate in Formal/TODO.md'), '★ a unanimous TRUE verdict was withheld: the object is on the formalization TODO')
@@ -756,6 +767,182 @@ await callTool('vibe_math_add_proposition', { id: 'p-nonote', 概述: '没有理
756
767
  }
757
768
  await callTool('vibe_math_abort', {}, RG)
758
769
 
770
+ // ===============================================================
771
+ // 8b. the §4.1 `defect` channel (contract §4.1 / §6 / §10 items 8-9)
772
+ //
773
+ // A fidelity defect is NOT "the proposition is false". These are BEHAVIOURAL assertions: a real
774
+ // agent reply carrying `formal:{decision:'defect', note}` is fed through the real reply path
775
+ // (subagent/end → handleVerifier → absorbFormalReply) and the record, the archived file and the
776
+ // formalization TODO are inspected on disk.
777
+ // ===============================================================
778
+ section('8b a formal.decision=defect reply withdraws the passed proof and withholds the verdict')
779
+ const RH = makeRoot()
780
+ await callTool('vibe_math_new_project', { name: 'lean-defect' }, RH)
781
+ await callTool('vibe_math_set_params', Object.assign({}, VPARAMS, { formalVerify: 'require' }), RH)
782
+ const defectProj = projRoot('lean-defect')
783
+ await callTool('vibe_math_add_proposition', { id: 'p-defect', 概述: '形式化写窄了的命题', 概率: 0.6, 分类: '数论' }, RH)
784
+ {
785
+ const pass = await callTool('vibe_math_lean_archive', { kind: 'proof', target: 'p-defect', content: 'theorem p_defect : 2 + 2 = 4 := by decide\n' }, RH)
786
+ assert(pass.ok === true && pass.passed === true, 'defect: the object starts out Lean-passed')
787
+ assert(existsSync(join(defectProj, 'Verified', 'Lean', 'p-defect.lean')), 'defect: the archived proof is on disk before the fidelity review')
788
+ }
789
+ await callTool('vibe_math_start', {}, RH)
790
+ {
791
+ const re = verifyRe('p-defect')
792
+ assert(await drive(RH, () => unfiredVerifiers(RH, re).length >= 2, 'verifiers for r-p-defect'), 'defect: the Lean-passed object is put to a fidelity review')
793
+ const vs = unfiredVerifiers(RH, re).slice(0, 2)
794
+ if (vs.length === 2) {
795
+ for (const v of vs) firedChildren.add(v.childId)
796
+ assert(/该对象已有\*\*通过的 Lean 形式化证明\*\*/.test(vs[0].prompt) && /不要投 0/.test(vs[0].prompt) && /formal:\{decision:'defect'/.test(vs[0].prompt),
797
+ 'defect: the fidelity prompt asks for the defect reply and forbids recording the deviation as 0')
798
+ // The defect reply carries an EXTREME Result on purpose: the gate (not the vote value) has to
799
+ // be what withholds the verdict — a defect must never be harvested as "the proposition is false".
800
+ fireEnd(vs[0].childId, { Result: 1, Reason: '逐条核对后认定形式化不忠实', formal: { target: 'p-defect', decision: 'defect', note: 'Lean 代码多加了 h>0 假设,命题原文未要求' } })
801
+ await sleep(240)
802
+ const st = await callTool('vibe_math_status', {}, RH)
803
+ const rec = st.formal.objects.find((o) => o.target === 'p-defect')
804
+ assert(!!rec && rec.status === 'attempted', '★ defect downgrades the formal record to attempted (observed ' + (rec && rec.status) + ')')
805
+ assert(st.formal.passed.indexOf('p-defect') === -1, '★ and the object is no longer reported as Lean-passed')
806
+ assert(!!rec && rec.proof === '', '★ defect clears the `proof` field')
807
+ assert(!existsSync(join(defectProj, 'Verified', 'Lean', 'p-defect.lean')), '★ defect deletes the archived proof Verified/Lean/p-defect.lean')
808
+ assert(existsSync(join(defectProj, 'Formal', 'p-defect.lean')), 'the WORK file Formal/p-defect.lean survives (the code itself is not lost)')
809
+ const persisted = JSON.parse(readIf(join(defectProj, 'State', 'formal.json')))
810
+ assert(persisted.records['p-defect'].decision === 'defect' && /多加了 h>0 假设/.test(persisted.records['p-defect'].note),
811
+ '★ the note (the concrete deviation) is recorded in the persisted formal record')
812
+ assert(/- 形式化: 已尝试未通过/.test(readIf(join(defectProj, 'Propos', '数论', 'p-defect.md'))), 'and the object card anchor is refreshed')
813
+ fireEnd(vs[1].childId, { Result: 1, Reason: '同意:形式化不忠实' })
814
+ await sleep(300)
815
+ }
816
+ }
817
+ {
818
+ const todo = readIf(join(defectProj, 'Formal', 'TODO.md'))
819
+ assert(/p-defect/.test(todo) && /多加了 h>0 假设/.test(todo), '★ the deviation is written into Formal/TODO.md')
820
+ const idx = readIf(join(defectProj, 'Formal', 'Index.md'))
821
+ assert(/p-defect/.test(idx) && /attempted/.test(idx) && !/Verified\/Lean\/p-defect\.lean/.test(idx), 'Formal/Index.md now shows attempted with no archived proof')
822
+ assert(!existsSync(join(defectProj, 'Verified', '命题', 'p-defect.md')), '★ require after a defect: NO Verified card is written (the verdict is withheld, not turned into "false")')
823
+ const card = readIf(join(defectProj, 'Propos', '数论', 'p-defect.md'))
824
+ assert(/- 状态: 未定论/.test(card), '★ and the object stays 未定论')
825
+ assert(/- 概率: 0.6/.test(card), 'the object keeps its existing probability: a defect must NOT be harvested as a refutation')
826
+ const ann = readIf(join(defectProj, 'Logs', '形式化.md'))
827
+ assert(/忠实性缺陷/.test(ann) && /多加了 h>0 假设/.test(ann), '★ the defect is announced with its concrete deviation')
828
+ assert(ann.indexOf('不是"命题为假"') !== -1, 'the announcement spells out that a fidelity defect is NOT "the proposition is false"')
829
+ const st = await callTool('vibe_math_status', {}, RH)
830
+ assert(st.formal.todo.some((t) => t.id === 'p-defect'), '★ the object is on the formalization TODO (undecided until the formalization is fixed and re-run)')
831
+ }
832
+ await callTool('vibe_math_abort', {}, RH)
833
+
834
+ section('8b-2 a defect without a note is refused (the deviation must be auditable)')
835
+ const RI = makeRoot()
836
+ await callTool('vibe_math_new_project', { name: 'lean-defect-nonote' }, RI)
837
+ await callTool('vibe_math_set_params', Object.assign({}, VPARAMS, { formalVerify: 'require' }), RI)
838
+ const nonoteProj = projRoot('lean-defect-nonote')
839
+ await callTool('vibe_math_add_proposition', { id: 'p-nonote-defect', 概述: '没有偏差说明的缺陷回执', 概率: 0.6, 分类: '数论' }, RI)
840
+ await callTool('vibe_math_lean_archive', { kind: 'proof', target: 'p-nonote-defect', content: 'theorem p_nn_defect : 2 + 2 = 4 := by decide\n' }, RI)
841
+ await callTool('vibe_math_start', {}, RI)
842
+ {
843
+ const re = verifyRe('p-nonote-defect')
844
+ assert(await drive(RI, () => unfiredVerifiers(RI, re).length >= 2, 'verifiers for r-p-nonote-defect'), 'defect: the passed object is put to a fidelity review')
845
+ const vs = unfiredVerifiers(RI, re).slice(0, 2)
846
+ if (vs.length === 2) {
847
+ for (const v of vs) firedChildren.add(v.childId)
848
+ fireEnd(vs[0].childId, { Result: 1, Reason: '觉得不忠实但没写清楚', formal: { target: 'p-nonote-defect', decision: 'defect' } })
849
+ await sleep(240)
850
+ const st = await callTool('vibe_math_status', {}, RI)
851
+ const rec = st.formal.objects.find((o) => o.target === 'p-nonote-defect')
852
+ assert(!!rec && rec.status === 'passed', '★ a defect WITHOUT a note is refused: the object stays Lean-passed (no silent downgrade)')
853
+ assert(existsSync(join(nonoteProj, 'Verified', 'Lean', 'p-nonote-defect.lean')), '★ and the archived proof is NOT deleted')
854
+ assert(st.formal.todo.every((t) => t.id !== 'p-nonote-defect') && !/p-nonote-defect/.test(readIf(join(nonoteProj, 'Formal', 'TODO.md'))),
855
+ 'and no bogus formalization-TODO entry is created')
856
+ assert(/未写明 note/.test(readIf(join(nonoteProj, 'Logs', '形式化.md'))), '★ the refusal is announced explicitly')
857
+ fireEnd(vs[1].childId, { Result: 1, Reason: '核对后认为一致' })
858
+ await sleep(300)
859
+ }
860
+ }
861
+ assert(await drive(RI, () => existsSync(join(nonoteProj, 'Verified', '命题', 'p-nonote-defect.md')), 'Verified card'), 'a refused defect leaves the gate open: the same vote still promotes the object')
862
+ // §4.1: the downgrade is unconditional — a `blocked` record loses to a defect too (it needs REDOING,
863
+ // not a free pass through the gate, which `blocked` would otherwise grant).
864
+ await callTool('vibe_math_add_proposition', { id: 'p-blocked-defect', 概述: '阻塞后仍被认定不忠实', 概率: 0.6, 分类: '数论' }, RI)
865
+ await callTool('vibe_math_lean_archive', { kind: 'blocked', target: 'p-blocked-defect', note: '先按难度记为阻塞' }, RI)
866
+ await restart(RI)
867
+ {
868
+ const re = verifyRe('p-blocked-defect')
869
+ assert(await drive(RI, () => unfiredVerifiers(RI, re).length >= 2, 'verifiers for r-p-blocked-defect'), 'a blocked object is put to a vote (the gate is open for blocked)')
870
+ const vs = unfiredVerifiers(RI, re).slice(0, 2)
871
+ if (vs.length === 2) {
872
+ for (const v of vs) firedChildren.add(v.childId)
873
+ fireEnd(vs[0].childId, { Result: 1, Reason: '形式化与命题不对应', formal: { target: 'p-blocked-defect', decision: 'defect', note: '阻塞所依据的形式化本身写错了对象' } })
874
+ await sleep(240)
875
+ const st = await callTool('vibe_math_status', {}, RI)
876
+ const rec = st.formal.objects.find((o) => o.target === 'p-blocked-defect')
877
+ assert(!!rec && rec.status === 'attempted', '★★ a defect ALWAYS downgrades, even from `blocked` (observed ' + (rec && rec.status) + ')')
878
+ assert(st.formal.blocked.indexOf('p-blocked-defect') === -1 && /阻塞所依据的形式化本身写错了对象/.test(rec.note || ''), 'and the blocked record is replaced by the concrete deviation')
879
+ fireEnd(vs[1].childId, { Result: 1, Reason: '同意,形式化写错了对象' })
880
+ await sleep(280)
881
+ }
882
+ }
883
+ assert(!existsSync(join(nonoteProj, 'Verified', '命题', 'p-blocked-defect.md')), 'require after a blocked→defect downgrade: still no Verified card (undecided, not "false")')
884
+ await callTool('vibe_math_abort', {}, RI)
885
+
886
+ // ===============================================================
887
+ // 8c. the injected text obeys the five hard requirements of contract §6
888
+ // ===============================================================
889
+ section('8c the injected text uses full tool names, Result (not verdict) and the run-before-archive rule')
890
+ const RJ = makeRoot()
891
+ await callTool('vibe_math_new_project', { name: 'lean-workline' }, RJ)
892
+ await callTool('vibe_math_set_params', Object.assign({}, VPARAMS, { formalVerify: 'require' }), RJ)
893
+ await callTool('vibe_math_add_problem', { id: 'q-defect', description: '顺手形式化的对象', priority: 0 }, RJ)
894
+ const workProj = projRoot('lean-workline')
895
+ // a `meta.formal` defect on the WORK-round path (absorbFormalFromReply) must downgrade too
896
+ await callTool('vibe_math_lean_archive', { kind: 'proof', target: 'q-defect', content: 'theorem q_defect : 2 + 2 = 4 := by decide\n' }, RJ)
897
+ await callTool('vibe_math_start', {}, RJ)
898
+ assert(await drive(RJ, () => !!lastSpawn(RJ, 'explorer:q-defect'), 'explorer:q-defect'), 'the explorer for q-defect was spawned')
899
+ {
900
+ const p = lastSpawn(RJ, 'explorer:q-defect').prompt
901
+ assert(/归档前先跑通(vibe_math_lean_run 或 run=true);跑不通的定义不要进可复用库。/.test(p),
902
+ '★ the work-round prompt requires a GREEN run before archiving a reusable definition (§6 hard requirement 3)')
903
+ assert(/"decision":"used\|blocked\|defect"/.test(p), 'the work-round reply contract advertises the defect decision too')
904
+ assert(!/verdict/.test(p) && !/(^|[^a-z_])lean_(run|archive|lib)/.test(p),
905
+ '★ the work-round prompt uses FULL tool names only and never the v4/v5 field name `verdict`')
906
+ fireEnd(lastSpawn(RJ, 'explorer:q-defect').childId, {
907
+ meta: { kind: 'directions', qid: 'q-defect', formal: { target: 'q-defect', decision: 'defect', note: '陈述里的自然数范围被写成了整数' },
908
+ directions: [{ id: 'd1', title: '直接形式化', method: 'Lean', core_assumption: '', feasibility: 0.6 }] },
909
+ })
910
+ await sleep(260)
911
+ const st = await callTool('vibe_math_status', {}, RJ)
912
+ const rec = st.formal.objects.find((o) => o.target === 'q-defect')
913
+ assert(!!rec && rec.status === 'attempted' && /自然数范围被写成了整数/.test(rec.note || ''),
914
+ '★ a `meta.formal` defect from a WORK reply downgrades the record too (absorbFormalFromReply, not just the verifier path)')
915
+ assert(!existsSync(join(workProj, 'Verified', 'Lean', 'q-defect.lean')), '★ and its archived proof is deleted')
916
+ }
917
+ await callTool('vibe_math_abort', {}, RJ)
918
+
919
+ section('8c-2 the fidelity branch reaches BOTH the review and the debate prompt, and names Result')
920
+ const RK = makeRoot()
921
+ await callTool('vibe_math_new_project', { name: 'lean-fidelity' }, RK)
922
+ await callTool('vibe_math_set_params', Object.assign({}, VPARAMS, { formalVerify: 'encourage', debateMaxRounds: 2 }), RK)
923
+ await callTool('vibe_math_add_proposition', { id: 'p-fid', 概述: '忠实性审查措辞观察对象', 概率: 0.6, 分类: '数论' }, RK)
924
+ await callTool('vibe_math_lean_archive', { kind: 'proof', target: 'p-fid', content: 'theorem p_fid : 2 + 2 = 4 := by decide\n' }, RK)
925
+ await callTool('vibe_math_start', {}, RK)
926
+ const fidBatch = await runVerifyRound(RK, 'p-fid', [0.9, 0.95])
927
+ assert(fidBatch !== null, 'fidelity: the review round was asked')
928
+ if (fidBatch) {
929
+ const vp = fidBatch.map((s) => s.prompt).join('\n')
930
+ assert(/一致 → Result = 1/.test(vp), "★ the review prompt states the faithful case as `Result = 1` (v3's REAL reply field, not v4/v5's verdict)")
931
+ assert(/发现任何偏差,不要投 0/.test(vp) && /形式化不合格/.test(vp), '★ and forbids expressing a fidelity defect as 0')
932
+ assert(/formal:\{decision:'defect', note:'<具体偏差>'\}/.test(vp), 'and points at the defect reply field to record it')
933
+ assert(/独立于这份 Lean 代码/.test(vp), 'only an INDEPENDENT refutation may be voted 0')
934
+ assert(/Result/.test(vp) && !/verdict/.test(vp), '★ the voting prompt names Result, never verdict (§6 hard requirement 2)')
935
+ assert(vp.indexOf('偏离 → 0') === -1, '★ no "偏离 → 0" instruction anywhere in the fidelity branch (contract §10 item 9)')
936
+ }
937
+ assert(await drive(RK, () => wakes.some((w) => w.rootId === RK.id && /交流群/.test(w.prompt)), 'debate prompt'), 'a non-consensus fidelity round moved to the debate')
938
+ {
939
+ const dp = wakes.filter((w) => w.rootId === RK.id).map((w) => w.prompt).join('\n')
940
+ assert(/一致 → Result = 1/.test(dp) && /不要投 0/.test(dp), '★ the DEBATE prompt carries the same fidelity wording')
941
+ assert(/Result/.test(dp) && !/verdict/.test(dp), 'the debate prompt names Result, never verdict')
942
+ assert(dp.indexOf('偏离 → 0') === -1, 'the debate prompt also refuses "a deviation is a 0"')
943
+ }
944
+ await callTool('vibe_math_abort', {}, RK)
945
+
759
946
  // ===============================================================
760
947
  // 9. reporting + persistence
761
948
  // ===============================================================
@@ -792,8 +979,11 @@ section('10 the captured prompt corpus is written for human review')
792
979
  mkdirSync(CORPUS_DIR, { recursive: true })
793
980
  writeFileSync(join(CORPUS_DIR, 'formal-verify-v3.json'), JSON.stringify({ entries: corpus }, null, 2), 'utf8')
794
981
  const md = ['# V3 形式化验证交互语料(prompt corpus)', '',
795
- '> 由 `formal-verify-v3.test.mjs` 落盘:框架**真正发出**的每一条提示词原文(工作区路径归一化为 `<WS>`,可 diff)。',
796
- '> 覆盖:explorer / solver / method-keeper 的日常工作提示词、三种模式下的表决初评与辩论提示词、规划提示词。', '']
982
+ '> 由 `formal-verify-v3.test.mjs` 落盘:框架**真正发出**的每一条提示词原文。路径归一化:工作区 → `<WS>`,',
983
+ '> VibeMath 根 → `<VIBEMATH>`(两者都按正/反斜杠两种写法替换,因此语料是确定性的、可 diff 的、不泄露本机路径)。',
984
+ '> 覆盖:explorer / solver / method-keeper 的日常工作提示词(含「顺手形式化」与"归档前先跑通"),',
985
+ '> `off`(零 Lean 文本)、`encourage`、**`require`** 三档下的表决初评与辩论提示词,`passed` 之后的忠实性审查分支',
986
+ '> (含 `defect` 出口),以及规划提示词。', '']
797
987
  for (let i = 0; i < corpus.length; i++) {
798
988
  const c = corpus[i]
799
989
  md.push('## [' + i + '] ' + c.kind + ' · ' + c.label)
@@ -809,10 +999,27 @@ section('10 the captured prompt corpus is written for human review')
809
999
  assert(corpus.some((c) => c.label.startsWith('explorer:')) && corpus.some((c) => c.label.startsWith('solver:')) && corpus.some((c) => c.label.startsWith('method-keeper')) && corpus.some((c) => c.label.startsWith('verifier:')), 'the corpus covers every interaction type this suite drives')
810
1000
  assert(corpus.some((c) => c.kind === 'wake'), 'the corpus also keeps the continuation prompts (debate rounds)')
811
1001
  // generic sweep over EVERY captured prompt, not spot checks (AUDIT §2.1)
812
- const dirty = corpus.filter((c) => /\[object Object\]|\bNaN\b|\bundefined\b/.test(c.prompt))
1002
+ const dirty = corpus.filter((c) => /\[object Object\]|\bNaN\b|:\s*undefined|["']undefined["']|undefined\s*[,}\]]/.test(c.prompt))
813
1003
  assert(dirty.length === 0, 'no captured prompt contains placeholder garbage (' + dirty.map((d) => d.label).join(',') + ')')
814
1004
  const joined = corpus.map((c) => c.prompt).join('\n')
815
1005
  assert(joined.indexOf(WS) === -1 && joined.indexOf(WS.replace(/\\/g, '/')) === -1, 'every captured prompt normalises the workspace path to <WS> (the corpus stays diffable)')
1006
+ assert(joined.indexOf(VIBE) === -1 && joined.indexOf(VIBE.replace(/\\/g, '/')) === -1 && joined.indexOf('<VIBEMATH>') !== -1,
1007
+ '★ every captured prompt normalises the VibeMath root to <VIBEMATH> (no machine path leaks into the shipped corpus, contract §10 item 10)')
1008
+ assert(!corpus.some((c) => c.root === RA.id && /Lean|形式化/.test(c.prompt)),
1009
+ '★ the off-mode prompts captured in the corpus contain ZERO Lean text (off stays a true no-op)')
1010
+ // contract §10 item 10: the corpus must cover require AND the work round (not just encourage + fidelity)
1011
+ assert(corpus.some((c) => /【Lean 形式化验证(鼓励模式)】/.test(c.prompt)), '★ the corpus covers the encourage-mode verification prompt')
1012
+ assert(corpus.some((c) => /【Lean 形式化验证(强制模式)】/.test(c.prompt)), '★ the corpus covers the REQUIRE-mode verification prompt')
1013
+ assert(corpus.some((c) => /【顺手形式化(鼓励)】/.test(c.prompt)) && corpus.some((c) => /【顺手形式化(强制)】/.test(c.prompt)), '★ the corpus covers the work-round 顺手形式化 prompt in both modes')
1014
+ assert(corpus.some((c) => /一致 → Result = 1/.test(c.prompt)), '★ the corpus keeps the passed/fidelity branch verbatim for human review')
1015
+ // contract §6 hard requirements 1-2 + §10 item 9, swept over EVERY captured prompt
1016
+ const verifier = corpus.filter((c) => c.label.startsWith('verifier:'))
1017
+ assert(verifier.length >= 5 && verifier.every((c) => /Result/.test(c.prompt) && !/verdict/.test(c.prompt)),
1018
+ '★ every captured voting prompt names Result and never verdict (§6 hard requirement 2)')
1019
+ const bareTools = corpus.filter((c) => /(^|[^a-z_])lean_(run|archive|lib)/.test(c.prompt))
1020
+ assert(bareTools.length === 0, '★ no captured prompt abbreviates a Lean tool name (§6 hard requirement 1): ' + bareTools.map((b) => b.label).join(','))
1021
+ const zeroDeviation = corpus.filter((c) => c.prompt.indexOf('偏离 → 0') !== -1)
1022
+ assert(zeroDeviation.length === 0, '★ no captured prompt turns a fidelity defect into a 0 vote (§6 hard requirement 5 / §10 item 9): ' + zeroDeviation.map((b) => b.label).join(','))
816
1023
  }
817
1024
 
818
1025
  console.log('')