Repository navigation
Expand file tree
/
Copy pathmath.ts
More file actions
103 lines (101 loc) · 4.78 KB
/
Copy pathmath.ts
File metadata and controls
103 lines (101 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bun
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { spawn } from 'node:child_process';
import os from 'node:os';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
export const agentToolCommands = {
'check-lean': 'scripts/mathematics/checkLean.ts',
'search-lean': 'scripts/mathematics/searchLean.ts',
declarations: 'scripts/mathematics/readDeclarations.ts',
knowledge: 'scripts/mathematics/theoremKnowledge.ts',
hub: 'scripts/mathematics/huggingMath.ts',
checkpoint: 'scripts/mathematics/checkpoint.ts',
'check-finite': 'scripts/mathematics/checkFinite.ts',
'kernel-certificate': 'scripts/mathematics/kernelCertificate.ts',
library: 'scripts/mathematics/library.ts',
continuation: 'scripts/mathematics/readContinuation.ts',
} as const;
const commands: Readonly<Record<string, string>> = {
...agentToolCommands,
build: 'scripts/build.ts',
doctor: 'scripts/mathematics/doctor.ts',
example: 'scripts/mathematics/runExample.ts',
run: 'out/main/math-solver.js',
batch: 'scripts/mathematics/runMathBatch.ts',
'bootstrap-lean-task': 'scripts/mathematics/bootstrapLeanTask.ts',
'bootstrap-imo': 'scripts/mathematics/bootstrapImo2026.ts',
'bootstrap-lean-eval': 'scripts/mathematics/bootstrapLeanEvalHeldOut.ts',
'list-lean-eval': 'scripts/mathematics/listLeanEval.ts',
'freeze-retrieval': 'scripts/mathematics/freezeMathRetrievalCorpus.ts',
'library-pack': 'scripts/mathematics/libraryPack.ts',
'library-catalog': 'scripts/mathematics/libraryCatalog.ts',
'auto-library': 'scripts/mathematics/autoLibrary.ts',
'continuation-seed': 'scripts/mathematics/seedContinuation.ts',
inspect: 'scripts/mathematics/inspectMathRun.ts',
recover: 'scripts/mathematics/recoverMathSnapshot.ts',
edit: 'scripts/mathematics/editMathRun.ts',
compare: 'scripts/mathematics/compareMathRuns.ts',
'sample-putnam': 'scripts/mathematics/samplePutnamRuns.ts',
'first-proof': 'scripts/mathematics/firstProof.ts',
formalize: 'scripts/mathematics/formalize.ts',
informalize: 'scripts/mathematics/informalize.ts',
'evaluate-formalization': 'scripts/mathematics/evaluateFormalization.ts',
summarize: 'scripts/mathematics/summarizeMathProofRuns.ts',
};
if (import.meta.main) runCli();
function runCli() {
const [command, ...args] = process.argv.slice(2);
if (args.length === 1 && args[0] === '-h') args[0] = '--help';
const runHelp = command === 'run' && args.length === 1 && args[0] === '--help';
const missingBundle = command === 'run' && !fs.existsSync(path.join(root, commands.run));
if (!command || ['help', '--help', '-h'].includes(command)) {
process.stdout.write(fs.readFileSync(path.join(root, 'bin/math-help.txt')));
} else if (!Object.hasOwn(commands, command)) {
console.error(`Unknown command: ${command}. Run theorem-os --help to list commands.`);
process.exitCode = 1;
} else if (missingBundle && !runHelp) {
console.error('Solver bundle not found. From the checkout, run bun run build, then retry theorem-os run.');
process.exitCode = 1;
} else {
// Only help may use the source entry; proof runs require the frozen bundle.
const bundledSeed = command === 'continuation-seed' && fs.existsSync(path.join(root, commands.run));
let entry = path.join(
root,
bundledSeed ? commands.run : missingBundle ? 'scripts/mathematics/runMathProof.ts' : commands[command]!,
);
const tools = path.join(root, 'out/main/agent-tools');
if (Object.hasOwn(agentToolCommands, command) && fs.existsSync(tools)) {
entry = path.join(tools, `${command}.mjs`);
} else if (command === 'check-lean' || command === 'search-lean') {
const legacy = path.join(root, 'out/main', `${command}.js`);
if (fs.existsSync(legacy)) entry = legacy;
}
if (bundledSeed) args.unshift('--theoremos-continuation-seed');
const env = {
...process.env,
CODEX_HOME: process.env.CODEX_HOME || path.join(os.homedir(), '.config', 'deepscientist', 'math-sol-codex'),
};
// Argument arrays preserve literal task/evaluator arguments without a shell.
const child = spawn(process.execPath, [entry, ...args], {
cwd: process.cwd(),
env,
stdio: 'inherit',
});
const forward = (signal: NodeJS.Signals) => child.kill(signal);
const interrupt = () => forward('SIGINT');
const terminate = () => forward('SIGTERM');
process.on('SIGINT', interrupt);
process.on('SIGTERM', terminate);
child.once('error', error => {
console.error(error.message);
process.exitCode = 1;
});
child.once('exit', (code, signal) => {
process.removeListener('SIGINT', interrupt);
process.removeListener('SIGTERM', terminate);
process.exitCode = code ?? (signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 1);
});
}
}