mirror of
https://github.com/ruvnet/RuView
synced 2026-07-31 18:51:42 +00:00
90b29595fb
Adds the accepted ADR-285 Homecore metaharness, WASM-first kernel, read-only MCP guidance, guarded local host adapters, reviewed memory, and provenance-only npm release gates.
86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
// SPDX-License-Identifier: MIT
|
|
// Prefer the packaged WebAssembly kernel while retaining an honest fallback.
|
|
|
|
import { readFileSync } from 'node:fs';
|
|
import { loadKernel } from '@metaharness/kernel';
|
|
|
|
const PKG = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
const MCP_SPEC = Object.freeze({
|
|
name: 'homecore',
|
|
command: ['npx', '-y', `${PKG.name}@${PKG.version}`, 'mcp', 'start'],
|
|
});
|
|
|
|
let cached;
|
|
let loading;
|
|
|
|
/**
|
|
* Load the metaharness kernel with WASM as the default requested backend.
|
|
* An explicit METAHARNESS_KERNEL_BACKEND value remains authoritative.
|
|
*/
|
|
export async function loadHomecoreKernel() {
|
|
if (cached) return cached;
|
|
if (loading) return loading;
|
|
loading = initializeKernel();
|
|
try {
|
|
cached = await loading;
|
|
return cached;
|
|
} finally {
|
|
loading = undefined;
|
|
}
|
|
}
|
|
|
|
async function initializeKernel() {
|
|
const explicit = process.env.METAHARNESS_KERNEL_BACKEND;
|
|
if (explicit) {
|
|
return Object.freeze({
|
|
...await loadKernel(),
|
|
homecoreRequestedBackend: explicit,
|
|
});
|
|
}
|
|
|
|
process.env.METAHARNESS_KERNEL_BACKEND = 'wasm';
|
|
try {
|
|
return Object.freeze({
|
|
...await loadKernel(),
|
|
homecoreRequestedBackend: 'wasm',
|
|
});
|
|
} catch (wasmError) {
|
|
delete process.env.METAHARNESS_KERNEL_BACKEND;
|
|
const fallback = await loadKernel();
|
|
return Object.freeze({
|
|
...fallback,
|
|
homecoreRequestedBackend: 'wasm',
|
|
wasmFallbackReason: wasmError instanceof Error ? wasmError.message : String(wasmError),
|
|
});
|
|
} finally {
|
|
if (explicit === undefined) delete process.env.METAHARNESS_KERNEL_BACKEND;
|
|
else process.env.METAHARNESS_KERNEL_BACKEND = explicit;
|
|
}
|
|
}
|
|
|
|
export async function getKernelStatus({ strict = false } = {}) {
|
|
const kernel = await loadHomecoreKernel();
|
|
const info = kernel.kernelInfo();
|
|
const validationError = kernel.mcpValidate(JSON.stringify(MCP_SPEC));
|
|
const wasm = kernel.backend === 'wasm';
|
|
const requestedBackend = kernel.homecoreRequestedBackend || 'wasm';
|
|
return {
|
|
ok: validationError === null && (!strict || wasm),
|
|
preferredBackend: 'wasm',
|
|
requestedBackend,
|
|
resolvedBackend: kernel.backend,
|
|
strict,
|
|
info,
|
|
mcpSpec: MCP_SPEC,
|
|
mcpValidation: validationError,
|
|
fallbackReason: kernel.wasmFallbackReason || null,
|
|
note: wasm
|
|
? 'The packaged WebAssembly kernel is active.'
|
|
: requestedBackend === 'wasm'
|
|
? `WASM was unavailable; the reported ${kernel.backend} fallback backend is active.`
|
|
: `The operator explicitly requested ${requestedBackend}; the reported ${kernel.backend} backend is active.`,
|
|
};
|
|
}
|
|
|
|
export { MCP_SPEC };
|