()
| 142 | * `kernelAvailable()` / `tryKernelExtract()` which check it per call. |
| 143 | */ |
| 144 | export function getKernel(): KernelModule | null { |
| 145 | if (cached !== undefined) return cached; |
| 146 | cached = null; |
| 147 | for (const candidate of candidatePaths()) { |
| 148 | try { |
| 149 | if (!fs.existsSync(candidate)) continue; |
| 150 | // createRequire: works identically from CJS output and future ESM. |
| 151 | const req = createRequire(__filename); |
| 152 | const mod = req(candidate) as KernelModule; |
| 153 | if (typeof mod.extractFile !== 'function' || typeof mod.contractInfo !== 'function') { |
| 154 | debug(`${candidate}: missing expected exports — ignoring`); |
| 155 | continue; |
| 156 | } |
| 157 | if (!verifyContract(mod, candidate)) continue; |
| 158 | kernelLanguages = new Set(mod.contractInfo().languages); |
| 159 | debug(`loaded ${candidate} (languages: ${[...kernelLanguages].join(', ')})`); |
| 160 | cached = mod; |
| 161 | break; |
| 162 | } catch (err) { |
| 163 | debug(`${candidate}: failed to load — ${err instanceof Error ? err.message : String(err)}`); |
| 164 | } |
| 165 | } |
| 166 | return cached; |
| 167 | } |
| 168 | |
| 169 | /** True when the kill switch is off, a verified binary is loaded, and it supports `language`. */ |
| 170 | export function kernelSupports(language: string): boolean { |
no test coverage detected