mizan-os 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  <p>Orchestrate <strong>Claude Code</strong>, <strong>Codex</strong>, <strong>Cursor</strong>, <strong>OpenCode</strong>, and <strong>Antigravity</strong> from one hardened, zero-dependency hub &mdash; with <code>&lt; 3k</code> fixed prefix tokens, a 4-tool <code>stdio</code> SQLite FTS5 MCP server, and zero-token weekly Kaizen audits.</p>
10
10
 
11
11
  <p>
12
+ <a href="https://www.npmjs.com/package/mizan-os"><img src="https://img.shields.io/npm/v/mizan-os?style=flat-square&color=cb3837&logo=npm&logoColor=white" alt="npm mizan-os" /></a>
12
13
  <a href="https://github.com/csa7mdm/mizan/actions/workflows/ci.yml"><img src="https://github.com/csa7mdm/mizan/actions/workflows/ci.yml/badge.svg" alt="Mizan CI" /></a>
13
14
  <img src="https://img.shields.io/badge/Node.js-24%2B%20Zero--Dep-22c55e?style=flat-square&logo=node.js&logoColor=white" alt="Node 24 Zero-Dep" />
14
15
  <img src="https://img.shields.io/badge/Fleet-5%20AI%20Agents-38bdf8?style=flat-square" alt="5 AI Agents" />
