import { parseArgs } from "node:util"; import { loadConfig } from "../../src/config/index.ts"; import { runStudy } from "../../src/flow/index.ts"; // 起研究的命令行入口:像用户一样给配置、指定研究目录、调 runStudy,按 Ctrl-C(SIGINT)时发"停下"信号。 // 新研究:node eval/lib/cli.ts --config --dir <研究目录> // 接着跑:node eval/lib/cli.ts --resume --dir <研究目录>(配置写 null,以账本里冻结的那份为准) // 结局打印成一行 "RESULT ",检验脚本按这一行读。 const { values } = parseArgs({ options: { config: { type: "string" }, resume: { type: "boolean" }, dir: { type: "string" } }, strict: true, }); if (values.dir === undefined) throw new Error("要写 --dir <研究目录>"); if ((values.config === undefined) === (values.resume !== true)) { throw new Error("--config 和 --resume 二选一,必须写一个"); } const config = values.config === undefined ? null : loadConfig(values.config); const stop = new AbortController(); process.on("SIGINT", () => { console.error("收到 SIGINT,发停下信号"); stop.abort(); }); const outcome = await runStudy({ studyDir: values.dir, config, stop: stop.signal }); console.log(`RESULT ${JSON.stringify(outcome)}`);