mirror of
https://github.com/ruvnet/RuView
synced 2026-07-31 18:51:42 +00:00
1b220c8d53
Mints a real MetaHarness (via vendor/metaharness's published `npx metaharness analyze --scaffold`, template vertical:coding, host claude-code) for the wifi-densepose-sar crate: architect/implementer/ reviewer/test-writer agents, doctor/review-diff commands, MCP server, Claude Code plugin -- following the same pattern as harness/ruview/ (ADR-182) and harness/homecore/ (ADR-285). Adds real wiring for the three pieces this was scoped around: - Darwin Mode (@metaharness/darwin) -- wired by the scaffold itself (npm run evolve / evolve:dry). - Router (@metaharness/router) -- src/router.ts, a real k-NN cost-optimal Router over two example model tiers. Its labelled examples are illustrative seed data (see the file's honesty note), not measured eval-log observations; the routing mechanism itself is real and tested. - Flywheel (@metaharness/flywheel) -- src/flywheel.ts, the real propose/evaluate/gate/promote loop wired with a SYNTHETIC proposer and evaluator (dataSource: 'SYNTHETIC', no model call). Proves the wiring end-to-end: a real signed, independently-replayable lineage, promoting each generation once the evaluator's noopRate actually moves (the default gate requires it to strictly improve -- a constant noopRate, even a "good" one, blocks every promotion forever, which the first version of this evaluator hit and the final version fixes). 14/14 tests pass (5 router + 5 flywheel + 4 install-smoke), `npm run build` clean under strict TypeScript, CLI commands (route, flywheel) verified manually. `.harness/manifest.json` is stale relative to the router/flywheel additions -- this scaffold has no manifest:update script (unlike harness/homecore/); documented as a known gap in the harness's own README.
157 lines
6.3 KiB
JavaScript
157 lines
6.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// SPDX-License-Identifier: MIT
|
|
// Generated by metaharness — the `wifi-densepose-sar-harness` CLI entry point.
|
|
//
|
|
// This is plain ESM JavaScript on purpose: it runs as-is via `npx wifi-densepose-sar-harness`
|
|
// with NO build step. `npm run build` (tsc) is only needed if you extend the
|
|
// TypeScript in src/. The published package ships this file directly (see the
|
|
// "bin" + "files" fields in package.json), so `npx wifi-densepose-sar-harness` works the moment
|
|
// `npm install` has resolved @metaharness/kernel + @metaharness/host-claude-code.
|
|
|
|
import { loadKernel } from '@metaharness/kernel';
|
|
import adapter from '@metaharness/host-claude-code';
|
|
|
|
const HARNESS_NAME = 'wifi-densepose-sar-harness';
|
|
|
|
/** `wifi-densepose-sar-harness init` — boot the kernel + host adapter and report status. */
|
|
async function init() {
|
|
const kernel = await loadKernel();
|
|
const info = kernel.kernelInfo();
|
|
console.log(`${HARNESS_NAME} — kernel ${info.version} (${kernel.backend})`);
|
|
console.log(`Host adapter: ${adapter.name}`);
|
|
console.log(`Run \`${HARNESS_NAME} doctor\` to verify the install.`);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* `wifi-densepose-sar-harness route <e0> <e1> <e2> <e3>` — route a 4-axis
|
|
* task embedding to the cost-optimal model tier via @metaharness/router.
|
|
* Needs `npm run build` first (src/router.ts is TypeScript; this command
|
|
* imports the compiled dist/ output so the base CLI stays build-free).
|
|
*/
|
|
async function route(args) {
|
|
const embedding = args.map(Number);
|
|
if (embedding.length !== 4 || embedding.some((n) => Number.isNaN(n))) {
|
|
console.error('Usage: wifi-densepose-sar-harness route <physicsExplanation> <codeReview> <numericalDebugging> <docWriting> (four 0..1 numbers)');
|
|
return 2;
|
|
}
|
|
let routeSarQuery;
|
|
try {
|
|
({ routeSarQuery } = await import('../dist/router.js'));
|
|
} catch (err) {
|
|
console.error(`route: dist/router.js not found — run \`npm run build\` first. (${err.message})`);
|
|
return 1;
|
|
}
|
|
const pick = routeSarQuery(embedding);
|
|
console.log(`route -> ${pick.id} (predicted quality ${pick.predictedQuality.toFixed(3)}, $${pick.costPerMTok}/MTok, met bar: ${pick.metBar})`);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* `wifi-densepose-sar-harness flywheel [generations]` — run the SYNTHETIC
|
|
* @metaharness/flywheel demo (see src/flywheel.ts) and print the lift curve
|
|
* + an independent replay-bundle verification. Needs `npm run build` first.
|
|
*/
|
|
async function flywheel(args) {
|
|
const generations = args[0] ? Number(args[0]) : 3;
|
|
if (Number.isNaN(generations) || generations < 1) {
|
|
console.error('Usage: wifi-densepose-sar-harness flywheel [generations>=1]');
|
|
return 2;
|
|
}
|
|
let runSarFlywheelDemo, verifySarFlywheelDemo;
|
|
try {
|
|
({ runSarFlywheelDemo, verifySarFlywheelDemo } = await import('../dist/flywheel.js'));
|
|
} catch (err) {
|
|
console.error(`flywheel: dist/flywheel.js not found — run \`npm run build\` first. (${err.message})`);
|
|
return 1;
|
|
}
|
|
console.log(`Running ${generations}-generation flywheel demo (dataSource: SYNTHETIC — see src/flywheel.ts)...`);
|
|
const result = await runSarFlywheelDemo(generations);
|
|
for (const point of result.liftCurve) {
|
|
console.log(` gen ${point.generation}: primary=${point.primary.toFixed(3)} delta=${point.delta.toFixed(3)} anchor=${point.anchor ?? 'n/a'}`);
|
|
}
|
|
const verdict = verifySarFlywheelDemo(result);
|
|
console.log(`generations run: ${result.generationsRun} · promotions: ${result.promotions.length} · replay verified: ${verdict.pass}`);
|
|
return verdict.pass ? 0 : 1;
|
|
}
|
|
|
|
/** `wifi-densepose-sar-harness doctor` — verify the install end-to-end (kernel + host resolve). */
|
|
async function doctor() {
|
|
const kernel = await loadKernel();
|
|
const info = kernel.kernelInfo();
|
|
const checks = [
|
|
['kernel loads', !!kernel],
|
|
['kernel reports a version', typeof info.version === 'string' && info.version.length > 0],
|
|
['kernel backend is native|wasm|js', ['native', 'wasm', 'js'].includes(kernel.backend)],
|
|
['host adapter has a name', typeof adapter?.name === 'string' && adapter.name.length > 0],
|
|
];
|
|
let ok = true;
|
|
for (const [label, pass] of checks) {
|
|
console.log(`${pass ? 'PASS' : 'FAIL'} ${label}`);
|
|
if (!pass) ok = false;
|
|
}
|
|
console.log(
|
|
ok
|
|
? `\n${HARNESS_NAME}: all checks passed (kernel ${info.version}, ${kernel.backend} backend, host ${adapter.name})`
|
|
: `\n${HARNESS_NAME}: doctor found problems`,
|
|
);
|
|
return ok ? 0 : 1;
|
|
}
|
|
|
|
/**
|
|
* Dispatch one CLI invocation. Exported (not just run on import) so a test can
|
|
* drive it without spawning a subprocess. Returns the intended exit code.
|
|
*/
|
|
export async function run(argv) {
|
|
const cmd = argv[0] ?? 'init';
|
|
switch (cmd) {
|
|
case 'init':
|
|
return init();
|
|
case 'doctor':
|
|
return doctor();
|
|
case 'route':
|
|
return route(argv.slice(1));
|
|
case 'flywheel':
|
|
return flywheel(argv.slice(1));
|
|
case '--version':
|
|
case '-v': {
|
|
const kernel = await loadKernel();
|
|
console.log(kernel.version());
|
|
return 0;
|
|
}
|
|
case '--help':
|
|
case '-h':
|
|
console.log(`Usage: ${HARNESS_NAME} <command>\n\n init boot the kernel + host adapter (default)\n doctor verify the install end-to-end\n route route a 4-axis task embedding to a cost-optimal model tier (needs \`npm run build\`)\n flywheel run the SYNTHETIC self-improvement demo loop (needs \`npm run build\`)\n --version print the kernel version`);
|
|
return 0;
|
|
default:
|
|
console.error(`Unknown command: ${cmd}. Try \`${HARNESS_NAME} --help\`.`);
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
// CLI guard: execute only when invoked directly (not when imported by a test).
|
|
// npm's bin shims pass a NON-normalized argv[1] (e.g. ".../.bin/../<pkg>/bin/cli.js"
|
|
// on Windows) and may differ in case, so realpath BOTH sides before comparing —
|
|
// a naive string === misses the npx/shim path and the CLI silently no-ops.
|
|
import { fileURLToPath } from 'node:url';
|
|
import { realpathSync } from 'node:fs';
|
|
import { argv } from 'node:process';
|
|
const invokedDirectly = (() => {
|
|
if (!argv[1]) return false;
|
|
try {
|
|
const a = realpathSync(argv[1]);
|
|
const b = realpathSync(fileURLToPath(import.meta.url));
|
|
return process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
} catch {
|
|
return false;
|
|
}
|
|
})();
|
|
if (invokedDirectly) {
|
|
run(argv.slice(2))
|
|
.then((code) => process.exit(code))
|
|
.catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
}
|