mirror of
https://github.com/ruvnet/RuView.git
synced 2026-08-27 10:35:52 +00:00
Adds two new npm packages that expose RuView's WiFi-DensePose sensing capabilities outside the Cognitum appliance ecosystem: - tools/ruview-mcp/ (@ruv/ruview-mcp) — MCP server with 6 tools: ruview_csi_latest, ruview_pose_infer, ruview_count_infer, ruview_registry_list, ruview_train_count, ruview_job_status. Uses @modelcontextprotocol/sdk with stdio transport. 6/6 smoke tests pass. TypeScript strict mode, Node 20. - tools/ruview-cli/ (@ruv/ruview-cli) — Yargs CLI with matching subcommands: csi tail, pose infer, count infer, cogs list, train count, job status. Same fail-open pattern as the cog binaries (WARN to stderr, exit 0 on unavailable sensing-server). - docs/adr/ADR-104-ruview-mcp-cli-distribution.md — design rationale, 6-row threat table, packaging plan, acceptance gates, failure modes. - docs/research/sota-2026-05-22/HORIZON.md — 12-hour horizon plan with 7 milestones tracked (M1 complete in this commit). Both packages are private:true pending the user's publish decision. Inference is via subprocess to the signed cog binaries (ADR-100/101/103) — no JS/WASM ML engine bundled.
120 lines
3.2 KiB
TypeScript
120 lines
3.2 KiB
TypeScript
/**
|
|
* ruview train — Training commands.
|
|
*
|
|
* train count --paired <jsonl> — kick off a count-cog training run.
|
|
*/
|
|
|
|
import type { Argv } from "yargs";
|
|
import { randomUUID } from "node:crypto";
|
|
import { mkdirSync, appendFileSync, openSync } from "node:fs";
|
|
import path from "node:path";
|
|
import os from "node:os";
|
|
import { spawn } from "node:child_process";
|
|
import { loadConfig } from "../config.js";
|
|
|
|
export function trainCommand(cli: Argv): void {
|
|
cli.command(
|
|
"train <task>",
|
|
"Training commands",
|
|
(y) =>
|
|
y
|
|
.positional("task", {
|
|
choices: ["count"] as const,
|
|
description: "Which cog to train",
|
|
})
|
|
.option("paired", {
|
|
type: "string",
|
|
demandOption: true,
|
|
description:
|
|
"Path to the paired JSONL training file (produced by scripts/align-ground-truth.js)",
|
|
})
|
|
.option("epochs", {
|
|
type: "number",
|
|
default: 400,
|
|
description: "Training epochs (default: 400)",
|
|
})
|
|
.option("lr", {
|
|
type: "number",
|
|
default: 1e-3,
|
|
description: "Initial learning rate (default: 0.001)",
|
|
})
|
|
.option("output-dir", {
|
|
type: "string",
|
|
description: "Output directory for model artifacts",
|
|
}),
|
|
async (args) => {
|
|
const config = loadConfig();
|
|
const jobId = randomUUID();
|
|
const logDir = config.jobsDir;
|
|
mkdirSync(logDir, { recursive: true });
|
|
const logPath = path.join(logDir, `${jobId}.log`);
|
|
const queuedAt = Date.now() / 1000;
|
|
|
|
const outputDir =
|
|
(args["output-dir"] as string | undefined) ??
|
|
"v2/crates/cog-person-count/cog/artifacts";
|
|
|
|
const header = [
|
|
`# RuView training job ${jobId}`,
|
|
`# started: ${new Date().toISOString()}`,
|
|
`# task: ${args.task}`,
|
|
`# paired: ${args.paired}`,
|
|
`# epochs: ${args.epochs}`,
|
|
`# lr: ${args.lr}`,
|
|
`# output-dir: ${outputDir}`,
|
|
"",
|
|
].join("\n");
|
|
appendFileSync(logPath, header);
|
|
|
|
const logFdOut = openSync(logPath, "a");
|
|
const logFdErr = openSync(logPath, "a");
|
|
|
|
const cargoArgs = [
|
|
"run",
|
|
"--release",
|
|
"-p",
|
|
"wifi-densepose-train",
|
|
"--",
|
|
"--task",
|
|
"count",
|
|
"--paired",
|
|
args.paired as string,
|
|
"--epochs",
|
|
String(args.epochs),
|
|
"--lr",
|
|
String(args.lr),
|
|
"--output-dir",
|
|
outputDir,
|
|
];
|
|
|
|
const child = spawn("cargo", cargoArgs, {
|
|
detached: true,
|
|
stdio: ["ignore", logFdOut, logFdErr],
|
|
});
|
|
child.unref();
|
|
|
|
child.on("error", (e) => {
|
|
appendFileSync(logPath, `\n# ERROR: ${e.message}\n`);
|
|
});
|
|
child.on("close", (code) => {
|
|
appendFileSync(logPath, `\n# exit code: ${code}\n`);
|
|
});
|
|
|
|
process.stdout.write(
|
|
JSON.stringify(
|
|
{
|
|
ok: true,
|
|
job_id: jobId,
|
|
status: "running",
|
|
log_path: logPath,
|
|
queued_at: queuedAt,
|
|
note: `Poll with: ruview job status --id ${jobId}`,
|
|
},
|
|
null,
|
|
2
|
|
) + "\n"
|
|
);
|
|
}
|
|
);
|
|
}
|