nimblebrain 0.4.0 → 0.5.0

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
@@ -8,8 +8,9 @@ coding agent to it.
8
8
  npx nimblebrain
9
9
  ```
10
10
 
11
- It checks the machine, starts NimbleBrain in Docker at `http://127.0.0.1:27246`, and
12
- connects your coding agent to a workspace over MCP. Run it again any time: on a
11
+ It checks the machine, starts NimbleBrain in Docker at `http://127.0.0.1:27246`,
12
+ connects your coding agent to a workspace over MCP, and opens it in your browser
13
+ (`--no-open` skips that). Run it again any time: on a
13
14
  machine that already has NimbleBrain it reports what is there.
14
15
 
15
16
  You need Docker with Compose v2, about 2 GB of memory for Docker, and Node.js 20 or
@@ -22,6 +23,7 @@ later.
22
23
  | `init` (default) | Check the machine, start NimbleBrain, connect your coding agent |
23
24
  | `doctor` | Check Docker, Compose, architecture, memory and the port; installs nothing |
24
25
  | `status` | Version, health, URL and each workspace's MCP URL |
26
+ | `open` | Open the web UI in your default browser |
25
27
  | `key` | Enter the model key at a hidden prompt |
26
28
  | `up` / `down` | Start or stop it; data survives `down` |
27
29
  | `logs` | Recent log lines |
@@ -10,6 +10,7 @@ import { access, chmod, mkdir, readFile, rm, rmdir, writeFile } from "node:fs/pr
10
10
  import { createServer } from "node:net";
11
11
  import { homedir } from "node:os";
12
12
  import { delimiter, dirname, join, resolve } from "node:path";
