nimblebrain 0.4.0 → 0.6.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 +5 -3
- package/dist/nimblebrain.js +262 -90
- package/package.json +1 -1
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`,
|
|
12
|
-
connects your coding agent to a workspace over MCP
|
|
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 |
|
|
@@ -34,7 +36,7 @@ later.
|
|
|
34
36
|
`--json` makes every command answer one JSON object, `{"ok": true, ...}` or
|
|
35
37
|
`{"ok": false, "error": "<CODE>", "fix": "..."}`, for scripts and coding agents.
|
|
36
38
|
`--yes` takes every default. `--agent claude-code|cursor|codex|none` names the agent to
|
|
37
|
-
connect. `npx nimblebrain help --json` lists every command, flag and error code.
|
|
39
|
+
connect. `npx nimblebrain help --json` lists every command with the fields it answers, every flag and every error code.
|
|
38
40
|
|
|
39
41
|
When a newer CLI or NimbleBrain release exists, the CLI says so on stderr after its
|
|
40
42
|
answer (once a day at most; it never updates anything itself).
|
package/dist/nimblebrain.js
CHANGED
|
@@ -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]"],
|
|
@@ -494,7 +519,7 @@ var FLAG_SPECS = {
|
|
|
494
519
|
provider: {
|
|
495
520
|
type: "string",
|
|
496
521
|
takes: "name",
|
|
497
|
-
description: "The model provider for key (default anthropic)",
|
|
522
|
+
description: "The model provider for key (default anthropic); the installed release decides which it takes, and key lists them",
|
|
498
523
|
commands: ["key"]
|
|
499
524
|
},
|
|
500
525
|
"local-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",
|
|
@@ -530,7 +560,7 @@ var FLAG_SPECS = {
|
|
|
530
560
|
help: {
|
|
531
561
|
type: "boolean",
|
|
532
562
|
short: "h",
|
|
533
|
-
description: "The commands and flags; with --json, these and every error code as JSON"
|
|
563
|
+
description: "The commands and flags; with --json, these, each command's answer and every error code as JSON"
|
|
534
564
|
},
|
|
535
565
|
version: { type: "boolean", short: "v", description: "This CLI's version" }
|
|
536
566
|
};
|
|
@@ -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
|
};
|
|
@@ -830,23 +861,112 @@ function gib(bytes) {
|
|
|
830
861
|
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
831
862
|
}
|
|
832
863
|
|
|
864
|
+
// src/answers.ts
|
|
865
|
+
var STATE = {
|
|
866
|
+
version: "The NimbleBrain runtime release installed, without the leading v",
|
|
867
|
+
cli_version: "This CLI's version; it moves independently of the runtime",
|
|
868
|
+
health: "ok when NimbleBrain answers, else down",
|
|
869
|
+
url: "Where the web UI and API answer, on 127.0.0.1",
|
|
870
|
+
workspaces: "Each workspace as {id, name, mcp}, mcp being its MCP URL; empty while down",
|
|
871
|
+
agent: "{connected, skill}: the coding agent init connected (or null), and the nimblebrain skill's name when that agent has it (else null)",
|
|
872
|
+
model_key: "set or missing: whether the install's .env holds a model key (never the key)",
|
|
873
|
+
host_loopback: "Whether this release can reach a server on this machine; mcp add needs it, update brings it",
|
|
874
|
+
local_model: "The Ollama model NimbleBrain's agents run on, or null for a hosted model key",
|
|
875
|
+
telemetry: "{state, locked?, ask?, set?}: on, off or undecided; locked says why no one can change it here; ask and set, only while undecided, are the question to pass to the person and the command that answers it",
|
|
876
|
+
updates: "{cli?, runtime?}, each {current, latest}: what the last cached lookup found; absent when nothing is known or the check is off"
|
|
877
|
+
};
|
|
878
|
+
var OLLAMA_STARTED = "The command that started Ollama, when this run started it";
|
|
879
|
+
var ANSWER_FIELDS = {
|
|
880
|
+
init: {
|
|
881
|
+
...STATE,
|
|
882
|
+
already: "true when an install was already here; it was reported, not changed",
|
|
883
|
+
manual: "The settings to add to the coding agent by hand, when connecting it failed",
|
|
884
|
+
opened: "Whether the browser opened, when init tried (a new install, a person at a terminal)",
|
|
885
|
+
ollama_started: OLLAMA_STARTED
|
|
886
|
+
},
|
|
887
|
+
doctor: {
|
|
888
|
+
checks: "Each check run, in order, as {check, ok, detail}",
|
|
889
|
+
arch: "The CPU architecture Docker reports",
|
|
890
|
+
ollama_started: `${OLLAMA_STARTED}; on a local model only`
|
|
891
|
+
},
|
|
892
|
+
status: STATE,
|
|
893
|
+
open: {
|
|
894
|
+
url: "The web UI's URL, to open by hand when opened is false",
|
|
895
|
+
opened: "Whether a browser was started"
|
|
896
|
+
},
|
|
897
|
+
key: {
|
|
898
|
+
provider: "The provider the key was entered for",
|
|
899
|
+
model_key: "set"
|
|
900
|
+
},
|
|
901
|
+
"local-model": {
|
|
902
|
+
local_model: "The model NimbleBrain's agents now run on (nimblebrain-<model>)",
|
|
903
|
+
ollama_started: OLLAMA_STARTED
|
|
904
|
+
},
|
|
905
|
+
telemetry: { telemetry: STATE.telemetry },
|
|
906
|
+
up: { ...STATE, ollama_started: OLLAMA_STARTED },
|
|
907
|
+
down: { health: "down" },
|
|
908
|
+
logs: { lines: "The runtime's last log lines, up to 100" },
|
|
909
|
+
update: {
|
|
910
|
+
...STATE,
|
|
911
|
+
already: "true when the install was already on that release",
|
|
912
|
+
from: "The release moved from, as vX.Y.Z, when it moved",
|
|
913
|
+
skill_update: "What happened to the connected agent's nimblebrain skill: updated, unchanged, not_installed or failed; absent with no agent"
|
|
914
|
+
},
|
|
915
|
+
uninstall: { removed: "true" },
|
|
916
|
+
"mcp add": {
|
|
917
|
+
serverName: "The name the server was added under",
|
|
918
|
+
url: "The URL as given",
|
|
919
|
+
dialed: "Where NimbleBrain, inside Docker, connects to it",
|
|
920
|
+
placements: "Where the server's UI appears, from its Server Card",
|
|
921
|
+
wsId: "The workspace it was added to",
|
|
922
|
+
warning: "Why the server is not connected yet (it was added anyway), when it is not",
|
|
923
|
+
notice: "Anything else NimbleBrain says about the server, when it says something"
|
|
924
|
+
},
|
|
925
|
+
"mcp list": {
|
|
926
|
+
wsId: "The workspace listed",
|
|
927
|
+
servers: "Each server as {serverName, displayName?, url?, state?, status?, statusReason?, toolCount?}"
|
|
928
|
+
},
|
|
929
|
+
"mcp remove": {
|
|
930
|
+
serverName: "The server removed",
|
|
931
|
+
wsId: "The workspace it was removed from"
|
|
932
|
+
},
|
|
933
|
+
help: {
|
|
934
|
+
cli_version: "This CLI's version",
|
|
935
|
+
commands: "Each command as {name, args, description, answer}",
|
|
936
|
+
flags: "Each flag as {name, short?, takes, description, commands?}",
|
|
937
|
+
errors: "Each error code as {code, fix, exit}"
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
|
|
833
941
|
// src/help.ts
|
|
834
942
|
var HELP_COMMAND = {
|
|
835
943
|
name: "help",
|
|
836
944
|
args: [],
|
|
837
|
-
description: "These commands and flags; with --json, these and every error code as JSON"
|
|
945
|
+
description: "These commands and flags; with --json, these, each command's answer and every error code as JSON",
|
|
946
|
+
answer: { ...ANSWER_FIELDS.help }
|
|
838
947
|
};
|
|
839
948
|
function commands() {
|
|
840
949
|
const list = Object.keys(COMMAND_SPECS).flatMap((name) => {
|
|
841
950
|
if (name === "mcp") {
|
|
842
|
-
return Object.
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
951
|
+
return Object.keys(MCP_SUBCOMMANDS).map((sub) => {
|
|
952
|
+
const spec = MCP_SUBCOMMANDS[sub];
|
|
953
|
+
return {
|
|
954
|
+
name: `mcp ${sub}`,
|
|
955
|
+
args: spec.operand ? [`<${spec.operand}>`] : [],
|
|
956
|
+
description: spec.description,
|
|
957
|
+
answer: { ...ANSWER_FIELDS[`mcp ${sub}`] }
|
|
958
|
+
};
|
|
959
|
+
});
|
|
847
960
|
}
|
|
848
961
|
const spec = COMMAND_SPECS[name];
|
|
849
|
-
return [
|
|
962
|
+
return [
|
|
963
|
+
{
|
|
964
|
+
name,
|
|
965
|
+
args: [...spec.args],
|
|
966
|
+
description: spec.description,
|
|
967
|
+
answer: { ...ANSWER_FIELDS[name] }
|
|
968
|
+
}
|
|
969
|
+
];
|
|
850
970
|
});
|
|
851
971
|
return [...list, HELP_COMMAND];
|
|
852
972
|
}
|
|
@@ -872,7 +992,13 @@ function errors() {
|
|
|
872
992
|
}));
|
|
873
993
|
}
|
|
874
994
|
function describe(version) {
|
|
875
|
-
return {
|
|
995
|
+
return {
|
|
996
|
+
ok: true,
|
|
997
|
+
cli_version: version,
|
|
998
|
+
commands: commands(),
|
|
999
|
+
flags: flags(),
|
|
1000
|
+
errors: errors()
|
|
1001
|
+
};
|
|
876
1002
|
}
|
|
877
1003
|
function helpText(version) {
|
|
878
1004
|
const cmds = commands().map((c) => [[c.name, ...c.args].join(" "), c.description]);
|
|
@@ -893,7 +1019,7 @@ function helpText(version) {
|
|
|
893
1019
|
"Flags:",
|
|
894
1020
|
...fls.map(row),
|
|
895
1021
|
"",
|
|
896
|
-
"
|
|
1022
|
+
"What each command answers, and every error code and its fix: npx nimblebrain help --json",
|
|
897
1023
|
""
|
|
898
1024
|
].join(`
|
|
899
1025
|
`);
|
|
@@ -994,71 +1120,6 @@ async function skillInstalled(deps, agent) {
|
|
|
994
1120
|
return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
|
|
995
1121
|
}
|
|
996
1122
|
|
|
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
1123
|
// src/status.ts
|
|
1063
1124
|
import { join as join5 } from "node:path";
|
|
1064
1125
|
|
|
@@ -1217,7 +1278,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
|
|
|
1217
1278
|
// package.json
|
|
1218
1279
|
var package_default = {
|
|
1219
1280
|
name: "nimblebrain",
|
|
1220
|
-
version: "0.
|
|
1281
|
+
version: "0.6.0",
|
|
1221
1282
|
description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
|
|
1222
1283
|
license: "Apache-2.0",
|
|
1223
1284
|
type: "module",
|
|
@@ -1242,7 +1303,7 @@ var package_default = {
|
|
|
1242
1303
|
};
|
|
1243
1304
|
|
|
1244
1305
|
// src/version.ts
|
|
1245
|
-
var
|
|
1306
|
+
var VERSION = package_default.version;
|
|
1246
1307
|
|
|
1247
1308
|
// src/status.ts
|
|
1248
1309
|
async function readInstall(deps, home) {
|
|
@@ -1263,7 +1324,7 @@ async function status(deps, home) {
|
|
|
1263
1324
|
const install = await readInstall(deps, home);
|
|
1264
1325
|
if (!install)
|
|
1265
1326
|
throw new CliError("NOT_INSTALLED", `No NimbleBrain install in ${home}.`);
|
|
1266
|
-
const url =
|
|
1327
|
+
const url = installUrl(install);
|
|
1267
1328
|
const up = await isUp(deps, url);
|
|
1268
1329
|
const workspaces = up ? await readWorkspaces(deps, url) : [];
|
|
1269
1330
|
const composeText = await deps.readText(join5(home, "docker-compose.yml")) ?? "";
|
|
@@ -1273,7 +1334,7 @@ async function status(deps, home) {
|
|
|
1273
1334
|
return {
|
|
1274
1335
|
ok: true,
|
|
1275
1336
|
version: install.version,
|
|
1276
|
-
cli_version:
|
|
1337
|
+
cli_version: VERSION,
|
|
1277
1338
|
health: up ? "ok" : "down",
|
|
1278
1339
|
url,
|
|
1279
1340
|
workspaces,
|
|
@@ -1287,6 +1348,9 @@ async function status(deps, home) {
|
|
|
1287
1348
|
telemetry: await currentTelemetry(deps, home, url)
|
|
1288
1349
|
};
|
|
1289
1350
|
}
|
|
1351
|
+
function installUrl(install) {
|
|
1352
|
+
return `http://127.0.0.1:${install.port}`;
|
|
1353
|
+
}
|
|
1290
1354
|
async function isUp(deps, url) {
|
|
1291
1355
|
const health = await deps.getJson(`${url}/v1/health`);
|
|
1292
1356
|
return health?.status === 200 && health.body?.status === "ok";
|
|
@@ -1299,6 +1363,99 @@ async function readWorkspaces(deps, url) {
|
|
|
1299
1363
|
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
1364
|
}
|
|
1301
1365
|
|
|
1366
|
+
// src/open.ts
|
|
1367
|
+
function browserCommand(deps, url) {
|
|
1368
|
+
const { env } = deps;
|
|
1369
|
+
if (env.SSH_CONNECTION || env.SSH_TTY)
|
|
1370
|
+
return;
|
|
1371
|
+
if (deps.platform === "darwin")
|
|
1372
|
+
return { cmd: "open", args: [url] };
|
|
1373
|
+
if (deps.platform === "linux" && (env.DISPLAY || env.WAYLAND_DISPLAY))
|
|
1374
|
+
return { cmd: "xdg-open", args: [url] };
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
async function openBrowser(deps, url) {
|
|
1378
|
+
const command = browserCommand(deps, url);
|
|
1379
|
+
if (!command)
|
|
1380
|
+
return false;
|
|
1381
|
+
return deps.launch(command.cmd, command.args);
|
|
1382
|
+
}
|
|
1383
|
+
async function open(ctx) {
|
|
1384
|
+
const { deps, home } = ctx;
|
|
1385
|
+
const install = await readInstall(deps, home);
|
|
1386
|
+
if (!install)
|
|
1387
|
+
throw new CliError("NOT_INSTALLED", `No NimbleBrain install in ${home}.`);
|
|
1388
|
+
const url = installUrl(install);
|
|
1389
|
+
if (!await isUp(deps, url))
|
|
1390
|
+
throw new CliError("NOT_RUNNING", "NimbleBrain is not running.", { url });
|
|
1391
|
+
return { ok: true, url, opened: await openBrowser(deps, url) };
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// src/release.ts
|
|
1395
|
+
var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
|
|
1396
|
+
var VERSION2 = /^v\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
|
|
1397
|
+
var MIN_RUNTIME = "v0.73.0";
|
|
1398
|
+
async function runtimeTag(deps, requested) {
|
|
1399
|
+
const pinned = requested ?? deps.env.NIMBLEBRAIN_TAG;
|
|
1400
|
+
let tag;
|
|
1401
|
+
if (pinned) {
|
|
1402
|
+
if (!VERSION2.test(pinned)) {
|
|
1403
|
+
throw new CliError("USAGE", `"${pinned}" is not a runtime release tag like v1.2.3.`);
|
|
1404
|
+
}
|
|
1405
|
+
tag = pinned;
|
|
1406
|
+
} else {
|
|
1407
|
+
tag = await newestRuntime(deps);
|
|
1408
|
+
}
|
|
1409
|
+
if (compareVersions(tag, MIN_RUNTIME) < 0) {
|
|
1410
|
+
throw new CliError("RUNTIME_UNSUPPORTED", `This CLI installs NimbleBrain ${MIN_RUNTIME} or newer, not ${tag}.`);
|
|
1411
|
+
}
|
|
1412
|
+
return tag;
|
|
1413
|
+
}
|
|
1414
|
+
async function newestRuntime(deps, timeoutMs = 1e4) {
|
|
1415
|
+
const res = await deps.getText(REFS_URL, timeoutMs);
|
|
1416
|
+
if (res && res.status !== 200) {
|
|
1417
|
+
throw new CliError("NETWORK", `GitHub answered ${res.status} when asked for the newest NimbleBrain release. Pass --runtime vX.Y.Z to skip the lookup.`);
|
|
1418
|
+
}
|
|
1419
|
+
const names = [...(res?.body ?? "").matchAll(/refs\/tags\/([^\s\0^]+)/g)].map((m) => m[1] ?? "");
|
|
1420
|
+
const newest = newestRelease(names);
|
|
1421
|
+
if (!newest)
|
|
1422
|
+
throw new CliError("NETWORK", "Could not find the newest NimbleBrain release.");
|
|
1423
|
+
return newest;
|
|
1424
|
+
}
|
|
1425
|
+
function newestRelease(tags) {
|
|
1426
|
+
const plain = tags.filter((t) => /^v\d+\.\d+\.\d+$/.test(t));
|
|
1427
|
+
return plain.sort(compareVersions).pop();
|
|
1428
|
+
}
|
|
1429
|
+
function compareVersions(a, b) {
|
|
1430
|
+
const [coreA = "", preA] = a.replace(/^v/, "").split(/-(.*)/s);
|
|
1431
|
+
const [coreB = "", preB] = b.replace(/^v/, "").split(/-(.*)/s);
|
|
1432
|
+
const core = compareIdentifiers(coreA.split("."), coreB.split("."));
|
|
1433
|
+
if (core !== 0 || !preA && !preB)
|
|
1434
|
+
return core;
|
|
1435
|
+
if (!preA || !preB)
|
|
1436
|
+
return preA ? -1 : 1;
|
|
1437
|
+
return compareIdentifiers(preA.split("."), preB.split("."));
|
|
1438
|
+
}
|
|
1439
|
+
function compareIdentifiers(a, b) {
|
|
1440
|
+
for (let i = 0;i < Math.min(a.length, b.length); i++) {
|
|
1441
|
+
const order = compareIdentifier(a[i] ?? "", b[i] ?? "");
|
|
1442
|
+
if (order !== 0)
|
|
1443
|
+
return order;
|
|
1444
|
+
}
|
|
1445
|
+
return a.length - b.length;
|
|
1446
|
+
}
|
|
1447
|
+
function compareIdentifier(x, y) {
|
|
1448
|
+
if (x === y)
|
|
1449
|
+
return 0;
|
|
1450
|
+
const xn = /^\d+$/.test(x);
|
|
1451
|
+
const yn = /^\d+$/.test(y);
|
|
1452
|
+
if (xn && yn)
|
|
1453
|
+
return Number(x) - Number(y);
|
|
1454
|
+
if (xn !== yn)
|
|
1455
|
+
return xn ? -1 : 1;
|
|
1456
|
+
return x < y ? -1 : 1;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1302
1459
|
// src/lifecycle.ts
|
|
1303
1460
|
var START_TIMEOUT_MS = 15 * 60000;
|
|
1304
1461
|
var HEALTH_TIMEOUT_MS = 3 * 60000;
|
|
@@ -1321,7 +1478,7 @@ async function init(ctx) {
|
|
|
1321
1478
|
const begun = Date.now();
|
|
1322
1479
|
rec.record("cli.init_started", { agent: flags.agent ?? null, interactive: deps.interactive });
|
|
1323
1480
|
try {
|
|
1324
|
-
return await install(ctx, consent, rec, begun);
|
|
1481
|
+
return await openWhenDone(ctx, await install(ctx, consent, rec, begun));
|
|
1325
1482
|
} catch (err) {
|
|
1326
1483
|
if (!(err instanceof CliError))
|
|
1327
1484
|
throw err;
|
|
@@ -1330,6 +1487,14 @@ async function init(ctx) {
|
|
|
1330
1487
|
throw err.with({ telemetry: field(consent, invocation(deps, home), lockedHere(deps)) });
|
|
1331
1488
|
}
|
|
1332
1489
|
}
|
|
1490
|
+
async function openWhenDone(ctx, result) {
|
|
1491
|
+
const { deps, flags } = ctx;
|
|
1492
|
+
if (!deps.interactive || flags.json || flags.noOpen)
|
|
1493
|
+
return result;
|
|
1494
|
+
if (result.health !== "ok")
|
|
1495
|
+
return result;
|
|
1496
|
+
return { ...result, opened: await openBrowser(deps, result.url) };
|
|
1497
|
+
}
|
|
1333
1498
|
async function settleFailure(rec, home, consent, err) {
|
|
1334
1499
|
if (err.code !== "MODEL_KEY_MISSING") {
|
|
1335
1500
|
const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
|
|
@@ -1903,10 +2068,10 @@ async function run(argv, deps) {
|
|
|
1903
2068
|
return render(toFailure(err), json, BARE_CLI);
|
|
1904
2069
|
}
|
|
1905
2070
|
if (parsed.kind === "help") {
|
|
1906
|
-
return parsed.flags.json ? render(describe(
|
|
2071
|
+
return parsed.flags.json ? render(describe(VERSION), true, BARE_CLI) : { stdout: helpText(VERSION), code: 0 };
|
|
1907
2072
|
}
|
|
1908
2073
|
if (parsed.kind === "version") {
|
|
1909
|
-
return parsed.flags.json ? render({ ok: true, version:
|
|
2074
|
+
return parsed.flags.json ? render({ ok: true, version: VERSION }, true, BARE_CLI) : { stdout: `${VERSION}
|
|
1910
2075
|
`, code: 0 };
|
|
1911
2076
|
}
|
|
1912
2077
|
const { command, flags, arg, operand } = parsed;
|
|
@@ -1927,7 +2092,7 @@ async function run(argv, deps) {
|
|
|
1927
2092
|
result = { ...await status(deps, home) };
|
|
1928
2093
|
break;
|
|
1929
2094
|
default: {
|
|
1930
|
-
const ctx = { deps, flags, home, version:
|
|
2095
|
+
const ctx = { deps, flags, home, version: VERSION, arg, operand };
|
|
1931
2096
|
const commands = {
|
|
1932
2097
|
init,
|
|
1933
2098
|
up,
|
|
@@ -1938,7 +2103,8 @@ async function run(argv, deps) {
|
|
|
1938
2103
|
key,
|
|
1939
2104
|
telemetry,
|
|
1940
2105
|
"local-model": localModel,
|
|
1941
|
-
mcp
|
|
2106
|
+
mcp,
|
|
2107
|
+
open
|
|
1942
2108
|
};
|
|
1943
2109
|
result = await commands[command](ctx);
|
|
1944
2110
|
}
|
|
@@ -1949,7 +2115,7 @@ async function run(argv, deps) {
|
|
|
1949
2115
|
if (!result.ok)
|
|
1950
2116
|
result = { ...result, fix: forInstall(result.fix, cli) };
|
|
1951
2117
|
if (!["init", "telemetry", "uninstall", "doctor"].includes(command)) {
|
|
1952
|
-
await settleWaiting(deps, home,
|
|
2118
|
+
await settleWaiting(deps, home, VERSION);
|
|
1953
2119
|
}
|
|
1954
2120
|
return answerWithUpdates(result, command, flags.json, check, cli);
|
|
1955
2121
|
}
|
|
@@ -1957,13 +2123,13 @@ async function answerWithUpdates(result, command, json, check, cli) {
|
|
|
1957
2123
|
if (!check)
|
|
1958
2124
|
return render(result, json, cli, command);
|
|
1959
2125
|
const runtime = isStatusShaped(result) ? result.version : undefined;
|
|
1960
|
-
const updates = updatesField(await check.known(0),
|
|
2126
|
+
const updates = updatesField(await check.known(0), VERSION, runtime);
|
|
1961
2127
|
const answer = render(updates && runtime !== undefined ? { ...result, updates } : result, json, cli, command);
|
|
1962
2128
|
const notices = async () => {
|
|
1963
2129
|
const known = await check.known(NOTICE_WAIT_MS);
|
|
1964
2130
|
if (json)
|
|
1965
2131
|
return;
|
|
1966
|
-
const lines = noticeLines(updatesField(known,
|
|
2132
|
+
const lines = noticeLines(updatesField(known, VERSION, runtime), RUNTIME_NOTICE.includes(command), cli);
|
|
1967
2133
|
return lines.length > 0 ? `${lines.join(`
|
|
1968
2134
|
`)}
|
|
1969
2135
|
` : undefined;
|
|
@@ -2010,7 +2176,7 @@ function render(result, json, cli, command) {
|
|
|
2010
2176
|
return { stdout: `error: ${result.message}
|
|
2011
2177
|
fix: ${result.fix}
|
|
2012
2178
|
`, code };
|
|
2013
|
-
const lines = isStatus(result) ? statusLines(result, cli, command) : genericLines(result);
|
|
2179
|
+
const lines = isStatus(result) ? statusLines(result, cli, command) : command === "open" ? openLines(result) : genericLines(result);
|
|
2014
2180
|
return { stdout: `${lines.join(`
|
|
2015
2181
|
`)}
|
|
2016
2182
|
`, code };
|
|
@@ -2038,10 +2204,16 @@ function statusLines(r, cli, command) {
|
|
|
2038
2204
|
lines.push(` CLI ${r.cli_version}`);
|
|
2039
2205
|
if (command === "init" && !r.already && r.health === "ok") {
|
|
2040
2206
|
const ask = agent ? `, or ask ${AGENT_NAMES[agent] ?? agent} what NimbleBrain can do` : "";
|
|
2041
|
-
|
|
2207
|
+
const use = r.opened ? `use NimbleBrain in your browser at ${r.url}` : `open ${r.url}`;
|
|
2208
|
+
lines.push("", `Next: ${use}${ask}. Stop it with ${cli} down.`);
|
|
2042
2209
|
}
|
|
2043
2210
|
return lines;
|
|
2044
2211
|
}
|
|
2212
|
+
function openLines(r) {
|
|
2213
|
+
return [
|
|
2214
|
+
r.opened ? ` Opened ${String(r.url)} in your browser.` : ` Open ${String(r.url)} in your browser; none could be started here.`
|
|
2215
|
+
];
|
|
2216
|
+
}
|
|
2045
2217
|
function agentLines(r) {
|
|
2046
2218
|
const agent = r.agent.connected;
|
|
2047
2219
|
if (!agent)
|
package/package.json
CHANGED