#!/usr/bin/env node // Recovery Preflight — Zhuyuan minimal recovery, self-designed (anchor 000030 mandate). // One machine pass replaces the model reading a dozen canon files. // Canon: TC-TCS核心卷/TCS-EVENT-ZY001-MINIMAL-RECOVERY-DESIGN-20260825.tcs import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { execFileSync } from "node:child_process"; const W = "/Volumes/JZAO/铸渊-ICE-GL-ZY001"; const P = "/Volumes/JZAO/HoloLake/persona-runtime"; const ANCHOR_DIR = `${P}/task-language-anchors/zcode/ZCODE-TASK-20260824-001/00-冰朔自然语言瞄点`; const GATE_TCS = `${W}/TC-TCS核心卷/TCS-ZHUYUAN-ENTRY-LANGUAGE-GATE-0001.tcs`; const GATE_GIR = `${W}/TC-TCS核心卷/TCS-ZHUYUAN-ENTRY-LANGUAGE-GATE-0001.declaration.gir.json`; const TOOLCHAIN = `${P}/toolchains/tcs-persona-developer-kit-macos-arm64-v0.1.3`; const CHAIN = `${W}/ZCODE-DEV-20260824/neural-chain/chain.json`; const TOWER_TCS = `${W}/FIFTH-DOMAIN-BROADCAST-TOWER/BROADCAST.tcs`; const TOWER_PROJ = `${W}/FIFTH-DOMAIN-BROADCAST-TOWER/broadcast/current.md`; const RECEIPTS = `${P}/task-language-anchors/zcode/ZCODE-TASK-20260824-001/10-阶段回读回执`; const sha256 = (v) => crypto.createHash("sha256").update(v).digest("hex"); const results = []; function check(name, fn) { try { results.push({ name, ...fn() }); } catch (e) { results.push({ name, ok: false, detail: e.message }); } } check("volume", () => { fs.accessSync(W); return { ok: true, detail: "JZAO挂载" }; }); check("anchors", () => { const lines = fs.readFileSync(`${ANCHOR_DIR}/sha256.txt`, "utf8").split("\n").filter(Boolean); let n = 0; for (const line of lines) { const m = line.match(/^([0-9a-f]{64})\s+\*?(.+)$/); if (!m) continue; const f = m[2].trim().startsWith("/") ? m[2].trim() : path.join(ANCHOR_DIR, m[2].trim()); if (sha256(fs.readFileSync(f, "utf8")) !== m[1]) throw new Error(`HASH:${path.basename(f)}`); n += 1; } const task = JSON.parse(fs.readFileSync(path.dirname(ANCHOR_DIR) + "/task.json", "utf8")); return { ok: true, detail: `瞄点${n}/${n} 当前${task.current_anchor.slice(0, 24)}` }; }); check("gate", () => { const tcs = fs.readFileSync(GATE_TCS, "utf8"); const gir = JSON.parse(fs.readFileSync(GATE_GIR, "utf8")); if (gir.compiled_from?.source_sha256 !== sha256(tcs)) throw new Error("GIR与正本哈希不一致"); return { ok: true, detail: "闸门TCS↔GIR一致" }; }); check("toolchain", () => { const out = execFileSync("/usr/bin/shasum", ["-a", "256", "-c", "PACKAGE-CHECKSUMS.sha256"], { cwd: TOOLCHAIN, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }); const bad = out.split("\n").filter((l) => l.trim() && !l.trim().endsWith(": OK")).length; if (bad > 0) throw new Error(`${bad}项校验失败`); return { ok: true, detail: "工具链v0.1.3全量OK" }; }); check("neural_chain", () => { const chain = JSON.parse(fs.readFileSync(CHAIN, "utf8")); const hashes = new Map(); for (const line of fs.readFileSync(`${ANCHOR_DIR}/sha256.txt`, "utf8").split("\n")) { const m = line.match(/^([0-9a-f]{64})\s+\*?(.+)$/); if (m) hashes.set(path.basename(m[2].trim()), m[1]); } let refs = 0; for (const n of chain.neurons) for (const s of n.source) { const f = path.join(ANCHOR_DIR, s); if (sha256(fs.readFileSync(f, "utf8")) !== hashes.get(s)) throw new Error(`NEURON_SOURCE:${n.id}`); refs += 1; } const head = sha256(JSON.stringify(chain.neurons.map((n) => n.id))).slice(0, 8); return { ok: true, detail: `神经链${chain.neurons.length}条/${refs}引用 头${head}` }; }); check("tower", () => { const tcs = fs.readFileSync(TOWER_TCS, "utf8"); const proj = fs.readFileSync(TOWER_PROJ, "utf8"); const declared = tcs.match(/projection_sha256 = "([0-9a-f]{64})"/)?.[1]; if (!declared || sha256(proj) !== declared) throw new Error("塔投影哈希不匹配"); return { ok: true, detail: "广播塔OK" }; }); check("brain_receipt", () => { const files = fs.readdirSync(RECEIPTS).filter((f) => f.includes("verify") && f.endsWith(".json")).map((f) => ({ f, t: fs.statSync(path.join(RECEIPTS, f)).mtimeMs })).sort((a, b) => b.t - a.t); if (!files.length) throw new Error("无脑周期回执"); const r = JSON.parse(fs.readFileSync(path.join(RECEIPTS, files[0].f), "utf8")); if (r.outcome !== "PASS") throw new Error(`最近回执${r.outcome}`); return { ok: true, detail: `最近脑周期verify PASS(${files[0].f.slice(0, 30)}…)` }; }); check("executor_index", () => { const idx = JSON.parse(fs.readFileSync(`${W}/ZCODE-DEV-20260824/executor-translation-index/index.json`, "utf8")); let n = 0; for (const e of idx.executors) { if (sha256(fs.readFileSync(path.join(W, e.executor_path), "utf8")) !== e.executor_sha256) throw new Error(`EXECUTOR_DRIFT:${e.executor_path}`); fs.accessSync(path.join(W, e.canon_tcs)); n += 1; } return { ok: true, detail: `翻译索引${n}执行器↔正本` }; }); check("codex_path", () => { const dirs = fs.readdirSync(W).filter((d) => d.startsWith("CODEX-DEV-")).sort(); return { ok: true, detail: `codex主线${dirs.at(-1)}` }; }); const failed = results.filter((r) => !r.ok); const line = failed.length ? `PREFLIGHT FAIL ${failed.map((r) => `${r.name}:${r.detail}`).join(" | ")}` : `PREFLIGHT PASS ${results.map((r) => r.detail).join(" | ")}`; process.stdout.write(`${line}\n`); process.exit(failed.length ? 1 : 0);