// Fifth Domain private host projection. One world runtime root per physical host. import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; import { pathToFileURL } from 'node:url'; export const WORLD_RUNTIME_ROOT = process.platform === 'darwin' ? '/Volumes/JZAO/铸渊-ICE-GL-ZY001/CODEX-DEV-20260915/光湖语言世界' : process.platform === 'linux' ? '/opt/guanghu/glw-2.0/current' : (() => { throw new Error('GLW2_WORLD_ROOT_HOST_UNREGISTERED'); })(); const pointer = JSON.parse(fs.readFileSync(path.join(WORLD_RUNTIME_ROOT, 'CURRENT-WORLD.json'), 'utf8')); if (pointer.world_id !== 'GLW-2.0-0001' || !String(pointer.state || '').startsWith('CURRENT_')) throw new Error('GLW2_WORLD_POINTER_INVALID'); const source = path.join(WORLD_RUNTIME_ROOT, pointer.world_root_source); const gir = path.join(WORLD_RUNTIME_ROOT, pointer.world_root_gir); if (JSON.parse(fs.readFileSync(gir, 'utf8')).compiled_from?.source_sha256 !== crypto.createHash('sha256').update(fs.readFileSync(source)).digest('hex')) throw new Error('GLW2_WORLD_ROOT_SOURCE_HASH_MISMATCH'); export function worldRuntimeUrl(filename) { if (!/^[A-Za-z0-9.-]+\.mjs$/.test(filename)) throw new Error('WORLD_RUNTIME_MODULE_NOT_REGISTERED'); const file = path.join(WORLD_RUNTIME_ROOT, '运行时', filename); if (!fs.existsSync(file) || fs.lstatSync(file).isSymbolicLink()) throw new Error('WORLD_RUNTIME_MODULE_MISSING_OR_SYMLINK'); return pathToFileURL(file).href; }