dsh-vibe-math 2.6.0 → 2.7.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.
Files changed (57) hide show
  1. package/README.en.md +156 -389
  2. package/README.md +156 -390
  3. package/cordis.patch.yml +56 -14
  4. package/docs/AUDIT-CHECKLIST.md +2 -2
  5. package/docs/final-paper.md +1 -0
  6. package/docs/formal-verification.md +184 -29
  7. package/docs/math-computation.md +121 -0
  8. package/docs/release-notes/RELEASE-NOTES-2.7.0.en.md +151 -0
  9. package/docs/release-notes/RELEASE-NOTES-2.7.0.md +115 -0
  10. package/docs/test-timing.md +24 -12
  11. package/installer.js +7 -4
  12. package/package.json +18 -2
  13. package/prompt-corpus-persona/persona-corpus.json +12 -12
  14. package/prompt-corpus-persona/persona-corpus.md +116 -32
  15. package/prompt-corpus-v2/formal-verify-v2.json +116 -92
  16. package/prompt-corpus-v2/formal-verify-v2.md +1430 -55
  17. package/prompt-corpus-v3/formal-verify-v3.json +101 -53
  18. package/prompt-corpus-v3/formal-verify-v3.md +1001 -22
  19. package/prompt-corpus-v4/formal-verify-v4.json +14 -14
  20. package/prompt-corpus-v4/formal-verify-v4.md +247 -14
  21. package/prompt-corpus-v5/prompt-corpus-v5.json +62 -62
  22. package/prompt-corpus-v5/prompt-corpus-v5.md +570 -3
  23. package/tests/audit-math-computation-contract.mjs +191 -0
  24. package/tests/audit-math-computation-parity.mjs +169 -0
  25. package/tests/audit-math-computation-sensitivity.mjs +231 -0
  26. package/tests/audit-persona-sensitivity.mjs +4 -4
  27. package/tests/audit-persona-surface.test.mjs +38 -10
  28. package/tests/audit-v5-integrity.mjs +14 -0
  29. package/tests/e2e-v5-round2.test.mjs +452 -2
  30. package/tests/formal-verify-v2.test.mjs +292 -6
  31. package/tests/formal-verify-v3.test.mjs +271 -4
  32. package/tests/formal-verify-v4.test.mjs +295 -6
  33. package/tests/formal-verify-v5.test.mjs +9 -1
  34. package/tests/helpers/math-computation-fake-seam.mjs +135 -0
  35. package/tests/math-computation-shared.test.mjs +504 -0
  36. package/tests/prompt-v5-integrity.test.mjs +5 -5
  37. package/vibe-math-v2/agent.cordis.yml +20 -8
  38. package/vibe-math-v2/math-computation.js +936 -0
  39. package/vibe-math-v2/math-engines.js +156 -0
  40. package/vibe-math-v2/vibe-math-v2.js +837 -40
  41. package/vibe-math-v2//345/256/236/347/216/260/346/226/271/346/241/210.md +6 -0
  42. package/vibe-math-v3/agent.cordis.yml +20 -8
  43. package/vibe-math-v3/math-computation.js +936 -0
  44. package/vibe-math-v3/math-engines.js +156 -0
  45. package/vibe-math-v3/vibe-math-v3.js +828 -47
  46. package/vibe-math-v3//345/256/236/347/216/260/346/226/271/346/241/210.md +6 -0
  47. package/vibe-math-v4/agent.cordis.yml +34 -6
  48. package/vibe-math-v4/math-computation.js +936 -0
  49. package/vibe-math-v4/math-engines.js +156 -0
  50. package/vibe-math-v4/vibe-math-v4.js +801 -31
  51. package/vibe-math-v4//345/256/236/347/216/260/346/226/271/346/241/210.md +6 -0
  52. package/vibe-math-v5/agent.cordis.yml +38 -6
  53. package/vibe-math-v5/math-computation.js +936 -0
  54. package/vibe-math-v5/math-engines.js +156 -0
  55. package/vibe-math-v5/vibe-math-v5.js +1120 -37
  56. package/vibe-math-v5//345/256/236/347/216/260/346/226/271/346/241/210.md +83 -3
  57. package/vibe-math-v5//346/236/266/346/236/204/345/233/276.md +251 -0
