Code Rooms
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import { spawnSync } from "node:child_process";
const root = path.resolve(new URL("..", import.meta.url).pathname);
const args = process.argv.slice(2);
function has(flag) {
return args.includes(flag);
}
function value(flag, fallback = undefined) {
const index = args.indexOf(flag);
if (index === -1) return fallback;
return args[index + 1] ?? fallback;
function run(command, commandArgs, options = {}) {
const result = spawnSync(command, commandArgs, {
cwd: options.cwd ?? root,
stdio: options.capture ? "pipe" : "inherit",
encoding: "utf8"
});
return result;
function commandExists(command) {
const result = spawnSync("sh", ["-lc", `command -v ${command}`], {
stdio: "pipe",
return result.status === 0 ? result.stdout.trim() : null;
function toolStatus(command) {
return commandExists(command) ? "available" : "missing";
function envStatus(name) {
return process.env[name] ? "set" : "unset";
function localHttpStatus(url) {
const result = spawnSync("curl", ["-fsS", "--max-time", "1", url], {
stdio: "ignore",
return result.status === 0 ? "available" : "missing";
function copyDir(src, dest) {
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
if (entry.name === ".DS_Store" || entry.name === "__pycache__") continue;
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) copyDir(srcPath, destPath);
else fs.copyFileSync(srcPath, destPath);
function printHelp() {
console.log(`
KOGNIT1V bootstrap
Default mode is a doctor/check only. External runtimes are explicit.
Commands:
--doctor print environment report
--doctor-tools print bundled/optional toolchain readiness
--install-skills copy skills/* into Codex skills directory
--codex-home <path> Codex home, defaults to $CODEX_HOME or ~/.codex
--with-m1nd check m1nd CLI/checkout readiness
--m1nd-path <path> existing m1nd checkout
--install-m1nd clone/install m1nd if needed
--m1nd-install-dir <path> default ~/.kognit1v/deps/m1nd
--build-m1nd-native run cargo build --release in m1nd checkout
Examples:
npm run bootstrap -- --doctor
npm run bootstrap -- --doctor-tools
npm run bootstrap -- --install-skills --codex-home "$CODEX_HOME"
npm run bootstrap -- --with-m1nd --m1nd-path /path/to/m1nd
npm run bootstrap -- --with-m1nd --install-m1nd
`);
if (has("--help") || has("-h")) {
printHelp();
process.exit(0);
const codexHomePath = value("--codex-home", process.env.CODEX_HOME || path.join(os.homedir(), ".codex"));
const codexHomeLabel = value("--codex-home")
? "<provided-codex-home>"
: process.env.CODEX_HOME
? "$CODEX_HOME"
: "~/.codex";
const report = {
id: "kognit1v.bootstrap.report",
repo: path.basename(root),
node: process.version,
codex_home: codexHomeLabel,
tools: {
bundled: {
skills: fs.readdirSync(path.join(root, "skills"), { withFileTypes: true }).filter((entry) => entry.isDirectory()).length,
contracts: fs.existsSync(path.join(root, "contracts")),
examples: fs.existsSync(path.join(root, "examples")),
validation_scripts: true
},
host: {
node: "available",
npm: toolStatus("npm"),
git: toolStatus("git"),
python3: toolStatus("python3"),
codex: toolStatus("codex")
optional: {
m1nd: toolStatus("m1nd"),
cargo: toolStatus("cargo"),
tmux: toolStatus("tmux"),
dext3r: localHttpStatus("http://127.0.0.1:5777/api/health"),
brotherizer_root: envStatus("BROTHERIZER_ROOT"),
omx_home: envStatus("OMX_HOME")
actions: [],
warnings: [],
status: "passed"
};
report.git = report.tools.host.git === "available";
report.npm = report.tools.host.npm === "available";
report.cargo = report.tools.optional.cargo === "available";
const validate = run("node", ["scripts/validate-kognit1v.mjs"], { capture: true });
report.validation = {
status: validate.status === 0 ? "passed" : "failed",
output: (validate.stdout || validate.stderr || "").trim()
if (validate.status !== 0) {
report.status = "failed";
report.warnings.push("repo validation failed; bootstrap stopped before install actions");
console.log(JSON.stringify(report, null, 2));
process.exit(1);
if (has("--install-skills")) {
const codexHome = codexHomePath;
const dest = path.join(codexHome, "skills");
for (const entry of fs.readdirSync(path.join(root, "skills"), { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
copyDir(path.join(root, "skills", entry.name), path.join(dest, entry.name));
report.actions.push(`installed skills into ${path.join("<codex-home>", "skills")}`);
if (has("--with-m1nd") || has("--install-m1nd")) {
const requestedPath = value("--m1nd-path");
const installDir = value("--m1nd-install-dir", path.join(os.homedir(), ".kognit1v", "deps", "m1nd"));
let m1ndPath = requestedPath || installDir;
const m1ndCli = commandExists("m1nd");
report.m1nd = {
cli: Boolean(m1ndCli),
checkout: fs.existsSync(m1ndPath),
native_binary: false
if (!fs.existsSync(m1ndPath) && has("--install-m1nd")) {
if (!report.git) {
report.warnings.push("git is required to clone m1nd");
} else {
fs.mkdirSync(path.dirname(m1ndPath), { recursive: true });
const clone = run("git", ["clone", "https://github.com/maxkle1nz/m1nd.git", m1ndPath]);
if (clone.status !== 0) {
report.warnings.push("m1nd clone failed");
report.actions.push("cloned m1nd");
report.m1nd.checkout = true;
if (fs.existsSync(path.join(m1ndPath, "package.json")) && has("--install-m1nd")) {
const install = run("npm", ["install", "-g", "."], { cwd: m1ndPath });
if (install.status !== 0) {
report.warnings.push("npm install -g . failed for m1nd");
report.actions.push("installed m1nd CLI via npm");
if (fs.existsSync(path.join(m1ndPath, "Cargo.toml")) && has("--build-m1nd-native")) {
if (!report.cargo) {
report.warnings.push("cargo is required for --build-m1nd-native");
const build = run("cargo", ["build", "--release"], { cwd: m1ndPath });
if (build.status !== 0) {
report.warnings.push("cargo build --release failed for m1nd");
report.actions.push("built m1nd native MCP runtime");
const nativePath = path.join(m1ndPath, "target", "release", "m1nd-mcp");
if (fs.existsSync(nativePath)) report.m1nd.native_binary = true;
if (!report.m1nd.cli && !has("--install-m1nd")) {
if (report.m1nd.checkout) {
report.warnings.push("m1nd CLI not on PATH; checkout was detected, install CLI with --install-m1nd if this host needs the m1nd command");
report.warnings.push("m1nd CLI not found; run with --install-m1nd or pass --m1nd-path");
if (has("--doctor-tools")) {
if (report.tools.host.codex === "missing") {
report.warnings.push("Codex runtime not found on PATH; KOGNIT1V ships skills, not Codex itself");
if (report.tools.optional.m1nd === "missing") {
report.warnings.push("m1nd not found on PATH; graph-first investigation remains optional until installed/configured");
if (report.tools.optional.tmux === "missing") {
report.warnings.push("tmux not found on PATH; multi-lane terminal workflows may need another coordinator");
if (report.tools.optional.dext3r === "missing") {
report.warnings.push("DEXT3R local companion is not responding on 127.0.0.1:5777; bundled DEXT3R skill remains optional");
if (report.tools.optional.brotherizer_root === "unset") {
report.warnings.push("BROTHERIZER_ROOT is unset; bundled Brotherizer skill will use only portable runtime guidance");
if (!has("--doctor") && !has("--doctor-tools") && !has("--install-skills") && !has("--with-m1nd") && !has("--install-m1nd")) {
report.warnings.push("no install flags passed; doctor/check only");
if (report.status !== "passed") {
process.exitCode = 1;