dsh-vibe-math 2.7.3 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +682 -682
  3. package/README.md +683 -683
  4. package/docs/AUDIT-CHECKLIST.md +758 -744
  5. package/docs/COMPAT-AUDIT-ROUND2.md +351 -351
  6. package/docs/COMPAT-AUDIT-ROUND3.md +154 -154
  7. package/docs/audit-methodology.md +93 -0
  8. package/docs/final-paper.md +172 -172
  9. package/docs/formal-verification.md +613 -588
  10. package/docs/generate_framework_diagram_v2.py +114 -114
  11. package/docs/generate_framework_diagram_v3.py +127 -127
  12. package/docs/math-computation.md +195 -194
  13. package/docs/release-notes/README.en.md +2 -0
  14. package/docs/release-notes/README.md +2 -0
  15. package/docs/release-notes/RELEASE-NOTES-2.0.22.md +112 -112
  16. package/docs/release-notes/RELEASE-NOTES-2.1.0.md +143 -143
  17. package/docs/release-notes/RELEASE-NOTES-2.2.0.md +266 -266
  18. package/docs/release-notes/RELEASE-NOTES-2.2.1.md +43 -43
  19. package/docs/release-notes/RELEASE-NOTES-2.2.2.md +88 -88
  20. package/docs/release-notes/RELEASE-NOTES-2.3.0.md +207 -207
  21. package/docs/release-notes/RELEASE-NOTES-2.3.1.md +134 -134
  22. package/docs/release-notes/RELEASE-NOTES-2.3.10.md +105 -105
  23. package/docs/release-notes/RELEASE-NOTES-2.3.11.md +57 -57
  24. package/docs/release-notes/RELEASE-NOTES-2.3.12.md +80 -80
  25. package/docs/release-notes/RELEASE-NOTES-2.3.2.md +145 -145
  26. package/docs/release-notes/RELEASE-NOTES-2.3.3.md +115 -115
  27. package/docs/release-notes/RELEASE-NOTES-2.3.4.md +69 -69
  28. package/docs/release-notes/RELEASE-NOTES-2.3.5.md +63 -63
  29. package/docs/release-notes/RELEASE-NOTES-2.3.6.md +66 -66
  30. package/docs/release-notes/RELEASE-NOTES-2.3.7.md +59 -59
  31. package/docs/release-notes/RELEASE-NOTES-2.3.8.md +45 -45
  32. package/docs/release-notes/RELEASE-NOTES-2.3.9.md +70 -70
  33. package/docs/release-notes/RELEASE-NOTES-2.8.0.en.md +65 -0
  34. package/docs/release-notes/RELEASE-NOTES-2.8.0.md +65 -0
  35. package/docs/release-notes/RELEASE-NOTES-2.8.1.en.md +49 -0
  36. package/docs/release-notes/RELEASE-NOTES-2.8.1.md +49 -0
  37. package/docs/release-playbook.md +111 -0
  38. package/docs/slv-playbook.md +117 -0
  39. package/docs/test-timing.md +158 -157
  40. package/docs//346/236/266/346/236/204/345/233/276.md +77 -77
  41. package/installer.js +792 -792
  42. package/package.json +18 -3
  43. package/prompt-corpus-v2/formal-verify-v2.json +2 -2
  44. package/prompt-corpus-v2/formal-verify-v2.md +4 -0
  45. package/prompt-corpus-v3/formal-verify-v3.json +7 -7
  46. package/prompt-corpus-v3/formal-verify-v3.md +14 -0
  47. package/prompt-corpus-v5/prompt-corpus-v5.json +61 -61
  48. package/prompt-corpus-v5/prompt-corpus-v5.md +122 -0
  49. package/scripts/clean-temp.mjs +234 -0
  50. package/scripts/release-check.mjs +181 -0
  51. package/tests/audit-engine-faces.mjs +298 -0
  52. package/tests/audit-formal-sensitivity.mjs +345 -342
  53. package/tests/audit-installer-compat.test.mjs +256 -256
  54. package/tests/audit-math-computation-sensitivity.mjs +1 -1
  55. package/tests/audit-persona-sensitivity.mjs +323 -323
  56. package/tests/audit-persona-surface.test.mjs +431 -431
  57. package/tests/audit-prompt-duplication.mutants.mjs +3 -2
  58. package/tests/audit-prompt-invariants.mjs +589 -546
  59. package/tests/audit-registration.mjs +78 -78
  60. package/tests/audit-spec-traceability.mjs +193 -193
  61. package/tests/audit-status-report-fields.mjs +172 -172
  62. package/tests/audit-v5-integrity.mjs +795 -795
  63. package/tests/audit-v5-sensitivity.mjs +433 -432
  64. package/tests/e2e-v5-round2.test.mjs +2453 -2426
  65. package/tests/formal-verify-v2.test.mjs +1806 -1800
  66. package/tests/formal-verify-v3.test.mjs +1757 -1750
  67. package/tests/formal-verify-v4.test.mjs +2114 -2106
  68. package/tests/formal-verify-v5.test.mjs +774 -767
  69. package/tests/math-computation-discovery.mutants.mjs +3 -3
  70. package/tests/math-computation-shared.test.mjs +122 -5
  71. package/tests/math-computation-v2.test.mjs +14 -2
  72. package/tests/math-computation-v3.test.mjs +14 -2
  73. package/tests/math-computation-v4.test.mjs +739 -739
  74. package/tests/prompt-v5-integrity.test.mjs +1291 -1291
  75. package/tests/release-check.mutants.mjs +78 -0
  76. package/tests/run-tests.mjs +393 -332
  77. package/tests/selfdrive-v5.mjs +560 -560
  78. package/tests/temp-hygiene.mutants.mjs +80 -0
  79. package/tests/v2-fix-probes.mutants.mjs +4 -0
  80. package/tests/v2-fix-probes.test.mjs +1034 -1033
  81. package/tests/v2v3-interrupt.mutants.mjs +111 -0
  82. package/tests/v3-fix-probes.mutants.mjs +99 -95
  83. package/tests/v3-fix-probes.test.mjs +891 -890
  84. package/tests/v4-final-paper.mutants.mjs +116 -0
  85. package/tests/v4-final-paper.test.mjs +628 -0
  86. package/tests/v5-institute-fixes.mutants.mjs +218 -190
  87. package/vibe-math-v2/agent.cordis.yml +376 -376
  88. package/vibe-math-v2/math-computation.js +17 -15
  89. package/vibe-math-v2/preset.yml +2 -2
  90. package/vibe-math-v2/v2/347/232/204/351/242/235/345/244/226/350/246/201/346/261/202.txt +21 -21
  91. package/vibe-math-v2/vibe-math-v2.js +5078 -5011
  92. package/vibe-math-v2//345/256/236/347/216/260/346/226/271/346/241/210.md +486 -486
  93. package/vibe-math-v3/agent.cordis.yml +420 -420
  94. package/vibe-math-v3/math-computation.js +17 -15
  95. package/vibe-math-v3/preset.yml +2 -2
  96. package/vibe-math-v3/vibe-math-v3.js +6215 -6149
  97. package/vibe-math-v3//345/256/236/347/216/260/346/226/271/346/241/210.md +649 -649
  98. package/vibe-math-v4/agent.cordis.yml +438 -438
  99. package/vibe-math-v4/math-computation.js +17 -15
  100. package/vibe-math-v4/preset.yml +2 -2
  101. package/vibe-math-v4/vibe-math-v4.js +4520 -4422
  102. package/vibe-math-v4//345/256/236/347/216/260/346/226/271/346/241/210.md +1015 -1015
  103. package/vibe-math-v5/math-computation.js +17 -15
  104. package/vibe-math-v5/vibe-math-v5.js +93 -11
  105. package/vibe-math-v5//345/256/236/347/216/260/346/226/271/346/241/210.md +1728 -1728
  106. package/vibe-math-v5//346/236/266/346/236/204/345/233/276.md +693 -693
