nimblebrain 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nimblebrain.js +287 -109
- package/package.json +1 -1
package/dist/nimblebrain.js
CHANGED
|
@@ -179,6 +179,10 @@ var ERRORS = {
|
|
|
179
179
|
RUNTIME_UNSUPPORTED: "Pass a newer runtime with --runtime, or leave it out to install the newest release.",
|
|
180
180
|
NOT_RUNNING: "Run `npx nimblebrain up`, then run this again.",
|
|
181
181
|
TELEMETRY_LOCKED: "Nothing to change: DO_NOT_TRACK or the install's configuration decides telemetry here.",
|
|
182
|
+
LOCAL_MODEL_UNREACHABLE: "Install Ollama (https://ollama.com/download) and start it, then run this again.",
|
|
183
|
+
LOCAL_MODEL_MISSING: "Download the model with `ollama pull <model>`, or check that Ollama has disk space, then run this again.",
|
|
184
|
+
LOCAL_MODEL_NO_TOOLS: "Choose a model with tool calling, such as gemma4:e4b; https://docs.nimblebrain.ai/config/local-models/ lists the ones run with NimbleBrain.",
|
|
185
|
+
LOCAL_CONTEXT_SMALL: "Run `npx nimblebrain local-model` to prepare the model again with a 32k context window.",
|
|
182
186
|
INTERRUPTED: "Run `npx nimblebrain status` to see what is in place, then run the same command again."
|
|
183
187
|
};
|
|
184
188
|
|
|
@@ -213,7 +217,8 @@ var COMMANDS = [
|
|
|
213
217
|
"logs",
|
|
214
218
|
"update",
|
|
215
219
|
"uninstall",
|
|
216
|
-
"telemetry"
|
|
220
|
+
"telemetry",
|
|
221
|
+
"local-model"
|
|
217
222
|
];
|
|
218
223
|
var AGENTS = ["claude-code", "cursor", "codex", "none"];
|
|
219
224
|
var DEFAULT_PORT = 27246;
|
|
@@ -224,6 +229,7 @@ var options = {
|
|
|
224
229
|
port: { type: "string" },
|
|
225
230
|
home: { type: "string" },
|
|
226
231
|
provider: { type: "string" },
|
|
232
|
+
"local-model": { type: "string" },
|
|
227
233
|
runtime: { type: "string" },
|
|
228
234
|
telemetry: { type: "string" },
|
|
229
235
|
help: { type: "boolean", short: "h" },
|
|
@@ -251,6 +257,7 @@ function parse(argv) {
|
|
|
251
257
|
port,
|
|
252
258
|
home: values.home,
|
|
253
259
|
provider: values.provider,
|
|
260
|
+
localModel: values["local-model"],
|
|
254
261
|
runtime: values.runtime,
|
|
255
262
|
telemetry
|
|
256
263
|
};
|
|
@@ -269,7 +276,7 @@ function telemetryFlag(value) {
|
|
|
269
276
|
throw new CliError("USAGE", `--telemetry must be on or off, not "${value}".`);
|
|
270
277
|
}
|
|
271
278
|
function command(name, positionals) {
|
|
272
|
-
const maxArgs = name === "telemetry" ? 2 : 1;
|
|
279
|
+
const maxArgs = name === "telemetry" || name === "local-model" ? 2 : 1;
|
|
273
280
|
if (positionals.length > maxArgs)
|
|
274
281
|
throw new CliError("USAGE", `Unexpected argument "${positionals[maxArgs]}".`);
|
|
275
282
|
if (!COMMANDS.includes(name))
|
|
@@ -290,6 +297,114 @@ function wantsJson(argv) {
|
|
|
290
297
|
return argv.includes("--json");
|
|
291
298
|
}
|
|
292
299
|
|
|
300
|
+
// src/compose.ts
|
|
301
|
+
import { join as join2 } from "node:path";
|
|
302
|
+
var PROJECT = "nimblebrain-local";
|
|
303
|
+
var VOLUME = `${PROJECT}_workspace`;
|
|
304
|
+
var RAW = "https://raw.githubusercontent.com/NimbleBrainInc/nimblebrain";
|
|
305
|
+
async function fetchCompose(deps, tag) {
|
|
306
|
+
const res = await deps.getText(`${RAW}/${tag}/docker-compose.yml`, 15000);
|
|
307
|
+
if (!res)
|
|
308
|
+
throw new CliError("NETWORK", `Could not download the Compose file for ${tag}.`);
|
|
309
|
+
if (res.status === 404) {
|
|
310
|
+
throw new CliError("RUNTIME_UNSUPPORTED", `NimbleBrain ${tag} has no Compose file to install.`);
|
|
311
|
+
}
|
|
312
|
+
if (res.status !== 200) {
|
|
313
|
+
throw new CliError("NETWORK", `Downloading the Compose file for ${tag} answered ${res.status}.`);
|
|
314
|
+
}
|
|
315
|
+
if (!res.body.includes("${NIMBLEBRAIN_TAG") || !res.body.includes("NIMBLEBRAIN_WEB_PORT")) {
|
|
316
|
+
throw new CliError("RUNTIME_UNSUPPORTED", `NimbleBrain ${tag}'s Compose file does not take its image tag and port from .env.`);
|
|
317
|
+
}
|
|
318
|
+
return res.body;
|
|
319
|
+
}
|
|
320
|
+
function keyVars(composeText) {
|
|
321
|
+
return [
|
|
322
|
+
...new Set([...composeText.matchAll(/\b([A-Z][A-Z0-9_]*_API_KEY)=\$\{\1\b/g)].map((m) => m[1] ?? ""))
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
function asksConsent(composeText) {
|
|
326
|
+
return composeText.includes("NB_TELEMETRY_CONSENT");
|
|
327
|
+
}
|
|
328
|
+
function providers(composeText) {
|
|
329
|
+
return Object.fromEntries(keyVars(composeText).map((v) => [
|
|
330
|
+
v.replace(/_API_KEY$/, "").replace(/_GENERATIVE_AI$/, "").toLowerCase(),
|
|
331
|
+
v
|
|
332
|
+
]));
|
|
333
|
+
}
|
|
334
|
+
function composeEnv(deps, vars) {
|
|
335
|
+
const env = { ...deps.env };
|
|
336
|
+
for (const v of [
|
|
337
|
+
...vars,
|
|
338
|
+
"NIMBLEBRAIN_TAG",
|
|
339
|
+
"NIMBLEBRAIN_WEB_PORT",
|
|
340
|
+
"COMPOSE_PROJECT_NAME",
|
|
341
|
+
"NB_TELEMETRY_KEY",
|
|
342
|
+
"NB_TELEMETRY_ID",
|
|
343
|
+
"NB_TELEMETRY_CONSENT",
|
|
344
|
+
"NB_LOCAL_MODEL_URL",
|
|
345
|
+
"NB_LOCAL_MODEL",
|
|
346
|
+
"NB_LOCAL_MODEL_CONTEXT"
|
|
347
|
+
]) {
|
|
348
|
+
delete env[v];
|
|
349
|
+
}
|
|
350
|
+
return env;
|
|
351
|
+
}
|
|
352
|
+
async function compose(deps, home, args, timeoutMs = 120000) {
|
|
353
|
+
const vars = keyVars(await deps.readText(paths(home).compose) ?? "");
|
|
354
|
+
return deps.exec("docker", ["compose", ...args], {
|
|
355
|
+
cwd: home,
|
|
356
|
+
env: composeEnv(deps, vars),
|
|
357
|
+
timeoutMs
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function startError(res) {
|
|
361
|
+
const text = `${res.stderr}
|
|
362
|
+
${res.stdout}`;
|
|
363
|
+
const last = text.trim().split(`
|
|
364
|
+
`).filter((l) => l.trim()).pop() ?? "Compose failed.";
|
|
365
|
+
if (/no such host|timeout|TLS handshake|connection refused|network is unreachable/i.test(text)) {
|
|
366
|
+
return new CliError("NETWORK", last);
|
|
367
|
+
}
|
|
368
|
+
if (/port is already allocated|address already in use/i.test(text)) {
|
|
369
|
+
return new CliError("PORT_IN_USE", last);
|
|
370
|
+
}
|
|
371
|
+
return new CliError("START_FAILED", last);
|
|
372
|
+
}
|
|
373
|
+
function setEnvLines(text, values) {
|
|
374
|
+
const lines = text === "" ? [] : text.replace(/\n$/, "").split(`
|
|
375
|
+
`);
|
|
376
|
+
const seen = new Set;
|
|
377
|
+
const out = lines.map((line) => {
|
|
378
|
+
const name = line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1];
|
|
379
|
+
if (name && name in values) {
|
|
380
|
+
seen.add(name);
|
|
381
|
+
return `${name}=${values[name]}`;
|
|
382
|
+
}
|
|
383
|
+
return line;
|
|
384
|
+
});
|
|
385
|
+
for (const [name, value] of Object.entries(values))
|
|
386
|
+
if (!seen.has(name))
|
|
387
|
+
out.push(`${name}=${value}`);
|
|
388
|
+
return `${out.join(`
|
|
389
|
+
`)}
|
|
390
|
+
`;
|
|
391
|
+
}
|
|
392
|
+
function keyProvider(envText, composeText) {
|
|
393
|
+
const set = Object.entries(providers(composeText)).find(([, v]) => hasKey(envText, [v]));
|
|
394
|
+
return set ? set[0] : null;
|
|
395
|
+
}
|
|
396
|
+
function hasKey(envText, vars) {
|
|
397
|
+
return vars.some((v) => new RegExp(`^${v}=\\S`, "m").test(envText));
|
|
398
|
+
}
|
|
399
|
+
var paths = (home) => ({
|
|
400
|
+
compose: join2(home, "docker-compose.yml"),
|
|
401
|
+
env: join2(home, ".env"),
|
|
402
|
+
instance: join2(home, "instance.json"),
|
|
403
|
+
install: join2(home, "install.json")
|
|
404
|
+
});
|
|
405
|
+
var INSTANCE_JSON = `${JSON.stringify({ auth: { adapter: "dev" } }, null, 2)}
|
|
406
|
+
`;
|
|
407
|
+
|
|
293
408
|
// src/doctor.ts
|
|
294
409
|
var SUPPORTED_ARCH = ["x86_64", "amd64", "aarch64", "arm64"];
|
|
295
410
|
var MIN_MEMORY = 2 * 1024 ** 3;
|
|
@@ -377,7 +492,7 @@ function gib(bytes) {
|
|
|
377
492
|
}
|
|
378
493
|
|
|
379
494
|
// src/agents.ts
|
|
380
|
-
import { join as
|
|
495
|
+
import { join as join3 } from "node:path";
|
|
381
496
|
var SERVER_NAME = "nimblebrain";
|
|
382
497
|
async function connectAgent(deps, agent, mcpUrl) {
|
|
383
498
|
if (agent === "none")
|
|
@@ -410,7 +525,7 @@ async function connectAgent(deps, agent, mcpUrl) {
|
|
|
410
525
|
}
|
|
411
526
|
}
|
|
412
527
|
async function connectCursor(deps, mcpUrl) {
|
|
413
|
-
const path =
|
|
528
|
+
const path = join3(deps.home, ".cursor", "mcp.json");
|
|
414
529
|
const text = await deps.readText(path);
|
|
415
530
|
const config = text ? JSON.parse(text) : {};
|
|
416
531
|
config.mcpServers = { ...config.mcpServers ?? {}, [SERVER_NAME]: { url: mcpUrl } };
|
|
@@ -443,120 +558,115 @@ async function installSkill(deps, agent) {
|
|
|
443
558
|
var SKILL_NAME = "nimblebrain";
|
|
444
559
|
function globalSkillsDir(deps, agent) {
|
|
445
560
|
if (agent === "claude-code")
|
|
446
|
-
return
|
|
561
|
+
return join3(deps.env.CLAUDE_CONFIG_DIR?.trim() || join3(deps.home, ".claude"), "skills");
|
|
447
562
|
if (agent === "codex")
|
|
448
|
-
return
|
|
563
|
+
return join3(deps.home, ".agents", "skills");
|
|
449
564
|
if (agent === "cursor")
|
|
450
|
-
return
|
|
565
|
+
return join3(deps.home, ".cursor", "skills");
|
|
451
566
|
return;
|
|
452
567
|
}
|
|
453
568
|
async function skillInstalled(deps, agent) {
|
|
454
569
|
const dir = globalSkillsDir(deps, agent);
|
|
455
570
|
if (!dir)
|
|
456
571
|
return null;
|
|
457
|
-
return await deps.readText(
|
|
572
|
+
return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
|
|
458
573
|
}
|
|
459
574
|
|
|
460
|
-
// src/
|
|
461
|
-
|
|
462
|
-
var
|
|
463
|
-
var
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
575
|
+
// src/local-model.ts
|
|
576
|
+
var OLLAMA_URL = "http://127.0.0.1:11434";
|
|
577
|
+
var OLLAMA_FROM_CONTAINER = "http://host.docker.internal:11434/v1";
|
|
578
|
+
var DEFAULT_LOCAL_MODEL = "gemma4:e4b";
|
|
579
|
+
var LOCAL_CONTEXT = 32768;
|
|
580
|
+
var PULL_TIMEOUT_MS = 60 * 60 * 1000;
|
|
581
|
+
var CREATE_TIMEOUT_MS = 2 * 60 * 1000;
|
|
582
|
+
function takesLocalModel(composeText) {
|
|
583
|
+
return composeText.includes("NB_LOCAL_MODEL_URL");
|
|
584
|
+
}
|
|
585
|
+
function nimblebrainModelName(model) {
|
|
586
|
+
return `nimblebrain-${model.replace(/[^A-Za-z0-9._-]+/g, "-")}`;
|
|
587
|
+
}
|
|
588
|
+
function localModelOf(envText) {
|
|
589
|
+
const line = envText.split(`
|
|
590
|
+
`).find((l) => l.startsWith("NB_LOCAL_MODEL="));
|
|
591
|
+
const value = line?.slice("NB_LOCAL_MODEL=".length).trim();
|
|
592
|
+
return value ? value : undefined;
|
|
593
|
+
}
|
|
594
|
+
async function show(deps, model) {
|
|
595
|
+
const res = await deps.postJson(`${OLLAMA_URL}/api/show`, { model });
|
|
596
|
+
return res?.status === 200 ? res.body : undefined;
|
|
597
|
+
}
|
|
598
|
+
function numCtxOf(parameters) {
|
|
599
|
+
const match = parameters?.match(/^num_ctx\s+(\d+)/m);
|
|
600
|
+
return match ? Number(match[1]) : undefined;
|
|
601
|
+
}
|
|
602
|
+
async function requireOllama(deps) {
|
|
603
|
+
const res = await deps.getJson(`${OLLAMA_URL}/api/version`);
|
|
604
|
+
const version = res?.body?.version;
|
|
605
|
+
if (res?.status !== 200 || typeof version !== "string") {
|
|
606
|
+
throw new CliError("LOCAL_MODEL_UNREACHABLE", `Ollama does not answer at ${OLLAMA_URL}.`, {
|
|
607
|
+
check: "ollama"
|
|
608
|
+
});
|
|
477
609
|
}
|
|
478
|
-
return
|
|
479
|
-
}
|
|
480
|
-
function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
...vars,
|
|
498
|
-
"NIMBLEBRAIN_TAG",
|
|
499
|
-
"NIMBLEBRAIN_WEB_PORT",
|
|
500
|
-
"COMPOSE_PROJECT_NAME",
|
|
501
|
-
"NB_TELEMETRY_KEY",
|
|
502
|
-
"NB_TELEMETRY_ID",
|
|
503
|
-
"NB_TELEMETRY_CONSENT"
|
|
504
|
-
]) {
|
|
505
|
-
delete env[v];
|
|
610
|
+
return version;
|
|
611
|
+
}
|
|
612
|
+
async function setupLocalModel(deps, model, pull) {
|
|
613
|
+
await requireOllama(deps);
|
|
614
|
+
let found = await show(deps, model);
|
|
615
|
+
if (!found) {
|
|
616
|
+
if (!await pull(model)) {
|
|
617
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`, {
|
|
618
|
+
check: "model"
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
deps.say(`Downloading ${model} with Ollama. A model is several GB; this can take a while.`);
|
|
622
|
+
const pulled = await deps.postJson(`${OLLAMA_URL}/api/pull`, { model, stream: false }, PULL_TIMEOUT_MS);
|
|
623
|
+
found = pulled?.status === 200 ? await show(deps, model) : undefined;
|
|
624
|
+
if (!found) {
|
|
625
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not download "${model}".`, {
|
|
626
|
+
check: "model"
|
|
627
|
+
});
|
|
628
|
+
}
|
|
506
629
|
}
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
async function compose(deps, home, args, timeoutMs = 120000) {
|
|
510
|
-
const vars = keyVars(await deps.readText(paths(home).compose) ?? "");
|
|
511
|
-
return deps.exec("docker", ["compose", ...args], {
|
|
512
|
-
cwd: home,
|
|
513
|
-
env: composeEnv(deps, vars),
|
|
514
|
-
timeoutMs
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
function startError(res) {
|
|
518
|
-
const text = `${res.stderr}
|
|
519
|
-
${res.stdout}`;
|
|
520
|
-
const last = text.trim().split(`
|
|
521
|
-
`).filter((l) => l.trim()).pop() ?? "Compose failed.";
|
|
522
|
-
if (/no such host|timeout|TLS handshake|connection refused|network is unreachable/i.test(text)) {
|
|
523
|
-
return new CliError("NETWORK", last);
|
|
630
|
+
if (!found.capabilities?.includes("tools")) {
|
|
631
|
+
throw new CliError("LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling, which NimbleBrain's agents need.`, { check: "tools" });
|
|
524
632
|
}
|
|
525
|
-
|
|
526
|
-
|
|
633
|
+
const name = nimblebrainModelName(model);
|
|
634
|
+
const created = await deps.postJson(`${OLLAMA_URL}/api/create`, { model: name, from: model, parameters: { num_ctx: LOCAL_CONTEXT }, stream: false }, CREATE_TIMEOUT_MS);
|
|
635
|
+
if (created?.status !== 200) {
|
|
636
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not prepare ${name} from ${model}.`, {
|
|
637
|
+
check: "model"
|
|
638
|
+
});
|
|
527
639
|
}
|
|
528
|
-
return
|
|
640
|
+
return {
|
|
641
|
+
NB_LOCAL_MODEL_URL: OLLAMA_FROM_CONTAINER,
|
|
642
|
+
NB_LOCAL_MODEL: name,
|
|
643
|
+
NB_LOCAL_MODEL_CONTEXT: String(LOCAL_CONTEXT)
|
|
644
|
+
};
|
|
529
645
|
}
|
|
530
|
-
function
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const name = line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1];
|
|
536
|
-
if (name && name in values) {
|
|
537
|
-
seen.add(name);
|
|
538
|
-
return `${name}=${values[name]}`;
|
|
539
|
-
}
|
|
540
|
-
return line;
|
|
646
|
+
async function checkLocalModel(deps, model) {
|
|
647
|
+
const checks = [];
|
|
648
|
+
const version = await requireOllama(deps).catch((err) => {
|
|
649
|
+
checks.push({ check: "ollama", ok: false, detail: err.message });
|
|
650
|
+
throw new CliError(err.code, err.message, { check: "ollama", checks });
|
|
541
651
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
652
|
+
checks.push({ check: "ollama", ok: true, detail: version });
|
|
653
|
+
const found = await show(deps, model);
|
|
654
|
+
const fail = (check, code, detail) => {
|
|
655
|
+
checks.push({ check, ok: false, detail });
|
|
656
|
+
throw new CliError(code, detail, { check, checks });
|
|
657
|
+
};
|
|
658
|
+
if (!found)
|
|
659
|
+
fail("model", "LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`);
|
|
660
|
+
checks.push({ check: "model", ok: true, detail: model });
|
|
661
|
+
if (!found?.capabilities?.includes("tools"))
|
|
662
|
+
fail("tools", "LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling.`);
|
|
663
|
+
checks.push({ check: "tools", ok: true, detail: "tool calling" });
|
|
664
|
+
const ctx = numCtxOf(found?.parameters);
|
|
665
|
+
if (ctx === undefined || ctx < LOCAL_CONTEXT)
|
|
666
|
+
fail("context", "LOCAL_CONTEXT_SMALL", `${model} has a context window of ${ctx ?? "Ollama's default"}, below ${LOCAL_CONTEXT}.`);
|
|
667
|
+
checks.push({ check: "context", ok: true, detail: `${ctx} tokens` });
|
|
668
|
+
return checks;
|
|
551
669
|
}
|
|
552
|
-
var paths = (home) => ({
|
|
553
|
-
compose: join3(home, "docker-compose.yml"),
|
|
554
|
-
env: join3(home, ".env"),
|
|
555
|
-
instance: join3(home, "instance.json"),
|
|
556
|
-
install: join3(home, "install.json")
|
|
557
|
-
});
|
|
558
|
-
var INSTANCE_JSON = `${JSON.stringify({ auth: { adapter: "dev" } }, null, 2)}
|
|
559
|
-
`;
|
|
560
670
|
|
|
561
671
|
// src/release.ts
|
|
562
672
|
var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
|
|
@@ -778,7 +888,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
|
|
|
778
888
|
// package.json
|
|
779
889
|
var package_default = {
|
|
780
890
|
name: "nimblebrain",
|
|
781
|
-
version: "0.1
|
|
891
|
+
version: "0.2.1",
|
|
782
892
|
description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
|
|
783
893
|
license: "Apache-2.0",
|
|
784
894
|
type: "module",
|
|
@@ -829,7 +939,8 @@ async function status(deps, home) {
|
|
|
829
939
|
const up = health?.status === 200 && health.body?.status === "ok";
|
|
830
940
|
const workspaces = up ? await readWorkspaces(deps, url) : [];
|
|
831
941
|
const vars = keyVars(await deps.readText(join5(home, "docker-compose.yml")) ?? "");
|
|
832
|
-
const
|
|
942
|
+
const envText = await deps.readText(join5(home, ".env")) ?? "";
|
|
943
|
+
const modelKey = hasKey(envText, vars) ? "set" : "missing";
|
|
833
944
|
return {
|
|
834
945
|
ok: true,
|
|
835
946
|
version: install.version,
|
|
@@ -842,6 +953,7 @@ async function status(deps, home) {
|
|
|
842
953
|
skill: install.agent ? await skillInstalled(deps, install.agent) : null
|
|
843
954
|
},
|
|
844
955
|
model_key: modelKey,
|
|
956
|
+
local_model: localModelOf(envText) ?? null,
|
|
845
957
|
telemetry: await currentTelemetry(deps, home, url)
|
|
846
958
|
};
|
|
847
959
|
}
|
|
@@ -904,7 +1016,12 @@ async function install(ctx, answer, rec, begun) {
|
|
|
904
1016
|
answer.consent = await chooseConsent(ctx, true);
|
|
905
1017
|
const { consent } = answer;
|
|
906
1018
|
await writeInstallFiles(deps, home, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
|
|
907
|
-
|
|
1019
|
+
const envText = await deps.readText(paths(home).env) ?? "";
|
|
1020
|
+
const hasModel = hasKey(envText, keyVars(composeText)) || localModelOf(envText) !== undefined;
|
|
1021
|
+
const local = flags.localModel ?? (!hasModel && asks(ctx) && takesLocalModel(composeText) ? await chooseModelSource(deps) : undefined);
|
|
1022
|
+
if (local)
|
|
1023
|
+
await useLocalModel(ctx, composeText, local);
|
|
1024
|
+
else if (!hasModel && asks(ctx))
|
|
908
1025
|
await enterKey(ctx, false);
|
|
909
1026
|
deps.say(`Starting NimbleBrain ${tag}. The first start downloads about 2 GB of images.`);
|
|
910
1027
|
await start(deps, home, flags.port);
|
|
@@ -918,12 +1035,15 @@ async function install(ctx, answer, rec, begun) {
|
|
|
918
1035
|
if (state.agent)
|
|
919
1036
|
rec.record("cli.agent_connected", { agent: state.agent });
|
|
920
1037
|
const result = { ...await status(deps, home), manual };
|
|
1038
|
+
const finalEnv = await deps.readText(paths(home).env) ?? "";
|
|
921
1039
|
rec.record("cli.init_completed", {
|
|
922
1040
|
duration_ms: Date.now() - begun,
|
|
923
|
-
model_key: result.model_key
|
|
1041
|
+
model_key: result.model_key,
|
|
1042
|
+
provider: localModelOf(finalEnv) ? "ollama" : keyProvider(finalEnv, composeText),
|
|
1043
|
+
agent: state.agent ?? null
|
|
924
1044
|
});
|
|
925
1045
|
await rec.settle(home, consent);
|
|
926
|
-
if (result.model_key === "missing") {
|
|
1046
|
+
if (result.model_key === "missing" && !result.local_model) {
|
|
927
1047
|
throw new CliError("MODEL_KEY_MISSING", "NimbleBrain is running; chat needs a model key.", {
|
|
928
1048
|
...result
|
|
929
1049
|
});
|
|
@@ -1075,6 +1195,35 @@ async function enterKey(ctx, restart) {
|
|
|
1075
1195
|
}
|
|
1076
1196
|
return { ok: true, provider, model_key: "set" };
|
|
1077
1197
|
}
|
|
1198
|
+
async function localModel(ctx) {
|
|
1199
|
+
const install = await requireInstall(ctx);
|
|
1200
|
+
const composeText = await ctx.deps.readText(paths(ctx.home).compose) ?? "";
|
|
1201
|
+
const model = ctx.arg ?? ctx.flags.localModel ?? DEFAULT_LOCAL_MODEL;
|
|
1202
|
+
const name = await useLocalModel(ctx, composeText, model);
|
|
1203
|
+
await start(ctx.deps, ctx.home, install.port);
|
|
1204
|
+
return { ok: true, local_model: name };
|
|
1205
|
+
}
|
|
1206
|
+
async function chooseModelSource(deps) {
|
|
1207
|
+
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/).");
|
|
1208
|
+
const answer = (await deps.prompt("Model (hosted, local) [hosted]: ")).trim().toLowerCase();
|
|
1209
|
+
return answer === "local" ? DEFAULT_LOCAL_MODEL : undefined;
|
|
1210
|
+
}
|
|
1211
|
+
async function useLocalModel(ctx, composeText, model) {
|
|
1212
|
+
const { deps, home } = ctx;
|
|
1213
|
+
if (!takesLocalModel(composeText)) {
|
|
1214
|
+
throw new CliError("RUNTIME_UNSUPPORTED", "This release's runtime takes no local model; a newer release does.");
|
|
1215
|
+
}
|
|
1216
|
+
const values = await setupLocalModel(deps, model, (m) => confirmPull(ctx, m));
|
|
1217
|
+
const p = paths(home);
|
|
1218
|
+
await deps.writeText(p.env, setEnvLines(await deps.readText(p.env) ?? "", values), 384);
|
|
1219
|
+
return values.NB_LOCAL_MODEL ?? model;
|
|
1220
|
+
}
|
|
1221
|
+
async function confirmPull(ctx, model) {
|
|
1222
|
+
if (!asks(ctx))
|
|
1223
|
+
return true;
|
|
1224
|
+
const answer = (await ctx.deps.prompt(`Download ${model} with Ollama? It is several GB. [Y/n] `)).trim().toLowerCase();
|
|
1225
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
1226
|
+
}
|
|
1078
1227
|
async function chooseAgent(deps) {
|
|
1079
1228
|
deps.say("A coding agent you connect can use NimbleBrain's tools. NimbleBrain's own agents still run on the model key above.");
|
|
1080
1229
|
const answer = await deps.prompt(`Connect a coding agent? (${AGENTS.join(", ")}) [none]: `);
|
|
@@ -1146,6 +1295,7 @@ Commands:
|
|
|
1146
1295
|
doctor Check Docker, Compose, architecture, memory and the port; installs nothing
|
|
1147
1296
|
status Version, health, URL and each workspace's MCP URL
|
|
1148
1297
|
key Enter the model key at a hidden prompt
|
|
1298
|
+
local-model [model] Run NimbleBrain's agents on a model served by Ollama (default gemma4:e4b)
|
|
1149
1299
|
telemetry [on|off|status] Whether this install sends anonymous usage data
|
|
1150
1300
|
up, down Start or stop NimbleBrain; data survives down
|
|
1151
1301
|
logs Recent runtime log lines
|
|
@@ -1159,6 +1309,7 @@ Flags:
|
|
|
1159
1309
|
--port <n> Local port (default 27246)
|
|
1160
1310
|
--home <dir> Where the install lives (default ~/.nimblebrain-local, or NIMBLEBRAIN_HOME)
|
|
1161
1311
|
--provider <name> The model provider for key (default anthropic)
|
|
1312
|
+
--local-model <model> init: run on this Ollama model instead of a hosted key
|
|
1162
1313
|
--runtime <tag> The NimbleBrain release to install or update to (default the newest)
|
|
1163
1314
|
--telemetry <on|off> The person's answer to sending anonymous usage data; without it, init asks or leaves it undecided
|
|
1164
1315
|
--help, --version
|
|
@@ -1185,7 +1336,7 @@ async function run(argv, deps) {
|
|
|
1185
1336
|
case "doctor": {
|
|
1186
1337
|
const install = await readInstall(deps, home);
|
|
1187
1338
|
const ours = install !== undefined && install.port === flags.port && await isHealthy(deps, flags.port);
|
|
1188
|
-
result = { ...await
|
|
1339
|
+
result = { ...await doctorInstall(deps, home, flags.port, ours) };
|
|
1189
1340
|
break;
|
|
1190
1341
|
}
|
|
1191
1342
|
case "status":
|
|
@@ -1193,7 +1344,17 @@ async function run(argv, deps) {
|
|
|
1193
1344
|
break;
|
|
1194
1345
|
default: {
|
|
1195
1346
|
const ctx = { deps, flags, home, version: VERSION2, arg };
|
|
1196
|
-
const commands = {
|
|
1347
|
+
const commands = {
|
|
1348
|
+
init,
|
|
1349
|
+
up,
|
|
1350
|
+
down,
|
|
1351
|
+
logs,
|
|
1352
|
+
update,
|
|
1353
|
+
uninstall,
|
|
1354
|
+
key,
|
|
1355
|
+
telemetry,
|
|
1356
|
+
"local-model": localModel
|
|
1357
|
+
};
|
|
1197
1358
|
result = await commands[command](ctx);
|
|
1198
1359
|
}
|
|
1199
1360
|
}
|
|
@@ -1205,6 +1366,23 @@ async function run(argv, deps) {
|
|
|
1205
1366
|
}
|
|
1206
1367
|
return render(result, flags.json, command);
|
|
1207
1368
|
}
|
|
1369
|
+
async function doctorInstall(deps, home, port, ours) {
|
|
1370
|
+
const machine = await doctor(deps, port, ours);
|
|
1371
|
+
const model = localModelOf(await deps.readText(paths(home).env) ?? "");
|
|
1372
|
+
if (!model)
|
|
1373
|
+
return machine;
|
|
1374
|
+
try {
|
|
1375
|
+
return { ...machine, checks: [...machine.checks, ...await checkLocalModel(deps, model)] };
|
|
1376
|
+
} catch (err) {
|
|
1377
|
+
if (!(err instanceof CliError))
|
|
1378
|
+
throw err;
|
|
1379
|
+
const local = err.detail.checks ?? [];
|
|
1380
|
+
throw new CliError(err.code, err.message, {
|
|
1381
|
+
...err.detail,
|
|
1382
|
+
checks: [...machine.checks, ...local]
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1208
1386
|
async function isHealthy(deps, port) {
|
|
1209
1387
|
const res = await deps.getJson(`http://127.0.0.1:${port}/v1/health`);
|
|
1210
1388
|
return res?.status === 200;
|
|
@@ -1241,7 +1419,7 @@ function statusLines(r, command) {
|
|
|
1241
1419
|
...changeLines(r),
|
|
1242
1420
|
` NimbleBrain ${r.version.startsWith("v") ? r.version : `v${r.version}`}: ${r.health === "ok" ? "running" : "stopped"} at ${r.url}`,
|
|
1243
1421
|
...r.workspaces.map((w) => ` workspace ${w.name}: ${w.mcp}`),
|
|
1244
|
-
` model key: ${r.model_key === "set" ? "set (NimbleBrain's own agents use it)" : "missing (run npx nimblebrain key)"}`
|
|
1422
|
+
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 npx nimblebrain key)"}`
|
|
1245
1423
|
];
|
|
1246
1424
|
const agent = r.agent.connected;
|
|
1247
1425
|
if (agent) {
|
package/package.json
CHANGED