@@ -0,0 +1,504 @@
1
+ // ============================================================================================
2
+ // math_computation — shared module contract suite (integration owner).
3
+ //
4
+ // Drives the canonical `math-computation.js` through the fake host seam (tests/helpers/
5
+ // math-computation-fake-seam.mjs): no real engine, no real subprocess, runs on any machine.
6
+ // Covers the freeze (INTERFACE-FREEZE.md): closed schema, 11 failure codes, argv echo, receipt
7
+ // determinism, cli default-on + both disable paths, licence probe, install plan->confirm, timeout,
8
+ // truncation, bad-argv-not-collapsed, and the availability/rule prompt text.
9
+ //
10
+ // Falsifiability: every assertion below fails for a specific mutation; the companion probe
11
+ // `tests/audit-math-computation-sensitivity.mjs` mutates a copy of the module and requires THIS
12
+ // suite to go red (cli default off / policy ignored / argv echo dropped / bad-argv collapsed /
13
+ // timeout timer removed / param renamed).
14
+ //
15
+ // Usage: node tests/math-computation-shared.test.mjs
16
+ // ============================================================================================
17
+ import { makeFakeHost } from './helpers/math-computation-fake-seam.mjs'
18
+ import { pathToFileURL } from 'node:url'
19
+
20
+ // The sensitivity probe (tests/audit-math-computation-sensitivity.mjs) points this at a MUTATED copy
21
+ // of the module pair; the default is the shipped copy in vibe-math-v2/.
22
+ const MODULE = process.env.MATH_COMPUTATION_MODULE
23
+ ? pathToFileURL(process.env.MATH_COMPUTATION_MODULE).href
24
+ : new URL('../vibe-math-v2/math-computation.js', import.meta.url).href
25
+ const M = await import(MODULE)
26
+
27
+ let passed = 0, failed = 0
28
+ const failures = []
29
+ function ok(cond, label, detail) {
30
+ if (cond) { passed++; return true }
31
+ failed++; failures.push(label + (detail ? ' — ' + detail : ''))
32
+ console.error(' FAIL ' + label + (detail ? ' — ' + detail : ''))
33
+ return false
34
+ }
35
+ const eq = (a, b, label) => ok(JSON.stringify(a) === JSON.stringify(b), label, 'got ' + JSON.stringify(a) + ' want ' + JSON.stringify(b))
36
+
37
+ async function withHost(opts, fn) {
38
+ const state = makeFakeHost(opts)
39
+ const reg = M.registerMathComputation(state.host)
40
+ await fn(state, reg)
41
+ }
42
+
43
+ console.log('-- math_computation shared contract --')
44
+
45
+ // ── 1. freeze: names, codes, defaults, prompt text ─────────────────────────────────────────────
46
+ {
47
+ ok(M.MATH_TOOL_NAME === 'math_computation', 'tool name is math_computation')
48
+ eq(M.MATH_PARAM_NAMES, ['mathComputation', 'mathMode', 'mathEngines', 'mathTimeoutMs', 'mathPackages', 'mathInstallScope'], 'six frozen param names in order')
49
+ eq(M.MATH_FAILURE_CODES.length, 11, 'eleven failure codes')
50
+ ok(M.MATH_FAILURE_CODES.indexOf('MATH_ENGINE_BAD_ARGV') !== -1 && M.MATH_FAILURE_CODES.indexOf('MATH_ENGINE_LICENSE_REQUIRED') !== -1, 'canonical codes present')
51
+ ok(M.MATH_PARAM_DEFAULTS.mathMode === 'typed+shell' && M.MATH_PARAM_DEFAULTS.mathComputation === 'auto', 'defaults: auto + typed+shell')
52
+ ok(M.MATH_PARAM_DEFAULTS.mathEngines.indexOf('cli') !== -1, 'cli is in the default engine set (default-on)')
53
+ ok(M.MATH_TOOL_DESCRIPTION.indexOf('computation/<id>/') === -1 && M.MATH_TOOL_DESCRIPTION.indexOf('Computation/<id>/') !== -1, 'description points at the receipt dir')
54
+ ok(M.MATH_TOOL_DESCRIPTION.indexOf('默认开启') !== -1, 'description says cli is on by default')
55
+ ok(M.MATH_TOOL_DESCRIPTION.indexOf('实际 argv') !== -1, 'description mentions the argv echo')
56
+ ok(M.MATH_TOOL_DESCRIPTION.indexOf('mathEngineOverride') !== -1, 'description mentions mathEngineOverride')
57
+ ok(M.MATH_RULE_LINES.some((l) => l.indexOf('①') !== -1 && l.indexOf('③') !== -1), 'rule lines carry the three selection criteria')
58
+ ok(M.MATH_SHELL_RULE_LINE.indexOf(M.MATH_SHELL_FALLBACK_MARK) !== -1, 'shell rule line carries the marking')
59
+ ok(M.MATH_RULE_LINES.every((l) => l.indexOf(M.MATH_SHELL_FALLBACK_MARK) === -1), 'mode-independent rule lines contain NO shell sentence')
60
+ ok(M.MATH_SHELL_FALLBACK_MARK_EN === 'not tool-archived', 'EN marking constant')
61
+ }
62
+
63
+ // ── 2. normalizeMathParams: explicit coercion ──────────────────────────────────────────────────
64
+ {
65
+ eq(M.normalizeMathParams({ mathComputation: 'off' }).mathComputation, 'off', 'enum accepted')
66
+ eq(M.normalizeMathParams({ mathComputation: 'nope' }).mathComputation, 'auto', 'bad enum falls back to default')
67
+ eq(M.normalizeMathParams({ mathMode: 'typed' }).mathMode, 'typed', 'mathMode typed accepted')
68
+ eq(M.normalizeMathParams({ mathMode: 'typed+shell' }).mathMode, 'typed+shell', 'mathMode typed+shell accepted')
69
+ eq(M.normalizeMathParams({ mathEngines: ['cli', 'python', 'cli', 'bogus'] }).mathEngines, ['cli', 'python'], 'engine list filtered + deduped, order kept')
70
+ eq(M.normalizeMathParams({ mathEngines: [] }).mathEngines, M.MATH_PARAM_DEFAULTS.mathEngines, 'empty engine list falls back to defaults')
71
+ eq(M.normalizeMathParams({ mathTimeoutMs: '0' }).mathTimeoutMs, 60000, 'non-positive timeout falls back (no silent instant timeout)')
72
+ eq(M.normalizeMathParams({ mathTimeoutMs: 10 }).mathTimeoutMs, 1000, 'timeout clamped to >= 1000')
73
+ eq(M.normalizeMathParams({ mathPackages: ['a', 'a', ''] }).mathPackages, ['a'], 'packages deduped and blanks dropped')
74
+ eq(M.normalizeMathParams({ mathInstallScope: 'system' }).mathInstallScope, 'system', 'system scope accepted when explicit')
75
+ eq(M.normalizeMathParams({ mathInstallScope: 'yes' }).mathInstallScope, 'user', 'bad scope falls back to user')
76
+ eq(M.normalizeMathParams({ nope: 1 }), {}, 'unknown keys are not echoed into params')
77
+ }
78
+
79
+ // ── 3. validateMathArgs: closed schema ─────────────────────────────────────────────────────────
80
+ {
81
+ ok(M.validateMathArgs({ op: 'probe', extra: 1 }).ok === false, 'unknown argument rejected')
82
+ ok(M.validateMathArgs({ op: 'nope' }).ok === false, 'unknown op rejected')
83
+ ok(M.validateMathArgs({ op: 'run', mode: 'code' }).ok === false, 'mode=code without code rejected')
84
+ ok(M.validateMathArgs({ op: 'run', mode: 'file', file: '../../etc/passwd' }).code === 'MATH_REFUSED', 'path escape refused at validation')
85
+ ok(M.validateMathArgs({ op: 'run', mode: 'file', file: '/abs/x.py' }).code === 'MATH_REFUSED', 'absolute path refused at validation')
86
+ ok(M.validateMathArgs({ op: 'run', mode: 'expr', expr: '1', engine: 'cli', cli: { command: 'x' } }).code === 'MATH_REFUSED', 'cli + expr refused')
87
+ ok(M.validateMathArgs({ op: 'run', engine: 'cli', mode: 'code', code: 'x' }).code === 'MATH_REFUSED', 'cli without cli{} refused')
88
+ ok(M.validateMathArgs({ op: 'run', engine: 'cli', cli: { command: '/x/y' }, mode: 'code', code: 'z' }, { mathMode: 'typed' }).code === 'MATH_REFUSED', 'cli refused while mathMode=typed')
89
+ ok(M.validateMathArgs({ op: 'run', engine: 'cli', cli: { command: '/x/y' }, mode: 'code', code: 'z' }, { mathEngines: ['python'] }).code === 'MATH_REFUSED', 'cli refused when absent from mathEngines')
90
+ ok(M.validateMathArgs({ op: 'install', packages: [] }).ok === false, 'install without packages rejected')
91
+ ok(M.validateMathArgs({ op: 'run', mode: 'code', code: 'x', timeoutMs: 10 }).ok === false, 'timeoutMs < 1000 rejected')
92
+ ok(M.validateMathArgs({ op: 'run', mode: 'code', code: 'x' }).ok === true, 'minimal run accepted')
93
+ ok(M.validateMathArgs({ op: 'receipt', file: 'Computation/abc/receipt.json' }).ok === true, 'receipt accepted')
94
+ }
95
+
96
+ // ── 4. registration shape ──────────────────────────────────────────────────────────────────────
97
+ {
98
+ await withHost({}, async (state) => {
99
+ const r = state.registrations[0]
100
+ ok(!!r, 'register() called exactly once')
101
+ ok(r.name === 'math_computation', 'registered under the frozen tool name')
102
+ ok(r.description === M.MATH_TOOL_DESCRIPTION, 'registered description is the frozen text')
103
+ ok(r.parameters && r.parameters.additionalProperties === false, 'registered schema is closed')
104
+ eq(r.parameters.required, ['op'], 'schema requires op')
105
+ ok(typeof r.handler === 'function', 'registered handler is callable')
106
+ })
107
+ }
108
+
109
+ // ── 5. probe ───────────────────────────────────────────────────────────────────────────────────
110
+ {
111
+ await withHost({}, async (state) => {
112
+ const r = await state.call({ op: 'probe' })
113
+ ok(r.ok === true && r.available === true, 'probe finds an installed engine')
114
+ ok(r.engines.length >= 1 && r.engines[0].name === 'python', 'first detected engine is python (order honoured)')
115
+ })
116
+ await withHost({ installed: [] }, async (state) => {
117
+ const r = await state.call({ op: 'probe' })
118
+ ok(r.ok === false && r.code === 'MATH_ENGINE_NOT_FOUND', 'no engine -> ENGINE_NOT_FOUND')
119
+ ok(r.next && r.next.kind === 'user-install' && r.next.command, 'ENGINE_NOT_FOUND carries the per-OS user-install guide')
120
+ })
121
+ await withHost({ packages: { numpy: 'present', sympy: 'missing' } }, async (state) => {
122
+ const r = await state.call({ op: 'probe', packages: ['numpy', 'sympy'] })
123
+ ok(r.ok === true && r.packages.found.numpy === 'present' && r.packages.found.sympy === null, 'package probe reports present/missing')
124
+ })
125
+ }
126
+
127
+ // ── 6. run: code mode, receipt, argv echo, determinism ─────────────────────────────────────────
128
+ {
129
+ await withHost({}, async (state) => {
130
+ const r1 = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)' })
131
+ ok(r1.ok === true && r1.exit === 0, 'run code succeeds')
132
+ ok(!!r1.receipt && r1.receipt.dir.indexOf('Computation/vibe-math-v2-') === 0, 'receipt dir is Computation/<runId>')
133
+ ok(!!state.file(r1.receipt.dir + '/script.py'), 'script original is on disk')
134
+ ok(state.file(r1.receipt.dir + '/stdout.txt') !== undefined && state.file(r1.receipt.dir + '/stderr.txt') !== undefined, 'full stdout/stderr are on disk')
135
+ const rj = JSON.parse(state.file(r1.receipt.json))
136
+ ok(!!rj.receipt === false && rj.runId === r1.receipt.dir.split('/')[1], 'receipt.json runId matches the directory')
137
+ eq(rj.argv, r1.argv, 'receipt argv === returned argv')
138
+ ok(r1.argv[r1.argv.length - 1].indexOf('script.py') !== -1, 'argv ends with the script path (copy-to-rerun)')
139
+ eq(rj.cwd, 'X:/fake/project', 'cwd is the project root')
140
+ ok(rj.determinism && rj.determinism.noWallClockInId === true, 'receipt declares no wall clock in the id')
141
+ // P2a item 1: the script is discoverable from BOTH the return value and the receipt.
142
+ ok(r1.scriptPath === rj.scriptPath && r1.scriptHash === rj.scriptHash, 'scriptPath + scriptHash are in the return value AND the receipt')
143
+ ok(r1.scriptHash === rj.script.sha256 && r1.scriptPath.indexOf('/script.py') !== -1, 'scriptHash matches the receipt script object')
144
+ const r2 = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)' })
145
+ ok(r2.baseRunDir === r1.baseRunDir, 'same input -> same archive id (baseRunDir)')
146
+ ok(r2.attempt === 2 && r2.attemptDir !== r1.attemptDir, 'a repeat is appended as attempt 2 (never overwriting attempt 1)')
147
+ ok(state.file(r2.attemptDir + '/receipt.json') !== undefined && state.file(r1.attemptDir + '/stdout.txt') === 'ran-ok\n', 'attempt 1 files are left untouched by attempt 2')
148
+ const r3 = await state.call({ op: 'run', engine: 'octave', mode: 'code', code: 'print(1)' })
149
+ ok(r3.baseRunDir !== r1.baseRunDir, 'different engine -> different archive id')
150
+ })
151
+ }
152
+
153
+ // ── 7. run: file + expr + captureFiles ─────────────────────────────────────────────────────────
154
+ {
155
+ await withHost({ files: { 'Problems/calc.py': 'print(2)' } }, async (state) => {
156
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/calc.py', captureFiles: ['Problems/calc.py'] })
157
+ ok(r.ok === true, 'run file succeeds')
158
+ eq(JSON.parse(state.file(r.receipt.json)).captured, ['Problems/calc.py'], 'captureFiles recorded and copied')
159
+ ok(!!state.file(r.receipt.dir + '/captured/Problems/calc.py'), 'captured file copied into the receipt')
160
+ })
161
+ await withHost({}, async (state) => {
162
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'file', file: '../../../etc/passwd' })
163
+ ok(r.ok === false && r.code === 'MATH_REFUSED', 'file escape refused at run time')
164
+ const r2 = await state.call({ op: 'run', engine: 'python', mode: 'file', file: 'nope.py' })
165
+ ok(r2.ok === false && r2.code === 'MATH_REFUSED', 'missing file refused')
166
+ const r3 = await state.call({ op: 'run', engine: 'python', mode: 'expr', expr: '1+1' })
167
+ ok(r3.ok === true, 'expr mode runs through the eval template')
168
+ const argv = state.spawns[state.spawns.length - 1].argv
169
+ ok(argv[argv.length - 1] === '1+1' && argv.indexOf('-c') !== -1, 'expr occupies exactly one argv element after -c')
170
+ })
171
+ }
172
+
173
+ // ── 8. cli: default-on + both disable paths + receipt ──────────────────────────────────────────
174
+ {
175
+ await withHost({}, async (state) => {
176
+ const r = await state.call({ op: 'run', engine: 'cli', mode: 'code', code: 'echo hi', cli: { command: '/fake/bin/mytool', argv: ['--flag', 'x'] } })
177
+ ok(r.ok === true, 'cli runs with DEFAULT params (default-on)')
178
+ eq(r.argv, ['/fake/bin/mytool', '--flag', 'x'], 'cli argv is command + user argv verbatim')
179
+ ok(r.engine === 'cli:/fake/bin/mytool' && r.engineInfo.name === 'cli:/fake/bin/mytool', 'cli is labelled cli:<command> in the shell and engineInfo')
180
+ const rj = JSON.parse(state.file(r.receipt.json))
181
+ ok(rj.engine.name === 'cli:/fake/bin/mytool' && rj.engine.source === 'cli' && rj.cli && rj.cli.argv.length === 2, 'cli receipt records cli:<command>, source=cli and argv')
182
+ })
183
+ await withHost({ params: { mathMode: 'typed' } }, async (state) => {
184
+ const r = await state.call({ op: 'run', engine: 'cli', mode: 'code', code: 'x', cli: { command: '/fake/bin/mytool' } })
185
+ ok(r.ok === false && r.code === 'MATH_REFUSED', 'cli disabled while mathMode=typed')
186
+ ok(!!r.next && r.next.kind === 'reason' && r.next.reason === 'policy', 'policy refusal carries next:{kind:reason, reason:policy}')
187
+ eq(state.spawns.length, 0, 'disabled cli never spawns anything')
188
+ })
189
+ await withHost({ params: { mathEngines: ['python'] } }, async (state) => {
190
+ const r = await state.call({ op: 'run', engine: 'cli', mode: 'code', code: 'x', cli: { command: '/fake/bin/mytool' } })
191
+ ok(r.ok === false && r.code === 'MATH_REFUSED', 'cli disabled when removed from mathEngines')
192
+ })
193
+ }
194
+
195
+ // ── 9. missing packages / licence / commercial install ─────────────────────────────────────────
196
+ {
197
+ await withHost({ packages: { sympy: 'missing' } }, async (state) => {
198
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'import sympy', packages: ['sympy'] })
199
+ ok(r.ok === false && r.code === 'MATH_MISSING_PACKAGES', 'missing package -> MISSING_PACKAGES')
200
+ eq(r.missing, ['sympy'], 'missing list reported')
201
+ ok(r.next && r.next.kind === 'agent-install' && r.next.dryRun === true, 'missing package leads to an install PLAN (not an install)')
202
+ ok(state.spawns.every((s) => s.argv.join(' ').indexOf('script.py') === -1), 'the user script was NOT executed when a package is missing')
203
+ })
204
+ await withHost({ licence: false }, async (state) => {
205
+ const r = await state.call({ op: 'run', engine: 'matlab', mode: 'expr', expr: 'disp(1)' })
206
+ ok(r.ok === false && r.code === 'MATH_ENGINE_LICENSE_REQUIRED', 'unlicensed commercial engine -> LICENSE_REQUIRED (not NOT_FOUND)')
207
+ ok(r.next && r.next.kind === 'vendor' && /mathworks/.test(r.next.url || ''), 'vendor link attached, no install plan')
208
+ const i = await state.call({ op: 'install', engine: 'matlab', packages: ['Statistics_Toolbox'] })
209
+ ok(i.ok === false && i.code === 'MATH_REFUSED', 'commercial install always refused')
210
+ })
211
+ }
212
+
213
+ // ── 10. timeout / non-zero / truncation / bad-argv ─────────────────────────────────────────────
214
+ {
215
+ await withHost({ hang: true }, async (state) => {
216
+ const r = await state.call({ op: 'run', engine: 'julia', mode: 'code', code: 'sleep(1)', timeoutMs: 1200 })
217
+ ok(r.ok === false && r.code === 'MATH_TIMEOUT', 'hang -> MATH_TIMEOUT')
218
+ ok(r.timedOut === true && !!r.receipt, 'timeout is flagged and still leaves a receipt')
219
+ const rj = JSON.parse(state.file(r.receipt.json))
220
+ ok(rj.timedOut === true && rj.exit === null, 'receipt records timedOut + null exit')
221
+ })
222
+ await withHost({ exit: 3 }, async (state) => {
223
+ const r = await state.call({ op: 'run', engine: 'julia', mode: 'code', code: 'boom' })
224
+ ok(r.ok === false && r.code === 'MATH_NONZERO_EXIT' && r.exit === 3, 'non-zero exit -> NONZERO_EXIT with the code')
225
+ })
226
+ await withHost({ stdoutBytes: 200000 }, async (state) => {
227
+ const r = await state.call({ op: 'run', engine: 'octave', mode: 'code', code: 'x=1' })
228
+ ok(r.ok === true && r.truncated.stdout === true, 'oversized stdout is a WARNING, not a failure')
229
+ ok(r.warnings.length === 1 && r.warnings[0].code === 'OUTPUT_TRUNCATED', 'OUTPUT_TRUNCATED warning present')
230
+ ok(r.stdout.length === M.MATH_CAPS.stdout, 'returned stdout is capped at 64KB')
231
+ ok(state.file(r.receipt.dir + '/stdout.txt').length === 200000, 'full output is on disk')
232
+ })
233
+ await withHost({ argError: "Error, unknown option '-q'" }, async (state) => {
234
+ const r = await state.call({ op: 'run', engine: 'maple', mode: 'code', code: 'x' })
235
+ ok(r.ok === false && r.code === 'MATH_ENGINE_BAD_ARGV', 'usage/option error -> MATH_ENGINE_BAD_ARGV (not collapsed into NONZERO_EXIT)')
236
+ ok(r.next && r.next.kind === 'engine-override' && r.next.hint === 'mathEngineOverride', 'next points at mathEngineOverride')
237
+ eq(r.next.argv, r.argv, 'the failing argv is echoed in next.argv')
238
+ ok(r.message.indexOf('mathEngineOverride') !== -1, 'message mentions the override escape hatch')
239
+ })
240
+ await withHost({ resolveThrows: true }, async (state) => {
241
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'x' })
242
+ ok(r.ok === false && r.code === 'MATH_ENGINE_NOT_FOUND', 'unresolvable executable -> ENGINE_NOT_FOUND (no crash)')
243
+ })
244
+ }
245
+
246
+ // ── 11. receipt op (idempotent re-render) ──────────────────────────────────────────────────────
247
+ {
248
+ await withHost({}, async (state) => {
249
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)' })
250
+ const before = state.file(r.receipt.md)
251
+ const again = await state.call({ op: 'receipt', file: r.receipt.dir })
252
+ ok(again.ok === true, 'op=receipt re-renders an existing receipt')
253
+ ok(state.file(r.receipt.md) === before, 're-render is idempotent (same bytes)')
254
+ const miss = await state.call({ op: 'receipt', file: 'Computation/nope' })
255
+ // Round-2 lens-1: a DELETED/missing archive is an explicit refusal, not a malformed call.
256
+ ok(miss.ok === false && miss.code === 'MATH_REFUSED', 'op=receipt on a missing archive -> MATH_REFUSED')
257
+ ok(miss.next && miss.next.kind === 'reason' && miss.next.reason === 'archive-missing', 'the refusal carries next.reason=archive-missing')
258
+ // A corrupt receipt.json is still a malformed artifact (different code, different reason).
259
+ await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)' })
260
+ const dirs = [...state.files.keys()].filter((k) => /^Computation\/[^/]+\/receipt\.json$/.test(k))
261
+ if (dirs.length) {
262
+ state.files.set(dirs[0], '{not json')
263
+ const corrupt = await state.call({ op: 'receipt', file: dirs[0].replace('/receipt.json', '') })
264
+ ok(corrupt.ok === false && corrupt.code === 'MATH_INVALID_ARGUMENT' && corrupt.next.reason === 'receipt-unparsable', 'a corrupt receipt.json stays MATH_INVALID_ARGUMENT (receipt-unparsable)')
265
+ }
266
+ })
267
+ }
268
+
269
+ // ── 12. install: plan -> confirm, scope, audit ─────────────────────────────────────────────────
270
+ {
271
+ await withHost({}, async (state) => {
272
+ const plan = await state.call({ op: 'install', engine: 'python', packages: ['sympy'] })
273
+ ok(plan.ok === true && !!plan.planToken, 'install returns a plan + planToken')
274
+ ok(plan.plan.scope === 'user', 'plan defaults to user scope')
275
+ ok(plan.plan.commands[0].argv.indexOf('--user') !== -1, 'user scope uses the --user template')
276
+ eq(state.spawns.length, 0, 'planning spawns nothing (never auto-install)')
277
+ const wrong = await state.call({ op: 'install', engine: 'python', packages: ['sympy'], confirm: 'deadbeef' })
278
+ ok(wrong.ok === false && wrong.code === 'MATH_REFUSED', 'confirm with a mismatched token is refused')
279
+ const done = await state.call({ op: 'install', engine: 'python', packages: ['sympy'], confirm: plan.planToken })
280
+ ok(done.ok === true && done.executed === true, 'confirm with the plan token executes')
281
+ const audit = JSON.parse(state.file(done.audit))
282
+ ok(audit.scope === 'user' && audit.installed[0] === 'sympy' && audit.rollback.commands.length === 1, 'audit records scope, installed list and an uninstall command')
283
+ ok(audit.network === 'not-enforced-by-plugin', 'audit is honest about network enforcement')
284
+ const plan2 = await state.call({ op: 'install', engine: 'python', packages: ['numpy'] })
285
+ ok(plan2.plan.scope === 'user', 'scope is NOT remembered: a later call is user again')
286
+ const sys = await state.call({ op: 'install', engine: 'python', packages: ['numpy'], scope: 'system' })
287
+ ok(sys.plan.scope === 'system', 'system scope only when explicitly requested per call')
288
+ const rSys = await state.call({ op: 'install', engine: 'r', packages: ['MASS'], scope: 'system' })
289
+ ok(rSys.ok === false && rSys.code === 'MATH_REFUSED', 'system scope refused when the manager has no system template')
290
+ })
291
+ }
292
+
293
+ // ── 13. tier off + availability line ───────────────────────────────────────────────────────────
294
+ {
295
+ await withHost({ params: { mathComputation: 'off' } }, async (state) => {
296
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'x' })
297
+ ok(r.ok === false && r.code === 'MATH_NOT_AVAILABLE', 'mathComputation=off is a true no-op')
298
+ ok(r.next && r.next.kind === 'enable', 'off tier tells the caller how to enable it')
299
+ eq(state.spawns.length, 0, 'off tier spawns nothing')
300
+ })
301
+ const probe = { ok: true, engines: [{ name: 'python', version: '1.2.3' }], available: true }
302
+ const zh = M.mathAvailabilityLine(probe, 'zh', 'typed+shell')
303
+ const typed = M.mathAvailabilityLine(probe, 'zh', 'typed')
304
+ const en = M.mathAvailabilityLine(probe, 'en', 'typed+shell')
305
+ ok(zh.indexOf('先 probe 再 run') !== -1 && zh.indexOf(M.MATH_SHELL_FALLBACK_MARK) !== -1, 'zh availability line: probe-first + shell marking')
306
+ ok(typed.indexOf(M.MATH_SHELL_FALLBACK_MARK) === -1, 'typed tier drops the shell-fallback sentence')
307
+ ok(en.indexOf(M.MATH_SHELL_FALLBACK_MARK_EN) !== -1 && en.indexOf('not tool-archived') !== -1, 'en availability line carries the marking')
308
+ }
309
+
310
+ // ── 14. no-subprocess matrix (adjudication c) ───────────────────────────────────────────────────
311
+ {
312
+ await withHost({ hasSubprocess: false }, async (state) => {
313
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'x' })
314
+ ok(r.ok === false && r.code === 'MATH_NO_SUBPROCESS', 'host that declares no subprocess -> MATH_NO_SUBPROCESS (not ENGINE_NOT_FOUND)')
315
+ ok(r.next && r.next.kind === 'note', 'no-subprocess carries the note next')
316
+ const p = await state.call({ op: 'probe' })
317
+ ok(p.ok === false && p.code === 'MATH_NO_SUBPROCESS', 'op=probe also reports NO_SUBPROCESS on such a host')
318
+ })
319
+ await withHost({ resolveThrows: true }, async (state) => {
320
+ const r = await state.call({ op: 'run', engine: 'python', mode: 'code', code: 'x' })
321
+ ok(r.ok === false && r.code === 'MATH_ENGINE_NOT_FOUND', 'without the flag, an unresolvable host still reports ENGINE_NOT_FOUND + install guide')
322
+ })
323
+ }
324
+
325
+ // ── 15. P2a: archive -> edit -> re-run integrity ───────────────────────────────────────────────
326
+ {
327
+ // 15a. mode:'file' is KEYED BY PATH, so an edit + re-run lands in the same archive id and the
328
+ // hash reconciliation reports the change (never a silent pass).
329
+ const st = makeFakeHost({ files: { 'Problems/calc.py': 'print(2)\n' } })
330
+ M.registerMathComputation(st.host)
331
+ const first = await st.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/calc.py' })
332
+ ok(first.ok === true && first.scriptChanged === false && first.scriptChangedDuringRun === false, 'first file run: no change flags')
333
+ st.files.set('Problems/calc.py', 'print(3)\n')
334
+ const second = await st.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/calc.py' })
335
+ ok(second.baseRunDir === first.baseRunDir, 'file mode is path-keyed: the edited file reuses the archive id')
336
+ ok(second.scriptChanged === true, 'edited file -> scriptChanged:true (no silent pass)')
337
+ ok(!!second.previousReceipt && second.previousReceipt.scriptHash === first.scriptHash, 'the RETURN SHELL also exposes previousReceipt (the stale hash)')
338
+ ok(second.warnings.some((w) => w.code === M.MATH_SCRIPT_CHANGED_WARNING), 'scriptChanged is warned visibly')
339
+ ok(second.attempt === 2 && second.scriptHash !== first.scriptHash, 'the new attempt carries the new scriptHash')
340
+ const secondReceipt = JSON.parse(st.file(second.receipt.json))
341
+ ok(secondReceipt.scriptChanged === true && !!secondReceipt.previousReceipt && secondReceipt.previousReceipt.scriptHash === first.scriptHash, 'receipt records scriptChanged + the previous receipt hash')
342
+
343
+ // 15b. a mid-run edit (one member edits while another runs) is flagged after the run.
344
+ const st2 = makeFakeHost({ files: { 'Problems/race.py': 'print(1)\n' }, mutateOnRun: { rel: 'Problems/race.py', text: 'print(9)\n' } })
345
+ M.registerMathComputation(st2.host)
346
+ const raced = await st2.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/race.py' })
347
+ ok(raced.ok === true && raced.scriptChangedDuringRun === true, 'mid-run edit -> scriptChangedDuringRun:true')
348
+ ok(raced.warnings.some((w) => w.code === M.MATH_SCRIPT_CHANGED_DURING_RUN_WARNING), 'mid-run edit is warned visibly')
349
+ ok(JSON.parse(st2.file(raced.receipt.json)).scriptChangedDuringRun === true, 'receipt records scriptChangedDuringRun')
350
+
351
+ // 15c. op:'receipt' reconciles the archived script hash, and never rewrites existing files.
352
+ const st3 = makeFakeHost({})
353
+ M.registerMathComputation(st3.host)
354
+ const run = await st3.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' })
355
+ const jsonBefore = st3.file(run.receipt.json)
356
+ const mdBefore = st3.file(run.receipt.md)
357
+ const clean = await st3.call({ op: 'receipt', file: run.baseRunDir })
358
+ ok(clean.ok === true && clean.scriptChanged === false, 'op=receipt on an untouched archive: no change')
359
+ ok(st3.file(run.receipt.json) === jsonBefore && st3.file(run.receipt.md) === mdBefore, 'op=receipt never rewrites existing receipt files')
360
+ st3.files.set(run.scriptPath, 'print(42)\n')
361
+ const dirty = await st3.call({ op: 'receipt', file: run.baseRunDir })
362
+ ok(dirty.ok === true && dirty.scriptChanged === true && dirty.currentScriptHash !== dirty.scriptHash, 'op=receipt reports scriptChanged for an edited archive script')
363
+ ok(dirty.warnings.some((w) => w.code === M.MATH_SCRIPT_CHANGED_WARNING), 'op=receipt warns visibly')
364
+ ok(st3.file(run.receipt.json) === jsonBefore, 'reconciliation still does not rewrite receipt.json')
365
+
366
+ // 15d. retention: over the documented cap the tool WARNS and never deletes.
367
+ const st4 = makeFakeHost({})
368
+ M.registerMathComputation(st4.host)
369
+ const cap = M.MATH_ARCHIVE_MAX_ATTEMPTS_PER_RUN
370
+ let last = null
371
+ for (let i = 0; i < cap + 1; i++) last = await st4.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' })
372
+ ok(last.attempt === cap + 1, 'attempts keep being appended past the cap (no deletion, no refusal)')
373
+ ok(last.warnings.some((w) => w.code === M.MATH_ARCHIVE_WARNING), 'over the retention cap the tool warns (ARCHIVE_RETENTION_EXCEEDED)')
374
+ ok(st4.file(last.baseRunDir + '/receipt.json') !== undefined, 'the FIRST attempt is still present after exceeding the cap')
375
+
376
+ // 15e. the failure return also carries the archive coordinates.
377
+ const st5 = makeFakeHost({ exit: 3 })
378
+ M.registerMathComputation(st5.host)
379
+ const bad = await st5.call({ op: 'run', engine: 'python', mode: 'code', code: 'boom\n' })
380
+ ok(bad.ok === false && bad.code === 'MATH_NONZERO_EXIT' && !!bad.scriptPath && !!bad.scriptHash, 'failure return carries scriptPath + scriptHash')
381
+ }
382
+
383
+ // ── 16. AUDIT-C fixes: concurrency, listDir retention, string-level path guard ──────────────────
384
+ {
385
+ // 16a (HIGH). Two same-id runs fired concurrently must never share an attempt dir: allocation +
386
+ // the claiming receipt write are serialised per archive id. Before the fix both took attempt 1 and
387
+ // the second silently overwrote the first receipt.
388
+ {
389
+ const stc = makeFakeHost({})
390
+ M.registerMathComputation(stc.host)
391
+ const [a, b] = await Promise.all([
392
+ stc.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' }),
393
+ stc.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' }),
394
+ ])
395
+ ok(a.receipt.dir !== b.receipt.dir, '★ 同一 id 的并发运行绝不共用一个 attempt 目录(并发下的 append-only)')
396
+ ok([a.attempt, b.attempt].sort().join(',') === '1,2', 'concurrent same-id runs take attempts 1 and 2 (neither archive is lost)')
397
+ ok(stc.file(a.attemptDir + '/receipt.json') !== undefined && stc.file(b.attemptDir + '/receipt.json') !== undefined, 'both concurrent attempts have their own receipt on disk')
398
+ }
399
+
400
+ // 16b (MEDIUM). Project-level retention via the optional listDir, and the no-listDir path.
401
+ {
402
+ const many = []
403
+ for (let i = 0; i < M.MATH_ARCHIVE_MAX_RUNS + 1; i++) many.push({ name: 'run-' + i, type: 'directory' })
404
+ const stl = makeFakeHost({ listDir: many })
405
+ M.registerMathComputation(stl.host)
406
+ const over = await stl.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' })
407
+ ok(over.warnings.some((w) => w.code === M.MATH_ARCHIVE_WARNING), 'listDir shows more than MATH_ARCHIVE_MAX_RUNS -> ARCHIVE_RETENTION_EXCEEDED (warn only)')
408
+ ok(stl.listDirCalls.length > 0 && stl.listDirCalls[0].indexOf('Computation') !== -1, 'the retention check asks the host to list Computation/')
409
+ ok(stl.file(over.attemptDir + '/receipt.json') !== undefined, 'nothing is deleted when the cap is exceeded')
410
+ const stn = makeFakeHost({})
411
+ M.registerMathComputation(stn.host)
412
+ const under = await stn.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' })
413
+ ok(stn.listDirCalls.length === 0, 'a host without listDir is never asked for a listing')
414
+ ok(!under.warnings.some((w) => w.code === M.MATH_ARCHIVE_WARNING), 'no listDir -> no project-level retention check and no false alarm')
415
+ }
416
+
417
+ // 16c (MEDIUM). The path guard is STRING-LEVEL: pin what it really does, including the limitation.
418
+ {
419
+ const sp = makeFakeHost({ files: { 'Problems/calc.py': 'print(1)\n', 'Problems/link.py': 'print(2)\n' } })
420
+ M.registerMathComputation(sp.host)
421
+ const up = await sp.call({ op: 'run', engine: 'python', mode: 'file', file: '../outside.py' })
422
+ ok(up.ok === false && up.code === 'MATH_REFUSED' && up.next.reason === 'path-outside-project', 'lexical escape ../ is refused')
423
+ const deep = await sp.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/../../outside.py' })
424
+ ok(deep.ok === false && deep.code === 'MATH_REFUSED', 'a lexical escape buried mid-path is refused')
425
+ const abs = await sp.call({ op: 'run', engine: 'python', mode: 'file', file: 'C:/Windows/system32/calc.py' })
426
+ ok(abs.ok === false && abs.code === 'MATH_REFUSED', 'an absolute path is refused')
427
+ // A symlink/junction is invisible to a string guard. This pins the LIMITATION (docs §6): a path
428
+ // that LOOKS in-project is accepted, because the guard never resolves it. The host fs owns real
429
+ // containment, so this assertion exists to stop the docs from claiming otherwise.
430
+ const linked = await sp.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/link.py' })
431
+ ok(linked.ok === true, 'an in-project path is accepted without resolving it (string-level guard: links/junctions are NOT followed)')
432
+ }
433
+
434
+ // 16d (AUDIT-A). Two more reconciliation false negatives, both fail-closed now:
435
+ // - the source file disappearing WHILE the run is in flight must count as a change;
436
+ // - a deleted archive script must make op:'receipt' report scriptChanged (the receipt cannot be
437
+ // evidence for any code once its script is gone).
438
+ {
439
+ const sd = makeFakeHost({ files: { 'Problems/gone.py': 'print(1)\n' }, deleteOnRun: { rel: 'Problems/gone.py' } })
440
+ M.registerMathComputation(sd.host)
441
+ const g = await sd.call({ op: 'run', engine: 'python', mode: 'file', file: 'Problems/gone.py' })
442
+ ok(g.ok === true && g.scriptChangedDuringRun === true, 'the source file disappearing mid-run is a change: scriptChangedDuringRun:true')
443
+ ok(g.warnings.some((w) => w.code === M.MATH_SCRIPT_CHANGED_DURING_RUN_WARNING), 'a disappeared source is warned visibly')
444
+ ok(JSON.parse(sd.file(g.attemptDir + '/receipt.json')).scriptChangedDuringRun === true, 'the receipt records it too')
445
+
446
+ const sm = makeFakeHost({})
447
+ M.registerMathComputation(sm.host)
448
+ const run2 = await sm.call({ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n' })
449
+ sm.files.delete(run2.scriptPath)
450
+ const rec2 = await sm.call({ op: 'receipt', file: run2.baseRunDir })
451
+ ok(rec2.ok === true && rec2.scriptChanged === true && rec2.currentScriptHash === null, 'a deleted archive script makes op=receipt report scriptChanged (fail-closed)')
452
+ ok(rec2.warnings.some((w) => w.code === M.MATH_SCRIPT_CHANGED_WARNING), 'the deletion is warned visibly')
453
+ }
454
+ }
455
+
456
+ // ── 17. AUDIT-B #1: mathEngineOverride is a REAL, accepted argument ─────────────────────────────
457
+ {
458
+ // 17a. It is accepted (not "unknown argument") and it really changes the assembled argv.
459
+ {
460
+ const so = makeFakeHost({})
461
+ M.registerMathComputation(so.host)
462
+ const r = await so.call({
463
+ op: 'run', engine: 'python', mode: 'code', code: 'print(1)\n',
464
+ mathEngineOverride: { python: { scriptArgv: ['-u', '<script>'], versionArgv: ['--version', '--override-proof'] } },
465
+ })
466
+ ok(r.ok === true, 'mathEngineOverride is ACCEPTED (previously rejected as an unknown argument)')
467
+ eq(r.argv[1], '-u', 'the overridden scriptArgv really changes the assembled argv')
468
+ ok(r.argv[r.argv.length - 1].indexOf('script.py') !== -1, 'the <script> placeholder is still substituted with the archived script path')
469
+ const versionSpawn = so.spawns.filter((s) => s.argv.indexOf('--override-proof') !== -1)
470
+ ok(versionSpawn.length > 0, 'the overridden versionArgv reaches the VERSION probe (not just the run argv)')
471
+ ok(!so.spawns.some((s) => s.argv.length === 2 && s.argv[1] === '--version'), 'the default versionArgv is not used once overridden')
472
+ }
473
+
474
+ // 17b. mode:'expr' override.
475
+ {
476
+ const se = makeFakeHost({})
477
+ M.registerMathComputation(se.host)
478
+ const r = await se.call({ op: 'run', engine: 'python', mode: 'expr', expr: '1+1', mathEngineOverride: { python: { evalArgv: ['-X', 'utf8', '-c', '<expr>'] } } })
479
+ eq(r.argv.slice(1, 4), ['-X', 'utf8', '-c'], 'the overridden evalArgv is used for mode=expr')
480
+ }
481
+
482
+ // 17c. The override stays CLOSED: bad shapes are refused with MATH_INVALID_ARGUMENT.
483
+ {
484
+ const sv = makeFakeHost({})
485
+ M.registerMathComputation(sv.host)
486
+ const unknownEngine = await sv.call({ op: 'run', engine: 'python', mode: 'code', code: 'x\n', mathEngineOverride: { fortran: { scriptArgv: ['<script>'] } } })
487
+ ok(unknownEngine.ok === false && unknownEngine.code === 'MATH_INVALID_ARGUMENT' && /unknown engine/.test(unknownEngine.message), 'an override for an unknown engine is refused')
488
+ const badShape = await sv.call({ op: 'run', engine: 'python', mode: 'code', code: 'x\n', mathEngineOverride: { python: { scriptArgv: 'not-an-array' } } })
489
+ ok(badShape.ok === false && badShape.code === 'MATH_INVALID_ARGUMENT' && /string\[\]/.test(badShape.message), 'a non-array template is refused')
490
+ const badKey = await sv.call({ op: 'run', engine: 'python', mode: 'code', code: 'x\n', mathEngineOverride: { python: { shellArgv: ['x'] } } })
491
+ ok(badKey.ok === false && badKey.code === 'MATH_INVALID_ARGUMENT' && /unknown key/.test(badKey.message), 'an unknown key inside the override is refused')
492
+ }
493
+
494
+ // 17d. The advertised hint and the schema agree with the implementation.
495
+ {
496
+ ok(!!M.MATH_TOOL_SCHEMA.properties.mathEngineOverride, 'MATH_TOOL_SCHEMA advertises mathEngineOverride')
497
+ ok(M.MATH_BAD_ARGV_HINT === 'mathEngineOverride', 'MATH_BAD_ARGV_HINT still names the escape hatch')
498
+ }
499
+ }
500
+
501
+ console.log('')
502
+ console.log('=== MATH COMPUTATION SHARED: ' + passed + ' passed, ' + failed + ' failed ===')
503
+ if (failures.length) for (const f of failures) console.error(' - ' + f)
504
+ process.exit(failed === 0 ? 0 : 1)
@@ -991,7 +991,7 @@ const RK = makeRoot()
991
991
  await callTool('vibe_v5_start', { problem: 'Lean 提示词测试', researcherCount: 2 }, RK)
992
992
  for (const sp of spawnsFor(RK)) { fireEnd(sp.childId, { progress: memberOfChild(sp.childId) + ':初始见解。', solved: false, contextPct: 10 }); await settle() }
993
993
  await settleInstitute(RK)
994
- await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage' }, RK)
994
+ await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage', leanAsync: false }, RK)
995
995
  // (a) an ordinary work round carries the "formalize reusable things as you go" request
996
996
  delivered.length = 0
997
997
  await callTool('vibe_v5_say', { to: 'r-1', text: '继续推进。' }, childAgent(childOf(RK, 'acad')))
@@ -1024,7 +1024,7 @@ const RL2 = makeRoot()
1024
1024
  await callTool('vibe_v5_start', { problem: 'Lean 忠实性提示词测试', researcherCount: 2 }, RL2)
1025
1025
  for (const sp of spawnsFor(RL2)) { fireEnd(sp.childId, { progress: memberOfChild(sp.childId) + ':初始见解。', solved: false, contextPct: 10 }); await settle() }
1026
1026
  await settleInstitute(RL2)
1027
- await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage' }, RL2)
1027
+ await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage', leanAsync: false }, RL2)
1028
1028
  await callTool('vibe_v5_record_proposition', { id: 'p-lean-b', statement: 'Lean 语料对象乙', value: 0.6, motive: 'm', p: 0.9 }, childAgent(childOf(RL2, 'r-1')))
1029
1029
  const leanB = await callTool('vibe_v5_lean_archive', { kind: 'proof', target: 'p-lean-b', content: 'theorem p_lean_b : 1 + 1 = 2 := by decide\n' }, childAgent(childOf(RL2, 'r-1')))
1030
1030
  assert(leanB.ok === true && leanB.passed === true, 'object 乙 has a proof that really passes (' + JSON.stringify({ ok: leanB.ok, passed: leanB.passed, code: leanB.run && leanB.run.code }) + ')')
@@ -1053,7 +1053,7 @@ const R_LEANREQ = makeRoot()
1053
1053
  await callTool('vibe_v5_start', { problem: 'Lean require 提示词测试', researcherCount: 2 }, R_LEANREQ)
1054
1054
  for (const sp of spawnsFor(R_LEANREQ)) { fireEnd(sp.childId, { progress: memberOfChild(sp.childId) + ':初始见解。', solved: false, contextPct: 10 }); await settle() }
1055
1055
  await settleInstitute(R_LEANREQ)
1056
- await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'require' }, R_LEANREQ)
1056
+ await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'require', leanAsync: false }, R_LEANREQ)
1057
1057
  await callTool('vibe_v5_record_proposition', { id: 'p-lean-req', statement: 'Lean 语料对象丙(require 档)', value: 0.6, motive: 'm', p: 0.8 }, childAgent(childOf(R_LEANREQ, 'r-1')))