@@ -0,0 +1,298 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * REAL-ENGINE FACES (task-3) — presence-detected, loud-SKIP guards for the three "engine faces" that the
4
+ * scripted live validation could only sample: numeric (python/Rscript), Lean (lean), LaTeX (xelatex).
5
+ *
6
+ * Rules:
7
+ * · an engine that is NOT resolvable ⇒ print `SKIP: … (<reason>)` and do not fail (the gate must never
8
+ * be red on a machine without engines, and must never be silently green either);
9
+ * · an engine that IS resolvable ⇒ run it for real (real binary, real subprocess) and assert;
10
+ * · every assertion below has a SINGLE-SITE NAMED-RED proof reachable via `--self-probe` (env seams:
11
+ * MATH_COMPUTATION_MODULE / V4_PLUGIN / V5_PLUGIN point the child at a one-site mutant copy).
12
+ *
13
+ * Usage: node tests/audit-engine-faces.mjs [--self-probe]
14
+ */
15
+ import { existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync, statSync } from 'node:fs'
16
+ import { tmpdir } from 'node:os'
17
+ import { dirname, join, resolve } from 'node:path'
18
+ import { spawn, spawnSync } from 'node:child_process'
19
+ import { fileURLToPath, pathToFileURL } from 'node:url'
20
+
21
+ const HERE = fileURLToPath(new URL('./', import.meta.url))
22
+ const REPO = resolve(HERE, '..')
23
+ let passed = 0, failed = 0
24
+ const failures = []
25
+ const skips = []
26
+ const ok = (cond, label, detail) => { if (cond) { passed++; console.log(' ok ' + label) } else { failed++; failures.push(label + (detail ? ' — ' + detail : '')); console.log(' FAIL ' + label + (detail ? ' — ' + detail : '')) } }
27
+ const skip = (face, reason) => { skips.push(face + ': ' + reason); console.log(' SKIP: no ' + face + ' on this machine (' + reason + ')') }
28
+ const read = (env, rel) => {
29
+ const v = process.env[env]
30
+ return readFileSync(v ? (resolve(REPO, v)) : join(REPO, rel), 'utf8')
31
+ }
32
+
33
+ /** Resolve an executable: absolute candidates first, then PATH (with Windows extensions). */
34
+ function which(cmd) {
35
+ if (!cmd) return null
36
+ if (/[\\/]/.test(cmd) || /^[A-Za-z]:/.test(cmd)) return existsSync(cmd) ? cmd : null
37
+ const exts = process.platform === 'win32' ? ['', '.exe', '.cmd', '.bat'] : ['']
38
+ for (const dir of String(process.env.PATH || '').split(process.platform === 'win32' ? ';' : ':')) {
39
+ if (!dir) continue
40
+ for (const ext of exts) {
41
+ const p = join(dir, cmd + ext)
42
+ try { if (existsSync(p) && statSync(p).isFile()) return p } catch (e) { /* keep looking */ }
43
+ }
44
+ }
45
+ const w = spawnSync('where', [cmd], { encoding: 'utf8' })
46
+ if (w.status === 0) { const first = String(w.stdout || '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0]; if (first && existsSync(first)) return first }
47
+ return null
48
+ }
49
+ const resolveFirst = (...cmds) => { for (const c of cmds) { const p = which(c); if (p) return p } return null }
50
+
51
+ const PY = resolveFirst(String(process.env.LOCALAPPDATA || '') + '\\Programs\\Python\\Python312\\python.exe', 'python', 'python3')
52
+ const RC = resolveFirst('C:\\Program Files\\R\\R-4.6.1\\bin\\Rscript.exe', 'Rscript')
53
+ const LEAN = resolveFirst('D:\\.elan\\bin\\lean.exe', 'lean')
54
+ const XELATEX = resolveFirst('D:\\texlive\\2025\\bin\\windows\\xelatex.exe', 'xelatex')
55
+
56
+ // ── shared helpers ────────────────────────────────────────────────────────────────────────────────
57
+ /** A REAL subprocess service in the shape the presets expect (resolveExecutable/spawn/done/collected). */
58
+ function realSubprocess() {
59
+ return {
60
+ async resolveExecutable(cmd) { const p = which(cmd); if (!p) throw new Error('not found on PATH: ' + cmd); return p },
61
+ spawn({ argv, cwd, stdio, graceMs }) {
62
+ const child = spawn(argv[0], argv.slice(1), { cwd, windowsHide: true })
63
+ let out = '', err = ''
64
+ const cap = 1 << 20
65
+ child.stdout.on('data', (d) => { if (out.length < cap) out += String(d) })
66
+ child.stderr.on('data', (d) => { if (err.length < cap) err += String(d) })
67
+ const done = new Promise((res) => {
68
+ child.on('error', (e) => res({ exitCode: null, signal: null, error: String((e && e.message) || e) }))
69
+ child.on('close', (code, signal) => res({ exitCode: code, signal: signal || null }))
70
+ })
71
+ return {
72
+ done,
73
+ terminate() { try { child.kill('SIGKILL') } catch (e) { /* best effort */ } },
74
+ collected: { stdout: { readFrom: () => ({ text: out }) }, stderr: { readFrom: () => ({ text: err }) } },
75
+ }
76
+ },
77
+ }
78
+ }
79
+ /** Minimal cordis-shaped ctx (modeled on tests/audit-tool-exec.mjs, but with a REAL subprocess). */
80
+ const FS_TRACE = []
81
+ function makeCtx(WS) {
82
+ const regs = []
83
+ const ctx = {
84
+ get(n) { if (n === 'subprocess') return realSubprocess(); return undefined },
85
+ on() {}, effect(fn) { const d = fn(); return () => { if (typeof d === 'function') d() } },
86
+ logger: { info() {}, warn() {}, error() {} },
87
+ tools: { register(spec) { regs.push(spec) } },
88
+ commands: { register() {} },
89
+ timeout(fn, ms) { const t = setTimeout(fn, ms); return () => clearTimeout(t) },
90
+ subagents: { list() { return ['spawn'] }, async startContinuable() { return { childId: 'c1' } }, async sendMessage() {}, async followup() {}, interrupt() {} },
91
+ agents: { roots() { return [] }, get() { return undefined } },
92
+ fs: {
93
+ async resolve(rel, o) { const s = String(rel); const abs = isAbsolute(s) ? s : join((o && o.cwd) || WS, ...s.split('/')); FS_TRACE.push('resolve:' + abs + ' exists=' + existsSync(abs)); return abs },
94
+ async stat(t) { FS_TRACE.push('stat:' + t + ' exists=' + existsSync(t)); try { return statSync(t).isDirectory() ? { type: 'directory' } : { type: 'file' } } catch (e) { return undefined } },
95
+ async readText(t) { FS_TRACE.push('readText:' + t); return readFileSync(t, 'utf8') },
96
+ async writeText(t, c) { mkdirSync(dirname(t), { recursive: true }); writeFileSync(t, c, 'utf8') },
97
+ async listDir(t) { try { return readdirSync(t, { withFileTypes: true }).map((e) => ({ name: e.name, type: e.isDirectory() ? 'directory' : 'file' })) } catch (e) { return [] } },
98
+ },
99
+ }
100
+ return { ctx, regs }
101
+ }
102
+ async function registeredTool(presetRel, name, WS) {
103
+ const { ctx, regs } = makeCtx(WS)
104
+ // `resolve`, not `join`: a seam value may be an ABSOLUTE path, and join(REPO, abs) mangles it.
105
+ const mod = await import(pathToFileURL(resolve(REPO, presetRel)).href + '?t=' + Date.now())
106
+ ;(mod.default || mod).apply(ctx)
107
+ return regs.find((s) => s.name === name) || null
108
+ }
109
+ const parse = (raw) => { try { return JSON.parse(String(raw)) } catch (e) { return { __unparsed: String(raw).slice(0, 300) } } }
110
+
111
+ // ── FACE 1: numeric (python / Rscript) — real binaries, real subprocess ───────────────────────────
112
+ console.log('=== FACE 1: numeric engines (real binaries) ===')
113
+ if (!PY && !RC) {
114
+ skip('numeric engine', 'neither python nor Rscript resolved (PATH + known absolute locations checked)')
115
+ } else {
116
+ const WS = mkdtempSync(join(tmpdir(), 'engine-num-'))
117
+ try {
118
+ const M = await import(pathToFileURL(process.env.MATH_COMPUTATION_MODULE ? resolve(REPO, process.env.MATH_COMPUTATION_MODULE) : join(REPO, 'vibe-math-v2/math-computation.js')).href + '?t=' + Date.now())
119
+ const engines = []
120
+ if (PY) engines.push('python')
121
+ if (RC) engines.push('r')
122
+ const handlers = {}
123
+ const host = {
124
+ register: (name, desc, schema, fn) => { handlers[name] = fn }, // the host registers the tool handler
125
+ params: () => ({ mathEngines: engines.slice(), mathMode: 'typed+shell', mathTimeoutMs: 60000, mathPackages: [], mathInstallScope: 'user' }),
126
+ projectRoot: () => WS,
127
+ exists: async (rel) => existsSync(resolve(WS, rel)) || existsSync(rel),
128
+ readText: async (rel) => { try { return readFileSync(resolve(WS, rel), 'utf8') } catch (e) { return undefined } },
129
+ writeText: async (rel, text) => { const abs = resolve(WS, rel); mkdirSync(dirname(abs), { recursive: true }); writeFileSync(abs, text, 'utf8'); return abs },
130
+ resolveExecutable: async (cmd) => which(cmd) || undefined,
131
+ // NOTE the contract difference: the MODULE's host `spawn` returns a plain result
132
+ // ({exit,timedOut,killed,ms,stdout,stderr}), while the PRESET's ctx subprocess service returns a
133
+ // handle ({done,terminate,collected}). Both are exercised here, each in its own shape.
134
+ spawn: async ({ argv, cwd, timeoutMs, stdoutCap, stderrCap }) => {
135
+ const t0 = Date.now()
136
+ const r = spawnSync(argv[0], argv.slice(1), { cwd, encoding: 'utf8', timeout: Math.max(1000, Number(timeoutMs) || 60000), maxBuffer: 8 << 20, windowsHide: true })
137
+ return {
138
+ exit: r.status === null ? null : r.status,
139
+ timedOut: !!(r.error && r.error.code === 'ETIMEDOUT'),
140
+ killed: false,
141
+ ms: Date.now() - t0,
142
+ stdout: String(r.stdout || '').slice(0, Number(stdoutCap) || undefined),
143
+ stderr: String(r.stderr || '').slice(0, Number(stderrCap) || undefined),
144
+ }
145
+ },
146
+ listDirAbs: async (abs) => { try { return readdirSync(abs, { withFileTypes: true }).map((e) => ({ name: e.name, type: e.isDirectory() ? 'directory' : 'file' })) } catch (e) { return [] } },
147
+ runtimeRoots: async () => [],
148
+ log: () => {},
149
+ }
150
+ M.registerMathComputation(host)
151
+ const call = (args) => handlers[M.MATH_TOOL_NAME](args, { id: 'probeProj', session: { id: 'S', header: { cwd: WS } } })
152
+ for (const eng of engines) {
153
+ const p = await call({ op: 'probe', engine: eng })
154
+ const entry = (p.engines || []).find((e) => e.name === eng)
155
+ ok(!!entry && Array.isArray(p.configured) && p.configured.indexOf(eng) !== -1 && ['path', 'host-runtime', 'known-install'].indexOf(entry.foundVia) !== -1,
156
+ '★ engine-faces numeric(' + eng + '): probe reports `configured` and a valid `foundVia` (' + String(entry && entry.foundVia) + ')')
157
+ const code = eng === 'python' ? 'print(6*7)\n' : 'cat(6*7)\n'
158
+ const r = await call({ op: 'run', engine: eng, mode: 'code', code: code })
159
+ ok(r.ok === true && typeof r.runId === 'string' && r.runId && Number(r.attempt) >= 1 && r.exit === 0,
160
+ '★ engine-faces numeric(' + eng + '): a real mode:\'code\' run returns runId/attempt/exit=0 (' + JSON.stringify({ runId: r.runId, attempt: r.attempt, exit: r.exit }) + ')')
161
+ ok(String(r.stdout || '').indexOf('42') !== -1, '★ engine-faces numeric(' + eng + '): the real computation returned 42', JSON.stringify(String(r.stdout || '').slice(0, 80)))
162
+ }
163
+ } finally { rmSync(WS, { recursive: true, force: true }) }
164
+ }
165
+
166
+ // ── FACE 2: Lean — real lean through the REGISTERED tool handler ──────────────────────────────────
167
+ console.log('=== FACE 2: Lean (real toolchain; registered-handler contract) ===')
168
+ if (!LEAN) {
169
+ skip('lean', 'lean did not resolve (PATH + D:\\.elan\\bin\\lean.exe checked)')
170
+ } else {
171
+ const WS = mkdtempSync(join(tmpdir(), 'engine-lean-'))
172
+ try {
173
+ // (a) DIRECT real Lean run. The good/bad pair is its own control: the good file must exit 0 and the
174
+ // wrong proof must exit non-zero with the toolchain's own error line. Written with Buffer.from(...,'utf8')
175
+ // (NO BOM): PowerShell's Set-Content -Encoding utf8 writes a BOM and Lean answers "1:0: expected token".
176
+ const good = 'theorem t : 1 + 1 = 2 := rfl\n'
177
+ const bad = 'theorem t : 1 + 1 = 3 := rfl\n'
178
+ writeFileSync(join(WS, 'Good.lean'), Buffer.from(good, 'utf8'))
179
+ writeFileSync(join(WS, 'Bad.lean'), Buffer.from(bad, 'utf8'))
180
+ const g = spawnSync(LEAN, [join(WS, 'Good.lean')], { encoding: 'utf8', windowsHide: true })
181
+ ok(g.status === 0, '★ engine-faces lean: a correct one-line theorem compiles with the REAL toolchain (exit 0; ' + JSON.stringify(String(g.stdout || '').trim().slice(0, 60)) + ')')
182
+ const b = spawnSync(LEAN, [join(WS, 'Bad.lean')], { encoding: 'utf8', windowsHide: true })
183
+ const bMsg = String(b.stderr || '') + String(b.stdout || '')
184
+ ok(b.status !== 0 && /error/i.test(bMsg),
185
+ '★ engine-faces lean: a WRONG proof fails with the toolchain\'s own error (exit ' + String(b.status) + '; ' + JSON.stringify(bMsg.split('\n')[0].slice(0, 80)) + ')')
186
+ // (b) the REGISTERED tool handler is reachable and enforces its NAMED path contract.
187
+ const tool = await registeredTool(process.env.V4_PLUGIN || 'vibe-math-v4/vibe-math-v4.js', 'vibe_v4_lean_run', WS)
188
+ ok(!!tool, '★ engine-faces lean: the registered tool \`vibe_v4_lean_run\` is reachable (spec found)')
189
+ const agent = { id: 'S', options: {}, session: { id: 'S', header: { cwd: WS } } }
190
+ const esc = parse(await tool.execute({ name: 'probeProj', file: '../../../../escape.lean' }, { agent }))
191
+ ok(esc && esc.ok === false && esc.code === 'V4_INVALID_ARGUMENT',
192
+ '★ engine-faces lean: the handler NAMES its path contract (an out-of-tree file ⇒ V4_INVALID_ARGUMENT; ' + JSON.stringify({ ok: esc && esc.ok, code: esc && esc.code }) + ')')
193
+ // (c) task-6: the resolver contract, asserted DIRECTLY through the exported seam
194
+ // (`resolveKnownTool`, exported exactly as `mathInstallRoots` is in the shared module). No ctx, no
195
+ // root agent, no scaffold file, and no engine required: the resolver is driven with fake subprocess
196
+ // services and a temp ELAN_HOME, so this block runs anywhere.
197
+ {
198
+ const presetPath = resolve(REPO, process.env.V4_PLUGIN || 'vibe-math-v4/vibe-math-v4.js')
199
+ const R = await import(pathToFileURL(presetPath).href + '?t=' + Date.now())
200
+ const res = R.resolveKnownTool
201
+ ok(typeof res === 'function', '★ engine-faces lean: the resolver seam `resolveKnownTool` is exported for testing (like `mathInstallRoots`)')
202
+ const fakeHome = mkdtempSync(join(tmpdir(), 'engine-elan-'))
203
+ mkdirSync(join(fakeHome, 'bin'), { recursive: true })
204
+ writeFileSync(join(fakeHome, 'bin', 'lean.exe'), 'stub')
205
+ const hadElan = Object.prototype.hasOwnProperty.call(process.env, 'ELAN_HOME'), savedElan = process.env.ELAN_HOME
206
+ const throwing = { resolveExecutable: async () => { throw new Error('not found on PATH') } }
207
+ const resolving = { resolveExecutable: async (c) => 'C:/fake/path/' + c + '.exe' }
208
+ try {
209
+ process.env.ELAN_HOME = fakeHome
210
+ const k = await res(throwing, { name: 'lean', explicit: '', kind: 'lean' })
211
+ ok(k && k.via === 'known-install' && Array.isArray(k.tried) && k.tried.some((t) => t.indexOf('lean') !== -1 || t.indexOf('bin') !== -1),
212
+ '★ engine-faces lean: with PATH missing, the KNOWN-LOCATION fallback resolves and reports via=known-install (' + JSON.stringify({ via: k && k.via, exe: String(k && k.exe).slice(-24), tried: (k && k.tried || []).slice(0, 2) }) + ')')
213
+ const p = await res(resolving, { name: 'lean', explicit: '', kind: 'lean' })
214
+ ok(p && p.via === 'path' && /fake\/path/.test(String(p.exe)),
215
+ '★ engine-faces lean: a host-resolvable command reports via=path (' + JSON.stringify({ via: p && p.via }) + ')')
216
+ const e1 = await res(resolving, { name: 'lean', explicit: 'C:/custom/leanx.exe', kind: 'lean' })
217
+ ok(e1 && e1.via === 'explicit', '★ engine-faces lean: an explicit command that resolves reports via=explicit (' + JSON.stringify({ via: e1 && e1.via }) + ')')
218
+ const e2 = await res(throwing, { name: 'lean', explicit: 'C:/nope/leanx.exe', kind: 'lean' })
219
+ ok(e2 && e2.exe === null && e2.via === null && Array.isArray(e2.tried) && e2.tried.length > 0,
220
+ '★ engine-faces lean: an explicit command is NEVER guessed away — it fails with via=null and lists what it probed (' + JSON.stringify({ via: e2 && e2.via, tried: (e2 && e2.tried || []).slice(0, 2) }) + ')')
221
+ } finally {
222
+ if (hadElan) process.env.ELAN_HOME = savedElan; else delete process.env.ELAN_HOME
223
+ rmSync(fakeHome, { recursive: true, force: true })
224
+ }
225
+ }
226
+ console.log(' note: the handler\'s FILE-EXECUTION path is not reachable from a minimal ctx: workspaceRoot()')
227
+ console.log(' reads the root agent (vibe-math-v4.js:338) and falls back to process.cwd() here, so the')
228
+ console.log(' tool resolved the file under the repo tree. The real toolchain is exercised directly above;')
229
+ console.log(' the handler contributes reachability + the named argument contract.')
230
+ } finally { rmSync(WS, { recursive: true, force: true }) }
231
+ }
232
+
233
+ // ── FACE 3: LaTeX — real xelatex detection + named degradation ────────────────────────────────────
234
+ console.log('=== FACE 3: LaTeX (real xelatex detection + named degradation) ===')
235
+ if (!XELATEX) {
236
+ skip('xelatex', 'xelatex did not resolve (PATH + D:\\texlive\\2025\\bin\\windows checked)')
237
+ } else {
238
+ const WS = mkdtempSync(join(tmpdir(), 'engine-latex-'))
239
+ try {
240
+ const start = await registeredTool(process.env.V5_PLUGIN || 'vibe-math-v5/vibe-math-v5.js', 'vibe_v5_paper', WS)
241
+ const setP = await registeredTool(process.env.V5_PLUGIN || 'vibe-math-v5/vibe-math-v5.js', 'vibe_v5_set', WS)
242
+ ok(!!start, '★ engine-faces latex: the registered tool `vibe_v5_paper` is reachable (spec found)')
243
+ const agent = { id: 'S', options: {}, session: { id: 'S', header: { cwd: WS } } }
244
+ if (setP) { try { await setP.execute({ name: 'probeProj', params: { paperLatexCommand: XELATEX } }, { agent }) } catch (e) { /* fall through to the start assertion */ } }
245
+ const r = parse(await start.execute({ name: 'probeProj' }, { agent }))
246
+ ok(r && r.ok === true && r.started === true,
247
+ '★ engine-faces latex: with an ABSOLUTE `paperLatexCommand` the paper entry starts directly (' + JSON.stringify({ ok: r && r.ok, started: r && r.started }) + ')')
248
+ if (setP) { try { await setP.execute({ name: 'probeProj', params: { paperLatexCommand: 'Z:/definitely/not/here/xelatex.exe' } }, { agent }) } catch (e) { /* ignore */ } }
249
+ const bad = parse(await start.execute({ name: 'probeProj' }, { agent }))
250
+ ok(bad && typeof bad === 'object' && bad.ok === true && (bad.started === true || bad.code === undefined),
251
+ '★ engine-faces latex: a NONEXISTENT `paperLatexCommand` neither crashes nor raises an error code (entry stays ok:true, code undefined) (' + JSON.stringify({ ok: bad && bad.ok, code: bad && bad.code, note: String(bad && bad.note || '').slice(0, 50) }) + ')')
252
+ console.log(' note: the LaTeX COMPILE (paper writer subagent) is not reachable from this probe; it asserts the ENTRY only — crash-freedom and no error code. The named degradation for an unresolvable command is a COMPILE-time behaviour (docs/final-paper.md) and is deliberately NOT claimed here.')
253
+ console.log(' This probe runs the REAL xelatex only because it carries its own candidate list')
254
+ console.log(' (D:\\texlive\\2025\\bin\\windows) - it is NOT evidence that the product discovers a non-standard TeX installation.')
255
+ } finally { rmSync(WS, { recursive: true, force: true }) }
256
+ }
257
+
258
+ // ── --self-probe: one SINGLE-SITE named-red proof per face (env seams point a child at a mutant copy) ──
259
+ if (process.argv.includes('--self-probe')) {
260
+ const { copyFileSync, cpSync } = await import('node:fs')
261
+ const child = (env) => spawnSync(process.execPath, [fileURLToPath(import.meta.url)], { encoding: 'utf8', maxBuffer: 1 << 26, env: Object.assign({}, process.env, env) })
262
+ const namedIn = (out) => (label) => String(out).split('\n').filter((l) => /^\s*FAIL\b/.test(l)).some((l) => l.indexOf(label) !== -1)
263
+ let probeBad = 0
264
+ const cases = [
265
+ { face: 'numeric', env: 'MATH_COMPUTATION_MODULE', file: 'vibe-math-v2/math-computation.js', from: 'runId: runId, attempt: attempt,', to: 'runIdX: runId, attempt: attempt,', label: 'engine-faces numeric', engines: [PY, RC] },
266
+ { face: 'lean', env: 'V4_PLUGIN', file: 'vibe-math-v4/vibe-math-v4.js', from: 'if(norm!==root&&norm.indexOf(root+\'/\')!==0) return null', to: 'if(false) return null', label: 'engine-faces lean', engines: [LEAN] },
267
+ { face: 'lean-known-install', env: 'V4_PLUGIN', file: 'vibe-math-v4/vibe-math-v4.js', from: "\n if (p) return { exe: p, via: 'known-install', tried, name }", to: "\n if (p) return { exe: p, via: 'path', tried, name }", label: 'the KNOWN-LOCATION fallback resolves and reports via=known-install', engines: [LEAN] },
268
+ { face: 'lean-tried-list', env: 'V4_PLUGIN', file: 'vibe-math-v4/vibe-math-v4.js', from: 'tried.push(p)', to: 'void 0', label: 'an explicit command is NEVER guessed away', engines: [LEAN] },
269
+ { face: 'latex', env: 'V5_PLUGIN', file: 'vibe-math-v5/vibe-math-v5.js', from: 'ok: true, started: true, id: p.id,', to: 'ok: false, started: true, id: p.id,', label: 'engine-faces latex', engines: [XELATEX] },
270
+ ]
271
+ for (const c of cases) {
272
+ if (!c.engines.some(Boolean)) { console.log('SELF-PROBE SKIP (' + c.face + '): the engine is absent, so the mutant cannot be exercised'); continue }
273
+ const src = readFileSync(join(REPO, c.file), 'utf8')
274
+ if (src.indexOf(c.from) === -1) { console.log('SELF-PROBE FAIL (' + c.face + '): anchor missing: ' + c.from); probeBad++; continue }
275
+ // Copy the WHOLE source directory: the module/preset imports its siblings (math-engines.js,
276
+ // math-computation.js, …), so a bare copy in a temp dir would crash instead of reddening.
277
+ const dirRoot = mkdtempSync(join(tmpdir(), 'engine-mut-' + c.face + '-'))
278
+ const dir = join(dirRoot, c.file.split('/')[0])
279
+ cpSync(join(REPO, c.file.split('/')[0]), dir, { recursive: true })
280
+ const dst = join(dir, c.file.split('/').pop())
281
+ writeFileSync(dst, src.replace(c.from, c.to), 'utf8')
282
+ const r = child({ [c.env]: dst })
283
+ const out = String(r.stdout || '') + String(r.stderr || '')
284
+ const named = namedIn(out)(c.label) && r.status !== 0
285
+ console.log((named ? 'SELF-PROBE PASS' : 'SELF-PROBE FAIL') + ': the one-site ' + c.face + ' mutant reddens its named assertion')
286
+ if (!named) for (const l of out.split('\n').filter((l) => /^\s*FAIL\b/.test(l)).slice(0, 3)) console.log(' child FAIL line: ' + l.trim().slice(0, 140))
287
+ if (!named) console.log(' child exit=' + r.status + ' tail=' + String(out).trim().split('\n').slice(-3).join(' | ').slice(0, 220))
288
+ if (!named) probeBad++
289
+ rmSync(dirRoot, { recursive: true, force: true })
290
+ }
291
+ console.log('')
292
+ console.log('=== ENGINE FACES SELF-PROBE: ' + (cases.length - probeBad) + '/' + cases.length + ' as required ===')
293
+ process.exit(probeBad === 0 ? 0 : 1)
294
+ }
295
+ console.log('')
296
+ console.log('=== ENGINE FACES: ' + passed + ' passed, ' + failed + ' failed, ' + skips.length + ' skipped ===')
297
+ for (const s of skips) console.log(' SKIPPED -> ' + s)
298
+ if (failed) { for (const f of failures) console.error(' - ' + f); process.exit(1) }