package/bin/mizan.mjs CHANGED
@@ -48,6 +48,8 @@ if (cmd === "start") {
48
48
  process.exit(runNode("action-center/server.mjs", [], extra));
49
49
  } else if (cmd === "connect") {
50
50
  process.exit(runNode("hub-mcp/connect.mjs", rest));
51
+ } else if (cmd === "mcp") {
52
+ process.exit(runNode("hub-mcp/index.mjs", rest));
51
53
  } else if (cmd === "sync-feed") {
52
54
  const args = rest.length ? rest : ["--source", path.join(ROOT, "feed", "lessons")];
53
55
  process.exit(runNode("ops/feed-sync.mjs", args));
@@ -64,6 +66,7 @@ if (cmd === "start") {
64
66
  "Mizan — Local-First Multi-Agent Control Plane (Zero-Dep Node 24)\n\n" +
65
67
  "Commands:\n" +
66
68
  " mizan start Start hardened Action Center (127.0.0.1:4321)\n" +
69
+ " mizan mcp Run zero-dep stdio SQLite FTS5 Hub MCP server\n" +
67
70
  " mizan connect [--dry-run] Auto-wire hub-mcp into Claude Code, OpenCode, Codex, Cursor\n" +
68
71
  " mizan sync-feed [--source] Sync Ed25519-signed community lessons into knowledge/community/\n" +
69
72
  " mizan distill [flags] Run Fail-Closed Privacy Distiller (--preview/--sign/--verify/--scan-md)\n" +
@@ -21,6 +21,11 @@ const __filename = fileURLToPath(import.meta.url);
21
21
  const __dirname = path.dirname(__filename);
22
22
  const SERVER_NAME = "brain-hub";
23
23
  const INDEX_PATH = path.resolve(__dirname, "index.mjs");
24
+ const IS_NPX_CACHE =
25
+ process.env.MIZAN_CONNECT_MODE === "npx" ||
26
+ /[\\/]_npx[\\/]|[\\/]npm-cache[\\/]/i.test(INDEX_PATH);
27
+ const MCP_CMD = IS_NPX_CACHE ? "npx" : "node";
28
+ const MCP_ARGS = IS_NPX_CACHE ? ["-y", "mizan-os", "mcp"] : [INDEX_PATH];
24
29
  const HOME_DIR = process.env.BRAIN_CONNECT_HOME || os.homedir();
25
30
  const ALL_AGENTS = ["claude", "opencode", "codex", "cursor"];
26
31
 
@@ -103,11 +108,11 @@ function connectClaude(opts) {
103
108
  const cfgPath = path.join(HOME_DIR, ".claude.json");
104
109
  const { exists, data } = readJsonSafe(cfgPath);
105
110
  const current = data?.mcpServers?.[SERVER_NAME];
106
- const expected = { type: "stdio", command: "node", args: [INDEX_PATH] };
111
+ const expected = { type: "stdio", command: MCP_CMD, args: MCP_ARGS };
107
112
  const isConnected =
108
113
  Boolean(current) &&
109
- current.command === "node" &&
110
- sameStringArray(current.args, [INDEX_PATH]);
114
+ current.command === MCP_CMD &&
115
+ sameStringArray(current.args, MCP_ARGS);
111
116
 
112
117
  if (opts.status) {
113
118
  return { agent: "claude", configPath: cfgPath, connected: isConnected, status: isConnected ? "connected" : "missing" };
@@ -140,7 +145,7 @@ function connectClaude(opts) {
140
145
  }
141
146
  const addRes = spawnSync(
142
147
  claudeCmd,
143
- ["mcp", "add", "-s", "user", SERVER_NAME, "--", "node", INDEX_PATH],
148
+ ["mcp", "add", "-s", "user", SERVER_NAME, "--", MCP_CMD, ...MCP_ARGS],
144
149
  { encoding: "utf8", windowsHide: true }
145
150
  );
146
151
  if (!addRes.error && addRes.status === 0) {
@@ -162,7 +167,7 @@ function connectOpenCode(opts) {
162
167
  const usesServersMap = Boolean(data?.mcp?.servers && typeof data.mcp.servers === "object") || !data?.mcp?.[SERVER_NAME];
163
168
  const container = usesServersMap ? data?.mcp?.servers : data?.mcp;
164
169
  const current = container?.[SERVER_NAME];
165
- const expected = { type: "local", command: ["node", INDEX_PATH] };
170
+ const expected = { type: "local", command: [MCP_CMD, ...MCP_ARGS] };
166
171
  const isConnected =
167
172
  Boolean(current) &&
168
173
  current.type === "local" &&
@@ -227,18 +232,19 @@ function connectCodex(opts) {
227
232
  const headerRe = /^\[mcp_servers\.(?:"brain-hub"|'brain-hub'|brain-hub)\]\s*$/;
228
233
  const range = findTomlSectionRange(lines, headerRe);
229
234
 
235
+ const desiredArgsToml = MCP_ARGS.map((a) => tomlLiteral(a)).join(", ");
230
236
  const desiredLines = [
231
237
  `[mcp_servers.${SERVER_NAME}]`,
232
- `command = "node"`,
233
- `args = [${tomlLiteral(INDEX_PATH)}]`,
238
+ `command = ${JSON.stringify(MCP_CMD)}`,
239
+ `args = [${desiredArgsToml}]`,
234
240
  `enabled = true`,
235
241
  ];
236
242
 
237
243
  const existingBlock = range ? lines.slice(range.start, range.end).map((l) => l.trim()).filter(Boolean) : [];
238
244
  const isConnected =
239
245
  range !== null &&
240
- existingBlock.some((l) => /^command\s*=\s*["']node["']$/.test(l)) &&
241
- existingBlock.some((l) => l.startsWith("args") && l.includes(INDEX_PATH)) &&
246
+ existingBlock.some((l) => l === `command = ${JSON.stringify(MCP_CMD)}` || l === `command = '${MCP_CMD}'`) &&
247
+ existingBlock.some((l) => l.startsWith("args") && MCP_ARGS.every((a) => l.includes(a))) &&
242
248
  !existingBlock.some((l) => /^enabled\s*=\s*false$/.test(l));
243
249
 
244
250
  if (opts.status) {
@@ -277,10 +283,10 @@ function connectCursor(opts) {
277
283
  const cfgPath = path.join(HOME_DIR, ".cursor", "mcp.json");
278
284
  const { exists, data } = readJsonSafe(cfgPath);
279
285
  const current = data?.mcpServers?.[SERVER_NAME];
280
- const expected = { command: "node", args: [INDEX_PATH] };
286
+ const expected = { command: MCP_CMD, args: MCP_ARGS };
281
287
  const isConnected =
282
288
  Boolean(current) &&
283
- current.command === "node" &&
289
+ current.command === MCP_CMD &&
284
290
  sameStringArray(current.args, expected.args);
285
291
 
286
292
  if (opts.status) {
@@ -335,10 +341,10 @@ function main() {
335
341
  }
336
342
 
337
343
  if (opts.json) {
338
- console.log(JSON.stringify({ server: SERVER_NAME, indexPath: INDEX_PATH, dryRun: opts.dryRun, results }, null, 2));
344
+ console.log(JSON.stringify({ server: SERVER_NAME, command: MCP_CMD, args: MCP_ARGS, indexPath: INDEX_PATH, dryRun: opts.dryRun, results }, null, 2));
339
345
  } else {
340
346
  const mode = opts.status ? "STATUS" : opts.remove ? "REMOVE" : opts.dryRun ? "DRY-RUN" : "CONNECT";
341
- console.log(`Brain v2 Hub MCP [${mode}] -> ${INDEX_PATH}`);
347
+ console.log(`Brain v2 Hub MCP [${mode}] -> ${MCP_CMD} ${MCP_ARGS.join(" ")}`);
342
348
  for (const r of results) {
343
349
  const extra = r.detail ? ` (${r.detail})` : r.method ? ` (${r.method})` : r.error ? ` — ${r.error}` : "";
344
350
  console.log(` - ${r.agent.padEnd(9)} ${String(r.status).padEnd(14)} ${r.configPath || ""}${extra}`);
@@ -1,12 +1,53 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { spawn } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
3
5
  import path from "node:path";
4
6
  import readline from "node:readline";
5
7
  import { fileURLToPath } from "node:url";
6
8
 
7
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const currentRoot = process.env.BRAIN_ROOT || path.resolve(__dirname, "..");
11
+ const hasLiveFixtures =
12
+ fs.existsSync(path.join(currentRoot, "LESSONS.md")) &&
13
+ fs.existsSync(path.join(currentRoot, "ops", "FLEET-STATUS.json")) &&
14
+ fs.existsSync(path.join(currentRoot, "knowledge", "MOBILE-PLAYBOOK.md"));
15
+
16
+ let tempRoot = null;
17
+ let targetRoot = currentRoot;
18
+ if (!hasLiveFixtures) {
19
+ tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mizan-hub-selftest-"));
20
+ fs.mkdirSync(path.join(tempRoot, "ops"), { recursive: true });
21
+ fs.mkdirSync(path.join(tempRoot, "knowledge"), { recursive: true });
22
+ fs.writeFileSync(
23
+ path.join(tempRoot, "LESSONS.md"),
24
+ "# Lessons\n- [tool] In PowerShell, git commit -F <file> avoids here-string pathspec errors. (2026-12-01)\n",
25
+ "utf8",
26
+ );
27
+ fs.writeFileSync(
28
+ path.join(tempRoot, "knowledge", "MOBILE-PLAYBOOK.md"),
29
+ "# Mobile Playbook\n## Wireless ADB\n- Use adb wireless debugging over Tailscale or LAN pairing.\n",
30
+ "utf8",
31
+ );
32
+ fs.writeFileSync(
33
+ path.join(tempRoot, "ops", "FLEET-STATUS.json"),
34
+ JSON.stringify({
35
+ agents: [
36
+ { id: "antigravity", quotaState: "green", planTier: "pro", fallbackChain: ["claude-code"] },
37
+ { id: "claude-code", quotaState: "green", planTier: "pro", fallbackChain: ["codex"] },
38
+ { id: "codex", quotaState: "green", planTier: "plus", fallbackChain: ["opencode"] },
39
+ { id: "opencode", quotaState: "green", planTier: "free-tier", fallbackChain: ["antigravity"] },
40
+ { id: "cursor", quotaState: "yellow-conserve", planTier: "entry", fallbackChain: ["antigravity"] },
41
+ ],
42
+ }, null, 2),
43
+ "utf8",
44
+ );
45
+ targetRoot = tempRoot;
46
+ }
47
+
8
48
  const proc = spawn(process.execPath, [path.join(__dirname, "index.mjs")], {
9
49
  stdio: ["pipe", "pipe", "inherit"],
50
+ env: { ...process.env, BRAIN_ROOT: targetRoot },
10
51
  });
11
52
 
12
53
  const rl = readline.createInterface({ input: proc.stdout });
@@ -56,4 +97,7 @@ try {
56
97
  console.log(`hub-mcp selftest PASSED (4 tools, lessons_hits=${lData.count}, comp_hits=${cData.count}, fleet=${oData.fleetQuotas.length})`);
57
98
  } finally {
58
99
  proc.kill();
100
+ if (tempRoot) {
101
+ try { fs.rmSync(tempRoot, { recursive: true, force: true }); } catch {}
102
+ }
59
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mizan-os",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Local-first multi-agent coding control plane, zero-dep Node 24 SQLite FTS5 Hub MCP, and fail-closed Ed25519 signed knowledge feeds.",
5
5
  "type": "module",
6
6
  "license": "MIT",