@agentfield/sdk 0.1.97-rc.6 → 0.1.97-rc.8

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
@@ -444,6 +444,15 @@ var init_claude = __esm({
444
444
  };
445
445
  }
446
446
  });
447
+ function resolveIdleMs(idleSeconds) {
448
+ let seconds = idleSeconds;
449
+ if (seconds === void 0) {
450
+ const raw = process.env.AGENTFIELD_HARNESS_IDLE_SECONDS;
451
+ const parsed = raw !== void 0 ? Number(raw) : NaN;
452
+ seconds = Number.isFinite(parsed) ? parsed : DEFAULT_IDLE_SECONDS;
453
+ }
454
+ return seconds > 0 ? seconds * 1e3 : void 0;
455
+ }
447
456
  function runCli(cmd, options) {
448
457
  return new Promise((resolve2, reject) => {
449
458
  const [bin, ...args] = cmd;
@@ -452,30 +461,67 @@ function runCli(cmd, options) {
452
461
  const proc = spawn(bin, args, {
453
462
  env,
454
463
  cwd: options?.cwd,
455
- stdio: ["pipe", "pipe", "pipe"]
464
+ stdio: ["ignore", "pipe", "pipe"]
456
465
  });
457
466
  let stdout = "";
458
467
  let stderr = "";
468
+ let settled = false;
469
+ let lastActivity = Date.now();
459
470
  proc.stdout.on("data", (data) => {
460
471
  stdout += data.toString();
472
+ lastActivity = Date.now();
461
473
  });
462
474
  proc.stderr.on("data", (data) => {
463
475
  stderr += data.toString();
476
+ lastActivity = Date.now();
464
477
  });
465
478
  const timer = options?.timeout ? setTimeout(() => {
466
- proc.kill();
479
+ if (settled) {
480
+ return;
481
+ }
482
+ settled = true;
483
+ cleanup();
484
+ proc.kill("SIGKILL");
467
485
  reject(new Error(`CLI timed out after ${options.timeout}ms`));
468
486
  }, options.timeout) : void 0;
469
- proc.on("close", (code) => {
487
+ const idleMs = resolveIdleMs(options?.idleSeconds);
488
+ const idleTimer = idleMs ? setInterval(() => {
489
+ if (settled) {
490
+ return;
491
+ }
492
+ if (Date.now() - lastActivity >= idleMs) {
493
+ settled = true;
494
+ cleanup();
495
+ proc.kill("SIGKILL");
496
+ reject(
497
+ new Error(
498
+ `CLI made no progress for ${Math.round(idleMs / 1e3)}s`
499
+ )
500
+ );
501
+ }
502
+ }, Math.min(idleMs, 1e3)) : void 0;
503
+ function cleanup() {
470
504
  if (timer) {
471
505
  clearTimeout(timer);
472
506
  }
507
+ if (idleTimer) {
508
+ clearInterval(idleTimer);
509
+ }
510
+ }
511
+ proc.on("close", (code) => {
512
+ if (settled) {
513
+ return;
514
+ }
515
+ settled = true;
516
+ cleanup();
473
517
  resolve2({ stdout, stderr, exitCode: code ?? 0 });
474
518
  });
475
519
  proc.on("error", (err) => {
476
- if (timer) {
477
- clearTimeout(timer);
520
+ if (settled) {
521
+ return;
478
522
  }
523
+ settled = true;
524
+ cleanup();
479
525
  reject(err);
480
526
  });
481
527
  });
@@ -521,9 +567,11 @@ function extractFinalText(events) {
521
567
  }
522
568
  return result;
523
569
  }
570
+ var DEFAULT_IDLE_SECONDS;
524
571
  var init_cli = __esm({
525
572
  "src/harness/cli.ts"() {
526
573
  init_openrouterAttribution();
574
+ DEFAULT_IDLE_SECONDS = 120;
527
575
  }
528
576
  });
529
577