1058
1058
  const propR = await callTool('vibe_v5_propose_verify', { target: 'p-lean-req', kind: 'proposition', reason: '语料' }, childAgent(childOf(R_LEANREQ, 'r-1')))
1059
1059
  assert(propR.ok === true && propR.started === true, 'the require-mode ballot started (' + JSON.stringify(propR).slice(0, 90) + ')')
@@ -1077,7 +1077,7 @@ const R_LEANDEF = makeRoot()
1077
1077
  await callTool('vibe_v5_start', { problem: 'Lean 缺陷后提示词测试', researcherCount: 2 }, R_LEANDEF)
1078
1078
  for (const sp of spawnsFor(R_LEANDEF)) { fireEnd(sp.childId, { progress: memberOfChild(sp.childId) + ':初始见解。', solved: false, contextPct: 10 }); await settle() }
1079
1079
  await settleInstitute(R_LEANDEF)
1080
- await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage' }, R_LEANDEF)
1080
+ await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage', leanAsync: false }, R_LEANDEF)
1081
1081
  await callTool('vibe_v5_record_proposition', { id: 'p-lean-def', statement: 'Lean 语料对象丁', value: 0.6, motive: 'm', p: 0.9 }, childAgent(childOf(R_LEANDEF, 'r-1')))
1082
1082
  const leanD = await callTool('vibe_v5_lean_archive', { kind: 'proof', target: 'p-lean-def', content: 'theorem p_lean_d : 1 + 1 = 2 := by decide\n' }, childAgent(childOf(R_LEANDEF, 'r-1')))