13
+ var LAUNCH_WAIT_MS = 2000;
13
14
  function realDeps() {
14
15
  return {
15
16
  exec(cmd, args, opts = {}) {
@@ -36,6 +37,29 @@ function realDeps() {
36
37
  child.on("close", (code) => resolve({ code, stdout, stderr, missing }));
37
38
  });
38
39
  },
40
+ launch(cmd, args) {
41
+ return new Promise((resolve) => {
42
+ let child;
43
+ try {
44
+ child = spawn(cmd, args, { stdio: "ignore", detached: true });
45
+ } catch {
46
+ resolve(false);
47
+ return;
48
+ }
49
+ const timer = setTimeout(() => {
50
+ child.unref();
51
+ resolve(true);
52
+ }, LAUNCH_WAIT_MS);
53
+ child.once("error", () => {
54
+ clearTimeout(timer);
55
+ resolve(false);
56
+ });
57
+ child.once("exit", (code) => {
58
+ clearTimeout(timer);
59
+ resolve(code === 0);
60
+ });
61
+ });
62
+ },
39
63
  async which(cmd) {
40
64
  const exts = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE").split(";") : [""];
41
65
  for (const dir of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {
@@ -438,6 +462,7 @@ var COMMAND_SPECS = {
438
462
  description: "Check Docker, Compose, architecture, memory and the port; installs nothing"
439
463
  },
440
464
  status: { args: [], description: "Version, health, URL and each workspace's MCP URL" },
465
+ open: { args: [], description: "Open NimbleBrain's web UI in the default browser" },
441
466
  key: { args: [], description: "Enter the model key at a hidden prompt" },
442
467
  "local-model": {
443
468
  args: ["[model]"],
@@ -509,6 +534,11 @@ var FLAG_SPECS = {
509
534
  description: "The NimbleBrain release to install or update to (default the newest)",
510
535
  commands: ["init", "update"]
511
536
  },
537
+ "no-open": {
538
+ type: "boolean",
539
+ description: "Do not open the web UI in the browser when init finishes",
540
+ commands: ["init"]
541
+ },
512
542
  telemetry: {
513
543
  type: "string",
514
544
  takes: "on|off",
@@ -563,6 +593,7 @@ function parse(argv) {
563
593
  localModel: values["local-model"],
564
594
  runtime: values.runtime,
565
595
  telemetry,
596
+ noOpen: values["no-open"] === true,
566
597
  name: values.name,
567
598
  workspace: values.workspace
568
599
  };
@@ -994,71 +1025,6 @@ async function skillInstalled(deps, agent) {
994
1025
  return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
995
1026
  }
996
1027
 
997
- // src/release.ts
998
- var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
999
- var VERSION = /^v\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
1000
- var MIN_RUNTIME = "v0.73.0";
1001
- async function runtimeTag(deps, requested) {
1002
- const pinned = requested ?? deps.env.NIMBLEBRAIN_TAG;
1003
- let tag;
1004
- if (pinned) {
1005
- if (!VERSION.test(pinned)) {
1006
- throw new CliError("USAGE", `"${pinned}" is not a runtime release tag like v1.2.3.`);
1007
- }
1008
- tag = pinned;
1009
- } else {
1010
- tag = await newestRuntime(deps);
1011
- }
1012
- if (compareVersions(tag, MIN_RUNTIME) < 0) {
1013
- throw new CliError("RUNTIME_UNSUPPORTED", `This CLI installs NimbleBrain ${MIN_RUNTIME} or newer, not ${tag}.`);
1014
- }
1015
- return tag;
1016
- }
1017
- async function newestRuntime(deps, timeoutMs = 1e4) {
1018
- const res = await deps.getText(REFS_URL, timeoutMs);
1019
- if (res && res.status !== 200) {
1020
- throw new CliError("NETWORK", `GitHub answered ${res.status} when asked for the newest NimbleBrain release. Pass --runtime vX.Y.Z to skip the lookup.`);
1021
- }
1022
- const names = [...(res?.body ?? "").matchAll(/refs\/tags\/([^\s\0^]+)/g)].map((m) => m[1] ?? "");
1023
- const newest = newestRelease(names);
1024
- if (!newest)
1025
- throw new CliError("NETWORK", "Could not find the newest NimbleBrain release.");
1026
- return newest;
1027
- }
1028
- function newestRelease(tags) {
1029
- const plain = tags.filter((t) => /^v\d+\.\d+\.\d+$/.test(t));
1030
- return plain.sort(compareVersions).pop();
1031
- }
1032
- function compareVersions(a, b) {
1033
- const [coreA = "", preA] = a.replace(/^v/, "").split(/-(.*)/s);
1034
- const [coreB = "", preB] = b.replace(/^v/, "").split(/-(.*)/s);
1035
- const core = compareIdentifiers(coreA.split("."), coreB.split("."));
1036
- if (core !== 0 || !preA && !preB)
1037
- return core;
1038
- if (!preA || !preB)
1039
- return preA ? -1 : 1;
1040
- return compareIdentifiers(preA.split("."), preB.split("."));
1041
- }
1042
- function compareIdentifiers(a, b) {
1043
- for (let i = 0;i < Math.min(a.length, b.length); i++) {
1044
- const order = compareIdentifier(a[i] ?? "", b[i] ?? "");
1045
- if (order !== 0)
1046
- return order;
1047
- }
1048
- return a.length - b.length;
1049
- }
1050
- function compareIdentifier(x, y) {
1051
- if (x === y)
1052
- return 0;
1053
- const xn = /^\d+$/.test(x);
1054
- const yn = /^\d+$/.test(y);
1055
- if (xn && yn)
1056
- return Number(x) - Number(y);
1057
- if (xn !== yn)
1058
- return xn ? -1 : 1;
1059
- return x < y ? -1 : 1;
1060
- }
1061
-
1062
1028
  // src/status.ts
1063
1029
  import { join as join5 } from "node:path";
1064
1030
 
@@ -1217,7 +1183,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
1217
1183
  // package.json
1218
1184
  var package_default = {
1219
1185
  name: "nimblebrain",
1220
- version: "0.4.0",
1186
+ version: "0.5.0",
1221
1187
  description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
1222
1188
  license: "Apache-2.0",
1223
1189
  type: "module",
@@ -1242,7 +1208,7 @@ var package_default = {
1242
1208
  };
1243
1209
 
1244
1210
  // src/version.ts
1245
- var VERSION2 = package_default.version;
1211
+ var VERSION = package_default.version;
1246
1212
 
1247
1213
  // src/status.ts
1248
1214
  async function readInstall(deps, home) {
@@ -1263,7 +1229,7 @@ async function status(deps, home) {
1263
1229
  const install = await readInstall(deps, home);
1264
1230
  if (!install)
1265
1231
  throw new CliError("NOT_INSTALLED", `No NimbleBrain install in ${home}.`);
1266
- const url = `http://127.0.0.1:${install.port}`;
1232
+ const url = installUrl(install);
1267
1233
  const up = await isUp(deps, url);
1268
1234
  const workspaces = up ? await readWorkspaces(deps, url) : [];
1269
1235
  const composeText = await deps.readText(join5(home, "docker-compose.yml")) ?? "";
@@ -1273,7 +1239,7 @@ async function status(deps, home) {
1273
1239
  return {
1274
1240
  ok: true,
1275
1241
  version: install.version,
1276
- cli_version: VERSION2,
1242
+ cli_version: VERSION,
1277
1243
  health: up ? "ok" : "down",
1278
1244
  url,
1279
1245
  workspaces,
@@ -1287,6 +1253,9 @@ async function status(deps, home) {
1287
1253
  telemetry: await currentTelemetry(deps, home, url)
1288
1254
  };
1289
1255
  }
1256
+ function installUrl(install) {
1257
+ return `http://127.0.0.1:${install.port}`;
1258
+ }
1290
1259
  async function isUp(deps, url) {
1291
1260
  const health = await deps.getJson(`${url}/v1/health`);
1292
1261
  return health?.status === 200 && health.body?.status === "ok";
@@ -1299,6 +1268,99 @@ async function readWorkspaces(deps, url) {
1299
1268
  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}` }));
1300
1269
  }
1301
1270
 
1271
+ // src/open.ts
1272
+ function browserCommand(deps, url) {
1273
+ const { env } = deps;
1274
+ if (env.SSH_CONNECTION || env.SSH_TTY)
1275
+ return;
1276
+ if (deps.platform === "darwin")
1277
+ return { cmd: "open", args: [url] };
1278
+ if (deps.platform === "linux" && (env.DISPLAY || env.WAYLAND_DISPLAY))
1279
+ return { cmd: "xdg-open", args: [url] };
1280
+ return;
1281
+ }
1282
+ async function openBrowser(deps, url) {
1283
+ const command = browserCommand(deps, url);
1284
+ if (!command)
1285
+ return false;
1286
+ return deps.launch(command.cmd, command.args);
1287
+ }
1288
+ async function open(ctx) {
1289
+ const { deps, home } = ctx;
1290
+ const install = await readInstall(deps, home);
1291
+ if (!install)
1292
+ throw new CliError("NOT_INSTALLED", `No NimbleBrain install in ${home}.`);
1293
+ const url = installUrl(install);
1294
+ if (!await isUp(deps, url))
1295
+ throw new CliError("NOT_RUNNING", "NimbleBrain is not running.", { url });
1296
+ return { ok: true, url, opened: await openBrowser(deps, url) };
1297
+ }
1298
+
1299
+ // src/release.ts
1300
+ var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
1301
+ var VERSION2 = /^v\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
1302
+ var MIN_RUNTIME = "v0.73.0";
1303
+ async function runtimeTag(deps, requested) {
1304
+ const pinned = requested ?? deps.env.NIMBLEBRAIN_TAG;
1305
+ let tag;
1306
+ if (pinned) {
1307
+ if (!VERSION2.test(pinned)) {
1308
+ throw new CliError("USAGE", `"${pinned}" is not a runtime release tag like v1.2.3.`);
1309
+ }
1310
+ tag = pinned;
1311
+ } else {
1312
+ tag = await newestRuntime(deps);
1313
+ }
1314
+ if (compareVersions(tag, MIN_RUNTIME) < 0) {
1315
+ throw new CliError("RUNTIME_UNSUPPORTED", `This CLI installs NimbleBrain ${MIN_RUNTIME} or newer, not ${tag}.`);
1316
+ }
1317
+ return tag;
1318
+ }
1319
+ async function newestRuntime(deps, timeoutMs = 1e4) {
1320
+ const res = await deps.getText(REFS_URL, timeoutMs);
1321
+ if (res && res.status !== 200) {
1322
+ throw new CliError("NETWORK", `GitHub answered ${res.status} when asked for the newest NimbleBrain release. Pass --runtime vX.Y.Z to skip the lookup.`);
1323
+ }
1324
+ const names = [...(res?.body ?? "").matchAll(/refs\/tags\/([^\s\0^]+)/g)].map((m) => m[1] ?? "");
1325
+ const newest = newestRelease(names);
1326
+ if (!newest)
1327
+ throw new CliError("NETWORK", "Could not find the newest NimbleBrain release.");
1328
+ return newest;
1329
+ }
1330
+ function newestRelease(tags) {
1331
+ const plain = tags.filter((t) => /^v\d+\.\d+\.\d+$/.test(t));
1332
+ return plain.sort(compareVersions).pop();
1333
+ }
1334
+ function compareVersions(a, b) {
1335
+ const [coreA = "", preA] = a.replace(/^v/, "").split(/-(.*)/s);
1336
+ const [coreB = "", preB] = b.replace(/^v/, "").split(/-(.*)/s);
1337
+ const core = compareIdentifiers(coreA.split("."), coreB.split("."));
1338
+ if (core !== 0 || !preA && !preB)
1339
+ return core;
1340
+ if (!preA || !preB)
1341
+ return preA ? -1 : 1;
1342
+ return compareIdentifiers(preA.split("."), preB.split("."));
1343
+ }
1344
+ function compareIdentifiers(a, b) {
1345
+ for (let i = 0;i < Math.min(a.length, b.length); i++) {
1346
+ const order = compareIdentifier(a[i] ?? "", b[i] ?? "");
1347
+ if (order !== 0)
1348
+ return order;
1349
+ }
1350
+ return a.length - b.length;
1351
+ }
1352
+ function compareIdentifier(x, y) {
1353
+ if (x === y)
1354
+ return 0;
1355
+ const xn = /^\d+$/.test(x);
1356
+ const yn = /^\d+$/.test(y);
1357
+ if (xn && yn)
1358
+ return Number(x) - Number(y);
1359
+ if (xn !== yn)
1360
+ return xn ? -1 : 1;
1361
+ return x < y ? -1 : 1;
1362
+ }
1363
+
1302
1364
  // src/lifecycle.ts
1303
1365
  var START_TIMEOUT_MS = 15 * 60000;
1304
1366
  var HEALTH_TIMEOUT_MS = 3 * 60000;
@@ -1321,7 +1383,7 @@ async function init(ctx) {
1321
1383
  const begun = Date.now();
1322
1384
  rec.record("cli.init_started", { agent: flags.agent ?? null, interactive: deps.interactive });
1323
1385
  try {
1324
- return await install(ctx, consent, rec, begun);
1386
+ return await openWhenDone(ctx, await install(ctx, consent, rec, begun));
1325
1387
  } catch (err) {
1326
1388
  if (!(err instanceof CliError))
1327
1389
  throw err;
@@ -1330,6 +1392,14 @@ async function init(ctx) {
1330
1392
  throw err.with({ telemetry: field(consent, invocation(deps, home), lockedHere(deps)) });
1331
1393
  }
1332
1394
  }
1395
+ async function openWhenDone(ctx, result) {
1396
+ const { deps, flags } = ctx;
1397
+ if (!deps.interactive || flags.json || flags.noOpen)
1398
+ return result;
1399
+ if (result.health !== "ok" || typeof result.url !== "string")
1400
+ return result;
1401
+ return { ...result, opened: await openBrowser(deps, result.url) };
1402
+ }
1333
1403
  async function settleFailure(rec, home, consent, err) {
1334
1404
  if (err.code !== "MODEL_KEY_MISSING") {
1335
1405
  const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
@@ -1903,10 +1973,10 @@ async function run(argv, deps) {
1903
1973
  return render(toFailure(err), json, BARE_CLI);
1904
1974
  }
1905
1975
  if (parsed.kind === "help") {
1906
- return parsed.flags.json ? render(describe(VERSION2), true, BARE_CLI) : { stdout: helpText(VERSION2), code: 0 };
1976
+ return parsed.flags.json ? render(describe(VERSION), true, BARE_CLI) : { stdout: helpText(VERSION), code: 0 };
1907
1977
  }
1908
1978
  if (parsed.kind === "version") {
1909
- return parsed.flags.json ? render({ ok: true, version: VERSION2 }, true, BARE_CLI) : { stdout: `${VERSION2}
1979
+ return parsed.flags.json ? render({ ok: true, version: VERSION }, true, BARE_CLI) : { stdout: `${VERSION}
1910
1980
  `, code: 0 };
1911
1981
  }
1912
1982
  const { command, flags, arg, operand } = parsed;
@@ -1927,7 +1997,7 @@ async function run(argv, deps) {
1927
1997
  result = { ...await status(deps, home) };
1928
1998
  break;
1929
1999
  default: {
1930
- const ctx = { deps, flags, home, version: VERSION2, arg, operand };
2000
+ const ctx = { deps, flags, home, version: VERSION, arg, operand };
1931
2001
  const commands = {
1932
2002
  init,
1933
2003
  up,
@@ -1938,7 +2008,8 @@ async function run(argv, deps) {
1938
2008
  key,
1939
2009
  telemetry,
1940
2010
  "local-model": localModel,
1941
- mcp
2011
+ mcp,
2012
+ open
1942
2013
  };
1943
2014
  result = await commands[command](ctx);
1944
2015
  }
@@ -1949,7 +2020,7 @@ async function run(argv, deps) {
1949
2020
  if (!result.ok)
1950
2021
  result = { ...result, fix: forInstall(result.fix, cli) };
1951
2022
  if (!["init", "telemetry", "uninstall", "doctor"].includes(command)) {
1952
- await settleWaiting(deps, home, VERSION2);
2023
+ await settleWaiting(deps, home, VERSION);
1953
2024
  }
1954
2025
  return answerWithUpdates(result, command, flags.json, check, cli);
1955
2026
  }
@@ -1957,13 +2028,13 @@ async function answerWithUpdates(result, command, json, check, cli) {
1957
2028
  if (!check)
1958
2029
  return render(result, json, cli, command);
1959
2030
  const runtime = isStatusShaped(result) ? result.version : undefined;
1960
- const updates = updatesField(await check.known(0), VERSION2, runtime);
2031
+ const updates = updatesField(await check.known(0), VERSION, runtime);
1961
2032
  const answer = render(updates && runtime !== undefined ? { ...result, updates } : result, json, cli, command);
1962
2033
  const notices = async () => {
1963
2034
  const known = await check.known(NOTICE_WAIT_MS);
1964
2035
  if (json)
1965
2036
  return;
1966
- const lines = noticeLines(updatesField(known, VERSION2, runtime), RUNTIME_NOTICE.includes(command), cli);
2037
+ const lines = noticeLines(updatesField(known, VERSION, runtime), RUNTIME_NOTICE.includes(command), cli);
1967
2038
  return lines.length > 0 ? `${lines.join(`
1968
2039
  `)}
1969
2040
  ` : undefined;
@@ -2010,7 +2081,7 @@ function render(result, json, cli, command) {
2010
2081
  return { stdout: `error: ${result.message}
2011
2082
  fix: ${result.fix}
2012
2083
  `, code };
2013
- const lines = isStatus(result) ? statusLines(result, cli, command) : genericLines(result);
2084
+ const lines = isStatus(result) ? statusLines(result, cli, command) : command === "open" ? openLines(result) : genericLines(result);
2014
2085
  return { stdout: `${lines.join(`
2015
2086
  `)}
2016
2087
  `, code };
@@ -2038,10 +2109,16 @@ function statusLines(r, cli, command) {
2038
2109
  lines.push(` CLI ${r.cli_version}`);
2039
2110
  if (command === "init" && !r.already && r.health === "ok") {
2040
2111
  const ask = agent ? `, or ask ${AGENT_NAMES[agent] ?? agent} what NimbleBrain can do` : "";
2041
- lines.push("", `Next: open ${r.url}${ask}. Stop it with ${cli} down.`);
2112
+ const use = r.opened ? `use NimbleBrain in your browser at ${r.url}` : `open ${r.url}`;
2113
+ lines.push("", `Next: ${use}${ask}. Stop it with ${cli} down.`);
2042
2114
  }
2043
2115
  return lines;
2044
2116
  }
2117
+ function openLines(r) {
2118
+ return [
2119
+ r.opened ? ` Opened ${String(r.url)} in your browser.` : ` Open ${String(r.url)} in your browser; none could be started here.`
2120
+ ];
2121
+ }
2045
2122
  function agentLines(r) {
2046
2123
  const agent = r.agent.connected;
2047
2124
  if (!agent)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nimblebrain",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
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",