nimblebrain 0.1.1 → 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 +300 -111
- 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 } };
|
|
@@ -426,122 +537,132 @@ function manualSettings(agent, mcpUrl) {
|
|
|
426
537
|
}
|
|
427
538
|
async function installSkill(deps, agent) {
|
|
428
539
|
if (agent === "none")
|
|
429
|
-
return
|
|
430
|
-
|
|
540
|
+
return;
|
|
541
|
+
await deps.exec("npx", [
|
|
431
542
|
"-y",
|
|
432
543
|
"skills",
|
|
433
544
|
"add",
|
|
434
545
|
"nimblebraininc/skills",
|
|
435
546
|
"--skill",
|
|
436
|
-
|
|
547
|
+
SKILL_NAME,
|
|
437
548
|
"--agent",
|
|
438
549
|
agent,
|
|
439
550
|
"-g",
|
|
440
551
|
"-y"
|
|
441
552
|
], { timeoutMs: 120000 });
|
|
442
|
-
return res.code === 0 ? "nimblebrain" : null;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// src/compose.ts
|
|
446
|
-
import { join as join3 } from "node:path";
|
|
447
|
-
var PROJECT = "nimblebrain-local";
|
|
448
|
-
var VOLUME = `${PROJECT}_workspace`;
|
|
449
|
-
var RAW = "https://raw.githubusercontent.com/NimbleBrainInc/nimblebrain";
|
|
450
|
-
async function fetchCompose(deps, tag) {
|
|
451
|
-
const res = await deps.getText(`${RAW}/${tag}/docker-compose.yml`, 15000);
|
|
452
|
-
if (!res)
|
|
453
|
-
throw new CliError("NETWORK", `Could not download the Compose file for ${tag}.`);
|
|
454
|
-
if (res.status === 404) {
|
|
455
|
-
throw new CliError("RUNTIME_UNSUPPORTED", `NimbleBrain ${tag} has no Compose file to install.`);
|
|
456
|
-
}
|
|
457
|
-
if (res.status !== 200) {
|
|
458
|
-
throw new CliError("NETWORK", `Downloading the Compose file for ${tag} answered ${res.status}.`);
|
|
459
|
-
}
|
|
460
|
-
if (!res.body.includes("${NIMBLEBRAIN_TAG") || !res.body.includes("NIMBLEBRAIN_WEB_PORT")) {
|
|
461
|
-
throw new CliError("RUNTIME_UNSUPPORTED", `NimbleBrain ${tag}'s Compose file does not take its image tag and port from .env.`);
|
|
462
|
-
}
|
|
463
|
-
return res.body;
|
|
464
|
-
}
|
|
465
|
-
function keyVars(composeText) {
|
|
466
|
-
return [
|
|
467
|
-
...new Set([...composeText.matchAll(/\b([A-Z][A-Z0-9_]*_API_KEY)=\$\{\1\b/g)].map((m) => m[1] ?? ""))
|
|
468
|
-
];
|
|
469
553
|
}
|
|
470
|
-
|
|
471
|
-
|
|
554
|
+
var SKILL_NAME = "nimblebrain";
|
|
555
|
+
function globalSkillsDir(deps, agent) {
|
|
556
|
+
if (agent === "claude-code")
|
|
557
|
+
return join3(deps.env.CLAUDE_CONFIG_DIR?.trim() || join3(deps.home, ".claude"), "skills");
|
|
558
|
+
if (agent === "codex")
|
|
559
|
+
return join3(deps.home, ".agents", "skills");
|
|
560
|
+
if (agent === "cursor")
|
|
561
|
+
return join3(deps.home, ".cursor", "skills");
|
|
562
|
+
return;
|
|
472
563
|
}
|
|
473
|
-
function
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
564
|
+
async function skillInstalled(deps, agent) {
|
|
565
|
+
const dir = globalSkillsDir(deps, agent);
|
|
566
|
+
if (!dir)
|
|
567
|
+
return null;
|
|
568
|
+
return await deps.readText(join3(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
|
|
478
569
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
570
|
+
|
|
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
|
+
});
|
|
491
605
|
}
|
|
492
|
-
return
|
|
493
|
-
}
|
|
494
|
-
async function
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
+
}
|
|
509
625
|
}
|
|
510
|
-
if (
|
|
511
|
-
|
|
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" });
|
|
512
628
|
}
|
|
513
|
-
|
|
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
|
+
});
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
NB_LOCAL_MODEL_URL: OLLAMA_FROM_CONTAINER,
|
|
638
|
+
NB_LOCAL_MODEL: name,
|
|
639
|
+
NB_LOCAL_MODEL_CONTEXT: String(LOCAL_CONTEXT)
|
|
640
|
+
};
|
|
514
641
|
}
|
|
515
|
-
function
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const name = line.match(/^([A-Z][A-Z0-9_]*)=/)?.[1];
|
|
521
|
-
if (name && name in values) {
|
|
522
|
-
seen.add(name);
|
|
523
|
-
return `${name}=${values[name]}`;
|
|
524
|
-
}
|
|
525
|
-
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 });
|
|
526
647
|
});
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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;
|
|
536
665
|
}
|
|
537
|
-
var paths = (home) => ({
|
|
538
|
-
compose: join3(home, "docker-compose.yml"),
|
|
539
|
-
env: join3(home, ".env"),
|
|
540
|
-
instance: join3(home, "instance.json"),
|
|
541
|
-
install: join3(home, "install.json")
|
|
542
|
-
});
|
|
543
|
-
var INSTANCE_JSON = `${JSON.stringify({ auth: { adapter: "dev" } }, null, 2)}
|
|
544
|
-
`;
|
|
545
666
|
|
|
546
667
|
// src/release.ts
|
|
547
668
|
var REFS_URL = "https://github.com/NimbleBrainInc/nimblebrain.git/info/refs?service=git-upload-pack";
|
|
@@ -763,7 +884,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
|
|
|
763
884
|
// package.json
|
|
764
885
|
var package_default = {
|
|
765
886
|
name: "nimblebrain",
|
|
766
|
-
version: "0.
|
|
887
|
+
version: "0.2.0",
|
|
767
888
|
description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
|
|
768
889
|
license: "Apache-2.0",
|
|
769
890
|
type: "module",
|
|
@@ -814,7 +935,8 @@ async function status(deps, home) {
|
|
|
814
935
|
const up = health?.status === 200 && health.body?.status === "ok";
|
|
815
936
|
const workspaces = up ? await readWorkspaces(deps, url) : [];
|
|
816
937
|
const vars = keyVars(await deps.readText(join5(home, "docker-compose.yml")) ?? "");
|
|
817
|
-
const
|
|
938
|
+
const envText = await deps.readText(join5(home, ".env")) ?? "";
|
|
939
|
+
const modelKey = hasKey(envText, vars) ? "set" : "missing";
|
|
818
940
|
return {
|
|
819
941
|
ok: true,
|
|
820
942
|
version: install.version,
|
|
@@ -822,8 +944,12 @@ async function status(deps, home) {
|
|
|
822
944
|
health: up ? "ok" : "down",
|
|
823
945
|
url,
|
|
824
946
|
workspaces,
|
|
825
|
-
agent: {
|
|
947
|
+
agent: {
|
|
948
|
+
connected: install.agent ?? null,
|
|
949
|
+
skill: install.agent ? await skillInstalled(deps, install.agent) : null
|
|
950
|
+
},
|
|
826
951
|
model_key: modelKey,
|
|
952
|
+
local_model: localModelOf(envText) ?? null,
|
|
827
953
|
telemetry: await currentTelemetry(deps, home, url)
|
|
828
954
|
};
|
|
829
955
|
}
|
|
@@ -886,7 +1012,12 @@ async function install(ctx, answer, rec, begun) {
|
|
|
886
1012
|
answer.consent = await chooseConsent(ctx, true);
|
|
887
1013
|
const { consent } = answer;
|
|
888
1014
|
await writeInstallFiles(deps, home, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
|
|
889
|
-
|
|
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))
|
|
890
1021
|
await enterKey(ctx, false);
|
|
891
1022
|
deps.say(`Starting NimbleBrain ${tag}. The first start downloads about 2 GB of images.`);
|
|
892
1023
|
await start(deps, home, flags.port);
|
|
@@ -905,7 +1036,7 @@ async function install(ctx, answer, rec, begun) {
|
|
|
905
1036
|
model_key: result.model_key
|
|
906
1037
|
});
|
|
907
1038
|
await rec.settle(home, consent);
|
|
908
|
-
if (result.model_key === "missing") {
|
|
1039
|
+
if (result.model_key === "missing" && !result.local_model) {
|
|
909
1040
|
throw new CliError("MODEL_KEY_MISSING", "NimbleBrain is running; chat needs a model key.", {
|
|
910
1041
|
...result
|
|
911
1042
|
});
|
|
@@ -930,7 +1061,7 @@ async function connectChosenAgent(ctx, state) {
|
|
|
930
1061
|
const conn = await connectAgent(deps, agent, first.mcp);
|
|
931
1062
|
if (conn.connected) {
|
|
932
1063
|
state.agent = conn.connected;
|
|
933
|
-
|
|
1064
|
+
await installSkill(deps, conn.connected);
|
|
934
1065
|
await writeState(deps, home, state);
|
|
935
1066
|
}
|
|
936
1067
|
return conn.manual;
|
|
@@ -1057,6 +1188,35 @@ async function enterKey(ctx, restart) {
|
|
|
1057
1188
|
}
|
|
1058
1189
|
return { ok: true, provider, model_key: "set" };
|
|
1059
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
|
+
}
|
|
1060
1220
|
async function chooseAgent(deps) {
|
|
1061
1221
|
deps.say("A coding agent you connect can use NimbleBrain's tools. NimbleBrain's own agents still run on the model key above.");
|
|
1062
1222
|
const answer = await deps.prompt(`Connect a coding agent? (${AGENTS.join(", ")}) [none]: `);
|
|
@@ -1128,6 +1288,7 @@ Commands:
|
|
|
1128
1288
|
doctor Check Docker, Compose, architecture, memory and the port; installs nothing
|
|
1129
1289
|
status Version, health, URL and each workspace's MCP URL
|
|
1130
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)
|
|
1131
1292
|
telemetry [on|off|status] Whether this install sends anonymous usage data
|
|
1132
1293
|
up, down Start or stop NimbleBrain; data survives down
|
|
1133
1294
|
logs Recent runtime log lines
|
|
@@ -1141,6 +1302,7 @@ Flags:
|
|
|
1141
1302
|
--port <n> Local port (default 27246)
|
|
1142
1303
|
--home <dir> Where the install lives (default ~/.nimblebrain-local, or NIMBLEBRAIN_HOME)
|
|
1143
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
|
|
1144
1306
|
--runtime <tag> The NimbleBrain release to install or update to (default the newest)
|
|
1145
1307
|
--telemetry <on|off> The person's answer to sending anonymous usage data; without it, init asks or leaves it undecided
|
|
1146
1308
|
--help, --version
|
|
@@ -1167,7 +1329,7 @@ async function run(argv, deps) {
|
|
|
1167
1329
|
case "doctor": {
|
|
1168
1330
|
const install = await readInstall(deps, home);
|
|
1169
1331
|
const ours = install !== undefined && install.port === flags.port && await isHealthy(deps, flags.port);
|
|
1170
|
-
result = { ...await
|
|
1332
|
+
result = { ...await doctorInstall(deps, home, flags.port, ours) };
|
|
1171
1333
|
break;
|
|
1172
1334
|
}
|
|
1173
1335
|
case "status":
|
|
@@ -1175,7 +1337,17 @@ async function run(argv, deps) {
|
|
|
1175
1337
|
break;
|
|
1176
1338
|
default: {
|
|
1177
1339
|
const ctx = { deps, flags, home, version: VERSION2, arg };
|
|
1178
|
-
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
|
+
};
|
|
1179
1351
|
result = await commands[command](ctx);
|
|
1180
1352
|
}
|
|
1181
1353
|
}
|
|
@@ -1187,6 +1359,23 @@ async function run(argv, deps) {
|
|
|
1187
1359
|
}
|
|
1188
1360
|
return render(result, flags.json, command);
|
|
1189
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
|
+
}
|
|
1190
1379
|
async function isHealthy(deps, port) {
|
|
1191
1380
|
const res = await deps.getJson(`http://127.0.0.1:${port}/v1/health`);
|
|
1192
1381
|
return res?.status === 200;
|
|
@@ -1223,14 +1412,14 @@ function statusLines(r, command) {
|
|
|
1223
1412
|
...changeLines(r),
|
|
1224
1413
|
` NimbleBrain ${r.version.startsWith("v") ? r.version : `v${r.version}`}: ${r.health === "ok" ? "running" : "stopped"} at ${r.url}`,
|
|
1225
1414
|
...r.workspaces.map((w) => ` workspace ${w.name}: ${w.mcp}`),
|
|
1226
|
-
` 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)"}`
|
|
1227
1416
|
];
|
|
1228
1417
|
const agent = r.agent.connected;
|
|
1229
1418
|
if (agent) {
|
|
1230
1419
|
const name = AGENT_NAMES[agent] ?? agent;
|
|
1231
1420
|
lines.push(` ${name} can use NimbleBrain's tools (it loads them when its next session starts)`);
|
|
1232
1421
|
if (!r.agent.skill)
|
|
1233
|
-
lines.push(` skill: not installed; add it with npx skills add nimblebraininc/skills --skill nimblebrain`);
|
|
1422
|
+
lines.push(` skill: not installed; add it with npx skills add nimblebraininc/skills --skill nimblebrain --agent ${agent} -g`);
|
|
1234
1423
|
} else if (r.manual) {
|
|
1235
1424
|
lines.push(` agent: not connected; add it by hand: ${r.manual}`);
|
|
1236
1425
|
}
|
package/package.json
CHANGED