@bendyline/gezel-cli 1.2.9 → 1.2.11

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.
@@ -20,7 +20,9 @@ import {
20
20
  createTrustingFetch as createTrustingFetch2,
21
21
  discoverOrSpawn as discoverOrSpawn2,
22
22
  isProcessAlive as isProcessAlive2,
23
+ listProcessSnapshots,
23
24
  readRuntime as readRuntime2,
25
+ requestDaemonHealth,
24
26
  resolveDaemonEntry as resolveDaemonEntry2,
25
27
  stopOwnedDaemon as stopOwnedDaemon2,
26
28
  stopProcessByPid
@@ -967,7 +969,8 @@ async function waitForTask(client, ref, options) {
967
969
  () => client.listQuestions(
968
970
  {
969
971
  projectId: task2.projectId,
970
- pending: true
972
+ pending: true,
973
+ taskRefs: [...refs]
971
974
  },
972
975
  signal
973
976
  )
@@ -1341,7 +1344,8 @@ function errorMessage(error) {
1341
1344
  // src/settings-command.ts
1342
1345
  import {
1343
1346
  classifySecurityLevel,
1344
- resolveSecurityPolicy
1347
+ resolveSecurityPolicy,
1348
+ securityCapabilitiesOf
1345
1349
  } from "@bendyline/gezel";
1346
1350
  var SECURITY_LEVEL_LABELS = {
1347
1351
  "super-lockdown": "Super Lockdown",
@@ -1349,17 +1353,33 @@ var SECURITY_LEVEL_LABELS = {
1349
1353
  free: "Unrestricted",
1350
1354
  custom: "Custom"
1351
1355
  };
1352
- function policyWithExternalServices(config, enabled) {
1353
- const current = resolveSecurityPolicy(config);
1354
- const caps = {
1355
- allowFileEdits: current.allowFileEdits,
1356
- allowExternalChat: current.allowExternalChat,
1357
- allowExternalServices: enabled,
1358
- allowScriptExecution: current.allowScriptExecution,
1359
- allowAppNetwork: current.allowAppNetwork
1360
- };
1356
+ function policyWithCapability(config, key, enabled) {
1357
+ const caps = { ...securityCapabilitiesOf(resolveSecurityPolicy(config)), [key]: enabled };
1361
1358
  return { level: classifySecurityLevel(caps), ...caps };
1362
1359
  }
1360
+ function policyWithExternalServices(config, enabled) {
1361
+ return policyWithCapability(config, "allowExternalServices", enabled);
1362
+ }
1363
+ var SECURITY_SWITCHES = [
1364
+ {
1365
+ command: "external-services",
1366
+ key: "allowExternalServices",
1367
+ label: "External services",
1368
+ description: "Show or set on/off for model-initiated external services, including web search"
1369
+ },
1370
+ {
1371
+ command: "run-package-scripts",
1372
+ key: "allowPackageScriptExecution",
1373
+ label: "Run package scripts",
1374
+ description: "Show or set on/off for gezels running package scripts and installed package binaries (outside the sandbox, with network access)"
1375
+ },
1376
+ {
1377
+ command: "edit-package-scripts",
1378
+ key: "allowPackageScriptEdits",
1379
+ label: "Edit package scripts",
1380
+ description: "Show or set on/off for gezels adding or changing the scripts in package.json"
1381
+ }
1382
+ ];
1363
1383
  function enabledValue(state) {
1364
1384
  if (state === void 0) return void 0;
1365
1385
  if (state === "on") return true;
@@ -1367,17 +1387,33 @@ function enabledValue(state) {
1367
1387
  throw new CliError("Use on or off.");
1368
1388
  }
1369
1389
  function registerSecurityCommands(program2, connect) {
1370
- program2.command("security").description("Inspect or explicitly change security settings").command("external-services [state]").description("Show or set on/off for model-initiated external services, including web search").option("--json", "Output the setting as JSON").action(async (state, options) => {
1390
+ const security = program2.command("security").description("Inspect or explicitly change security settings");
1391
+ for (const setting of SECURITY_SWITCHES) {
1392
+ security.command(`${setting.command} [state]`).description(setting.description).option("--json", "Output the setting as JSON").action(async (state, options) => {
1393
+ const enabled = enabledValue(state);
1394
+ const client = await connect();
1395
+ const config = await client.getConfig();
1396
+ const policy = resolveSecurityPolicy(config);
1397
+ if (enabled !== void 0) {
1398
+ await client.updateConfig({
1399
+ securityPolicy: policyWithCapability(config, setting.key, enabled)
1400
+ });
1401
+ }
1402
+ const value = enabled ?? policy[setting.key];
1403
+ console.log(
1404
+ options.json ? JSON.stringify({ [setting.key]: value }) : `${setting.label}: ${value ? "on" : "off"}`
1405
+ );
1406
+ });
1407
+ }
1408
+ }
1409
+ function registerGrowthCommand(program2, connect) {
1410
+ program2.command("growth [state]").description("Show or set on/off for gezel growth: XP and the level-ups it offers").option("--json", "Output the setting as JSON").action(async (state, options) => {
1371
1411
  const enabled = enabledValue(state);
1372
1412
  const client = await connect();
1373
- const config = await client.getConfig();
1374
- const policy = resolveSecurityPolicy(config);
1375
- if (enabled !== void 0) {
1376
- await client.updateConfig({ securityPolicy: policyWithExternalServices(config, enabled) });
1377
- }
1378
- const result = { allowExternalServices: enabled ?? policy.allowExternalServices };
1413
+ const config = enabled === void 0 ? await client.getConfig() : await client.updateConfig({ growth: { enabled } });
1414
+ const value = config.growth?.enabled !== false;
1379
1415
  console.log(
1380
- options.json ? JSON.stringify(result) : `External services: ${result.allowExternalServices ? "on" : "off"}`
1416
+ options.json ? JSON.stringify({ growthEnabled: value }) : `Growth (XP and level-ups): ${value ? "on" : "off"}`
1381
1417
  );
1382
1418
  });
1383
1419
  }
@@ -1404,7 +1440,8 @@ var ENGINE_BINARY = {
1404
1440
  };
1405
1441
  async function ensureCraftbookSetup(client, options) {
1406
1442
  const services = options.needs.services ?? [];
1407
- if (!options.needs.models?.length && services.length === 0) return;
1443
+ const commands = options.needs.commands ?? [];
1444
+ if (!options.needs.models?.length && services.length === 0 && commands.length === 0) return;
1408
1445
  const config = await client.getConfig();
1409
1446
  const models = resolveCraftbookModelNeeds(options.needs.models, {
1410
1447
  ...options.params ? { params: options.params } : {},
@@ -1412,7 +1449,7 @@ async function ensureCraftbookSetup(client, options) {
1412
1449
  defaultProvider: defaultModelEngine(config, options.platform, options.arch)
1413
1450
  });
1414
1451
  const gaps = craftbookSetupGaps(
1415
- { services, models },
1452
+ { services, models, commands },
1416
1453
  await readSetupState(client, config, models)
1417
1454
  );
1418
1455
  if (gaps.length === 0) return;
@@ -1455,6 +1492,18 @@ ${lines.join("\n")}
1455
1492
  if (!yes) stop(gap);
1456
1493
  await client.updateConfig({ securityPolicy: next });
1457
1494
  options.write("External services: on\n");
1495
+ } else if (gap.kind === "package-scripts") {
1496
+ const current = await client.getConfig();
1497
+ const next = policyWithCapability(current, "allowPackageScriptExecution", true);
1498
+ const from = SECURITY_LEVEL_LABELS[resolveSecurityPolicy2(current).level];
1499
+ const to = SECURITY_LEVEL_LABELS[next.level];
1500
+ const change = from === to ? "" : ` This changes your security level from ${from} to ${to}.`;
1501
+ const yes = await prompter.confirm(
1502
+ `Let gezels run package scripts such as ${gap.commands[0]}? They run outside the sandbox, as your account, with network access, and Gezel asks before each new command.${change} [y/N] `
1503
+ );
1504
+ if (!yes) stop(gap);
1505
+ await client.updateConfig({ securityPolicy: next });
1506
+ options.write("Run package scripts: on\n");
1458
1507
  } else if (gap.kind === "web-search") {
1459
1508
  if (gap.keyMissing) {
1460
1509
  options.write(
@@ -1504,7 +1553,7 @@ ${lines.join("\n")}
1504
1553
  for (const gap of downloads) await pullChatModel(client, gap.provider, gap.id, options.write);
1505
1554
  }
1506
1555
  const after = craftbookSetupGaps(
1507
- { services, models },
1556
+ { services, models, commands },
1508
1557
  await readSetupState(client, await client.getConfig(), models)
1509
1558
  );
1510
1559
  if (after.length > 0) {
@@ -1607,6 +1656,7 @@ async function readSetupState(client, config, models) {
1607
1656
  );
1608
1657
  return {
1609
1658
  allowExternalServices: resolveSecurityPolicy2(config).allowExternalServices,
1659
+ allowPackageScriptExecution: resolveSecurityPolicy2(config).allowPackageScriptExecution,
1610
1660
  ...config.webSearch?.provider ? { webSearchProvider: config.webSearch.provider } : {},
1611
1661
  hasBraveSearchApiKey: config.hasBraveSearchApiKey === true,
1612
1662
  installedModels: Object.fromEntries(installed)
@@ -1642,6 +1692,8 @@ function describeGap(gap, sizes) {
1642
1692
  switch (gap.kind) {
1643
1693
  case "external-services":
1644
1694
  return `External services are off, so gezels cannot reach the web${why}.`;
1695
+ case "package-scripts":
1696
+ return `Run package scripts is off, so gezels cannot run ${gap.commands.join(", ")}${why}.`;
1645
1697
  case "web-search":
1646
1698
  return gap.keyMissing ? `Web search needs a Brave Search API key, and none is set${why}.` : `Web search is not set to Brave Search${why}.`;
1647
1699
  case "model": {
@@ -1654,6 +1706,7 @@ function instructions(gaps) {
1654
1706
  const out = [];
1655
1707
  for (const gap of gaps) {
1656
1708
  if (gap.kind === "external-services") out.push("gezel security external-services on");
1709
+ else if (gap.kind === "package-scripts") out.push("gezel security run-package-scripts on");
1657
1710
  else if (gap.kind === "web-search")
1658
1711
  out.push(
1659
1712
  `gezel secret set braveSearchApiKey --env BRAVE_SEARCH_API_KEY --use-for-search (get a key at ${BRAVE_KEY_URL})`
@@ -1756,6 +1809,26 @@ function shorthandEcho(id, tail) {
1756
1809
  return `\u2192 gezel do ${[id, ...tail].map(shellWord).join(" ")}`;
1757
1810
  }
1758
1811
 
1812
+ // src/daemon-stop.ts
1813
+ async function planDaemonStop(input) {
1814
+ const { pid, health } = input;
1815
+ if (pid === null) return { kind: "not-running" };
1816
+ if (!input.alive(pid)) return { kind: "stale" };
1817
+ if (health?.hostedBy === "app") return { kind: "brake" };
1818
+ if (health?.pid !== void 0) {
1819
+ if (health.pid !== pid) return { kind: "mismatch", healthPid: health.pid };
1820
+ if (health.hostedBy === "standalone") return { kind: "kill" };
1821
+ }
1822
+ const command = await input.commandOf(pid);
1823
+ if (command !== null && isGezeldCommand(command)) return { kind: "kill" };
1824
+ if (health) return { kind: "brake" };
1825
+ if (command === null) return { kind: "unconfirmed" };
1826
+ return { kind: "foreign", command };
1827
+ }
1828
+ function isGezeldCommand(command) {
1829
+ return /(?:^|[\\/\s"'])gezeld(?:\.[cm]?js|\.exe)?(?=["'\s]|$)/i.test(command);
1830
+ }
1831
+
1759
1832
  // src/engagement-mode.ts
1760
1833
  var CLI_ENGAGEMENT_MODES = [
1761
1834
  {
@@ -3054,6 +3127,7 @@ var cliGlobals = () => program.opts();
3054
3127
  registerSecretCommands(program, () => connectOwned(cliGlobals()));
3055
3128
  registerMcpCommands(program, () => connectOwned(cliGlobals()));
3056
3129
  registerSecurityCommands(program, () => connectOwned(cliGlobals()));
3130
+ registerGrowthCommand(program, () => connectOwned(cliGlobals()));
3057
3131
  program.hook("preAction", () => {
3058
3132
  const globals = cliGlobals();
3059
3133
  validateGlobals(globals);
@@ -3393,7 +3467,7 @@ program.command("stop").description(
3393
3467
  );
3394
3468
  }
3395
3469
  });
3396
- async function clearStaleRuntime(stoppedPid) {
3470
+ async function clearStaleRuntime(stoppedPid, opts = {}) {
3397
3471
  const { readFile: readFile4, rm: rm3 } = await import("fs/promises");
3398
3472
  const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
3399
3473
  const runtime = gezelPaths2().runtime;
@@ -3401,7 +3475,7 @@ async function clearStaleRuntime(stoppedPid) {
3401
3475
  (await readFile4(runtime.pid, "utf8").catch(() => "")).trim(),
3402
3476
  10
3403
3477
  );
3404
- if (recorded !== stoppedPid || isProcessAlive2(stoppedPid)) return;
3478
+ if (recorded !== stoppedPid || !opts.pidReused && isProcessAlive2(stoppedPid)) return;
3405
3479
  await Promise.all(
3406
3480
  [
3407
3481
  runtime.pid,
@@ -3430,15 +3504,75 @@ async function stopUserDaemon(globals) {
3430
3504
  return;
3431
3505
  }
3432
3506
  const runtime = await readRuntime2();
3433
- if (!runtime) {
3434
- console.log("gezeld is not running");
3435
- return;
3507
+ const plan = await planDaemonStop({
3508
+ pid: runtime?.pid ?? null,
3509
+ alive: isProcessAlive2,
3510
+ health: runtime ? await runtimeHealth(runtime) : null,
3511
+ commandOf: processCommand
3512
+ });
3513
+ switch (plan.kind) {
3514
+ case "not-running":
3515
+ console.log("gezeld is not running");
3516
+ return;
3517
+ case "stale":
3518
+ await clearStaleRuntime(runtime.pid);
3519
+ console.log("gezeld is not running; removed the runtime files it left behind");
3520
+ return;
3521
+ case "foreign":
3522
+ await clearStaleRuntime(runtime.pid, { pidReused: true });
3523
+ console.log(
3524
+ `gezeld is not running. Its old process id ${runtime.pid} now belongs to another program, which was left alone; removed gezeld's leftover runtime files.`
3525
+ );
3526
+ return;
3527
+ case "unconfirmed":
3528
+ console.error(
3529
+ `gezeld (pid ${runtime.pid}) is not answering, and Gezel could not read the process list to confirm that pid is still gezeld, so it was not stopped.`
3530
+ );
3531
+ process.exitCode = 1;
3532
+ return;
3533
+ case "mismatch":
3534
+ console.error(
3535
+ `The Gezel service on port ${runtime.port} reports pid ${plan.healthPid}, but runtime/pid says ${runtime.pid}; stopped nothing. Run \`gezel status\` to see which is running.`
3536
+ );
3537
+ process.exitCode = 1;
3538
+ return;
3539
+ case "brake": {
3540
+ const result = await (await connectOwned(globals)).emergencyStopChats();
3541
+ console.log(
3542
+ `This Gezel service belongs to the Gezel app, which would start it again, so it keeps running. Stopped its AI work instead (${result.cancelledTurns} active ${result.cancelledTurns === 1 ? "chat" : "chats"}). Quit the Gezel app to shut it down.`
3543
+ );
3544
+ return;
3545
+ }
3546
+ case "kill":
3547
+ if (await stopDaemonPid(runtime.pid)) {
3548
+ console.log(`stopped gezeld pid=${runtime.pid}`);
3549
+ } else {
3550
+ console.error(`failed to confirm gezeld pid=${runtime.pid} stopped`);
3551
+ process.exitCode = 1;
3552
+ }
3436
3553
  }
3437
- if (await stopDaemonPid(runtime.pid)) {
3438
- console.log(`stopped gezeld pid=${runtime.pid}`);
3439
- } else {
3440
- console.error(`failed to confirm gezeld pid=${runtime.pid} stopped`);
3441
- process.exitCode = 1;
3554
+ }
3555
+ async function runtimeHealth(runtime) {
3556
+ try {
3557
+ const response = await requestDaemonHealth(runtime.baseUrl, {
3558
+ fetch: runtime.cert ? createTrustingFetch2({ cert: runtime.cert }) : globalThis.fetch,
3559
+ timeoutMs: 3e3
3560
+ });
3561
+ if (!response.ok) return null;
3562
+ const body = response.body ?? {};
3563
+ return {
3564
+ ...typeof body.pid === "number" ? { pid: body.pid } : {},
3565
+ ...body.hostedBy === "app" || body.hostedBy === "standalone" ? { hostedBy: body.hostedBy } : {}
3566
+ };
3567
+ } catch {
3568
+ return null;
3569
+ }
3570
+ }
3571
+ async function processCommand(pid) {
3572
+ try {
3573
+ return (await listProcessSnapshots()).find((entry) => entry.pid === pid)?.command ?? "";
3574
+ } catch {
3575
+ return null;
3442
3576
  }
3443
3577
  }
3444
3578
  program.command("mode [mode]").description("Show or set AI activity (read-only, reactive, reactive+tasks, or full-play)").action(async (requested) => {
@@ -4445,8 +4579,26 @@ function resolveModelProvider(raw) {
4445
4579
  }
4446
4580
  return resolveOnDeviceProvider3(process.platform, process.arch);
4447
4581
  }
4448
- model.command("concurrency [slots]").description("Show or set local inference slots; use auto to restore automatic sizing").option("-p, --provider <engine>", "mlx | llama-cpp | ds4 (default: platform default)").option("--json", "Output the slot override as JSON").action(async (slots, opts) => {
4449
- const provider = resolveModelProvider(opts.provider);
4582
+ var CONCURRENCY_SERVICE_PROVIDERS = [
4583
+ "codex-cli",
4584
+ "anthropic-cli",
4585
+ "copilot",
4586
+ "openai",
4587
+ "anthropic"
4588
+ ];
4589
+ model.command("concurrency [slots]").description(
4590
+ "Show or set how many turns a provider runs at once (local inference slots, or a cloud/CLI provider such as codex-cli); auto restores the default"
4591
+ ).option(
4592
+ "-p, --provider <engine>",
4593
+ `mlx | llama-cpp | ds4 | ${CONCURRENCY_SERVICE_PROVIDERS.join(" | ")} (default: platform default)`
4594
+ ).option("--json", "Output the slot override as JSON").action(async (slots, opts) => {
4595
+ const service = CONCURRENCY_SERVICE_PROVIDERS.find((name) => name === opts.provider);
4596
+ if (!service && opts.provider && !["mlx", "llama-cpp", "ds4"].includes(opts.provider)) {
4597
+ throw new CliError(
4598
+ `--provider must be one of mlx, llama-cpp, ds4, ${CONCURRENCY_SERVICE_PROVIDERS.join(", ")} (got "${opts.provider}")`
4599
+ );
4600
+ }
4601
+ const provider = service ?? resolveModelProvider(opts.provider);
4450
4602
  if (slots !== void 0 && slots !== "auto" && (!/^\d+$/.test(slots) || !Number.isSafeInteger(Number(slots)) || Number(slots) < 1)) {
4451
4603
  throw new CliError("Concurrency must be a positive integer, or auto.");
4452
4604
  }
@@ -4459,8 +4611,9 @@ model.command("concurrency [slots]").description("Show or set local inference sl
4459
4611
  await client.updateConfig({ providerConcurrency: concurrency });
4460
4612
  }
4461
4613
  const result = { provider, slots: concurrency[provider] ?? null };
4614
+ const applies = service ? "applies after a daemon restart" : "applies when idle sessions reload";
4462
4615
  console.log(
4463
- opts.json ? JSON.stringify(result) : `${provider}: ${result.slots ?? "auto"}${result.slots === null ? "" : " inference slots"}${slots === void 0 ? "" : " (applies when idle sessions reload)"}`
4616
+ opts.json ? JSON.stringify(result) : `${provider}: ${result.slots ?? "auto"}${result.slots === null ? "" : ` ${service ? "concurrent turns" : "inference slots"}`}${slots === void 0 ? "" : ` (${applies})`}`
4464
4617
  );
4465
4618
  });
4466
4619
  model.command("context <id> [tokens]").description("Show or set a model context window in tokens; use auto to clear an override").option("-p, --provider <engine>", "mlx | llama-cpp | ds4 (default: platform default)").option("--json", "Output the context override as JSON").action(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-cli",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "The gezel command-line tool: chat with your gezels, run craftbooks, and manage local models from the terminal.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -44,15 +44,15 @@
44
44
  "!dist/**/*.map"
45
45
  ],
46
46
  "dependencies": {
47
- "@bendyline/gezel": "1.2.9",
48
- "@bendyline/gezel-app-sdk": "1.1.9",
49
- "@bendyline/gezel-catalog": "1.2.9",
50
- "@bendyline/gezel-client": "1.2.9",
47
+ "@bendyline/gezel": "1.2.11",
48
+ "@bendyline/gezel-app-sdk": "1.1.11",
49
+ "@bendyline/gezel-catalog": "1.2.11",
50
+ "@bendyline/gezel-client": "1.2.11",
51
51
  "@bendyline/gezel-knowledge": "1.2.9",
52
- "@bendyline/gezel-service": "1.2.9",
53
- "@bendyline/squisq": "2.13.3",
54
- "@bendyline/squisq-formats": "2.8.4",
55
- "@bendyline/squisq-react": "2.12.12",
52
+ "@bendyline/gezel-service": "1.2.11",
53
+ "@bendyline/squisq": "2.13.6",
54
+ "@bendyline/squisq-formats": "2.8.7",
55
+ "@bendyline/squisq-react": "2.12.16",
56
56
  "commander": "^15.0.0",
57
57
  "ink": "^7.1.1",
58
58
  "ink-text-input": "^6.0.0",