nimblebrain 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/dist/nimblebrain.js +99 -31
  2. package/package.json +1 -1
@@ -426,20 +426,35 @@ function manualSettings(agent, mcpUrl) {
426
426
  }
427
427
  async function installSkill(deps, agent) {
428
428
  if (agent === "none")
429
- return null;
430
- const res = await deps.exec("npx", [
429
+ return;
430
+ await deps.exec("npx", [
431
431
  "-y",
432
432
  "skills",
433
433
  "add",
434
434
  "nimblebraininc/skills",
435
435
  "--skill",
436
- "nimblebrain",
436
+ SKILL_NAME,
437
437
  "--agent",
438
438
  agent,
439
439
  "-g",
440
440
  "-y"
441
441
  ], { timeoutMs: 120000 });
442
- return res.code === 0 ? "nimblebrain" : null;
442
+ }
443
+ var SKILL_NAME = "nimblebrain";
444
+ function globalSkillsDir(deps, agent) {
445
+ if (agent === "claude-code")
446
+ return join2(deps.env.CLAUDE_CONFIG_DIR?.trim() || join2(deps.home, ".claude"), "skills");
447
+ if (agent === "codex")
448
+ return join2(deps.home, ".agents", "skills");
449
+ if (agent === "cursor")
450
+ return join2(deps.home, ".cursor", "skills");
451
+ return;
452
+ }
453
+ async function skillInstalled(deps, agent) {
454
+ const dir = globalSkillsDir(deps, agent);
455
+ if (!dir)
456
+ return null;
457
+ return await deps.readText(join2(dir, SKILL_NAME, "SKILL.md")) === undefined ? null : SKILL_NAME;
443
458
  }
444
459
 
445
460
  // src/compose.ts
@@ -763,7 +778,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
763
778
  // package.json
764
779
  var package_default = {
765
780
  name: "nimblebrain",
766
- version: "0.1.0",
781
+ version: "0.1.2",
767
782
  description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
768
783
  license: "Apache-2.0",
769
784
  type: "module",
@@ -822,7 +837,10 @@ async function status(deps, home) {
822
837
  health: up ? "ok" : "down",
823
838
  url,
824
839
  workspaces,
825
- agent: { connected: install.agent ?? null, skill: install.skill ?? null },
840
+ agent: {
841
+ connected: install.agent ?? null,
842
+ skill: install.agent ? await skillInstalled(deps, install.agent) : null
843
+ },
826
844
  model_key: modelKey,
827
845
  telemetry: await currentTelemetry(deps, home, url)
828
846
  };
@@ -843,42 +861,48 @@ async function init(ctx) {
843
861
  const { deps, flags, home } = ctx;
844
862
  if (await readInstall(deps, home))
845
863
  return { ...await status(deps, home), already: true };
846
- const consent = await chooseConsent(ctx);
864
+ const answer = { consent: await chooseConsent(ctx, false) };
847
865
  const rec = recorder2(deps, ctx.version, await reportId(deps, home));
848
866
  const begun = Date.now();
849
867
  rec.record("cli.init_started", { agent: flags.agent ?? null, interactive: deps.interactive });
850
868
  try {
851
- return await install(ctx, consent, rec, begun);
869
+ return await install(ctx, answer, rec, begun);
852
870
  } catch (err) {
853
871
  if (!(err instanceof CliError))
854
872
  throw err;
855
- if (err.code !== "MODEL_KEY_MISSING") {
856
- const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
857
- rec.record(check ? "cli.doctor_failed" : "cli.init_failed", { error: err.code, check });
858
- }
859
- await rec.settle(home, consent);
873
+ if (err.code !== "CANCELLED" || answer.consent !== "undecided")
874
+ await settleFailure(rec, home, answer.consent, err);
860
875
  throw new CliError(err.code, err.message, {
861
876
  ...err.detail,
862
- telemetry: field(consent, lockedHere(deps))
877
+ telemetry: field(answer.consent, lockedHere(deps))
863
878
  });
864
879
  }
865
880
  }
866
- async function chooseConsent(ctx) {
881
+ async function settleFailure(rec, home, consent, err) {
882
+ if (err.code !== "MODEL_KEY_MISSING") {
883
+ const check = typeof err.detail.check === "string" ? err.detail.check : undefined;
884
+ rec.record(check ? "cli.doctor_failed" : "cli.init_failed", { error: err.code, check });
885
+ }
886
+ await rec.settle(home, consent);
887
+ }
888
+ async function chooseConsent(ctx, ask) {
867
889
  if (lockedHere(ctx.deps))
868
890
  return "off";
869
891
  if (ctx.flags.telemetry)
870
892
  return ctx.flags.telemetry;
871
- if (!asks(ctx))
893
+ if (!ask || !asks(ctx))
872
894
  return "undecided";
873
895
  return parseAnswer(await ctx.deps.prompt(`${QUESTION} [y/N] `));
874
896
  }
875
- async function install(ctx, consent, rec, begun) {
897
+ async function install(ctx, answer, rec, begun) {
876
898
  const { deps, flags, home } = ctx;
877
899
  await doctor(deps, flags.port);
878
900
  await guardOurs(deps, home);
879
901
  const tag = await runtimeTag(deps, flags.runtime);
880
902
  const composeText = await fetchCompose(deps, tag);
881
903
  await confirmStart(ctx, tag);
904
+ answer.consent = await chooseConsent(ctx, true);
905
+ const { consent } = answer;
882
906
  await writeInstallFiles(deps, home, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
883
907
  if (!hasKey(await deps.readText(paths(home).env) ?? "", keyVars(composeText)) && asks(ctx))
884
908
  await enterKey(ctx, false);
@@ -924,7 +948,7 @@ async function connectChosenAgent(ctx, state) {
924
948
  const conn = await connectAgent(deps, agent, first.mcp);
925
949
  if (conn.connected) {
926
950
  state.agent = conn.connected;
927
- state.skill = await installSkill(deps, conn.connected) ?? undefined;
951
+ await installSkill(deps, conn.connected);
928
952
  await writeState(deps, home, state);
929
953
  }
930
954
  return conn.manual;
@@ -1032,6 +1056,7 @@ async function enterKey(ctx, restart) {
1032
1056
  const offered = providers(await deps.readText(paths(home).compose) ?? "");
1033
1057
  const names = Object.keys(offered);
1034
1058
  let provider = flags.provider;
1059
+ deps.say("NimbleBrain's own agents run on a model key you give it, billed by that provider.");
1035
1060
  if (!provider) {
1036
1061
  const answer = await deps.prompt(`Model provider (${names.join(", ")}) [anthropic]: `);
1037
1062
  provider = answer || "anthropic";
@@ -1051,7 +1076,8 @@ async function enterKey(ctx, restart) {
1051
1076
  return { ok: true, provider, model_key: "set" };
1052
1077
  }
1053
1078
  async function chooseAgent(deps) {
1054
- const answer = await deps.prompt(`Connect which coding agent? (${AGENTS.join(", ")}) [none]: `);
1079
+ deps.say("A coding agent you connect can use NimbleBrain's tools. NimbleBrain's own agents still run on the model key above.");
1080
+ const answer = await deps.prompt(`Connect a coding agent? (${AGENTS.join(", ")}) [none]: `);
1055
1081
  return AGENTS.includes(answer) ? answer : "none";
1056
1082
  }
1057
1083
  async function start(deps, home, port) {
@@ -1177,7 +1203,7 @@ async function run(argv, deps) {
1177
1203
  if (!["init", "telemetry", "uninstall", "doctor"].includes(command)) {
1178
1204
  await settleWaiting(deps, home, VERSION2);
1179
1205
  }
1180
- return render(result, flags.json);
1206
+ return render(result, flags.json, command);
1181
1207
  }
1182
1208
  async function isHealthy(deps, port) {
1183
1209
  const res = await deps.getJson(`http://127.0.0.1:${port}/v1/health`);
@@ -1188,7 +1214,7 @@ function toFailure(err) {
1188
1214
  return failure(err);
1189
1215
  return failure(new CliError("USAGE", err instanceof Error ? err.message : String(err)));
1190
1216
  }
1191
- function render(result, json) {
1217
+ function render(result, json, command) {
1192
1218
  const code = exitCodeFor(result);
1193
1219
  if (json)
1194
1220
  return { stdout: `${JSON.stringify(result)}
@@ -1197,23 +1223,65 @@ function render(result, json) {
1197
1223
  return { stdout: `error: ${result.message}
1198
1224
  fix: ${result.fix}
1199
1225
  `, code };
1200
- return { stdout: human(result), code };
1201
- }
1202
- function human(result) {
1203
- const lines = Object.entries(result).filter(([key]) => key !== "ok").flatMap(([key, value]) => field2(key, value));
1204
- return `${lines.join(`
1226
+ const lines = isStatus(result) ? statusLines(result, command) : genericLines(result);
1227
+ return { stdout: `${lines.join(`
1205
1228
  `)}
1206
- `;
1229
+ `, code };
1230
+ }
1231
+ function isStatus(result) {
1232
+ return "health" in result && "url" in result && "workspaces" in result;
1233
+ }
1234
+ var AGENT_NAMES = {
1235
+ "claude-code": "Claude Code",
1236
+ cursor: "Cursor",
1237
+ codex: "Codex"
1238
+ };
1239
+ function statusLines(r, command) {
1240
+ const lines = [
1241
+ ...changeLines(r),
1242
+ ` NimbleBrain ${r.version.startsWith("v") ? r.version : `v${r.version}`}: ${r.health === "ok" ? "running" : "stopped"} at ${r.url}`,
1243
+ ...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)"}`
1245
+ ];
1246
+ const agent = r.agent.connected;
1247
+ if (agent) {
1248
+ const name = AGENT_NAMES[agent] ?? agent;
1249
+ lines.push(` ${name} can use NimbleBrain's tools (it loads them when its next session starts)`);
1250
+ if (!r.agent.skill)
1251
+ lines.push(` skill: not installed; add it with npx skills add nimblebraininc/skills --skill nimblebrain --agent ${agent} -g`);
1252
+ } else if (r.manual) {
1253
+ lines.push(` agent: not connected; add it by hand: ${r.manual}`);
1254
+ }
1255
+ lines.push(telemetryLine(r.telemetry));
1256
+ lines.push(` CLI ${r.cli_version}`);
1257
+ if (command === "init" && !r.already && r.health === "ok") {
1258
+ const ask = agent ? `, or ask ${AGENT_NAMES[agent] ?? agent} what NimbleBrain can do` : "";
1259
+ lines.push("", `Next: open ${r.url}${ask}. Stop it with npx nimblebrain down.`);
1260
+ }
1261
+ return lines;
1262
+ }
1263
+ function changeLines(r) {
1264
+ if (r.already)
1265
+ return [" already installed"];
1266
+ return r.from ? [` updated from ${r.from}`] : [];
1267
+ }
1268
+ function telemetryLine(t) {
1269
+ const how = t.locked ? ` (${t.locked})` : t.set ? ` (answer with ${t.set})` : "";
1270
+ return ` telemetry: ${t.state}${how}`;
1271
+ }
1272
+ function genericLines(result) {
1273
+ return Object.entries(result).filter(([key]) => key !== "ok").flatMap(([key, value]) => field2(key, value));
1207
1274
  }
1208
1275
  function field2(key, value) {
1276
+ if (value === undefined || value === null)
1277
+ return [];
1209
1278
  if (key === "checks" && Array.isArray(value)) {
1210
1279
  return value.map((c) => ` ${c.ok ? "✓" : "✗"} ${c.check}: ${c.detail}`);
1211
1280
  }
1212
- if (key === "workspaces" && Array.isArray(value)) {
1213
- return value.map((w) => ` workspace ${w.name}: ${w.mcp}`);
1281
+ if (typeof value === "object" && !Array.isArray(value)) {
1282
+ return Object.entries(value).flatMap(([k, v]) => field2(`${key} ${k}`, v));
1214
1283
  }
1215
- const text = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
1216
- return [` ${key}: ${text}`];
1284
+ return [` ${key}: ${Array.isArray(value) ? value.join(", ") : String(value)}`];
1217
1285
  }
1218
1286
  function interrupted(argv, exitCode) {
1219
1287
  const err = new CliError("INTERRUPTED", `The CLI stopped before it answered (exit code ${exitCode}).`, { exit_code: exitCode });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nimblebrain",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",