dsh-vibe-math 2.2.2 → 2.3.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/AUDIT-CHECKLIST.md +28 -0
- package/README.md +98 -1
- package/RELEASE-NOTES-2.3.0.md +207 -0
- package/audit-formal-sensitivity.mjs +247 -0
- package/audit-persona-sensitivity.mjs +249 -0
- package/audit-persona-surface.test.mjs +349 -0
- package/audit-v5-integrity.mjs +40 -1
- package/audit-v5-sensitivity.mjs +77 -6
- package/docs/formal-verification.md +321 -0
- package/docs/generate_framework_diagram_v5.mjs +22 -16
- package/formal-verify-v2.test.mjs +672 -0
- package/formal-verify-v3.test.mjs +824 -0
- package/formal-verify-v4.test.mjs +603 -0
- package/formal-verify-v5.test.mjs +526 -0
- package/package.json +15 -2
- package/prompt-corpus-persona/persona-corpus.json +32 -0
- package/prompt-corpus-persona/persona-corpus.md +674 -0
- package/prompt-corpus-v3/formal-verify-v3.json +280 -0
- package/prompt-corpus-v3/formal-verify-v3.md +2826 -0
- package/prompt-corpus-v5/prompt-corpus-v5.json +75 -9
- package/prompt-corpus-v5/prompt-corpus-v5.md +384 -65
- package/prompt-v5-integrity.test.mjs +111 -10
- package/vibe-math-v2/agent.cordis.yml +40 -2
- package/vibe-math-v2/vibe-math-v2.js +627 -19
- package/vibe-math-v2//345/256/236/347/216/260/346/226/271/346/241/210.md +145 -1
- package/vibe-math-v3/agent.cordis.yml +46 -2
- package/vibe-math-v3/vibe-math-v3.js +749 -21
- package/vibe-math-v3//345/256/236/347/216/260/346/226/271/346/241/210.md +87 -2
- package/vibe-math-v4/agent.cordis.yml +46 -4
- package/vibe-math-v4/vibe-math-v4.js +652 -15
- package/vibe-math-v4//345/256/236/347/216/260/346/226/271/346/241/210.md +226 -0
- package/vibe-math-v5/agent.cordis.yml +41 -5
- package/vibe-math-v5/vibe-math-v5.js +562 -9
- package/vibe-math-v5//345/256/236/347/216/260/346/226/271/346/241/210.md +108 -4
- package/vibe-math-v5//346/236/266/346/236/204/345/233/276.md +57 -0
- package//347/244/272/344/276/213/345/233/276//346/241/206/346/236/266/345/233/276-v5.svg +51 -46
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// V4 LEAN FORMAL VERIFICATION SUITE (docs/formal-verification.md)
|
|
3
|
+
//
|
|
4
|
+
// Asserts the whole contract of the `formalVerify` knob for the v4 preset:
|
|
5
|
+
// · 'off' is a TRUE no-op (no Lean text anywhere, no gate, verification unchanged)
|
|
6
|
+
// · 'encourage' injects the Lean section into the VERIFICATION prompt AND the ordinary work
|
|
7
|
+
// round, and — the actual point of the feature — turns the voting prompt into a
|
|
8
|
+
// FIDELITY review once a Lean run has passed
|
|
9
|
+
// · 'require' withholds a unanimous 真/假 verdict as 未定论 until the object is Lean-passed
|
|
10
|
+
// or carries an explicit, reasoned blocker record; then it allows it, and the
|
|
11
|
+
// Verified card records how strong the result really is
|
|
12
|
+
// · the three tools (run / archive / lib) write the right things to the right paths
|
|
13
|
+
//
|
|
14
|
+
// The Lean toolchain is mocked through the `subprocess` SERVICE (a fake Lean: a file passes unless
|
|
15
|
+
// it still contains `sorry` or the marker `-- FAIL`), so the tests exercise the REAL code path
|
|
16
|
+
// (resolveExecutable → spawn → collected stdout → exit code) without requiring Lean to be installed.
|
|
17
|
+
//
|
|
18
|
+
// V4_PLUGIN lets a sensitivity probe point this suite at a MUTATED copy of the plugin; without that
|
|
19
|
+
// override every probe would run the unmutated file and pass vacuously (AUDIT-CHECKLIST §2.5).
|
|
20
|
+
//
|
|
21
|
+
// Prompt text is asserted through the plugin's own `vibe_v4_prompts` host tool — the exact builder
|
|
22
|
+
// the framework uses — rather than by guessing which queued wake carries which prompt. That keeps
|
|
23
|
+
// the assertions precise even when the scheduler queues several rounds in one pass, and the suite
|
|
24
|
+
// still drives the real consensus path for every STATE transition (AUDIT-CHECKLIST §0.1/§2.2).
|
|
25
|
+
//
|
|
26
|
+
// Run: node formal-verify-v4.test.mjs
|
|
27
|
+
// ============================================================
|
|
28
|
+
import { mkdtempSync, existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs'
|
|
29
|
+
import { tmpdir } from 'node:os'
|
|
30
|
+
import { join, dirname, isAbsolute } from 'node:path'
|
|
31
|
+
import { pathToFileURL, fileURLToPath } from 'node:url'
|
|
32
|
+
|
|
33
|
+
// V4_PLUGIN (same convention the v5 suite uses for V5_PLUGIN): point the suite at a MUTATED copy of
|
|
34
|
+
// the plugin so a sensitivity probe can prove each invariant actually turns this suite red. Accept a
|
|
35
|
+
// plain filesystem path or a file:// URL, and never touch the value otherwise.
|
|
36
|
+
function pluginUrl() {
|
|
37
|
+
const raw = process.env.V4_PLUGIN
|
|
38
|
+
if (!raw || !String(raw).trim()) return new URL('./vibe-math-v4/vibe-math-v4.js', import.meta.url)
|
|
39
|
+
const s = String(raw).trim()
|
|
40
|
+
if (/^file:/i.test(s)) return new URL(s)
|
|
41
|
+
return pathToFileURL(fileURLToPath(new URL('file:///' + s.replace(/\\/g, '/'))))
|
|
42
|
+
}
|
|
43
|
+
const PLUGIN = pluginUrl()
|
|
44
|
+
|
|
45
|
+
let passed = 0, failed = 0
|
|
46
|
+
const failures = []
|
|
47
|
+
const assert = (c, m) => { if (c) { passed++; console.log(' ok - ' + m) } else { failed++; failures.push(m); console.error(' FAIL - ' + m) } }
|
|
48
|
+
const sleep = ms => new Promise(r => setTimeout(r, ms))
|
|
49
|
+
const section = (t) => console.log('\n[' + t + ']')
|
|
50
|
+
const JSONX = o => '```json\n' + JSON.stringify(o) + '\n```'
|
|
51
|
+
const promptOf = (entry) => (entry && entry.blocks && entry.blocks[0] && entry.blocks[0].text) || ''
|
|
52
|
+
const readIf = (p) => (existsSync(p) ? readFileSync(p, 'utf8') : '')
|
|
53
|
+
|
|
54
|
+
// ===============================================================
|
|
55
|
+
// MOCK HOST — the shape selfdrive-v4 / e2e-v4-fixes use, plus a fake Lean
|
|
56
|
+
// ===============================================================
|
|
57
|
+
let toolchainAvailable = true
|
|
58
|
+
const leanRuns = [] // every spawn the framework made, for cwd/argv assertions
|
|
59
|
+
|
|
60
|
+
function makeSubprocess() {
|
|
61
|
+
return {
|
|
62
|
+
async resolveExecutable(cmd) {
|
|
63
|
+
if (!toolchainAvailable) throw new Error('spawn lean ENOENT')
|
|
64
|
+
if (String(cmd) !== 'lean' && String(cmd) !== 'lake') throw new Error('unknown executable ' + cmd)
|
|
65
|
+
return String(cmd)
|
|
66
|
+
},
|
|
67
|
+
spawn(spec) {
|
|
68
|
+
// The plugin passes an ABSOLUTE path as the last argv element, so resolve it directly; fall
|
|
69
|
+
// back to scanning the argv for an existing .lean file (mirrors leanAbsPath).
|
|
70
|
+
const last = spec.argv[spec.argv.length - 1]
|
|
71
|
+
const file = existsSync(last) ? last : (spec.argv.find(a => /\.lean$/.test(String(a)) && existsSync(a)) || last)
|
|
72
|
+
const text = existsSync(file) ? readFileSync(file, 'utf8') : ''
|
|
73
|
+
const bad = /sorry|-- FAIL/.test(text)
|
|
74
|
+
leanRuns.push({ argv: spec.argv.slice(), file, cwd: spec.cwd, graceMs: spec.graceMs, stdio: spec.stdio })
|
|
75
|
+
const stdout = bad ? '' : 'ok\n'
|
|
76
|
+
const stderr = bad ? 'error: declaration uses sorry\n' : ''
|
|
77
|
+
return {
|
|
78
|
+
done: Promise.resolve({ exitCode: bad ? 1 : 0, signal: null }),
|
|
79
|
+
collected: {
|
|
80
|
+
stdout: { readFrom: () => ({ text: stdout, nextOffset: stdout.length, lossy: false }) },
|
|
81
|
+
stderr: { readFrom: () => ({ text: stderr, nextOffset: stderr.length, lossy: false }) },
|
|
82
|
+
},
|
|
83
|
+
terminate() {},
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function makeHost() {
|
|
90
|
+
const WS = mkdtempSync(join(tmpdir(), 'vibe-v4-lean-'))
|
|
91
|
+
const listeners = {}, toolRegs = [], spawns = [], followups = []
|
|
92
|
+
const subprocess = makeSubprocess()
|
|
93
|
+
let ROOT
|
|
94
|
+
const ctx = {
|
|
95
|
+
get(name) { return name === 'subprocess' ? subprocess : undefined },
|
|
96
|
+
on(e, fn) { (listeners[e] = listeners[e] || []).push(fn) },
|
|
97
|
+
effect(fn) { const d = fn(); return () => { if (typeof d === 'function') d() } },
|
|
98
|
+
logger: { info() {}, warn() {}, error() {} },
|
|
99
|
+
timeout(cb, ms) { const h = setTimeout(cb, ms); return () => clearTimeout(h) },
|
|
100
|
+
tools: { register(s) { toolRegs.push(s) } }, commands: { register() {} },
|
|
101
|
+
// Real DSH exposes ONLY subagents.sendMessage for continuable wakes (followup is an Agent
|
|
102
|
+
// method, not a subagents service method) — deliberately no followup, so a regression fails.
|
|
103
|
+
subagents: {
|
|
104
|
+
list() { return ['spawn'] },
|
|
105
|
+
async startContinuable({ label, request }) { const id = 'c' + (spawns.length + 1); spawns.push({ label, request, childId: id }); return { childId: id } },
|
|
106
|
+
async sendMessage(parent, childId, blocks) { followups.push({ childId, blocks }) },
|
|
107
|
+
interrupt() {},
|
|
108
|
+
},
|
|
109
|
+
agents: { roots() { return [] }, get(id) { return id === 'sess-A' ? ROOT : undefined } },
|
|
110
|
+
fs: {
|
|
111
|
+
async resolve(rel, opts) { const b = (opts && opts.cwd) || WS; const p = (typeof rel === 'string' && isAbsolute(rel)) ? rel.replace(/\//g, '\\') : join(b, ...String(rel).split('/')); return { targetKey: p, displayPath: p } },
|
|
112
|
+
async stat(t) { return existsSync(t.targetKey) ? { version: 'v1', type: 'file', size: 1 } : undefined },
|
|
113
|
+
async readText(t) { return readFileSync(t.targetKey, 'utf8') },
|
|
114
|
+
async writeText(t, c) { mkdirSync(dirname(t.targetKey), { recursive: true }); writeFileSync(t.targetKey, c, 'utf8') },
|
|
115
|
+
async listDir(t) { if (!existsSync(t.targetKey)) return []; return readdirSync(t.targetKey, { withFileTypes: true }).map(e => ({ name: e.name, type: e.isDirectory() ? 'directory' : 'file' })) },
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
ROOT = { id: 'sess-A', options: { provider: 'mock', model: 'm' }, session: { id: 'sess-A', header: { cwd: WS, parentSession: undefined } }, followup() {}, ctx: undefined }
|
|
119
|
+
const projectRoot = join(WS, 'VibeMath', 'Projects', 'default')
|
|
120
|
+
const vibeRoot = join(WS, 'VibeMath')
|
|
121
|
+
let consumed = 0
|
|
122
|
+
const h = {
|
|
123
|
+
WS, ctx, toolRegs, spawns, followups, ROOT, projectRoot, vibeRoot,
|
|
124
|
+
async callTool(n, a, agent) {
|
|
125
|
+
const s = toolRegs.find(x => x.name === n); if (!s) throw new Error('no tool ' + n)
|
|
126
|
+
return JSON.parse(await s.execute(a || {}, { agent: agent || ROOT }))
|
|
127
|
+
},
|
|
128
|
+
/** The exact prompt text a resident would receive, read through the plugin's own host tool. */
|
|
129
|
+
async prompts(which, rId, arg) {
|
|
130
|
+
const out = await h.callTool('vibe_v4_prompts', Object.assign({ which, member: rId }, arg || {}), ROOT)
|
|
131
|
+
return out.text
|
|
132
|
+
},
|
|
133
|
+
resAgent: (cid) => ({ id: cid, session: { id: cid, header: { cwd: WS, parentSession: 'sess-A' } } }),
|
|
134
|
+
ridOfChild(cid) { for (const sp of spawns) if (sp.childId === cid) return sp.label; return '' },
|
|
135
|
+
childOf(rId) { for (const sp of spawns) if (sp.label === rId) return sp.childId; return '' },
|
|
136
|
+
fireEnd(cid, reply) {
|
|
137
|
+
const blocks = reply === undefined ? [] : [{ type: 'text', text: JSONX(reply) }]
|
|
138
|
+
for (const fn of (listeners['subagent/end'] || [])) fn({ id: cid, runId: 'r', provider: 'spawn', local: true, stopReason: 'completed', lastAssistantMessage: blocks })
|
|
139
|
+
},
|
|
140
|
+
/** Every prompt this project's residents have received (founding + wakes). */
|
|
141
|
+
allPrompts() {
|
|
142
|
+
return spawns.map(s => (s.request && s.request.prompt && s.request.prompt[0] && s.request.prompt[0].text) || '').join('\n')
|
|
143
|
+
+ '\n' + followups.map(promptOf).join('\n')
|
|
144
|
+
},
|
|
145
|
+
nextWake() { while (consumed < followups.length) return followups[consumed++]; return null },
|
|
146
|
+
resetCursor() { consumed = followups.length },
|
|
147
|
+
}
|
|
148
|
+
return h
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function mount() {
|
|
152
|
+
const h = makeHost()
|
|
153
|
+
const mod = await import(PLUGIN.href + '?t=' + Date.now() + Math.random())
|
|
154
|
+
;(mod.default || mod).apply(h.ctx)
|
|
155
|
+
return h
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ===============================================================
|
|
159
|
+
// driving helpers
|
|
160
|
+
// ===============================================================
|
|
161
|
+
/** Complete every brainstorm round so the run becomes phase=active, then park the heartbeat. */
|
|
162
|
+
async function establish() {
|
|
163
|
+
const h = await mount()
|
|
164
|
+
const before = h.spawns.length
|
|
165
|
+
await h.callTool('vibe_v4_start', { problem: '形式化契约验证测试', residentCount: 2 })
|
|
166
|
+
for (let i = 0; i < 60 && h.spawns.length < before + 2; i++) await sleep(10)
|
|
167
|
+
for (const sp of h.spawns.slice(before)) { h.fireEnd(sp.childId, { summary: '初始见解。', solved: false, contextPct: 10 }); await sleep(30) }
|
|
168
|
+
// Park the heartbeat far away: these tests drive wakes explicitly, so a short heartbeat would
|
|
169
|
+
// only add unrelated normal rounds and make the followup stream harder to reason about.
|
|
170
|
+
await h.callTool('vibe_v4_set', { activityTimeoutMs: 600000 })
|
|
171
|
+
for (let i = 0; i < 40; i++) { const s = await h.callTool('vibe_v4_status', {}); if (s.phase === 'active') break; await sleep(20) }
|
|
172
|
+
await sleep(30)
|
|
173
|
+
h.resetCursor()
|
|
174
|
+
return h
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Answer the next wake with `replyFor(promptText, rId)`; returns how many wakes were answered.
|
|
178
|
+
* `stop` is evaluated AFTER processing each wake, never before the first one: a run that is simply
|
|
179
|
+
* idle between rounds would otherwise satisfy "no verification in flight" at entry and the loop
|
|
180
|
+
* would exit without answering anything.
|
|
181
|
+
*/
|
|
182
|
+
async function drive(h, replyFor, stop, budget = 40) {
|
|
183
|
+
let n = 0
|
|
184
|
+
for (; n < budget; n++) {
|
|
185
|
+
const w = h.nextWake()
|
|
186
|
+
if (!w) break
|
|
187
|
+
const pt = promptOf(w)
|
|
188
|
+
h.fireEnd(w.childId, replyFor(pt, h.ridOfChild(w.childId)))
|
|
189
|
+
await sleep(12)
|
|
190
|
+
if (stop && await stop()) { n++; break }
|
|
191
|
+
}
|
|
192
|
+
return n
|
|
193
|
+
}
|
|
194
|
+
const verifySettled = (h) => async () => { const s = await h.callTool('vibe_v4_status', {}); return s.verifyInProgress === false && s.pendingVerify === null }
|
|
195
|
+
const voteReply = (plan) => (pt, rId) => (/团队验证/.test(pt)
|
|
196
|
+
? { vote: { verdict: plan(rId), reason: rId + ' 的判断' } }
|
|
197
|
+
: { summary: '继续推进。', solved: false, contextPct: 20 })
|
|
198
|
+
/** Drive the pending verification to a settled state and return the resulting status. */
|
|
199
|
+
async function settleVerify(h, plan = () => 1, budget = 40) {
|
|
200
|
+
await drive(h, voteReply(plan), verifySettled(h), budget)
|
|
201
|
+
return await h.callTool('vibe_v4_status', {})
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Record a card for `target`, have r-1 propose verifying it, vote it wherever it lands, and return
|
|
205
|
+
* the settled status. Prompt TEXT is asserted separately (see `h.prompts`) — this helper exercises
|
|
206
|
+
* the real consensus path for the STATE transitions.
|
|
207
|
+
*/
|
|
208
|
+
async function proposeAndVote(h, target, opts = {}) {
|
|
209
|
+
const card = opts.card || { id: target, title: target, statement: '待验证对象 ' + target, prob: 0.8, value: 0.6, motivation: 'm' }
|
|
210
|
+
await h.callTool('vibe_v4_record_proposition', card, h.resAgent(h.childOf('r-1')))
|
|
211
|
+
// The heartbeat is parked far away, so drive the FIRST round explicitly: an idle resident is
|
|
212
|
+
// woken immediately by an incoming message (postMessage → wakeResident).
|
|
213
|
+
const before = h.followups.length
|
|
214
|
+
await h.callTool('vibe_v4_message', { to: 'r-1', content: '请处理本轮工作。' })
|
|
215
|
+
for (let i = 0; i < 300 && h.followups.length === before; i++) await sleep(10)
|
|
216
|
+
const proposal = opts.proposal || { summary: '提议验证 ' + target + '。', solved: false, propose_verify: target, contextPct: 20 }
|
|
217
|
+
await drive(h, (pt) => (/团队验证/.test(pt)
|
|
218
|
+
? { vote: { verdict: (opts.verdict === undefined ? 1 : opts.verdict), reason: '预看提示词' } }
|
|
219
|
+
: proposal), verifySettled(h))
|
|
220
|
+
// The verification may only have been QUEUED by the proposal round; finish it.
|
|
221
|
+
return await settleVerify(h, opts.plan || (() => (opts.verdict === undefined ? 1 : opts.verdict)))
|
|
222
|
+
}
|
|
223
|
+
/** Wake exactly the given resident with an ordinary work round and return that wake. */
|
|
224
|
+
async function workWake(h, rId) {
|
|
225
|
+
const before = h.followups.length
|
|
226
|
+
await h.callTool('vibe_v4_message', { to: rId, content: '请继续推进。' })
|
|
227
|
+
for (let i = 0; i < 300 && h.followups.length === before; i++) await sleep(10)
|
|
228
|
+
const w = h.nextWake()
|
|
229
|
+
assert(w !== null, 'a work wake was delivered to ' + rId)
|
|
230
|
+
return w
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ===============================================================
|
|
234
|
+
console.log('-- V4 Lean formal verification --')
|
|
235
|
+
|
|
236
|
+
// ---------- 1. 'off' is a true no-op ----------
|
|
237
|
+
section("1 'off' (default) is a true no-op")
|
|
238
|
+
const A = await establish()
|
|
239
|
+
{
|
|
240
|
+
const st = await A.callTool('vibe_v4_status', {})
|
|
241
|
+
assert(st.formal.mode === 'off' && st.formal.on === false, "the default mode is 'off' (got " + st.formal.mode + ')')
|
|
242
|
+
assert(/formalVerify=off/.test(st.params), "status exposes formalVerify=off in its readable params (got " + st.params + ')')
|
|
243
|
+
// Scan BEFORE any hand-written test message is injected: this test's own text would otherwise
|
|
244
|
+
// taint the scan. The scan is on the feature's own TOKENS rather than the bare word 形式化: the
|
|
245
|
+
// pre-existing brainstorm brief already contains 形式化 in the unrelated sentence about being
|
|
246
|
+
// free to invent theories, so asserting the bare word would fail for a reason that has nothing
|
|
247
|
+
// to do with this contract (AUDIT-CHECKLIST §2.2).
|
|
248
|
+
const all = A.allPrompts()
|
|
249
|
+
assert(!/Lean/.test(all), 'no founding/round prompt mentions Lean in off mode')
|
|
250
|
+
assert(!/顺手形式化|Lean 通过|忠实性审查|vibe_v4_lean/.test(all), 'no founding/round prompt carries any Lean-formalization text in off mode')
|
|
251
|
+
assert(all.length > 0, 'sanity: the scan actually saw the founding prompts')
|
|
252
|
+
}
|
|
253
|
+
// an off-mode verification must behave exactly as before: unanimous 真 → Verified/, no formal record
|
|
254
|
+
const offSettled = await proposeAndVote(A, 'p-off', {
|
|
255
|
+
card: { id: 'p-off', title: '关模式', statement: '关模式下的普通命题', prob: 0.8, value: 0.6, motivation: 'm' },
|
|
256
|
+
proposal: { summary: '请提议验证 p-off。', solved: false, propose_verify: 'p-off', contextPct: 20 },
|
|
257
|
+
})
|
|
258
|
+
assert(existsSync(join(A.projectRoot, 'Verified', '命题', 'p-off.md')), "★ 'off' still closes a unanimous TRUE verdict with NO Lean artifact")
|
|
259
|
+
assert(offSettled.formal.passed.length === 0 && offSettled.formal.objects.length === 0, "'off' records no formal object at all")
|
|
260
|
+
assert(!/形式化/.test(readIf(join(A.projectRoot, 'Verified', '命题', 'p-off.md'))), 'the Verified card carries no formal line in off mode')
|
|
261
|
+
assert(!existsSync(join(A.projectRoot, 'Formal', 'TODO.md')) || !/p-off/.test(readIf(join(A.projectRoot, 'Formal', 'TODO.md'))), 'no formalization TODO was created for p-off')
|
|
262
|
+
assert(!/顺手形式化|Lean/.test(await A.prompts('verify', 'r-1', { target: 'p-off' })), 'the voting prompt carries no Lean text in off mode')
|
|
263
|
+
assert(!/顺手形式化/.test(await A.prompts('normal', 'r-1')), 'the work prompt carries no formalization line in off mode')
|
|
264
|
+
// the tools still EXIST in off mode (static registration), they are just never advertised
|
|
265
|
+
assert(['vibe_v4_lean_run', 'vibe_v4_lean_archive', 'vibe_v4_lean_lib'].every(n => !!A.toolRegs.find(t => t.name === n)),
|
|
266
|
+
'the three Lean tools are registered in every mode (registration is static)')
|
|
267
|
+
|
|
268
|
+
// ---------- 2. parameter validation + runtime switching ----------
|
|
269
|
+
section('2 parameter validation and runtime switching')
|
|
270
|
+
const B = await establish()
|
|
271
|
+
{
|
|
272
|
+
const bad = await B.callTool('vibe_v4_set', { formalVerify: 'banana' })
|
|
273
|
+
assert(bad.formal.mode === 'off' && /formalVerify=off/.test(bad.params), "an unknown mode degrades to 'off', never to a stronger mode (got " + bad.formal.mode + ')')
|
|
274
|
+
const enc = await B.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
275
|
+
assert(enc.formal.mode === 'encourage', "'encourage' is accepted")
|
|
276
|
+
const req = await B.callTool('vibe_v4_set', { formalVerify: 'require', leanTimeoutMs: -5, leanCommand: ' ' })
|
|
277
|
+
assert(req.formal.mode === 'require', "'require' is accepted")
|
|
278
|
+
assert(/leanTimeoutMs=120000/.test(req.params), 'a non-positive leanTimeoutMs falls back to the default (' + (/leanTimeoutMs=\S+/.exec(req.params) || [])[0] + ')')
|
|
279
|
+
assert(/leanCommand=lean/.test(req.params), 'a blank leanCommand falls back to "lean"')
|
|
280
|
+
const lk = await B.callTool('vibe_v4_set', { leanCommand: 'lake', leanArgs: ['env', 'lean'] })
|
|
281
|
+
assert(/leanCommand=lake/.test(lk.params) && /leanArgs=env,lean/.test(lk.params), 'leanCommand/leanArgs are settable (lake env lean)')
|
|
282
|
+
const la = await B.callTool('vibe_v4_set', { leanArgs: 'a, b ,,c' })
|
|
283
|
+
assert(/leanArgs=a,b,c/.test(la.params), 'leanArgs accepts a comma-separated string and drops blanks (got ' + (/leanArgs=[^,]*,[^,]*,[^,]*/.exec(la.params) || [])[0] + ')')
|
|
284
|
+
await B.callTool('vibe_v4_set', { leanTimeoutMs: 5 })
|
|
285
|
+
assert(/leanTimeoutMs=5/.test((await B.callTool('vibe_v4_status', {})).params), 'a legitimate leanTimeoutMs is preserved')
|
|
286
|
+
await B.callTool('vibe_v4_set', { leanTimeoutMs: 0 })
|
|
287
|
+
assert(/leanTimeoutMs=120000/.test((await B.callTool('vibe_v4_status', {})).params), 'leanTimeoutMs:0 also falls back to the default')
|
|
288
|
+
// the switch must be visible to the very NEXT prompt, not to some frozen brief
|
|
289
|
+
await B.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
290
|
+
assert(/顺手形式化/.test(await B.prompts('normal', 'r-1')), '★ switching the mode at runtime changes the NEXT prompt immediately')
|
|
291
|
+
await B.callTool('vibe_v4_set', { formalVerify: 'off' })
|
|
292
|
+
assert(!/顺手形式化/.test(await B.prompts('normal', 'r-1')), 'switching back to off removes it again')
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ---------- 3. 'encourage' injection into BOTH prompts ----------
|
|
296
|
+
section("3 'encourage' injects the Lean section into the verification AND the work prompt")
|
|
297
|
+
const C = await establish()
|
|
298
|
+
await C.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
299
|
+
{
|
|
300
|
+
// The ordinary work round. Read the builder AND drive a real wake, so the assertion cannot pass
|
|
301
|
+
// on a builder that is never actually used to address a resident.
|
|
302
|
+
const built = await C.prompts('normal', 'r-2')
|
|
303
|
+
assert(/【顺手形式化(鼓励)】/.test(built), '★ the ordinary work round tells residents to formalize reusable objects as they go')
|
|
304
|
+
assert(/vibe_v4_lean_archive kind='def'/.test(built), 'the work round points at the archive tool for reusable definitions')
|
|
305
|
+
assert(/vibe_v4_lean_lib 查重/.test(built), 'the work round tells them to de-duplicate against the reuse library first')
|
|
306
|
+
assert(/"formal":/.test(built), 'the work reply contract documents the formal field')
|
|
307
|
+
assert(/Resident researcher r-2/.test(built), 'the work prompt is addressed to the resident it is built for')
|
|
308
|
+
const hb = await C.prompts('heartbeat', 'r-2')
|
|
309
|
+
assert(/【顺手形式化(鼓励)】/.test(hb), 'the CHECKPOINT/heartbeat round carries it too')
|
|
310
|
+
const w = await workWake(C, 'r-2')
|
|
311
|
+
assert(/【顺手形式化(鼓励)】/.test(promptOf(w)), '★ a REAL delivered work wake contains the line (the builder is the one in use)')
|
|
312
|
+
C.fireEnd(w.childId, { summary: '继续推进。', solved: false, contextPct: 20 })
|
|
313
|
+
await sleep(30)
|
|
314
|
+
const core = await C.prompts('coreRules')
|
|
315
|
+
assert(/\[核心规则重申\]/.test(core) && /【顺手形式化(鼓励)】/.test(core), 'the post-compact core-rules recap also carries the formalization line')
|
|
316
|
+
}
|
|
317
|
+
{
|
|
318
|
+
await proposeAndVote(C, 'p-enc', {
|
|
319
|
+
card: { id: 'p-enc', title: '鼓励注入', statement: '鼓励模式下的忠实性审查', prob: 0.5, value: 0.6, motivation: 'm' },
|
|
320
|
+
proposal: { summary: '提议验证 p-enc。', solved: false, propose_verify: 'p-enc', contextPct: 20 },
|
|
321
|
+
verdict: 0.5, plan: () => 0.5,
|
|
322
|
+
})
|
|
323
|
+
const prompt = await C.prompts('verify', 'r-1', { target: 'p-enc', stage: 'independent' })
|
|
324
|
+
assert(/【Lean 形式化验证(鼓励模式)】/.test(prompt), 'the voting prompt explains the Lean mode')
|
|
325
|
+
assert(/一旦 Lean 通过,你唯一需要确认的就是忠实性/.test(prompt), 'the voting prompt states that a passing Lean run shrinks the question to fidelity')
|
|
326
|
+
assert(/实现难度/.test(prompt), 'the voting prompt asks for the implementation-difficulty judgement')
|
|
327
|
+
assert(/可以不做,但请在回执的 formal 字段写明难度判断/.test(prompt), "'encourage' explicitly allows skipping (with a recorded judgement)")
|
|
328
|
+
assert(/vibe_v4_lean_run/.test(prompt) && /vibe_v4_lean_archive/.test(prompt) && /vibe_v4_lean_lib/.test(prompt), 'the voting prompt names all three tools')
|
|
329
|
+
assert(/"formal":/.test(prompt), '★ the voting reply contract documents the formal field')
|
|
330
|
+
assert(/Resident r-1/.test(prompt), 'the voting prompt is addressed to the voter it is built for')
|
|
331
|
+
assert(!/强制模式/.test(prompt), "'encourage' does not use the mandatory wording")
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ---------- 4. the run tool ----------
|
|
335
|
+
section('4 lean_run executes through the subprocess service and reports honestly')
|
|
336
|
+
const D = await establish()
|
|
337
|
+
await D.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
338
|
+
mkdirSync(join(D.projectRoot, 'Formal'), { recursive: true })
|
|
339
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'good.lean'), 'theorem t : 1 = 1 := rfl\n', 'utf8')
|
|
340
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'bad.lean'), 'theorem t : 1 = 2 := by sorry\n', 'utf8')
|
|
341
|
+
const r1 = D.resAgent(D.childOf('r-1'))
|
|
342
|
+
const runGood = await D.callTool('vibe_v4_lean_run', { file: 'Formal/good.lean' }, r1)
|
|
343
|
+
assert(runGood.ok === true && runGood.exitCode === 0, 'a file with no sorry runs green (' + JSON.stringify({ ok: runGood.ok, exitCode: runGood.exitCode }) + ')')
|
|
344
|
+
assert(typeof runGood.ms === 'number' && typeof runGood.command === 'string' && runGood.file === 'Formal/good.lean', 'the result carries {ms, command, file} as the spec requires')
|
|
345
|
+
assert(leanRuns.length > 0 && String(leanRuns[leanRuns.length - 1].cwd).replace(/\\/g, '/') === D.projectRoot.replace(/\\/g, '/'), 'the toolchain runs with the PROJECT root as cwd')
|
|
346
|
+
{
|
|
347
|
+
const last = leanRuns[leanRuns.length - 1]
|
|
348
|
+
assert(String(last.argv[0]).indexOf('lean') !== -1 && /\.lean$/.test(String(last.argv[last.argv.length - 1])), 'argv is [exe, ...leanArgs, absolute file]')
|
|
349
|
+
assert(last.stdio && last.stdio.stdin === 'ignore', "stdin is ignored (the spec's stdio shape)")
|
|
350
|
+
}
|
|
351
|
+
const runBad = await D.callTool('vibe_v4_lean_run', { file: 'Formal/bad.lean' }, r1)
|
|
352
|
+
assert(runBad.ok === false && runBad.exitCode === 1, 'a file that still uses sorry reports a red run')
|
|
353
|
+
assert(/sorry/.test(runBad.stderr), 'the compiler output is returned verbatim (' + JSON.stringify(runBad.stderr).slice(0, 60) + ')')
|
|
354
|
+
assert(runBad.code === 'LEAN_FAILED', 'a red run is typed LEAN_FAILED')
|
|
355
|
+
const runMissing = await D.callTool('vibe_v4_lean_run', { file: 'Formal/nope.lean' }, r1)
|
|
356
|
+
assert(runMissing.ok === false && runMissing.code === 'V4_NOT_FOUND', 'a missing file is refused with a typed code')
|
|
357
|
+
const runNoFile = await D.callTool('vibe_v4_lean_run', {}, r1)
|
|
358
|
+
assert(runNoFile.ok === false && runNoFile.code === 'V4_INVALID_ARGUMENT', 'a run without a file is refused')
|
|
359
|
+
// The guard's boundary is the VibeMath ROOT, not the project: the global reuse library
|
|
360
|
+
// deliberately lives at <VibeMath>/Formal/{Lib,Proved}, so climbing out of the project but staying
|
|
361
|
+
// inside VibeMath must remain legal (it just fails as a missing file).
|
|
362
|
+
const runOutside = await D.callTool('vibe_v4_lean_run', { file: '../../Formal/Lib/x.lean' }, r1)
|
|
363
|
+
assert(runOutside.code === 'V4_NOT_FOUND', 'climbing out of the project but staying inside VibeMath is allowed (the global library lives there)')
|
|
364
|
+
const esc1 = await D.callTool('vibe_v4_lean_run', { file: '../../../../../etc/evil.lean' }, r1)
|
|
365
|
+
assert(esc1.ok === false && esc1.code === 'V4_INVALID_ARGUMENT', '★ a traversal that climbs ABOVE the VibeMath root is refused')
|
|
366
|
+
const esc2 = await D.callTool('vibe_v4_lean_run', { file: 'Formal/../../../../../../evil.lean' }, r1)
|
|
367
|
+
assert(esc2.ok === false && esc2.code === 'V4_INVALID_ARGUMENT', 'a deeper traversal is refused too')
|
|
368
|
+
const esc3 = await D.callTool('vibe_v4_lean_run', { file: '/etc/evil.lean' }, r1)
|
|
369
|
+
assert(esc3.ok === false && esc3.code === 'V4_INVALID_ARGUMENT', 'an unrelated absolute path is refused')
|
|
370
|
+
const esc4 = await D.callTool('vibe_v4_lean_run', { file: 'C:\\Windows\\evil.lean' }, r1)
|
|
371
|
+
assert(esc4.ok === false && esc4.code === 'V4_INVALID_ARGUMENT', 'an unrelated absolute path with a drive letter is refused')
|
|
372
|
+
const notLean = await D.callTool('vibe_v4_lean_run', { file: 'Formal/good.txt' }, r1)
|
|
373
|
+
assert(notLean.ok === false && notLean.code === 'V4_INVALID_ARGUMENT', 'only .lean files can be executed')
|
|
374
|
+
toolchainAvailable = false
|
|
375
|
+
const noTc = await D.callTool('vibe_v4_lean_run', { file: 'Formal/good.lean' }, r1)
|
|
376
|
+
assert(noTc.ok === false && noTc.code === 'LEAN_NOT_FOUND', '★ a missing toolchain returns LEAN_NOT_FOUND instead of crashing')
|
|
377
|
+
assert(/仍可把形式化代码写下来归档/.test(noTc.message || ''), 'the failure explains the graceful degradation')
|
|
378
|
+
assert((await D.callTool('vibe_v4_status', {})).ok === true, 'the group did NOT crash on the missing toolchain (status still answers)')
|
|
379
|
+
toolchainAvailable = true
|
|
380
|
+
|
|
381
|
+
// ---------- 5. a passing proof flips the review subject to fidelity ----------
|
|
382
|
+
section('5 a passing proof flips the review subject to fidelity')
|
|
383
|
+
const arc = await D.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-proof', content: 'theorem p_proof : 3 * 1 ^ 2 - 2 = (1:Nat) ^ 2 := by decide\n' }, r1)
|
|
384
|
+
assert(arc.ok === true && arc.passed === true, 'the proof is archived and passes (' + JSON.stringify({ ok: arc.ok, passed: arc.passed }) + ')')
|
|
385
|
+
assert(arc.file === 'Formal/p-proof.lean', 'the working file is Formal/<target>.lean')
|
|
386
|
+
assert(arc.proof === 'Verified/Lean/p-proof.lean', 'the archived proof path is Verified/Lean/<target>.lean')
|
|
387
|
+
assert(existsSync(join(D.projectRoot, 'Formal', 'p-proof.lean')), 'the working file exists on disk')
|
|
388
|
+
assert(existsSync(join(D.projectRoot, 'Verified', 'Lean', 'p-proof.lean')), '★ the proof is archived under Verified/Lean/ as the proof of that object')
|
|
389
|
+
const stD = await D.callTool('vibe_v4_status', {})
|
|
390
|
+
assert(stD.formal.passed.indexOf('p-proof') !== -1, 'status reports the object as Lean-passed')
|
|
391
|
+
const idxD = readIf(join(D.projectRoot, 'Formal', 'Index.md'))
|
|
392
|
+
assert(/p-proof/.test(idxD) && /passed/.test(idxD) && /Verified\/Lean\/p-proof\.lean/.test(idxD), 'Formal/Index.md indexes the object, its status and its archived proof')
|
|
393
|
+
// a RED proof must NOT mint a Verified/Lean/ copy or mark the object passed
|
|
394
|
+
const arcRed = await D.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-red', content: 'theorem p_red : 1 = 2 := by sorry\n' }, r1)
|
|
395
|
+
assert(arcRed.ok === true && arcRed.passed === false && arcRed.status === 'attempted', 'a red proof is archived as attempted, not passed')
|
|
396
|
+
assert(!existsSync(join(D.projectRoot, 'Verified', 'Lean', 'p-red.lean')), '★ a red run does NOT mint a Verified/Lean proof copy')
|
|
397
|
+
// durable state: the record survives a resume (v4 has no session projection)
|
|
398
|
+
{
|
|
399
|
+
const raw = readIf(join(D.projectRoot, 'State', 'formal.json'))
|
|
400
|
+
assert(/"p-proof"/.test(raw) && /"passed"/.test(raw), "★ the formal record is persisted in v4's own durable State/formal.json")
|
|
401
|
+
const before = D.spawns.length
|
|
402
|
+
await D.callTool('vibe_v4_abort', {})
|
|
403
|
+
const res = await D.callTool('vibe_v4_resume', {})
|
|
404
|
+
assert(res.ok === true && D.spawns.length > before, 'abort → resume re-spawns residents')
|
|
405
|
+
const stR = await D.callTool('vibe_v4_status', {})
|
|
406
|
+
assert(stR.formal.passed.indexOf('p-proof') !== -1, '★ the Lean-passed record SURVIVES resume (durable state, not an in-memory projection)')
|
|
407
|
+
for (const sp of D.spawns.slice(before)) { D.fireEnd(sp.childId, { summary: '恢复见解。', solved: false, contextPct: 10 }); await sleep(25) }
|
|
408
|
+
await D.callTool('vibe_v4_set', { activityTimeoutMs: 600000 })
|
|
409
|
+
D.resetCursor()
|
|
410
|
+
}
|
|
411
|
+
// now the voting prompt must ASK FOR FIDELITY, not for a re-derivation
|
|
412
|
+
{
|
|
413
|
+
await proposeAndVote(D, 'p-proof', {
|
|
414
|
+
card: { id: 'p-proof', title: '忠实性', statement: '3N²−2=b² 在 N=1 时成立', prob: 0.9, value: 0.6, motivation: 'm' },
|
|
415
|
+
proposal: { summary: '提议验证 p-proof。', solved: false, propose_verify: 'p-proof', contextPct: 20 },
|
|
416
|
+
verdict: 0.5, plan: () => 0.5,
|
|
417
|
+
})
|
|
418
|
+
const prompt = await D.prompts('verify', 'r-1', { target: 'p-proof', stage: 'independent' })
|
|
419
|
+
assert(/该对象已有\*\*通过的 Lean 形式化证明\*\*/.test(prompt), 'the voting prompt announces the passing proof')
|
|
420
|
+
assert(/你不需要重新检查推导/.test(prompt), '★ it tells voters NOT to re-derive')
|
|
421
|
+
assert(/忠实性审查/.test(prompt), '★ it tells voters the review subject is now fidelity')
|
|
422
|
+
assert(/定义 \/ 对象 \/ 条件 \/ 假设 \/ 结论是否与命题原文\*\*完全一致\*\*/.test(prompt), 'it enumerates exactly what fidelity means')
|
|
423
|
+
assert(/因此请把 verdict 用在\*\*忠实性\*\*上/.test(prompt), 'the shift is made explicit in the verdict instruction')
|
|
424
|
+
assert(/Verified\/Lean\/p-proof\.lean/.test(prompt), 'it points at the archived proof')
|
|
425
|
+
// the SAME object's work round must not inherit the fidelity framing (that is a voting
|
|
426
|
+
// instruction), but it does carry the standing formalization line.
|
|
427
|
+
const work = await D.prompts('normal', 'r-1')
|
|
428
|
+
assert(!/忠实性审查/.test(work), 'the fidelity instruction is confined to the voting prompt')
|
|
429
|
+
assert(/【顺手形式化(鼓励)】/.test(work), 'the work round carries the standing formalization line instead')
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ---------- 6. the reusable cross-project library ----------
|
|
433
|
+
section('6 reusable definitions and lemmas go to the GLOBAL library')
|
|
434
|
+
const libPath = join(D.vibeRoot, 'Formal', 'Lib')
|
|
435
|
+
const provedPath = join(D.vibeRoot, 'Formal', 'Proved')
|
|
436
|
+
const defRes = await D.callTool('vibe_v4_lean_archive', { kind: 'def', name: 'ZMod5', content: 'def ZMod5 := Fin 5\n' }, r1)
|
|
437
|
+
assert(defRes.ok === true && defRes.file === 'Formal/Lib/ZMod5.lean', 'a reusable definition is archived to the global lib (' + defRes.file + ')')
|
|
438
|
+
assert(existsSync(join(libPath, 'ZMod5.lean')), '★ the definition exists under VibeMath/Formal/Lib/ (cross-project, NOT inside the project)')
|
|
439
|
+
assert(!existsSync(join(D.projectRoot, 'Formal', 'Lib', 'ZMod5.lean')), 'it is NOT duplicated inside the project tree')
|
|
440
|
+
const lemRes = await D.callTool('vibe_v4_lean_archive', { kind: 'lemma', name: 'sq_odd', content: 'theorem sq_odd (n : Nat) : Odd (n*n) → Odd n := by omega\n' }, r1)
|
|
441
|
+
assert(lemRes.ok === true && lemRes.file === 'Formal/Proved/sq_odd.lean', 'a lemma is archived to Proved/')
|
|
442
|
+
assert(existsSync(join(provedPath, 'sq_odd.lean')), 'the lemma exists under VibeMath/Formal/Proved/')
|
|
443
|
+
assert(/ZMod5/.test(readIf(join(libPath, 'Index.md'))), 'Lib/Index.md lists the new definition')
|
|
444
|
+
assert(/sq_odd/.test(readIf(join(provedPath, 'Index.md'))), 'Proved/Index.md lists the new lemma')
|
|
445
|
+
// `from` copies an existing workspace .lean file instead of inline content
|
|
446
|
+
writeFileSync(join(D.projectRoot, 'Formal', 'src.lean'), 'def copied := 7\n', 'utf8')
|
|
447
|
+
const fromRes = await D.callTool('vibe_v4_lean_archive', { kind: 'def', name: 'Copied', from: 'Formal/src.lean' }, r1)
|
|
448
|
+
assert(fromRes.ok === true && readIf(join(libPath, 'Copied.lean')) === 'def copied := 7\n', "kind='def' accepts from=<existing .lean file>")
|
|
449
|
+
const fromEsc = await D.callTool('vibe_v4_lean_archive', { kind: 'def', name: 'Evil', from: '../../../../etc/passwd' }, r1)
|
|
450
|
+
assert(fromEsc.ok === false && fromEsc.code === 'V4_INVALID_ARGUMENT', "★ kind='def' refuses a `from` outside the VibeMath root")
|
|
451
|
+
const libList = await D.callTool('vibe_v4_lean_lib', {}, r1)
|
|
452
|
+
assert(libList.ok === true && libList.counts.lib >= 2 && libList.counts.proved >= 1, 'lean_lib reports the reuse library sizes (' + JSON.stringify(libList.counts) + ')')
|
|
453
|
+
assert(libList.objects.some(o => o.target === 'p-proof' && o.status === 'passed'), 'lean_lib lists per-object formal status')
|
|
454
|
+
assert(/复用优先/.test(libList.hint || ''), 'lean_lib tells agents to reuse before redefining')
|
|
455
|
+
assert(libList.paths && /Formal\/Lib/.test(libList.paths.lib), 'lean_lib reports the global library paths')
|
|
456
|
+
const noName = await D.callTool('vibe_v4_lean_archive', { kind: 'def', content: 'def x := 1\n' }, r1)
|
|
457
|
+
assert(noName.ok === false && noName.code === 'V4_INVALID_ARGUMENT', 'archiving a definition without a name is refused')
|
|
458
|
+
const noBody = await D.callTool('vibe_v4_lean_archive', { kind: 'lemma', name: 'empty' }, r1)
|
|
459
|
+
assert(noBody.ok === false && noBody.code === 'V4_INVALID_ARGUMENT', 'archiving without content or from is refused')
|
|
460
|
+
const badKind = await D.callTool('vibe_v4_lean_archive', { kind: 'nonsense' }, r1)
|
|
461
|
+
assert(badKind.ok === false && badKind.code === 'V4_INVALID_ARGUMENT', 'an unknown archive kind is refused')
|
|
462
|
+
const libNoRefresh = await D.callTool('vibe_v4_lean_lib', { refresh: false }, r1)
|
|
463
|
+
assert(libNoRefresh.ok === true && libNoRefresh.rebuilt === false && libNoRefresh.counts.lib === null, 'refresh:false reads without rebuilding')
|
|
464
|
+
|
|
465
|
+
// ---------- 7. blocked needs a reason ----------
|
|
466
|
+
section('7 a "blocker" record must be explicit and reasoned')
|
|
467
|
+
const blkNoNote = await D.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-blk' }, r1)
|
|
468
|
+
assert(blkNoNote.ok === false && blkNoNote.code === 'V4_INVALID_ARGUMENT', '★ blocked without a note is refused')
|
|
469
|
+
const blkBlank = await D.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-blk', note: ' ' }, r1)
|
|
470
|
+
assert(blkBlank.ok === false && blkBlank.code === 'V4_INVALID_ARGUMENT', 'a whitespace-only note is refused too')
|
|
471
|
+
const blk = await D.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-blk', note: '需要外层解析数论框架,本轮工作量不可接受' }, r1)
|
|
472
|
+
assert(blk.ok === true && blk.status === 'blocked', 'a reasoned blocker is recorded')
|
|
473
|
+
const stBlk = await D.callTool('vibe_v4_status', {})
|
|
474
|
+
assert(stBlk.formal.blocked.indexOf('p-blk') !== -1, 'status lists the blocked object')
|
|
475
|
+
assert(/需要外层解析数论框架/.test(readIf(join(D.projectRoot, 'Formal', 'Index.md'))), 'the blocker reason is written into the index')
|
|
476
|
+
|
|
477
|
+
// ---------- 8. the per-round `formal` reply channel ----------
|
|
478
|
+
section('8 the per-round `formal` reply judgement is recorded')
|
|
479
|
+
{
|
|
480
|
+
const w1 = await workWake(D, 'r-1')
|
|
481
|
+
D.fireEnd(w1.childId, { summary: '难度太高,本轮不做形式化。', formal: { target: 'p-reply', decision: 'blocked', note: '需要大量未形式化的实分析前置知识' }, contextPct: 20 })
|
|
482
|
+
await sleep(60)
|
|
483
|
+
const st = await D.callTool('vibe_v4_status', {})
|
|
484
|
+
assert(st.formal.blocked.indexOf('p-reply') !== -1, '★ a `formal.decision=blocked` reply is recorded as a blocker')
|
|
485
|
+
assert(/实分析前置知识/.test(readIf(join(D.projectRoot, 'Formal', 'Index.md'))), 'and its reason reaches the index')
|
|
486
|
+
}
|
|
487
|
+
{
|
|
488
|
+
const w2 = await workWake(D, 'r-2')
|
|
489
|
+
D.fireEnd(w2.childId, { summary: '我写了形式化草稿。', formal: { target: 'p-reply2', decision: 'used', file: 'Formal/p-reply2.lean' }, contextPct: 20 })
|
|
490
|
+
await sleep(60)
|
|
491
|
+
const st = await D.callTool('vibe_v4_status', {})
|
|
492
|
+
assert(st.formal.objects.some(o => o.target === 'p-reply2' && o.status === 'attempted'),
|
|
493
|
+
'a `formal.decision=used` reply records the object as ATTEMPTED with its file (no green run yet)')
|
|
494
|
+
}
|
|
495
|
+
{
|
|
496
|
+
const w3 = await workWake(D, 'r-1')
|
|
497
|
+
D.fireEnd(w3.childId, { summary: '不做。', formal: { target: 'p-reply3', decision: 'blocked' }, contextPct: 20 })
|
|
498
|
+
await sleep(60)
|
|
499
|
+
const st = await D.callTool('vibe_v4_status', {})
|
|
500
|
+
assert(!st.formal.objects.some(o => o.target === 'p-reply3'), 'a blocker with no note creates NO record')
|
|
501
|
+
assert(st.ok === true, 'the refusal did not crash the run')
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// ---------- 9. the 'require' gate ----------
|
|
505
|
+
section("9 'require' withholds a verdict until the formal record exists")
|
|
506
|
+
const E = await establish()
|
|
507
|
+
await E.callTool('vibe_v4_set', { formalVerify: 'require' })
|
|
508
|
+
{
|
|
509
|
+
await proposeAndVote(E, 'p-gate', {
|
|
510
|
+
card: { id: 'p-gate', title: '门禁', statement: '必须形式化的命题', prob: 0.8, value: 0.6, motivation: 'm' },
|
|
511
|
+
proposal: { summary: '提议验证 p-gate。', solved: false, propose_verify: 'p-gate', contextPct: 20 },
|
|
512
|
+
verdict: 1,
|
|
513
|
+
})
|
|
514
|
+
const prompt = await E.prompts('verify', 'r-1', { target: 'p-gate', stage: 'independent' })
|
|
515
|
+
assert(/【Lean 形式化验证(强制模式)】/.test(prompt), 'the voting prompt says 强制模式')
|
|
516
|
+
assert(/必须产出 Lean 形式化/.test(prompt), "'require' states the formalization is mandatory")
|
|
517
|
+
assert(/本次裁定不会生效/.test(prompt), 'the prompt warns that the verdict will not take effect without it')
|
|
518
|
+
assert(!/可以不做/.test(prompt), "'require' does NOT offer the encourage-mode opt-out")
|
|
519
|
+
}
|
|
520
|
+
const gated = await E.callTool('vibe_v4_status', {})
|
|
521
|
+
assert(gated.verifyInProgress === false && gated.pendingVerify === null, 'the verification actually RAN to a settled state (so the next assertion is falsifiable)')
|
|
522
|
+
assert(!existsSync(join(E.projectRoot, 'Verified', '命题', 'p-gate.md')), '★ a unanimous TRUE verdict did NOT promote the object to Verified/')
|
|
523
|
+
assert(gated.formal.todo.indexOf('p-gate') !== -1, '★ it is recorded as 未定论 (a formalization TODO entry)')
|
|
524
|
+
assert(gated.formal.objects.some(o => o.target === 'p-gate' && o.status === 'none'), 'the object keeps a `none` formal record (never silently marked passed)')
|
|
525
|
+
assert(!/已验证·真/.test(readIf(join(E.projectRoot, 'Propos', 'r-1', 'p-gate.md'))), 'the source card was NOT rewritten to 已验证·真 (the conclusion was withheld, not taken)')
|
|
526
|
+
const todoE = readIf(join(E.projectRoot, 'Formal', 'TODO.md'))
|
|
527
|
+
assert(existsSync(join(E.projectRoot, 'Formal', 'TODO.md')), 'Formal/TODO.md was created')
|
|
528
|
+
assert(/p-gate/.test(todoE) && /formal-required/.test(todoE), '★ the object is on the formalization TODO with the machine-readable reason')
|
|
529
|
+
assert(!/已验证·真/.test(readIf(join(E.projectRoot, 'Shared', 'debates', 'p-gate.md'))), 'the debate record does NOT claim a 真 conclusion')
|
|
530
|
+
assert(/formal-required/.test(readIf(join(E.projectRoot, 'Formal', 'Index.md'))), 'the index carries the withheld verdict too')
|
|
531
|
+
// now formalize it and re-verify: the gate must open
|
|
532
|
+
const proofNow = await E.callTool('vibe_v4_lean_archive', { kind: 'proof', target: 'p-gate', content: 'theorem p_gate : 2 + 2 = 4 := by decide\n' }, E.resAgent(E.childOf('r-1')))
|
|
533
|
+
assert(proofNow.ok === true && proofNow.passed === true, 'the object is now Lean-passed')
|
|
534
|
+
{
|
|
535
|
+
await proposeAndVote(E, 'p-gate', {
|
|
536
|
+
card: { id: 'p-gate', title: '门禁', statement: '必须形式化的命题', prob: 0.8, value: 0.6, motivation: 'm' },
|
|
537
|
+
proposal: { summary: '已形式化,重新提议验证 p-gate。', solved: false, propose_verify: 'p-gate', contextPct: 20 },
|
|
538
|
+
verdict: 1,
|
|
539
|
+
})
|
|
540
|
+
const prompt = await E.prompts('verify', 'r-1', { target: 'p-gate', stage: 'independent' })
|
|
541
|
+
assert(/该对象已有\*\*通过的 Lean 形式化证明\*\*/.test(prompt), 'the re-verify prompt now points at the passing proof')
|
|
542
|
+
}
|
|
543
|
+
const gated2 = await E.callTool('vibe_v4_status', {})
|
|
544
|
+
assert(existsSync(join(E.projectRoot, 'Verified', '命题', 'p-gate.md')), '★ with a passing Lean artifact the same verdict DOES promote it')
|
|
545
|
+
const card = readIf(join(E.projectRoot, 'Verified', '命题', 'p-gate.md'))
|
|
546
|
+
assert(/- 形式化: Lean 通过/.test(card), '★ the Verified card records how strong the result is (Lean 通过)')
|
|
547
|
+
assert(/Verified\/Lean\/p-gate\.lean/.test(card), 'the card points at the archived proof')
|
|
548
|
+
assert(gated2.formal.todo.indexOf('p-gate') === -1, 'the satisfied TODO entry was cleared')
|
|
549
|
+
// the blocker escape hatch must also open the gate
|
|
550
|
+
await E.callTool('vibe_v4_lean_archive', { kind: 'blocked', target: 'p-blocked-ok', note: '命题涉及未形式化的分析学,本轮不做' }, E.resAgent(E.childOf('r-1')))
|
|
551
|
+
await proposeAndVote(E, 'p-blocked-ok', {
|
|
552
|
+
card: { id: 'p-blocked-ok', title: '阻塞放行', statement: '记录阻塞后可定论', prob: 0.8, value: 0.6, motivation: 'm' },
|
|
553
|
+
proposal: { summary: '提议验证 p-blocked-ok。', solved: false, propose_verify: 'p-blocked-ok', contextPct: 20 },
|
|
554
|
+
verdict: 1,
|
|
555
|
+
})
|
|
556
|
+
assert(existsSync(join(E.projectRoot, 'Verified', '命题', 'p-blocked-ok.md')), '★ an explicit reasoned blocker also lets the verdict through (decide by difficulty, but decide out loud)')
|
|
557
|
+
assert(/- 形式化: 阻塞(/.test(readIf(join(E.projectRoot, 'Verified', '命题', 'p-blocked-ok.md'))), 'the card records the blocker')
|
|
558
|
+
assert((await E.callTool('vibe_v4_status', {})).formal.blocked.indexOf('p-blocked-ok') !== -1, 'status lists it as blocked')
|
|
559
|
+
// a `require`-mode FALSE verdict must be gated exactly the same way (the gate sits on the choke
|
|
560
|
+
// point, not on the 真 branch): assert the tally was recorded BEFORE asserting it was withheld.
|
|
561
|
+
await proposeAndVote(E, 'p-gate-false', {
|
|
562
|
+
card: { id: 'p-gate-false', title: '假也要门禁', statement: '一个会被一致判假的命题', prob: 0.1, value: 0.6, motivation: 'm' },
|
|
563
|
+
proposal: { summary: '提议验证 p-gate-false。', solved: false, propose_verify: 'p-gate-false', contextPct: 20 },
|
|
564
|
+
verdict: 0,
|
|
565
|
+
})
|
|
566
|
+
const gatedF = await E.callTool('vibe_v4_status', {})
|
|
567
|
+
assert(!existsSync(join(E.projectRoot, 'Verified', '命题', 'p-gate-false.md')), '★ a unanimous FALSE verdict is gated too')
|
|
568
|
+
assert(gatedF.formal.todo.indexOf('p-gate-false') !== -1, 'the false verdict is recorded as 未定论 as well')
|
|
569
|
+
assert(!/已验证·假/.test(readIf(join(E.projectRoot, 'Propos', 'r-1', 'p-gate-false.md'))), 'the source card was not rewritten to 已验证·假')
|
|
570
|
+
|
|
571
|
+
// ---------- 10. 'encourage' does NOT gate ----------
|
|
572
|
+
section("10 'encourage' has no gate (the verdict still closes)")
|
|
573
|
+
const F = await establish()
|
|
574
|
+
await F.callTool('vibe_v4_set', { formalVerify: 'encourage' })
|
|
575
|
+
await proposeAndVote(F, 'p-enc-ok', {
|
|
576
|
+
card: { id: 'p-enc-ok', title: '鼓励不门禁', statement: '鼓励模式下无形式化产物也能定论', prob: 0.8, value: 0.6, motivation: 'm' },
|
|
577
|
+
proposal: { summary: '提议验证 p-enc-ok。', solved: false, propose_verify: 'p-enc-ok', contextPct: 20 },
|
|
578
|
+
verdict: 1,
|
|
579
|
+
})
|
|
580
|
+
assert(existsSync(join(F.projectRoot, 'Verified', '命题', 'p-enc-ok.md')), "★ 'encourage' imposes NO gate: the verdict closes with no Lean artifact")
|
|
581
|
+
assert(/- 形式化: 未尝试/.test(readIf(join(F.projectRoot, 'Verified', '命题', 'p-enc-ok.md'))), 'the card still states the object was never formalized')
|
|
582
|
+
|
|
583
|
+
// ---------- 11. reporting ----------
|
|
584
|
+
section('11 the host can audit formal strength')
|
|
585
|
+
const repF = await F.callTool('vibe_v4_formal_report', {}, F.ROOT)
|
|
586
|
+
assert(/## Lean 形式化/.test(repF.formalReport), 'the formal report has a Lean section')
|
|
587
|
+
assert(/模式:encourage/.test(repF.formalReport), 'it states the mode')
|
|
588
|
+
const repOff = await A.callTool('vibe_v4_formal_report', {}, A.ROOT)
|
|
589
|
+
assert(/未启用/.test(repOff.formalReport), 'in off mode the report says the feature is not enabled')
|
|
590
|
+
const repE = await E.callTool('vibe_v4_report', {}, E.ROOT)
|
|
591
|
+
assert(repE.formal && repE.formal.passed.indexOf('p-gate') !== -1, 'the structured report exposes the Lean-passed objects')
|
|
592
|
+
assert(repE.formal.blocked.indexOf('p-blocked-ok') !== -1, 'and the blocked objects')
|
|
593
|
+
const reportE = await E.callTool('vibe_v4_formal_report', {}, E.ROOT)
|
|
594
|
+
assert(/已通过:.*p-gate/.test(reportE.formalReport), 'the human report lists Lean-passed objects')
|
|
595
|
+
assert(/已记录阻塞:.*p-blocked-ok/.test(reportE.formalReport), 'the human report lists blocked objects')
|
|
596
|
+
assert(/形式化待办:.*p-gate-false/.test(reportE.formalReport), 'the human report lists the formalization TODO')
|
|
597
|
+
|
|
598
|
+
// ===============================================================
|
|
599
|
+
console.log('')
|
|
600
|
+
console.log('passed=' + passed + ' failed=' + failed)
|
|
601
|
+
if (failed) { console.error('FAILURES:'); for (const f of failures) console.error(' - ' + f); process.exit(1) }
|
|
602
|
+
console.log('ALL GREEN')
|
|
603
|
+
process.exit(0)
|