Repository navigation
Expand file tree
/
Copy pathmath.ts
More file actions
125 lines (122 loc) · 6.89 KB
/
Copy pathmath.ts
File metadata and controls
125 lines (122 loc) · 6.89 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/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)), '..');
const commands: Readonly<Record<string, string>> = {
build: 'scripts/build.ts',
doctor: 'scripts/mathematics/doctor.ts',
example: 'scripts/mathematics/runExample.ts',
component: 'scripts/mathematics/component.ts',
run: 'out/main/math-solver.js',
batch: 'scripts/mathematics/runMathBatch.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',
'search-lean': fs.existsSync(path.join(root, 'out/main/search-lean.js'))
? 'out/main/search-lean.js'
: 'scripts/mathematics/searchLean.ts',
declarations: 'scripts/mathematics/readDeclarations.ts',
knowledge: 'scripts/mathematics/theoremKnowledge.ts',
hub: 'scripts/mathematics/huggingMath.ts',
'check-lean': 'scripts/mathematics/checkLean.ts',
checkpoint: 'scripts/mathematics/checkpoint.ts',
'plan-validate': 'scripts/mathematics/planValidate.ts',
'check-finite': 'scripts/mathematics/checkFinite.ts',
'kernel-certificate': 'scripts/mathematics/kernelCertificate.ts',
'library-pack': 'scripts/mathematics/libraryPack.ts',
'library-catalog': 'scripts/mathematics/libraryCatalog.ts',
library: 'scripts/mathematics/library.ts',
'auto-library': 'scripts/mathematics/autoLibrary.ts',
continuation: 'scripts/mathematics/readContinuation.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',
};
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)) {
console.log(`theorem-os <command> [arguments]
build Freeze mathematical sources and build the solver
doctor Check local tools, login and sandbox permissions
example Replay or solve a small Lean tutorial without Mathlib
component Create and check a replaceable search component
run Run or resume an isolated mathematics proof (optional --portfolio-exploration)
batch Run prepared problems concurrently in separate processes
bootstrap-imo Prepare an IMO2026 proof workspace
bootstrap-lean-eval Prepare a public Lean-Eval workspace
list-lean-eval List V1 obligations and public formalization gap warnings
freeze-retrieval Freeze allowed local Lean declaration sources
search-lean Find declarations in verified local Lean packages
declarations Search saved owned declarations with bounded type previews
knowledge Build and query previously checked theorem sources
hub Export frozen results and import private HuggingMath drafts
check-lean Check changed Lean files with bounded diagnostics
checkpoint Save the acknowledgment requested by the active host
plan-validate Check a cooperative Lead plan and report field-level issues
check-finite Replay finite Boolean constraints and return witnesses
kernel-certificate Generate chunked decide +kernel certificate modules
library-pack Extract checked run modules or backport upstream files as a frozen library
library-catalog Index versioned library releases and select only the modules a task needs
library Search the pinned release, inspect sources and request host installation
auto-library Plan, prove and publish the library modules a problem needs, before solving it
continuation Read or search frozen continuation attachments in bounded pages
continuation-seed Initialize a new prepared run from advisory sources and fresh helper checks
inspect Read a research report or export a versioned task plan
recover Restore a research snapshot and recheck saved helpers
edit Approve the exact version of a native team's initial route
compare Read and check saved comparison reports
sample-putnam Read and check saved PutnamBench sample reports
first-proof Audit and prepare the First Proof Batch 3 Lean adaptation offline
formalize Formalize an informal problem and review its Lean statement
informalize Explain a checked Lean proof in natural language, step by step with audits
evaluate-formalization Prepare, review and score blind formalization candidates
summarize Summarize saved proof-run receipts
Use theorem-os <command> --help for command arguments.`);
} 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 entry = missingBundle ? 'scripts/mathematics/runMathProof.ts' : commands[command]!;
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, [path.join(root, 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);
});
}