@agent-device/proxy 0.21.42-nightly.20261122.239 → 0.21.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.
@@ -71,6 +71,8 @@ const DAEMON_REQUEST_MAX_BYTES = 67108864;
71
71
  const DAEMON_HTTP_INSTANCE_HEADER = "x-agent-device-instance";
72
72
  const DAEMON_HTTP_UPSTREAM_INSTANCE_HEADER = "x-agent-device-upstream-instance";
73
73
  const DAEMON_HTTP_INSTANCE_MISMATCH_HEADER = "x-agent-device-instance-mismatch";
74
+ /** Why a daemon, the proxy, or a client refuses a request addressed to another daemon instance. */
75
+ const DAEMON_INSTANCE_REASONS = { instanceMismatch: { reason: "remote_instance_mismatch" } };
74
76
  function buildDaemonInstanceMismatchRpcResponse(id, message, data) {
75
77
  return {
76
78
  jsonrpc: "2.0",
@@ -96,4 +98,4 @@ function buildDaemonHealthPayload(service, version, options = {}) {
96
98
  };
97
99
  }
98
100
  //#endregion
99
- export { DAEMON_HTTP_PUBLIC_NETWORK_ACCESS as a, DAEMON_REQUEST_MAX_BYTES as c, buildDaemonHttpUrl as d, buildDaemonInstanceMismatchRpcResponse as f, normalizeTenantId as g, normalizeDaemonPublicOrigin as h, DAEMON_HTTP_NETWORK_ACCESS_HEADER as i, buildDaemonHealthPayload as l, nodeHttpRequestUrl as m, DAEMON_HTTP_INSTANCE_HEADER as n, DAEMON_HTTP_TENANT_HEADER as o, isTenantOwnedSessionName as p, DAEMON_HTTP_INSTANCE_MISMATCH_HEADER as r, DAEMON_HTTP_UPSTREAM_INSTANCE_HEADER as s, DAEMON_HTTP_BASE_PATH as t, buildDaemonHttpAuthHeaders as u };
101
+ export { normalizeTenantId as _, DAEMON_HTTP_PUBLIC_NETWORK_ACCESS as a, DAEMON_INSTANCE_REASONS as c, buildDaemonHttpAuthHeaders as d, buildDaemonHttpUrl as f, normalizeDaemonPublicOrigin as g, nodeHttpRequestUrl as h, DAEMON_HTTP_NETWORK_ACCESS_HEADER as i, DAEMON_REQUEST_MAX_BYTES as l, isTenantOwnedSessionName as m, DAEMON_HTTP_INSTANCE_HEADER as n, DAEMON_HTTP_TENANT_HEADER as o, buildDaemonInstanceMismatchRpcResponse as p, DAEMON_HTTP_INSTANCE_MISMATCH_HEADER as r, DAEMON_HTTP_UPSTREAM_INSTANCE_HEADER as s, DAEMON_HTTP_BASE_PATH as t, buildDaemonHealthPayload as u };
package/dist/errors.mjs CHANGED
@@ -176,12 +176,11 @@ var AppError = class AppError extends Error {
176
176
  }
177
177
  };
178
178
  /**
179
- * `details.reason` of a request its requester abandoned — an explicit cancel or
180
- * a client disconnect. One definition, so every layer that must let a
181
- * cancellation through untouched (retry loops, provider adapters, runner
182
- * transports) dispatches on the same typed reason.
179
+ * `details.reason` of a request its requester abandoned. One row, so every layer that must let a
180
+ * cancellation through untouched (retry loops, provider adapters, runner transports) dispatches on
181
+ * the same typed reason through {@link isRequestCanceledDetails}.
183
182
  */
184
- const REQUEST_CANCELED_REASON = "request_canceled";
183
+ const REQUEST_CANCELED_REASONS = { canceled: { reason: "request_canceled" } };
185
184
  const REQUEST_CANCELED_MESSAGE = "request canceled";
