@agentskit/cli 0.13.41 → 0.13.43

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/bin.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.43"};
43
44
  async function loadJsonConfig(path6) {
44
45
  try {
45
46
  const raw = await promises.readFile(path6, "utf8");
@@ -917,90 +918,37 @@ function configHooksToHandlers(config) {
917
918
  }
918
919
  return handlers;
919
920
  }
920
- function runShellHook(entry, payload) {
921
- return new Promise((resolvePromise) => {
922
- const timeoutMs = entry.timeout ?? 5e3;
923
- let settled = false;
924
- const settle = (result) => {
925
- if (settled) return;
926
- settled = true;
927
- clearTimeout(timer);
928
- resolvePromise(result);
929
- };
930
- const child = child_process.spawn("sh", ["-c", entry.run], {
931
- stdio: ["pipe", "pipe", "inherit"],
932
- detached: true
933
- });
934
- let stdout = "";
935
- let stdoutBytes = 0;
936
- child.stdout.on("data", (chunk) => {
937
- const text = chunk.toString();
938
- const bytes = Buffer.byteLength(text);
939
- if (stdoutBytes + bytes > MAX_HOOK_STDOUT_BYTES) {
940
- if (child.pid !== void 0) {
941
- try {
942
- process.kill(-child.pid, "SIGKILL");
943
- } catch {
944
- }
945
- }
946
- try {
947
- child.kill("SIGKILL");
948
- } catch {
949
- }
950
- settle({ decision: "block", reason: `shell hook output exceeded ${MAX_HOOK_STDOUT_BYTES} bytes` });
951
- return;
952
- }
953
- stdoutBytes += bytes;
954
- stdout += text;
955
- });
956
- const timer = setTimeout(() => {
957
- if (child.pid !== void 0) {
958
- try {
959
- process.kill(-child.pid, "SIGKILL");
960
- } catch {
961
- }
962
- }
963
- try {
964
- child.kill("SIGKILL");
965
- } catch {
966
- }
967
- settle({ decision: "block", reason: `shell hook timed out after ${timeoutMs}ms` });
968
- }, timeoutMs);
969
- child.stdin.on("error", () => {
970
- });
971
- child.on("close", (code) => {
972
- if (code !== 0) {
973
- settle({
974
- decision: "block",
975
- reason: `shell hook exited with code ${code}`
976
- });
977
- return;
978
- }
979
- const trimmed = stdout.trim();
980
- if (!trimmed) {
981
- settle({ decision: "continue" });
982
- return;
983
- }
984
- try {
985
- const parsed = JSON.parse(trimmed);
986
- if (!parsed || typeof parsed !== "object" || !("decision" in parsed) || !["continue", "block", "modify"].includes(String(parsed.decision))) {
987
- settle({ decision: "block", reason: "shell hook returned an invalid decision" });
988
- } else {
989
- settle(parsed);
990
- }
991
- } catch {
992
- settle({ decision: "block", reason: "shell hook returned invalid JSON" });
993
- }
994
- });
995
- child.on("error", (err) => {
996
- settle({ decision: "block", reason: err.message });
921
+ async function runShellHook(entry, payload) {
922
+ const timeoutMs = entry.timeout ?? 5e3;
923
+ let result;
924
+ try {
925
+ result = await crossPlatform.runShell(entry.run, {
926
+ input: JSON.stringify(payload),
927
+ timeoutMs,
928
+ // Hooks are fire-and-judge: no grace period once the budget is spent.
929
+ killGraceMs: 0,
930
+ maxOutputBytes: MAX_HOOK_STDOUT_BYTES
997
931
  });
998
- try {
999
- child.stdin.write(JSON.stringify(payload));
1000
- child.stdin.end();
1001
- } catch {
932
+ } catch (err) {
933
+ return { decision: "block", reason: err instanceof Error ? err.message : String(err) };
934
+ }
935
+ if (result.stderr) process.stderr.write(result.stderr);
936
+ if (result.truncated) {
937
+ return { decision: "block", reason: `shell hook output exceeded ${MAX_HOOK_STDOUT_BYTES} bytes` };
938
+ }
939
+ if (result.timedOut) return { decision: "block", reason: `shell hook timed out after ${timeoutMs}ms` };
940
+ if (result.code !== 0) return { decision: "block", reason: `shell hook exited with code ${result.code}` };
941
+ const trimmed = result.stdout.trim();
942
+ if (!trimmed) return { decision: "continue" };
943
+ try {
944
+ const parsed = JSON.parse(trimmed);
945
+ if (!parsed || typeof parsed !== "object" || !("decision" in parsed) || !["continue", "block", "modify"].includes(String(parsed.decision))) {
946
+ return { decision: "block", reason: "shell hook returned an invalid decision" };
1002
947
  }
1003
- });
948
+ return parsed;
949
+ } catch {
950
+ return { decision: "block", reason: "shell hook returned invalid JSON" };
951
+ }
1004
952
  }
1005
953
  function groupIntoTurns(messages) {
1006
954
  const turns = [];
@@ -1357,10 +1305,9 @@ var McpClient = class {
1357
1305
  }
1358
1306
  async start() {
1359
1307
  if (this.child) return;
1360
- const child = child_process.spawn(this.spec.command, this.spec.args ?? [], {
1308
+ const child = crossPlatform.spawnNodeChild(this.spec.command, this.spec.args ?? [], {
1361
1309
  env: { ...process.env, ...this.spec.env ?? {} },
1362
- stdio: ["pipe", "pipe", "pipe"],
1363
- detached: process.platform !== "win32"
1310
+ stdio: "pipe"
1364
1311
  });
1365
1312
  this.child = child;
1366
1313
  child.stdout.on("data", (chunk) => this.onStdout(chunk.toString()));
@@ -1399,11 +1346,8 @@ var McpClient = class {
1399
1346
  const child = this.child;
1400
1347
  if (!child || child.killed) return;
1401
1348
  const kill = (signal) => {
1402
- try {
1403
- if (process.platform !== "win32" && child.pid) process.kill(-child.pid, signal);
1404
- else child.kill(signal);
1405
- } catch {
1406
- }
1349
+ if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) return;
1350
+ void crossPlatform.killProcessTree(child.pid, signal, (sig) => child.kill(sig));
1407
1351
  };
1408
1352
  kill("SIGTERM");
1409
1353
  const timer = setTimeout(() => kill("SIGKILL"), DISPOSE_GRACE_MS);