nimblebrain 0.3.0 → 0.4.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 +6 -2
- package/dist/nimblebrain.js +688 -243
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ later.
|
|
|
25
25
|
| `key` | Enter the model key at a hidden prompt |
|
|
26
26
|
| `up` / `down` | Start or stop it; data survives `down` |
|
|
27
27
|
| `logs` | Recent log lines |
|
|
28
|
-
| `update` | Move to the newest release, keeping data |
|
|
28
|
+
| `update` | Move to the newest release, keeping data, and refresh your agent's `nimblebrain` skill |
|
|
29
29
|
| `uninstall` | Remove it and its data |
|
|
30
30
|
| `telemetry [on\|off\|status]` | Whether this install sends anonymous usage data |
|
|
31
31
|
| `mcp add <url>` | Add an MCP server you run on this machine to a workspace (`--name`, `--workspace`) |
|
|
@@ -34,7 +34,11 @@ later.
|
|
|
34
34
|
`--json` makes every command answer one JSON object, `{"ok": true, ...}` or
|
|
35
35
|
`{"ok": false, "error": "<CODE>", "fix": "..."}`, for scripts and coding agents.
|
|
36
36
|
`--yes` takes every default. `--agent claude-code|cursor|codex|none` names the agent to
|
|
37
|
-
connect.
|
|
37
|
+
connect. `npx nimblebrain help --json` lists every command, flag and error code.
|
|
38
|
+
|
|
39
|
+
When a newer CLI or NimbleBrain release exists, the CLI says so on stderr after its
|
|
40
|
+
answer (once a day at most; it never updates anything itself).
|
|
41
|
+
`NIMBLEBRAIN_NO_UPDATE_CHECK=1` turns that off.
|
|
38
42
|
|
|
39
43
|
## Usage data
|
|
40
44
|
|
package/dist/nimblebrain.js
CHANGED
|
@@ -5,10 +5,11 @@ import { writeSync } from "node:fs";
|
|
|
5
5
|
|
|
6
6
|
// src/deps.ts
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
-
import {
|
|
8
|
+
import { constants } from "node:fs";
|
|
9
|
+
import { access, chmod, mkdir, readFile, rm, rmdir, writeFile } from "node:fs/promises";
|
|
9
10
|
import { createServer } from "node:net";
|
|
10
11
|
import { homedir } from "node:os";
|
|
11
|
-
import { dirname, join, resolve } from "node:path";
|
|
12
|
+
import { delimiter, dirname, join, resolve } from "node:path";
|
|
12
13
|
function realDeps() {
|
|
13
14
|
return {
|
|
14
15
|
exec(cmd, args, opts = {}) {
|
|
@@ -35,6 +36,18 @@ function realDeps() {
|
|
|
35
36
|
child.on("close", (code) => resolve({ code, stdout, stderr, missing }));
|
|
36
37
|
});
|
|
37
38
|
},
|
|
39
|
+
async which(cmd) {
|
|
40
|
+
const exts = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE").split(";") : [""];
|
|
41
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {
|
|
42
|
+
for (const ext of exts) {
|
|
43
|
+
try {
|
|
44
|
+
await access(join(dir, cmd + ext), constants.X_OK);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
},
|
|
38
51
|
portFree(port) {
|
|
39
52
|
return new Promise((resolve) => {
|
|
40
53
|
const server = createServer();
|
|
@@ -78,6 +91,7 @@ function realDeps() {
|
|
|
78
91
|
`);
|
|
79
92
|
},
|
|
80
93
|
env: process.env,
|
|
94
|
+
platform: process.platform,
|
|
81
95
|
home: homedir(),
|
|
82
96
|
cwd: process.cwd()
|
|
83
97
|
};
|
|
@@ -154,6 +168,19 @@ function typeHidden(value, chunk) {
|
|
|
154
168
|
function installHome(deps, flag) {
|
|
155
169
|
return resolve(deps.cwd, flag ?? deps.env.NIMBLEBRAIN_HOME ?? join(deps.home, ".nimblebrain-local"));
|
|
156
170
|
}
|
|
171
|
+
var BARE_CLI = "npx nimblebrain";
|
|
172
|
+
function invocation(deps, home) {
|
|
173
|
+
const fallback = resolve(deps.cwd, join(deps.home, ".nimblebrain-local"));
|
|
174
|
+
if (home === fallback && installHome(deps) === fallback)
|
|
175
|
+
return BARE_CLI;
|
|
176
|
+
return `${BARE_CLI} --home ${shellQuote(home)}`;
|
|
177
|
+
}
|
|
178
|
+
function shellQuote(s) {
|
|
179
|
+
return /^[A-Za-z0-9_./,:@%+=-]+$/.test(s) ? s : `'${s.replaceAll("'", `'\\''`)}'`;
|
|
180
|
+
}
|
|
181
|
+
function forInstall(text, cli) {
|
|
182
|
+
return text.replaceAll(BARE_CLI, () => cli);
|
|
183
|
+
}
|
|
157
184
|
|
|
158
185
|
// src/args.ts
|
|
159
186
|
import { parseArgs } from "node:util";
|
|
@@ -196,59 +223,321 @@ var ERRORS = {
|
|
|
196
223
|
NAME_IS_CATALOG_ENTRY: "Pass another name with --name; this one belongs to a catalog connector.",
|
|
197
224
|
REQUEST_FAILED: "Run `npx nimblebrain logs` and look at the last error line, then run this again."
|
|
198
225
|
};
|
|
226
|
+
var FIX_VARIANTS = {
|
|
227
|
+
LOCAL_MODEL_UNREACHABLE: {
|
|
228
|
+
brew_install: "Install Ollama with `brew install ollama`, then run this again; it offers to start Ollama for you.",
|
|
229
|
+
app: "Open the Ollama app, then run this again.",
|
|
230
|
+
brew: "Run `brew services start ollama` (it then also starts at login), then run this again.",
|
|
231
|
+
systemd: "Run `sudo systemctl start ollama`, then run this again.",
|
|
232
|
+
serve: "Run `ollama serve` in another terminal, then run this again."
|
|
233
|
+
}
|
|
234
|
+
};
|
|
199
235
|
|
|
200
236
|
class CliError extends Error {
|
|
201
237
|
code;
|
|
202
238
|
fix;
|
|
203
239
|
detail;
|
|
204
|
-
|
|
240
|
+
variant;
|
|
241
|
+
constructor(code, message, detail = {}, variant) {
|
|
205
242
|
super(message ?? code);
|
|
206
243
|
this.code = code;
|
|
207
|
-
|
|
244
|
+
const variants = FIX_VARIANTS[code];
|
|
245
|
+
this.fix = variant && variants?.[variant] || ERRORS[code];
|
|
246
|
+
this.variant = variant;
|
|
208
247
|
this.detail = detail;
|
|
209
248
|
}
|
|
249
|
+
with(detail, message = this.message) {
|
|
250
|
+
return new CliError(this.code, message, { ...this.detail, ...detail }, this.variant);
|
|
251
|
+
}
|
|
210
252
|
}
|
|
211
253
|
function failure(err) {
|
|
212
254
|
return { ...err.detail, ok: false, error: err.code, message: err.message, fix: err.fix };
|
|
213
255
|
}
|
|
214
256
|
function exitCodeFor(result) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
257
|
+
return result.ok ? 0 : exitCodeOf(result.error);
|
|
258
|
+
}
|
|
259
|
+
function exitCodeOf(code) {
|
|
260
|
+
return code === "USAGE" ? 2 : 1;
|
|
218
261
|
}
|
|
219
262
|
|
|
220
|
-
// src/
|
|
221
|
-
var
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
"
|
|
233
|
-
|
|
263
|
+
// src/local-model.ts
|
|
264
|
+
var OLLAMA_URL = "http://127.0.0.1:11434";
|
|
265
|
+
var OLLAMA_FROM_CONTAINER = "http://host.docker.internal:11434/v1";
|
|
266
|
+
var DEFAULT_LOCAL_MODEL = "gemma4:e4b";
|
|
267
|
+
var LOCAL_CONTEXT = 32768;
|
|
268
|
+
var PULL_TIMEOUT_MS = 60 * 60 * 1000;
|
|
269
|
+
var OLLAMA_START_TIMEOUT_MS = 30000;
|
|
270
|
+
var CREATE_TIMEOUT_MS = 2 * 60 * 1000;
|
|
271
|
+
function takesLocalModel(composeText) {
|
|
272
|
+
return composeText.includes("NB_LOCAL_MODEL_URL");
|
|
273
|
+
}
|
|
274
|
+
function nimblebrainModelName(model) {
|
|
275
|
+
return `nimblebrain-${model.replace(/[^A-Za-z0-9._-]+/g, "-")}`;
|
|
276
|
+
}
|
|
277
|
+
function localModelOf(envText) {
|
|
278
|
+
const line = envText.split(`
|
|
279
|
+
`).find((l) => l.startsWith("NB_LOCAL_MODEL="));
|
|
280
|
+
const value = line?.slice("NB_LOCAL_MODEL=".length).trim();
|
|
281
|
+
return value ? value : undefined;
|
|
282
|
+
}
|
|
283
|
+
async function show(deps, model) {
|
|
284
|
+
const res = await deps.postJson(`${OLLAMA_URL}/api/show`, { model });
|
|
285
|
+
return res?.status === 200 ? res.body : undefined;
|
|
286
|
+
}
|
|
287
|
+
function numCtxOf(parameters) {
|
|
288
|
+
const match = parameters?.match(/^num_ctx\s+(\d+)/m);
|
|
289
|
+
return match ? Number(match[1]) : undefined;
|
|
290
|
+
}
|
|
291
|
+
async function ollamaVersion(deps) {
|
|
292
|
+
const res = await deps.getJson(`${OLLAMA_URL}/api/version`);
|
|
293
|
+
const version = res?.body?.version;
|
|
294
|
+
return res?.status === 200 && typeof version === "string" ? version : undefined;
|
|
295
|
+
}
|
|
296
|
+
var SYSTEMD_UNITS = [
|
|
297
|
+
"/etc/systemd/system/ollama.service",
|
|
298
|
+
"/usr/lib/systemd/system/ollama.service"
|
|
234
299
|
];
|
|
300
|
+
async function findOllama(deps) {
|
|
301
|
+
const apps = ["/Applications", `${deps.home}/Applications`].map((dir) => `${dir}/Ollama.app/Contents/Info.plist`);
|
|
302
|
+
if (deps.platform === "darwin" && await anyFile(deps, apps))
|
|
303
|
+
return { kind: "app", start: ["open", "-g", "-a", "Ollama"], fix: "app" };
|
|
304
|
+
if (deps.platform === "linux" && await anyFile(deps, SYSTEMD_UNITS))
|
|
305
|
+
return {
|
|
306
|
+
kind: "systemd",
|
|
307
|
+
start: ["systemctl", "start", "--no-ask-password", "ollama"],
|
|
308
|
+
fix: "systemd"
|
|
309
|
+
};
|
|
310
|
+
const brew = await deps.exec("brew", ["list", "--versions", "ollama"]);
|
|
311
|
+
if (brew.code === 0 && brew.stdout.trim())
|
|
312
|
+
return { kind: "brew", start: ["brew", "services", "start", "ollama"], fix: "brew" };
|
|
313
|
+
if (await deps.which("ollama"))
|
|
314
|
+
return { kind: "binary", fix: "serve" };
|
|
315
|
+
return { kind: "none", fix: brew.missing ? undefined : "brew_install" };
|
|
316
|
+
}
|
|
317
|
+
async function anyFile(deps, files) {
|
|
318
|
+
for (const file of files)
|
|
319
|
+
if (await deps.readText(file) !== undefined)
|
|
320
|
+
return true;
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
async function ensureOllama(deps, confirm) {
|
|
324
|
+
const running = await ollamaVersion(deps);
|
|
325
|
+
if (running)
|
|
326
|
+
return { version: running };
|
|
327
|
+
const install = await findOllama(deps);
|
|
328
|
+
const down = (message, extra = {}) => new CliError("LOCAL_MODEL_UNREACHABLE", message, { check: "ollama", ollama: install.kind, ...extra }, install.fix);
|
|
329
|
+
if (!install.start) {
|
|
330
|
+
throw down(install.kind === "none" ? `Ollama does not answer at ${OLLAMA_URL}, and it does not look installed.` : `Ollama does not answer at ${OLLAMA_URL}.`);
|
|
331
|
+
}
|
|
332
|
+
const command = install.start.join(" ");
|
|
333
|
+
if (!await confirm(command)) {
|
|
334
|
+
throw down(`Ollama is installed but not running at ${OLLAMA_URL}; it was not started.`);
|
|
335
|
+
}
|
|
336
|
+
deps.say(`Starting Ollama: ${command}`);
|
|
337
|
+
const [cmd = "", ...args] = install.start;
|
|
338
|
+
const res = await deps.exec(cmd, args, { timeoutMs: 60000 });
|
|
339
|
+
if (res.code !== 0 || res.missing) {
|
|
340
|
+
const why = res.stderr.trim().split(`
|
|
341
|
+
`)[0];
|
|
342
|
+
throw down(`\`${command}\` did not start Ollama${why ? `: ${why}` : "."}`);
|
|
343
|
+
}
|
|
344
|
+
for (let waited = 0;waited < OLLAMA_START_TIMEOUT_MS; waited += 1000) {
|
|
345
|
+
await deps.sleep(1000);
|
|
346
|
+
const version = await ollamaVersion(deps);
|
|
347
|
+
if (version) {
|
|
348
|
+
deps.say(`Ollama ${version} is running.`);
|
|
349
|
+
if (deps.platform === "linux")
|
|
350
|
+
deps.say("On Linux, NimbleBrain's container reaches Ollama only when it listens beyond 127.0.0.1 (OLLAMA_HOST=0.0.0.0).");
|
|
351
|
+
return { version, started: command };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
throw down(`Ollama was started with \`${command}\` but did not answer at ${OLLAMA_URL} within 30 seconds.`, { ollama_started: command });
|
|
355
|
+
}
|
|
356
|
+
async function setupLocalModel(deps, model, asks) {
|
|
357
|
+
const { started } = await ensureOllama(deps, asks.start);
|
|
358
|
+
try {
|
|
359
|
+
return { values: await prepareModel(deps, model, asks.pull), started };
|
|
360
|
+
} catch (err) {
|
|
361
|
+
if (err instanceof CliError && started)
|
|
362
|
+
throw err.with({ ollama_started: started });
|
|
363
|
+
throw err;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function prepareModel(deps, model, pull) {
|
|
367
|
+
let found = await show(deps, model);
|
|
368
|
+
if (!found) {
|
|
369
|
+
if (!await pull(model)) {
|
|
370
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`, {
|
|
371
|
+
check: "model"
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
deps.say(`Downloading ${model} with Ollama. A model is several GB; this can take a while.`);
|
|
375
|
+
const pulled = await deps.postJson(`${OLLAMA_URL}/api/pull`, { model, stream: false }, PULL_TIMEOUT_MS);
|
|
376
|
+
found = pulled?.status === 200 ? await show(deps, model) : undefined;
|
|
377
|
+
if (!found) {
|
|
378
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not download "${model}".`, {
|
|
379
|
+
check: "model"
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!found.capabilities?.includes("tools")) {
|
|
384
|
+
throw new CliError("LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling, which NimbleBrain's agents need.`, { check: "tools" });
|
|
385
|
+
}
|
|
386
|
+
const name = nimblebrainModelName(model);
|
|
387
|
+
const created = await deps.postJson(`${OLLAMA_URL}/api/create`, { model: name, from: model, parameters: { num_ctx: LOCAL_CONTEXT }, stream: false }, CREATE_TIMEOUT_MS);
|
|
388
|
+
if (created?.status !== 200) {
|
|
389
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not prepare ${name} from ${model}.`, {
|
|
390
|
+
check: "model"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
NB_LOCAL_MODEL_URL: OLLAMA_FROM_CONTAINER,
|
|
395
|
+
NB_LOCAL_MODEL: name,
|
|
396
|
+
NB_LOCAL_MODEL_CONTEXT: String(LOCAL_CONTEXT)
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async function checkLocalModel(deps, model, start) {
|
|
400
|
+
const checks = [];
|
|
401
|
+
const { version, started } = await ensureOllama(deps, start).catch((err) => {
|
|
402
|
+
if (!(err instanceof CliError))
|
|
403
|
+
throw err;
|
|
404
|
+
checks.push({ check: "ollama", ok: false, detail: err.message });
|
|
405
|
+
throw err.with({ check: "ollama", checks });
|
|
406
|
+
});
|
|
407
|
+
checks.push({
|
|
408
|
+
check: "ollama",
|
|
409
|
+
ok: true,
|
|
410
|
+
detail: started ? `${version} (started: ${started})` : version
|
|
411
|
+
});
|
|
412
|
+
const found = await show(deps, model);
|
|
413
|
+
const fail = (check, code, detail) => {
|
|
414
|
+
checks.push({ check, ok: false, detail });
|
|
415
|
+
throw new CliError(code, detail, { check, checks, ollama_started: started });
|
|
416
|
+
};
|
|
417
|
+
if (!found)
|
|
418
|
+
fail("model", "LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`);
|
|
419
|
+
checks.push({ check: "model", ok: true, detail: model });
|
|
420
|
+
if (!found?.capabilities?.includes("tools"))
|
|
421
|
+
fail("tools", "LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling.`);
|
|
422
|
+
checks.push({ check: "tools", ok: true, detail: "tool calling" });
|
|
423
|
+
const ctx = numCtxOf(found?.parameters);
|
|
424
|
+
if (ctx === undefined || ctx < LOCAL_CONTEXT)
|
|
425
|
+
fail("context", "LOCAL_CONTEXT_SMALL", `${model} has a context window of ${ctx ?? "Ollama's default"}, below ${LOCAL_CONTEXT}.`);
|
|
426
|
+
checks.push({ check: "context", ok: true, detail: `${ctx} tokens` });
|
|
427
|
+
return { checks, started };
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/args.ts
|
|
431
|
+
var COMMAND_SPECS = {
|
|
432
|
+
init: {
|
|
433
|
+
args: [],
|
|
434
|
+
description: "Check this machine, start NimbleBrain, connect your coding agent (default)"
|
|
435
|
+
},
|
|
436
|
+
doctor: {
|
|
437
|
+
args: [],
|
|
438
|
+
description: "Check Docker, Compose, architecture, memory and the port; installs nothing"
|
|
439
|
+
},
|
|
440
|
+
status: { args: [], description: "Version, health, URL and each workspace's MCP URL" },
|
|
441
|
+
key: { args: [], description: "Enter the model key at a hidden prompt" },
|
|
442
|
+
"local-model": {
|
|
443
|
+
args: ["[model]"],
|
|
444
|
+
description: `Run NimbleBrain's agents on a model served by Ollama (default ${DEFAULT_LOCAL_MODEL})`
|
|
445
|
+
},
|
|
446
|
+
telemetry: {
|
|
447
|
+
args: ["[on|off|status]"],
|
|
448
|
+
description: "Whether this install sends anonymous usage data"
|
|
449
|
+
},
|
|
450
|
+
up: { args: [], description: "Start NimbleBrain" },
|
|
451
|
+
down: { args: [], description: "Stop NimbleBrain; data survives down" },
|
|
452
|
+
logs: { args: [], description: "Recent runtime log lines" },
|
|
453
|
+
update: {
|
|
454
|
+
args: [],
|
|
455
|
+
description: "Move to the newest release, keeping data, and refresh the connected agent's nimblebrain skill"
|
|
456
|
+
},
|
|
457
|
+
uninstall: { args: [], description: "Remove NimbleBrain and its data" },
|
|
458
|
+
mcp: {
|
|
459
|
+
args: ["<add|list|remove>"],
|
|
460
|
+
description: "MCP servers in development; see mcp add, list and remove"
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var COMMANDS = Object.keys(COMMAND_SPECS);
|
|
464
|
+
var TELEMETRY_ARGS = ["on", "off", "status"];
|
|
235
465
|
var AGENTS = ["claude-code", "cursor", "codex", "none"];
|
|
236
466
|
var DEFAULT_PORT = 27246;
|
|
237
|
-
var
|
|
238
|
-
json: {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
467
|
+
var FLAG_SPECS = {
|
|
468
|
+
json: {
|
|
469
|
+
type: "boolean",
|
|
470
|
+
description: "One JSON object on stdout; progress and notices go to stderr"
|
|
471
|
+
},
|
|
472
|
+
yes: {
|
|
473
|
+
type: "boolean",
|
|
474
|
+
short: "y",
|
|
475
|
+
description: "Take every default; implied when no terminal is attached"
|
|
476
|
+
},
|
|
477
|
+
agent: {
|
|
478
|
+
type: "string",
|
|
479
|
+
takes: "name",
|
|
480
|
+
description: `The coding agent to connect: ${AGENTS.slice(0, -1).join(", ")} or ${AGENTS.at(-1)}`,
|
|
481
|
+
commands: ["init"]
|
|
482
|
+
},
|
|
483
|
+
port: {
|
|
484
|
+
type: "string",
|
|
485
|
+
takes: "n",
|
|
486
|
+
description: `Local port (default ${DEFAULT_PORT})`,
|
|
487
|
+
commands: ["init", "doctor"]
|
|
488
|
+
},
|
|
489
|
+
home: {
|
|
490
|
+
type: "string",
|
|
491
|
+
takes: "dir",
|
|
492
|
+
description: "Where the install lives (default ~/.nimblebrain-local, or NIMBLEBRAIN_HOME); a home with another folder name is a separate install"
|
|
493
|
+
},
|
|
494
|
+
provider: {
|
|
495
|
+
type: "string",
|
|
496
|
+
takes: "name",
|
|
497
|
+
description: "The model provider for key (default anthropic)",
|
|
498
|
+
commands: ["key"]
|
|
499
|
+
},
|
|
500
|
+
"local-model": {
|
|
501
|
+
type: "string",
|
|
502
|
+
takes: "model",
|
|
503
|
+
description: "Run on this Ollama model instead of a hosted key",
|
|
504
|
+
commands: ["init"]
|
|
505
|
+
},
|
|
506
|
+
runtime: {
|
|
507
|
+
type: "string",
|
|
508
|
+
takes: "tag",
|
|
509
|
+
description: "The NimbleBrain release to install or update to (default the newest)",
|
|
510
|
+
commands: ["init", "update"]
|
|
511
|
+
},
|
|
512
|
+
telemetry: {
|
|
513
|
+
type: "string",
|
|
514
|
+
takes: "on|off",
|
|
515
|
+
description: "The person's answer to sending anonymous usage data; without it, init asks or leaves it undecided",
|
|
516
|
+
commands: ["init"]
|
|
517
|
+
},
|
|
518
|
+
name: {
|
|
519
|
+
type: "string",
|
|
520
|
+
takes: "name",
|
|
521
|
+
description: "The server name (default from the server's card, else its URL)",
|
|
522
|
+
commands: ["mcp add"]
|
|
523
|
+
},
|
|
524
|
+
workspace: {
|
|
525
|
+
type: "string",
|
|
526
|
+
takes: "id",
|
|
527
|
+
description: "The workspace (default the one init connected, the first in status)",
|
|
528
|
+
commands: ["mcp add", "mcp list", "mcp remove"]
|
|
529
|
+
},
|
|
530
|
+
help: {
|
|
531
|
+
type: "boolean",
|
|
532
|
+
short: "h",
|
|
533
|
+
description: "The commands and flags; with --json, these and every error code as JSON"
|
|
534
|
+
},
|
|
535
|
+
version: { type: "boolean", short: "v", description: "This CLI's version" }
|
|
251
536
|
};
|
|
537
|
+
var options = Object.fromEntries(Object.entries(FLAG_SPECS).map(([name, f]) => [
|
|
538
|
+
name,
|
|
539
|
+
f.short ? { type: f.type, short: f.short } : { type: f.type }
|
|
540
|
+
]));
|
|
252
541
|
function parse(argv) {
|
|
253
542
|
const { values, positionals } = parseStrict(argv);
|
|
254
543
|
const json = values.json === true;
|
|
@@ -297,7 +586,11 @@ function telemetryFlag(value) {
|
|
|
297
586
|
return value;
|
|
298
587
|
throw new CliError("USAGE", `--telemetry must be on or off, not "${value}".`);
|
|
299
588
|
}
|
|
300
|
-
var MCP_SUBCOMMANDS = {
|
|
589
|
+
var MCP_SUBCOMMANDS = {
|
|
590
|
+
add: { operand: "url", description: "Add an MCP server you run on this machine to a workspace" },
|
|
591
|
+
list: { operand: null, description: "The servers in a workspace" },
|
|
592
|
+
remove: { operand: "serverName", description: "Remove a server from a workspace" }
|
|
593
|
+
};
|
|
301
594
|
function command(name, positionals) {
|
|
302
595
|
if (!COMMANDS.includes(name))
|
|
303
596
|
throw new CliError("USAGE", `Unknown command "${name}".`);
|
|
@@ -307,7 +600,7 @@ function command(name, positionals) {
|
|
|
307
600
|
if (positionals.length > maxArgs)
|
|
308
601
|
throw new CliError("USAGE", `Unexpected argument "${positionals[maxArgs]}".`);
|
|
309
602
|
const arg = positionals[1];
|
|
310
|
-
if (name === "telemetry" && arg !== undefined && !
|
|
603
|
+
if (name === "telemetry" && arg !== undefined && !TELEMETRY_ARGS.includes(arg))
|
|
311
604
|
throw new CliError("USAGE", `telemetry takes on, off or status, not "${arg}".`);
|
|
312
605
|
return name;
|
|
313
606
|
}
|
|
@@ -315,7 +608,7 @@ function mcpCommand(positionals) {
|
|
|
315
608
|
const sub = positionals[1];
|
|
316
609
|
if (sub === undefined || !Object.hasOwn(MCP_SUBCOMMANDS, sub))
|
|
317
610
|
throw new CliError("USAGE", `mcp takes add <url>, list or remove <serverName>${sub === undefined ? "" : `, not "${sub}"`}.`);
|
|
318
|
-
const operand = MCP_SUBCOMMANDS[sub];
|
|
611
|
+
const { operand } = MCP_SUBCOMMANDS[sub];
|
|
319
612
|
const maxArgs = operand === null ? 2 : 3;
|
|
320
613
|
if (positionals.length > maxArgs)
|
|
321
614
|
throw new CliError("USAGE", `Unexpected argument "${positionals[maxArgs]}".`);
|
|
@@ -537,6 +830,75 @@ function gib(bytes) {
|
|
|
537
830
|
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
538
831
|
}
|
|
539
832
|
|
|
833
|
+
// src/help.ts
|
|
834
|
+
var HELP_COMMAND = {
|
|
835
|
+
name: "help",
|
|
836
|
+
args: [],
|
|
837
|
+
description: "These commands and flags; with --json, these and every error code as JSON"
|
|
838
|
+
};
|
|
839
|
+
function commands() {
|
|
840
|
+
const list = Object.keys(COMMAND_SPECS).flatMap((name) => {
|
|
841
|
+
if (name === "mcp") {
|
|
842
|
+
return Object.entries(MCP_SUBCOMMANDS).map(([sub, spec]) => ({
|
|
843
|
+
name: `mcp ${sub}`,
|
|
844
|
+
args: spec.operand ? [`<${spec.operand}>`] : [],
|
|
845
|
+
description: spec.description
|
|
846
|
+
}));
|
|
847
|
+
}
|
|
848
|
+
const spec = COMMAND_SPECS[name];
|
|
849
|
+
return [{ name, args: [...spec.args], description: spec.description }];
|
|
850
|
+
});
|
|
851
|
+
return [...list, HELP_COMMAND];
|
|
852
|
+
}
|
|
853
|
+
function flags() {
|
|
854
|
+
return Object.entries(FLAG_SPECS).map(([name, spec]) => {
|
|
855
|
+
const f = {
|
|
856
|
+
name: `--${name}`,
|
|
857
|
+
takes: "takes" in spec ? spec.takes : null,
|
|
858
|
+
description: spec.description
|
|
859
|
+
};
|
|
860
|
+
if ("short" in spec)
|
|
861
|
+
f.short = `-${spec.short}`;
|
|
862
|
+
if ("commands" in spec)
|
|
863
|
+
f.commands = [...spec.commands];
|
|
864
|
+
return f;
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function errors() {
|
|
868
|
+
return Object.keys(ERRORS).map((code) => ({
|
|
869
|
+
code,
|
|
870
|
+
fix: ERRORS[code],
|
|
871
|
+
exit: exitCodeOf(code)
|
|
872
|
+
}));
|
|
873
|
+
}
|
|
874
|
+
function describe(version) {
|
|
875
|
+
return { ok: true, cli_version: version, commands: commands(), flags: flags(), errors: errors() };
|
|
876
|
+
}
|
|
877
|
+
function helpText(version) {
|
|
878
|
+
const cmds = commands().map((c) => [[c.name, ...c.args].join(" "), c.description]);
|
|
879
|
+
const fls = flags().map((f) => [
|
|
880
|
+
[f.takes ? `${f.name} <${f.takes}>` : f.name, f.short].filter(Boolean).join(", "),
|
|
881
|
+
f.commands ? `${f.description}; for ${f.commands.join(", ")}` : f.description
|
|
882
|
+
]);
|
|
883
|
+
const width = Math.max(...[...cmds, ...fls].map(([left]) => left.length)) + 2;
|
|
884
|
+
const row = ([left, right]) => ` ${left.padEnd(width)}${right}`;
|
|
885
|
+
return [
|
|
886
|
+
`nimblebrain ${version}: install and run NimbleBrain on this machine`,
|
|
887
|
+
"",
|
|
888
|
+
"Usage: npx nimblebrain [command] [flags]",
|
|
889
|
+
"",
|
|
890
|
+
"Commands:",
|
|
891
|
+
...cmds.map(row),
|
|
892
|
+
"",
|
|
893
|
+
"Flags:",
|
|
894
|
+
...fls.map(row),
|
|
895
|
+
"",
|
|
896
|
+
"Every error code and its fix: npx nimblebrain help --json",
|
|
897
|
+
""
|
|
898
|
+
].join(`
|
|
899
|
+
`);
|
|
900
|
+
}
|
|
901
|
+
|
|
540
902
|
// src/agents.ts
|
|
541
903
|
import { join as join3 } from "node:path";
|
|
542
904
|
var SERVER_NAME = "nimblebrain";
|
|
@@ -601,6 +963,20 @@ async function installSkill(deps, agent) {
|
|
|
601
963
|
"-y"
|
|
602
964
|
], { timeoutMs: 120000 });
|
|
603
965
|
}
|
|
966
|
+
async function refreshSkill(deps, agent) {
|
|
967
|
+
if (!await skillInstalled(deps, agent))
|
|
968
|
+
return "not_installed";
|
|
969
|
+
try {
|
|
970
|
+
const res = await deps.exec("npx", ["-y", "skills", "update", SKILL_NAME, "-g", "-y"], {
|
|
971
|
+
timeoutMs: 120000
|
|
972
|
+
});
|
|
973
|
+
if (res.code !== 0)
|
|
974
|
+
return "failed";
|
|
975
|
+
return /Updated \d+ skill/.test(res.stdout) ? "updated" : "unchanged";
|
|
976
|
+
} catch {
|
|
977
|
+
return "failed";
|
|
978
|
+
}
|
|
979
|
+
}
|
|
604
980
|
var SKILL_NAME = "nimblebrain";
|
|
605
981
|
function globalSkillsDir(deps, agent) {
|
|
606
982
|
if (agent === "claude-code")
|
|
@@ -618,102 +994,6 @@ async function skillInstalled(deps, agent) {
|
|
|
618
994
|
return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
|
|
619
995
|
}
|
|
620
996
|
|
|
621
|
-
// src/local-model.ts
|
|
622
|
-
var OLLAMA_URL = "http://127.0.0.1:11434";
|
|
623
|
-
var OLLAMA_FROM_CONTAINER = "http://host.docker.internal:11434/v1";
|
|
624
|
-
var DEFAULT_LOCAL_MODEL = "gemma4:e4b";
|
|
625
|
-
var LOCAL_CONTEXT = 32768;
|
|
626
|
-
var PULL_TIMEOUT_MS = 60 * 60 * 1000;
|
|
627
|
-
var CREATE_TIMEOUT_MS = 2 * 60 * 1000;
|
|
628
|
-
function takesLocalModel(composeText) {
|
|
629
|
-
return composeText.includes("NB_LOCAL_MODEL_URL");
|
|
630
|
-
}
|
|
631
|
-
function nimblebrainModelName(model) {
|
|
632
|
-
return `nimblebrain-${model.replace(/[^A-Za-z0-9._-]+/g, "-")}`;
|
|
633
|
-
}
|
|
634
|
-
function localModelOf(envText) {
|
|
635
|
-
const line = envText.split(`
|
|
636
|
-
`).find((l) => l.startsWith("NB_LOCAL_MODEL="));
|
|
637
|
-
const value = line?.slice("NB_LOCAL_MODEL=".length).trim();
|
|
638
|
-
return value ? value : undefined;
|
|
639
|
-
}
|
|
640
|
-
async function show(deps, model) {
|
|
641
|
-
const res = await deps.postJson(`${OLLAMA_URL}/api/show`, { model });
|
|
642
|
-
return res?.status === 200 ? res.body : undefined;
|
|
643
|
-
}
|
|
644
|
-
function numCtxOf(parameters) {
|
|
645
|
-
const match = parameters?.match(/^num_ctx\s+(\d+)/m);
|
|
646
|
-
return match ? Number(match[1]) : undefined;
|
|
647
|
-
}
|
|
648
|
-
async function requireOllama(deps) {
|
|
649
|
-
const res = await deps.getJson(`${OLLAMA_URL}/api/version`);
|
|
650
|
-
const version = res?.body?.version;
|
|
651
|
-
if (res?.status !== 200 || typeof version !== "string") {
|
|
652
|
-
throw new CliError("LOCAL_MODEL_UNREACHABLE", `Ollama does not answer at ${OLLAMA_URL}.`, {
|
|
653
|
-
check: "ollama"
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
return version;
|
|
657
|
-
}
|
|
658
|
-
async function setupLocalModel(deps, model, pull) {
|
|
659
|
-
await requireOllama(deps);
|
|
660
|
-
let found = await show(deps, model);
|
|
661
|
-
if (!found) {
|
|
662
|
-
if (!await pull(model)) {
|
|
663
|
-
throw new CliError("LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`, {
|
|
664
|
-
check: "model"
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
deps.say(`Downloading ${model} with Ollama. A model is several GB; this can take a while.`);
|
|
668
|
-
const pulled = await deps.postJson(`${OLLAMA_URL}/api/pull`, { model, stream: false }, PULL_TIMEOUT_MS);
|
|
669
|
-
found = pulled?.status === 200 ? await show(deps, model) : undefined;
|
|
670
|
-
if (!found) {
|
|
671
|
-
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not download "${model}".`, {
|
|
672
|
-
check: "model"
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if (!found.capabilities?.includes("tools")) {
|
|
677
|
-
throw new CliError("LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling, which NimbleBrain's agents need.`, { check: "tools" });
|
|
678
|
-
}
|
|
679
|
-
const name = nimblebrainModelName(model);
|
|
680
|
-
const created = await deps.postJson(`${OLLAMA_URL}/api/create`, { model: name, from: model, parameters: { num_ctx: LOCAL_CONTEXT }, stream: false }, CREATE_TIMEOUT_MS);
|
|
681
|
-
if (created?.status !== 200) {
|
|
682
|
-
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not prepare ${name} from ${model}.`, {
|
|
683
|
-
check: "model"
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
return {
|
|
687
|
-
NB_LOCAL_MODEL_URL: OLLAMA_FROM_CONTAINER,
|
|
688
|
-
NB_LOCAL_MODEL: name,
|
|
689
|
-
NB_LOCAL_MODEL_CONTEXT: String(LOCAL_CONTEXT)
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
async function checkLocalModel(deps, model) {
|
|
693
|
-
const checks = [];
|
|
694
|
-
const version = await requireOllama(deps).catch((err) => {
|
|
695
|
-
checks.push({ check: "ollama", ok: false, detail: err.message });
|
|
696
|
-
throw new CliError(err.code, err.message, { check: "ollama", checks });
|
|
697
|
-
});
|
|
698
|
-
checks.push({ check: "ollama", ok: true, detail: version });
|
|
699
|
-
const found = await show(deps, model);
|
|
700
|
-
const fail = (check, code, detail) => {
|
|
701
|
-
checks.push({ check, ok: false, detail });
|
|
702
|
-
throw new CliError(code, detail, { check, checks });
|
|
703
|
-
};
|
|
704
|
-
if (!found)
|
|
705
|
-
fail("model", "LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`);
|
|
706
|
-
checks.push({ check: "model", ok: true, detail: model });
|
|
707
|
-
if (!found?.capabilities?.includes("tools"))
|
|
708
|
-
fail("tools", "LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling.`);
|
|
709
|
-
checks.push({ check: "tools", ok: true, detail: "tool calling" });
|
|
710
|
-
const ctx = numCtxOf(found?.parameters);
|
|
711
|
-
if (ctx === undefined || ctx < LOCAL_CONTEXT)
|
|
712
|
-
fail("context", "LOCAL_CONTEXT_SMALL", `${model} has a context window of ${ctx ?? "Ollama's default"}, below ${LOCAL_CONTEXT}.`);
|
|
713
|
-
checks.push({ check: "context", ok: true, detail: `${ctx} tokens` });
|
|
714
|
-
return checks;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
997
|
// src/release.ts
|
|
718
998
|
var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
|
|
719
999
|
var VERSION = /^v\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
|
|
@@ -734,8 +1014,8 @@ async function runtimeTag(deps, requested) {
|
|
|
734
1014
|
}
|
|
735
1015
|
return tag;
|
|
736
1016
|
}
|
|
737
|
-
async function newestRuntime(deps) {
|
|
738
|
-
const res = await deps.getText(REFS_URL,
|
|
1017
|
+
async function newestRuntime(deps, timeoutMs = 1e4) {
|
|
1018
|
+
const res = await deps.getText(REFS_URL, timeoutMs);
|
|
739
1019
|
if (res && res.status !== 200) {
|
|
740
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.`);
|
|
741
1021
|
}
|
|
@@ -793,19 +1073,22 @@ var RELEASED = true;
|
|
|
793
1073
|
function telemetryKey(deps) {
|
|
794
1074
|
return deps.env.NIMBLEBRAIN_TELEMETRY_KEY ?? (RELEASED ? TELEMETRY_KEY : "");
|
|
795
1075
|
}
|
|
1076
|
+
function doNotTrack(deps) {
|
|
1077
|
+
return deps.env.DO_NOT_TRACK === "1";
|
|
1078
|
+
}
|
|
796
1079
|
function lockedHere(deps) {
|
|
797
|
-
if (deps
|
|
1080
|
+
if (doNotTrack(deps) || deps.env.NB_TELEMETRY_DISABLED === "1")
|
|
798
1081
|
return "do_not_track";
|
|
799
1082
|
if (!telemetryKey(deps))
|
|
800
1083
|
return "no_destination";
|
|
801
1084
|
return;
|
|
802
1085
|
}
|
|
803
|
-
function field(state, locked) {
|
|
1086
|
+
function field(state, cli, locked) {
|
|
804
1087
|
if (locked)
|
|
805
1088
|
return { state: state === "undecided" ? "off" : state, locked };
|
|
806
1089
|
if (state !== "undecided")
|
|
807
1090
|
return { state };
|
|
808
|
-
return { state, ask: QUESTION, set:
|
|
1091
|
+
return { state, ask: QUESTION, set: `${cli} telemetry on|off` };
|
|
809
1092
|
}
|
|
810
1093
|
function recorder2(deps, version, id) {
|
|
811
1094
|
const events = [];
|
|
@@ -886,7 +1169,7 @@ async function currentTelemetry(deps, home, url) {
|
|
|
886
1169
|
const rt = await runtimeTelemetry(deps, url);
|
|
887
1170
|
const state = rt?.consent ?? seededConsent(await deps.readText(join4(home, ".env")) ?? "");
|
|
888
1171
|
const lock = here ?? (rt?.locked === "operator" || rt?.locked === "no_destination" ? rt.locked : undefined);
|
|
889
|
-
return field(state, lock);
|
|
1172
|
+
return field(state, invocation(deps, home), lock);
|
|
890
1173
|
}
|
|
891
1174
|
async function settleWaiting(deps, home, version) {
|
|
892
1175
|
try {
|
|
@@ -934,7 +1217,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
|
|
|
934
1217
|
// package.json
|
|
935
1218
|
var package_default = {
|
|
936
1219
|
name: "nimblebrain",
|
|
937
|
-
version: "0.
|
|
1220
|
+
version: "0.4.0",
|
|
938
1221
|
description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
|
|
939
1222
|
license: "Apache-2.0",
|
|
940
1223
|
type: "module",
|
|
@@ -1020,6 +1303,15 @@ async function readWorkspaces(deps, url) {
|
|
|
1020
1303
|
var START_TIMEOUT_MS = 15 * 60000;
|
|
1021
1304
|
var HEALTH_TIMEOUT_MS = 3 * 60000;
|
|
1022
1305
|
var asks = ({ deps, flags }) => deps.interactive && !flags.yes && !flags.json;
|
|
1306
|
+
var yes = (answer) => /^(y|yes)?$/i.test(answer.trim());
|
|
1307
|
+
function confirmOllamaStart(ctx, unasked) {
|
|
1308
|
+
return async (command) => {
|
|
1309
|
+
if (!asks(ctx))
|
|
1310
|
+
return unasked;
|
|
1311
|
+
const login = command.startsWith("brew services") ? " It then also starts at login." : "";
|
|
1312
|
+
return yes(await ctx.deps.prompt(`Ollama isn't running. Start it with \`${command}\`?${login} [Y/n] `));
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1023
1315
|
async function init(ctx) {
|
|
1024
1316
|
const { deps, flags, home } = ctx;
|
|
1025
1317
|
if (await readInstall(deps, home))
|
|
@@ -1035,10 +1327,7 @@ async function init(ctx) {
|
|
|
1035
1327
|
throw err;
|
|
1036
1328
|
if (err.code !== "CANCELLED" || consent !== "undecided")
|
|
1037
1329
|
await settleFailure(rec, home, consent, err);
|
|
1038
|
-
throw
|
|
1039
|
-
...err.detail,
|
|
1040
|
-
telemetry: field(consent, lockedHere(deps))
|
|
1041
|
-
});
|
|
1330
|
+
throw err.with({ telemetry: field(consent, invocation(deps, home), lockedHere(deps)) });
|
|
1042
1331
|
}
|
|
1043
1332
|
}
|
|
1044
1333
|
async function settleFailure(rec, home, consent, err) {
|
|
@@ -1056,7 +1345,8 @@ async function chooseConsent(ctx) {
|
|
|
1056
1345
|
if (!asks(ctx))
|
|
1057
1346
|
return "undecided";
|
|
1058
1347
|
const consent = parseAnswer(await ctx.deps.prompt(`${QUESTION} [Y/n] `));
|
|
1059
|
-
|
|
1348
|
+
const cli = invocation(ctx.deps, ctx.home);
|
|
1349
|
+
ctx.deps.say(consent === "on" ? `Sending anonymous usage data. Turn it off any time: ${cli} telemetry off` : `No usage data will be sent. Turn it on any time: ${cli} telemetry on`);
|
|
1060
1350
|
return consent;
|
|
1061
1351
|
}
|
|
1062
1352
|
async function install(ctx, consent, rec, begun) {
|
|
@@ -1070,36 +1360,43 @@ async function install(ctx, consent, rec, begun) {
|
|
|
1070
1360
|
const envText = await deps.readText(paths(home).env) ?? "";
|
|
1071
1361
|
const hasModel = hasKey(envText, keyVars(composeText)) || localModelOf(envText) !== undefined;
|
|
1072
1362
|
const local = flags.localModel ?? (!hasModel && asks(ctx) && takesLocalModel(composeText) ? await chooseModelSource(deps) : undefined);
|
|
1363
|
+
let ollamaStarted;
|
|
1073
1364
|
if (local)
|
|
1074
|
-
await useLocalModel(ctx, composeText, local);
|
|
1365
|
+
ollamaStarted = (await useLocalModel(ctx, composeText, local)).started;
|
|
1075
1366
|
else if (!hasModel && asks(ctx))
|
|
1076
1367
|
await enterKey(ctx, false);
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1368
|
+
return carryingStarted(ollamaStarted, async () => {
|
|
1369
|
+
deps.say(`Starting NimbleBrain ${tag}. The first start downloads about 2 GB of images.`);
|
|
1370
|
+
await start(deps, home, flags.port);
|
|
1371
|
+
const state = {
|
|
1372
|
+
version: tag.replace(/^v/, ""),
|
|
1373
|
+
port: flags.port,
|
|
1374
|
+
project
|
|
1375
|
+
};
|
|
1376
|
+
await writeState(deps, home, state);
|
|
1377
|
+
const manual = await connectChosenAgent(ctx, state);
|
|
1378
|
+
if (state.agent)
|
|
1379
|
+
rec.record("cli.agent_connected", { agent: state.agent });
|
|
1380
|
+
const result = {
|
|
1381
|
+
...await status(deps, home),
|
|
1382
|
+
manual,
|
|
1383
|
+
ollama_started: ollamaStarted
|
|
1384
|
+
};
|
|
1385
|
+
const finalEnv = await deps.readText(paths(home).env) ?? "";
|
|
1386
|
+
rec.record("cli.init_completed", {
|
|
1387
|
+
duration_ms: Date.now() - begun,
|
|
1388
|
+
model_key: result.model_key,
|
|
1389
|
+
provider: localModelOf(finalEnv) ? "ollama" : keyProvider(finalEnv, composeText),
|
|
1390
|
+
agent: state.agent ?? null
|
|
1100
1391
|
});
|
|
1101
|
-
|
|
1102
|
-
|
|
1392
|
+
await rec.settle(home, consent);
|
|
1393
|
+
if (result.model_key === "missing" && !result.local_model) {
|
|
1394
|
+
throw new CliError("MODEL_KEY_MISSING", "NimbleBrain is running; chat needs a model key.", {
|
|
1395
|
+
...result
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
return { ...result };
|
|
1399
|
+
});
|
|
1103
1400
|
}
|
|
1104
1401
|
async function confirmStart(ctx, tag) {
|
|
1105
1402
|
if (!asks(ctx))
|
|
@@ -1125,10 +1422,25 @@ async function connectChosenAgent(ctx, state) {
|
|
|
1125
1422
|
return conn.manual;
|
|
1126
1423
|
}
|
|
1127
1424
|
async function up(ctx) {
|
|
1425
|
+
const { deps, home } = ctx;
|
|
1128
1426
|
const install = await requireInstall(ctx);
|
|
1129
|
-
await
|
|
1130
|
-
|
|
1427
|
+
const local = localModelOf(await deps.readText(paths(home).env) ?? "");
|
|
1428
|
+
const ollama = local ? await ensureOllama(deps, confirmOllamaStart(ctx, true)).catch((err) => {
|
|
1429
|
+
if (err instanceof CliError)
|
|
1430
|
+
return err;
|
|
1431
|
+
throw err;
|
|
1432
|
+
}) : undefined;
|
|
1433
|
+
const started = ollama instanceof CliError ? ollama.detail.ollama_started : ollama?.started;
|
|
1434
|
+
const result = await carryingStarted(started, async () => {
|
|
1435
|
+
await start(deps, home, install.port);
|
|
1436
|
+
return status(deps, home);
|
|
1437
|
+
});
|
|
1438
|
+
if (ollama instanceof CliError) {
|
|
1439
|
+
throw ollama.with({ ...result }, `NimbleBrain is running, but ${lowerFirst(ollama.message)}`);
|
|
1440
|
+
}
|
|
1441
|
+
return { ...result, ollama_started: ollama?.started };
|
|
1131
1442
|
}
|
|
1443
|
+
var lowerFirst = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
1132
1444
|
async function down(ctx) {
|
|
1133
1445
|
await requireInstall(ctx);
|
|
1134
1446
|
const res = await compose(ctx.deps, ctx.home, ["down"]);
|
|
@@ -1156,8 +1468,10 @@ async function update(ctx) {
|
|
|
1156
1468
|
const tag = await runtimeTag(deps, ctx.flags.runtime);
|
|
1157
1469
|
const from = `v${install.version}`;
|
|
1158
1470
|
const order = compareVersions(tag, from);
|
|
1159
|
-
if (order === 0)
|
|
1160
|
-
|
|
1471
|
+
if (order === 0) {
|
|
1472
|
+
const skill_update = await refreshAgentSkill(deps, install);
|
|
1473
|
+
return { ...await status(deps, home), already: true, ...skill_update };
|
|
1474
|
+
}
|
|
1161
1475
|
if (order < 0) {
|
|
1162
1476
|
throw new CliError("USAGE", `${tag} is older than the installed ${from}; NimbleBrain does not move backwards.`);
|
|
1163
1477
|
}
|
|
@@ -1169,7 +1483,13 @@ async function update(ctx) {
|
|
|
1169
1483
|
throw startError(pull);
|
|
1170
1484
|
await start(deps, home, install.port);
|
|
1171
1485
|
await writeState(deps, home, { ...install, version: tag.replace(/^v/, "") });
|
|
1172
|
-
|
|
1486
|
+
const skill_update = await refreshAgentSkill(deps, install);
|
|
1487
|
+
return { ...await status(deps, home), from, ...skill_update };
|
|
1488
|
+
}
|
|
1489
|
+
async function refreshAgentSkill(deps, install) {
|
|
1490
|
+
if (!install.agent || install.agent === "none")
|
|
1491
|
+
return {};
|
|
1492
|
+
return { skill_update: await refreshSkill(deps, install.agent) };
|
|
1173
1493
|
}
|
|
1174
1494
|
async function uninstall(ctx) {
|
|
1175
1495
|
const { deps, flags, home } = ctx;
|
|
@@ -1213,7 +1533,7 @@ async function telemetry(ctx) {
|
|
|
1213
1533
|
await deps.writeText(p.env, setEnvLines(await deps.readText(p.env) ?? "", { NB_TELEMETRY_CONSENT: ctx.arg }), 384);
|
|
1214
1534
|
const rec = recorder2(deps, ctx.version, await reportId(deps, home));
|
|
1215
1535
|
await rec.settle(home, ctx.arg);
|
|
1216
|
-
return { ok: true, telemetry: field(ctx.arg) };
|
|
1536
|
+
return { ok: true, telemetry: field(ctx.arg, invocation(deps, home)) };
|
|
1217
1537
|
}
|
|
1218
1538
|
async function key(ctx) {
|
|
1219
1539
|
if (!ctx.deps.interactive) {
|
|
@@ -1250,9 +1570,18 @@ async function localModel(ctx) {
|
|
|
1250
1570
|
const install = await requireInstall(ctx);
|
|
1251
1571
|
const composeText = await ctx.deps.readText(paths(ctx.home).compose) ?? "";
|
|
1252
1572
|
const model = ctx.arg ?? ctx.flags.localModel ?? DEFAULT_LOCAL_MODEL;
|
|
1253
|
-
const name = await useLocalModel(ctx, composeText, model);
|
|
1254
|
-
await start(ctx.deps, ctx.home, install.port);
|
|
1255
|
-
return { ok: true, local_model: name };
|
|
1573
|
+
const { name, started } = await useLocalModel(ctx, composeText, model);
|
|
1574
|
+
await carryingStarted(started, () => start(ctx.deps, ctx.home, install.port));
|
|
1575
|
+
return { ok: true, local_model: name, ollama_started: started };
|
|
1576
|
+
}
|
|
1577
|
+
async function carryingStarted(started, next) {
|
|
1578
|
+
try {
|
|
1579
|
+
return await next();
|
|
1580
|
+
} catch (err) {
|
|
1581
|
+
if (err instanceof CliError && started)
|
|
1582
|
+
throw err.with({ ollama_started: started });
|
|
1583
|
+
throw err;
|
|
1584
|
+
}
|
|
1256
1585
|
}
|
|
1257
1586
|
async function chooseModelSource(deps) {
|
|
1258
1587
|
deps.say("NimbleBrain's own agents need a model: a hosted one with your API key, or a local one through Ollama (free, slower; https://docs.nimblebrain.ai/config/local-models/).");
|
|
@@ -1264,16 +1593,18 @@ async function useLocalModel(ctx, composeText, model) {
|
|
|
1264
1593
|
if (!takesLocalModel(composeText)) {
|
|
1265
1594
|
throw new CliError("RUNTIME_UNSUPPORTED", "This release's runtime takes no local model; a newer release does.");
|
|
1266
1595
|
}
|
|
1267
|
-
const values = await setupLocalModel(deps, model,
|
|
1596
|
+
const { values, started } = await setupLocalModel(deps, model, {
|
|
1597
|
+
start: confirmOllamaStart(ctx, true),
|
|
1598
|
+
pull: (m) => confirmPull(ctx, m)
|
|
1599
|
+
});
|
|
1268
1600
|
const p = paths(home);
|
|
1269
1601
|
await deps.writeText(p.env, setEnvLines(await deps.readText(p.env) ?? "", values), 384);
|
|
1270
|
-
return values.NB_LOCAL_MODEL ?? model;
|
|
1602
|
+
return { name: values.NB_LOCAL_MODEL ?? model, started };
|
|
1271
1603
|
}
|
|
1272
1604
|
async function confirmPull(ctx, model) {
|
|
1273
1605
|
if (!asks(ctx))
|
|
1274
1606
|
return true;
|
|
1275
|
-
|
|
1276
|
-
return answer === "" || answer === "y" || answer === "yes";
|
|
1607
|
+
return yes(await ctx.deps.prompt(`Download ${model} with Ollama? It is several GB. [Y/n] `));
|
|
1277
1608
|
}
|
|
1278
1609
|
async function chooseAgent(deps) {
|
|
1279
1610
|
deps.say("A coding agent you connect can use NimbleBrain's tools. NimbleBrain's own agents still run on the model key above.");
|
|
@@ -1460,64 +1791,136 @@ async function call(t, args, timeoutMs) {
|
|
|
1460
1791
|
return body.structuredContent ?? {};
|
|
1461
1792
|
}
|
|
1462
1793
|
|
|
1463
|
-
// src/
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1794
|
+
// src/updates.ts
|
|
1795
|
+
import { join as join6 } from "node:path";
|
|
1796
|
+
var NPM_LATEST = "https://registry.npmjs.org/nimblebrain/latest";
|
|
1797
|
+
var FRESH_MS = 24 * 60 * 60000;
|
|
1798
|
+
var LOOKUP_TIMEOUT_MS = 5000;
|
|
1799
|
+
var NOTICE_WAIT_MS = 1000;
|
|
1800
|
+
var SEMVER = /^v?\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
1801
|
+
function cachePath(deps) {
|
|
1802
|
+
const xdg = deps.env.XDG_CACHE_HOME?.trim();
|
|
1803
|
+
const base = xdg?.startsWith("/") ? xdg : join6(deps.home, ".cache");
|
|
1804
|
+
return join6(base, "nimblebrain", "update-check.json");
|
|
1805
|
+
}
|
|
1806
|
+
function updateCheckOff(deps) {
|
|
1807
|
+
const ci = deps.env.CI?.trim().toLowerCase();
|
|
1808
|
+
return ci !== undefined && ci !== "" && ci !== "false" && ci !== "0" || deps.env.NIMBLEBRAIN_NO_UPDATE_CHECK === "1" || doNotTrack(deps);
|
|
1809
|
+
}
|
|
1810
|
+
function startUpdateCheck(deps) {
|
|
1811
|
+
if (updateCheckOff(deps))
|
|
1812
|
+
return;
|
|
1813
|
+
const cached = readCache(deps);
|
|
1814
|
+
let settled = false;
|
|
1815
|
+
const refreshed = cached.then(async (old) => {
|
|
1816
|
+
if (old && Date.now() - old.checked_at < FRESH_MS)
|
|
1817
|
+
return old;
|
|
1818
|
+
return await lookup(deps, old) ?? old;
|
|
1819
|
+
});
|
|
1820
|
+
refreshed.then(() => {
|
|
1821
|
+
settled = true;
|
|
1822
|
+
});
|
|
1823
|
+
return {
|
|
1824
|
+
async known(waitMs) {
|
|
1825
|
+
const old = await cached;
|
|
1826
|
+
if (settled)
|
|
1827
|
+
return refreshed;
|
|
1828
|
+
const deadline = waitMs > 0 ? deps.sleep(waitMs).then(() => old) : Promise.resolve(old);
|
|
1829
|
+
return Promise.race([refreshed, deadline]);
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
async function readCache(deps) {
|
|
1834
|
+
try {
|
|
1835
|
+
const raw = JSON.parse(await deps.readText(cachePath(deps)) ?? "null");
|
|
1836
|
+
if (typeof raw?.checked_at !== "number")
|
|
1837
|
+
return;
|
|
1838
|
+
return {
|
|
1839
|
+
checked_at: raw.checked_at,
|
|
1840
|
+
cli: version(raw.cli),
|
|
1841
|
+
runtime: version(raw.runtime)
|
|
1842
|
+
};
|
|
1843
|
+
} catch {
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
async function lookup(deps, old) {
|
|
1848
|
+
try {
|
|
1849
|
+
const [npm, runtime] = await Promise.all([
|
|
1850
|
+
deps.getJson(NPM_LATEST, LOOKUP_TIMEOUT_MS),
|
|
1851
|
+
newestRuntime(deps, LOOKUP_TIMEOUT_MS).catch(() => {
|
|
1852
|
+
return;
|
|
1853
|
+
})
|
|
1854
|
+
]);
|
|
1855
|
+
const cli = npm?.status === 200 ? version(npm.body?.version) : undefined;
|
|
1856
|
+
if (!cli && !runtime)
|
|
1857
|
+
return;
|
|
1858
|
+
const known = {
|
|
1859
|
+
checked_at: Date.now(),
|
|
1860
|
+
cli: cli ?? old?.cli,
|
|
1861
|
+
runtime: runtime ?? old?.runtime
|
|
1862
|
+
};
|
|
1863
|
+
await deps.writeText(cachePath(deps), `${JSON.stringify(known)}
|
|
1864
|
+
`);
|
|
1865
|
+
return known;
|
|
1866
|
+
} catch {
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
function version(value) {
|
|
1871
|
+
return typeof value === "string" && SEMVER.test(value) ? value : undefined;
|
|
1872
|
+
}
|
|
1873
|
+
function updatesField(known, cliVersion, runtimeVersion) {
|
|
1874
|
+
const updates = {};
|
|
1875
|
+
if (known?.cli)
|
|
1876
|
+
updates.cli = { current: cliVersion, latest: known.cli };
|
|
1877
|
+
if (known?.runtime && runtimeVersion) {
|
|
1878
|
+
updates.runtime = { current: runtimeVersion, latest: known.runtime.replace(/^v/, "") };
|
|
1879
|
+
}
|
|
1880
|
+
return updates.cli || updates.runtime ? updates : undefined;
|
|
1881
|
+
}
|
|
1882
|
+
function noticeLines(updates, withRuntime, run = "npx nimblebrain") {
|
|
1883
|
+
const lines = [];
|
|
1884
|
+
const cli = updates?.cli;
|
|
1885
|
+
if (cli && compareVersions(cli.latest, cli.current) > 0) {
|
|
1886
|
+
lines.push(`nimblebrain ${cli.latest} is available (you have ${cli.current}): npx nimblebrain@latest`);
|
|
1887
|
+
}
|
|
1888
|
+
const rt = updates?.runtime;
|
|
1889
|
+
if (withRuntime && rt && compareVersions(rt.latest, rt.current) > 0) {
|
|
1890
|
+
lines.push(`NimbleBrain v${rt.latest} is available (you have v${rt.current}): ${run} update`);
|
|
1891
|
+
}
|
|
1892
|
+
return lines;
|
|
1893
|
+
}
|
|
1482
1894
|
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
--yes, -y Take every default; implied when no terminal is attached
|
|
1486
|
-
--agent <name> claude-code, cursor, codex or none
|
|
1487
|
-
--port <n> Local port (default 27246)
|
|
1488
|
-
--home <dir> Where the install lives (default ~/.nimblebrain-local, or NIMBLEBRAIN_HOME);
|
|
1489
|
-
a home with another folder name is a separate install
|
|
1490
|
-
--provider <name> The model provider for key (default anthropic)
|
|
1491
|
-
--local-model <model> init: run on this Ollama model instead of a hosted key
|
|
1492
|
-
--runtime <tag> The NimbleBrain release to install or update to (default the newest)
|
|
1493
|
-
--telemetry <on|off> The person's answer to sending anonymous usage data; without it, init asks or leaves it undecided
|
|
1494
|
-
--name <name> For mcp add: the server name (default from the server's card, else its URL)
|
|
1495
|
-
--workspace <id> For mcp: the workspace (default the one init connected, the first in status)
|
|
1496
|
-
--help, --version
|
|
1497
|
-
`;
|
|
1895
|
+
// src/main.ts
|
|
1896
|
+
var RUNTIME_NOTICE = ["status", "up", "init"];
|
|
1498
1897
|
async function run(argv, deps) {
|
|
1499
1898
|
const json = wantsJson(argv);
|
|
1500
1899
|
let parsed;
|
|
1501
1900
|
try {
|
|
1502
1901
|
parsed = parse(argv);
|
|
1503
1902
|
} catch (err) {
|
|
1504
|
-
return render(toFailure(err), json);
|
|
1903
|
+
return render(toFailure(err), json, BARE_CLI);
|
|
1904
|
+
}
|
|
1905
|
+
if (parsed.kind === "help") {
|
|
1906
|
+
return parsed.flags.json ? render(describe(VERSION2), true, BARE_CLI) : { stdout: helpText(VERSION2), code: 0 };
|
|
1505
1907
|
}
|
|
1506
|
-
if (parsed.kind === "help")
|
|
1507
|
-
return { stdout: HELP, code: 0 };
|
|
1508
1908
|
if (parsed.kind === "version") {
|
|
1509
|
-
return parsed.flags.json ? render({ ok: true, version: VERSION2 }, true) : { stdout: `${VERSION2}
|
|
1909
|
+
return parsed.flags.json ? render({ ok: true, version: VERSION2 }, true, BARE_CLI) : { stdout: `${VERSION2}
|
|
1510
1910
|
`, code: 0 };
|
|
1511
1911
|
}
|
|
1512
1912
|
const { command, flags, arg, operand } = parsed;
|
|
1913
|
+
const check = startUpdateCheck(deps);
|
|
1513
1914
|
const home = installHome(deps, flags.home);
|
|
1915
|
+
const cli = invocation(deps, home);
|
|
1514
1916
|
let result;
|
|
1515
1917
|
try {
|
|
1516
1918
|
switch (command) {
|
|
1517
1919
|
case "doctor": {
|
|
1518
1920
|
const install = await readInstall(deps, home);
|
|
1519
1921
|
const ours = install !== undefined && install.port === flags.port && await isHealthy(deps, flags.port);
|
|
1520
|
-
|
|
1922
|
+
const startOllama = confirmOllamaStart({ deps, flags }, false);
|
|
1923
|
+
result = { ...await doctorInstall(deps, home, flags.port, ours, startOllama) };
|
|
1521
1924
|
break;
|
|
1522
1925
|
}
|
|
1523
1926
|
case "status":
|
|
@@ -1543,26 +1946,50 @@ async function run(argv, deps) {
|
|
|
1543
1946
|
} catch (err) {
|
|
1544
1947
|
result = toFailure(err);
|
|
1545
1948
|
}
|
|
1949
|
+
if (!result.ok)
|
|
1950
|
+
result = { ...result, fix: forInstall(result.fix, cli) };
|
|
1546
1951
|
if (!["init", "telemetry", "uninstall", "doctor"].includes(command)) {
|
|
1547
1952
|
await settleWaiting(deps, home, VERSION2);
|
|
1548
1953
|
}
|
|
1549
|
-
return
|
|
1954
|
+
return answerWithUpdates(result, command, flags.json, check, cli);
|
|
1955
|
+
}
|
|
1956
|
+
async function answerWithUpdates(result, command, json, check, cli) {
|
|
1957
|
+
if (!check)
|
|
1958
|
+
return render(result, json, cli, command);
|
|
1959
|
+
const runtime = isStatusShaped(result) ? result.version : undefined;
|
|
1960
|
+
const updates = updatesField(await check.known(0), VERSION2, runtime);
|
|
1961
|
+
const answer = render(updates && runtime !== undefined ? { ...result, updates } : result, json, cli, command);
|
|
1962
|
+
const notices = async () => {
|
|
1963
|
+
const known = await check.known(NOTICE_WAIT_MS);
|
|
1964
|
+
if (json)
|
|
1965
|
+
return;
|
|
1966
|
+
const lines = noticeLines(updatesField(known, VERSION2, runtime), RUNTIME_NOTICE.includes(command), cli);
|
|
1967
|
+
return lines.length > 0 ? `${lines.join(`
|
|
1968
|
+
`)}
|
|
1969
|
+
` : undefined;
|
|
1970
|
+
};
|
|
1971
|
+
return { ...answer, notices };
|
|
1972
|
+
}
|
|
1973
|
+
function isStatusShaped(result) {
|
|
1974
|
+
return typeof result.version === "string" && "health" in result && "url" in result && "workspaces" in result;
|
|
1550
1975
|
}
|
|
1551
|
-
async function doctorInstall(deps, home, port, ours) {
|
|
1976
|
+
async function doctorInstall(deps, home, port, ours, startOllama) {
|
|
1552
1977
|
const machine = await doctor(deps, port, ours);
|
|
1553
1978
|
const model = localModelOf(await deps.readText(paths(home).env) ?? "");
|
|
1554
1979
|
if (!model)
|
|
1555
1980
|
return machine;
|
|
1556
1981
|
try {
|
|
1557
|
-
|
|
1982
|
+
const local = await checkLocalModel(deps, model, startOllama);
|
|
1983
|
+
return {
|
|
1984
|
+
...machine,
|
|
1985
|
+
checks: [...machine.checks, ...local.checks],
|
|
1986
|
+
ollama_started: local.started
|
|
1987
|
+
};
|
|
1558
1988
|
} catch (err) {
|
|
1559
1989
|
if (!(err instanceof CliError))
|
|
1560
1990
|
throw err;
|
|
1561
1991
|
const local = err.detail.checks ?? [];
|
|
1562
|
-
throw
|
|
1563
|
-
...err.detail,
|
|
1564
|
-
checks: [...machine.checks, ...local]
|
|
1565
|
-
});
|
|
1992
|
+
throw err.with({ checks: [...machine.checks, ...local] });
|
|
1566
1993
|
}
|
|
1567
1994
|
}
|
|
1568
1995
|
async function isHealthy(deps, port) {
|
|
@@ -1574,7 +2001,7 @@ function toFailure(err) {
|
|
|
1574
2001
|
return failure(err);
|
|
1575
2002
|
return failure(new CliError("USAGE", err instanceof Error ? err.message : String(err)));
|
|
1576
2003
|
}
|
|
1577
|
-
function render(result, json, command) {
|
|
2004
|
+
function render(result, json, cli, command) {
|
|
1578
2005
|
const code = exitCodeFor(result);
|
|
1579
2006
|
if (json)
|
|
1580
2007
|
return { stdout: `${JSON.stringify(result)}
|
|
@@ -1583,7 +2010,7 @@ function render(result, json, command) {
|
|
|
1583
2010
|
return { stdout: `error: ${result.message}
|
|
1584
2011
|
fix: ${result.fix}
|
|
1585
2012
|
`, code };
|
|
1586
|
-
const lines = isStatus(result) ? statusLines(result, command) : genericLines(result);
|
|
2013
|
+
const lines = isStatus(result) ? statusLines(result, cli, command) : genericLines(result);
|
|
1587
2014
|
return { stdout: `${lines.join(`
|
|
1588
2015
|
`)}
|
|
1589
2016
|
`, code };
|
|
@@ -1596,22 +2023,22 @@ var AGENT_NAMES = {
|
|
|
1596
2023
|
cursor: "Cursor",
|
|
1597
2024
|
codex: "Codex"
|
|
1598
2025
|
};
|
|
1599
|
-
function statusLines(r, command) {
|
|
2026
|
+
function statusLines(r, cli, command) {
|
|
1600
2027
|
const lines = [
|
|
1601
2028
|
...changeLines(r),
|
|
1602
2029
|
` NimbleBrain ${r.version.startsWith("v") ? r.version : `v${r.version}`}: ${r.health === "ok" ? "running" : "stopped"} at ${r.url}`,
|
|
1603
2030
|
...r.workspaces.map((w) => ` workspace ${w.name}: ${w.mcp}`),
|
|
1604
|
-
r.local_model ? ` model: ${r.local_model} on Ollama (NimbleBrain's own agents use it)` : ` model key: ${r.model_key === "set" ? "set (NimbleBrain's own agents use it)" :
|
|
2031
|
+
r.local_model ? ` model: ${r.local_model} on Ollama (NimbleBrain's own agents use it)` : ` model key: ${r.model_key === "set" ? "set (NimbleBrain's own agents use it)" : `missing (run ${cli} key)`}`
|
|
1605
2032
|
];
|
|
1606
2033
|
const agent = r.agent.connected;
|
|
1607
2034
|
lines.push(...agentLines(r));
|
|
1608
2035
|
if (!r.host_loopback)
|
|
1609
|
-
lines.push(
|
|
2036
|
+
lines.push(` servers on this machine: not reachable until ${cli} update`);
|
|
1610
2037
|
lines.push(telemetryLine(r.telemetry));
|
|
1611
2038
|
lines.push(` CLI ${r.cli_version}`);
|
|
1612
2039
|
if (command === "init" && !r.already && r.health === "ok") {
|
|
1613
2040
|
const ask = agent ? `, or ask ${AGENT_NAMES[agent] ?? agent} what NimbleBrain can do` : "";
|
|
1614
|
-
lines.push("", `Next: open ${r.url}${ask}. Stop it with
|
|
2041
|
+
lines.push("", `Next: open ${r.url}${ask}. Stop it with ${cli} down.`);
|
|
1615
2042
|
}
|
|
1616
2043
|
return lines;
|
|
1617
2044
|
}
|
|
@@ -1623,10 +2050,19 @@ function agentLines(r) {
|
|
|
1623
2050
|
const lines = [
|
|
1624
2051
|
` ${name} can use NimbleBrain's tools (it loads them when its next session starts)`
|
|
1625
2052
|
];
|
|
2053
|
+
const refresh = r.skill_update && SKILL_REFRESH_LINES[r.skill_update];
|
|
2054
|
+
if (refresh)
|
|
2055
|
+
lines.push(` skill: ${refresh}`);
|
|
1626
2056
|
if (!r.agent.skill)
|
|
1627
2057
|
lines.push(` skill: not installed; add it with npx skills add nimblebraininc/skills --skill nimblebrain --agent ${agent} -g`);
|
|
1628
2058
|
return lines;
|
|
1629
2059
|
}
|
|
2060
|
+
var SKILL_REFRESH_LINES = {
|
|
2061
|
+
updated: "updated to the newest nimblebrain skill",
|
|
2062
|
+
unchanged: "the nimblebrain skill is current",
|
|
2063
|
+
failed: "could not refresh the nimblebrain skill; try npx skills update nimblebrain -g",
|
|
2064
|
+
not_installed: undefined
|
|
2065
|
+
};
|
|
1630
2066
|
function changeLines(r) {
|
|
1631
2067
|
if (r.already)
|
|
1632
2068
|
return [" already installed"];
|
|
@@ -1659,18 +2095,24 @@ function field2(key, value) {
|
|
|
1659
2095
|
}
|
|
1660
2096
|
return [` ${key}: ${String(value)}`];
|
|
1661
2097
|
}
|
|
1662
|
-
function interrupted(argv, exitCode) {
|
|
2098
|
+
function interrupted(argv, exitCode, deps) {
|
|
1663
2099
|
const err = new CliError("INTERRUPTED", `The CLI stopped before it answered (exit code ${exitCode}).`, { exit_code: exitCode });
|
|
1664
|
-
|
|
2100
|
+
let cli = BARE_CLI;
|
|
2101
|
+
try {
|
|
2102
|
+
cli = invocation(deps, installHome(deps, parse(argv).flags.home));
|
|
2103
|
+
} catch {}
|
|
2104
|
+
const result = failure(err);
|
|
2105
|
+
return render({ ...result, fix: forInstall(result.fix, cli) }, wantsJson(argv), cli);
|
|
1665
2106
|
}
|
|
1666
2107
|
|
|
1667
2108
|
// src/bin.ts
|
|
1668
2109
|
var argv = process.argv.slice(2);
|
|
2110
|
+
var deps = realDeps();
|
|
1669
2111
|
var answered = false;
|
|
1670
2112
|
process.on("exit", (code) => {
|
|
1671
2113
|
if (answered)
|
|
1672
2114
|
return;
|
|
1673
|
-
const out = interrupted(argv, code);
|
|
2115
|
+
const out = interrupted(argv, code, deps);
|
|
1674
2116
|
writeSync(1, out.stdout);
|
|
1675
2117
|
writeSync(2, `nimblebrain: stopped before answering (exit code ${code})
|
|
1676
2118
|
`);
|
|
@@ -1683,7 +2125,10 @@ for (const [signal, n] of [
|
|
|
1683
2125
|
]) {
|
|
1684
2126
|
process.on(signal, () => process.exit(128 + n));
|
|
1685
2127
|
}
|
|
1686
|
-
var
|
|
1687
|
-
writeSync(1, stdout);
|
|
2128
|
+
var answer = await run(argv, deps);
|
|
2129
|
+
writeSync(1, answer.stdout);
|
|
1688
2130
|
answered = true;
|
|
1689
|
-
|
|
2131
|
+
var notices = await answer.notices?.();
|
|
2132
|
+
if (notices)
|
|
2133
|
+
writeSync(2, notices);
|
|
2134
|
+
process.exit(answer.code);
|
package/package.json
CHANGED