nimblebrain 0.6.0 → 0.7.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.
Files changed (2) hide show
  1. package/dist/nimblebrain.js +107 -41
  2. package/package.json +1 -1
@@ -222,7 +222,6 @@ var ERRORS = {
222
222
  NOT_INSTALLED: "Run `npx nimblebrain` to install it.",
223
223
  NOT_OURS: "Another install holds this name or its data. Remove it yourself, or choose a --home whose folder has another name.",
224
224
  NETWORK: "Check the network connection, then run the same command again.",
225
- MODEL_KEY_MISSING: "Run `npx nimblebrain key` in your own terminal to enter a model key.",
226
225
  HEALTH_TIMEOUT: "Run `npx nimblebrain logs` and look at the last error line.",
227
226
  AGENT_UNSUPPORTED: "Pass --agent claude-code, cursor, codex or none.",
228
227
  START_FAILED: "Run `npx nimblebrain logs` and look at the last error line, then run this again.",
@@ -248,6 +247,17 @@ var ERRORS = {
248
247
  REQUEST_FAILED: "Run `npx nimblebrain logs` and look at the last error line, then run this again."
249
248
  };
250
249
  var FIX_VARIANTS = {
250
+ DOCKER_MISSING: {
251
+ mac_brew: "Install Docker Desktop with `brew install --cask docker`, open it once from Applications, then run this again.",
252
+ mac: "Install Docker Desktop (https://docs.docker.com/desktop/setup/install/mac-install/), open it once, then run this again."
253
+ },
254
+ COMPOSE_MISSING: {
255
+ brew: "Install Compose with `brew install docker-compose`, then run this again."
256
+ },
257
+ LOW_MEMORY: {
258
+ colima: "Restart Colima with more memory: `colima stop && colima start --memory 4`, then run this again.",
259
+ docker_desktop: "In Docker Desktop, open Settings > Resources, set Memory to at least 2 GB, apply, then run this again."
260
+ },
251
261
  LOCAL_MODEL_UNREACHABLE: {
252
262
  brew_install: "Install Ollama with `brew install ollama`, then run this again; it offers to start Ollama for you.",
253
263
  app: "Open the Ollama app, then run this again.",
@@ -719,9 +729,34 @@ function composeEnv(deps, vars) {
719
729
  }
720
730
  return env;
721
731
  }
732
+ var PLUGIN = { cmd: "docker", args: ["compose"] };
733
+ var found = new WeakMap;
734
+ function findCompose(deps) {
735
+ let lookup = found.get(deps);
736
+ if (!lookup) {
737
+ lookup = lookUpCompose(deps);
738
+ found.set(deps, lookup);
739
+ }
740
+ return lookup;
741
+ }
742
+ async function lookUpCompose(deps) {
743
+ for (const program of [PLUGIN, { cmd: "docker-compose", args: [] }]) {
744
+ const res = await deps.exec(program.cmd, [...program.args, "version", "--short"]);
745
+ if (res.code === 0 && majorOf(res.stdout) >= 2)
746
+ return { ...program, version: res.stdout.trim() };
747
+ }
748
+ return;
749
+ }
750
+ function majorOf(version) {
751
+ return Number.parseInt(version.trim().replace(/^v/, ""), 10);
752
+ }
753
+ async function composeExec(deps, args, opts) {
754
+ const program = await findCompose(deps) ?? PLUGIN;
755
+ return deps.exec(program.cmd, [...program.args, ...args], opts);
756
+ }
722
757
  async function compose(deps, home, args, timeoutMs = 120000) {
723
758
  const vars = keyVars(await deps.readText(paths(home).compose) ?? "");
724
- return deps.exec("docker", ["compose", ...args], {
759
+ return composeExec(deps, args, {
725
760
  cwd: home,
726
761
  env: composeEnv(deps, vars),
727
762
  timeoutMs
@@ -777,14 +812,14 @@ var INSTANCE_JSON = `${JSON.stringify({ auth: { adapter: "dev" } }, null, 2)}
777
812
 
778
813
  // src/doctor.ts
779
814
  var SUPPORTED_ARCH = ["x86_64", "amd64", "aarch64", "arm64"];
780
- var MIN_MEMORY = 2 * 1024 ** 3;
815
+ var MIN_MEMORY = 1.75 * 1024 ** 3;
781
816
  async function doctor(deps, port, portInUseByUs = false) {
782
817
  const log = recorder();
783
818
  await checkDocker(deps, log);
784
819
  const facts = await checkDaemon(deps, log);
785
820
  await checkCompose(deps, log);
786
821
  checkArch(facts.arch, log);
787
- checkMemory(facts.memory, log);
822
+ checkMemory(facts, log);
788
823
  await checkPort(deps, port, portInUseByUs, log);
789
824
  return { ok: true, checks: log.checks, arch: facts.arch };
790
825
  }
@@ -795,16 +830,18 @@ function recorder() {
795
830
  pass: (check, detail) => {
796
831
  checks.push({ check, ok: true, detail });
797
832
  },
798
- fail: (check, code, detail) => {
833
+ fail: (check, code, detail, variant) => {
799
834
  checks.push({ check, ok: false, detail });
800
- throw new CliError(code, detail, { check, checks });
835
+ throw new CliError(code, detail, { check, checks }, variant);
801
836
  }
802
837
  };
803
838
  }
804
839
  async function checkDocker(deps, log) {
805
840
  const version = await deps.exec("docker", ["--version"]);
806
- if (version.missing)
807
- log.fail("docker", "DOCKER_MISSING", "Docker is not installed.");
841
+ if (version.missing) {
842
+ const variant = deps.platform !== "darwin" ? undefined : await deps.which("brew") ? "mac_brew" : "mac";
843
+ log.fail("docker", "DOCKER_MISSING", "Docker is not installed.", variant);
844
+ }
808
845
  log.pass("docker", version.stdout.trim());
809
846
  }
810
847
  async function checkDaemon(deps, log) {
@@ -820,12 +857,12 @@ ${info.stdout}`)) {
820
857
  return parseInfo(info.stdout);
821
858
  }
822
859
  async function checkCompose(deps, log) {
823
- const compose = await deps.exec("docker", ["compose", "version", "--short"]);
824
- const major = Number.parseInt(compose.stdout.trim().replace(/^v/, ""), 10);
825
- if (compose.code !== 0 || !(major >= 2)) {
826
- log.fail("compose", "COMPOSE_MISSING", "Docker Compose v2 is not available.");
860
+ const program = await findCompose(deps);
861
+ if (!program) {
862
+ const variant = deps.platform === "darwin" && await deps.which("brew") ? "brew" : undefined;
863
+ log.fail("compose", "COMPOSE_MISSING", "Docker Compose v2 is not available.", variant);
827
864
  }
828
- log.pass("compose", compose.stdout.trim());
865
+ log.pass("compose", program.cmd === "docker" ? program.version : `${program.version} (${program.cmd})`);
829
866
  }
830
867
  function checkArch(arch, log) {
831
868
  if (!SUPPORTED_ARCH.includes(arch)) {
@@ -833,9 +870,9 @@ function checkArch(arch, log) {
833
870
  }
834
871
  log.pass("arch", arch);
835
872
  }
836
- function checkMemory(memory, log) {
873
+ function checkMemory({ memory, kind }, log) {
837
874
  if (memory > 0 && memory < MIN_MEMORY) {
838
- log.fail("memory", "LOW_MEMORY", `Docker has ${gib(memory)} of memory; NimbleBrain needs 2 GB.`);
875
+ log.fail("memory", "LOW_MEMORY", `Docker has ${gib(memory)} of memory; NimbleBrain needs 2 GB.`, kind);
839
876
  }
840
877
  log.pass("memory", memory > 0 ? gib(memory) : "unknown");
841
878
  }
@@ -851,7 +888,8 @@ function parseInfo(stdout) {
851
888
  const info = JSON.parse(stdout);
852
889
  return {
853
890
  arch: typeof info.Architecture === "string" ? info.Architecture : "",
854
- memory: typeof info.MemTotal === "number" ? info.MemTotal : 0
891
+ memory: typeof info.MemTotal === "number" ? info.MemTotal : 0,
892
+ kind: info.OperatingSystem === "Docker Desktop" ? "docker_desktop" : info.Name === "colima" ? "colima" : undefined
855
893
  };
856
894
  } catch {
857
895
  return { arch: "", memory: 0 };
@@ -1130,6 +1168,8 @@ var TELEMETRY_KEY = "phc_qKmpYhdDtcFYZchu3KAKFFmYHG88nfUDPCFqxoAmbS7E";
1130
1168
  var ENDPOINT = "https://us.i.posthog.com/batch/";
1131
1169
  var QUESTION = "Help improve NimbleBrain by sending anonymous usage data? No prompts, content, names or keys are sent.";
1132
1170
  var reportPath = (home) => join4(home, "telemetry-report.jsonl");
1171
+ var idPath = (home) => join4(home, "telemetry-id");
1172
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1133
1173
  var RELEASED = true;
1134
1174
  function telemetryKey(deps) {
1135
1175
  return deps.env.NIMBLEBRAIN_TELEMETRY_KEY ?? (RELEASED ? TELEMETRY_KEY : "");
@@ -1199,6 +1239,21 @@ async function send(deps, home, batch) {
1199
1239
  else
1200
1240
  await deps.writeText(reportPath(home), toLines(batch), 384);
1201
1241
  }
1242
+ async function installId(deps, home) {
1243
+ if (lockedHere(deps))
1244
+ return;
1245
+ try {
1246
+ const kept = (await deps.readText(idPath(home)))?.trim();
1247
+ if (kept && UUID.test(kept))
1248
+ return kept.toLowerCase();
1249
+ const id = await reportId(deps, home) ?? randomUUID();
1250
+ await deps.writeText(idPath(home), `${id}
1251
+ `, 384);
1252
+ return id;
1253
+ } catch {
1254
+ return;
1255
+ }
1256
+ }
1202
1257
  async function reportId(deps, home) {
1203
1258
  return (await readReport(deps, home))[0]?.distinct_id;
1204
1259
  }
@@ -1246,9 +1301,10 @@ async function settleWaiting(deps, home, version) {
1246
1301
  }
1247
1302
  function envValues(deps, id, consent, asksFirst) {
1248
1303
  const values = {
1249
- NB_TELEMETRY_ID: id,
1250
1304
  NB_TELEMETRY_KEY: asksFirst ? telemetryKey(deps) : ""
1251
1305
  };
1306
+ if (id)
1307
+ values.NB_TELEMETRY_ID = id;
1252
1308
  if (consent !== "undecided")
1253
1309
  values.NB_TELEMETRY_CONSENT = consent;
1254
1310
  return values;
@@ -1278,7 +1334,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
1278
1334
  // package.json
1279
1335
  var package_default = {
1280
1336
  name: "nimblebrain",
1281
- version: "0.6.0",
1337
+ version: "0.7.1",
1282
1338
  description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
1283
1339
  license: "Apache-2.0",
1284
1340
  type: "module",
@@ -1362,6 +1418,9 @@ async function readWorkspaces(deps, url) {
1362
1418
  const body = boot.body;
1363
1419
  return (body.workspaces ?? []).filter((w) => typeof w.id === "string" && typeof w.name === "string").map((w) => ({ id: w.id, name: w.name, mcp: `${url}/mcp/${w.id}` }));
1364
1420
  }
1421
+ function hasModelIn(r) {
1422
+ return r.model_key === "set" || r.local_model !== null;
1423
+ }
1365
1424
 
1366
1425
  // src/open.ts
1367
1426
  function browserCommand(deps, url) {
@@ -1474,7 +1533,8 @@ async function init(ctx) {
1474
1533
  if (await readInstall(deps, home))
1475
1534
  return { ...await status(deps, home), already: true };
1476
1535
  const consent = await chooseConsent(ctx);
1477
- const rec = recorder2(deps, ctx.version, await reportId(deps, home));
1536
+ const id = await foreignFile(deps, home) ? undefined : await installId(deps, home);
1537
+ const rec = recorder2(deps, ctx.version, id ?? await reportId(deps, home));
1478
1538
  const begun = Date.now();
1479
1539
  rec.record("cli.init_started", { agent: flags.agent ?? null, interactive: deps.interactive });
1480
1540
  try {
@@ -1491,15 +1551,13 @@ async function openWhenDone(ctx, result) {
1491
1551
  const { deps, flags } = ctx;
1492
1552
  if (!deps.interactive || flags.json || flags.noOpen)
1493
1553
  return result;
1494
- if (result.health !== "ok")
1554
+ if (result.health !== "ok" || !hasModelIn(result))
1495
1555
  return result;
1496
1556
  return { ...result, opened: await openBrowser(deps, result.url) };
1497
1557
  }
1498
1558
  async function settleFailure(rec, home, consent, err) {
1499
- if (err.code !== "MODEL_KEY_MISSING") {
1500
- const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
1501
- rec.record(check ? "cli.doctor_failed" : "cli.init_failed", { error: err.code, check });
1502
- }
1559
+ const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
1560
+ rec.record(check ? "cli.doctor_failed" : "cli.init_failed", { error: err.code, check });
1503
1561
  await rec.settle(home, consent);
1504
1562
  }
1505
1563
  async function chooseConsent(ctx) {
@@ -1521,7 +1579,7 @@ async function install(ctx, consent, rec, begun) {
1521
1579
  const tag = await runtimeTag(deps, flags.runtime);
1522
1580
  const composeText = await fetchCompose(deps, tag);
1523
1581
  await confirmStart(ctx, tag);
1524
- await writeInstallFiles(deps, home, project, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
1582
+ await writeInstallFiles(deps, home, project, tag, flags.port, composeText, envValues(deps, lockedHere(deps) ? undefined : rec.id, consent, asksConsent(composeText)));
1525
1583
  const envText = await deps.readText(paths(home).env) ?? "";
1526
1584
  const hasModel = hasKey(envText, keyVars(composeText)) || localModelOf(envText) !== undefined;
1527
1585
  const local = flags.localModel ?? (!hasModel && asks(ctx) && takesLocalModel(composeText) ? await chooseModelSource(deps) : undefined);
@@ -1555,11 +1613,6 @@ async function install(ctx, consent, rec, begun) {
1555
1613
  agent: state.agent ?? null
1556
1614
  });
1557
1615
  await rec.settle(home, consent);
1558
- if (result.model_key === "missing" && !result.local_model) {
1559
- throw new CliError("MODEL_KEY_MISSING", "NimbleBrain is running; chat needs a model key.", {
1560
- ...result
1561
- });
1562
- }
1563
1616
  return { ...result };
1564
1617
  });
1565
1618
  }
@@ -1674,7 +1727,7 @@ async function uninstall(ctx) {
1674
1727
  await deps.exec("claude", ["mcp", "remove", "-s", "user", SERVER_NAME]);
1675
1728
  if (install.agent === "codex")
1676
1729
  await deps.exec("codex", ["mcp", "remove", SERVER_NAME]);
1677
- for (const file of [...Object.values(paths(home)), reportPath(home)])
1730
+ for (const file of [...Object.values(paths(home)), reportPath(home), idPath(home)])
1678
1731
  await deps.remove(file);
1679
1732
  await deps.remove(home);
1680
1733
  return { ok: true, removed: true };
@@ -1817,16 +1870,13 @@ async function requireInstall({ deps, home }) {
1817
1870
  }
1818
1871
  async function guardOurs(deps, home) {
1819
1872
  const project = projectFor(home);
1820
- const env = await deps.readText(paths(home).env);
1821
- const marked = env?.match(/^COMPOSE_PROJECT_NAME=(.*?)\r?$/m)?.[1];
1822
- if (marked === project || marked === DEFAULT_PROJECT)
1873
+ const marked = await markedProject(deps, home);
1874
+ if (marked)
1823
1875
  return marked;
1824
- for (const file of Object.values(paths(home))) {
1825
- if (await deps.readText(file) !== undefined) {
1826
- throw new CliError("NOT_OURS", `${file} already exists and this CLI did not write it.`);
1827
- }
1828
- }
1829
- const projects = await deps.exec("docker", ["compose", "ls", "-a", "--format", "json"]);
1876
+ const file = await foreignFile(deps, home);
1877
+ if (file)
1878
+ throw new CliError("NOT_OURS", `${file} already exists and this CLI did not write it.`);
1879
+ const projects = await composeExec(deps, ["ls", "-a", "--format", "json"]);
1830
1880
  const taken = projects.code === 0 && listsProject(projects.stdout, project);
1831
1881
  const volumes = await deps.exec("docker", [
1832
1882
  "volume",
@@ -1840,6 +1890,20 @@ async function guardOurs(deps, home) {
1840
1890
  }
1841
1891
  return project;
1842
1892
  }
1893
+ async function markedProject(deps, home) {
1894
+ const env = await deps.readText(paths(home).env);
1895
+ const marked = env?.match(/^COMPOSE_PROJECT_NAME=(.*?)\r?$/m)?.[1];
1896
+ return marked === projectFor(home) || marked === DEFAULT_PROJECT ? marked : undefined;
1897
+ }
1898
+ async function foreignFile(deps, home) {
1899
+ if (await markedProject(deps, home))
1900
+ return;
1901
+ for (const file of Object.values(paths(home))) {
1902
+ if (await deps.readText(file) !== undefined)
1903
+ return file;
1904
+ }
1905
+ return;
1906
+ }
1843
1907
  function listsProject(stdout, project) {
1844
1908
  try {
1845
1909
  const list = JSON.parse(stdout);
@@ -2202,7 +2266,9 @@ function statusLines(r, cli, command) {
2202
2266
  lines.push(` servers on this machine: not reachable until ${cli} update`);
2203
2267
  lines.push(telemetryLine(r.telemetry));
2204
2268
  lines.push(` CLI ${r.cli_version}`);
2205
- if (command === "init" && !r.already && r.health === "ok") {
2269
+ if (command === "init" && !r.already && r.health === "ok" && !hasModelIn(r)) {
2270
+ lines.push("", `Next: give NimbleBrain a model so it can chat. Run ${cli} key in your own terminal to enter a model key, or ${cli} local-model to run one on this machine with Ollama.`);
2271
+ } else if (command === "init" && !r.already && r.health === "ok") {
2206
2272
  const ask = agent ? `, or ask ${AGENT_NAMES[agent] ?? agent} what NimbleBrain can do` : "";
2207
2273
  const use = r.opened ? `use NimbleBrain in your browser at ${r.url}` : `open ${r.url}`;
2208
2274
  lines.push("", `Next: ${use}${ask}. Stop it with ${cli} down.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nimblebrain",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",