nimblebrain 0.1.2 → 0.2.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/dist/nimblebrain.js +279 -108
- 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,110 @@ 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 hasKey(envText, vars) {
|
|
393
|
+
return vars.some((v) => new RegExp(`^${v}=\\S`, "m").test(envText));
|
|
394
|
+
}
|
|
395
|
+
var paths = (home) => ({
|
|
396
|
+
compose: join2(home, "docker-compose.yml"),
|
|
397
|
+
env: join2(home, ".env"),
|
|
398
|
+
instance: join2(home, "instance.json"),
|
|
399
|
+
install: join2(home, "install.json")
|
|
400
|
+
});
|
|
401
|
+
var INSTANCE_JSON = `${JSON.stringify({ auth: { adapter: "dev" } }, null, 2)}
|
|
402
|
+
`;
|
|
403
|
+
|
|
293
404
|
// src/doctor.ts
|
|
294
405
|
var SUPPORTED_ARCH = ["x86_64", "amd64", "aarch64", "arm64"];
|
|
295
406
|
var MIN_MEMORY = 2 * 1024 ** 3;
|
|
@@ -377,7 +488,7 @@ function gib(bytes) {
|
|
|
377
488
|
}
|
|
378
489
|
|
|
379
490
|
// src/agents.ts
|
|
380
|
-
import { join as
|
|
491
|
+
import { join as join3 } from "node:path";
|
|
381
492
|
var SERVER_NAME = "nimblebrain";
|
|
382
493
|
async function connectAgent(deps, agent, mcpUrl) {
|
|
383
494
|
if (agent === "none")
|
|
@@ -410,7 +521,7 @@ async function connectAgent(deps, agent, mcpUrl) {
|
|
|
410
521
|
}
|
|
411
522
|
}
|
|
412
523
|
async function connectCursor(deps, mcpUrl) {
|
|
413
|
-
const path =
|
|
524
|
+
const path = join3(deps.home, ".cursor", "mcp.json");
|
|
414
525
|
const text = await deps.readText(path);
|
|
415
526
|
const config = text ? JSON.parse(text) : {};
|
|
416
527
|
config.mcpServers = { ...config.mcpServers ?? {}, [SERVER_NAME]: { url: mcpUrl } };
|
|
@@ -443,120 +554,115 @@ async function installSkill(deps, agent) {
|
|
|
443
554
|
var SKILL_NAME = "nimblebrain";
|
|
444
555
|
function globalSkillsDir(deps, agent) {
|
|
445
556
|
if (agent === "claude-code")
|
|
446
|
-
return
|
|
557
|
+
return join3(deps.env.CLAUDE_CONFIG_DIR?.trim() || join3(deps.home, ".claude"), "skills");
|
|
447
558
|
if (agent === "codex")
|
|
448
|
-
return
|
|
559
|
+
return join3(deps.home, ".agents", "skills");
|
|
449
560
|
if (agent === "cursor")
|
|
450
|
-
return
|
|
561
|
+
return join3(deps.home, ".cursor", "skills");
|
|
451
562
|
return;
|
|
452
563
|
}
|
|
453
564
|
async function skillInstalled(deps, agent) {
|
|
454
565
|
const dir = globalSkillsDir(deps, agent);
|
|
455
566
|
if (!dir)
|
|
456
567
|
return null;
|
|
457
|
-
return await deps.readText(
|
|
568
|
+
return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
|
|
458
569
|
}
|
|
459
570
|
|
|
460
|
-
// src/
|
|
461
|
-
|
|
462
|
-
var
|
|
463
|
-
var
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
571
|
+
// src/local-model.ts
|
|
572
|
+
var OLLAMA_URL = "http://127.0.0.1:11434";
|
|
573
|
+
var OLLAMA_FROM_CONTAINER = "http://host.docker.internal:11434/v1";
|
|
574
|
+
var DEFAULT_LOCAL_MODEL = "gemma4:e4b";
|
|
575
|
+
var LOCAL_CONTEXT = 32768;
|
|
576
|
+
var PULL_TIMEOUT_MS = 60 * 60 * 1000;
|
|
577
|
+
var CREATE_TIMEOUT_MS = 2 * 60 * 1000;
|
|
578
|
+
function takesLocalModel(composeText) {
|
|
579
|
+
return composeText.includes("NB_LOCAL_MODEL_URL");
|
|
580
|
+
}
|
|
581
|
+
function nimblebrainModelName(model) {
|
|
582
|
+
return `nimblebrain-${model.replace(/[^A-Za-z0-9._-]+/g, "-")}`;
|
|
583
|
+
}
|
|
584
|
+
function localModelOf(envText) {
|
|
585
|
+
const line = envText.split(`
|
|
586
|
+
`).find((l) => l.startsWith("NB_LOCAL_MODEL="));
|
|
587
|
+
const value = line?.slice("NB_LOCAL_MODEL=".length).trim();
|
|
588
|
+
return value ? value : undefined;
|
|
589
|
+
}
|
|
590
|
+
async function show(deps, model) {
|
|
591
|
+
const res = await deps.postJson(`${OLLAMA_URL}/api/show`, { model });
|
|
592
|
+
return res?.status === 200 ? res.body : undefined;
|
|
593
|
+
}
|
|
594
|
+
function numCtxOf(parameters) {
|
|
595
|
+
const match = parameters?.match(/^num_ctx\s+(\d+)/m);
|
|
596
|
+
return match ? Number(match[1]) : undefined;
|
|
597
|
+
}
|
|
598
|
+
async function requireOllama(deps) {
|
|
599
|
+
const res = await deps.getJson(`${OLLAMA_URL}/api/version`);
|
|
600
|
+
const version = res?.body?.version;
|
|
601
|
+
if (res?.status !== 200 || typeof version !== "string") {
|
|
602
|
+
throw new CliError("LOCAL_MODEL_UNREACHABLE", `Ollama does not answer at ${OLLAMA_URL}.`, {
|
|
603
|
+
check: "ollama"
|
|
604
|
+
});
|
|
474
605
|
}
|
|
475
|
-
|
|
476
|
-
|
|
606
|
+
return version;
|
|
607
|
+
}
|
|
608
|
+
async function setupLocalModel(deps, model, pull) {
|
|
609
|
+
await requireOllama(deps);
|
|
610
|
+
let found = await show(deps, model);
|
|
611
|
+
if (!found) {
|
|
612
|
+
if (!await pull(model)) {
|
|
613
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`, {
|
|
614
|
+
check: "model"
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
deps.say(`Downloading ${model} with Ollama. A model is several GB; this can take a while.`);
|
|
618
|
+
const pulled = await deps.postJson(`${OLLAMA_URL}/api/pull`, { model, stream: false }, PULL_TIMEOUT_MS);
|
|
619
|
+
found = pulled?.status === 200 ? await show(deps, model) : undefined;
|
|
620
|
+
if (!found) {
|
|
621
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not download "${model}".`, {
|
|
622
|
+
check: "model"
|
|
623
|
+
});
|
|
624
|
+
}
|
|
477
625
|
}
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
function keyVars(composeText) {
|
|
481
|
-
return [
|
|
482
|
-
...new Set([...composeText.matchAll(/\b([A-Z][A-Z0-9_]*_API_KEY)=\$\{\1\b/g)].map((m) => m[1] ?? ""))
|
|
483
|
-
];
|
|
484
|
-
}
|
|
485
|
-
function asksConsent(composeText) {
|
|
486
|
-
return composeText.includes("NB_TELEMETRY_CONSENT");
|
|
487
|
-
}
|
|
488
|
-
function providers(composeText) {
|
|
489
|
-
return Object.fromEntries(keyVars(composeText).map((v) => [
|
|
490
|
-
v.replace(/_API_KEY$/, "").replace(/_GENERATIVE_AI$/, "").toLowerCase(),
|
|
491
|
-
v
|
|
492
|
-
]));
|
|
493
|
-
}
|
|
494
|
-
function composeEnv(deps, vars) {
|
|
495
|
-
const env = { ...deps.env };
|
|
496
|
-
for (const v of [
|
|
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];
|
|
626
|
+
if (!found.capabilities?.includes("tools")) {
|
|
627
|
+
throw new CliError("LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling, which NimbleBrain's agents need.`, { check: "tools" });
|
|
506
628
|
}
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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);
|
|
524
|
-
}
|
|
525
|
-
if (/port is already allocated|address already in use/i.test(text)) {
|
|
526
|
-
return new CliError("PORT_IN_USE", last);
|
|
629
|
+
const name = nimblebrainModelName(model);
|
|
630
|
+
const created = await deps.postJson(`${OLLAMA_URL}/api/create`, { model: name, from: model, parameters: { num_ctx: LOCAL_CONTEXT }, stream: false }, CREATE_TIMEOUT_MS);
|
|
631
|
+
if (created?.status !== 200) {
|
|
632
|
+
throw new CliError("LOCAL_MODEL_MISSING", `Ollama could not prepare ${name} from ${model}.`, {
|
|
633
|
+
check: "model"
|
|
634
|
+
});
|
|
527
635
|
}
|
|
528
|
-
return
|
|
636
|
+
return {
|
|
637
|
+
NB_LOCAL_MODEL_URL: OLLAMA_FROM_CONTAINER,
|
|
638
|
+
NB_LOCAL_MODEL: name,
|
|
639
|
+
NB_LOCAL_MODEL_CONTEXT: String(LOCAL_CONTEXT)
|
|
640
|
+
};
|
|
529
641
|
}
|
|
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;
|
|
642
|
+
async function checkLocalModel(deps, model) {
|
|
643
|
+
const checks = [];
|
|
644
|
+
const version = await requireOllama(deps).catch((err) => {
|
|
645
|
+
checks.push({ check: "ollama", ok: false, detail: err.message });
|
|
646
|
+
throw new CliError(err.code, err.message, { check: "ollama", checks });
|
|
541
647
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
648
|
+
checks.push({ check: "ollama", ok: true, detail: version });
|
|
649
|
+
const found = await show(deps, model);
|
|
650
|
+
const fail = (check, code, detail) => {
|
|
651
|
+
checks.push({ check, ok: false, detail });
|
|
652
|
+
throw new CliError(code, detail, { check, checks });
|
|
653
|
+
};
|
|
654
|
+
if (!found)
|
|
655
|
+
fail("model", "LOCAL_MODEL_MISSING", `Ollama has no model "${model}".`);
|
|
656
|
+
checks.push({ check: "model", ok: true, detail: model });
|
|
657
|
+
if (!found?.capabilities?.includes("tools"))
|
|
658
|
+
fail("tools", "LOCAL_MODEL_NO_TOOLS", `${model} does not support tool calling.`);
|
|
659
|
+
checks.push({ check: "tools", ok: true, detail: "tool calling" });
|
|
660
|
+
const ctx = numCtxOf(found?.parameters);
|
|
661
|
+
if (ctx === undefined || ctx < LOCAL_CONTEXT)
|
|
662
|
+
fail("context", "LOCAL_CONTEXT_SMALL", `${model} has a context window of ${ctx ?? "Ollama's default"}, below ${LOCAL_CONTEXT}.`);
|
|
663
|
+
checks.push({ check: "context", ok: true, detail: `${ctx} tokens` });
|
|
664
|
+
return checks;
|
|
551
665
|
}
|
|
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
666
|
|
|
561
667
|
// src/release.ts
|
|
562
668
|
var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
|
|
@@ -778,7 +884,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
|
|
|
778
884
|
// package.json
|
|
779
885
|
var package_default = {
|
|
780
886
|
name: "nimblebrain",
|
|
781
|
-
version: "0.
|
|
887
|
+
version: "0.2.0",
|
|
782
888
|
description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
|
|
783
889
|
license: "Apache-2.0",
|
|
784
890
|
type: "module",
|
|
@@ -829,7 +935,8 @@ async function status(deps, home) {
|
|
|
829
935
|
const up = health?.status === 200 && health.body?.status === "ok";
|
|
830
936
|
const workspaces = up ? await readWorkspaces(deps, url) : [];
|
|
831
937
|
const vars = keyVars(await deps.readText(join5(home, "docker-compose.yml")) ?? "");
|
|
832
|
-
const
|
|
938
|
+
const envText = await deps.readText(join5(home, ".env")) ?? "";
|
|
939
|
+
const modelKey = hasKey(envText, vars) ? "set" : "missing";
|
|
833
940
|
return {
|
|
834
941
|
ok: true,
|
|
835
942
|
version: install.version,
|
|
@@ -842,6 +949,7 @@ async function status(deps, home) {
|
|
|
842
949
|
skill: install.agent ? await skillInstalled(deps, install.agent) : null
|
|
843
950
|
},
|
|
844
951
|
model_key: modelKey,
|
|
952
|
+
local_model: localModelOf(envText) ?? null,
|
|
845
953
|
telemetry: await currentTelemetry(deps, home, url)
|
|
846
954
|
};
|
|
847
955
|
}
|
|
@@ -904,7 +1012,12 @@ async function install(ctx, answer, rec, begun) {
|
|
|
904
1012
|
answer.consent = await chooseConsent(ctx, true);
|
|
905
1013
|
const { consent } = answer;
|
|
906
1014
|
await writeInstallFiles(deps, home, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
|
|
907
|
-
|
|
1015
|
+
const envText = await deps.readText(paths(home).env) ?? "";
|
|
1016
|
+
const hasModel = hasKey(envText, keyVars(composeText)) || localModelOf(envText) !== undefined;
|
|
1017
|
+
const local = flags.localModel ?? (!hasModel && asks(ctx) && takesLocalModel(composeText) ? await chooseModelSource(deps) : undefined);
|
|
1018
|
+
if (local)
|
|
1019
|
+
await useLocalModel(ctx, composeText, local);
|
|
1020
|
+
else if (!hasModel && asks(ctx))
|
|
908
1021
|
await enterKey(ctx, false);
|
|
909
1022
|
deps.say(`Starting NimbleBrain ${tag}. The first start downloads about 2 GB of images.`);
|
|
910
1023
|
await start(deps, home, flags.port);
|
|
@@ -923,7 +1036,7 @@ async function install(ctx, answer, rec, begun) {
|
|
|
923
1036
|
model_key: result.model_key
|
|
924
1037
|
});
|
|
925
1038
|
await rec.settle(home, consent);
|
|
926
|
-
if (result.model_key === "missing") {
|
|
1039
|
+
if (result.model_key === "missing" && !result.local_model) {
|
|
927
1040
|
throw new CliError("MODEL_KEY_MISSING", "NimbleBrain is running; chat needs a model key.", {
|
|
928
1041
|
...result
|
|
929
1042
|
});
|
|
@@ -1075,6 +1188,35 @@ async function enterKey(ctx, restart) {
|
|
|
1075
1188
|
}
|
|
1076
1189
|
return { ok: true, provider, model_key: "set" };
|
|
1077
1190
|
}
|
|
1191
|
+
async function localModel(ctx) {
|
|
1192
|
+
const install = await requireInstall(ctx);
|
|
1193
|
+
const composeText = await ctx.deps.readText(paths(ctx.home).compose) ?? "";
|
|
1194
|
+
const model = ctx.arg ?? ctx.flags.localModel ?? DEFAULT_LOCAL_MODEL;
|
|
1195
|
+
const name = await useLocalModel(ctx, composeText, model);
|
|
1196
|
+
await start(ctx.deps, ctx.home, install.port);
|
|
1197
|
+
return { ok: true, local_model: name };
|
|
1198
|
+
}
|
|
1199
|
+
async function chooseModelSource(deps) {
|
|
1200
|
+
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/).");
|
|
1201
|
+
const answer = (await deps.prompt("Model (hosted, local) [hosted]: ")).trim().toLowerCase();
|
|
1202
|
+
return answer === "local" ? DEFAULT_LOCAL_MODEL : undefined;
|
|
1203
|
+
}
|
|
1204
|
+
async function useLocalModel(ctx, composeText, model) {
|
|
1205
|
+
const { deps, home } = ctx;
|
|
1206
|
+
if (!takesLocalModel(composeText)) {
|
|
1207
|
+
throw new CliError("RUNTIME_UNSUPPORTED", "This release's runtime takes no local model; a newer release does.");
|
|
1208
|
+
}
|
|
1209
|
+
const values = await setupLocalModel(deps, model, (m) => confirmPull(ctx, m));
|
|
1210
|
+
const p = paths(home);
|
|
1211
|
+
await deps.writeText(p.env, setEnvLines(await deps.readText(p.env) ?? "", values), 384);
|
|
1212
|
+
return values.NB_LOCAL_MODEL ?? model;
|
|
1213
|
+
}
|
|
1214
|
+
async function confirmPull(ctx, model) {
|
|
1215
|
+
if (!asks(ctx))
|
|
1216
|
+
return true;
|
|
1217
|
+
const answer = (await ctx.deps.prompt(`Download ${model} with Ollama? It is several GB. [Y/n] `)).trim().toLowerCase();
|
|
1218
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
1219
|
+
}
|
|
1078
1220
|
async function chooseAgent(deps) {
|
|
1079
1221
|
deps.say("A coding agent you connect can use NimbleBrain's tools. NimbleBrain's own agents still run on the model key above.");
|
|
1080
1222
|
const answer = await deps.prompt(`Connect a coding agent? (${AGENTS.join(", ")}) [none]: `);
|
|
@@ -1146,6 +1288,7 @@ Commands:
|
|
|
1146
1288
|
doctor Check Docker, Compose, architecture, memory and the port; installs nothing
|
|
1147
1289
|
status Version, health, URL and each workspace's MCP URL
|
|
1148
1290
|
key Enter the model key at a hidden prompt
|
|
1291
|
+
local-model [model] Run NimbleBrain's agents on a model served by Ollama (default gemma4:e4b)
|
|
1149
1292
|
telemetry [on|off|status] Whether this install sends anonymous usage data
|
|
1150
1293
|
up, down Start or stop NimbleBrain; data survives down
|
|
1151
1294
|
logs Recent runtime log lines
|
|
@@ -1159,6 +1302,7 @@ Flags:
|
|
|
1159
1302
|
--port <n> Local port (default 27246)
|
|
1160
1303
|
--home <dir> Where the install lives (default ~/.nimblebrain-local, or NIMBLEBRAIN_HOME)
|
|
1161
1304
|
--provider <name> The model provider for key (default anthropic)
|
|
1305
|
+
--local-model <model> init: run on this Ollama model instead of a hosted key
|
|
1162
1306
|
--runtime <tag> The NimbleBrain release to install or update to (default the newest)
|
|
1163
1307
|
--telemetry <on|off> The person's answer to sending anonymous usage data; without it, init asks or leaves it undecided
|
|
1164
1308
|
--help, --version
|
|
@@ -1185,7 +1329,7 @@ async function run(argv, deps) {
|
|
|
1185
1329
|
case "doctor": {
|
|
1186
1330
|
const install = await readInstall(deps, home);
|
|
1187
1331
|
const ours = install !== undefined && install.port === flags.port && await isHealthy(deps, flags.port);
|
|
1188
|
-
result = { ...await
|
|
1332
|
+
result = { ...await doctorInstall(deps, home, flags.port, ours) };
|
|
1189
1333
|
break;
|
|
1190
1334
|
}
|
|
1191
1335
|
case "status":
|
|
@@ -1193,7 +1337,17 @@ async function run(argv, deps) {
|
|
|
1193
1337
|
break;
|
|
1194
1338
|
default: {
|
|
1195
1339
|
const ctx = { deps, flags, home, version: VERSION2, arg };
|
|
1196
|
-
const commands = {
|
|
1340
|
+
const commands = {
|
|
1341
|
+
init,
|
|
1342
|
+
up,
|
|
1343
|
+
down,
|
|
1344
|
+
logs,
|
|
1345
|
+
update,
|
|
1346
|
+
uninstall,
|
|
1347
|
+
key,
|
|
1348
|
+
telemetry,
|
|
1349
|
+
"local-model": localModel
|
|
1350
|
+
};
|
|
1197
1351
|
result = await commands[command](ctx);
|
|
1198
1352
|
}
|
|
1199
1353
|
}
|
|
@@ -1205,6 +1359,23 @@ async function run(argv, deps) {
|
|
|
1205
1359
|
}
|
|
1206
1360
|
return render(result, flags.json, command);
|
|
1207
1361
|
}
|
|
1362
|
+
async function doctorInstall(deps, home, port, ours) {
|
|
1363
|
+
const machine = await doctor(deps, port, ours);
|
|
1364
|
+
const model = localModelOf(await deps.readText(paths(home).env) ?? "");
|
|
1365
|
+
if (!model)
|
|
1366
|
+
return machine;
|
|
1367
|
+
try {
|
|
1368
|
+
return { ...machine, checks: [...machine.checks, ...await checkLocalModel(deps, model)] };
|
|
1369
|
+
} catch (err) {
|
|
1370
|
+
if (!(err instanceof CliError))
|
|
1371
|
+
throw err;
|
|
1372
|
+
const local = err.detail.checks ?? [];
|
|
1373
|
+
throw new CliError(err.code, err.message, {
|
|
1374
|
+
...err.detail,
|
|
1375
|
+
checks: [...machine.checks, ...local]
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1208
1379
|
async function isHealthy(deps, port) {
|
|
1209
1380
|
const res = await deps.getJson(`http://127.0.0.1:${port}/v1/health`);
|
|
1210
1381
|
return res?.status === 200;
|
|
@@ -1241,7 +1412,7 @@ function statusLines(r, command) {
|
|
|
1241
1412
|
...changeLines(r),
|
|
1242
1413
|
` NimbleBrain ${r.version.startsWith("v") ? r.version : `v${r.version}`}: ${r.health === "ok" ? "running" : "stopped"} at ${r.url}`,
|
|
1243
1414
|
...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)"}`
|
|
1415
|
+
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
1416
|
];
|
|
1246
1417
|
const agent = r.agent.connected;
|
|
1247
1418
|
if (agent) {
|
package/package.json
CHANGED