MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getKernel

Function getKernel

src/extraction/kernel/loader.ts:148–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Calls 6

candidatePathsFunction · 0.85
reqFunction · 0.85
verifyContractFunction · 0.85
contractInfoMethod · 0.80
debugFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected