@agentskit/cli 0.13.41 → 0.13.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/index.cjs CHANGED
@@ -15,12 +15,13 @@ var tools = require('@agentskit/tools');
15
15
  var skills = require('@agentskit/skills');
16
16
  var memory = require('@agentskit/memory');
17
17
  var integrations = require('@agentskit/integrations');
18
- var child_process = require('child_process');
18
+ var crossPlatform = require('@agentskit/cross-platform');
19
19
  var jsxRuntime = require('react/jsx-runtime');
20
20
  var url = require('url');
21
21
  var runtime = require('@agentskit/runtime');
22
22
  var prompts = require('@inquirer/prompts');
23
23
  var kleur = require('kleur');
24
+ var child_process = require('child_process');
24
25
  var module$1 = require('module');
25
26
  var chokidar = require('chokidar');
26
27
  var rag = require('@agentskit/rag');
@@ -39,7 +40,7 @@ var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
39
40
 
40
41
  // package.json
41
42
  var package_default = {
42
- version: "0.13.41"};
43
+ version: "0.13.42"};
43
44
  async function loadJsonConfig(path6) {
44
45
  try {
45
46
  const raw = await promises.readFile(path6, "utf8");
@@ -925,90 +926,37 @@ function configHooksToHandlers(config) {
925
926
  }
926
927
  return handlers;
927
928
  }
928
- function runShellHook(entry, payload) {
929
- return new Promise((resolvePromise) => {
930
- const timeoutMs = entry.timeout ?? 5e3;
931
- let settled = false;
932
- const settle = (result) => {
933
- if (settled) return;
934
- settled = true;
935
- clearTimeout(timer);
936
- resolvePromise(result);
937
- };
938
- const child = child_process.spawn("sh", ["-c", entry.run], {
939
- stdio: ["pipe", "pipe", "inherit"],
940
- detached: true
941
- });
942
- let stdout = "";
943
- let stdoutBytes = 0;
944
- child.stdout.on("data", (chunk) => {
945
- const text = chunk.toString();
946
- const bytes = Buffer.byteLength(text);
947
- if (stdoutBytes + bytes > MAX_HOOK_STDOUT_BYTES) {
948
- if (child.pid !== void 0) {
949
- try {
950
- process.kill(-child.pid, "SIGKILL");
951
- } catch {
952
- }
953
- }
954
- try {
955
- child.kill("SIGKILL");
956
- } catch {
957
- }
958
- settle({ decision: "block", reason: `shell hook output exceeded ${MAX_HOOK_STDOUT_BYTES} bytes` });
959
- return;
960
- }
961
- stdoutBytes += bytes;
962
- stdout += text;
963
- });
964
- const timer = setTimeout(() => {
965
- if (child.pid !== void 0) {
966
- try {
967
- process.kill(-child.pid, "SIGKILL");
968
- } catch {
969
- }
970
- }
971
- try {
972
- child.kill("SIGKILL");
973
- } catch {
974
- }
975
- settle({ decision: "block", reason: `shell hook timed out after ${timeoutMs}ms` });
976
- }, timeoutMs);
977
- child.stdin.on("error", () => {
978
- });
979
- child.on("close", (code) => {
980
- if (code !== 0) {
981
- settle({
982
- decision: "block",
983
- reason: `shell hook exited with code ${code}`
984
- });
985
- return;
986
- }
987
- const trimmed = stdout.trim();
988
- if (!trimmed) {
989
- settle({ decision: "continue" });
990
- return;
991
- }
992
- try {
993
- const parsed = JSON.parse(trimmed);
994
- if (!parsed || typeof parsed !== "object" || !("decision" in parsed) || !["continue", "block", "modify"].includes(String(parsed.decision))) {
995
- settle({ decision: "block", reason: "shell hook returned an invalid decision" });
996
- } else {
997
- settle(parsed);
998
- }
999
- } catch {
1000
- settle({ decision: "block", reason: "shell hook returned invalid JSON" });
1001
- }
1002
- });
1003
- child.on("error", (err) => {
1004
- settle({ decision: "block", reason: err.message });
929
+ async function runShellHook(entry, payload) {
930
+ const timeoutMs = entry.timeout ?? 5e3;
931
+ let result;
932
+ try {
933
+ result = await crossPlatform.runShell(entry.run, {
934
+ input: JSON.stringify(payload),
935
+ timeoutMs,
936
+ // Hooks are fire-and-judge: no grace period once the budget is spent.
937
+ killGraceMs: 0,
938
+ maxOutputBytes: MAX_HOOK_STDOUT_BYTES
1005
939
  });
1006
- try {
1007
- child.stdin.write(JSON.stringify(payload));
1008
- child.stdin.end();
1009
- } catch {
940
+ } catch (err) {
941
+ return { decision: "block", reason: err instanceof Error ? err.message : String(err) };
942
+ }
943
+ if (result.stderr) process.stderr.write(result.stderr);
944
+ if (result.truncated) {
945
+ return { decision: "block", reason: `shell hook output exceeded ${MAX_HOOK_STDOUT_BYTES} bytes` };
946
+ }
947
+ if (result.timedOut) return { decision: "block", reason: `shell hook timed out after ${timeoutMs}ms` };
948
+ if (result.code !== 0) return { decision: "block", reason: `shell hook exited with code ${result.code}` };
949
+ const trimmed = result.stdout.trim();
950
+ if (!trimmed) return { decision: "continue" };
951
+ try {
952
+ const parsed = JSON.parse(trimmed);
953
+ if (!parsed || typeof parsed !== "object" || !("decision" in parsed) || !["continue", "block", "modify"].includes(String(parsed.decision))) {
954
+ return { decision: "block", reason: "shell hook returned an invalid decision" };
1010
955
  }
1011
- });
956
+ return parsed;
957
+ } catch {
958
+ return { decision: "block", reason: "shell hook returned invalid JSON" };
959
+ }
1012
960
  }
1013
961
  function groupIntoTurns(messages) {
1014
962
  const turns = [];
@@ -1365,10 +1313,9 @@ var McpClient = class {
1365
1313
  }
1366
1314
  async start() {
1367
1315
  if (this.child) return;
1368
- const child = child_process.spawn(this.spec.command, this.spec.args ?? [], {
1316
+ const child = crossPlatform.spawnNodeChild(this.spec.command, this.spec.args ?? [], {
1369
1317
  env: { ...process.env, ...this.spec.env ?? {} },
1370
- stdio: ["pipe", "pipe", "pipe"],
1371
- detached: process.platform !== "win32"
1318
+ stdio: "pipe"
1372
1319
  });
1373
1320
  this.child = child;
1374
1321
  child.stdout.on("data", (chunk) => this.onStdout(chunk.toString()));
@@ -1407,11 +1354,8 @@ var McpClient = class {
1407
1354
  const child = this.child;
1408
1355
  if (!child || child.killed) return;
1409
1356
  const kill = (signal) => {
1410
- try {
1411
- if (process.platform !== "win32" && child.pid) process.kill(-child.pid, signal);
1412
- else child.kill(signal);
1413
- } catch {
1414
- }
1357
+ if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) return;
1358
+ void crossPlatform.killProcessTree(child.pid, signal, (sig) => child.kill(sig));
1415
1359
  };
1416
1360
  kill("SIGTERM");
1417
1361
  const timer = setTimeout(() => kill("SIGKILL"), DISPOSE_GRACE_MS);