186
185
  const REQUEST_CANCELED_HINT = "The request was canceled intentionally (explicit cancel or client disconnect) — no retry is needed unless the cancellation was unintended.";
187
186
  /**
@@ -193,7 +192,7 @@ function createRequestCanceledError(details, cause) {
193
192
  return new AppError("COMMAND_FAILED", REQUEST_CANCELED_MESSAGE, {
194
193
  hint: REQUEST_CANCELED_HINT,
195
194
  ...details,
196
- reason: REQUEST_CANCELED_REASON
195
+ reason: REQUEST_CANCELED_REASONS.canceled.reason
197
196
  }, cause);
198
197
  }
199
198
  function asAppError(err, fallbackCode = "UNKNOWN") {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { r as normalizeError, t as AppError } from "./errors.mjs";
2
2
  import { l as timingSafeStringEqual } from "./transport.mjs";
3
- import { a as DAEMON_HTTP_PUBLIC_NETWORK_ACCESS, c as DAEMON_REQUEST_MAX_BYTES, d as buildDaemonHttpUrl, f as buildDaemonInstanceMismatchRpcResponse, g as normalizeTenantId, h as normalizeDaemonPublicOrigin, i as DAEMON_HTTP_NETWORK_ACCESS_HEADER, l as buildDaemonHealthPayload, n as DAEMON_HTTP_INSTANCE_HEADER, o as DAEMON_HTTP_TENANT_HEADER, p as isTenantOwnedSessionName, r as DAEMON_HTTP_INSTANCE_MISMATCH_HEADER, s as DAEMON_HTTP_UPSTREAM_INSTANCE_HEADER, t as DAEMON_HTTP_BASE_PATH, u as buildDaemonHttpAuthHeaders } from "./daemon-http.mjs";
3
+ import { _ as normalizeTenantId, a as DAEMON_HTTP_PUBLIC_NETWORK_ACCESS, c as DAEMON_INSTANCE_REASONS, d as buildDaemonHttpAuthHeaders, f as buildDaemonHttpUrl, g as normalizeDaemonPublicOrigin, i as DAEMON_HTTP_NETWORK_ACCESS_HEADER, l as DAEMON_REQUEST_MAX_BYTES, m as isTenantOwnedSessionName, n as DAEMON_HTTP_INSTANCE_HEADER, o as DAEMON_HTTP_TENANT_HEADER, p as buildDaemonInstanceMismatchRpcResponse, r as DAEMON_HTTP_INSTANCE_MISMATCH_HEADER, s as DAEMON_HTTP_UPSTREAM_INSTANCE_HEADER, t as DAEMON_HTTP_BASE_PATH, u as buildDaemonHealthPayload } from "./daemon-http.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import http from "node:http";
6
6
  //#region src/install-source-admission.ts
@@ -508,7 +508,7 @@ function refuseStaleProxyInstance(request, route, rpcId, instanceId) {
508
508
  return sendInstanceMismatch(rpcId);
509
509
  }
510
510
  function sendInstanceMismatch(rpcId) {
511
- return Response.json(buildDaemonInstanceMismatchRpcResponse(rpcId, "Proxy instance changed", normalizeError(new AppError("COMMAND_FAILED", "Proxy instance changed", { reason: "remote_instance_mismatch" }))), {
511
+ return Response.json(buildDaemonInstanceMismatchRpcResponse(rpcId, "Proxy instance changed", normalizeError(new AppError("COMMAND_FAILED", "Proxy instance changed", { reason: DAEMON_INSTANCE_REASONS.instanceMismatch.reason }))), {
512
512
  status: 409,
513
513
  headers: { [DAEMON_HTTP_INSTANCE_MISMATCH_HEADER]: "true" }
514
514
  });
@@ -1,4 +1,4 @@
1
- import { m as nodeHttpRequestUrl } from "./daemon-http.mjs";
1
+ import { h as nodeHttpRequestUrl } from "./daemon-http.mjs";
2
2
  import { Readable } from "node:stream";
3
3
  import { pipeline } from "node:stream/promises";
4
4
  import { TLSSocket } from "node:tls";
package/dist/process.mjs CHANGED
@@ -202,6 +202,14 @@ function createExecTraceContext(cmd, timeoutMs, hostEnv) {
202
202
  }
203
203
  //#endregion
204
204
  //#region ../host-kit/src/internal/exec.ts
205
+ /**
206
+ * The refusals this module answers with when a host command cannot run or its result cannot be
207
+ * attributed to a host.
208
+ */
209
+ const HOST_COMMAND_REASONS = {
210
+ hostEnvironmentUnscoped: { reason: "host_environment_unscoped" },
211
+ xcrunToolNotFound: { reason: "xcrun-tool-not-found" }
212
+ };
205
213
  const BARE_COMMAND_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
206
214
  const commandExecutorOverrideScope = new AsyncLocalStorage();
207
215
  async function withoutCommandExecutorOverride(fn) {
@@ -465,7 +473,7 @@ function xcrunToolNotFoundDetails(stderr) {
465
473
  const developerDir = commandDeveloperDir();
466
474
  const source = developerDir ? `DEVELOPER_DIR ${developerDir}` : "the developer dir selected by xcode-select (see xcode-select -p)";
467
475
  return {
468
- reason: "xcrun-tool-not-found",
476
+ reason: HOST_COMMAND_REASONS.xcrunToolNotFound.reason,
469
477
  developerDir: developerDir ?? null,
470
478
  hint: `xcrun could not find ${tool} in ${source}. Export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer (or your Xcode's path) before running agent-device, or run sudo xcode-select -s /Applications/Xcode.app.`
471
479
  };
@@ -626,6 +634,18 @@ function sleep(ms, signal) {
626
634
  }
627
635
  //#endregion
628
636
  //#region ../host-kit/src/internal/host-process.ts
637
+ /**
638
+ * Why a confirmed stop left the process alone. The verdict travels to the caller and, through
639
+ * {@link confirmedProcessStopDetails}, into `error.details.reason`.
640
+ */
641
+ const PROCESS_STOP_REASONS = {
642
+ signalFailed: { reason: "signal-failed" },
643
+ exitTimeout: { reason: "exit-timeout" },
644
+ identityUnverified: { reason: "identity-unverified" }
645
+ };
646
+ const SIGNAL_FAILED = PROCESS_STOP_REASONS.signalFailed.reason;
647
+ const EXIT_TIMEOUT = PROCESS_STOP_REASONS.exitTimeout.reason;
648
+ const IDENTITY_UNVERIFIED = PROCESS_STOP_REASONS.identityUnverified.reason;
629
649
  const PS_TIMEOUT_MS = 1e3;
630
650
  const HOST_PS_COMMANDS = ["/bin/ps", "/run/current-system/sw/bin/ps"];
631
651
  const WINDOWS_PS_TIMEOUT_MS = 2e3;
@@ -1065,7 +1085,7 @@ function confirmedProcessStopDetails(retained, pid) {
1065
1085
  return {
1066
1086
  reason: retained.reason,
1067
1087
  signal: "signal" in retained ? retained.signal : void 0,
1068
- errno: retained.reason === "signal-failed" ? retained.errno : void 0,
1088
+ errno: retained.reason === SIGNAL_FAILED ? retained.errno : void 0,
1069
1089
  pid
1070
1090
  };
1071
1091
  }
@@ -1081,7 +1101,7 @@ function describeUnconfirmedProcessStop(pid, claimedAs) {
1081
1101
  * so an unrelated failure's details cannot be forwarded as one.
1082
1102
  */
1083
1103
  function isConfirmedProcessStopReason(value) {
1084
- return value === "signal-failed" || value === "exit-timeout" || value === "identity-unverified";
1104
+ return value === SIGNAL_FAILED || value === EXIT_TIMEOUT || value === IDENTITY_UNVERIFIED;
1085
1105
  }
1086
1106
  /**
1087
1107
  * The verdict a nested layer published, or nothing when the error carries no stop verdict. A wrapper
@@ -1097,7 +1117,7 @@ function readConfirmedProcessStopDetails(details) {
1097
1117
  return {
1098
1118
  reason,
1099
1119
  signal: signal === "SIGTERM" || signal === "SIGINT" || signal === "SIGKILL" ? signal : void 0,
1100
- errno: reason === "signal-failed" && typeof errno === "string" ? errno : void 0,
1120
+ errno: reason === SIGNAL_FAILED && typeof errno === "string" ? errno : void 0,
1101
1121
  pid
1102
1122
  };
1103
1123
  }
@@ -1127,7 +1147,7 @@ async function stopProcessAndConfirmExit(target, budget) {
1127
1147
  };
1128
1148
  if (identity === "unverified") return {
1129
1149
  status: "retained",
1130
- reason: "identity-unverified"
1150
+ reason: IDENTITY_UNVERIFIED
1131
1151
  };
1132
1152
  const graceful = budget.gracefulSignal ?? "SIGTERM";
1133
1153
  const term = await proveSignalStage(target, graceful, budget.termTimeoutMs);
@@ -1136,7 +1156,7 @@ async function stopProcessAndConfirmExit(target, budget) {
1136
1156
  if (kill.proof !== "survived" && kill.proof !== "unverified") return stageVerdict(kill, "SIGKILL");
1137
1157
  return {
1138
1158
  status: "retained",
1139
- reason: "exit-timeout",
1159
+ reason: EXIT_TIMEOUT,
1140
1160
  signal: "SIGKILL"
1141
1161
  };
1142
1162
  }
@@ -1154,7 +1174,7 @@ function stageVerdict(stage, signal) {
1154
1174
  if (stage.proof === "refused") return retainedSignalFailure(signal, stage.errno);
1155
1175
  return {
1156
1176
  status: "retained",
1157
- reason: "identity-unverified"
1177
+ reason: IDENTITY_UNVERIFIED
1158
1178
  };
1159
1179
  }
1160
1180
  /** Pre-signal identity proof: `released` when `kill(pid, 0)` fails, else {@link judgeProcessIdentity}. */
@@ -1165,7 +1185,7 @@ async function proveStopTargetIdentity(target) {
1165
1185
  function retainedSignalFailure(signal, errno) {
1166
1186
  return {
1167
1187
  status: "retained",
1168
- reason: "signal-failed",
1188
+ reason: SIGNAL_FAILED,
1169
1189
  signal,
1170
1190
  errno
1171
1191
  };
@@ -1369,7 +1389,7 @@ async function reapOwnedProcess(record, policy) {
1369
1389
  }
1370
1390
  function reapOutcomeOf(stop) {
1371
1391
  if (stop.status === "stopped") return stop.signal && !stop.reassigned ? "terminated" : "missing";
1372
- return stop.reason === "identity-unverified" ? "unconfirmed" : "survived";
1392
+ return stop.reason === PROCESS_STOP_REASONS.identityUnverified.reason ? "unconfirmed" : "survived";
1373
1393
  }
1374
1394
  function gracefulSignalFor(record) {
1375
1395
  return record.purpose === "simctl-screen-recording" ? "SIGINT" : "SIGTERM";
@@ -1700,6 +1720,7 @@ function classifyOwnerStateDirectory(stateDir) {
1700
1720
  //#endregion
1701
1721
  //#region ../host-kit/src/process.ts
1702
1722
  var process_exports = /* @__PURE__ */ __exportAll({
1723
+ PROCESS_STOP_REASONS: () => PROCESS_STOP_REASONS,
1703
1724
  captureHostEnvironment: () => captureHostEnvironment,
1704
1725
  classifyOwnerLiveness: () => classifyOwnerLiveness,
1705
1726
  classifyOwnerLivenessAsync: () => classifyOwnerLivenessAsync,
@@ -1746,4 +1767,4 @@ async function readProcessExecutablePaths(pids, host, timeoutMs) {
1746
1767
  return await (await import("./process-executable-path.mjs")).readProcessExecutablePaths(pids, host, timeoutMs);
1747
1768
  }
1748
1769
  //#endregion
1749
- export { captureHostEnvironment, classifyOwnerLiveness, classifyOwnerLivenessAsync, classifyOwnerLivenessFromObservation, confirmedProcessStopDetails, createOwnedProcessRecordStore, describeUnconfirmedProcessStop, expandProcessTree, hostNodeExecutablePath, hostNodeVersion, hostPlatform, hostProcessId, isProcessAlive, isProcessGroupAlive, isProcessPid, isProcessZombie, judgeProcessIdentity, listHostProcesses, runCmd as n, ownerIdentityDiffers, ownerIdentityMatches, processStartTimesDiffer, withoutCommandExecutorOverride as r, readConfirmedProcessStopDetails, readCurrentOwnerIdentity, readHostCpuArch, readHostCpuArchSync, readHostProcessIdentityObservations, readHostProcessIdentityObservationsAsync, readOwnedProcessRecordFile, readProcessCommand, readProcessExecutablePaths, readProcessIdentities, readProcessIdentityFacts, readProcessStartTime, reapOwnedProcessRecordsAtStartup, signalPidsBestEffort, signalProcessGroupBestEffort, stopProcessAndConfirmExit, process_exports as t, uniquePositivePids, waitForProcessExit, writeHostStderr };
1770
+ export { PROCESS_STOP_REASONS, captureHostEnvironment, classifyOwnerLiveness, classifyOwnerLivenessAsync, classifyOwnerLivenessFromObservation, confirmedProcessStopDetails, createOwnedProcessRecordStore, describeUnconfirmedProcessStop, expandProcessTree, hostNodeExecutablePath, hostNodeVersion, hostPlatform, hostProcessId, isProcessAlive, isProcessGroupAlive, isProcessPid, isProcessZombie, judgeProcessIdentity, listHostProcesses, runCmd as n, ownerIdentityDiffers, ownerIdentityMatches, processStartTimesDiffer, withoutCommandExecutorOverride as r, readConfirmedProcessStopDetails, readCurrentOwnerIdentity, readHostCpuArch, readHostCpuArchSync, readHostProcessIdentityObservations, readHostProcessIdentityObservationsAsync, readOwnedProcessRecordFile, readProcessCommand, readProcessExecutablePaths, readProcessIdentities, readProcessIdentityFacts, readProcessStartTime, reapOwnedProcessRecordsAtStartup, signalPidsBestEffort, signalProcessGroupBestEffort, stopProcessAndConfirmExit, process_exports as t, uniquePositivePids, waitForProcessExit, writeHostStderr };
@@ -2,7 +2,12 @@ import { t as AppError } from "./errors.mjs";
2
2
  import { a as isTransferPhaseTimeoutError, c as observeCompletedRequestWrites, i as createTransferPhaseWatchdog, n as TRANSFER_CONNECT_TIMEOUT_MS, o as loadNodeHttpRequester, r as TRANSFER_RESPONSE_HEADER_TIMEOUT_MS, s as observeClientRequestPhases, t as TRANSFER_BODY_INACTIVITY_TIMEOUT_MS } from "./transport.mjs";
3
3
  //#region src/transfer-transport.ts
4
4
  const PROXY_TRANSFER_AGGREGATE_MS = 6e5;
5
- const TRANSFER_FORWARDING_DEADLINE_REASON = "transfer_forwarding_deadline_exceeded";
5
+ /** Why the proxy's own transfer hop gives up on the exchange. */
6
+ const TRANSFER_FORWARDING_REASONS = {
7
+ forwardingDeadline: { reason: "transfer_forwarding_deadline_exceeded" },
8
+ gatewayStatus: { reason: "transfer_gateway_status" },
9
+ upstreamClosed: { reason: "transfer_upstream_closed" }
10
+ };
6
11
  const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([
7
12
  204,
8
13
  205,
@@ -47,7 +52,7 @@ async function settleUpstreamFetch(upstreamFetch, request) {
47
52
  function transferWireDetails(error) {
48
53
  if (!(error instanceof AppError) || error.code !== "COMMAND_FAILED") return {};
49
54
  const { reason, transferPhase, timeoutMs } = error.details ?? {};
50
- if (reason === TRANSFER_FORWARDING_DEADLINE_REASON) return transferPhase === "forwarding" && timeoutMs === PROXY_TRANSFER_AGGREGATE_MS ? {
55
+ if (reason === TRANSFER_FORWARDING_REASONS.forwardingDeadline.reason) return transferPhase === "forwarding" && timeoutMs === PROXY_TRANSFER_AGGREGATE_MS ? {
51
56
  reason,
52
57
  transferPhase,
53
58
  timeoutMs
@@ -76,7 +81,7 @@ function transferWireDetails(error) {
76
81
  function openExchange(caller) {
77
82
  const forwarding = new AbortController();
78
83
  const timer = setTimeout(() => forwarding.abort(new AppError("COMMAND_FAILED", "Proxy transfer forwarding deadline exceeded", {
79
- reason: TRANSFER_FORWARDING_DEADLINE_REASON,
84
+ reason: TRANSFER_FORWARDING_REASONS.forwardingDeadline.reason,
80
85
  transferPhase: "forwarding",
81
86
  timeoutMs: PROXY_TRANSFER_AGGREGATE_MS
82
87
  })), PROXY_TRANSFER_AGGREGATE_MS);
@@ -151,7 +156,7 @@ async function exchangeOverNodeHttp(request, exchange) {
151
156
  const status = res.statusCode ?? 500;
152
157
  if (status < 200 || status > 599) {
153
158
  fail(new AppError("COMMAND_FAILED", "Upstream daemon returned an unusable HTTP status", {
154
- reason: "transfer_gateway_status",
159
+ reason: TRANSFER_FORWARDING_REASONS.gatewayStatus.reason,
155
160
  status
156
161
  }));
157
162
  return;
@@ -182,7 +187,7 @@ async function exchangeOverNodeHttp(request, exchange) {
182
187
  req.once("close", () => {
183
188
  requestClosed.abort();
184
189
  closed();
185
- if (!answered) fail(new AppError("COMMAND_FAILED", "Upstream daemon closed before responding", { reason: "transfer_upstream_closed" }));
190
+ if (!answered) fail(new AppError("COMMAND_FAILED", "Upstream daemon closed before responding", { reason: TRANSFER_FORWARDING_REASONS.upstreamClosed.reason }));
186
191
  });
187
192
  });
188
193
  req.on("error", fail);
@@ -250,7 +255,7 @@ function waitUntilDrained(req, signal) {
250
255
  if (signal.aborted) aborted();
251
256
  else if (req.destroyed || req.closed) {
252
257
  cleanup();
253
- reject(new AppError("COMMAND_FAILED", "Upstream daemon closed during a write", { reason: "transfer_upstream_closed" }));
258
+ reject(new AppError("COMMAND_FAILED", "Upstream daemon closed during a write", { reason: TRANSFER_FORWARDING_REASONS.upstreamClosed.reason }));
254
259
  } else if (!req.writableNeedDrain) drained();
255
260
  });
256
261
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-device/proxy",
3
- "version": "0.21.42-nightly.20261122.239",
3
+ "version": "0.21.42",
4
4
  "type": "module",
5
5
  "description": "Transport-neutral authenticating proxy in front of an agent-device daemon.",
6
6
  "license": "MIT",