1083
1083
  assert(leanD.ok === true && leanD.passed === true, 'object 丁 has a passing proof before the defect')
@@ -1109,7 +1109,7 @@ const R_LEANHINT = makeRoot()
1109
1109
  await callTool('vibe_v5_start', { problem: 'Lean 工具提示语料测试', researcherCount: 2 }, R_LEANHINT)
1110
1110
  for (const sp of spawnsFor(R_LEANHINT)) { fireEnd(sp.childId, { progress: memberOfChild(sp.childId) + ':初始见解。', solved: false, contextPct: 10 }); await settle() }
1111
1111
  await settleInstitute(R_LEANHINT)
1112
- await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage' }, R_LEANHINT)
1112
+ await callTool('vibe_v5_set', { maxParallel: 8, formalVerify: 'encourage', leanAsync: false }, R_LEANHINT)
1113
1113
  {
1114
1114
  const r1 = childAgent(childOf(R_LEANHINT, 'r-1'))
1115
1115
  // Labels are OURS (they name the call that produced the string); only the VALUES are
@@ -33,9 +33,15 @@
33
33
  - vibe_math_new_project / vibe_math_set_project / vibe_math_list_projects — per-project folders.
34
34
  - vibe_math_list_decisions / vibe_math_decide {id, action: approve|reject|override, verdict?} — resolve manual decisions.
35
35
  - vibe_math_list_agents / vibe_math_message_agent / vibe_math_interrupt_agent — inspect / steer / interrupt subagents.
36
- - vibe_math_lean_run / vibe_math_lean_archive / vibe_math_lean_lib — Lean formal
37
- verification (execute / archive / list the reuse library). The scheduler's child agents
38
- use them too; they work in every mode.
36
+ - vibe_math_lean_run / vibe_math_lean_archive / vibe_math_lean_lib / vibe_math_lean_read /
37
+ vibe_math_lean_job — Lean formal verification (execute / archive / list + read the reuse
38
+ library / inspect or wait for a background compile job). leanAsync=true (default) queues the
39
+ compile and returns a jobId; nothing counts as proved until that job settles ok (so "有把握"
40
+ is not the same as "已验证"). The scheduler's child agents use them too; they work in every
41
+ mode.
42
+
43
+ - math_computation {op: probe|run|receipt|install, engine, mode: code|file|expr, …} — 先 probe 预检引擎/包/许可,再调引擎计算并把脚本与输出归档成可复核回执;缺引擎/缺包只报告与给安装指引/计划;shell 兜底不算归档。
44
+ - 归档→编辑→重跑:mode:'code' 的脚本原件在回执的 scriptPath(Computation/<id>/script.<ext>),你可以用普通文件工具打开并编辑它;编辑后用 mode:'file' 指向它重跑,会写出一份**新回执/新 attempt**(含新的 scriptHash)。**旧回执对修改后的代码无效**——报告里必须引用与当前代码哈希一致的那份回执;工具会在 scriptChanged / scriptChangedDuringRun 为 true 时显式告警。
39
45
 
40
46
  Final paper: strict termination writes Paper/<project>/{paper.md,paper.tex,paper.pdf,paper.meta.json,paper.log.md}
41
47
  automatically — a dedicated paper-writing child assembles the solved material (finalPaper=false disables only that
@@ -74,7 +80,7 @@
74
80
  explicit, reasoned blocker record; the scheduler is never wedged by it).
75
81
  - Paths: work file Formal/<id>.lean; archived proof Verified/Lean/<id>.lean; reusable
76
82
  definitions VibeMath/Formal/Lib/; proved lemmas VibeMath/Formal/Proved/.
77
- - The toolchain knobs leanCommand / leanArgs / leanTimeoutMs are tunable as well
83
+ - The toolchain knobs leanCommand / leanArgs / leanTimeoutMs / leanAsync / leanInitiative / leanSearchPaths / leanJobsMaxParallel are tunable as well
78
84
  (e.g. leanCommand='lake' with leanArgs=['env','lean']); a missing Lean binary is
79
85
  reported as LEAN_NOT_FOUND and still lets the code be written and archived.
80
86
  - vibe_math_status / vibe_math_report show the mode, the per-object formal status and the
@@ -104,9 +110,15 @@
104
110
  - vibe_math_new_project / vibe_math_set_project / vibe_math_list_projects — per-project folders.
105
111
  - vibe_math_list_decisions / vibe_math_decide {id, action: approve|reject|override, verdict?} — resolve manual decisions.
106
112
  - vibe_math_list_agents / vibe_math_message_agent / vibe_math_interrupt_agent — inspect / steer / interrupt subagents.
107
- - vibe_math_lean_run / vibe_math_lean_archive / vibe_math_lean_lib — Lean formal
108
- verification (execute / archive / list the reuse library). The scheduler's child agents
109
- use them too; they work in every mode.
113
+ - vibe_math_lean_run / vibe_math_lean_archive / vibe_math_lean_lib / vibe_math_lean_read /
114
+ vibe_math_lean_job — Lean formal verification (execute / archive / list + read the reuse
115
+ library / inspect or wait for a background compile job). leanAsync=true (default) queues the
116
+ compile and returns a jobId; nothing counts as proved until that job settles ok (so "有把握"
117
+ is not the same as "已验证"). The scheduler's child agents use them too; they work in every
118
+ mode.
119
+
120
+ - math_computation {op: probe|run|receipt|install, engine, mode: code|file|expr, …} — 先 probe 预检引擎/包/许可,再调引擎计算并把脚本与输出归档成可复核回执;缺引擎/缺包只报告与给安装指引/计划;shell 兜底不算归档。
121
+ - 归档→编辑→重跑:mode:'code' 的脚本原件在回执的 scriptPath(Computation/<id>/script.<ext>),你可以用普通文件工具打开并编辑它;编辑后用 mode:'file' 指向它重跑,会写出一份**新回执/新 attempt**(含新的 scriptHash)。**旧回执对修改后的代码无效**——报告里必须引用与当前代码哈希一致的那份回执;工具会在 scriptChanged / scriptChangedDuringRun 为 true 时显式告警。
110
122
 
111
123
  Final paper: strict termination writes Paper/<project>/{paper.md,paper.tex,paper.pdf,paper.meta.json,paper.log.md}
112
124
  automatically — a dedicated paper-writing child assembles the solved material (finalPaper=false disables only that
@@ -145,7 +157,7 @@
145
157
  explicit, reasoned blocker record; the scheduler is never wedged by it).
146
158
  - Paths: work file Formal/<id>.lean; archived proof Verified/Lean/<id>.lean; reusable
147
159
  definitions VibeMath/Formal/Lib/; proved lemmas VibeMath/Formal/Proved/.
148
- - The toolchain knobs leanCommand / leanArgs / leanTimeoutMs are tunable as well
160
+ - The toolchain knobs leanCommand / leanArgs / leanTimeoutMs / leanAsync / leanInitiative / leanSearchPaths / leanJobsMaxParallel are tunable as well
149
161
  (e.g. leanCommand='lake' with leanArgs=['env','lean']); a missing Lean binary is
150
162
  reported as LEAN_NOT_FOUND and still lets the code be written and archived.
151
163
  - vibe_math_status / vibe_math_report show the mode, the per-object formal status and the