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/cli.js +21 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/tools.shell.d.ts +6 -0
- package/dist/tools.shell.js +20 -6
- package/dist/tools.shell.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1465,6 +1465,15 @@ var init_shell_sandbox = __esm({
|
|
|
1465
1465
|
});
|
|
1466
1466
|
|
|
1467
1467
|
// src/tools.shell.ts
|
|
1468
|
+
function killGroup(proc, signal) {
|
|
1469
|
+
if (!proc?.pid) return false;
|
|
1470
|
+
try {
|
|
1471
|
+
process.kill(-proc.pid, signal);
|
|
1472
|
+
return true;
|
|
1473
|
+
} catch {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1468
1477
|
async function spawnArgvFor(command, cwd, osSandbox) {
|
|
1469
1478
|
if (!osSandbox) return { bin: "/bin/sh", args: ["-c", command] };
|
|
1470
1479
|
const opts = osSandbox === true ? {} : osSandbox;
|
|
@@ -1487,7 +1496,7 @@ function makeRealShellTool(options) {
|
|
|
1487
1496
|
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
1488
1497
|
return {
|
|
1489
1498
|
name: "Shell",
|
|
1490
|
-
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.",
|
|
1499
|
+
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.",
|
|
1491
1500
|
parameters: {
|
|
1492
1501
|
type: "object",
|
|
1493
1502
|
required: ["command"],
|
|
@@ -1547,10 +1556,12 @@ function makeRealShellTool(options) {
|
|
|
1547
1556
|
};
|
|
1548
1557
|
let proc;
|
|
1549
1558
|
try {
|
|
1550
|
-
proc = spawn3(argv.bin, argv.args, { cwd: options.cwd, env: childEnv(options), signal: ctl.signal });
|
|
1559
|
+
proc = spawn3(argv.bin, argv.args, { cwd: options.cwd, env: childEnv(options), signal: ctl.signal, ...DETACHED });
|
|
1551
1560
|
} catch (e) {
|
|
1552
1561
|
return finish(`[exit 1] failed to spawn shell: ${e?.message ?? e}`);
|
|
1553
1562
|
}
|
|
1563
|
+
if (ctl.signal.aborted) killGroup(proc, "SIGKILL");
|
|
1564
|
+
else ctl.signal.addEventListener("abort", () => killGroup(proc, "SIGKILL"), { once: true });
|
|
1554
1565
|
const collect = (chunk) => {
|
|
1555
1566
|
const s = typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
|
|
1556
1567
|
out += s;
|
|
@@ -1626,7 +1637,7 @@ ${clean(out) || "(no output yet)"}`;
|
|
|
1626
1637
|
}
|
|
1627
1638
|
];
|
|
1628
1639
|
}
|
|
1629
|
-
var log12, clean, SECRET_ENV_RE, _spawn, ShellJobRegistry, NO_JOB2;
|
|
1640
|
+
var log12, clean, DETACHED, SECRET_ENV_RE, _spawn, ShellJobRegistry, NO_JOB2;
|
|
1630
1641
|
var init_tools_shell = __esm({
|
|
1631
1642
|
"src/tools.shell.ts"() {
|
|
1632
1643
|
"use strict";
|
|
@@ -1636,6 +1647,7 @@ var init_tools_shell = __esm({
|
|
|
1636
1647
|
init_shell_sandbox();
|
|
1637
1648
|
log12 = forComponent("shell");
|
|
1638
1649
|
clean = (s) => truncateOutput(redactSecrets(s.replace(/\n+$/, "")));
|
|
1650
|
+
DETACHED = { stdio: ["ignore", "pipe", "pipe"], detached: true };
|
|
1639
1651
|
SECRET_ENV_RE = /(_API_KEY|_TOKEN|_SECRET|_PASSWORD|_PRIVATE_KEY|^AWS_|^GITHUB_TOKEN$|^OPENAI_|^ANTHROPIC_|^GOOGLE_|^GEMINI_|^GROQ_|^NPM_TOKEN$)/i;
|
|
1640
1652
|
ShellJobRegistry = class {
|
|
1641
1653
|
constructor(cfg) {
|
|
@@ -1656,7 +1668,7 @@ var init_tools_shell = __esm({
|
|
|
1656
1668
|
try {
|
|
1657
1669
|
const spawn3 = this.cfg.spawn ?? await nodeSpawn();
|
|
1658
1670
|
const argv = this.cfg.osSandbox ? await spawnArgvFor(command, this.cfg.cwd, this.cfg.osSandbox) : { bin: "/bin/sh", args: ["-c", command] };
|
|
1659
|
-
const proc = spawn3(argv.bin, argv.args, { cwd: this.cfg.cwd, env: childEnv(this.cfg) });
|
|
1671
|
+
const proc = spawn3(argv.bin, argv.args, { cwd: this.cfg.cwd, env: childEnv(this.cfg), ...DETACHED });
|
|
1660
1672
|
job.proc = proc;
|
|
1661
1673
|
proc.stdout?.on("data", append);
|
|
1662
1674
|
proc.stderr?.on("data", append);
|
|
@@ -1695,9 +1707,11 @@ var init_tools_shell = __esm({
|
|
|
1695
1707
|
const j = this.jobs.get(id);
|
|
1696
1708
|
if (!j) return false;
|
|
1697
1709
|
if (j.status === "running") {
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1710
|
+
if (!killGroup(j.proc, "SIGTERM")) {
|
|
1711
|
+
try {
|
|
1712
|
+
j.proc?.kill("SIGTERM");
|
|
1713
|
+
} catch {
|
|
1714
|
+
}
|
|
1701
1715
|
}
|
|
1702
1716
|
j.status = "killed";
|
|
1703
1717
|
}
|