nimblebrain 0.7.0 → 0.7.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.
Files changed (2) hide show
  1. package/dist/nimblebrain.js +43 -13
  2. package/package.json +1 -1
@@ -1168,6 +1168,8 @@ var TELEMETRY_KEY = "phc_qKmpYhdDtcFYZchu3KAKFFmYHG88nfUDPCFqxoAmbS7E";
1168
1168
  var ENDPOINT = "https://us.i.posthog.com/batch/";
1169
1169
  var QUESTION = "Help improve NimbleBrain by sending anonymous usage data? No prompts, content, names or keys are sent.";
1170
1170
  var reportPath = (home) => join4(home, "telemetry-report.jsonl");
1171
+ var idPath = (home) => join4(home, "telemetry-id");
1172
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1171
1173
  var RELEASED = true;
1172
1174
  function telemetryKey(deps) {
1173
1175
  return deps.env.NIMBLEBRAIN_TELEMETRY_KEY ?? (RELEASED ? TELEMETRY_KEY : "");
@@ -1237,6 +1239,21 @@ async function send(deps, home, batch) {
1237
1239
  else
1238
1240
  await deps.writeText(reportPath(home), toLines(batch), 384);
1239
1241
  }
1242
+ async function installId(deps, home) {
1243
+ if (lockedHere(deps))
1244
+ return;
1245
+ try {
1246
+ const kept = (await deps.readText(idPath(home)))?.trim();
1247
+ if (kept && UUID.test(kept))
1248
+ return kept.toLowerCase();
1249
+ const id = await reportId(deps, home) ?? randomUUID();
1250
+ await deps.writeText(idPath(home), `${id}
1251
+ `, 384);
1252
+ return id;
1253
+ } catch {
1254
+ return;
1255
+ }
1256
+ }
1240
1257
  async function reportId(deps, home) {
1241
1258
  return (await readReport(deps, home))[0]?.distinct_id;
1242
1259
  }
@@ -1284,9 +1301,10 @@ async function settleWaiting(deps, home, version) {
1284
1301
  }
1285
1302
  function envValues(deps, id, consent, asksFirst) {
1286
1303
  const values = {
1287
- NB_TELEMETRY_ID: id,
1288
1304
  NB_TELEMETRY_KEY: asksFirst ? telemetryKey(deps) : ""
1289
1305
  };
1306
+ if (id)
1307
+ values.NB_TELEMETRY_ID = id;
1290
1308
  if (consent !== "undecided")
1291
1309
  values.NB_TELEMETRY_CONSENT = consent;
1292
1310
  return values;
@@ -1316,7 +1334,7 @@ async function setRuntimeTelemetry(deps, url, consent) {
1316
1334
  // package.json
1317
1335
  var package_default = {
1318
1336
  name: "nimblebrain",
1319
- version: "0.7.0",
1337
+ version: "0.7.1",
1320
1338
  description: "Install, run and connect NimbleBrain, the open-source runtime for agents and MCP apps, on this machine.",
1321
1339
  license: "Apache-2.0",
1322
1340
  type: "module",
@@ -1515,7 +1533,8 @@ async function init(ctx) {
1515
1533
  if (await readInstall(deps, home))
1516
1534
  return { ...await status(deps, home), already: true };
1517
1535
  const consent = await chooseConsent(ctx);
1518
- const rec = recorder2(deps, ctx.version, await reportId(deps, home));
1536
+ const id = await foreignFile(deps, home) ? undefined : await installId(deps, home);
1537
+ const rec = recorder2(deps, ctx.version, id ?? await reportId(deps, home));
1519
1538
  const begun = Date.now();
1520
1539
  rec.record("cli.init_started", { agent: flags.agent ?? null, interactive: deps.interactive });
1521
1540
  try {
@@ -1560,7 +1579,7 @@ async function install(ctx, consent, rec, begun) {
1560
1579
  const tag = await runtimeTag(deps, flags.runtime);
1561
1580
  const composeText = await fetchCompose(deps, tag);
1562
1581
  await confirmStart(ctx, tag);
1563
- await writeInstallFiles(deps, home, project, tag, flags.port, composeText, envValues(deps, rec.id, consent, asksConsent(composeText)));
1582
+ await writeInstallFiles(deps, home, project, tag, flags.port, composeText, envValues(deps, lockedHere(deps) ? undefined : rec.id, consent, asksConsent(composeText)));
1564
1583
  const envText = await deps.readText(paths(home).env) ?? "";
1565
1584
  const hasModel = hasKey(envText, keyVars(composeText)) || localModelOf(envText) !== undefined;
1566
1585
  const local = flags.localModel ?? (!hasModel && asks(ctx) && takesLocalModel(composeText) ? await chooseModelSource(deps) : undefined);
@@ -1708,7 +1727,7 @@ async function uninstall(ctx) {
1708
1727
  await deps.exec("claude", ["mcp", "remove", "-s", "user", SERVER_NAME]);
1709
1728
  if (install.agent === "codex")
1710
1729
  await deps.exec("codex", ["mcp", "remove", SERVER_NAME]);
1711
- for (const file of [...Object.values(paths(home)), reportPath(home)])
1730
+ for (const file of [...Object.values(paths(home)), reportPath(home), idPath(home)])
1712
1731
  await deps.remove(file);
1713
1732
  await deps.remove(home);
1714
1733
  return { ok: true, removed: true };
@@ -1851,15 +1870,12 @@ async function requireInstall({ deps, home }) {
1851
1870
  }
1852
1871
  async function guardOurs(deps, home) {
1853
1872
  const project = projectFor(home);
1854
- const env = await deps.readText(paths(home).env);
1855
- const marked = env?.match(/^COMPOSE_PROJECT_NAME=(.*?)\r?$/m)?.[1];
1856
- if (marked === project || marked === DEFAULT_PROJECT)
1873
+ const marked = await markedProject(deps, home);
1874
+ if (marked)
1857
1875
  return marked;
1858
- for (const file of Object.values(paths(home))) {
1859
- if (await deps.readText(file) !== undefined) {
1860
- throw new CliError("NOT_OURS", `${file} already exists and this CLI did not write it.`);
1861
- }
1862
- }
1876
+ const file = await foreignFile(deps, home);
1877
+ if (file)
1878
+ throw new CliError("NOT_OURS", `${file} already exists and this CLI did not write it.`);
1863
1879
  const projects = await composeExec(deps, ["ls", "-a", "--format", "json"]);
1864
1880
  const taken = projects.code === 0 && listsProject(projects.stdout, project);
1865
1881
  const volumes = await deps.exec("docker", [
@@ -1874,6 +1890,20 @@ async function guardOurs(deps, home) {
1874
1890
  }
1875
1891
  return project;
1876
1892
  }
1893
+ async function markedProject(deps, home) {
1894
+ const env = await deps.readText(paths(home).env);
1895
+ const marked = env?.match(/^COMPOSE_PROJECT_NAME=(.*?)\r?$/m)?.[1];
1896
+ return marked === projectFor(home) || marked === DEFAULT_PROJECT ? marked : undefined;
1897
+ }
1898
+ async function foreignFile(deps, home) {
1899
+ if (await markedProject(deps, home))
1900
+ return;
1901
+ for (const file of Object.values(paths(home))) {
1902
+ if (await deps.readText(file) !== undefined)
1903
+ return file;
1904
+ }
1905
+ return;
1906
+ }
1877
1907
  function listsProject(stdout, project) {
1878
1908
  try {
1879
1909
  const list = JSON.parse(stdout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nimblebrain",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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",