// Fetch the transitive closure of OAI.* imports starting from FixedBase (reading files only). const fs = require("fs"), path = require("path"), { execFileSync } = require("child_process"); const C = "3344da59991ed94f9ba711217b29c1d760badfa6"; const root = process.argv[2]; const seen = new Set(), queue = ["OAI.Combinatorics.Sunflower.FixedBase"]; let lines = 0; const bad = []; const external = new Set(); while (queue.length) { const mod = queue.shift(); if (seen.has(mod)) continue; seen.add(mod); const rel = mod.split(".").join("/") + ".lean"; const local = path.join(root, rel); if (!fs.existsSync(local)) { fs.mkdirSync(path.dirname(local), { recursive: true }); execFileSync("curl", ["-sS", "--max-time", "60", "-o", local, `https://raw.githubusercontent.com/openai/math/${C}/lean/${rel}`]); } const src = fs.readFileSync(local, "utf8"); lines += src.split("\n").length; if (src.startsWith("404")) { bad.push(mod + ": 404"); continue; } src.split("\n").forEach((l, i) => { if (/\bsorry\b|\badmit\b|^\s*axiom\b|native_decide|implemented_by|@\[extern|\bunsafe\b|ofReduceBool|trustCompiler|#eval|run_cmd|^\s*elab |^\s*initialize/.test(l)) bad.push(`${mod}:${i + 1}: ${l.trim()}`); const m = l.match(/^import\s+(\S+)/); if (m) { if (m[1].startsWith("OAI.")) queue.push(m[1]); else external.add(m[1].split(".")[0]); } }); } console.log("modules in closure:", seen.size, "lines:", lines); console.log("external import roots:", [...external].join(", ")); console.log("flagged:", bad.length ? "\n" + bad.join("\n") : "none");