@aiden-ade/sandbox-agent 0.1.70 → 0.1.71

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.
Files changed (2) hide show
  1. package/dist/index.cjs +36 -15
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -22087,7 +22087,7 @@ function describeError(error2) {
22087
22087
  }
22088
22088
 
22089
22089
  // src/version.ts
22090
- var AGENT_VERSION = "0.1.70";
22090
+ var AGENT_VERSION = "0.1.71";
22091
22091
 
22092
22092
  // src/daemon-worktree.ts
22093
22093
  var import_node_child_process3 = require("child_process");
@@ -27763,6 +27763,7 @@ var RUNNER_STATUS_MIN_SUPPORTED_PROTOCOL_VERSION = Math.max(1, RUNNER_STATUS_PRO
27763
27763
  var RUNNER_STATUS_MAX_SUPPORTED_PROTOCOL_VERSION = RUNNER_STATUS_PROTOCOL_VERSION;
27764
27764
  var RUNNER_RECOVERY_GRACE_MS = 2 * 60 * 1e3;
27765
27765
  var SYSTEM_ABORT_RUN_ERRORS = {
27766
+ authority_lost: "Agent run stopped because execution authority was lost",
27766
27767
  watchdog_timeout: "Agent run was stopped by the server after a period of no stream activity",
27767
27768
  provider_exited: "Agent process exited unexpectedly",
27768
27769
  runner_stalled: "Agent run stalled with no recent activity and was recovered"
@@ -38263,6 +38264,7 @@ var BaseMachineAgent = class _BaseMachineAgent {
38263
38264
  presenter;
38264
38265
  runtime;
38265
38266
  abortController = null;
38267
+ abortReason = "user";
38266
38268
  /** Log the "synced MCP session headers" line once per run(), not per respawn. */
38267
38269
  mcpHeadersLogged = false;
38268
38270
  constructor(presenter, runtime) {
@@ -38403,8 +38405,21 @@ var BaseMachineAgent = class _BaseMachineAgent {
38403
38405
  }
38404
38406
  }
38405
38407
  // ── Shared helpers ─────────────────────────────────────────────────────
38406
- abort() {
38407
- this.abortController?.abort();
38408
+ abort(reason = "user") {
38409
+ this.abortReason = reason;
38410
+ this.abortController?.abort(reason);
38411
+ }
38412
+ normalizeAbortedResult(result) {
38413
+ const message = this.abortReason === "user" ? "Interrupted by user" : SYSTEM_ABORT_RUN_ERRORS[this.abortReason];
38414
+ const normalized = {
38415
+ ...result,
38416
+ success: false,
38417
+ summary: message,
38418
+ error: message
38419
+ };
38420
+ if (this.abortReason === "user") delete normalized.errorKind;
38421
+ else normalized.errorKind = this.abortReason;
38422
+ return normalized;
38408
38423
  }
38409
38424
  isAbortError(error2) {
38410
38425
  if (error2 instanceof Error && error2.name === "AbortError") return true;
@@ -38514,6 +38529,9 @@ Prefer relative paths and keep your work scoped to this project.`
38514
38529
  runtimeSessionId: result.runtimeSessionId || result.providerSessionId,
38515
38530
  providerSessionId: result.providerSessionId || result.runtimeSessionId
38516
38531
  };
38532
+ if (this.abortController?.signal.aborted) {
38533
+ lastResult = this.normalizeAbortedResult(lastResult);
38534
+ }
38517
38535
  if (lastResult.success || !lastResult.error) break;
38518
38536
  if (this.abortController?.signal.aborted) break;
38519
38537
  if (lastResult.errorKind === "model_mismatch") break;
@@ -38612,6 +38630,7 @@ ${runtimeConfig.task}` } : {}
38612
38630
  return normalizedResult;
38613
38631
  }
38614
38632
  async run(config2) {
38633
+ this.abortReason = "user";
38615
38634
  this.abortController = new AbortController();
38616
38635
  const backendKind = this.resolveBackendKind(config2);
38617
38636
  const supportTier = config2.supportTier || this.getDefaultSupportTier(backendKind);
@@ -38649,7 +38668,7 @@ ${runtimeConfig.task}` } : {}
38649
38668
  return await this.runCliBackend(initialConfig, safeProjectPath);
38650
38669
  } catch (error2) {
38651
38670
  const interrupted = this.isAbortError(error2);
38652
- const message = interrupted ? "Interrupted by user" : error2 instanceof Error ? error2.message : String(error2);
38671
+ const message = interrupted ? this.abortReason === "user" ? "Interrupted by user" : SYSTEM_ABORT_RUN_ERRORS[this.abortReason] : error2 instanceof Error ? error2.message : String(error2);
38653
38672
  if (!interrupted) {
38654
38673
  console.error("[base-machine-agent] CLI runtime failed", error2);
38655
38674
  this.presenter.onError(message, true);
@@ -38679,7 +38698,8 @@ ${runtimeConfig.task}` } : {}
38679
38698
  ...classified ? { recoveryClass: classified.recoveryClass } : {},
38680
38699
  ...problem ? { problem } : {},
38681
38700
  backendKind,
38682
- supportTier
38701
+ supportTier,
38702
+ ...interrupted && this.abortReason !== "user" ? { errorKind: this.abortReason } : {}
38683
38703
  };
38684
38704
  this.presenter.onComplete(result);
38685
38705
  return result;
@@ -46543,13 +46563,13 @@ var CoreAgent = class _CoreAgent extends BaseMachineAgent {
46543
46563
  this.providerApiKey = runtime.providerApiKey;
46544
46564
  this.onProviderSpawned = runtime.onProviderSpawned;
46545
46565
  }
46546
- abort() {
46566
+ abort(reason = "user") {
46547
46567
  this._aborted = true;
46548
- super.abort();
46568
+ super.abort(reason);
46549
46569
  }
46550
- kill() {
46570
+ kill(reason = "user") {
46551
46571
  this._aborted = true;
46552
- super.abort();
46572
+ super.abort(reason);
46553
46573
  const child = this.childProcess;
46554
46574
  if (!child || child.killed || child.exitCode !== null) return false;
46555
46575
  return this.killChildProcess(child);
@@ -69425,7 +69445,8 @@ var WebPresenter = class {
69425
69445
  onComplete(result) {
69426
69446
  if (this.terminalEmitted) return;
69427
69447
  this.terminalEmitted = true;
69428
- const completedResult = !result.success && !result.problem && !this.applicationProblem ? {
69448
+ const isAuthorityLoss = result.errorKind === "authority_lost";
69449
+ const completedResult = !result.success && !result.problem && !this.applicationProblem && !isAuthorityLoss ? {
69429
69450
  ...result,
69430
69451
  problem: createCliProblem(
69431
69452
  classifyCliErrorDetailed(result.error || result.summary || "Unknown error", 1),
@@ -70057,19 +70078,19 @@ async function runSandbox(config2) {
70057
70078
  lifecycle.info("sandbox_agent_ws_connect_attempt", {
70058
70079
  wsUrl: config2.wsUrl
70059
70080
  });
70060
- const stopActiveAgent = () => {
70081
+ const stopActiveAgent = (reason = "user") => {
70061
70082
  reportActiveRun = false;
70062
70083
  activeRootExecutionActivity?.release();
70063
70084
  activeRootExecutionActivity = null;
70064
70085
  const agent = currentAgent;
70065
70086
  if (!agent) return;
70066
- const killed = agent.kill();
70087
+ const killed = agent.kill(reason);
70067
70088
  if (!killed) {
70068
- agent.abort();
70089
+ agent.abort(reason);
70069
70090
  return;
70070
70091
  }
70071
70092
  const abortDeadline = setTimeout(() => {
70072
- if (currentAgent === agent) agent.abort();
70093
+ if (currentAgent === agent) agent.abort(reason);
70073
70094
  }, 5e3);
70074
70095
  abortDeadline.unref?.();
70075
70096
  };
@@ -70078,7 +70099,7 @@ async function runSandbox(config2) {
70078
70099
  lifecycle.warn("sandbox_agent_process_fenced", reason);
70079
70100
  stopped = true;
70080
70101
  executionLeaseClient?.close();
70081
- stopActiveAgent();
70102
+ stopActiveAgent("authority_lost");
70082
70103
  const resolvePendingMessage = pendingMessageResolve;
70083
70104
  pendingMessageResolve = null;
70084
70105
  resolvePendingMessage?.(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiden-ade/sandbox-agent",
3
- "version": "0.1.70",
3
+ "version": "0.1.71",
4
4
  "type": "module",
5
5
  "description": "Alan agent runtime — cloud sandbox and local daemon (alan-agent CLI)",
6
6
  "bin": {