agent.libx.js 0.94.24 → 0.94.25

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/index.js CHANGED
@@ -1470,6 +1470,15 @@ __export(tools_shell_exports, {
1470
1470
  makeRealShellTool: () => makeRealShellTool,
1471
1471
  makeShellJobTools: () => makeShellJobTools
1472
1472
  });
1473
+ function killGroup(proc, signal) {
1474
+ if (!proc?.pid) return false;
1475
+ try {
1476
+ process.kill(-proc.pid, signal);
1477
+ return true;
1478
+ } catch {
1479
+ return false;
1480
+ }
1481
+ }
1473
1482
  async function spawnArgvFor(command, cwd, osSandbox) {
1474
1483
  if (!osSandbox) return { bin: "/bin/sh", args: ["-c", command] };
1475
1484
  const opts = osSandbox === true ? {} : osSandbox;
@@ -1492,7 +1501,7 @@ function makeRealShellTool(options) {
1492
1501
  const timeoutMs = options.timeoutMs ?? 12e4;
1493
1502
  return {
1494
1503
  name: "Shell",
1495
- description: "Run a shell command via /bin/sh in the working directory. Executes any installed binary \u2014 ls, cat, grep, git, bun, node, curl, scripts, etc. Returns combined stdout+stderr; non-zero exits are prefixed `[exit N]`. Set `background:true` for long-running processes (servers, watchers) \u2014 returns a job id immediately; poll with ShellOutput, stop with ShellKill.",
1504
+ description: "Run a shell command via /bin/sh in the working directory. Executes any installed binary \u2014 ls, cat, grep, git, bun, node, curl, scripts, etc. Returns combined stdout+stderr; non-zero exits are prefixed `[exit N]`. Runs non-interactively with no terminal (stdin is /dev/null): commands that prompt for input fail fast rather than hang \u2014 for privileged actions use a non-interactive flag (e.g. `sudo -n`), or ask the user to run the command themselves. Set `background:true` for long-running processes (servers, watchers) \u2014 returns a job id immediately; poll with ShellOutput, stop with ShellKill.",
1496
1505
  parameters: {
1497
1506
  type: "object",
1498
1507
  required: ["command"],
@@ -1552,10 +1561,12 @@ function makeRealShellTool(options) {
1552
1561
  };
1553
1562
  let proc;
1554
1563
  try {
1555
- proc = spawn(argv.bin, argv.args, { cwd: options.cwd, env: childEnv(options), signal: ctl.signal });
1564
+ proc = spawn(argv.bin, argv.args, { cwd: options.cwd, env: childEnv(options), signal: ctl.signal, ...DETACHED });
1556
1565
  } catch (e) {
1557
1566
  return finish(`[exit 1] failed to spawn shell: ${e?.message ?? e}`);
1558
1567
  }
1568
+ if (ctl.signal.aborted) killGroup(proc, "SIGKILL");
1569
+ else ctl.signal.addEventListener("abort", () => killGroup(proc, "SIGKILL"), { once: true });
1559
1570
  const collect = (chunk) => {
1560
1571
  const s = typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
1561
1572
  out += s;
@@ -1631,7 +1642,7 @@ ${clean(out) || "(no output yet)"}`;
1631
1642
  }
1632
1643
  ];
1633
1644
  }
1634
- var log4, clean, SECRET_ENV_RE, _spawn, ShellJobRegistry, NO_JOB2;
1645
+ var log4, clean, DETACHED, SECRET_ENV_RE, _spawn, ShellJobRegistry, NO_JOB2;
1635
1646
  var init_tools_shell = __esm({
1636
1647
  "src/tools.shell.ts"() {
1637
1648
  "use strict";
@@ -1641,6 +1652,7 @@ var init_tools_shell = __esm({
1641
1652
  init_shell_sandbox();
1642
1653
  log4 = forComponent("shell");
1643
1654
  clean = (s) => truncateOutput(redactSecrets(s.replace(/\n+$/, "")));
1655
+ DETACHED = { stdio: ["ignore", "pipe", "pipe"], detached: true };
1644
1656
  SECRET_ENV_RE = /(_API_KEY|_TOKEN|_SECRET|_PASSWORD|_PRIVATE_KEY|^AWS_|^GITHUB_TOKEN$|^OPENAI_|^ANTHROPIC_|^GOOGLE_|^GEMINI_|^GROQ_|^NPM_TOKEN$)/i;
1645
1657
  ShellJobRegistry = class {
1646
1658
  constructor(cfg) {
@@ -1661,7 +1673,7 @@ var init_tools_shell = __esm({
1661
1673
  try {
1662
1674
  const spawn = this.cfg.spawn ?? await nodeSpawn();
1663
1675
  const argv = this.cfg.osSandbox ? await spawnArgvFor(command, this.cfg.cwd, this.cfg.osSandbox) : { bin: "/bin/sh", args: ["-c", command] };
1664
- const proc = spawn(argv.bin, argv.args, { cwd: this.cfg.cwd, env: childEnv(this.cfg) });
1676
+ const proc = spawn(argv.bin, argv.args, { cwd: this.cfg.cwd, env: childEnv(this.cfg), ...DETACHED });
1665
1677
  job.proc = proc;
1666
1678
  proc.stdout?.on("data", append);
1667
1679
  proc.stderr?.on("data", append);
@@ -1700,9 +1712,11 @@ var init_tools_shell = __esm({
1700
1712
  const j = this.jobs.get(id);
1701
1713
  if (!j) return false;
1702
1714
  if (j.status === "running") {
1703
- try {
1704
- j.proc?.kill("SIGTERM");
1705
- } catch {
1715
+ if (!killGroup(j.proc, "SIGTERM")) {
1716
+ try {
1717
+ j.proc?.kill("SIGTERM");
1718
+ } catch {
1719
+ }
1706
1720
  }
1707
1721
  j.status = "killed";
1708
1722
  }