@livx.cc/agentx 0.99.41 → 0.99.42
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 +58 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.js +58 -2
- package/dist/index.js.map +1 -1
- package/dist/tools.shell.d.ts +8 -0
- package/dist/tools.shell.js +58 -2
- package/dist/tools.shell.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2179,7 +2179,7 @@ function makeRealShellTool(options) {
|
|
|
2179
2179
|
return { ...this, description: rebound.description, run: rebound.run, withCwd: rebound.withCwd };
|
|
2180
2180
|
},
|
|
2181
2181
|
get description() {
|
|
2182
|
-
return
|
|
2182
|
+
return "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. " + (options.registry?.adopt ? `A command still running after ${defaultTimeoutMs}ms is NOT killed \u2014 it is handed to a background job and you get its id, so you can keep checking on it (\`[still running]\`). Pass \`timeoutMs\` (max ${maxTimeoutMs}) to wait longer in the foreground, and always bound network commands yourself (e.g. \`curl -m 10\`). ` : `Each command is killed after ${defaultTimeoutMs}ms (result \`[exit 124]\` with whatever output it produced) \u2014 pass \`timeoutMs\` (max ${maxTimeoutMs}) for a legitimately slower command, and always bound network commands yourself (e.g. \`curl -m 10\`). `) + backgroundDoc();
|
|
2183
2183
|
},
|
|
2184
2184
|
// Declared so transports above the agent loop can size their own deadline with headroom (see AgentTool.maxDurationMs).
|
|
2185
2185
|
maxDurationMs: maxTimeoutMs,
|
|
@@ -2218,9 +2218,12 @@ function makeRealShellTool(options) {
|
|
|
2218
2218
|
else ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
2219
2219
|
}
|
|
2220
2220
|
let timedOut = false;
|
|
2221
|
-
|
|
2221
|
+
let onDeadline = () => {
|
|
2222
2222
|
timedOut = true;
|
|
2223
2223
|
ctl.abort();
|
|
2224
|
+
};
|
|
2225
|
+
const timer = setTimeout(() => {
|
|
2226
|
+
onDeadline();
|
|
2224
2227
|
}, timeoutMs);
|
|
2225
2228
|
let pend = "";
|
|
2226
2229
|
let flushTimer = null;
|
|
@@ -2251,6 +2254,18 @@ function makeRealShellTool(options) {
|
|
|
2251
2254
|
}
|
|
2252
2255
|
if (ctl.signal.aborted) killGroup(proc, "SIGKILL");
|
|
2253
2256
|
else ctl.signal.addEventListener("abort", () => killGroup(proc, "SIGKILL"), { once: true });
|
|
2257
|
+
const registry = options.registry;
|
|
2258
|
+
if (registry?.adopt) {
|
|
2259
|
+
onDeadline = () => {
|
|
2260
|
+
timedOut = true;
|
|
2261
|
+
if (settled) return;
|
|
2262
|
+
flushEmit(ctx);
|
|
2263
|
+
proc.stdout?.off?.("data", collect);
|
|
2264
|
+
proc.stderr?.off?.("data", collect);
|
|
2265
|
+
const id = registry.adopt(cmd, proc, out);
|
|
2266
|
+
finish(handoffFor(timeoutMs, id, clean(out), !!registry.notifiesOnExit));
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2254
2269
|
const collect = (chunk) => {
|
|
2255
2270
|
const s = typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
|
|
2256
2271
|
out += s;
|
|
@@ -2283,6 +2298,12 @@ function makeRealShellTool(options) {
|
|
|
2283
2298
|
}
|
|
2284
2299
|
};
|
|
2285
2300
|
}
|
|
2301
|
+
function handoffFor(timeoutMs, id, body, notifies) {
|
|
2302
|
+
const head = `[still running] exceeded ${timeoutMs}ms, so it was handed to background job ${id} \u2014 NOT killed, it is still going. Check on it with ShellOutput({id:"${id}"}) / ShellStatus({id:"${id}"}), stop it with ShellKill({id:"${id}"}). ` + (notifies ? "Its completion will be reported to you, so you may continue with other work meanwhile." : "Nothing will tell you when it finishes \u2014 poll it yourself before you rely on its result.");
|
|
2303
|
+
return body ? `${head}
|
|
2304
|
+
Output so far:
|
|
2305
|
+
${body}` : head;
|
|
2306
|
+
}
|
|
2286
2307
|
function reasonFor(timedOut, timeoutMs, body) {
|
|
2287
2308
|
const head = timedOut ? `[exit 124] timed out after ${timeoutMs}ms (killed). Re-running this command unchanged will time out again. Either re-run it with background:true (returns a job id immediately; poll with ShellOutput/ShellStatus, stop with ShellKill) or narrow it so it can finish \u2014 bound it, scope it, or ask for less.` : "[exit 130] cancelled (killed)";
|
|
2288
2309
|
return body ? `${head}
|
|
@@ -2422,6 +2443,41 @@ var init_tools_shell = __esm({
|
|
|
2422
2443
|
list() {
|
|
2423
2444
|
return [...this.jobs].map(([id, j]) => ({ id, command: j.command, status: j.status }));
|
|
2424
2445
|
}
|
|
2446
|
+
/**
|
|
2447
|
+
* Take over an ALREADY-RUNNING child as a background job. A foreground command that outruns its
|
|
2448
|
+
* timeout is not necessarily a hung command — killing it throws away work that was nearly done and,
|
|
2449
|
+
* worse, a launcher that spawned its own detached worker leaves that worker running with nothing
|
|
2450
|
+
* tracking it. Adopting hands the model a handle instead: the command keeps going, its completion
|
|
2451
|
+
* is reported like any other job, and `seed` carries the output produced before the handoff.
|
|
2452
|
+
*/
|
|
2453
|
+
adopt(command, proc, seed = "") {
|
|
2454
|
+
const id = `job-${++this.seq}`;
|
|
2455
|
+
const max = this.cfg.maxBuffer ?? 256 * 1024;
|
|
2456
|
+
const job = { command, buf: seed.slice(-max), status: "running", proc };
|
|
2457
|
+
const append = (chunk) => {
|
|
2458
|
+
const s = typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
|
|
2459
|
+
job.buf = (job.buf + s).slice(-max);
|
|
2460
|
+
};
|
|
2461
|
+
proc.stdout?.on("data", append);
|
|
2462
|
+
proc.stderr?.on("data", append);
|
|
2463
|
+
proc.on("error", (err2) => {
|
|
2464
|
+
if (job.status === "running") {
|
|
2465
|
+
job.status = "error";
|
|
2466
|
+
append(`
|
|
2467
|
+
[error] ${err2?.message ?? err2}`);
|
|
2468
|
+
this.notifyExit(id, job);
|
|
2469
|
+
}
|
|
2470
|
+
});
|
|
2471
|
+
proc.on("close", (code) => {
|
|
2472
|
+
if (job.status === "running") {
|
|
2473
|
+
job.status = "exited";
|
|
2474
|
+
job.exitCode = code ?? void 0;
|
|
2475
|
+
this.notifyExit(id, job);
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
this.jobs.set(id, job);
|
|
2479
|
+
return id;
|
|
2480
|
+
}
|
|
2425
2481
|
kill(id) {
|
|
2426
2482
|
const j = this.jobs.get(id);
|
|
2427
2483
|
if (!j) return false;
|